mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Evaluate template args for missing templates else en.w flags will sometimes be large
This commit is contained in:
parent
c98404a8fe
commit
d6aeb2e177
@ -19,5 +19,5 @@ package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.
|
||||
public class Xot_compile_data {
|
||||
public boolean OnlyInclude_exists;
|
||||
public boolean Arg_nde_has_key() {return arg_nde_has_key;} public Xot_compile_data Arg_nde_has_key_(boolean v) {arg_nde_has_key = v; return this;} private boolean arg_nde_has_key;
|
||||
public static final Xot_compile_data Null = new Xot_compile_data();
|
||||
public static final Xot_compile_data Noop = new Xot_compile_data();
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class Xot_defn_tmpl implements Xot_defn {
|
||||
byte[] new_data = Extract_onlyinclude(data_raw, wiki.Utl__bfr_mkr());
|
||||
Xop_ctx new_ctx = Xop_ctx.New__sub(wiki, ctx, page); // COMMENT:changed from ctx.Page() to page; DATE:2016-07-11
|
||||
Xot_defn_tmpl tmpl = wiki.Parser_mgr().Main().Parse_text_to_defn_obj(new_ctx, new_ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), Bry_.Empty, new_data);
|
||||
tmpl.Root().Tmpl_compile(new_ctx, new_data, Xot_compile_data.Null);
|
||||
tmpl.Root().Tmpl_compile(new_ctx, new_data, Xot_compile_data.Noop);
|
||||
data_raw = new_data;
|
||||
root = tmpl.Root();
|
||||
}
|
||||
|
@ -154,9 +154,9 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
||||
case Xot_defn_.Tid_raw:
|
||||
case Xot_defn_.Tid_msg:
|
||||
int raw_colon_pos = Bry_find_.Find_fwd(name_ary, Byte_ascii.Colon);
|
||||
if (raw_colon_pos == Bry_find_.Not_found) {} // colon missing; EX: {{raw}}; noop and assume template name; DATE:2014-02-11
|
||||
if (raw_colon_pos == Bry_find_.Not_found) {} // colon missing; EX: {{raw}}; noop and assume template name; DATE:2014-02-11
|
||||
else { // colon present;
|
||||
name_ary = Bry_.Mid(name_ary, finder_subst_end + 1, name_ary_len); // chop off "raw"; +1 is for ":"; note that +1 is in bounds b/c raw_colon was found
|
||||
name_ary = Bry_.Mid(name_ary, finder_subst_end + 1, name_ary_len); // chop off "raw"; +1 is for ":"; note that +1 is in bounds b/c raw_colon was found
|
||||
name_ary_len = name_ary.length;
|
||||
Object ns_eval2 = wiki.Ns_mgr().Names_get_w_colon(name_ary, 0, name_ary_len); // match {{:Portal or {{:Wikipedia
|
||||
if (ns_eval2 != null) {
|
||||
@ -198,14 +198,16 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
||||
if (subst_found || template_prefix_found) { // if "subst:" or "Template:" found, use orig name; DATE:2014-03-31
|
||||
bfr.Add(Xop_curly_bgn_lxr.Hook).Add(name_ary_orig).Add(Xop_curly_end_lxr.Hook);
|
||||
return false;
|
||||
}
|
||||
else { // output entire tmpl_src WITH args; used to output name only which broke pages; PAGE:en.w:Flag_of_Greenland; DATE:2016-06-21
|
||||
}
|
||||
else {// output entire tmpl_src WITH args; used to output name only which broke pages; PAGE:en.w:Flag_of_Greenland; DATE:2016-06-21
|
||||
bfr.Add(Xop_curly_bgn_lxr.Hook);
|
||||
bfr.Add(name_ary);
|
||||
for (int i = 0; i < args_len; ++i) {
|
||||
Arg_nde_tkn nde = this.Args_get_by_idx(i);
|
||||
bfr.Add_byte(Byte_ascii.Pipe);
|
||||
bfr.Add_mid(src, nde.Src_bgn(), nde.Src_end());
|
||||
// must evaluate args; "size={{{size|}}}" must become "size="; PAGE:en.w:Europe; en.w:Template:Country_data_Guernsey DATE:2016-10-13
|
||||
nde.Tmpl_compile(ctx, src, Xot_compile_data.Noop);
|
||||
nde.Tmpl_evaluate(ctx, src, caller, bfr);
|
||||
}
|
||||
bfr.Add(Xop_curly_end_lxr.Hook);
|
||||
return false;
|
||||
|
@ -31,6 +31,12 @@ public class Xot_invk_wkr__missing__tst {
|
||||
fxt.Test_parse_tmpl_str("{{test_template}}", "{{{{{1}}}| a | b }}"); // NOTE: this should include spaces (" {{{1}}} "), but for now, ignore
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Missing__evaluate_optional() { // PURPOSE: missing title should still evaulate optional args; "{{{a|}}}" -> ""; PAGE:en.w:Europe; en.w:Template:Country_data_Guernsey DATE:2016-10-13
|
||||
fxt.Init_defn_clear();
|
||||
fxt.Init_defn_add("test_template", "{{ {{{1}}} | {{{a|}}} | b }}");
|
||||
fxt.Test_parse_tmpl_str("{{test_template}}", "{{{{{1}}}| | b }}"); // NOTE: "| |" not "| {{{a|}}} |"
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Missing_foreign() {
|
||||
Xow_ns ns = fxt.Wiki().Ns_mgr().Ns_template();
|
||||
byte[] old_ns = ns.Name_db();
|
||||
|
Loading…
Reference in New Issue
Block a user