7 * @copyright Copyright © 2005-2008, Brion Vibber
8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
12 * implements Special:Nuke
15 class SpecialNuke
extends SpecialPage
{
16 function __construct() {
17 parent
::__construct( 'Nuke', 'nuke' );
20 function execute( $par ){
21 global $wgUser, $wgRequest;
23 if( !$this->userCanExecute( $wgUser ) ){
24 $this->displayRestrictionError();
29 $this->outputHeader();
31 $target = $wgRequest->getText( 'target', $par );
32 $reason = $wgRequest->getText( 'wpReason',
33 wfMsgForContent( 'nuke-defaultreason', $target ) );
34 $posted = $wgRequest->wasPosted() &&
35 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
37 $pages = $wgRequest->getArray( 'pages' );
39 return $this->doDelete( $pages, $reason );
43 $this->listForm( $target, $reason );
49 function promptForm() {
50 global $wgUser, $wgOut;
52 $sk = $wgUser->getSkin();
54 $nuke = $this->getTitle();
55 $submit = Xml
::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-user' ) ) );
57 $wgOut->addWikiMsg( 'nuke-tools' );
58 $wgOut->addHTML( Xml
::element( 'form', array(
59 'action' => $nuke->getLocalURL( 'action=submit' ),
62 Xml
::element( 'input', array(
65 'name' => 'target' ) ) .
68 $wgOut->addHTML( "</form>" );
71 function listForm( $username, $reason ) {
72 global $wgUser, $wgOut, $wgLang;
74 $pages = $this->getNewPages( $username );
75 $escapedName = wfEscapeWikiText( $username );
76 if( count( $pages ) == 0 ) {
77 $wgOut->addWikiMsg( 'nuke-nopages', $escapedName );
78 return $this->promptForm();
80 $wgOut->addWikiMsg( 'nuke-list', $escapedName );
82 $nuke = $this->getTitle();
83 $submit = Xml
::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'nuke-submit-delete' ) ) );
85 $wgOut->addHTML( Xml
::element( 'form', array(
86 'action' => $nuke->getLocalURL( 'action=delete' ),
90 wfMsgHtml( 'deletecomment' ) . ' ' .
91 Xml
::element( 'input', array(
97 Xml
::element( 'input', array(
99 'name' => 'wpEditToken',
100 'value' => $wgUser->editToken() ) ) .
103 $sk = $wgUser->getSkin();
104 foreach( $pages as $info ) {
105 list( $title, $edits ) = $info;
106 $image = $title->getNamespace() == NS_IMAGE ?
wfLocalFile( $title ) : false;
107 $thumb = $image && $image->exists() ?
$image->getThumbnail( 120, 120 ) : false;
109 $wgOut->addHTML( '<li>' .
110 Xml
::element( 'input', array(
111 'type' => 'checkbox',
113 'value' => $title->getPrefixedDbKey(),
114 'checked' => 'checked' ) ) .
116 ( $thumb ?
$thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .
117 $sk->makeKnownLinkObj( $title ) .
119 $sk->makeKnownLinkObj( $title, wfMsgExt( 'nchanges', array( 'parsemag' ), $wgLang->formatNum( $edits ) ), 'action=history' ) .
122 $wgOut->addHTML( "</ul>\n$submit</form>" );
125 function getNewPages( $username ) {
126 $dbr = wfGetDB( DB_SLAVE
);
127 $result = $dbr->select( 'recentchanges',
128 array( 'rc_namespace', 'rc_title', 'rc_timestamp', 'COUNT(*) AS edits' ),
130 'rc_user_text' => $username,
131 '(rc_new = 1) OR (rc_log_type = "upload" AND rc_log_action = "upload")'
135 'ORDER BY' => 'rc_timestamp DESC',
136 'GROUP BY' => 'rc_namespace, rc_title'
140 while( $row = $result->fetchObject() ) {
141 $pages[] = array( Title
::makeTitle( $row->rc_namespace
, $row->rc_title
), $row->edits
);
147 function doDelete( $pages, $reason ) {
148 foreach( $pages as $page ) {
149 $title = Title
::newFromUrl( $page );
150 $file = $title->getNamespace() == NS_IMAGE ?
wfLocalFile( $title ) : false;
152 $oldimage = null; // Must be passed by reference
153 FileDeleteForm
::doDelete( $title, $file, $oldimage, $reason, false );
155 $article = new Article( $title );
156 $article->doDelete( $reason );