Thiemo Kreuz (WMDE) has uploaded a new change for review. (
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, 17 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/77/403177/1
diff --git a/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
b/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
index f3ebea3..5480425 100644
--- a/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
+++ b/client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua
@@ -194,31 +194,32 @@
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
+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'
@@ -238,9 +239,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..4066a55 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
-- @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: newchange
Gerrit-Change-Id: Ieed8cedadec4bde0f9a35bac8ebf035ad90c72d0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Kreuz (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits