jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/403177 )

Change subject: Streamline mw.wikibase.entity:getAllStatements
......................................................................


Streamline mw.wikibase.entity:getAllStatements

This patch fixes one issue: resolving a label might fail and return nil.
An array access with nil does work just fine, but it's still cleaner and
more obvious if this case is checked before.

This patch also streamlines the code and tries to make it as easy to
follow as possible.

Bug: T166056
Change-Id: Ieed8cedadec4bde0f9a35bac8ebf035ad90c72d0
---
M client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
M client/includes/DataAccess/Scribunto/mw.wikibase.lua
2 files changed, 18 insertions(+), 17 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua 
b/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
index cd7fbb4..a543990 100644
--- a/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
+++ b/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
@@ -226,31 +226,33 @@
        return sitelink.title
 end
 
--- Get claims by property id or label from entity
---
 -- @param {table} entity
 -- @param {string} propertyLabelOrId
-local resolvePropertyClaims = function( entity, propertyLabelOrId )
-       local propertyId
-       if isValidPropertyId( propertyLabelOrId ) then
-               propertyId = propertyLabelOrId
-       else
-               propertyId = mw.wikibase.resolvePropertyId( propertyLabelOrId )
-       end
+-- @param {string} funcName for error logging
+local getEntityStatements = function( entity, propertyLabelOrId, funcName )
+       checkType( funcName, 1, propertyLabelOrId, 'string' )
 
-       if entity.claims == nil or not entity.claims[propertyId] then
+       if not entity.claims then
                return {}
        end
-       return entity.claims[propertyId]
+
+       local propertyId = propertyLabelOrId
+       if not isValidPropertyId( propertyId ) then
+               propertyId = mw.wikibase.resolvePropertyId( propertyId )
+       end
+
+       if propertyId and entity.claims[propertyId] then
+               return entity.claims[propertyId]
+       end
+
+       return {}
 end
 
 -- Get the best statements with the given property id or label
 --
 -- @param {string} propertyLabelOrId
 methodtable.getBestStatements = function( entity, propertyLabelOrId )
-       checkType( 'getBestStatements', 1, propertyLabelOrId, 'string' )
-
-       local entityStatements = resolvePropertyClaims( entity, 
propertyLabelOrId )
+       local entityStatements = getEntityStatements( entity, 
propertyLabelOrId, 'getBestStatements' )
        local statements = {}
        local bestRank = 'normal'
 
@@ -270,9 +272,7 @@
 --
 -- @param {string} propertyLabelOrId
 methodtable.getAllStatements = function( entity, propertyLabelOrId )
-       checkType( 'getAllStatements', 1, propertyLabelOrId, 'string' )
-
-       return resolvePropertyClaims( entity, propertyLabelOrId )
+       return getEntityStatements( entity, propertyLabelOrId, 
'getAllStatements' )
 end
 
 -- Get a table with all property ids attached to the entity.
diff --git a/client/includes/DataAccess/Scribunto/mw.wikibase.lua 
b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
index 2199bc9..e46fc36 100644
--- a/client/includes/DataAccess/Scribunto/mw.wikibase.lua
+++ b/client/includes/DataAccess/Scribunto/mw.wikibase.lua
@@ -137,6 +137,7 @@
 
        -- @param {string} entityId
        -- @param {string} propertyId
+       -- @param {string} funcName for error logging
        -- @param {string} rank Which statements to include. Either "best" or 
"all".
        local getEntityStatements = function( entityId, propertyId, funcName, 
rank )
                if not php.getSetting( 'allowArbitraryDataAccess' ) and 
entityId ~= wikibase.getEntityIdForCurrentPage() then

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieed8cedadec4bde0f9a35bac8ebf035ad90c72d0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Kreuz (WMDE) <thiemo.kr...@wikimedia.de>
Gerrit-Reviewer: Eranroz <eranro...@gmail.com>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchane...@gmail.com>
Gerrit-Reviewer: Thiemo Kreuz (WMDE) <thiemo.kr...@wikimedia.de>
Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to