Difference between revisions of "Extension:NukeDPL.php"

From Organic Design wiki
(1.1.1 - standardise formatting and better description)
Line 1: Line 1:
 
<?php
 
<?php
# Extension:NukeDPL{{Category:Extensions|NukeDPL}}{{php}}
+
/**
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
+
* NukeDPL extension - Mass delete by DPL query
# - See http://www.mediawiki.org/wiki/Extension:NukeDPL for installation and usage details
+
*
# - Author: http://www.organicdesign.co.nz/nad User:Nad
+
* See http://www.mediawiki.org/wiki/Extension:NukeDPL for installation and usage details
# - Adapted from Special:Nuke by Brion Vibber, see http://www.mediawiki.org/wiki/Nuke
+
*
 +
* @package MediaWiki
 +
* @subpackage Extensions
 +
* @author Aran Dunkley [http://www.organicdesign.co.nz/nad User:Nad]
 +
* @copyright © 2007 Aran Dunkley
 +
* @licence GNU General Public Licence 2.0 or later
 +
*/
  
 
if(!defined('MEDIAWIKI')) die('Not a valid entry point.');
 
if(!defined('MEDIAWIKI')) die('Not a valid entry point.');
  
define('NUKEDPL_VERSION', '1.1.0, 2007-07-12');
+
define('NUKEDPL_VERSION', '1.1.1, 2007-06-01');
  
 
$wgGroupPermissions['sysop']['nuke'] = true;
 
$wgGroupPermissions['sysop']['nuke'] = true;
Line 20: Line 26:
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:NukeDPL',
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:NukeDPL',
 
'version'    => NUKEDPL_VERSION
 
'version'    => NUKEDPL_VERSION
);
+
);
  
 
function wfSetupNukeDPL() {
 
function wfSetupNukeDPL() {
Line 34: Line 40:
 
# Add the specialpage to the environment
 
# Add the specialpage to the environment
 
SpecialPage::addPage(new SpecialNukeDPL());
 
SpecialPage::addPage(new SpecialNukeDPL());
}
+
}
  
# Define a new class based on the SpecialPage class
+
/**
 +
* Define a new class based on the SpecialPage class
 +
*/
 
require_once("$IP/includes/SpecialPage.php");
 
require_once("$IP/includes/SpecialPage.php");
 
class SpecialNukeDPL extends SpecialPage {
 
class SpecialNukeDPL extends SpecialPage {
Line 43: Line 51:
 
function SpecialNukeDPL() {
 
function SpecialNukeDPL() {
 
SpecialPage::SpecialPage('NukeDPL','nuke');
 
SpecialPage::SpecialPage('NukeDPL','nuke');
}
+
}
 
   
 
   
 
# Override SpecialPage::execute($param = '')
 
# Override SpecialPage::execute($param = '')
Line 51: Line 59:
 
$form = new NukeDPLForm( $target, $wgRequest );
 
$form = new NukeDPLForm( $target, $wgRequest );
 
$form->run();
 
$form->run();
}
 
 
}
 
}
 +
}
  
 
class NukeDPLForm {
 
class NukeDPLForm {
Line 62: Line 70:
 
$this->mPosted = $request->wasPosted() && $wgUser->matchEditToken($request->getVal('wpEditToken'));
 
$this->mPosted = $request->wasPosted() && $wgUser->matchEditToken($request->getVal('wpEditToken'));
 
if ($this->mPosted) $this->mPages = $request->getArray('pages');
 
if ($this->mPosted) $this->mPages = $request->getArray('pages');
}
+
}
  
 
function run() {
 
function run() {
Line 68: Line 76:
 
if ($this->mTarget != '') $this->listForm($this->mTarget,$this->mReason);
 
if ($this->mTarget != '') $this->listForm($this->mTarget,$this->mReason);
 
else $this->promptForm();
 
else $this->promptForm();
}
+
}
  
 
function promptForm() {
 
function promptForm() {
Line 77: Line 85:
 
$submit = wfElement('input',array('type' => 'submit'));
 
$submit = wfElement('input',array('type' => 'submit'));
  
$wgOut->addWikiText("This tool allows for mass deletions of pages selected by a DPL query:");
+
$wgOut->addWikiText("This tool allows for mass deletions of pages selected by a DPL query.<br>");
 +
$wgOut->addWikiText("''(Remember, titles are case-sensitive, and don't add any DPL tags of braces)''");
 
$wgOut->addHTML(wfElement('form', array('action' => $nuke->getLocalURL('action=submit'),'method' => 'post'),null)
 
$wgOut->addHTML(wfElement('form', array('action' => $nuke->getLocalURL('action=submit'),'method' => 'post'),null)
 
.'<textarea name="target" cols=25 rows=10></textarea>' . "\n$submit\n");
 
.'<textarea name="target" cols=25 rows=10></textarea>' . "\n$submit\n");
 
$wgOut->addHTML("</form>");
 
$wgOut->addHTML("</form>");
}
+
}
  
 
function listForm($query,$reason) {
 
function listForm($query,$reason) {
Line 90: Line 99:
 
$wgOut->addWikiText(wfMsg('nuke-nopages',$query));
 
$wgOut->addWikiText(wfMsg('nuke-nopages',$query));
 
return $this->promptForm();
 
return $this->promptForm();
}
+
}
  
 
$wgOut->addWikiText(wfMsg('nuke-list',$query));
 
