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

v2.11.1.1

This commit is contained in:
gnosygnu
2015-11-01 20:50:05 -05:00
parent 4f43f51b18
commit b990ec409f
858 changed files with 6758 additions and 4187 deletions

View File

@@ -16,7 +16,7 @@ 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.parsers; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*;
import gplx.core.btries.*; import gplx.core.log_msgs.*;
import gplx.xowa.langs.*;
import gplx.xowa.guis.*; import gplx.xowa.xtns.lst.*;
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wdatas.*;

View File

@@ -22,6 +22,6 @@ public class Xop_lxr_ {
, Tid_list = 10, Tid_hdr = 11, Tid_hr = 12, Tid_xnde = 13, Tid_lnke_bgn = 14, Tid_lnke_end = 15, Tid_tblw = 16, Tid_pre = 17, Tid_under = 18, Tid_comment = 19
, Tid_eq = 20, Tid_curly_bgn = 21, Tid_curly_end = 22, Tid_brack_bgn = 23, Tid_brack_end = 24, Tid_poem = 25
, Tid_tvar = 26, Tid_vnt_bgn = 27, Tid_vnt_end = 28, Tid_vnt_eqgt = 29, Tid_vnt_tmpl_bgn = 30, Tid_word = 31, Tid_nl_poem = 32, Tid_cr = 33
, Tid_brack_end_lnki = 34, Tid_nl_tab = 35, Tid_macro = 36
, Tid_brack_end_lnki = 34, Tid_nl_tab = 35, Tid_escape = 36
;
}

View File

