Index: trunk/extensions/FeaturedFeeds/ApiFeaturedFeeds.php |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | } |
17 | 17 | |
18 | 18 | public function execute() { |
| 19 | + global $wgContLang; |
19 | 20 | wfProfileIn( __METHOD__ ); |
20 | 21 | |
21 | 22 | $params = $this->extractRequestParams(); |
— | — | @@ -31,7 +32,12 @@ |
32 | 33 | wfProfileOut( __METHOD__ ); |
33 | 34 | $this->dieUsage( 'Invalid language code', 'language-invalid' ); |
34 | 35 | } |
35 | | - $feeds = FeaturedFeeds::getFeeds( $language ); |
| 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 ); |
36 | 42 | $ourFeed = $feeds[$params['feed']]; |
37 | 43 | |
38 | 44 | $feedClass = new $wgFeedClasses[$params['feedformat']] ( |
— | — | @@ -52,7 +58,7 @@ |
53 | 59 | public function getAllowedParams() { |
54 | 60 | global $wgFeedClasses; |
55 | 61 | $feedFormatNames = array_keys( $wgFeedClasses ); |
56 | | - $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false ) ); |
| 62 | + $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false, false ) ); |
57 | 63 | return array ( |
58 | 64 | 'feedformat' => array( |
59 | 65 | ApiBase::PARAM_DFLT => 'rss', |
— | — | @@ -64,7 +70,10 @@ |
65 | 71 | ), |
66 | 72 | 'language' => array( |
67 | 73 | ApiBase::PARAM_TYPE => 'string', |
68 | | - ) |
| 74 | + ), |
| 75 | + 'variant' => array( |
| 76 | + ApiBase::PARAM_TYPE => 'string', |
| 77 | + ), |
69 | 78 | ); |
70 | 79 | } |
71 | 80 | |
— | — | @@ -72,7 +81,8 @@ |
73 | 82 | return array( |
74 | 83 | 'feedformat' => 'The format of the feed', |
75 | 84 | 'feed' => 'Feed name', |
76 | | - 'language' => 'Feed language code. Ignored by some feeds.' |
| 85 | + 'language' => 'Feed language code. Ignored by some feeds.', |
| 86 | + 'variant' => 'Feed variant code.', |
77 | 87 | ); |
78 | 88 | } |
79 | 89 | |
— | — | @@ -84,6 +94,7 @@ |
85 | 95 | return array_merge( parent::getPossibleErrors(), array( |
86 | 96 | array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ), |
87 | 97 | array( 'code' => 'language-invalid', 'info' => 'Invalid language code' ), |
| 98 | + array( 'code' => 'variant-invalid', 'info' => 'Invalid variant code' ), |
88 | 99 | ) ); |
89 | 100 | } |
90 | 101 | |
— | — | @@ -91,7 +102,7 @@ |
92 | 103 | global $wgVersion; |
93 | 104 | // attempt to find a valid feed name |
94 | 105 | // if none available, just use an example value |
95 | | - $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false ) ); |
| 106 | + $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false, false ) ); |
96 | 107 | $feed = reset( $availableFeeds ); |
97 | 108 | if ( !$feed ) { |
98 | 109 | $feed = 'featured'; |
Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php |
— | — | @@ -7,27 +7,31 @@ |
8 | 8 | * Returns the list of feeds |
9 | 9 | * |
10 | 10 | * @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 |
11 | 12 | * @return array Feeds in format of 'name' => array of FeedItem |
12 | 13 | */ |
13 | | - public static function getFeeds( $langCode ) { |
14 | | - global $wgMemc, $wgLangCode; |
| 14 | + public static function getFeeds( $langCode, $variantCode ) { |
| 15 | + global $wgMemc, $wgLangCode, $wgContLang; |
15 | 16 | |
16 | 17 | if ( !$langCode || self::allInContentLanguage() ) { |
17 | 18 | $langCode = $wgLangCode; |
18 | 19 | } |
| 20 | + if ( $variantCode === false ) { |
| 21 | + $variantCode = $wgContLang->getPreferredVariant(); |
| 22 | + } |
19 | 23 | static $cache = array(); |
20 | | - if ( isset( $cache[$langCode] ) ) { |
21 | | - return $cache[$langCode]; |
| 24 | + if ( isset( $cache[$langCode][$variantCode] ) ) { |
| 25 | + return $cache[$langCode][$variantCode]; |
22 | 26 | } |
23 | 27 | |
24 | | - $key = self::getCacheKey( $langCode ); |
| 28 | + $key = self::getCacheKey( $langCode, $variantCode ); |
25 | 29 | $feeds = $wgMemc->get( $key ); |
26 | 30 | |
27 | 31 | if ( !$feeds ) { |
28 | | - $feeds = self::getFeedsInternal( $langCode ); |
| 32 | + $feeds = self::getFeedsInternal( $langCode, $variantCode ); |
29 | 33 | $wgMemc->set( $key, $feeds, self::getMaxAge() ); |
30 | 34 | } |
31 | | - $cache[$langCode] = $feeds; |
| 35 | + $cache[$langCode][$variantCode] = $feeds; |
32 | 36 | return $feeds; |
33 | 37 | } |
34 | 38 | |
— | — | @@ -36,8 +40,8 @@ |
37 | 41 | * @param String $langCode: Feed language code |
38 | 42 | * @return String |
39 | 43 | */ |
40 | | - private static function getCacheKey( $langCode ) { |
41 | | - return wfMemcKey( 'featured-feeds', $langCode ); |
| 44 | + private static function getCacheKey( $langCode, $variantCode ) { |
| 45 | + return wfMemcKey( 'featured-feeds', $langCode, $variantCode ); |
42 | 46 | } |
43 | 47 | |
44 | 48 | /** |
— | — | @@ -83,9 +87,13 @@ |
84 | 88 | * @return bool |
85 | 89 | */ |
86 | 90 | public static function beforePageDisplay( OutputPage &$out ) { |
87 | | - global $wgAdvertisedFeedTypes; |
| 91 | + global $wgAdvertisedFeedTypes, $wgContLang; |
88 | 92 | if ( $out->getTitle()->isMainPage() ) { |
89 | | - foreach ( self::getFeeds( $out->getLanguage()->getCode() ) as $feed ) { |
| 93 | + $feeds = self::getFeeds( |
| 94 | + $out->getLanguage()->getCode(), |
| 95 | + $wgContLang->getPreferredVariant() |
| 96 | + ); |
| 97 | + foreach ( $feeds as $feed ) { |
90 | 98 | foreach ( $wgAdvertisedFeedTypes as $type ) { |
91 | 99 | $out->addLink( array( |
92 | 100 | 'rel' => 'alternate', |
— | — | @@ -106,10 +114,13 @@ |
107 | 115 | * @return Boolean |
108 | 116 | */ |
109 | 117 | public static function skinTemplateOutputPageBeforeExec( &$sk, &$tpl ) { |
110 | | - global $wgDisplayFeedsInSidebar, $wgAdvertisedFeedTypes; |
| 118 | + global $wgDisplayFeedsInSidebar, $wgAdvertisedFeedTypes, $wgContLang; |
111 | 119 | |
112 | 120 | if ( $wgDisplayFeedsInSidebar && $sk->getContext()->getTitle()->isMainPage() ) { |
113 | | - $feeds = self::getFeeds( $sk->getContext()->getLanguage()->getCode() ); |
| 121 | + $feeds = self::getFeeds( |
| 122 | + $sk->getContext()->getLanguage()->getCode(), |
| 123 | + $wgContLang->getPreferredVariant() |
| 124 | + ); |
114 | 125 | $links = array(); |
115 | 126 | $format = $wgAdvertisedFeedTypes[0]; // @fixme: |
116 | 127 | foreach ( $feeds as $feed ) { |
— | — | @@ -163,7 +174,7 @@ |
164 | 175 | * @return array |
165 | 176 | * @throws MWException |
166 | 177 | */ |
167 | | - private static function getFeedsInternal( $langCode ) { |
| 178 | + private static function getFeedsInternal( $langCode, $variantCode ) { |
168 | 179 | wfProfileIn( __METHOD__ ); |
169 | 180 | $feedDefs = self::getFeedDefinitions(); |
170 | 181 | |
— | — | @@ -171,7 +182,7 @@ |
172 | 183 | $requestedLang = Language::factory( $langCode ); |
173 | 184 | $parser = new Parser(); |
174 | 185 | foreach ( $feedDefs as $name => $opts ) { |
175 | | - $feed = new FeaturedFeedChannel( $name, $opts, $requestedLang ); |
| 186 | + $feed = new FeaturedFeedChannel( $name, $opts, $requestedLang, $variantCode ); |
176 | 187 | if ( !$feed->isOK() ) { |
177 | 188 | continue; |
178 | 189 | } |
— | — | @@ -252,7 +263,7 @@ |
253 | 264 | public $shortTitle; |
254 | 265 | public $description; |
255 | 266 | |
256 | | - public function __construct( $name, $options, $lang ) { |
| 267 | + public function __construct( $name, $options, $lang, $variant ) { |
257 | 268 | global $wgContLang; |
258 | 269 | if ( !self::$parserOptions ) { |
259 | 270 | self::$parserOptions = new ParserOptions(); |
— | — | @@ -266,6 +277,7 @@ |
267 | 278 | } else { |
268 | 279 | $this->language = $wgContLang; |
269 | 280 | } |
| 281 | + $this->variant = $variant; |
270 | 282 | } |
271 | 283 | |
272 | 284 | private function msg( $key ) { |
— | — | @@ -286,13 +298,19 @@ |
287 | 299 | } |
288 | 300 | |
289 | 301 | public function init() { |
290 | | - global $wgLanguageCode; |
| 302 | + global $wgLanguageCode, $wgContLang; |
291 | 303 | if ( $this->title !== false ) { |
292 | 304 | return; |
293 | 305 | } |
294 | 306 | $this->title = $this->msg( $this->options['title'] )->text(); |
295 | 307 | $this->shortTitle = $this->msg( $this->options['short-title'] ); |
296 | 308 | $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 | + } |
297 | 315 | $pageMsg = $this->msg( $this->options['page'] )->params( $this->language->getCode() ); |
298 | 316 | if ( $pageMsg->isDisabled() ) { |
299 | 317 | // fall back manually, messages can be existent but empty |
— | — | @@ -330,6 +348,7 @@ |
331 | 349 | * @return FeaturedFeedItem |
332 | 350 | */ |
333 | 351 | public function getFeedItem( $date ) { |
| 352 | + global $wgContLang; |
334 | 353 | self::$parserOptions->setTimestamp( $date ); |
335 | 354 | self::$parserOptions->setUserLang( $this->language ); |
336 | 355 | |
— | — | @@ -347,16 +366,20 @@ |
348 | 367 | return false; |
349 | 368 | } |
350 | 369 | $text = self::$parser->parse( $text, $title, self::$parserOptions )->getText(); |
351 | | - $url = SpecialPage::getTitleFor( 'FeedItem' , |
| 370 | + $special = SpecialPage::getTitleFor( 'FeedItem' , |
352 | 371 | $this->name . '/' . wfTimestamp( TS_MW, $date ) . '/' . $this->language->getCode() |
353 | | - )->getFullURL(); |
| 372 | + ); |
| 373 | + $entry = self::$parser->transformMsg( $this->entryName, self::$parserOptions ); |
| 374 | + if ( $wgContLang->hasVariants() && $this->variant ) { |
| 375 | + $text = $wgContLang->mConverter->convertTo( $text, $this->variant ); |
| 376 | + $entry = $wgContLang->mConverter->convertTo( $entry, $this->variant ); |
| 377 | + // bug 34010. otherwise variant specified in the second argument can be ignored. |
| 378 | + $url = $special->getFullURL( array( 'variant' => $this->variant ) ); |
| 379 | + } else { |
| 380 | + $url = $special->getFullURL(); |
| 381 | + } |
354 | 382 | |
355 | | - return new FeaturedFeedItem( |
356 | | - self::$parser->transformMsg( $this->entryName, self::$parserOptions ), |
357 | | - wfExpandUrl( $url ), |
358 | | - $text, |
359 | | - $date |
360 | | - ); |
| 383 | + return new FeaturedFeedItem( $entry, wfExpandUrl( $url ), $text, $date ); |
361 | 384 | } |
362 | 385 | |
363 | 386 | /** |
— | — | @@ -376,6 +399,9 @@ |
377 | 400 | if ( $this->options['inUserLanguage'] && $this->language->getCode() != $wgContLang->getCode() ) { |
378 | 401 | $options['language'] = $this->language->getCode(); |
379 | 402 | } |
| 403 | + if ( $wgContLang->hasVariants() && $this->variant ) { |
| 404 | + $options['variant'] = $this->variant; |
| 405 | + } |
380 | 406 | return wfScript( 'api' ) . '?' . wfArrayToCGI( $options ); |
381 | 407 | } |
382 | 408 | } |
Index: trunk/extensions/FeaturedFeeds/SpecialFeedItem.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | return; |
17 | 17 | } |
18 | 18 | list( $feedName, $date, $langCode ) = $parts; |
19 | | - $feeds = FeaturedFeeds::getFeeds( $langCode ); |
| 19 | + $feeds = FeaturedFeeds::getFeeds( $langCode, '' ); |
20 | 20 | if ( !isset( $feeds[$feedName] ) ) { |
21 | 21 | $out->showErrorPage( 'error', 'ffeed-feed-not-found', array( $feedName ) ); |
22 | 22 | return; |
— | — | @@ -54,8 +54,10 @@ |
55 | 55 | } |
56 | 56 | |
57 | 57 | private function displayItem( FeaturedFeedItem $item ) { |
| 58 | + global $wgContLang; |
58 | 59 | $out = $this->getOutput(); |
59 | | - $out->setPageTitle( $item->getRawTitle() ); |
| 60 | + // The language converter converts page content automatically but not page title. |
| 61 | + $out->setPageTitle( $wgContLang->convert( $item->getRawTitle() ) ); |
60 | 62 | $out->addHTML( $item->getRawText() ); |
61 | 63 | } |
62 | 64 | } |