1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2014-07-06 22:58:35 -04:00
parent 57f65b4d0c
commit ecbe2918d8
187 changed files with 4184 additions and 2286 deletions

View File

@@ -16,12 +16,14 @@ 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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.xtns.gallery.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.poems.*; import gplx.xowa.xtns.hiero.*;
import gplx.xowa.xtns.gallery.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.poems.*; import gplx.xowa.xtns.hiero.*;
import gplx.xowa.xtns.scores.*; import gplx.xowa.xtns.listings.*; import gplx.xowa.xtns.titleBlacklists.*;
public class Xow_xtn_mgr implements GfoInvkAble {
private OrderedHash regy = OrderedHash_.new_bry_();
public int Count() {return regy.Count();}
public Cite_xtn_mgr Xtn_cite() {return xtn_cite;} private Cite_xtn_mgr xtn_cite;
public Xow_xtn_mgr Ctor_by_app(Xoa_app app) { // NOTE: needed for options
Add(app, new Cite_xtn_mgr());
Add(app, new Scrib_xtn_mgr());
Add(app, new Gallery_xtn_mgr());
Add(app, new Poem_xtn_mgr());
@@ -40,6 +42,7 @@ public class Xow_xtn_mgr implements GfoInvkAble {
Xox_mgr mgr = proto.Clone_new();
mgr.Xtn_ctor_by_wiki(wiki);
regy.Add(mgr.Xtn_key(), mgr);
Set_members(mgr);
}
return this;
}
@@ -63,8 +66,12 @@ public class Xow_xtn_mgr implements GfoInvkAble {
private Xox_mgr Add(Xoa_app app, Xox_mgr xtn) {
xtn.Xtn_ctor_by_app(app);
regy.Add(xtn.Xtn_key(), xtn);
Set_members(xtn);
return xtn;
}
private void Set_members(Xox_mgr mgr) {
if (Bry_.Eq(mgr.Xtn_key(), Cite_xtn_mgr.XTN_KEY)) xtn_cite = (Cite_xtn_mgr)mgr;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_or_fail(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Cite_xtn_mgr extends Xox_mgr_base {
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_ascii_("cite");
public byte[] Group_default_name() {return group_default_name;} private byte[] group_default_name = Bry_.new_ascii_("lower-alpha");
@Override public Xox_mgr Clone_new() {return new Cite_xtn_mgr();}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_group_default_name)) return String_.new_utf8_(group_default_name);
else if (ctx.Match(k, Invk_group_default_name_)) group_default_name = m.ReadBry("v");
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk_group_default_name = "group_default_name", Invk_group_default_name_ = "group_default_name_";
}

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*;
public class Ref_html_wtr {
public Ref_html_wtr(Xow_wiki wiki) {
@@ -23,7 +23,7 @@ public class Ref_html_wtr {
}
public void Xnde_ref(Xoh_html_wtr_ctx opts, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
Ref_nde itm = (Ref_nde)xnde.Xnde_xtn();
if (itm == null) return; // FUTURE: See Battle of Midway
if (itm == null) return;
if (itm.Follow_y()) return; // NOTE: "follow" is always appended to preceding ref; will never generate its own ^ a
cfg.Itm_html().Bld_bfr_many(bfr
, Itm_id(itm, true)
@@ -70,7 +70,6 @@ public class Ref_html_wtr {
int itms_len = lst.Itms_len();
for (int j = 0; j < itms_len; j++) { // iterate over itms in grp
Ref_nde head_itm = lst.Itms_get_at(j);
// if (head_itm.Exists_in_lnki_title()) continue; // EX: if ref is in lnki_title only, ignore; EX:w:UK; DATE:2014-03-05
Bry_bfr tmp = Bry_bfr.new_();
int list_len = List_len(head_itm);
grp_list_fmtr.Init(ctx.Wiki(), cfg, head_itm);

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Ref_html_wtr_cfg {
public Bry_fmtr Itm_html() {return itm_html;} private Bry_fmtr itm_html; public Ref_html_wtr_cfg Itm_html_(String v) {itm_html = Bry_fmtr.new_(v, "itm_id", "grp_id", "grp_key"); return this;}
public Bry_fmtr Itm_id_uid() {return itm_id_uid;} private Bry_fmtr itm_id_uid; public Ref_html_wtr_cfg Itm_id_uid_(String v) {itm_id_uid = Bry_fmtr.new_(v, "uid"); return this;}

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Ref_itm_grp {
private ListAdp lsts = ListAdp_.new_();
public Ref_itm_grp(byte[] grp_name) {this.grp_name = grp_name;}

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Ref_itm_lst {
public Ref_itm_lst(byte[] grp_name) {this.grp_name = grp_name;}
byte[] grp_name; int idx_major_last = 0;

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Ref_itm_mgr {
private Hash_adp_bry grps = Hash_adp_bry.ci_();
private Ref_itm_grp grp_default = new Ref_itm_grp(Bry_.Empty);

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Ref_itm_mgr_cfg_tst {
@Before public void init() {fxt.Clear();} private Ref_itm_mgr_cfg_fxt fxt = new Ref_itm_mgr_cfg_fxt();

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Ref_itm_mgr_tst {
Ref_itm_mgr_fxt fxt = new Ref_itm_mgr_fxt();

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*;
public class Ref_nde implements Xox_xnde, Xop_xnde_atr_parser {
public byte[] Name() {return name;} public Ref_nde Name_(byte[] v) {name = v; return this;} private byte[] name = Bry_.Empty;
@@ -35,8 +35,12 @@ public class Ref_nde implements Xox_xnde, Xop_xnde_atr_parser {
Byte_obj_val xatr_key = (Byte_obj_val)xatr_key_obj;
switch (xatr_key.Val()) {
case Xatr_id_name: name = wiki.App().Sanitizer().Escape_id(xatr.Val_as_bry(src)); break;
case Xatr_id_group: group = xatr.Val_as_bry(src); break;
case Xatr_id_follow: follow = xatr.Val_as_bry(src); break;
case Xatr_id_group: {
group = xatr.Val_as_bry(src);
if (Bry_.Eq(group, wiki.Xtn_mgr().Xtn_cite().Group_default_name())) group = Bry_.Empty; // if group == default, make it same as empty; DATE:2014-07-03
break;
}
}
}
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {

View File

@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*;
public class References_nde implements Xox_xnde, Xop_xnde_atr_parser {
public byte[] Group() {return group;} public References_nde Group_(byte[] v) {group = v; return this;} private byte[] group = Bry_.Empty;
@@ -26,11 +26,11 @@ public class References_nde implements Xox_xnde, Xop_xnde_atr_parser {
switch (xatr_key.Val()) {
case Xatr_id_group: {
group = xatr.Val_as_bry(src);
if (Bry_.Match(group, Bry_group)) group = Bry_.Empty; // HACK: reflist returns <references group>
if (Bry_.Eq(group, wiki.Xtn_mgr().Xtn_cite().Group_default_name())) group = Bry_.Empty; // if group == default, make it same as empty; DATE:2014-07-03
break;
}
}
} private static byte[] Bry_group = Bry_.new_ascii_("group");
}
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn cur_root, byte[] src, Xop_xnde_tkn xnde) {
if (ctx.Tid_is_popup()) return;
Ref_itm_mgr ref_mgr = ctx.Cur_page().Ref_mgr();

View File

@@ -15,11 +15,10 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_basic_tst {
private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Page().Ref_mgr().Grps_clear();}
public class References_nde_basic_tst {
@Before public void init() {fxt.Clear_ref_mgr();} private Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
@@ -90,71 +89,6 @@ public class References_nde_basic_tst {
, ""
));
}
@Test public void Group() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x</ref>"
, "<ref group='group_a'>y</ref>"
, "<ref>z</ref>"
, "<references group='group_a'/>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[group_a 1]</a></sup>"
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "</ol>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">z</span></li>"
, "</ol>"
, ""
));
}
@Test public void Pre_ignored() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref> x</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"> x</span></li>"
, "</ol>"
, ""
));
}
@Test public void Pre_ignored_2() { // PURPOSE: <ref> creates <li> which will effectively disable all pre; EX.WP: Robert Browning
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x"
, " y"
, "</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x"
, " y"
, "</span></li>"
, "</ol>"
, ""
));
}
@Test public void Pre_ignored_3() { // PURPOSE: " <references>" should not create pre; fr.w:Heidi_(roman); DATE:2014-02-17
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x</ref>"
, ""
, " <references/>"
), String_.Concat_lines_nl_skip_last
( "<p><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "</p>"
, " <ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "</ol>"
, ""
));
fxt.Init_para_n_();
}
@Test public void List_ignored() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>*x</ref>"
@@ -237,45 +171,6 @@ public class References_nde_basic_tst {
, ""
));
}
@Test public void Empty_name() { // PURPOSE: <references group=""/> is same as <references/>; DATE:2013-02-06
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>b</ref>"
, "<references group=\"\"/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, ""
));
}
@Test public void Multiple_same_name_groups() { // PURPOSE: multiple groups with same name "clears" out references; DATE:2013-02-11
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>a</ref>"
, "<references/>"
, "<ref>b</ref>"
, "<references/>"
, "<ref>c</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">a</span></li>"
, "</ol>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">c</span></li>"
, "</ol>"
, ""
));
}
@Test public void Empty_group() { // PURPOSE: group without items should be blank; should not throw error; DATE:2013-02-12
fxt.Test_parse_page_wiki_str("<references name='group_a'/>", "");
}
@Test public void Empty_group_before_ref() { // PURPOSE: empty grp before itm should not throw error; DATE:2013-02-18; EX: w:Help:External links and references; Johnstown,_Colorado
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
( "<references/><references/>a<ref>test</ref>"

View File

@@ -0,0 +1,125 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_group_tst {
@Before public void init() {fxt.Clear_ref_mgr();} private Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x</ref>"
, "<ref group='group_a'>y</ref>"
, "<ref>z</ref>"
, "<references group='group_a'/>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[group_a 1]</a></sup>"
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "</ol>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">z</span></li>"
, "</ol>"
, ""
));
}
@Test public void Lower_alpha_is_ignored() {
String expd =
String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "</ol>"
, ""
);
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref group='lower-alpha'>x</ref>"
, "<ref>y</ref>" // note: no group name, but still goes in "lower-alpha" group
, "<references group='lower-alpha'/>"
), expd);
fxt.Clear_ref_mgr();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref group='lower-alpha'>x</ref>" // note: "lower-alpha" group name, but goes in default group
, "<ref>y</ref>"
, "<references/>"
), expd);
}
@Test public void Empty() { // PURPOSE: <references group=""/> is same as <references/>; DATE:2013-02-06
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>b</ref>"
, "<references group=\"\"/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, ""
));
}
@Test public void Val_less_defaults_to_key() { // PURPOSE: similar to above, except "group" is same as "group=group"; DATE:2014-07-03
String expd = String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[group 1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, "");
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref group='group'>b</ref>"
, "<references group/>"
), expd
);
fxt.Clear_ref_mgr();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last // PURPOSE.FIX: similar to above, except "group />" was not same as "group/>"; SEE:xatr_parser and " a " test; DATE:2014-07-03
( "<ref group='group'>b</ref>"
, "<references group />"
), expd
);
}
@Test public void Empty_group() { // PURPOSE: group without items should be blank; should not throw error; DATE:2013-02-12
fxt.Test_parse_page_wiki_str("<references name='group_a'/>", "");
}
@Test public void Multiple_same_name_groups() { // PURPOSE: multiple groups with same name "clears" out references; DATE:2013-02-11
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>a</ref>"
, "<references/>"
, "<ref>b</ref>"
, "<references/>"
, "<ref>c</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">a</span></li>"
, "</ol>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">c</span></li>"
, "</ol>"
, ""
));
}
}

