r82526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82525‎ | r82526 | r82527 >
Date:18:50, 20 February 2011
Author:ialex
Status:ok
Tags:
Comment:
* Removed usage of $wgTitle in site notice hook
* Code simplification in Collection.templates.php
* misc bug fixes:
** pass the page name to wfAjaxCollectionGetBookCreatorBoxContent() so that the link doesn't point to the main page
** make the "printable version" when the action parameter is not present in the URL
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.hooks.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)
  • /trunk/extensions/Collection/Collection.templates.php (modified) (history)
  • /trunk/extensions/Collection/js/bookcreator.js (modified) (history)
  • /trunk/extensions/Collection/js/collection.js (modified) (history)
  • /trunk/extensions/Collection/js/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.php
@@ -269,12 +269,23 @@
270270
271271 $wgAjaxExportList[] = 'wfAjaxCollectionAddCategory';
272272
273 -function wfAjaxCollectionGetBookCreatorBoxContent( $ajaxHint = '', $oldid = null ) {
 273+function wfAjaxCollectionGetBookCreatorBoxContent( $ajaxHint = '', $oldid = null, $pageName = null ) {
 274+ global $wgUser;
 275+
274276 if ( !is_null( $oldid ) ) {
275277 $oldid = intval( $oldid );
276278 }
277 - $html = CollectionHooks::getBookCreatorBoxContent( $ajaxHint, $oldid );
278279
 280+ $title = null;
 281+ if ( !is_null( $pageName ) ) {
 282+ $title = Title::newFromText( $pageName );
 283+ }
 284+ if ( is_null( $title ) ) {
 285+ $title = Title::newMainPage();
 286+ }
 287+
 288+ $html = CollectionHooks::getBookCreatorBoxContent( $wgUser->getSkin(), $title, $ajaxHint, $oldid );
 289+
279290 $json = new Services_JSON();
280291 $result = array();
281292 $result['html'] = $html;
Index: trunk/extensions/Collection/Collection.hooks.php
@@ -73,8 +73,8 @@
7474 return false;
7575 }
7676
77 - $action = $wgRequest->getVal( 'action' );
78 - if ( $action != '' && $action != 'view' && $action != 'purge' ) {
 77+ $action = $wgRequest->getVal( 'action', 'view' );
 78+ if ( $action != 'view' && $action != 'purge' ) {
7979 return false;
8080 }
8181
@@ -144,7 +144,7 @@
145145 global $wgOut;
146146 if ( !$wgOut->isPrintable() ) {
147147 $attribs = array(
148 - 'href' => $wgRequest->appendQuery( 'printable=yes' ),
 148+ 'href' => $sk->getTitle()->getLocalUrl( $wgRequest->appendQueryValue( 'printable', 'yes', true ) ),
149149 'title' => $sk->titleAttrib( 't-print', 'withaccess' ),
150150 'accesskey' => $sk->accesskey( 't-print' ),
151151 );
@@ -168,10 +168,9 @@
169169 /**
170170 * Callback for hook SiteNoticeAfter
171171 */
172 - static function siteNoticeAfter( &$siteNotice ) {
 172+ static function siteNoticeAfter( &$siteNotice, $skin = null ) {
173173 global $wgCollectionArticleNamespaces;
174174 global $wgRequest;
175 - global $wgTitle;
176175
177176 $action = $wgRequest->getVal( 'action' );
178177 if ( $action != '' && $action != 'view' && $action != 'purge' ) {
@@ -184,46 +183,50 @@
185184 return true;
186185 }
187186
188 - $myTitle = SpecialPage::getTitleFor( 'Book' );
189 - if ( $myTitle->equals( $wgTitle ) ) {
 187+ if ( $skin ) {
 188+ $title = $skin->getTitle();
 189+ } else {
 190+ global $wgTitle, $wgUser;
 191+ $title = $wgTitle;
 192+ $skin = $wgUser->getSkin();
 193+ }
 194+
 195+ if ( $title->isSpecial( 'Book' ) ) {
190196 $cmd = $wgRequest->getVal( 'bookcmd', '' );
191197 if ( $cmd == 'suggest' ) {
192 - $siteNotice .= self::renderBookCreatorBox( 'suggest' );
 198+ $siteNotice .= self::renderBookCreatorBox( $title, $skin, 'suggest' );
193199 } else if ( $cmd == '' ) {
194 - $siteNotice .= self::renderBookCreatorBox( 'showbook' );
 200+ $siteNotice .= self::renderBookCreatorBox( $title, $skin, 'showbook' );
195201 }
196202 return true;
197203 }
198204
199 - if ( is_null( $wgTitle ) || !$wgTitle->exists() ) {
 205+ if ( !$title->exists() ) {
200206 return true;
201207 }
202208
203 - $namespace = $wgTitle->getNamespace();
 209+ $namespace = $title->getNamespace();
204210 if ( !in_array( $namespace, $wgCollectionArticleNamespaces )
205211 && $namespace != NS_CATEGORY ) {
206212 return true;
207213 }
208214
209 - $siteNotice .= self::renderBookCreatorBox();
 215+ $siteNotice .= self::renderBookCreatorBox( $title, $skin );
210216 return true;
211217 }
212218
213 - static function renderBookCreatorBox( $mode = '' ) {
 219+ static function renderBookCreatorBox( $title, $skin, $mode = '' ) {
214220 global $wgCollectionStyleVersion;
215221 global $wgJsMimeType;
216222 global $wgOut;
217223 global $wgScriptPath;
218 - global $wgTitle;
219 - global $wgUser;
220224 global $wgRequest;
221225
222 - $sk = $wgUser->getSkin();
223226 $jsPath = "$wgScriptPath/extensions/Collection/js";
224227 $imagePath = "$wgScriptPath/extensions/Collection/images";
225 - $ptext = $wgTitle->getPrefixedText();
 228+ $ptext = $title->getPrefixedText();
226229 $oldid = $wgRequest->getVal( 'oldid', 0 );
227 - if ( $oldid == $wgTitle->getLatestRevID() ) {
 230+ if ( $oldid == $title->getLatestRevID() ) {
228231 $oldid = 0;
229232 }
230233
@@ -252,7 +255,7 @@
253256 array( 'style' => 'margin-left: 90px;' ),
254257 Xml::tags( 'div',
255258 array( 'style' => 'float: right' ),
256 - $sk->link(
 259+ $skin->link(
257260 Title::newFromText( wfMsg( 'coll-helppage' ) ),
258261 Xml::element( 'img',
259262 array(
@@ -277,7 +280,7 @@
278281 wfMsgHtml( 'coll-book_creator' )
279282 )
280283 . ' ('
281 - . $sk->link(
 284+ . $skin->link(
282285 SpecialPage::getTitleFor( 'Book' ),
283286 wfMsgHtml( 'coll-disable' ),
284287 array(
@@ -295,31 +298,27 @@
296299 'id' => 'coll-book_creator_box',
297300 'style' => 'margin-left: 90px; margin-bottom: 0;',
298301 ),
299 - self::getBookCreatorBoxContent( $addRemoveState, $oldid )
 302+ self::getBookCreatorBoxContent( $skin, $title, $addRemoveState, $oldid )
300303 );
301304
302305 $html .= Xml::closeElement( 'div' );
303306 return $html;
304307 }
305308
306 - static function getBookCreatorBoxContent( $ajaxHint = null, $oldid = null ) {
307 - global $wgUser;
 309+ static function getBookCreatorBoxContent( $skin, $title, $ajaxHint = null, $oldid = null ) {
308310 global $wgScriptPath;
309311
310 - $sk = $wgUser->getSkin();
311312 $imagePath = "$wgScriptPath/extensions/Collection/images";
312313
313 - return self::getBookCreatorBoxAddRemoveLink( $sk, $imagePath, $ajaxHint, $oldid )
314 - . self::getBookCreatorBoxShowBookLink( $sk, $imagePath, $ajaxHint )
315 - . self::getBookCreatorBoxSuggestLink( $sk, $imagePath, $ajaxHint );
 314+ return self::getBookCreatorBoxAddRemoveLink( $skin, $imagePath, $ajaxHint, $title, $oldid )
 315+ . self::getBookCreatorBoxShowBookLink( $skin, $imagePath, $ajaxHint )
 316+ . self::getBookCreatorBoxSuggestLink( $skin, $imagePath, $ajaxHint );
316317 }
317318
318 - static function getBookCreatorBoxAddRemoveLink( $sk, $imagePath, $ajaxHint, $oldid ) {
319 - global $wgTitle;
 319+ static function getBookCreatorBoxAddRemoveLink( $sk, $imagePath, $ajaxHint, $title, $oldid ) {
 320+ $namespace = $title->getNamespace();
 321+ $ptext = $title->getPrefixedText();
320322
321 - $namespace = $wgTitle->getNamespace();
322 - $ptext = $wgTitle->getPrefixedText();
323 -
324323 if ( $ajaxHint == 'suggest' || $ajaxHint == 'showbook' ) {
325324 return Xml::tags( 'span',
326325 array( 'style' => 'color: #777;' ),
@@ -341,7 +340,7 @@
342341 $icon = 'silk-add.png';
343342 $captionMsg = 'coll-add_category';
344343 $tooltipMsg = 'coll-add_category_tooltip';
345 - $query = array( 'bookcmd' => 'add_category', 'cattitle' => $wgTitle->getText() );
 344+ $query = array( 'bookcmd' => 'add_category', 'cattitle' => $title->getText() );
346345 $onclick = "collectionCall('AddCategory', ['addcategory', wgTitle]); return false;";
347346 } else {
348347 if ( $ajaxHint == 'addarticle'
Index: trunk/extensions/Collection/js/bookcreator.js
@@ -35,7 +35,7 @@
3636 $.getJSON(script_url, {
3737 'action': 'ajax',
3838 'rs': 'wfAjaxCollectionGetBookCreatorBoxContent',
39 - 'rsargs[]': [hint, oldid]
 39+ 'rsargs[]': [hint, oldid, wgPageName]
4040 }, function(result) {
4141 $('#coll-book_creator_box').html(result.html);
4242 });
Index: trunk/extensions/Collection/js/collection.js
@@ -94,7 +94,7 @@
9595 $('#titleInput').val('');
9696 $('#subtitleInput').val('');
9797 refresh_list(result);
98 - req('GetBookCreatorBoxContent', ['showbook', null], function(result2) {
 98+ req('GetBookCreatorBoxContent', ['showbook', null, wgPageName], function(result2) {
9999 $('#coll-book_creator_box').html(result2.html);
100100 });
101101 });
@@ -125,7 +125,7 @@
126126 [index],
127127 function(result) {
128128 refresh_list(result);
129 - req('GetBookCreatorBoxContent', ['showbook', null], function(result2) {
 129+ req('GetBookCreatorBoxContent', ['showbook', null, wgPageName], function(result2) {
130130 $('#coll-book_creator_box').html(result2.html);
131131 });
132132 });
Index: trunk/extensions/Collection/js/suggest.js
@@ -30,7 +30,7 @@
3131 $.getJSON(script_url, {
3232 'action': 'ajax',
3333 'rs': 'wfAjaxCollectionGetBookCreatorBoxContent',
34 - 'rsargs[]': ['suggest', null]
 34+ 'rsargs[]': ['suggest', null, wgPageName]
3535 }, function(result) {
3636 $('#coll-book_creator_box').html(result.html);
3737 });
Index: trunk/extensions/Collection/Collection.body.php
@@ -44,7 +44,6 @@
4545 global $wgUser;
4646 global $wgContLang;
4747 global $wgCollectionMaxArticles;
48 - global $wgTitle;
4948
5049 // support previous URLs (e.g. used in templates) which used the "$par" part
5150 // (i.e. subpages of the Special page)
@@ -61,7 +60,7 @@
6261
6362 switch ( $wgRequest->getVal( 'bookcmd', '' ) ) {
6463 case 'book_creator':
65 - $this->renderBookCreatorPage( $wgRequest->getVal( 'referer', '' ) );
 64+ $this->renderBookCreatorPage( $wgRequest->getVal( 'referer', '' ), $par );
6665 return;
6766
6867 case 'start_book_creator':
@@ -74,7 +73,7 @@
7574 return;
7675 case 'stop_book_creator':
7776 $title = Title::newFromText( $wgRequest->getVal( 'referer', '' ) );
78 - if ( is_null( $title ) || $title->equals( $wgTitle ) ) {
 77+ if ( is_null( $title ) || $title->equals( $this->getTitle( $par ) ) ) {
7978 $title = Title::newMainPage();
8079 }
8180 if ( $wgRequest->getVal( 'disable' ) ) {
@@ -305,11 +304,10 @@
306305 return;
307306 }
308307
309 - function renderBookCreatorPage( $referer ) {
 308+ function renderBookCreatorPage( $referer, $par ) {
310309 global $wgCollectionStyleVersion;
311310 global $wgOut;
312311 global $wgScriptPath;
313 - global $wgTitle;
314312 global $wgUser;
315313 global $wgJsMimeType;
316314
@@ -332,7 +330,7 @@
333331 "</script>" );
334332
335333 $title = Title::newFromText( $referer );
336 - if ( is_null( $title ) || $title->equals( $wgTitle ) ) {
 334+ if ( is_null( $title ) || $title->equals( $this->getTitle( $par ) ) ) {
337335 $title = Title::newMainPage();
338336 }
339337 $sk = $wgUser->getSkin();
Index: trunk/extensions/Collection/Collection.templates.php
@@ -84,11 +84,7 @@
8585 if ( $t && $t->exists() ) { ?>
8686 <div id="coll-order_info" style="display:none; margin-top: 2em;">
8787 <?php
88 -echo $GLOBALS['wgParser']->parse( '{{:' . $t . '}}',
89 - $GLOBALS['wgTitle'],
90 - $GLOBALS['wgOut']->parserOptions(),
91 - true
92 -)->getText();
 88+echo $GLOBALS['wgOut']->parse( '{{:' . $t . '}}' );
9389 ?>
9490 </div>
9591 <?php } ?>
@@ -98,12 +94,7 @@
9995 <h2><span class="mw-headline"><?php $this->msg( 'coll-download_title' ) ?></span></h2>
10096 <?php if ( count( $this->data['formats'] ) == 1 ) {
10197 $writer = array_rand( $this->data['formats'] );
102 - echo $GLOBALS['wgParser']->parse(
103 - wfMsgNoTrans( 'coll-download_as_text', $this->data['formats'][$writer] ),
104 - $GLOBALS['wgTitle'],
105 - $GLOBALS['wgOut']->parserOptions(),
106 - true
107 - )->getText();
 98+ echo wfMsgExt( 'coll-download_as_text', 'parse', $this->data['formats'][$writer] );
10899 $buttonLabel = wfMsgHtml( 'coll-download_as', htmlspecialchars( $this->data['formats'][$writer] ) );
109100 } else {
110101 $this->msgWiki( 'coll-download_text' );
@@ -322,7 +313,7 @@
323314
324315 <h2><span class="mw-headline"><?php $this->msg( 'coll-overwrite_title' ) ?></span></h2>
325316
326 -<p><?php echo $GLOBALS['wgParser']->parse( wfMsgNoTrans( 'coll-overwrite_text', $this->data['title']->getPrefixedText() ), $GLOBALS['wgTitle'], $GLOBALS['wgOut']->parserOptions(), true )->getText() ?></p>
 317+<p><?php echo wfMsgExt( 'coll-overwrite_text', 'parse', $this->data['title']->getPrefixedText() ); ?></p>
327318
328319 <form action="<?php echo htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book' ) ) ?>" method="post">
329320 <input name="overwrite" type="submit" value="<?php $this->msg( 'coll-yes' ) ?>" />
@@ -361,11 +352,7 @@
362353 }
363354 $t = Title::newFromText( $title_string );
364355 if ( $t && $t->exists() ) {
365 - echo $GLOBALS['wgParser']->parse( '{{:' . $t . '}}',
366 - $GLOBALS['wgTitle'],
367 - $GLOBALS['wgOut']->parserOptions(),
368 - true
369 - )->getText();
 356+ echo $GLOBALS['wgOut']->parse( '{{:' . $t . '}}' );
370357 }
371358 }
372359 }
@@ -377,32 +364,17 @@
378365 class CollectionFinishedTemplate extends QuickTemplate {
379366 function execute() {
380367
381 -echo $GLOBALS['wgParser']->parse(
382 - wfMsgNoTrans( 'coll-rendering_finished_text', $this->data['download_url'] ),
383 - $GLOBALS['wgTitle'],
384 - $GLOBALS['wgOut']->parserOptions(),
385 - true
386 -)->getText();
 368+echo wfMsgExt( 'coll-rendering_finished_text', 'parse', $this->data['download_url'] );
387369
388370 if ( $this->data['is_cached'] ) {
389371 $forceRenderURL = SkinTemplate::makeSpecialUrl( 'Book', 'bookcmd=forcerender&' . $this->data['query'] );
390372 echo wfMsg( 'coll-is_cached', htmlspecialchars( $forceRenderURL ) );
391373 }
392 -echo $GLOBALS['wgParser']->parse(
393 - wfMsgNoTrans( 'coll-excluded-templates', wfMsgForContent( 'coll-exclusion_category_title' ) ),
394 - $GLOBALS['wgTitle'],
395 - $GLOBALS['wgOut']->parserOptions(),
396 - true
397 -)->getText();
 374+echo wfMsgExt( 'coll-excluded-templates', 'parse', wfMsgForContent( 'coll-exclusion_category_title' ) );
398375 $title_string = wfMsgForContent( 'coll-template_blacklist_title' );
399376 $t = Title::newFromText( $title_string );
400377 if ( $t && $t->exists() ) {
401 - echo $GLOBALS['wgParser']->parse(
402 - wfMsgNoTrans( 'coll-blacklisted-templates', $title_string ),
403 - $GLOBALS['wgTitle'],
404 - $GLOBALS['wgOut']->parserOptions(),
405 - true
406 - )->getText();
 378+ echo wfMsgExt( 'coll-blacklisted-templates', 'parse', $title_string );
407379 }
408380 if ( $this->data['return_to'] ) {
409381 // We are doing this the hard way (i.e. via the HTML detour), to prevent
@@ -422,11 +394,7 @@
423395 }
424396 $t = Title::newFromText( $title_string );
425397 if ( $t && $t->exists() ) {
426 - echo $GLOBALS['wgParser']->parse( '{{:' . $t . '}}',
427 - $GLOBALS['wgTitle'],
428 - $GLOBALS['wgOut']->parserOptions(),
429 - true
430 - )->getText();
 398+ echo $GLOBALS['wgOut']->parse( '{{:' . $t . '}}' );
431399 }
432400 ?>
433401

Status & tagging log