Commit graph

3 commits

Author SHA1 Message Date
Tim Starling
d36ea70309 Fix some PHPStorm inspections (#1)
* Triple backslash in regex should really be quadruple backslash
* Using the returned value of a void method
* Immediately overwritten array keys
* Duplicate array keys
* Foreach variable reuse
* sprintf() with too many params
* Incorrect reference usage

Change-Id: I3c649b543c9561a1614058c50f3847f663ff04df
2023-03-25 00:19:33 +00:00
Tim Starling
0b12f8b698 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
2022-11-09 12:57:23 +11:00
Timo Tijhof
75ccdc6147 languages: Move default $wgNamespaceAliases to MessagesEn.php
These are not configuration but business logic, similar to the
canonical names that are in NamespaceInfo.php, these must always
exist and cannot be altered or unset.

They were previously unconditionally assigned during all requests
in Setup.php and passed down as "site configuration".

Changes:

* Move them to MessagesEn.php where they can be cached and
  processed the same way as other core-provided aliases.

  Document and confirm with tests that this is a mergeable
  attribute that follows the language chain.

* Remove the duplicated code in a few places that was reading
  this variable + Language::getNamespaceAliases(), to instead
  just call the latter and move the logic there, centralised,
  and tested.

  In doing so I noticed that these were applied in an
  inconsistent order. Sometimes the config won, sometimes not.
  There's no obvious right or wrong way here, but I've chosen
  to standardise on the way that Language::getNamespaceIds() did
  it, which is that config wins. This because that method seems
  to be most widely used of the three (it decides how URLs and
  titles are parsed), and thus the one I least want to change
  the behaviour of.

* Document that $wgNamespaceAliases may only be used to
  define (extra) aliases, it is and never was a way to access
  the complete list of aliases.

Bug: T189966
Change-Id: Ibb14181aba8c1b509264ed40523e9ab4000fd71a
2020-03-14 19:27:40 +00:00