$wgOut->addWikiText(wfMsg('nuke-list',$query));
Line 101: Line 110:
 
.wfElement('input',array('name' => 'wpReason','value' => $reason,'size' => 60))."</div>\n$submit"
 
.wfElement('input',array('name' => 'wpReason','value' => $reason,'size' => 60))."</div>\n$submit"
 
.wfElement('input',array('type' => 'hidden','name' => 'wpEditToken','value' => $wgUser->editToken()))."\n<ul>\n"
 
.wfElement('input',array('type' => 'hidden','name' => 'wpEditToken','value' => $wgUser->editToken()))."\n<ul>\n"
);
+
);
  
 
$sk =& $wgUser->getSkin();
 
$sk =& $wgUser->getSkin();
Line 108: Line 117:
 
.wfElement('input',array('type' => 'checkbox','name' => "pages[]",'value' => $title,'checked' => 'checked'))
 
.wfElement('input',array('type' => 'checkbox','name' => "pages[]",'value' => $title,'checked' => 'checked'))
 
.'&nbsp;'.$sk->makeKnownLinkObj(Title::newFromText($title))."</li>\n"
 
.'&nbsp;'.$sk->makeKnownLinkObj(Title::newFromText($title))."</li>\n"
);
+
);
}
+
}
 
$wgOut->addHTML("</ul>\n$submit</form>");
 
$wgOut->addHTML("</ul>\n$submit</form>");
}
+
}
  
 
function getPages($query) {
 
function getPages($query) {
Line 121: Line 130:
 
preg_match_all('|^\\${3}(.+?)\\${3}|m',$out->getText(),$matches);
 
preg_match_all('|^\\${3}(.+?)\\${3}|m',$out->getText(),$matches);
 
return $matches[1];
 
return $matches[1];
}
+
}
  
 
function doDelete($pages,$reason) {
 
function doDelete($pages,$reason) {
Line 128: Line 137:
 
$article = new Article($title);
 
$article = new Article($title);
 
$article->doDelete($reason);
 
$article->doDelete($reason);
}
 
 
}
 
}
 
}
 
}
?>
+
}

Revision as of 09:31, 1 June 2008

<?php /**

* NukeDPL extension - Mass delete by DPL query
*
* See http://www.mediawiki.org/wiki/Extension:NukeDPL for installation and usage details
*
* @package MediaWiki
* @subpackage Extensions
* @author Aran Dunkley User:Nad
* @copyright © 2007 Aran Dunkley
* @licence GNU General Public Licence 2.0 or later
*/

if(!defined('MEDIAWIKI')) die('Not a valid entry point.');

define('NUKEDPL_VERSION', '1.1.1, 2007-06-01');

$wgGroupPermissions['sysop']['nuke'] = true; $wgAvailableRights[] = 'nuke'; $wgExtensionFunctions[] = 'wfSetupNukeDPL';

$wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:NukeDPL', 'author' => 'User:Nad', 'description' => 'Mass delete by DPL query', 'url' => 'http://www.mediawiki.org/wiki/Extension:NukeDPL', 'version' => NUKEDPL_VERSION );

