mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.7.3.1
This commit is contained in:
@@ -67,7 +67,7 @@ public class Xop_curly_wkr implements Xop_ctx_wkr {
|
||||
int curly_end_dash = lxr_end_pos;
|
||||
if (curly_end_dash < src_len && src[curly_end_dash] == Byte_ascii.Dash) { // "-" exists after curlies; EX: "}}-"
|
||||
if (bgn_tkn_len > 2 && end_tkn_len > 2) { // more than 3 curlies at bgn / end with flanking dashes; EX: "-{{{ }}}-"; NOTE: 3 is needed b/c 2 will never be reduced; EX: "-{{" will always be "-" and "{{", not "-{" and "{"
|
||||
int numeric_val = Bry_.X_to_int_or(src, bgn_tkn.Src_end(), lxr_bgn_pos, -1);
|
||||
int numeric_val = Bry_.Xto_int_or(src, bgn_tkn.Src_end(), lxr_bgn_pos, -1);
|
||||
if ( numeric_val != -1 // do not apply if numeric val; EX:"-{{{0}}}-" vs "-{{{#expr:0}}}-" sr.w:Template:Link_FA
|
||||
&& bgn_tkn_len == 3 && end_tkn_len == 3 // exactly 3 tokens; assume param token; "-{{{" -> "-" + "{{{" x> -> "-{" + "{{"; if unbalanced (3,4 or 4,3) fall into code below
|
||||
) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Xop_subst_tst {
|
||||
@Test public void Tmpl_txt_subst_pf() {fxt.Test_parse_tmpl_str_test("{{subst:#expr:0}}" , "{{test}}" , "0");}
|
||||
@Test public void Tmpl_txt_safesubst_prm() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}#if:{{{1|}}}{{{{{|safesubst:}}}!}}c1|c2}}" , "{{test}}" , "c2");}
|
||||
@Test public void Exc_tmpl_prm_safesubst_ns() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst}}}:NAMESPACE}}" , "{{test}}" , "");}
|
||||
@Test public void Unreferenced() { // PURPOSE: if subst, but in tmpl stage, do not actually subst; EX.WP:Unreferenced; DATE:2013-01-31
|
||||
@Test public void Unreferenced() { // PURPOSE: if subst, but in tmpl stage, do not actually subst; PAGE:en.w:Unreferenced; DATE:2013-01-31
|
||||
fxt.Init_defn_clear();
|
||||
fxt.Init_defn_add("substcheck", "SUBST");
|
||||
fxt.Init_defn_add("ifsubst", String_.Concat_lines_nl
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Xot_defn_tmpl_ {
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
orig.Subs_get(i).Tmpl_evaluate(ctx, src, caller, arg_bfr);
|
||||
Arg_itm_tkn rv = tkn_mkr.ArgItm(-1, -1); // NOTE: was -1, 0; DATE:2013-04-10
|
||||
byte[] rv_ary = orig_arg.KeyTkn_exists() && val_tkn ? arg_bfr.XtoAryAndClearAndTrim() : arg_bfr.XtoAryAndClear(); // // NOTE: must trim if key_exists; DUPE:TRIM_IF_KEY; EX.WP:Coord in Chernobyl disaster, Sahara
|
||||
byte[] rv_ary = orig_arg.KeyTkn_exists() && val_tkn ? arg_bfr.XtoAryAndClearAndTrim() : arg_bfr.XtoAryAndClear(); // // NOTE: must trim if key_exists; DUPE:TRIM_IF_KEY; PAGE:en.w:Coord in Chernobyl disaster, Sahara
|
||||
rv.Dat_ary_(rv_ary);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Xot_examples_tst {
|
||||
@Test public void About() {
|
||||
Init_tmpl_about(); fxt.Test_parse_tmpl_str("{{About|abc}}", "This article is about abc.  For other uses, see [[Test page (disambiguation)]].");
|
||||
}
|
||||
@Test public void About_2() { // EX.WP: {{About|the NASA space mission||Messenger (disambiguation)}}
|
||||
@Test public void About_2() { // PAGE:en.w:{{About|the NASA space mission||Messenger (disambiguation)}}
|
||||
Init_tmpl_about(); fxt.Test_parse_tmpl_str("{{About|a||b{{!}}c}}", "This article is about a.  For other uses, see [[b|c]].");
|
||||
}
|
||||
@Test public void OtherUses() {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Xot_invk_mock implements Xot_invk {
|
||||
for (int i = 0; i < list_len; i++) { // iterate over list to find nth *non-keyd* arg; SEE:NOTE_1
|
||||
Arg_nde_tkn nde = (Arg_nde_tkn)args.FetchAt(i);
|
||||
if (nde.KeyTkn_exists()) {
|
||||
int key_int = Bry_.X_to_int_or(nde.Key_tkn().Dat_ary(), -1);
|
||||
int key_int = Bry_.Xto_int_or(nde.Key_tkn().Dat_ary(), -1);
|
||||
if (key_int == -1)
|
||||
continue;
|
||||
else { // key is numeric
|
||||
@@ -55,7 +55,8 @@ public class Xot_invk_mock implements Xot_invk {
|
||||
}
|
||||
public Arg_nde_tkn Args_get_by_key(byte[] src, byte[] key) {return (Arg_nde_tkn)args.Fetch(key);}
|
||||
public static Xot_invk_mock new_(byte defn_tid, KeyVal... args) {return new_(defn_tid, 1, args);}
|
||||
public static Xot_invk_mock new_(KeyVal... args) {return new_(Xot_defn_.Tid_null, 1, args);}
|
||||
public static Xot_invk_mock new_(KeyVal... args) {return new_(Xot_defn_.Tid_null, 1, args);}
|
||||
public static Xot_invk_mock test_(KeyVal... args) {return new_(Xot_defn_.Tid_null, 0, args);}
|
||||
// public static Xot_invk_mock new_(byte defn_tid, int idx_adj, params KeyVal[] args) {
|
||||
// Xot_invk_mock rv = new Xot_invk_mock(defn_tid, idx_adj);
|
||||
// int len = args.length;
|
||||
|
||||
@@ -16,14 +16,15 @@ 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; import gplx.*;
|
||||
import gplx.xowa.xtns.scribunto.*;
|
||||
public class Xot_invk_temp implements Xot_invk {
|
||||
public Xot_invk_temp(boolean root_frame) {this.root_frame = root_frame;}
|
||||
public Xot_invk_temp(byte defn_tid, byte[] src, Arg_nde_tkn name_tkn, int src_bgn, int src_end) {
|
||||
this.defn_tid = defn_tid; this.src = src;
|
||||
this.name_tkn = name_tkn; this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
}
|
||||
public byte[] Src() {return src;} private byte[] src; public Xot_invk_temp Src_(byte[] src) {this.src = src; return this;}
|
||||
public byte Defn_tid() {return defn_tid;} private byte defn_tid = Xot_defn_.Tid_null;
|
||||
public Xot_invk_temp(boolean root_frame) {this.root_frame = root_frame;}
|
||||
public boolean Root_frame() {return root_frame;} private boolean root_frame;
|
||||
public Arg_nde_tkn Name_tkn() {return name_tkn;} Arg_nde_tkn name_tkn;
|
||||
public byte[] Frame_ttl() {return frame_ttl;} public void Frame_ttl_(byte[] v) {frame_ttl = v;} private byte[] frame_ttl = Bry_.Empty; // NOTE: set frame_ttl to non-null value; PAGE:en.w:Constantine_the_Great {{Christianity}}; DATE:2014-06-26
|
||||
@@ -38,7 +39,7 @@ public class Xot_invk_temp implements Xot_invk {
|
||||
for (int i = 0; i < list_len; i++) { // iterate over list to find nth *non-keyd* arg; SEE:NOTE_1
|
||||
Arg_nde_tkn nde = (Arg_nde_tkn)list.FetchAt(i);
|
||||
if (nde.KeyTkn_exists()) {
|
||||
int key_int = Bry_.X_to_int_or(nde.Key_tkn().Dat_ary(), -1);
|
||||
int key_int = Bry_.Xto_int_or(nde.Key_tkn().Dat_ary(), -1);
|
||||
if (key_int == -1)
|
||||
continue;
|
||||
else { // key is numeric
|
||||
@@ -65,7 +66,7 @@ public class Xot_invk_temp implements Xot_invk {
|
||||
hash.Del(key_ref);
|
||||
hash.Add(key_ref, arg);
|
||||
} HashAdp hash = HashAdp_.new_();
|
||||
public static final Xot_invk_temp PageIsCaller = new Xot_invk_temp(true); // SEE NOTE_2
|
||||
public static final Xot_invk_temp Page_is_caller = new Xot_invk_temp(true); // SEE NOTE_2
|
||||
Xot_invk_temp() {}
|
||||
}
|
||||
/*
|
||||
@@ -83,6 +84,6 @@ WIKI: "a {{mwo_concat|{{{1}}}|b}} c"
|
||||
TEXT: "a {{{1}}}b c"
|
||||
|
||||
Note that in order to resolve mwo_concat we need to pass in an Xot_invk
|
||||
This Xot_invk is the "PageIsCaller" ref
|
||||
This Xot_invk is the "Page_is_caller" ref
|
||||
Note this has no parameters and is always empty
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.cnvs.*;
|
||||
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.pfuncs.ttls.*;
|
||||
public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
||||
public boolean Root_frame() {return false;}
|
||||
public Arg_nde_tkn Name_tkn() {return name_tkn;} public Xot_invk_tkn Name_tkn_(Arg_nde_tkn v) {name_tkn = v; return this;} Arg_nde_tkn name_tkn = Arg_nde_tkn.Null;
|
||||
@@ -179,7 +179,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
||||
}
|
||||
defn = wiki.Cache_mgr().Defn_cache().Get_by_key(name_ary);
|
||||
if (defn == null) {
|
||||
if (name_ary_len != 0 ) { // name_ary_len != 0 for direct template inclusions; EX.WP:Human evolution and {{:Human evolution/Species chart}}; && ctx.Tmpl_whitelist().Has(name_ary)
|
||||
if (name_ary_len != 0 ) { // name_ary_len != 0 for direct template inclusions; PAGE:en.w:Human evolution and {{:Human evolution/Species chart}}; && ctx.Tmpl_whitelist().Has(name_ary)
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.Add(wiki.Ns_mgr().Ns_template().Name_db_w_colon(), name_ary));
|
||||
if (ttl == null) { // ttl is not valid; just output orig; REF.MW:Parser.php|braceSubstitution|if ( !$found ) $text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
|
||||
byte[] missing_ttl
|
||||
@@ -225,9 +225,9 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
|
||||
ignore_hash.Add_str_obj("Clarify{{subst", String_.Empty);
|
||||
}
|
||||
if (ignore_hash.Get_by_bry(name_ary) == null) {
|
||||
if (Pf_xtn_rel2abs.Rel2abs_ttl(name_ary, name_bgn, name_ary_len)) {// rel_path; EX: {{/../Peer page}}; DATE:2013-03-27
|
||||
if (Pfunc_rel2abs.Rel2abs_ttl(name_ary, name_bgn, name_ary_len)) {// rel_path; EX: {{/../Peer page}}; DATE:2013-03-27
|
||||
Bry_bfr tmp_bfr = ctx.App().Utl_bry_bfr_mkr().Get_b512();
|
||||
name_ary = Pf_xtn_rel2abs.Rel2abs(tmp_bfr, Bry_.Mid(name_ary, name_bgn, name_ary_len), ctx.Cur_page().Ttl().Raw());
|
||||
name_ary = Pfunc_rel2abs.Rel2abs(tmp_bfr, Bry_.Mid(name_ary, name_bgn, name_ary_len), ctx.Cur_page().Ttl().Raw());
|
||||
tmp_bfr.Mkr_rls();
|
||||
return SubEval(ctx, wiki, bfr, name_ary, caller, src);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class Xot_invk_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
|
||||
case Xot_defn_.Tid_safesubst:
|
||||
int subst_bgn = finder.Subst_bgn(), subst_end = finder.Subst_end();
|
||||
invk.Tmpl_subst_props_(finder_typeId, subst_bgn, subst_end);
|
||||
if ((ctx.Parse_tid() == Xop_parser_.Parse_tid_tmpl && finder_typeId == Xot_defn_.Tid_subst) // NOTE: if subst, but in tmpl stage, do not actually subst; EX.WP:Unreferenced; DATE:2013-01-31
|
||||
if ((ctx.Parse_tid() == Xop_parser_.Parse_tid_tmpl && finder_typeId == Xot_defn_.Tid_subst) // NOTE: if subst, but in tmpl stage, do not actually subst; PAGE:en.w:Unreferenced; DATE:2013-01-31
|
||||
|| ctx.Cur_page().Ttl().Ns().Id_tmpl()) { // also, if on tmpl page, never evaluate (questionable, but seems to be needed)
|
||||
}
|
||||
else
|
||||
|
||||
@@ -243,7 +243,7 @@ public class Xot_invk_wkr_basic_tst {
|
||||
fxt.Test_parse_tmpl_str("{{test_1| a }}", "a");
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Ws_trimmed_key_2() { // PURPOSE: trim prm; note that 1 is key not idx; EX.WP:Coord in Chernobyl disaster, Sahara
|
||||
@Test public void Ws_trimmed_key_2() { // PURPOSE: trim prm; note that 1 is key not idx; PAGE:en.w:Coord in Chernobyl disaster, Sahara
|
||||
fxt.Init_defn_clear();
|
||||
fxt.Init_defn_add("test_1", "{{test_2|1={{{1}}}}}");
|
||||
fxt.Init_defn_add("test_2", "{{{1}}}");
|
||||
@@ -265,7 +265,7 @@ public class Xot_invk_wkr_basic_tst {
|
||||
fxt.Test_parse_tmpl_str("{{test_1|a}}", "a");
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Keyd_arg_is_trimmed() { // PURPOSE: trim entire arg only, not individual prm; EX.WP: William Shakespeare; {{Relatebardtree}}
|
||||
@Test public void Keyd_arg_is_trimmed() { // PURPOSE: trim entire arg only, not individual prm; PAGE:en.w:William Shakespeare; {{Relatebardtree}}
|
||||
fxt.Init_defn_clear();
|
||||
fxt.Init_defn_add("test_1", "{{test_2|1={{{{{{1}}}}}}}}");
|
||||
fxt.Init_defn_add("test_2", "{{{1}}}");
|
||||
@@ -278,7 +278,7 @@ public class Xot_invk_wkr_basic_tst {
|
||||
fxt.Test_parse_tmpl_str("{{test_1| }}", "(? [[dynamic is blank]] ?)");
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Xnde_xtn_ref_not_arg() { // PURPOSE: <ref name= should not be interpreted as arg; EX: {{tmp|a<ref name="b"/>}}; arg1 is a<ref name="b"/> not "b"; EX.WP: WWI
|
||||
@Test public void Xnde_xtn_ref_not_arg() { // PURPOSE: <ref name= should not be interpreted as arg; EX: {{tmp|a<ref name="b"/>}}; arg1 is a<ref name="b"/> not "b"; PAGE:en.w:WWI
|
||||
fxt.Init_defn_clear();
|
||||
fxt.Init_defn_add("test_1", "{{{1}}}");
|
||||
fxt.Test_parse_page_tmpl_str("{{test_1|a<ref name=b />}}", "a<ref name=b />");
|
||||
@@ -426,5 +426,5 @@ Template:Test with text of "#a"
|
||||
a) "a{{test}}" would return "a\n#a" b/c of rule for auto-adding \n
|
||||
b) bug was that "{{test}}" would return "#a" b/c "#a" was at bos which would expand to list later
|
||||
however, needs to be "\n#a" b/c appended to other strings wherein bos would be irrelevant.
|
||||
Actual situation was very complicated. EX.WP:Rome
|
||||
Actual situation was very complicated. PAGE:en.w:Rome
|
||||
*/
|
||||
|
||||
@@ -48,10 +48,10 @@ public class Xot_invk_wkr_prepend_nl_tst {
|
||||
));
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Pfunc() {// PURPOSE: if {| : ; # *, auto add new_line; parser_function variant; EX.WP:Soviet Union; Infobox former country
|
||||
@Test public void Pfunc() {// PURPOSE: if {| : ; # *, auto add new_line; parser_function variant; PAGE:en.w:Soviet Union; Infobox former country
|
||||
fxt.Test_parse_tmpl_str_test("" , "z {{#if:true|#a|n}}" , "z \n#a");
|
||||
}
|
||||
@Test public void Bos() { // PURPOSE: function should expand "*a" to "\n*a" even if "*a" is bos; SEE:NOTE_1 EX.WP: Rome and Panoramas;
|
||||
@Test public void Bos() { // PURPOSE: function should expand "*a" to "\n*a" even if "*a" is bos; SEE:NOTE_1 PAGE:en.w:Rome and Panoramas;
|
||||
fxt.Test_parse_page_tmpl_str("{{#if:x|*a}}", "\n*a");
|
||||
}
|
||||
@Test public void Tmpl_arg() { // PURPOSE: tmpl arg should auto-create?
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Xot_prm_tkn extends Xop_tkn_itm_base {
|
||||
if (find_tkn_static) { // subs_are_static, so extract idx/key; EX: {{{a b}}} will have 3 subs which are all static; {{{a{{{1}}}b}}} will be dynamic
|
||||
int find_tkn_bgn = find_tkn.Dat_bgn(), find_tkn_end = find_tkn.Dat_end();
|
||||
if (find_tkn_end - find_tkn_bgn > 0) { // NOTE: handles empty find_tkns; EX: {{{|safesubst:}}}
|
||||
prm_idx = Bry_.X_to_int_or(src, find_tkn_bgn, find_tkn_end, -1); // parse as number first; note that bgn,end should not include ws; EX: " 1 " will fail
|
||||
prm_idx = Bry_.Xto_int_or(src, find_tkn_bgn, find_tkn_end, -1); // parse as number first; note that bgn,end should not include ws; EX: " 1 " will fail
|
||||
if (prm_idx == -1) prm_key = Bry_.Mid(src, find_tkn_bgn, find_tkn_end);// not a number; parse as key
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,9 @@ public class Xot_prm_tkn extends Xop_tkn_itm_base {
|
||||
Bry_bfr find_bfr = Bry_bfr.new_();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
find_tkn.Subs_get(i).Tmpl_evaluate(ctx, src, caller, find_bfr);
|
||||
prm_idx = Bry_.X_to_int_or_trim(find_bfr.Bfr(), 0, find_bfr.Len(), -1); // parse as number first; NOTE: trim needed to transform "{{{ 1 }}}" to "1"; it.w:Portale:Giochi_da_tavolo; DATE:2014-02-09
|
||||
prm_idx = Bry_.Xto_int_or_trim(find_bfr.Bfr(), 0, find_bfr.Len(), -1); // parse as number first; NOTE: trim needed to transform "{{{ 1 }}}" to "1"; it.w:Portale:Giochi_da_tavolo; DATE:2014-02-09
|
||||
if (prm_idx == -1)
|
||||
prm_key = find_bfr.XtoAryAndClearAndTrim(); // not a number; parse as key; NOTE: must trim; EX.WP: William Shakespeare; {{Relatebardtree}}
|
||||
prm_key = find_bfr.XtoAryAndClearAndTrim(); // not a number; parse as key; NOTE: must trim; PAGE:en.w:William Shakespeare; {{Relatebardtree}}
|
||||
}
|
||||
Arg_nde_tkn arg_nde = null;
|
||||
if (prm_idx == -1) { // prm is key; EX: "{{{key1}}}"
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Xot_tmpl_wtr {
|
||||
// NOTE: originally "if (ctx.Parse_tid() == Xop_parser_.Parse_tid_page_tmpl) {" but if not needed; Xot_tmpl_wtr should not be called for tmpls and <oi> should not make it to page_wiki
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
ctx.Only_include_evaluate_(true);
|
||||
xnde.Tmpl_evaluate(ctx, src, Xot_invk_temp.PageIsCaller, tmp_bfr);
|
||||
xnde.Tmpl_evaluate(ctx, src, Xot_invk_temp.Page_is_caller, tmp_bfr);
|
||||
ctx.Only_include_evaluate_(false);
|
||||
rslt_bfr.Add_bfr_and_preserve(tmp_bfr);
|
||||
break;
|
||||
@@ -85,7 +85,7 @@ public class Xot_tmpl_wtr {
|
||||
rslt_bfr.Add_mid(src, tkn.Src_bgn(), tkn.Src_end()); break; // write src from bgn/end
|
||||
case Xop_tkn_itm_.Tid_ignore: break; // hide comments and <*include*> ndes
|
||||
case Xop_tkn_itm_.Tid_tmpl_prm:
|
||||
tkn.Tmpl_evaluate(ctx, src, Xot_invk_temp.PageIsCaller.Src_(src), rslt_bfr);
|
||||
tkn.Tmpl_evaluate(ctx, src, Xot_invk_temp.Page_is_caller.Src_(src), rslt_bfr);
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_tvar:
|
||||
gplx.xowa.xtns.translates.Xop_tvar_tkn tvar_tkn = (gplx.xowa.xtns.translates.Xop_tvar_tkn)tkn;
|
||||
@@ -93,7 +93,7 @@ public class Xot_tmpl_wtr {
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_tmpl_invk:
|
||||
try {
|
||||
tkn.Tmpl_evaluate(ctx, src, Xot_invk_temp.PageIsCaller.Src_(src), rslt_bfr);
|
||||
tkn.Tmpl_evaluate(ctx, src, Xot_invk_temp.Page_is_caller.Src_(src), rslt_bfr);
|
||||
}
|
||||
catch (Exception exc) {
|
||||
Err_string = String_.new_utf8_(src, tkn.Src_bgn(), tkn.Src_end()) + "|" + ClassAdp_.NameOf_obj(exc) + "|" + Err_.Message_lang(exc);
|
||||
|
||||
Reference in New Issue
Block a user