jenkins-bot has submitted this change and it was merged.

Change subject: Make remote content skin tabs non-File specific
......................................................................


Make remote content skin tabs non-File specific

This is one of the steps for implementing shadow namespaces -
generalizing foreign file specific code to be usable for any namespace.
This allows us to no-longer special case WikiFilePage in SkinTemplate
when building content_navigation, and will let GlobalUserPage to add
similar tabs just by overriding the same functions.

The new WikiPage::getWikiDisplayName() and WikiPage::getSourceURL()
functions will return expected values for both local and remote content.

Change-Id: Ib3d7dcbefe95da351872e63f306799eef83e00a7
---
M includes/page/WikiFilePage.php
M includes/page/WikiPage.php
M includes/skins/SkinTemplate.php
3 files changed, 50 insertions(+), 9 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/page/WikiFilePage.php b/includes/page/WikiFilePage.php
index 74566cb..1fa4bfa 100644
--- a/includes/page/WikiFilePage.php
+++ b/includes/page/WikiFilePage.php
@@ -224,4 +224,20 @@
 
                return TitleArray::newFromResult( $res );
        }
+
+       /**
+        * @since 1.28
+        * @return string
+        */
+       public function getWikiDisplayName() {
+               return $this->getFile()->getRepo()->getDisplayName();
+       }
+
+       /**
+        * @since 1.28
+        * @return string
+        */
+       public function getSourceURL() {
+               return $this->getFile()->getDescriptionUrl();
+       }
 }
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 284a343..924a395 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -3727,4 +3727,30 @@
        public function isLocal() {
                return true;
        }
+
+       /**
+        * The display name for the site this content
+        * come from. If a subclass overrides isLocal(),
+        * this could return something other than the
+        * current site name
+        *
+        * @since 1.28
+        * @return string
+        */
+       public function getWikiDisplayName() {
+               global $wgSitename;
+               return $wgSitename;
+       }
+
+       /**
+        * Get the source URL for the content on this page,
+        * typically the canonical URL, but may be a remote
+        * link if the content comes from another site
+        *
+        * @since 1.28
+        * @return string
+        */
+       public function getSourceURL() {
+               return $this->getTitle()->getCanonicalURL();
+       }
 }
diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php
index e6763ca..69f2e49 100644
--- a/includes/skins/SkinTemplate.php
+++ b/includes/skins/SkinTemplate.php
@@ -919,19 +919,18 @@
                                        
$content_navigation['views']['view']['redundant'] = true;
                                }
 
-                               $isForeignFile = $title->inNamespace( NS_FILE ) 
&& $this->canUseWikiPage() &&
-                                       $this->getWikiPage() instanceof 
WikiFilePage && !$this->getWikiPage()->isLocal();
+                               $page = $this->canUseWikiPage() ? 
$this->getWikiPage() : false;
+                               $isRemoteContent = $page && !$page->isLocal();
 
                                // If it is a non-local file, show a link to 
the file in its own repository
                                // @todo abstract this for remote content that 
isn't a file
-                               if ( $isForeignFile ) {
-                                       $file = $this->getWikiPage()->getFile();
+                               if ( $isRemoteContent ) {
                                        
$content_navigation['views']['view-foreign'] = [
                                                'class' => '',
                                                'text' => wfMessageFallback( 
"$skname-view-foreign", 'view-foreign' )->
                                                        setContext( 
$this->getContext() )->
-                                                       params( 
$file->getRepo()->getDisplayName() )->text(),
-                                               'href' => 
$file->getDescriptionUrl(),
+                                                       params( 
$page->getWikiDisplayName() )->text(),
+                                               'href' => $page->getSourceURL(),
                                                'primary' => false,
                                        ];
                                }
@@ -955,9 +954,9 @@
                                                        && 
$title->getDefaultMessageText() !== false
                                                )
                                        ) {
-                                               $msgKey = $isForeignFile ? 
'edit-local' : 'edit';
+                                               $msgKey = $isRemoteContent ? 
'edit-local' : 'edit';
                                        } else {
-                                               $msgKey = $isForeignFile ? 
'create-local' : 'create';
+                                               $msgKey = $isRemoteContent ? 
'create-local' : 'create';
                                        }
                                        $content_navigation['views']['edit'] = [
                                                'class' => ( $isEditing && ( 
$section !== 'new' || !$showNewSection )
@@ -967,7 +966,7 @@
                                                'text' => wfMessageFallback( 
"$skname-view-$msgKey", $msgKey )
                                                        ->setContext( 
$this->getContext() )->text(),
                                                'href' => $title->getLocalURL( 
$this->editUrlOptions() ),
-                                               'primary' => !$isForeignFile, 
// don't collapse this in vector
+                                               'primary' => !$isRemoteContent, 
// don't collapse this in vector
                                        ];
 
                                        // section link

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib3d7dcbefe95da351872e63f306799eef83e00a7
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: GergÅ‘ Tisza <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to