(bug 10323) Special:Undelete should have "inverse selection" button
[mediawiki.git] / includes / specials / SpecialNuke.php
blobff17a578038afe1bd1c50c8c1bb4fd6cb314f501
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
6 * @author Brion Vibber
7 * @copyright Copyright © 2005-2008, Brion Vibber
8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
9 */
11 /**
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();
25 return;
28 $this->setHeaders();
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' ) );
36 if( $posted ) {
37 $pages = $wgRequest->getArray( 'pages' );
38 if( $pages ) {
39 return $this->doDelete( $pages, $reason );
42 if( $target != '' ) {
43 $this->listForm( $target, $reason );
44 } else {
45 $this->promptForm();
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' ),
60 'method' => 'post' ),
61 null ) .
62 Xml::element( 'input', array(
63 'type' => 'text',
64 'size' => 40,
65 'name' => 'target' ) ) .
66 "\n$submit\n" );
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' ),
87 'method' => 'post' ),
88 null ) .
89 "\n<div>" .
90 wfMsgHtml( 'deletecomment' ) . ' ' .
91 Xml::element( 'input', array(
92 'name' => 'wpReason',
93 'value' => $reason,
94 'size' => 60 ) ) .
95 "</div><br />" .
96 $submit .
97 Xml::element( 'input', array(
98 'type' => 'hidden',
99 'name' => 'wpEditToken',
100 'value' => $wgUser->editToken() ) ) .
101 "\n<ul>\n" );
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',
112 'name' => "pages[]",
113 'value' => $title->getPrefixedDbKey(),
114 'checked' => 'checked' ) ) .
115 '&nbsp;' .
116 ( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .
117 $sk->makeKnownLinkObj( $title ) .
118 '&nbsp;(' .
119 $sk->makeKnownLinkObj( $title, wfMsgExt( 'nchanges', array( 'parsemag' ), $wgLang->formatNum( $edits ) ), 'action=history' ) .
120 ")</li>\n" );
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' ),
129 array(
130 'rc_user_text' => $username,
131 '(rc_new = 1) OR (rc_log_type = "upload" AND rc_log_action = "upload")'
133 __METHOD__,
134 array(
135 'ORDER BY' => 'rc_timestamp DESC',
136 'GROUP BY' => 'rc_namespace, rc_title'
139 $pages = array();
140 while( $row = $result->fetchObject() ) {
141 $pages[] = array( Title::makeTitle( $row->rc_namespace, $row->rc_title ), $row->edits );
143 $result->free();
144 return $pages;
147 function doDelete( $pages, $reason ) {
148 foreach( $pages as $page ) {
149 $title = Title::newFromUrl( $page );
150 $file = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
151 if ( $file ) {
152 $oldimage = null; // Must be passed by reference
153 FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, false );
154 } else {
155 $article = new Article( $title );
156 $article->doDelete( $reason );