jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/365438 )

Change subject: Make SpecialGoToLinkedPage accept a chain of sites instead of 
one
......................................................................


Make SpecialGoToLinkedPage accept a chain of sites instead of one

Bug: T166473
Change-Id: I821e645ac13d516397e5be6fc949e09614d6cfbf
---
M repo/includes/Specials/SpecialGoToLinkedPage.php
M repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
2 files changed, 23 insertions(+), 13 deletions(-)

Approvals:
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, approved



diff --git a/repo/includes/Specials/SpecialGoToLinkedPage.php 
b/repo/includes/Specials/SpecialGoToLinkedPage.php
index f54599c..7cdeb06 100644
--- a/repo/includes/Specials/SpecialGoToLinkedPage.php
+++ b/repo/includes/Specials/SpecialGoToLinkedPage.php
@@ -79,15 +79,18 @@
        /**
         * @param string|null $subPage
         *
-        * @return array array( string $site, string $itemString )
+        * @return array array( string[] $sites, string $itemString )
         */
        private function getArguments( $subPage ) {
                $request = $this->getRequest();
                $parts = ( $subPage === '' ) ? [] : explode( '/', $subPage, 2 );
-               $site = trim( $request->getVal( 'site', isset( $parts[0] ) ? 
$parts[0] : '' ) );
+               $sites = explode(
+                       ',',
+                       trim( $request->getVal( 'site', isset( $parts[0] ) ? 
$parts[0] : '' ) )
+               );
                $itemString = trim( $request->getVal( 'itemid', isset( 
$parts[1] ) ? $parts[1] : 0 ) );
 
-               return [ $site, $itemString ];
+               return [ $sites, $itemString ];
        }
 
        /**
@@ -186,32 +189,34 @@
         */
        public function execute( $subPage ) {
                parent::execute( $subPage );
-               list( $site, $itemString ) = $this->getArguments( $subPage );
+               list( $sites, $itemString ) = $this->getArguments( $subPage );
 
-               if ( !empty( $site ) || !empty( $itemString ) ) {
-                       $url = $this->getTargetUrl( $site, $itemString );
-                       if ( null !== $url ) {
-                               $this->getOutput()->redirect( $url );
-                               return;
+               if ( !empty( $sites ) || !empty( $itemString ) ) {
+                       foreach ( $sites as $site ) {
+                               $url = $this->getTargetUrl( $site, $itemString 
);
+                               if ( $url !== null ) {
+                                       $this->getOutput()->redirect( $url );
+                                       return;
+                               }
                        }
                }
 
                $this->outputError();
-               $this->outputForm( $site, $itemString );
+               $this->outputForm( $sites, $itemString );
        }
 
        /**
         * Output a form via the context's OutputPage object to go to a
         * sitelink (linked page) for an item and site id.
         *
-        * @param string $site
+        * @param string[] $sites
         * @param string $itemString
         */
-       private function outputForm( $site, $itemString ) {
+       private function outputForm( array $sites, $itemString ) {
                $formDescriptor = [
                        'site' => [
                                'name' => 'site',
-                               'default' => $site ?: '',
+                               'default' => implode( ',', $sites ),
                                'type' => 'text',
                                'id' => 'wb-gotolinkedpage-sitename',
                                'size' => 12,
diff --git a/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
index 07c4c2f..9553676 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialGoToLinkedPageTest.php
@@ -144,6 +144,10 @@
                                'XXwiki/Q23', null, 'XXwiki', 'Q23',
                                '(wikibase-gotolinkedpage-error-page-not-found)'
                        ],
+                       'notFound3' => [
+                               'XXwiki,enwiki,zhwiki/Q23', null, 
'XXwiki,enwiki,zhwiki', 'Q23',
+                               '(wikibase-gotolinkedpage-error-page-not-found)'
+                       ],
                ];
        }
 
@@ -171,6 +175,7 @@
                $cases['found'] = [ 'dewiki/Q23', 
'http://dewiki.com/TestPageName' ];
                $cases['foundEntityRedirect'] = [ 'dewiki/Q24', 
'http://dewiki.com/TestPageName' ];
                $cases['foundWithSiteIdHack'] = [ 'de/Q23', 
'http://dewiki.com/TestPageName' ];
+               $cases['foundInFallbackChain'] = [ 'enwiki,dewiki,fawiki/Q23', 
'http://dewiki.com/TestPageName' ];
                return $cases;
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I821e645ac13d516397e5be6fc949e09614d6cfbf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: AnotherLadsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to