r48883 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48882‎ | r48883 | r48884 >
Date:15:41, 26 March 2009
Author:ashley
Status:deferred
Tags:
Comment:
RefreshSpecial:
*general cleanup
*check for database lock/user's block status in addition to the 'refreshspecial' user right
*renamed a couple functions per coding standards
*removed an unused function + associated message
*tweak Finnish special page alias
*move JS into its own file (no, it still doesn't work as it probably was intended to, but...)
*bump version number and add myself to authors
*spacing
Modified paths:
  • /trunk/extensions/RefreshSpecial/RefreshSpecial.alias.php (modified) (history)
  • /trunk/extensions/RefreshSpecial/RefreshSpecial.body.php (modified) (history)
  • /trunk/extensions/RefreshSpecial/RefreshSpecial.i18n.php (modified) (history)
  • /trunk/extensions/RefreshSpecial/RefreshSpecial.js (added) (history)
  • /trunk/extensions/RefreshSpecial/RefreshSpecial.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RefreshSpecial/RefreshSpecial.body.php
@@ -3,8 +3,8 @@
44 * Protect against register_globals vulnerabilities.
55 * This line must be present before any global variable is referenced.
66 */
7 -if ( ! defined( 'MEDIAWIKI' ) )
8 - die();
 7+if ( !defined( 'MEDIAWIKI' ) )
 8+ die( "This is not a valid entry point.\n" );
99
1010 require_once("QueryPage.php"); //sigh, this line has to be there so that the extension works
1111
@@ -25,15 +25,28 @@
2626 public function execute( $par ) {
2727 global $wgOut, $wgUser, $wgRequest;
2828
29 - wfLoadExtensionMessages('RefreshSpecial');
 29+ wfLoadExtensionMessages( 'RefreshSpecial' );
3030
31 - $wgOut->setPageTitle( wfMsg('refreshspecial-title') );
 31+ $wgOut->setPageTitle( wfMsg( 'refreshspecial-title' ) );
3232
33 - if( !$wgUser->isAllowed('refreshspecial') ) {
 33+ # If the user doesn't have the required permission, display an error
 34+ if( !$wgUser->isAllowed( 'refreshspecial' ) ) {
3435 $wgOut->permissionRequired( 'refreshspecial' );
3536 return;
3637 }
3738
 39+ # Show a message if the database is in read-only mode
 40+ if ( wfReadOnly() ) {
 41+ $wgOut->readOnlyPage();
 42+ return;
 43+ }
 44+
 45+ # If user is blocked, s/he doesn't need to access this page
 46+ if ( $wgUser->isBlocked() ) {
 47+ $wgOut->blockedPage();
 48+ return;
 49+ }
 50+
3851 $cSF = new RefreshSpecialForm();
3952
4053 $action = $wgRequest->getVal( 'action' );
@@ -42,10 +55,10 @@
4356 } else if( 'failure' == $action ) {
4457 $cSF->showForm( wfMsg('refreshspecial-fail') );
4558 } else if( $wgRequest->wasPosted() && 'submit' == $action &&
46 - $wgUser->matchEditToken( $wgRequest->getVal('wpEditToken') ) ) {
 59+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
4760 $cSF->doSubmit();
4861 } else {
49 - $cSF->showForm('');
 62+ $cSF->showForm( '' );
5063 }
5164 }
5265 }
@@ -63,11 +76,11 @@
6477 * @param $err string Error message if there was an error, otherwise null
6578 */
6679 function showForm( $err ) {
67 - global $wgOut, $wgUser, $wgRequest, $wgQueryPages;
 80+ global $wgOut, $wgUser, $wgRequest, $wgScriptPath, $wgQueryPages;
6881
6982 $token = htmlspecialchars( $wgUser->editToken() );
7083 $titleObj = SpecialPage::getTitleFor( 'RefreshSpecial' );
71 - $action = $titleObj->escapeLocalURL( "action=submit" );
 84+ $action = $titleObj->escapeLocalURL( 'action=submit' );
7285
7386 if ( '' != $err ) {
7487 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
@@ -76,9 +89,11 @@
7790
7891 $wgOut->addWikiMsg( 'refreshspecial-help' );
7992
80 - ( 'submit' == $wgRequest->getVal( 'action' ) ) ? $scLink = htmlspecialchars($this->mLink) : $scLink = '';
 93+ ( 'submit' == $wgRequest->getVal( 'action' ) ) ? $scLink = htmlspecialchars( $this->mLink ) : $scLink = '';
8194
82 - $wgOut->addHTML("<form name=\"RefreshSpecial\" method=\"post\" action=\"{$action}\"><ul>");
 95+ $wgOut->addScriptFile( $wgScriptPath . '/extensions/RefreshSpecial/RefreshSpecial.js' );
 96+ $wgOut->addHTML( "<form name=\"RefreshSpecial\" method=\"post\" action=\"{$action}\">
 97+ <ul>\n" );
8398
8499 /**
85100 * List pages right here
@@ -88,48 +103,38 @@
89104 * that brings up an interesting question - do we need that limit or not?
90105 */
91106 foreach ( $wgQueryPages as $page ) {
92 - @list( $class, $special, $limit ) = $page;
 107+ @list( $class, $special, $limit ) = $page;
93108
94 - $specialObj = SpecialPage::getPage( $special );
95 - if ( !$specialObj ) {
96 - $wgOut->addWikiText( wfMsg('refreshspecial-no-page') . " $special\n" );
97 - exit;
98 - }
99 - $file = $specialObj->getFile();
100 - if ( $file ) {
101 - require_once( $file );
102 - }
103 - $queryPage = new $class;
104 - $checked = '';
 109+ $specialObj = SpecialPage::getPage( $special );
 110+ if ( !$specialObj ) {
 111+ $wgOut->addWikiText( wfMsg( 'refreshspecial-no-page' ) . " $special\n" );
 112+ exit;
 113+ }
 114+ $file = $specialObj->getFile();
 115+ if ( $file ) {
 116+ require_once( $file );
 117+ }
 118+ $queryPage = new $class;
 119+ $checked = '';
105120 if ( $queryPage->isExpensive() ) {
106 - $checked = "checked=\"checked\"";
107 - $wgOut->addHTML("<li>
108 - <input type=\"checkbox\" name=\"wpSpecial[]\" value=\"$special\" $checked />
 121+ $checked = 'checked="checked"';
 122+ $wgOut->addHTML("\t\t\t\t\t<li>
 123+ <input type=\"checkbox\" name=\"wpSpecial[]\" value=\"$special\" $checked />
109124 <b>$special</b>
110 - </li>");
 125+ </li>\n");
111126 }
112127 }
113128
114 - $wgOut->addHTML("<li>
115 - <input type=\"checkbox\" name=\"check_all\" id=\"refreshSpecialCheckAll\" onclick=\"refreshSpecialCheck(this.form);\" /><label for=\"refreshSpecialCheckAll\">&nbsp;" . wfMsg ( 'refreshspecial-select-all-pages' ) . "
116 - <noscript>" . wfMsg ( 'refreshspecial-js-disabled' ) . "
117 - </noscript>" );
118 - $wgOut->addHTML("</label>
119 - </li>
120 - <script type=\"text/javascript\">
121 - function refreshSpecialCheck( form ) {
122 - pattern = document.getElementById('refreshSpecialCheckAll').checked;
123 - for( i = 0; i < form.elements.length; i++ ) {
124 - if( form.elements[i].type == 'checkbox' && form.elements[i].name != 'check_all' ) {
125 - form.elements[i].checked = pattern;
126 - }
127 - }
128 - }
129 - </script>
130 - </ul>
131 - <input tabindex=\"5\" name=\"wpRefreshSpecialSubmit\" type=\"submit\" value=\"".wfMsg('refreshspecial-button')."\" />
132 - <input type='hidden' name='wpEditToken' value=\"{$token}\" />
133 - </form>");
 129+ $wgOut->addHTML( "\t\t\t\t\t" . '<li>
 130+ <input type="checkbox" name="check_all" id="refreshSpecialCheckAll" onclick="refreshSpecialCheck(this.form);" />
 131+ <label for="refreshSpecialCheckAll">&nbsp;' . wfMsg( 'refreshspecial-select-all-pages' ) . '
 132+ <noscript>' . wfMsg( 'refreshspecial-js-disabled' ) . '</noscript>
 133+ </label>
 134+ </li>
 135+ </ul>
 136+ <input tabindex="5" name="wpRefreshSpecialSubmit" type="submit" value="'. wfMsg( 'refreshspecial-button' ). '" />
 137+ <input type="hidden" name="wpEditToken" value="'. $token .'" />
 138+ </form>' . "\n" );
134139 }
135140
136141 /**
@@ -138,7 +143,7 @@
139144 * @param $amount int
140145 * @return array Amount of elapsed time
141146 */
142 - function compute_time($amount) {
 147+ function computeTime( $amount ) {
143148 $return_array = array();
144149 $return_array['hours'] = intval( $amount / 3600 );
145150 $return_array['minutes'] = intval( $amount % 3600 / 60 );
@@ -153,7 +158,7 @@
154159 * @param $message mixed Message displayed to the user containing the elapsed time
155160 * @return true
156161 */
157 - function format_time_message( $time, &$message ) {
 162+ function formatTimeMessage( $time, &$message ) {
158163 if ( $time['hours'] ) {
159164 $message .= $time['hours'] . 'h ';
160165 }
@@ -172,12 +177,12 @@
173178 global $wgRequest, $wgQueryPages, $wgOut;
174179 $dbw = wfGetDB( DB_MASTER );
175180 $to_refresh = $wgRequest->getArray( 'wpSpecial' );
176 - $total = array (
177 - 'pages' => 0,
178 - 'rows' => 0,
179 - 'elapsed' => 0,
180 - 'total_elapsed' => 0
181 - );
 181+ $total = array(
 182+ 'pages' => 0,
 183+ 'rows' => 0,
 184+ 'elapsed' => 0,
 185+ 'total_elapsed' => 0
 186+ );
182187
183188 foreach ( $wgQueryPages as $page ) {
184189 @list( $class, $special, $limit ) = $page;
@@ -187,7 +192,7 @@
188193
189194 $specialObj = SpecialPage::getPage( $special );
190195 if ( !$specialObj ) {
191 - $wgOut->addWikiText( wfMsg('refreshspecial-no-page').": $special\n");
 196+ $wgOut->addWikiText( wfMsg( 'refreshspecial-no-page' ).": $special\n" );
192197 exit;
193198 }
194199 $file = $specialObj->getFile();
@@ -198,7 +203,7 @@
199204
200205 $message = '';
201206 if( !( isset( $options['only'] ) ) or ( $options['only'] == $queryPage->getName() ) ) {
202 - $wgOut->addHTML("<b>$special</b>: ");
 207+ $wgOut->addHTML( "<b>$special</b>: " );
203208
204209 if ( $queryPage->isExpensive() ) {
205210 $t1 = explode( ' ', microtime() );
@@ -207,28 +212,28 @@
208213 $t2 = explode( ' ', microtime() );
209214
210215 if ( $num === false ) {
211 - $wgOut->addHTML( wfMsg('refreshspecial-db-error') . "<br />" );
 216+ $wgOut->addHTML( wfMsg( 'refreshspecial-db-error' ) . '<br />' );
212217 } else {
213 - $message = wfMsgExt( 'refreshspecial-page-result', array( 'escape', 'parsemag' ), $num ) . "&nbsp;";
214 - $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
 218+ $message = wfMsgExt( 'refreshspecial-page-result', array( 'escape', 'parsemag' ), $num ) . '&nbsp;';
 219+ $elapsed = ( $t2[0] - $t1[0] ) + ( $t2[1] - $t1[1] );
215220 $total['elapsed'] += $elapsed;
216221 $total['rows'] += $num;
217222 $total['pages']++;
218 - $ftime = $this->compute_time($elapsed);
219 - $this->format_time_message($ftime, $message);
220 - $wgOut->addHTML("$message<br />");
 223+ $ftime = $this->computeTime( $elapsed );
 224+ $this->formatTimeMessage( $ftime, $message );
 225+ $wgOut->addHTML( "$message<br />" );
221226 }
222227
223228 $t1 = explode( ' ', microtime() );
224229
225230 # Reopen any connections that have closed
226231 if ( !wfGetLB()->pingAll() ) {
227 - $wgOut->addHTML("<br />");
 232+ $wgOut->addHTML( '<br />' );
228233 do {
229 - $wgOut->addHTML( wfMsg('refreshspecial-reconnecting') ."<br />" );
230 - sleep(REFRESHSPECIAL_RECONNECTION_SLEEP);
 234+ $wgOut->addHTML( wfMsg( 'refreshspecial-reconnecting' ) . '<br />' );
 235+ sleep( REFRESHSPECIAL_RECONNECTION_SLEEP );
231236 } while ( !wfGetLB()->pingAll() );
232 - $wgOut->addHTML( wfMsg('refreshspecial-reconnected') . "<br /><br />" );
 237+ $wgOut->addHTML( wfMsg( 'refreshspecial-reconnected' ) . '<br /><br />' );
233238 } else {
234239 # Commit the results
235240 $dbw->commit();
@@ -237,53 +242,52 @@
238243 # Wait for the slave to catch up
239244 $slaveDB = wfGetDB( DB_SLAVE, array( 'QueryPage::recache', 'vslow' ) );
240245 while( $slaveDB->getLag() > REFRESHSPECIAL_SLAVE_LAG_LIMIT ) {
241 - $wgOut->addHTML( wfMsg('refreshspecial-slave-lagged') ."<br />" );
242 - sleep(REFRESHSPECIAL_SLAVE_LAG_SLEEP);
 246+ $wgOut->addHTML( wfMsg( 'refreshspecial-slave-lagged' ) . '<br />' );
 247+ sleep( REFRESHSPECIAL_SLAVE_LAG_SLEEP );
243248 }
244249
245250 $t2 = explode( ' ', microtime() );
246251 $elapsed_total = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
247252 $total['total_elapsed'] += $elapsed + $elapsed_total;
248253 } else {
249 - $wgOut->addHTML( wfMsg('refreshspecial-skipped')."<br />" );
 254+ $wgOut->addHTML( wfMsg( 'refreshspecial-skipped' ) . '<br />' );
250255 }
251256 }
252257 }
253258 /* display all stats */
254259 $elapsed_message = '';
255260 $total_elapsed_message = '';
256 - $this->format_time_message( $this->compute_time($total['elapsed']), $elapsed_message );
257 - $this->format_time_message( $this->compute_time($total['total_elapsed']), $total_elapsed_message );
258 - $wgOut->addHTML( "<br />" . wfMsgExt('refreshspecial-total-display', array( 'escape', 'parsemag' ), $total['pages'], $total['rows'], $elapsed_message, $total_elapsed_message) );
259 - $wgOut->addHTML("</ul></form>");
 261+ $this->formatTimeMessage( $this->computeTime( $total['elapsed'] ), $elapsed_message );
 262+ $this->formatTimeMessage( $this->computeTime( $total['total_elapsed'] ), $total_elapsed_message );
 263+ $wgOut->addHTML( '<br />' .
 264+ wfMsgExt( 'refreshspecial-total-display',
 265+ array( 'escape', 'parsemag' ),
 266+ $total['pages'],
 267+ $total['rows'],
 268+ $elapsed_message,
 269+ $total_elapsed_message
 270+ )
 271+ );
 272+ $wgOut->addHTML( '</ul></form>' );
260273 }
261274
262275 /**
263 - * On success
264 - */
265 - function showSuccess() {
266 - global $wgOut, $wgRequest;
267 - $wgOut->setPageTitle( wfMsg('refreshspecial-title') );
268 - $wgOut->setSubTitle( wfMsg('refreshspecial-success-subtitle') );
269 - }
270 -
271 - /**
272276 * On submit
273277 */
274278 function doSubmit() {
275279 global $wgOut, $wgUser, $wgRequest;
276280 /* guard against an empty array */
277281 $array = $wgRequest->getArray( 'wpSpecial' );
278 - if ( !is_array($array) || empty($array) || is_null($array) ) {
279 - $this->showForm( wfMsg('refreshspecial-none-selected') );
 282+ if ( !is_array( $array ) || empty( $array ) || is_null( $array ) ) {
 283+ $this->showForm( wfMsg( 'refreshspecial-none-selected' ) );
280284 return;
281285 }
282286
283 - $wgOut->setSubTitle( wfMsg( 'refreshspecial-choice', wfMsg('refreshspecial-refreshing') ) );
 287+ $wgOut->setSubTitle( wfMsg( 'refreshspecial-choice', wfMsg( 'refreshspecial-refreshing' ) ) );
284288 $this->refreshSpecial();
285289 $sk = $wgUser->getSkin();
286290 $titleObj = SpecialPage::getTitleFor( 'RefreshSpecial' );
287 - $link_back = $sk->makeKnownLinkObj( $titleObj, wfMsg('refreshspecial-link-back') );
288 - $wgOut->addHTML("<br /><b>" . $link_back . "</b>");
 291+ $link_back = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'refreshspecial-link-back' ) );
 292+ $wgOut->addHTML( '<br /><b>' . $link_back . '</b>' );
289293 }
290 -}
 294+}
\ No newline at end of file
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.i18n.php
@@ -22,7 +22,6 @@
2323 'refreshspecial-fail' => 'Please check at least one special page to refresh.',
2424 'refreshspecial-refreshing' => 'refreshing special pages',
2525 'refreshspecial-skipped' => 'cheap, skipped',
26 - 'refreshspecial-success-subtitle' => 'refreshing special pages',
2726 'refreshspecial-choice' => 'refreshing special pages',
2827 'refreshspecial-js-disabled' => '(<i>You cannot select all pages when JavaScript is disabled</i>)',
2928 'refreshspecial-select-all-pages' => 'Select all pages',
@@ -329,7 +328,7 @@
330329
331330 /** Finnish (Suomi)
332331 * @author Crt
333 - * @author Jack Phoenix
 332+ * @author Jack Phoenix <jack@countervandalism.net>
334333 * @author Mobe
335334 * @author Nike
336335 * @author Vililikku
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.php
@@ -4,20 +4,22 @@
55 *
66 * @file
77 * @ingroup Extensions
 8+ * @version 1.2.1
89 * @author Bartek Łapiński <bartek@wikia-inc.com>
9 - * @version 1.1
 10+ * @author Jack Phoenix <jack@countervandalism.net>
1011 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1112 * @link http://www.mediawiki.org/wiki/Extension:RefreshSpecial Documentation
1213 */
1314
14 -if( !defined('MEDIAWIKI') )
15 - die();
 15+if( !defined( 'MEDIAWIKI' ) ){
 16+ die( "This is not a valid entry point.\n" );
 17+}
1618
1719 // Extension credits that will be shown on Special:Version
1820 $wgExtensionCredits['specialpage'][] = array(
1921 'name' => 'Refresh Special',
20 - 'author' => 'Bartek Łapiński',
21 - 'version' => '1.2',
 22+ 'author' => array( 'Bartek Łapiński', 'Jack Phoenix' ),
 23+ 'version' => '1.2.1',
2224 'url' => 'http://www.mediawiki.org/wiki/Extension:RefreshSpecial',
2325 'description' => 'Allows manual special page refresh of special pages',
2426 'descriptionmsg' => 'refreshspecial-desc',
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.js
@@ -0,0 +1,11 @@
 2+/**
 3+ * JavaScript helper function for RefreshSpecial extension
 4+ */
 5+function refreshSpecialCheck( form ) {
 6+ pattern = document.getElementById( 'refreshSpecialCheckAll' ).checked;
 7+ for( i = 0; i < form.elements.length; i++ ) {
 8+ if( form.elements[i].type == 'checkbox' && form.elements[i].name != 'check_all' ) {
 9+ form.elements[i].checked = pattern;
 10+ }
 11+ }
 12+}
\ No newline at end of file
Property changes on: trunk/extensions/RefreshSpecial/RefreshSpecial.js
___________________________________________________________________
Name: svn:eol-style
113 + native
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.alias.php
@@ -34,7 +34,7 @@
3535
3636 /** Finnish (Suomi) */
3737 $aliases['fi'] = array(
38 - 'RefreshSpecial' => array( 'Toimintosivun päivitys' ),
 38+ 'RefreshSpecial' => array( 'Toimintosivujen päivitys' ),
3939 );
4040
4141 /** Galician (Galego) */

Status & tagging log