1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-06-13 12:54:14 +00:00

Scribunto: Synchronize latest of mw.wikibase.entity.lua [#614]

This commit is contained in:
gnosygnu 2019-11-23 05:30:44 -05:00
parent b2864f8c6a
commit c307946bd2
4 changed files with 185 additions and 83 deletions

View File

@ -42,6 +42,7 @@ public class WikibaseClientDefault {
rv.addSetting("allowDataAccessInUserLanguage", false); rv.addSetting("allowDataAccessInUserLanguage", false);
rv.addSetting("sharedCacheDuration", 60 * 60); rv.addSetting("sharedCacheDuration", 60 * 60);
rv.addSetting("fineGrainedLuaTracking", false); // PERF: setting deliberately to false else every call to entity.sitelinks['frwiki']); will generate another round-trip to Scrib; SEE:mw.wikibase.lua; REF.MW: https://gerrit.wikimedia.org/r/#/c/operations/mediawiki-config/+/412664/3/wmf-config/InitialiseSettings.php rv.addSetting("fineGrainedLuaTracking", false); // PERF: setting deliberately to false else every call to entity.sitelinks['frwiki']); will generate another round-trip to Scrib; SEE:mw.wikibase.lua; REF.MW: https://gerrit.wikimedia.org/r/#/c/operations/mediawiki-config/+/412664/3/wmf-config/InitialiseSettings.php
rv.addSetting("siteGlobalID", "wikidatawiki");
return rv; return rv;
} }
} }

View File

