2008-05-09 18:53:09 +00:00
|
|
|
<?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 );
|
2009-01-12 18:23:47 +00:00
|
|
|
|
|
|
|
// Normalise name
|
|
|
|
if ( $target !== '' ) {
|
|
|
|
$user = User::newFromName( $target );
|
|
|
|
if ( $user ) $target = $user->getName();
|
|
|
|
}
|
|
|
|
|
2008-05-09 18:53:09 +00:00
|
|
|
$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() {
|
2009-01-12 18:23:47 +00:00
|
|
|
global $wgOut;
|
|
|
|
|
|
|
|
$input = Xml::input( 'target', 40 );
|
|
|
|
$submit = Xml::submitButton( wfMsg( 'nuke-submit-user' ) );
|
|
|
|
|
|
|
|
$wgOut->addWikiMsg( 'nuke-tools' );
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::openElement( 'form', array(
|
|
|
|
'action' => $this->getTitle()->getLocalURL( 'action=submit' ),
|
|
|
|
'method' => 'post' )
|
|
|
|
) . "$input\n$submit\n"
|
|
|
|
);
|
2008-05-09 18:53:09 +00:00
|
|
|
|
|
|
|
$wgOut->addHTML( "</form>" );
|
|
|
|
}
|
|
|
|
|
|
|
|
function listForm( $username, $reason ) {
|
|
|
|
global $wgUser, $wgOut, $wgLang;
|
|
|
|
|
|
|
|
$pages = $this->getNewPages( $username );
|
2009-01-12 18:23:47 +00:00
|
|
|
|
2008-05-09 18:53:09 +00:00
|
|
|
if( count( $pages ) == 0 ) {
|
2009-01-12 18:23:47 +00:00
|
|
|
$wgOut->addWikiMsg( 'nuke-nopages', $username );
|
2008-05-09 18:53:09 +00:00
|
|
|
return $this->promptForm();
|
|
|
|
}
|
2009-01-12 18:23:47 +00:00
|
|
|
$wgOut->addWikiMsg( 'nuke-list', $username );
|
2008-05-09 18:53:09 +00:00
|
|
|
|
|
|
|
$nuke = $this->getTitle();
|
2009-01-12 18:23:47 +00:00
|
|
|
$submit = Xml::submitButton( wfMsg( 'nuke-submit-delete' ) );
|
|
|
|
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::openElement( 'form', array(
|
|
|
|
'action' => $nuke->getLocalURL( 'action=delete' ),
|
|
|
|
'method' => 'post' )
|
|
|
|
) .
|
|
|
|
Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
|
|
|
|
Xml::inputLabel(
|
|
|
|
wfMsg( 'deletecomment' ), 'wpReason', 'wpReason', 60, $reason
|
|
|
|
) . '<br /><br />' .
|
|
|
|
Xml::submitButton( wfMsg( 'nuke-submit-delete' ) )
|
|
|
|
);
|
|
|
|
|
|
|
|
$wgOut->addHTML( '<ul>' );
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
2008-05-09 18:53:09 +00:00
|
|
|
foreach( $pages as $info ) {
|
|
|
|
list( $title, $edits ) = $info;
|
2008-06-01 19:34:23 +00:00
|
|
|
$image = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
|
2008-06-03 14:48:32 +00:00
|
|
|
$thumb = $image && $image->exists() ? $image->getThumbnail( 120, 120 ) : false;
|
2009-01-12 18:23:47 +00:00
|
|
|
|
|
|
|
$changes = wfMsgExt( 'nchanges', 'parsemag', $wgLang->formatNum( $edits ) );
|
2008-06-01 19:34:23 +00:00
|
|
|
|
2008-05-09 18:53:09 +00:00
|
|
|
$wgOut->addHTML( '<li>' .
|
2009-01-12 18:23:47 +00:00
|
|
|
Xml::check( 'pages[]', true,
|
|
|
|
array( 'value' => $title->getPrefixedDbKey() )
|
|
|
|
) .
|
2008-05-09 18:53:09 +00:00
|
|
|
' ' .
|
2008-06-01 19:34:23 +00:00
|
|
|
( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .
|
2008-05-09 18:53:09 +00:00
|
|
|
$sk->makeKnownLinkObj( $title ) .
|
|
|
|
' (' .
|
2009-01-12 18:23:47 +00:00
|
|
|
$sk->makeKnownLinkObj( $title, $changes, 'action=history' ) .
|
2008-05-09 18:53:09 +00:00
|
|
|
")</li>\n" );
|
|
|
|
}
|
2009-01-12 18:23:47 +00:00
|
|
|
$wgOut->addHTML(
|
|
|
|
"</ul>\n" .
|
|
|
|
Xml::submitButton( wfMsg( 'nuke-submit-delete' ) ) .
|
|
|
|
"</form>"
|
|
|
|
);
|
2008-05-09 18:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNewPages( $username ) {
|
2008-06-03 14:48:32 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-09-16 01:57:01 +00:00
|
|
|
$result = $dbr->select( 'recentchanges',
|
|
|
|
array( 'rc_namespace', 'rc_title', 'rc_timestamp', 'COUNT(*) AS edits' ),
|
2008-05-09 18:53:09 +00:00
|
|
|
array(
|
|
|
|
'rc_user_text' => $username,
|
2010-05-20 14:08:30 +00:00
|
|
|
"(rc_new = 1) OR (rc_log_type = 'upload' AND rc_log_action = 'upload')"
|
2008-09-16 01:57:01 +00:00
|
|
|
),
|
2008-05-09 18:53:09 +00:00
|
|
|
__METHOD__,
|
|
|
|
array(
|
|
|
|
'ORDER BY' => 'rc_timestamp DESC',
|
2008-09-16 01:57:01 +00:00
|
|
|
'GROUP BY' => 'rc_namespace, rc_title'
|
|
|
|
)
|
|
|
|
);
|
2008-05-09 18:53:09 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function doDelete( $pages, $reason ) {
|
|
|
|
foreach( $pages as $page ) {
|
2010-02-13 23:58:30 +00:00
|
|
|
$title = Title::newFromURL( $page );
|
2008-06-01 19:34:23 +00:00
|
|
|
$file = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
|
|
|
|
if ( $file ) {
|
|
|
|
$oldimage = null; // Must be passed by reference
|
|
|
|
FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, false );
|
|
|
|
} else {
|
|
|
|
$article = new Article( $title );
|
|
|
|
$article->doDelete( $reason );
|
|
|
|
}
|
2008-05-09 18:53:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|