r45095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45094‎ | r45095 | r45096 >
Date:15:12, 27 December 2008
Author:ashley
Status:deferred
Tags:
Comment:
RefreshSpecial tweaks:
*mark function visibility
*delay message loading
*add license (per wikia's google code page)
*doxygen comment tweaks
*altered Finnish special page alias a bit (I'd assume that this extension would be used to update two or more special pages at a time, not just one ;-)
*removed message documentation; that can be found at http://www.mediawiki.org/wiki/Extension:RefreshSpecial#System_messages now
*addWikiMsg() instead of addWikiText( wfMsg() )
*coding style tweaks
*use the alias file we have
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.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RefreshSpecial/RefreshSpecial.body.php
@@ -13,9 +13,8 @@
1414 /**
1515 * Constructor
1616 */
17 - function __construct() {
18 - parent::__construct( 'RefreshSpecial', 'refreshspecial', true, 'execute', false );
19 - wfLoadExtensionMessages('RefreshSpecial');
 17+ public function __construct() {
 18+ parent::__construct( 'RefreshSpecial'/*class*/, 'refreshspecial'/*restriction*/ );
2019 }
2120
2221 /**
@@ -23,17 +22,19 @@
2423 *
2524 * @param $par Mixed: parameter passed to the page or null
2625 */
27 - function execute( $par ) {
 26+ public function execute( $par ) {
2827 global $wgOut, $wgUser, $wgRequest;
 28+ wfLoadExtensionMessages('RefreshSpecial');
 29+
2930 $wgOut->setPageTitle( wfMsg('refreshspecial-title') );
3031 $cSF = new RefreshSpecialForm();
3132
32 - $action = $wgRequest->getVal('action');
33 - if ('success' == $action) {
 33+ $action = $wgRequest->getVal( 'action' );
 34+ if( 'success' == $action ) {
3435 /* do something */
35 - } else if ('failure' == $action) {
 36+ } else if( 'failure' == $action ) {
3637 $cSF->showForm( wfMsg('refreshspecial-fail') );
37 - } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
 38+ } else if( $wgRequest->wasPosted() && 'submit' == $action &&
3839 $wgUser->matchEditToken( $wgRequest->getVal('wpEditToken') ) ) {
3940 $cSF->doSubmit();
4041 } else {
@@ -50,13 +51,6 @@
5152 var $mMode, $mLink;
5253
5354 /**
54 - * Constructor
55 - */
56 - function RefreshSpecialForm() {
57 - global $wgRequest;
58 - }
59 -
60 - /**
6155 * Show the actual form
6256 *
6357 * @param $err string Error message if there was an error, otherwise null
@@ -65,19 +59,19 @@
6660 global $wgOut, $wgUser, $wgRequest, $wgQueryPages;
6761
6862 $token = htmlspecialchars( $wgUser->editToken() );
69 - $titleObj = Title::makeTitle( NS_SPECIAL, 'RefreshSpecial' );
 63+ $titleObj = SpecialPage::getTitleFor( 'RefreshSpecial' );
7064 $action = $titleObj->escapeLocalURL( "action=submit" );
7165
72 - if ( "" != $err ) {
 66+ if ( '' != $err ) {
7367 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
7468 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
7569 }
7670
77 - $wgOut->addWikiText( wfMsg('refreshspecial-help') );
 71+ $wgOut->addWikiMsg( 'refreshspecial-help' );
7872
79 - ( 'submit' == $wgRequest->getVal( 'action' )) ? $scLink = htmlspecialchars ($this->mLink) : $scLink = '';
 73+ ( 'submit' == $wgRequest->getVal( 'action' ) ) ? $scLink = htmlspecialchars($this->mLink) : $scLink = '';
8074
81 - $wgOut->addHTML("<form name=\"RefreshSpecial\" method=\"post\" action=\"{$action}\"><ul>");
 75+ $wgOut->addHTML("<form name=\"RefreshSpecial\" method=\"post\" action=\"{$action}\"><ul>");
8276
8377 /**
8478 * List pages right here
@@ -91,7 +85,7 @@
9286
9387 $specialObj = SpecialPage::getPage( $special );
9488 if ( !$specialObj ) {
95 - $wgOut->addWikiText( wfMsg('refreshspecial-no-page') . " $special\n");
 89+ $wgOut->addWikiText( wfMsg('refreshspecial-no-page') . " $special\n" );
9690 exit;
9791 }
9892 $file = $specialObj->getFile();
@@ -116,10 +110,10 @@
117111 $wgOut->addHTML("</label>
118112 </li>
119113 <script type=\"text/javascript\">
120 - function refreshSpecialCheck (form) {
121 - pattern = document.getElementById ('refreshSpecialCheckAll').checked;
122 - for (i=0; i<form.elements.length; i++) {
123 - if (form.elements[i].type == 'checkbox' && form.elements[i].name != 'check_all') {
 114+ function refreshSpecialCheck( form ) {
 115+ pattern = document.getElementById('refreshSpecialCheckAll').checked;
 116+ for( i = 0; i < form.elements.length; i++ ) {
 117+ if( form.elements[i].type == 'checkbox' && form.elements[i].name != 'check_all' ) {
124118 form.elements[i].checked = pattern;
125119 }
126120 }
@@ -152,7 +146,7 @@
153147 * @param $message mixed Message displayed to the user containing the elapsed time
154148 * @return true
155149 */
156 - function format_time_message($time, &$message) {
 150+ function format_time_message( $time, &$message ) {
157151 if ( $time['hours'] ) {
158152 $message .= $time['hours'] . 'h ';
159153 }
@@ -170,7 +164,7 @@
171165 function refreshSpecial() {
172166 global $wgRequest, $wgQueryPages, $wgOut;
173167 $dbw = wfGetDB( DB_MASTER );
174 - $to_refresh = $wgRequest->getArray('wpSpecial');
 168+ $to_refresh = $wgRequest->getArray( 'wpSpecial' );
175169 $total = array (
176170 'pages' => 0,
177171 'rows' => 0,
@@ -180,13 +174,13 @@
181175
182176 foreach ( $wgQueryPages as $page ) {
183177 @list( $class, $special, $limit ) = $page;
184 - if ( !in_array($special, $to_refresh) ) {
 178+ if ( !in_array( $special, $to_refresh ) ) {
185179 continue;
186180 }
187181
188182 $specialObj = SpecialPage::getPage( $special );
189183 if ( !$specialObj ) {
190 - $wgOut->addWikiText( wfMsg('refreshspecial-no-page').": $special\n");
 184+ $wgOut->addWikiText( wfMsg('refreshspecial-no-page').": $special\n");
191185 exit;
192186 }
193187 $file = $specialObj->getFile();
@@ -195,8 +189,8 @@
196190 }
197191 $queryPage = new $class;
198192
199 - $message = "";
200 - if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
 193+ $message = '';
 194+ if( !( isset( $options['only'] ) ) or ( $options['only'] == $queryPage->getName() ) ) {
201195 $wgOut->addHTML("<b>$special</b>: ");
202196
203197 if ( $queryPage->isExpensive() ) {
@@ -206,7 +200,7 @@
207201 $t2 = explode( ' ', microtime() );
208202
209203 if ( $num === false ) {
210 - $wgOut->addHTML( wfMsg('refreshspecial-db-error') . "<br />");
 204+ $wgOut->addHTML( wfMsg('refreshspecial-db-error') . "<br />" );
211205 } else {
212206 $message = "got $num rows in ";
213207 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
@@ -222,26 +216,26 @@
223217 if ( !wfGetLB()->pingAll() ) {
224218 $wgOut->addHTML("<br />");
225219 do {
226 - $wgOut->addHTML( wfMsg('refreshspecial-reconnecting') ."<br />");
 220+ $wgOut->addHTML( wfMsg('refreshspecial-reconnecting') ."<br />" );
227221 sleep(REFRESHSPECIAL_RECONNECTION_SLEEP);
228222 } while ( !wfGetLB()->pingAll() );
229 - $wgOut->addHTML( wfMsg('refreshspecial-reconnected') . "<br /><br />");
 223+ $wgOut->addHTML( wfMsg('refreshspecial-reconnected') . "<br /><br />" );
230224 } else {
231225 # Commit the results
232 - $dbw->immediateCommit();
 226+ $dbw->commit();
233227 }
234228
235229 # Wait for the slave to catch up
236 - $slaveDB = wfGetDB( DB_SLAVE, array('QueryPage::recache', 'vslow' ) );
 230+ $slaveDB = wfGetDB( DB_SLAVE, array( 'QueryPage::recache', 'vslow' ) );
237231 while( $slaveDB->getLag() > REFRESHSPECIAL_SLAVE_LAG_LIMIT ) {
238 - $wgOut->addHTML(wfMsg('refreshspecial-slave-lagged') ."<br />");
 232+ $wgOut->addHTML( wfMsg('refreshspecial-slave-lagged') ."<br />" );
239233 sleep(REFRESHSPECIAL_SLAVE_LAG_SLEEP);
240234 }
241235 $t2 = explode( ' ', microtime() );
242236 $elapsed_total = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
243237 $total['total_elapsed'] += $elapsed + $elapsed_total;
244238 } else {
245 - $wgOut->addHTML(wfMsg('refreshspecial-skipped')."<br />");
 239+ $wgOut->addHTML( wfMsg('refreshspecial-skipped')."<br />" );
246240 }
247241 }
248242 }
@@ -269,17 +263,17 @@
270264 function doSubmit() {
271265 global $wgOut, $wgUser, $wgRequest;
272266 /* guard against an empty array */
273 - $array = $wgRequest->getArray('wpSpecial');
 267+ $array = $wgRequest->getArray( 'wpSpecial' );
274268 if ( !is_array($array) || empty($array) || is_null($array) ) {
275269 $this->showForm( wfMsg('refreshspecial-none-selected') );
276270 return;
277271 }
278272
279 - $wgOut->setSubTitle( wfMsg('refreshspecial-choice', wfMsg('refreshspecial-refreshing') ) );
 273+ $wgOut->setSubTitle( wfMsg( 'refreshspecial-choice', wfMsg('refreshspecial-refreshing') ) );
280274 $this->refreshSpecial();
281275 $sk = $wgUser->getSkin();
282 - $titleObj = Title::makeTitle( NS_SPECIAL, 'RefreshSpecial' );
283 - $link_back = $sk->makeKnownLinkObj($titleObj, wfMsg('refreshspecial-here') );
 276+ $titleObj = SpecialPage::getTitleFor( 'RefreshSpecial' );
 277+ $link_back = $sk->makeKnownLinkObj( $titleObj, wfMsg('refreshspecial-here') );
284278 $wgOut->addHTML("<br />".wfMsg('refreshspecial-link-back')." $link_back.");
285279 }
286280 }
\ No newline at end of file
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.i18n.php
@@ -2,6 +2,7 @@
33 /**
44 * Internationalisation file for the RefreshSpecial extension.
55 *
 6+ * @file
67 * @ingroup Extensions
78 */
89
@@ -10,7 +11,7 @@
1112 /** English
1213 * @author Bartek Łapiński
1314 */
14 -$messages['en'] = array (
 15+$messages['en'] = array(
1516 'refreshspecial' => 'Refresh special pages',
1617 'refreshspecial-desc' => 'Allows [[Special:RefreshSpecial|manual special page refresh]] of special pages',
1718 'refreshspecial-title' => 'Refresh special pages',
@@ -34,18 +35,6 @@
3536 'refreshspecial-total-display' => '<br />Refreshed $1 pages totaling $2 rows in time $3 (complete time of the script run is $4)',
3637 );
3738
38 -/** Message documentation (Message documentation)
39 - * @author Jon Harald Søby
40 - * @author Purodha
41 - */
42 -$messages['qqq'] = array(
43 - 'refreshspecial' => '{{Identical|Refresh special pages}}',
44 - 'refreshspecial-desc' => 'Shown in [[Special:Version]] as a short description of this extension. Do not translate links.',
45 - 'refreshspecial-title' => '{{Identical|Refresh special pages}}',
46 - 'refreshspecial-refreshing' => '{{Identical|Refreshing special pages}}',
47 - 'refreshspecial-success-subtitle' => '{{Identical|Refreshing special pages}}',
48 -);
49 -
5039 /** Arabic (العربية)
5140 * @author Meno25
5241 */
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.php
@@ -2,27 +2,32 @@
33 /**
44 * A special page providing means to manually refresh special pages
55 *
 6+ * @file
67 * @ingroup Extensions
7 - * @author Bartek Łapiński <bartek@wikia.com>
8 - * @version 1.0
 8+ * @author Bartek Łapiński <bartek@wikia-inc.com>
 9+ * @version 1.1
 10+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
911 * @link http://www.mediawiki.org/wiki/Extension:RefreshSpecial Documentation
1012 */
1113
12 -if(!defined('MEDIAWIKI'))
 14+if( !defined('MEDIAWIKI') )
1315 die();
1416
15 -$wgAvailableRights[] = 'refreshspecial';
16 -$wgGroupPermissions['staff']['refreshspecial'] = true;
17 -
 17+// Extension credits that will be shown on Special:Version
1818 $wgExtensionCredits['specialpage'][] = array(
19 - 'name' => 'Refresh Special',
20 - 'author' => 'Bartek Łapiński',
21 - 'version' => '1.1',
22 - 'url' => 'http://www.mediawiki.org/wiki/Extension:RefreshSpecial',
23 - 'description' => 'Allows manual special page refresh of special pages',
 19+ 'name' => 'Refresh Special',
 20+ 'author' => 'Bartek Łapiński',
 21+ 'version' => '1.1',
 22+ 'url' => 'http://www.mediawiki.org/wiki/Extension:RefreshSpecial',
 23+ 'description' => 'Allows manual special page refresh of special pages',
2424 'descriptionmsg' => 'refreshspecial-desc',
2525 );
2626
 27+// New user right, required to use Special:RefreshSpecial
 28+$wgAvailableRights[] = 'refreshspecial';
 29+$wgGroupPermissions['staff']['refreshspecial'] = true;
 30+
 31+// Set up the new special page
2732 $dir = dirname(__FILE__) . '/';
2833 $wgExtensionMessagesFiles['RefreshSpecial'] = $dir . 'RefreshSpecial.i18n.php';
2934 $wgExtensionAliasesFiles['RefreshSpecial'] = $dir . 'RefreshSpecial.alias.php';
@@ -36,4 +41,4 @@
3742 /* amount of acceptable slave lag */
3843 define('REFRESHSPECIAL_SLAVE_LAG_LIMIT', 600);
3944 /* interval when slave is lagged */
40 -define('REFRESHSPECIAL_SLAVE_LAG_SLEEP', 30);
 45+define('REFRESHSPECIAL_SLAVE_LAG_SLEEP', 30);
\ No newline at end of file
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.alias.php
@@ -2,10 +2,13 @@
33 /**
44 * Aliases for special pages
55 *
 6+ * @file
 7+ * @ingroup Extensions
68 */
79
810 $aliases = array();
911
 12+/** English */
1013 $aliases['en'] = array(
1114 'RefreshSpecial' => array( 'RefreshSpecial' ),
1215 );
@@ -31,7 +34,7 @@
3235
3336 /** Finnish (Suomi) */
3437 $aliases['fi'] = array(
35 - 'RefreshSpecial' => array( 'Toimintosivun päivitys' ),
 38+ 'RefreshSpecial' => array( 'Toimintosivujen päivitys' ),
3639 );
3740
3841 /** Swiss German (Alemannisch) */
@@ -62,5 +65,4 @@
6366 /** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬) */
6467 $aliases['no'] = array(
6568 'RefreshSpecial' => array( 'Oppdater spesialsider' ),
66 -);
67 -
 69+);
\ No newline at end of file

Status & tagging log