Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351366 )

Change subject: Fix inconsistent spec of InterwikiLookup::getAlPrefixes.
......................................................................

Fix inconsistent spec of InterwikiLookup::getAlPrefixes.

The documented return type was not what existing callers expected,
and not what the default implementation actually returned.

This patch fixes the interface documentation and the behavior of
an alternative implementation.

Change-Id: Ib09bffeba3ddc5b43da1c7c299f1fa946be4e2e2
---
M includes/interwiki/InterwikiLookup.php
M includes/interwiki/InterwikiLookupAdapter.php
M tests/phpunit/includes/interwiki/InterwikiLookupAdapterTest.php
3 files changed, 41 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/66/351366/1

diff --git a/includes/interwiki/InterwikiLookup.php 
b/includes/interwiki/InterwikiLookup.php
index d0a7719..5a9af1a 100644
--- a/includes/interwiki/InterwikiLookup.php
+++ b/includes/interwiki/InterwikiLookup.php
@@ -47,10 +47,18 @@
        public function fetch( $prefix );
 
        /**
-        * Returns all interwiki prefixes
+        * Returns information about all interwiki prefixes, in the form of rows
+        * of the interwiki table. Each row may have the following keys:
+        *
+        * - iw_prefix: the prefix. Always present.
+        * - iw_url: the URL to use for linking, with $1 as a placeholder for 
the target page. Always present.
+        * - iw_api: the URL of the API (of any). Optional.
+        * - iw_wikiid: the wiki ID (usually the database name for local 
wikis). Optional.
+        * - iw_local: whether the wiki is local, and the "magic redirect" 
mechanism should apply. Defaults to false.
+        * - iw_trans: whether "scary translcusion" is allowed for this site. 
Defaults to false.
         *
         * @param string|null $local If set, limits output to local/non-local 
interwikis
-        * @return string[] List of prefixes
+        * @return array[] interwiki rows.
         */
        public function getAllPrefixes( $local = null );
 
diff --git a/includes/interwiki/InterwikiLookupAdapter.php 
b/includes/interwiki/InterwikiLookupAdapter.php
index 60d6f43..3baea1a 100644
--- a/includes/interwiki/InterwikiLookupAdapter.php
+++ b/includes/interwiki/InterwikiLookupAdapter.php
@@ -87,16 +87,20 @@
         * See InterwikiLookup::getAllPrefixes
         *
         * @param string|null $local If set, limits output to local/non-local 
interwikis
-        * @return string[] List of prefixes
+        * @return array[] interwiki rows
         */
        public function getAllPrefixes( $local = null ) {
-               if ( $local === null ) {
-                       return array_keys( $this->getInterwikiMap() );
-               }
                $res = [];
                foreach ( $this->getInterwikiMap() as $interwikiId => 
$interwiki ) {
-                       if ( $interwiki->isLocal() === $local ) {
-                               $res[] = $interwikiId;
+                       if ( $local === null || $interwiki->isLocal() === 
$local ) {
+                               $res[] = [
+                                       'iw_prefix' => $interwikiId,
+                                       'iw_url' => $interwiki->getURL(),
+                                       'iw_api' => $interwiki->getAPI(),
+                                       'iw_wikiid' => $interwiki->getWikiID(),
+                                       'iw_local' => $interwiki->isLocal(),
+                                       'iw_trans' => 
$interwiki->isTranscludable(),
+                               ];
                        }
                }
                return $res;
diff --git a/tests/phpunit/includes/interwiki/InterwikiLookupAdapterTest.php 
b/tests/phpunit/includes/interwiki/InterwikiLookupAdapterTest.php
index 4754b04..4dde20fd 100644
--- a/tests/phpunit/includes/interwiki/InterwikiLookupAdapterTest.php
+++ b/tests/phpunit/includes/interwiki/InterwikiLookupAdapterTest.php
@@ -60,20 +60,37 @@
        }
 
        public function testGetAllPrefixes() {
+               $foo = [
+                       'iw_prefix' => 'foo',
+                       'iw_url' => '',
+                       'iw_api' => '',
+                       'iw_wikiid' => 'foobar',
+                       'iw_local' => false,
+                       'iw_trans' => false,
+               ];
+               $enwt = [
+                       'iw_prefix' => 'enwt',
+                       'iw_url' => 'https://en.wiktionary.org/wiki/$1',
+                       'iw_api' => 'https://en.wiktionary.org/w/api.php',
+                       'iw_wikiid' => 'enwiktionary',
+                       'iw_local' => true,
+                       'iw_trans' => false,
+               ];
+
                $this->assertEquals(
-                       [ 'foo', 'enwt' ],
+                       [ $foo, $enwt ],
                        $this->interwikiLookup->getAllPrefixes(),
                        'getAllPrefixes()'
                );
 
                $this->assertEquals(
-                       [ 'foo' ],
+                       [ $foo ],
                        $this->interwikiLookup->getAllPrefixes( false ),
                        'get external prefixes'
                );
 
                $this->assertEquals(
-                       [ 'enwt' ],
+                       [ $enwt ],
                        $this->interwikiLookup->getAllPrefixes( true ),
                        'get local prefixes'
                );
@@ -92,7 +109,7 @@
        }
 
        private function getSites() {
-               $sites = [];
+               $sites = [ ];
 
                $site = new Site();
                $site->setGlobalId( 'foobar' );

-- 
To view, visit https://gerrit.wikimedia.org/r/351366
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib09bffeba3ddc5b43da1c7c299f1fa946be4e2e2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to