mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.4.1'
This commit is contained in:
@@ -26,7 +26,7 @@ public abstract class Xox_mgr_base implements Xox_mgr {
|
||||
public boolean Enabled() {return enabled;} private boolean enabled;
|
||||
@gplx.Virtual public boolean Enabled_default() {return true;}
|
||||
public void Enabled_y_() {enabled = true; enabled_manually = true;} public void Enabled_n_() {enabled = false; enabled_manually = true;} // TEST:
|
||||
public void Enabled_(boolean v) {enabled = v;}
|
||||
@gplx.Virtual public void Enabled_(boolean v) {enabled = v;}
|
||||
public boolean Enabled_manually() {return enabled_manually;} private boolean enabled_manually;
|
||||
public abstract Xox_mgr Xtn_clone_new();
|
||||
@gplx.Virtual public void Xtn_ctor_by_app(Xoae_app app) {}
|
||||
@@ -36,7 +36,7 @@ public abstract class Xox_mgr_base implements Xox_mgr {
|
||||
|
||||
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled)) return Yn.To_str(enabled);
|
||||
else if (ctx.Match(k, Invk_enabled_)) {enabled = m.ReadYn("v"); enabled_manually = true;}
|
||||
else if (ctx.Match(k, Invk_enabled_)) {this.Enabled_(m.ReadYn("v")); enabled_manually = true;}
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Cite_xtn_mgr extends Xox_mgr_base {
|
||||
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("cite");
|
||||
// public byte[] Group_default_name() {return group_default_name;} private byte[] group_default_name = Bry_.new_a7("lower-alpha");
|
||||
public static byte[] Group_default_name() {return group_default_name;} private static byte[] group_default_name = Bry_.new_a7("lower-alpha");
|
||||
@Override public Xox_mgr Xtn_clone_new() {return new Cite_xtn_mgr();}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_group_default_name)) return String_.new_u8(group_default_name);
|
||||
@@ -28,4 +26,6 @@ public class Cite_xtn_mgr extends Xox_mgr_base {
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_group_default_name = "group_default_name", Invk_group_default_name_ = "group_default_name_";
|
||||
|
||||
public static byte[] Group_default_name() {return group_default_name;} private static byte[] group_default_name = Bry_.new_a7("lower-alpha");
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
|
||||
public class Ref_html_wtr {
|
||||
private final Xoh_ref_list_fmtr grp_list_fmtr = new Xoh_ref_list_fmtr();
|
||||
private final Bfr_arg__bry_fmtr grp_key_fmtr = Bfr_arg_.New_bry_fmtr__null(), itm_id_fmtr = Bfr_arg_.New_bry_fmtr__null(), grp_id_fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
public Ref_html_wtr(Xowe_wiki wiki) {
|
||||
cfg = Ref_html_wtr_cfg.new_();
|
||||
}
|
||||
@@ -37,7 +38,7 @@ public class Ref_html_wtr {
|
||||
? itm.Idx_major() + 1
|
||||
: (Object)grp_key_fmtr.Set(cfg.Itm_grp_text(), itm.Group(), itm.Idx_major() + 1)
|
||||
);
|
||||
} private Bfr_arg__bry_fmtr grp_key_fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
}
|
||||
public Ref_html_wtr_cfg Cfg() {return cfg;} private Ref_html_wtr_cfg cfg;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
cfg.Init_by_wiki(wiki);
|
||||
@@ -51,12 +52,12 @@ public class Ref_html_wtr {
|
||||
else
|
||||
return itm_id_fmtr.Set(cfg.Itm_id_key_many(), itm.Name(), itm.Idx_major());
|
||||
}
|
||||
} private Bfr_arg__bry_fmtr itm_id_fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
}
|
||||
private Bfr_arg Grp_id(Ref_nde itm) {
|
||||
return itm.Name() == Bry_.Empty // name is blank >>> uid
|
||||
? grp_id_fmtr.Set(cfg.Grp_id_uid(), itm.Uid())
|
||||
: grp_id_fmtr.Set(cfg.Grp_id_key(), itm.Name(), itm.Idx_major());
|
||||
} private Bfr_arg__bry_fmtr grp_id_fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
}
|
||||
private int List_len(Ref_nde itm) {
|
||||
int len = itm.Related_len();
|
||||
int rv = len;
|
||||
|
||||
@@ -17,14 +17,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_grp {
|
||||
private List_adp lsts = List_adp_.New();
|
||||
private final List_adp lsts = List_adp_.New();
|
||||
private int lst_idx;
|
||||
public Ref_itm_grp(byte[] grp_name) {this.grp_name = grp_name;}
|
||||
public byte[] Grp_name() {return grp_name;} private byte[] grp_name;
|
||||
public int Grp_seal() {
|
||||
if (lst_idx == lsts.Count()) // NOTE: lst_idx == lsts.Count() if there are no itms in lst; need to add placeholder list anyway; <references> nodes has a List_index, which will call lsts.Get_at(); see Empty_group_before_ref
|
||||
lsts.Add(new Ref_itm_lst(grp_name));
|
||||
return lst_idx++;
|
||||
} int lst_idx;
|
||||
}
|
||||
public int Lsts_len() {return lsts.Count();}
|
||||
public Ref_itm_lst Lsts_get_at(int i) {return i < lsts.Count() ? (Ref_itm_lst)lsts.Get_at(i) : null;} // NOTE: null can be returned; see Infobox planet; w:Mars
|
||||
public void Lsts_add(byte[] itm_name, byte[] follow, Ref_nde itm) {
|
||||
|
||||
@@ -17,8 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_lst {
|
||||
public Ref_itm_lst(byte[] grp_name) {this.grp_name = grp_name;}
|
||||
byte[] grp_name; int idx_major_last = 0;
|
||||
private final Hash_adp hash = Hash_adp_bry.cs();
|
||||
private final List_adp list = List_adp_.New();
|
||||
private int idx_major_last = 0;
|
||||
// private byte[] grp_name;
|
||||
public Ref_itm_lst(byte[] grp_name) {} //this.grp_name = grp_name;
|
||||
public int Itms_len() {return list.Count();}
|
||||
public Ref_nde Itms_get_at(int i) {return (Ref_nde)list.Get_at(i);}
|
||||
public void Itms_add(byte[] itm_name, byte[] follow, Ref_nde itm) {
|
||||
@@ -59,5 +62,4 @@ public class Ref_itm_lst {
|
||||
list.Clear();
|
||||
idx_major_last = 0;
|
||||
}
|
||||
Hash_adp hash = Hash_adp_bry.cs(); List_adp list = List_adp_.New();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_mgr {
|
||||
private Hash_adp_bry grps = Hash_adp_bry.cs(); // CASE_MATCH:changed from ci; DATE:2014-07-07
|
||||
private Ref_itm_grp grp_default = new Ref_itm_grp(Bry_.Empty);
|
||||
private final Hash_adp_bry grps = Hash_adp_bry.cs(); // CASE_MATCH:changed from ci; DATE:2014-07-07
|
||||
private final Ref_itm_grp grp_default = new Ref_itm_grp(Bry_.Empty);
|
||||
private int uid_last;
|
||||
public boolean References__recursing() {return references__recursing;} public void References__recursing_(boolean v) {references__recursing = v;} private boolean references__recursing;
|
||||
public Ref_itm_lst Lst_get(byte[] grp_name, int lst_idx) {
|
||||
|
||||
@@ -59,7 +59,6 @@ public class Ref_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
|
||||
html_wtr.Ref_wtr().Xnde_ref(hctx, bfr, src, xnde);
|
||||
}
|
||||
private static final Ref_nde[] Ary_empty = new Ref_nde[0];
|
||||
public Ref_nde[] Related() {return related;} Ref_nde[] related = Ary_empty;
|
||||
public int Related_len() {return related_len;} private int related_len;
|
||||
public Ref_nde Related_get(int i) {return related[i];}
|
||||
@@ -74,6 +73,7 @@ public class Ref_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
}
|
||||
public static final int Idx_minor_follow = -2;
|
||||
public static final byte Xatr_id_name = 0, Xatr_id_group = 1, Xatr_id_follow = 2;
|
||||
private static final Ref_nde[] Ary_empty = new Ref_nde[0];
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_obj("name", Byte_obj_val.new_(Ref_nde.Xatr_id_name))
|
||||
.Add_str_obj("group", Byte_obj_val.new_(Ref_nde.Xatr_id_group))
|
||||
|
||||
@@ -23,13 +23,14 @@ public class Flagged_revs_lib implements Scrib_lib {
|
||||
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_lib Core_(Scrib_core v) {this.core = v; return this;} // TEST:
|
||||
public Scrib_lib Clone_lib(Scrib_core core) {return new Flagged_revs_lib();}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
this.core = core;
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, core.App().Fsys_mgr().Bin_xtns_dir().GenSubFil_nest("FlaggedRevs", "scribunto", "mw.ext.FlaggedRevs.lua"));
|
||||
return mod;
|
||||
}
|
||||
public Scrib_proc_mgr Procs() {return procs;} private final 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_getStabilitySettings: return GetStabilitySettings(args, rslt);
|
||||
@@ -38,7 +39,7 @@ public class Flagged_revs_lib implements Scrib_lib {
|
||||
}
|
||||
private static final int Proc_getStabilitySettings = 0;
|
||||
public static final String Invk_getStabilitySettings = "getStabilitySettings";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_getStabilitySettings);
|
||||
private static final String[] Proc_names = String_.Ary(Invk_getStabilitySettings);
|
||||
public boolean GetStabilitySettings(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] page_name = args.Cast_bry_or_null(0);
|
||||
Xoa_ttl page_ttl = null;
|
||||
|
||||
@@ -20,29 +20,29 @@ import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.vnts.*;
|
||||
public class Xof_math_html_wtr {
|
||||
private Xof_math_itm tmp_math_itm = new Xof_math_itm();
|
||||
private Bry_fmtr math_fmtr_latex = Bry_fmtr.new_("<img id='xowa_math_img_~{math_idx}' src='' width='' height=''/><span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>", "math_idx", "math_text");
|
||||
private Bry_fmtr math_fmtr_mathjax = Bry_fmtr.new_("<span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>", "math_idx", "math_text");
|
||||
private final Bry_fmtr math_fmtr_latex = Bry_fmtr.new_("<img id='xowa_math_img_~{math_idx}' src='' width='' height=''/><span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>", "math_idx", "math_text");
|
||||
private final Bry_fmtr math_fmtr_mathjax = Bry_fmtr.new_("<span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>", "math_idx", "math_text");
|
||||
public void Write(Xoh_html_wtr wtr, Xop_ctx ctx, Xoh_wtr_ctx opts, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
Xoae_app app = ctx.App(); Xowe_wiki wiki = ctx.Wiki(); Xoae_page page = ctx.Page();
|
||||
boolean renderer_is_latex = !app.File_mgr().Math_mgr().Renderer_is_mathjax();
|
||||
byte[] math_bry = Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
Bry_bfr tmp_bfr = app.Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
math_bry = Escape_tex(tmp_bfr, !renderer_is_latex, math_bry);
|
||||
byte[] math_bry_clean = wiki.Html_mgr().Js_cleaner().Clean(wiki, math_bry, 0, math_bry.length); // check for js;
|
||||
if (math_bry_clean != null) math_bry = math_bry_clean; // js found; use clean version; DATE:2013-08-26
|
||||
boolean enabled = app.File_mgr().Math_mgr().Enabled();
|
||||
if (renderer_is_latex && app.File_mgr().Math_mgr().Find_itm(tmp_math_itm, page.Wiki().Domain_str(), math_bry)) {
|
||||
Xof_math_itm math_itm = ctx.Tmp_mgr().Math_itm();
|
||||
if (renderer_is_latex && app.File_mgr().Math_mgr().Find_itm(math_itm, page.Wiki().Domain_str(), math_bry)) {
|
||||
bfr.Add(Xoh_consts.Img_bgn);
|
||||
bfr.Add_str_u8(tmp_math_itm.Png_url().To_http_file_str());
|
||||
bfr.Add_str_u8(math_itm.Png_url().To_http_file_str());
|
||||
bfr.Add(Xoh_consts.__inline_quote);
|
||||
}
|
||||
else
|
||||
Write_for_mathjax(bfr, page, enabled, renderer_is_latex, math_bry, tmp_bfr);
|
||||
Write_for_mathjax(bfr, page, enabled, renderer_is_latex, math_bry, tmp_bfr, math_itm);
|
||||
}
|
||||
private void Write_for_mathjax(Bry_bfr bfr, Xoae_page page, boolean enabled, boolean renderer_is_latex, byte[] math_bry, Bry_bfr tmp_bfr) {
|
||||
private void Write_for_mathjax(Bry_bfr bfr, Xoae_page page, boolean enabled, boolean renderer_is_latex, byte[] math_bry, Bry_bfr tmp_bfr, Xof_math_itm math_itm) {
|
||||
int id = page.File_math().Count();
|
||||
Xof_math_itm new_math_itm = tmp_math_itm.Clone().Id_(id);
|
||||
Xof_math_itm new_math_itm = math_itm.Clone().Id_(id);
|
||||
Bry_fmtr math_fmtr = renderer_is_latex ? math_fmtr_latex : math_fmtr_mathjax;
|
||||
boolean armor_math = page.Lang().Vnt_mgr().Enabled() && !renderer_is_latex; // REF.MW:LangConverter.php|armourMath
|
||||
if (armor_math) bfr.Add(Vnt_convert_lang.Bry__armor_bgn);
|
||||
|
||||
@@ -43,8 +43,7 @@ public class Pf_func_ {
|
||||
nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, bfr);
|
||||
return bfr.To_bry_and_clear_and_trim();
|
||||
}
|
||||
private static final Number_parser lhs_parser = new Number_parser().Hex_enabled_(true), rhs_parser = new Number_parser().Hex_enabled_(true);
|
||||
public static boolean Eq_(byte[] lhs, byte[] rhs) { // PATCH.PHP: php allows "003" == "3.0"; ASSUME: numbers are either int or int-like decimal; long, float, decimal not supported
|
||||
public static boolean Eq(Xop_ctx ctx, byte[] lhs, byte[] rhs) { // PATCH.PHP: php allows "003" == "3.0"; ASSUME: numbers are either int or int-like decimal; long, float, decimal not supported
|
||||
int lhs_len = lhs.length, rhs_len = rhs.length;
|
||||
boolean rv = true;
|
||||
if (lhs_len == rhs_len) {
|
||||
@@ -58,13 +57,13 @@ public class Pf_func_ {
|
||||
}
|
||||
else if (lhs_len == 0 || rhs_len == 0) // one side is empty String and the other side is String; return false;
|
||||
return false;
|
||||
synchronized (lhs_parser) { // LOCK:static-obj; DATE:2016-07-06
|
||||
lhs_parser.Parse(lhs, 0, lhs_len);
|
||||
if (lhs_parser.Has_err()) return false;
|
||||
rhs_parser.Parse(rhs, 0, rhs_len);
|
||||
if (rhs_parser.Has_err()) return false;
|
||||
return lhs_parser.Has_frac() || rhs_parser.Has_frac() ? lhs_parser.Rv_as_dec().Eq(rhs_parser.Rv_as_dec()) : lhs_parser.Rv_as_int() == rhs_parser.Rv_as_int();
|
||||
}
|
||||
Number_parser lhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_0();
|
||||
Number_parser rhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_1();
|
||||
lhs_parser.Parse(lhs, 0, lhs_len);
|
||||
if (lhs_parser.Has_err()) return false;
|
||||
rhs_parser.Parse(rhs, 0, rhs_len);
|
||||
if (rhs_parser.Has_err()) return false;
|
||||
return lhs_parser.Has_frac() || rhs_parser.Has_frac() ? lhs_parser.Rv_as_dec().Eq(rhs_parser.Rv_as_dec()) : lhs_parser.Rv_as_int() == rhs_parser.Rv_as_int();
|
||||
}
|
||||
public static void Reg(Xow_domain_itm domain_itm, gplx.xowa.langs.funcs.Xol_func_regy func_regy, Xol_lang_itm lang) {
|
||||
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
|
||||
|
||||
@@ -16,25 +16,24 @@ 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.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
class Func_tkn_stack {
|
||||
public void Clear() {stack_len = 0;}
|
||||
public int Len() {return stack_len;}
|
||||
public Func_tkn GetLast() {return stack_len == 0 ? null : stack[stack_len - 1];}
|
||||
private Func_tkn[] ary = new Func_tkn[0]; private int len = 0, max = 0;
|
||||
public void Clear() {len = 0;}
|
||||
public int Len() {return len;}
|
||||
public Func_tkn Get_at_last() {return len == 0 ? null : ary[len - 1];}
|
||||
public Func_tkn Pop() {
|
||||
int stack_len_new = stack_len - 1;
|
||||
Func_tkn rv = stack[stack_len_new];
|
||||
stack_len = stack_len_new;
|
||||
int new_len = len - 1;
|
||||
Func_tkn rv = ary[new_len];
|
||||
len = new_len;
|
||||
return rv;
|
||||
}
|
||||
public void Push(Func_tkn v) {
|
||||
int stack_len_new = stack_len + 1;
|
||||
if (stack_len_new > stack_max) {
|
||||
stack_max = stack_len_new * 2;
|
||||
stack = (Func_tkn[])Array_.Resize(stack, stack_max);
|
||||
int new_len = len + 1;
|
||||
if (new_len > max) {
|
||||
max = new_len * 2;
|
||||
ary = (Func_tkn[])Array_.Resize(ary, max);
|
||||
}
|
||||
stack[stack_len] = v;
|
||||
stack_len = stack_len_new;
|
||||
ary[len] = v;
|
||||
len = new_len;
|
||||
}
|
||||
Func_tkn[] stack = new Func_tkn[0]; int stack_len = 0, stack_max = 0;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class Pfunc_expr extends Pf_func_base {
|
||||
Evaluate(bfr, ctx, val_dat_ary);
|
||||
}
|
||||
public static boolean Evaluate(Bry_bfr bfr, Xop_ctx ctx, byte[] expr) {
|
||||
Pfunc_expr_shunter shunter = ctx.Tmp_mgr().Expr_shunter();
|
||||
Decimal_adp rslt = shunter.Evaluate(ctx, expr); // NOTE: php uses "float" but really is a double; http://www.php.net/manual/en/language.types.float.php
|
||||
if (rslt == Pfunc_expr_shunter.Null_rslt) {
|
||||
bfr.Add_bfr_and_preserve(shunter.Err());
|
||||
@@ -36,11 +37,10 @@ public class Pfunc_expr extends Pf_func_base {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private static Pfunc_expr_shunter shunter = Pfunc_expr_shunter.Instance;
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_xtn_expr;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_expr().Name_(name);}
|
||||
}
|
||||
class Pfunc_expr_msg {
|
||||
public static final Gfo_msg_grp Nde = Gfo_msg_grp_.new_(Xoa_app_.Nde, "expr");
|
||||
public static final Gfo_msg_itm Unknown = Gfo_msg_itm_.new_warn_(Nde, "unknown", "unknown");
|
||||
public static final Gfo_msg_grp Nde = Gfo_msg_grp_.new_(Xoa_app_.Nde, "expr");
|
||||
public static final Gfo_msg_itm Unknown = Gfo_msg_itm_.new_warn_(Nde, "unknown", "unknown");
|
||||
}
|
||||
|
||||
@@ -20,12 +20,11 @@ import gplx.core.btries.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Pfunc_expr_shunter {
|
||||
private Btrie_fast_mgr trie = expression_(); private final Btrie_rv trv = new Btrie_rv();
|
||||
Val_stack val_stack = new Val_stack();
|
||||
Func_tkn_stack prc_stack = new Func_tkn_stack();
|
||||
public static final Decimal_adp Null_rslt = null;
|
||||
private final Object thread_lock = new Object();
|
||||
public Bry_bfr Err() {return err_bfr;} Bry_bfr err_bfr = Bry_bfr_.New();
|
||||
private final Btrie_fast_mgr trie = expression_(); private final Btrie_rv trv = new Btrie_rv();
|
||||
private final Val_stack val_stack = new Val_stack();
|
||||
private final Func_tkn_stack prc_stack = new Func_tkn_stack();
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_();
|
||||
public Bry_bfr Err() {return err_bfr;} private final Bry_bfr err_bfr = Bry_bfr_.New();
|
||||
public Decimal_adp Err_set(Xop_ctx ctx, int msgId) {return Err_set(ctx, msgId, Bry_.Empty);}
|
||||
public Decimal_adp Err_set(Xop_ctx ctx, int msg_id, byte[] arg) {
|
||||
byte[] msg_val = ctx.Wiki().Msg_mgr().Val_by_id(msg_id);
|
||||
@@ -33,136 +32,137 @@ public class Pfunc_expr_shunter {
|
||||
tmp_fmtr.Fmt_(msg_val).Bld_bfr_one(err_bfr, arg);
|
||||
err_bfr.Add(Err_end_ary);
|
||||
return Null_rslt;
|
||||
} static final byte[] Err_bgn_ary = Bry_.new_a7("<strong class=\"error\">"), Err_end_ary = Bry_.new_a7("</strong>"); Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_();
|
||||
}
|
||||
public void Rslt_set(byte[] bry) {
|
||||
err_bfr.Add(bry);
|
||||
}
|
||||
public Decimal_adp Evaluate(Xop_ctx ctx, byte[] src) { // REF.MW: Expr.php
|
||||
synchronized (thread_lock) {
|
||||
int src_len = src.length; if (src_len == 0) return Null_rslt;
|
||||
int cur_pos = 0; byte cur_byt = src[0];
|
||||
boolean mode_expr = true; Func_tkn prv_prc = null;
|
||||
val_stack.Clear(); prc_stack.Clear();
|
||||
while (true) {
|
||||
// can't think of a way for this to happen; note that operators will automatically push values/operators off stack that are lower; can't get up to 100
|
||||
// if (val_stack.Len() > 100 || prc_stack.Len() > 100) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_err__stack_exhausted);
|
||||
Object o = trie.Match_at_w_b0(trv, cur_byt, src, cur_pos, src_len);
|
||||
int bgn_pos = cur_pos;
|
||||
if (o == null) { // letter or unknown symbol
|
||||
while (cur_pos < src_len) {
|
||||
byte b = src[cur_pos++];
|
||||
if (Byte_ascii.Is_ltr(b))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unrecognised_word, Bry_.Mid(src, bgn_pos, cur_pos));
|
||||
int src_len = src.length; if (src_len == 0) return Null_rslt;
|
||||
int cur_pos = 0; byte cur_byt = src[0];
|
||||
boolean mode_expr = true; Func_tkn prv_prc = null;
|
||||
val_stack.Clear(); prc_stack.Clear();
|
||||
while (true) {
|
||||
// can't think of a way for this to happen; note that operators will automatically push values/operators off stack that are lower; can't get up to 100
|
||||
// if (val_stack.Len() > 100 || prc_stack.Len() > 100) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_err__stack_exhausted);
|
||||
Object o = trie.Match_at_w_b0(trv, cur_byt, src, cur_pos, src_len);
|
||||
int bgn_pos = cur_pos;
|
||||
if (o == null) { // letter or unknown symbol
|
||||
while (cur_pos < src_len) {
|
||||
byte b = src[cur_pos++];
|
||||
if (Byte_ascii.Is_ltr(b))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
else {
|
||||
Expr_tkn t = (Expr_tkn)o;
|
||||
cur_pos = trv.Pos();
|
||||
switch (t.Tid()) {
|
||||
case Expr_tkn_.Tid_space: break;
|
||||
case Expr_tkn_.Tid_number:
|
||||
if (!mode_expr) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_number);
|
||||
int numBgn = cur_pos - 1;
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
if (cur_pos == src_len) break;
|
||||
switch (src[cur_pos]) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Dot:
|
||||
++cur_pos;
|
||||
break;
|
||||
default: loop = false; break;
|
||||
}
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unrecognised_word, Bry_.Mid(src, bgn_pos, cur_pos));
|
||||
}
|
||||
else {
|
||||
Expr_tkn t = (Expr_tkn)o;
|
||||
cur_pos = trv.Pos();
|
||||
switch (t.Tid()) {
|
||||
case Expr_tkn_.Tid_space: break;
|
||||
case Expr_tkn_.Tid_number:
|
||||
if (!mode_expr) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_number);
|
||||
int numBgn = cur_pos - 1;
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
if (cur_pos == src_len) break;
|
||||
switch (src[cur_pos]) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Dot:
|
||||
++cur_pos;
|
||||
break;
|
||||
default: loop = false; break;
|
||||
}
|
||||
Decimal_adp num = Null_rslt;
|
||||
try {num = Bry_.To_decimal(src, numBgn, cur_pos);}
|
||||
catch (Exception exc) {
|
||||
// NOTE: PATCH.PHP: 65.5.5 can evaluate to 65.5; EX "{{Geological eras|-600|height=2|border=none}}" eventually does "|10-to={{#ifexpr:{{{1|-4567}}}<-65.5|-65.5|{{{1}}}}}.5" which is 65.5.5
|
||||
Err_.Noop(exc);
|
||||
int dot_count = 0;
|
||||
for (int i = numBgn; i < cur_pos; i++) {
|
||||
if (src[i] == Byte_ascii.Dot) {
|
||||
switch (dot_count) {
|
||||
case 0: dot_count = 1; break;
|
||||
case 1:
|
||||
try {
|
||||
num = Bry_.To_decimal(src, numBgn, i);
|
||||
}
|
||||
catch (Exception exc_inner) {Err_.Noop(exc_inner);}
|
||||
break;
|
||||
}
|
||||
}
|
||||
Decimal_adp num = Null_rslt;
|
||||
try {num = Bry_.To_decimal(src, numBgn, cur_pos);}
|
||||
catch (Exception exc) {
|
||||
// NOTE: PATCH.PHP: 65.5.5 can evaluate to 65.5; EX "{{Geological eras|-600|height=2|border=none}}" eventually does "|10-to={{#ifexpr:{{{1|-4567}}}<-65.5|-65.5|{{{1}}}}}.5" which is 65.5.5
|
||||
Err_.Noop(exc);
|
||||
int dot_count = 0;
|
||||
for (int i = numBgn; i < cur_pos; i++) {
|
||||
if (src[i] == Byte_ascii.Dot) {
|
||||
switch (dot_count) {
|
||||
case 0: dot_count = 1; break;
|
||||
case 1:
|
||||
try {
|
||||
num = Bry_.To_decimal(src, numBgn, i);
|
||||
}
|
||||
catch (Exception exc_inner) {Err_.Noop(exc_inner);}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (num == null) return Null_rslt;
|
||||
}
|
||||
val_stack.Push(num);
|
||||
mode_expr = false;
|
||||
break;
|
||||
case Expr_tkn_.Tid_paren_lhs:
|
||||
if (!mode_expr) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_operator, Bry_.new_a7("("));
|
||||
prc_stack.Push((Func_tkn)t);
|
||||
break;
|
||||
case Expr_tkn_.Tid_operator:
|
||||
Func_tkn cur_prc = (Func_tkn)t;
|
||||
if (Byte_ascii.Is_ltr(cur_byt)) {
|
||||
int nxt_pos = Bry_find_.Find_fwd_while_letter(src, cur_pos, src_len);
|
||||
if (nxt_pos > cur_pos)
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unrecognised_word, Bry_.Mid(src, bgn_pos, nxt_pos));
|
||||
}
|
||||
if (cur_prc.Func_is_const()) { // func is "pi" or "e"; DATE:2014-03-01
|
||||
if (mode_expr) { // number expected; just call Calc (which will place value on stack)
|
||||
cur_prc.Calc(ctx, this, val_stack);
|
||||
break;
|
||||
}
|
||||
else // operator expected; fail b/c pi / e is not an operator;
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_number);
|
||||
}
|
||||
if (mode_expr) { // NOTE: all the GetAlts have higher precedence; "break;" need to skip evaluation below else will fail for --1
|
||||
Func_tkn alt_prc = cur_prc.GetAlt();
|
||||
prc_stack.Push(alt_prc);
|
||||
if (num == null) return Null_rslt;
|
||||
}
|
||||
val_stack.Push(num);
|
||||
mode_expr = false;
|
||||
break;
|
||||
case Expr_tkn_.Tid_paren_lhs:
|
||||
if (!mode_expr) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_operator, Bry_.new_a7("("));
|
||||
prc_stack.Push((Func_tkn)t);
|
||||
break;
|
||||
case Expr_tkn_.Tid_operator:
|
||||
Func_tkn cur_prc = (Func_tkn)t;
|
||||
if (Byte_ascii.Is_ltr(cur_byt)) {
|
||||
int nxt_pos = Bry_find_.Find_fwd_while_letter(src, cur_pos, src_len);
|
||||
if (nxt_pos > cur_pos)
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unrecognised_word, Bry_.Mid(src, bgn_pos, nxt_pos));
|
||||
}
|
||||
if (cur_prc.Func_is_const()) { // func is "pi" or "e"; DATE:2014-03-01
|
||||
if (mode_expr) { // number expected; just call Calc (which will place value on stack)
|
||||
cur_prc.Calc(ctx, this, val_stack);
|
||||
break;
|
||||
}
|
||||
prv_prc = prc_stack.GetLast();
|
||||
while (prv_prc != null && (cur_prc.Precedence() <= prv_prc.Precedence())) {
|
||||
if (!prv_prc.Calc(ctx, this, val_stack)) return Null_rslt;
|
||||
prc_stack.Pop();
|
||||
prv_prc = prc_stack.GetLast();
|
||||
}
|
||||
prc_stack.Push(cur_prc);
|
||||
mode_expr = true;
|
||||
break;
|
||||
case Expr_tkn_.Tid_paren_rhs: {
|
||||
prv_prc = prc_stack.GetLast();
|
||||
while (prv_prc != null && prv_prc.Tid() != Expr_tkn_.Tid_paren_lhs) {
|
||||
if (!prv_prc.Calc(ctx, this, val_stack)) return Null_rslt;
|
||||
prc_stack.Pop();
|
||||
prv_prc = prc_stack.GetLast();
|
||||
}
|
||||
if (prv_prc == Paren_bgn_tkn.Instance)
|
||||
prc_stack.Pop();
|
||||
else
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_closing_bracket);
|
||||
mode_expr = false;
|
||||
else // operator expected; fail b/c pi / e is not an operator;
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_number);
|
||||
}
|
||||
if (mode_expr) { // NOTE: all the GetAlts have higher precedence; "break;" need to skip evaluation below else will fail for --1
|
||||
Func_tkn alt_prc = cur_prc.GetAlt();
|
||||
prc_stack.Push(alt_prc);
|
||||
break;
|
||||
}
|
||||
prv_prc = prc_stack.Get_at_last();
|
||||
while (prv_prc != null && (cur_prc.Precedence() <= prv_prc.Precedence())) {
|
||||
if (!prv_prc.Calc(ctx, this, val_stack)) return Null_rslt;
|
||||
prc_stack.Pop();
|
||||
prv_prc = prc_stack.Get_at_last();
|
||||
}
|
||||
prc_stack.Push(cur_prc);
|
||||
mode_expr = true;
|
||||
break;
|
||||
case Expr_tkn_.Tid_paren_rhs: {
|
||||
prv_prc = prc_stack.Get_at_last();
|
||||
while (prv_prc != null && prv_prc.Tid() != Expr_tkn_.Tid_paren_lhs) {
|
||||
if (!prv_prc.Calc(ctx, this, val_stack)) return Null_rslt;
|
||||
prc_stack.Pop();
|
||||
prv_prc = prc_stack.Get_at_last();
|
||||
}
|
||||
if (prv_prc == Paren_bgn_tkn.Instance)
|
||||
prc_stack.Pop();
|
||||
else
|
||||
return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unexpected_closing_bracket);
|
||||
mode_expr = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cur_pos == src_len) break;
|
||||
cur_byt = src[cur_pos];
|
||||
}
|
||||
while (prc_stack.Len() > 0) {
|
||||
Func_tkn cur_prc = prc_stack.Pop();
|
||||
if (cur_prc.Tid() == Expr_tkn_.Tid_paren_lhs) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unclosed_bracket);
|
||||
if (!cur_prc.Calc(ctx, this, val_stack)) return Null_rslt;
|
||||
}
|
||||
return val_stack.Len() == 0 ? Null_rslt : val_stack.Pop(); // HACK: for [[List of Premiers of South Australia by time in office]] and {{#expr:\n{{age in days
|
||||
if (cur_pos == src_len) break;
|
||||
cur_byt = src[cur_pos];
|
||||
}
|
||||
while (prc_stack.Len() > 0) {
|
||||
Func_tkn cur_prc = prc_stack.Pop();
|
||||
if (cur_prc.Tid() == Expr_tkn_.Tid_paren_lhs) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_unclosed_bracket);
|
||||
if (!cur_prc.Calc(ctx, this, val_stack)) return Null_rslt;
|
||||
}
|
||||
return val_stack.Len() == 0 ? Null_rslt : val_stack.Pop(); // HACK: for [[List of Premiers of South Australia by time in office]] and {{#expr:\n{{age in days
|
||||
}
|
||||
private static Btrie_fast_mgr expression_() {
|
||||
|
||||
|
||||
public static final Decimal_adp Null_rslt = null;
|
||||
private static Btrie_fast_mgr expression_() { // changed to instance; DATE:2016-07-20
|
||||
Btrie_fast_mgr rv = Btrie_fast_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; math and expressions
|
||||
Trie_add(rv, new Ws_tkn(Byte_ascii.Space));
|
||||
Trie_add(rv, new Ws_tkn(Byte_ascii.Tab));
|
||||
@@ -221,5 +221,5 @@ public class Pfunc_expr_shunter {
|
||||
return rv;
|
||||
}
|
||||
private static void Trie_add(Btrie_fast_mgr trie, Expr_tkn tkn) {trie.Add(tkn.Val_ary(), tkn);}
|
||||
public static final Pfunc_expr_shunter Instance = new Pfunc_expr_shunter(); Pfunc_expr_shunter() {}
|
||||
private static final byte[] Err_bgn_ary = Bry_.new_a7("<strong class=\"error\">"), Err_end_ary = Bry_.new_a7("</strong>");
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Pfunc_ifeq extends Pf_func_base {
|
||||
int self_args_len = self.Args_len(); if (self_args_len < 2) return; // no equal/not_equal clauses defined; return; EX: {{#if:a}} {{#if:a|b}}
|
||||
byte[] lhs = Eval_argx(ctx, src, caller, self);
|
||||
byte[] rhs = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0);
|
||||
if (Pf_func_.Eq_(lhs, rhs))
|
||||
if (Pf_func_.Eq(ctx, lhs, rhs))
|
||||
bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1));
|
||||
else
|
||||
bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 2));
|
||||
|
||||
@@ -18,7 +18,7 @@ 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_ifeq_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 Ifeq_y() {fxt.Test_parse_tmpl_str_test("{{#ifeq:1|1|a|b}}" , "{{test}}" , "a");}
|
||||
|
||||
@@ -16,30 +16,32 @@ 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.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.core.envs.*; import gplx.core.caches.*;
|
||||
import gplx.xowa.bldrs.wms.apis.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Pfunc_ifexist_mgr {
|
||||
private Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
private Hash_adp regy = Hash_adp_bry.cs();
|
||||
public void Clear() {regy.Clear();}
|
||||
private final Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
public boolean Exists(Xowe_wiki wiki, byte[] raw_bry) {
|
||||
if (Bry_.Len_eq_0(raw_bry)) return false; // return early; NOTE: {{autolink}} can pass in "" (see test)
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, raw_bry); if (ttl == null) return false;
|
||||
byte[] ttl_bry = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
|
||||
Object exists_obj = regy.Get_by(ttl_bry);
|
||||
if (exists_obj != null) return ((Pfunc_ifexist_itm)exists_obj).Exists();
|
||||
Pfunc_ifexist_itm exists_itm = new Pfunc_ifexist_itm(ttl_bry);
|
||||
regy.Add(ttl_bry, exists_itm);
|
||||
byte[] ttl_bry = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
|
||||
|
||||
// try to get from cache
|
||||
Gfo_cache_mgr cache_mgr = wiki.Cache_mgr().Ifexist_cache();
|
||||
Pfunc_ifexist_itm cache_itm = (Pfunc_ifexist_itm)cache_mgr.Get_by_key(ttl_bry);
|
||||
if (cache_itm != null) return cache_itm.Exists();
|
||||
|
||||
cache_itm = new Pfunc_ifexist_itm(ttl_bry);
|
||||
cache_mgr.Add(ttl_bry, cache_itm, 1);
|
||||
db_page.Clear();
|
||||
Xow_ns ttl_ns = ttl.Ns();
|
||||
boolean rv = false;
|
||||
switch (ttl_ns.Id()) {
|
||||
case Xow_ns_.Tid__special: rv = true; break; // NOTE: some pages call for [[Special]]; always return true for now; DATE:2014-07-17
|
||||
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(exists_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
default: rv = Find_ttl_in_db(exists_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(cache_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
default: rv = Find_ttl_in_db(cache_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
}
|
||||
exists_itm.Exists_(rv);
|
||||
cache_itm.Exists_(rv);
|
||||
return rv;
|
||||
}
|
||||
private boolean Find_ttl_in_db(Pfunc_ifexist_itm itm, Xowe_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
|
||||
@@ -73,8 +75,9 @@ public class Pfunc_ifexist_mgr {
|
||||
}
|
||||
}
|
||||
}
|
||||
class Pfunc_ifexist_itm {
|
||||
class Pfunc_ifexist_itm implements Rls_able {
|
||||
public Pfunc_ifexist_itm(byte[] ttl) {this.ttl = ttl;}
|
||||
public byte[] Ttl() {return ttl;} private byte[] ttl;
|
||||
public boolean Exists() {return exists;} public void Exists_(boolean v) {exists = v;} private boolean exists;
|
||||
public void Rls() {}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class Pfunc_ifexist_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {
|
||||
fxt.Reset();
|
||||
fxt.Wiki().Parser_mgr().Ifexist_mgr().Clear();
|
||||
fxt.Wiki().Cache_mgr().Ifexist_cache().Clear();
|
||||
}
|
||||
@Test public void Basic_pass() {fxt.Test_parse_tmpl_str_test("{{#ifexist: Abc | exists | doesn't exist }}" , "{{test}}" , "doesn't exist");}
|
||||
@Test public void Empty() {fxt.Test_parse_tmpl_str_test("{{#ifexist:|y|n}}" , "{{test}}" , "n");} // NOTE: {{autolink}} can pass in ""
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Pfunc_ifexpr extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
int self_args_len = self.Args_len();
|
||||
byte[] argx = Eval_argx(ctx, src, caller, self); if (argx == null) return;
|
||||
Pfunc_expr_shunter shunter = ctx.Tmp_mgr().Expr_shunter();
|
||||
Decimal_adp result = shunter.Evaluate(ctx, argx);
|
||||
boolean is_nan = result == Pfunc_expr_shunter.Null_rslt;
|
||||
if (is_nan && shunter.Err().Len() > 0) {
|
||||
@@ -39,5 +40,4 @@ public class Pfunc_ifexpr extends Pf_func_base {
|
||||
bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0));
|
||||
}
|
||||
}
|
||||
private final Pfunc_expr_shunter shunter = Pfunc_expr_shunter.Instance;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Pfunc_switch extends Pf_func_base {
|
||||
last_keyless_arg = null; // set last_keyless_arg to null
|
||||
byte[] case_key = Get_or_eval(ctx, src, caller, self, bfr, arg.Key_tkn(), tmp);
|
||||
if ( fall_thru_found // fall-thru found earlier; take cur value; EX: {{#switch:a|a|b=1|c=2}} -> 1
|
||||
|| Pf_func_.Eq_(case_key, argx) // case_key matches argx; EX: {{#switch:a|a=1}}
|
||||
|| Pf_func_.Eq(ctx, case_key, argx) // case_key matches argx; EX: {{#switch:a|a=1}}
|
||||
) {
|
||||
match = Get_or_eval(ctx, src, caller, self, bfr, arg.Val_tkn(), tmp);
|
||||
break; // stop iterating; explicit match found;
|
||||
@@ -52,7 +52,7 @@ public class Pfunc_switch extends Pf_func_base {
|
||||
else { // = missing; EX: "|a|", "|#default|"
|
||||
last_keyless_arg = arg;
|
||||
byte[] case_val = Get_or_eval(ctx, src, caller, self, bfr, arg.Val_tkn(), tmp);
|
||||
if (Pf_func_.Eq_(case_val, argx)) // argx matches case_val; EX: case_val="|a|" and argx="a"
|
||||
if (Pf_func_.Eq(ctx, case_val, argx)) // argx matches case_val; EX: case_val="|a|" and argx="a"
|
||||
fall_thru_found = true; // set as fall-thru; note that fall-thrus will have "val" in next keyed arg, so need to continue iterating; EX: {{#switch:a|a|b=1|c=2}} "a" is fall-thru, but "b" is next keyed arg with a val
|
||||
else if (kwd_mgr.Kwd_default_match(case_val)) { // case_val starts with #default; EX: "|#default|" or "|#defaultabc|"
|
||||
last_keyless_arg = null; // unflag last keyless arg else |#defaultabc| will be treated as last_keyless_arg and generate "#defaultabc"; DATE:2014-05-29
|
||||
|
||||
@@ -23,11 +23,11 @@ public class Pfunc_plural extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {// REF.MW: CoreParserFunctions.php
|
||||
byte[] number = Eval_argx(ctx, src, caller, self);
|
||||
int self_args_len = self.Args_len();
|
||||
int arg_idx = Pf_func_.Eq_(number, Ary_Num_1) ? 0 : 1;
|
||||
int arg_idx = Pf_func_.Eq(ctx, number, Ary_Num_1) ? 0 : 1;
|
||||
if (arg_idx == 1 && self_args_len == 1) arg_idx = 0; // number is plural, but plural_arg not present; use singular; see test
|
||||
byte[] word = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, arg_idx);
|
||||
bfr.Add(word);
|
||||
} static final byte[] Ary_Num_1 = new byte[] {Byte_ascii.Num_1};
|
||||
} static final byte[] Ary_Num_1 = new byte[] {Byte_ascii.Num_1};
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_i18n_plural;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_plural().Name_(name);}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Pfunc_scrib_lib implements Scrib_lib {
|
||||
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 void Core_(Scrib_core v) {this.core = v;} // TEST:
|
||||
public Scrib_lib Clone_lib(Scrib_core core) {return new Pfunc_scrib_lib();}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
this.core = core;
|
||||
Init();
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Pfunc_case extends Pf_func_base { // EX: {{lc:A}} -> a
|
||||
Xol_lang_itm lang = ctx.Wiki().Lang();
|
||||
boolean upper = case_type == Xol_lang_itm.Tid_upper;
|
||||
if (first) {
|
||||
Bry_bfr tmp_bfr = ctx.App().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
argx = lang.Case_mgr().Case_build_1st(tmp_bfr, upper, argx, 0, argx_len);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Pfunc_tag extends Pf_func_base {
|
||||
@Override public boolean Func_require_colon_arg() {return true;}
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
// make <xnde> based on {{#tag}}; EX: {{#tag:ref|a|name=1}} -> <ref name='1'>a</ref>
|
||||
Bry_bfr tmp_bfr = ctx.App().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
// get tag_idx, tag_data, and tag_is_ref
|
||||
int tag_idx = -1;
|
||||
|
||||
@@ -163,56 +163,56 @@ public class Pft_fmt_itm_ {
|
||||
.Add("xmY" , Pft_fmt_itm_.Hijiri_year_idx)
|
||||
// TODO_OLD: space; "
|
||||
;
|
||||
|
||||
public static Pft_fmt_itm[] Parse(Xop_ctx ctx, byte[] fmt) {
|
||||
synchronized (fmt_itms) { // LOCK:static-obj; DATE:2016-07-06
|
||||
Btrie_fast_mgr trie = Pft_fmt_itm_.Regy;
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
int i = 0, fmt_len = fmt.length;
|
||||
fmt_itms.Clear(); int raw_bgn = String_.Pos_neg1; byte raw_byt = Byte_.Zero;
|
||||
while (i < fmt_len) {
|
||||
byte b = fmt[i];
|
||||
Object o = trie.Match_at_w_b0(trv, b, fmt, i, fmt_len);
|
||||
if (o != null) {
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(i - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(raw_byt) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i)); raw_bgn = String_.Pos_neg1;}
|
||||
fmt_itms.Add((Pft_fmt_itm)o);
|
||||
i = trv.Pos();
|
||||
}
|
||||
else {
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash:
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(i - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(raw_byt) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i)); raw_bgn = String_.Pos_neg1;}
|
||||
++i; // peek next char
|
||||
if (i == fmt_len) // trailing backslash; add one; EX: "b\" -> "b\" not "b"
|
||||
fmt_itms.Add(new Pft_fmt_itm_raw_byt(Byte_ascii.Backslash));
|
||||
else
|
||||
fmt_itms.Add(new Pft_fmt_itm_raw_byt(fmt[i]));
|
||||
++i;
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(i - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(raw_byt) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i)); raw_bgn = String_.Pos_neg1;}
|
||||
++i; // skip quote_bgn
|
||||
raw_bgn = i;
|
||||
while (i < fmt_len) {
|
||||
b = fmt[i];
|
||||
if (b == Byte_ascii.Quote) {
|
||||
break;
|
||||
}
|
||||
else
|
||||
++i;
|
||||
List_adp fmt_itms = ctx.Wiki().Parser_mgr().Time_parser_itms();
|
||||
Btrie_fast_mgr trie = Pft_fmt_itm_.Regy;
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
int i = 0, fmt_len = fmt.length;
|
||||
fmt_itms.Clear(); int raw_bgn = String_.Pos_neg1; byte raw_byt = Byte_.Zero;
|
||||
while (i < fmt_len) {
|
||||
byte b = fmt[i];
|
||||
Object o = trie.Match_at_w_b0(trv, b, fmt, i, fmt_len);
|
||||
if (o != null) {
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(i - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(raw_byt) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i)); raw_bgn = String_.Pos_neg1;}
|
||||
fmt_itms.Add((Pft_fmt_itm)o);
|
||||
i = trv.Pos();
|
||||
}
|
||||
else {
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash:
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(i - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(raw_byt) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i)); raw_bgn = String_.Pos_neg1;}
|
||||
++i; // peek next char
|
||||
if (i == fmt_len) // trailing backslash; add one; EX: "b\" -> "b\" not "b"
|
||||
fmt_itms.Add(new Pft_fmt_itm_raw_byt(Byte_ascii.Backslash));
|
||||
else
|
||||
fmt_itms.Add(new Pft_fmt_itm_raw_byt(fmt[i]));
|
||||
++i;
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(i - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(raw_byt) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i)); raw_bgn = String_.Pos_neg1;}
|
||||
++i; // skip quote_bgn
|
||||
raw_bgn = i;
|
||||
while (i < fmt_len) {
|
||||
b = fmt[i];
|
||||
if (b == Byte_ascii.Quote) {
|
||||
break;
|
||||
}
|
||||
fmt_itms.Add(i - raw_bgn == 0 ? new Pft_fmt_itm_raw_byt(Byte_ascii.Quote) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i));
|
||||
raw_bgn = String_.Pos_neg1;
|
||||
++i; // skip quote_end
|
||||
break;
|
||||
default:
|
||||
if (raw_bgn == String_.Pos_neg1) {raw_bgn = i; raw_byt = b;}
|
||||
i += gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
|
||||
break;
|
||||
}
|
||||
else
|
||||
++i;
|
||||
}
|
||||
fmt_itms.Add(i - raw_bgn == 0 ? new Pft_fmt_itm_raw_byt(Byte_ascii.Quote) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i));
|
||||
raw_bgn = String_.Pos_neg1;
|
||||
++i; // skip quote_end
|
||||
break;
|
||||
default:
|
||||
if (raw_bgn == String_.Pos_neg1) {raw_bgn = i; raw_byt = b;}
|
||||
i += gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(fmt_len - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(fmt[fmt_len - 1]) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, fmt_len)); raw_bgn = String_.Pos_neg1;}
|
||||
return (Pft_fmt_itm[])fmt_itms.To_ary(Pft_fmt_itm.class);
|
||||
}
|
||||
} private static List_adp fmt_itms = List_adp_.New();
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(fmt_len - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(fmt[fmt_len - 1]) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, fmt_len)); raw_bgn = String_.Pos_neg1;}
|
||||
return (Pft_fmt_itm[])fmt_itms.To_ary(Pft_fmt_itm.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.pfuncs.times; 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.parsers.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.xtns.pfuncs.times.*;
|
||||
public class Pft_func_date_int extends Pf_func_base {
|
||||
public Pft_func_date_int(int id, int date_tid) {this.id = id; this.date_tid = date_tid;} private int date_tid;
|
||||
@Override public int Id() {return id;} private int id;
|
||||
@@ -25,6 +25,7 @@ public class Pft_func_date_int extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
DateAdp date = DateAdp_.MinValue;
|
||||
Xowe_wiki wiki = ctx.Wiki(); Xol_lang_itm lang = ctx.Lang();
|
||||
Pft_func_formatdate_bldr date_fmt_bldr = wiki.Parser_mgr().Date_fmt_bldr();
|
||||
switch (date_tid) {
|
||||
case Date_tid_lcl: date = DateAdp_.Now(); break;
|
||||
case Date_tid_utc: date = DateAdp_.Now().XtoUtc(); break;
|
||||
@@ -35,39 +36,39 @@ public class Pft_func_date_int extends Pf_func_base {
|
||||
case Xol_kwd_grp_.Id_utc_year:
|
||||
case Xol_kwd_grp_.Id_lcl_year:
|
||||
case Xol_kwd_grp_.Id_rev_year:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.Year_len4);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.Year_len4);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_utc_month_int_len2:
|
||||
case Xol_kwd_grp_.Id_lcl_month_int_len2:
|
||||
case Xol_kwd_grp_.Id_rev_month_int_len2:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.Month_int_len2);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.Month_int_len2);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_utc_month_int:
|
||||
case Xol_kwd_grp_.Id_lcl_month_int:
|
||||
case Xol_kwd_grp_.Id_rev_month_int:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.Month_int);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.Month_int);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_utc_day_int_len2:
|
||||
case Xol_kwd_grp_.Id_lcl_day_int_len2:
|
||||
case Xol_kwd_grp_.Id_rev_day_int_len2:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.Day_int_len2);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.Day_int_len2);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_utc_day_int:
|
||||
case Xol_kwd_grp_.Id_lcl_day_int:
|
||||
case Xol_kwd_grp_.Id_rev_day_int:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.Day_int);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.Day_int);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_lcl_hour:
|
||||
case Xol_kwd_grp_.Id_utc_hour:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.Hour_base24_len2);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.Hour_base24_len2);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_lcl_dow:
|
||||
case Xol_kwd_grp_.Id_utc_dow:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.Dow_base1_int);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.Dow_base1_int);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_lcl_week:
|
||||
case Xol_kwd_grp_.Id_utc_week:
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, wiki, lang, date, Pft_fmt_itm_.WeekOfYear_int);
|
||||
date_fmt_bldr.Format(bfr, wiki, lang, date, Pft_fmt_itm_.WeekOfYear_int);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_lcl_time:
|
||||
case Xol_kwd_grp_.Id_utc_time: // 17:29
|
||||
|
||||
@@ -35,13 +35,12 @@ public class Pft_func_formatdate extends Pf_func_base {
|
||||
bfr.Add(date_bry);
|
||||
return;
|
||||
}
|
||||
DateAdp date = Pft_func_time.ParseDate(date_bry, false, ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls());
|
||||
DateAdp date = Pft_func_time.ParseDate(date_bry, false, ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls());
|
||||
if (date == null) {bfr.Add(date_bry); return;} // date not parseable; return self; DATE:2014-04-13
|
||||
date_bldr.Format(bfr, ctx.Wiki(), ctx.Lang(), date, (Pft_fmt_itm[])o);
|
||||
ctx.Wiki().Parser_mgr().Date_fmt_bldr().Format(bfr, ctx.Wiki(), ctx.Lang(), date, (Pft_fmt_itm[])o);
|
||||
}
|
||||
public static Pft_func_formatdate_bldr Date_bldr() {return date_bldr;} private static Pft_func_formatdate_bldr date_bldr = new Pft_func_formatdate_bldr();
|
||||
private static final Pft_fmt_itm[] Fmt_itms_default = new Pft_fmt_itm[0];
|
||||
private static final Btrie_fast_mgr trie = Btrie_fast_mgr.cs()
|
||||
private static final Pft_fmt_itm[] Fmt_itms_default = new Pft_fmt_itm[0];
|
||||
private static final Btrie_fast_mgr trie = Btrie_fast_mgr.cs()
|
||||
.Add("dmy" , new Pft_fmt_itm[] {Pft_fmt_itm_.Day_int, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Month_name, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Year_len4})
|
||||
.Add("mdy" , new Pft_fmt_itm[] {Pft_fmt_itm_.Month_name, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Day_int, Pft_fmt_itm_.Byte_comma, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Year_len4})
|
||||
.Add("ymd" , new Pft_fmt_itm[] {Pft_fmt_itm_.Year_len4, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Month_name, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Day_int})
|
||||
|
||||
@@ -22,46 +22,42 @@ public class Pft_func_formatdate_bldr {
|
||||
public Pft_func_formatdate_bldr Idx_nxt_(int v) {idx_nxt = v; return this;} private int idx_nxt;
|
||||
public Pft_fmt_itm[] Fmt_itms() {return fmt_itms;} private Pft_fmt_itm[] fmt_itms;
|
||||
public void Format(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang_itm lang, DateAdp date, Pft_fmt_itm fmt_itm) {
|
||||
synchronized (this) { // LOCK:static-obj;Pft_func_formatdate.Date_bldr(); DATE:2016-07-07
|
||||
fmt_itm.Fmt(bfr, wiki, lang, date, this);
|
||||
}
|
||||
fmt_itm.Fmt(bfr, wiki, lang, date, this);
|
||||
}
|
||||
public void Format(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang_itm lang, DateAdp date, Pft_fmt_itm[] fmt_itms) {
|
||||
synchronized (this) { // LOCK:static-obj;Pft_func_formatdate.Date_bldr(); DATE:2016-07-07
|
||||
this.fmt_itms = fmt_itms;
|
||||
int len = fmt_itms.length;
|
||||
idx_cur = 0; idx_nxt = -1;
|
||||
Pft_fmt_itm chained_fmt = null;
|
||||
while (idx_cur < len) {
|
||||
Pft_fmt_itm fmt_itm = fmt_itms[idx_cur];
|
||||
if (fmt_itm.TypeId() == Pft_fmt_itm_.Tid_hebrew_numeral)
|
||||
chained_fmt = fmt_itm;
|
||||
else {
|
||||
if (chained_fmt != null) {
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
synchronized (tmp_bfr) {
|
||||
fmt_itm.Fmt(tmp_bfr, wiki, lang, date, this);
|
||||
chained_fmt.Fmt(tmp_bfr, wiki, lang, date, this);
|
||||
bfr.Add(tmp_bfr.To_bry_and_rls());
|
||||
chained_fmt = null;
|
||||
}
|
||||
this.fmt_itms = fmt_itms;
|
||||
int len = fmt_itms.length;
|
||||
idx_cur = 0; idx_nxt = -1;
|
||||
Pft_fmt_itm chained_fmt = null;
|
||||
while (idx_cur < len) {
|
||||
Pft_fmt_itm fmt_itm = fmt_itms[idx_cur];
|
||||
if (fmt_itm.TypeId() == Pft_fmt_itm_.Tid_hebrew_numeral)
|
||||
chained_fmt = fmt_itm;
|
||||
else {
|
||||
if (chained_fmt != null) {
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
synchronized (tmp_bfr) {
|
||||
fmt_itm.Fmt(tmp_bfr, wiki, lang, date, this);
|
||||
chained_fmt.Fmt(tmp_bfr, wiki, lang, date, this);
|
||||
bfr.Add(tmp_bfr.To_bry_and_rls());
|
||||
chained_fmt = null;
|
||||
}
|
||||
else
|
||||
fmt_itm.Fmt(bfr, wiki, lang, date, this);
|
||||
}
|
||||
if (idx_nxt == -1)
|
||||
++idx_cur;
|
||||
else {
|
||||
idx_cur = idx_nxt;
|
||||
idx_nxt = -1;
|
||||
}
|
||||
else
|
||||
fmt_itm.Fmt(bfr, wiki, lang, date, this);
|
||||
}
|
||||
if (chained_fmt != null) {
|
||||
int year_int = bfr.To_int_and_clear(-1);
|
||||
if (year_int != -1) { // handle no format; EX:{{#time:xh}} DATE:2014-07-20
|
||||
date = DateAdp_.seg_(new int[] {year_int, date.Month(), date.Day(), date.Hour(), date.Minute(), date.Second(), date.Frac()});
|
||||
chained_fmt.Fmt(bfr, wiki, lang, date, this);
|
||||
}
|
||||
if (idx_nxt == -1)
|
||||
++idx_cur;
|
||||
else {
|
||||
idx_cur = idx_nxt;
|
||||
idx_nxt = -1;
|
||||
}
|
||||
}
|
||||
if (chained_fmt != null) {
|
||||
int year_int = bfr.To_int_and_clear(-1);
|
||||
if (year_int != -1) { // handle no format; EX:{{#time:xh}} DATE:2014-07-20
|
||||
date = DateAdp_.seg_(new int[] {year_int, date.Month(), date.Day(), date.Hour(), date.Minute(), date.Second(), date.Frac()});
|
||||
chained_fmt.Fmt(bfr, wiki, lang, date, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Pft_func_time extends Pf_func_base {
|
||||
byte[] arg_lang = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1);
|
||||
Bry_bfr error_bfr = Bry_bfr_.New();
|
||||
DateAdp date = ParseDate(arg_date, utc, error_bfr);
|
||||
Xowe_wiki wiki = ctx.Wiki();
|
||||
if (date == null || error_bfr.Len() > 0)
|
||||
bfr.Add_str_a7("<strong class=\"error\">").Add_bfr_and_clear(error_bfr).Add_str_a7("</strong>");
|
||||
else {
|
||||
@@ -37,11 +38,11 @@ public class Pft_func_time extends Pf_func_base {
|
||||
if (Bry_.Len_gt_0(arg_lang)) {
|
||||
Xol_lang_stub specified_lang_itm = Xol_lang_stub_.Get_by_key_or_null(arg_lang);
|
||||
if (specified_lang_itm != null) { // NOTE: if lang_code is bad, then ignore (EX:bad_code)
|
||||
Xol_lang_itm specified_lang = ctx.Wiki().Appe().Lang_mgr().Get_by_or_new(arg_lang);
|
||||
Xol_lang_itm specified_lang = wiki.Appe().Lang_mgr().Get_by_or_new(arg_lang);
|
||||
lang = specified_lang;
|
||||
}
|
||||
}
|
||||
Pft_func_formatdate.Date_bldr().Format(bfr, ctx.Wiki(), lang, date, fmt_ary);
|
||||
wiki.Parser_mgr().Date_fmt_bldr().Format(bfr, wiki, lang, date, fmt_ary);
|
||||
}
|
||||
}
|
||||
public static DateAdp ParseDate(byte[] date, boolean utc, Bry_bfr error_bfr) {
|
||||
|
||||
@@ -45,10 +45,8 @@ class Pxd_parser {
|
||||
fmtr.Bld_bfr(error_bfr, args);
|
||||
} private Bry_bfr error_bfr = Bry_bfr_.New_w_size(32);
|
||||
public DateAdp Parse(byte[] src, Bry_bfr error_bfr) {
|
||||
// synchronized (this) { // LOCK:static-obj; DATE:2016-07-06
|
||||
Tokenize(src); // NOTE: should check if Tokenize failed, but want to be liberal as date parser is not fully implemented; this will always default to 1st day of year; DATE:2014-03-27
|
||||
return Evaluate(src, error_bfr);
|
||||
// }
|
||||
Tokenize(src); // NOTE: should check if Tokenize failed, but want to be liberal as date parser is not fully implemented; this will always default to 1st day of year; DATE:2014-03-27
|
||||
return Evaluate(src, error_bfr);
|
||||
}
|
||||
private boolean Tokenize(byte[] src) {
|
||||
this.src = src; src_len = src.length;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Pfunc_anchorencode extends Pf_func_base { // EX: {{anchorencode:a b
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
if (anchor_ctx == null) Func_init(ctx);
|
||||
byte[] val_ary = Eval_argx(ctx, src, caller, self); if (val_ary == Bry_.Empty) return;
|
||||
Anchor_encode(val_ary, bfr, ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls());
|
||||
Anchor_encode(val_ary, bfr, ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls());
|
||||
}
|
||||
public static void Anchor_encode(byte[] src, Bry_bfr bfr, Bry_bfr tmp_bfr) {
|
||||
Xop_root_tkn root = anchor_ctx.Tkn_mkr().Root(src);
|
||||
|
||||
@@ -16,39 +16,40 @@ 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.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.core.envs.*; import gplx.core.caches.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Pfunc_filepath extends Pf_func_base {
|
||||
@Override public boolean Func_require_colon_arg() {return true;}
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_url_filepath;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_filepath().Name_(name);}
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
// init
|
||||
byte[] val_ary = Eval_argx(ctx, src, caller, self); if (val_ary == Bry_.Empty) return;
|
||||
Xowe_wiki wiki = ctx.Wiki();
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(Xow_ns_.Tid__file, val_ary); if (ttl == null) return; // text is not valid ttl; exit;
|
||||
Xoae_page page = Load_page(wiki, ttl); if (page.Db().Page().Exists_n()) return; // page not found in wiki or commons; exit;
|
||||
byte[] ttl_bry = page.Ttl().Page_url();
|
||||
|
||||
// Xof_orig_itm orig_itm = wiki.File_mgr().Orig_mgr().Find_by_ttl_or_null(ttl_bry);
|
||||
// if (orig_itm == Xof_orig_itm.Null) return;
|
||||
// Xof_repo_itm repo = wiki.File_mgr().Repo_mgr().Get_trg_by_id_or_null(orig_itm.Repo()).Trg();
|
||||
// url_bldr.Init_for_trg_html(Xof_repo_itm_.Mode_orig, repo, orig_itm.Ttl(), Xof_file_wkr_.Md5_fast(orig_itm.Ttl()), orig_itm.Ext(), -1, -1, -1);
|
||||
// bfr.Add(url_bldr.Xto_bry());
|
||||
Pfunc_filepath_itm commons_itm = Load_page(wiki, ttl); if (!commons_itm.Exists()) return; // page not found in wiki or commons; exit;
|
||||
byte[] ttl_bry = commons_itm.Page_url();
|
||||
|
||||
// look for file
|
||||
Xofw_file_finder_rslt tmp_rslt = wiki.File_mgr().Repo_mgr().Page_finder_locate(ttl_bry);
|
||||
if (tmp_rslt.Repo_idx() == Byte_.Max_value_127) return;
|
||||
Xof_repo_itm trg_repo = wiki.File_mgr().Repo_mgr().Repos_get_at(tmp_rslt.Repo_idx()).Trg();
|
||||
Xof_xfer_itm xfer_itm = ctx.Tmp_mgr().Xfer_itm();
|
||||
xfer_itm.Orig_ttl_and_redirect_(ttl_bry, Bry_.Empty); // redirect is empty b/c Get_page does all redirect lookups
|
||||
byte[] url = url_bldr.Init_for_trg_html(Xof_repo_itm_.Mode_orig, trg_repo, ttl_bry, xfer_itm.Orig_ttl_md5(), xfer_itm.Orig_ext(), Xof_img_size.Size__neg1, Xof_lnki_time.Null, Xof_lnki_page.Null).Xto_bry();
|
||||
byte[] url = wiki.Parser_mgr().Url_bldr().Init_for_trg_html(Xof_repo_itm_.Mode_orig, trg_repo, ttl_bry, xfer_itm.Orig_ttl_md5(), xfer_itm.Orig_ext(), Xof_img_size.Size__neg1, Xof_lnki_time.Null, Xof_lnki_page.Null).Xto_bry();
|
||||
bfr.Add(url);
|
||||
}
|
||||
private static final Xof_xfer_itm xfer_itm = new Xof_xfer_itm();
|
||||
private static final Xof_url_bldr url_bldr = new Xof_url_bldr();
|
||||
private static Xoae_page Load_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
private static Pfunc_filepath_itm Load_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
// try to get from cache
|
||||
Gfo_cache_mgr cache_mgr = wiki.Cache_mgr().Commons_cache();
|
||||
byte[] cache_key = ttl.Page_url();
|
||||
Pfunc_filepath_itm cache_itm = (Pfunc_filepath_itm)cache_mgr.Get_by_key(cache_key);
|
||||
if (cache_itm != null) return cache_itm;
|
||||
|
||||
// do db retrieval
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl);
|
||||
if (page.Db().Page().Exists_n()) { // file not found in current wiki; try commons;
|
||||
Xowe_wiki commons_wiki = (Xowe_wiki)wiki.Appe().Wiki_mgr().Get_by_or_null(wiki.Commons_wiki_key());
|
||||
@@ -61,6 +62,16 @@ public class Pfunc_filepath extends Pf_func_base {
|
||||
page = commons_wiki.Data_mgr().Load_page_by_ttl(ttl);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
|
||||
// add to cache
|
||||
cache_itm = new Pfunc_filepath_itm(page.Db().Page().Exists(), cache_key);
|
||||
cache_mgr.Add(cache_key, cache_itm, 1);
|
||||
return cache_itm;
|
||||
}
|
||||
}
|
||||
class Pfunc_filepath_itm implements Rls_able {
|
||||
public Pfunc_filepath_itm(boolean exists, byte[] page_url) {this.exists = exists; this.page_url = page_url;}
|
||||
public boolean Exists() {return exists;} private final boolean exists;
|
||||
public byte[] Page_url() {return page_url;} private final byte[] page_url;
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Pfunc_rel2abs extends Pf_func_base {
|
||||
byte[] qry = Eval_argx(ctx, src, caller, self);
|
||||
byte[] orig = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self.Args_len(), 0);
|
||||
if (orig.length == 0) orig = ctx.Page().Ttl().Full_txt_w_ttl_case();
|
||||
bfr.Add(Rel2abs(ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls(), qry, orig));
|
||||
bfr.Add(Rel2abs(ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls(), qry, orig));
|
||||
}
|
||||
public static boolean Rel2abs_ttl(byte[] ttl, int bgn, int end) {
|
||||
int last = end - 1;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
|
||||
.Add_mid(ttl_ary, xwiki.Key_bry().length + 1, ttl_ary.length); // "A#b?c=d"; +1 for colon after "commons:"; NOTE: ugly way of getting rest of url, but ttl currently does not have Full_wo_wiki
|
||||
}
|
||||
else {
|
||||
Bry_bfr tmp_bfr = ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
switch (tid) {
|
||||
case Tid_local: tmp_bfr.Add(ctx.Wiki().Props().ArticlePath());break;
|
||||
case Tid_full: tmp_bfr.Add(Bry_relative_url).Add(ctx.Wiki().Props().Server_name()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
Xoae_page page = ctx.Page();
|
||||
if (page.Pages_recursed()) return; // moved from Pp_index_parser; DATE:2014-05-21s
|
||||
page.Pages_recursed_(true);
|
||||
Bry_bfr full_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
Bry_bfr full_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy(); if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs(); // SEE:NOTE:page_regy; DATE:2014-01-01
|
||||
page.Html_data().Indicators().Enabled_(Bool_.N); // disable <indicator> b/c <page> should not add to current page; PAGE:en.s:The_Parochial_System_(Wilberforce,_1838); DATE:2015-04-29
|
||||
byte[] page_bry = Bld_wikitext(full_bfr, lst_page_regy);
|
||||
@@ -300,7 +300,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
int list_len = list.Count(); if (list_len == 0) return Ttls_null;
|
||||
Xoa_ttl[] rv = new Xoa_ttl[(list_len / step_int) + ((list_len % step_int == 0) ? 0 : 1)];
|
||||
int rv_idx = 0;
|
||||
Bry_bfr ttl_bfr = app.Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr ttl_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
for (int i = 0; i < list_len; i += step_int) {
|
||||
Int_obj_val page = (Int_obj_val)list.Get_at(i);
|
||||
ttl_bfr.Add(ns_page.Name_db_w_colon()) // EX: 'Page:'
|
||||
@@ -329,7 +329,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
Xoa_ttl bgn_page_ttl = bgn_page_bry == null ? null : ary[0];
|
||||
Xoa_ttl end_page_ttl = end_page_bry == null ? null : ary[ary_len - 1];
|
||||
|
||||
Bry_bfr page_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
Bry_bfr page_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
ctx.Tmpl_output_(page_bfr);
|
||||
Lst_pfunc_wkr lst_pfunc_wkr = new Lst_pfunc_wkr();
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import gplx.xowa.xtns.scribunto.libs.*; import gplx.xowa.xtns.scribunto.engines.
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Scrib_core {
|
||||
private Hash_adp_bry mods = Hash_adp_bry.cs();
|
||||
private int expensive_function_count;
|
||||
public Scrib_core(Xoae_app app, Xop_ctx ctx) {// NOTE: ctx needed for language reg
|
||||
this.app = app; this.ctx = ctx;
|
||||
this.wiki = ctx.Wiki(); this.page = ctx.Page(); // NOTE: wiki / page needed for title reg; DATE:2014-02-05
|
||||
@@ -114,7 +115,7 @@ public class Scrib_core {
|
||||
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));
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Scrib_core_fxt {
|
||||
public Scrib_core_fxt(Xop_fxt fxt) {
|
||||
app = fxt.App();
|
||||
wiki = fxt.Wiki();
|
||||
core = wiki.Parser_mgr().Scrib().Core_make(wiki.Parser_mgr().Ctx());
|
||||
core = wiki.Parser_mgr().Scrib().Core_init(wiki.Parser_mgr().Ctx());
|
||||
server = new Process_server_mock();
|
||||
core.Interpreter().Server_(server);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class Scrib_core_fxt {
|
||||
if (core == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
core = wiki.Parser_mgr().Scrib().Core_make(wiki.Parser_mgr().Ctx());
|
||||
core = wiki.Parser_mgr().Scrib().Core_init(wiki.Parser_mgr().Ctx());
|
||||
server = new Process_server_mock();
|
||||
core.Interpreter().Server_(server);
|
||||
}
|
||||
|
||||
@@ -16,49 +16,39 @@ 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; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Scrib_core_mgr {
|
||||
private static final List_adp cores = List_adp_.New();
|
||||
public Scrib_core Core() {return core;} private Scrib_core core;
|
||||
public Scrib_core Core_make(Xop_ctx ctx) {
|
||||
public void Terminate_when_page_changes_y_() {terminate_when_page_changes = true;} private boolean terminate_when_page_changes;
|
||||
public Scrib_core Core_init(Xop_ctx ctx) {
|
||||
core = new Scrib_core(ctx.App(), ctx);
|
||||
core_invalidate_when_page_changes = false;
|
||||
synchronized (cores) {
|
||||
cores.Add(core);
|
||||
}
|
||||
terminate_when_page_changes = false;
|
||||
return core;
|
||||
}
|
||||
public void Core_term() {
|
||||
if (core != null) core.Term();
|
||||
synchronized (cores) {
|
||||
cores.Del(core);
|
||||
if (core != null) {
|
||||
core.Term();
|
||||
core = null;
|
||||
}
|
||||
core = null;
|
||||
}
|
||||
public void Core_invalidate_when_page_changes() {core_invalidate_when_page_changes = true;} private boolean core_invalidate_when_page_changes;
|
||||
public void Core_page_changed(Xoae_page page) {
|
||||
if ( core != null // core explicitly invalidated
|
||||
|| core_invalidate_when_page_changes // core marked invalidated b/c of error in {{#invoke}} but won't be regen'd until page changes; invalidate now; PAGE:th.d:all; DATE:2014-10-03
|
||||
) {
|
||||
if ( core != null // null check
|
||||
&& Bry_.Eq(page.Wiki().Domain_bry(), core.Cur_wiki()) // current page is in same wiki as last page
|
||||
&& !core_invalidate_when_page_changes // if core_invalidate_when_page_changes, then must call Core_term
|
||||
)
|
||||
core.When_page_changed(page);
|
||||
else // current page is in different wiki
|
||||
Core_term(); // invalidate scrib engine; note that lua will cache chunks by Module name and two modules in two different wikis can have the same name, but different data: EX:Module:Citation/CS1/Configuration and enwiki / zhwiki; DATE:2014-03-21
|
||||
core_invalidate_when_page_changes = false;
|
||||
public void When_page_changed(Xoae_page page) {
|
||||
if (terminate_when_page_changes) { // true when error in {{#invoke}}; PAGE:th.d:all; DATE:2014-10-03
|
||||
Core_term(); // terminate core; note that next call to {{#invoke}} will check for null and rebuild if null;
|
||||
terminate_when_page_changes = false;
|
||||
}
|
||||
else { // no error on previous page; notify core that page changed; note that lua will cache chunks by Module name and two modules in two different wikis can have the same name, but different data: EX:Module:Citation/CS1/Configuration and enwiki / zhwiki; DATE:2014-03-21
|
||||
if (core != null) // null-check needed when engine first created
|
||||
core.When_page_changed(page); // NOTE: must call When_page_changed on core to update page; else, current ttl is not updated, and scrib_wikibase will return wrong document; DATE:2016-07-22
|
||||
}
|
||||
}
|
||||
|
||||
public static void Term_all() {
|
||||
synchronized (cores) {
|
||||
int cores_len = cores.Len();
|
||||
for (int i = 0; i < cores_len; ++i) {
|
||||
Scrib_core core = (Scrib_core)cores.Get_at(i);
|
||||
core.Term();
|
||||
}
|
||||
cores.Clear();
|
||||
public static void Term_all(Xoae_app app) { // NOLOCK.app_level
|
||||
Xoae_wiki_mgr wiki_mgr = app.Wiki_mgr();
|
||||
int len = wiki_mgr.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wiki_mgr.Get_at(i);
|
||||
wiki.Parser_mgr().Scrib().Core_term();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Scrib_invoke_func extends Pf_func_base {
|
||||
Scrib_core core = wiki.Parser_mgr().Scrib().Core();
|
||||
if (core == null) {
|
||||
synchronized (this) {
|
||||
core = wiki.Parser_mgr().Scrib().Core_make(ctx);
|
||||
core = wiki.Parser_mgr().Scrib().Core_init(ctx);
|
||||
core.Init();
|
||||
core.When_page_changed(ctx.Page());
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class Scrib_invoke_func extends Pf_func_base {
|
||||
|| err_filter_mgr.Count_eq_0( ) // err_filter_mgr exists, but no definitions
|
||||
|| !err_filter_mgr.Match(String_.new_u8(mod_name), String_.new_u8(fnc_name), err.To_str__msg_only())) // NOTE: must be To_str__msg_only; err_filter_mgr has defintion and it doesn't match current; print warn; DATE:2015-07-24
|
||||
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", ctx.Page().Ttl().Raw(), String_.new_u8(src, self.Src_bgn(), self.Src_end()), err.To_str__log());
|
||||
wiki.Parser_mgr().Scrib().Core_invalidate_when_page_changes(); // NOTE: invalidate core when page changes, not for rest of page, else page with many errors will be very slow due to multiple invalidations; PAGE:th.d:all; DATE:2014-10-03
|
||||
wiki.Parser_mgr().Scrib().Terminate_when_page_changes_y_(); // NOTE: terminate core when page changes; not terminating now, else page with many errors will be very slow due to multiple remakes of core; PAGE:th.d:all; DATE:2014-10-03
|
||||
}
|
||||
}
|
||||
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, Err err) {Error(bfr, msg_mgr, Err_.cast_or_make(err).To_str__top_wo_args());}// NOTE: must use "short" error message to show in wikitext; DATE:2015-07-27
|
||||
|
||||
@@ -21,4 +21,5 @@ public interface Scrib_lib {
|
||||
Scrib_lib Init();
|
||||
Scrib_lua_mod Register(Scrib_core core, Io_url script_dir);
|
||||
boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt);
|
||||
Scrib_lib Clone_lib(Scrib_core core);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Scrib_lib_mgr {
|
||||
public void Init_for_core(Scrib_core core, Io_url script_dir) {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Scrib_lib lib = Get_at(i);
|
||||
Scrib_lib lib = Get_at(i).Clone_lib(core);
|
||||
lib.Register(core, script_dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ public class Scrib_proc_mgr {
|
||||
public Scrib_proc Get_by_key(String key) {synchronized (hash) {return (Scrib_proc)hash.Get_by(key);}}
|
||||
public Scrib_proc Get_at(int i) {synchronized (hash) {return (Scrib_proc)hash.Get_at(i);}}
|
||||
public void Set(String key, Scrib_proc proc) {
|
||||
// synchronized (hash) { // LOCK:DELETE; DATE:2016-07-06
|
||||
hash.Add_if_dupe_use_nth(key, proc); // WORKAROUND: Add_if_dupe_use_nth b/c some libraries reuse proc name; EX: getGlobalSiteId is used by mw.wikibase.lua and mw.wikibase.entity.lua
|
||||
// }
|
||||
hash.Add_if_dupe_use_nth(key, proc); // WORKAROUND: Add_if_dupe_use_nth b/c some libraries reuse proc name; EX: getGlobalSiteId is used by mw.wikibase.lua and mw.wikibase.entity.lua
|
||||
}
|
||||
public Scrib_proc Set(Scrib_lib lib, String proc_name, int proc_id) {
|
||||
Scrib_proc proc = new Scrib_proc(lib, proc_name, proc_id);
|
||||
|
||||
@@ -23,10 +23,14 @@ public class Scrib_xtn_mgr extends Xox_mgr_base {
|
||||
@Override public void Xtn_ctor_by_app(Xoae_app app) {this.app = app;} private Xoae_app app;
|
||||
@Override public Xox_mgr Xtn_clone_new() {return new Scrib_xtn_mgr();}
|
||||
public Scrib_lib_mgr Lib_mgr() {return lib_mgr;} private Scrib_lib_mgr lib_mgr = new Scrib_lib_mgr();
|
||||
@Override public void Enabled_(boolean v) {
|
||||
Scrib_core_mgr.Term_all(app);
|
||||
super.Enabled_(v);
|
||||
}
|
||||
public byte Engine_type() {return engine_type;} private byte engine_type = Scrib_engine_type.Type_luaj;
|
||||
public void Engine_type_(byte cmd) {
|
||||
engine_type = cmd;
|
||||
gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all();
|
||||
gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all(app);
|
||||
}
|
||||
public int Lua_timeout() {return lua_timeout;} private int lua_timeout = 4000;
|
||||
public int Lua_timeout_polling() {return lua_timeout_polling;} private int lua_timeout_polling = 1;
|
||||
@@ -36,7 +40,7 @@ public class Scrib_xtn_mgr extends Xox_mgr_base {
|
||||
public boolean Luaj_debug_enabled() {return luaj_debug_enabled;} private boolean luaj_debug_enabled;
|
||||
public void Luaj_debug_enabled_(boolean v) {
|
||||
this.luaj_debug_enabled = v;
|
||||
gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all();// restart server in case luaj caches any debug data
|
||||
gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all(app);// restart server in case luaj caches any debug data
|
||||
}
|
||||
public Xop_log_invoke_wkr Invoke_wkr() {return invoke_wkr;} private Xop_log_invoke_wkr invoke_wkr;
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Mock_scrib_fxt {
|
||||
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 = wiki.Parser_mgr().Scrib().Core_make(wiki.Parser_mgr().Ctx());
|
||||
core = wiki.Parser_mgr().Scrib().Core_init(wiki.Parser_mgr().Ctx());
|
||||
core.Engine_(engine); engine.Clear();
|
||||
core.Interpreter().Server_(server);
|
||||
Xot_invk parent_frame = new Xot_invk_temp(true); parent_frame.Frame_tid_(Scrib_frame_.Tid_null);
|
||||
|
||||
@@ -20,6 +20,7 @@ public class Scrib_lib_html implements Scrib_lib {
|
||||
public Scrib_lib_html(Scrib_core core) {}
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
public Scrib_lib Init() {procs.Init_by_lib(this, String_.Ary_empty); return this;}
|
||||
public Scrib_lib Clone_lib(Scrib_core core) {return new Scrib_lib_html(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.html.lua"));
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
public Scrib_lib_language(Scrib_core core) {this.core = core;} private 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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_language(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.language.lua"));
|
||||
@@ -150,7 +151,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
private boolean Case_1st(Scrib_proc_args args, Scrib_proc_rslt rslt, boolean upper) {
|
||||
Xol_lang_itm lang = lang_(args);
|
||||
byte[] word = args.Pull_bry(1);
|
||||
Bry_bfr bfr = core.Wiki().Appe().Utl__bfr_mkr().Get_b128().Mkr_rls();
|
||||
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b128().Mkr_rls();
|
||||
return rslt.Init_obj(lang.Case_mgr().Case_build_1st(bfr, upper, word, 0, word.length));
|
||||
}
|
||||
public boolean Lc(Scrib_proc_args args, Scrib_proc_rslt rslt) {return Case_all(args, rslt, Bool_.N);}
|
||||
@@ -181,7 +182,8 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
byte[] fmt_bry = args.Pull_bry(1);
|
||||
byte[] date_bry = args.Cast_bry_or_empty(2); // NOTE: optional empty is required b/c date is sometimes null; use Bry_.Empty b/c this is what Pft_func_time.ParseDate takes; DATE:2013-04-05
|
||||
boolean utc = args.Cast_bool_or_n(3);
|
||||
Bry_bfr tmp_bfr = core.App().Utl__bfr_mkr().Get_b512();
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
Pft_fmt_itm[] fmt_ary = Pft_fmt_itm_.Parse(core.Ctx(), fmt_bry);
|
||||
DateAdp date = null;
|
||||
if (Bry_.Len_eq_0(date_bry))
|
||||
@@ -198,7 +200,8 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
date = Pft_func_time.ParseDate(date_bry, utc, tmp_bfr); // NOTE: not using java's datetime parse b/c it is more strict; not reconstructing PHP's datetime parse b/c it is very complicated (state machine); re-using MW's parser b/c it is inbetween; DATE:2015-07-29
|
||||
}
|
||||
if (date == null || tmp_bfr.Len() > 0) {tmp_bfr.Mkr_rls(); return rslt.Init_fail("bad argument #2 to 'formatDate' (not a valid timestamp)");}
|
||||
Pft_func_formatdate.Date_bldr().Format(tmp_bfr, core.Wiki(), lang, date, fmt_ary);
|
||||
|
||||
wiki.Parser_mgr().Date_fmt_bldr().Format(tmp_bfr, wiki, lang, date, fmt_ary);
|
||||
byte[] rv = tmp_bfr.To_bry_and_rls();
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class Scrib_lib_message implements Scrib_lib {
|
||||
public Scrib_lib_message(Scrib_core core) {this.core = core;} private 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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_message(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.message.lua"));// NOTE: "lang" not passed in
|
||||
|
||||
@@ -25,6 +25,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
public Scrib_lua_mod Mod() {return mod;} public void Mod_(Scrib_lua_mod v) {this.mod = v;} private Scrib_lua_mod mod;
|
||||
public boolean Allow_env_funcs() {return allow_env_funcs;} private boolean allow_env_funcs = true;
|
||||
public Scrib_lib Init() {procs.Init_by_lib(this, Proc_names); return this;}
|
||||
public Scrib_lib Clone_lib(Scrib_core core) {return new Scrib_lib_mw(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
core.RegisterInterface(this, script_dir.GenSubFil("mwInit.lua")); // DATE:2014-07-12
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Scrib_lib_site implements Scrib_lib {
|
||||
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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_site(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.site.lua"));// NOTE: info not passed by default; rely on Init_for_wiki
|
||||
|
||||
@@ -19,18 +19,19 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.core.bits.*;
|
||||
import gplx.xowa.langs.msgs.*;
|
||||
public class Scrib_lib_text implements Scrib_lib {
|
||||
private final Scrib_lib_text__json_util json_util = new Scrib_lib_text__json_util();
|
||||
private final Scrib_lib_text__reindex_data reindex_data = new Scrib_lib_text__reindex_data();
|
||||
private final Scrib_lib_text__json_util json_util = new Scrib_lib_text__json_util();
|
||||
private final Scrib_lib_text__reindex_data reindex_data = new Scrib_lib_text__reindex_data();
|
||||
public Scrib_lib_text(Scrib_core core) {this.core = core;} private 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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_text(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.text.lua"));
|
||||
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 final 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_unstrip: return Unstrip(args, rslt);
|
||||
@@ -46,7 +47,7 @@ public class Scrib_lib_text implements Scrib_lib {
|
||||
private static final int Proc_unstrip = 0, Proc_unstripNoWiki = 1, Proc_killMarkers = 2, Proc_getEntityTable = 3, Proc_init_text_for_wiki = 4, Proc_jsonEncode = 5, Proc_jsonDecode = 6;
|
||||
public static final String Invk_unstrip = "unstrip", Invk_unstripNoWiki = "unstripNoWiki", Invk_killMarkers = "killMarkers", Invk_getEntityTable = "getEntityTable"
|
||||
, Invk_init_text_for_wiki = "init_text_for_wiki", Invk_jsonEncode = "jsonEncode", Invk_jsonDecode = "jsonDecode";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_unstrip, Invk_unstripNoWiki, Invk_killMarkers, Invk_getEntityTable, Invk_init_text_for_wiki, Invk_jsonEncode, Invk_jsonDecode);
|
||||
private static final String[] Proc_names = String_.Ary(Invk_unstrip, Invk_unstripNoWiki, Invk_killMarkers, Invk_getEntityTable, Invk_init_text_for_wiki, Invk_jsonEncode, Invk_jsonDecode);
|
||||
public boolean Unstrip(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(args.Pull_str(0));} // NOTE: XOWA does not use MediaWiki strip markers; just return original; DATE:2015-01-20
|
||||
public boolean UnstripNoWiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(args.Pull_str(0));} // NOTE: XOWA does not use MediaWiki strip markers; just return original; DATE:2015-01-20
|
||||
public boolean KillMarkers(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(args.Pull_str(0));} // NOTE: XOWA does not use MediaWiki strip markers; just return original; DATE:2015-01-20
|
||||
|
||||
@@ -25,6 +25,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
public Scrib_lib_title(Scrib_core core) {this.core = core;} private 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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_title(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.title.lua")
|
||||
@@ -84,7 +85,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
byte[] qry_bry = args.Extract_qry_args(wiki, 2);
|
||||
// byte[] proto = Scrib_kv_utl_.Val_to_bry_or(values, 3, null); // NOTE: Scribunto has more conditional logic around argument 2 and setting protocols; DATE:2014-07-07
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
Bry_bfr bfr = wiki.Appe().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
//if (url_func_tid == Pfunc_urlfunc.Tid_full) {
|
||||
// if (proto == null) proto = Proto_relative;
|
||||
// Object proto_obj = proto_hash.Get_by(proto); if (proto_obj == null) throw Err_.new_fmt_("protocol is not valid: {0}", proto);
|
||||
@@ -134,12 +135,11 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
if (ttl == Xoa_ttl.Null) return rslt.Init_null();
|
||||
// TODO_OLD: MW does extra logic here to cache ttl in ttl cache to avoid extra title lookups
|
||||
boolean ttl_exists = false, ttl_redirect = false; int ttl_id = 0;
|
||||
synchronized (tmp_db_page) {
|
||||
ttl_exists = core.Wiki().Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, ttl.Ns(), ttl.Page_db());
|
||||
}
|
||||
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
ttl_exists = core.Wiki().Db_mgr().Load_mgr().Load_by_ttl(db_page, ttl.Ns(), ttl.Page_db());
|
||||
if (ttl_exists) {
|
||||
ttl_redirect = tmp_db_page.Redirected();
|
||||
ttl_id = tmp_db_page.Id();
|
||||
ttl_redirect = db_page.Redirected();
|
||||
ttl_id = db_page.Id();
|
||||
}
|
||||
Keyval[] rv = new Keyval[4];
|
||||
rv[ 0] = Keyval_.new_("isRedirect" , ttl_redirect); // title.isRedirect
|
||||
@@ -226,6 +226,6 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
if (!ns_file_or_media)
|
||||
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_wikitext = "wikitext";
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Scrib_lib_uri implements Scrib_lib {
|
||||
public Scrib_lib_uri(Scrib_core core) {this.core = core;} private 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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_uri(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.uri.lua")); // NOTE: defaultUrl handled by Init_lib_url
|
||||
@@ -46,8 +47,8 @@ public class Scrib_lib_uri implements Scrib_lib {
|
||||
private static final String[] Proc_names = String_.Ary(Invk_anchorEncode, Invk_localUrl, Invk_fullUrl, Invk_canonicalUrl, Invk_init_uri_for_page);
|
||||
public boolean AnchorEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] raw_bry = args.Pull_bry(0);
|
||||
Bry_bfr bfr = core.App().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = core.App().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
Pfunc_anchorencode.Func_init(core.Ctx());
|
||||
Pfunc_anchorencode.Anchor_encode(raw_bry, bfr, tmp_bfr);
|
||||
tmp_bfr.Clear_and_rls();
|
||||
@@ -59,7 +60,7 @@ public class Scrib_lib_uri implements Scrib_lib {
|
||||
byte[] qry_bry = args.Extract_qry_args(wiki, 1);
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
|
||||
if (ttl == null) return rslt.Init_null();
|
||||
Bry_bfr bfr = core.App().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
if (ttl.Ns().Id() == Xow_ns_.Tid__media) { // change "Media:" -> "File:"
|
||||
bfr.Add(wiki.Ns_mgr().Ns_file().Name_db_w_colon());
|
||||
bfr.Add(ttl.Page_db());
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Scrib_lib_ustring implements Scrib_lib {
|
||||
public int Pattern_len_max() {return pattern_len_max;} public Scrib_lib_ustring Pattern_len_max_(int v) {pattern_len_max = v; return this;} private int pattern_len_max = 10000;
|
||||
private Scrib_regx_converter regx_converter = new Scrib_regx_converter();
|
||||
public Scrib_lib Init() {procs.Init_by_lib(this, Proc_names); return this;}
|
||||
public Scrib_lib Clone_lib(Scrib_core core) {return new Scrib_lib_ustring(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.ustring.lua")
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private 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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_wikibase(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.wikibase.lua"));
|
||||
@@ -93,7 +94,8 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
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[] 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"
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Wdata_doc wdoc = 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;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
public Scrib_lib_wikibase_entity(Scrib_core core) {this.core = core;} private 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_lib Clone_lib(Scrib_core core) {return new Scrib_lib_wikibase_entity(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.wikibase.entity.lua"));
|
||||
@@ -52,7 +53,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
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();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang);
|
||||
return rslt.Init_obj(bfr.To_bry_and_rls());
|
||||
}
|
||||
|
||||
@@ -90,37 +90,38 @@ class Scrib_lib_wikibase_srl {
|
||||
}
|
||||
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;
|
||||
Scrib_lib_wikibase_srl_visitor visitor = new Scrib_lib_wikibase_srl_visitor();
|
||||
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];
|
||||
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);
|
||||
Keyval[] grp_val = Srl_claims_prop_grp(visitor, "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
|
||||
}
|
||||
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(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wdata_claim_grp grp, int base_adj) {
|
||||
int len = grp.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(visitor, 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(Scrib_lib_wikibase_srl_visitor visitor, 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_("mainsnak", Srl_claims_prop_itm_core(visitor, 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));
|
||||
Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(visitor, itm.Qualifiers(), base_adj));
|
||||
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(Scrib_lib_wikibase_srl_visitor visitor, 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;
|
||||
List_adp rv = List_adp_.New();
|
||||
@@ -132,25 +133,24 @@ 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(visitor, 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)));
|
||||
}
|
||||
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(Scrib_lib_wikibase_srl_visitor visitor, 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];
|
||||
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] = Keyval_.new_("datavalue", Srl_claims_prop_itm_core_val(visitor, 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(Scrib_lib_wikibase_srl_visitor visitor, 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_OLD: throw exc
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.*;
|
||||
public class Xow_wiki_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xow_wiki_fxt fxt = new Xow_wiki_fxt();
|
||||
@Test public void Load_page_and_parse() { // PURPOSE.fix: unknown page causes null reference error in scribunto; DATE:2013-08-27
|
||||
fxt.Fxt().Wiki().Parser_mgr().Scrib().Core_make(fxt.Fxt().Ctx());
|
||||
fxt.Fxt().Wiki().Parser_mgr().Scrib().Core_init(fxt.Fxt().Ctx());
|
||||
fxt.Test_getPageByTtl("Does_not_exist", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*;
|
||||
public class Blacklist_scrib_lib implements Scrib_lib {
|
||||
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_lib Clone_lib(Scrib_core core) {return new Blacklist_scrib_lib();}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, core.App().Fsys_mgr().Bin_xtns_dir().GenSubFil_nest("TitleBlacklist", "mw.ext.TitleBlacklist.lua"));
|
||||
@@ -34,7 +35,7 @@ public class Blacklist_scrib_lib implements Scrib_lib {
|
||||
}
|
||||
private static final int Proc_test = 0;
|
||||
public static final String Invk_test = "test";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_test);
|
||||
private static final String[] Proc_names = String_.Ary(Invk_test);
|
||||
public boolean Test(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_null(); // assume all titles are blacklisted; note that this info is not available;
|
||||
}
|
||||
|
||||
@@ -26,18 +26,29 @@ public class Wbase_doc_mgr {
|
||||
this.hash = app.Cache_mgr().Doc_cache();
|
||||
}
|
||||
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Add(byte[] full_db, Wdata_doc page) {hash.Add(full_db, page);} // TEST:
|
||||
public void Clear() {
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
hash.Clear();
|
||||
}
|
||||
}
|
||||
public void Add(byte[] full_db, Wdata_doc page) { // TEST:
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
if (hash.Get_or_null(full_db) == null)
|
||||
hash.Add(full_db, page);
|
||||
}
|
||||
}
|
||||
public Wdata_doc Get_by_ttl_or_null(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
byte[] qid_bry = qid_mgr.Get_or_null(wiki, ttl); // EX: "enwiki","Earth" -> "Q2"
|
||||
return qid_bry == null ? null : this.Get_by_bry_or_null(qid_bry);
|
||||
}
|
||||
public Wdata_doc Get_by_xid_or_null(byte[] xid) {return Get_by_bry_or_null(Prepend_property_if_needed(xid));}// scribunto passes either p1 or q1; convert p1 to "Property:P1"
|
||||
public Wdata_doc Get_by_bry_or_null(byte[] full_db) { // must be format like "Q2" or "Property:P1"
|
||||
public Wdata_doc Get_by_bry_or_null(byte[] full_db) { // must be correct format; EX:"Q2" or "Property:P1"
|
||||
Wdata_doc rv = hash.Get_or_null(full_db);
|
||||
if (rv == null) {
|
||||
byte[] page_src = Load_or_null(full_db); if (page_src == null) return null; // page not found
|
||||
rv = new Wdata_doc(full_db, wbase_mgr, wbase_mgr.Jdoc_parser().Parse(page_src));
|
||||
synchronized (hash) { // LOCK:app-level; both hash and jdoc_parser
|
||||
rv = new Wdata_doc(full_db, wbase_mgr, wbase_mgr.Jdoc_parser().Parse(page_src));
|
||||
}
|
||||
Add(full_db, rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -46,7 +57,7 @@ public class Wbase_doc_mgr {
|
||||
if (!enabled) return null;
|
||||
Xoa_ttl page_ttl = Xoa_ttl.Parse(wbase_mgr.Wdata_wiki(), full_db); if (page_ttl == null) {app.Usr_dlg().Warn_many("", "", "invalid qid for ttl: qid=~{0}", full_db); return null;}
|
||||
Xoae_page page_itm = wbase_mgr.Wdata_wiki().Data_mgr().Load_page_by_ttl(page_ttl);
|
||||
return page_itm.Db().Page().Exists_n() ? null : page_itm.Db().Text().Text_bry();
|
||||
return page_itm.Db().Page().Exists() ? page_itm.Db().Text().Text_bry() : null;
|
||||
}
|
||||
|
||||
private static byte[] Prepend_property_if_needed(byte[] bry) {
|
||||
|
||||
@@ -21,8 +21,17 @@ public class Wbase_pid_mgr { // EX: "en|road_map" -> 15 ("Property:P15")
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Wbase_pid_mgr(Wdata_wiki_mgr wbase_mgr) {this.wbase_mgr = wbase_mgr;}
|
||||
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Add(byte[] pid_key, int pid_id) {hash.Add_bry_int(pid_key, pid_id);}
|
||||
public void Clear() {
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
hash.Clear();
|
||||
}
|
||||
}
|
||||
public void Add(byte[] pid_key, int pid_id) {
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
if (!hash.Has(pid_key))
|
||||
hash.Add_bry_int(pid_key, pid_id);
|
||||
}
|
||||
}
|
||||
public int Get_or_null(byte[] lang_key, byte[] pid_name) {
|
||||
if (!enabled) return Wdata_wiki_mgr.Pid_null;
|
||||
byte[] pid_key = Bry_.Add(lang_key, Byte_ascii.Pipe_bry, pid_name); // EX: "en|road_map"
|
||||
|
||||
@@ -20,16 +20,20 @@ import gplx.xowa.wikis.domains.*;
|
||||
public class Wbase_qid_mgr {// EX: "enwiki|0|Earth" -> "Q2"
|
||||
private final Wdata_wiki_mgr wbase_mgr;
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private final gplx.core.primitives.Int_obj_ref tmp_wiki_tid = gplx.core.primitives.Int_obj_ref.New_zero();
|
||||
private final gplx.core.primitives.Int_obj_ref tmp_wiki_tid = gplx.core.primitives.Int_obj_ref.New_zero(); // NOTE: return value is not checked; only used for function signature
|
||||
public Wbase_qid_mgr(Wdata_wiki_mgr wbase_mgr) {
|
||||
this.wbase_mgr = wbase_mgr;
|
||||
}
|
||||
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Clear() {
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
hash.Clear();
|
||||
}
|
||||
}
|
||||
public void Add(Bry_bfr bfr, byte[] lang_key, int wiki_tid, byte[] ns_num, byte[] ttl, byte[] qid) { // TEST:
|
||||
Xow_abrv_wm_.To_abrv(bfr, lang_key, tmp_wiki_tid.Val_(wiki_tid));
|
||||
byte[] qids_key = bfr.Add_byte(Byte_ascii.Pipe).Add(ns_num).Add_byte(Byte_ascii.Pipe).Add(ttl).To_bry();
|
||||
hash.Add(qids_key, qid);
|
||||
this.Add(qids_key, qid);
|
||||
}
|
||||
public byte[] Get_or_null(Xowe_wiki wiki, Xoa_ttl ttl) {return Get_or_null(wiki.Wdata_wiki_abrv(), ttl);}
|
||||
public byte[] Get_or_null(byte[] wiki_abrv, Xoa_ttl ttl) {
|
||||
@@ -40,8 +44,14 @@ public class Wbase_qid_mgr {// EX: "enwiki|0|Earth" -> "Q2"
|
||||
if (rv == null) { // not in cache; load from db
|
||||
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_qid(wiki_abrv, ttl.Ns().Num_bry(), ttl.Page_db());
|
||||
byte[] val_for_hash = rv == null ? Bry_.Empty : rv; // JAVA: hashtable does not accept null as value; use Bry_.Empty
|
||||
hash.Add(key, val_for_hash); // NOTE: if not in db, will insert Bry_.Empty; DATE:2014-07-23
|
||||
this.Add(key, val_for_hash); // NOTE: if not in db, will insert Bry_.Empty; DATE:2014-07-23
|
||||
}
|
||||
return Bry_.Len_eq_0(rv) ? null : rv; // JAVA: convert Bry_.Empty to null which is what callers expect
|
||||
}
|
||||
private void Add(byte[] key, byte[] val) {
|
||||
synchronized (hash) { // LOCK:app-level
|
||||
if (!hash.Has(key))
|
||||
hash.Add(key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
private final Wdata_prop_val_visitor prop_val_visitor;
|
||||
private final Wdata_doc_parser wdoc_parser_v1 = new Wdata_doc_parser_v1(), wdoc_parser_v2 = new Wdata_doc_parser_v2();
|
||||
private Wdata_hwtr_mgr hwtr_mgr;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32);
|
||||
public Wdata_wiki_mgr(Xoae_app app) {
|
||||
this.app = app;
|
||||
this.evt_mgr = new Gfo_evt_mgr(this);
|
||||
@@ -60,9 +61,11 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
}
|
||||
public Xop_log_property_wkr Property_wkr() {return property_wkr;} private Xop_log_property_wkr property_wkr;
|
||||
public void Clear() {
|
||||
Qid_mgr.Clear();
|
||||
Pid_mgr.Clear();
|
||||
Doc_mgr.Clear();
|
||||
synchronized (wdoc_parser_v2) { // LOCK:app-level
|
||||
Qid_mgr.Clear();
|
||||
Pid_mgr.Clear();
|
||||
Doc_mgr.Clear();
|
||||
}
|
||||
}
|
||||
public byte[] Get_claim_or(Xow_domain_itm domain, Xoa_ttl page_ttl, int pid, byte[] or) {
|
||||
byte[] qid = this.Qid_mgr.Get_or_null(domain.Abrv_wm(), page_ttl); if (qid == null) return or;
|
||||
@@ -74,7 +77,7 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
claim_itm.Welcome(prop_val_visitor);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
} private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32);
|
||||
}
|
||||
public void Resolve_to_bfr(Bry_bfr bfr, Wdata_claim_grp prop_grp, byte[] lang_key) {
|
||||
synchronized (this) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
|
||||
Hwtr_mgr_assert();
|
||||
@@ -121,13 +124,11 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
}
|
||||
private void Hwtr_msgs_make() {
|
||||
if (!app.Wiki_mgr().Wiki_regy().Has(Xow_domain_itm_.Bry__wikidata)) return;
|
||||
// synchronized (this) { // LOCK:DELETE; DATE:2016-07-06
|
||||
Xol_lang_itm new_lang = app.Usere().Lang();
|
||||
Xowe_wiki cur_wiki = this.Wdata_wiki();
|
||||
cur_wiki.Xtn_mgr().Xtn_wikibase().Load_msgs(cur_wiki, new_lang);
|
||||
Wdata_hwtr_msgs hwtr_msgs = Wdata_hwtr_msgs.new_(cur_wiki.Msg_mgr());
|
||||
hwtr_mgr.Init_by_lang(hwtr_msgs);
|
||||
// }
|
||||
Xol_lang_itm new_lang = app.Usere().Lang();
|
||||
Xowe_wiki cur_wiki = this.Wdata_wiki();
|
||||
cur_wiki.Xtn_mgr().Xtn_wikibase().Load_msgs(cur_wiki, new_lang);
|
||||
Wdata_hwtr_msgs hwtr_msgs = Wdata_hwtr_msgs.new_(cur_wiki.Msg_mgr());
|
||||
hwtr_mgr.Init_by_lang(hwtr_msgs);
|
||||
}
|
||||
public static void Write_json_as_html(Json_parser jdoc_parser, Bry_bfr bfr, byte[] data_raw) {
|
||||
bfr.Add(Xoh_consts.Span_bgn_open).Add(Xoh_consts.Id_atr).Add(Html_json_id).Add(Xoh_consts.__end_quote); // <span id="xowa-wikidata-json">
|
||||
|
||||
@@ -80,7 +80,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
}
|
||||
}
|
||||
public void Init_qids_add(String lang_key, int wiki_tid, String ttl, String qid) {
|
||||
Bry_bfr tmp_bfr = app.Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
wdata_mgr.Qid_mgr.Add(tmp_bfr, Bry_.new_a7(lang_key), wiki_tid, Bry_.new_a7("000"), Bry_.new_a7(ttl), Bry_.new_a7(qid));
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
|
||||
parser_fxt.Page_ttl_("Q1_en");
|
||||
parser_fxt.Exec_parse_page_all_as_str(raw);
|
||||
Bry_bfr tmp_bfr = wiki.Appe().Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
|
||||
wdata_lang_wtr.Page_(page).Bfr_arg__add(tmp_bfr);
|
||||
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_rls());
|
||||
@@ -168,7 +168,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
public void Test_write_json_as_html(String raw_str, String expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw_str);
|
||||
raw_bry = gplx.langs.jsons.Json_parser_tst.Replace_apos(raw_bry);
|
||||
Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
Wdata_wiki_mgr.Write_json_as_html(wdata_mgr.Jdoc_parser(), bfr, raw_bry);
|
||||
Tfds.Eq(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Wdata_xwiki_link_wtr implements gplx.core.brys.Bfr_arg {
|
||||
Wdata_doc doc = wdata_mgr.Doc_mgr.Get_by_ttl_or_null(wiki, ttl); if (doc == null) return Qid_null; // no links
|
||||
boolean external_links_mgr_enabled = external_links_mgr.Enabled();
|
||||
Ordered_hash links = doc.Slink_list();
|
||||
Bry_bfr tmp_bfr = wiki.Appe().Utl__bfr_mkr().Get_k004();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
int len = links.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wdata_sitelink_itm slink = (Wdata_sitelink_itm)links.Get_at(i);
|
||||
|
||||
@@ -406,7 +406,7 @@ class Wdata_qual_tbl extends Wdata_tbl_base {
|
||||
private static final String Fld_qual_id = "qual_id", Fld_page_id = "page_id", Fld_val_text = "val_text";
|
||||
}
|
||||
class Xob_wdata_db_visitor implements Wdata_claim_visitor {
|
||||
private final Wdata_wiki_mgr wdata_mgr; private byte[] lang_key;
|
||||
private final Wdata_wiki_mgr wdata_mgr; private byte[] lang_key;
|
||||
public Xob_wdata_db_visitor(Wdata_wiki_mgr wdata_mgr) {this.wdata_mgr = wdata_mgr;}
|
||||
public void Init(byte[] lang_key) {this.lang_key = lang_key;}
|
||||
public byte[] Rv() {return rv;} private byte[] rv;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Wdata_external_lang_links_data {
|
||||
if (Bry_.Eq(argx, Key_sort)) {sort = true; return;} // {{noexternallanglinks:*}}; assume it cannot be combined with other langs_hash: EX: {{noexternallanglinks:*|en|fr}}
|
||||
int args_len = self.Args_len();
|
||||
Langs_add(argx);
|
||||
Bry_bfr tmp_bfr = ctx.App().Utl__bfr_mkr().Get_b128();
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b128();
|
||||
for (int i = 0; i < args_len; i++) {
|
||||
Arg_nde_tkn nde = self.Args_get_by_idx(i);
|
||||
nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, tmp_bfr); // NOTE: changed from self to caller; DATE:2016-03-16
|
||||
|
||||
@@ -58,10 +58,10 @@ public class Wdata_itemByTitle_page implements Xow_special_page {
|
||||
}
|
||||
private static boolean Navigate(Gfo_usr_dlg usr_dlg, Xoae_app app, Wdata_wiki_mgr wdata_mgr, Xoae_page page, byte[] site_bry, byte[] page_bry) {
|
||||
page_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url.Decode(page_bry); // NOTE: space is converted to + on postback to url; decode
|
||||
byte[] wiki_domain = Xow_abrv_wm_.Parse_to_domain_bry(site_bry); if (wiki_domain == null) {usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_u8(site_bry)); return false;}
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(wiki_domain); if (wiki == null) {usr_dlg.Warn_many("", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_u8(wiki_domain)); return false;}
|
||||
Xoa_ttl wdata_ttl = Xoa_ttl.Parse(wiki, page_bry); if (wdata_ttl == null) {usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_u8(page_bry)); return false;}
|
||||
Wdata_doc doc = wdata_mgr.Doc_mgr.Get_by_ttl_or_null(wiki, wdata_ttl); if (doc == null) {usr_dlg.Warn_many("", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_u8(wdata_ttl.Raw())); return false;}
|
||||
byte[] wiki_domain = Xow_abrv_wm_.Parse_to_domain_bry(site_bry); if (wiki_domain == null) {usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_u8(site_bry)); return false;}
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(wiki_domain); if (wiki == null) {usr_dlg.Warn_many("", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_u8(wiki_domain)); return false;}
|
||||
Xoa_ttl wdata_ttl = Xoa_ttl.Parse(wiki, page_bry); if (wdata_ttl == null) {usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_u8(page_bry)); return false;}
|
||||
Wdata_doc doc = wdata_mgr.Doc_mgr.Get_by_ttl_or_null(wiki, wdata_ttl); if (doc == null) {usr_dlg.Warn_many("", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_u8(wdata_ttl.Raw())); return false;}
|
||||
byte[] qid_bry = doc.Qid();
|
||||
wdata_mgr.Wdata_wiki().Data_mgr().Redirect(page, qid_bry); if (page.Db().Page().Exists_n()) {usr_dlg.Warn_many("", "", "qid cannot be found in wikidata; qid:~{0}", String_.new_u8(qid_bry)); return false;}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user