mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.8.4.1
This commit is contained in:
@@ -51,7 +51,7 @@ public class Xop_ctx {
|
||||
public int Tmpl_tkn_max() {return tmpl_tkn_max;} public void Tmpl_tkn_max_(int v) {tmpl_tkn_max = v;} private int tmpl_tkn_max = Int_.MaxValue;
|
||||
public Xop_keeplist_wiki Tmpl_keeplist() {return tmpl_keeplist;} public void Tmpl_keeplist_(Xop_keeplist_wiki v) {this.tmpl_keeplist = v;} private Xop_keeplist_wiki tmpl_keeplist;
|
||||
public boolean Tmpl_args_parsing() {return tmpl_args_parsing;} public Xop_ctx Tmpl_args_parsing_(boolean v) {tmpl_args_parsing = v; return this;} private boolean tmpl_args_parsing;
|
||||
public Bry_bfr Tmpl_output() {return tmpl_output;} public Xop_ctx Tmpl_output_(Bry_bfr v) {tmpl_output = v; return this;} private Bry_bfr tmpl_output;
|
||||
public Bry_bfr Tmpl_output() {return tmpl_output;} public Xop_ctx Tmpl_output_(Bry_bfr v) {tmpl_output = v; return this;} private Bry_bfr tmpl_output; // OBSOLETE: after tmpl_prepend_nl rewrite; DATE:2014-08-21
|
||||
public Xot_defn_trace Defn_trace() {return defn_trace;} public Xop_ctx Defn_trace_(Xot_defn_trace v) {defn_trace = v; return this;} private Xot_defn_trace defn_trace = Xot_defn_trace_null._;
|
||||
public boolean Only_include_evaluate() {return only_include_evaluate;} public Xop_ctx Only_include_evaluate_(boolean v) {only_include_evaluate = v; return this;} private boolean only_include_evaluate;
|
||||
public Lst_section_nde_mgr Lst_section_mgr() {if (lst_section_mgr == null) lst_section_mgr = new Lst_section_nde_mgr(); return lst_section_mgr;} private Lst_section_nde_mgr lst_section_mgr;
|
||||
@@ -298,22 +298,6 @@ public class Xop_ctx {
|
||||
if (stack_pos == -1) return;
|
||||
ctx.Stack_pop_til(root, src, stack_pos, true, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_txt);
|
||||
}
|
||||
public void Tmpl_prepend_nl(Bry_bfr cur, byte[] val, int val_len) { // cur=current bfr; tmpl_output=main bfr that cur will eventually be appended to; val=result of template
|
||||
if ( val_len == 0 // val is empty
|
||||
|| cur.Match_end_byt(Byte_ascii.NewLine) // if cur has \n already, don't add; bn.w:লিওনেল_মেসি |ko.w:도쿄_지하철_히비야_선|DATE:2014-05-27
|
||||
|| tmpl_prepend_nl_trie.Match_bgn(val, 0, val_len) == null // val does not start with {| : ; # *; REF.MW:Parser.php|braceSubstitution
|
||||
) return;
|
||||
Bry_bfr prv_bfr = cur.Len() == 0 // note that cur_bfr should be checked first before tmpl_output
|
||||
? tmpl_output // main template bfr
|
||||
: cur // current bfr, which may be localized to within a template; see prepend tests
|
||||
;
|
||||
if ( tmpl_args_parsing // if processing template args, always add \n; EX:vi.w:Friedrich_II_của_Phổ; DATE:2014-04-26
|
||||
|| ( prv_bfr != null // note that prv_bfr can be null when called from a subparse, as in Scrib.Preprocess; EX:w:Portal:Canada; DATE:2014-02-13
|
||||
&& !prv_bfr.Match_end_byt(Byte_ascii.NewLine)) // previous char is not \n;
|
||||
) {
|
||||
cur.Add_byte(Byte_ascii.NewLine);
|
||||
}
|
||||
} private static final Btrie_fast_mgr tmpl_prepend_nl_trie = Xop_curly_bgn_lxr.tmpl_bgn_trie_();
|
||||
public static Xop_ctx new_(Xow_wiki wiki) {
|
||||
Xop_ctx rv = new Xop_ctx(wiki, Xoa_page.new_(wiki, Xoa_ttl.parse_(wiki, Xoa_page_.Main_page_bry))); // HACK: use "Main_Page" to put in valid page title
|
||||
return rv;
|
||||
|
||||
@@ -60,6 +60,7 @@ public class Xop_fxt {
|
||||
wiki.Db_mgr().Load_mgr().Clear();
|
||||
app.Wiki_mgr().Clear();
|
||||
Io_mgr._.InitEngine_mem(); // clear created pages
|
||||
wiki.Cfg_parser().Display_title_restrict_(false); // default to false, as a small number of tests assume restrict = false;
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Reset_for_msgs() {
|
||||
@@ -226,6 +227,12 @@ public class Xop_fxt {
|
||||
Tfds.Eq(expd, String_.new_utf8_(actl));
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) {
|
||||
byte[] raw_bry = Bry_.new_utf8_(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
|
||||
return root;
|
||||
}
|
||||
public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_utf8_(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
|
||||
@@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.html.*;
|
||||
public class Xop_redirect_mgr {
|
||||
private Hash_adp_bry redirect_hash;
|
||||
public Xop_redirect_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public class Xop_redirect_mgr {
|
||||
private final Xow_wiki wiki; private final Url_encoder url_decoder; private Hash_adp_bry redirect_hash;
|
||||
public Xop_redirect_mgr(Xow_wiki wiki) {this.wiki = wiki; this.url_decoder = wiki.App().Encoder_mgr().Url_ttl();} // NOTE: must be Url_ttl, not Url; PAGE:en.w:Template:Positionskarte+ -> Template:Location_map+, not Template:Location_map DATE:2014-08-21
|
||||
public void Clear() {redirect_hash = null;} // TEST:
|
||||
public boolean Is_redirect(byte[] text, int text_len) {return this.Extract_redirect(text, text_len) != null;}
|
||||
public Xoa_ttl Extract_redirect_loop(byte[] src) {
|
||||
@@ -45,8 +45,9 @@ public class Xop_redirect_mgr {
|
||||
ttl_bgn += Xop_tkn_.Lnki_bgn.length;
|
||||
int ttl_end = Bry_finder.Find_fwd(src, Xop_tkn_.Lnki_end, ttl_bgn);
|
||||
if (ttl_end == Bry_.NotFound) return Redirect_null_ttl;
|
||||
byte[] redirect_ary = Bry_.Mid(src, ttl_bgn, ttl_end);
|
||||
return Xoa_ttl.parse_(wiki, redirect_ary);
|
||||
byte[] redirect_bry = Bry_.Mid(src, ttl_bgn, ttl_end);
|
||||
redirect_bry = url_decoder.Decode(redirect_bry); // NOTE: url-decode links; PAGE: en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18
|
||||
return Xoa_ttl.parse_(wiki, redirect_bry);
|
||||
}
|
||||
public static final Xoa_ttl Extract_redirect_is_null = null;
|
||||
public static final int Redirect_max_allowed = 4;
|
||||
|
||||
@@ -34,6 +34,11 @@ public class Xop_redirect_mgr_tst {
|
||||
fxt.Test_redirect("#перенаправление [[A]]", "A");
|
||||
fxt.Test_redirect("#ПЕРЕНАПРАВЛЕНИЕ [[A]]", "A");
|
||||
}
|
||||
@Test public void Url_decode() {fxt.Test_redirect("#REDIRECT [[A%28B%29]]" , "A(B)");} // PURPOSE: url-decode links; PAGE:en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18
|
||||
@Test public void Url_decode_plus() {fxt.Test_redirect("#REDIRECT [[A%28B%29+]]", "A(B)+");} // PURPOSE: do not url-decode +; PAGE:en.w:Template:Positionskarte+; DATE:2014-08-22
|
||||
@Test public void Frame_ttl() { // PURPOSE: redirect should set invk frame title to redirect_trg, not original; PAGE:en.w:Statutory_city DATE:2014-08-22
|
||||
fxt.Test_frame_ttl("Template:A", "#REDIRECT [[Template:B]]", "Template:B", "Template:B");
|
||||
}
|
||||
}
|
||||
class Xop_redirect_mgr_fxt {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@@ -44,6 +49,14 @@ class Xop_redirect_mgr_fxt {
|
||||
public void Init_utf8() {
|
||||
fxt.Wiki().Lang().Case_mgr_utf8_();
|
||||
}
|
||||
public void Test_frame_ttl(String tmpl_ttl_str, String tmpl_wtxt_str, String redirect_ttl, String expd_frame_ttl) {
|
||||
fxt.Init_page_create(tmpl_ttl_str, tmpl_wtxt_str); // create redirect_src
|
||||
fxt.Init_page_create(redirect_ttl, "test"); // create redirect_trg
|
||||
fxt.Test_parse_page_tmpl_tkn("{{" + tmpl_ttl_str + "}}"); // parse {{redirect_src}}
|
||||
Xoa_ttl tmpl_ttl = Xoa_ttl.parse_(fxt.Wiki(), Bry_.new_utf8_(tmpl_ttl_str));
|
||||
Xot_defn_tmpl defn_tmpl = (Xot_defn_tmpl)fxt.Wiki().Cache_mgr().Defn_cache().Get_by_key(tmpl_ttl.Page_db()); // get defn (which parse should have created)
|
||||
Tfds.Eq(expd_frame_ttl, String_.new_utf8_(defn_tmpl.Frame_ttl())); // check frame_ttl
|
||||
}
|
||||
public void Test_redirect(String raw_str, String expd_str) {
|
||||
Xop_redirect_mgr redirect_mgr = fxt.Ctx().Wiki().Redirect_mgr();
|
||||
redirect_mgr.Clear();
|
||||
|
||||
Reference in New Issue
Block a user