mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Nuke
synced 2024-11-15 03:35:39 +00:00
Moved Special:Nuke page class to SpecialNuke_body.php and made it extends SpecialPage, this allows to not load messages at each request
This commit is contained in:
parent
a90c9db429
commit
d82d4feb4d
155
SpecialNuke.php
155
SpecialNuke.php
|
@ -3,13 +3,14 @@
|
|||
if( !defined( 'MEDIAWIKI' ) )
|
||||
die( 'Not an entry point.' );
|
||||
|
||||
$wgExtensionFunctions[] = 'wfSetupNuke';
|
||||
$wgExtensionMessagesFiles['Nuke'] = dirname(__FILE__) . '/SpecialNuke.i18n.php';
|
||||
$dir = dirname(__FILE__) . '/';
|
||||
|
||||
$wgExtensionMessagesFiles['Nuke'] = $dir . 'SpecialNuke.i18n.php';
|
||||
|
||||
$wgExtensionCredits['specialpage'][] = array(
|
||||
'name' => 'Nuke',
|
||||
'svn-date' => '$LastChangedDate$',
|
||||
'svn-revision' => '$LastChangedRevision$',
|
||||
'svn-date' => '$LastChangedDate$',
|
||||
'svn-revision' => '$LastChangedRevision$',
|
||||
'description' => 'Gives sysops the ability to mass delete pages',
|
||||
'descriptionmsg' => 'nuke-desc',
|
||||
'author' => 'Brion Vibber',
|
||||
|
@ -19,147 +20,5 @@ $wgExtensionCredits['specialpage'][] = array(
|
|||
$wgGroupPermissions['sysop']['nuke'] = true;
|
||||
$wgAvailableRights[] = 'nuke';
|
||||
|
||||
function wfSetupNuke() {
|
||||
wfLoadExtensionMessages( 'Nuke' );
|
||||
|
||||
$GLOBALS['wgSpecialPages']['Nuke'] = array(
|
||||
/*class*/ 'SpecialPage',
|
||||
/*name*/ 'Nuke',
|
||||
/* permission */'nuke',
|
||||
/*listed*/ true,
|
||||
/*function*/ false,
|
||||
/*file*/ false );
|
||||
}
|
||||
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
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, 'Nuke' );
|
||||
$submit = wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-user' ) ) );
|
||||
|
||||
$wgOut->addWikiText( wfMsg( 'nuke-tools' ) );
|
||||
$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" );
|
||||
|
||||
$wgOut->addHTML( "</form>" );
|
||||
}
|
||||
|
||||
function listForm( $username, $reason ) {
|
||||
global $wgUser, $wgOut, $wgLang;
|
||||
|
||||
$pages = $this->getNewPages( $username );
|
||||
$escapedName = wfEscapeWikiText( $username );
|
||||
if( count( $pages ) == 0 ) {
|
||||
$wgOut->addWikiText( wfMsg( 'nuke-nopages', $escapedName ) );
|
||||
return $this->promptForm();
|
||||
}
|
||||
$wgOut->addWikiText( wfMsg( 'nuke-list', $escapedName ) );
|
||||
|
||||
$nuke = Title::makeTitle( NS_SPECIAL, 'Nuke' );
|
||||
$submit = wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-delete' ) ) );
|
||||
|
||||
$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><br />" .
|
||||
$submit .
|
||||
wfElement( 'input', array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'wpEditToken',
|
||||
'value' => $wgUser->editToken() ) ) .
|
||||
"\n<ul>\n" );
|
||||
|
||||
$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 ) .
|
||||
' (' .
|
||||
$sk->makeKnownLinkObj( $title, wfMsgExt( 'nchanges', array( 'parsemag' ), $wgLang->formatNum( $edits ) ), 'action=history' ) .
|
||||
")</li>\n" );
|
||||
}
|
||||
$wgOut->addHTML( "</ul>\n$submit</form>" );
|
||||
}
|
||||
|
||||
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',
|
||||
'GROUP BY' => $dbr->implicitGroupby() ? 'rev_page' : 'rc_namespace, rc_title, rc_timestamp'
|
||||
) );
|
||||
$pages = array();
|
||||
while( $row = $dbr->fetchObject( $result ) ) {
|
||||
$pages[] = array( Title::makeTitle( $row->rc_namespace, $row->rc_title ), $row->edits );
|
||||
}
|
||||
$dbr->freeResult( $result );
|
||||
return $pages;
|
||||
}
|
||||
|
||||
function doDelete( $pages, $reason ) {
|
||||
foreach( $pages as $page ) {
|
||||
$title = Title::newFromUrl( $page );
|
||||
$article = new Article( $title );
|
||||
$article->doDelete( $reason );
|
||||
}
|
||||
}
|
||||
}
|
||||
$wgAutoloadClasses['SpecialNuke'] = $dir . 'SpecialNuke_body.php';
|
||||
$wgSpecialPages['Nuke'] = 'SpecialNuke';
|
||||
|
|
140
SpecialNuke_body.php
Normal file
140
SpecialNuke_body.php
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
if( !defined( 'MEDIAWIKI' ) )
|
||||
die( 'Not an entry point.' );
|
||||
|
||||
class SpecialNuke extends SpecialPage {
|
||||
function __construct() {
|
||||
wfLoadExtensionMessages( 'Nuke' );
|
||||
parent::__construct( 'Nuke', 'nuke' );
|
||||
}
|
||||
|
||||
function execute( $par ){
|
||||
global $wgUser, $wgRequest;
|
||||
|
||||
if( !$this->userCanExecute( $wgUser ) ){
|
||||
$this->displayRestrictionError();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setHeaders();
|
||||
$this->outputHeader();
|
||||
|
||||
$target = $wgRequest->getText( 'target', $par );
|
||||
$reason = $wgRequest->getText( 'wpReason',
|
||||
wfMsgForContent( 'nuke-defaultreason', $target ) );
|
||||
$posted = $wgRequest->wasPosted() &&
|
||||
$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
|
||||
if( $posted ) {
|
||||
$pages = $wgRequest->getArray( 'pages' );
|
||||
if( $pages ) {
|
||||
return $this->doDelete( $pages, $reason );
|
||||
}
|
||||
}
|
||||
if( $target != '' ) {
|
||||
$this->listForm( $target, $reason );
|
||||
} else {
|
||||
$this->promptForm();
|
||||
}
|
||||
}
|
||||
|
||||
function promptForm() {
|
||||
global $wgUser, $wgOut;
|
||||
$sk =& $wgUser->getSkin();
|
||||
|
||||
$nuke = Title::makeTitle( NS_SPECIAL, 'Nuke' );
|
||||
$submit = Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-user' ) ) );
|
||||
|
||||
$wgOut->addWikiText( wfMsg( 'nuke-tools' ) );
|
||||
$wgOut->addHTML( Xml::element( 'form', array(
|
||||
'action' => $nuke->getLocalURL( 'action=submit' ),
|
||||
'method' => 'post' ),
|
||||
null ) .
|
||||
Xml::element( 'input', array(
|
||||
'type' => 'text',
|
||||
'size' => 40,
|
||||
'name' => 'target' ) ) .
|
||||
"\n$submit\n" );
|
||||
|
||||
$wgOut->addHTML( "</form>" );
|
||||
}
|
||||
|
||||
function listForm( $username, $reason ) {
|
||||
global $wgUser, $wgOut, $wgLang;
|
||||
|
||||
$pages = $this->getNewPages( $username );
|
||||
$escapedName = wfEscapeWikiText( $username );
|
||||
if( count( $pages ) == 0 ) {
|
||||
$wgOut->addWikiText( wfMsg( 'nuke-nopages', $escapedName ) );
|
||||
return $this->promptForm();
|
||||
}
|
||||
$wgOut->addWikiText( wfMsg( 'nuke-list', $escapedName ) );
|
||||
|
||||
$nuke = $this->getTitle();
|
||||
$submit = Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-delete' ) ) );
|
||||
|
||||
$wgOut->addHTML( Xml::element( 'form', array(
|
||||
'action' => $nuke->getLocalURL( 'action=delete' ),
|
||||
'method' => 'post' ),
|
||||
null ) .
|
||||
"\n<div>" .
|
||||
wfMsgHtml( 'deletecomment' ) . ': ' .
|
||||
Xml::element( 'input', array(
|
||||
'name' => 'wpReason',
|
||||
'value' => $reason,
|
||||
'size' => 60 ) ) .
|
||||
"</div><br />" .
|
||||
$submit .
|
||||
Xml::element( 'input', array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'wpEditToken',
|
||||
'value' => $wgUser->editToken() ) ) .
|
||||
"\n<ul>\n" );
|
||||
|
||||
$sk =& $wgUser->getSkin();
|
||||
foreach( $pages as $info ) {
|
||||
list( $title, $edits ) = $info;
|
||||
$wgOut->addHTML( '<li>' .
|
||||
Xml::element( 'input', array(
|
||||
'type' => 'checkbox',
|
||||
'name' => "pages[]",
|
||||
'value' => $title->getPrefixedDbKey(),
|
||||
'checked' => 'checked' ) ) .
|
||||
' ' .
|
||||
$sk->makeKnownLinkObj( $title ) .
|
||||
' (' .
|
||||
$sk->makeKnownLinkObj( $title, wfMsgExt( 'nchanges', array( 'parsemag' ), $wgLang->formatNum( $edits ) ), 'action=history' ) .
|
||||
")</li>\n" );
|
||||
}
|
||||
$wgOut->addHTML( "</ul>\n$submit</form>" );
|
||||
}
|
||||
|
||||
function getNewPages( $username ) {
|
||||
$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' ),
|
||||
__METHOD__,
|
||||
array(
|
||||
'ORDER BY' => 'rc_timestamp DESC',
|
||||
'GROUP BY' => $dbr->implicitGroupby() ? 'rev_page' : 'rc_namespace, rc_title, rc_timestamp'
|
||||
) );
|
||||
$pages = array();
|
||||
while( $row = $dbr->fetchObject( $result ) ) {
|
||||
$pages[] = array( Title::makeTitle( $row->rc_namespace, $row->rc_title ), $row->edits );
|
||||
}
|
||||
$dbr->freeResult( $result );
|
||||
return $pages;
|
||||
}
|
||||
|
||||
function doDelete( $pages, $reason ) {
|
||||
foreach( $pages as $page ) {
|
||||
$title = Title::newFromUrl( $page );
|
||||
$article = new Article( $title );
|
||||
$article->doDelete( $reason );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue