r82136 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82135‎ | r82136 | r82137 >
Date:20:21, 14 February 2011
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
Added a changable limit and the option to not filter the recent changes on a single user
Modified paths:
  • /trunk/extensions/Nuke/Nuke.i18n.php (modified) (history)
  • /trunk/extensions/Nuke/Nuke.php (modified) (history)
  • /trunk/extensions/Nuke/Nuke_body.php (modified) (history)
  • /trunk/extensions/Nuke/SpecialNuke.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Nuke/Nuke_body.php
@@ -1,14 +1,12 @@
22 <?php
33
4 -if( !defined( 'MEDIAWIKI' ) )
5 - die( 'Not an entry point.' );
6 -
74 class SpecialNuke extends SpecialPage {
8 - function __construct() {
 5+
 6+ public function __construct() {
97 parent::__construct( 'Nuke', 'nuke' );
108 }
119
12 - function execute( $par ){
 10+ public function execute( $par ){
1311 global $wgUser, $wgRequest;
1412
1513 if( !$this->userCanExecute( $wgUser ) ){
@@ -18,65 +16,94 @@
1917
2018 $this->setHeaders();
2119 $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+ }
2229
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+ }
3944 }
 45+ else {
 46+ $this->listForm( $target, $reason, $wgRequest->getInt( 'limit' ) );
 47+ }
4048 }
41 - if( $target != '' ) {
42 - $this->listForm( $target, $reason );
43 - } else {
 49+ else {
4450 $this->promptForm();
4551 }
4652 }
4753
4854 /**
49 - * Prompt for a username or IP address
 55+ * Prompt for a username or IP address.
5056 */
51 - function promptForm() {
52 - global $wgOut;
 57+ protected function promptForm() {
 58+ global $wgOut, $wgUser;
5359
54 - $input = Xml::input( 'target', 40 );
55 - $submit = Xml::submitButton( wfMsg( 'nuke-submit-user' ) );
56 -
5760 $wgOut->addWikiMsg( 'nuke-tools' );
 61+
5862 $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' )
6382 );
64 -
65 - $wgOut->addHTML( "</form>" );
6683 }
6784
6885 /**
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
7091 */
71 - function listForm( $username, $reason ) {
 92+ protected function listForm( $username, $reason, $limit ) {
7293 global $wgUser, $wgOut, $wgLang;
7394
74 - $pages = $this->getNewPages( $username );
 95+ $pages = $this->getNewPages( $username, $limit );
7596
7697 if( count( $pages ) == 0 ) {
7798 $wgOut->addWikiMsg( 'nuke-nopages', $username );
7899 return $this->promptForm();
79100 }
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+ }
81108
82109 $nuke = $this->getTitle();
83110
@@ -131,7 +158,7 @@
132159
133160 $sk = $wgUser->getSkin();
134161 foreach( $pages as $info ) {
135 - list( $title, $edits ) = $info;
 162+ list( $title, $edits, $userName ) = $info;
136163 $image = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
137164 $thumb = $image && $image->exists() ? $image->transform( array( 'width' => 120, 'height' => 120 ), 0 ) : false;
138165
@@ -145,9 +172,11 @@
146173 ( $thumb ? $thumb->toHtml( array( 'desc-link' => true ) ) : '' ) .
147174 $sk->makeKnownLinkObj( $title ) .
148175 '&#160;(' .
 176+ ( $userName ? wfMsgExt( 'nuke-editby', 'parseinline', $userName ) . ',&#160;' : '' ) .
149177 $sk->makeKnownLinkObj( $title, $changes, 'action=history' ) .
150178 ")</li>\n" );
151179 }
 180+
152181 $wgOut->addHTML(
153182 "</ul>\n" .
154183 Xml::submitButton( wfMsg( 'nuke-submit-delete' ) ) .
@@ -155,29 +184,66 @@
156185 );
157186 }
158187
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 ) {
160197 $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+
161215 $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,
167218 __METHOD__,
168219 array(
169220 'ORDER BY' => 'rc_timestamp DESC',
170 - 'GROUP BY' => 'rc_namespace, rc_title'
 221+ 'GROUP BY' => 'rc_namespace, rc_title',
 222+ 'LIMIT' => $limit
171223 )
172224 );
 225+
173226 $pages = array();
 227+
174228 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+ );
176234 }
 235+
177236 $dbr->freeResult( $result );
 237+
178238 return $pages;
179239 }
180240
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 ) {
182248 foreach( $pages as $page ) {
183249 $title = Title::newFromURL( $page );
184250 $file = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
Index: trunk/extensions/Nuke/Nuke.i18n.php
@@ -18,13 +18,19 @@
1919 'nuke-nopages' => "No new pages by [[Special:Contributions/$1|$1]] in recent changes.",
2020 'nuke-list' => "The following pages were recently created by [[Special:Contributions/$1|$1]];
2121 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.',
2224 'nuke-defaultreason' => "Mass deletion of pages added by $1",
2325 '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.',
2527 'nuke-submit-user' => 'Go',
2628 'nuke-submit-delete' => 'Delete selected',
2729 'right-nuke' => 'Mass delete pages',
2830 '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]]'
2935 );
3036
3137 /** Message documentation (Message documentation)
Index: trunk/extensions/Nuke/Nuke.php
@@ -1,8 +1,11 @@
22 <?php
33
4 -if( !defined( 'MEDIAWIKI' ) )
 4+if( !defined( 'MEDIAWIKI' ) ) {
55 die( 'Not an entry point.' );
 6+}
67
 8+define( 'Nuke_VERSION', '1.1' );
 9+
710 $dir = dirname(__FILE__) . '/';
811
912 $wgExtensionMessagesFiles['Nuke'] = $dir . 'Nuke.i18n.php';
@@ -13,7 +16,8 @@
1417 'name' => 'Nuke',
1518 'descriptionmsg' => 'nuke-desc',
1619 '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,
1822 );
1923
2024 $wgGroupPermissions['sysop']['nuke'] = true;
Index: trunk/extensions/Nuke/SpecialNuke.php
@@ -1,3 +1,2 @@
22 <?php
33 require_once( dirname( __FILE__ ) . '/Nuke.php' );
4 -

Follow-up revisions

RevisionCommit summaryAuthorDate
r82147Consistency tweaks for r82136raymond21:28, 14 February 2011
r82167fix typo in r82136raymond13:20, 15 February 2011
r100182Follow up to r82136;jeroendedauw22:46, 18 October 2011

Comments

#Comment by 😂 (talk | contribs)   21:38, 14 February 2011

Is there any reason for introducing Nuke_VERSION? Why not just put the 1.1 in the $wgExtensionCredits.

#Comment by Jeroen De Dauw (talk | contribs)   21:58, 14 February 2011

It allows other extensions to easily check if a certain version of this one is installed. Not a huge deal, but then again, why not do it like this?

#Comment by 😂 (talk | contribs)   22:03, 14 February 2011

Why does another extension need to check Nuke's version?

#Comment by Jeroen De Dauw (talk | contribs)   22:11, 14 February 2011

Before this turns in to an endless debate as usual: I don't think it makes any real difference, and think it's rather pointless to discuss further. If this is bad in any way, please change. If it's not, just let it be and don't demand I make a mathematical proof of the universe making sense :p

#Comment by 😂 (talk | contribs)   22:25, 14 February 2011

Class constants are at least nicer than global-scoped defines.

#Comment by MaxSem (talk | contribs)   17:14, 5 October 2011

This revision broke $par handling: previously, upon visiting e.g. Special:Nuke/Jeroen De Dauw we saw a confirmatgion screen, now only username promt is displayed.

Status & tagging log