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

'v3.5.1.1'

This commit is contained in:
gnosygnu
2016-05-01 21:06:12 -04:00
parent 5ce4ea2a08
commit 96636f3161
131 changed files with 2287 additions and 928 deletions

View File

@@ -24,7 +24,34 @@ public class Scrib_proc_args {
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_safe(int idx) { // NOTE: must check for null array items; EX:[2:v2] -> [1:null,2:v2]; PAGE:en.d:Category:Nouns_by_language DATE:2016-04-29
Keyval[] rv = (Keyval[])Get_or_fail(idx);
List_adp list = null;
int rv_len = rv.length;
for (int i = 0; i < rv_len; ++i) {
Keyval kv = rv[i];
if ( kv.Key_tid() == Type_adp_.Tid__int // luaj will be int
|| kv.Key_tid() == Type_adp_.Tid__obj) { // lua will be obj; note that luaj will also have other non-key objects
Object key_obj = kv.Key_as_obj();
if (key_obj.getClass() == Int_.Cls_ref_type) { // key is int; cast it
int key_int = Int_.cast(kv.Key_as_obj());
if (key_int != i + 1) { // key_int should match i; if not, then gaps exist; EX:[2:v2] should be 2nd element, not 1st
if (list == null) {
list = List_adp_.new_();
rv = null;
}
for (int j = 0; j < key_int - 1; ++j) // add everything up to key_int as null; EX: [2:v2] -> [1:null]
list.Add(Keyval_.int_(j + List_adp_.Base1, null));
}
}
}
if (rv == null)
list.Add(kv);
}
if (rv == null)
rv = (Keyval[])list.To_ary(Keyval.class);
return rv;
}
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) {

View File

@@ -45,7 +45,7 @@ public class Luaj_engine implements Scrib_engine {
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));
msg.set("functions", Luaj_value_.Obj_to_lua_val(server, functions));
server.Dispatch(msg);
}
public Keyval[] CallFunction(int id, Keyval[] args) {
@@ -54,7 +54,7 @@ public class Luaj_engine implements Scrib_engine {
msg.set("op", Val_callFunction);
msg.set("id", LuaValue.valueOf(id));
msg.set("nargs", LuaValue.valueOf(args_len));
msg.set("args", Luaj_value_.X_obj_to_val(server, args));
msg.set("args", Luaj_value_.Obj_to_lua_val(server, args));
return this.Dispatch_as_kv_ary(msg);
}
public Keyval[] ExecuteModule(int mod_id) {
@@ -63,7 +63,7 @@ public class Luaj_engine implements Scrib_engine {
public void CleanupChunks(Keyval[] ids) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", "cleanupChunks");
msg.set("ids", Luaj_value_.X_obj_to_val(server, ids));
msg.set("ids", Luaj_value_.Obj_to_lua_val(server, ids));
this.Dispatch_as_kv_ary(msg);
}
public Keyval[] Dispatch_as_kv_ary(LuaTable msg) {
@@ -103,7 +103,7 @@ public class Luaj_engine implements Scrib_engine {
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_returnMessage);
msg.set("nvalues", LuaValue.valueOf(values.length));
msg.set("values", Luaj_value_.X_obj_to_val(server, values));
msg.set("values", Luaj_value_.Obj_to_lua_val(server, values));
return msg;
}
private LuaTable ReturnFail(String fail_msg) {

View File

@@ -16,6 +16,7 @@ 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.engines.luaj; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import java.util.*;
import org.luaj.vm2.*;
class Luaj_value_ {
public static String Get_val_as_str(LuaTable owner, String key) {
@@ -26,9 +27,9 @@ class Luaj_value_ {
}
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);
return Luaj_value_.Lua_tbl_to_kv_ary(server, table);
}
public static Keyval[] X_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
public static Keyval[] Lua_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
List_adp temp = List_adp_.new_();
LuaValue cur = LuaValue.NIL;
int len = 0;
@@ -36,7 +37,7 @@ class Luaj_value_ {
Varargs itm = tbl.next(cur);
if (itm == LuaValue.NIL) break; // no more pairs; stop
LuaValue itm_val = itm.arg(2); // val is itm 2
Object itm_val_obj = X_val_to_obj(server, itm_val);
Object itm_val_obj = Lua_val_to_obj(server, itm_val);
LuaValue itm_key = itm.arg(1);
Keyval kv = null;
if (itm_val.type() == LuaValue.TFUNCTION) { // function is converted to Scrib_lua_proc
@@ -51,7 +52,8 @@ class Luaj_value_ {
else {
switch (itm_key.type()) {
case LuaValue.TNUMBER:
kv = Keyval_.int_(((LuaNumber)itm_key).toint(), itm_val_obj);
int key_int = ((LuaNumber)itm_key).toint();
kv = Keyval_.int_(key_int, itm_val_obj);
break;
case LuaValue.TSTRING:
kv = Keyval_.new_(((LuaString)itm_key).tojstring(), itm_val_obj);
@@ -67,7 +69,7 @@ class Luaj_value_ {
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) {
private static Object Lua_val_to_obj(Luaj_server server, LuaValue v) {
switch (v.type()) {
case LuaValue.TNIL: return null;
case LuaValue.TBOOLEAN: return ((LuaBoolean)v).toboolean();
@@ -78,12 +80,12 @@ class Luaj_value_ {
return v_num.toint();
else
return v_num.todouble();
case LuaValue.TTABLE: return X_tbl_to_kv_ary(server, (LuaTable)v);
case LuaValue.TTABLE: return Lua_tbl_to_kv_ary(server, (LuaTable)v);
case LuaValue.TFUNCTION: return server.Get_id_by_closure(v);
default: throw Err_.new_unhandled(v.type());
}
}
public static LuaValue X_obj_to_val(Luaj_server server, Object o) {
public static LuaValue Obj_to_lua_val(Luaj_server server, Object o) {
if (o == null) return LuaValue.NIL;
Class<?> c = Type_adp_.ClassOf_obj(o);
if (Object_.Eq(c, Bool_.Cls_ref_type)) return LuaValue.valueOf((Boolean)o);
@@ -92,8 +94,8 @@ class Luaj_value_ {
else if (Object_.Eq(c, String_.Cls_ref_type)) return LuaValue.valueOf((String)o);
else if (Object_.Eq(c, Double_.Cls_ref_type)) return LuaValue.valueOf((Double)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 Kv_ary_to_lua_tbl(server, (Keyval)o);
else if (Object_.Eq(c, Keyval[].class)) return Kv_ary_to_lua_tbl(server, (Keyval[])o);
else if (Object_.Eq(c, Long_.Cls_ref_type)) return LuaValue.valueOf((Long)o);
else if (Object_.Eq(c, Scrib_lua_proc.class)) return server.Get_closure_by_id(((Scrib_lua_proc)o).Id());
else if (Object_.Eq(c, Float_.Cls_ref_type)) return LuaValue.valueOf((Float)o);
@@ -101,12 +103,12 @@ class Luaj_value_ {
else if (Object_.Eq(c, Short_.Cls_ref_type)) return LuaValue.valueOf((Short)o);
else return LuaValue.NIL;
}
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, Keyval... ary) {
private static LuaTable Kv_ary_to_lua_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];
LuaValue itm_val = X_obj_to_val(server, itm.Val());
LuaValue itm_val = Obj_to_lua_val(server, itm.Val());
switch (itm.Key_tid()) {
case Type_adp_.Tid__int:
rv.set(Int_.cast(itm.Key_as_obj()), itm_val);

View File

@@ -19,16 +19,16 @@ package gplx.xowa.xtns.scribunto.engines.mocks; import gplx.*; import gplx.xowa.
import gplx.core.primitives.*;
public abstract class Mock_proc_fxt {
public Mock_proc_fxt(int id, String key) {this.id = id; this.key = key;}
public int Id() {return id;} private final int id;
public String Key() {return key;} private final String key;
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);
}
class Mock_engine implements Scrib_engine {
private final Hash_adp hash = Hash_adp_.new_();
private final Int_obj_ref tmp_hash_id = Int_obj_ref.neg1_();
private final Hash_adp hash = Hash_adp_.new_();
private final Int_obj_ref tmp_hash_id = Int_obj_ref.neg1_();
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_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) {
Mock_proc_fxt proc = (Mock_proc_fxt)hash.Get_by_or_fail(tmp_hash_id.Val_(id));
@@ -37,7 +37,7 @@ class Mock_engine implements Scrib_engine {
public void RegisterLibrary(Keyval[] functions_ary) {}
public Keyval[] ExecuteModule(int mod_id) {return null;}
public void CleanupChunks(Keyval[] ids) {}
public void Clear() {}
public void Clear() {hash.Clear();}
public void RegisterLibraryForTest(Mock_proc_fxt proc) {
hash.Add(Int_obj_ref.new_(proc.Id()), proc);
}

View File

@@ -36,6 +36,7 @@ public class Mock_scrib_fxt {
core.When_page_changed(parser_fxt.Page());
}
public void Init__cbk(Mock_proc_fxt... ary) {
engine.Clear();
for (Mock_proc_fxt proc : ary)
engine.RegisterLibraryForTest(proc);
}

View File

@@ -16,7 +16,7 @@ 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.engines.process; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import gplx.core.texts.*;
import gplx.core.encoders.*;
import gplx.xowa.xtns.scribunto.libs.*;
public class Process_engine implements Scrib_engine {
private Scrib_core core; private Xoae_app app; private Scrib_xtn_mgr scrib_opts;
@@ -85,7 +85,7 @@ public class Process_engine implements Scrib_engine {
return Keyval_.Ary_empty;
}
}
} private static final byte[] Dispatch_hdr = Bry_.new_a7("0000000000000000"); // itm_len + itm_chk in 8-len HexDec
} private static final byte[] Dispatch_hdr = Bry_.new_a7("0000000000000000"); // itm_len + itm_chk in 8-len HexDec
private void Dispatch_bld_send(Bry_bfr bfr, Object[] ary) {
int len = ary.length; if (len % 2 != 0) throw Err_.new_wo_type("arguments must be factor of 2", "len", len);
bfr.Add(Dispatch_hdr);
@@ -102,7 +102,7 @@ public class Process_engine implements Scrib_engine {
bfr.Add_byte(Byte_ascii.Curly_end);
int msg_len = bfr.Len() - 16; // 16 for Dispatch_hdr_len
int chk_len = (msg_len * 2) -1; // defined by Scribunto
HexDecUtl.Write(bfr.Bfr(), 0, 8, msg_len);
HexDecUtl.Write(bfr.Bfr(), 9, 16, chk_len);
Hex_utl_.Write(bfr.Bfr(), 0, 8, msg_len);
Hex_utl_.Write(bfr.Bfr(), 9, 16, chk_len);
}
}

View File

@@ -53,7 +53,7 @@ public class Process_send_wtr {
bfr.Add_int_variable(prc.Id());
bfr.Add_byte(Byte_ascii.Brack_end);
return true;
} static final byte[] Prc_bgn = Bry_.new_a7("chunks[");
} static final byte[] Prc_bgn = Bry_.new_a7("chunks[");
private boolean Encode_ary(Bry_bfr bfr, Keyval[] ary) {
int len = ary.length;
bfr.Add_byte(Byte_ascii.Curly_bgn);
@@ -82,17 +82,18 @@ public class Process_send_wtr {
public boolean Encode_obj(Bry_bfr bfr, Object o) {
if (o == null) {bfr.Add(CONST_nil); return true;}
Class<?> c = Type_adp_.ClassOf_obj(o);
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.cast(o));
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast(o));
else if (Object_.Eq(c, Double_.Cls_ref_type)) {if (!Encode_double(bfr, Double_.cast(o))) return false;}
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.cast(o));
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast(o));
else if (Object_.Eq(c, Long_.Cls_ref_type)) bfr.Add_long_variable(Long_.cast(o));
else if (Object_.Eq(c, Double_.Cls_ref_type)) {if (!Encode_double(bfr, Double_.cast(o))) return false;}
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 {throw Scrib_xtn_mgr.err_("Object cannot be serialized: {0}", Type_adp_.NameOf_obj(o));}
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: ~{0}", Type_adp_.NameOf_obj(o));}
return true;
}
private static final byte[] CONST_nil = Bry_.new_a7("nil"), CONST_bool_true = Bry_.new_a7("true"), CONST_bool_false = Bry_.new_a7("false"), CONST_escape_000 = Bry_.new_a7("\\000");
private static final byte[] CONST_nil = Bry_.new_a7("nil"), CONST_bool_true = Bry_.new_a7("true"), CONST_bool_false = Bry_.new_a7("false"), CONST_escape_000 = Bry_.new_a7("\\000");
private static final String GRP_KEY = "xowa-scribunto-lua-srl";
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.engines.process; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import gplx.core.threads.*;
import gplx.core.texts.HexDecUtl;
import gplx.core.encoders.*;
import gplx.xowa.xtns.scribunto.*;
import gplx.core.threads.Thread_adp_;
import java.io.*;

View File

@@ -16,7 +16,7 @@ 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.engines.process; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import gplx.core.ios.*; import gplx.core.texts.*;
import gplx.core.ios.*; import gplx.core.encoders.*;
public class Process_stream_rdr {
public Process_stream_rdr(byte[] bry_header, byte[] bry_body) {this.bry_header = bry_header; this.bry_body = bry_body;} private byte[] bry_header, bry_body;
public IoStream_stream_rdr Rdr() {return rdr;} IoStream_stream_rdr rdr = new IoStream_stream_rdr();
@@ -26,8 +26,8 @@ public class Process_stream_rdr {
if (bytes_read == -1) return null; // stream closed; should only occur when shutting down
else throw Err_.new_wo_type("failed to read header");
}
int body_len = HexDecUtl.parse_or(bry_header, 0,8, -1); if (body_len == -1) throw Err_.new_wo_type("failed to read body_len");
int chk_len= HexDecUtl.parse_or(bry_header, 9, 16, -1); if (chk_len == -1 || chk_len != (body_len * 2) - 1) throw Err_.new_wo_type("failed to read chk_len");
int body_len = Hex_utl_.Parse_or(bry_header, 0,8, -1); if (body_len == -1) throw Err_.new_wo_type("failed to read body_len");
int chk_len= Hex_utl_.Parse_or(bry_header, 9, 16, -1); if (chk_len == -1 || chk_len != (body_len * 2) - 1) throw Err_.new_wo_type("failed to read chk_len");
byte[] trg_bry = (body_len > bry_body.length) ? new byte[body_len] : bry_body;
return Read_body(trg_bry, body_len, rdr);
}

View File

@@ -41,17 +41,17 @@ 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);
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 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_safe(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_safe(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));
}
@@ -153,7 +153,7 @@ class Scrib_lib_message_data {
return msg_val;
}
static final byte Key_tid_keys = 1, Key_tid_rawMessage = 2, Key_tid_lang = 3, Key_tid_useDB = 4, Key_tid_title = 5, Key_tid_params = 6;
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("keys", Key_tid_keys)
.Add_str_byte("rawMessage", Key_tid_rawMessage)
.Add_str_byte("lang", Key_tid_lang)
@@ -168,14 +168,14 @@ class Scrib_lib_message_data {
return ((Byte_obj_val)o).Val();
}
public static final byte Fmt_tid_parse = 1, Fmt_tid_text = 2, Fmt_tid_plain = 3, Fmt_tid_escaped = 4, Fmt_tid_parseAsBlock = 5;
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("parse", Fmt_tid_parse)
.Add_str_byte("text", Fmt_tid_text)
.Add_str_byte("plain", Fmt_tid_plain)
.Add_str_byte("escaped", Fmt_tid_escaped)
.Add_str_byte("parseAsBlock", Fmt_tid_parseAsBlock);
public static final byte Check_tid_exists = 1, Check_tid_isBlank = 2, Check_tid_isDisabled = 3;
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("exists", Check_tid_exists)
.Add_str_byte("isBlank", Check_tid_isBlank)
.Add_str_byte("isDisabled", Check_tid_isDisabled);

View File

@@ -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_safe(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
@@ -359,7 +359,7 @@ 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);
Keyval[] args_ary = args.Pull_kv_ary_safe(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);

View File

@@ -18,10 +18,11 @@ 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.*;
public class Scrib_lib_mw__lib_tst {
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
@Before public void init() {
fxt.Clear_for_lib();
lib = fxt.Core().Lib_mw().Init();
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
}
@Test public void ParentFrameExists() {
fxt.Init_frame_parent("test");
fxt.Test_scrib_proc_bool(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, true);
@@ -79,6 +80,11 @@ public class Scrib_lib_mw__lib_tst {
@Test public void NewChildFrame() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_newChildFrame, Object_.Ary("current", "Page_0", Scrib_kv_utl_.flat_many_("key1", "val1")), "frame0");
}
@Test public void ExpandTemplate__null_arg() {
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
fxt.Parser_fxt().Data_create("Template:A", "b{{{1}}}c");
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", "A", Scrib_kv_utl_.flat_many_(2, "v2")), "bc"); // list: args is ary
}
@Test public void SetTTL() {
fxt.Test_scrib_proc_empty(lib, Scrib_lib_mw.Invk_setTTL, Object_.Ary(123));
Tfds.Eq(123, fxt.Core().Frame_current().Frame_lifetime());

View File

@@ -99,17 +99,23 @@ public class Scrib_lib_site implements Scrib_lib {
local = 0;
else if (filter != null)
throw Err_.new_wo_type("bad argument #1 to 'interwikiMap' (unknown filter '$filter')", "filter", filter);
// 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][];
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
if (local == 1 && !itm_is_local) continue;
if (local == 0 && itm_is_local) continue;
String prefix = itm.Key_str();
rv[i] = InterwikiMap_itm(itm, prefix, itm_is_local);
Hash_adp misc_cache = core.Wiki().Cache_mgr().Misc_cache();
String cache_key = "scribunto.interwikimap." + core.Wiki().Domain_str() + "." + filter;
Keyval[] rv = (Keyval[])misc_cache.Get_by(cache_key);
if (rv == null) {
Xow_xwiki_mgr xwiki_mgr = core.Wiki().Xwiki_mgr();
int xwiki_len = xwiki_mgr.Len();
List_adp list = List_adp_.new_();
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
if (local == 1 && !itm_is_local) continue;
if (local == 0 && itm_is_local) continue;
String prefix = itm.Key_str();
list.Add(Keyval_.new_(prefix, InterwikiMap_itm(itm, prefix, itm_is_local)));
}
rv = (Keyval[])list.To_ary_and_clear(Keyval.class);
misc_cache.Add(cache_key, rv);
}
return rslt.Init_obj(rv);
}

View File

@@ -52,6 +52,19 @@ public class Scrib_lib_site_tst {
@Test public void PagesInNs() {
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
}
@Test public void InterwikiMap() {
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_interwikiMap, Object_.Ary("!local"), String_.Concat_lines_nl_skip_last
( "1="
, " en.wikipedia.org="
, " prefix=en.wikipedia.org"
, " url=en.wikipedia.org"
, " isProtocolRelative=false"
, " isLocal=false"
, " isTranscludable=false"
, " isCurrentWiki=false"
, " isExtraLanguageLink=false"
));
}
@Test public void Init_lib_site() {
Xowe_wiki wiki = fxt.Core().Wiki();
wiki.Stats().Load_by_db(1, 2, 3, 4, 5, 6, 7, 8);

View File

@@ -144,7 +144,7 @@ public class Scrib_lib_title implements Scrib_lib {
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[ 2] = Keyval_.new_("contentModel" , Key_wikitext); // $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);
}
@@ -227,5 +227,5 @@ public class Scrib_lib_title implements Scrib_lib {
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";
public static final String Key_wikitext = "wikitext";
}

View File

@@ -132,7 +132,7 @@ public class Scrib_lib_title_tst {
( "1="
, " isRedirect=" + Bool_.To_str_lower(redirect)
, " id=" + Int_.To_str(ttl_id)
, " contentModel=" + Scrib_lib_title.Key_wikitexet
, " contentModel=" + Scrib_lib_title.Key_wikitext
, " exists=" + Bool_.To_str_lower(exists)
);
}

View File

@@ -346,7 +346,10 @@ class Scrib_lib_ustring_gsub_mgr {
}
}
Keyval[] rslts = core.Interpreter().CallFunction(repl_func.Id(), luacbk_args);
tmp_bfr.Add_str_u8(Scrib_kv_utl_.Val_to_str(rslts, 0));
if (rslts.length > 0) { // ArrayIndex check
Object rslt_obj = rslts[0].Val(); // 0th idx has result
tmp_bfr.Add_str_u8(Object_.Xto_str_strict_or_empty(rslt_obj)); // NOTE: always convert to String; rslt_obj can be int; PAGE:en.d:seven DATE:2016-04-27
}
break;
}
default: throw Err_.new_unhandled(repl_tid);

View File

@@ -56,6 +56,11 @@ public class Scrib_lib_ustring__gsub__tst {
Exec_gsub("ab", ".", -1, proc_root.To_scrib_lua_proc(), "ab;2"); // fails if "ab;4"
Tfds.Eq_str("0;1;2;0;1;2;", bfr.To_str_and_clear()); // fails if "0;1;1;1"
}
@Test public void Replace__proc__number() { // PURPOSE:handle replace-as-number in gproc; PAGE:en.d:seven; DATE:2016-04-27
Mock_proc__number proc = new Mock_proc__number(0);
fxt.Init__cbk(proc);
Exec_gsub("ab", ".", -1, proc.To_scrib_lua_proc(), "12;2"); // fails if "ab;4"
}
@Test public void Regx__int() { // PURPOSE: do not fail if integer is passed in for @regx; PAGE:en.d:λύω DATE:2014-09-02
Exec_gsub("abcd", 1 , -1, "A" , "abcd;0");
}
@@ -102,3 +107,10 @@ class Mock_proc__recursive extends Mock_proc_fxt { private final Mock_scrib_f
return args;
}
}
class Mock_proc__number extends Mock_proc_fxt { private int counter = 0;
public Mock_proc__number(int id) {super(id, "number");}
@Override public Keyval[] Exec_by_scrib(Keyval[] args) {
args[0].Val_(++counter); // set replace-val to int
return args;
}
}