Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311075

Change subject: Add RemoteWikiPage interface
......................................................................

Add RemoteWikiPage interface

This is one of the first steps to implementing shadow namespaces -
creating a generic interface for representing remote content. 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 implementing the same interface.

There is a note on the RemoteWikiPage interface that it is woefully
incomplete and more will be added to it in the future.

Change-Id: Ib3d7dcbefe95da351872e63f306799eef83e00a7
---
M autoload.php
A includes/page/RemoteWikiPage.php
M includes/page/WikiFilePage.php
M includes/skins/SkinTemplate.php
4 files changed, 69 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/75/311075/1

diff --git a/autoload.php b/autoload.php
index 9fd83eb..fa85a0c 100644
--- a/autoload.php
+++ b/autoload.php
@@ -1143,6 +1143,7 @@
        'RefreshLinks' => __DIR__ . '/maintenance/refreshLinks.php',
        'RefreshLinksJob' => __DIR__ . 
'/includes/jobqueue/jobs/RefreshLinksJob.php',
        'RegexlikeReplacer' => __DIR__ . 
'/includes/libs/replacers/RegexlikeReplacer.php',
+       'RemoteWikiPage' => __DIR__ . '/includes/page/RemoteWikiPage.php',
        'RemoveInvalidEmails' => __DIR__ . 
'/maintenance/removeInvalidEmails.php',
        'RemoveUnusedAccounts' => __DIR__ . 
'/maintenance/removeUnusedAccounts.php',
        'RenameDbPrefix' => __DIR__ . '/maintenance/renameDbPrefix.php',
diff --git a/includes/page/RemoteWikiPage.php b/includes/page/RemoteWikiPage.php
new file mode 100644
index 0000000..2700dad
--- /dev/null
+++ b/includes/page/RemoteWikiPage.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Interface for WikiPage when the content might come from a remote wiki
+ *
+ * @note This interface is incomplete and will be added to over time
+ * @since 1.28
+ */
+interface RemoteWikiPage {
+
+       /**
+        * Get a name that identifies the remote wiki
+        * the content comes from for display
+        *
+        * @return string
+        */
+       public function getRemoteWikiDisplayName();
+
+       /**
+        * URL to view the content on the remote wiki
+        *
+        * @return string
+        */
+       public function getRemoteURL();
+}
diff --git a/includes/page/WikiFilePage.php b/includes/page/WikiFilePage.php
index c478550..81731e1 100644
--- a/includes/page/WikiFilePage.php
+++ b/includes/page/WikiFilePage.php
@@ -25,7 +25,7 @@
  *
  * @ingroup Media
  */
-class WikiFilePage extends WikiPage {
+class WikiFilePage extends WikiPage implements RemoteWikiPage {
        /** @var File */
        protected $mFile = false;
        /** @var LocalRepo */
@@ -224,4 +224,20 @@
 
                return TitleArray::newFromResult( $res );
        }
+
+       /**
+        * @since 1.28
+        * @return string
+        */
+       public function getRemoteWikiDisplayName() {
+               return $this->getFile()->getRepo()->getDisplayName();
+       }
+
+       /**
+        * @since 1.28
+        * @return string
+        */
+       public function getRemoteURL() {
+               return $this->getFile()->getDescriptionUrl();
+       }
 }
diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php
index 2351ab8..c6b0115 100644
--- a/includes/skins/SkinTemplate.php
+++ b/includes/skins/SkinTemplate.php
@@ -920,19 +920,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() 
&& $page instanceof RemoteWikiPage;
 
                                // 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->getRemoteWikiDisplayName() )->text(),
+                                               'href' => $page->getRemoteURL(),
                                                'primary' => false,
                                        ];
                                }
@@ -956,9 +955,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 )
@@ -968,7 +967,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: newchange
Gerrit-Change-Id: Ib3d7dcbefe95da351872e63f306799eef83e00a7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>

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

Reply via email to