r99354 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99353‎ | r99354 | r99355 >
Date:16:00, 9 October 2011
Author:johnduhart
Status:resolved (Comments)
Tags:
Comment:
CategoryViewer now requires a Context
Modified paths:
  • /trunk/phase3/includes/CategoryPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/CategoryPage.php
@@ -34,11 +34,11 @@
3535 }
3636
3737 function view() {
38 - global $wgRequest, $wgUser;
 38+ $request = $this->getContext()->getRequest();
 39+ $diff = $request->getVal( 'diff' );
 40+ $diffOnly = $request->getBool( 'diffonly',
 41+ $this->getContext()->getUser()->getOption( 'diffonly' ) );
3942
40 - $diff = $wgRequest->getVal( 'diff' );
41 - $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
42 -
4343 if ( isset( $diff ) && $diffOnly ) {
4444 return parent::view();
4545 }
@@ -63,18 +63,17 @@
6464 }
6565
6666 function closeShowCategory() {
67 - global $wgOut, $wgRequest;
68 -
6967 // Use these as defaults for back compat --catrope
70 - $oldFrom = $wgRequest->getVal( 'from' );
71 - $oldUntil = $wgRequest->getVal( 'until' );
 68+ $request = $this->getContext()->getRequest();
 69+ $oldFrom = $request->getVal( 'from' );
 70+ $oldUntil = $request->getVal( 'until' );
7271
73 - $reqArray = $wgRequest->getValues();
 72+ $reqArray = $request->getValues();
7473
7574 $from = $until = array();
7675 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
77 - $from[$type] = $wgRequest->getVal( "{$type}from", $oldFrom );
78 - $until[$type] = $wgRequest->getVal( "{$type}until", $oldUntil );
 76+ $from[$type] = $request->getVal( "{$type}from", $oldFrom );
 77+ $until[$type] = $request->getVal( "{$type}until", $oldUntil );
7978
8079 // Do not want old-style from/until propagating in nav links.
8180 if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
@@ -88,8 +87,8 @@
8988 unset( $reqArray["from"] );
9089 unset( $reqArray["to"] );
9190
92 - $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $reqArray );
93 - $wgOut->addHTML( $viewer->getHTML() );
 91+ $viewer = new $this->mCategoryViewerClass( $this->mTitle, $this->getContext(), $from, $until, $reqArray );
 92+ $this->getContext()->getOutput()->addHTML( $viewer->getHTML() );
