2005-09-18 09:28:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if( !defined( 'MEDIAWIKI' ) )
|
|
|
|
die( 'Not an entry point.' );
|
|
|
|
|
|
|
|
$wgExtensionFunctions[] = 'wfSetupNuke';
|
2008-01-09 17:19:53 +00:00
|
|
|
$wgExtensionMessagesFiles['Nuke'] = dirname(__FILE__) . '/SpecialNuke.i18n.php';
|
2005-09-18 09:28:56 +00:00
|
|
|
|
2007-07-26 10:54:37 +00:00
|
|
|
$wgExtensionCredits['specialpage'][] = array(
|
2008-02-14 13:50:42 +00:00
|
|
|
'name' => 'Nuke',
|
|
|
|
'version' => '2008-02-14',
|
|
|
|
'description' => 'Gives sysops the ability to mass delete pages',
|
|
|
|
'descriptionmsg' => 'nuke-desc',
|
|
|
|
'author' => 'Brion Vibber',
|
|
|
|
'url' => 'http://www.mediawiki.org/wiki/Extension:Nuke'
|
2007-07-26 10:54:37 +00:00
|
|
|
);
|
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
$wgGroupPermissions['sysop']['nuke'] = true;
|
|
|
|
$wgAvailableRights[] = 'nuke';
|
|
|
|
|
|
|
|
function wfSetupNuke() {
|
2008-01-09 17:19:53 +00:00
|
|
|
wfLoadExtensionMessages( 'Nuke' );
|
|
|
|
|
2006-10-09 09:20:35 +00:00
|
|
|
$GLOBALS['wgSpecialPages']['Nuke'] = array(
|
2008-01-09 17:19:53 +00:00
|
|
|
/*class*/ 'SpecialPage',
|
2006-10-09 09:20:35 +00:00
|
|
|
/*name*/ 'Nuke',
|
|
|
|
/* permission */'nuke',
|
2008-01-09 17:19:53 +00:00
|
|
|
/*listed*/ true,
|
2006-10-09 09:20:35 +00:00
|
|
|
/*function*/ false,
|
|
|
|
/*file*/ false );
|
2005-09-18 09:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function wfSpecialNuke( $par = '' ) {
|
|
|
|
global $wgRequest;
|
|
|
|
$target = $wgRequest->getText( 'target', $par );
|
|
|
|
$form = new NukeForm( $target, $wgRequest );
|
|
|
|
$form->run();
|
|
|
|
}
|
|
|
|
|
|
|
|
class NukeForm {
|
|
|
|
function NukeForm( $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' );
|
|
|
|
}
|
|
|
|
}
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
function promptForm() {
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
$sk =& $wgUser->getSkin();
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
$nuke = Title::makeTitle( NS_SPECIAL, 'Nuke' );
|
2008-01-21 22:12:04 +00:00
|
|
|
$submit = wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-user' ) ) );
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2007-09-30 20:33:06 +00:00
|
|
|
$wgOut->addWikiText( wfMsgForContent('nuke-tools') );
|
2005-09-18 09:28:56 +00:00
|
|
|
$wgOut->addHTML( wfElement( 'form', array(
|
|
|
|
'action' => $nuke->getLocalURL( 'action=submit' ),
|
|
|
|
'method' => 'post' ),
|
|
|
|
null ) .
|
|
|
|
wfElement( 'input', array(
|
|
|
|
'type' => 'text',
|
|
|
|
'size' => 40,
|
|
|
|
'name' => 'target' ) ) .
|
|
|
|
"\n$submit\n" );
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
$wgOut->addHTML( "</form>" );
|
|
|
|
}
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
function listForm( $username, $reason ) {
|
|
|
|
global $wgUser, $wgOut, $wgLang;
|
|
|
|
|
|
|
|
$pages = $this->getNewPages( $username );
|
2008-01-21 22:12:04 +00:00
|
|
|
$escapedName = wfEscapeWikiText( $username );
|
2005-09-18 09:28:56 +00:00
|
|
|
if( count( $pages ) == 0 ) {
|
|
|
|
$wgOut->addWikiText( wfMsg( 'nuke-nopages', $escapedName ) );
|
|
|
|
return $this->promptForm();
|
|
|
|
}
|
|
|
|
$wgOut->addWikiText( wfMsg( 'nuke-list', $escapedName ) );
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
$nuke = Title::makeTitle( NS_SPECIAL, 'Nuke' );
|
2008-01-21 22:12:04 +00:00
|
|
|
$submit = wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-delete' ) ) );
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
$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 ) ) .
|
2008-01-22 10:22:01 +00:00
|
|
|
"</div><br />" .
|
2005-09-18 09:28:56 +00:00
|
|
|
$submit .
|
|
|
|
wfElement( 'input', array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'wpEditToken',
|
|
|
|
'value' => $wgUser->editToken() ) ) .
|
|
|
|
"\n<ul>\n" );
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
$sk =& $wgUser->getSkin();
|
|
|
|
foreach( $pages as $info ) {
|
|
|
|
list( $title, $edits ) = $info;
|
|
|
|
$wgOut->addHTML( '<li>' .
|
|
|
|
wfElement( 'input', array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'name' => "pages[]",
|
|
|
|
'value' => $title->getPrefixedDbKey(),
|
|
|
|
'checked' => 'checked' ) ) .
|
|
|
|
' ' .
|
|
|
|
$sk->makeKnownLinkObj( $title ) .
|
|
|
|
' (' .
|
2008-01-21 22:12:04 +00:00
|
|
|
$sk->makeKnownLinkObj( $title, wfMsgExt( 'nchanges', array( 'parsemag' ), $wgLang->formatNum( $edits ) ), 'action=history' ) .
|
2005-09-18 09:28:56 +00:00
|
|
|
")</li>\n" );
|
|
|
|
}
|
|
|
|
$wgOut->addHTML( "</ul>\n$submit</form>" );
|
|
|
|
}
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
function getNewPages( $username ) {
|
|
|
|
$fname = 'NukeForm::getNewPages';
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
$result = $dbr->select( array( 'recentchanges', 'revision' ),
|
|
|
|
array( 'rc_namespace', 'rc_title', 'rc_timestamp', 'COUNT(rev_id) AS edits' ),
|
|
|
|
array(
|
|
|
|
'rc_user_text' => $username,
|
|
|
|
'rc_new' => 1,
|
|
|
|
'rc_cur_id=rev_page' ),
|
|
|
|
$fname,
|
|
|
|
array(
|
|
|
|
'ORDER BY' => 'rc_timestamp DESC',
|
2007-04-19 14:50:14 +00:00
|
|
|
'GROUP BY' => $dbr->implicitGroupby() ? 'rev_page' : 'rc_namespace, rc_title, rc_timestamp'
|
|
|
|
) );
|
2005-09-18 09:28:56 +00:00
|
|
|
$pages = array();
|
|
|
|
while( $row = $dbr->fetchObject( $result ) ) {
|
|
|
|
$pages[] = array( Title::makeTitle( $row->rc_namespace, $row->rc_title ), $row->edits );
|
|
|
|
}
|
|
|
|
$dbr->freeResult( $result );
|
|
|
|
return $pages;
|
|
|
|
}
|
2008-01-09 17:19:53 +00:00
|
|
|
|
2005-09-18 09:28:56 +00:00
|
|
|
function doDelete( $pages, $reason ) {
|
|
|
|
foreach( $pages as $page ) {
|
|
|
|
$title = Title::newFromUrl( $page );
|
|
|
|
$article = new Article( $title );
|
|
|
|
$article->doDelete( $reason );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|