r110478 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110477‎ | r110478 | r110479 >
Date:14:22, 1 February 2012
Author:maxsem
Status:ok
Tags:
Comment:
*temporary* revert of r110207 and r110271, will recommit with my fixes later
Modified paths:
  • /trunk/extensions/FeaturedFeeds/ApiFeaturedFeeds.php (modified) (history)
  • /trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php (modified) (history)
  • /trunk/extensions/FeaturedFeeds/SpecialFeedItem.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FeaturedFeeds/ApiFeaturedFeeds.php
@@ -15,7 +15,6 @@
1616 }
1717
1818 public function execute() {
19 - global $wgContLang;
2019 wfProfileIn( __METHOD__ );
2120
2221 $params = $this->extractRequestParams();
@@ -32,12 +31,7 @@
3332 wfProfileOut( __METHOD__ );
3433 $this->dieUsage( 'Invalid language code', 'language-invalid' );
3534 }
36 - $variant = isset( $params['variant'] ) ? $params['variant'] : false;
37 - if ( $variant !== false && !in_array( $variant, $wgContLang->getVariants() ) ) {
38 - wfProfileOut( __METHOD__ );
39 - $this->dieUsage( 'Invalid variant code', 'variant-invalid' );
40 - }
41 - $feeds = FeaturedFeeds::getFeeds( $language, $variant );
 35+ $feeds = FeaturedFeeds::getFeeds( $language );
4236 $ourFeed = $feeds[$params['feed']];
4337
4438 $feedClass = new $wgFeedClasses[$params['feedformat']] (
@@ -58,7 +52,7 @@
5953 public function getAllowedParams() {
6054 global $wgFeedClasses;
6155 $feedFormatNames = array_keys( $wgFeedClasses );
62 - $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false, false ) );
 56+ $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false ) );
6357 return array (
6458 'feedformat' => array(
6559 ApiBase::PARAM_DFLT => 'rss',
@@ -70,10 +64,7 @@
7165 ),
7266 'language' => array(
7367 ApiBase::PARAM_TYPE => 'string',
74 - ),
75 - 'variant' => array(
76 - ApiBase::PARAM_TYPE => 'string',
77 - ),
 68+ )
7869 );
7970 }
8071
@@ -81,8 +72,7 @@
8273 return array(
8374 'feedformat' => 'The format of the feed',
8475 'feed' => 'Feed name',
85 - 'language' => 'Feed language code. Ignored by some feeds.',
86 - 'variant' => 'Feed variant code.',
 76+ 'language' => 'Feed language code. Ignored by some feeds.'
8777 );
8878 }
8979
@@ -94,7 +84,6 @@
9585 return array_merge( parent::getPossibleErrors(), array(
9686 array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
9787 array( 'code' => 'language-invalid', 'info' => 'Invalid language code' ),
98 - array( 'code' => 'variant-invalid', 'info' => 'Invalid variant code' ),
9988 ) );
10089 }
10190
@@ -102,7 +91,7 @@
10392 global $wgVersion;
10493 // attempt to find a valid feed name
10594 // if none available, just use an example value
106 - $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false, false ) );
 95+ $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false ) );
