Index: trunk/extensions/Nuke/Nuke_body.php |
— | — | @@ -1,14 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -if( !defined( 'MEDIAWIKI' ) ) |
5 | | - die( 'Not an entry point.' ); |
6 | | - |
7 | 4 | class SpecialNuke extends SpecialPage { |
8 | | - function __construct() { |
| 5 | + |
| 6 | + public function __construct() { |
9 | 7 | parent::__construct( 'Nuke', 'nuke' ); |
10 | 8 | } |
11 | 9 | |
12 | | - function execute( $par ){ |
| 10 | + public function execute( $par ){ |
13 | 11 | global $wgUser, $wgRequest; |
14 | 12 | |
15 | 13 | if( !$this->userCanExecute( $wgUser ) ){ |
— | — | @@ -18,65 +16,94 @@ |
19 | 17 | |
20 | 18 | $this->setHeaders(); |
21 | 19 | $this->outputHeader(); |
| 20 | + |
| 21 | + if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
| 22 | + $target = $wgRequest->getText( 'target', $par ); |
| 23 | + |
| 24 | + // Normalise name |
| 25 | + if ( $target !== '' ) { |
| 26 | + $user = User::newFromName( $target ); |
| 27 | + if ( $user ) $target = $user->getName(); |
| 28 | + } |
22 | 29 | |
23 | | - $target = $wgRequest->getText( 'target', $par ); |
24 | | - |
25 | | - // Normalise name |
26 | | - if ( $target !== '' ) { |
27 | | - $user = User::newFromName( $target ); |
28 | | - if ( $user ) $target = $user->getName(); |
29 | | - } |
30 | | - |
31 | | - $reason = $wgRequest->getText( 'wpReason', |
32 | | - wfMsgForContent( 'nuke-defaultreason', $target ) ); |
33 | | - $posted = $wgRequest->wasPosted() && |
34 | | - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ); |
35 | | - if( $posted ) { |
36 | | - $pages = $wgRequest->getArray( 'pages' ); |
37 | | - if( $pages ) { |
38 | | - return $this->doDelete( $pages, $reason ); |
| 30 | + $reason = $wgRequest->getText( |
| 31 | + 'wpReason', |
| 32 | + wfMsgForContent( |
| 33 | + 'nuke-defaultreason', |
| 34 | + $target === '' ? wfMsg( 'nuke-multiplepeople' ) : $target |
| 35 | + ) |
| 36 | + ); |
| 37 | + |
| 38 | + if ( $wgRequest->getVal( 'action' ) == 'delete' ) { |
| 39 | + $pages = $wgRequest->getArray( 'pages' ); |
| 40 | + |
| 41 | + if( $pages ) { |
| 42 | + return $this->doDelete( $pages, $reason ); |
| 43 | + } |
39 | 44 | } |
| 45 | + else { |
| 46 | + $this->listForm( $target, $reason, $wgRequest->getInt( 'limit' ) ); |
| 47 | + } |
40 | 48 | } |
41 | | - if( $target != '' ) { |
42 | | - $this->listForm( $target, $reason ); |
43 | | - } else { |
| 49 | + else { |
44 | 50 | $this->promptForm(); |
45 | 51 | } |
46 | 52 | } |
47 | 53 | |
48 | 54 | /** |
49 | | - * Prompt for a username or IP address |
| 55 | + * Prompt for a username or IP address. |
50 | 56 | */ |
51 | | - function promptForm() { |
52 | | - global $wgOut; |
| 57 | + protected function promptForm() { |
| 58 | + global $wgOut, $wgUser; |
53 | 59 | |
54 | | - $input = Xml::input( 'target', 40 ); |
55 | | - $submit = Xml::submitButton( wfMsg( 'nuke-submit-user' ) ); |
56 | | - |
57 | 60 | $wgOut->addWikiMsg( 'nuke-tools' ); |
| 61 | + |
58 | 62 | $wgOut->addHTML( |
59 | | - Xml::openElement( 'form', array( |
60 | | - 'action' => $this->getTitle()->getLocalURL( 'action=submit' ), |
61 | | - 'method' => 'post' ) |
62 | | - ) . "$input\n$submit\n" |
| 63 | + Xml::openElement( |
| 64 | + 'form', |
| 65 | + array( |
| 66 | + 'action' => $this->getTitle()->getLocalURL( 'action=submit' ), |
| 67 | + 'method' => 'post' |
| 68 | + ) |
| 69 | + ) |
| 70 | + . '<table><tr>' |
| 71 | + . '<td>' . htmlspecialchars( wfMsg( 'nuke-userorip' ) ) . '</td>' |
| 72 | + . '<td>' . Xml::input( 'target', 40 ) . '</td>' |
| 73 | + . '</tr><tr>' |
| 74 | + . '<td>' . htmlspecialchars( wfMsg( 'nuke-maxpages' ) ) . '</td>' |
| 75 | + . '<td>' . Xml::input( 'limit', 7, '500' ) . '</td>' |
| 76 | + . '</tr><tr>' |
| 77 | + . '<td></td>' |
| 78 | + . '<td>' . Xml::submitButton( wfMsg( 'nuke-submit-user' ) ) . '</td>' |
| 79 | + .'</tr></table>' |
| 80 | + . Html::hidden( 'wpEditToken', $wgUser->editToken() ) |
| 81 | + . Xml::closeElement( 'form' ) |
63 | 82 | ); |
64 | | - |
65 | | - $wgOut->addHTML( "</form>" ); |
66 | 83 | } |
67 | 84 | |
68 | 85 | /** |
69 | | - * Display list of pages to delete |
| 86 | + * Display list of pages to delete. |
| 87 | + * |
| 88 | + * @param string $username |
| 89 | + * @param string $reason |
| 90 | + * @param integer $limit |
70 | 91 | */ |
71 | | - function listForm( $username, $reason ) { |
| 92 | + protected function listForm( $username, $reason, $limit ) { |
72 | 93 | global $wgUser, $wgOut, $wgLang; |
73 | 94 | |
74 | | - $pages = $this->getNewPages( $username ); |
| 95 | + $pages = $this->getNewPages( $username, $limit ); |
75 | 96 | |
76 | 97 | if( count( $pages ) == 0 ) { |
77 | 98 | $wgOut->addWikiMsg( 'nuke-nopages', $username ); |
78 | 99 | return $this->promptForm(); |
79 | 100 | } |
80 | | - $wgOut->addWikiMsg( 'nuke-list', $username ); |
| 101 | + |
| 102 | + if ( $username == '' ) { |
| 103 | + $wgOut->addWikiMsg( 'nuke-list-multiple' ); |
| 104 | + } |
| 105 | + else { |
| 106 | + $wgOut->addWikiMsg( 'nuke-list', $username ); |
| 107 | + } |
81 | 108 | |
82 | 109 | $nuke = $this->getTitle(); |
83 | 110 | |
— | — | @@ -131,7 +158,7 @@ |
132 | 159 | |
133 | 160 | $sk = $wgUser->getSkin(); |
134 | 161 | foreach( $pages as $info ) { |
135 | | - list( $title, $edits ) = $info; |
| 162 | + list( $title, $edits, $userName ) = $info; |
136 | 163 | $image = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false; |
137 | 164 | $thumb = $image && $image->exists() ? $image->transform( array( 'width' => 120, 'height' => 120 ), 0 ) : false; |
138 | 165 | |
— | — | @@ -145,9 +172,11 @@ |
146 | 173 | ( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) . |
147 | 174 | $sk->makeKnownLinkObj( $title ) . |
148 | 175 | ' (' . |
| 176 | + ( $userName ? wfMsgExt( 'nuke-editby', 'parseinline', $userName ) . ', ' : '' ) . |
149 | 177 | $sk->makeKnownLinkObj( $title, $changes, 'action=history' ) . |
150 | 178 | ")</li>\n" ); |
151 | 179 | } |
| 180 | + |
152 | 181 | $wgOut->addHTML( |
153 | 182 | "</ul>\n" . |
154 | 183 | Xml::submitButton( wfMsg( 'nuke-submit-delete' ) ) . |
— | — | @@ -155,29 +184,66 @@ |
156 | 185 | ); |
157 | 186 | } |
158 | 187 | |
159 | | - function getNewPages( $username ) { |
| 188 | + /** |
| 189 | + * Gets a list of new pages by the specified user or everyone when none is specified. |
| 190 | + * |
| 191 | + * @param string $username |
| 192 | + * @param integer $limit |
| 193 | + * |
| 194 | + * @return array |
| 195 | + */ |
| 196 | + protected function getNewPages( $username, $limit ) { |
160 | 197 | $dbr = wfGetDB( DB_SLAVE ); |
| 198 | + |
| 199 | + $what = array( |
| 200 | + 'rc_namespace', |
| 201 | + 'rc_title', |
| 202 | + 'rc_timestamp', |
| 203 | + 'COUNT(*) AS edits' |
| 204 | + ); |
| 205 | + |
| 206 | + $where = array( "(rc_new = 1) OR (rc_log_type = 'import' AND rc_log_action = 'upload')" ); |
| 207 | + |
| 208 | + if ( $username == '' ) { |
| 209 | + $what[] = 'rc_user_text'; |
| 210 | + } |
| 211 | + else { |
| 212 | + $where['rc_user_text'] = $username; |
| 213 | + } |
| 214 | + |
161 | 215 | $result = $dbr->select( 'recentchanges', |
162 | | - array( 'rc_namespace', 'rc_title', 'rc_timestamp', 'COUNT(*) AS edits' ), |
163 | | - array( |
164 | | - 'rc_user_text' => $username, |
165 | | - "(rc_new = 1) OR (rc_log_type = 'import' AND rc_log_action = 'upload')" |
166 | | - ), |
| 216 | + $what, |
| 217 | + $where, |
167 | 218 | __METHOD__, |
168 | 219 | array( |
169 | 220 | 'ORDER BY' => 'rc_timestamp DESC', |
170 | | - 'GROUP BY' => 'rc_namespace, rc_title' |
| 221 | + 'GROUP BY' => 'rc_namespace, rc_title', |
| 222 | + 'LIMIT' => $limit |
171 | 223 | ) |
172 | 224 | ); |
| 225 | + |
173 | 226 | $pages = array(); |
| 227 | + |
174 | 228 | foreach ( $result as $row ) { |
175 | | - $pages[] = array( Title::makeTitle( $row->rc_namespace, $row->rc_title ), $row->edits ); |
| 229 | + $pages[] = array( |
| 230 | + Title::makeTitle( $row->rc_namespace, $row->rc_title ), |
| 231 | + $row->edits, |
| 232 | + $username == '' ? $row->rc_user_text : false |
| 233 | + ); |
176 | 234 | } |
| 235 | + |
177 | 236 | $dbr->freeResult( $result ); |
| 237 | + |
178 | 238 | return $pages; |
179 | 239 | } |
180 | 240 | |
181 | | - function doDelete( $pages, $reason ) { |
| 241 | + /** |
| 242 | + * Does the actual deletion of the pages. |
| 243 | + * |
| 244 | + * @param array $pages The pages to delete |
| 245 | + * @param string $reason |
| 246 | + */ |
| 247 | + protected function doDelete( array $pages, $reason ) { |
182 | 248 | foreach( $pages as $page ) { |
183 | 249 | $title = Title::newFromURL( $page ); |
184 | 250 | $file = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false; |
Index: trunk/extensions/Nuke/Nuke.i18n.php |
— | — | @@ -18,13 +18,19 @@ |
19 | 19 | 'nuke-nopages' => "No new pages by [[Special:Contributions/$1|$1]] in recent changes.", |
20 | 20 | 'nuke-list' => "The following pages were recently created by [[Special:Contributions/$1|$1]]; |
21 | 21 | put in a comment and hit the button to delete them.", |
| 22 | + 'nuke-list-multiple' => 'The following pages were recently created; |
| 23 | +put in a comment and hit the button to delete them.', |
22 | 24 | 'nuke-defaultreason' => "Mass deletion of pages added by $1", |
23 | 25 | 'nuke-tools' => 'This tool allows for mass deletions of pages recently added by a given user or an IP address. |
24 | | -Input the username or IP address to get a list of pages to delete.', |
| 26 | +Input the username or IP address to get a list of pages to delete, or leave blank for all users.', |
25 | 27 | 'nuke-submit-user' => 'Go', |
26 | 28 | 'nuke-submit-delete' => 'Delete selected', |
27 | 29 | 'right-nuke' => 'Mass delete pages', |
28 | 30 | 'nuke-select' => 'Select: $1', |
| 31 | + 'nuke-userorip' => 'User, ip or blank: ', |
| 32 | + 'nuke-maxpages' => 'Maximun amount of pages: ', |
| 33 | + 'nuke-multiplepeople'=> 'multiple people', |
| 34 | + 'nuke-editby' => 'Created by [[Special:Contributions/$1|$1]]' |
29 | 35 | ); |
30 | 36 | |
31 | 37 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Nuke/Nuke.php |
— | — | @@ -1,8 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -if( !defined( 'MEDIAWIKI' ) ) |
| 4 | +if( !defined( 'MEDIAWIKI' ) ) { |
5 | 5 | die( 'Not an entry point.' ); |
| 6 | +} |
6 | 7 | |
| 8 | +define( 'Nuke_VERSION', '1.1' ); |
| 9 | + |
7 | 10 | $dir = dirname(__FILE__) . '/'; |
8 | 11 | |
9 | 12 | $wgExtensionMessagesFiles['Nuke'] = $dir . 'Nuke.i18n.php'; |
— | — | @@ -13,7 +16,8 @@ |
14 | 17 | 'name' => 'Nuke', |
15 | 18 | 'descriptionmsg' => 'nuke-desc', |
16 | 19 | 'author' => 'Brion Vibber', |
17 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:Nuke' |
| 20 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Nuke', |
| 21 | + 'version' => Nuke_VERSION, |
18 | 22 | ); |
19 | 23 | |
20 | 24 | $wgGroupPermissions['sysop']['nuke'] = true; |
Index: trunk/extensions/Nuke/SpecialNuke.php |
— | — | @@ -1,3 +1,2 @@ |
2 | 2 | <?php |
3 | 3 | require_once( dirname( __FILE__ ) . '/Nuke.php' ); |
4 | | - |