r110170 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110169‎ | r110170 | r110171 >
Date:21:14, 27 January 2012
Author:maxsem
Status:resolved (Comments)
Tags:
Comment:
Don't fragment cache if feeds aren't multilingual anyway
Modified paths:
  • /trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FeaturedFeeds/FeaturedFeeds.body.php
@@ -1,6 +1,8 @@
22 <?php
33
44 class FeaturedFeeds {
 5+ private static $allInContLang = null;
 6+
57 /**
68 * Returns the list of feeds
79 *
@@ -8,10 +10,10 @@
911 * @return array Feeds in format of 'name' => array of FeedItem
1012 */
1113 public static function getFeeds( $langCode ) {
12 - global $wgMemc, $wgContLang;
 14+ global $wgMemc, $wgLangCode;
1315
14 - if ( !$langCode ) {
15 - $langCode = $wgContLang->getCode();
 16+ if ( !$langCode || self::allInContentLanguage() ) {
 17+ $langCode = $wgLangCode;
1618 }
1719 static $cache = array();
1820 if ( isset( $cache[$langCode] ) ) {
@@ -44,21 +46,37 @@
4547 */
4648 private static function getFeedDefinitions() {
4749 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 ) );
5054
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+ }
5662 }
 63+ self::$allInContLang = self::$allInContLang && !$feedDefs[$name]['inUserLanguage'];
5764 }
5865 }
5966 return $feedDefs;
6067 }
6168
6269 /**
 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+ /**
6381 * Adds feeds to the page header
6482 *
6583 * @param OutputPage $out
@@ -146,8 +164,6 @@
147165 * @throws MWException
148166 */
149167 private static function getFeedsInternal( $langCode ) {
150 - global $wgContLang;
151 -
152168 wfProfileIn( __METHOD__ );
153169 $feedDefs = self::getFeedDefinitions();
154170

Sign-offs

UserFlagDate
Reedyinspected22:17, 27 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r110576Follow-up r110170: proper check for cachednessmaxsem15:16, 2 February 2012

Comments

#Comment by Liangent (talk | contribs)   13:26, 2 February 2012

When $wgFeaturedFeeds == array(), do we still want to run code inside if ( !$feedDefs ) { } again after it has already run?

#Comment by MaxSem (talk | contribs)   15:17, 2 February 2012

Thanks, fixed.

#Comment by Krinkle (talk | contribs)   02:28, 27 February 2012

This wasn't merged yet (I see no follow-ups). If that is the case, do we still need it? 1.19 was branched after this so it'll be in 1.19.0 and already is in 1.19wmf1. Untagging for now, feel free to re-tag.

Status & tagging log