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:
parent
b2864f8c6a
commit
c307946bd2
@ -42,6 +42,7 @@ public class WikibaseClientDefault {
|
||||
rv.addSetting("allowDataAccessInUserLanguage", false);
|
||||
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("siteGlobalID", "wikidatawiki");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,8 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
case Proc_isValidEntityId: return IsValidEntityId(args, rslt);
|
||||
case Proc_getPropertyOrder: return GetPropertyOrder(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);
|
||||
}
|
||||
}
|
||||
@ -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_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_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
|
||||
Invk_getLabel = "getLabel", Invk_getLabelByLanguage = "getLabelByLanguage", Invk_getEntity = "getEntity", Invk_entityExists = "entityExists"
|
||||
, 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_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount"
|
||||
, Invk_isValidEntityId = "isValidEntityId", Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
||||
, Invk_incrementStatsKey = "incrementStatsKey", Invk_getEntityModuleName = "getEntityModuleName"
|
||||
;
|
||||
private static final String[] Proc_names = String_.Ary
|
||||
( Invk_getLabel, Invk_getLabelByLanguage, Invk_getEntity, Invk_entityExists, Invk_getEntityStatements, Invk_getSetting, Invk_getEntityUrl
|
||||
, Invk_renderSnak, Invk_formatValue, Invk_renderSnaks, Invk_formatValues
|
||||
, 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);}
|
||||
|
||||
@ -324,6 +327,21 @@ public function formatValues( $snaksSerialization ) {
|
||||
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)
|
||||
}
|
||||
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) {
|
||||
// get qid / pid from scrib_arg[0]
|
||||
byte[] xid_bry = args.Pull_bry(0);
|
||||
@ -342,3 +360,16 @@ public function formatValues( $snaksSerialization ) {
|
||||
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
|
||||
*/
|
||||
|
@ -195,6 +195,15 @@ public class Basic__tst {
|
||||
@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
|
||||
}
|
||||
@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_ {
|
||||
public static Keyval[] Get_snaks_ary(Wdata_wiki_mgr_fxt wdata_fxt, Wbase_claim_base... ary) {
|
||||
|
@ -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
|
||||
Provides Lua setupInterface
|
||||
@ -12,56 +13,64 @@
|
||||
]]
|
||||
|
||||
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 checkType = util.checkType
|
||||
local checkTypeMulti = util.checkTypeMulti
|
||||
|
||||
local cacheSize = 15 -- Size of the LRU cache being used to cache entities
|
||||
local cacheOrder = {}
|
||||
local entityCache = {}
|
||||
|
||||
-- Cache a given entity (can also be false, in case it doesn't exist).
|
||||
-- Get a cache data structure to use with addToCache and getFromCache
|
||||
-- with a given maximum size.
|
||||
--
|
||||
-- @param entityId
|
||||
-- @param entity
|
||||
local cacheEntity = function( entityId, entity )
|
||||
if #cacheOrder == cacheSize then
|
||||
local entityIdToRemove = table.remove( cacheOrder, cacheSize )
|
||||
entityCache[ entityIdToRemove ] = nil
|
||||
-- @param maxCacheSize
|
||||
local function initCache( maxCacheSize )
|
||||
return {
|
||||
data = {},
|
||||
order = {},
|
||||
size = 0,
|
||||
maxCacheSize = maxCacheSize,
|
||||
}
|
||||
end
|
||||
|
||||
table.insert( cacheOrder, 1, entityId )
|
||||
entityCache[ entityId ] = entity
|
||||
end
|
||||
|
||||
-- Retrieve an entity. Will return false in case it's known to not exist
|
||||
-- and nil in case of a cache miss.
|
||||
-- Cache a given value (can also be false, in case it doesn't exist).
|
||||
--
|
||||
-- @param entityId
|
||||
local getCachedEntity = function( entityId )
|
||||
-- xowa:bgn
|
||||
if reset_entity_cache then
|
||||
reset_entity_cache = false
|
||||
entityCache = {}
|
||||
-- @param cache
|
||||
-- @param key
|
||||
-- @param value
|
||||
local function addToCache( cache, key, value )
|
||||
if cache.size == cache.maxCacheSize then
|
||||
local toRemove = table.remove( cache.order, cache.maxCacheSize )
|
||||
cache.data[ toRemove ] = nil
|
||||
else
|
||||
cache.size = cache.size + 1
|
||||
end
|
||||
-- xowa:end
|
||||
if entityCache[ entityId ] ~= nil then
|
||||
for cacheOrderId, cacheOrderEntityId in pairs( cacheOrder ) do
|
||||
if cacheOrderEntityId == entityId then
|
||||
table.remove( cacheOrder, cacheOrderId )
|
||||
|
||||
table.insert( cache.order, 1, key )
|
||||
cache.data[ key ] = value
|
||||
end
|
||||
|
||||
-- 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
|
||||
end
|
||||
end
|
||||
table.insert( cacheOrder, 1, entityId )
|
||||
table.insert( cache.order, 1, key )
|
||||
end
|
||||
|
||||
return entityCache[ entityId ]
|
||||
return cache.data[ key ]
|
||||
end
|
||||
|
||||
-- 15 slot cache for entities
|
||||
local entityCache = initCache( 15 )
|
||||
|
||||
-- 50 slot cache for statements
|
||||
local statementCache = initCache( 50 )
|
||||
|
||||
function wikibase.setupInterface()
|
||||
local php = mw_interface
|
||||
mw_interface = nil
|
||||
@ -70,7 +79,7 @@ function wikibase.setupInterface()
|
||||
local pageEntityId = false
|
||||
|
||||
-- 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
|
||||
return wikibase.getEntityIdForCurrentPage()
|
||||
end
|
||||
@ -79,8 +88,8 @@ function wikibase.setupInterface()
|
||||
end
|
||||
|
||||
-- Get the mw.wikibase.entity object for a given id. Cached.
|
||||
local getEntityObject = function( id )
|
||||
local entity = getCachedEntity( id )
|
||||
local function getEntityObject( id )
|
||||
local entity = getFromCache( entityCache, id )
|
||||
|
||||
if entity == nil then
|
||||
entity = php.getEntity( id )
|
||||
@ -94,26 +103,24 @@ function wikibase.setupInterface()
|
||||
entity = false
|
||||
end
|
||||
|
||||
cacheEntity( id, entity )
|
||||
addToCache( entityCache, id, entity )
|
||||
end
|
||||
|
||||
if type( entity ) ~= 'table' then
|
||||
return nil
|
||||
end
|
||||
|
||||
local entityModule = require( php.getEntityModuleName( id ) )
|
||||
|
||||
-- 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
|
||||
|
||||
-- Get the entity id for the current page. Cached.
|
||||
-- Nil if not linked to an entity.
|
||||
wikibase.getEntityIdForCurrentPage = function()
|
||||
-- xowa:bgn
|
||||
if reset_entity_id then
|
||||
reset_entity_id = false
|
||||
pageEntityId = false
|
||||
end
|
||||
-- xowa:end
|
||||
function wikibase.getEntityIdForCurrentPage()
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntityIdForCurrentPage.call' )
|
||||
|
||||
if pageEntityId == false then
|
||||
pageEntityId = php.getEntityId( tostring( mw.title.getCurrentTitle().prefixedText ) )
|
||||
end
|
||||
@ -127,9 +134,12 @@ function wikibase.setupInterface()
|
||||
--
|
||||
-- @param {string} pageTitle
|
||||
-- @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' )
|
||||
checkTypeMulti( 'getEntityIdForTitle', 2, globalSiteId, { 'string', 'nil' } )
|
||||
|
||||
return php.getEntityId( pageTitle, globalSiteId )
|
||||
end
|
||||
|
||||
@ -137,7 +147,9 @@ function wikibase.setupInterface()
|
||||
-- specified 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' } )
|
||||
|
||||
id = getIdOfConnectedItemIfNil( id )
|
||||
@ -146,9 +158,9 @@ function wikibase.setupInterface()
|
||||
return nil
|
||||
end
|
||||
|
||||
-- if not php.getSetting( 'allowArbitraryDataAccess' ) and id ~= wikibase.getEntityIdForCurrentPage() then
|
||||
-- error( 'Access to arbitrary entities has been disabled.', 2 )
|
||||
-- end
|
||||
if not php.getSetting( 'allowArbitraryDataAccess' ) and id ~= wikibase.getEntityIdForCurrentPage() then
|
||||
error( 'Access to arbitrary entities has been disabled.', 2 )
|
||||
end
|
||||
|
||||
return getEntityObject( id )
|
||||
end
|
||||
@ -160,17 +172,28 @@ function wikibase.setupInterface()
|
||||
-- @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
|
||||
-- error( 'Access to arbitrary entities has been disabled.', 2 )
|
||||
-- end
|
||||
local function getEntityStatements( entityId, propertyId, funcName, rank )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.getEntityStatements.call' )
|
||||
|
||||
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, 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
|
||||
return statements[propertyId]
|
||||
-- Use a clone here, so that users can't modify the cached statement
|
||||
return mw.clone( statements[propertyId] )
|
||||
end
|
||||
|
||||
return {}
|
||||
@ -183,7 +206,7 @@ function wikibase.setupInterface()
|
||||
--
|
||||
-- @param {string} entityId
|
||||
-- @param {string} propertyId
|
||||
wikibase.getBestStatements = function( entityId, propertyId )
|
||||
function wikibase.getBestStatements( entityId, propertyId )
|
||||
return getEntityStatements( entityId, propertyId, 'getBestStatements', 'best' )
|
||||
end
|
||||
|
||||
@ -192,7 +215,7 @@ function wikibase.setupInterface()
|
||||
--
|
||||
-- @param {string} entityId
|
||||
-- @param {string} propertyId
|
||||
wikibase.getAllStatements = function( entityId, propertyId )
|
||||
function wikibase.getAllStatements( entityId, propertyId )
|
||||
return getEntityStatements( entityId, propertyId, 'getAllStatements', 'all' )
|
||||
end
|
||||
|
||||
@ -200,7 +223,9 @@ function wikibase.setupInterface()
|
||||
-- connected entity, if exists.
|
||||
--
|
||||
-- @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' } )
|
||||
|
||||
id = getIdOfConnectedItemIfNil( id )
|
||||
@ -216,7 +241,9 @@ function wikibase.setupInterface()
|
||||
-- or of the connected entity, if exists.
|
||||
--
|
||||
-- @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' } )
|
||||
|
||||
id = getIdOfConnectedItemIfNil( id )
|
||||
@ -231,7 +258,7 @@ function wikibase.setupInterface()
|
||||
-- Like wikibase.getLabelWithLang, but only returns the plain label.
|
||||
--
|
||||
-- @param {string} [id]
|
||||
wikibase.getLabel = function( id )
|
||||
function wikibase.getLabel( id )
|
||||
checkTypeMulti( 'getLabel', 1, id, { 'string', 'nil' } )
|
||||
local label = wikibase.getLabelWithLang( id )
|
||||
|
||||
@ -245,7 +272,9 @@ function wikibase.setupInterface()
|
||||
--
|
||||
-- @param {string} id
|
||||
-- @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', 2, languageCode, 'string' )
|
||||
|
||||
@ -256,7 +285,9 @@ function wikibase.setupInterface()
|
||||
-- or of the connected entity, if exists.
|
||||
--
|
||||
-- @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' } )
|
||||
|
||||
id = getIdOfConnectedItemIfNil( id )
|
||||
@ -271,7 +302,7 @@ function wikibase.setupInterface()
|
||||
-- Like wikibase.getDescriptionWithLang, but only returns the plain description.
|
||||
--
|
||||
-- @param {string} [id]
|
||||
wikibase.getDescription = function( id )
|
||||
function wikibase.getDescription( id )
|
||||
checkTypeMulti( 'getDescription', 1, id, { 'string', 'nil' } )
|
||||
local description = wikibase.getDescriptionWithLang( id )
|
||||
|
||||
@ -285,7 +316,9 @@ function wikibase.setupInterface()
|
||||
--
|
||||
-- @param {string} itemId
|
||||
-- @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' )
|
||||
checkTypeMulti( 'getSitelink', 2, globalSiteId, { 'string', 'nil' } )
|
||||
|
||||
@ -298,7 +331,9 @@ function wikibase.setupInterface()
|
||||
-- Is this a valid (parseable) entity id?
|
||||
--
|
||||
-- @param {string} entityIdSerialization
|
||||
wikibase.isValidEntityId = function( entityIdSerialization )
|
||||
function wikibase.isValidEntityId( entityIdSerialization )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.isValidEntityId.call' )
|
||||
|
||||
checkType( 'isValidEntityId', 1, entityIdSerialization, 'string' )
|
||||
|
||||
return php.isValidEntityId( entityIdSerialization )
|
||||
@ -307,7 +342,9 @@ function wikibase.setupInterface()
|
||||
-- Does the entity in question exist?
|
||||
--
|
||||
-- @param {string} entityId
|
||||
wikibase.entityExists = function( entityId )
|
||||
function wikibase.entityExists( entityId )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.entityExists.call' )
|
||||
|
||||
checkType( 'entityExists', 1, entityId, 'string' )
|
||||
|
||||
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.
|
||||
--
|
||||
-- @param {table} snakSerialization
|
||||
wikibase.renderSnak = function( snakSerialization )
|
||||
function wikibase.renderSnak( snakSerialization )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.renderSnak.call' )
|
||||
|
||||
checkType( 'renderSnak', 1, snakSerialization, 'table' )
|
||||
|
||||
return php.renderSnak( snakSerialization )
|
||||
@ -329,7 +368,9 @@ function wikibase.setupInterface()
|
||||
-- Render a Snak value from its serialization as rich wikitext.
|
||||
--
|
||||
-- @param {table} snakSerialization
|
||||
wikibase.formatValue = function( snakSerialization )
|
||||
function wikibase.formatValue( snakSerialization )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.formatValue.call' )
|
||||
|
||||
checkType( 'formatValue', 1, snakSerialization, 'table' )
|
||||
|
||||
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.
|
||||
--
|
||||
-- @param {table} snaksSerialization
|
||||
wikibase.renderSnaks = function( snaksSerialization )
|
||||
function wikibase.renderSnaks( snaksSerialization )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.renderSnaks.call' )
|
||||
|
||||
checkType( 'renderSnaks', 1, snaksSerialization, 'table' )
|
||||
|
||||
return php.renderSnaks( snaksSerialization )
|
||||
@ -347,7 +390,9 @@ function wikibase.setupInterface()
|
||||
-- Render a list of Snak values from their serialization as rich wikitext.
|
||||
--
|
||||
-- @param {table} snaksSerialization
|
||||
wikibase.formatValues = function( snaksSerialization )
|
||||
function wikibase.formatValues( snaksSerialization )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.formatValues.call' )
|
||||
|
||||
checkType( 'formatValues', 1, snaksSerialization, 'table' )
|
||||
|
||||
return php.formatValues( snaksSerialization )
|
||||
@ -356,7 +401,9 @@ function wikibase.setupInterface()
|
||||
-- Returns a property id for the given label or id
|
||||
--
|
||||
-- @param {string} propertyLabelOrId
|
||||
wikibase.resolvePropertyId = function( propertyLabelOrId )
|
||||
function wikibase.resolvePropertyId( propertyLabelOrId )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.resolvePropertyId.call' )
|
||||
|
||||
checkType( 'resolvePropertyId', 1, propertyLabelOrId, 'string' )
|
||||
|
||||
return php.resolvePropertyId( propertyLabelOrId )
|
||||
@ -365,13 +412,17 @@ function wikibase.setupInterface()
|
||||
-- Returns a table of the given property IDs ordered
|
||||
--
|
||||
-- @param {table} propertyIds
|
||||
wikibase.orderProperties = function( propertyIds )
|
||||
function wikibase.orderProperties( propertyIds )
|
||||
php.incrementStatsKey( 'wikibase.client.scribunto.wikibase.orderProperties.call' )
|
||||
|
||||
checkType( 'orderProperties', 1, propertyIds, 'table' )
|
||||
return php.orderProperties( propertyIds )
|
||||
end
|
||||
|
||||
-- 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()
|
||||
end
|
||||
|
||||
@ -380,7 +431,9 @@ function wikibase.setupInterface()
|
||||
-- @param {string} fromEntityId
|
||||
-- @param {string} propertyId
|
||||
-- @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', 2, propertyId, 'string' )
|
||||
checkType( 'getReferencedEntityId', 3, toIds, 'table' )
|
||||
@ -402,6 +455,13 @@ function wikibase.setupInterface()
|
||||
return php.getReferencedEntityId( fromEntityId, propertyId, toIds )
|
||||
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.wikibase = wikibase
|
||||
package.loaded['mw.wikibase'] = wikibase
|
||||
@ -410,8 +470,9 @@ end
|
||||
|
||||
-- xowa:bgn
|
||||
function wikibase.notify_page_changed()
|
||||
reset_entity_id = true
|
||||
reset_entity_cache = true
|
||||
-- reset cache everytime page changes
|
||||
entityCache = initCache( 15 )
|
||||
statementCache = initCache( 50 )
|
||||
end
|
||||
-- xowa:end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user