View File

@@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_pre_tst {
@Before public void init() {fxt.Clear_ref_mgr();} private Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Pre_ignored() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref> x</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"> x</span></li>"
, "</ol>"
, ""
));
}
@Test public void Pre_ignored_2() { // PURPOSE: <ref> creates <li> which will effectively disable all pre; PAGE:en.w:Robert_Browning
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x"
, " y"
, "</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x"
, " y"
, "</span></li>"
, "</ol>"
, ""
));
}
@Test public void Pre_ignored_3() { // PURPOSE: " <references>" should not create pre; fr.w:Heidi_(roman); DATE:2014-02-17
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x</ref>"
, ""
, " <references/>"
), String_.Concat_lines_nl_skip_last
( "<p><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "</p>"
, " <ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "</ol>"
, ""
));
fxt.Init_para_n_();
}
}

View File

@@ -15,10 +15,10 @@ GNU Affero General Public License for more details.
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.refs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_rare_tst {
@Before public void init() {fxt.Page().Ref_mgr().Grps_clear(); fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Clear_ref_mgr(); fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Recursive() { // PURPOSE: handle recursive situations; EX: ja.w:Kソリューション ; ja.w:Template:cite web; DATE:2014-03-05
fxt.Init_page_create("Template:Recursive", "<ref>{{Recursive}}</ref>");

View File

@@ -140,7 +140,7 @@ class Dpl_itm {
byte[] key_bry = Bry_.Mid(src, fld_bgn, fld_end);
boolean log =
( Known_invalid_keys.Get_by_mid(src, fld_bgn, fld_end) != null
|| Bry_.HasAtBgn(key_bry, Html_consts.Comm_bgn) // ignore comment-like keys; EX: <!--category=Ctg_0--> will have key of "<!--category="
|| Bry_.HasAtBgn(key_bry, Html_tag_.Comm_bgn) // ignore comment-like keys; EX: <!--category=Ctg_0--> will have key of "<!--category="
);
String err_msg = String_.Format("unknown_key: page={0} key={1}", String_.new_utf8_(page_ttl), String_.new_utf8_(key_bry));
if (log)

View File

@@ -153,7 +153,7 @@ public class Gallery_itm_parser {
private void Fld_end() {
int fld_end = cur_pos;
if (cur_fld != Fld_caption) {
int non_ws_pos = Bry_finder.Find_bwd_non_ws(src, cur_pos - 1, itm_bgn) + 1; // SEE:non_ws_pos
int non_ws_pos = Bry_finder.Find_bwd_non_ws_or_not_found(src, cur_pos - 1, itm_bgn) + 1; // SEE:non_ws_pos
if (non_ws_pos != Bry_.NotFound + 1)
fld_end = non_ws_pos;
}

View File

@@ -176,10 +176,10 @@ public abstract class Gallery_mgr_base {
return tmp_bfr.XtoAryAndClear();
}
private static void Box_hdr_write(Bry_bfr bfr, Xop_xatr_whitelist_mgr whitelist_mgr, byte[] src, byte[] gallery_ul_uid, byte[] cls, byte[] style, ListAdp xatr_list) {
bfr.Add_byte(Byte_ascii.Lt).Add(Html_consts.Ul_tag_bry);
Html_wtr.Write_atr(bfr, Html_atrs.Id_bry, gallery_ul_uid);
Html_wtr.Write_atr(bfr, Html_atrs.Cls_bry, cls);
Html_wtr.Write_atr(bfr, Html_atrs.Style_bry, style);
bfr.Add_byte(Byte_ascii.Lt).Add(Html_tag_.Ul_name_bry);
Html_wtr.Write_atr(bfr, Html_atr_.Id_bry, gallery_ul_uid);
Html_wtr.Write_atr(bfr, Html_atr_.Cls_bry, cls);
Html_wtr.Write_atr(bfr, Html_atr_.Style_bry, style);
if (xatr_list != null) {
int len = xatr_list.Count();
for (int i = 0; i < len; i++) {

View File

@@ -239,8 +239,8 @@ class Hiero_html_wtr {
private Hiero_phoneme_mgr phoneme_mgr;
private Bry_bfr temp_bfr = Bry_bfr.reset_(255);
public Hiero_html_wtr(Hiero_html_mgr mgr, Hiero_phoneme_mgr phoneme_mgr) {this.phoneme_mgr = phoneme_mgr;}
public void Hr(Bry_bfr bfr) {bfr.Add(Html_consts.Hr_bry).Add_byte_nl();}
public void Tbl_eol(Bry_bfr bfr) {bfr.Add(Tbl_eol_bry);}
public void Hr(Bry_bfr bfr) {bfr.Add(Html_tag_.Hr_bry).Add_byte_nl();}
public void Tbl_eol(Bry_bfr bfr) {bfr.Add(Tbl_eol_bry);}
private static final String
Tbl_bgn_str = "<table class=\"mw-hiero-table\">"
;
@@ -311,7 +311,7 @@ class Hiero_html_wtr {
int height = (int)((Hiero_html_mgr.Max_height * Hiero_html_mgr.scale) / 100);
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph); if (phoneme_itm == null) throw Err_.new_fmt_("missing phoneme: {0}", String_.new_utf8_(glyph));
byte[] code = phoneme_itm.Gardiner_code();
byte[] title = bgn ? Html_consts.Lt : Html_consts.Gt;
byte[] title = bgn ? Html_entity_.Lt_bry : Html_entity_.Gt_bry;
return cartouche_img_fmtr.Bld_bry_many(temp_bfr, Hiero_xtn_mgr.Img_src_dir, code, height, title);
}
private static final Bry_fmtr cartouche_img_fmtr = Bry_fmtr.new_(String_.Concat

View File

@@ -40,11 +40,11 @@ class Hiero_parser {
int new_pos = trie.Match_pos();
switch (itm.Tid()) {
case Hiero_parser_itm.Tid_comment:
int end_comm = Bry_finder.Find_fwd(src, Html_consts.Comm_end, new_pos, end);
int end_comm = Bry_finder.Find_fwd(src, Html_tag_.Comm_end, new_pos, end);
if (end_comm == Bry_finder.Not_found) // --> not found; for now, ignore <!--
pos = new_pos;
else
pos = end_comm + Html_consts.Comm_end_len;
pos = end_comm + Html_tag_.Comm_end_len;
break;
case Hiero_parser_itm.Tid_block_spr:
New_block();
@@ -106,7 +106,7 @@ class Hiero_parser {
Init_itms(Hiero_parser_itm.Tid_tkn_spr, "*", ":", "(", ")");
Init_itms(Hiero_parser_itm.Tid_dot, ".");
Init_itms(Hiero_parser_itm.Tid_single_char , "!");
Init_itms(Hiero_parser_itm.Tid_comment, Html_consts.Comm_bgn_str);
Init_itms(Hiero_parser_itm.Tid_comment, Html_tag_.Comm_bgn_str);
}
private void Init_itms(byte tid, String... keys) {
int keys_len = keys.length;

View File

@@ -53,10 +53,10 @@ public class Xof_math_html_wtr {
for (int i = bgn; i < end; i++) {
byte b = bry[i];
switch (b) {
case Byte_ascii.Lt: if (mathjax) escaped = gplx.html.Html_consts.Lt; break;
case Byte_ascii.Gt: if (mathjax) escaped = gplx.html.Html_consts.Gt; break;
case Byte_ascii.Lt: if (mathjax) escaped = gplx.html.Html_entity_.Lt_bry; break;
case Byte_ascii.Gt: if (mathjax) escaped = gplx.html.Html_entity_.Gt_bry; break;
case Byte_ascii.Amp: escaped = Const_amp; break;
case Byte_ascii.Quote: if (mathjax) escaped = gplx.html.Html_consts.Quote; break;
case Byte_ascii.Quote: if (mathjax) escaped = gplx.html.Html_entity_.Quote_bry; break;
default:
if (dirty || write_to_bfr)
bfr.Add_byte(b);

View File

@@ -22,7 +22,7 @@ public class Pfunc_expr extends Pf_func_base {
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self); if (val_dat_ary == Bry_.Empty) return;
DecimalAdp rslt = shunter.Evaluate(ctx, val_dat_ary); // NOTE: php uses "float" but really is a double; http://www.php.net/manual/en/language.types.float.php
if (rslt == Pfunc_expr_shunter.Null_rslt) {
bb.Add_bfr(shunter.Err());
bb.Add_bfr_and_preserve(shunter.Err());
// ctx.Msg_log().Add_args(src, self.Src_bgn(), self.Src_end(), Pfunc_expr_msg.Unknown);
shunter.Err().Clear();
}

View File

@@ -17,46 +17,19 @@ 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.*;
public class Pfunc_ifexist extends Pf_func_base {
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bb) {
int self_args_len = self.Args_len();
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self);
if (Exists(tmp_db_page, ctx, val_dat_ary))
bb.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0));
else
bb.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1));
} private static final Xodb_page tmp_db_page = Xodb_page.tmp_();
public static int Count = 0;
public static boolean Exists(Xodb_page rv, Xop_ctx ctx, byte[] val_dat_ary) {
rv.Clear();
if (val_dat_ary.length == 0) return false;
if (val_dat_ary[0] == Byte_ascii.Brack_bgn) return false; // HACK: values like [[Commune (socialism)|Commune]] in [[Template:Infobox Former Country]] for Paris Commune
Xow_wiki wiki = ctx.Wiki();
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, val_dat_ary);
if (ttl == null) return false; // not a valid title; TODO: logme; see [[Dinosaur]]; Template:Taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{{taxonomy/{Placeholder <strong class=\"error\">error message</strong>.\n}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
byte[] page_ttl = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
if (ttl.Ns().Id() < 0) {
rv.Exists_(true);
return true; // HACK: -2 Media namespace returned for Heart normal.svg in Superficial_temporal_artery
}
Object exists_val = ctx.Wiki().If_exists_regy().Fetch(val_dat_ary);
if (exists_val != null) {
boolean exists = ((Bool_obj_val)exists_val).Val();
rv.Exists_(exists);
return exists;
}
boolean found = wiki.Db_mgr().Load_mgr().Load_by_ttl(rv, ttl.Ns(), page_ttl);
if ( !found
&& wiki.Lang().Vnt_mgr().Enabled()) {
Xodb_page page = wiki.Lang().Vnt_mgr().Convert_ttl(wiki, ttl.Ns(), page_ttl);
if (page != Xodb_page.Null)
found = page.Exists();
}
rv.Exists_(found);
++Count;
ctx.Wiki().If_exists_regy().Add(val_dat_ary, found ? Bool_obj_val.True : Bool_obj_val.False);
return found;
}
@Override public int Id() {return Xol_kwd_grp_.Id_xtn_iferror;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_ifexist().Name_(name);}
}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr rslt_bfr) {
int args_len = self.Args_len();
byte[] val_bry = Eval_argx(ctx, src, caller, self);
if (Exists(ctx.Wiki(), val_bry))
rslt_bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 0));
else
rslt_bfr.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 1));
}
public static boolean Exists(Xow_wiki wiki, byte[] ttl_bry) {
synchronized (Mgr) {return Mgr.Exists(wiki, ttl_bry);}
}
public static final Pfunc_ifexist_mgr Mgr = new Pfunc_ifexist_mgr();
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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.*;
public class Pfunc_ifexist_mgr {
private Xodb_page db_page = Xodb_page.tmp_();
private HashAdp regy = HashAdp_.new_bry_();
public void Clear() {regy.Clear();}
public boolean Exists(Xow_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.Fetch(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);
db_page.Clear();
Xow_ns ttl_ns = ttl.Ns();
switch (ttl_ns.Id()) {
case Xow_ns_.Id_special:
wiki.App().Usr_dlg().Warn_many("", "", "ifexist.special ns page; page=~{0} ifexist=~{1}", wiki.Ctx().Cur_page().Url().X_to_full_str_safe(), String_.new_utf8_(raw_bry));
exists_itm.Exists_(true);
return true;
case Xow_ns_.Id_media: return Find_ttl_for_media_ns(exists_itm, wiki, ttl_ns, ttl_bry);
default: return Find_ttl_in_db(exists_itm, wiki, ttl_ns, ttl_bry);
}
}
private boolean Find_ttl_in_db(Pfunc_ifexist_itm itm, Xow_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
boolean rv = wiki.Db_mgr().Load_mgr().Load_by_ttl(db_page, ns, ttl_bry);
if ( !rv
&& wiki.Lang().Vnt_mgr().Enabled()) {
Xodb_page page = wiki.Lang().Vnt_mgr().Convert_ttl(wiki, ns, ttl_bry);
if (page != Xodb_page.Null)
rv = page.Exists();
}
itm.Exists_(rv);
return rv;
}
private boolean Find_ttl_for_media_ns(Pfunc_ifexist_itm itm, Xow_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
Xow_ns file_ns = wiki.Ns_mgr().Ns_file();
boolean rv = Find_ttl_in_db(itm, wiki, file_ns, ttl_bry); if (rv) return true; // rarely true, but check first anyway
Xow_wiki commons_wiki = wiki.App().Wiki_mgr().Wiki_commons();
if (commons_wiki == null)
return wiki.File_mgr().Exists(ttl_bry); // user may not have commons_wiki; try to check files
else {
file_ns = commons_wiki.Ns_mgr().Ns_file();
return Find_ttl_in_db(itm, commons_wiki, file_ns, ttl_bry); // accurate test of whether or not Media file exists
}
}
}
class Pfunc_ifexist_itm {
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;
}

View File

@@ -26,4 +26,25 @@ public class Pfunc_ifexist_tst {
fxt.Init_page_create("A_&_b", "");
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();
Xow_wiki commons_wiki = fxt.App().Wiki_mgr().Get_by_key_or_make(gplx.xowa.wikis.Xow_wiki_domain_.Url_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().Meta_mgr().Get_itm_or_new(Bry_.new_ascii_("A.png"));
meta_itm.Orig_exists_(Bool_.Y_byte);
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "y");
}
}

View File

@@ -26,7 +26,7 @@ public class Pfunc_ifexpr extends Pf_func_base {
DecimalAdp result = shunter.Evaluate(ctx, val_dat_ary);
boolean is_nan = result == Pfunc_expr_shunter.Null_rslt;
if (is_nan && shunter.Err().Len() > 0) {
bb.Add_bfr(shunter.Err());
bb.Add_bfr_and_preserve(shunter.Err());
shunter.Err().Clear();
}
else {

View File

@@ -346,7 +346,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
lst_pfunc_wkr.Init_include(ttl.Full_db(), cur_sect_bgn, cur_sect_end).Exec(page_bfr, ctx);
ctx.Tmpl_prepend_nl(full_bfr, page_bfr.Bfr(), page_bfr.Len());
full_bfr.Add_bfr_and_clear(page_bfr);
full_bfr.Add(gplx.html.Html_consts.Space_bry);
full_bfr.Add(gplx.html.Html_entity_.Space_bry);
}
page_bfr.Mkr_rls();
ctx.Tmpl_output_(null);

View File

@@ -83,7 +83,7 @@ public class Pp_pages_nde_basic_tst {
));
}
@Test public void Err_page_ns_doesnt_exist() {
fxt.Wiki().Ns_mgr_(Xow_ns_mgr_.default_());
fxt.Wiki().Ns_mgr_(Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.Ascii()));
fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached valid ns_page from previous tests
fxt.Test_parse_page_wiki_str("<pages index=\"A\" from=1 to=3 />", "&lt;pages index=&quot;A&quot; from=1 to=3 /&gt;");
fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached invalid ns_page for next tests

View File

@@ -77,7 +77,7 @@ public class Score_xnde implements Xox_xnde, Xop_xnde_atr_parser, Xoh_cmd_itm {
html_id_img = hcmd_id + "_img";
html_id_a = hcmd_id + "_a";
html_a_href = ""; html_img_src = "";
html_img_alt = String_.new_utf8_(Bry_.Replace(code, Xoa_consts.Nl_bry, gplx.html.Html_consts.Nl_bry));
html_img_alt = String_.new_utf8_(Bry_.Replace(code, Xoa_consts.Nl_bry, gplx.html.Html_entity_.Nl_bry));
String html_img_alt_tmp = "", html_img_src_tmp = "", html_a_href_tmp = "";
html_img_src = png_file.To_http_file_str();
html_a_href = aud_file.To_http_file_str();

View File

@@ -57,7 +57,7 @@ public class Scrib_invoke_func extends Pf_func_base {
}
catch (Exception e) {
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
bfr.Add(Html_consts.Comm_bgn).Add_str(Err_.Message_gplx_brief(e)).Add(Html_consts.Comm_end);
bfr.Add(Html_tag_.Comm_bgn).Add_str(Err_.Message_gplx_brief(e)).Add(Html_tag_.Comm_end);
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", String_.new_utf8_(ctx.Cur_page().Ttl().Raw()), String_.new_utf8_(src, self.Src_bgn(), self.Src_end()), Err_.Message_gplx_brief(e));
Scrib_core.Core_invalidate(); // reset core
}

View File

@@ -58,16 +58,28 @@ public class Scrib_proc_args {
Object rv = Get_or_fail(i);
return (KeyVal[])rv;
}
public byte[][] Cast_params_as_bry_ary_or_empty(int params_idx) {
public byte[][] Cast_params_as_bry_ary_or_rest_of_ary(int params_idx) { // PAGE:ru.w:Ленин,_Владимир_Ильич; DATE:2014-07-01 MW:LanguageLibrary.php|ConvertPlural: if (is_array($args[0])) $args = $args[0]; $forms = array_values(array_map('strval', $args));
if (params_idx < 0 || params_idx >= ary_len) return Bry_.Ary_empty;
KeyVal[] tbl = (KeyVal[])ary[params_idx].Val();
int rv_len = tbl.length;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; i++) {
KeyVal itm = tbl[i];
rv[i] = Bry_.new_utf8_(String_.cast_(itm.Val()));
Object o = ary[params_idx].Val();
if (ClassAdp_.Eq_typeSafe(o, KeyVal[].class)) {
KeyVal[] tbl = (KeyVal[])o;
int rv_len = tbl.length;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; i++) {
KeyVal itm = tbl[i];
rv[i] = Bry_.new_utf8_(String_.cast_(itm.Val()));
}
return rv;
}
else {
int rv_len = ary_len - params_idx;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; i++) {
KeyVal itm = ary[i + params_idx];
rv[i] = Bry_.new_utf8_(String_.cast_(itm.Val()));
}
return rv;
}
return rv;
}
public byte[] Extract_qry_args(Xow_wiki wiki, int idx) {
Object qry_args_obj = Cast_obj_or_null(idx);

View File

@@ -218,7 +218,7 @@ public class Scrib_lib_language implements Scrib_lib {
public boolean ConvertPlural(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xol_lang lang = lang_(args);
int count = args.Pull_int(1);
byte[][] words = args.Cast_params_as_bry_ary_or_empty(2);
byte[][] words = args.Cast_params_as_bry_ary_or_rest_of_ary(2);
byte[] rv = lang.Plural().Plural_eval(lang, count, words);
return rslt.Init_obj(rv);
}

View File

@@ -98,7 +98,8 @@ public class Scrib_lib_language_tst {
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_convertGrammar, Object_.Ary("fi", "talo", "elative"), "talosta");
}
@Test public void ConvertPlural() {
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_convertPlural, Object_.Ary("ru", 5, Kv_ary_("a", "b", "c")), "c");
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_convertPlural, Object_.Ary("ru", 5, Kv_ary_("a", "b", "c")), "c"); // forms in kv_ary
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_convertPlural, Object_.Ary("ru", 5, "a", "b", "c"), "c"); // forms as rest of ary; PAGE:ru.w:Ленин,_Владимир_Ильич DATE:2014-07-01
}
@Test public void IsRTL() {
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isRTL, Object_.Ary("en"), "false");

