Add extra views (tabs) for files in a foreign repository
authorThis, that and the other <at.light@live.com.au>
Mon, 7 Apr 2014 10:00:11 +0000 (20:00 +1000)
committerThis, that and the other <at.light@live.com.au>
Mon, 7 Apr 2014 10:00:11 +0000 (20:00 +1000)
Previously, foreign files with no local page had only a [Create] tab, with
no explanation that this created a local description page. There was not
even a [Read] tab - from SkinTemplate's perspective, a foreign file page
did not exist.

This patch changes the following view tabs:
* [Read] now always appears on foreign files - no change in functionality
* New tab [View on <repo name>] always appears on foreign files
* [Create] tab renamed to [Add local description] for foreign files without
  a local page
* [Edit] tab renamed to [Edit local description] for foreign files with a
  local page

This is related to bug 26525. I am hesitant to implement a [Edit on
<repo name>] tab that goes straight to the edit screen, as I worry about
users getting confused and thinking they are editing the file locally.

Change-Id: I4a43b759b7a7e9ac2c8d437408847bf3b6c1f4a9

includes/SkinTemplate.php
languages/i18n/en.json
languages/i18n/qqq.json

index 5073913..f359a1c 100644 (file)
@@ -944,8 +944,11 @@ class SkinTemplate extends Skin {
                        $content_navigation['namespaces'][$talkId]['context'] = 'talk';
 
                        if ( $userCanRead ) {
+                               $isForeignFile = $title->inNamespace( NS_FILE ) && $this->canUseWikiPage() &&
+                                       $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal();
+
                                // Adds view view link
-                               if ( $title->exists() ) {
+                               if ( $title->exists() || $isForeignFile ) {
                                        $content_navigation['views']['view'] = $this->tabAction(
                                                $isTalk ? $talkPage : $subjectPage,
                                                array( "$skname-view-view", 'view' ),
@@ -955,6 +958,19 @@ class SkinTemplate extends Skin {
                                        $content_navigation['views']['view']['redundant'] = true;
                                }
 
+                               // If it is a non-local file, show a link to the file in its own repository
+                               if ( $isForeignFile ) {
+                                       $file = $this->getWikiPage()->getFile();
+                                       $content_navigation['views']['view-foreign'] = array(
+                                               'class' => '',
+                                               'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
+                                                       setContext( $this->getContext() )->
+                                                       params( $file->getRepo()->getDisplayName() )->text(),
+                                               'href' => $file->getDescriptionUrl(),
+                                               'primary' => false,
+                                       );
+                               }
+
                                wfProfileIn( __METHOD__ . '-edit' );
 
                                // Checks if user can edit the current page if it exists or create it otherwise
@@ -969,13 +985,16 @@ class SkinTemplate extends Skin {
                                                && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
                                        $section = $request->getVal( 'section' );
 
-                                       $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
-                                               'edit' : 'create';
+                                       if ( $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ) {
+                                               $msgKey = $isForeignFile ? 'edit-local' : 'edit';
+                                       } else {
+                                               $msgKey = $isForeignFile ? 'create-local' : 'create';
+                                       }
                                        $content_navigation['views']['edit'] = array(
                                                'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass,
                                                'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
                                                'href' => $title->getLocalURL( $this->editUrlOptions() ),
-                                               'primary' => true, // don't collapse this in vector
+                                               'primary' => !$isForeignFile, // don't collapse this in vector
                                        );
 
                                        // section link
index 9031b96..4ca6300 100644 (file)
     "permalink": "Permanent link",
     "print": "Print",
     "view": "View",
+    "view-foreign": "View on $1",
     "edit": "Edit",
+    "edit-local": "Edit local description",
     "create": "Create",
+    "create-local": "Add local description",
     "editthispage": "Edit this page",
     "create-this-page": "Create this page",
     "delete": "Delete",
index 5b3c939..03fe572 100644 (file)
     "permalink": "Display name for a permanent link to the current revision of a page. When the page is edited, permalink will still link to this revision. Example: Last menu link on [[{{MediaWiki:Mainpage}}]]\n\nSee also:\n* {{msg-mw|Permalink}}\n* {{msg-mw|Accesskey-t-permalink}}\n* {{msg-mw|Tooltip-t-permalink}}\n{{Identical|Permalink}}",
     "print": "{{Identical|Print}}",
     "view": "The default text of the \"View\" or \"Read\" (Vector) views tab which represents the basic view for the page. Should be in the infinitive mood.\n\n{{Identical|View}}",
+    "view-foreign": "The text on the tab that sends people to the \"master copy\" of the file at the foreign file\nrepository (e.g. Wikimedia Commons). Should be in the infinitive mood.\n\nParameters:\n* $1 - the name of the shared repository. On Wikimedia sites, $1 is {{msg-mw|Shared-repo-name-shared}}. On wikis using [[mw:InstantCommons|InstantCommons]], $1 is {{msg-mw|Shared-repo-name-wikimediacommons}}. The default value for $1 is {{msg-mw|Shared-repo}}.",
     "edit": "The text of the tab going to the edit form. When the page is protected, you will see {{msg-mw|Viewsource}}. Should be in the infinitive mood.\n\nSee also:\n* {{msg-mw|Edit}}\n* {{msg-mw|Accesskey-ca-edit}}\n* {{msg-mw|Tooltip-ca-edit}}\n{{Identical|Edit}}",
-    "create": "The text on the tab of the edit form on unexisting pages starts editing them.\n\n{{Identical|Create}}",
+    "edit-local": "The text on the tab going to the edit form for the local description page of a file from a foreign file repository (e.g. Wikimedia Commons). Should be in the infinitive mood.\n\nSee also:\n* {{msg-mw|Edit}}\n* {{msg-mw|Create-local}}",
+    "create": "The text on the tab of the edit form on unexisting pages starts editing them. Should be in the infinitive mood.\n\n{{Identical|Create}}",
+    "create-local": "The text on the tab going to the creation form for the (not yet existing) local description page of a file from a foreign file repository (e.g. Wikimedia Commons). Should be in the infinitive mood.\n\nSee also:\n* {{msg-mw|Create}}\n* {{msg-mw|Edit-local}}",
     "editthispage": "This is the \"edit\" link as used in the Cologne Blue skin, at the bottom of the page.\n\nSee {{msg-mw|Create-this-page}} for when the page does not exist.\n{{Identical|Edit this page}}",
     "create-this-page": "In the Cologne Blue skin this is the text for the link leading to the edit form on pages that have not yet been created, at the bottom of the page. See {{msg-mw|editthispage}} for when the page already exists.\n{{Identical|Createpage}}",
     "delete": "Name of the Delete tab shown for admins. Should be in the infinitive mood.\n\nSee also:\n* {{msg-mw|Delete}}\n* {{msg-mw|Accesskey-ca-delete}}\n* {{msg-mw|Tooltip-ca-delete}}\n{{Identical|Delete}}",