Jens Ohlig has uploaded a new change for review. https://gerrit.wikimedia.org/r/54666
Change subject: (#46126) Lua function sitelink(id) that returns the link with the element ...................................................................... (#46126) Lua function sitelink(id) that returns the link with the element Change-Id: I675ad7072572c25569da41332ae4e9c2c3a3aaea --- M client/includes/WikibaseLibrary.php M client/resources/mw.wikibase.lua 2 files changed, 21 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/66/54666/1 diff --git a/client/includes/WikibaseLibrary.php b/client/includes/WikibaseLibrary.php index 5cb8fe8..517331f 100644 --- a/client/includes/WikibaseLibrary.php +++ b/client/includes/WikibaseLibrary.php @@ -35,6 +35,7 @@ $lib = array( 'getEntity' => array( $this, 'getEntity' ), 'getEntityId' => array( $this, 'getEntityId' ) + 'getGlobalSiteId' => array( $this, 'getGlobalSiteId' ) ); $this->getEngine()->registerInterface( dirname( __FILE__ ) . '/../resources/' . 'mw.wikibase.lua', $lib, array() ); } @@ -103,4 +104,15 @@ return array( $id->getPrefixedId() ); } + /** + * Get global site ID (e.g. "enwiki") + * This is basically a helper function. + * I can see this becoming part of mw.site in the Scribunto extension. + * + * @since 0.4 + * + */ + public function getGlobalSiteId() { + return array( \Wikibase\Settings::get( 'siteGlobalID' ) ); + } } diff --git a/client/resources/mw.wikibase.lua b/client/resources/mw.wikibase.lua index 7139ab8..850325b 100644 --- a/client/resources/mw.wikibase.lua +++ b/client/resources/mw.wikibase.lua @@ -43,6 +43,15 @@ if label == nil then return nil end return label.value end + wikibase.sitelink = function ( id ) + local entity = php.getEntity( id ) + if entity == nil then return nil end + local globalSiteId = php.getGlobalSiteId() + if globalSiteId == nil then return nil end + local sitelink = entity.sitelinks[globalSiteId] + if sitelink == nil then return nil end + return sitelink.value + end mw = mw or {} mw.wikibase = wikibase package.loaded['mw.wikibase'] = wikibase -- To view, visit https://gerrit.wikimedia.org/r/54666 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I675ad7072572c25569da41332ae4e9c2c3a3aaea Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jens Ohlig <jens.oh...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits