From: Roan Kattouw Date: Tue, 1 Nov 2011 16:25:26 +0000 (+0000) Subject: Revert r101488, breaks parser test. Add a comment explaining why there is no caching... X-Git-Tag: 1.31.0-rc.0~26778 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=698f9e9c00e5b52462e7dfe402895839932e190b;p=lhc%2Fweb%2Fwiklou.git Revert r101488, breaks parser test. Add a comment explaining why there is no caching currently being done, and document the fact that the hook is called a zillion times in hooks.txt --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 33bc594d26..506145a675 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2032,7 +2032,10 @@ $user: User to get groups for &$rights: Array of rights, which may be added to. 'UserGetDefaultOptions': after fetching the core default, this hook is ran -right before returning the options to the caller. +right before returning the options to the caller. WARNING: this hook is +called for every call to User::getDefaultOptions(), which means it's +potentially called dozens or hundreds of times. You may want to cache +the results of non-trivial operations in your hook function for this reason. &$defaultOptions: Array of preference keys and their default values. 'UserGetEmail': called when getting an user email address diff --git a/includes/User.php b/includes/User.php index 973a304c51..b0d291d8d4 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1207,10 +1207,6 @@ class User { */ public static function getDefaultOptions() { global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin; - static $defOpt = null; - if ( $defOpt !== null ) { - return $defOpt; - } $defOpt = $wgDefaultUserOptions; # default language setting @@ -1222,6 +1218,12 @@ 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;