mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.3.1'
This commit is contained in:
@@ -20,7 +20,7 @@ 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 {
|
||||
Btrie_fast_mgr trie = expression_();
|
||||
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;
|
||||
@@ -46,7 +46,7 @@ public class Pfunc_expr_shunter {
|
||||
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_bgn_w_byte(cur_byt, src, cur_pos, src_len);
|
||||
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) {
|
||||
@@ -60,7 +60,7 @@ public class Pfunc_expr_shunter {
|
||||
}
|
||||
else {
|
||||
Expr_tkn t = (Expr_tkn)o;
|
||||
cur_pos = trie.Match_pos();
|
||||
cur_pos = trv.Pos();
|
||||
switch (t.Tid()) {
|
||||
case Expr_tkn_.Tid_space: break;
|
||||
case Expr_tkn_.Tid_number:
|
||||
|
||||
@@ -43,15 +43,16 @@ public class Pfunc_iferror extends Pf_func_base {
|
||||
byte state = State_null;
|
||||
int pos = 0;
|
||||
boolean valid = false;
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
while (true) {
|
||||
if (pos == src_len) break;
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
|
||||
Object o = trie.Match_at_w_b0(trv, b, src, pos, src_len);
|
||||
if (o == null)
|
||||
++pos;
|
||||
else {
|
||||
Byte_obj_val bv = (Byte_obj_val)o;
|
||||
int pos_nxt = trie.Match_pos();
|
||||
int pos_nxt = trv.Pos();
|
||||
if (pos_nxt == src_len) return false; // each of the three states requires at least one character afterwards
|
||||
switch (bv.Val()) {
|
||||
case State_close: // >: reset state
|
||||
@@ -108,7 +109,7 @@ public class Pfunc_iferror extends Pf_func_base {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static final Btrie_slim_mgr trie = trie_();
|
||||
private static final Btrie_slim_mgr trie = trie_();
|
||||
static final byte State_null = 0, State_nde = 1, State_class = 2, State_error = 3, State_close = 4;
|
||||
private static Btrie_slim_mgr trie_() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en
|
||||
|
||||
@@ -31,7 +31,6 @@ public class Pfunc_ifexist extends Pf_func_base {
|
||||
bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 1));
|
||||
}
|
||||
public static boolean Exists(Xowe_wiki wiki, byte[] ttl_bry) {
|
||||
synchronized (Mgr) {return Mgr.Exists(wiki, ttl_bry);}
|
||||
return wiki.Parser_mgr().Ifexist_mgr().Exists(wiki, ttl_bry);
|
||||
}
|
||||
public static final Pfunc_ifexist_mgr Mgr = new Pfunc_ifexist_mgr();
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@ 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.*; import gplx.xowa.wikis.tdbs.metas.*;
|
||||
public class Pfunc_ifexist_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {
|
||||
fxt.Reset();
|
||||
fxt.Wiki().Parser_mgr().Ifexist_mgr().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 ""
|
||||
@Test public void Db_key() { // PURPOSE: test that (1) & is encoded; (2) " " becomes "_"; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
|
||||
@@ -27,22 +30,18 @@ public class Pfunc_ifexist_tst {
|
||||
fxt.Test_parse_tmpl_str_test("{{#ifexist:A & b|y|n}}", "{{test}}", "y");
|
||||
}
|
||||
@Test public void Media_n() {// DATE:2014-07-04
|
||||
Pfunc_ifexist.Mgr.Clear();
|
||||
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "n");
|
||||
}
|
||||
@Test public void Media_y_wiki() {// DATE:2014-07-04
|
||||
Pfunc_ifexist.Mgr.Clear();
|
||||
fxt.Init_page_create("File:A.png", "");
|
||||
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "y");
|
||||
}
|
||||
@Test public void Media_y_commons() {// DATE:2014-07-04
|
||||
Pfunc_ifexist.Mgr.Clear();
|
||||
Xowe_wiki commons_wiki = fxt.App().Wiki_mgr().Get_by_or_make(gplx.xowa.wikis.domains.Xow_domain_itm_.Bry__commons);
|
||||
fxt.Init_page_create(commons_wiki, "File:A.png", "");
|
||||
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "y");
|
||||
}
|
||||
@Test public void Media_y_file_v1() {// DATE:2014-07-04
|
||||
Pfunc_ifexist.Mgr.Clear();
|
||||
Xof_meta_itm meta_itm = fxt.Wiki().File_mgr().Dbmeta_mgr().Get_itm_or_new(Bry_.new_a7("A.png"));
|
||||
meta_itm.Orig_exists_(Bool_.Y_byte);
|
||||
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "y");
|
||||
|
||||
@@ -25,16 +25,16 @@ public class Pfunc_displaytitle extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self);
|
||||
Xowe_wiki wiki = ctx.Wiki(); Xop_parser parser = wiki.Parser_mgr().Main();
|
||||
Xop_ctx display_ttl_ctx = Xop_ctx.new_sub_(ctx);
|
||||
Xop_ctx display_ttl_ctx = Xop_ctx.New__sub__reuse_page(ctx);
|
||||
Xop_root_tkn display_ttl_root = parser.Parse_text_to_wdom(display_ttl_ctx, val_dat_ary, false);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
boolean restrict = wiki.Cfg_parser().Display_title_restrict();
|
||||
Xoh_wtr_ctx hctx = restrict ? Xoh_wtr_ctx.Display_title : Xoh_wtr_ctx.Basic; // restrict removes certain HTML (display:none)
|
||||
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, display_ttl_ctx, hctx, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
|
||||
wiki.Html_mgr().Html_wtr().Write_tkn_to_html(tmp_bfr, display_ttl_ctx, hctx, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
|
||||
byte[] val_html = tmp_bfr.To_bry_and_clear();
|
||||
if (restrict) { // restrict only allows displayTitles which have text similar to the pageTitle; PAGE:de.b:Kochbuch/_Druckversion; DATE:2014-08-18
|
||||
Xoae_page page = ctx.Page();
|
||||
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, display_ttl_ctx, Xoh_wtr_ctx.Alt, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
|
||||
wiki.Html_mgr().Html_wtr().Write_tkn_to_html(tmp_bfr, display_ttl_ctx, Xoh_wtr_ctx.Alt, display_ttl_root.Data_mid(), display_ttl_root, 0, display_ttl_root);
|
||||
byte[] val_html_lc = tmp_bfr.To_bry_and_clear();
|
||||
Xol_case_mgr case_mgr = wiki.Lang().Case_mgr();
|
||||
val_html_lc = Standardize_displaytitle_text(case_mgr, val_html_lc);
|
||||
|
||||
@@ -18,6 +18,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.core.brys.*; import gplx.core.brys.fmtrs.*; import gplx.core.btries.*; import gplx.core.log_msgs.*;
|
||||
class Pxd_parser {
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
byte[] src; int cur_pos, tkn_bgn_pos, src_len, tkn_type;
|
||||
public Pxd_itm[] Tkns() {return tkns;} Pxd_itm[] tkns;
|
||||
public int Tkns_len() {return tkns_len;} private int tkns_len;
|
||||
@@ -80,11 +81,11 @@ class Pxd_parser {
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
case Byte_ascii.At:
|
||||
MakePrvTkn(cur_pos, Pxd_itm_.Tid_null); // first, make prv tkn
|
||||
Object o = trie.Match_bgn_w_byte(b, src, cur_pos, src_len); // now match String against tkn
|
||||
Object o = trie.Match_at_w_b0(trv, b, src, cur_pos, src_len); // now match String against tkn
|
||||
if (o == null) return false; // unknown letter / word; exit now;
|
||||
tkns[tkns_len] = ((Pxd_itm_prototype)o).MakeNew(tkns_len);
|
||||
++tkns_len;
|
||||
cur_pos = trie.Match_pos() - 1; // -1 b/c trie matches to next char, and ++ below
|
||||
cur_pos = trv.Pos() - 1; // -1 b/c trie matches to next char, and ++ below
|
||||
break;
|
||||
case Byte_ascii.Comma: case Byte_ascii.Plus:
|
||||
MakePrvTkn(cur_pos, Pxd_itm_.Tid_null);
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Pfunc_anchorencode extends Pf_func_base { // EX: {{anchorencode:a b
|
||||
if (anchor_ctx != null) return;// NOTE: called by Scrib_uri
|
||||
encode_trie.Add(Byte_ascii.Colon, Bfr_arg_.New_byte(Byte_ascii.Colon));
|
||||
encode_trie.Add(Byte_ascii.Space, Bfr_arg_.New_byte(Byte_ascii.Underline));
|
||||
anchor_ctx = Xop_ctx.new_sub_(ctx);
|
||||
anchor_ctx = Xop_ctx.New__sub__reuse_page(ctx);
|
||||
anchor_ctx.Para().Enabled_n_();
|
||||
anchor_tkn_mkr = anchor_ctx.Tkn_mkr();
|
||||
anchor_parser = ctx.Wiki().Parser_mgr().Anchor_encoder();
|
||||
|
||||
@@ -53,10 +53,12 @@ public class Pfunc_filepath extends Pf_func_base {
|
||||
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());
|
||||
if (commons_wiki != null) { // commons_wiki not installed; exit; DATE:2013-06-08
|
||||
synchronized (commons_wiki) { // LOCK:app-level; wiki.commons; DATE:2016-07-06
|
||||
if (!Env_.Mode_testing()) commons_wiki.Init_assert();// must assert load else page_zip never detected; DATE:2013-03-10
|
||||
page = commons_wiki.Data_mgr().Load_page_by_ttl(ttl);
|
||||
if (!Env_.Mode_testing()) {
|
||||
synchronized (commons_wiki) { // LOCK:app-level; wiki.commons; DATE:2016-07-06
|
||||
commons_wiki.Init_assert();// must assert load else page_zip never detected; DATE:2013-03-10
|
||||
}
|
||||
}
|
||||
page = commons_wiki.Data_mgr().Load_page_by_ttl(ttl);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
|
||||
@@ -67,8 +67,9 @@ public class Pfunc_rel2abs extends Pf_func_base {
|
||||
if (qry_len == 0) return src;// no qry; return src; EX:{{#rel2abs:|a/b}} -> a/b
|
||||
byte[] tmp = src;
|
||||
int tmp_adj = 0, i = 0, prv_slash_end = 0, tmp_len = src_len, seg_pos = 0;
|
||||
boolean tmp_is_1st = true;
|
||||
Object o = qry_bgns_with.Match_bgn(qry, 0, qry_len); // check if qry begins with ".", "/", "./", "../"; if it doesn't return;
|
||||
boolean tmp_is_1st = true;
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
Object o = qry_bgns_with.Match_at(trv, qry, 0, qry_len); // check if qry begins with ".", "/", "./", "../"; if it doesn't return;
|
||||
if (o != null) {
|
||||
int id = ((Int_obj_ref)o).Val();
|
||||
rel2abs_tid.Val_(id);
|
||||
@@ -80,7 +81,7 @@ public class Pfunc_rel2abs extends Pf_func_base {
|
||||
case Id_dot_dot_slash: // "../"
|
||||
break; // qry is relative to src; noop
|
||||
case Id_dot_dot: // ".."
|
||||
int match_end = qry_bgns_with.Match_pos();
|
||||
int match_end = trv.Pos();
|
||||
if (match_end < qry_len && qry[match_end] == Byte_ascii.Dot) // NOTE: handles "..."; if "...*" then treat as invalid and return; needed for en.wiktionary.org/wiki/Wiktionary:Requests for cleanup/archive/2006
|
||||
return qry;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user