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

Change subject: Minor refactoring of foreign EntityId parsing in 
LinkBeginHookHandler
......................................................................


Minor refactoring of foreign EntityId parsing in LinkBeginHookHandler

This is split from I26893ee to have two very minimal, very easy to
review diffs. Note that this patch alone does not do much and should
be reviewed considering what I26893ee will do on top of this.

Bug: T157004
Change-Id: Ifc7b64e21ee0959479de8c66b13770f58a9c8921
---
M repo/includes/Hooks/LinkBeginHookHandler.php
1 file changed, 11 insertions(+), 11 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/Hooks/LinkBeginHookHandler.php 
b/repo/includes/Hooks/LinkBeginHookHandler.php
index bd3d266..439bf26 100644
--- a/repo/includes/Hooks/LinkBeginHookHandler.php
+++ b/repo/includes/Hooks/LinkBeginHookHandler.php
@@ -172,9 +172,10 @@
                $outTitle = $out->getTitle();
 
                $targetIsForeignEntityPage = $this->isForeignEntityPage( 
$target );
+               $isLocal = !$targetIsForeignEntityPage;
 
-               if ( !$targetIsForeignEntityPage &&
-                       !$this->entityNamespaceLookup->isEntityNamespace( 
$target->getNamespace() )
+               if ( $isLocal
+                       && !$this->entityNamespaceLookup->isEntityNamespace( 
$target->getNamespace() )
                ) {
                        return;
                }
@@ -200,11 +201,10 @@
                if ( SpecialPageFactory::exists( $targetText ) ) {
                        $target = Title::makeTitle( NS_SPECIAL, $targetText );
                        $html = $this->linkRenderer->makeKnownLink( $target );
-
                        return;
                }
 
-               if ( !$targetIsForeignEntityPage && !$target->exists() ) {
+               if ( $isLocal && !$target->exists() ) {
                        // The link points to a non-existing item.
                        return;
                }
@@ -256,11 +256,8 @@
         */
        private function isForeignEntityPage( LinkTarget $target ) {
                $interwiki = $target->getInterwiki();
-               if ( $interwiki === '' ) {
-                       return false;
-               }
 
-               if ( !$this->interwikiLookup->isValidInterwiki( $interwiki ) ) {
+               if ( $interwiki === '' || 
!$this->interwikiLookup->isValidInterwiki( $interwiki ) ) {
                        return false;
                }
 
@@ -284,16 +281,19 @@
         */
        private function getEntityIdFromTarget( Title $target ) {
                if ( $this->isForeignEntityPage( $target ) ) {
+                       $interwiki = $target->getInterwiki();
                        $idPart = substr( $target->getText(), strlen( 
'Special:EntityPage/' ) );
-                       // FIXME: This assumes repository name is equal to 
interwiki. This assumption might become invalid
+
                        try {
+                               // FIXME: This assumes repository name is equal 
to interwiki. This assumption might
+                               // become invalid
                                return $this->entityIdParser->parse(
-                                       EntityId::joinSerialization( [ 
$target->getInterwiki(), '', $idPart ] )
+                                       EntityId::joinSerialization( [ 
$interwiki, '', $idPart ] )
                                );
                        } catch ( EntityIdParsingException $ex ) {
                        }
-                       return null;
 
+                       return null;
                }
 
                return $this->entityIdLookup->getEntityIdForTitle( $target );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc7b64e21ee0959479de8c66b13770f58a9c8921
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Jakob <jakob.warkot...@wikimedia.de>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
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