9493 }
9594 }
9695
@@ -138,9 +137,26 @@
139138 */
140139 private $query;
141140
142 - function __construct( $title, $from = '', $until = '', $query = array() ) {
 141+ /**
 142+ * Context object
 143+ * @var IContextSource
 144+ */
 145+ protected $context;
 146+
 147+ /**
 148+ * Constructor
 149+ *
 150+ * @since 1.19 $context is a second, required parameter
 151+ * @param $title Title
 152+ * @param $context IContextSource
 153+ * @param $from String
 154+ * @param $until String
 155+ * @param $query Array
 156+ */
 157+ function __construct( $title, IContextSource $context, $from = '', $until = '', $query = array() ) {
143158 global $wgCategoryPagingLimit;
144159 $this->title = $title;
 160+ $this->context = $context;
145161 $this->from = $from;
146162 $this->until = $until;
147163 $this->limit = $wgCategoryPagingLimit;
@@ -156,10 +172,10 @@
157173 * @return string HTML output
158174 */
159175 public function getHTML() {
160 - global $wgOut, $wgCategoryMagicGallery, $wgLang;
 176+ global $wgCategoryMagicGallery;
161177 wfProfileIn( __METHOD__ );
162178
163 - $this->showGallery = $wgCategoryMagicGallery && !$wgOut->mNoGallery;
 179+ $this->showGallery = $wgCategoryMagicGallery && !$this->context->getOutput()->mNoGallery;
164180
165181 $this->clearCategoryState();
166182 $this->doCategoryQuery();
@@ -187,7 +203,8 @@
188204 $r = wfMsgExt( 'category-empty', array( 'parse' ) );
189205 }
190206
191 - $langAttribs = array( 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() );
 207+ $lang = $this->getLang();
 208+ $langAttribs = array( 'lang' => $lang->getCode(), 'dir' => $lang->getDir() );
192209 # put a div around the headings which are in the user language
193210 $r = Html::openElement( 'div', $langAttribs ) . $r . '</div>';
194211
@@ -248,8 +265,6 @@
249266 * @param string $sortkey The human-readable sortkey (before transforming to icu or whatever).
250267 */
251268 function getSubcategorySortChar( $title, $sortkey ) {
252 - global $wgContLang;
253 -
254269 if ( $title->getPrefixedText() == $sortkey ) {
255270 $word = $title->getDBkey();
256271 } else {
@@ -258,14 +273,13 @@
259274
260275 $firstChar = $this->collation->getFirstLetter( $word );
261276
262 - return $wgContLang->convert( $firstChar );
 277+ return $this->getLang()->convert( $firstChar );
263278 }
264279
265280 /**
266281 * Add a page in the image namespace
267282 */
268283 function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
269 - global $wgContLang;
270284 if ( $this->showGallery ) {
271285 $flip = $this->flip['file'];
272286 if ( $flip ) {
@@ -282,7 +296,7 @@
283297 }
284298 $this->imgsNoGallery[] = $link;
285299
286 - $this->imgsNoGallery_start_char[] = $wgContLang->convert(
 300+ $this->imgsNoGallery_start_char[] = $this->getLang()->convert(
287301 $this->collation->getFirstLetter( $sortkey ) );
288302 }
289303 }
@@ -291,8 +305,6 @@
292306 * Add a miscellaneous page
293307 */
294308 function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
295 - global $wgContLang;
296 -
297309 $link = Linker::link( $title );
298310 if ( $isRedirect ) {
299311 // This seems kind of pointless given 'mw-redirect' class,
@@ -301,7 +313,7 @@
302314 }
303315 $this->articles[] = $link;
304316
305 - $this->articles_start_char[] = $wgContLang->convert(
 317+ $this->articles_start_char[] = $this->getLang()->convert->convert(
306318 $this->collation->getFirstLetter( $sortkey ) );
307319 }
308320
@@ -610,7 +622,7 @@
611623 private function pagingLinks( $first, $last, $type = '' ) {
612624 global $wgLang;
613625
614 - $limitText = $wgLang->formatNum( $this->limit );
 626+ $limitText = $this->getLang()->formatNum( $this->limit );
615627
616628 $prevLink = wfMsgExt( 'prevn', array( 'escape', 'parsemag' ), $limitText );
617629
@@ -685,7 +697,6 @@
686698 * @return String: A message giving the number of items, to output to HTML.
687699 */
688700 private function getCountMessage( $rescnt, $dbcnt, $type ) {
689 - global $wgLang;
690701 # There are three cases:
691702 # 1) The category table figure seems sane. It might be wrong, but
692703 # we can't do anything about it if we don't recalculate it on ev-
@@ -725,13 +736,22 @@
726737 } else {
727738 # Case 3: hopeless. Don't give a total count at all.
728739 return wfMsgExt( "category-$type-count-limited", 'parse',
729 - $wgLang->formatNum( $rescnt ) );
 740+ $this->getLang()->formatNum( $rescnt ) );
730741 }
731742 return wfMsgExt(
732743 "category-$type-count",
733744 'parse',
734 - $wgLang->formatNum( $rescnt ),
735 - $wgLang->formatNum( $totalcnt )
 745+ $this->getLang()->formatNum( $rescnt ),
 746+ $this->getLang()->formatNum( $totalcnt )
736747 );
737748 }
 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+ }
738758 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r99356Followup r99354, update extensions that use CategoryViewer to be compatiable ...johnduhart16:04, 9 October 2011
r99365Followup r99354, fix Fatal errorjohnduhart18:39, 9 October 2011
r99403Fixes for r99354:...ialex14:55, 10 October 2011
r100962Followup r99354, adding release notes entryjohnduhart11:43, 27 October 2011

Comments

#Comment by IAlex (talk | contribs)   16:24, 9 October 2011

Why did you change $wgContLang to the getLang() method ? It is meant to replace $wgLang, not $wgContLang.

#Comment by Johnduhart (talk | contribs)   00:25, 10 October 2011

Oh. Whoops, I saw $wgContLang in ResourceContext and I thought that's what it was returning. Just so we're clear, $wgContLang is per wiki and not per-user, correct?

#Comment by IAlex (talk | contribs)   04:24, 10 October 2011

Correct, it does not depend on the user. The check you saw is to not create twice a Language object with the same code.

#Comment by Nikerabbit (talk | contribs)   15:43, 11 October 2011

How about at least a release notes entry that the signature of CategoryPage constructor has changed?

#Comment by Johnduhart (talk | contribs)   22:15, 17 October 2011

Still needs to be done, marking fixme so I don't forget it.

Status & tagging log