View File

@@ -130,7 +130,7 @@ class Scrib_lib_message_data {
byte[] msg_val = Fetch_msg(cur_lang, wiki, ctx, exec_params);
if (Bry_.Len_eq_0(msg_val)) {
Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
bfr.Add(gplx.html.Html_consts.Lt).Add(msg_key).Add(gplx.html.Html_consts.Gt); // NOTE: Message.php has logic that says: if plain, "< >", else "&lt; &gt;"; for now, always use escaped
bfr.Add(gplx.html.Html_entity_.Lt_bry).Add(msg_key).Add(gplx.html.Html_entity_.Gt_bry); // NOTE: Message.php has logic that says: if plain, "< >", else "&lt; &gt;"; for now, always use escaped
return bfr.Mkr_rls().XtoAryAndClear();
}
switch (fmt_tid) {

View File

@@ -117,6 +117,9 @@ public class Scrib_lib_mw_tst {
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if", "", "y", "n") , "n"); // list: args is ary
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if", Scrib_kv_utl_.base1_many_("", "y", "n")) , "n"); // list: args is table
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if:", "y", "n") , "n"); // colon_in_name
}
@Test public void CallParserFunction_tag() {
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.flat_many_(1, "current", 2, "#tag", 3, Scrib_kv_utl_.flat_many_("3", "id=1", "2", "text", "1", "pre")), "<pre 3=\"id=1\">2=text</pre>");// named: sort args; NOTE: keys should probably be stripped
}
@Test public void CallParserFunction_displayTitle() { // PURPOSE: DISPLAYTITLE not being set when called through CallParserFunction; DATE:2013-08-05

View File

@@ -41,7 +41,7 @@ public class Scrib_lib_site_tst {
// fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_loadSiteStats, Object_.Ary_empty, "1;2;3;4;5;6;7");
// }
@Test public void Init_lib_site() {
Xow_ns_mgr ns_mgr = new Xow_ns_mgr();
Xow_ns_mgr ns_mgr = new Xow_ns_mgr(fxt.Core().Wiki().Lang().Case_mgr());
ns_mgr.Add_new(Scrib_xtn_mgr.Ns_id_module, "Module");
ns_mgr.Add_new(Scrib_xtn_mgr.Ns_id_module_talk, "Module talk");
ns_mgr.Add_new(Xow_ns_.Id_special, "Special");

View File

@@ -41,9 +41,9 @@ public class Scrib_lib_text implements Scrib_lib {
private static final String[] Proc_names = String_.Ary(Invk_unstrip, Invk_getEntityTable, Invk_init_text_for_wiki);
public boolean Unstrip(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(args.Pull_str(0));}
public boolean GetEntityTable(Scrib_proc_args args, Scrib_proc_rslt rslt) {
if (Html_consts == null) Html_consts = Scrib_lib_text_html_entities.new_();
return rslt.Init_obj(Html_consts);
} static KeyVal[] Html_consts;
if (Html_entity_ == null) Html_entity_ = Scrib_lib_text_html_entities.new_();
return rslt.Init_obj(Html_entity_);
} static KeyVal[] Html_entity_;
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), KeyVal_.Ary_empty);}
public boolean Init_text_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xow_msg_mgr msg_mgr = core.Wiki().Msg_mgr();