From: Marius Hoch Date: Mon, 29 Oct 2012 00:21:20 +0000 (+0100) Subject: Cache the result of User::getDefaultOptions X-Git-Tag: 1.31.0-rc.0~21823^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=adf6e8fcdd56c5ab76fb757630f0e772ec2853c5;p=lhc%2Fweb%2Fwiklou.git Cache the result of User::getDefaultOptions Caching the result of User::getDefaultOptions as it always returns the same data, despite for unit tests, which can't use the cached values as they do evil things with variables being constant in normal operation. Change-Id: I02d557006d2f879e7ce510a5e47fa1543baab8a6 --- diff --git a/includes/User.php b/includes/User.php index e210eba6cf..770b28eed9 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1216,6 +1216,14 @@ class User { public static function getDefaultOptions() { global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin; + static $defOpt = null; + if ( !defined( 'MW_PHPUNIT_TEST' ) && $defOpt !== null ) { + // Disabling this for the unit tests, as they rely on being able to change $wgContLang + // mid-request and see that change reflected in the return value of this function. + // Which is insane and would never happen during normal MW operation + return $defOpt; + } + $defOpt = $wgDefaultUserOptions; # default language setting $defOpt['variant'] = $wgContLang->getCode(); @@ -1225,12 +1233,6 @@ class User { } $defOpt['skin'] = $wgDefaultSkin; - // FIXME: Ideally we'd cache the results of this function so the hook is only run once, - // but that breaks the parser tests because they rely on being able to change $wgContLang - // mid-request and see that change reflected in the return value of this function. - // Which is insane and would never happen during normal MW operation, but is also not - // likely to get fixed unless and until we context-ify everything. - // See also https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101488#c25275 wfRunHooks( 'UserGetDefaultOptions', array( &$defOpt ) ); return $defOpt;