diff options
author | Tim Starling <tstarling@wikimedia.org> | 2022-11-09 11:47:13 +1100 |
---|---|---|
committer | Tim Starling <tstarling@wikimedia.org> | 2022-11-09 12:57:23 +1100 |
commit | 0b12f8b69880d108db9035176532c891e8a75f79 (patch) | |
tree | 7828406885aa27acb7958e7e652c76986b1b7c03 | |
parent | ebd13491b7595fe113106822fd2e7eec70eb0eb9 (diff) | |
download | mediawikicore-0b12f8b69880d108db9035176532c891e8a75f79.tar.gz mediawikicore-0b12f8b69880d108db9035176532c891e8a75f79.zip |
Improve LocalisationCache post-merge validation check
When I deleted MessagesEn.php, neither the exception on line 498 nor
the exception modified here was thrown. Extensions register namespaces,
hiding the lack of default namespaces. If namespaceNames was missing,
RHS line 1004 would raise a warning but would create the key.
Also, phan was complaining that the key might be absent.
So, use 'rtl' instead of 'namespaceNames' as our test for data validity,
since it's less likely to be overridden by extensions. Move the check up
above the normalization of individual keys. Use isset() to satisfy phan.
Bug: T322278
Change-Id: I44c7506205fbe9ba6ffbd1155a6cdcf3ff0960eb
-rw-r--r-- | includes/language/LocalisationCache.php | 11 | ||||
-rw-r--r-- | tests/phpunit/data/messages/Messages_en.php | 1 |
2 files changed, 6 insertions, 6 deletions
diff --git a/includes/language/LocalisationCache.php b/includes/language/LocalisationCache.php index f48b90bbc1ad..b27e44d5f655 100644 --- a/includes/language/LocalisationCache.php +++ b/includes/language/LocalisationCache.php @@ -985,6 +985,11 @@ class LocalisationCache { } } + if ( !isset( $allData['rtl'] ) ) { + throw new MWException( __METHOD__ . ': Localisation data failed validation check! ' . + 'Check that your languages/messages/MessagesEn.php file is intact.' ); + } + # Add cache dependencies for any referenced globals $deps['wgExtensionMessagesFiles'] = new GlobalDependency( 'wgExtensionMessagesFiles' ); // The 'MessagesDirs' config setting is used in LocalisationCache::getMessagesDirs(). @@ -1026,12 +1031,6 @@ class LocalisationCache { $unused = true; // Used to be $purgeBlobs, removed in 1.34 $this->hookRunner->onLocalisationCacheRecache( $this, $code, $allData, $unused ); - // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive - if ( $allData['namespaceNames'] === null ) { - throw new MWException( __METHOD__ . ': Localisation data failed validation check! ' . - 'Check that your languages/messages/MessagesEn.php file is intact.' ); - } - # Set the preload key $allData['preload'] = $this->buildPreload( $allData ); diff --git a/tests/phpunit/data/messages/Messages_en.php b/tests/phpunit/data/messages/Messages_en.php index c713b131c725..aa56eeda8104 100644 --- a/tests/phpunit/data/messages/Messages_en.php +++ b/tests/phpunit/data/messages/Messages_en.php @@ -9,3 +9,4 @@ $namespaceNames = []; $specialPageAliases = []; $preloadedMessages = []; +$rtl = false; |