Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/210907

Change subject: Default mw.wikibase.* lua functions to the connected item of a 
page
......................................................................

Default mw.wikibase.* lua functions to the connected item of a page

untested, and no tests yet...

default mw.wikibase.label, mw.wikibase.description, mw.wikibase.sitelink
to use connected item, if id is not specified.

Bug: T99078
Change-Id: Ief78b1c8f591d1da8a6ca03e6cb02c339954a99d
---
M client/includes/DataAccess/Scribunto/mw.wikibase.lua
1 file changed, 11 insertions(+), 5 deletions(-)


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

diff --git a/client/includes/DataAccess/Scribunto/mw.wikibase.lua 
b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
index 03b0e47..e9a38b8 100644
--- a/client/includes/DataAccess/Scribunto/mw.wikibase.lua
+++ b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
@@ -32,6 +32,12 @@
                return pageEntityId
        end
 
+       local setEntityIdForCurrentPageIfNil = function( id )
+               if id == nil then
+                       id = getEntityIdForCurrentPage()
+               end
+       end
+
        -- Get the mw.wikibase.entity object for a given id. Cached.
        local getEntityObject = function( id )
                if entities[ id ] == nil then
@@ -61,11 +67,8 @@
 
        -- Get the mw.wikibase.entity object for the current page
        wikibase.getEntity = function( id )
-               checkTypeMulti( 'getEntity', 1, id, { 'string', 'nil' } )
-
-               if id == nil then
-                       id = getEntityIdForCurrentPage()
-               end
+               id = setToIdOfConnectedItemIfNil( id )
+               checkTypeMulti( 'getEntity', 1, id, { 'string' } )
 
                if not php.getSetting( 'allowArbitraryDataAccess' ) and id ~= 
getEntityIdForCurrentPage() then
                        error( 'Access to arbitrary items has been disabled.', 
2 )
@@ -85,6 +88,7 @@
        --
        -- @param id
        wikibase.label = function( id )
+               id = setToIdOfConnectedItemIfNil( id )
                checkType( 'label', 1, id, 'string' )
 
                return php.getLabel( id )
@@ -94,6 +98,7 @@
        --
        -- @param id
        wikibase.description = function( id )
+               id = setToIdOfConnectedItemIfNil( id )
                checkType( 'description', 1, id, 'string' )
 
                return php.getDescription( id )
@@ -103,6 +108,7 @@
        --
        -- @param id
        wikibase.sitelink = function( id )
+               id = setToIdOfConnectedItemIfNil( id )
                checkType( 'sitelink', 1, id, 'string' )
 
                return php.getSiteLinkPageName( id )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief78b1c8f591d1da8a6ca03e6cb02c339954a99d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to