r99403 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99402‎ | r99403 | r99404 >
Date:14:55, 10 October 2011
Author:ialex
Status:ok (Comments)
Tags:todo 
Comment:
Fixes for r99354:
* Restore call to $wgContLang
* Make CategoryViewer extend ContextSource

Also simplify things by using wfMessage() instead of wfMsg*() in some cases
Modified paths:
  • /trunk/phase3/includes/CategoryPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/CategoryPage.php
@@ -92,7 +92,7 @@
9393 }
9494 }
9595
96 -class CategoryViewer {
 96+class CategoryViewer extends ContextSource {
9797 var $limit, $from, $until,
9898 $articles, $articles_start_char,
9999 $children, $children_start_char,
@@ -138,12 +138,6 @@
139139 private $query;
140140
141141 /**
142 - * Context object
143 - * @var IContextSource
144 - */
145 - protected $context;
146 -
147 - /**
148142 * Constructor
149143 *
150144 * @since 1.19 $context is a second, required parameter
@@ -156,7 +150,7 @@
157151 function __construct( $title, IContextSource $context, $from = '', $until = '', $query = array() ) {
158152 global $wgCategoryPagingLimit;
159153 $this->title = $title;
160 - $this->context = $context;
 154+ $this->setContext( $context );
161155 $this->from = $from;
162156 $this->until = $until;
163157 $this->limit = $wgCategoryPagingLimit;
@@ -175,7 +169,7 @@
176170 global $wgCategoryMagicGallery;
177171 wfProfileIn( __METHOD__ );
178172
179 - $this->showGallery = $wgCategoryMagicGallery && !$this->context->getOutput()->mNoGallery;
 173+ $this->showGallery = $wgCategoryMagicGallery && !$this->getOutput()->mNoGallery;
180174
181175 $this->clearCategoryState();
182176 $this->doCategoryQuery();
@@ -265,6 +259,8 @@
266260 * @param string $sortkey The human-readable sortkey (before transforming to icu or whatever).
267261 */
268262 function getSubcategorySortChar( $title, $sortkey ) {
 263+ global $wgContLang;
 264+
269265 if ( $title->getPrefixedText() == $sortkey ) {
270266 $word = $title->getDBkey();
271267 } else {
@@ -273,13 +269,14 @@
274270
275271 $firstChar = $this->collation->getFirstLetter( $word );
276272
277 - return $this->getLang()->convert( $firstChar );
 273+ return $wgContLang->convert( $firstChar );
278274 }
279275
280276 /**
281277 * Add a page in the image namespace
282278 */
283279 function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
 280+ global $wgContLang;
284281 if ( $this->showGallery ) {
285282 $flip = $this->flip['file'];
286283 if ( $flip ) {
@@ -296,7 +293,7 @@
297294 }
298295 $this->imgsNoGallery[] = $link;
299296
300 - $this->imgsNoGallery_start_char[] = $this->getLang()->convert(
 297+ $this->imgsNoGallery_start_char[] = $wgContLang->convert(
301298 $this->collation->getFirstLetter( $sortkey ) );
302299 }
303300 }
@@ -305,6 +302,8 @@
306303 * Add a miscellaneous page
307304 */
308305 function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
 306+ global $wgContLang;
 307+
309308 $link = Linker::link( $title );
310309 if ( $isRedirect ) {
311310 // This seems kind of pointless given 'mw-redirect' class,
@@ -313,7 +312,7 @@
314313 }
315314 $this->articles[] = $link;
316315
317 - $this->articles_start_char[] = $this->getLang()->convert(
 316+ $this->articles_start_char[] = $wgContLang->convert(
318317 $this->collation->getFirstLetter( $sortkey ) );
319318 }
320319
@@ -620,12 +619,8 @@
621620 * @return String HTML
622621 */
623622 private function pagingLinks( $first, $last, $type = '' ) {
624 - global $wgLang;
 623+ $prevLink = wfMessage( 'prevn' )->numParams( $this->limit )->escaped();
625624
626 - $limitText = $this->getLang()->formatNum( $this->limit );
627 -
628 - $prevLink = wfMsgExt( 'prevn', array( 'escape', 'parsemag' ), $limitText );
629 -
630625 if ( $first != '' ) {
631626 $prevQuery = $this->query;
632627 $prevQuery["{$type}until"] = $first;
@@ -638,7 +633,7 @@
639634 );
640635 }
641636
642 - $nextLink = wfMsgExt( 'nextn', array( 'escape', 'parsemag' ), $limitText );
 637+ $nextLink = wfMessage( 'nextn' )->numParams( $this->limit )->escaped();
643638
644639 if ( $last != '' ) {
645640 $lastQuery = $this->query;
@@ -735,23 +730,8 @@
736731 $this->cat->refreshCounts();
737732 } else {
738733 # Case 3: hopeless. Don't give a total count at all.
739 - return wfMsgExt( "category-$type-count-limited", 'parse',
740 - $this->getLang()->formatNum( $rescnt ) );
 734+ return wfMessage( "category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
741735 }
742 - return wfMsgExt(
743 - "category-$type-count",
744 - 'parse',
745 - $this->getLang()->formatNum( $rescnt ),
746 - $this->getLang()->formatNum( $totalcnt )
747 - );
 736+ return wfMessage( "category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
748737 }
749 -
750 - /**
751 - * Returns a language object from the context
752 - *
753 - * @return Language
754 - */
755 - protected function getLang() {
756 - return $this->context->getLang();
757 - }
758738 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99354CategoryViewer now requires a Contextjohnduhart16:00, 9 October 2011

Comments

#Comment by Johnduhart (talk | contribs)   15:42, 10 October 2011

Thanks, did not know about ContextSourceÍ

#Comment by Krinkle (talk | contribs)   00:04, 20 December 2011

May wanna use $this->msg( .. ) (ContextSource::msg) instead of wfMessage( .. ), as wfMessage is also using a global otherwise.

Status & tagging log