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

'v3.6.4.1'

This commit is contained in:
gnosygnu
2016-06-26 01:10:38 -04:00
parent 8afc115176
commit b3c2d3bb5f
108 changed files with 1813 additions and 873 deletions

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*; import gplx.xowa.wikis.ttls.*;
public class Xop_subst_tst {
private final Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {
fxt.Reset();
fxt.Init_defn_clear();
@@ -51,7 +51,7 @@ public class Xop_subst_tst {
@Test public void Urlencode_missing_ttl() { // PURPOSE: handle missing ttl inside {{does-template-exist}}; EX: en.d:Kazakhstan; DATE:2014-03-25
fxt.Init_defn_clear();
fxt.Init_defn_add("test", "{{safesubst:urlencode:{{safesubst:Template:{{{1}}}}}}}");
fxt.Test_parse_page_tmpl_str("{{test|xyz}}", "%5B%5B%3ATemplate%3AXyz%5D%5D"); // url-encoded version of [[:Template:xyz]]
fxt.Test_parse_page_tmpl_str("{{test|xyz}}", "%5B%5BTemplate%3Axyz%5D%5D"); // url-encoded version of [[:Template:xyz]]; NOTE: removed leading ":" from ":Template:" DATE:2016-06-24
}
@Test public void Urlencode_invalid_ttl() { // PURPOSE: handle invalid ttl inside does-template-exist; EX: en.d:peace; DATE:2014-03-31
fxt.Init_defn_clear();

View File

@@ -56,6 +56,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
int name_bgn = 0, name_ary_len = 0;
boolean subst_found = false;
boolean name_had_subst = false;
boolean template_prefix_found = false;
if (defn == Xot_defn_.Null) { // tmpl_name is not exact match; may be dynamic, subst, transclusion, etc..
if (name_key_tkn.Itm_static() == Bool_.N_byte) { // tmpl is dynamic; EX:{{{{{1}}}|a}}
Bry_bfr name_tkn_bfr = Bry_bfr_.New_w_size(name_tkn.Src_end() - name_tkn.Src_bgn());
@@ -76,12 +77,11 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
bfr.Add(Ary_unknown_bgn).Add(Ary_dynamic_is_blank).Add(Ary_unknown_end); // FUTURE: excerpt actual String; WHEN: add raw to defn
return false;
}
if (name_ary[name_bgn] == Byte_ascii.Colon) { // check 1st letter for transclusion
return Transclude(ctx, wiki, bfr, name_ary, caller, src); // transclusion; EX: {{:Name of page}}
if (name_ary[name_bgn] == Byte_ascii.Colon) { // check 1st letter for transclusion
return Transclude(ctx, wiki, bfr, Bool_.N, name_ary, caller, src); // transclusion; EX: {{:Name of page}}
}
// ignore "{{Template:"; EX: {{Template:a}} is the same thing as {{a}}
boolean template_prefix_found = false;
int tmpl_ns_len = wiki.Ns_mgr().Tmpls_get_w_colon(name_ary, name_bgn, name_ary_len);
if (tmpl_ns_len != Bry_find_.Not_found) {
name_ary = Bry_.Mid(name_ary, name_bgn + tmpl_ns_len, name_ary_len);
@@ -191,14 +191,6 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
bfr.Add(Xop_curly_end_lxr.Hook);
return false;
}
// DELETE:v3.6.4
// byte[] missing_ttl
// = subst_found || template_prefix_found // if "subst:" or "Template:" found, use orig name; DATE:2014-03-31
// ? name_ary_orig
// : name_ary
// ;
// bfr.Add(Xop_curly_bgn_lxr.Hook).Add(missing_ttl).Add(Xop_curly_end_lxr.Hook);
// return false;
}
else { // some templates produce null ttls; EX: "Citation needed{{subst"
defn = wiki.Cache_mgr().Defn_cache().Get_by_key(ttl.Page_db());
@@ -242,8 +234,8 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
return SubEval(ctx, wiki, bfr, name_ary, caller, src);
}
if (subst_found)
return Transclude(ctx, wiki, bfr, name_ary, caller, src);
Print_not_found(bfr, wiki.Ns_mgr(), name_ary);
return Transclude(ctx, wiki, bfr, template_prefix_found, name_ary, caller, src);
Print_not_found__w_template(bfr, wiki.Ns_mgr(), name_ary);
return false;
}
break;
@@ -351,7 +343,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
bfr.Add(nde.Val_tkn().Dat_ary());
}
}
private boolean Transclude(Xop_ctx ctx, Xowe_wiki wiki, Bry_bfr bfr, byte[] name_ary, Xot_invk caller, byte[] src) {
private boolean Transclude(Xop_ctx ctx, Xowe_wiki wiki, Bry_bfr bfr, boolean template_prefix_found, byte[] name_ary, Xot_invk caller, byte[] src) {
Xoa_ttl page_ttl = Xoa_ttl.parse(wiki, name_ary); if (page_ttl == null) return false; // ttl not valid; EX: {{:[[abc]]}}
byte[] transclude_src = null;
if (page_ttl.Ns().Id_is_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr
@@ -372,7 +364,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
return Eval_sub(ctx, transclude_tmpl, caller, src, bfr);
}
else {
Print_not_found(bfr, wiki.Ns_mgr(), page_ttl.Full_txt_w_ttl_case());
Print_not_found__by_transclude(bfr, wiki.Ns_mgr(), template_prefix_found, name_ary);
return false;
}
}
@@ -402,9 +394,17 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
}
return rv;
}
public static void Print_not_found(Bry_bfr bfr, Xow_ns_mgr ns_mgr, byte[] name_ary) { // print missing as [[:Template:Missing]]; REF:MW: Parser.php|braceSubstitution|$text = "[[:$titleText]]"; EX:en.d:Kazakhstan; DATE:2014-03-25
byte[] template_ns_name = ns_mgr.Ns_template().Name_db();
bfr.Add(Xop_tkn_.Lnki_bgn).Add_byte(Byte_ascii.Colon).Add(template_ns_name).Add_byte(Byte_ascii.Colon).Add(name_ary).Add(Xop_tkn_.Lnki_end);
private static void Print_not_found__by_transclude(Bry_bfr bfr, Xow_ns_mgr ns_mgr, boolean name_has_template, byte[] name_ary) {// print missing as [[Missing]]; PAGE:en.d:a DATE:2016-06-24
bfr.Add(Xop_tkn_.Lnki_bgn);
if (name_has_template)
bfr.Add(ns_mgr.Ns_template().Name_db()).Add_byte(Byte_ascii.Colon);
bfr.Add(name_ary);
bfr.Add(Xop_tkn_.Lnki_end);
}
public static void Print_not_found__w_template(Bry_bfr bfr, Xow_ns_mgr ns_mgr, byte[] name_ary) { // print missing as [[:Template:Missing]]; REF:MW: Parser.php|braceSubstitution|$text = "[[:$titleText]]"; EX:en.d:Kazakhstan; DATE:2014-03-25
bfr.Add(Xop_tkn_.Lnki_bgn).Add_byte(Byte_ascii.Colon);
bfr.Add(ns_mgr.Ns_template().Name_db()).Add_byte(Byte_ascii.Colon);
bfr.Add(name_ary).Add(Xop_tkn_.Lnki_end);
}
private boolean SubEval(Xop_ctx ctx, Xowe_wiki wiki, Bry_bfr bfr, byte[] name_ary, Xot_invk caller, byte[] src_for_tkn) {
Xoa_ttl page_ttl = Xoa_ttl.parse(wiki, name_ary); if (page_ttl == null) return false; // ttl not valid; EX: {{:[[abc]]}}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*;
public class Xot_invk_wkr_basic_tst {
public class Xot_invk_wkr__basic__tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic() {

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xot_invk_wkr_prepend_nl_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
public class Xot_invk_wkr__prepend_nl__tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() { // PURPOSE: if {| : ; # *, auto add new_line REF.MW:Parser.php|braceSubstitution
fxt.Init_defn_clear();
fxt.Init_defn_add("test_inner", "# a");

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xot_invk_wkr_raw_msg_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
public class Xot_invk_wkr__raw_msg__tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_defn_clear();}
@Test public void Raw() { // PURPOSE: {{raw:A}} is same as {{A}}; EX.WIKT:android; {{raw:ja/script}}
fxt.Init_defn_clear();

View File

@@ -17,10 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xot_invk_wkr_transclude_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
public class Xot_invk_wkr__transclude__tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_defn_clear();}
@Test public void Template() { // PURPOSE: {{:Template:Test}} is same as {{Template:Test}}; EX.WIKT:android; japanese and {{:Template:ja/script}}
@Test public void Basic() { // PURPOSE: {{:Template:Test}} is same as {{Template:Test}}; EX.WIKT:android; japanese and {{:Template:ja/script}}
fxt.Init_defn_add("Test_1", "{{#if:|y|n}}"); // NOTE: must be of form "Test 1"; test_1 will fail
fxt.Test_parse_tmpl_str("{{:Template:Test 1}}", "n");
}
@@ -33,8 +33,19 @@ public class Xot_invk_wkr_transclude_tst {
fxt.Init_page_create("Root", "<gallery>A.png|a{{/Leaf}}b</gallery>"); // NOTE: gallery neeeded for XOWA to fail; MW fails if just {{/Leaf}}
fxt.Test_parse_page("Root", "<gallery>A.png|a{{/Leaf}}b</gallery>");
}
@Test public void Missing() { // PURPOSE: transclusion of a missing page should create a link, not print an empty String; EX: it.u:Dipartimento:Design; DATE:2014-02-12
@Test public void Missing__sub_page() { // PURPOSE: transclusion of a missing page should create a link, not print an empty String; EX: it.u:Dipartimento:Design; DATE:2014-02-12
fxt.Page_ttl_("Test_Page");
fxt.Test_parse_tmpl_str("{{/Sub}}", "[[Test_Page/Sub]]");
}
@Test public void Missing__colon_prefix() {// PURPOSE: page with colon_prefix should not add Template: PAGE:en.d:a; DATE:2016-06-24
fxt.Test_parse_tmpl_str("{{:a}}", "[[:a]]"); // ":a", not "Template:A" or "A"
}
@Test public void Colon_by_safesubst() { // SUPPORT: page with colon_prefix should not add Template: PAGE:en.d:a; DATE:2016-06-24
fxt.Init_defn_add("Test_2", "{{safesubst:Template:{{{1}}}}}");
fxt.Test_parse_tmpl_str("{{Test 2|b}}", "[[Template:b]]");
}
@Test public void Colon_w_template() { // SUPPORT: page with colon_prefix should not add Template: PAGE:en.d:a; DATE:2016-06-24
fxt.Init_defn_add("Test_3", "{{:Template:{{{1}}}}}");
fxt.Test_parse_tmpl_str("{{Test 3|b}}", "[[:Template:b]]");
}
}