function wfSetupNukeDPL() { global $wgMessageCache;

$wgMessageCache->addMessages(array( 'nukedpl' => 'Mass delete by DPL query', 'nuke-nopages' => "No pages to delete using DPL-query: $1", 'nuke-list' => "The following pages were selected by DPL-query: $1 hit the button to delete them.", 'nuke-defaultreason' => "Mass removal of pages selected by DPL-query: ($1)", ));

# Add the specialpage to the environment SpecialPage::addPage(new SpecialNukeDPL()); }

/**

* Define a new class based on the SpecialPage class
*/

require_once("$IP/includes/SpecialPage.php"); class SpecialNukeDPL extends SpecialPage {

# Constructor function SpecialNukeDPL() { SpecialPage::SpecialPage('NukeDPL','nuke'); }

# Override SpecialPage::execute($param = ) function execute($param) { global $wgRequest; $target = $wgRequest->getText( 'target', $par ); $form = new NukeDPLForm( $target, $wgRequest ); $form->run(); } }

class NukeDPLForm {

function NukeDPLForm($target,$request) { global $wgUser; $this->mTarget = $target; $this->mReason = $request->getText('wpReason',wfMsgForContent('nuke-defaultreason',$target)); $this->mPosted = $request->wasPosted() && $wgUser->matchEditToken($request->getVal('wpEditToken')); if ($this->mPosted) $this->mPages = $request->getArray('pages'); }

function run() { if ($this->mPosted && $this->mPages) return $this->doDelete($this->mPages,$this->mReason); if ($this->mTarget != ) $this->listForm($this->mTarget,$this->mReason); else $this->promptForm(); }

function promptForm() { global $wgUser, $wgOut;

$sk =& $wgUser->getSkin(); $nuke = Title::makeTitle(NS_SPECIAL,'NukeDPL'); $submit = wfElement('input',array('type' => 'submit'));

$wgOut->addWikiText("This tool allows for mass deletions of pages selected by a DPL query.
"); $wgOut->addWikiText("(Remember, titles are case-sensitive, and don't add any DPL tags of braces)"); $wgOut->addHTML(wfElement('form', array('action' => $nuke->getLocalURL('action=submit'),'method' => 'post'),null) .'<textarea name="target" cols=25 rows=10></textarea>' . "\n$submit\n"); $wgOut->addHTML("</form>"); }

function listForm($query,$reason) { global $wgUser,$wgOut,$wgLang;

$pages = $this->getPages($query); if (count($pages) == 0) { $wgOut->addWikiText(wfMsg('nuke-nopages',$query)); return $this->promptForm(); }

$wgOut->addWikiText(wfMsg('nuke-list',$query));

$nuke = Title::makeTitle(NS_SPECIAL,'NukeDPL'); $submit = wfElement('input',array('type' => 'submit')); $wgOut->addHTML( wfElement('form',array('action' => $nuke->getLocalURL('action=delete'),'method' => 'post'),null)

."\n

".wfMsgHtml('deletecomment').': ' .wfElement('input',array('name' => 'wpReason','value' => $reason,'size' => 60))."

\n$submit" .wfElement('input',array('type' => 'hidden','name' => 'wpEditToken','value' => $wgUser->editToken()))."\n

    \n" ); $sk =& $wgUser->getSkin(); foreach ($pages as $title) { $wgOut->addHTML('
  • ' .wfElement('input',array('type' => 'checkbox','name' => "pages[]",'value' => $title,'checked' => 'checked')) .' '.$sk->makeKnownLinkObj(Title::newFromText($title))."
  • \n"

    ); }

    $wgOut->addHTML("

\n$submit</form>");

}

function getPages($query) { global $wgTitle,$wgParser,$wgUser; $fname = 'NukeDPLForm::getNewPages'; $query = trim($query)."\nmode=userformat\nlistseparators=,\\n$$$%PAGE%$$$,,\n"; $opt = ParserOptions::newFromUser($wgUser);

$out = $wgParser->parse("

Extension:DynamicPageList (DPL), version 3.3.3: Warning: No parameter option supplied for '$query'. (Missing '=')


Extension:DynamicPageList (DPL), version 3.3.3: Error: No selection criteria found! You must use at least one of the following parameters: category, namespace, titlematch, linksto, uses, createdby, modifiedby, lastmodifiedby, or their 'not' variants


Extension:DynamicPageList (DPL), version 3.3.3: Warning: No results.

",$wgTitle,$opt,false,true);

preg_match_all('|^\\${3}(.+?)\\${3}|m',$out->getText(),$matches); return $matches[1]; }

function doDelete($pages,$reason) { foreach($pages as $page) { $title = Title::newFromUrl($page); $article = new Article($title); $article->doDelete($reason); } } }