@ -66,6 +66,8 @@ public class Scrib_lib_wikibase implements Scrib_lib {
case Proc_isValidEntityId: return IsValidEntityId(args, rslt); case Proc_isValidEntityId: return IsValidEntityId(args, rslt);
case Proc_getPropertyOrder: return GetPropertyOrder(args, rslt); case Proc_getPropertyOrder: return GetPropertyOrder(args, rslt);
case Proc_orderProperties: return OrderProperties(args, rslt); case Proc_orderProperties: return OrderProperties(args, rslt);
case Proc_incrementStatsKey: return IncrementStatsKey(args, rslt);
case Proc_getEntityModuleName: return GetEntityModuleName(args, rslt);
default: throw Err_.new_unhandled(key); default: throw Err_.new_unhandled(key);
} }
} }
@ -73,7 +75,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
Proc_getLabel = 0, Proc_getLabelByLanguage = 1, Proc_getEntity = 2, Proc_entityExists = 3, Proc_getEntityStatements = 4, Proc_getSetting = 5, Proc_getEntityUrl = 6 Proc_getLabel = 0, Proc_getLabelByLanguage = 1, Proc_getEntity = 2, Proc_entityExists = 3, Proc_getEntityStatements = 4, Proc_getSetting = 5, Proc_getEntityUrl = 6
, Proc_renderSnak = 7, Proc_formatValue = 8, Proc_renderSnaks = 9, Proc_formatValues = 10, Proc_getEntityId = 11, Proc_getReferencedEntityId = 12 , Proc_renderSnak = 7, Proc_formatValue = 8, Proc_renderSnaks = 9, Proc_formatValues = 10, Proc_getEntityId = 11, Proc_getReferencedEntityId = 12
, Proc_getUserLang = 13, Proc_getDescription = 14, Proc_resolvePropertyId = 15, Proc_getSiteLinkPageName = 16, Proc_incrementExpensiveFunctionCount = 17 , Proc_getUserLang = 13, Proc_getDescription = 14, Proc_resolvePropertyId = 15, Proc_getSiteLinkPageName = 16, Proc_incrementExpensiveFunctionCount = 17
, Proc_isValidEntityId = 18, Proc_getPropertyOrder = 19, Proc_orderProperties = 20; , Proc_isValidEntityId = 18, Proc_getPropertyOrder = 19, Proc_orderProperties = 20, Proc_incrementStatsKey = 21, Proc_getEntityModuleName = 22;
public static final String public static final String
Invk_getLabel = "getLabel", Invk_getLabelByLanguage = "getLabelByLanguage", Invk_getEntity = "getEntity", Invk_entityExists = "entityExists" Invk_getLabel = "getLabel", Invk_getLabelByLanguage = "getLabelByLanguage", Invk_getEntity = "getEntity", Invk_entityExists = "entityExists"
, Invk_getEntityStatements = "getEntityStatements" , Invk_getEntityStatements = "getEntityStatements"
@ -83,12 +85,13 @@ public class Scrib_lib_wikibase implements Scrib_lib {
, Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId" , Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId"
, Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount" , Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount"
, Invk_isValidEntityId = "isValidEntityId", Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties" , Invk_isValidEntityId = "isValidEntityId", Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
, Invk_incrementStatsKey = "incrementStatsKey", Invk_getEntityModuleName = "getEntityModuleName"
; ;
private static final String[] Proc_names = String_.Ary private static final String[] Proc_names = String_.Ary
( Invk_getLabel, Invk_getLabelByLanguage, Invk_getEntity, Invk_entityExists, Invk_getEntityStatements, Invk_getSetting, Invk_getEntityUrl ( Invk_getLabel, Invk_getLabelByLanguage, Invk_getEntity, Invk_entityExists, Invk_getEntityStatements, Invk_getSetting, Invk_getEntityUrl
, Invk_renderSnak, Invk_formatValue, Invk_renderSnaks, Invk_formatValues , Invk_renderSnak, Invk_formatValue, Invk_renderSnaks, Invk_formatValues
, Invk_getEntityId, Invk_getReferencedEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount , Invk_getEntityId, Invk_getReferencedEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount
, Invk_isValidEntityId, Invk_getPropertyOrder, Invk_orderProperties , Invk_isValidEntityId, Invk_getPropertyOrder, Invk_orderProperties, Invk_incrementStatsKey, Invk_getEntityModuleName
); );
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);} public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);}
@ -324,6 +327,21 @@ public function formatValues( $snaksSerialization ) {
public boolean IncrementExpensiveFunctionCount(Scrib_proc_args args, Scrib_proc_rslt rslt) { public boolean IncrementExpensiveFunctionCount(Scrib_proc_args args, Scrib_proc_rslt rslt) {
return rslt.Init_obj(Keyval_.Ary_empty); // NOTE: for now, always return null (XOWA does not care about expensive parser functions) return rslt.Init_obj(Keyval_.Ary_empty); // NOTE: for now, always return null (XOWA does not care about expensive parser functions)
} }
public boolean IncrementStatsKey(Scrib_proc_args args, Scrib_proc_rslt rslt) {
return rslt.Init_null();
}
public boolean GetEntityModuleName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String moduleName = "mw.wikibase.entity"; // FOOTNOTE:GetEntityModuleName
// String prefixedEntityId = Get_xid_from_args(args);
try {
// $type = $entityId->getEntityType();
// $moduleName = $this->getLuaEntityModules()[$type] ?? 'mw.wikibase.entity';
}
catch (Exception exc) {
moduleName = "mw.wikibase.entity";
}
return rslt.Init_obj(moduleName);
}
private byte[] Get_xid_from_args(Scrib_proc_args args) { private byte[] Get_xid_from_args(Scrib_proc_args args) {
// get qid / pid from scrib_arg[0] // get qid / pid from scrib_arg[0]
byte[] xid_bry = args.Pull_bry(0); byte[] xid_bry = args.Pull_bry(0);
@ -342,3 +360,16 @@ public function formatValues( $snaksSerialization ) {
return wdoc; return wdoc;
} }
} }
/*
FOOTNOTE:GetEntityModuleName
Wikibase currently always returns 'mw.wikibase.entity' b/c "$this->getLuaEntityModules()[$type]" is always null
* getLuaEntityModules returns an EntityTypeDefinitions
* EntityTypeDefinitions is created in WikibaseRepo using entitytypes.php
* Neither entitytypes.php has a key definition for 'lua-entity-module'
See below references
* https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/lib/includes/EntityTypeDefinitions.php
* https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/repo/includes/WikibaseRepo.php
* https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/repo/WikibaseRepo.entitytypes.php
* https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/lib/WikibaseLib.entitytypes.php
*/

