[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Allow getting the sitelink to an arbitrary site with mw.wiki...

2017-10-05 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/382334 )

Change subject: Allow getting the sitelink to an arbitrary site with 
mw.wikibase.sitelink
..


Allow getting the sitelink to an arbitrary site with mw.wikibase.sitelink

Bug: T142903
Change-Id: I5471e913a0352e3caf083f3d8054001cc825c006
---
M client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
M 
client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
M client/includes/DataAccess/Scribunto/mw.wikibase.lua
M client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryTests.lua
M 
client/tests/phpunit/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindingsTest.php
M docs/lua.wiki
6 files changed, 53 insertions(+), 19 deletions(-)

Approvals:
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, approved



diff --git 
a/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php 
b/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
index 9dcc0df..3e4a6fe 100644
--- a/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
+++ b/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
@@ -462,12 +462,15 @@
 * Wrapper for getSiteLinkPageName in WikibaseLuaBindings
 *
 * @param string $prefixedEntityId
+* @param string|null $globalSiteId
 *
 * @return string[]
 */
-   public function getSiteLinkPageName( $prefixedEntityId ) {
+   public function getSiteLinkPageName( $prefixedEntityId, $globalSiteId = 
null ) {
$this->checkType( 'getSiteLinkPageName', 1, $prefixedEntityId, 
'string' );
-   return [ 
$this->getLanguageIndependentLuaBindings()->getSiteLinkPageName( 
$prefixedEntityId ) ];
+   $this->checkTypeOptional( 'getSiteLinkPageName', 1, 
$globalSiteId, 'string', null );
+
+   return [ 
$this->getLanguageIndependentLuaBindings()->getSiteLinkPageName( 
$prefixedEntityId, $globalSiteId ) ];
}
 
/**
diff --git 
a/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
 
b/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
index 5606142..951d01e 100644
--- 
a/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
+++ 
b/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
@@ -88,26 +88,32 @@
 
/**
 * @param string $prefixedEntityId
+* @param string|null $globalSiteId
 *
 * @return string|null Null if no site link found.
 */
-   public function getSiteLinkPageName( $prefixedEntityId ) {
+   public function getSiteLinkPageName( $prefixedEntityId, $globalSiteId = 
null ) {
+   $globalSiteId = $globalSiteId !== null ? $globalSiteId : 
$this->siteId;
+
try {
$itemId = new ItemId( $prefixedEntityId );
} catch ( InvalidArgumentException $e ) {
return null;
}
 
-   // @fixme the SiteLinks do not contain badges! but all we want 
here is page name.
+   if ( $globalSiteId === $this->siteId ) {
+   $this->usageAccumulator->addTitleUsage( $itemId );
+   } else {
+   $this->usageAccumulator->addSiteLinksUsage( $itemId );
+   }
+
$siteLinkRows = $this->siteLinkLookup->getLinks(
[ $itemId->getNumericId() ],
-   [ $this->siteId ]
+   [ $globalSiteId ]
);
 
foreach ( $siteLinkRows as $siteLinkRow ) {
$siteLink = new SiteLink( $siteLinkRow[0], 
$siteLinkRow[1] );
-
-   $this->usageAccumulator->addTitleUsage( $itemId );
return $siteLink->getPageName();
}
 
diff --git a/client/includes/DataAccess/Scribunto/mw.wikibase.lua 
b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
index 19a40d2..5aac57e 100644
--- a/client/includes/DataAccess/Scribunto/mw.wikibase.lua
+++ b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
@@ -245,10 +245,12 @@
-- Get the local sitelink title for the given entity id.
--
-- @param {string} id
-   wikibase.sitelink = function( id )
+   -- @param {string} [globalSiteId]
+   wikibase.sitelink = function( id, globalSiteId )
checkType( 'sitelink', 1, id, 'string' )
+   checkTypeMulti( 'sitelink', 2, globalSiteId, { 'string', 'nil' 
} )
 
-   return php.getSiteLinkPageName( id )
+   return php.getSiteLinkPageName( id, globalSiteId )
end
 
 
diff --git 
a/client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryTests.lua
 
b/client/tes

[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Allow getting the sitelink to an arbitrary site with mw.wiki...

2017-10-04 Thread Hoo man (Code Review)
Hoo man has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/382334 )

Change subject: Allow getting the sitelink to an arbitrary site with 
mw.wikibase.sitelink
..

Allow getting the sitelink to an arbitrary site with mw.wikibase.sitelink

Bug: T142903
Change-Id: I5471e913a0352e3caf083f3d8054001cc825c006
---
M client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
M 
client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
M client/includes/DataAccess/Scribunto/mw.wikibase.lua
M client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryTests.lua
M 
client/tests/phpunit/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindingsTest.php
M docs/lua.wiki
6 files changed, 53 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/34/382334/1

diff --git 
a/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php 
b/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
index 9dcc0df..3e4a6fe 100644
--- a/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
+++ b/client/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibrary.php
@@ -462,12 +462,15 @@
 * Wrapper for getSiteLinkPageName in WikibaseLuaBindings
 *
 * @param string $prefixedEntityId
+* @param string|null $globalSiteId
 *
 * @return string[]
 */
-   public function getSiteLinkPageName( $prefixedEntityId ) {
+   public function getSiteLinkPageName( $prefixedEntityId, $globalSiteId = 
null ) {
$this->checkType( 'getSiteLinkPageName', 1, $prefixedEntityId, 
'string' );
-   return [ 
$this->getLanguageIndependentLuaBindings()->getSiteLinkPageName( 
$prefixedEntityId ) ];
+   $this->checkTypeOptional( 'getSiteLinkPageName', 1, 
$globalSiteId, 'string', null );
+
+   return [ 
$this->getLanguageIndependentLuaBindings()->getSiteLinkPageName( 
$prefixedEntityId, $globalSiteId ) ];
}
 
/**
diff --git 
a/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
 
b/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
index 5606142..951d01e 100644
--- 
a/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
+++ 
b/client/includes/DataAccess/Scribunto/WikibaseLanguageIndependentLuaBindings.php
@@ -88,26 +88,32 @@
 
/**
 * @param string $prefixedEntityId
+* @param string|null $globalSiteId
 *
 * @return string|null Null if no site link found.
 */
-   public function getSiteLinkPageName( $prefixedEntityId ) {
+   public function getSiteLinkPageName( $prefixedEntityId, $globalSiteId = 
null ) {
+   $globalSiteId = $globalSiteId !== null ? $globalSiteId : 
$this->siteId;
+
try {
$itemId = new ItemId( $prefixedEntityId );
} catch ( InvalidArgumentException $e ) {
return null;
}
 
-   // @fixme the SiteLinks do not contain badges! but all we want 
here is page name.
+   if ( $globalSiteId === $this->siteId ) {
+   $this->usageAccumulator->addTitleUsage( $itemId );
+   } else {
+   $this->usageAccumulator->addSiteLinksUsage( $itemId );
+   }
+
$siteLinkRows = $this->siteLinkLookup->getLinks(
[ $itemId->getNumericId() ],
-   [ $this->siteId ]
+   [ $globalSiteId ]
);
 
foreach ( $siteLinkRows as $siteLinkRow ) {
$siteLink = new SiteLink( $siteLinkRow[0], 
$siteLinkRow[1] );
-
-   $this->usageAccumulator->addTitleUsage( $itemId );
return $siteLink->getPageName();
}
 
diff --git a/client/includes/DataAccess/Scribunto/mw.wikibase.lua 
b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
index 19a40d2..5aac57e 100644
--- a/client/includes/DataAccess/Scribunto/mw.wikibase.lua
+++ b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
@@ -245,10 +245,12 @@
-- Get the local sitelink title for the given entity id.
--
-- @param {string} id
-   wikibase.sitelink = function( id )
+   -- @param {string} [globalSiteId]
+   wikibase.sitelink = function( id, globalSiteId )
checkType( 'sitelink', 1, id, 'string' )
+   checkTypeMulti( 'sitelink', 2, globalSiteId, { 'string', 'nil' 
} )
 
-   return php.getSiteLinkPageName( id )
+   return php.getSiteLinkPageName( id, globalSiteId )
end
 
 
diff --git 
a/client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryTests.lua
 
b/client/te