Difference between revisions of "Extension:NukeDPL.php"
(setup call doubled up) |
m |
||
Line 6: | Line 6: | ||
# - Adapted from Special:Nuke by Brion Vibber, see http://www.mediawiki.org/wiki/Nuke | # - Adapted from Special:Nuke by Brion Vibber, see http://www.mediawiki.org/wiki/Nuke | ||
− | if( !defined( 'MEDIAWIKI' ) ) die( 'Not | + | if(!defined('MEDIAWIKI')) die('Not a valid entry point.'); |
define('NUKEDPL_VERSION', '1.0.2, 2007-05-14'); | define('NUKEDPL_VERSION', '1.0.2, 2007-05-14'); | ||
$wgGroupPermissions['sysop']['nuke'] = true; | $wgGroupPermissions['sysop']['nuke'] = true; | ||
− | $wgAvailableRights[] = 'nuke'; | + | $wgAvailableRights[] = 'nuke'; |
− | $wgExtensionFunctions[] = 'wfSetupNukeDPL'; | + | $wgExtensionFunctions[] = 'wfSetupNukeDPL'; |
$wgExtensionCredits['specialpage'][] = array( | $wgExtensionCredits['specialpage'][] = array( | ||
− | + | 'name' => 'Special:NukeDPL', | |
− | + | 'author' => '[http://www.organicdesign.co.nz/nad User:Nad]', | |
− | + | 'description' => 'Mass delete by DPL query', | |
− | + | 'url' => 'http://www.mediawiki.org/wiki/Extension:NukeDPL', | |
− | + | 'version' => NUKEDPL_VERSION | |
− | + | ); | |
function wfSetupNukeDPL() { | function wfSetupNukeDPL() { | ||
− | + | global $wgMessageCache,$wgSpecialPages; | |
− | + | $wgMessageCache->addMessages(array( | |
− | + | 'nukedpl' => 'Mass delete by DPL query', | |
− | + | 'nuke-nopages' => "No pages to delete using DPL-query: <tt>$1</tt>", | |
− | + | 'nuke-list' => "The following pages were selected by DPL-query: <tt>$1</tt> hit the button to delete them.", | |
− | + | 'nuke-defaultreason' => "Mass removal of pages selected by DPL-query: ($1)", | |
− | + | )); | |
− | |||
− | |||
− | + | $wgSpecialPages['NukeDPL'] = array( | |
− | + | 'SpecialPage', # class | |
− | + | 'NukeDPL', # name as seen in links | |
− | + | 'nuke', # user rights required | |
− | + | true, # listed in special:specialpages | |
− | + | false, # function called by execute() - defaults to wfSpecial{$name} | |
− | + | false, # file included by execute() - defaults to Special{$name}.php | |
− | } | + | false # includable |
+ | ); | ||
+ | } | ||
function wfSpecialNukeDPL( $par = '' ) { | function wfSpecialNukeDPL( $par = '' ) { | ||
− | + | global $wgRequest; | |
− | + | $target = $wgRequest->getText( 'target', $par ); | |
− | + | $form = new NukeDPLForm( $target, $wgRequest ); | |
− | + | $form->run(); | |
− | } | + | } |
class NukeDPLForm { | 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->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<div>" . | |
− | + | wfMsgHtml( 'deletecomment' ) . ': ' . | |
− | + | 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" ); | |
− | + | $sk =& $wgUser->getSkin(); | |
− | + | foreach( $pages as $title ) { | |
− | + | $wgOut->addHTML( '<li>' . | |
− | + | wfElement( 'input', array( | |
− | + | 'type' => 'checkbox', | |
− | + | 'name' => "pages[]", | |
− | + | 'value' => $title, | |
− | + | 'checked' => 'checked' ) ) . | |
− | + | ' ' . | |
− | + | $sk->makeKnownLinkObj( Title::newFromText($title) ) . "</li>\n" ); | |
− | + | } | |
− | + | $wgOut->addHTML( "</ul>\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("<dpl>$query</dpl>",$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 ); | |
− | + | } | |
− | + | } | |
} | } | ||
?> | ?> |
Revision as of 00:56, 20 May 2007
<?php
- Extension:NukeDPL
{{#Security:*|dev}}{{#Security:view|*}}Template:Php
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - See http://www.mediawiki.org/wiki/Extension:NukeDPL for installation and usage details
- - Author: http://www.organicdesign.co.nz/nad User:Nad
- - Adapted from Special:Nuke by Brion Vibber, see http://www.mediawiki.org/wiki/Nuke
if(!defined('MEDIAWIKI')) die('Not a valid entry point.');
define('NUKEDPL_VERSION', '1.0.2, 2007-05-14');
$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,$wgSpecialPages; $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)", ));
$wgSpecialPages['NukeDPL'] = array( 'SpecialPage', # class 'NukeDPL', # name as seen in links 'nuke', # user rights required true, # listed in special:specialpages false, # function called by execute() - defaults to wfSpecial{$name} false, # file included by execute() - defaults to Special{$name}.php false # includable ); }
function wfSpecialNukeDPL( $par = ) { 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->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 ); } } }
?>