View File

@ -193,7 +193,16 @@ public class Basic__tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityUrl, Object_.Ary("Q2" ), "https://www.wikidata.org/wiki/Special:EntityPage/Q2"); fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityUrl, Object_.Ary("Q2" ), "https://www.wikidata.org/wiki/Special:EntityPage/Q2");
} }
@Test public void GetSetting() { @Test public void GetSetting() {
fxt.Test_scrib_proc_obj(lib, Scrib_lib_wikibase.Invk_getSetting, Object_.Ary("allowArbitraryDataAccess" ), true); // PAGE:en.w:Beccles DATE:2018-06-27 fxt.Test_scrib_proc_obj(lib, Scrib_lib_wikibase.Invk_getSetting, Object_.Ary("allowArbitraryDataAccess"), true); // PAGE:en.w:Beccles DATE:2018-06-27
}
@Test public void GetSetting__siteGlobalID() {
fxt.Test_scrib_proc_obj(lib, Scrib_lib_wikibase.Invk_getSetting, Object_.Ary("siteGlobalID"), "wikidatawiki");
}
@Test public void IncrementStatsKey() {
fxt.Test_scrib_proc_obj(lib, Scrib_lib_wikibase.Invk_incrementStatsKey, Object_.Ary("wikibase.client.scribunto.wikibase.getEntityIdForCurrentPage.call"), null);
}
@Test public void GetEntityModuleName() {
fxt.Test_scrib_proc_obj(lib, Scrib_lib_wikibase.Invk_getEntityModuleName, Object_.Ary("Q123"), "mw.wikibase.entity");
} }
} }
class Wbase_snak_utl_ { class Wbase_snak_utl_ {

View File

@ -1,4 +1,5 @@
--XOWA:updated 2018-06-21 --XOWA:updated 2019-11-22
--REF:https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/client/includes/DataAccess/Scribunto/mw.wikibase.lua
--[[ --[[
Registers and defines functions to access Wikibase through the Scribunto extension Registers and defines functions to access Wikibase through the Scribunto extension
Provides Lua setupInterface Provides Lua setupInterface
@ -12,56 +13,64 @@
]] ]]
local wikibase = {} local wikibase = {}
-- xowa:bgn "uncache" entities; DATE:2014-07-26
local reset_entity_id = false
local reset_entity_cache = false
-- xowa:end
local util = require 'libraryUtil' local util = require 'libraryUtil'
local checkType = util.checkType local checkType = util.checkType
local checkTypeMulti = util.checkTypeMulti local checkTypeMulti = util.checkTypeMulti
local cacheSize = 15 -- Size of the LRU cache being used to cache entities -- Get a cache data structure to use with addToCache and getFromCache
local cacheOrder = {} -- with a given maximum size.
local entityCache = {}
-- Cache a given entity (can also be false, in case it doesn't exist).
-- --
-- @param entityId -- @param maxCacheSize
-- @param entity local function initCache( maxCacheSize )
local cacheEntity = function( entityId, entity ) return {
if #cacheOrder == cacheSize then data = {},
local entityIdToRemove = table.remove( cacheOrder, cacheSize ) order = {},
entityCache[ entityIdToRemove ] = nil size = 0,
end maxCacheSize = maxCacheSize,
}
table.insert( cacheOrder, 1, entityId )
entityCache[ entityId ] = entity
end end
-- Retrieve an entity. Will return false in case it's known to not exist -- Cache a given value (can also be false, in case it doesn't exist).
-- and nil in case of a cache miss.
-- --
-- @param entityId -- @param cache
local getCachedEntity = function( entityId ) -- @param key
-- xowa:bgn -- @param value
if reset_entity_cache then local function addToCache( cache, key, value )
reset_entity_cache = false if cache.size == cache.maxCacheSize then
entityCache = {} local toRemove = table.remove( cache.order, cache.maxCacheSize )
cache.data[ toRemove ] = nil
else
cache.size = cache.size + 1
end end
-- xowa:end
if entityCache[ entityId ] ~= nil then table.insert( cache.order, 1, key )
for cacheOrderId, cacheOrderEntityId in pairs( cacheOrder ) do cache.data[ key ] = value
if cacheOrderEntityId == entityId then end
table.remove( cacheOrder, cacheOrderId )
-- Retrieve a value from a cache. Will return nil in case of a cache miss.
--
-- @param cache
-- @param key
local function getFromCache( cache, key )
if cache.data[ key ] ~= nil then
for cacheOrderId, cacheOrderKey in pairs( cache.order ) do
if cacheOrderKey == key then
table.remove( cache.order, cacheOrderId )
break break
end end
end end
table.insert( cacheOrder, 1, entityId ) table.insert( cache.order, 1, key )
end end
return entityCache[ entityId ] return cache.data[ key ]
end end
-- 15 slot cache for entities
local entityCache = initCache( 15 )
-- 50 slot cache for statements
local statementCache = initCache( 50 )
function wikibase.setupInterface() function wikibase.setupInterface()
local php = mw_interface local php = mw_interface
mw_interface = nil mw_interface = nil
@ -70,7 +79,7 @@ function wikibase.setupInterface()
local pageEntityId = false local pageEntityId = false
-- Get the entity id of the connected item, if id is nil. Cached. -- Get the entity id of the connected item, if id is nil. Cached.
local getIdOfConnectedItemIfNil = function( id ) local function getIdOfConnectedItemIfNil( id )
if id == nil then if id == nil then
return wikibase.getEntityIdForCurrentPage() return wikibase.getEntityIdForCurrentPage()
end end
@ -79,8 +88,8 @@ function wikibase.setupInterface()
end end
-- Get the mw.wikibase.entity object for a given id. Cached. -- Get the mw.wikibase.entity object for a given id. Cached.
local getEntityObject = function( id ) local function getEntityObject( id )
local entity = getCachedEntity( id ) local entity = getFromCache( entityCache, id )
if entity == nil then if entity == nil then
entity = php.getEntity( id ) entity = php.getEntity( id )
@ -94,26 +103,24 @@ function wikibase.setupInterface()
entity = false entity = false
end end
cacheEntity( id, entity ) addToCache( entityCache, id, entity )
end end
if type( entity ) ~= 'table' then if type( entity ) ~= 'table' then
return nil return nil
end end
local entityModule = require( php.getEntityModuleName( id ) )
-- Use a deep clone here, so that people can't modify the entity -- Use a deep clone here, so that people can't modify the entity
return wikibase.entity.create( mw.clone( entity ) ) return entityModule.create( mw.clone( entity ) )
end end
-- Get the entity id for the current page. Cached. -- Get the entity id for the current page. Cached.
-- Nil if not linked to an entity. -- Nil if not linked to an entity.
wikibase.getEntityIdForCurrentPage = function() function wikibase.getEntityIdForCurrentPage()
-- xowa:bgn php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntityIdForCurrentPage.call' )
if reset_entity_id then
reset_entity_id = false
pageEntityId = false
end
-- xowa:end
if pageEntityId == false then if pageEntityId == false then
pageEntityId = php.getEntityId( tostring( mw.title.getCurrentTitle().prefixedText ) ) pageEntityId = php.getEntityId( tostring( mw.title.getCurrentTitle().prefixedText ) )
end end
@ -127,9 +134,12 @@ function wikibase.setupInterface()
-- --
-- @param {string} pageTitle -- @param {string} pageTitle
-- @param {string} [globalSiteId] -- @param {string} [globalSiteId]
wikibase.getEntityIdForTitle = function( pageTitle, globalSiteId ) function wikibase.getEntityIdForTitle( pageTitle, globalSiteId )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntityIdForTitle.call' )
checkType( 'getEntityIdForTitle', 1, pageTitle, 'string' ) checkType( 'getEntityIdForTitle', 1, pageTitle, 'string' )
checkTypeMulti( 'getEntityIdForTitle', 2, globalSiteId, { 'string', 'nil' } ) checkTypeMulti( 'getEntityIdForTitle', 2, globalSiteId, { 'string', 'nil' } )
return php.getEntityId( pageTitle, globalSiteId ) return php.getEntityId( pageTitle, globalSiteId )
end end
@ -137,7 +147,9 @@ function wikibase.setupInterface()
-- specified id. -- specified id.
-- --
-- @param {string} [id] -- @param {string} [id]
wikibase.getEntity = function( id ) function wikibase.getEntity( id )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntity.call' )
checkTypeMulti( 'getEntity', 1, id, { 'string', 'nil' } ) checkTypeMulti( 'getEntity', 1, id, { 'string', 'nil' } )
id = getIdOfConnectedItemIfNil( id ) id = getIdOfConnectedItemIfNil( id )
@ -146,9 +158,9 @@ function wikibase.setupInterface()
return nil return nil
end end
-- if not php.getSetting( 'allowArbitraryDataAccess' ) and id ~= wikibase.getEntityIdForCurrentPage() then if not php.getSetting( 'allowArbitraryDataAccess' ) and id ~= wikibase.getEntityIdForCurrentPage() then
-- error( 'Access to arbitrary entities has been disabled.', 2 ) error( 'Access to arbitrary entities has been disabled.', 2 )
-- end end
return getEntityObject( id ) return getEntityObject( id )
end end
@ -160,17 +172,28 @@ function wikibase.setupInterface()
-- @param {string} propertyId -- @param {string} propertyId
-- @param {string} funcName for error logging -- @param {string} funcName for error logging
-- @param {string} rank Which statements to include. Either "best" or "all". -- @param {string} rank Which statements to include. Either "best" or "all".
local getEntityStatements = function( entityId, propertyId, funcName, rank ) local function getEntityStatements( entityId, propertyId, funcName, rank )
-- if not php.getSetting( 'allowArbitraryDataAccess' ) and entityId ~= wikibase.getEntityIdForCurrentPage() then php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntityStatements.call' )
-- error( 'Access to arbitrary entities has been disabled.', 2 )
-- end if not php.getSetting( 'allowArbitraryDataAccess' ) and entityId ~= wikibase.getEntityIdForCurrentPage() then
error( 'Access to arbitrary entities has been disabled.', 2 )
end
checkType( funcName, 1, entityId, 'string' ) checkType( funcName, 1, entityId, 'string' )
checkType( funcName, 2, propertyId, 'string' ) checkType( funcName, 2, propertyId, 'string' )
local statements = php.getEntityStatements( entityId, propertyId, rank ) local cacheKey = entityId .. '-' .. propertyId .. '-' .. rank
local statements = getFromCache( statementCache, cacheKey )
if statements == nil then
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntityStatements.cache_miss' )
statements = php.getEntityStatements( entityId, propertyId, rank )
addToCache( statementCache, cacheKey, statements )
end
if statements and statements[propertyId] then if statements and statements[propertyId] then
return statements[propertyId] -- Use a clone here, so that users can't modify the cached statement
return mw.clone( statements[propertyId] )
end end
return {} return {}
@ -183,7 +206,7 @@ function wikibase.setupInterface()
-- --
-- @param {string} entityId -- @param {string} entityId
-- @param {string} propertyId -- @param {string} propertyId
wikibase.getBestStatements = function( entityId, propertyId ) function wikibase.getBestStatements( entityId, propertyId )
return getEntityStatements( entityId, propertyId, 'getBestStatements', 'best' ) return getEntityStatements( entityId, propertyId, 'getBestStatements', 'best' )
end end
@ -192,7 +215,7 @@ function wikibase.setupInterface()
-- --
-- @param {string} entityId -- @param {string} entityId
-- @param {string} propertyId -- @param {string} propertyId
wikibase.getAllStatements = function( entityId, propertyId ) function wikibase.getAllStatements( entityId, propertyId )
return getEntityStatements( entityId, propertyId, 'getAllStatements', 'all' ) return getEntityStatements( entityId, propertyId, 'getAllStatements', 'all' )
end end
@ -200,7 +223,9 @@ function wikibase.setupInterface()
-- connected entity, if exists. -- connected entity, if exists.
-- --
-- @param {string} [id] -- @param {string} [id]
wikibase.getEntityUrl = function( id ) function wikibase.getEntityUrl( id )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntityUrl.call' )
checkTypeMulti( 'getEntityUrl', 1, id, { 'string', 'nil' } ) checkTypeMulti( 'getEntityUrl', 1, id, { 'string', 'nil' } )
id = getIdOfConnectedItemIfNil( id ) id = getIdOfConnectedItemIfNil( id )
@ -216,7 +241,9 @@ function wikibase.setupInterface()
-- or of the connected entity, if exists. -- or of the connected entity, if exists.
-- --
-- @param {string} [id] -- @param {string} [id]
wikibase.getLabelWithLang = function( id ) function wikibase.getLabelWithLang( id )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getLabelWithLang.call' )
checkTypeMulti( 'getLabelWithLang', 1, id, { 'string', 'nil' } ) checkTypeMulti( 'getLabelWithLang', 1, id, { 'string', 'nil' } )
id = getIdOfConnectedItemIfNil( id ) id = getIdOfConnectedItemIfNil( id )
@ -231,7 +258,7 @@ function wikibase.setupInterface()
-- Like wikibase.getLabelWithLang, but only returns the plain label. -- Like wikibase.getLabelWithLang, but only returns the plain label.
-- --
-- @param {string} [id] -- @param {string} [id]
wikibase.getLabel = function( id ) function wikibase.getLabel( id )
checkTypeMulti( 'getLabel', 1, id, { 'string', 'nil' } ) checkTypeMulti( 'getLabel', 1, id, { 'string', 'nil' } )
local label = wikibase.getLabelWithLang( id ) local label = wikibase.getLabelWithLang( id )
@ -245,7 +272,9 @@ function wikibase.setupInterface()
-- --
-- @param {string} id -- @param {string} id
-- @param {string} languageCode -- @param {string} languageCode
wikibase.getLabelByLang = function( id, languageCode ) function wikibase.getLabelByLang( id, languageCode )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getLabelByLang.call' )
checkType( 'getLabelByLang', 1, id, 'string' ) checkType( 'getLabelByLang', 1, id, 'string' )
checkType( 'getLabelByLang', 2, languageCode, 'string' ) checkType( 'getLabelByLang', 2, languageCode, 'string' )
@ -256,7 +285,9 @@ function wikibase.setupInterface()
-- or of the connected entity, if exists. -- or of the connected entity, if exists.
-- --
-- @param {string} [id] -- @param {string} [id]
wikibase.getDescriptionWithLang = function( id ) function wikibase.getDescriptionWithLang( id )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getDescriptionWithLang.call' )
checkTypeMulti( 'getDescriptionWithLang', 1, id, { 'string', 'nil' } ) checkTypeMulti( 'getDescriptionWithLang', 1, id, { 'string', 'nil' } )
id = getIdOfConnectedItemIfNil( id ) id = getIdOfConnectedItemIfNil( id )
@ -271,7 +302,7 @@ function wikibase.setupInterface()
-- Like wikibase.getDescriptionWithLang, but only returns the plain description. -- Like wikibase.getDescriptionWithLang, but only returns the plain description.
-- --
-- @param {string} [id] -- @param {string} [id]
wikibase.getDescription = function( id ) function wikibase.getDescription( id )
checkTypeMulti( 'getDescription', 1, id, { 'string', 'nil' } ) checkTypeMulti( 'getDescription', 1, id, { 'string', 'nil' } )
local description = wikibase.getDescriptionWithLang( id ) local description = wikibase.getDescriptionWithLang( id )
@ -285,7 +316,9 @@ function wikibase.setupInterface()
-- --
-- @param {string} itemId -- @param {string} itemId
-- @param {string} [globalSiteId] -- @param {string} [globalSiteId]
wikibase.getSitelink = function( itemId, globalSiteId ) function wikibase.getSitelink( itemId, globalSiteId )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getSitelink.call' )
checkType( 'getSitelink', 1, itemId, 'string' ) checkType( 'getSitelink', 1, itemId, 'string' )
checkTypeMulti( 'getSitelink', 2, globalSiteId, { 'string', 'nil' } ) checkTypeMulti( 'getSitelink', 2, globalSiteId, { 'string', 'nil' } )
@ -298,7 +331,9 @@ function wikibase.setupInterface()
-- Is this a valid (parseable) entity id? -- Is this a valid (parseable) entity id?
-- --
-- @param {string} entityIdSerialization -- @param {string} entityIdSerialization
wikibase.isValidEntityId = function( entityIdSerialization ) function wikibase.isValidEntityId( entityIdSerialization )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.isValidEntityId.call' )
checkType( 'isValidEntityId', 1, entityIdSerialization, 'string' ) checkType( 'isValidEntityId', 1, entityIdSerialization, 'string' )
return php.isValidEntityId( entityIdSerialization ) return php.isValidEntityId( entityIdSerialization )
@ -307,7 +342,9 @@ function wikibase.setupInterface()
-- Does the entity in question exist? -- Does the entity in question exist?
-- --
-- @param {string} entityId -- @param {string} entityId
wikibase.entityExists = function( entityId ) function wikibase.entityExists( entityId )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.entityExists.call' )
checkType( 'entityExists', 1, entityId, 'string' ) checkType( 'entityExists', 1, entityId, 'string' )
if not php.getSetting( 'allowArbitraryDataAccess' ) and entityId ~= wikibase.getEntityIdForCurrentPage() then if not php.getSetting( 'allowArbitraryDataAccess' ) and entityId ~= wikibase.getEntityIdForCurrentPage() then
@ -320,7 +357,9 @@ function wikibase.setupInterface()
-- Render a Snak value from its serialization as wikitext escaped plain text. -- Render a Snak value from its serialization as wikitext escaped plain text.
-- --
-- @param {table} snakSerialization -- @param {table} snakSerialization
wikibase.renderSnak = function( snakSerialization ) function wikibase.renderSnak( snakSerialization )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.renderSnak.call' )
checkType( 'renderSnak', 1, snakSerialization, 'table' ) checkType( 'renderSnak', 1, snakSerialization, 'table' )
return php.renderSnak( snakSerialization ) return php.renderSnak( snakSerialization )
@ -329,7 +368,9 @@ function wikibase.setupInterface()
-- Render a Snak value from its serialization as rich wikitext. -- Render a Snak value from its serialization as rich wikitext.
-- --
-- @param {table} snakSerialization -- @param {table} snakSerialization
wikibase.formatValue = function( snakSerialization ) function wikibase.formatValue( snakSerialization )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.formatValue.call' )
checkType( 'formatValue', 1, snakSerialization, 'table' ) checkType( 'formatValue', 1, snakSerialization, 'table' )
return php.formatValue( snakSerialization ) return php.formatValue( snakSerialization )
@ -338,7 +379,9 @@ function wikibase.setupInterface()
-- Render a list of Snak values from their serialization as wikitext escaped plain text. -- Render a list of Snak values from their serialization as wikitext escaped plain text.
-- --
-- @param {table} snaksSerialization -- @param {table} snaksSerialization
wikibase.renderSnaks = function( snaksSerialization ) function wikibase.renderSnaks( snaksSerialization )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.renderSnaks.call' )
checkType( 'renderSnaks', 1, snaksSerialization, 'table' ) checkType( 'renderSnaks', 1, snaksSerialization, 'table' )
return php.renderSnaks( snaksSerialization ) return php.renderSnaks( snaksSerialization )
@ -347,7 +390,9 @@ function wikibase.setupInterface()
-- Render a list of Snak values from their serialization as rich wikitext. -- Render a list of Snak values from their serialization as rich wikitext.
-- --
-- @param {table} snaksSerialization -- @param {table} snaksSerialization
wikibase.formatValues = function( snaksSerialization ) function wikibase.formatValues( snaksSerialization )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.formatValues.call' )
checkType( 'formatValues', 1, snaksSerialization, 'table' ) checkType( 'formatValues', 1, snaksSerialization, 'table' )
return php.formatValues( snaksSerialization ) return php.formatValues( snaksSerialization )
@ -356,7 +401,9 @@ function wikibase.setupInterface()
-- Returns a property id for the given label or id -- Returns a property id for the given label or id
-- --
-- @param {string} propertyLabelOrId -- @param {string} propertyLabelOrId
wikibase.resolvePropertyId = function( propertyLabelOrId ) function wikibase.resolvePropertyId( propertyLabelOrId )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.resolvePropertyId.call' )
checkType( 'resolvePropertyId', 1, propertyLabelOrId, 'string' ) checkType( 'resolvePropertyId', 1, propertyLabelOrId, 'string' )
return php.resolvePropertyId( propertyLabelOrId ) return php.resolvePropertyId( propertyLabelOrId )
@ -365,13 +412,17 @@ function wikibase.setupInterface()
-- Returns a table of the given property IDs ordered -- Returns a table of the given property IDs ordered
-- --
-- @param {table} propertyIds -- @param {table} propertyIds
wikibase.orderProperties = function( propertyIds ) function wikibase.orderProperties( propertyIds )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.orderProperties.call' )
checkType( 'orderProperties', 1, propertyIds, 'table' ) checkType( 'orderProperties', 1, propertyIds, 'table' )
return php.orderProperties( propertyIds ) return php.orderProperties( propertyIds )
end end
-- Returns an ordered table of serialized property IDs -- Returns an ordered table of serialized property IDs
wikibase.getPropertyOrder = function() function wikibase.getPropertyOrder()
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getPropertyOrder.call' )
return php.getPropertyOrder() return php.getPropertyOrder()
end end
@ -380,7 +431,9 @@ function wikibase.setupInterface()
-- @param {string} fromEntityId -- @param {string} fromEntityId
-- @param {string} propertyId -- @param {string} propertyId
-- @param {table} toIds -- @param {table} toIds
wikibase.getReferencedEntityId = function( fromEntityId, propertyId, toIds ) function wikibase.getReferencedEntityId( fromEntityId, propertyId, toIds )
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getReferencedEntityId.call' )
checkType( 'getReferencedEntityId', 1, fromEntityId, 'string' ) checkType( 'getReferencedEntityId', 1, fromEntityId, 'string' )
checkType( 'getReferencedEntityId', 2, propertyId, 'string' ) checkType( 'getReferencedEntityId', 2, propertyId, 'string' )
checkType( 'getReferencedEntityId', 3, toIds, 'table' ) checkType( 'getReferencedEntityId', 3, toIds, 'table' )
@ -402,6 +455,13 @@ function wikibase.setupInterface()
return php.getReferencedEntityId( fromEntityId, propertyId, toIds ) return php.getReferencedEntityId( fromEntityId, propertyId, toIds )
end end
-- Returns the current site's global id
function wikibase.getGlobalSiteId()
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getGlobalSiteId.call' )
return php.getSetting( 'siteGlobalID' )
end
mw = mw or {} mw = mw or {}
mw.wikibase = wikibase mw.wikibase = wikibase
package.loaded['mw.wikibase'] = wikibase package.loaded['mw.wikibase'] = wikibase
@ -410,8 +470,9 @@ end
-- xowa:bgn -- xowa:bgn
function wikibase.notify_page_changed() function wikibase.notify_page_changed()
reset_entity_id = true -- reset cache everytime page changes
reset_entity_cache = true entityCache = initCache( 15 )
statementCache = initCache( 50 )
end end
-- xowa:end -- xowa:end