10796 $feed = reset( $availableFeeds );
10897 if ( !$feed ) {
10998 $feed = 'featured';
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php
@@ -7,31 +7,27 @@
88 * Returns the list of feeds
99 *
1010 * @param $langCode string|bool Code of language to use or false if default
11 - * @param $variantCode string|bool Code of variant to use or false if default or empty string if don't convert
1211 * @return array Feeds in format of 'name' => array of FeedItem
1312 */
14 - public static function getFeeds( $langCode, $variantCode ) {
15 - global $wgMemc, $wgLangCode, $wgContLang;
 13+ public static function getFeeds( $langCode ) {
 14+ global $wgMemc, $wgLangCode;
1615
1716 if ( !$langCode || self::allInContentLanguage() ) {
1817 $langCode = $wgLangCode;
1918 }
20 - if ( $variantCode === false ) {
21 - $variantCode = $wgContLang->getPreferredVariant();
22 - }
2319 static $cache = array();
24 - if ( isset( $cache[$langCode][$variantCode] ) ) {
25 - return $cache[$langCode][$variantCode];
 20+ if ( isset( $cache[$langCode] ) ) {
 21+ return $cache[$langCode];
2622 }
2723
28 - $key = self::getCacheKey( $langCode, $variantCode );
 24+ $key = self::getCacheKey( $langCode );
2925 $feeds = $wgMemc->get( $key );
3026
3127 if ( !$feeds ) {
32 - $feeds = self::getFeedsInternal( $langCode, $variantCode );
 28+ $feeds = self::getFeedsInternal( $langCode );
3329 $wgMemc->set( $key, $feeds, self::getMaxAge() );
3430 }
35 - $cache[$langCode][$variantCode] = $feeds;
 31+ $cache[$langCode] = $feeds;
3632 return $feeds;
3733 }
3834
@@ -40,8 +36,8 @@
4137 * @param String $langCode: Feed language code
4238 * @return String
4339 */
44 - private static function getCacheKey( $langCode, $variantCode ) {
45 - return wfMemcKey( 'featured-feeds', $langCode, $variantCode );
 40+ private static function getCacheKey( $langCode ) {
 41+ return wfMemcKey( 'featured-feeds', $langCode );
4642 }
4743
4844 /**
@@ -87,13 +83,9 @@
8884 * @return bool
8985 */
9086 public static function beforePageDisplay( OutputPage &$out ) {
91 - global $wgAdvertisedFeedTypes, $wgContLang;
 87+ global $wgAdvertisedFeedTypes;
9288 if ( $out->getTitle()->isMainPage() ) {
93 - $feeds = self::getFeeds(
94 - $out->getLanguage()->getCode(),
95 - $wgContLang->getPreferredVariant()
96 - );
97 - foreach ( $feeds as $feed ) {
 89+ foreach ( self::getFeeds( $out->getLanguage()->getCode() ) as $feed ) {
9890 foreach ( $wgAdvertisedFeedTypes as $type ) {
9991 $out->addLink( array(
10092 'rel' => 'alternate',
@@ -114,13 +106,10 @@
115107 * @return Boolean
116108 */
117109 public static function skinTemplateOutputPageBeforeExec( &$sk, &$tpl ) {
118 - global $wgDisplayFeedsInSidebar, $wgAdvertisedFeedTypes, $wgContLang;
 110+ global $wgDisplayFeedsInSidebar, $wgAdvertisedFeedTypes;
119111
120112 if ( $wgDisplayFeedsInSidebar && $sk->getContext()->getTitle()->isMainPage() ) {
121 - $feeds = self::getFeeds(
122 - $sk->getContext()->getLanguage()->getCode(),
123 - $wgContLang->getPreferredVariant()
124 - );
 113+ $feeds = self::getFeeds( $sk->getContext()->getLanguage()->getCode() );
125114 $links = array();
126115 $format = $wgAdvertisedFeedTypes[0]; // @fixme:
127116 foreach ( $feeds as $feed ) {
@@ -174,7 +163,7 @@
175164 * @return array
176165 * @throws MWException
177166 */
178 - private static function getFeedsInternal( $langCode, $variantCode ) {
 167+ private static function getFeedsInternal( $langCode ) {
179168 wfProfileIn( __METHOD__ );
180169 $feedDefs = self::getFeedDefinitions();
181170
@@ -182,7 +171,7 @@
183172 $requestedLang = Language::factory( $langCode );
184173 $parser = new Parser();
185174 foreach ( $feedDefs as $name => $opts ) {
186 - $feed = new FeaturedFeedChannel( $name, $opts, $requestedLang, $variantCode );
 175+ $feed = new FeaturedFeedChannel( $name, $opts, $requestedLang );
187176 if ( !$feed->isOK() ) {
188177 continue;
189178 }
@@ -263,7 +252,7 @@
264253 public $shortTitle;
265254 public $description;
266255
267 - public function __construct( $name, $options, $lang, $variant ) {
 256+ public function __construct( $name, $options, $lang ) {
268257 global $wgContLang;
269258 if ( !self::$parserOptions ) {
270259 self::$parserOptions = new ParserOptions();
@@ -277,7 +266,6 @@
278267 } else {
279268 $this->language = $wgContLang;
280269 }
281 - $this->variant = $variant;
282270 }
283271
284272 private function msg( $key ) {
@@ -298,19 +286,13 @@
299287 }
300288
301289 public function init() {
302 - global $wgContLang;
 290+ global $wgLanguageCode;
303291 if ( $this->title !== false ) {
304292 return;
305293 }
306294 $this->title = $this->msg( $this->options['title'] )->text();
307295 $this->shortTitle = $this->msg( $this->options['short-title'] );
308296 $this->description = $this->msg( $this->options['description'] )->text();
309 - // Convert the messages if the content language has variants.
310 - if ( $wgContLang->hasVariants() && $this->variant ) {
311 - $this->title = $wgContLang->mConverter->convertTo( $this->title, $this->variant );
312 - $this->shortTitle = $wgContLang->mConverter->convertTo( $this->shortTitle, $this->variant );
313 - $this->description = $wgContLang->mConverter->convertTo( $this->description, $this->variant );
314 - }
315297 $pageMsg = $this->msg( $this->options['page'] )->params( $this->language->getCode() );
316298 if ( $pageMsg->isDisabled() ) {
317299 return;
@@ -340,7 +322,6 @@
341323 * @return FeaturedFeedItem
342324 */
343325 public function getFeedItem( $date ) {
344 - global $wgContLang;
345326 self::$parserOptions->setTimestamp( $date );
346327 self::$parserOptions->setUserLang( $this->language );
347328
@@ -358,19 +339,16 @@
359340 return false;
360341 }
361342 $text = self::$parser->parse( $text, $title, self::$parserOptions )->getText();
362 - $special = SpecialPage::getTitleFor( 'FeedItem' ,
 343+ $url = SpecialPage::getTitleFor( 'FeedItem' ,
363344 $this->name . '/' . wfTimestamp( TS_MW, $date ) . '/' . $this->language->getCode()
364 - );
365 - $entry = self::$parser->transformMsg( $this->entryName, self::$parserOptions );
366 - if ( $wgContLang->hasVariants() && $this->variant ) {
367 - $text = $wgContLang->mConverter->convertTo( $text, $this->variant );
368 - $entry = $wgContLang->mConverter->convertTo( $entry, $this->variant );
369 - $url = $special->getFullURL( array( 'variant' => $this->variant ) );
370 - } else {
371 - $url = $special->getFullURL();
372 - }
 345+ )->getFullURL();
373346
374 - return new FeaturedFeedItem( $entry, wfExpandUrl( $url ), $text, $date );
 347+ return new FeaturedFeedItem(
 348+ self::$parser->transformMsg( $this->entryName, self::$parserOptions ),
 349+ wfExpandUrl( $url ),
 350+ $text,
 351+ $date
 352+ );
375353 }
376354
377355 /**
@@ -390,9 +368,6 @@
391369 if ( $this->options['inUserLanguage'] && $this->language->getCode() != $wgContLang->getCode() ) {
392370 $options['language'] = $this->language->getCode();
393371 }
394 - if ( $wgContLang->hasVariants() && $this->variant ) {
395 - $options['variant'] = $this->variant;
396 - }
397372 return wfScript( 'api' ) . '?' . wfArrayToCGI( $options );
398373 }
399374 }
Index: trunk/extensions/FeaturedFeeds/SpecialFeedItem.php
@@ -15,7 +15,7 @@
1616 return;
1717 }
1818 list( $feedName, $date, $langCode ) = $parts;
19 - $feeds = FeaturedFeeds::getFeeds( $langCode, '' );
 19+ $feeds = FeaturedFeeds::getFeeds( $langCode );
2020 if ( !isset( $feeds[$feedName] ) ) {
2121 $out->showErrorPage( 'error', 'ffeed-feed-not-found', array( $feedName ) );
2222 return;
@@ -54,10 +54,8 @@
5555 }
5656
5757 private function displayItem( FeaturedFeedItem $item ) {
58 - global $wgContLang;
5958 $out = $this->getOutput();
60 - // The language converter converts page content automatically but not page title.
61 - $out->setPageTitle( $wgContLang->convert( $item->getRawTitle() ) );
 59+ $out->setPageTitle( $item->getRawTitle() );
6260 $out->addHTML( $item->getRawText() );
6361 }
6462 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r110207Do language variant conversion in feedsliangent14:23, 28 January 2012
r110271Drop a comment. We'll never turn to variant-as-2nd-arg because of r109161.liangent08:45, 30 January 2012

Status & tagging log