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

'v3.7.4.1'

This commit is contained in:
gnosygnu
2016-07-25 21:59:51 -04:00
parent 7a851a41a5
commit 8e91ac0bc4
175 changed files with 2079 additions and 933 deletions

View File

@@ -24,7 +24,7 @@ public class Pfunc_ifeq extends Pf_func_base {
int self_args_len = self.Args_len(); if (self_args_len < 2) return; // no equal/not_equal clauses defined; return; EX: {{#if:a}} {{#if:a|b}}
byte[] lhs = Eval_argx(ctx, src, caller, self);
byte[] rhs = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0);
if (Pf_func_.Eq_(lhs, rhs))
if (Pf_func_.Eq(ctx, lhs, rhs))
bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1));
else
bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 2));

View File

@@ -18,7 +18,7 @@ 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.*;
public class Pfunc_ifeq_tst {
private final Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Ifeq_y() {fxt.Test_parse_tmpl_str_test("{{#ifeq:1|1|a|b}}" , "{{test}}" , "a");}

View File

@@ -16,30 +16,32 @@ 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.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.core.envs.*;
import gplx.core.envs.*; import gplx.core.caches.*;
import gplx.xowa.bldrs.wms.apis.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
public class Pfunc_ifexist_mgr {
private Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
private Hash_adp regy = Hash_adp_bry.cs();
public void Clear() {regy.Clear();}
private final Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
public boolean Exists(Xowe_wiki wiki, byte[] raw_bry) {
if (Bry_.Len_eq_0(raw_bry)) return false; // return early; NOTE: {{autolink}} can pass in "" (see test)
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, raw_bry); if (ttl == null) return false;
byte[] ttl_bry = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
Object exists_obj = regy.Get_by(ttl_bry);
if (exists_obj != null) return ((Pfunc_ifexist_itm)exists_obj).Exists();
Pfunc_ifexist_itm exists_itm = new Pfunc_ifexist_itm(ttl_bry);
regy.Add(ttl_bry, exists_itm);
byte[] ttl_bry = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
// try to get from cache
Gfo_cache_mgr cache_mgr = wiki.Cache_mgr().Ifexist_cache();
Pfunc_ifexist_itm cache_itm = (Pfunc_ifexist_itm)cache_mgr.Get_by_key(ttl_bry);
if (cache_itm != null) return cache_itm.Exists();
cache_itm = new Pfunc_ifexist_itm(ttl_bry);
cache_mgr.Add(ttl_bry, cache_itm, 1);
db_page.Clear();
Xow_ns ttl_ns = ttl.Ns();
boolean rv = false;
switch (ttl_ns.Id()) {
case Xow_ns_.Tid__special: rv = true; break; // NOTE: some pages call for [[Special]]; always return true for now; DATE:2014-07-17
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(exists_itm, wiki, ttl_ns, ttl_bry); break;
default: rv = Find_ttl_in_db(exists_itm, wiki, ttl_ns, ttl_bry); break;
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(cache_itm, wiki, ttl_ns, ttl_bry); break;
default: rv = Find_ttl_in_db(cache_itm, wiki, ttl_ns, ttl_bry); break;
}
exists_itm.Exists_(rv);
cache_itm.Exists_(rv);
return rv;
}
private boolean Find_ttl_in_db(Pfunc_ifexist_itm itm, Xowe_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
@@ -73,8 +75,9 @@ public class Pfunc_ifexist_mgr {
}
}
}
class Pfunc_ifexist_itm {
class Pfunc_ifexist_itm implements Rls_able {
public Pfunc_ifexist_itm(byte[] ttl) {this.ttl = ttl;}
public byte[] Ttl() {return ttl;} private byte[] ttl;
public boolean Exists() {return exists;} public void Exists_(boolean v) {exists = v;} private boolean exists;
public void Rls() {}
}

View File

@@ -21,7 +21,7 @@ public class Pfunc_ifexist_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {
fxt.Reset();
fxt.Wiki().Parser_mgr().Ifexist_mgr().Clear();
fxt.Wiki().Cache_mgr().Ifexist_cache().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 ""

View File

@@ -26,6 +26,7 @@ public class Pfunc_ifexpr extends Pf_func_base {
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
int self_args_len = self.Args_len();
byte[] argx = Eval_argx(ctx, src, caller, self); if (argx == null) return;
Pfunc_expr_shunter shunter = ctx.Tmp_mgr().Expr_shunter();
Decimal_adp result = shunter.Evaluate(ctx, argx);
boolean is_nan = result == Pfunc_expr_shunter.Null_rslt;
if (is_nan && shunter.Err().Len() > 0) {
@@ -39,5 +40,4 @@ public class Pfunc_ifexpr extends Pf_func_base {
bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0));
}
}
private final Pfunc_expr_shunter shunter = Pfunc_expr_shunter.Instance;
}

View File

@@ -38,7 +38,7 @@ public class Pfunc_switch extends Pf_func_base {
last_keyless_arg = null; // set last_keyless_arg to null
byte[] case_key = Get_or_eval(ctx, src, caller, self, bfr, arg.Key_tkn(), tmp);
if ( fall_thru_found // fall-thru found earlier; take cur value; EX: {{#switch:a|a|b=1|c=2}} -> 1
|| Pf_func_.Eq_(case_key, argx) // case_key matches argx; EX: {{#switch:a|a=1}}
|| Pf_func_.Eq(ctx, case_key, argx) // case_key matches argx; EX: {{#switch:a|a=1}}
) {
match = Get_or_eval(ctx, src, caller, self, bfr, arg.Val_tkn(), tmp);
break; // stop iterating; explicit match found;
@@ -52,7 +52,7 @@ public class Pfunc_switch extends Pf_func_base {
else { // = missing; EX: "|a|", "|#default|"
last_keyless_arg = arg;
byte[] case_val = Get_or_eval(ctx, src, caller, self, bfr, arg.Val_tkn(), tmp);
if (Pf_func_.Eq_(case_val, argx)) // argx matches case_val; EX: case_val="|a|" and argx="a"
if (Pf_func_.Eq(ctx, case_val, argx)) // argx matches case_val; EX: case_val="|a|" and argx="a"
fall_thru_found = true; // set as fall-thru; note that fall-thrus will have "val" in next keyed arg, so need to continue iterating; EX: {{#switch:a|a|b=1|c=2}} "a" is fall-thru, but "b" is next keyed arg with a val
else if (kwd_mgr.Kwd_default_match(case_val)) { // case_val starts with #default; EX: "|#default|" or "|#defaultabc|"
last_keyless_arg = null; // unflag last keyless arg else |#defaultabc| will be treated as last_keyless_arg and generate "#defaultabc"; DATE:2014-05-29