Daniel Kinzler has submitted this change and it was merged.

Change subject: (bug 46229) show edit link if an item is connected to a client 
page
......................................................................


(bug 46229) show edit link if an item is connected to a client page

If there is only one site link in the item, the edit link should
still appear on that linked wikipedia (client) page so that it is
easier to add more site links, and know if the page is connected or not.

Change-Id: I073a784552954c4b3a52291ecb46d126ef870025
---
M client/WikibaseClient.hooks.php
M client/includes/LangLinkHandler.php
2 files changed, 66 insertions(+), 28 deletions(-)

Approvals:
  Daniel Kinzler: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 6891b31..362402c 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -380,6 +380,8 @@
                        $langLinkHandler->addLinksFromRepository( 
$parser->getTitle(), $parser->getOutput() );
                }
 
+               $langLinkHandler->updateItemIdProperty( $parser->getTitle(), 
$parser->getOutput() );
+
                if ( $useRepoLinks || Settings::get( 'alwaysSort' ) ) {
                        // sort links
                        $interwikiSorter = new InterwikiSorter(
@@ -452,11 +454,13 @@
                        \Sites::singleton() );
 
                $noExternalLangLinks = 
$langLinkHandler->getNoExternalLangLinks( $pout );
+
                if ( $noExternalLangLinks !== array() ) {
                        $out->setProperty( 'noexternallanglinks', 
$noExternalLangLinks );
                }
 
                $itemId = $pout->getProperty( 'wikibase_item' );
+
                if ( $itemId !== false ) {
                        $out->setProperty( 'wikibase_item', $itemId );
                }
@@ -477,6 +481,11 @@
        public static function onSkinTemplateOutputPageBeforeExec( \Skin 
&$skin, \QuickTemplate &$template ) {
                wfProfileIn( __METHOD__ );
 
+               if ( \Action::getActionName( $skin->getContext() ) !== 'view' ) 
{
+                       wfProfileOut( __METHOD__ );
+                       return true;
+               }
+
                $title = $skin->getContext()->getTitle();
                $namespaceChecker = new NamespaceChecker(
                        Settings::get( 'excludeNamespaces' ),
@@ -484,43 +493,47 @@
                );
 
                if ( $title->exists() && $namespaceChecker->isWikibaseEnabled( 
$title->getNamespace() ) ) {
-                       if ( empty( $template->data['language_urls'] ) && 
\Action::getActionName( $skin->getContext() ) === 'view' ) {
-                               // if property is not set, it will return null
-                               $noExternalLangLinks = 
$skin->getOutput()->getProperty( 'noexternallanglinks' );
+                       // if property is not set, these will return null
+                       $prefixedId = $skin->getOutput()->getProperty( 
'wikibase_item' );
+                       $noExternalLangLinks = $skin->getOutput()->getProperty( 
'noexternallanglinks' );
 
-                               if ( $noExternalLangLinks === null || 
!in_array( '*', $noExternalLangLinks ) ) {
+                       // @todo: may want a data link somewhere, even if the 
links are suppressed
+                       if ( $noExternalLangLinks === null || !in_array( '*', 
$noExternalLangLinks ) ) {
+                               if ( $prefixedId !== null ) {
+                                       $entityId = 
EntityId::newFromPrefixedId( $prefixedId );
+
+                                       // should not happen but just in case
+                                       if ( $entityId === null ) {
+                                               wfWarn( 'Wikibase $entityId is 
is set as output page property but is not valid.' );
+                                               wfProfileOut( __METHOD__ );
+                                               return true;
+                                       }
+
+                                       $repoLinker = new RepoLinker(
+                                               Settings::get( 'repoUrl' ),
+                                               Settings::get( 
'repoArticlePath' ),
+                                               Settings::get( 'repoScriptPath' 
),
+                                               Settings::get( 'repoNamespaces' 
)
+                                       );
+
+                                       // links to the associated item on the 
repo
+                                       $template->data['language_urls'][] = 
array(
+                                               'href' => 
$repoLinker->repoItemUrl( $entityId ),
+                                               'text' => wfMessage( 
'wikibase-editlinks' )->text(),
+                                               'title' => wfMessage( 
'wikibase-editlinkstitle' )->text(),
+                                               'class' => 'wbc-editpage',
+                                       );
+                               } else {
                                        // Placeholder in case the page doesn't 
have any langlinks yet
                                        // self::onBeforePageDisplay adds the 
JavaScript module which will overwrite this with a link
+                                       // We can leave this here in case 
people want to use it for gadgets, css or whatnot,
+                                       // even if the widget is not enabled.
                                        $template->data['language_urls'][] = 
array(
                                                'text' => '',
                                                'id' => 'wbc-linkToItem',
                                                'class' => 'wbc-editpage 
wbc-nolanglinks',
                                        );
                                }
-
-                               wfProfileOut( __METHOD__ );
-                               return true;
-                       }
-
-                       $prefixedId = $skin->getOutput()->getProperty( 
'wikibase_item' );
-
-                       if ( $prefixedId !== null ) {
-                               $entityId = EntityId::newFromPrefixedId( 
$prefixedId );
-
-                               $repoLinker = new RepoLinker(
-                                       Settings::get( 'repoUrl' ),
-                                       Settings::get( 'repoArticlePath' ),
-                                       Settings::get( 'repoScriptPath' ),
-                                       Settings::get( 'repoNamespaces' )
-                               );
-
-                               // links to the special page
-                               $template->data['language_urls'][] = array(
-                                       'href' => $repoLinker->repoItemUrl( 
$entityId ),
-                                       'text' => wfMessage( 
'wikibase-editlinks' )->text(),
-                                       'title' => wfMessage( 
'wikibase-editlinkstitle' )->text(),
-                                       'class' => 'wbc-editpage',
-                               );
                        }
                }
 
diff --git a/client/includes/LangLinkHandler.php 
b/client/includes/LangLinkHandler.php
index 4b85ffb..7a104ad 100644
--- a/client/includes/LangLinkHandler.php
+++ b/client/includes/LangLinkHandler.php
@@ -382,10 +382,12 @@
        public function addLinksFromRepository( Title $title, ParserOutput $out 
) {
                wfProfileIn( __METHOD__ );
 
+               // @todo: inject this as a parameter
                $site = $this->sites->getSite( $this->siteId );
 
                if ( $site === null ) {
                        wfWarn( 'Site not found for ' . $this->siteId . '. 
Cannot add links from repository.' );
+                       wfProfileOut( __METHOD__ );
                        return;
                }
 
@@ -411,6 +413,29 @@
                        }
                }
 
+               wfProfileOut( __METHOD__ );
+       }
+
+       /**
+        * Add wikibase_item parser output property
+        *
+        * @since 0.4
+        *
+        * @param Title $title
+        * @param ParserOutput $out
+        */
+       public function updateItemIdProperty( Title $title, ParserOutput $out ) 
{
+               wfProfileIn( __METHOD__ );
+
+               // @todo inject this as a parameter
+               $site = $this->sites->getSite( $this->siteId );
+
+               if ( $site === null ) {
+                       wfWarn( 'Site not found for ' . $this->siteId . '. 
Cannot add links from repository.' );
+                       wfProfileOut( __METHOD__ );
+                       return;
+               }
+
                $propertyHandler = new EntityIdPropertyUpdater( 
$this->siteLinksLookup, $site );
                $propertyHandler->updateItemIdProperty( $out, $title );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I073a784552954c4b3a52291ecb46d126ef870025
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to