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

Change subject: Link to Special:EntityPage instead of getting namespace 
settings in RepoLinker
......................................................................


Link to Special:EntityPage instead of getting namespace settings in RepoLinker

Bug: T153769
Change-Id: I89a33cb5c5bdc194fdb1e3cd77a13ee5b63b7eef
---
M client/includes/Api/ApiListEntityUsage.php
M client/includes/Api/ApiPropsEntityUsage.php
M client/includes/RepoLinker.php
M client/includes/WikibaseClient.php
M client/tests/phpunit/includes/Hooks/DeletePageNoticeCreatorTest.php
M client/tests/phpunit/includes/Hooks/MovePageNoticeTest.php
M client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
M client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
M client/tests/phpunit/includes/RepoLinkerTest.php
9 files changed, 30 insertions(+), 134 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, but someone else must approve
  WMDE-leszek: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/includes/Api/ApiListEntityUsage.php 
b/client/includes/Api/ApiListEntityUsage.php
index 6296626..66845ea 100644
--- a/client/includes/Api/ApiListEntityUsage.php
+++ b/client/includes/Api/ApiListEntityUsage.php
@@ -135,7 +135,7 @@
                $entry[$row->eu_entity_id] = [ 'aspects' => [ $row->eu_aspect ] 
];
                if ( $url ) {
                        $entry[$row->eu_entity_id]['url'] = 
$this->repoLinker->getPageUrl(
-                               'Special:EntityData/' . $row->eu_entity_id );
+                               'Special:EntityPage/' . $row->eu_entity_id );
                }
                ApiResult::setIndexedTagName(
                        $entry[$row->eu_entity_id]['aspects'], 'aspect'
diff --git a/client/includes/Api/ApiPropsEntityUsage.php 
b/client/includes/Api/ApiPropsEntityUsage.php
index a67a820..c3fe617 100644
--- a/client/includes/Api/ApiPropsEntityUsage.php
+++ b/client/includes/Api/ApiPropsEntityUsage.php
@@ -79,7 +79,7 @@
                                $entry[$row->eu_entity_id] = [ 'aspects' => [ 
$row->eu_aspect ] ];
                                if ( isset( $prop['url'] ) ) {
                                        $entry[$row->eu_entity_id]['url'] = 
$this->repoLinker->getPageUrl(
-                                               'Special:EntityData/' . 
$row->eu_entity_id );
+                                               'Special:EntityPage/' . 
$row->eu_entity_id );
                                }
                                ApiResult::setIndexedTagName(
                                        $entry[$row->eu_entity_id]['aspects'], 
'aspect'
diff --git a/client/includes/RepoLinker.php b/client/includes/RepoLinker.php
index 93a575b..7e64d96 100644
--- a/client/includes/RepoLinker.php
+++ b/client/includes/RepoLinker.php
@@ -18,46 +18,15 @@
 
        private $scriptPath;
 
-       private $namespaces;
-
        /**
         * @param string $baseUrl
         * @param string $articlePath
         * @param string $scriptPath
-        * @param string[] $namespaces // repoNamespaces setting
         */
-       public function __construct( $baseUrl, $articlePath, $scriptPath, array 
$namespaces ) {
+       public function __construct( $baseUrl, $articlePath, $scriptPath ) {
                $this->baseUrl = $baseUrl;
                $this->articlePath = $articlePath;
                $this->scriptPath = $scriptPath;
-               $this->namespaces = $namespaces;
-       }
-
-       /**
-        * Get namespace of an entity in string format
-        * @todo: need a better way to have knowledge of repo namespace mappings
-        *
-        * @param string $entityType
-        *
-        * @return string
-        * @throws InvalidArgumentException
-        */
-       public function getNamespace( $entityType ) {
-               if ( !array_key_exists( $entityType, $this->namespaces ) ) {
-                       throw new InvalidArgumentException( "No namespace 
configured for entities of type $entityType" );
-               }
-
-               return $this->namespaces[$entityType];
-       }
-
-       /**
-        * @param EntityId $entityId
-        *
-        * @return string
-        */
-       public function getEntityNamespace( EntityId $entityId ) {
-               $entityType = $entityId->getEntityType();
-               return $this->getNamespace( $entityType );
        }
 
        /**
@@ -131,23 +100,13 @@
        }
 
        /**
-        * Get the full title as string, including namespace for an entity
-        * @todo: use a more robust mechanism for building entity titles
-        *   if efficient enough, maybe EntityTitleLookup.
-        *
         * @param EntityId $entityId
         *
         * @return string
         */
        public function getEntityTitle( EntityId $entityId ) {
-               $entityNamespace = $this->getEntityNamespace( $entityId );
                $title = $entityId->getSerialization();
-
-               if ( $entityNamespace ) {
-                       $title = $entityNamespace . ':' . $title;
-               }
-
-               return $title;
+               return 'Special:EntityPage/' . $title;
        }
 
        /**
diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index d2fd9b3..ccd821c 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -494,8 +494,7 @@
                return new RepoLinker(
                        $this->settings->getSetting( 'repoUrl' ),
                        $this->settings->getSetting( 'repoArticlePath' ),
-                       $this->settings->getSetting( 'repoScriptPath' ),
-                       $this->settings->getSetting( 'repoNamespaces' )
+                       $this->settings->getSetting( 'repoScriptPath' )
                );
        }
 
diff --git 
a/client/tests/phpunit/includes/Hooks/DeletePageNoticeCreatorTest.php 
b/client/tests/phpunit/includes/Hooks/DeletePageNoticeCreatorTest.php
index 5aa4d9c..94a4102 100644
--- a/client/tests/phpunit/includes/Hooks/DeletePageNoticeCreatorTest.php
+++ b/client/tests/phpunit/includes/Hooks/DeletePageNoticeCreatorTest.php
@@ -30,12 +30,8 @@
                $baseUrl = 'http://www.example.com';
                $articlePath = '/wiki/$1';
                $scriptPath = '';
-               $repoNamespaces = array(
-                       'item' => '',
-                       'property' => 'Property:'
-               );
 
-               return new RepoLinker( $baseUrl, $articlePath, $scriptPath, 
$repoNamespaces );
+               return new RepoLinker( $baseUrl, $articlePath, $scriptPath );
        }
 
        /**
@@ -77,7 +73,7 @@
 
        protected function getParsedMessage( $messageKey ) {
                return '<div class="plainlinks">'
-                       . wfMessage( $messageKey, 
'http://www.example.com/wiki/Q4880' )
+                       . wfMessage( $messageKey, 
'http://www.example.com/wiki/Special:EntityPage/Q4880' )
                                ->inLanguage( 'de' )->parse()
                        . '</div>';
        }
diff --git a/client/tests/phpunit/includes/Hooks/MovePageNoticeTest.php 
b/client/tests/phpunit/includes/Hooks/MovePageNoticeTest.php
index 23806bf..46283e3 100644
--- a/client/tests/phpunit/includes/Hooks/MovePageNoticeTest.php
+++ b/client/tests/phpunit/includes/Hooks/MovePageNoticeTest.php
@@ -33,12 +33,8 @@
                $baseUrl = 'http://www.example.com';
                $articlePath = '/wiki/$1';
                $scriptPath = '';
-               $repoNamespaces = array(
-                       'item' => '',
-                       'property' => 'Property:'
-               );
 
-               return new RepoLinker( $baseUrl, $articlePath, $scriptPath, 
$repoNamespaces );
+               return new RepoLinker( $baseUrl, $articlePath, $scriptPath );
        }
 
        /**
@@ -97,7 +93,7 @@
 
        protected function getParsedMessage( $messageKey ) {
                return '<div id="wbc-after-page-move" class="plainlinks">'
-                       . wfMessage( $messageKey, 
'http://www.example.com/wiki/Q4880' )
+                       . wfMessage( $messageKey, 
'http://www.example.com/wiki/Special:EntityPage/Q4880' )
                                ->inLanguage( 'de' )->parse()
                        . '</div>';
        }
diff --git 
a/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php 
b/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
index 3ae4ccd..eb7007c 100644
--- a/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
+++ b/client/tests/phpunit/includes/RecentChanges/ChangeLineFormatterTest.php
@@ -45,11 +45,7 @@
                $this->repoLinker = new RepoLinker(
                        'http://www.wikidata.org',
                        '/wiki/$1',
-                       '/w',
-                       array(
-                               'item' => '',
-                               'property' => 'Property'
-                       )
+                       '/w'
                );
        }
 
@@ -162,8 +158,8 @@
 
        public function getEditSiteLinkPatterns() {
                return array(
-                       '/title=Q4&amp;curid=5&amp;action=history/',
-                       '/title=Q4&amp;curid=5&amp;diff=92&amp;oldid=90/',
+                       
'/title=Special%3AEntityPage%2FQ4&amp;curid=5&amp;action=history/',
+                       
'/title=Special%3AEntityPage%2FQ4&amp;curid=5&amp;diff=92&amp;oldid=90/',
                        '/<span class="comment">\('
                                . '‎<span dir="auto"><span 
class="autocomment">Changed claim: <\/span><\/span> '
                                . '<a .*?>Property:P213<\/a>: <a .*?>Q850<\/a>'
@@ -188,7 +184,9 @@
                        'edit-entitylink' => allOf(
                                withTagName( 'a' ),
                                withClass( 'wb-entity-link' ),
-                               withAttribute( 'href' )->havingValue( 
'http://www.wikidata.org/wiki/Q4' ),
+                               withAttribute( 'href' )->havingValue(
+                                       
'http://www.wikidata.org/wiki/Special:EntityPage/Q4'
+                               ),
                                havingTextContents( 'Q4' )
                        ),
                        'edit-changeslist-date' => allOf(
diff --git a/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php 
b/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
index d5d60fd..929a5ac 100644
--- a/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
+++ b/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
@@ -26,18 +26,17 @@
                $baseUrl = 'http://www.example.com';
                $articlePath = '/wiki/$1';
                $scriptPath = '';
-               $repoNamespaces = array(
-                       'item' => '',
-                       'property' => 'Property:'
-               );
 
-               return new RepoLinker( $baseUrl, $articlePath, $scriptPath, 
$repoNamespaces );
+               return new RepoLinker( $baseUrl, $articlePath, $scriptPath );
        }
 
        public function getLinksProvider() {
                $prefixedId = 'q9000';
 
-               $href = preg_quote( 
'http://www.example.com/wiki/Q9000#sitelinks-wikipedia', '/' );
+               $href = preg_quote(
+                       
'http://www.example.com/wiki/Special:EntityPage/Q9000#sitelinks-wikipedia',
+                       '/'
+               );
                $editLinks = preg_quote( wfMessage( 'wikibase-editlinks' 
)->text(), '/' );
                $addLinks = preg_quote( wfMessage( 'wikibase-linkitem-addlinks' 
)->text(), '/' );
 
diff --git a/client/tests/phpunit/includes/RepoLinkerTest.php 
b/client/tests/phpunit/includes/RepoLinkerTest.php
index 95267f1..9814189 100644
--- a/client/tests/phpunit/includes/RepoLinkerTest.php
+++ b/client/tests/phpunit/includes/RepoLinkerTest.php
@@ -25,28 +25,16 @@
                                'baseUrl' => '//www.example.com',
                                'articlePath' => '/wiki/$1',
                                'scriptPath' => '',
-                               'repoNamespaces' => array(
-                                       'item' => '',
-                                       'property' => 'Property'
-                               )
                        ),
                        array(
                                'baseUrl' => '//example.com/',
                                'articlePath' => '/wiki/$1',
                                'scriptPath' => '',
-                               'repoNamespaces' => array(
-                                       'item' => '',
-                                       'property' => 'Property'
-                               )
                        ),
                        array(
                                'baseUrl' => 'http://www.example.com',
                                'articlePath' => '/wiki/$1',
                                'scriptPath' => '/w',
-                               'repoNamespaces' => array(
-                                       'item' => 'Item',
-                                       'property' => 'Property'
-                               )
                        )
                );
        }
@@ -55,45 +43,7 @@
                return new RepoLinker(
                        $settings['baseUrl'],
                        $settings['articlePath'],
-                       $settings['scriptPath'],
-                       $settings['repoNamespaces']
-               );
-       }
-
-       /**
-        * @dataProvider namespaceProvider
-        */
-       public function testGetNamespace( $expected, array $settings, 
$entityType ) {
-               $repoLinker = $this->getRepoLinkerForSettings( $settings );
-               $namespace = $repoLinker->getNamespace( $entityType );
-
-               $this->assertEquals( $expected, $namespace );
-       }
-
-       public function namespaceProvider() {
-               $settings = $this->getRepoSettings();
-
-               return array(
-                       array( '', $settings[0], 'item' ),
-                       array( 'Property', $settings[1], 'property' ),
-                       array( 'Item', $settings[2], 'item' )
-               );
-       }
-
-       /**
-        * @dataProvider invalidNamespaceProvider
-        */
-       public function testGetNamespaceWithInvalid_ThrowsException( array 
$settings, $entityType ) {
-               $repoLinker = $this->getRepoLinkerForSettings( $settings );
-               $this->setExpectedException( InvalidArgumentException::class );
-               $repoLinker->getNamespace( $entityType );
-       }
-
-       public function invalidNamespaceProvider() {
-               $settings = $this->getRepoSettings();
-
-               return array(
-                       array( $settings[0], 'chocolate' )
+                       $settings['scriptPath']
                );
        }
 
@@ -111,11 +61,10 @@
                $propertyId = new PropertyId( 'P472' );
                $settings = $this->getRepoSettings();
 
-               return array(
-                       array( 'Q388', $settings[0], $itemId ),
-                       array( 'Item:Q388', $settings[2], $itemId ),
-                       array( 'Property:P472', $settings[0], $propertyId )
-               );
+               return [
+                       [ 'Special:EntityPage/Q388', $settings[0], $itemId ],
+                       [ 'Special:EntityPage/P472', $settings[0], $propertyId ]
+               ];
        }
 
        /**
@@ -204,19 +153,19 @@
 
                return array(
                        array(
-                               '<a class="extiw wb-entity-link" 
href="//example.com/wiki/Q730">Q730</a>',
+                               '<a class="extiw wb-entity-link" 
href="//example.com/wiki/Special:EntityPage/Q730">Q730</a>',
                                $settings[1],
                                new ItemId( 'Q730' ),
                                array()
                        ),
                        array(
-                               '<a class="extiw wb-entity-link" 
href="http://www.example.com/wiki/Item:Q730";>Q730</a>',
+                               '<a class="extiw wb-entity-link" 
href="http://www.example.com/wiki/Special:EntityPage/Q730";>Q730</a>',
                                $settings[2],
                                new ItemId( 'Q730' ),
                                array()
                        ),
                        array(
-                               '<a class="extiw wb-entity-link kittens" 
href="http://www.example.com/wiki/Item:Q730";>Q730</a>',
+                               '<a class="extiw wb-entity-link kittens" 
href="http://www.example.com/wiki/Special:EntityPage/Q730";>Q730</a>',
                                $settings[2],
                                new ItemId( 'Q730' ),
                                array( 'kittens' )
@@ -238,12 +187,12 @@
 
                return array(
                        array(
-                               '//example.com/wiki/Q730',
+                               '//example.com/wiki/Special:EntityPage/Q730',
                                $settings[1],
                                new ItemId( 'Q730' )
                        ),
                        array(
-                               'http://www.example.com/wiki/Item:Q1234',
+                               
'http://www.example.com/wiki/Special:EntityPage/Q1234',
                                $settings[2],
                                new ItemId( 'Q1234' )
                        )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I89a33cb5c5bdc194fdb1e3cd77a13ee5b63b7eef
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to