@@ -64,7 +64,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
tmpl_props.OnlyInclude_exists = false; int subs_len = root.Subs_len();
for (int i = 0; i < subs_len; i++)
root.Subs_get(i).Tmpl_compile(ctx, src, tmpl_props);
boolean only_include_chk = Bry_find_.Find_fwd(src, Xop_xnde_tag_.Name_onlyinclude, 0, src.length) != Bry_.NotFound;
boolean only_include_chk = Bry_find_.Find_fwd(src, Xop_xnde_tag_.Name_onlyinclude, 0, src.length) != Bry_find_.Not_found;
if (only_include_chk) tmpl_props.OnlyInclude_exists = true;
tmpl.Init_by_new(ns, name, src, root, tmpl_props.OnlyInclude_exists);
} private Xot_compile_data tmpl_props = new Xot_compile_data();

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public interface Xop_tkn_itm extends Xop_tkn_grp {
byte Tkn_tid();
Xop_tkn_itm Tkn_ini_pos(boolean immutable, int bgn, int end);
@@ -38,6 +39,7 @@ public interface Xop_tkn_itm extends Xop_tkn_grp {
void Tmpl_fmt(Xop_ctx ctx, byte[] src, Xot_fmtr fmtr);
void Tmpl_compile(Xop_ctx ctx, byte[] src, Xot_compile_data prep_data); // SEE:NOTE_1:Tmpl_compile
boolean Tmpl_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Bry_bfr bfr);
void Html__write(Bry_bfr bfr, Xoh_html_wtr wtr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoh_html_wtr_cfg cfg, Xop_tkn_grp grp, int sub_idx, byte[] src);
}
/*
NOTE_1: Tmpl_compile

View File

@@ -70,6 +70,7 @@ public class Xop_tkn_itm_ {
, Tid_vnt_rule = 48
, Tid_vnt_eqgt = 49
, Tid_cr = 50
, Tid_escape = 51
;
public static final String[] Tid__names
= new String[]
@@ -124,5 +125,6 @@ public static final String[] Tid__names
, "vnt_rule"
, "vnt_eqgt"
, "cr"
, "escape"
};
}

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public abstract class Xop_tkn_itm_base implements Xop_tkn_itm {
public abstract byte Tkn_tid();
public Xop_tkn_grp Tkn_grp() {return grp == null ? this : grp;} private Xop_tkn_grp grp; // NOTE: not sure about this; need to handle null refs when tkns are manipulated but not yet added to a group
@@ -146,6 +147,7 @@ public abstract class Xop_tkn_itm_base implements Xop_tkn_itm {
}
subs_len = 0;
}
@gplx.Virtual public void Html__write(Bry_bfr bfr, Xoh_html_wtr wtr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoh_html_wtr_cfg cfg, Xop_tkn_grp grp, int sub_idx, byte[] src) {throw Err_.new_unimplemented();}
public void Clear() {
src_bgn = src_end = tkn_sub_idx = -1; ignore = false; tmpl_static = false;
Subs_clear();

View File

@@ -16,7 +16,8 @@ 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.parsers; import gplx.*; import gplx.xowa.*;
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.vnts.*;
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.tblws.*;
import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.vnts.*; import gplx.xowa.xtns.cite.*;
public class Xop_tkn_mkr {
public Xop_root_tkn Root(byte[] raw) {return new Xop_root_tkn().Root_src_(raw);}
public Xop_txt_tkn Txt(int bgn, int end) {return new Xop_txt_tkn(bgn, end);}

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public class Xop_tkn_null implements Xop_tkn_itm {
public byte Tkn_tid() {return Xop_tkn_itm_.Tid_null;}
public boolean Tkn_immutable() {return true;}
@@ -49,5 +50,6 @@ public class Xop_tkn_null implements Xop_tkn_itm {
public void Tmpl_fmt(Xop_ctx ctx, byte[] src, Xot_fmtr fmtr) {}
public void Tmpl_compile(Xop_ctx ctx, byte[] src, Xot_compile_data prep_data) {}
public boolean Tmpl_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Bry_bfr bfr) {return true;}
public void Html__write(Bry_bfr bfr, Xoh_html_wtr wtr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoh_html_wtr_cfg cfg, Xop_tkn_grp grp, int sub_idx, byte[] src) {}
public static final Xop_tkn_null Null_tkn = new Xop_tkn_null();
}

View File

@@ -16,7 +16,7 @@ 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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.lnkis.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
public class Xop_amp_trie_itm {
public Xop_amp_trie_itm(byte tid, int char_int, byte[] xml_name_bry) {
this.tid = tid;

View File

@@ -16,6 +16,7 @@ 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.parsers.apos; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_apos_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "apos");
public static final Gfo_msg_itm

View File

@@ -16,6 +16,7 @@ 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.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_hdr_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "hdr");
public static final Gfo_msg_itm

View File

@@ -16,18 +16,19 @@ 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.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public class Xop_hdr_tkn extends Xop_tkn_itm_base {
public Xop_hdr_tkn(int bgn, int end, int hdr_len) {this.Tkn_ini_pos(false, bgn, end); this.hdr_len = hdr_len;}
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*;
public class Xop_hdr_tkn extends Xop_tkn_itm_base {
public Xop_hdr_tkn(int bgn, int end, int hdr_level) {this.Tkn_ini_pos(false, bgn, end); this.hdr_level = hdr_level;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hdr;}
public int Hdr_len() {return hdr_len;} public Xop_hdr_tkn Hdr_len_(int v) {hdr_len = v; return this;} private int hdr_len = -1;
public int Hdr_level() {return hdr_level;} public Xop_hdr_tkn Hdr_level_(int v) {hdr_level = v; return this;} private int hdr_level = -1;
public int Hdr_bgn_manual() {return hdr_bgn_manual;} public Xop_hdr_tkn Hdr_bgn_manual_(int v) {hdr_bgn_manual = v; return this;} private int hdr_bgn_manual;
public int Hdr_end_manual() {return hdr_end_manual;} public Xop_hdr_tkn Hdr_end_manual_(int v) {hdr_end_manual = v; return this;} private int hdr_end_manual;
public boolean Hdr_html_first() {return hdr_html_first;} public Xop_hdr_tkn Hdr_html_first_y_() {hdr_html_first = true; return this;} private boolean hdr_html_first;
public int Hdr_html_dupe_idx() {return hdr_html_dupe_idx;} private int hdr_html_dupe_idx;
public byte[] Hdr_html_id() {return hdr_html_id;} public Xop_hdr_tkn Hdr_html_id_(byte[] v) {hdr_html_id = v; return this;} private byte[] hdr_html_id = Bry_.Empty;
public byte[] Hdr_toc_text() {return hdr_toc_text;} public Xop_hdr_tkn Hdr_toc_text_(byte[] v) {hdr_toc_text = v; return this;} private byte[] hdr_toc_text;
public int Hdr_html_dupe_idx_next() {
hdr_html_dupe_idx = hdr_html_dupe_idx == 0 ? 2 : hdr_html_dupe_idx + 1;
return hdr_html_dupe_idx;
}
public byte[] Hdr_html_id() {return hdr_html_id;} public Xop_hdr_tkn Hdr_html_id_(byte[] v) {hdr_html_id = v; return this;} private byte[] hdr_html_id = Bry_.Empty;
}

View File

@@ -20,14 +20,14 @@ import gplx.core.tests.*;
public class Xop_hdr_tkn_chkr extends Xop_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Xop_hdr_tkn.class;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_hdr;}
public int Hdr_len() {return hdr_len;} public Xop_hdr_tkn_chkr Hdr_len_(int v) {hdr_len = v; return this;} private int hdr_len = -1;
public int Hdr_len() {return hdr_len;} public Xop_hdr_tkn_chkr Hdr_level_(int v) {hdr_len = v; return this;} private int hdr_len = -1;
public int Hdr_ws_bgn() {return hdr_ws_bgn;} public Xop_hdr_tkn_chkr Hdr_ws_bgn_(int v) {hdr_ws_bgn = v; return this;} private int hdr_ws_bgn = -1;
public int Hdr_ws_end() {return hdr_ws_end;} public Xop_hdr_tkn_chkr Hdr_ws_end_(int v) {hdr_ws_end = v; return this;} private int hdr_ws_end = -1;
public int Hdr_ws_trailing() {return hdr_ws_trailing;} public Xop_hdr_tkn_chkr Hdr_ws_trailing_(int v) {hdr_ws_trailing = v; return this;} private int hdr_ws_trailing = -1;
public Xop_hdr_tkn_chkr Hdr_html_id_(String v) {hdr_html_id = Bry_.new_a7(v); return this;} private byte[] hdr_html_id = Bry_.Empty;
@Override public int Chk_hook(Tst_mgr mgr, String path, Object actl_obj, int err) {
Xop_hdr_tkn actl = (Xop_hdr_tkn)actl_obj;
err += mgr.Tst_val(hdr_len == -1, path, "hdr_len", hdr_len, actl.Hdr_len());
err += mgr.Tst_val(hdr_len == -1, path, "hdr_len", hdr_len, actl.Hdr_level());
err += mgr.Tst_val(hdr_html_id == Bry_.Empty, path, "hdr_html_id", String_.new_a7(hdr_html_id), String_.new_a7(actl.Hdr_html_id()));
return err;
}

View File

@@ -24,9 +24,9 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
public void AutoClose(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos, Xop_tkn_itm tkn) {
// bgn never closed; mark inert; EX: "==a"
Xop_hdr_tkn bgn = (Xop_hdr_tkn)tkn;
int bgn_hdr_len = bgn.Hdr_len();
int bgn_hdr_len = bgn.Hdr_level();
bgn.Hdr_bgn_manual_(bgn_hdr_len);
bgn.Hdr_len_(0);
bgn.Hdr_level_(0);
if (bgn_hdr_len > 1 && ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki) // NOTE: \n= is not uncommon for templates; ignore them;
ctx.Msg_log().Add_itm_none(Xop_hdr_log.Dangling_hdr, src, bgn.Src_bgn(), bgn_pos);
}
@@ -51,7 +51,7 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
if (ctx.Cur_tkn_tid() == Xop_tkn_itm_.Tid_tmpl_curly_bgn) return ctx.Lxr_make_txt_(cur_pos);
Xop_hdr_tkn hdr = (Xop_hdr_tkn)ctx.Stack_pop_til(root, src, stackPos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_hdr);
ctx.Apos().EndFrame(ctx, root, src, bgn_pos, false); // end any apos; EX: ==''a==
int hdr_len = hdr.Hdr_len(), bgn_manual = 0, end_manual = 0;
int hdr_len = hdr.Hdr_level(), bgn_manual = 0, end_manual = 0;
boolean dirty = false;
if (end_hdr_len < hdr_len) { // mismatch: end has more; adjust hdr
bgn_manual = hdr_len - end_hdr_len;
@@ -71,7 +71,7 @@ public class Xop_hdr_wkr implements Xop_ctx_wkr {
dirty = true;
}
if (dirty)
hdr.Hdr_bgn_manual_(bgn_manual).Hdr_end_manual_(end_manual).Hdr_len_(hdr_len);
hdr.Hdr_bgn_manual_(bgn_manual).Hdr_end_manual_(end_manual).Hdr_level_(hdr_len);
cur_pos = Find_fwd_while_ws_hdr_version(src, cur_pos, src_len); // NOTE: hdr gobbles up trailing ws; EX: "==a== \n\t \n \nb" gobbles up all 3 "\n"s; otherwise para_wkr will process <br/>
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag_h2);
hdr.Subs_move(root);

View File

@@ -1,56 +0,0 @@
/*
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.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_hdr_wkr__div_wrapper_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() { // PURPOSE: basic div_wrapper test; DATE:2015-06-24
fxt.Wtr_cfg().Hdr__div_wrapper_(Bool_.Y);
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "==a=="
, "b"
, "==c=="
, "d"
, "==e=="
, "f"
), String_.Concat_lines_nl_skip_last
( "<h2>a</h2>"
, "<div>"
, ""
, "<p>b"
, "</p>"
, ""
, "</div>"
, "<h2>c</h2>"
, "<div>"
, ""
, "<p>d"
, "</p>"
, ""
, "</div>"
, "<h2>e</h2>"
, "<div>"
, ""
, "<p>f"
, "</p>"
, "</div>"
));
fxt.Wtr_cfg().Hdr__div_wrapper_(Bool_.N);
}
}

View File

@@ -30,7 +30,7 @@ public class Mwh_atr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_ATT
private int nde_uid, nde_tid;
public Bry_obj_ref Bry_obj() {return bry_ref;} private final Bry_obj_ref bry_ref = Bry_obj_ref.null_();
public int Nde_end_tid() {return nde_end_tid;} private int nde_end_tid;
public int Parse(Mwh_doc_wkr wkr, int nde_uid, int nde_tid, byte[] src, int src_bgn, int src_end) {
public int Parse(Mwh_atr_wkr wkr, int nde_uid, int nde_tid, byte[] src, int src_bgn, int src_end) {
this.nde_uid = nde_uid; this.nde_tid = nde_tid;
this.nde_end_tid = Mwh_doc_parser.Nde_end_tid__invalid;
this.atr_bgn = -1;
@@ -440,7 +440,7 @@ public class Mwh_atr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_ATT
++pos;
b = src[pos];
}
int gt_pos = Bry_find_.Find_fwd(src, Byte_ascii.Gt, pos, end); if (gt_pos == Bry_.NotFound) return Bry_find_.Not_found;
int gt_pos = Bry_find_.Find_fwd(src, Byte_ascii.Gt, pos, end); if (gt_pos == Bry_find_.Not_found) return Bry_find_.Not_found;
byte[] bry = (byte[])xnde_hash.Get_by_mid(src, pos, gt_pos);
bry_ref.Val_(bry);
return bry == null ? Bry_find_.Not_found : bry.length + pos;

View File

@@ -0,0 +1,21 @@
/*
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.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public interface Mwh_atr_wkr {
void On_atr_each (Mwh_atr_parser mgr, byte[] src, int nde_tid, boolean valid, boolean repeated, boolean key_exists, byte[] key_bry, byte[] val_bry_manual, int[] itm_ary, int itm_idx);
}

View File

@@ -16,9 +16,8 @@ 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.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public interface Mwh_doc_wkr {
public interface Mwh_doc_wkr extends Mwh_atr_wkr {
Hash_adp_bry Nde_regy();
void On_atr_each (Mwh_atr_parser mgr, byte[] src, int nde_tid, boolean valid, boolean repeated, boolean key_exists, byte[] key_bry, byte[] val_bry_manual, int[] itm_ary, int itm_idx);
void On_txt_end (Mwh_doc_parser mgr, byte[] src, int nde_tid, int itm_bgn, int itm_end);
void On_nde_head_bgn(Mwh_doc_parser mgr, byte[] src, int nde_tid, int key_bgn, int key_end);
void On_nde_head_end(Mwh_doc_parser mgr, byte[] src, int nde_tid, int itm_bgn, int itm_end, boolean inline);

View File

@@ -1,97 +0,0 @@
/*
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.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.net.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.apps.urls.*;
public class Xoh_lnke_wtr {
// private Xoae_app app;
public Xoh_lnke_wtr(Xowe_wiki wiki) {}// this.app = wiki.Appe();}
public void Write_all(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke) {
int lnke_bgn = lnke.Lnke_bgn(), lnke_end = lnke.Lnke_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
if (!hctx.Mode_is_alt()) { // write href, unless mode is alt
if (hctx.Mode_is_hdump()) {
if (lnke.Lnke_typ() == Xop_lnke_tkn.Lnke_typ_text)
bfr.Add_str_a7("<a xtid='a_lnke_txt' href=\"");
else {
if (lnke.Subs_len() == 0)
bfr.Add_str_a7("<a xtid='a_lnke_brk_n' href=\"");
else
bfr.Add_str_a7("<a xtid='a_lnke_brk_y' href=\"");
}
}
else
bfr.Add(Xoh_consts.A_bgn);
if (Write_href(bfr, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa))
bfr.Add(A_lhs_end_external);
else
bfr.Add(A_lhs_end_internal);
}
Write_caption(bfr, html_wtr, hctx, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
if (!hctx.Mode_is_alt()) {
if (proto_is_xowa) // add <img />
bfr.Add(Xoh_consts.Img_bgn).Add(html_wtr.Html_mgr().Img_xowa_protocol()).Add(Xoh_consts.__inline_quote);
bfr.Add(Xoh_consts.A_end);
}
}
public boolean Write_href(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke, int lnke_bgn, int lnke_end, boolean proto_is_xowa) {
byte[] lnke_xwiki_wiki = lnke.Lnke_xwiki_wiki();
if (lnke_xwiki_wiki == null) {
if (lnke.Lnke_relative()) { // relative; EX: //a.org
bfr.Add(ctx.Wiki().Utl__url_parser().Url_parser().Relative_url_protocol_bry()).Add_mid(src, lnke_bgn, lnke_end);
return true;
}
else { // xowa or regular; EX: http://a.org
if (proto_is_xowa) {
bfr.Add(Xop_lnke_wkr.Bry_xowa_protocol);
Xoa_app_.Utl__encoder_mgr().Gfs().Encode(bfr, src, lnke_bgn, lnke_end);
return false;
}
else { // regular; add href
bfr.Add_mid(src, lnke_bgn, lnke_end);
return true;
}
}
}
else { // xwiki
Url_encoder href_encoder = Xoa_app_.Utl__encoder_mgr().Href_quotes();
bfr.Add(Xoh_href_.Bry__site).Add(lnke_xwiki_wiki).Add(Xoh_href_.Bry__wiki)
.Add(href_encoder.Encode(lnke.Lnke_xwiki_page())); // NOTE: must encode page; EX:%22%3D -> '">' which will end attribute; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15
if (lnke.Lnke_xwiki_qargs() != null)
Gfo_qarg_mgr.Concat_bfr(bfr, href_encoder, lnke.Lnke_xwiki_qargs()); // NOTE: must encode args
return false;
}
}
public void Write_caption(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke, int lnke_bgn, int lnke_end, boolean proto_is_xowa) {
int subs_len = lnke.Subs_len();
if (subs_len == 0) { // no text; auto-number; EX: "[1]"
if (lnke.Lnke_typ() == Xop_lnke_tkn.Lnke_typ_text)
bfr.Add_mid(src, lnke_bgn, lnke_end);
else
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(ctx.Cur_page().Html_data().Lnke_autonumber_next()).Add_byte(Byte_ascii.Brack_end);
}
else { // text available
for (int i = 0; i < subs_len; i++)
html_wtr.Write_tkn(bfr, ctx, hctx, src, lnke, i, lnke.Subs_get(i));
}
}
private static final byte[]
A_lhs_end_external = Bry_.new_a7("\" class=\"external text\" rel=\"nofollow\">")
, A_lhs_end_internal = Bry_.new_a7("\">")
;
}

View File

@@ -1,36 +0,0 @@
/*
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.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xoh_lnke_wtr_tst {
private Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_(); fxt.Reset();}
@Test public void Basic() {fxt.Test_parse_page_wiki_str("[irc://a]" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">[1]</a>");}
@Test public void Autonumber() {fxt.Test_parse_page_wiki_str("[irc://a] [irc://b]" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">[1]</a> <a href=\"irc://b\" class=\"external text\" rel=\"nofollow\">[2]</a>");}
@Test public void Caption() {fxt.Test_parse_page_wiki_str("[irc://a b]" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">b</a>");}
@Test public void Caption_wtxt() {fxt.Test_parse_page_wiki_str("[irc://a ''b'']" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\"><i>b</i></a>");}
@Test public void Xowa_protocol() {
String img = "<img src=\"file:///mem/xowa/bin/any/xowa/file/app.general/xowa_exec.png\"/>";
fxt.Wiki().Sys_cfg().Xowa_proto_enabled_(true);
fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a\" z]" , "<a href=\"xowa-cmd:a\">z" + img + "</a>");
fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a.b('c_d');\" z]" , "<a href=\"xowa-cmd:a.b('c_d');\">z" + img + "</a>");
fxt.Test_parse_page_wiki_str("[xowa-cmd:*\"a\"b*c\"* z]" , "<a href=\"xowa-cmd:a%22b%2Ac\">z" + img + "</a>");
fxt.Wiki().Sys_cfg().Xowa_proto_enabled_(false);
fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a\" b]" , "[xowa-cmd:&quot;a&quot; b]"); // protocol is disabled: literalize String (i.e.: don't make it an anchor)
}
}

View File

@@ -16,6 +16,7 @@ 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.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_lnke_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "lnke");
public static final Gfo_msg_itm Dangling = Gfo_msg_itm_.new_note_(owner, "dangling"); // NOTE: WP.BOT:YOBOT;PAGE:en.w:Pan_flute

View File

@@ -27,14 +27,13 @@ public class Xop_lnke_tkn extends Xop_tkn_itm_base {//20111222
public byte[] Lnke_xwiki_page() {return lnke_xwiki_page;} private byte[] lnke_xwiki_page;
public Gfo_qarg_itm[] Lnke_xwiki_qargs() {return lnke_xwiki_qargs;} Gfo_qarg_itm[] lnke_xwiki_qargs;
public void Lnke_xwiki_(byte[] wiki, byte[] page, Gfo_qarg_itm[] args) {this.lnke_xwiki_wiki = wiki; this.lnke_xwiki_page = page; this.lnke_xwiki_qargs = args;}
public int Lnke_bgn() {return lnke_bgn;} private int lnke_bgn;
public int Lnke_end() {return lnke_end;} private int lnke_end;
public Xop_lnke_tkn Lnke_rng_(int bgn, int end) {lnke_bgn = bgn; lnke_end = end; return this;}
public int Lnke_href_bgn() {return lnke_href_bgn;} private int lnke_href_bgn;
public int Lnke_href_end() {return lnke_href_end;} private int lnke_href_end;
public byte[] Protocol() {return protocol;} private byte[] protocol;
public byte Proto_tid() {return proto_tid;} private byte proto_tid;
public Xop_lnke_tkn Subs_add_ary(Xop_tkn_itm... ary) {for (Xop_tkn_itm itm : ary) super.Subs_add(itm); return this;}
public Xop_lnke_tkn(int bgn, int end, byte[] protocol, byte proto_tid, byte lnke_typ, int lnke_bgn, int lnke_end) {
this.Tkn_ini_pos(false, bgn, end); this.protocol = protocol; this.proto_tid = proto_tid; this.lnke_typ = lnke_typ; this.lnke_bgn = lnke_bgn; this.lnke_end = lnke_end;
public Xop_lnke_tkn(int bgn, int end, byte[] protocol, byte proto_tid, byte lnke_typ, int lnke_href_bgn, int lnke_href_end) {
this.Tkn_ini_pos(false, bgn, end); this.protocol = protocol; this.proto_tid = proto_tid; this.lnke_typ = lnke_typ; this.lnke_href_bgn = lnke_href_bgn; this.lnke_href_end = lnke_href_end;
} Xop_lnke_tkn() {}
}

View File

@@ -28,7 +28,7 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
// "[" but no "]"; EX: "[irc://a"; NOTE: lnkes that start with protocol will be ac'd in MakeTkn_bgn; EX: "http://a"
Xop_lnke_tkn bgn_tkn = (Xop_lnke_tkn)tkn;
bgn_tkn.Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack_dangling);
bgn_tkn.Src_end_(bgn_tkn.Lnke_end()); // NOTE: endPos is lnke_end, not cur_pos or src_len; EX: "[irc://a b", lnk ends at a, not b; NOTE: still bgns at [
bgn_tkn.Src_end_(bgn_tkn.Lnke_href_end()); // NOTE: endPos is lnke_end, not cur_pos or src_len; EX: "[irc://a b", lnk ends at a, not b; NOTE: still bgns at [
ctx.Msg_log().Add_itm_none(Xop_lnke_log.Dangling, src, tkn.Src_bgn(), cur_pos);
}
public static final String Str_xowa_protocol = "xowa-cmd:";
@@ -283,7 +283,7 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
// NOTE: fmt is [xowa-cmd:^"app.setup_mgr.import_wiki('');"^ ]
if (lnke_type != Xop_lnke_tkn.Lnke_typ_brack) return ctx.Lxr_make_txt_(cur_pos); // NOTE: must check for [ or else C:\xowa\ will cause it to evaluate as lnke
int proto_end_pos = cur_pos + 1; // +1 to skip past :
int lhs_dlm_pos = Bry_find_.Find_fwd(src, Byte_ascii.Quote, proto_end_pos, src_len); if (lhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int lhs_dlm_pos = Bry_find_.Find_fwd(src, Byte_ascii.Quote, proto_end_pos, src_len); if (lhs_dlm_pos == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int lnke_bgn_pos = lhs_dlm_pos + 1;
byte[] rhs_dlm_bry = Bry_quote;
if (lhs_dlm_pos - proto_end_pos > 0) {
@@ -291,9 +291,9 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
rhs_dlm_bry = bfr.Add(Bry_quote).Add_mid(src, proto_end_pos, lhs_dlm_pos).To_bry_and_clear();
bfr.Mkr_rls();
}
int rhs_dlm_pos = Bry_find_.Find_fwd(src, rhs_dlm_bry, lnke_bgn_pos, src_len); if (rhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int txt_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, rhs_dlm_pos + rhs_dlm_bry.length, src_len); if (txt_bgn == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int txt_end = Bry_find_.Find_fwd(src, Byte_ascii.Brack_end, txt_bgn, src_len); if (txt_end == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int rhs_dlm_pos = Bry_find_.Find_fwd(src, rhs_dlm_bry, lnke_bgn_pos, src_len); if (rhs_dlm_pos == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int txt_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, rhs_dlm_pos + rhs_dlm_bry.length, src_len); if (txt_bgn == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int txt_end = Bry_find_.Find_fwd(src, Byte_ascii.Brack_end, txt_bgn, src_len); if (txt_end == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int end_pos = txt_end + 1; // +1 to place after ]
Xop_lnke_tkn tkn = tkn_mkr.Lnke(bgn_pos, end_pos, protocol, proto_tid, lnke_type, lnke_bgn_pos, rhs_dlm_pos); // +1 to ignore [

View File

@@ -34,18 +34,18 @@ public class Xop_lnke_wkr_brack_tst {
@Test public void Brace_xnde_bgn() {// PURPOSE: occurred at ref of UK; a {{cite web|url=http://www.abc.gov/{{dead link|date=December 2011}}|title=UK}} b
fxt.Test_parse_page_wiki_str
( "[http://b.org<sup>c</sup>]"
, "<a href=\"http://b.org\" class=\"external text\" rel=\"nofollow\"><sup>c</sup></a>"
, "<a href=\"http://b.org\" rel=\"nofollow\" class=\"external text\"><sup>c</sup></a>"
);
}
@Test public void Brace_newLine() {
fxt.Test_parse_page_wiki("[irc://a\n]", fxt.tkn_txt_(0, 8), fxt.tkn_nl_char_len1_(8), fxt.tkn_txt_(9, 10));
}
@Test public void Html_brack() {
fxt.Test_parse_page_wiki_str("[irc://a]", "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">[1]</a>");
fxt.Test_parse_page_wiki_str("[irc://a]", "<a href=\"irc://a\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>");
}
@Test public void Apos() {
fxt.Test_parse_page_wiki_str("[http://www.a.org''b'']", "<a href=\"http://www.a.org\" class=\"external text\" rel=\"nofollow\"><i>b</i></a>");
fxt.Test_parse_page_wiki_str("[http://www.a.org'b]", "<a href=\"http://www.a.org'b\" class=\"external text\" rel=\"nofollow\">[1]</a>");
fxt.Test_parse_page_wiki_str("[http://www.a.org''b'']", "<a href=\"http://www.a.org\" rel=\"nofollow\" class=\"external text\"><i>b</i></a>");
fxt.Test_parse_page_wiki_str("[http://www.a.org'b]", "<a href=\"http://www.a.org'b\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>");
}
@Test public void Nowiki() {
fxt.Test_parse_page_all_str
@@ -57,7 +57,7 @@ public class Xop_lnke_wkr_brack_tst {
fxt.Test_parse_page_wiki_str
( "[http://a.org b [[C]] d]"
,String_.Concat_lines_nl_skip_last
( "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">b <a href=\"/wiki/C\">C</a> d</a>"
( "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">b <a href=\"/wiki/C\">C</a> d</a>"
));
}
@Test public void Encode_xwiki() { // PURPOSE: href title and args should always be encoded; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15
@@ -74,21 +74,21 @@ public class Xop_lnke_wkr_brack_tst {
@Test public void Encode_basic() { // PURPOSE: counterpart to Encode_xwiki; DATE:2014-07-15
fxt.Test_parse_page_wiki_str // encode page
( "[http://a.org/%22%3E_A B]"
, "<a href=\"http://a.org/%22%3E_A\" class=\"external text\" rel=\"nofollow\">B</a>" // '%22%3E' not '">'
, "<a href=\"http://a.org/%22%3E_A\" rel=\"nofollow\" class=\"external text\">B</a>" // '%22%3E' not '">'
);
fxt.Test_parse_page_wiki_str // encode args
( "[http://a.org/A?b=%22%3E_C D]"
, "<a href=\"http://a.org/A?b=%22%3E_C\" class=\"external text\" rel=\"nofollow\">D</a>" // '%22%3E' not '">'
, "<a href=\"http://a.org/A?b=%22%3E_C\" rel=\"nofollow\" class=\"external text\">D</a>" // '%22%3E' not '">'
);
}
@Test public void Encode_relative() { // PURPOSE: counterpart to Encode_xwiki; DATE:2014-07-15
fxt.Test_parse_page_wiki_str // encode page
( "[//a.org/%22%3E_A B]"
, "<a href=\"https://a.org/%22%3E_A\" class=\"external text\" rel=\"nofollow\">B</a>" // '%22%3E' not '">'
, "<a href=\"https://a.org/%22%3E_A\" rel=\"nofollow\" class=\"external text\">B</a>" // '%22%3E' not '">'
);
fxt.Test_parse_page_wiki_str // encode args
( "[//a.org/A?b=%22%3E_C D]"
, "<a href=\"https://a.org/A?b=%22%3E_C\" class=\"external text\" rel=\"nofollow\">D</a>" // '%22%3E' not '">'
, "<a href=\"https://a.org/A?b=%22%3E_C\" rel=\"nofollow\" class=\"external text\">D</a>" // '%22%3E' not '">'
);
}
}

View File

@@ -25,7 +25,7 @@ public class Xop_lnke_wkr_relative_tst {
);
}
@Test public void Relative_external() {
fxt.Test_parse_page_wiki_str("[//www.a.org a]", "<a href=\"https://www.a.org\" class=\"external text\" rel=\"nofollow\">a</a>");
fxt.Test_parse_page_wiki_str("[//www.a.org a]", "<a href=\"https://www.a.org\" rel=\"nofollow\" class=\"external text\">a</a>");
}
@Test public void Relative_internal() {
fxt.Init_xwiki_add_user_("en.wikipedia.org");

View File

@@ -23,14 +23,14 @@ public class Xop_lnke_wkr_text_tst {
fxt.Test_parse_page_wiki("irc://a", fxt.tkn_lnke_(0, 7).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_text).Lnke_rng_(0, 7));
}
@Test public void Text_html() {
fxt.Test_parse_page_wiki_str("irc://a", "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">irc://a</a>");
fxt.Test_parse_page_wiki_str("irc://a", "<a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</a>");
}
@Test public void Text_after() {
fxt.Test_parse_page_wiki("irc://a b c", fxt.tkn_lnke_(0, 7).Lnke_rng_(0, 7), fxt.tkn_space_(7, 8), fxt.tkn_txt_(8, 9), fxt.tkn_space_(9, 10), fxt.tkn_txt_(10, 11));
}
@Test public void Text_before_ascii() { // PURPOSE: free form external urls should not match if preceded by letters; EX:de.w:Sylvie_und_Bruno; DATE:2014-05-11
fxt.Ctx().Lang().Case_mgr_u8_();
String expd_lnke_html = "<a href=\"tel:a\" class=\"external text\" rel=\"nofollow\">tel:a</a>";
String expd_lnke_html = "<a href=\"tel:a\" rel=\"nofollow\" class=\"external free\">tel:a</a>";
fxt.Test_parse_page_wiki_str("titel:a" , "titel:a");
fxt.Test_parse_page_wiki_str(" tel:a" , " " + expd_lnke_html);
fxt.Test_parse_page_wiki_str("!tel:a" , "!" + expd_lnke_html);
@@ -60,21 +60,21 @@ public class Xop_lnke_wkr_text_tst {
, "*irc://b"
),String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li><a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">irc://a</a>"
, " <li><a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</a>"
, " </li>"
, " <li><a href=\"irc://b\" class=\"external text\" rel=\"nofollow\">irc://b</a>"
, " <li><a href=\"irc://b\" rel=\"nofollow\" class=\"external free\">irc://b</a>"
, " </li>"
, "</ul>"
));
}
@Test public void Defect_reverse_caption_link() { // PURPOSE: bad lnke formatting (caption before link); ] should show up at end, but only [ shows up; PAGE:en.w:Paul Philippoteaux; [caption http://www.americanheritage.com]
fxt.Test_parse_page_wiki_str("[caption irc://a]", "[caption <a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">irc://a</a>]");
fxt.Test_parse_page_wiki_str("[caption irc://a]", "[caption <a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</a>]");
}
@Test public void Lnki() { // PURPOSE: trailing lnki should not get absorbed into lnke; DATE:2014-07-11
fxt.Test_parse_page_wiki_str
( "http://a.org[[B]]" // NOTE: [[ should create another lnki
,String_.Concat_lines_nl_skip_last
( "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a><a href=\"/wiki/B\">B</a>"
( "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a><a href=\"/wiki/B\">B</a>"
));
}
@Test public void Protocol_only() { // PURPOSE: protocol only should return text; DATE:2014-10-09
@@ -84,16 +84,16 @@ public class Xop_lnke_wkr_text_tst {
fxt.Test_parse_page_wiki_str("[http:]" , "[http:]");
}
@Test public void Ignore_punctuation_at_end() { // PURPOSE: ignore "," and related punctuation at end; DATE:2014-10-09
fxt.Test_parse_page_wiki_str("http://a.org," , "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>,"); // basic
fxt.Test_parse_page_wiki_str("http://a.org,," , "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>,,"); // many
fxt.Test_parse_page_wiki_str("http://a.org/b,c" , "<a href=\"http://a.org/b,c\" class=\"external text\" rel=\"nofollow\">http://a.org/b,c</a>"); // do not ignore if in middle
fxt.Test_parse_page_wiki_str("http://a.org:" , "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>:"); // colon at end; compare to "http:"
fxt.Test_parse_page_wiki_str("http://a.org," , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>,"); // basic
fxt.Test_parse_page_wiki_str("http://a.org,," , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>,,"); // many
fxt.Test_parse_page_wiki_str("http://a.org/b,c" , "<a href=\"http://a.org/b,c\" rel=\"nofollow\" class=\"external free\">http://a.org/b,c</a>"); // do not ignore if in middle
fxt.Test_parse_page_wiki_str("http://a.org:" , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>:"); // colon at end; compare to "http:"
}
@Test public void Ignore_punctuation_at_end__paren_end() { // PURPOSE: end parent has special rules; DATE:2014-10-10
fxt.Test_parse_page_wiki_str("(http://a.org)" , "(<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>)"); // trim=y
fxt.Test_parse_page_wiki_str("http://a.org/b(c)", "<a href=\"http://a.org/b(c)\" class=\"external text\" rel=\"nofollow\">http://a.org/b(c)</a>"); // trim=n
fxt.Test_parse_page_wiki_str("(http://a.org)" , "(<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>)"); // trim=y
fxt.Test_parse_page_wiki_str("http://a.org/b(c)", "<a href=\"http://a.org/b(c)\" rel=\"nofollow\" class=\"external free\">http://a.org/b(c)</a>"); // trim=n
}
@Test public void Sym_quote() { // PURPOSE: quote should interrupt lnke; DATE:2014-10-10
fxt.Test_parse_page_wiki_str("http://a.org/b\"c", "<a href=\"http://a.org/b\" class=\"external text\" rel=\"nofollow\">http://a.org/b</a>&quot;c");
fxt.Test_parse_page_wiki_str("http://a.org/b\"c", "<a href=\"http://a.org/b\" rel=\"nofollow\" class=\"external free\">http://a.org/b</a>&quot;c");
}
}

View File

@@ -43,7 +43,7 @@ public class Xop_lnke_wkr_uncommon_tst {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "[[http://a.org a]] [[http://b.org b]]"
), String_.Concat_lines_nl_skip_last
( "[<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">a</a>] [<a href=\"http://b.org\" class=\"external text\" rel=\"nofollow\">b</a>]"
( "[<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">a</a>] [<a href=\"http://b.org\" rel=\"nofollow\" class=\"external text\">b</a>]"
));
}
}

View File

@@ -41,11 +41,11 @@ public class Xop_lnke_wkr_xwiki_tst {
fxt.Test_parse_page_wiki_str("[http://en.wikipedia.org/wiki/A?action=edit a]", "<a href=\"/site/en.wikipedia.org/wiki/A?action=edit\">a</a>");
}
@Test public void Ignore_proto() { // PURPOSE: handle other protocols; PAGE:uk.w:Маскалі; DATE:2015-07-28
fxt.Test_parse_page_wiki_str("[mailto:a b]", "<a href=\"mailto:a\" class=\"external text\" rel=\"nofollow\">b</a>");// should be /w/, not /en.wikipedia.org
fxt.Test_parse_page_wiki_str("[mailto:a b]", "<a href=\"mailto:a\" rel=\"nofollow\" class=\"external text\">b</a>");// should be /w/, not /en.wikipedia.org
}
@Test public void Ignore_alias() { // PURPOSE: fictitious example to make sure aliases are not subbed for domains; DATE:2015-07-28
fxt.Init_xwiki_add_user_("w", "en.wikipedia.org");
fxt.Test_parse_page_wiki_str("[https://w/b c]", "<a href=\"https://w/b\" class=\"external text\" rel=\"nofollow\">c</a>");// should be /w/, not /en.wikipedia.org
fxt.Test_parse_page_wiki_str("[https://w/b c]", "<a href=\"https://w/b\" rel=\"nofollow\" class=\"external text\">c</a>");// should be /w/, not /en.wikipedia.org
}
@Test public void Xwiki__qargs() { // PURPOSE: fix null ref error; PAGE:en.w:Wikipedia:Template_standardisation/demometa DATE:2015-08-02
fxt.Init_xwiki_add_user_("en.wikipedia.org");

View File

@@ -26,8 +26,8 @@ public class Xop_tkn_chkr_lnke extends Xop_tkn_chkr_base {
@Override public int Chk_hook(Tst_mgr mgr, String path, Object actl_obj, int err) {
Xop_lnke_tkn actl = (Xop_lnke_tkn)actl_obj;
err += mgr.Tst_val(lnke_typ == Xop_lnke_tkn.Lnke_typ_null, path, "lnke_typ", lnke_typ, actl.Lnke_typ());
err += mgr.Tst_val(lnke_bgn == -1, path, "lnke_bgn", lnke_bgn, actl.Lnke_bgn());
err += mgr.Tst_val(lnke_end == -1, path, "lnke_end", lnke_end, actl.Lnke_end());
err += mgr.Tst_val(lnke_bgn == -1, path, "lnke_bgn", lnke_bgn, actl.Lnke_href_bgn());
err += mgr.Tst_val(lnke_end == -1, path, "lnke_end", lnke_end, actl.Lnke_href_end());
return err;
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.net.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.lnkis.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.htmls.hrefs.*;
public class Xop_link_parser {
public byte[] Html_xowa_ttl() {return html_xowa_ttl;} private byte[] html_xowa_ttl;
public byte Html_anchor_cls() {return html_anchor_cls;} private byte html_anchor_cls;
@@ -52,7 +52,7 @@ public class Xop_link_parser {
int proto_len = tmp_url.Protocol_bry().length;
if (proto_len + 1 < raw_len && raw[proto_len + 1] == Byte_ascii.Slash) { // next char is slash, assume xfer_itm refers to protocol; EX: file:///C/A.png
int slash_pos = Bry_find_.Find_bwd(raw, Byte_ascii.Slash);
if (slash_pos != Bry_.NotFound) // set xowa_title to file_name; TODO: call Xoa_url.build; note that this will fail sometimes when (a) xfer_itm is very long (File:ReallyLongName will be shortened to 128 chars) or (b) xfer_itm has invalid windows characters (EX:File:a"b"c.jpg)
if (slash_pos != Bry_find_.Not_found) // set xowa_title to file_name; TODO: call Xoa_url.build; note that this will fail sometimes when (a) xfer_itm is very long (File:ReallyLongName will be shortened to 128 chars) or (b) xfer_itm has invalid windows characters (EX:File:a"b"c.jpg)
html_xowa_ttl = Bry_.Mid(raw, slash_pos + Int_.Const_dlm_len, raw.length);
}
else // next char is not slash; assume xfer_itm refers to ns; EX:File:A.png

View File

@@ -16,6 +16,7 @@ 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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_lnki_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "lnki");
public static final Gfo_msg_itm

View File

@@ -16,7 +16,7 @@ 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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.xowa.files.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.lnkis.*; import gplx.xowa.xtns.pfuncs.ttls.*;
import gplx.xowa.files.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.xtns.pfuncs.ttls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.tmpls.*;
public class Xop_lnki_tkn extends Xop_tkn_itm_base {
@@ -24,7 +24,7 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
public void Tkn_tid_to_txt() {tkn_tid = Xop_tkn_itm_.Tid_txt;}
public int Ns_id() {return ns_id;} public Xop_lnki_tkn Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
public Xoa_ttl Ttl() {return ttl;} public Xop_lnki_tkn Ttl_(Xoa_ttl v) {ttl = v; return this;} private Xoa_ttl ttl;
public byte Lnki_type() {return lnki_type;} public Xop_lnki_tkn Lnki_type_(byte v) {lnki_type = (byte)Bitmask_.Add_int(lnki_type, v); return this;} private byte lnki_type = Xop_lnki_type.Id_null;
public byte Lnki_type() {return lnki_type;} private byte lnki_type = Xop_lnki_type.Id_null;
public int Tail_bgn() {return tail_bgn;} public Xop_lnki_tkn Tail_bgn_(int v) {tail_bgn = v; return this;} private int tail_bgn = -1;
public int Tail_end() {return tail_end;} public Xop_lnki_tkn Tail_end_(int v) {tail_end = v; return this;} private int tail_end = -1;
public byte Border() {return border;} public Xop_lnki_tkn Border_(byte v) {border = v; return this;} private byte border = Bool_.__byte;
@@ -61,6 +61,11 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|| (ns_id == Xow_ns_.Id_category // a Category only has a target; any caption is ignored; EX: [[Category:a|b], b is ignored
&& !ttl.ForceLiteralLink()));
}
public Xop_lnki_tkn Lnki_type_(byte v) {
if (lnki_type == Xop_lnki_type.Id_null) // NOTE:per MW:1.25.2, only use 1st argument of thumb|frame|frameless;/includes/parser/Parser.php; // use first appearing option, discard others.; DATE:2015-11-01
lnki_type = v;
return this;
}
public static final double Upright_null = -1;
public static final int Width_null = -1, Height_null = -1;
}

View File

@@ -29,27 +29,27 @@ public class Xop_lnki_type {
)
return true;
else if ( Bitmask_.Has_int(id, Id_frame) // [[File:A.png|frame]] -> 400,200 (frame is always default size)
|| id == Id_null // [[File:A.png]] -> 400,200 (default to original size)
|| id == Id_null // [[File:A.png]] -> 400,200 (default to original size)
|| Bitmask_.Has_int(id, Id_none) // TODO: deprecate; NOTE: still used by one test; DATE:2015-08-03
)
return false;
else // should not happen
else // should not happen
throw Err_.new_unhandled(id);
}
public static boolean Id_limits_large_size(byte id) {// Linker.php|makeThumbLink2|Do not present an image bigger than the source, for bitmap-style images; assuming original of 400,200
public static boolean Id_limits_large_size(byte id) { // Linker.php|makeThumbLink2|Do not present an image bigger than the source, for bitmap-style images; assuming original of 400,200
if ( Bitmask_.Has_int(id, Id_thumb) // [[File:A.png|600px|thumb]] -> 400,200
|| Bitmask_.Has_int(id, Id_frameless) // [[File:A.png|600px|frameless]] -> 400,200
|| Bitmask_.Has_int(id, Id_frame) // [[File:A.png|600px|frame]] -> 400,200 (frame is always default size)
)
return true;
else if ( id == Id_null // [[File:A.png|600px]] -> 600,400; uses orig file of 400,200, but <img> tag src_width / src_height set to 600,400
else if ( id == Id_null // [[File:A.png|600px]] -> 600,400; uses orig file of 400,200, but <img> tag src_width / src_height set to 600,400
|| Bitmask_.Has_int(id, Id_none) // TODO: deprecate; NOTE: leaving in b/c of above failed-deprecate; DATE:2015-08-03
)
return false;
else // should not happen;
else // should not happen;
throw Err_.new_unhandled(id);
}
public static boolean Id_supports_upright(byte id) {// REF:Linker.php|makeImageLink;if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) DATE:2014-05-22
public static boolean Id_supports_upright(byte id) { // REF:Linker.php|makeImageLink;if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) DATE:2014-05-22
if ( Bitmask_.Has_int(id, Id_thumb)
|| Bitmask_.Has_int(id, Id_frameless)
|| Bitmask_.Has_int(id, Id_frame)
@@ -59,7 +59,7 @@ public class Xop_lnki_type {
|| Bitmask_.Has_int(id, Id_none)
)
return false;
else // should not happen;
else // should not happen;
throw Err_.new_unhandled(id);
}
}

View File

@@ -53,7 +53,7 @@ public class Xop_lnki_wkr__basic_tst {
@Test public void Image() {
fxt.Test_parse_page_wiki("[[Image:a]]" , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file).Trg_tkn_(fxt.tkn_arg_val_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9))));
fxt.Test_parse_page_wiki("[[Image:a|border]]" , fxt.tkn_lnki_().Border_(Bool_.Y_byte));
fxt.Test_parse_page_wiki("[[Image:a|thumb]]" , fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb));
fxt.Test_parse_page_wiki("[[Image:a|thumb]]" , fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb));
fxt.Test_parse_page_wiki("[[Image:a|left]]" , fxt.tkn_lnki_().HAlign_(Xop_lnki_align_h.Left));
fxt.Test_parse_page_wiki("[[Image:a|top]]" , fxt.tkn_lnki_().VAlign_(Xop_lnki_align_v.Top));
fxt.Test_parse_page_wiki("[[Image:a|10px]]" , fxt.tkn_lnki_().Width_(10).Height_(-1));

View File

@@ -69,7 +69,7 @@ public class Xop_lnki_wkr__ctg_tst {
, "[[Category:B]]" // category should not show below
), String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li> <a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>"
, " <li> <a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>"
, " </li>"
, "</ul>"
, ""

View File

@@ -0,0 +1,25 @@
/*
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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_lnki_wkr__frame_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
// PURPOSE:use 1st imgtype param; changed between mw1.22.2 and mw1.25.2 PAGE:he.w:מספן_המודיעין EX: [[File:Osa-I class Project205 DN-SN-84-01770.jpg|thumb|frame|abcde]]
@Test public void Use_1st__thumb() {fxt.Test_parse_page_wiki("[[File:A.png|thumb|frame]]", fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb));}
@Test public void Use_1st__frame() {fxt.Test_parse_page_wiki("[[File:A.png|frame|thumb]]", fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_frame));}
}

View File

@@ -32,7 +32,7 @@ public class Xop_lnki_wkr__uncommon_tst {
}
@Test public void Triple_bracket_with_lnke_lnki() { // PURPOSE: handle [http://a.org [[File:A.png|123px]]]; PAGE:ar.w:محمد DATE:2014-08-20
fxt.Test_parse_page_all_str("[http://a.org [[File:A.png|123px]]]"
, "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\"><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" /></a></a>"
, "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\"><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" /></a></a>"
);
}
@Test public void Multiple_captions() { // PURPOSE: multiple captions should be concatenated (used to only take first); EX:zh.d:维基词典:Unicode字符索引/00000FFF; DATE:2014-05-05

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
import gplx.core.primitives.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.htmls.hdumps.core.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.htmls.core.makes.imgs.*;
import gplx.xowa.parsers.tmpls.*;
public class Xog_redlink_mgr implements GfoInvkAble {
private Xog_win_itm win; private Xog_html_itm html_itm; private Xowe_wiki wiki; private Xoae_page page;

View File

@@ -19,7 +19,7 @@ package gplx.xowa.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; imp
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.users.*;
public class Xopg_redlink_lnki_list {
private int lnki_idx = gplx.xowa.htmls.lnkis.Xoh_lnki_wtr.Lnki_id_min; // NOTE: default to 1, not 0, b/c 0 is ignored by wtr; DATE:2014-10-09
private int lnki_idx = gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Lnki_id_min; // NOTE: default to 1, not 0, b/c 0 is ignored by wtr; DATE:2014-10-09
public Xopg_redlink_lnki_list(boolean ttl_is_module) { // never redlink in Module ns; particularly since Lua has multi-line comments for [[ ]]
this.disabled = ttl_is_module;
}
@@ -28,7 +28,7 @@ public class Xopg_redlink_lnki_list {
public int Thread_id() {return thread_id;} private int thread_id = 1;
public void Clear() {
if (disabled) return;
lnki_idx = 0; // NOTE: must start at 0, so that ++lnki_idx is > 0; html_wtr checks for > 0
lnki_idx = gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Lnki_id_min; // NOTE: must start at 0, so that ++lnki_idx is > 0; html_wtr checks for > 0
lnki_list.Clear();
thread_id++;
}

View File

@@ -16,6 +16,7 @@ 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.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_comm_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "comment");
public static final Gfo_msg_itm

View File

@@ -61,9 +61,9 @@ public class Xop_eq_lxr implements Xop_lxr {
hdr_like = ws_end == src_len || src[ws_end] == Byte_ascii.Nl; // hdr_like if next char \n or eos
if (!hdr_like) {
int ctg_end = Xop_nl_lxr.Scan_fwd_for_ctg(ctx, src, cur_pos, src_len); // check if ==[[Category:A]]; DATE:2014-04-17
if ( ctg_end != Bry_.NotFound) { // [[Category: found
if ( ctg_end != Bry_find_.Not_found) { // [[Category: found
ctg_end = Bry_find_.Find_fwd(src, Xop_tkn_.Lnki_end, ctg_end, src_len);
if (ctg_end != Bry_.NotFound) { // ]] found; note that this should do more validation; EX: [[Category:]] should not be valid; DATE:2014-04-17
if (ctg_end != Bry_find_.Not_found) { // ]] found; note that this should do more validation; EX: [[Category:]] should not be valid; DATE:2014-04-17
ctg_end += Xop_tkn_.Lnki_end_len;
ctg_end = Bry_find_.Find_fwd_while_space_or_tab(src, ctg_end, src_len);
if (ctg_end == src_len || src[ctg_end] == Byte_ascii.Nl) // hdr_like if ]]\n after [[Category:A]]

View File

@@ -1,35 +0,0 @@
/*
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.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*; import gplx.xowa.langs.*;
public class Xop_macro_lxr implements Xop_lxr {
public Xop_macro_lxr() {}
public int Lxr_tid() {return Xop_lxr_.Tid_macro;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Tab, this); core_trie.Add(Xop_tab_tkn.Bry_tab_ent, this);}
public void Init_by_lang(Xol_lang_itm lang, Btrie_fast_mgr core_trie) {}
public void Term(Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Tab);
src[bgn_pos] = Byte_ascii.Tab; // HACK: SEE:NOTE_1:tabs
for (int i = bgn_pos + 1; i < cur_pos; i++)
src[i] = Byte_ascii.Space;
ctx.Subs_add(root, tkn_mkr.Tab(bgn_pos, cur_pos));
return cur_pos;
}
public static final Xop_tab_lxr Instance = new Xop_tab_lxr();
}

View File

@@ -16,6 +16,7 @@ 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.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_misc_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "super");
public static final Gfo_msg_itm

View File

@@ -17,12 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public class Xop_space_tkn extends Xop_tkn_itm_base {
public Xop_space_tkn(boolean immutable, int bgn, int end) {this.Tkn_ini_pos(immutable, bgn, end);}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_space;}
@Override public Xop_tkn_itm Tkn_clone(Xop_ctx ctx, int bgn, int end) {
return ctx.Tkn_mkr().Space_mutable(bgn, end);
}
public Xop_space_tkn(boolean immutable, int bgn, int end) {this.Tkn_ini_pos(immutable, bgn, end);}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_space;}
@Override public Xop_tkn_itm Tkn_clone(Xop_ctx ctx, int bgn, int end) {return ctx.Tkn_mkr().Space_mutable(bgn, end);}
@Override public boolean Tmpl_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Bry_bfr bfr) {
if (this.Tkn_immutable()) {
bfr.Add_byte(Byte_ascii.Space);
@@ -31,5 +30,7 @@ public class Xop_space_tkn extends Xop_tkn_itm_base {
else
return super.Tmpl_evaluate(ctx, src, caller, bfr);
}
Xop_space_tkn() {}
@Override public void Html__write(Bry_bfr bfr, Xoh_html_wtr wtr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoh_html_wtr_cfg cfg, Xop_tkn_grp grp, int sub_idx, byte[] src) {
bfr.Add_byte_repeat(Byte_ascii.Space, this.Src_end_grp(grp, sub_idx) - this.Src_bgn_grp(grp, sub_idx)); // NOTE: lnki.caption will convert \n to \s; see Xop_nl_lxr; PAGE:en.w:Schwarzschild radius
}
}

View File

@@ -26,7 +26,7 @@ public class Xop_nl_lxr implements Xop_lxr {
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
if (bgn_pos == Xop_parser_.Doc_bgn_bos) return ctx.Lxr_make_txt_(cur_pos); // simulated nl at beginning of every parse
int trim_category_pos = Scan_fwd_for_ctg(ctx, src, cur_pos, src_len);
if (trim_category_pos != Bry_.NotFound) { // [[Category]] found after ws
if (trim_category_pos != Bry_find_.Not_found) { // [[Category]] found after ws
int root_subs_len = root.Subs_len();
if (root_subs_len > 0) {
Xop_tkn_itm tkn = root.Subs_get(root_subs_len - 1);
@@ -104,14 +104,14 @@ public class Xop_nl_lxr implements Xop_lxr {
&& Bry_.Has_at(src, src_len, ctg_trie.Match_pos(), Byte_ascii.Colon)) { // check that next char is :
return i;// return pos of 1st [
}
return Bry_.NotFound;
return Bry_find_.Not_found;
}
break;
default: // non-ws; return not found
return Bry_.NotFound;
return Bry_find_.Not_found;
}
}
return Bry_.NotFound;
return Bry_find_.Not_found;
}
public static final Xop_nl_lxr Instance = new Xop_nl_lxr(); Xop_nl_lxr() {}
}

View File

@@ -16,6 +16,7 @@ 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.parsers.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public class Xop_para_tkn extends Xop_tkn_itm_base {
public Xop_para_tkn(int pos) {this.Tkn_ini_pos(false, pos, pos);}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_para;}
@@ -28,4 +29,26 @@ public class Xop_para_tkn extends Xop_tkn_itm_base {
, Tid_para = 1 // </p>
, Tid_pre = 2 // </pre>
;
@Override public void Html__write(Bry_bfr bfr, Xoh_html_wtr wtr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoh_html_wtr_cfg cfg, Xop_tkn_grp grp, int sub_idx, byte[] src) {
if (nl_bgn && bfr.Len() > 0) {
if (hctx.Mode_is_alt()) // write called during alt=''
bfr.Add_byte_space(); // write '\s', not '\n'
else
bfr.Add_byte_if_not_last(Byte_ascii.Nl); // write '\n'
}
switch (para_end) {
case Xop_para_tkn.Tid_none: break;
case Xop_para_tkn.Tid_para: bfr.Add(Html_tag_.P_rhs).Add_byte_nl(); break; // '<p>'
case Xop_para_tkn.Tid_pre: bfr.Add(Html_tag_.Pre_rhs).Add_byte_nl(); break; // '<pre>'
default: throw Err_.new_unhandled(para_end);
}
switch (para_bgn) {
case Xop_para_tkn.Tid_none: break;
case Xop_para_tkn.Tid_para: Xoh_html_wtr_.Para__assert_tag_starts_on_nl(bfr, this.Src_bgn()); bfr.Add(Html_tag_.P_lhs); break; // '</p>'
case Xop_para_tkn.Tid_pre: Xoh_html_wtr_.Para__assert_tag_starts_on_nl(bfr, this.Src_bgn()); bfr.Add(Html_tag_.Pre_lhs); break; // '</pre>'
default: throw Err_.new_unhandled(para_bgn);
}
if (space_bgn > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, space_bgn);
}
}

View File

@@ -16,6 +16,7 @@ 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.parsers.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public class Xop_pre_tkn extends Xop_tkn_itm_base {
public Xop_pre_tkn(int bgn, int end, byte pre_tid, Xop_tkn_itm pre_bgn_tkn) {
this.Tkn_ini_pos(false, bgn, end);
@@ -23,5 +24,12 @@ public class Xop_pre_tkn extends Xop_tkn_itm_base {
}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_pre;}
public byte Pre_tid() {return pre_tid;} private byte pre_tid = Pre_tid_null;
@Override public void Html__write(Bry_bfr bfr, Xoh_html_wtr wtr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoh_html_wtr_cfg cfg, Xop_tkn_grp grp, int sub_idx, byte[] src) {
switch (pre_tid) {
case Xop_pre_tkn.Pre_tid_bgn: bfr.Add(Html_tag_.Pre_lhs); break; // '<pre>'
case Xop_pre_tkn.Pre_tid_end: bfr.Add(Bry__pre__rhs); break; // '\n</pre>\n\n'
}
}
public static final byte Pre_tid_null = 0, Pre_tid_bgn = 1, Pre_tid_end = 2;
private static final byte[] Bry__pre__rhs = Bry_.new_a7("\n</pre>\n\n");
}

View File

@@ -16,6 +16,7 @@ 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_tblw_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "tblw");
public static final Gfo_msg_itm

View File

@@ -16,6 +16,7 @@ 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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.xowa.htmls.*;
public class Arg_itm_tkn_null extends Xop_tkn_null implements Arg_itm_tkn { public int Dat_bgn() {return -1;}
public int Dat_end() {return -1;} public Arg_itm_tkn Dat_end_(int v) {return this;}
public Arg_itm_tkn Dat_rng_(int bgn, int end) {return this;}

View File

@@ -38,5 +38,5 @@ class Arg_itm_tkn_mock extends Arg_itm_tkn_base {
this.Dat_ary_(dat_ary);
this.val = v;
} String val;
@Override public boolean Tmpl_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Bry_bfr bfr) {bfr.Add_str(val); return true;}
@Override public boolean Tmpl_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Bry_bfr bfr) {bfr.Add_str_u8(val); return true;}
}

View File

@@ -16,6 +16,7 @@ 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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_curly_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "curly");
public static final Gfo_msg_itm

View File

@@ -16,6 +16,7 @@ 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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_tmpl_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "tmpl");
public static final Gfo_msg_itm

View File

@@ -41,12 +41,12 @@ public class Xot_defn_tmpl implements Xot_defn {
int src_len = src.length;
while (true) {
int find_bgn = Bry_find_.Find_fwd(src, Bry_onlyinclude_bgn, pos, src_len);
if (find_bgn == Bry_.NotFound) {
if (find_bgn == Bry_find_.Not_found) {
break;
}
int find_bgn_lhs = find_bgn + Bry_onlyinclude_bgn_len;
int find_end = Bry_find_.Find_fwd(src, Bry_onlyinclude_end, find_bgn_lhs, src_len);
if (find_end == Bry_.NotFound) {
if (find_end == Bry_find_.Not_found) {
break;
}
bfr.Add_mid(src, find_bgn_lhs, find_end);

View File

@@ -94,9 +94,9 @@ public class Xot_defn_trace_dbg implements Xot_defn_trace {
String s = (String)argKeys.Get_at(i);
String key = String_.GetStrBefore(s, "=");
String val = String_.GetStrAfter(s, "=");
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add_str(key)
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add_str_u8(key)
.Add_byte_repeat(Byte_ascii.Space, key_max - String_.Len(key))
.Add_byte(Byte_ascii.Colon).Add_byte(Byte_ascii.Space).Add_str(val).Add_byte_nl();
.Add_byte(Byte_ascii.Colon).Add_byte(Byte_ascii.Space).Add_str_u8(val).Add_byte_nl();
}
}

View File

@@ -82,7 +82,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
// 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_.NotFound) {
if (tmpl_ns_len != Bry_find_.Not_found) {
name_ary = Bry_.Mid(name_ary, name_bgn + tmpl_ns_len, name_ary_len);
name_ary_len = name_ary.length;
name_bgn = 0;
@@ -124,7 +124,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
case Xot_defn_.Tid_func:
if (defn.Defn_require_colon_arg()) {
colon_pos = Bry_find_.Find_fwd(name_ary, Byte_ascii.Colon);
if (colon_pos == Bry_.NotFound)
if (colon_pos == Bry_find_.Not_found)
defn = Xot_defn_.Null;
}
else {
@@ -134,7 +134,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
case Xot_defn_.Tid_raw:
case Xot_defn_.Tid_msg:
int raw_colon_pos = Bry_find_.Find_fwd(name_ary, Byte_ascii.Colon);
if (raw_colon_pos == Bry_.NotFound) {} // colon missing; EX: {{raw}}; noop and assume template name; DATE:2014-02-11
if (raw_colon_pos == Bry_find_.Not_found) {} // colon missing; EX: {{raw}}; noop and assume template name; DATE:2014-02-11
else { // colon present;
name_ary = Bry_.Mid(name_ary, finder.Subst_end() + 1, name_ary_len); // chop off "raw"; +1 is for ":"; note that +1 is in bounds b/c raw_colon was found
name_ary_len = name_ary.length;

View File

@@ -435,7 +435,7 @@ public class Xot_invk_wkr_basic_tst {
}
@Test public void Tmpl_case_match() { // PURPOSE: template name should match by case; EX:es.d:eclipse; DATE:2014-02-12
fxt.Init_defn_clear();
fxt.Init_defn_add("CASE_MATCH", "found", Xow_ns_case_.Id_all);
fxt.Init_defn_add("CASE_MATCH", "found", Xow_ns_case_.Tid__all);
fxt.Test_parse_tmpl_str("{{case_match}}", "[[:Template:case_match]]"); // Xot_invk_tkn will do 2 searches: "test" and "Test"
fxt.Test_parse_tmpl_str("{{cASE_MATCH}}", "found"); // Xot_invk_tkn will do 2 searches: "tEST" and "TEST"
fxt.Init_defn_clear();

View File

@@ -16,6 +16,7 @@ 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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xot_prm_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "tmpl_defn_arg");
public static final Gfo_msg_itm

View File

@@ -43,10 +43,10 @@ public class Xop_redirect_mgr {
Object redirect_itm = redirect_hash.Get_by_mid(src, bgn, kwd_end);
if (redirect_itm == null) return Redirect_null_ttl; // not a redirect kwd
int ttl_bgn = Xop_redirect_mgr_.Get_ttl_bgn_or_neg1(src, kwd_end, src_len);
if (ttl_bgn == Bry_.NotFound) return Redirect_null_ttl;
if (ttl_bgn == Bry_find_.Not_found) return Redirect_null_ttl;
ttl_bgn += Xop_tkn_.Lnki_bgn.length;
int ttl_end = Bry_find_.Find_fwd(src, Xop_tkn_.Lnki_end, ttl_bgn);
if (ttl_end == Bry_.NotFound) return Redirect_null_ttl;
if (ttl_end == Bry_find_.Not_found) return Redirect_null_ttl;
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);
@@ -112,16 +112,16 @@ class Xop_redirect_mgr_ {
if (colon_null)
colon_null = false;
else
return Bry_.NotFound;
return Bry_find_.Not_found;
break;
default:
break;
case Byte_ascii.Brack_bgn:
int nxt_pos = i + 1;
if (nxt_pos >= end) return Bry_.NotFound; // [ at eos
return src[nxt_pos] == Byte_ascii.Brack_bgn ? i : Bry_.NotFound;
if (nxt_pos >= end) return Bry_find_.Not_found; // [ at eos
return src[nxt_pos] == Byte_ascii.Brack_bgn ? i : Bry_find_.Not_found;
}
}
return Bry_.NotFound;
return Bry_find_.Not_found;
}
}

View File

@@ -16,7 +16,7 @@ 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.parsers.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*; import gplx.xowa.parsers.amps.*;
import gplx.core.btries.*; import gplx.xowa.parsers.amps.*; import gplx.core.log_msgs.*;
public class Xop_sanitizer {
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs(), amp_trie;
private Xop_amp_mgr amp_mgr;

View File

@@ -16,7 +16,7 @@ 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.parsers.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*; import gplx.xowa.parsers.amps.*;
import org.junit.*; import gplx.core.log_msgs.*; import gplx.xowa.parsers.amps.*;
public class Xop_sanitizer_tst {
Xop_sanitizer_fxt fxt = new Xop_sanitizer_fxt();
@Before public void init() {fxt.Clear();}

View File

@@ -114,9 +114,9 @@ public class Vnt_convert_lang {
pos += 2; // skip "-{"
frame_bfr.Add(Bry__curly_bgn);
if (!warning_done) {
frame_bfr.Add_str("<span class=\"error\">max depth");
frame_bfr.Add_str_a7("<span class=\"error\">max depth");
// wfMessage('language-converter-depth-warning')->numParams($this->mMaxDepth)->inContentLanguage()->text()
frame_bfr.Add_str("</span>");
frame_bfr.Add_str_a7("</span>");
warning_done = true;
}
continue;

View File

@@ -16,6 +16,7 @@ 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.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_xnde_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "xnde");
public static final Gfo_msg_itm

View File

@@ -536,7 +536,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
break;
}
}
return found ? rv : Bry_.NotFound;
return found ? rv : Bry_find_.Not_found;
}
private int Find_xtn_end_lhs(Xop_ctx ctx, Xop_xnde_tag tag, byte[] src, int src_len, int open_bgn, int open_end, byte[] close_bry) {
int tag_bgn = open_bgn - Pfunc_tag.Xtag_len;
@@ -552,7 +552,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
return i;
}
}
return Bry_.NotFound;
return Bry_find_.Not_found;
}
}
private int Find_xtn_end_tag(Xop_ctx ctx, byte[] src, int src_len, int open_end, byte[] close_bry, int tag_bgn) {
@@ -590,14 +590,14 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
close_bry[i] = src[src_offset + i];
boolean auto_close = false;
int close_bgn = Find_xtn_end_lhs(ctx, tag, src, src_len, open_bgn, open_end, close_bry);
if (close_bgn == Bry_.NotFound) auto_close = true; // auto-close if end not found; verified with <poem>, <gallery>, <imagemap>, <hiero>, <references> DATE:2014-08-23
if (close_bgn == Bry_find_.Not_found) auto_close = true; // auto-close if end not found; verified with <poem>, <gallery>, <imagemap>, <hiero>, <references> DATE:2014-08-23
int close_end = -1;
if (auto_close) {
xnde_end = close_bgn = close_end = src_len;
}
else {
close_end = Find_end_tag_pos(src, src_len, close_bgn + close_bry.length);
if (close_end == Bry_.NotFound) return ctx.Lxr_make_log_(Xop_xnde_log.Xtn_end_not_found, src, open_bgn, open_end);
if (close_end == Bry_find_.Not_found) return ctx.Lxr_make_log_(Xop_xnde_log.Xtn_end_not_found, src, open_bgn, open_end);
xnde_end = close_end;
}