jenkins-bot has submitted this change and it was merged.
Change subject: (bug 47726) Adds a link to corresponding Wikibase Item to
action=info
......................................................................
(bug 47726) Adds a link to corresponding Wikibase Item to action=info
Adds a link to the corresponding Wikibase Repo item to action=info of
the corresponding Wikibase Client article page. The Item ID on Wikibase Repo is
used as anchor text.
Bug: 47726
Change-Id: Ifa6ca0f0e6180d1eacf4cfae3e1746b40cd34be0
---
M client/WikibaseClient.hooks.php
M client/WikibaseClient.i18n.php
M client/WikibaseClient.php
3 files changed, 53 insertions(+), 0 deletions(-)
Approvals:
Hoo man: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 2e7edb2..b238502 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -648,4 +648,51 @@
}
return true;
}
+
+ /**
+ * Adds the Entity ID of the corresponding Wikidata item in action=info
+ *
+ * @param IContextSource $context
+ * @param array $pageInfo
+ *
+ * @return bool
+ */
+ public static function onInfoAction( $context, array &$pageInfo ) {
+ // Check if wikibase namespace is enabled
+ $title = $context->getTitle();
+ $namespaceChecker = new NamespaceChecker(
+ Settings::get( 'excludeNamespaces' ),
+ Settings::get( 'namespaces' )
+ );
+
+ if ( $title->exists() && $namespaceChecker->isWikibaseEnabled(
$title->getNamespace() ) ) {
+
+ $site = \MediaWikiSite::newFromGlobalId( Settings::get(
'siteGlobalID' ) );
+
+ $siteLinkLookup =
WikibaseClient::getDefaultInstance()->getStore()->getSiteLinkTable();
+ $entityId = $siteLinkLookup->getEntityIdForSiteLink(
+ new SiteLink( $site, $title->getFullText() )
+ );
+
+ if( $entityId ) {
+ // Creating a Repo link with Item ID as anchor
text
+ $repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
+ $idFormatter =
WikibaseClient::getDefaultInstance()->getEntityIdFormatter();
+ $idString = $idFormatter->format( $entityId );
+ $itemLink = \Linker::makeExternalLink(
$repoLinker->repoItemUrl( $entityId ), $idString, true, 'plainlink' );
+
+ // Adding the Repo link to array &$pageInfo
+ $pageInfo['header-basic'][] = array(
+ $context->msg(
'wikibase-pageinfo-entity-id' ),
+ $itemLink
+ );
+ } else {
+ $pageInfo['header-basic'][] = array(
+ $context->msg(
'wikibase-pageinfo-entity-id' ),
+ $context->msg(
'wikibase-pageinfo-entity-id-none' )
+ );
+ }
+ }
+ return true;
+ }
}
diff --git a/client/WikibaseClient.i18n.php b/client/WikibaseClient.i18n.php
index 7c64bcc..768726f 100644
--- a/client/WikibaseClient.i18n.php
+++ b/client/WikibaseClient.i18n.php
@@ -65,6 +65,8 @@
'wikibase-unconnectedpages-page-warning' => 'The page title could not
be used for the query and is ignored.',
'wikibase-unconnectedpages-iwdata-label' => 'Only pages with
interlanguagelinks',
'wikibase-unconnectedpages-format-row' => '($1 interlanguagelinks on
the page)',
+ 'wikibase-pageinfo-entity-id' => 'Wikidata Item ID',
+ 'wikibase-pageinfo-entity-id-none' => 'None',
);
/** Message documentation (Message documentation)
@@ -167,6 +169,9 @@
Parameters:
* $1 - number of inter-language links',
+
+ 'wikibase-pageinfo-entity-id' => 'A link to the corresponding Wikibase
Item',
+ 'wikibase-pageinfo-entity-id-none' => 'The page is not linked with a
wikibase item.',
);
/** Afrikaans (Afrikaans)
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index 61ef105..5170bec 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -126,6 +126,7 @@
// extension hooks
$wgHooks['WikibaseDeleteData'][] =
'\Wikibase\ClientHooks::onWikibaseDeleteData';
$wgHooks['WikibaseRebuildData'][] =
'\Wikibase\ClientHooks::onWikibaseRebuildData';
+$wgHooks['InfoAction'][]
= '\Wikibase\ClientHooks::onInfoAction';
// api modules
$wgAPIMetaModules['wikibase'] = 'Wikibase\ApiClientInfo';
--
To view, visit https://gerrit.wikimedia.org/r/64644
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifa6ca0f0e6180d1eacf4cfae3e1746b40cd34be0
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Pragunbhutani <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Pragunbhutani <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits