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:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.categorytrees; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.xowa.htmls.core.htmls.utls.*;
|
||||
public class Categorytree_func extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_categorytree;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Categorytree_func().Name_(name);}
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
byte[] argx = Eval_argx(ctx, src, caller, self); if (argx == null) return;
|
||||
Xow_wiki wiki = ctx.Wiki();
|
||||
Xoa_ttl ctg_ttl = wiki.Ttl_parse(gplx.xowa.wikis.nss.Xow_ns_.Tid__category, argx); if (ctg_ttl == null) return; // ignore bad titles; EX: {{#categorytree:<>}}
|
||||
gplx.xowa.parsers.lnkis.Xop_lnki_wkr_.Write_lnki(bfr, ctg_ttl, true);
|
||||
}
|
||||
public static final Categorytree_func Instance = new Categorytree_func(); Categorytree_func() {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.categorytrees; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Categorytree_func_tst {
|
||||
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse__tmpl_to_html("{{#categorytree:A B}}", "<a href='/wiki/Category:A_B'>Category:A B</a>");
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class Geoc_isin_func_tst {
|
||||
}
|
||||
}
|
||||
class Geoc_isin_func_fxt {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
public void Reset() {
|
||||
fxt.Reset();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa
|
||||
import gplx.core.brys.fmtrs.*; import gplx.core.strings.*; import gplx.core.consoles.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.apps.progs.*;
|
||||
public class Xof_math_mgr implements GfoInvkAble {
|
||||
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
|
||||
private Xoae_app app;
|
||||
public Process_adp Cmd_convert_tex_to_dvi() {return cmd_convert_tex_to_dvi;} private Process_adp cmd_convert_tex_to_dvi = new Process_adp();
|
||||
public Process_adp Cmd_convert_dvi_to_png() {return cmd_convert_dvi_to_png;} private Process_adp cmd_convert_dvi_to_png = new Process_adp();
|
||||
@@ -29,11 +30,11 @@ public class Xof_math_mgr implements GfoInvkAble {
|
||||
cmd_convert_dvi_to_png = app_mgr.App_convert_dvi_to_png();
|
||||
}
|
||||
private Io_url Make_math_dir(String wiki_key) {return app.Fsys_mgr().Root_dir().GenSubDir_nest("file", wiki_key, "math");}
|
||||
public Xof_math_html_wtr Html_wtr() {return html_wtr;} private final Xof_math_html_wtr html_wtr = new Xof_math_html_wtr();
|
||||
public Xof_math_html_wtr Html_wtr() {return html_wtr;} private final Xof_math_html_wtr html_wtr = new Xof_math_html_wtr();
|
||||
public void Make_itm(Xof_math_itm rv, String wiki_key, byte[] math_bry) {
|
||||
Io_url math_dir = Make_math_dir(wiki_key);
|
||||
math_bry = app.Math_subst_regy().Subst(math_bry);
|
||||
String md5 = gplx.core.security.HashAlgo_.Md5.CalcHash(Console_adp_.Noop, gplx.core.ios.IoStream_.ary_(math_bry));
|
||||
String md5 = md5_hash.Hash_bry_as_str(math_bry);
|
||||
Io_url png_fil = Make_png_fil(math_dir, md5);
|
||||
rv.Ctor(math_bry, md5, png_fil);
|
||||
}
|
||||
|
||||
@@ -241,6 +241,7 @@ public class Pf_func_ {
|
||||
, Xol_kwd_grp_.Id_rev_revisionsize
|
||||
, Xol_kwd_grp_.Id_pagebanner
|
||||
, Xol_kwd_grp_.Id_rev_protectionexpiry
|
||||
, Xol_kwd_grp_.Id_categorytree
|
||||
};
|
||||
public static Xot_defn Get_prototype(int id) {
|
||||
switch (id) {
|
||||
@@ -408,6 +409,7 @@ public class Pf_func_ {
|
||||
case Xol_kwd_grp_.Id_insider: return gplx.xowa.xtns.insiders.Insider_func.Instance;
|
||||
|
||||
case Xol_kwd_grp_.Id_massMessage_target: return gplx.xowa.xtns.massMessage.Message_target_func.Instance;
|
||||
case Xol_kwd_grp_.Id_categorytree: return gplx.xowa.xtns.categorytrees.Categorytree_func.Instance;
|
||||
|
||||
case Xol_kwd_grp_.Id_pendingChangeLevel: return gplx.xowa.xtns.flaggedRevs.Pending_change_level_func.Instance;
|
||||
case Xol_kwd_grp_.Id_pagesUsingPendingChanges: return gplx.xowa.xtns.flaggedRevs.Pages_using_pending_changes_func.Instance;
|
||||
|
||||
@@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
public class Pfunc_if_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void If_y() {fxt.Test_parse_tmpl_str_test("{{#if:1|a|b}}" , "{{test}}" , "a");}
|
||||
@Test public void If_n() {fxt.Test_parse_tmpl_str_test("{{#if:|a|b}}" , "{{test}}" , "b");}
|
||||
@Test public void If_n() {fxt.Test_parse_tmpl_str_test("{{#if:|a|b}}" , "{{test}}" , "b");}
|
||||
@Test public void If_n_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b}}" , "{{test}}" , "b");}
|
||||
@Test public void If_y_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b \n}}" , "{{test}}" , "b");}
|
||||
@Test public void If_y_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b \n}}" , "{{test}}" , "b");}
|
||||
@Test public void If_y_ws1() {fxt.Test_parse_tmpl_str_test("{{#if: |a|{{#if: |a|b}}\n}}" , "{{test}}" , "b");}
|
||||
@Test public void If_prm_n() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{{1}}}|b}}" , "{{test}}" , "b");}
|
||||
@Test public void If_prm_y() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{{1}}}|b}}" , "{{test|a}}" , "a");}
|
||||
@@ -31,7 +31,7 @@ public class Pfunc_if_tst {
|
||||
@Test public void If_prm_nest_0() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test}}" , "c");}
|
||||
@Test public void If_prm_nest_1() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test|1}}" , "b");}
|
||||
@Test public void If_prm_nest_2() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test|1|2}}" , "a");}
|
||||
@Test public void If_ignore_key() {fxt.Test_parse_tmpl_str_test("{{#if:|<i id=1|<i id=2}}" , "{{test}}" , "<i id=2");}
|
||||
@Test public void If_ignore_key() {fxt.Test_parse_tmpl_str_test("{{#if:|<i id=1|<i id=2}}" , "{{test}}" , "<i id=2");}
|
||||
@Test public void If_newline() { // PURPOSE: new_line in comments; WP:[[redirect-distinguish|a|b]]
|
||||
fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last
|
||||
( "{{#if:1<!--"
|
||||
|
||||
@@ -38,9 +38,9 @@ public class Pfunc_scrib_lib implements Scrib_lib {
|
||||
}
|
||||
private static final int Proc_expr = 0;
|
||||
public static final String Invk_expr = "expr";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_expr);
|
||||
private static final String[] Proc_names = String_.Ary(Invk_expr);
|
||||
public boolean Expr(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] expr_bry = args.Pull_bry(0);
|
||||
byte[] expr_bry = args.Xstr_bry_or_null(0); // NOTE: some modules will pass in an int; PAGE:en.w:531_BC DATE:2016-04-29
|
||||
Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b128();
|
||||
Pfunc_expr.Evaluate(tmp_bfr, core.Ctx(), expr_bry);
|
||||
String expr_rslt = tmp_bfr.To_str_and_rls();
|
||||
|
||||
@@ -28,6 +28,9 @@ public class Pfunc_scrib_lib_tst {
|
||||
@Test public void Expr__pass() {
|
||||
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("1 + 2") , "3");
|
||||
}
|
||||
@Test public void Expr__int() {
|
||||
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary(3) , "3"); // int should not cause class cast error; PAGE:en.w:531_BC; DATE:2016-04-29
|
||||
}
|
||||
@Test public void Expr__fail() { // PURPOSE: if bad input don't throw error; return error message; PAGE:es.w:Freer_(Texas) DATE:2015-07-28
|
||||
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("fail") , "<strong class=\"error\">Expression error: Unrecognised word \"fail\"</strong>");
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
|
||||
Xox_mgr_base.Xtn_write_escape(app, bfr, code);
|
||||
bfr.Add(Xoh_consts.Pre_end);
|
||||
}
|
||||
private static final gplx.core.security.Hash_algo sha1_hash = gplx.core.security.Hash_algo_.New__sha1();
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
Xowe_wiki wiki = ctx.Wiki(); Xoae_page page = ctx.Page();
|
||||
Score_xtn_mgr score_xtn = (Score_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Score_xtn_mgr.XTN_KEY);
|
||||
@@ -68,7 +69,7 @@ public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
|
||||
if (ly_process.Exe_exists() == Bool_.N_byte) {Html_write_code_as_pre(bfr, app); return;}
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
tmp_bfr.Add(code).Add_byte_pipe().Add_int_bool(lang_is_abc).Add_byte_pipe().Add_int_bool(code_is_raw);
|
||||
sha1 = gplx.core.security.HashAlgo_.Sha1.Calc_hash_bry(tmp_bfr.To_bry_and_rls()); // NOTE: MW transforms to base32; for now, keep sha1 as raw
|
||||
sha1 = sha1_hash.Hash_bry_as_bry(tmp_bfr.To_bry_and_rls()); // NOTE: MW transforms to base32; for now, keep sha1 as raw
|
||||
sha1_prefix = String_.new_a7(sha1, 0, 8);
|
||||
output_dir = app.Fsys_mgr().File_dir().GenSubDir_nest(wiki.Domain_str(), "lilypond", Char_.To_str(sha1[0]), Char_.To_str(sha1[1]), String_.new_a7(sha1)); // NOTE: MW also adds an extra level for 8-len; EX: /.../sha1_32_len/sha1_8_len/
|
||||
png_file = output_dir.GenSubFil(sha1_prefix + ".png");
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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.*;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.p
|
||||
public class Tabber_xnde implements Xox_xnde {
|
||||
private byte[] id;
|
||||
private Tabber_tab_itm[] tab_itms_ary;
|
||||
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
@@ -28,7 +29,7 @@ public class Tabber_xnde implements Xox_xnde {
|
||||
// split on "|-|"; EX: "A|-|B" -> tab_1='A'; tab_2='B'
|
||||
List_adp tab_itms_list = List_adp_.new_();
|
||||
byte[] xnde_body = Xox_xnde_.Extract_body_or_null(src, xnde); if (xnde_body == null) return;
|
||||
this.id = Id_test == null ? gplx.core.security.HashAlgo_.Md5.Calc_hash_bry(xnde_body) : Id_test;
|
||||
this.id = Id_test == null ? md5_hash.Hash_bry_as_bry(xnde_body) : Id_test;
|
||||
byte[][] tab_itms = Bry_split_.Split(xnde_body, Spr__tab_itms);
|
||||
for (int i = 0; i < tab_itms.length; ++i) {
|
||||
byte[] tab_itm = tab_itms[i];
|
||||
|
||||
Reference in New Issue
Block a user