1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.3.4.1'

This commit is contained in:
gnosygnu
2016-03-27 23:44:59 -04:00
parent de67253a9c
commit baaef32df2
903 changed files with 13339 additions and 8695 deletions

View File

@@ -107,10 +107,15 @@ public class Scrib_core {
lib_uri.Notify_page_changed();
lib_title.Notify_page_changed();
lib_wikibase.Notify_page_changed();
expensive_function_count = 0;
}
public byte[] Cur_wiki() {return cur_wiki;} private byte[] cur_wiki = Bry_.Empty;
public byte[] Cur_lang() {return cur_lang;} private byte[] cur_lang = Bry_.Empty;
public Scrib_lua_mod RegisterInterface(Scrib_lib lib, Io_url url, KeyVal... args) {
public void Increment_expensive_function_count() {
++expensive_function_count;
if (expensive_function_count > 255) {}
} private int expensive_function_count;
public Scrib_lua_mod RegisterInterface(Scrib_lib lib, Io_url url, Keyval... args) {
this.RegisterLibrary(lib.Procs());
Scrib_lua_mod rv = this.LoadLibraryFromFile(url.NameAndExt(), Io_mgr.Instance.LoadFilStr(url));
Scrib_lua_proc setupInterface_func = rv.Fncs_get_by_key("setupInterface");
@@ -120,24 +125,24 @@ public class Scrib_core {
}
public void RegisterLibrary(Scrib_proc_mgr lib_proc_mgr) {
int len = lib_proc_mgr.Len();
KeyVal[] functions_ary = new KeyVal[len];
Keyval[] functions_ary = new Keyval[len];
for (int i = 0; i < len; i++) {
Scrib_proc lib_proc = lib_proc_mgr.Get_at(i);
String lib_proc_key = lib_proc.Proc_key();
this.proc_mgr.Set(lib_proc_key, lib_proc);
functions_ary[i] = KeyVal_.new_(lib_proc.Proc_name(), lib_proc_key);
functions_ary[i] = Keyval_.new_(lib_proc.Proc_name(), lib_proc_key);
}
engine.RegisterLibrary(functions_ary);
}
@gplx.Internal protected Scrib_lua_mod LoadLibraryFromFile(String name, String text) {
int lib_id = engine.LoadString("@" + name, text).Id(); // NOTE: 'Prepending an "@" to the chunk name makes Lua think it is a filename'
KeyVal[] values = engine.CallFunction(lib_id, KeyVal_.Ary_empty);
Keyval[] values = engine.CallFunction(lib_id, Keyval_.Ary_empty);
Scrib_lua_mod rv = new Scrib_lua_mod(this, name);
if (values.length > 0) { // NOTE: values.length == 0 for "package.lua" (no fnc_ids returned);
KeyVal[] fncs = Scrib_kv_utl_.Val_to_KeyVal_ary(values, 0);
Keyval[] fncs = Scrib_kv_utl_.Val_to_KeyVal_ary(values, 0);
int len = fncs.length;
for (int i = 0; i < len; i++) {
KeyVal itm = fncs[i];
Keyval itm = fncs[i];
Scrib_lua_proc fnc = Scrib_lua_proc.cast_or_null_(itm.Val());
if (fnc != null) rv.Fncs_add(fnc); // NOTE: some lua funcs will return INF; EX: stringLengthLimit
}
@@ -164,8 +169,8 @@ public class Scrib_core {
parent_frame.Frame_tid_(Scrib_frame_.Tid_parent); current_frame.Frame_tid_(Scrib_frame_.Tid_current);
try {
Scrib_lua_mod mod = Mods_get_or_new(mod_name, mod_text);
KeyVal[] func_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_u8(fnc_name));
KeyVal[] func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeModule"), func_args); // call init_chunk to get proc dynamically; DATE:2014-07-12
Keyval[] func_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_u8(fnc_name));
Keyval[] func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeModule"), func_args); // call init_chunk to get proc dynamically; DATE:2014-07-12
if (func_rslt == null || func_rslt.length < 2) throw Err_.new_wo_type("lua.error:function did not return a value", "fnc_name", String_.new_u8(fnc_name)); // must return at least 2 items for func_rslt[1] below; DATE:2014-09-22
Scrib_lua_proc proc = (Scrib_lua_proc)func_rslt[1].Val(); // note that init_chunk should have: [0]:true/false result; [1]:proc
func_args = Scrib_kv_utl_.base1_many_(proc);
@@ -176,7 +181,7 @@ public class Scrib_core {
// gplx.xowa.parsers.xndes.Xop_xnde_tkn.Hack_ctx = ctx;
// bfr.Add(rslt_bry);
if (!Env_.Mode_testing())
engine.CleanupChunks(KeyVal_.Ary(KeyVal_.int_(proc.Id(), ""))); // cleanup chunk immediately; needed for heavy pages like en.d:water; DATE:2014-08-07
engine.CleanupChunks(Keyval_.Ary(Keyval_.int_(proc.Id(), ""))); // cleanup chunk immediately; needed for heavy pages like en.d:water; DATE:2014-08-07
}
finally {
lib_mw.Invoke_end();

View File

@@ -26,8 +26,8 @@ public class Scrib_core_fxt {
}
public Scrib_core_fxt Clear() {
if (core == null) {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
core = Scrib_core.Core_new_(app, wiki.Parser_mgr().Ctx());
server = new Process_server_mock();
core.Interpreter().Server_(server);
@@ -41,9 +41,9 @@ public class Scrib_core_fxt {
} private Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public Scrib_core Core() {return core;} private Scrib_core core;
public Process_server_mock Server() {return server;} Process_server_mock server;
public KeyVal kv_(Object key, Object val) {return KeyVal_.obj_(key, val);}
public KeyVal[] kv_ary_(KeyVal... v) {return v;}
public KeyVal kv_func_(String key, int id) {return KeyVal_.new_(key, new Scrib_lua_proc(key, id));}
public Keyval kv_(Object key, Object val) {return Keyval_.obj_(key, val);}
public Keyval[] kv_ary_(Keyval... v) {return v;}
public Keyval kv_func_(String key, int id) {return Keyval_.new_(key, new Scrib_lua_proc(key, id));}
public Scrib_core_fxt Init_lib_fil(String name, String text) {
Io_url url = core.Fsys_mgr().Script_dir().GenSubFil(name);
Io_mgr.Instance.SaveFilStr(url, text);
@@ -70,10 +70,10 @@ public class Scrib_core_fxt {
Tfds.Eq(expd_id, actl_id);
return this;
}
public Scrib_core_fxt Test_CallFunction(int prc_id, Object[] args, KeyVal... expd) {
KeyVal[] actl = core.Interpreter().CallFunction(prc_id, Scrib_kv_utl_.base1_many_(args));
public Scrib_core_fxt Test_CallFunction(int prc_id, Object[] args, Keyval... expd) {
Keyval[] actl = core.Interpreter().CallFunction(prc_id, Scrib_kv_utl_.base1_many_(args));
Test_server_logs();
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
return this;
}
public Scrib_core_fxt Test_RegisterLibrary(String[] proc_names, String[] expd_keys) {
@@ -87,15 +87,15 @@ public class Scrib_core_fxt {
Tfds.Eq_ary_str(expd_keys, actl_keys);
return this;
}
public Scrib_core_fxt Test_LoadLibraryFromFile(String name, String text, KeyVal... expd) {
public Scrib_core_fxt Test_LoadLibraryFromFile(String name, String text, Keyval... expd) {
Scrib_lua_mod actl_lib = core.LoadLibraryFromFile(name, text);
int actl_len = actl_lib.Fncs_len();
KeyVal[] actl = new KeyVal[actl_len];
Keyval[] actl = new Keyval[actl_len];
for (int i = 0; i < actl_len; i++) {
Scrib_lua_proc itm = actl_lib.Fncs_get_at(i);
actl[i] = KeyVal_.new_(itm.Key(), itm.Id());
actl[i] = Keyval_.new_(itm.Key(), itm.Id());
}
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
return this;
}
public Scrib_core_fxt Test_Module_GetInitChunk(String name, String text, int expd_id) {
@@ -105,14 +105,14 @@ public class Scrib_core_fxt {
Tfds.Eq(expd_id, actl_id);
return this;
}
public Scrib_core_fxt Test_ExecuteModule(int mod_id, KeyVal... expd) {
KeyVal[] values = core.Interpreter().ExecuteModule(mod_id);
KeyVal[] actl = (KeyVal[])values[0].Val();
public Scrib_core_fxt Test_ExecuteModule(int mod_id, Keyval... expd) {
Keyval[] values = core.Interpreter().ExecuteModule(mod_id);
Keyval[] actl = (Keyval[])values[0].Val();
Test_server_logs();
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
return this;
}
public Scrib_core_fxt Test_GetExpandedArgument(KeyVal[] args, String arg, String expd) {// NOTE: test is rigidly defined; (a) always same 3 arguments in frame; (b) expd={"val_1", "val_2", "val_3", ""}
public Scrib_core_fxt Test_GetExpandedArgument(Keyval[] args, String arg, String expd) {// NOTE: test is rigidly defined; (a) always same 3 arguments in frame; (b) expd={"val_1", "val_2", "val_3", ""}
this.Expd_server_rcvd_add("0000003D00000079{[\"op\"]=\"call\",[\"id\"]=8,[\"nargs\"]=1,[\"args\"]={[1]=chunks[9]}}")
.Init_server_prep_add("a:4:{s:2:\"id\";s:32:\"mw_interface-getExpandedArgument\";s:2:\"op\";s:4:\"call\";s:5:\"nargs\";i:2;s:4:\"args\";a:2:{i:1;s:7:\"current\";i:2;s:" + String_.Len(arg) + ":\"" + arg + "\";}}");
if (String_.Eq(expd, ""))
@@ -125,13 +125,13 @@ public class Scrib_core_fxt {
Test_server_logs();
return this;
}
public Scrib_core_fxt Test_GetAllExpandedArguments(KeyVal... args) {
public Scrib_core_fxt Test_GetAllExpandedArguments(Keyval... args) {
core.Frame_current_(Xot_invk_mock.new_(Frame_ttl_test, args));
core.Interpreter().ExecuteModule(9);
Test_server_logs();
return this;
}
public Scrib_core_fxt Test_Invoke(String mod_name, String mod_code, String prc_name, KeyVal... args) {
public Scrib_core_fxt Test_Invoke(String mod_name, String mod_code, String prc_name, Keyval... args) {
core.Invoke(wiki, core.Ctx(), Bry_.Empty, Xot_invk_mock.Null, Xot_invk_mock.new_(Frame_ttl_test, args), tmp_bfr, Bry_.new_u8(mod_name), Bry_.new_u8(mod_code), Bry_.new_u8(prc_name));
Test_server_logs();
return this;

View File

@@ -47,4 +47,4 @@ class Scrib_err_filter_mgr_fxt {
public void Test_print(String expd) {
Tfds.Eq_str_lines(expd, err_mgr.Print());
}
}
}

View File

@@ -28,7 +28,7 @@ public class Scrib_frame_ {
public static Xot_invk Get_frame(Scrib_core core, String frame_id) {
if (String_.Eq(frame_id, "current")) return core.Frame_current();
else if (String_.Eq(frame_id, "parent")) return core.Frame_parent();
else if (String_.Eq(frame_id, "empty")) return Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, null, KeyVal_.Ary_empty); // not sure if it should return null title; DATE:2014-07-12
else if (String_.Eq(frame_id, "empty")) return Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, null, Keyval_.Ary_empty); // not sure if it should return null title; DATE:2014-07-12
else {
return (Xot_invk)core.Frame_created_list().Get_by(frame_id); // NOTE: can return null; some calls expect nil; EX:mw.lua and "currentFrame = newFrame( 'empty' )"; DATE:2014-07-12
}

View File

@@ -52,7 +52,7 @@ public class Scrib_invoke_func_fxt {
public Scrib_invoke_func_fxt Init_server_print_key_y_() {server.Print_key_(true); return this;}
public Scrib_invoke_func_fxt Init_server_print_key_n_() {server.Print_key_(false); return this;}
public Scrib_invoke_func_fxt Init_lua_rcvd_raw(String raw) {server.Prep_add(raw); return this;}
public Scrib_invoke_func_fxt Init_lua_rcvd(String cbk_name, KeyVal... ary) {
public Scrib_invoke_func_fxt Init_lua_rcvd(String cbk_name, Keyval... ary) {
server.Prep_add(rsp_bldr.Bld_mw_cbk(cbk_name, ary));
return this;
}
@@ -69,8 +69,8 @@ public class Scrib_invoke_func_fxt {
this.Init_lua_rcvd_rv();
return this;
}
public Scrib_invoke_func_fxt Init_lua_rcvd_expandTemplate(String frame, String tmpl_ttl, KeyVal... ary) {
ary = new KeyVal[] {KeyVal_.int_(1, "current"), KeyVal_.int_(2, tmpl_ttl), KeyVal_.int_(3, ary)};
public Scrib_invoke_func_fxt Init_lua_rcvd_expandTemplate(String frame, String tmpl_ttl, Keyval... ary) {
ary = new Keyval[] {Keyval_.int_(1, "current"), Keyval_.int_(2, tmpl_ttl), Keyval_.int_(3, ary)};
server.Prep_add(rsp_bldr.Bld_mw_cbk("expandTemplate", ary));
this.Init_lua_rcvd_rv();
return this;
@@ -92,11 +92,11 @@ public class Scrib_invoke_func_fxt {
Tfds.Eq_str(expd, tmp_bfr.To_str_and_clear(), "error");
}
public void Test_lib_proc(Scrib_lib lib, String func_name, Object[] args, String expd) {Test_lib_proc_kv(lib, func_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_lib_proc_kv(Scrib_lib lib, String func_name, KeyVal[] args, String expd) {
public void Test_lib_proc_kv(Scrib_lib lib, String func_name, Keyval[] args, String expd) {
Test_lib_proc_internal(lib, func_name, args);
this.Test_invoke(expd);
}
private void Test_lib_proc_internal(Scrib_lib lib, String func_name, KeyVal[] args) {
private void Test_lib_proc_internal(Scrib_lib lib, String func_name, Keyval[] args) {
Init_lua_module();
this.Init_cbk(Scrib_core.Key_mw_interface, lib, func_name);
this.Init_lua_rcvd(func_name, args);
@@ -105,16 +105,16 @@ public class Scrib_invoke_func_fxt {
public void Test_log_rcvd(int i, String expd) {
Tfds.Eq(expd, (String)server.Log_rcvd().Get_at(i));
}
public void Init_frame_parent(String ttl, KeyVal... ary) {
public void Init_frame_parent(String ttl, Keyval... ary) {
core.Frame_parent_(Xot_invk_mock.test_(Bry_.new_u8(ttl), ary));
}
public void Init_frame_current(KeyVal... ary) {
public void Init_frame_current(Keyval... ary) {
core.Frame_current_(Xot_invk_mock.test_(Bry_.new_a7("Module:Mod_0"), ary));
}
public void Clear_for_lib() {Clear_for_lib("en.wikipedia.org", "en");}
public void Clear_for_lib(String domain, String lang) {
Xoae_app app = Xoa_app_fxt.app_();
fxt = new Xop_fxt(app, Xoa_app_fxt.wiki_(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)))); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib
Xoae_app app = Xoa_app_fxt.Make__app__edit();
fxt = new Xop_fxt(app, Xoa_app_fxt.Make__wiki__edit(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)))); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib
core_fxt = new Scrib_core_fxt(fxt);
core = core_fxt.Core();
Xot_invk parent_frame = new Xot_invk_temp(true); parent_frame.Frame_tid_(Scrib_frame_.Tid_null);
@@ -123,35 +123,35 @@ public class Scrib_invoke_func_fxt {
core.When_page_changed(fxt.Page());
}
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_str(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(Object_.Xto_str_strict_or_null_mark(expd), Object_.Xto_str_strict_or_null_mark(actl[0].Val()));
}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps__flat(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
KeyVal[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {
Keyval[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(expd, Kv_ary_to_kv_vals_str(actl_ary));
}
public void Test_scrib_proc_kv_objs(Scrib_lib lib, String proc_name, KeyVal[] args, Object... expd_ary) {
KeyVal[] actl_kvs = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_kv_objs(Scrib_lib lib, String proc_name, Keyval[] args, Object... expd_ary) {
Keyval[] actl_kvs = Test__lib_proc__core(lib, proc_name, args);
Object[] actl_ary = KeyVal_to_obj_ary(actl_kvs);
Tfds.Eq_ary(expd_ary, actl_ary);
}
private static Object[] KeyVal_to_obj_ary(KeyVal[] kv_ary) {
private static Object[] KeyVal_to_obj_ary(Keyval[] kv_ary) {
int len = kv_ary.length;
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i) {
KeyVal kv = kv_ary[i];
Keyval kv = kv_ary[i];
rv[i] = kv.Val();
}
return rv;
}
private String Kv_ary_to_kv_vals_str(KeyVal[] ary) {
private String Kv_ary_to_kv_vals_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
KeyVal kv = ary[i];
Keyval kv = ary[i];
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(kv.Val()));
}
return bfr.To_str_and_clear();
@@ -159,30 +159,30 @@ public class Scrib_invoke_func_fxt {
public void Test_scrib_proc_bool(Scrib_lib lib, String proc_name, Object[] args, boolean expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_int(Scrib_lib lib, String proc_name, Object[] args, int expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, Object[] args, Object expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, KeyVal[] args, Object expd) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, Keyval[] args, Object expd) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(expd, actl[0].Val());
}
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, Object[] args) {Test_scrib_proc_empty(lib, proc_name, Scrib_kv_utl_.base1_many_(args));}
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, KeyVal[] args) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, Keyval[] args) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(0, actl.length);
}
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_str_ary(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
KeyVal[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
String actl = KeyVal_.Ary__to_str__nest(actl_ary);
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {
Keyval[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
String actl = Keyval_.Ary__to_str__nest(actl_ary);
Tfds.Eq_str_lines(expd, actl);
}
public KeyVal[] Test_scrib_proc_rv_as_kv_ary(Scrib_lib lib, String proc_name, Object[] args) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return (KeyVal[])actl[0].Val();
public Keyval[] Test_scrib_proc_rv_as_kv_ary(Scrib_lib lib, String proc_name, Object[] args) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return (Keyval[])actl[0].Val();
}
public Object Test_scrib_proc_rv_as_obj(Scrib_lib lib, String proc_name, Object[] args) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
Keyval[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return actl[0].Val();
}
private KeyVal[] Test__lib_proc__core(Scrib_lib lib, String proc_name, KeyVal[] args) {
private Keyval[] Test__lib_proc__core(Scrib_lib lib, String proc_name, Keyval[] args) {
Scrib_proc proc = lib.Procs().Get_by_key(proc_name);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(new Scrib_proc_args(args), proc_rslt);
@@ -193,7 +193,7 @@ public class Scrib_invoke_func_fxt {
}
class Scrib_lua_rsp_bldr {
Bry_bfr bfr = Bry_bfr.reset_(255);
public String Bld_mw_cbk(String cbk_name, KeyVal... ary) {
public String Bld_mw_cbk(String cbk_name, Keyval... ary) {
cbk_name = "mw_interface-" + cbk_name;
bfr.Add_str_a7("a:4:{s:2:\"id\";");
Bld_str(bfr, cbk_name);
@@ -208,7 +208,7 @@ class Scrib_lua_rsp_bldr {
else if (Object_.Eq(v_type, String_.Cls_ref_type)) Bld_str(bfr, String_.cast(v));
else if (Object_.Eq(v_type, Bool_.Cls_ref_type)) Bld_bool(bfr, Bool_.cast(v));
else if (Object_.Eq(v_type, Double_.Cls_ref_type)) Bld_double(bfr, Double_.cast(v));
else if (Object_.Eq(v_type, KeyVal[].class)) Bld_kv_ary(bfr, (KeyVal[])v);
else if (Object_.Eq(v_type, Keyval[].class)) Bld_kv_ary(bfr, (Keyval[])v);
else if (Object_.Eq(v_type, Scrib_lua_proc.class)) Bld_fnc(bfr, (Scrib_lua_proc)v);
else throw Err_.new_unhandled(Type_adp_.NameOf_obj(v));
}
@@ -217,11 +217,11 @@ class Scrib_lua_rsp_bldr {
private void Bld_double(Bry_bfr bfr, double v) {bfr.Add_str_a7("d:").Add_double(v).Add_byte(Byte_ascii.Semic);}
private void Bld_str(Bry_bfr bfr, String v) {bfr.Add_str_a7("s:").Add_int_variable(Bry_.new_u8(v).length).Add_str_a7(":\"").Add_str_a7(v).Add_str_a7("\";");} // NOTE: must use Bry_.new_u8(v).length to calculate full bry len
private void Bld_fnc(Bry_bfr bfr, Scrib_lua_proc v) {bfr.Add_str_a7("O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:").Add_int_variable(v.Id()).Add_byte(Byte_ascii.Semic).Add_byte(Byte_ascii.Curly_end);}
private void Bld_kv_ary(Bry_bfr bfr, KeyVal[] ary) {
private void Bld_kv_ary(Bry_bfr bfr, Keyval[] ary) {
int len = ary.length;
bfr.Add_str_a7("a:").Add_int_variable(len).Add_str_a7(":{");
for (int i = 0; i < len; i++) {
KeyVal kv = ary[i];
Keyval kv = ary[i];
Bld_obj(bfr, kv.Key_as_obj());
Bld_obj(bfr, kv.Val());
}

View File

@@ -17,48 +17,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Scrib_kv_utl_ {
public static KeyVal[] base1_obj_(Object v) {return new KeyVal[] {KeyVal_.int_(0 + Scrib_core.Base_1, v)};}
public static KeyVal[] base1_many_(Object... vals) {
public static Keyval[] base1_obj_(Object v) {return new Keyval[] {Keyval_.int_(0 + Scrib_core.Base_1, v)};}
public static Keyval[] base1_many_(Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++)
rv[i] = KeyVal_.int_(i + Scrib_core.Base_1, vals[i]);
rv[i] = Keyval_.int_(i + Scrib_core.Base_1, vals[i]);
return rv;
}
public static KeyVal[] base1_many_ary_(Object... vals) {
public static Keyval[] base1_many_ary_(Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++)
rv[i] = KeyVal_.int_(i + Scrib_core.Base_1, vals[i]);
rv[i] = Keyval_.int_(i + Scrib_core.Base_1, vals[i]);
return rv;
}
public static KeyVal[] base1_list_(List_adp list) {
public static Keyval[] base1_list_(List_adp list) {
int len = list.Count();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++)
rv[i] = KeyVal_.int_(i + Scrib_core.Base_1, list.Get_at(i));
rv[i] = Keyval_.int_(i + Scrib_core.Base_1, list.Get_at(i));
list.Clear();
return rv;
}
public static KeyVal[] flat_many_(Object... vals) {
public static Keyval[] flat_many_(Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len / 2];
Keyval[] rv = new Keyval[len / 2];
for (int i = 0; i < len; i += 2)
rv[i / 2] = KeyVal_.obj_(vals[i], vals[i + 1]);
rv[i / 2] = Keyval_.obj_(vals[i], vals[i + 1]);
return rv;
}
public static String Val_to_str(KeyVal[] ary, int idx) {
public static String Val_to_str(Keyval[] ary, int idx) {
if (ary == null) throw Err_.new_wo_type("ary is null");
int ary_len = ary.length;
if (ary_len == 0 && idx == 0) return ""; // NOTE: Modules can throw exceptions in which return value is nothing; do not fail; return ""; EX: -logy; DATE:2013-10-14
if (idx >= ary_len) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_to_str(ary));
if (idx >= ary_len) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", Keyval_.Ary_to_str(ary));
Object o = ary[idx].Val();
try {return (String)o;}
catch (Exception e) {throw Err_.new_cast(e, String.class, o);}
}
public static KeyVal[] Val_to_KeyVal_ary(KeyVal[] ary, int idx) {
if (ary == null) throw Err_.new_wo_type("ary is null"); if (idx >= ary.length) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_to_str(ary));
try {return (KeyVal[])ary[idx].Val();}
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as KeyVal[] failed", "ary", KeyVal_.Ary_to_str(ary));}
public static Keyval[] Val_to_KeyVal_ary(Keyval[] ary, int idx) {
if (ary == null) throw Err_.new_wo_type("ary is null"); if (idx >= ary.length) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", Keyval_.Ary_to_str(ary));
try {return (Keyval[])ary[idx].Val();}
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as Keyval[] failed", "ary", Keyval_.Ary_to_str(ary));}
}
}

View File

@@ -43,12 +43,12 @@ public class Scrib_lua_mod {
public void Execute() {
hash.Clear(); // NOTE: questionable. should probably be removed, as it forces all modules to be "loadString"'d again; DATE:2013-10-16
this.LoadString(name); // assert lua_id;
KeyVal[] rslt = core.Interpreter().ExecuteModule(lua_id);
Keyval[] rslt = core.Interpreter().ExecuteModule(lua_id);
if (rslt.length == 0) throw Err_.new_wo_type("module missing", "name", name, "lua_id", lua_id);
KeyVal[] prcs_ary = (KeyVal[])rslt[0].Val();
Keyval[] prcs_ary = (Keyval[])rslt[0].Val();
int prcs_len = prcs_ary.length;
for (int i = 0; i < prcs_len; i++) {
KeyVal prc_kv = prcs_ary[i];
Keyval prc_kv = prcs_ary[i];
String prc_key = prc_kv.Key();
Object prc_val = prc_kv.Val();
Scrib_lua_proc fnc = null;

View File

@@ -17,14 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Scrib_proc_args {
private KeyVal[] ary; private int ary_len;
public Scrib_proc_args(KeyVal[] v) {Init(v);}
private Keyval[] ary; private int ary_len;
public Scrib_proc_args(Keyval[] v) {Init(v);}
public int Len() {return ary_len;}
public KeyVal[] Ary() {return ary;}
public Keyval[] Ary() {return ary;}
public boolean Pull_bool(int i) {return Bool_.cast(Get_or_fail(i));}
public String Pull_str(int i) {return String_.cast(Get_or_fail(i));}
public byte[] Pull_bry(int i) {return Bry_.new_u8(String_.cast(Get_or_fail(i)));}
public KeyVal[] Pull_kv_ary(int i) {return (KeyVal[])Get_or_fail(i);}
public Keyval[] Pull_kv_ary(int i) {return (Keyval[])Get_or_fail(i);}
public int Pull_int(int i) {Object rv = Get_or_fail(i);
try {return Int_.coerce_(rv);} // coerce to handle "1" and 1; will still fail if "abc" is passed
catch (Exception e) {
@@ -45,6 +45,7 @@ public class Scrib_proc_args {
}
}
public Object Pull_obj(int i) {return Get_or_fail(i);}
public String Cast_str_or(int i, String or) {Object rv = Get_or_null(i); return rv == null ? or : String_.cast (rv);}
public String Cast_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : String_.cast (rv);}
public byte[] Cast_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(String_.cast (rv));} // NOTE: cast is deliberate; Scrib call checkType whi
public byte[] Cast_bry_or_empty(int i) {Object rv = Get_or_null(i); return rv == null ? Bry_.Empty : Bry_.new_u8(String_.cast (rv));}
@@ -55,16 +56,16 @@ public class Scrib_proc_args {
public int Cast_int_or(int i, int or) {Object rv = Get_or_null(i); return rv == null ? or : Int_.coerce_(rv);} // coerce to handle "1" and 1;
public String Xstr_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Object_.Xto_str_loose_or(rv, null);} // NOTE: Modules can throw exceptions in which return value is nothing; do not fail; return ""; EX: -logy; DATE:2013-10-14
public byte[] Xstr_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(Object_.Xto_str_loose_or(rv, null));}
public KeyVal[] Cast_kv_ary_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : (KeyVal[])rv;}
public Keyval[] Cast_kv_ary_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : (Keyval[])rv;}
public byte[][] Cast_params_as_bry_ary_or_rest_of_ary(int params_idx) { // PAGE:ru.w:Ленин,_Владимир_Ильич; DATE:2014-07-01 MW:LanguageLibrary.php|ConvertPlural: if (is_array($args[0])) $args = $args[0]; $forms = array_values(array_map('strval', $args));
if (params_idx < 0 || params_idx >= ary_len) return Bry_.Ary_empty;
Object o = ary[params_idx].Val();
if (Type_adp_.Eq_typeSafe(o, KeyVal[].class)) {
KeyVal[] tbl = (KeyVal[])o;
if (Type_adp_.Eq_typeSafe(o, Keyval[].class)) {
Keyval[] tbl = (Keyval[])o;
int rv_len = tbl.length;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; i++) {
KeyVal itm = tbl[i];
Keyval itm = tbl[i];
rv[i] = Bry_.new_u8(String_.cast(itm.Val()));
}
return rv;
@@ -73,7 +74,7 @@ public class Scrib_proc_args {
int rv_len = ary_len - params_idx;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; i++) {
KeyVal itm = ary[i + params_idx];
Keyval itm = ary[i + params_idx];
rv[i] = Bry_.new_u8(String_.cast(itm.Val()));
}
return rv;
@@ -85,12 +86,12 @@ public class Scrib_proc_args {
Class<?> qry_args_cls = Type_adp_.ClassOf_obj(qry_args_obj);
if (qry_args_cls == String.class)
return Bry_.new_u8((String)qry_args_obj);
else if (qry_args_cls == KeyVal[].class) {
else if (qry_args_cls == Keyval[].class) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
KeyVal[] kvs = (KeyVal[])qry_args_obj;
Keyval[] kvs = (Keyval[])qry_args_obj;
int len = kvs.length;
for (int i = 0; i < len; i++) {
KeyVal kv = kvs[i];
Keyval kv = kvs[i];
if (i != 0) bfr.Add_byte(Byte_ascii.Amp);
bfr.Add_str_u8(kv.Key());
bfr.Add_byte(Byte_ascii.Eq);
@@ -103,16 +104,16 @@ public class Scrib_proc_args {
return Bry_.Empty;
}
}
private void Init(KeyVal[] v) {
private void Init(Keyval[] v) {
int v_len = v.length;
if (v_len == 0) {
ary = KeyVal_.Ary_empty;
ary = Keyval_.Ary_empty;
ary_len = 0;
return;
}
int v_max = -1;
for (int i = 0; i < v_len; i++) {
KeyVal kv = v[i];
Keyval kv = v[i];
int idx = Int_.cast(kv.Key_as_obj());
if (v_max < idx) v_max = idx;
}
@@ -121,9 +122,9 @@ public class Scrib_proc_args {
this.ary = v;
}
else { // keys are not in sequential order, or there are gaps; EX: [1:a,3:c]
ary = new KeyVal[ary_len];
ary = new Keyval[ary_len];
for (int i = 0; i < v_len; i++) {
KeyVal kv = v[i];
Keyval kv = v[i];
int idx = Int_.cast(kv.Key_as_obj());
ary[idx - List_adp_.Base1] = kv;
}
@@ -131,12 +132,12 @@ public class Scrib_proc_args {
}
private Object Get_or_null(int i) {
if (i < 0 || i >= ary_len) return null;
KeyVal kv = ary[i];
Keyval kv = ary[i];
return kv == null ? null : kv.Val();
}
private Object Get_or_fail(int i) {
if (i < 0 || i >= ary_len) throw Err_.new_wo_type("bad argument: nil", "idx", i, "len", ary_len);
KeyVal kv = ary[i];
Keyval kv = ary[i];
Object rv = kv == null ? null : kv.Val();
if (rv == null) throw Err_.new_wo_type("scrib arg is null", "idx", i, "len", ary_len);
return rv;

View File

@@ -17,46 +17,46 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Scrib_proc_rslt {
private KeyVal[] ary;
public KeyVal[] Ary() {return ary;}
private Keyval[] ary;
public Keyval[] Ary() {return ary;}
public String Fail_msg() {return fail_msg;} private String fail_msg;
public boolean Init_fail(String v) {fail_msg = v; return false;}
public boolean Init_null() {Init_obj(null); return true;} // return array(null);
public boolean Init_str_empty() {Init_obj(""); return true;}
public boolean Init_ary_empty() {ary = KeyVal_.Ary_empty; return true;}
public boolean Init_ary_empty() {ary = Keyval_.Ary_empty; return true;}
public boolean Init_obj(Object val) {
ary = new KeyVal[] {KeyVal_.int_(Scrib_core.Base_1, val)};
ary = new Keyval[] {Keyval_.int_(Scrib_core.Base_1, val)};
return true;
}
public boolean Init_many_objs(Object... vals) {
int len = vals.length;
ary = new KeyVal[len];
ary = new Keyval[len];
for (int i = 0; i < len; i++)
ary[i] = KeyVal_.int_(i + Scrib_core.Base_1, vals[i]);
ary[i] = Keyval_.int_(i + Scrib_core.Base_1, vals[i]);
return true;
}
public boolean Init_many_kvs(KeyVal... kvs) {
public boolean Init_many_kvs(Keyval... kvs) {
ary = kvs;
return true;
}
public boolean Init_many_list(List_adp list) {
int len = list.Count();
ary = new KeyVal[len];
ary = new Keyval[len];
for (int i = 0; i < len; i++)
ary[i] = KeyVal_.int_(i + Scrib_core.Base_1, list.Get_at(i));
ary[i] = Keyval_.int_(i + Scrib_core.Base_1, list.Get_at(i));
list.Clear();
return true;
}
public boolean Init_many_empty() {
ary = KeyVal_.Ary_empty;
ary = Keyval_.Ary_empty;
return true;
}
public boolean Init_bry_ary(byte[][] v) { // NOTE:fallbacks should return "table {fallback_1, fallback_2}"; PAGE:wd:Main_Page DATE:2015-04-21
int len = v.length;
KeyVal[] itms = new KeyVal[len];
Keyval[] itms = new Keyval[len];
for (int i = 0; i < len; i++)
itms[i] = KeyVal_.int_(i + Scrib_core.Base_1, String_.new_u8(v[i]));
this.ary = new KeyVal[] {KeyVal_.int_(Scrib_core.Base_1, itms)};
itms[i] = Keyval_.int_(i + Scrib_core.Base_1, String_.new_u8(v[i]));
this.ary = new Keyval[] {Keyval_.int_(Scrib_core.Base_1, itms)};
return true;
}
}

View File

@@ -20,8 +20,8 @@ public interface Scrib_engine {
boolean Dbg_print(); void Dbg_print_(boolean v);
Scrib_server Server(); void Server_(Scrib_server v);
Scrib_lua_proc LoadString(String name, String text);
KeyVal[] CallFunction(int id, KeyVal[] args);
void RegisterLibrary(KeyVal[] functions_ary);
KeyVal[] ExecuteModule(int mod_id);
void CleanupChunks(KeyVal[] ids);
Keyval[] CallFunction(int id, Keyval[] args);
void RegisterLibrary(Keyval[] functions_ary);
Keyval[] ExecuteModule(int mod_id);
void CleanupChunks(Keyval[] ids);
}

View File

@@ -30,5 +30,5 @@ public class Scrib_engine_type {
else throw Err_.new_unimplemented();
}
public static final byte Type_lua = 0, Type_luaj = 1;
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_("luaj"), KeyVal_.new_("lua"));
public static Keyval[] Options__list = Keyval_.Ary(Keyval_.new_("luaj"), Keyval_.new_("lua"));
}

View File

@@ -26,8 +26,8 @@ public class Luaj_engine implements Scrib_engine {
this.core = core;
server = new Luaj_server(core, debug_enabled);
proc_mgr = core.Proc_mgr();
Luaj_server_func_recv._.Engine_(this);
Luaj_server_func_dbg._.Core_(core);
Luaj_server_func_recv.Instance.Engine_(this);
Luaj_server_func_dbg.Instance.Core_(core);
}
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {server = (Luaj_server)v;}
public boolean Dbg_print() {return dbg_print;} public void Dbg_print_(boolean v) {dbg_print = v;} private boolean dbg_print;
@@ -41,14 +41,14 @@ public class Luaj_engine implements Scrib_engine {
LuaInteger proc_id = (LuaInteger)values_tbl.rawget(1);
return new Scrib_lua_proc(name, proc_id.v);
}
public void RegisterLibrary(KeyVal[] functions) {
public void RegisterLibrary(Keyval[] functions) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_registerLibrary);
msg.set("name", "mw_interface");
msg.set("functions", Luaj_value_.X_obj_to_val(server, functions));
server.Dispatch(msg);
}
public KeyVal[] CallFunction(int id, KeyVal[] args) {
public Keyval[] CallFunction(int id, Keyval[] args) {
int args_len = args.length;
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_callFunction);
@@ -57,16 +57,16 @@ public class Luaj_engine implements Scrib_engine {
msg.set("args", Luaj_value_.X_obj_to_val(server, args));
return this.Dispatch_as_kv_ary(msg);
}
public KeyVal[] ExecuteModule(int mod_id) {
public Keyval[] ExecuteModule(int mod_id) {
return this.CallFunction(core.Lib_mw().Mod().Fncs_get_id("executeModule"), Scrib_kv_utl_.base1_obj_(new Scrib_lua_proc("", mod_id)));
}
public void CleanupChunks(KeyVal[] ids) {
public void CleanupChunks(Keyval[] ids) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", "cleanupChunks");
msg.set("ids", Luaj_value_.X_obj_to_val(server, ids));
this.Dispatch_as_kv_ary(msg);
}
public KeyVal[] Dispatch_as_kv_ary(LuaTable msg) {
public Keyval[] Dispatch_as_kv_ary(LuaTable msg) {
while (true) {
LuaTable rsp = server.Dispatch(msg);
String op = Luaj_value_.Get_val_as_str(rsp, "op");
@@ -77,29 +77,29 @@ public class Luaj_engine implements Scrib_engine {
else if (String_.Eq(op, "error")) {
String err = Luaj_value_.Get_val_as_str(rsp, "value");
core.Handle_error(err, "");
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
else
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
}
public LuaTable Server_recv_call(LuaTable rsp) {
String proc_id = Luaj_value_.Get_val_as_str(rsp, "id");
KeyVal[] args = Luaj_value_.Get_val_as_kv_ary(server, rsp, "args");
Keyval[] args = Luaj_value_.Get_val_as_kv_ary(server, rsp, "args");
Scrib_proc proc = proc_mgr.Get_by_key(proc_id); if (proc == null) throw Scrib_xtn_mgr.err_("could not find proc with id of {0}", proc_id);
Scrib_proc_args proc_args = new Scrib_proc_args(args);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(proc_args, proc_rslt);
String fail_msg = proc_rslt.Fail_msg();
if (fail_msg == null) {
KeyVal[] cbk_rslts = proc_rslt.Ary();
Keyval[] cbk_rslts = proc_rslt.Ary();
return ReturnMessage(cbk_rslts);
}
else {
return ReturnFail(fail_msg);
}
}
private LuaTable ReturnMessage(KeyVal[] values) {
private LuaTable ReturnMessage(Keyval[] values) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_returnMessage);
msg.set("nvalues", LuaValue.valueOf(values.length));

View File

@@ -21,14 +21,13 @@ import org.luaj.vm2.*; import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.jse.*;
import gplx.xowa.xtns.scribunto.engines.process.*;
public class Luaj_server implements Scrib_server {
private LuaTable server;
public Luaj_server(Scrib_core core, boolean debug_enabled) {
}
public Luaj_server(Scrib_core core, boolean debug_enabled) {}
public static Globals Globals_singleton;
public void Init(String... init_args) {
Globals_singleton = JsePlatform.standardGlobals();
Globals_singleton.load(new DebugLib());
Globals_singleton.load(new MWClient());
Globals_singleton.set("dbg", Luaj_server_func_dbg._);
Globals_singleton.set("dbg", Luaj_server_func_dbg.Instance);
String root_str = init_args[2];
if (Op_sys.Cur().Tid_is_wnt())
root_str = String_.Replace(root_str, Op_sys.Wnt.Fsys_dir_spr_str(), Op_sys.Lnx.Fsys_dir_spr_str());
@@ -75,7 +74,7 @@ public class Luaj_server implements Scrib_server {
*/
public LuaValue call(LuaValue libname) {
LuaValue library = tableOf();
library.set("client_recv", Luaj_server_func_recv._);
library.set("client_recv", Luaj_server_func_recv.Instance);
LuaValue env = gplx.xowa.xtns.scribunto.engines.luaj.Luaj_server.Globals_singleton;
env.set( "MWClient", library );
return library;

View File

@@ -36,5 +36,5 @@ public class Luaj_server_func_dbg extends VarArgFunction {
core.Page().Html_data().Xtn_scribunto_dbg_(bfr.To_bry_and_clear());
return NONE;
}
public static Luaj_server_func_dbg _ = new Luaj_server_func_dbg();
public static Luaj_server_func_dbg Instance = new Luaj_server_func_dbg();
}

View File

@@ -28,5 +28,5 @@ public class Luaj_server_func_recv extends OneArgFunction {
if (!String_.Eq(op, "call")) throw Err_.new_wo_type("luaj_recvr only processes op calls");
return engine.Server_recv_call(tbl);
}
public static Luaj_server_func_recv _ = new Luaj_server_func_recv();
public static Luaj_server_func_recv Instance = new Luaj_server_func_recv();
}

View File

@@ -24,11 +24,11 @@ class Luaj_value_ {
public static LuaTable Get_val_as_lua_table(LuaTable owner, String key) {
return (LuaTable)owner.get(key);
}
public static KeyVal[] Get_val_as_kv_ary(Luaj_server server, LuaTable owner, String key) {
public static Keyval[] Get_val_as_kv_ary(Luaj_server server, LuaTable owner, String key) {
LuaTable table = (LuaTable)owner.get(key);
return Luaj_value_.X_tbl_to_kv_ary(server, table);
}
public static KeyVal[] X_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
public static Keyval[] X_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
List_adp temp = List_adp_.new_();
LuaValue cur = LuaValue.NIL;
int len = 0;
@@ -38,23 +38,23 @@ class Luaj_value_ {
LuaValue itm_val = itm.arg(2); // val is itm 2
Object itm_val_obj = X_val_to_obj(server, itm_val);
LuaValue itm_key = itm.arg(1);
KeyVal kv = null;
Keyval kv = null;
if (itm_val.type() == LuaValue.TFUNCTION) { // function is converted to Scrib_lua_proc
String func_key = itm_key.tojstring();
int func_id = Int_.cast(itm_val_obj);
Scrib_lua_proc lua_func = new Scrib_lua_proc(func_key, func_id);
if (itm_key.type() == LuaValue.TSTRING) // most functions are named
kv = KeyVal_.new_(func_key, lua_func);
kv = Keyval_.new_(func_key, lua_func);
else // some are not; particularly "anonymous" functions in Module for gsub_function; these will have a kv of int,int; note that key must be int; if string, lua will not be able to match it back to int later
kv = KeyVal_.int_(((LuaInteger)itm_key).v, lua_func);
kv = Keyval_.int_(((LuaInteger)itm_key).v, lua_func);
}
else {
switch (itm_key.type()) {
case LuaValue.TNUMBER:
kv = KeyVal_.int_(((LuaNumber)itm_key).toint(), itm_val_obj);
kv = Keyval_.int_(((LuaNumber)itm_key).toint(), itm_val_obj);
break;
case LuaValue.TSTRING:
kv = KeyVal_.new_(((LuaString)itm_key).tojstring(), itm_val_obj);
kv = Keyval_.new_(((LuaString)itm_key).tojstring(), itm_val_obj);
break;
default:
throw Err_.new_unhandled(itm_key.type());
@@ -64,8 +64,8 @@ class Luaj_value_ {
cur = itm_key;
++len;
}
if (len == 0) return KeyVal_.Ary_empty;
return (KeyVal[])temp.To_ary(KeyVal.class);
if (len == 0) return Keyval_.Ary_empty;
return (Keyval[])temp.To_ary(Keyval.class);
}
private static Object X_val_to_obj(Luaj_server server, LuaValue v) {
switch (v.type()) {
@@ -91,16 +91,16 @@ class Luaj_value_ {
else if (Object_.Eq(c, Double_.Cls_ref_type)) return LuaValue.valueOf((Double)o);
else if (Object_.Eq(c, String_.Cls_ref_type)) return LuaValue.valueOf((String)o);
else if (Object_.Eq(c, byte[].class)) return LuaValue.valueOf(String_.new_u8((byte[])o));
else if (Object_.Eq(c, KeyVal.class)) return X_kv_ary_to_tbl(server, (KeyVal)o);
else if (Object_.Eq(c, KeyVal[].class)) return X_kv_ary_to_tbl(server, (KeyVal[])o);
else if (Object_.Eq(c, Keyval.class)) return X_kv_ary_to_tbl(server, (Keyval)o);
else if (Object_.Eq(c, Keyval[].class)) return X_kv_ary_to_tbl(server, (Keyval[])o);
else if (Object_.Eq(c, Scrib_lua_proc.class)) return server.Get_closure_by_id(((Scrib_lua_proc)o).Id());
else return LuaValue.NIL;
}
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, KeyVal... ary) {
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, Keyval... ary) {
LuaTable rv = LuaValue.tableOf();
int len = ary.length;
for (int i = 0; i < len; i++) {
KeyVal itm = ary[i];
Keyval itm = ary[i];
LuaValue itm_val = X_obj_to_val(server, itm.Val());
switch (itm.Key_tid()) {
case Type_adp_.Tid__int:

View File

@@ -22,7 +22,7 @@ public abstract class Mock_proc_fxt {
public int Id() {return id;} private final int id;
public String Key() {return key;} private final String key;
public Scrib_lua_proc To_scrib_lua_proc() {return new Scrib_lua_proc(key, id);}
public abstract KeyVal[] Exec_by_scrib(KeyVal[] args);
public abstract Keyval[] Exec_by_scrib(Keyval[] args);
}
class Mock_engine implements Scrib_engine {
private final Hash_adp hash = Hash_adp_.new_();
@@ -30,13 +30,13 @@ class Mock_engine implements Scrib_engine {
public boolean Dbg_print() {return false;} public void Dbg_print_(boolean v) {}
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {} private final Mock_server server = new Mock_server();
public Scrib_lua_proc LoadString(String name, String text) {return null;}
public KeyVal[] CallFunction(int id, KeyVal[] args) {
public Keyval[] CallFunction(int id, Keyval[] args) {
Mock_proc_fxt proc = (Mock_proc_fxt)hash.Get_by_or_fail(tmp_hash_id.Val_(id));
return proc.Exec_by_scrib(args);
}
public void RegisterLibrary(KeyVal[] functions_ary) {}
public KeyVal[] ExecuteModule(int mod_id) {return null;}
public void CleanupChunks(KeyVal[] ids) {}
public void RegisterLibrary(Keyval[] functions_ary) {}
public Keyval[] ExecuteModule(int mod_id) {return null;}
public void CleanupChunks(Keyval[] ids) {}
public void Clear() {}
public void RegisterLibraryForTest(Mock_proc_fxt proc) {
hash.Add(Int_obj_ref.new_(proc.Id()), proc);

View File

@@ -21,11 +21,11 @@ public class Mock_scrib_fxt {
private final Mock_engine engine = new Mock_engine();
private final Mock_server server = new Mock_server();
private Xop_fxt parser_fxt;
public Scrib_core Core() {return core;} private Scrib_core core;
public Scrib_core Core() {return core;} private Scrib_core core;
public void Clear() {Clear("en.wikipedia.org", "en");}
public void Clear(String domain, String lang) {
Xoae_app app = Xoa_app_fxt.app_();
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)));
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)));
parser_fxt = new Xop_fxt(app, wiki); // NOTE: always new(); don't try to cache; causes errors in Language_lib
core = Scrib_core.Core_new_(app, wiki.Parser_mgr().Ctx());
core.Engine_(engine); engine.Clear();
@@ -39,47 +39,49 @@ public class Mock_scrib_fxt {
for (Mock_proc_fxt proc : ary)
engine.RegisterLibraryForTest(proc);
}
public void Test__proc__objs__flat(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.Y, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__objs__nest(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.N, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.Y, args);}
public void Test__proc__kvps__nest(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.N, args);}
private static void Test__proc__kvps(Scrib_lib lib, String proc_name, String expd, boolean flat, KeyVal[] args) {
KeyVal[] actl_ary = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
public void Init__page(String ttl, String txt) {parser_fxt.Init_page_create(ttl, txt);}
public void Test__proc__ints (Scrib_lib lib, String proc_name, Object[] args, int expd) {Test__proc__kvps(lib, proc_name, Bool_.Y, Int_.To_str(expd), Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__objs__flat(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.Y, expd, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__objs__nest(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.N, expd, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.Y, expd, args);}
public void Test__proc__kvps__nest(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.N, expd, args);}
private static void Test__proc__kvps(Scrib_lib lib, String proc_name, boolean flat, String expd, Keyval[] args) {
Keyval[] actl_ary = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
if (flat)
Tfds.Eq(expd, Mock_scrib_fxt_.Kvp_vals_to_str(actl_ary));
else
Tfds.Eq_str_lines(expd, KeyVal_.Ary__to_str__nest(actl_ary));
Tfds.Eq_str_lines(expd, Keyval_.Ary__to_str__nest(actl_ary));
}
public void Test__proc__objs__empty(Scrib_lib lib, String proc_name, Object[] args) {Test__proc__kvps__empty(lib, proc_name, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__kvps__empty(Scrib_lib lib, String proc_name, KeyVal[] args) {
public void Test__proc__kvps__empty(Scrib_lib lib, String proc_name, Keyval[] args) {
Tfds.Eq(0, Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args).length);
}
public void Test__proc__kvps__vals(Scrib_lib lib, String proc_name, KeyVal[] args, Object... expd_ary) {
KeyVal[] actl_kvs = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
public void Test__proc__kvps__vals(Scrib_lib lib, String proc_name, Keyval[] args, Object... expd_ary) {
Keyval[] actl_kvs = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
Object[] actl_ary = Mock_scrib_fxt_.Kvp_vals_to_objs(actl_kvs);
Tfds.Eq_ary(expd_ary, actl_ary);
}
}
class Mock_scrib_fxt_ {
public static KeyVal[] Test__lib_proc__core(Scrib_lib lib, String proc_name, KeyVal[] args) {
public static Keyval[] Test__lib_proc__core(Scrib_lib lib, String proc_name, Keyval[] args) {
Scrib_proc proc = lib.Procs().Get_by_key(proc_name);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(new Scrib_proc_args(args), proc_rslt);
return proc_rslt.Ary();
}
public static Object[] Kvp_vals_to_objs(KeyVal[] kvps) {
public static Object[] Kvp_vals_to_objs(Keyval[] kvps) {
int len = kvps.length;
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i)
rv[i] = kvps[i].Val();
return rv;
}
public static String Kvp_vals_to_str(KeyVal[] ary) {
public static String Kvp_vals_to_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
KeyVal kv = ary[i];
Keyval kv = ary[i];
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(kv.Val()));
}
return bfr.To_str_and_clear();

View File

@@ -31,22 +31,22 @@ public class Process_engine implements Scrib_engine {
public boolean Dbg_print() {return dbg_print;} public void Dbg_print_(boolean v) {dbg_print = v;} private boolean dbg_print;
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {server = v;} Scrib_server server;
public Scrib_lua_proc LoadString(String name, String text) {
KeyVal[] rslt = this.Dispatch("op", "loadString", "text", text, "chunkName", name);
Keyval[] rslt = this.Dispatch("op", "loadString", "text", text, "chunkName", name);
return new Scrib_lua_proc(name, Int_.cast(rslt[0].Val()));
}
public KeyVal[] CallFunction(int id, KeyVal[] args) {
public Keyval[] CallFunction(int id, Keyval[] args) {
return this.Dispatch("op", "call", "id", id, "nargs", args.length, "args", args);
}
public void RegisterLibrary(KeyVal[] functions_ary) {
public void RegisterLibrary(Keyval[] functions_ary) {
this.Dispatch("op", "registerLibrary", "name", Scrib_core.Key_mw_interface, "functions", functions_ary);
}
public void CleanupChunks(KeyVal[] ids) {
public void CleanupChunks(Keyval[] ids) {
this.Dispatch("op", "cleanupChunks", "ids", ids);
}
public KeyVal[] ExecuteModule(int mod_id) {
public Keyval[] ExecuteModule(int mod_id) {
return this.CallFunction(core.Lib_mw().Mod().Fncs_get_id("executeModule"), Scrib_kv_utl_.base1_obj_(new Scrib_lua_proc("", mod_id)));
}
private KeyVal[] Dispatch(Object... ary) {
private Keyval[] Dispatch(Object... ary) {
Bry_bfr bfr = app.Utl__bfr_mkr().Get_k004().Clear();
while (true) {
Dispatch_bld_send(bfr, ary);
@@ -61,18 +61,18 @@ public class Process_engine implements Scrib_engine {
}
else if (String_.Eq(op, "error")) {
core.Handle_error(rsp.Rslt_ary()[0].Val_to_str_or_empty(), "");
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
else if (String_.Eq(op, "call")) {
String id = rsp.Call_id();
KeyVal[] args = rsp.Call_args();
Keyval[] args = rsp.Call_args();
Scrib_proc proc = proc_mgr.Get_by_key(id); if (proc == null) throw Scrib_xtn_mgr.err_("could not find proc with id of {0}", id);
Scrib_proc_args proc_args = new Scrib_proc_args(args);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(proc_args, proc_rslt);
String fail_msg = proc_rslt.Fail_msg();
if (fail_msg == null) {
KeyVal[] cbk_rslts = proc_rslt.Ary();
Keyval[] cbk_rslts = proc_rslt.Ary();
ary = Object_.Ary("op", "return", "nvalues", cbk_rslts.length, "values", cbk_rslts);
}
else {
@@ -82,7 +82,7 @@ public class Process_engine implements Scrib_engine {
else {
bfr.Mkr_rls();
// app.Usr_dlg().Warn_many("", "", "invalid dispatch: op=~{0} page=~{1}", op, String_.new_u8(core.Ctx().Page().Page_ttl().Page_db()));
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
}
} private static final byte[] Dispatch_hdr = Bry_.new_a7("0000000000000000"); // itm_len + itm_chk in 8-len HexDec

View File

@@ -27,26 +27,26 @@ public class Process_recv_msg {
} private Hash_adp arg_keys = Hash_adp_.new_(); private static final byte Arg_op = 0, Arg_values = 1, Arg_id = 2, Arg_args = 3;
public String Op() {return op;} private String op;
public String Call_id() {return call_id;} private String call_id;
public KeyVal[] Rslt_ary() {return rslt_ary;} private KeyVal[] rslt_ary;
public KeyVal[] Values() {return values;} private KeyVal[] values;
public KeyVal[] Call_args() {return call_args;} private KeyVal[] call_args;
public Keyval[] Rslt_ary() {return rslt_ary;} private Keyval[] rslt_ary;
public Keyval[] Values() {return values;} private Keyval[] values;
public Keyval[] Call_args() {return call_args;} private Keyval[] call_args;
public String Extract(byte[] rsp) {
try {
op = call_id = null;
rslt_ary = values = call_args = null;
KeyVal[] root_ary = parser.Parse_as_kvs(rsp);
rslt_ary = (KeyVal[])root_ary[0].Val();
Keyval[] root_ary = parser.Parse_as_kvs(rsp);
rslt_ary = (Keyval[])root_ary[0].Val();
int len = rslt_ary.length;
for (int i = 0; i < len; i++) {
KeyVal kv = rslt_ary[i];
Keyval kv = rslt_ary[i];
String kv_key = kv.Key();
Byte_obj_val bv = (Byte_obj_val)arg_keys.Get_by(kv_key);
if (bv != null) {
switch (bv.Val()) {
case Arg_op: op = kv.Val_to_str_or_empty(); break;
case Arg_values: values = (KeyVal[])kv.Val(); break;
case Arg_values: values = (Keyval[])kv.Val(); break;
case Arg_id: call_id = kv.Val_to_str_or_empty(); break;
case Arg_args: call_args = (KeyVal[])kv.Val(); break;
case Arg_args: call_args = (Keyval[])kv.Val(); break;
}
}
}

View File

@@ -54,19 +54,19 @@ public class Process_send_wtr {
bfr.Add_byte(Byte_ascii.Brack_end);
return true;
} static final byte[] Prc_bgn = Bry_.new_a7("chunks[");
private boolean Encode_ary(Bry_bfr bfr, KeyVal[] ary) {
private boolean Encode_ary(Bry_bfr bfr, Keyval[] ary) {
int len = ary.length;
bfr.Add_byte(Byte_ascii.Curly_bgn);
for (int i = 0; i < len; i++) {
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
KeyVal itm = ary[i];
Keyval itm = ary[i];
Encode_key(bfr, itm.Key_as_obj());
Encode_obj(bfr, itm.Val());
}
bfr.Add_byte(Byte_ascii.Curly_end);
return true;
}
private boolean Encode_kv(Bry_bfr bfr, KeyVal kv) {
private boolean Encode_kv(Bry_bfr bfr, Keyval kv) {
bfr.Add_byte(Byte_ascii.Curly_bgn);
Encode_key(bfr, kv.Key_as_obj());
Encode_obj(bfr, kv.Val());
@@ -88,8 +88,8 @@ public class Process_send_wtr {
else if (Object_.Eq(c, String.class)) {if (!Encode_str(bfr, (String)o)) return false;}
else if (Object_.Eq(c, byte[].class)) {if (!Encode_str(bfr, (byte[])o)) return false;} // NOTE: not in Scribunto; added here for PERF of not re-creating a String Object
else if (Object_.Eq(c, Scrib_lua_proc.class)) {if (!Encode_prc(bfr, (Scrib_lua_proc)o)) return false;}
else if (Object_.Eq(c, KeyVal.class)) {if (!Encode_kv(bfr, (KeyVal)o)) return false;}
else if (Object_.Eq(c, KeyVal[].class)) {if (!Encode_ary(bfr, (KeyVal[])o)) return false;}
else if (Object_.Eq(c, Keyval.class)) {if (!Encode_kv(bfr, (Keyval)o)) return false;}
else if (Object_.Eq(c, Keyval[].class)) {if (!Encode_ary(bfr, (Keyval[])o)) return false;}
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: {0}", Type_adp_.NameOf_obj(o));}
return true;
}

View File

@@ -36,7 +36,7 @@ class Scrib_lua_srl_fxt {
srl = new Process_send_wtr(usr_dlg);
}
} Process_send_wtr srl; Gfo_usr_dlg usr_dlg;
public KeyVal[] ary_(KeyVal... ary) {return ary;}
public KeyVal itm_(String key, Object val) {return KeyVal_.new_(key, val);}
public Keyval[] ary_(Keyval... ary) {return ary;}
public Keyval itm_(String key, Object val) {return Keyval_.new_(key, val);}
public void Test_encode(Object o, String expd) {Tfds.Eq(expd, srl.Encode(o));}
}

View File

@@ -55,34 +55,34 @@ class Process_server_mock_rcvd_val implements Process_server_mock_rcvd {
public Process_server_mock_rcvd_val(boolean print_key) {this.print_key = print_key;} private boolean print_key;
public String Bld(Object[] cmd_objs) {
Bry_bfr tmp_bfr = Bry_bfr.new_();
Bld_recursive(tmp_bfr, 0, (KeyVal[])cmd_objs[5]);
Bld_recursive(tmp_bfr, 0, (Keyval[])cmd_objs[5]);
byte[] values_str = tmp_bfr.To_bry_and_clear();
tmp_bfr.Add(Bry_rv_bgn).Add_int_variable(values_str.length).Add(Bry_rv_mid).Add(values_str).Add(Bry_rv_end);
return tmp_bfr.To_str_and_clear();
}
private void Bld_recursive(Bry_bfr bfr, int depth, KeyVal[] ary) {
private void Bld_recursive(Bry_bfr bfr, int depth, Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
KeyVal kv = ary[i];
Keyval kv = ary[i];
Object kv_val = kv.Val();
if (kv_val == null) {
bfr.Add(gplx.langs.jsons.Json_itm_.Bry__null);
continue;
}
Class<?> kv_val_type = kv_val.getClass();
boolean kv_val_is_array = Type_adp_.Eq(kv_val_type, KeyVal[].class);
boolean kv_val_is_array = Type_adp_.Eq(kv_val_type, Keyval[].class);
if (print_key && !kv_val_is_array)
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
if (Type_adp_.Eq(kv_val_type, Bool_.Cls_ref_type))
bfr.Add(Bool_.cast(kv_val) ? gplx.langs.jsons.Json_itm_.Bry__true : gplx.langs.jsons.Json_itm_.Bry__false);
else if (kv_val_is_array) {
KeyVal[] sub = (KeyVal[])kv_val;
Keyval[] sub = (Keyval[])kv_val;
if (sub.length == 0) {bfr.Add_byte(Byte_ascii.Curly_bgn).Add_byte(Byte_ascii.Curly_end);}
else {
bfr.Add_byte_nl();
bfr.Add_byte_repeat(Byte_ascii.Space, (depth + 1) * 2);
Bld_recursive(bfr, depth + 1, (KeyVal[])kv_val);
Bld_recursive(bfr, depth + 1, (Keyval[])kv_val);
}
}
else

View File

@@ -18,32 +18,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.langs.jsons.*;
class Kv_ary_utl {
public static KeyVal[] new_(boolean base_1, Object... vals) {
public static Keyval[] new_(boolean base_1, Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; ++i)
rv[i] = KeyVal_.int_(i + (base_1 ? 1 : 0), vals[i]);
rv[i] = Keyval_.int_(i + (base_1 ? 1 : 0), vals[i]);
return rv;
}
public static KeyVal[] new_kvs(KeyVal... vals) {return vals;}
public static String Ary_to_str(Json_wtr wtr, KeyVal[] ary) {
public static Keyval[] new_kvs(Keyval... vals) {return vals;}
public static String Ary_to_str(Json_wtr wtr, Keyval[] ary) {
wtr.Doc_nde_bgn();
Ary_to_str(wtr, 0, ary);
return wtr.Doc_nde_end().To_str_and_clear();
}
private static void Ary_to_str(Json_wtr wtr, int indent, KeyVal[] ary) {
private static void Ary_to_str(Json_wtr wtr, int indent, Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Ary_to_str__itm(wtr, indent, ary[i]);
}
}
private static void Ary_to_str__itm(Json_wtr wtr, int indent, KeyVal itm) {
private static void Ary_to_str__itm(Json_wtr wtr, int indent, Keyval itm) {
Object val = itm.Val();
Class<?> val_type = val.getClass();
int type_tid = Type_adp_.To_tid_type(val_type);
if (type_tid == Type_adp_.Tid__obj) {
if (Type_adp_.Eq(val_type, KeyVal[].class))
Ary_to_str__nde(wtr, indent, itm.Key(), (KeyVal[])itm.Val());
if (Type_adp_.Eq(val_type, Keyval[].class))
Ary_to_str__nde(wtr, indent, itm.Key(), (Keyval[])itm.Val());
else if (Type_adp_.Is_array(val_type))
Ary_to_str__ary(wtr, indent, itm.Key(), Array_.cast(val));
else
@@ -57,7 +57,7 @@ class Kv_ary_utl {
Ary_to_str__ary_itms(wtr, indent + 1, array);
wtr.Ary_end();
}
private static void Ary_to_str__nde(Json_wtr wtr, int indent, String key, KeyVal[] kv) {
private static void Ary_to_str__nde(Json_wtr wtr, int indent, String key, Keyval[] kv) {
wtr.Nde_bgn(key);
Ary_to_str(wtr, indent + 1, kv);
wtr.Nde_end();
@@ -69,8 +69,8 @@ class Kv_ary_utl {
Class<?> itm_type = itm.getClass();
int itm_type_tid = Type_adp_.To_tid_type(itm_type);
if (itm_type_tid == Type_adp_.Tid__obj) {
if (Type_adp_.Eq(itm_type, KeyVal.class))
Ary_to_str__itm(wtr, indent + 1, (KeyVal)itm);
if (Type_adp_.Eq(itm_type, Keyval.class))
Ary_to_str__itm(wtr, indent + 1, (Keyval)itm);
else if (Type_adp_.Is_array(itm_type))
Ary_to_str__ary_itms(wtr, indent + 1, Array_.cast(itm));
else

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
class Scrib_err {
public static Err Make__err__arg(String proc, int arg_idx, String actl, String expd) {
String rv = String_.Format("bad argument #{0} to {1} ({2} expected, got {3})", arg_idx, proc, expd, actl); // "bad argument #$argIdx to '$name' ($expectType expected, got $type)"
return Err_.new_("scribunto", rv);
}
}

View File

@@ -78,7 +78,7 @@ public class Scrib_lib_language implements Scrib_lib {
, Invk_formatNum, Invk_formatDate, Invk_formatDuration, Invk_getDurationIntervals, Invk_parseFormattedNumber
, Invk_convertPlural, Invk_convertGrammar, Invk_gender, Invk_isRTL
);
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 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
@@ -166,9 +166,9 @@ public class Scrib_lib_language implements Scrib_lib {
byte[] num = args.Xstr_bry_or_null(1);
boolean skip_commafy = false;
if (num != null) { // MW: if num present, check options table for noCommafy arg;
KeyVal[] kv_ary = args.Cast_kv_ary_or_null(2);
Keyval[] kv_ary = args.Cast_kv_ary_or_null(2);
if (kv_ary != null) {
Object skip_commafy_obj = KeyVal_.Ary_get_by_key_or_null(kv_ary, "noCommafy");
Object skip_commafy_obj = Keyval_.Ary_get_by_key_or_null(kv_ary, "noCommafy");
if (skip_commafy_obj != null)
skip_commafy = Bool_.cast(skip_commafy_obj);
}
@@ -212,7 +212,7 @@ public class Scrib_lib_language implements Scrib_lib {
public boolean FormatDuration(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xol_lang_itm lang = lang_(args);
long seconds = args.Pull_long(1);
KeyVal[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Keyval[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Xol_duration_itm[] intervals = Xol_duration_itm_.Xto_itm_ary(intervals_kv_ary);
byte[] rv = lang.Duration_mgr().Format_durations(core.Ctx(), seconds, intervals);
return rslt.Init_obj(rv);
@@ -220,7 +220,7 @@ public class Scrib_lib_language implements Scrib_lib {
public boolean GetDurationIntervals(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xol_lang_itm lang = lang_(args);
long seconds = args.Pull_long(1);
KeyVal[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Keyval[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Xol_duration_itm[] intervals = Xol_duration_itm_.Xto_itm_ary(intervals_kv_ary);
Xol_interval_itm[] rv = lang.Duration_mgr().Get_duration_intervals(seconds, intervals);
return rslt.Init_obj(Xol_interval_itm.Xto_kv_ary(rv));

View File

@@ -68,8 +68,8 @@ public class Scrib_lib_language_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("de", 1234), "1.234"); // german spr
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", 1234), "1,234"); // english spr
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234"), "1,234"); // String passed (not int)
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", true))) , "1234"); // noCommafy.y
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", false))) , "1,234"); // noCommafy.n
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", Keyval_.Ary(Keyval_.new_("noCommafy", true))) , "1234"); // noCommafy.y
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", Keyval_.Ary(Keyval_.new_("noCommafy", false))) , "1,234"); // noCommafy.n
}
@Test public void FormatDate() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "2013-03-17", false), "2013-03-17");
@@ -84,7 +84,7 @@ public class Scrib_lib_language_tst {
@Test public void FormatDate_date_omitted() { // PURPOSE: some calls skip the date; retrieve arg_4 by int; EX: pl.w:L._Frank_Baum
Tfds.Now_enabled_y_();
Tfds.Now_set(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, KeyVal_.Ary(KeyVal_.int_(1, "en"), KeyVal_.int_(2, "Y-m-d"), KeyVal_.int_(4, false)), "2013-12-19");
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Keyval_.Ary(Keyval_.int_(1, "en"), Keyval_.int_(2, "Y-m-d"), Keyval_.int_(4, false)), "2013-12-19");
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", ""), "2013-12-19");// PURPOSE: '' should return today, not fail; EX: th.w:สถานีรถไฟตรัง
Tfds.Now_enabled_n_();
}
@@ -135,11 +135,11 @@ public class Scrib_lib_language_tst {
, " seconds=3"
));
}
public static KeyVal[] Kv_ary_(String... ary) {
public static Keyval[] Kv_ary_(String... ary) {
int ary_len = ary.length;
KeyVal[] rv = new KeyVal[ary_len];
Keyval[] rv = new Keyval[ary_len];
for (int i = 0; i < ary_len; i++) {
rv[i] = KeyVal_.int_(i, ary[i]);
rv[i] = Keyval_.int_(i, ary[i]);
}
return rv;
}

View File

@@ -42,20 +42,20 @@ public class Scrib_lib_message implements Scrib_lib {
private static final int Proc_plain = 0, Proc_check = 1, Proc_init_message_for_lang = 2;
public static final String Invk_plain = "plain", Invk_check = "check", Invk_init_message_for_lang = "init_message_for_lang";
private static final String[] Proc_names = String_.Ary(Invk_plain, Invk_check, Invk_init_message_for_lang);
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 Plain(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte fmt_tid = Scrib_lib_message_data.Fmt_tid_plain;
KeyVal[] data_kvary = args.Pull_kv_ary(0);
Keyval[] data_kvary = args.Pull_kv_ary(0);
Scrib_lib_message_data msg_data = new Scrib_lib_message_data().Parse(data_kvary);
return rslt.Init_obj(String_.new_u8(msg_data.Make_msg(core.Cur_lang(), core.Wiki(), core.Ctx(), true, fmt_tid)));
}
public boolean Check(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte chk_tid = Scrib_lib_message_data.parse_chk_(args.Pull_bry(0));
KeyVal[] data_kvary = args.Pull_kv_ary(1);
Keyval[] data_kvary = args.Pull_kv_ary(1);
Scrib_lib_message_data msg_data = new Scrib_lib_message_data().Parse(data_kvary);
return rslt.Init_obj(msg_data.Chk_msg(core.Cur_lang(), core.Wiki(), core.Ctx(), false, chk_tid));
}
public boolean Init_message_for_lang(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(KeyVal_.new_("lang", core.Wiki().Lang().Key_str()));}
public boolean Init_message_for_lang(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(Keyval_.new_("lang", core.Wiki().Lang().Key_str()));}
}
class Scrib_lib_message_data {
public boolean Use_db() {return use_db;} private boolean use_db;
@@ -65,16 +65,16 @@ class Scrib_lib_message_data {
public byte[] Raw_msg_key() {return raw_msg_key;} private byte[] raw_msg_key;
public Object[] Args() {return args;} Object[] args;
public Xoa_ttl Ttl() {return ttl;} public Scrib_lib_message_data Ttl_(Xoa_ttl v) {ttl = v; return this;} Xoa_ttl ttl;
public Scrib_lib_message_data Parse(KeyVal[] ary) {
public Scrib_lib_message_data Parse(Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
KeyVal kv = ary[i];
Keyval kv = ary[i];
byte[] kv_key = Bry_.new_a7(kv.Key());
Object key_obj = key_hash.Get_by(kv_key); if (key_obj == null) throw Err_.new_wo_type("msg_key is invalid", "key", kv_key);
byte key_tid = ((Byte_obj_val)key_obj).Val();
switch (key_tid) {
case Key_tid_keys:
KeyVal[] keys_ary = (KeyVal[])kv.Val();
Keyval[] keys_ary = (Keyval[])kv.Val();
msg_key = keys_ary[0].Val_to_bry();
break;
case Key_tid_rawMessage: raw_msg_key = kv.Val_to_bry(); break;
@@ -82,7 +82,7 @@ class Scrib_lib_message_data {
case Key_tid_useDB: use_db = Bool_.cast(kv.Val()); break;
case Key_tid_title: title_bry = kv.Val_to_bry(); break;
case Key_tid_params:
KeyVal[] args_ary = (KeyVal[])kv.Val();
Keyval[] args_ary = (Keyval[])kv.Val();
int args_ary_len = args_ary.length;
args = new String[args_ary_len];
for (int j = 0; j < args_ary_len; j++)

View File

@@ -33,11 +33,11 @@ public class Scrib_lib_message_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary_lang("sun", "fr")) , "dim");
}
@Test public void Plain_rawMessage() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "$1", "params", KeyVal_.Ary(KeyVal_.int_(1, "abc")))), "abc");
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "$1", "params", Keyval_.Ary(Keyval_.int_(1, "abc")))), "abc");
}
@Test public void Plain_rawMessage_empty() {// PURPOSE:rawMessage would throw null ref if rawMessage called template that returns empty value; PAGE:it.w:L'Internazionale DATE:2015-02-25
fxt.Parser_fxt().Init_page_create("Template:Msg", "");
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "{{Msg}}", "params", KeyVal_.Ary(KeyVal_.int_(1, "abc")))), "");
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "{{Msg}}", "params", Keyval_.Ary(Keyval_.int_(1, "abc")))), "");
}
@Test public void Check() {
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("exists" , keys_ary("sun")) , true);
@@ -58,19 +58,19 @@ public class Scrib_lib_message_tst {
private void Init_msg(Xol_lang_itm lang, String key, String val) {
lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_a7(key)).Atrs_set(Bry_.new_a7(val), false, false);
}
KeyVal[] keys_ary(String msg_key) {return keys_ary(msg_key, null, null);}
KeyVal[] keys_ary_arg(String msg_key, String arg) {return keys_ary(msg_key, null, arg);}
KeyVal[] keys_ary_lang(String msg_key, String lang) {return keys_ary(msg_key, lang, null);}
KeyVal[] keys_ary(String msg_key, String lang, String arg) {
Keyval[] keys_ary(String msg_key) {return keys_ary(msg_key, null, null);}
Keyval[] keys_ary_arg(String msg_key, String arg) {return keys_ary(msg_key, null, arg);}
Keyval[] keys_ary_lang(String msg_key, String lang) {return keys_ary(msg_key, lang, null);}
Keyval[] keys_ary(String msg_key, String lang, String arg) {
boolean arg_exists = arg != null;
boolean lang_exists = lang != null;
int idx = 0;
KeyVal[] rv = new KeyVal[1 + (arg_exists ? 1 : 0) + (lang_exists ? 1 : 0)];
rv[0] = KeyVal_.new_("keys", KeyVal_.Ary(KeyVal_.int_(1, msg_key)));
Keyval[] rv = new Keyval[1 + (arg_exists ? 1 : 0) + (lang_exists ? 1 : 0)];
rv[0] = Keyval_.new_("keys", Keyval_.Ary(Keyval_.int_(1, msg_key)));
if (arg_exists)
rv[++idx] = KeyVal_.new_("params", KeyVal_.Ary(KeyVal_.int_(1, arg)));
rv[++idx] = Keyval_.new_("params", Keyval_.Ary(Keyval_.int_(1, arg)));
if (lang_exists)
rv[++idx] = KeyVal_.new_("lang", lang);
rv[++idx] = Keyval_.new_("lang", lang);
return rv;
}
}

View File

@@ -29,7 +29,7 @@ public class Scrib_lib_mw implements Scrib_lib {
Init();
core.RegisterInterface(this, script_dir.GenSubFil("mwInit.lua")); // DATE:2014-07-12
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.lua")
, KeyVal_.new_("allowEnvFuncs", allow_env_funcs));
, Keyval_.new_("allowEnvFuncs", allow_env_funcs));
return mod;
}
public void Invoke_bgn(Xowe_wiki wiki, Xop_ctx ctx, byte[] new_src) {
@@ -81,7 +81,7 @@ public class Scrib_lib_mw implements Scrib_lib {
, Invk_getFrameTitle = "getFrameTitle", Invk_setTTL = "setTTL"
, Invk_parentFrameExists = "parentFrameExists"
;
private static final String[] Proc_names = String_.Ary
private static final String[] Proc_names = String_.Ary
( Invk_loadPackage, Invk_loadPHPLibrary
, Invk_frameExists, Invk_newChildFrame
, Invk_getExpandedArgument, Invk_getAllExpandedArguments
@@ -164,7 +164,7 @@ public class Scrib_lib_mw implements Scrib_lib {
Xot_invk parent_frame = Scrib_frame_.Get_parent(core, frame_tid);
int frame_arg_adj = Scrib_frame_.Get_arg_adj(frame_tid);
int args_len = frame.Args_len() - frame_arg_adj;
if (args_len < 1) return rslt.Init_obj(KeyVal_.Ary_empty); // occurs when "frame:getParent().args" but no parent frame
if (args_len < 1) return rslt.Init_obj(Keyval_.Ary_empty); // occurs when "frame:getParent().args" but no parent frame
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b128(); // NOTE: do not make modular level variable, else random failures; DATE:2013-10-14
List_adp rv = List_adp_.new_();
int arg_idx = 0;
@@ -202,11 +202,11 @@ public class Scrib_lib_mw implements Scrib_lib {
nde.Val_tkn().Tmpl_evaluate(ctx, src, parent_frame, tmp_bfr);
// ctx.Scribunto = Bool_.N;
String val = key_missing ? tmp_bfr.To_str_and_clear() : tmp_bfr.To_str_and_clear_and_trim(); // NOTE: must trim if key_exists; DUPE:TRIM_IF_KEY
KeyVal kv = key_is_str ? KeyVal_.new_(key_as_str, val) : KeyVal_.int_(key_as_int, val);
Keyval kv = key_is_str ? Keyval_.new_(key_as_str, val) : Keyval_.int_(key_as_int, val);
rv.Add(kv);
}
tmp_bfr.Mkr_rls();
return rslt.Init_obj((KeyVal[])rv.To_ary(KeyVal.class));
return rslt.Init_obj((Keyval[])rv.To_ary(Keyval.class));
}
public boolean FrameExists(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String frame_id = args.Pull_str(0);
@@ -227,7 +227,7 @@ public class Scrib_lib_mw implements Scrib_lib {
Xop_ctx tmp_ctx = Xop_ctx.new_sub_(cur_wiki);
int args_adj = Scrib_frame_.Get_arg_adj(frame_tid);
int args_len = frame.Args_len() - args_adj;
KeyVal[] kv_args = new KeyVal[args_len];
Keyval[] kv_args = new Keyval[args_len];
Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b512();
for (int i = 0; i < args_len; i++) {
Arg_nde_tkn arg = frame.Args_get_by_idx(i + args_adj);
@@ -236,7 +236,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (String_.Eq(key, "")) key = Int_.To_str(i);
arg.Val_tkn().Tmpl_evaluate(ctx, src, parent_frame, tmp_bfr); // NOTE: must evaluate against parent_frame; evaluating against current frame may cause stack-overflow; DATE:2013-04-04
String val = tmp_bfr.To_str_and_clear();
kv_args[i] = KeyVal_.new_(key, val);
kv_args[i] = Keyval_.new_(key, val);
}
Xot_invk_mock mock_frame = Xot_invk_mock.new_(Bry_.new_u8(frame_id), kv_args); // use frame_id for Frame_ttl; in lieu of a better candidate; DATE:2014-09-21
tmp_ctx.Parse_tid_(Xop_parser_.Parse_tid_page_tmpl); // default xnde names to template; needed for test, but should be in place; DATE:2014-06-27
@@ -252,7 +252,7 @@ public class Scrib_lib_mw implements Scrib_lib {
int fnc_name_len = fnc_name.length;
Bry_obj_ref argx_ref = Bry_obj_ref.New_empty();
Bry_obj_ref fnc_name_ref = Bry_obj_ref.New(fnc_name);
KeyVal[] parser_func_args = CallParserFunction_parse_args(cur_wiki.Appe().Utl_num_parser(), argx_ref, fnc_name_ref, args.Ary());
Keyval[] parser_func_args = CallParserFunction_parse_args(cur_wiki.Appe().Utl_num_parser(), argx_ref, fnc_name_ref, args.Ary());
Xot_invk_mock frame = Xot_invk_mock.new_(parent_frame.Defn_tid(), 0, fnc_name, parser_func_args); // pass something as frame_ttl; choosng fnc_name; DATE:2014-09-21
Xol_func_itm finder = cur_wiki.Lang().Func_regy().Find_defn(fnc_name, 0, fnc_name_len);
Xot_defn defn = finder.Func();
@@ -264,17 +264,17 @@ public class Scrib_lib_mw implements Scrib_lib {
bfr.Mkr_rls();
return rslt.Init_obj(bfr.To_str_and_clear());
}
private KeyVal[] CallParserFunction_parse_args(Number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, KeyVal[] args) {
private Keyval[] CallParserFunction_parse_args(Number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, Keyval[] args) {
List_adp rv = List_adp_.new_();
// flatten args
int args_len = args.length;
for (int i = 2; i < args_len; i++) {
KeyVal arg = args[i];
Keyval arg = args[i];
if (Is_kv_ary(arg)) {
KeyVal[] arg_kv_ary = (KeyVal[])arg.Val();
Keyval[] arg_kv_ary = (Keyval[])arg.Val();
int arg_kv_ary_len = arg_kv_ary.length;
for (int j = 0; j < arg_kv_ary_len; j++) {
KeyVal sub_arg = arg_kv_ary[j];
Keyval sub_arg = arg_kv_ary[j];
rv.Add(sub_arg);
}
}
@@ -287,7 +287,7 @@ public class Scrib_lib_mw implements Scrib_lib {
int fnc_name_len = fnc_name.length;
int fnc_name_colon_pos = Bry_find_.Find_fwd(fnc_name, Byte_ascii.Colon, 0, fnc_name_len);
if (fnc_name_colon_pos == Bry_find_.Not_found) {
KeyVal arg_argx = (KeyVal)rv.Get_at(0);
Keyval arg_argx = (Keyval)rv.Get_at(0);
argx_ref.Val_(arg_argx.Val_to_bry());
rv.Del_at(0);
}
@@ -296,9 +296,9 @@ public class Scrib_lib_mw implements Scrib_lib {
fnc_name = Bry_.Mid(fnc_name, 0, fnc_name_colon_pos);
fnc_name_ref.Val_(fnc_name);
}
return (KeyVal[])rv.To_ary(KeyVal.class);
return (Keyval[])rv.To_ary(Keyval.class);
}
private static boolean Is_kv_ary(KeyVal kv) {return Type_adp_.Eq_typeSafe(kv.Val(), KeyVal[].class);}
private static boolean Is_kv_ary(Keyval kv) {return Type_adp_.Eq_typeSafe(kv.Val(), Keyval[].class);}
public boolean ExpandTemplate(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String ttl_str = args.Pull_str(1);
byte[] ttl_bry = Bry_.new_u8(ttl_str);
@@ -306,7 +306,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (ttl == null) return rslt.Init_ary_empty(); // invalid ttl;
if (!ttl.ForceLiteralLink() && ttl.Ns().Id_is_main()) // title is not literal and is not prefixed with Template; parse again as template; EX: ":A" and "Template:A" are fine; "A" is parsed again as "Template:A"
ttl = Xoa_ttl.parse(cur_wiki, Bry_.Add(cur_wiki.Ns_mgr().Ns_template().Name_db_w_colon(), ttl_bry)); // parse again, but add "Template:"
KeyVal[] args_ary = args.Pull_kv_ary(2);
Keyval[] args_ary = args.Pull_kv_ary(2);
// BLOCK.bgn:Xot_invk_tkn.Transclude; cannot reuse b/c Transclude needs invk_tkn, and invk_tkn is manufactured late; DATE:2014-01-02
byte[] sub_src = null;
if (ttl.Ns().Id_is_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr
@@ -316,7 +316,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (sub_src == null) // ttl is not in template cache, or is a ttl in non-Template ns; load title
sub_src = core.Wiki().Cache_mgr().Page_cache().Get_or_load_as_src(ttl);
if (sub_src != null) {
Xot_invk_mock sub_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt(), args_ary); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-09-21
Xot_invk_mock sub_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt_w_ttl_case(), args_ary); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-09-21
Xot_defn_tmpl transclude_tmpl = ctx.Wiki().Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), ttl.Ns(), ttl.Page_db(), sub_src);
Bry_bfr sub_bfr = cur_wiki.Utl__bfr_mkr().Get_k004();
transclude_tmpl.Tmpl_evaluate(ctx, sub_frame, sub_bfr);
@@ -330,7 +330,7 @@ public class Scrib_lib_mw implements Scrib_lib {
// BLOCK.end:Xot_invk_tkn.Transclude
}
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 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 IsSubsting(Scrib_proc_args args, Scrib_proc_rslt rslt) {
boolean is_substing = false;
Xot_invk current_frame = core.Frame_current();
@@ -359,8 +359,8 @@ public class Scrib_lib_mw implements Scrib_lib {
ttl = Xoa_ttl.parse(cur_wiki, Bry_.new_u8((String)ttl_obj));
if (ttl == null) throw Err_.new_wo_type("newChild: invalid title", "title", (String)ttl_obj);
}
KeyVal[] args_ary = args.Pull_kv_ary(2);
Xot_invk_mock new_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt(), args_ary); // NOTE: use spaces, not unders; REF.MW:$frame->getTitle()->getPrefixedText(); DATE:2014-08-14
Keyval[] args_ary = args.Pull_kv_ary(2);
Xot_invk_mock new_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt_w_ttl_case(), args_ary); // NOTE: use spaces, not unders; REF.MW:$frame->getTitle()->getPrefixedText(); DATE:2014-08-14
String new_frame_id = "frame" + Int_.To_str(frame_list_len);
frame_list.Add(new_frame_id, new_frame);
return rslt.Init_obj(new_frame_id);
@@ -379,8 +379,8 @@ public class Scrib_lib_mw implements Scrib_lib {
}
class Scrib_lib_mw_callParserFunction_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
KeyVal lhs = (KeyVal)lhsObj;
KeyVal rhs = (KeyVal)rhsObj;
Keyval lhs = (Keyval)lhsObj;
Keyval rhs = (Keyval)rhsObj;
Object lhs_key = lhs.Key_as_obj();
Object rhs_key = rhs.Key_as_obj();
boolean lhs_is_int = Int_.TypeMatch(lhs_key.getClass());
@@ -392,5 +392,5 @@ class Scrib_lib_mw_callParserFunction_sorter implements gplx.core.lists.Comparer
else // both are strings
return String_.Compare(String_.cast(lhs_key), String_.cast(rhs_key));
}
public static final Scrib_lib_mw_callParserFunction_sorter Instance = new Scrib_lib_mw_callParserFunction_sorter(); Scrib_lib_mw_callParserFunction_sorter() {}
public static final Scrib_lib_mw_callParserFunction_sorter Instance = new Scrib_lib_mw_callParserFunction_sorter(); Scrib_lib_mw_callParserFunction_sorter() {}
}

View File

@@ -30,15 +30,15 @@ public class Scrib_lib_mw__lib_tst {
fxt.Test_scrib_proc_bool(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, false);
}
@Test public void GetAllExpandedArguments() {
fxt.Init_frame_current(KeyVal_.new_("k1", "v1"));
fxt.Init_frame_current(Keyval_.new_("k1", "v1"));
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "1=\n k1=v1");
}
@Test public void GetAllExpandedArguments_parent() {
fxt.Init_frame_parent("test", KeyVal_.new_("1", "a1"), KeyVal_.new_("2", "a2"));
fxt.Init_frame_parent("test", Keyval_.new_("1", "a1"), Keyval_.new_("2", "a2"));
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("parent"), "1=\n 1=a1\n 2=a2");
}
@Test public void GetExpandedArgument() {
fxt.Init_frame_current(KeyVal_.int_(1, "val_1"), KeyVal_.new_("key_2", "val_2"), KeyVal_.int_(3, "val_3"));
fxt.Init_frame_current(Keyval_.int_(1, "val_1"), Keyval_.new_("key_2", "val_2"), Keyval_.int_(3, "val_3"));
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , "val_1"); // get 1st by idx
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "2") , "val_3"); // get 2nd by idx (which is "3", not "key_2)
fxt.Test_scrib_proc_empty (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "3")); // get 3rd by idx (which is n/a, not "val_3")
@@ -46,17 +46,17 @@ public class Scrib_lib_mw__lib_tst {
fxt.Test_scrib_proc_empty (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_3")); // key_3 n/a
}
@Test public void GetExpandedArgument_parent() {
fxt.Init_frame_parent ("test", KeyVal_.new_("1", "a1"), KeyVal_.new_("2", "a2"));
fxt.Init_frame_current(KeyVal_.new_("2", "b2"));
fxt.Init_frame_parent ("test", Keyval_.new_("1", "a1"), Keyval_.new_("2", "a2"));
fxt.Init_frame_current(Keyval_.new_("2", "b2"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "1"), "a1");
}
@Test public void GetExpandedArgument_numeric_key() { // PURPOSE.FIX: frame.args[1] was ignoring "1=val_1" b/c it was looking for 1st unnamed arg (and 1 is the name for "1=val_1")
fxt.Init_frame_current(KeyVal_.new_("1", "val_1"));
fxt.Init_frame_current(Keyval_.new_("1", "val_1"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1"), "val_1"); // get 1st by idx, even though idx is String
}
@Test public void GetExpandedArgument_numeric_key_2() { // PURPOSE.FIX: same as above, but for parent context; DATE:2013-09-23
fxt.Init_frame_parent ("test", KeyVal_.new_("2", "a1"));
fxt.Init_frame_current(KeyVal_.new_("2", "a2"));
fxt.Init_frame_parent ("test", Keyval_.new_("2", "a1"));
fxt.Init_frame_current(Keyval_.new_("2", "a2"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2"), "a1"); // get 1st by idx, even though idx is String
}
@Test public void GetExpandedArgument_out_of_bounds() {
@@ -86,4 +86,4 @@ public class Scrib_lib_mw__lib_tst {
@Test public void LoadPHPLibrary() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_loadPHPLibrary, Object_.Ary("mock_library") , Scrib_invoke_func_fxt.Null_rslt);
}
}
}

View File

@@ -17,10 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.addons.ctgs.*;
import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.xwikis.*;
public class Scrib_lib_site implements Scrib_lib {
public Scrib_lib_site(Scrib_core core) {this.core = core;} private Scrib_core core;
public Scrib_lib_site(Scrib_core core) {this.core = core;} private final Scrib_core core;
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
public Scrib_lib Init() {procs.Init_by_lib(this, Proc_names); return this;}
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
@@ -29,7 +29,7 @@ public class Scrib_lib_site implements Scrib_lib {
notify_wiki_changed_fnc = mod.Fncs_get_by_key("notify_wiki_changed");
return mod;
} private Scrib_lua_proc notify_wiki_changed_fnc;
public Scrib_proc_mgr Procs() {return procs;} private Scrib_proc_mgr procs = new Scrib_proc_mgr();
public Scrib_proc_mgr Procs() {return procs;} private final Scrib_proc_mgr procs = new Scrib_proc_mgr();
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
switch (key) {
case Proc_getNsIndex: return GetNsIndex(args, rslt);
@@ -51,9 +51,34 @@ public class Scrib_lib_site implements Scrib_lib {
}
public boolean PagesInCategory(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte[] ctg_name = args.Pull_bry(0);
// byte[] ctg_type = Scrib_kv_utl_.Val_to_bry(values, 1); // TODO.7: get by categoy type; WHEN: categories
int ctg_count = core.Wiki().Db_mgr().Load_mgr().Load_ctg_count(ctg_name);
return rslt.Init_obj(ctg_count);
String ctg_type = args.Cast_str_or(1, "all");
Xoa_ttl ctg_ttl = core.Wiki().Ttl_parse(Xow_ns_.Tid__category, ctg_name);
if (ctg_ttl == null) return rslt.Init_obj(0);
Xoax_ctg_addon ctg_mgr = Xoax_ctg_addon.Get(core.Wiki());
Xoctg_ctg_itm ctg_itm = ctg_mgr.Itms__get_or_null(ctg_name);
if (ctg_itm == null) {
core.Increment_expensive_function_count();
ctg_itm = ctg_mgr.Itms__load(ctg_name);
}
if (String_.Eq(ctg_type, "*")) {
Keyval[] rv = new Keyval[4];
rv[0] = Keyval_.new_("all", ctg_itm.All);
rv[1] = Keyval_.new_("pages", ctg_itm.Pages);
rv[2] = Keyval_.new_("subcats", ctg_itm.Subcs);
rv[3] = Keyval_.new_("files", ctg_itm.Files);
return rslt.Init_obj(rv);
}
else {
int rv_count = 0;
switch (ctg_type) {
case "all": rv_count = ctg_itm.All; break;
case "pages": rv_count = ctg_itm.Pages; break;
case "subcats": rv_count = ctg_itm.Subcs; break;
case "files": rv_count = ctg_itm.Files; break;
default: throw Scrib_err.Make__err__arg(Invk_pagesInCategory, 2, ctg_type, "one of '*', 'all', 'pages', 'subcats', or 'files'");
}
return rslt.Init_obj(rv_count);
}
}
public boolean PagesInNs(Scrib_proc_args args, Scrib_proc_rslt rslt) {
int ns_id = args.Pull_int(0);
@@ -77,7 +102,7 @@ public class Scrib_lib_site implements Scrib_lib {
// TODO: cache interwikimap results
Xow_xwiki_mgr xwiki_mgr = core.Wiki().Xwiki_mgr();
int xwiki_len = xwiki_mgr.Len();
KeyVal[][] rv = new KeyVal[xwiki_len][];
Keyval[][] rv = new Keyval[xwiki_len][];
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
@@ -88,96 +113,96 @@ public class Scrib_lib_site implements Scrib_lib {
}
return rslt.Init_obj(rv);
}
private KeyVal[] InterwikiMap_itm(Xow_xwiki_itm itm, String prefix, boolean itm_is_local) {
private Keyval[] InterwikiMap_itm(Xow_xwiki_itm itm, String prefix, boolean itm_is_local) {
boolean is_extralanguage_link = false;
int rv_len = 7;
if (is_extralanguage_link) rv_len += 2;
String url = String_.new_u8(itm.Domain_bry());
boolean url_is_relative = String_.Has_at_bgn(url, "//");
KeyVal[] rv = new KeyVal[rv_len];
rv[ 0] = KeyVal_.new_("prefix" , prefix);
rv[ 1] = KeyVal_.new_("url" , url); // wfExpandUrl( $row['iw_url'], PROTO_RELATIVE ),
rv[ 2] = KeyVal_.new_("isProtocolRelative" , url_is_relative); // substr( $row['iw_url'], 0, 2 ) === '//',
rv[ 3] = KeyVal_.new_("isLocal" , itm_is_local); // isset( $row['iw_local'] ) && $row['iw_local'] == '1',
rv[ 4] = KeyVal_.new_("isTranscludable" , Bool_.N); // isset( $row['iw_trans'] ) && $row['iw_trans'] == '1',
rv[ 5] = KeyVal_.new_("isCurrentWiki" , Bool_.N); // in_array( $prefix, $wgLocalInterwikis ),
rv[ 6] = KeyVal_.new_("isExtraLanguageLink" , is_extralanguage_link); // in_array( $prefix, $wgExtraInterlanguageLinkPrefixes ),
Keyval[] rv = new Keyval[rv_len];
rv[ 0] = Keyval_.new_("prefix" , prefix);
rv[ 1] = Keyval_.new_("url" , url); // wfExpandUrl( $row['iw_url'], PROTO_RELATIVE ),
rv[ 2] = Keyval_.new_("isProtocolRelative" , url_is_relative); // substr( $row['iw_url'], 0, 2 ) === '//',
rv[ 3] = Keyval_.new_("isLocal" , itm_is_local); // isset( $row['iw_local'] ) && $row['iw_local'] == '1',
rv[ 4] = Keyval_.new_("isTranscludable" , Bool_.N); // isset( $row['iw_trans'] ) && $row['iw_trans'] == '1',
rv[ 5] = Keyval_.new_("isCurrentWiki" , Bool_.N); // in_array( $prefix, $wgLocalInterwikis ),
rv[ 6] = Keyval_.new_("isExtraLanguageLink" , is_extralanguage_link); // in_array( $prefix, $wgExtraInterlanguageLinkPrefixes ),
if (is_extralanguage_link) {
rv[7] = KeyVal_.new_("displayText" , "displayText_TODO"); // $displayText = wfMessage( "interlanguage-link-$prefix" ); if ( !$displayText->isDisabled() ) ...
rv[7] = KeyVal_.new_("tooltip" , "tooltip_TODO"); // $tooltip = wfMessage( "interlanguage-link-sitename-$prefix" );
rv[7] = Keyval_.new_("displayText" , "displayText_TODO"); // $displayText = wfMessage( "interlanguage-link-$prefix" ); if ( !$displayText->isDisabled() ) ...
rv[7] = Keyval_.new_("tooltip" , "tooltip_TODO"); // $tooltip = wfMessage( "interlanguage-link-sitename-$prefix" );
}
return rv;
}
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), KeyVal_.Ary_empty);}
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean Init_site_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xowe_wiki wiki = core.Wiki();
KeyVal[] rv = new KeyVal[7];
Keyval[] rv = new Keyval[7];
Bld_info(rv);
rv[5] = KeyVal_.new_("name" + "spaces", Bld_ns_ary(wiki));
rv[6] = KeyVal_.new_("stats", Bld_stats(wiki));
rv[5] = Keyval_.new_("name" + "spaces", Bld_ns_ary(wiki));
rv[6] = Keyval_.new_("stats", Bld_stats(wiki));
return rslt.Init_obj(rv);
}
private void Bld_info(KeyVal[] rv) {
private void Bld_info(Keyval[] rv) {
Xow_wiki_props props = core.Wiki().Props();
rv[0] = KeyVal_.new_("siteName" , props.Site_name());
rv[1] = KeyVal_.new_("server" , props.Server());
rv[2] = KeyVal_.new_("scriptPath" , props.ScriptPath());
rv[3] = KeyVal_.new_("stylePath" , props.StylePath());
rv[4] = KeyVal_.new_("currentVersion" , props.Current_version());
rv[0] = Keyval_.new_("siteName" , props.Site_name());
rv[1] = Keyval_.new_("server" , props.Server());
rv[2] = Keyval_.new_("scriptPath" , props.ScriptPath());
rv[3] = Keyval_.new_("stylePath" , props.StylePath());
rv[4] = Keyval_.new_("currentVersion" , props.Current_version());
}
private KeyVal[] Bld_ns_ary(Xowe_wiki wiki) {
private Keyval[] Bld_ns_ary(Xowe_wiki wiki) {
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
int len = ns_mgr.Ids_len();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
int rv_idx = 0;
for (int i = 0; i < len; i++) {
Xow_ns ns = ns_mgr.Ids_get_at(i);
if (ns == null) continue;
int ns_id = ns.Id();
rv[rv_idx++] = KeyVal_.int_(ns_id, Bld_ns(wiki, ns, ns_id));
rv[rv_idx++] = Keyval_.int_(ns_id, Bld_ns(wiki, ns, ns_id));
}
return rv;
}
private KeyVal[] Bld_ns(Xowe_wiki wiki, Xow_ns ns, int ns_id) {
private Keyval[] Bld_ns(Xowe_wiki wiki, Xow_ns ns, int ns_id) {
int len = 16;
if (ns_id < Xow_ns_.Tid__main) len = 14;
else if (ns_id == Xow_ns_.Tid__main) len = 17;
KeyVal[] rv = new KeyVal[len];
rv[ 0] = KeyVal_.new_("id" , ns_id);
rv[ 1] = KeyVal_.new_("name" , ns.Name_ui());
rv[ 2] = KeyVal_.new_("canonicalName" , ns.Name_db_str()); // strtr( $canonical, "_", " " ),
rv[ 3] = KeyVal_.new_("hasSubpages" , ns.Subpages_enabled()); // MWNs::hasSubpages( $ns ),
rv[ 4] = KeyVal_.new_("hasGenderDistinction" , ns.Is_gender_aware()); // MWNs::hasGenderDistinction( $ns ),
rv[ 5] = KeyVal_.new_("isCapitalized" , ns.Is_capitalized()); // MWNs::isCapitalized( $ns ),
rv[ 6] = KeyVal_.new_("isContent" , ns.Is_content()); // MWNs::isContent( $ns ),
rv[ 7] = KeyVal_.new_("isIncludable" , ns.Is_includable()); // !MWNs::isNonincludable( $ns ),
rv[ 8] = KeyVal_.new_("isMovable" , ns.Is_movable()); // MWNs::isMovable( $ns ),
rv[ 9] = KeyVal_.new_("isSubject" , ns.Id_is_subj());
rv[10] = KeyVal_.new_("isTalk" , ns.Id_is_talk());
rv[11] = KeyVal_.new_("defaultContentModel" , null); // MWNs::getNsContentModel( $ns ), ASSUME: always null?
rv[12] = KeyVal_.new_("aliases" , ns.Aliases_as_scrib_ary()); // DATE:2014-02-15
Keyval[] rv = new Keyval[len];
rv[ 0] = Keyval_.new_("id" , ns_id);
rv[ 1] = Keyval_.new_("name" , ns.Name_ui());
rv[ 2] = Keyval_.new_("canonicalName" , ns.Name_db_str()); // strtr( $canonical, "_", " " ),
rv[ 3] = Keyval_.new_("hasSubpages" , ns.Subpages_enabled()); // MWNs::hasSubpages( $ns ),
rv[ 4] = Keyval_.new_("hasGenderDistinction" , ns.Is_gender_aware()); // MWNs::hasGenderDistinction( $ns ),
rv[ 5] = Keyval_.new_("isCapitalized" , ns.Is_capitalized()); // MWNs::isCapitalized( $ns ),
rv[ 6] = Keyval_.new_("isContent" , ns.Is_content()); // MWNs::isContent( $ns ),
rv[ 7] = Keyval_.new_("isIncludable" , ns.Is_includable()); // !MWNs::isNonincludable( $ns ),
rv[ 8] = Keyval_.new_("isMovable" , ns.Is_movable()); // MWNs::isMovable( $ns ),
rv[ 9] = Keyval_.new_("isSubject" , ns.Id_is_subj());
rv[10] = Keyval_.new_("isTalk" , ns.Id_is_talk());
rv[11] = Keyval_.new_("defaultContentModel" , null); // MWNs::getNsContentModel( $ns ), ASSUME: always null?
rv[12] = Keyval_.new_("aliases" , ns.Aliases_as_scrib_ary()); // DATE:2014-02-15
if (ns_id < 0)
rv[13] = KeyVal_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
rv[13] = Keyval_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
else {
rv[13] = KeyVal_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
rv[14] = KeyVal_.new_("talk" , ns.Id_talk_id()); // MWNs::getTalk( $ns );
rv[15] = KeyVal_.new_("associated" , ns.Id_alt_id()); // MWNs::getAssociated( $ns );
rv[13] = Keyval_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
rv[14] = Keyval_.new_("talk" , ns.Id_talk_id()); // MWNs::getTalk( $ns );
rv[15] = Keyval_.new_("associated" , ns.Id_alt_id()); // MWNs::getAssociated( $ns );
if (ns_id == Xow_ns_.Tid__main)
rv[16] = KeyVal_.new_("displayName" , wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ns_blankns)); // MWNs::getAssociated( $ns );
rv[16] = Keyval_.new_("displayName" , wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ns_blankns)); // MWNs::getAssociated( $ns );
}
return rv;
}
private KeyVal[] Bld_stats(Xowe_wiki wiki) {
Xow_wiki_stats stats = wiki.Stats();
KeyVal[] rv = new KeyVal[8];
rv[0] = KeyVal_.new_("pages", stats.NumPages()); // SiteStats::pages(),
rv[1] = KeyVal_.new_("articles", stats.NumArticles()); // SiteStats::articles(),
rv[2] = KeyVal_.new_("files", stats.NumFiles()); // SiteStats::images(),
rv[3] = KeyVal_.new_("edits", stats.NumEdits()); // SiteStats::edits(),
rv[4] = KeyVal_.new_("views", stats.NumViews()); // $wgDisableCounters ? null : (int)SiteStats::views(),
rv[5] = KeyVal_.new_("users", stats.NumUsers()); // SiteStats::users(),
rv[6] = KeyVal_.new_("activeUsers", stats.NumUsersActive());// SiteStats::activeUsers(),
rv[7] = KeyVal_.new_("admins", stats.NumAdmins()); // SiteStats::activeUsers(),
private Keyval[] Bld_stats(Xowe_wiki wiki) {
Xow_site_stats_mgr stats = wiki.Stats();
Keyval[] rv = new Keyval[8];
rv[0] = Keyval_.new_("pages" , stats.Num_pages()); // SiteStats::pages(),
rv[1] = Keyval_.new_("articles" , stats.Num_articles()); // SiteStats::articles(),
rv[2] = Keyval_.new_("files" , stats.Num_files()); // SiteStats::images(),
rv[3] = Keyval_.new_("edits" , stats.Num_edits()); // SiteStats::edits(),
rv[4] = Keyval_.new_("views" , stats.Num_views()); // $wgDisableCounters ? null : (int)SiteStats::views(),
rv[5] = Keyval_.new_("users" , stats.Num_users()); // SiteStats::users(),
rv[6] = Keyval_.new_("activeUsers" , stats.Num_active()); // SiteStats::activeUsers(),
rv[7] = Keyval_.new_("admins" , stats.Num_admins()); // SiteStats::activeUsers(),
return rv;
}
}

View File

@@ -16,30 +16,45 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import org.junit.*; import gplx.xowa.wikis.nss.*;
import org.junit.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
public class Scrib_lib_site_tst {
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
@Before public void init() {
fxt.Clear_for_lib();
fxt.Clear();
lib = fxt.Core().Lib_site().Init();
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
@Test public void GetNsIndex() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Help"), 12);
}
@Test public void GetNsIndex_invalid() {
fxt.Test_scrib_proc_empty(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Helpx")); // unknown ns; return empty String
@Test public void GetNsIndex__valid() {
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Help"), 12);
}
@Test public void GetNsIndex__invalid() {
fxt.Test__proc__objs__empty(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Helpx")); // unknown ns; return empty String
}
@Test public void UsersInGroup() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_usersInGroup, Object_.Ary("sysop"), 0); // SELECT * FROM user_groups;
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_usersInGroup, Object_.Ary("sysop"), 0); // SELECT * FROM user_groups;
}
@Test public void PagesInCategory() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A"), 0);
@Test public void PagesInCategory__invalid() {
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A|"), 0);
}
@Test public void PagesInCategory__exists() {
gplx.xowa.addons.ctgs.Xoax_ctg_addon.Get(fxt.Core().Wiki()).Itms__add(Bry_.new_a7("A"), 3, 2, 1);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "pages") , 3);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "subcats") , 2);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "files") , 1);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "all") , 6);
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "*") , String_.Concat_lines_nl_skip_last
( "1="
, " all=6"
, " pages=3"
, " subcats=2"
, " files=1"
));
}
@Test public void PagesInNs() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
}
@Test public void Init_lib_site() {
Xowe_wiki wiki = fxt.Parser_fxt().Wiki();
fxt.Parser_fxt().Wiki().Stats().NumPages_(1).NumArticles_(2).NumFiles_(3).NumEdits_(4).NumViews_(5).NumUsers_(6).NumUsersActive_(7).NumAdmins_(8);
Xowe_wiki wiki = fxt.Core().Wiki();
wiki.Stats().Load_by_db(1, 2, 3, 4, 5, 6, 7, 8);
wiki.Ns_mgr()
.Clear()
.Add_new(Xow_ns_.Tid__module , Xow_ns_.Key__module)
@@ -49,7 +64,7 @@ public class Scrib_lib_site_tst {
.Add_new(Xow_ns_.Tid__talk , Xow_ns_.Key__talk)
.Init_w_defaults()
;
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl_skip_last
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl_skip_last
( "1="
, " siteName=Wikipedia"
, " server=http://en.wikipedia.org"

View File

@@ -53,31 +53,13 @@ public class Scrib_lib_text implements Scrib_lib {
public boolean GetEntityTable(Scrib_proc_args args, Scrib_proc_rslt rslt) {
if (Gfh_entity_ == null) Gfh_entity_ = Scrib_lib_text_html_entities.new_();
return rslt.Init_obj(Gfh_entity_);
} private static KeyVal[] Gfh_entity_;
// public boolean JsonEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
// Object itm = args.Pull_obj(0);
// Class<?> itm_type = itm.getClass();
// KeyVal[] itm_as_kvy = null;
// Object itm_as_ary = null;
// if (Type_adp_.Eq(itm_type, typeof(KeyVal[]))) itm_as_kvy = (KeyVal[])itm;
// else if (Type_adp_.Is_array(itm_type)) itm_as_ary = Array_.cast(itm);
// int flags = args.Cast_int_or(1, 0);
// if (itm_as_kvy != null && !Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))
// itm_as_kvy = json_util.Reindex_arrays(itm_as_kvy, true);
// byte[] rv = null;
// if (itm_as_kvy != null)
// rv = json_util.Encode_as_nde(itm_as_kvy, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
// else if (itm_as_ary != null)
// rv = json_util.Encode_as_ary(itm_as_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);;
// if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
// return rslt.Init_obj(rv);
// }
} private static Keyval[] Gfh_entity_;
public boolean JsonEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Object itm = args.Pull_obj(0);
Class<?> itm_type = itm.getClass();
KeyVal[] itm_as_kvy = null;
Keyval[] itm_as_kvy = null;
Object itm_as_ary = null;
if (Type_adp_.Eq(itm_type, KeyVal[].class)) itm_as_kvy = (KeyVal[])itm;
if (Type_adp_.Eq(itm_type, Keyval[].class)) itm_as_kvy = (Keyval[])itm;
else if (Type_adp_.Is_array(itm_type)) itm_as_ary = Array_.cast(itm);
int flags = args.Cast_int_or(1, 0);
synchronized (reindex_data) {
@@ -114,7 +96,7 @@ public class Scrib_lib_text implements Scrib_lib {
byte rv_tid = json_util.Decode(core.App().Utl__json_parser(), json, opts);
if (rv_tid == Bool_.__byte) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to decode String " + String_.new_u8(json));
if (rv_tid == Bool_.Y_byte && !(Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))) {
KeyVal[] rv_as_kvy = (KeyVal[])json_util.Decode_rslt_as_nde();
Keyval[] rv_as_kvy = (Keyval[])json_util.Decode_rslt_as_nde();
synchronized (reindex_data) {
json_util.Reindex_arrays(reindex_data, rv_as_kvy, false);
return rslt.Init_obj(reindex_data.Rv_is_kvy() ? reindex_data.Rv_as_kvy() : reindex_data.Rv_as_ary());
@@ -124,14 +106,14 @@ public class Scrib_lib_text implements Scrib_lib {
return rslt.Init_obj(json_util.Decode_rslt_as_ary());
}
}
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), KeyVal_.Ary_empty);}
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean Init_text_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xow_msg_mgr msg_mgr = core.Wiki().Msg_mgr();
KeyVal[] rv = new KeyVal[4];
rv[0] = KeyVal_.new_("comma", Init_lib_text_get_msg(msg_mgr, "comma-separator"));
rv[1] = KeyVal_.new_("and", Init_lib_text_get_msg(msg_mgr, "and") + Init_lib_text_get_msg(msg_mgr, "word-separator"));
rv[2] = KeyVal_.new_("ellipsis", Init_lib_text_get_msg(msg_mgr, "ellipsis"));
rv[3] = KeyVal_.new_("nowiki_protocols", KeyVal_.Ary_empty); // NOTE: code implemented, but waiting for it to be used; DATE:2014-03-20
Keyval[] rv = new Keyval[4];
rv[0] = Keyval_.new_("comma", Init_lib_text_get_msg(msg_mgr, "comma-separator"));
rv[1] = Keyval_.new_("and", Init_lib_text_get_msg(msg_mgr, "and") + Init_lib_text_get_msg(msg_mgr, "word-separator"));
rv[2] = Keyval_.new_("ellipsis", Init_lib_text_get_msg(msg_mgr, "ellipsis"));
rv[3] = Keyval_.new_("nowiki_protocols", Keyval_.Ary_empty); // NOTE: code implemented, but waiting for it to be used; DATE:2014-03-20
return rslt.Init_obj(rv);
}
private String Init_lib_text_get_msg(Xow_msg_mgr msg_mgr, String msg_key) {

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.core.net.*;
class Scrib_lib_text_ {
public static KeyVal[] Init_nowiki_protocols(Xowe_wiki wiki) {
public static Keyval[] Init_nowiki_protocols(Xowe_wiki wiki) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
Ordered_hash protocols = Gfo_protocol_itm.Regy;
int len = protocols.Count();
@@ -26,14 +26,14 @@ class Scrib_lib_text_ {
for (int i = 0; i < len; i++) {
Gfo_protocol_itm itm = (Gfo_protocol_itm)protocols.Get_at(i);
if (itm.Text_ends_w_colon()) { // To convert the protocol into a case-insensitive Lua pattern, we need to replace letters with a character class like [Xx] and insert a '%' before various punctuation.
KeyVal kv = Init_nowiki_protocols_itm(bfr, itm);
Keyval kv = Init_nowiki_protocols_itm(bfr, itm);
rv.Add(kv);
}
}
bfr.Mkr_rls();
return (KeyVal[])rv.To_ary(KeyVal.class);
return (Keyval[])rv.To_ary(Keyval.class);
}
private static KeyVal Init_nowiki_protocols_itm(Bry_bfr bfr, Gfo_protocol_itm itm) {
private static Keyval Init_nowiki_protocols_itm(Bry_bfr bfr, Gfo_protocol_itm itm) {
byte[] key = itm.Key_wo_colon_bry();
int end = key.length - 1; // -1 to ignore final colon
for (int i = 0; i < end; i++) {
@@ -62,6 +62,6 @@ class Scrib_lib_text_ {
}
}
bfr.Add(Colon_encoded);
return KeyVal_.new_(itm.Key_wo_colon_str(), bfr.To_str_and_clear());
return Keyval_.new_(itm.Key_wo_colon_str(), bfr.To_str_and_clear());
} private static final byte[] Colon_encoded = Bry_.new_a7("&#58;");
}

View File

@@ -19,7 +19,7 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
import gplx.langs.jsons.*;
class Scrib_lib_text__json_util {
private final Json_wtr wtr = new Json_wtr();
public void Reindex_arrays(Scrib_lib_text__reindex_data rv, KeyVal[] kv_ary, boolean is_encoding) {
public void Reindex_arrays(Scrib_lib_text__reindex_data rv, Keyval[] kv_ary, boolean is_encoding) {
int next = 0;
if (is_encoding) {
Array_.Sort(kv_ary, KeyVal__sorter__key_is_numeric.Instance);
@@ -28,10 +28,10 @@ class Scrib_lib_text__json_util {
boolean is_sequence = true;
int len = kv_ary.length;
for (int i = 0; i < len; ++i) {
KeyVal kv = kv_ary[i];
Keyval kv = kv_ary[i];
Object kv_val = kv.Val();
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), KeyVal[].class)) {
Reindex_arrays(rv, (KeyVal[])kv_val, is_encoding);
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), Keyval[].class)) {
Reindex_arrays(rv, (Keyval[])kv_val, is_encoding);
if (!rv.Rv_is_kvy())
kv.Val_(rv.Rv_as_ary());
}
@@ -62,23 +62,23 @@ class Scrib_lib_text__json_util {
}
rv.Init(Bool_.Y, kv_ary, null);
}
private static Object[] To_array_values(KeyVal[] ary) {
private static Object[] To_array_values(Keyval[] ary) {
int len = ary.length;
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i) {
KeyVal itm = ary[i];
Keyval itm = ary[i];
rv[i] = itm.Val();
}
return rv;
}
private static void Convert_to_base1(KeyVal[] ary) {
private static void Convert_to_base1(Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
KeyVal itm = ary[i];
Keyval itm = ary[i];
itm.Key_(i + 1);
}
}
public KeyVal[] Decode_rslt_as_nde() {return decode_rslt_as_nde;} private KeyVal[] decode_rslt_as_nde;
public Keyval[] Decode_rslt_as_nde() {return decode_rslt_as_nde;} private Keyval[] decode_rslt_as_nde;
public Object Decode_rslt_as_ary() {return decode_rslt_as_ary;} private Object decode_rslt_as_ary;
public byte Decode(Json_parser parser, byte[] src, int flag) {
synchronized (wtr) {
@@ -90,13 +90,13 @@ class Scrib_lib_text__json_util {
else {
Json_nde root = (Json_nde)jdoc.Root_grp();
int len = root.Len();
this.decode_rslt_as_nde = new KeyVal[len];
this.decode_rslt_as_nde = new Keyval[len];
for (int i = 0; i < len; ++i) {
Json_kv json_kv = root.Get_at_as_kv(i);
String kv_str = json_kv.Key_as_str();
Object kv_val = Decode_obj(json_kv.Val());
int kv_int = Int_.parse_or(kv_str, Int_.Min_value);
decode_rslt_as_nde[i] = kv_int == Int_.Min_value ? KeyVal_.new_(kv_str, kv_val) : KeyVal_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
decode_rslt_as_nde[i] = kv_int == Int_.Min_value ? Keyval_.new_(kv_str, kv_val) : Keyval_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
}
return Bool_.Y_byte;
}
@@ -119,19 +119,19 @@ class Scrib_lib_text__json_util {
}
return rv;
}
private KeyVal[] Decode_nde(Json_nde nde) {
private Keyval[] Decode_nde(Json_nde nde) {
int len = nde.Len();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; ++i) {
Json_kv itm = nde.Get_at_as_kv(i);
String kv_str = itm.Key_as_str();
int kv_int = Int_.parse_or(kv_str, Int_.Min_value);
Object kv_val = Decode_obj(itm.Val());
rv[i] = kv_int == Int_.Min_value ? KeyVal_.new_(kv_str, kv_val) : KeyVal_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
rv[i] = kv_int == Int_.Min_value ? Keyval_.new_(kv_str, kv_val) : Keyval_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
}
return rv;
}
public byte[] Encode_as_nde(KeyVal[] itm, int flag, int skip) {
public byte[] Encode_as_nde(Keyval[] itm, int flag, int skip) {
synchronized (wtr ) {
wtr.Clear().Doc_nde_bgn();
Encode_kv_ary(itm);
@@ -145,19 +145,19 @@ class Scrib_lib_text__json_util {
return wtr.Doc_ary_end().To_bry_and_clear();
}
}
private void Encode_kv_ary(KeyVal[] kv_ary) {
private void Encode_kv_ary(Keyval[] kv_ary) {
int len = kv_ary.length;
for (int i = 0; i < len; ++i) {
KeyVal kv = kv_ary[i];
Keyval kv = kv_ary[i];
Encode_kv(kv);
}
}
private void Encode_kv(KeyVal kv) {
private void Encode_kv(Keyval kv) {
Object kv_val = kv.Val();
Class<?> type = Type_adp_.ClassOf_obj(kv_val);
if (Type_adp_.Eq(type, KeyVal[].class)) {
if (Type_adp_.Eq(type, Keyval[].class)) {
wtr.Nde_bgn(kv.Key());
Encode_kv_ary((KeyVal[])kv_val);
Encode_kv_ary((Keyval[])kv_val);
wtr.Nde_end();
}
else if (Type_adp_.Is_array(type)) { // encode as array
@@ -194,8 +194,8 @@ class Scrib_lib_text__json_util {
}
class KeyVal__sorter__key_is_numeric implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
KeyVal lhs_itm = (KeyVal)lhsObj;
KeyVal rhs_itm = (KeyVal)rhsObj;
Keyval lhs_itm = (Keyval)lhsObj;
Keyval rhs_itm = (Keyval)rhsObj;
int lhs_int = Int_.parse_or(lhs_itm.Key(), Int_.Min_value);
int rhs_int = Int_.parse_or(rhs_itm.Key(), Int_.Min_value);
return CompareAble_.Compare(lhs_int, rhs_int);
@@ -204,9 +204,9 @@ class KeyVal__sorter__key_is_numeric implements gplx.core.lists.ComparerAble {
}
class Scrib_lib_text__reindex_data {
public boolean Rv_is_kvy() {return rv_is_kvy;} private boolean rv_is_kvy;
public KeyVal[] Rv_as_kvy() {return rv_as_kvy;} private KeyVal[] rv_as_kvy;
public Keyval[] Rv_as_kvy() {return rv_as_kvy;} private Keyval[] rv_as_kvy;
public Object Rv_as_ary() {return rv_as_ary;} private Object rv_as_ary;
public void Init(boolean rv_is_kvy, KeyVal[] rv_as_kvy, Object rv_as_ary) {
public void Init(boolean rv_is_kvy, Keyval[] rv_as_kvy, Object rv_as_ary) {
this.rv_is_kvy = rv_is_kvy;
this.rv_as_kvy = rv_as_kvy;
this.rv_as_ary = rv_as_ary;

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.core.primitives.*;
class Scrib_lib_text_html_entities {
public static KeyVal[] new_() {
KeyVal[] rv = new KeyVal[1510];
public static Keyval[] new_() {
Keyval[] rv = new Keyval[1510];
Int_obj_ref idx = Int_obj_ref.zero_();
new_itm_(rv, idx, Bry_.New_by_ints(9), "&Tab;");
new_itm_(rv, idx, Bry_.New_by_ints(10), "&NewLine;");
@@ -1533,7 +1533,7 @@ new_itm_(rv, idx, Bry_.New_by_ints(240, 157, 149, 170), "&yopf;");
new_itm_(rv, idx, Bry_.New_by_ints(240, 157, 149, 171), "&zopf;");
return rv;
}
private static void new_itm_(KeyVal[] ary, Int_obj_ref idx, byte[] key, String val) {
ary[idx.Val_add_post()] = KeyVal_.new_(String_.new_u8(key), val);
private static void new_itm_(Keyval[] ary, Int_obj_ref idx, byte[] key, String val) {
ary[idx.Val_add_post()] = Keyval_.new_(String_.new_u8(key), val);
}
}

View File

@@ -31,7 +31,7 @@ public class Scrib_lib_text_json_tst {
( "{"
, "}"
)
, KeyVal_.Ary_empty
, Keyval_.Ary_empty
);
}
@Test public void Nde__key_obj__primitives() { // NOTE: based on MW
@@ -50,12 +50,12 @@ public class Scrib_lib_text_json_tst {
, " }"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("int", 1)
, KeyVal_.new_("String", "abc")
, KeyVal_.new_("true", true)
, KeyVal_.new_("array", new int[] {1, 2, 3})
, KeyVal_.new_("node", KeyVal_.Ary(KeyVal_.new_("key", "val")))
, Keyval_.Ary
( Keyval_.new_("int", 1)
, Keyval_.new_("String", "abc")
, Keyval_.new_("true", true)
, Keyval_.new_("array", new int[] {1, 2, 3})
, Keyval_.new_("node", Keyval_.Ary(Keyval_.new_("key", "val")))
));
}
@Test public void Nde__obj_in_obj() {
@@ -69,10 +69,10 @@ public class Scrib_lib_text_json_tst {
, " ]"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x", new Object[]
{ 1, 2, KeyVal_.Ary
( KeyVal_.new_("y", "x")
, Keyval_.Ary
( Keyval_.new_("x", new Object[]
{ 1, 2, Keyval_.Ary
( Keyval_.new_("y", "x")
)
}
)
@@ -93,10 +93,10 @@ public class Scrib_lib_text_json_tst {
, " ]"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x"
, new Object[] {1, 2, KeyVal_.Ary
( KeyVal_.new_("y"
, Keyval_.Ary
( Keyval_.new_("x"
, new Object[] {1, 2, Keyval_.Ary
( Keyval_.new_("y"
, new Object[] {3, 4}
))}))
);
@@ -109,10 +109,10 @@ public class Scrib_lib_text_json_tst {
, ", '2':2"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x", "x")
, KeyVal_.new_("1", 1)
, KeyVal_.new_("2", 2)
, Keyval_.Ary
( Keyval_.new_("x", "x")
, Keyval_.new_("1", 1)
, Keyval_.new_("2", 2)
));
}
@Test public void Nde__key_int__auto() {// NOTE: based on MW
@@ -193,13 +193,13 @@ public class Scrib_lib_text_json_tst {
@Test public void Nde__smoke() {
json_fxt.Test_json_encode(fxt, lib
, Scrib_lib_text__json_util.Flag__none
, KeyVal_.Ary
( KeyVal_.new_("axes", KeyVal_.Ary
( KeyVal_.int_(1, KeyVal_.Ary
( KeyVal_.new_("type", "x")
, Keyval_.Ary
( Keyval_.new_("axes", Keyval_.Ary
( Keyval_.int_(1, Keyval_.Ary
( Keyval_.new_("type", "x")
))
, KeyVal_.int_(2, KeyVal_.Ary
( KeyVal_.new_("type", "y")
, Keyval_.int_(2, Keyval_.Ary
( Keyval_.new_("type", "y")
))
))
)
@@ -216,7 +216,7 @@ public class Scrib_lib_text_json_tst {
);
}
@Test public void Decode__key__int() {
KeyVal[] kv_ary = (KeyVal[])json_fxt.Test_json_decode(fxt, lib
Keyval[] kv_ary = (Keyval[])json_fxt.Test_json_decode(fxt, lib
, Scrib_lib_text__json_util.Flag__none
, Json_doc.Make_str_by_apos
( "{ '1':"
@@ -225,15 +225,15 @@ public class Scrib_lib_text_json_tst {
, ", '2':'b'"
, "}"
)
, KeyVal_.Ary
( KeyVal_.int_(1, KeyVal_.Ary
( KeyVal_.int_(11, "aa")
, Keyval_.Ary
( Keyval_.int_(1, Keyval_.Ary
( Keyval_.int_(11, "aa")
))
, KeyVal_.int_(2, "b")
, Keyval_.int_(2, "b")
)
);
Tfds.Eq(kv_ary[0].Key_as_obj(), 1);
Tfds.Eq(((KeyVal[])kv_ary[0].Val())[0].Key_as_obj(), 11);
Tfds.Eq(((Keyval[])kv_ary[0].Val())[0].Key_as_obj(), 11);
}
}
class Scrib_lib_json_fxt {
@@ -253,7 +253,7 @@ class Scrib_lib_json_fxt {
private String To_str(Object o) {
if (o == null) return "<< NULL >>";
Class<?> type = o.getClass();
if (Type_adp_.Eq(type, KeyVal[].class)) return Kv_ary_utl.Ary_to_str(wtr, (KeyVal[])o);
if (Type_adp_.Eq(type, Keyval[].class)) return Kv_ary_utl.Ary_to_str(wtr, (Keyval[])o);
else if (Type_adp_.Is_array(type)) return Array_.To_str_nested_obj(o);
else return Object_.Xto_str_strict_or_null(o);
}

View File

@@ -28,7 +28,7 @@ public class Scrib_lib_text_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_text.Invk_unstrip, Object_.Ary("a"), "a");
}
@Test public void GetEntityTable() {
KeyVal[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
Keyval[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
Tfds.Eq(1510, actl.length); // large result; only test # of entries
}
}

View File

@@ -28,8 +28,8 @@ public class Scrib_lib_title implements Scrib_lib {
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
Init();
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.title.lua")
, KeyVal_.new_("thisTitle", "") // NOTE: pass blank; will be updated by GetCurrentTitle
, KeyVal_.new_("NS_MEDIA", Xow_ns_.Tid__media) // NOTE: MW passes down NS_MEDIA; this should be -2 on all wikis...
, Keyval_.new_("thisTitle", "") // NOTE: pass blank; will be updated by GetCurrentTitle
, Keyval_.new_("NS_MEDIA", Xow_ns_.Tid__media) // NOTE: MW passes down NS_MEDIA; this should be -2 on all wikis...
);
notify_page_changed_fnc = mod.Fncs_get_by_key("notify_page_changed");
return mod;
@@ -73,7 +73,7 @@ public class Scrib_lib_title implements Scrib_lib {
if (ttl == null) return rslt.Init_obj(null); // invalid title; exit; matches MW logic
return rslt.Init_obj(GetInexpensiveTitleData(ttl));
}
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 GetUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xowe_wiki wiki = core.Wiki();
byte[] ttl_bry = args.Pull_bry(0);
@@ -141,11 +141,11 @@ public class Scrib_lib_title implements Scrib_lib {
ttl_redirect = tmp_db_page.Redirected();
ttl_id = tmp_db_page.Id();
}
KeyVal[] rv = new KeyVal[4];
rv[ 0] = KeyVal_.new_("isRedirect" , ttl_redirect); // title.isRedirect
rv[ 1] = KeyVal_.new_("id" , ttl_id); // $title->getArticleID(),
rv[ 2] = KeyVal_.new_("contentModel" , Key_wikitexet); // $title->getContentModel(); see Defines.php and CONTENT_MODEL_
rv[ 3] = KeyVal_.new_("exists" , ttl_exists); // $ret['id'] > 0; TODO: if Special: check regy of implemented pages
Keyval[] rv = new Keyval[4];
rv[ 0] = Keyval_.new_("isRedirect" , ttl_redirect); // title.isRedirect
rv[ 1] = Keyval_.new_("id" , ttl_id); // $title->getArticleID(),
rv[ 2] = Keyval_.new_("contentModel" , Key_wikitexet); // $title->getContentModel(); see Defines.php and CONTENT_MODEL_
rv[ 3] = Keyval_.new_("exists" , ttl_exists); // $ret['id'] > 0; TODO: if Special: check regy of implemented pages
return rslt.Init_obj(rv);
}
public boolean GetFileInfo(Scrib_proc_args args, Scrib_proc_rslt rslt) {
@@ -158,20 +158,20 @@ public class Scrib_lib_title implements Scrib_lib {
if (ttl.Ns().Id_is_media()) ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__file, ttl.Page_db()); // if [[Media:]] change to [[File:]]; theoretically, this should be changed in Get_page, but not sure if I want to put this logic that low; DATE:2014-01-07
// Xoae_page file_page = Pfunc_filepath.Load_page(wiki, ttl); // EXPENSIVE
// boolean exists = !file_page.Missing();
// if (!exists) return rslt.Init_obj(KeyVal_.Ary(KeyVal_.new_("exists", false))); // NOTE: do not reinstate; will exit early if commons is not installed; DATE:2015-01-25; NOTE: Media objects are often flagged as absent in offline mode
// if (!exists) return rslt.Init_obj(Keyval_.Ary(Keyval_.new_("exists", false))); // NOTE: do not reinstate; will exit early if commons is not installed; DATE:2015-01-25; NOTE: Media objects are often flagged as absent in offline mode
// NOTE: MW registers image if deleted; XOWA doesn't register b/c needs width / height also, not just image name
wiki.File_mgr().Init_file_mgr_by_load(wiki);
Xof_orig_itm itm = wiki.File__orig_mgr().Find_by_ttl_or_null(ttl.Page_db());
if (itm == Xof_orig_itm.Null) return rslt.Init_obj(GetFileInfo_absent);
KeyVal[] rv = KeyVal_.Ary
( KeyVal_.new_("exists" , true)
, KeyVal_.new_("width" , itm.W())
, KeyVal_.new_("height" , itm.H())
, KeyVal_.new_("pages" , null) // TODO: get pages info
Keyval[] rv = Keyval_.Ary
( Keyval_.new_("exists" , true)
, Keyval_.new_("width" , itm.W())
, Keyval_.new_("height" , itm.H())
, Keyval_.new_("pages" , null) // TODO: get pages info
);
return rslt.Init_obj(rv);
}
private static final KeyVal[] GetFileInfo_absent = KeyVal_.Ary(KeyVal_.new_("exists", false));
private static final Keyval[] GetFileInfo_absent = Keyval_.Ary(Keyval_.new_("exists", false));
public boolean GetContent(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte[] ttl_bry = args.Pull_bry(0);
Xowe_wiki wiki = core.Wiki();
@@ -204,8 +204,8 @@ public class Scrib_lib_title implements Scrib_lib {
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
return rslt.Init_obj(CascadingProtection_rv);
}
public static final KeyVal[] CascadingProtection_rv = KeyVal_.Ary(KeyVal_.new_("sources", Bool_.N), KeyVal_.new_("restrictions", KeyVal_.Ary_empty));
private KeyVal[] GetInexpensiveTitleData(Xoa_ttl ttl) {
public static final Keyval[] CascadingProtection_rv = Keyval_.Ary(Keyval_.new_("sources", Bool_.N), Keyval_.new_("restrictions", Keyval_.Ary_empty));
private Keyval[] GetInexpensiveTitleData(Xoa_ttl ttl) {
Xow_ns ns = ttl.Ns();
boolean ns_file_or_media = ns.Id_is_file_or_media(), ns_special = ns.Id_is_special();
int rv_len = 7, rv_idx = 7;
@@ -213,18 +213,18 @@ public class Scrib_lib_title implements Scrib_lib {
if (!ns_file_or_media) ++rv_len;
Xow_xwiki_itm xwiki_itm = ttl.Wik_itm();
String xwiki_str = xwiki_itm == null ? "" : xwiki_itm.Key_str();
KeyVal[] rv = new KeyVal[rv_len];
rv[ 0] = KeyVal_.new_("isLocal" , true); // title.isLocal; NOTE: always true; passing "http:" also returns true; not sure how to handle "Interwiki::fetch( $this->mInterwiki )->isLocal()"
rv[ 1] = KeyVal_.new_("interwiki" , xwiki_str); // $title->getInterwiki(),
rv[ 2] = KeyVal_.new_("namespace" , ns.Id()); // $ns,
rv[ 3] = KeyVal_.new_("nsText" , Xow_ns_canonical_.To_canonical_or_local_as_str(ns)); // $title->getNsText(), NOTE: needed b/c some modules expect English "Template"; PAGE:sh.w:Koprno DATE:2015-11-08
rv[ 4] = KeyVal_.new_("text" , ttl.Page_txt()); // $title->getText(),
rv[ 5] = KeyVal_.new_("fragment" , ttl.Anch_txt()); // $title->getFragment(),
rv[ 6] = KeyVal_.new_("thePartialUrl" , ttl.Page_db()); // $title->getPartialUrl(),
Keyval[] rv = new Keyval[rv_len];
rv[ 0] = Keyval_.new_("isLocal" , true); // title.isLocal; NOTE: always true; passing "http:" also returns true; not sure how to handle "Interwiki::fetch( $this->mInterwiki )->isLocal()"
rv[ 1] = Keyval_.new_("interwiki" , xwiki_str); // $title->getInterwiki(),
rv[ 2] = Keyval_.new_("namespace" , ns.Id()); // $ns,
rv[ 3] = Keyval_.new_("nsText" , Xow_ns_canonical_.To_canonical_or_local_as_str(ns)); // $title->getNsText(), NOTE: needed b/c some modules expect English "Template"; PAGE:sh.w:Koprno DATE:2015-11-08
rv[ 4] = Keyval_.new_("text" , ttl.Page_txt()); // $title->getText(),
rv[ 5] = Keyval_.new_("fragment" , ttl.Anch_txt()); // $title->getFragment(),
rv[ 6] = Keyval_.new_("thePartialUrl" , ttl.Page_db()); // $title->getPartialUrl(),
if (ns_special)
rv[rv_idx++] = KeyVal_.new_("exists" , false); // TODO: lookup specials
rv[rv_idx++] = Keyval_.new_("exists" , false); // TODO: lookup specials
if (!ns_file_or_media)
rv[rv_idx++] = KeyVal_.new_("file" , false); // REF.MW: if ( $ns !== NS_FILE && $ns !== NS_MEDIA ) $ret['file'] = false;
rv[rv_idx++] = Keyval_.new_("file" , false); // REF.MW: if ( $ns !== NS_FILE && $ns !== NS_MEDIA ) $ret['file'] = false;
return rv;
} private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
public static final String Key_wikitexet = "wikitext";

View File

@@ -44,7 +44,7 @@ public class Scrib_lib_title_tst {
// fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "", "http") , "http://en.wikipedia.org/wiki/Main_Page"); // TODO
}
@Test public void GetUrl__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; fr.w:Wikip<69>dia:Image_du_jour/Date; DATE:2013-12-24
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", KeyVal_.Ary(KeyVal_.new_("action", "edit"), KeyVal_.new_("preload", "b"))), "http://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", Keyval_.Ary(Keyval_.new_("action", "edit"), Keyval_.new_("preload", "b"))), "http://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
}
@Test public void MakeTitle() {
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Module", "A") , ttl_fast(828, "Module", "A"));
@@ -110,14 +110,6 @@ public class Scrib_lib_title_tst {
byte[] ttl_bry = Bry_.new_u8(ttl_str);
wiki.File__orig_mgr().Insert(Xof_repo_itm_.Repo_remote, ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty);
}
// private static void Init_page_regy(Xowe_wiki wiki, String ttl, int id, boolean is_redirect) {
// String url_str = "test/en.wikipedia.org/wiki_page_regy";
// Dbmeta_tbl_itm meta = new Xowd_page_tbl().new_meta();
// Db_conn_pool.Instance.Set_mem(url_str, meta);
// Db_conn_info url = Db_conn_info_.mem_(url_str);
// Xowd_page_tbl tbl = new Xowd_page_tbl(Bool_.N, url);
// tbl.Insert(id, ns_id, Bry_.new_u8(ttl), is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id);
// }
private static String ttl_fast(int ns_id, String ns_str, String ttl) {return ttl_fast(ns_id, ns_str, ttl, "", "", ttl);}
private static String ttl_fast(int ns_id, String ns_str, String ttl, String anchor) {return ttl_fast(ns_id, ns_str, ttl, anchor, "", ttl);}
private static String ttl_fast(int ns_id, String ns_str, String ttl, String anchor, String xwiki) {return ttl_fast(ns_id, ns_str, ttl, anchor, xwiki, ttl);}

View File

@@ -29,7 +29,7 @@ public class Scrib_lib_uri implements Scrib_lib {
notify_page_changed_fnc = mod.Fncs_get_by_key("notify_page_changed");
return mod;
} private Scrib_lua_proc notify_page_changed_fnc;
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 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) {
switch (key) {

View File

@@ -31,7 +31,7 @@ public class Scrib_lib_uri_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("[bad]" ), Scrib_invoke_func_fxt.Null_rslt); // handle invalid titles; EX:it.w:Billy_the_Kid; DATE:2014-01-20
}
@Test public void Url__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; it.w:Astronomie; DATE:2014-01-18
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", KeyVal_.Ary(KeyVal_.new_("action", "edit"))), "//en.wikipedia.org/wiki/A?action=edit");
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", Keyval_.Ary(Keyval_.new_("action", "edit"))), "//en.wikipedia.org/wiki/A?action=edit");
}
@Test public void AnchorEncode() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_anchorEncode , Object_.Ary("[irc://a b c]" ), "b_c");

View File

@@ -29,8 +29,8 @@ public class Scrib_lib_ustring implements Scrib_lib {
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
Init();
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.ustring.lua")
, KeyVal_.new_("stringLengthLimit", string_len_max)
, KeyVal_.new_("patternLengthLimit", pattern_len_max)
, Keyval_.new_("stringLengthLimit", string_len_max)
, Keyval_.new_("patternLengthLimit", pattern_len_max)
);
return mod;
}
@@ -145,18 +145,18 @@ public class Scrib_lib_ustring implements Scrib_lib {
public boolean Gmatch_callback(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String text = args.Xstr_str_or_null(0); // NOTE: UstringLibrary.php!ustringGmatchCallback calls preg_match directly; $s can be any type, and php casts automatically;
String regx = args.Pull_str(1);
KeyVal[] capt = args.Cast_kv_ary_or_null(2);
Keyval[] capt = args.Cast_kv_ary_or_null(2);
int pos = args.Pull_int(3);
Regx_adp regx_adp = Scrib_lib_ustring.RegxAdp_new_(core.Ctx(), regx);
Regx_match[] regx_rslts = regx_adp.Match_all(text, pos);
int len = regx_rslts.length;
if (len == 0) return rslt.Init_many_objs(pos, KeyVal_.Ary_empty);
if (len == 0) return rslt.Init_many_objs(pos, Keyval_.Ary_empty);
Regx_match match = regx_rslts[0]; // NOTE: take only 1st result
List_adp tmp_list = List_adp_.new_();
AddCapturesFromMatch(tmp_list, match, text, capt, true); // NOTE: was incorrectly set as false; DATE:2014-04-23
return rslt.Init_many_objs(match.Find_end(), Scrib_kv_utl_.base1_list_(tmp_list));
}
private void AddCapturesFromMatch(List_adp tmp_list, Regx_match rslt, String text, KeyVal[] capts, boolean op_is_match) {// NOTE: this matches behavior in UstringLibrary.php!addCapturesFromMatch
private void AddCapturesFromMatch(List_adp tmp_list, Regx_match rslt, String text, Keyval[] capts, boolean op_is_match) {// NOTE: this matches behavior in UstringLibrary.php!addCapturesFromMatch
Regx_group[] grps = rslt.Groups();
int grps_len = grps.length;
int capts_len = capts == null ? 0 : capts.length;
@@ -215,16 +215,16 @@ class Scrib_lib_ustring_gsub_mgr {
tmp_repl_tid = Repl_tid_string;
tmp_repl_bry = Bry_.new_u8(Int_.To_str(Int_.cast(repl_obj)));
}
else if (Object_.Eq(repl_type, KeyVal[].class)) {
else if (Object_.Eq(repl_type, Keyval[].class)) {
tmp_repl_tid = Repl_tid_table;
KeyVal[] repl_tbl = (KeyVal[])repl_obj;
Keyval[] repl_tbl = (Keyval[])repl_obj;
if (repl_hash == null)
repl_hash = Hash_adp_.new_();
else
repl_hash.Clear();
int repl_tbl_len = repl_tbl.length;
for (int i = 0; i < repl_tbl_len; i++) {
KeyVal repl_itm = repl_tbl[i];
Keyval repl_itm = repl_tbl[i];
String repl_itm_val = repl_itm.Val_to_str_or_empty();
repl_hash.Add(repl_itm.Key(), Bry_.new_u8(repl_itm_val));
}
@@ -326,7 +326,7 @@ class Scrib_lib_ustring_gsub_mgr {
break;
}
case Repl_tid_luacbk: {
KeyVal[] luacbk_args = null;
Keyval[] luacbk_args = null;
Regx_group[] grps = match.Groups();
int grps_len = grps.length;
if (grps_len == 0) { // no match; use original String
@@ -334,14 +334,14 @@ class Scrib_lib_ustring_gsub_mgr {
luacbk_args = Scrib_kv_utl_.base1_obj_(find_str);
}
else { // match; build ary of matches; (see UStringLibrary.php)
luacbk_args = new KeyVal[grps_len];
luacbk_args = new Keyval[grps_len];
for (int i = 0; i < grps_len; i++) {
Regx_group grp = grps[i];
String find_str = String_.Mid(text, grp.Bgn(), grp.End());
luacbk_args[i] = KeyVal_.int_(i + Scrib_core.Base_1, find_str);
luacbk_args[i] = Keyval_.int_(i + Scrib_core.Base_1, find_str);
}
}
KeyVal[] rslts = core.Interpreter().CallFunction(repl_func.Id(), luacbk_args);
Keyval[] rslts = core.Interpreter().CallFunction(repl_func.Id(), luacbk_args);
tmp_bfr.Add_str_u8(Scrib_kv_utl_.Val_to_str(rslts, 0));
break;
}

View File

@@ -33,7 +33,7 @@ public class Scrib_lib_ustring__gmatch__tst {
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 8) , "1=8\n2=");
}
@Test public void Callback__nomatch() {// PURPOSE.fix: was originally returning "" instead of original String; EX:vi.d:trở_thành; DATE:2014-04-23
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a", "a" , KeyVal_.Ary_empty, 0) , "1=1\n2=\n 1=a");
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a", "a" , Keyval_.Ary_empty, 0) , "1=1\n2=\n 1=a");
}
@Test public void Callback__anypos() {// PURPOSE.fix: was not handling $capt argument; EX:vi.d:trở_thành; DATE:2014-04-23
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a bcd e", "()(b)" , Scrib_kv_utl_.base1_many_(true, false), 0), String_.Concat_lines_nl_skip_last

View File

@@ -92,7 +92,7 @@ class Mock_proc__recursive extends Mock_proc_fxt { private final Mock_scrib_fxt
this.fxt = fxt; this.lib = lib; this.inner = inner;
this.bfr = bfr;
}
@Override public KeyVal[] Exec_by_scrib(KeyVal[] args) {
@Override public Keyval[] Exec_by_scrib(Keyval[] args) {
bfr.Add_int_variable(this.Id()).Add_byte_semic();
if (inner != null)
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_("a", ".", inner.To_scrib_lua_proc(), -1), "a;1");

View File

@@ -38,7 +38,7 @@ public class Scrib_lib_ustring__match__tst {
Exec_match("" , "a?" , 1, ""); // no results with ? should return "" not nil; PAGE:en.d:民; DATE:2015-01-30
}
@Test public void Args_out_of_order() {
fxt.Test__proc__kvps__empty(lib, Scrib_lib_ustring.Invk_match, KeyVal_.Ary(KeyVal_.int_(2, "[a]")));
fxt.Test__proc__kvps__empty(lib, Scrib_lib_ustring.Invk_match, Keyval_.Ary(Keyval_.int_(2, "[a]")));
}
// @Test public void Match_viwiktionary() {
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);

View File

@@ -47,8 +47,8 @@ public class Scrib_lib_wikibase implements Scrib_lib {
}
private static final int Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_renderSnak = 3, Proc_renderSnaks = 4, Proc_getEntityId = 5, Proc_getUserLang = 6, Proc_getDescription = 7, Proc_resolvePropertyId = 8, Proc_getSiteLinkPageName = 9, Proc_incrementExpensiveFunctionCount = 10;
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount";
private static final String[] Proc_names = String_.Ary(Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount);
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), KeyVal_.Ary_empty);}
private static final String[] Proc_names = String_.Ary(Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount);
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) {
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
@@ -66,7 +66,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
byte[] ttl_bry = args.Pull_bry(0);
Xowe_wiki wiki = core.Wiki();
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
byte[] rv = wiki.Appe().Wiki_mgr().Wdata_mgr().Qids_get(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);
}
public boolean GetUserLang(Scrib_proc_args args, Scrib_proc_rslt rslt) {
@@ -88,13 +88,13 @@ public class Scrib_lib_wikibase implements Scrib_lib {
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 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 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 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
}
private Wdata_doc Get_wdoc(byte[] ttl_bry) {
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Pages_get_by_ttl_name(ttl_bry);
if (wdoc == null) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), ttl_bry);
private Wdata_doc Get_wdoc(byte[] xid_bry) {
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);
return wdoc;
}
}

View File

@@ -37,7 +37,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
}
private static final int Proc_getGlobalSiteId = 0, Proc_formatPropertyValues = 1;
public static final String Invk_getGlobalSiteId = "getGlobalSiteId", Invk_formatPropertyValues = "formatPropertyValues";
private static final String[] Proc_names = String_.Ary(Invk_getGlobalSiteId, Invk_formatPropertyValues);
private static final String[] Proc_names = String_.Ary(Invk_getGlobalSiteId, Invk_formatPropertyValues);
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
}
@@ -47,13 +47,13 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
Xoae_app app = core.App(); Xowe_wiki wiki = core.Wiki();
Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr();
byte[] lang = wiki.Wdata_wiki_lang();
Wdata_doc wdoc = wdata_mgr.Pages_get(qid); if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), qid); return rslt.Init_str_empty();} // NOTE: return empty String, not nil; PAGE:fr.s:Henri_Bergson; DATE:2014-08-13
int pid_int = wdata_mgr.Pids__parse_as_int_or_null(pid); // parse as num; EX: p123 -> 123; PAGE:hr.w:Hepatitis DATE:2015-11-08
if (pid_int == Wdata_wiki_mgr.Pid_null) pid_int = wdata_mgr.Pids__get_by_name(lang, pid); // parse as name; EX: name > 123
Wdata_doc wdoc = wdata_mgr.Doc_mgr.Get_by_bry_or_null(qid); if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), qid); return rslt.Init_str_empty();} // NOTE: return empty String, not nil; PAGE:fr.s:Henri_Bergson; DATE:2014-08-13
int pid_int = Wbase_pid_mgr.To_int_or_null(pid); // parse as num; EX: p123 -> 123; PAGE:hr.w:Hepatitis DATE:2015-11-08
if (pid_int == Wdata_wiki_mgr.Pid_null) pid_int = wdata_mgr.Pid_mgr.Get_or_null(lang, pid); // parse as name; EX: name > 123
if (pid_int == Wdata_wiki_mgr.Pid_null) return rslt.Init_str_empty();
Wdata_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty();
Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512();
wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang);
return rslt.Init_obj(bfr.To_bry_and_rls());
}
}
}

View File

@@ -28,7 +28,7 @@ public class Scrib_lib_wikibase_entity_tst {
}
@Test public void FormatPropertyValues() {
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_str(3, "P3_val")).Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_str(3, "P3_val")).Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3") , "P3_val"); // lookup by id
wdata_fxt.Init_pids_add("en", "P3_val", 3);
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3_val") , "P3_val"); // lookup by name

View File

@@ -18,111 +18,111 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
class Scrib_lib_wikibase_srl {
public static KeyVal[] Srl(Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
public static Keyval[] Srl(Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
int base_adj = legacy_style ? 0 : 1;
List_adp rv = List_adp_.new_();
if (header_enabled) {
rv.Add(KeyVal_.new_("id", wdoc.Qid()));
rv.Add(KeyVal_.new_("type", Wdata_dict_value_entity_tid.Str_item));
rv.Add(KeyVal_.new_("schemaVersion", base_adj + 1)); // NOTE: needed by mw.wikibase.lua
rv.Add(Keyval_.new_("id", wdoc.Qid()));
rv.Add(Keyval_.new_("type", Wdata_dict_value_entity_tid.Str_item));
rv.Add(Keyval_.new_("schemaVersion", base_adj + 1)); // NOTE: needed by mw.wikibase.lua
}
Srl_root(rv, Wdata_doc_parser_v2.Str_labels , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Label_list()));
Srl_root(rv, Wdata_doc_parser_v2.Str_descriptions , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Descr_list()));
Srl_root(rv, Wdata_doc_parser_v2.Str_sitelinks , Srl_sitelinks (Wdata_dict_sitelink.Str_site , Wdata_dict_sitelink.Str_title, wdoc.Slink_list(), base_adj));
Srl_root(rv, Wdata_doc_parser_v2.Str_aliases , Srl_aliases (base_adj, wdoc.Alias_list()));
Srl_root(rv, Wdata_doc_parser_v2.Str_claims , Srl_claims (base_adj, legacy_style, wdoc.Claim_list()));
return (KeyVal[])rv.To_ary(KeyVal.class);
return (Keyval[])rv.To_ary(Keyval.class);
}
private static void Srl_root(List_adp rv, String label, KeyVal[] ary) {
private static void Srl_root(List_adp rv, String label, Keyval[] ary) {
if (ary == null) return; // don't add node if empty; EX: labels:{} should not add "labels" kv
rv.Add(KeyVal_.new_(label, ary));
rv.Add(Keyval_.new_(label, ary));
}
private static KeyVal[] Srl_langtexts(String lang_label, String text_label, Ordered_hash list) {
private static Keyval[] Srl_langtexts(String lang_label, String text_label, Ordered_hash list) {
int len = list.Count(); if (len == 0) return null;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_langtext_itm itm = (Wdata_langtext_itm)list.Get_at(i);
String lang = String_.new_u8(itm.Lang());
String text = String_.new_u8(itm.Text());
rv[i] = KeyVal_.new_(lang, KeyVal_.Ary(KeyVal_.new_(lang_label, lang), KeyVal_.new_(text_label, text)));
rv[i] = Keyval_.new_(lang, Keyval_.Ary(Keyval_.new_(lang_label, lang), Keyval_.new_(text_label, text)));
}
return rv;
}
private static KeyVal[] Srl_sitelinks(String key_label, String val_label, Ordered_hash list, int base_adj) {
private static Keyval[] Srl_sitelinks(String key_label, String val_label, Ordered_hash list, int base_adj) {
int len = list.Count(); if (len == 0) return null;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.Get_at(i);
String site = String_.new_u8(itm.Site());
String name = String_.new_u8(itm.Name());
rv[i] = KeyVal_.new_(site, KeyVal_.Ary(KeyVal_.new_(key_label, site), KeyVal_.new_(val_label, name), Srl_sitelinks_badges(itm.Badges(), base_adj)));
rv[i] = Keyval_.new_(site, Keyval_.Ary(Keyval_.new_(key_label, site), Keyval_.new_(val_label, name), Srl_sitelinks_badges(itm.Badges(), base_adj)));
}
return rv;
}
private static KeyVal Srl_sitelinks_badges(byte[][] badges, int base_adj) { // DATE:2014-11-13
private static Keyval Srl_sitelinks_badges(byte[][] badges, int base_adj) { // DATE:2014-11-13
if (badges == null) badges = Bry_.Ary_empty; // null badges -> badges:[]
int len = badges.length;
KeyVal[] kvs = len == 0 ? KeyVal_.Ary_empty : new KeyVal[len];
Keyval[] kvs = len == 0 ? Keyval_.Ary_empty : new Keyval[len];
for (int i = 0; i < len; i++) {
byte[] badge = badges[i];
kvs[i] = KeyVal_.int_(i + base_adj, String_.new_u8(badge));
kvs[i] = Keyval_.int_(i + base_adj, String_.new_u8(badge));
}
return KeyVal_.new_("badges", kvs);
return Keyval_.new_("badges", kvs);
}
private static KeyVal[] Srl_aliases(int base_adj, Ordered_hash list) {
private static Keyval[] Srl_aliases(int base_adj, Ordered_hash list) {
int len = list.Count(); if (len == 0) return null;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_alias_itm itm = (Wdata_alias_itm)list.Get_at(i);
String lang = String_.new_u8(itm.Lang());
rv[i] = KeyVal_.new_(lang, Srl_aliases_langs(base_adj, lang, itm.Vals()));
rv[i] = Keyval_.new_(lang, Srl_aliases_langs(base_adj, lang, itm.Vals()));
}
return rv;
}
private static KeyVal[] Srl_aliases_langs(int base_adj, String lang, byte[][] ary) {
private static Keyval[] Srl_aliases_langs(int base_adj, String lang, byte[][] ary) {
int len = ary.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
byte[] itm = ary[i];
rv[i] = KeyVal_.int_(i + base_adj, KeyVal_.Ary(KeyVal_.new_(Wdata_dict_langtext.Str_language, lang), KeyVal_.new_(Wdata_dict_langtext.Str_value, String_.new_u8(itm)))); // NOTE: using same base_adj logic as claims
rv[i] = Keyval_.int_(i + base_adj, Keyval_.Ary(Keyval_.new_(Wdata_dict_langtext.Str_language, lang), Keyval_.new_(Wdata_dict_langtext.Str_value, String_.new_u8(itm)))); // NOTE: using same base_adj logic as claims
}
return rv;
}
private static KeyVal[] Srl_claims(int base_adj, boolean legacy_style, Ordered_hash claim_grps) {
private static Keyval[] Srl_claims(int base_adj, boolean legacy_style, Ordered_hash claim_grps) {
int len = claim_grps.Count(); if (len == 0) return null;
int rv_len = legacy_style ? len * 2 : len; // NOTE: legacyStyle returns 2 sets of properties: official "P" and legacy "p"; DATE:2014-05-11
KeyVal[] rv = new KeyVal[rv_len];
Keyval[] rv = new Keyval[rv_len];
for (int i = 0; i < len; i++) {
Wdata_claim_grp grp = (Wdata_claim_grp)claim_grps.Get_at(i);
String pid_str = Int_.To_str(grp.Id());
KeyVal[] grp_val = Srl_claims_prop_grp("P" + pid_str, grp, base_adj);
rv[i] = KeyVal_.new_("P" + pid_str, grp_val);
Keyval[] grp_val = Srl_claims_prop_grp("P" + pid_str, grp, base_adj);
rv[i] = Keyval_.new_("P" + pid_str, grp_val);
if (legacy_style)
rv[i + len] = KeyVal_.new_("p" + pid_str, grp_val); // SEE:WikibaseLuaBindings.php; This is a B/C hack to allow existing lua code to use hardcoded IDs in both lower (legacy) and upper case.; DATE:2014-05-11
rv[i + len] = Keyval_.new_("p" + pid_str, grp_val); // SEE:WikibaseLuaBindings.php; This is a B/C hack to allow existing lua code to use hardcoded IDs in both lower (legacy) and upper case.; DATE:2014-05-11
}
return rv;
}
private static KeyVal[] Srl_claims_prop_grp(String pid, Wdata_claim_grp grp, int base_adj) {
private static Keyval[] Srl_claims_prop_grp(String pid, Wdata_claim_grp grp, int base_adj) {
int len = grp.Len();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_claim_itm_core itm = grp.Get_at(i);
rv[i] = KeyVal_.int_(i + base_adj, Srl_claims_prop_itm(pid, itm, base_adj)); // NOTE: must be super 0 or super 1; DATE:2014-05-09
rv[i] = Keyval_.int_(i + base_adj, Srl_claims_prop_itm(pid, itm, base_adj)); // NOTE: must be super 0 or super 1; DATE:2014-05-09
}
return rv;
}
private static KeyVal[] Srl_claims_prop_itm(String pid, Wdata_claim_itm_core itm, int base_adj) {
private static Keyval[] Srl_claims_prop_itm(String pid, Wdata_claim_itm_core itm, int base_adj) {
List_adp list = List_adp_.new_();
list.Add(KeyVal_.new_("id", pid));
list.Add(KeyVal_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm)));
list.Add(KeyVal_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid())));
list.Add(KeyVal_.new_("type", itm.Prop_type()));
list.Add(Keyval_.new_("id", pid));
list.Add(Keyval_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm)));
list.Add(Keyval_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid())));
list.Add(Keyval_.new_("type", itm.Prop_type()));
Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(itm.Qualifiers(), base_adj));
return (KeyVal[])list.To_ary_and_clear(KeyVal.class);
return (Keyval[])list.To_ary_and_clear(Keyval.class);
}
private static KeyVal[] Srl_qualifiers(Wdata_claim_grp_list list, int base_adj) {
private static Keyval[] Srl_qualifiers(Wdata_claim_grp_list list, int base_adj) {
if (list == null) return null;
int list_len = list.Len(); if (list_len == 0) return KeyVal_.Ary_empty;
int list_len = list.Len(); if (list_len == 0) return Keyval_.Ary_empty;
List_adp rv = List_adp_.new_();
List_adp pid_list = List_adp_.new_();
for (int i = 0; i < list_len; ++i) {
@@ -132,25 +132,25 @@ class Scrib_lib_wikibase_srl {
String itm_pid = grp.Id_str();
for (int j = 0; j < grp_len; ++j) {
Wdata_claim_itm_core itm = grp.Get_at(j);
pid_list.Add(KeyVal_.int_(j + base_adj, Srl_claims_prop_itm_core(itm_pid, itm))); // NOTE: was originally "+ 1"; changed to base_adj; PAGE:ru.w:Tor ru.w:Кактусовые DATE:2014-10-25
pid_list.Add(Keyval_.int_(j + base_adj, Srl_claims_prop_itm_core(itm_pid, itm))); // NOTE: was originally "+ 1"; changed to base_adj; PAGE:ru.w:Tor ru.w:Кактусовые DATE:2014-10-25
}
rv.Add(KeyVal_.new_(itm_pid, (KeyVal[])pid_list.To_ary_and_clear(KeyVal.class)));
rv.Add(Keyval_.new_(itm_pid, (Keyval[])pid_list.To_ary_and_clear(Keyval.class)));
}
return (KeyVal[])rv.To_ary_and_clear(KeyVal.class);
return (Keyval[])rv.To_ary_and_clear(Keyval.class);
}
private static KeyVal[] Srl_claims_prop_itm_core(String pid, Wdata_claim_itm_core itm) {
private static Keyval[] Srl_claims_prop_itm_core(String pid, Wdata_claim_itm_core itm) {
boolean snak_is_valued = itm.Snak_tid() == Wdata_dict_snak_tid.Tid_value; // PURPOSE: was != Wdata_dict_snak_tid.Tid_novalue; PAGE:it.s:Autore:Anonimo DATE:2015-12-06
int snak_is_valued_adj = snak_is_valued ? 1 : 0;
KeyVal[] rv = new KeyVal[3 + snak_is_valued_adj];
Keyval[] rv = new Keyval[3 + snak_is_valued_adj];
if (snak_is_valued) // NOTE: novalue must not return slot (no datavalue node in json); PAGE:ru.w:Лимонов,_Эдуард_Вениаминович; DATE:2015-02-16; ALSO: sv.w:Joseph_Jaquet; DATE:2015-07-31
rv[0] = KeyVal_.new_("datavalue", Srl_claims_prop_itm_core_val(itm));
rv[0 + snak_is_valued_adj] = KeyVal_.new_("property", pid);
rv[1 + snak_is_valued_adj] = KeyVal_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid()));
rv[2 + snak_is_valued_adj] = KeyVal_.new_("datatype", Wdata_dict_val_tid.To_str__srl(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
rv[0] = Keyval_.new_("datavalue", Srl_claims_prop_itm_core_val(itm));
rv[0 + snak_is_valued_adj] = Keyval_.new_("property", pid);
rv[1 + snak_is_valued_adj] = Keyval_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid()));
rv[2 + snak_is_valued_adj] = Keyval_.new_("datatype", Wdata_dict_val_tid.To_str__srl(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
return rv;
}
private static final Scrib_lib_wikibase_srl_visitor visitor = new Scrib_lib_wikibase_srl_visitor();
private static KeyVal[] Srl_claims_prop_itm_core_val(Wdata_claim_itm_core itm) {
private static Keyval[] Srl_claims_prop_itm_core_val(Wdata_claim_itm_core itm) {
switch (itm.Snak_tid()) {
case Wdata_dict_snak_tid.Tid_somevalue: return Datavalue_somevalue;
case Wdata_dict_snak_tid.Tid_novalue: return Datavalue_novalue; // TODO: throw exc
@@ -160,6 +160,6 @@ class Scrib_lib_wikibase_srl {
}
}
public static final String Key_type = "type", Key_value = "value";
private static final KeyVal[] Datavalue_somevalue = KeyVal_.Ary_empty; // changed to not return value-node; PAGE:it.s:Autore:Anonimo DATE:2015-12-06 // new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
private static final KeyVal[] Datavalue_novalue = KeyVal_.Ary_empty;
private static final Keyval[] Datavalue_somevalue = Keyval_.Ary_empty; // changed to not return value-node; PAGE:it.s:Autore:Anonimo DATE:2015-12-06 // new Keyval[] {Keyval_.new_(Key_type, ""), Keyval_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
private static final Keyval[] Datavalue_novalue = Keyval_.Ary_empty;
}

View File

@@ -391,36 +391,36 @@ class Scrib_lib_wikibase_srl_fxt {
public Scrib_lib_wikibase_srl_fxt Init_prop(Wdata_claim_itm_core prop) {wdoc_bldr.Add_claims(prop); return this;}
public Scrib_lib_wikibase_srl_fxt Test(String... expd) {return Test(false, expd);}
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, String... expd) {
KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(wdoc_bldr.Xto_wdoc(), header_enabled, base0);
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(wdoc_bldr.Xto_wdoc(), header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
public Scrib_lib_wikibase_srl_fxt Test(Wdata_doc wdoc, String... expd) {return Test(false, wdoc, expd);}
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, Wdata_doc wdoc, String... expd) {
KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(wdoc, header_enabled, base0);
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(wdoc, header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
private String Xto_str(KeyVal[] ary) {
private String Xto_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
Xto_str(bfr, ary, 0);
return bfr.To_str_and_clear();
}
private void Xto_str(Bry_bfr bfr, KeyVal[] ary, int depth) {
private void Xto_str(Bry_bfr bfr, Keyval[] ary, int depth) {
int len = ary.length;
for (int i = 0; i < len; i++) {
KeyVal kv = ary[i];
Keyval kv = ary[i];
Xto_str(bfr, kv, depth);
}
}
private void Xto_str(Bry_bfr bfr, KeyVal kv, int depth) {
private void Xto_str(Bry_bfr bfr, Keyval kv, int depth) {
bfr.Add_byte_repeat(Byte_ascii.Space, depth * 2);
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
Object kv_val = kv.Val();
if (kv_val == null) {bfr.Add_str_a7("null").Add_byte_nl(); return;}
Class<?> kv_val_cls = kv_val.getClass();
if (Type_adp_.Eq(kv_val_cls, KeyVal[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (KeyVal[])kv_val, depth + 1);}
else if (Type_adp_.Eq(kv_val_cls, KeyVal[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (KeyVal)kv_val, depth + 1);}
if (Type_adp_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval[])kv_val, depth + 1);}
else if (Type_adp_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval)kv_val, depth + 1);}
else bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(Object_.Xto_str_strict_or_empty(kv_val)).Add_byte(Byte_ascii.Apos).Add_byte_nl();
}
}

View File

@@ -18,78 +18,78 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.xtns.wdatas.core.*;
class Scrib_lib_wikibase_srl_visitor implements Wdata_claim_visitor {
public KeyVal[] Rv() {return rv;} KeyVal[] rv;
public Keyval[] Rv() {return rv;} Keyval[] rv;
public void Visit_str(Wdata_claim_itm_str itm) {
rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Xto_str(itm.Val_tid()));
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, String_.new_u8(itm.Val_str()));
rv = new Keyval[2];
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Xto_str(itm.Val_tid()));
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, String_.new_u8(itm.Val_str()));
}
public void Visit_entity(Wdata_claim_itm_entity itm) {
rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_entity);
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Entity_value(itm));
rv = new Keyval[2];
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_entity);
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Entity_value(itm));
}
private static KeyVal[] Entity_value(Wdata_claim_itm_core itm) {
private static Keyval[] Entity_value(Wdata_claim_itm_core itm) {
Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)itm;
KeyVal[] rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Wdata_dict_value_entity.Str_entity_type, claim_entity.Entity_tid_str());
rv[1] = KeyVal_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.To_str(claim_entity.Entity_id()));
Keyval[] rv = new Keyval[2];
rv[0] = Keyval_.new_(Wdata_dict_value_entity.Str_entity_type, claim_entity.Entity_tid_str());
rv[1] = Keyval_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.To_str(claim_entity.Entity_id()));
return rv;
}
public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {
rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_monolingualtext);
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm));
rv = new Keyval[2];
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_monolingualtext);
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm));
}
private static KeyVal[] Monolingualtext_value(Wdata_claim_itm_monolingualtext itm) {
KeyVal[] rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_u8(itm.Text()));
rv[1] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_u8(itm.Lang()));
private static Keyval[] Monolingualtext_value(Wdata_claim_itm_monolingualtext itm) {
Keyval[] rv = new Keyval[2];
rv[0] = Keyval_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_u8(itm.Text()));
rv[1] = Keyval_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_u8(itm.Lang()));
return rv;
}
public void Visit_quantity(Wdata_claim_itm_quantity itm) {
rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_quantity);
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Quantity_value(itm));
rv = new Keyval[2];
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_quantity);
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Quantity_value(itm));
}
private static KeyVal[] Quantity_value(Wdata_claim_itm_quantity itm) {
KeyVal[] rv = new KeyVal[4];
rv[0] = KeyVal_.new_(Wdata_dict_value_quantity.Str_amount , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
rv[1] = KeyVal_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_u8(itm.Unit()));
rv[2] = KeyVal_.new_(Wdata_dict_value_quantity.Str_upperbound , itm.Ubound_as_num().To_str());
rv[3] = KeyVal_.new_(Wdata_dict_value_quantity.Str_lowerbound , itm.Lbound_as_num().To_str());
private static Keyval[] Quantity_value(Wdata_claim_itm_quantity itm) {
Keyval[] rv = new Keyval[4];
rv[0] = Keyval_.new_(Wdata_dict_value_quantity.Str_amount , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
rv[1] = Keyval_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_u8(itm.Unit()));
rv[2] = Keyval_.new_(Wdata_dict_value_quantity.Str_upperbound , itm.Ubound_as_num().To_str());
rv[3] = Keyval_.new_(Wdata_dict_value_quantity.Str_lowerbound , itm.Lbound_as_num().To_str());
return rv;
}
public void Visit_time(Wdata_claim_itm_time itm) {
rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_time);
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Time_value(itm));
rv = new Keyval[2];
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_time);
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Time_value(itm));
}
private static KeyVal[] Time_value(Wdata_claim_itm_time itm) {
KeyVal[] rv = new KeyVal[6];
rv[0] = KeyVal_.new_(Wdata_dict_value_time.Str_time , String_.new_a7(itm.Time()));
rv[1] = KeyVal_.new_(Wdata_dict_value_time.Str_precision , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
rv[2] = KeyVal_.new_(Wdata_dict_value_time.Str_before , itm.Before_int());
rv[3] = KeyVal_.new_(Wdata_dict_value_time.Str_after , itm.After_int());
rv[4] = KeyVal_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
rv[5] = KeyVal_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str);
private static Keyval[] Time_value(Wdata_claim_itm_time itm) {
Keyval[] rv = new Keyval[6];
rv[0] = Keyval_.new_(Wdata_dict_value_time.Str_time , String_.new_a7(itm.Time()));
rv[1] = Keyval_.new_(Wdata_dict_value_time.Str_precision , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
rv[2] = Keyval_.new_(Wdata_dict_value_time.Str_before , itm.Before_int());
rv[3] = Keyval_.new_(Wdata_dict_value_time.Str_after , itm.After_int());
rv[4] = Keyval_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
rv[5] = Keyval_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str);
return rv;
}
public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) {
rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_globecoordinate);
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Globecoordinate_value(itm));
rv = new Keyval[2];
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_globecoordinate);
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Globecoordinate_value(itm));
}
private static KeyVal[] Globecoordinate_value(Wdata_claim_itm_globecoordinate itm) {
KeyVal[] rv = new KeyVal[5];
rv[0] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse(String_.new_a7(itm.Lat())));
rv[1] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse(String_.new_a7(itm.Lng())));
rv[2] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_altitude , String_.new_u8(itm.Alt()));
rv[3] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_globe , String_.new_u8(itm.Glb()));
rv[4] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_precision , itm.Prc_as_num().To_double());
private static Keyval[] Globecoordinate_value(Wdata_claim_itm_globecoordinate itm) {
Keyval[] rv = new Keyval[5];
rv[0] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse(String_.new_a7(itm.Lat())));
rv[1] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse(String_.new_a7(itm.Lng())));
rv[2] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_altitude , String_.new_u8(itm.Alt()));
rv[3] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_globe , String_.new_u8(itm.Glb()));
rv[4] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_precision , itm.Prc_as_num().To_double());
return rv;
}
public void Visit_system(Wdata_claim_itm_system itm) {
rv = KeyVal_.Ary_empty;
rv = Keyval_.Ary_empty;
}
}

View File

@@ -19,8 +19,8 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
import org.junit.*;
import gplx.xowa.xtns.wdatas.*;
public class Scrib_lib_wikibase_tst {
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
@Before public void init() {
fxt.Clear_for_lib("en.wikipedia.org", "zh-hans");
lib = fxt.Core().Lib_wikibase().Init();
@@ -36,31 +36,31 @@ public class Scrib_lib_wikibase_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("missing_page" ), "");
}
@Test public void GetLabel__cur() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hans", "s").Add_label("zh-hant", "t").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hans", "s").Add_label("zh-hant", "t").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "s"); // do not get fallback
}
@Test public void GetLabel__fallback_1() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hant", "t").Add_label("zh-hk", "h").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hant", "t").Add_label("zh-hk", "h").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "t"); // get 1st fallback
}
@Test public void GetLabel__fallback_2() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hk", "hk").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hk", "hk").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "hk"); // get 2nd fallback
}
@Test public void GetLabel__fallback_en() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "en").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "en").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "en"); // get en
}
@Test public void GetDescr() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_description("zh-hans", "s").Add_description("zh-hant", "t").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_description("zh-hans", "s").Add_description("zh-hant", "t").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getDescription, Object_.Ary("q2"), "s");
}
@Test public void GetSlink() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_sitelink("enwiki", "a").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_sitelink("enwiki", "a").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getSiteLinkPageName, Object_.Ary("q2"), "a");
}
@Test public void GetEntity() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl_skip_last
( "1="
, " id=q2"
@@ -73,7 +73,7 @@ public class Scrib_lib_wikibase_tst {
));
}
@Test public void GetEntity_property() { // PURPOSE: getEntity should be able to convert "p2" to "Property:P2"; EX:es.w:Arnold_Gesell; DATE:2014-02-18
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("en", "b").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("en", "b").Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("p2", false), String_.Concat_lines_nl_skip_last
( "1="
, " id=Property:p2" // only difference from above
@@ -86,7 +86,7 @@ public class Scrib_lib_wikibase_tst {
));
}
@Test public void ResolvePropertyId() {
wdata_fxt.Init_pages_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");
}
}

View File

@@ -23,7 +23,7 @@ public class Scrib_regx_converter {
public Scrib_regx_converter() {Init();}
public String Regx() {return regx;} private String regx;
public List_adp Capt_list() {return capt_list;}
public KeyVal[] Capt_ary() {return capt_list.Count() == 0 ? null : (KeyVal[])capt_list.To_ary(KeyVal.class);}
public Keyval[] Capt_ary() {return capt_list.Count() == 0 ? null : (Keyval[])capt_list.To_ary(Keyval.class);}
private Bry_fmtr fmtr_balanced; private Bry_bfr bfr_balanced;
public String Parse(byte[] src, byte[] anchor) {
int len = src.length;
@@ -48,7 +48,7 @@ public class Scrib_regx_converter {
if (i + 1 >= len) throw Err_.new_wo_type("Unmatched open-paren at pattern character " + Int_.To_str(i));
boolean capt_itm = src[i + 1] == Byte_ascii.Paren_end; // current is "()"
++grps_len;
capt_list.Add(KeyVal_.int_(grps_len, capt_itm));
capt_list.Add(Keyval_.int_(grps_len, capt_itm));
bfr.Add_byte(Byte_ascii.Paren_bgn);
grps_open.Add(grps_len);
grps_parens.Add(i + 1);
@@ -99,7 +99,6 @@ public class Scrib_regx_converter {
case Byte_ascii.Ltr_f: { // EX: lua frontier pattern; "%f[%a]"; DATE:2015-07-21
++i;
if (i + 1 >= len || src[i] != Byte_ascii.Brack_bgn) throw Err_.new_("scribunto", "missing '[' after %f in pattern at pattern character $ii");
// %f always followed by bracketed term; convert lua bracketed term to regex
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
i = bracketedCharSetToRegex(tmp_bfr, src, i, len);

View File

@@ -66,4 +66,4 @@ class Scrib_regx_converter_fxt {
String actl = Regx_adp_.Replace(text, regex_str, replace);
Tfds.Eq(expd, actl);
}
}
}