Don't use SearchEngineConfig::searchableNamespaces in User::getDefaultOptions.
authordaniel <daniel.kinzler@wikimedia.de>
Sat, 6 Aug 2016 13:25:06 +0000 (15:25 +0200)
committerDaniel Kinzler <daniel.kinzler@wikimedia.de>
Sat, 6 Aug 2016 14:56:23 +0000 (14:56 +0000)
Default options should be the same for all users. SearchEngineConfig::searchableNamespaces
however calls a hok that allows the set of searchable namespaces to be adjusted per user,
e.g. based on the user groups or permissions, like Extension:Lockdown does.

Since SearchableNamespace hook handlers may access the global user objects, problems arise
when it is that global user object trying to initialize itself that triggers the call to
User::getDefaultOptions. This can cause recursive calls to User::load(), see I6d1b9fe07.

Furthermore, these seems to be no need to actively record the searchable namespaces beyond
the contents of $wgNamespacesToBeSearchedDefault. If a 'searchNs' option is absent, it is
treated as disabled.

Bug: T142295
Bug: T137051
Change-Id: I5f6bcdfc588acef0873136bf338d79890863e009

includes/user/User.php

index 8d3fcea..4c5af34 100644 (file)
@@ -1578,9 +1578,12 @@ class User implements IDBAccessObject {
                foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
                        $defOpt[$langCode == $wgContLang->getCode() ? 'variant' : "variant-$langCode"] = $langCode;
                }
-               $namespaces = MediaWikiServices::getInstance()->getSearchEngineConfig()->searchableNamespaces();
-               foreach ( $namespaces as $nsnum => $nsname ) {
-                       $defOpt['searchNs' . $nsnum] = !empty( $wgNamespacesToBeSearchedDefault[$nsnum] );
+
+               // NOTE: don't use SearchEngineConfig::getSearchableNamespaces here,
+               // since extensions may change the set of searchable namespaces depending
+               // on user groups/permissions.
+               foreach ( $wgNamespacesToBeSearchedDefault as $nsnum => $val ) {
+                       $defOpt['searchNs' . $nsnum] = (boolean)$val;
                }
                $defOpt['skin'] = Skin::normalizeKey( $wgDefaultSkin );