mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Wikibase: Add entityExists
This commit is contained in:
parent
29a8fb7824
commit
6348aa6177
@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||||
public class Scrib_lib_mgr {
|
public class Scrib_lib_mgr {
|
||||||
private List_adp list = List_adp_.New();
|
private final List_adp list = List_adp_.New();
|
||||||
public int Len() {return list.Count();}
|
public int Len() {return list.Count();}
|
||||||
public void Add(Scrib_lib v) {list.Add(v); v.Init();}
|
public void Add(Scrib_lib v) {list.Add(v); v.Init();}
|
||||||
public Scrib_lib Get_at(int i) {return (Scrib_lib)list.Get_at(i);}
|
public Scrib_lib Get_at(int i) {return (Scrib_lib)list.Get_at(i);}
|
||||||
|
@ -19,10 +19,13 @@ import gplx.xowa.wikis.domains.*;
|
|||||||
import gplx.xowa.xtns.scribunto.procs.*;
|
import gplx.xowa.xtns.scribunto.procs.*;
|
||||||
import gplx.xowa.xtns.wbases.mediawiki.client.includes.*; import gplx.xowa.xtns.wbases.mediawiki.client.includes.dataAccess.scribunto.*;
|
import gplx.xowa.xtns.wbases.mediawiki.client.includes.*; import gplx.xowa.xtns.wbases.mediawiki.client.includes.dataAccess.scribunto.*;
|
||||||
public class Scrib_lib_wikibase implements Scrib_lib {
|
public class Scrib_lib_wikibase implements Scrib_lib {
|
||||||
|
private final Scrib_core core;
|
||||||
private Wbase_entity_accessor entity_accessor;
|
private Wbase_entity_accessor entity_accessor;
|
||||||
private WikibaseLanguageIndependentLuaBindings wikibaseLanguageIndependentLuaBindings;
|
private WikibaseLanguageIndependentLuaBindings wikibaseLanguageIndependentLuaBindings;
|
||||||
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private Scrib_core core;
|
private Scrib_lua_proc notify_page_changed_fnc;
|
||||||
|
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;}
|
||||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||||
|
public Scrib_proc_mgr Procs() {return procs;} private final Scrib_proc_mgr procs = new Scrib_proc_mgr();
|
||||||
public Scrib_lib Init() {
|
public Scrib_lib Init() {
|
||||||
procs.Init_by_lib(this, Proc_names);
|
procs.Init_by_lib(this, Proc_names);
|
||||||
Wbase_doc_mgr entityMgr = core.App().Wiki_mgr().Wdata_mgr().Doc_mgr;
|
Wbase_doc_mgr entityMgr = core.App().Wiki_mgr().Wdata_mgr().Doc_mgr;
|
||||||
@ -36,77 +39,97 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
|||||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.wikibase.lua"));
|
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.wikibase.lua"));
|
||||||
notify_page_changed_fnc = mod.Fncs_get_by_key("notify_page_changed");
|
notify_page_changed_fnc = mod.Fncs_get_by_key("notify_page_changed");
|
||||||
return mod;
|
return mod;
|
||||||
} private Scrib_lua_proc notify_page_changed_fnc;
|
}
|
||||||
public Scrib_proc_mgr Procs() {return procs;} private Scrib_proc_mgr procs = new Scrib_proc_mgr();
|
|
||||||
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case Proc_getLabel: return GetLabel(args, rslt);
|
case Proc_getLabel: return GetLabel(args, rslt);
|
||||||
// getLabelByLanguage
|
case Proc_getLabelByLanguage: return GetLabelByLanguage(args, rslt);
|
||||||
case Proc_getEntity: return GetEntity(args, rslt);
|
case Proc_getEntity: return GetEntity(args, rslt);
|
||||||
|
case Proc_entityExists: return EntityExists(args, rslt);
|
||||||
case Proc_getEntityStatements: return GetEntityStatements(args, rslt);
|
case Proc_getEntityStatements: return GetEntityStatements(args, rslt);
|
||||||
case Proc_getSetting: return GetSetting(args, rslt);
|
case Proc_getSetting: return GetSetting(args, rslt);
|
||||||
case Proc_getEntityUrl: return GetEntityUrl(args, rslt);
|
case Proc_getEntityUrl: return GetEntityUrl(args, rslt);
|
||||||
case Proc_renderSnak: return RenderSnak(args, rslt);
|
case Proc_renderSnak: return RenderSnak(args, rslt);
|
||||||
// formatValue
|
case Proc_formatValue: return FormatValue(args, rslt);
|
||||||
case Proc_renderSnaks: return RenderSnaks(args, rslt);
|
case Proc_renderSnaks: return RenderSnaks(args, rslt);
|
||||||
case Proc_getEntityId: return GetEntityId(args, rslt);
|
case Proc_getEntityId: return GetEntityId(args, rslt);
|
||||||
|
case Proc_getReferencedEntityId: return GetReferencedEntityId(args, rslt);
|
||||||
case Proc_getUserLang: return GetUserLang(args, rslt);
|
case Proc_getUserLang: return GetUserLang(args, rslt);
|
||||||
case Proc_getDescription: return GetDescription(args, rslt);
|
case Proc_getDescription: return GetDescription(args, rslt);
|
||||||
case Proc_resolvePropertyId: return ResolvePropertyId(args, rslt);
|
case Proc_resolvePropertyId: return ResolvePropertyId(args, rslt);
|
||||||
case Proc_getSiteLinkPageName: return GetSiteLinkPageName(args, rslt);
|
case Proc_getSiteLinkPageName: return GetSiteLinkPageName(args, rslt);
|
||||||
case Proc_incrementExpensiveFunctionCount: return IncrementExpensiveFunctionCount(args, rslt);
|
case Proc_incrementExpensiveFunctionCount: return IncrementExpensiveFunctionCount(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_isValidEntityId: return IsValidEntityId(args, rslt);
|
|
||||||
default: throw Err_.new_unhandled(key);
|
default: throw Err_.new_unhandled(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static final int
|
private static final int
|
||||||
Proc_getLabel = 0 //, Proc_getLabelByLanguage = 1
|
Proc_getLabel = 0, Proc_getLabelByLanguage = 1, Proc_getEntity = 2, Proc_entityExists = 3, Proc_getEntityStatements = 4, Proc_getSetting = 5, Proc_getEntityUrl = 6
|
||||||
, Proc_getEntity = 2, Proc_getEntityStatements = 3, Proc_getSetting = 4, Proc_getEntityUrl = 5, Proc_renderSnak = 6//, Proc_formatValue = 7
|
, Proc_renderSnak = 7, Proc_formatValue = 8, Proc_renderSnaks = 9, Proc_getEntityId = 10, Proc_getReferencedEntityId = 11
|
||||||
, Proc_renderSnaks = 8, Proc_getEntityId = 9, Proc_getUserLang = 10, Proc_getDescription = 11, Proc_resolvePropertyId = 12
|
, Proc_getUserLang = 12, Proc_getDescription = 13, Proc_resolvePropertyId = 14, Proc_getSiteLinkPageName = 15, Proc_incrementExpensiveFunctionCount = 16
|
||||||
, Proc_getSiteLinkPageName = 13, Proc_incrementExpensiveFunctionCount = 14, Proc_getPropertyOrder = 15, Proc_orderProperties = 16, Proc_isValidEntityId = 17;
|
, Proc_isValidEntityId = 17, Proc_getPropertyOrder = 18, Proc_orderProperties = 19;
|
||||||
public static final String
|
public static final String
|
||||||
Invk_getLabel = "getLabel", Invk_getLabelByLanguage = "getLabelByLanguage", Invk_getEntity = "getEntity", Invk_getEntityStatements = "getEntityStatements"
|
Invk_getLabel = "getLabel", Invk_getLabelByLanguage = "getLabelByLanguage", Invk_getEntity = "getEntity", Invk_entityExists = "entityExists"
|
||||||
, Invk_getSetting = "getSetting", Invk_getEntityUrl = "getEntityUrl", Invk_renderSnak = "renderSnak", Invk_formatValue = "formatValue", Invk_renderSnaks = "renderSnaks"
|
, Invk_getEntityStatements = "getEntityStatements"
|
||||||
, Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId"
|
, Invk_getSetting = "getSetting", Invk_getEntityUrl = "getEntityUrl"
|
||||||
, Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount", Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
, Invk_renderSnak = "renderSnak", Invk_formatValue = "formatValue", Invk_renderSnaks = "renderSnaks"
|
||||||
, Invk_isValidEntityId = "isValidEntityId"
|
, Invk_getEntityId = "getEntityId", Invk_getReferencedEntityId = "getReferencedEntityId"
|
||||||
|
, Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId"
|
||||||
|
, Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount"
|
||||||
|
, Invk_isValidEntityId = "isValidEntityId", Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
||||||
;
|
;
|
||||||
private static final String[] Proc_names = String_.Ary
|
private static final String[] Proc_names = String_.Ary
|
||||||
( Invk_getLabel, Invk_getLabelByLanguage, Invk_getEntity, Invk_getEntityStatements, Invk_getSetting, Invk_getEntityUrl, Invk_renderSnak, Invk_formatValue, Invk_renderSnaks
|
( Invk_getLabel, Invk_getLabelByLanguage, Invk_getEntity, Invk_entityExists, Invk_getEntityStatements, Invk_getSetting, Invk_getEntityUrl
|
||||||
, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount
|
, Invk_renderSnak, Invk_formatValue, Invk_renderSnaks
|
||||||
, Invk_getPropertyOrder, Invk_orderProperties, Invk_isValidEntityId
|
, Invk_getEntityId, Invk_getReferencedEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount
|
||||||
|
, Invk_isValidEntityId, Invk_getPropertyOrder, Invk_orderProperties
|
||||||
);
|
);
|
||||||
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);}
|
||||||
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
|
||||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
|
||||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
|
||||||
}
|
|
||||||
public boolean GetEntity(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
|
||||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core);
|
|
||||||
if (wdoc == null)
|
|
||||||
return rslt.Init_ary_empty();
|
|
||||||
// return rslt.Init_obj(Keyval_.Ary(Keyval_.new_("schemaVersion", 2))); // NOTE: was "rslt.Init_ary_empty()" PAGE:de.w:Critérium_International_2016 DATE:2017-12-30
|
|
||||||
|
|
||||||
Wbase_prop_mgr prop_mgr = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Prop_mgr();
|
public boolean IsValidEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
|
||||||
}
|
|
||||||
public boolean GetEntityUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
|
||||||
byte[] entityId = args.Pull_bry(0);
|
byte[] entityId = args.Pull_bry(0);
|
||||||
byte[] entity_url = Wbase_client.getDefaultInstance().RepoLinker().getEntityUrl(entityId);
|
|
||||||
return rslt.Init_obj(entity_url);
|
// EntityId.php.extractSerializationParts expands "localRepoName:random:serialization:parts:entityId"
|
||||||
|
int colonPos = Bry_find_.Find_bwd(entityId, Byte_ascii.Colon);
|
||||||
|
if (colonPos != -1) {
|
||||||
|
entityId = Bry_.Mid(entityId, colonPos + 1);
|
||||||
}
|
}
|
||||||
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str());}
|
|
||||||
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
/* REF: https://github.com/wmde/WikibaseDataModel/tree/master/src/Entity/
|
||||||
Xowe_wiki wiki = core.Wiki();
|
PropertyId.php.PATTERN: '/^P[1-9]\d{0,9}\z/i';
|
||||||
Wdata_wiki_mgr wdata_mgr = wiki.Appe().Wiki_mgr().Wdata_mgr();
|
ItemId.php.PATTERN : '/^Q[1-9]\d{0,9}\z/i';
|
||||||
String rv = Wdata_prop_val_visitor_.Render_snak(wdata_mgr, wiki, core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
*/
|
||||||
return rslt.Init_obj(rv);
|
boolean valid = false;
|
||||||
|
if (entityId.length > 0) {
|
||||||
|
switch (entityId[0]) {
|
||||||
|
case Byte_ascii.Ltr_P:
|
||||||
|
case Byte_ascii.Ltr_Q:
|
||||||
|
if (entityId.length > 1) {
|
||||||
|
switch (entityId[1]) {
|
||||||
|
case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||||
|
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||||
|
boolean numeric = true;
|
||||||
|
for (int i = 2; i < entityId.length; i++) {
|
||||||
|
switch (entityId[i]) {
|
||||||
|
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||||
|
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
numeric = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
public boolean RenderSnaks(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
}
|
||||||
String rv = Wdata_prop_val_visitor_.Render_snaks(core.Wiki(), core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
if (numeric)
|
||||||
return rslt.Init_obj(rv);
|
valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rslt.Init_obj(valid);
|
||||||
}
|
}
|
||||||
public boolean GetEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean GetEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
byte[] ttl_bry = args.Pull_bry(0);
|
byte[] ttl_bry = args.Pull_bry(0);
|
||||||
@ -115,25 +138,27 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
|||||||
byte[] rv = wiki.Appe().Wiki_mgr().Wdata_mgr().Qid_mgr.Get_or_null(wiki, ttl); if (rv == null) rv = Bry_.Empty;
|
byte[] rv = wiki.Appe().Wiki_mgr().Wdata_mgr().Qid_mgr.Get_or_null(wiki, ttl); if (rv == null) rv = Bry_.Empty;
|
||||||
return rslt.Init_obj(rv);
|
return rslt.Init_obj(rv);
|
||||||
}
|
}
|
||||||
public boolean GetUserLang(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean GetReferencedEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
return rslt.Init_obj(core.App().Usere().Lang().Key_bry());
|
throw Err_.new_unimplemented();
|
||||||
}
|
}
|
||||||
public boolean GetDescription(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean EntityExists(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
Wdata_doc wdoc = Get_wdoc_or_null(args, core, false);
|
||||||
return rslt.Init_obj(wdoc.Descr_list__get_or_fallback(core.Lang()));
|
return rslt.Init_obj(wdoc != null);
|
||||||
}
|
}
|
||||||
public boolean ResolvePropertyId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean GetEntity(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty(); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
Wdata_doc wdoc = Get_wdoc_or_null(args, core, true);
|
||||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
if (wdoc == null) {
|
||||||
|
return rslt.Init_ary_empty();
|
||||||
|
// return rslt.Init_obj(Keyval_.Ary(Keyval_.new_("schemaVersion", 2))); // NOTE: was "rslt.Init_ary_empty()" PAGE:de.w:Critérium_International_2016 DATE:2017-12-30
|
||||||
}
|
}
|
||||||
public boolean GetSiteLinkPageName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
|
||||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty(); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
Wbase_prop_mgr prop_mgr = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Prop_mgr();
|
||||||
Xow_domain_itm domain_itm = core.Wiki().Domain_itm();
|
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
||||||
return rslt.Init_obj(wdoc.Slink_list__get_or_fallback(domain_itm.Abrv_wm()));
|
|
||||||
}
|
}
|
||||||
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 GetEntityUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
byte[] entityId = args.Pull_bry(0);
|
||||||
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
byte[] entity_url = Wbase_client.getDefaultInstance().RepoLinker().getEntityUrl(entityId);
|
||||||
|
return rslt.Init_obj(entity_url);
|
||||||
}
|
}
|
||||||
public boolean GetEntityStatements(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean GetEntityStatements(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
byte[] prefixedEntityId = args.Pull_bry(0);
|
byte[] prefixedEntityId = args.Pull_bry(0);
|
||||||
@ -146,9 +171,18 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
|||||||
return rslt.Init_null();
|
return rslt.Init_null();
|
||||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl_claims_prop_ary(prop_mgr, String_.new_u8(propertyId), statements, 1));
|
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl_claims_prop_ary(prop_mgr, String_.new_u8(propertyId), statements, 1));
|
||||||
}
|
}
|
||||||
public boolean IsValidEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
return rslt.Init_obj(true);
|
Xowe_wiki wiki = core.Wiki();
|
||||||
} /*
|
Wdata_wiki_mgr wdata_mgr = wiki.Appe().Wiki_mgr().Wdata_mgr();
|
||||||
|
String rv = Wdata_prop_val_visitor_.Render_snak(wdata_mgr, wiki, core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
||||||
|
return rslt.Init_obj(rv);
|
||||||
|
}
|
||||||
|
public boolean RenderSnaks(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
String rv = Wdata_prop_val_visitor_.Render_snaks(core.Wiki(), core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
||||||
|
return rslt.Init_obj(rv);
|
||||||
|
}
|
||||||
|
public boolean FormatValue(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
/*
|
||||||
public function formatValues( $snaksSerialization ) {
|
public function formatValues( $snaksSerialization ) {
|
||||||
$this->checkType( 'formatValues', 1, $snaksSerialization, 'table' );
|
$this->checkType( 'formatValues', 1, $snaksSerialization, 'table' );
|
||||||
try {
|
try {
|
||||||
@ -159,20 +193,58 @@ public function formatValues( $snaksSerialization ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
throw Err_.new_unimplemented();
|
||||||
|
}
|
||||||
|
public boolean ResolvePropertyId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
Wdata_doc wdoc = Get_wdoc_or_null(args, core, true); if (wdoc == null) return rslt.Init_ary_empty(); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
||||||
|
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||||
|
}
|
||||||
|
public boolean GetPropertyOrder(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
throw Err_.new_("wbase", "getPropertyOrder not implemented", "url", core.Page().Url().To_str());
|
||||||
|
}
|
||||||
|
public boolean OrderProperties(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
throw Err_.new_("wbase", "orderProperties not implemented", "url", core.Page().Url().To_str());
|
||||||
|
}
|
||||||
|
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
Wdata_doc wdoc = Get_wdoc_or_null(args, core, true);
|
||||||
|
if (wdoc == null)
|
||||||
|
return rslt.Init_ary_empty();
|
||||||
|
else
|
||||||
|
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||||
|
}
|
||||||
public boolean GetLabelByLanguage(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean GetLabelByLanguage(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
byte[] prefixedEntityId = args.Pull_bry(0);
|
byte[] prefixedEntityId = args.Pull_bry(0);
|
||||||
byte[] languageCode = args.Pull_bry(1);
|
byte[] languageCode = args.Pull_bry(1);
|
||||||
return rslt.Init_obj(wikibaseLanguageIndependentLuaBindings.getLabelByLanguage(prefixedEntityId, languageCode));
|
return rslt.Init_obj(wikibaseLanguageIndependentLuaBindings.getLabelByLanguage(prefixedEntityId, languageCode));
|
||||||
}
|
}
|
||||||
private static Wdata_doc Get_wdoc_or_null(Scrib_proc_args args, Scrib_core core) {
|
public boolean GetSiteLinkPageName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
Wdata_doc wdoc = Get_wdoc_or_null(args, core, true); if (wdoc == null) return rslt.Init_ary_empty(); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
||||||
|
Xow_domain_itm domain_itm = core.Wiki().Domain_itm();
|
||||||
|
return rslt.Init_obj(wdoc.Slink_list__get_or_fallback(domain_itm.Abrv_wm()));
|
||||||
|
}
|
||||||
|
public boolean GetDescription(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
Wdata_doc wdoc = Get_wdoc_or_null(args, core, true); if (wdoc == null) return rslt.Init_ary_empty();
|
||||||
|
return rslt.Init_obj(wdoc.Descr_list__get_or_fallback(core.Lang()));
|
||||||
|
}
|
||||||
|
public boolean GetUserLang(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
return rslt.Init_obj(core.App().Usere().Lang().Key_bry());
|
||||||
|
}
|
||||||
|
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
||||||
|
}
|
||||||
|
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str());
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
private static Wdata_doc Get_wdoc_or_null(Scrib_proc_args args, Scrib_core core, boolean logMissing) {
|
||||||
// get qid / pid from scrib_arg[0]; if none, return null;
|
// get qid / pid from scrib_arg[0]; if none, return null;
|
||||||
byte[] xid_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(xid_bry)) return null; // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
byte[] xid_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(xid_bry)) return null; // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||||
|
|
||||||
// get wdoc
|
// get wdoc
|
||||||
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Doc_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Doc_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
||||||
if (wdoc == null) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), xid_bry);
|
if (wdoc == null && logMissing) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), xid_bry);
|
||||||
return wdoc;
|
return wdoc;
|
||||||
}
|
}
|
||||||
public boolean GetPropertyOrder(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getPropertyOrder not implemented", "url", core.Page().Url().To_str());}
|
|
||||||
public boolean OrderProperties(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "orderProperties not implemented", "url", core.Page().Url().To_str());}
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,27 @@ public class Scrib_lib_wikibase_tst {
|
|||||||
// @Test public void GetGlobalSiteId() {
|
// @Test public void GetGlobalSiteId() {
|
||||||
// fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
// fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
||||||
// }
|
// }
|
||||||
|
@Test public void IsValidEntityId() {
|
||||||
|
IsValidEntityIdCheck(Bool_.Y, "P1");
|
||||||
|
IsValidEntityIdCheck(Bool_.Y, "P123");
|
||||||
|
IsValidEntityIdCheck(Bool_.Y, "Q1");
|
||||||
|
IsValidEntityIdCheck(Bool_.Y, "Q123");
|
||||||
|
IsValidEntityIdCheck(Bool_.Y, "A:B:Q123");
|
||||||
|
|
||||||
|
IsValidEntityIdCheck(Bool_.N, "p1");
|
||||||
|
IsValidEntityIdCheck(Bool_.N, "q1");
|
||||||
|
IsValidEntityIdCheck(Bool_.N, "P");
|
||||||
|
IsValidEntityIdCheck(Bool_.N, "P1A");
|
||||||
|
IsValidEntityIdCheck(Bool_.N, "P01");
|
||||||
|
}
|
||||||
|
private void IsValidEntityIdCheck(boolean expd, String val) {
|
||||||
|
fxt.Test_scrib_proc_bool(lib, Scrib_lib_wikibase.Invk_isValidEntityId, Object_.Ary(val), expd);
|
||||||
|
}
|
||||||
|
@Test public void EntityExists() {
|
||||||
|
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
|
||||||
|
fxt.Test_scrib_proc_bool(lib, Scrib_lib_wikibase.Invk_entityExists, Object_.Ary("q2" ), true);
|
||||||
|
fxt.Test_scrib_proc_bool(lib, Scrib_lib_wikibase.Invk_entityExists, Object_.Ary("Q1" ), false);
|
||||||
|
}
|
||||||
@Test public void GetEntityId() {
|
@Test public void GetEntityId() {
|
||||||
wdata_fxt.Init_links_add("enwiki", "Earth", "q2");
|
wdata_fxt.Init_links_add("enwiki", "Earth", "q2");
|
||||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("Earth" ), "q2");
|
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("Earth" ), "q2");
|
||||||
|
Loading…
Reference in New Issue
Block a user