1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-29 23:10:52 +00:00

Wikibase: Fix script error '=Module:Cycling race:3070 attempt to index ? (a nil value)' on 1 de.w page

This commit is contained in:
gnosygnu 2017-12-30 09:50:18 -05:00
parent 2550a87a60
commit af3e8aef00
3 changed files with 10 additions and 2 deletions

View File

@ -81,7 +81,7 @@ public class Scrib_lib_language implements Scrib_lib {
public void Notify_lang_changed() {if (notify_lang_changed_fnc != null) core.Interpreter().CallFunction(notify_lang_changed_fnc.Id(), Keyval_.Ary_empty);} public void Notify_lang_changed() {if (notify_lang_changed_fnc != null) core.Interpreter().CallFunction(notify_lang_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean GetContLangCode(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(core.Ctx().Lang().Key_str());} public boolean GetContLangCode(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(core.Ctx().Lang().Key_str());}
public boolean IsSupportedLanguage(Scrib_proc_args args, Scrib_proc_rslt rslt) {return IsKnownLanguageTag(args, rslt);}// NOTE: checks if "MessagesXX.php" exists; note that xowa has all "MessagesXX.php"; for now, assume same functionality as IsKnownLanguageTag (worst case is that a small wiki depends on a lang not being there; will need to put in a "wiki.Langs()" then) public boolean IsSupportedLanguage(Scrib_proc_args args, Scrib_proc_rslt rslt) {return IsKnownLanguageTag(args, rslt);}// NOTE: checks if "MessagesXX.php" exists; note that xowa has all "MessagesXX.php"; for now, assume same functionality as IsKnownLanguageTag (worst case is that a small wiki depends on a lang not being there; will need to put in a "wiki.Langs()" then)
public boolean IsKnownLanguageTag(Scrib_proc_args args, Scrib_proc_rslt rslt) { // NOTE: checks if in languages/Names.php public boolean IsKnownLanguageTag(Scrib_proc_args args, Scrib_proc_rslt rslt) { // NOTE: checks if in languages/Names.php; TODO: support foreign translations; EX: Englische is en in de.w
String lang_code = args.Cast_str_or_null(0); String lang_code = args.Cast_str_or_null(0);
boolean exists = false; boolean exists = false;
if ( lang_code != null // null check; protecting against Module passing in nil from lua if ( lang_code != null // null check; protecting against Module passing in nil from lua

View File

@ -82,7 +82,10 @@ public class Scrib_lib_wikibase implements Scrib_lib {
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang())); return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
} }
public boolean GetEntity(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(); Wdata_doc wdoc = Get_wdoc_or_null(args, core);
if (wdoc == null)
return rslt.Init_obj(Keyval_.Ary_empty); // 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(); Wbase_prop_mgr prop_mgr = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Prop_mgr();
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(Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
} }

View File

@ -84,6 +84,11 @@ public class Scrib_lib_wikibase_tst {
, " value=b" , " value=b"
)); ));
} }
@Test public void GetEntity__missing() { // PURPOSE: missing entity should return empty kv array; PAGE:de.w:Critérium_International_2016 DATE:2017-12-30
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl_skip_last
( "1=" // not ""
));
}
@Test public void ResolvePropertyId() { @Test public void ResolvePropertyId() {
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("zh-hans", "prop_a").Xto_wdoc()); wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("zh-hans", "prop_a").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_resolvePropertyId, Object_.Ary("p2"), "prop_a"); fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_resolvePropertyId, Object_.Ary("p2"), "prop_a");