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

v2.12.1.1

This commit is contained in:
gnosygnu
2015-12-06 23:12:52 -05:00
parent 097e6c7f80
commit 9509363f46
337 changed files with 3473 additions and 1917 deletions

View File

@@ -61,10 +61,10 @@ public class Xop_ctx {
public boolean Only_include_evaluate() {return only_include_evaluate;} public Xop_ctx Only_include_evaluate_(boolean v) {only_include_evaluate = v; return this;} private boolean only_include_evaluate;
public Lst_section_nde_mgr Lst_section_mgr() {if (lst_section_mgr == null) lst_section_mgr = new Lst_section_nde_mgr(); return lst_section_mgr;} private Lst_section_nde_mgr lst_section_mgr;
public Hash_adp_bry Lst_page_regy() {return lst_page_regy;} private Hash_adp_bry lst_page_regy;
public boolean Ref_ignore() {return ref_ignore;} public Xop_ctx Ref_ignore_(boolean v) {ref_ignore = v; return this;} private boolean ref_ignore; // NOTE: only applies to sub_ctx's created by <pages> and {{#lst}}; if true, does not add <ref> to page.Ref_mgr; DATE:2014-04-24
public byte[] References_group() {return references_group;} public Xop_ctx References_group_(byte[] v) {references_group = v; return this;} private byte[] references_group;
public boolean Tid_is_popup() {return tid_is_popup;} public void Tid_is_popup_(boolean v) {tid_is_popup = v;} private boolean tid_is_popup = false;
public boolean Tid_is_image_map() {return tid_is_image_map;} public Xop_ctx Tid_is_image_map_(boolean v) {tid_is_image_map = v; return this;} private boolean tid_is_image_map;
public boolean Ref_ignore() {return ref_ignore;} public Xop_ctx Ref_ignore_(boolean v) {ref_ignore = v; return this;} private boolean ref_ignore; // NOTE: only applies to sub_ctx's created by <pages> and {{#lst}}; if true, does not add <ref> to page.Ref_mgr; DATE:2014-04-24
public byte[] References_group() {return references_group;} public Xop_ctx References_group_(byte[] v) {references_group = v; return this;} private byte[] references_group;
public boolean Tid_is_popup() {return tid_is_popup;} public void Tid_is_popup_(boolean v) {tid_is_popup = v;} private boolean tid_is_popup = false;
public boolean Tid_is_image_map() {return tid_is_image_map;} public Xop_ctx Tid_is_image_map_(boolean v) {tid_is_image_map = v; return this;} private boolean tid_is_image_map;
public Xop_log_invoke_wkr Xtn__scribunto__invoke_wkr() {
if (scrib_invoke_wkr == null)
scrib_invoke_wkr = ((Scrib_xtn_mgr)(app.Xtn_mgr().Get_or_fail(Scrib_xtn_mgr.XTN_KEY))).Invoke_wkr();
@@ -72,8 +72,9 @@ public class Xop_ctx {
} private Xop_log_invoke_wkr scrib_invoke_wkr;
public Xop_log_property_wkr Xtn__wikidata__property_wkr() {return app.Wiki_mgr().Wdata_mgr().Property_wkr();}
public Gfo_msg_log Msg_log() {return msg_log;} private Gfo_msg_log msg_log;
public Xop_ctx Clear() {
cur_page.Clear();
public Xop_ctx Clear_all() {return Clear(true);}
public Xop_ctx Clear(boolean clear_scrib) {
cur_page.Clear(clear_scrib);
stack = Xop_tkn_itm_.Ary_empty;
stack_len = stack_max = 0;
app.Wiki_mgr().Wdata_mgr().Clear();
@@ -96,12 +97,12 @@ public class Xop_ctx {
Stack_pop_til(root, src, 0, true, src_len, src_len, Xop_tkn_itm_.Tid_txt);
for (Xop_ctx_wkr wkr : wkrs) wkr.Page_end(this, root, src, src_len);
}
public boolean Lxr_make() {return lxr_make;} public Xop_ctx Lxr_make_(boolean v) {lxr_make = v; return this;} private boolean lxr_make = false;
public int Lxr_make_txt_(int pos) {lxr_make = false; return pos;}
public int Lxr_make_log_(Gfo_msg_itm itm, byte[] src, int bgn_pos, int cur_pos) {lxr_make = false; msg_log.Add_itm_none(itm, src, bgn_pos, cur_pos); return cur_pos;}
public boolean Empty_ignored() {return empty_ignored;}
public void Empty_ignored_y_() {empty_ignored = true;} private boolean empty_ignored = false;
public void Empty_ignored_n_() {empty_ignored = false;}
public boolean Lxr_make() {return lxr_make;} public Xop_ctx Lxr_make_(boolean v) {lxr_make = v; return this;} private boolean lxr_make = false;
public int Lxr_make_txt_(int pos) {lxr_make = false; return pos;}
public int Lxr_make_log_(Gfo_msg_itm itm, byte[] src, int bgn_pos, int cur_pos) {lxr_make = false; msg_log.Add_itm_none(itm, src, bgn_pos, cur_pos); return cur_pos;}
public boolean Empty_ignored() {return empty_ignored;}
public void Empty_ignored_y_() {empty_ignored = Bool_.Y;} private boolean empty_ignored = false;
public void Empty_ignored_n_() {empty_ignored = Bool_.N;}
public void Empty_ignore(Xop_root_tkn root, int empty_bgn) {
int empty_end = root.Subs_len();
for (int i = empty_bgn; i < empty_end; i++) {
@@ -303,15 +304,12 @@ public class Xop_ctx {
if (stack_pos == -1) return;
ctx.Stack_pop_til(root, src, stack_pos, true, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_txt);
}
public static Xop_ctx new_(Xowe_wiki wiki) {
Xop_ctx rv = new Xop_ctx(wiki, Xoae_page.new_(wiki, Xoa_ttl.parse(wiki, Xoa_page_.Main_page_bry))); // HACK: use "Main_Page" to put in valid page title
return rv;
}
public static Xop_ctx new_sub_(Xowe_wiki wiki) {return new_sub_(wiki, wiki.Parser_mgr().Ctx().cur_page);}
public static Xop_ctx new_main_page(Xowe_wiki wiki) {return new_(wiki, Xoa_page_.Main_page_bry);} // HACK: use "Main_Page" to put in valid page title
public static Xop_ctx new_(Xowe_wiki wiki, byte[] ttl_bry) {return new Xop_ctx(wiki, Xoae_page.New(wiki, wiki.Ttl_parse(ttl_bry)));}
public static Xop_ctx new_sub_(Xowe_wiki wiki) {return new_sub_(wiki, wiki.Parser_mgr().Ctx().cur_page);}
public static Xop_ctx new_sub_(Xowe_wiki wiki, Xoae_page page) { // TODO: new_sub_ should reuse ctx's page; callers who want new_page should call new_sub_page_; DATE:2014-04-10
Xop_ctx ctx = wiki.Parser_mgr().Ctx();
Xop_ctx rv = new Xop_ctx(wiki, page);
new_copy(ctx, rv);
new_copy(wiki.Parser_mgr().Ctx(), rv);
return rv;
}
public static Xop_ctx new_sub_page_(Xowe_wiki wiki, Xop_ctx ctx, Hash_adp_bry lst_page_regy) {
@@ -320,8 +318,17 @@ public class Xop_ctx {
rv.lst_page_regy = lst_page_regy; // NOTE: must share ref for lst only (do not share for sub_(), else stack overflow)
return rv;
}
public static Xop_ctx New_sub_by_ctx(Xop_ctx ctx) {
Xowe_wiki wiki = ctx.Wiki();
Xop_ctx rv = new Xop_ctx(wiki, Xoae_page.New(wiki, wiki.Ttl_parse(ctx.Cur_page().Ttl().Full_db())));
new_copy(ctx, rv);
return rv;
}
private static void new_copy(Xop_ctx src, Xop_ctx trg) {
trg.Lnki().File_wkr_(src.Lnki().File_wkr()); // always share file_wkr between sub contexts
trg.tmpl_output = src.tmpl_output; // share bfr for optimization purposes
trg.ref_ignore = src.ref_ignore; // copy ref_ignore; needed for refs inside poem else duplicate refs; it.s:La_Secchia_rapita/Canto_primo; DATE:2015-12-03
trg.references_group = src.references_group;
trg.cur_page.Ref_mgr_(src.cur_page.Ref_mgr());
}
}

View File

@@ -70,7 +70,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
tmpl.Init_by_new(ns, name, src, root, tmpl_props.OnlyInclude_exists);
} private Xot_compile_data tmpl_props = new Xot_compile_data();
public void Parse_page_all_clear(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src) {
ctx.Cur_page().Clear(); ctx.App().Msg_log().Clear();
ctx.Cur_page().Clear_all(); ctx.App().Msg_log().Clear();
Parse_text_to_wdom(root, ctx, tkn_mkr, src, Xop_parser_.Doc_bgn_bos);
}
public Xop_root_tkn Parse_text_to_wdom_old_ctx(Xop_ctx old_ctx, byte[] src, boolean doc_bgn_pos) {return Parse_text_to_wdom(Xop_ctx.new_sub_(old_ctx.Wiki()), src, doc_bgn_pos);}

View File

@@ -22,7 +22,7 @@ public class Xow_parser_mgr {
private Xop_parser anchor_encode_parser;
public Xow_parser_mgr(Xowe_wiki wiki) {
this.wiki = wiki; this.tkn_mkr = wiki.Appe().Parser_mgr().Tkn_mkr();
this.ctx = Xop_ctx.new_(wiki);
this.ctx = Xop_ctx.new_main_page(wiki);
this.main = Xop_parser.new_wiki(wiki);
}
public Xop_ctx Ctx() {return ctx;} private final Xop_ctx ctx;
@@ -40,7 +40,7 @@ public class Xow_parser_mgr {
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(page); // notify scribunto about page changed
ctx.Cur_page_(page);
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw());
if (clear) {page.Clear();}
if (clear) {page.Clear_all();}
Xoa_ttl ttl = page.Ttl();
if (Xow_page_tid.Identify(wiki.Domain_tid(), ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10
main.Parse_text_to_wdom(root, ctx, tkn_mkr, page.Data_raw(), Xop_parser_.Doc_bgn_bos);

View File

@@ -16,8 +16,20 @@ 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.bits.*;
public class Xop_lnki_type {
public static final byte Id_null = 0, Id_none = 1, Id_frameless = 2, Id_frame = 4, Id_thumb = 8;
public static final byte Tid_null = 0, Tid_none = 1, Tid_frameless = 2, Tid_frame = 3, Tid_thumb = 4; // SERIALIZED
public static byte To_tid(byte flag) {
switch (flag) {
case Xop_lnki_type.Id_null: return Xop_lnki_type.Tid_null;
case Xop_lnki_type.Id_none: return Xop_lnki_type.Tid_none;
case Xop_lnki_type.Id_frameless: return Xop_lnki_type.Tid_frameless;
case Xop_lnki_type.Id_frame: return Xop_lnki_type.Tid_frame;
case Xop_lnki_type.Id_thumb: return Xop_lnki_type.Tid_thumb;
default: throw Err_.new_unhandled(flag);
}
}
public static boolean Id_is_thumbable(byte id) {
return ( Bitmask_.Has_int(id, Id_thumb) // for purposes of displaying images on page, thumb and frame both create a thumb box
|| Bitmask_.Has_int(id, Id_frame)

View File

@@ -265,14 +265,26 @@ public class Xop_lnki_wkr__basic_tst {
@Test public void Encoded_url() { // PURPOSE.fix: url-encoded characters broke parser when embedded in link; DATE:2013-03-01
fxt.Init_xwiki_add_user_("commons.wikimedia.org");
fxt.Test_parse_page_wiki_str("[[File:A.png|link=//commons.wikimedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0?uselang=ru|b]]"
, "<a href=\"/site/commons.wikimedia.org/wiki/Заглавная_страница?uselang=ru\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"b\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>");
, "<a href=\"/site/commons.wikimedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0?uselang=ru\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"b\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>");
}
@Test public void Link_invalid() { // PURPOSE.fix: do not render invalid text; EX: link={{{1}}}; [[Fil:Randers_-_Hadsund_railway.png|120x160px|link={{{3}}}|Randers-Hadsund Jernbane]]; DATE:2013-03-04
@Test public void Link__invalid() { // PURPOSE.fix: do not render invalid text; EX: link={{{1}}}; [[Fil:Randers_-_Hadsund_railway.png|120x160px|link={{{3}}}|Randers-Hadsund Jernbane]]; DATE:2013-03-04
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link={{{1}}}|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@Test public void Link__html_ent() {// PURPOSE:html entities should be converted to chars; EX:&nbsp; -> _; DATE:2013-12-16
fxt.Test_parse_page_wiki_str
( "[[File:A.png|link=b&nbsp;c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/B_c\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
));
}
@Test public void Link__encode() {// PURPOSE:spaces should become underscore; DATE:2015-11-27
fxt.Test_parse_page_wiki_str
( "[[File:A.png|link=File:A b ç.ogg]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/File:A_b_%C3%A7.ogg\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
));
}
@Test public void Href_anchor_leading_space() { // PURPOSE: ?action=edit should be encoded; DATE:2013-02-10
fxt.Test_parse_page_all_str("[[A #b]]", "<a href=\"/wiki/A#b\">A #b</a>");
}
@@ -292,19 +304,13 @@ public class Xop_lnki_wkr__basic_tst {
fxt.Test_parse_page_all_str("[[Ab]]çd e", "<a href=\"/wiki/Ab\">Abçd</a> e");
lnki_trail_mgr.Del(ltr_c_in_french);
}
@Test public void Link_html_ent() {// PURPOSE:html entities should be converted to chars; EX:&nbsp; -> _; DATE:2013-12-16
fxt.Test_parse_page_wiki_str
( "[[File:A.png|link=b&nbsp;c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/B_c\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
));
}
@Test public void Page() {
fxt.Test_parse_page_wiki("[[File:A.pdf|page=12]]" , fxt.tkn_lnki_().Page_(12));
}
@Test public void Visited() { // PURPOSE: show redirected titles as visited; EX:fr.w:Alpes_Pennines; DATE:2014-02-28
Xowe_wiki wiki = fxt.Wiki();
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_a7("Src")); // simulate requrest for "Src" page
Xoae_page previous_page = Xoae_page.test_(wiki, ttl);
Xoae_page previous_page = Xoae_page.New_test(wiki, ttl);
previous_page.Redirected_ttls().Add(Bry_.new_a7("Src")); // simulate redirect from "Src"
fxt.App().Usere().History_mgr().Add(previous_page); // simulate "Src" already being clicked once; this is the key call
fxt.Wtr_cfg().Lnki_visited_y_();

View File

@@ -41,7 +41,7 @@ public class Xop_lnki_wkr__link_tst {
@Test public void Link_file_system() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=file:///C/B.png|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"file:///C/B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
( "<a href=\"file:///C/B.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@Test public void Link_file_ns() {

View File

@@ -25,5 +25,5 @@ public class Xop_ignore_tkn extends Xop_tkn_itm_base {
@Override public boolean Tmpl_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Bry_bfr bfr) {return true;}
public static final byte
Ignore_tid_null = 0, Ignore_tid_comment = 1, Ignore_tid_include_tmpl = 2, Ignore_tid_include_wiki = 3, Ignore_tid_htmlTidy_tblw = 4
, Ignore_tid_xnde_dangling = 5, Ignore_tid_nbsp = 6, Ignore_tid_empty_li = 7, Ignore_tid_pre_at_bos = 8, Ignore_tid_tr_w_td = 9;
, Ignore_tid_xnde_dangling = 5, Ignore_tid_nbsp = 6, Ignore_tid_empty_li = 7, Ignore_tid_pre_at_bos = 8, Ignore_tid_tr_w_td = 9, Ignore_tid_double_pipe = 10;
}

View File

@@ -189,7 +189,12 @@ public class Xop_tblw_wkr implements Xop_ctx_wkr {
case Tblw_type_td2:
boolean create_th = false;
switch (prv_tid) {
case Xop_tkn_itm_.Tid_tblw_tr: break; // noop; <tr><td>
case Xop_tkn_itm_.Tid_tblw_tr:
if (wlxr_type == Tblw_type_td2) { // ignore sequences like "\n|- ||"; PAGE: nl.w:Tabel_van_Belgische_gemeenten; DATE:2015-12-03
ctx.Subs_add(root, tkn_mkr.Ignore(bgn_pos, cur_pos, Xop_ignore_tkn.Ignore_tid_double_pipe));
return cur_pos;
}
break;
case Xop_tkn_itm_.Tid_tblw_td: // fix; <td><td> -> <td></td><td>
if ( prv_tkn.Tblw_xml() // prv is <td>
&& !tbl_is_xml // cur is "\n|"

View File

@@ -111,4 +111,19 @@ public class Xop_tblw_wkr__uncommon_tst {
, "</table>"
));
}
@Test public void Tr_with_pipe_should_ignore() { // PURPOSE: ignore sequences like "\n|- ||"; PAGE: nl.w:Tabel_van_Belgische_gemeenten; DATE:2015-12-03
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "{|"
, "|- ||"
, "|a|b"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
));
}
}

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.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public interface Xot_defn extends RlsAble {
public interface Xot_defn extends Rls_able {
byte Defn_tid();
byte[] Name();
int Cache_size();

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.dbs.*;
public class Vnt_log_tbl implements RlsAble {
public class Vnt_log_tbl implements Rls_able {
private final String tbl_name = "log_vnt"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_uid, fld_page_id, fld_rule_idx
, fld_flag_count, fld_lang_count, fld_undi_count, fld_bidi_count

View File

@@ -21,7 +21,7 @@ public class Xop_xnde_tag_ {
public static final int End_nde_mode_normal = 0, End_nde_mode_inline = 1, End_nde_mode_escape = 2; // escape is for hr which does not support </hr>
public static final int Bgn_nde_mode_normal = 0, Bgn_nde_mode_inline = 1;
public static final byte[] Name_onlyinclude = Bry_.new_a7("onlyinclude");
public static final byte[] Xtn_end_tag_bgn = Bry_.new_a7("</");//, Xtn_end_tag_end = Bry_.new_a7(">");
public static final byte[] Xtn_end_tag_bgn = Bry_.new_a7("</");
public static final int
Tid__null = -1
, Tid_b = 0

View File

@@ -541,31 +541,10 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
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;
if (tag_bgn > -1
&& Bry_.Eq(src, tag_bgn, tag_bgn + Pfunc_tag.Xtag_bgn_lhs.length, Pfunc_tag.Xtag_bgn_lhs)) // xtn created by tag
return Find_xtn_end_tag(ctx, src, src_len, open_end, close_bry, tag_bgn + Pfunc_tag.Xtag_bgn);
else { // search rest of String for case-insensitive name; NOTE: used to do CS first, then fall-back on CI; DATE:2013-12-02
xtn_end_tag_trie.Clear();
xtn_end_tag_trie.Add_obj(close_bry, close_bry);
for (int i = open_end; i < src_len; i++) {
Object o = xtn_end_tag_trie.Match_bgn(src, i, src_len);
if (o != null) {
return i;
}
}
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) {
int tag_id = Bry_.To_int_or(src, tag_bgn, tag_bgn + 10, -1);
if (tag_id == -1) {ctx.App().Usr_dlg().Warn_many("", "", "parser.xtn: could not extract int: page=~{0}", ctx.Cur_page().Url().To_str()); return Bry_find_.Not_found;}
Bry_bfr tmp = ctx.Wiki().Utl__bfr_mkr().Get_b128();
tmp.Add(Pfunc_tag.Xtag_end_lhs).Add_int_pad_bgn(Byte_ascii.Num_0, 10, tag_id).Add(Pfunc_tag.Xtag_rhs);
byte[] tag_end = tmp.To_bry_and_rls();
int rv = Bry_find_.Find_fwd(src, tag_end, open_end + Pfunc_tag.Xtag_rhs.length);
if (rv == Bry_find_.Not_found) {ctx.App().Usr_dlg().Warn_many("", "", "parser.xtn: could not find end: page=~{0}", ctx.Cur_page().Url().To_str()); return Bry_find_.Not_found;}
rv = Bry_find_.Find_bwd(src, Byte_ascii.Lt, rv - 1);
if (rv == Bry_find_.Not_found) {ctx.App().Usr_dlg().Warn_many("", "", "parser.xtn: could not find <: page=~{0}", ctx.Cur_page().Url().To_str()); return Bry_find_.Not_found;}
return rv;
&& Bry_.Eq(src, tag_bgn, tag_bgn, Pfunc_tag.Xtag_bgn_lhs)) // xtn created by tag
return Xop_xnde_wkr_.Find_xtag_end(ctx, src, open_end, src_len);
else // search rest of String for case-insensitive name; NOTE: used to do CS first, then fall-back on CI; DATE:2013-12-02
return Xop_xnde_wkr_.Find_xtn_end(ctx, src, open_end, src_len, close_bry);
}
private int Make_xnde_xtn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, Xop_xnde_tag tag, int open_bgn, int open_end, int name_bgn, int name_end, int atrs_bgn, int atrs_end, Mwh_atr_itm[] atrs, boolean inline, boolean pre2_hack) {
// NOTE: find end_tag that exactly matches bgnTag; must be case sensitive;
@@ -704,7 +683,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
}
}
return xnde_end;
} private Btrie_slim_mgr xtn_end_tag_trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; listed XML node names are en
}
private Xop_xnde_tkn New_xnde_pair(Xop_ctx ctx, Xop_root_tkn root, Xop_tkn_mkr tkn_mkr, Xop_xnde_tag tag, int open_bgn, int open_end, int close_bgn, int close_end) {
Xop_xnde_tkn rv = tkn_mkr.Xnde(open_bgn, close_end).Tag_(tag).Tag_open_rng_(open_bgn, open_end).Tag_close_rng_(close_bgn, close_end).CloseMode_(Xop_xnde_tkn.CloseMode_pair);
int name_bgn = open_bgn + 1;
@@ -736,20 +715,6 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
}
public static Xop_log_basic_wkr Timeline_log_wkr = Xop_log_basic_wkr.Null;
}
class Xop_xnde_wkr_ {
public static void AutoClose_handle_dangling_nde_in_caption(Xop_root_tkn root, Xop_tkn_itm owner) {
int subs_bgn = -1, subs_len = owner.Subs_len();
for (int i = 0; i < subs_len; i++) {
Xop_tkn_itm sub_itm = owner.Subs_get(i);
if (sub_itm.Tkn_tid() == Xop_tkn_itm_.Tid_pipe) { // tkn is "|"; assume that caption should end here
subs_bgn = i;
break;
}
}
if (subs_bgn != -1)
root.Subs_move(owner, subs_bgn, subs_len); // move everything after "|" back to root
}
}
/*
NOTE_1: special logic for <*include*>
cannot process like regular xnde tag b/c cannot auto-close tags on tmpl

View File

@@ -0,0 +1,66 @@
/*
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.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.xowa.xtns.pfuncs.strings.*;
class Xop_xnde_wkr_ {
private static final Btrie_slim_mgr xtn_end_tag_trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; listed XML node names are en
private static final int Find_xtn_end__tid__end = 0, Find_xtn_end__tid__xtag = 1;
private static final Int_obj_ref Find_xtn_end__key__end = Int_obj_ref.new_(Find_xtn_end__tid__end), Find_xtn_end__key__xtag = Int_obj_ref.new_(Find_xtn_end__tid__xtag);
private static final Bry_bfr Find_xtag_end__bfr = Bry_bfr.new_(32);
public static void AutoClose_handle_dangling_nde_in_caption(Xop_root_tkn root, Xop_tkn_itm owner) {
int subs_bgn = -1, subs_len = owner.Subs_len();
for (int i = 0; i < subs_len; i++) {
Xop_tkn_itm sub_itm = owner.Subs_get(i);
if (sub_itm.Tkn_tid() == Xop_tkn_itm_.Tid_pipe) { // tkn is "|"; assume that caption should end here
subs_bgn = i;
break;
}
}
if (subs_bgn != -1)
root.Subs_move(owner, subs_bgn, subs_len); // move everything after "|" back to root
}
public static int Find_xtn_end(Xop_ctx ctx, byte[] src, int open_end, int src_end, byte[] close_bry) {
xtn_end_tag_trie.Clear();
xtn_end_tag_trie.Add_obj(Pfunc_tag.Xtag_bgn_lhs, Find_xtn_end__key__xtag);
xtn_end_tag_trie.Add_obj(close_bry, Find_xtn_end__key__end);
for (int i = open_end; i < src_end; ++i) {
Object o = xtn_end_tag_trie.Match_bgn(src, i, src_end);
if (o != null) {
int tid = ((Int_obj_ref)o).Val();
if (tid == Find_xtn_end__tid__end) // xtn_end found; use it
return i;
else { // xtag found; skip over it; PAGE:it.s:La_Secchia_rapita/Canto_primo DATE:2015-12-03
int xtag_end = Find_xtag_end(ctx, src, i, src_end);
int angle_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, xtag_end, src_end);
i = angle_end;
}
}
}
return Bry_find_.Not_found;
}
public static int Find_xtag_end(Xop_ctx ctx, byte[] src, int pos, int src_end) {
int xtag_bgn = pos + Pfunc_tag.Xtag_bgn_lhs.length;
int tag_id = Bry_.To_int_or(src, xtag_bgn, xtag_bgn + Pfunc_tag.Id_len, -1); if (tag_id == -1) {Xoa_app_.Usr_dlg().Warn_many("", "", "parser.xtn: could not extract id from xtag_bgn: page=~{0}", ctx.Cur_page().Url().To_str()); return Bry_find_.Not_found;}
Find_xtag_end__bfr.Add(Pfunc_tag.Xtag_end_lhs).Add_int_pad_bgn(Byte_ascii.Num_0, Pfunc_tag.Id_len, tag_id).Add(Pfunc_tag.Xtag_rhs);
byte[] tag_end = Find_xtag_end__bfr.To_bry_and_clear();
int rv = Bry_find_.Find_fwd(src, tag_end, pos + Pfunc_tag.Xtag_rhs.length); if (rv == Bry_find_.Not_found) {ctx.App().Usr_dlg().Warn_many("", "", "parser.xtn: could not find xtag end: page=~{0}", ctx.Cur_page().Url().To_str()); return Bry_find_.Not_found;}
rv = Bry_find_.Find_bwd(src, Byte_ascii.Lt, rv - 1); if (rv == Bry_find_.Not_found) {ctx.App().Usr_dlg().Warn_many("", "", "parser.xtn: could not find <: page=~{0}", ctx.Cur_page().Url().To_str()); return Bry_find_.Not_found;}
return rv;
}
}