Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php |
— | — | @@ -1,6 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class FeaturedFeeds { |
| 5 | + private static $allInContLang = null; |
| 6 | + |
5 | 7 | /** |
6 | 8 | * Returns the list of feeds |
7 | 9 | * |
— | — | @@ -8,10 +10,10 @@ |
9 | 11 | * @return array Feeds in format of 'name' => array of FeedItem |
10 | 12 | */ |
11 | 13 | public static function getFeeds( $langCode ) { |
12 | | - global $wgMemc, $wgContLang; |
| 14 | + global $wgMemc, $wgLangCode; |
13 | 15 | |
14 | | - if ( !$langCode ) { |
15 | | - $langCode = $wgContLang->getCode(); |
| 16 | + if ( !$langCode || self::allInContentLanguage() ) { |
| 17 | + $langCode = $wgLangCode; |
16 | 18 | } |
17 | 19 | static $cache = array(); |
18 | 20 | if ( isset( $cache[$langCode] ) ) { |
— | — | @@ -44,21 +46,37 @@ |
45 | 47 | */ |
46 | 48 | private static function getFeedDefinitions() { |
47 | 49 | global $wgFeaturedFeeds, $wgFeaturedFeedsDefaults; |
48 | | - $feedDefs = $wgFeaturedFeeds; |
49 | | - wfRunHooks( 'FeaturedFeeds::getFeeds', array( &$feedDefs ) ); |
| 50 | + static $feedDefs = false; |
| 51 | + if ( !$feedDefs ) { |
| 52 | + $feedDefs = $wgFeaturedFeeds; |
| 53 | + wfRunHooks( 'FeaturedFeeds::getFeeds', array( &$feedDefs ) ); |
50 | 54 | |
51 | | - // fill defaults |
52 | | - foreach ( $feedDefs as $name => $opts ) { |
53 | | - foreach ( $wgFeaturedFeedsDefaults as $setting => $value ) { |
54 | | - if ( !isset( $opts[$setting] ) ) { |
55 | | - $feedDefs[$name][$setting] = $value; |
| 55 | + // fill defaults |
| 56 | + self::$allInContLang = true; |
| 57 | + foreach ( $feedDefs as $name => $opts ) { |
| 58 | + foreach ( $wgFeaturedFeedsDefaults as $setting => $value ) { |
| 59 | + if ( !isset( $opts[$setting] ) ) { |
| 60 | + $feedDefs[$name][$setting] = $value; |
| 61 | + } |
56 | 62 | } |
| 63 | + self::$allInContLang = self::$allInContLang && !$feedDefs[$name]['inUserLanguage']; |
57 | 64 | } |
58 | 65 | } |
59 | 66 | return $feedDefs; |
60 | 67 | } |
61 | 68 | |
62 | 69 | /** |
| 70 | + * Returns whether all feeds are in content language |
| 71 | + * @return Boolean |
| 72 | + */ |
| 73 | + public static function allInContentLanguage() { |
| 74 | + if ( is_null( self::$allInContLang ) ) { |
| 75 | + self::getFeedDefinitions(); |
| 76 | + } |
| 77 | + return self::$allInContLang; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
63 | 81 | * Adds feeds to the page header |
64 | 82 | * |
65 | 83 | * @param OutputPage $out |
— | — | @@ -146,8 +164,6 @@ |
147 | 165 | * @throws MWException |
148 | 166 | */ |
149 | 167 | private static function getFeedsInternal( $langCode ) { |
150 | | - global $wgContLang; |
151 | | - |
152 | 168 | wfProfileIn( __METHOD__ ); |
153 | 169 | $feedDefs = self::getFeedDefinitions(); |
154 | 170 | |