Interwiki: Don't override interwiki map order
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 25 Apr 2017 20:36:06 +0000 (13:36 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 25 Apr 2017 22:38:32 +0000 (15:38 -0700)
commit0548f1902cb308c70541ff0f4ffb2feb24d03066
treed6dd8e8d94783e1be1ac6774c791cbfd79282b8b
parent273eea7357c546d1a1aafd73320e10e8ddac79eb
Interwiki: Don't override interwiki map order

The ksort() here was causing the order to be enforced as
alphabetical instead of preserving the original order.

The order usually doesn't matter, except with regards to handling
of duplicates. Due to Parsoid normalising external links to interwiki
links, it has to do a reverse lookup. In doing so it has to decide
which one to prefer. It currently picks the first match from the
API request for meta=siteinfo&siprop=interwikimap, which didn't
match the defined order in the actual Interwiki map due to ksort()
being called in getAllPrefixes().

Sort in this function was originally introduced in 2010 with
commit 844e7c83e4 (2011; r92528; T21838), which is otherwise unrelated
and left no rationale.

The existing unit tests needed to be adjusted slightly as they
assumed alphabetical order. While it appeared they were also defined
in alphabetical order, this was merely the order of the variable
creation. The effective order is preserved within locals and globals,
but overall globals come before locals.

Also removed the duplicate test for Hash and CDB in InterwikiTest
that belongs in ClassicInterwikiLookupTest instead.

Bug: T145337
Change-Id: I7348748801cbdf16c6ceea5b0654fc174b79707e
includes/interwiki/ClassicInterwikiLookup.php
tests/phpunit/includes/interwiki/ClassicInterwikiLookupTest.php
tests/phpunit/includes/interwiki/InterwikiTest.php