Language: Don't return aliases to namespaces that don't exist
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 2 Oct 2018 21:18:38 +0000 (17:18 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 2 Oct 2018 21:18:38 +0000 (17:18 -0400)
On a multi-wiki server using a l10n cache, the cache will probably
include aliases from all extensions enabled for any wiki while the
namespaces themselves will only be defined on the wikis where the
extension is loaded.

Bug: T206030
Change-Id: I985dfa3eb17944d5fc0c5be0979be21504fb1341

languages/Language.php

index 5897241..8104b2c 100644 (file)
@@ -703,6 +703,14 @@ class Language {
                        }
 
                        $this->namespaceAliases = $aliases + $convertedNames;
+
+                       # Filter out aliases to namespaces that don't exist, e.g. from extensions
+                       # that aren't loaded here but are included in the l10n cache.
+                       # (array_intersect preserves keys from its first argument)
+                       $this->namespaceAliases = array_intersect(
+                               $this->namespaceAliases,
+                               array_keys( $this->getNamespaces() )
+                       );
                }
 
                return $this->namespaceAliases;