1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2016-01-03 21:27:38 -05:00
parent 9509363f46
commit 096045614c
647 changed files with 11693 additions and 7648 deletions

View File

@@ -36,7 +36,7 @@ public class Xoa_parser_mgr {
// int angle_bgn_pos = Bry_find_.Find_fwd(src, Byte_ascii.Angle_bgn, src_bgn, src_end);
// if (angle_bgn_pos != Bry_find_.Not_found) {
// src = Bry_.Mid(src, src_bgn, src_end);
// src = Bry_.Replace(src, Byte_ascii.Angle_bgn_bry, gplx.langs.htmls.Html_entity_.Lt_bry);
// src = Bry_.Replace(src, Byte_ascii.Angle_bgn_bry, gplx.langs.htmls.Gfh_entity_.Lt_bry);
// src_bgn = 0;
// src_end = src.length;
// }

View File

@@ -45,7 +45,7 @@ public class Xop_parser__tst {
}
}
class Xop_parser__fxt {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
private Bry_bfr bfr = Bry_bfr.reset_(255);
public void Clear() {
fxt.Reset();

View File

@@ -17,7 +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.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.*;
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.cites.*;
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

@@ -44,10 +44,10 @@ public class Xop_amp_trie_itm {
}
public void Print_literal(Bry_bfr bfr) {
switch (char_int) {
case Byte_ascii.Lt: bfr.Add(Html_entity_.Lt_bry); break; // NOTE: never write actual char; EX: "&lt;" should be written as "&lt;", not "<"; MW does same; DATE:2014-11-07
case Byte_ascii.Gt: bfr.Add(Html_entity_.Gt_bry); break;
case Byte_ascii.Quote: bfr.Add(Html_entity_.Quote_bry); break;
case Byte_ascii.Amp: bfr.Add(Html_entity_.Amp_bry); break;
case Byte_ascii.Lt: bfr.Add(Gfh_entity_.Lt_bry); break; // NOTE: never write actual char; EX: "&lt;" should be written as "&lt;", not "<"; MW does same; DATE:2014-11-07
case Byte_ascii.Gt: bfr.Add(Gfh_entity_.Gt_bry); break;
case Byte_ascii.Quote: bfr.Add(Gfh_entity_.Quote_bry); break;
case Byte_ascii.Amp: bfr.Add(Gfh_entity_.Amp_bry); break;
default:
bfr.Add(u8_bry); // write literal; EX: "[" not "&#91;"
break;

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_amp_wkr_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Name() {fxt.Test_parse_page_wiki("&amp;" , fxt.tkn_html_ref_("&amp;"));} // check for html_ref
@Test public void Name_fail() {fxt.Test_parse_page_wiki("&nil;" , fxt.tkn_txt_(0, 5));} // check for text
@Test public void Hex() {fxt.Test_parse_page_wiki("&#x3A3;" , fxt.tkn_html_ncr_(931));} // check for html_ncr; Σ: http://en.wikipedia.org/wiki/Numeric_character_reference
@@ -29,7 +29,7 @@ public class Xop_amp_wkr_tst {
@Test public void Defect_bad_code_fails() { // PURPOSE: early rewrite of Xop_amp_mgr caused Xoh_html_wtr_escaper to fail with array out of bounds error; EX:w:Czech_Republic; DATE:2014-05-11
fxt.Test_parse_page_wiki_str
( "[[File:A.png|alt=<p>&#10;</p>]]" // basically checks amp parsing inside xnde inside lnki's alt (which uses different parsing code
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"&#10;\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"&#10;\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
);
}
@Test public void Ignore_ncr() { // PURPOSE: check that ncr is unescaped; PAGE:de.w:Cross-Site-Scripting; DATE:2014-07-23

View File

@@ -19,7 +19,7 @@ package gplx.xowa.parsers.apos; import gplx.*; import gplx.xowa.*; import gplx.x
import org.junit.*;
import gplx.xowa.parsers.lists.*;
public class Xop_apos_wkr_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_wiki("''a''" , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn) , fxt.tkn_txt_(2, 3), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end));
fxt.Test_parse_page_wiki("'''a'''" , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn) , fxt.tkn_txt_(3, 4), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end));

View File

@@ -18,7 +18,7 @@ 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__basic_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void H2() {fxt.Test_parse_page_wiki_str("==a==" , "<h2>a</h2>\n");}
@Test public void H3() {fxt.Test_parse_page_wiki_str("===a===" , "<h3>a</h3>\n");}

View File

@@ -18,7 +18,7 @@ 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__para_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Hdr_at_bos() { // PURPOSE: check that BOS==a== does not throw null ref in para; DATE:2014-02-18
fxt.Test_parse_page_all_str("==a==", "<h2>a</h2>\n");

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_list_wkr_basic_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void List_1() {
fxt.Test_parse_page_wiki("\n*a"

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_list_wkr_para_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_list_wkr_uncommon_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Bug_specified_div() { // FIX: </div> was not clearing state for lnki; PAGE:en.w:Ananke (moon)
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last

View File

@@ -18,7 +18,7 @@ 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.*; import gplx.xowa.parsers.xndes.*;
public class Xop_lnke_wkr_brack_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Brace_noText() {
fxt.Test_parse_page_wiki("[irc://a]", fxt.tkn_lnke_(0, 9).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack).Lnke_rng_(1, 8));
}

View File

@@ -18,7 +18,7 @@ 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 Xop_lnke_wkr_dangling_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Dangling_eos() {
fxt.Test_parse_page_wiki("[irc://a b"
, fxt.tkn_lnke_(0, 8).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack_dangling)

View File

@@ -18,7 +18,7 @@ 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 Xop_lnke_wkr_relative_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Relative_obj() {
fxt.Test_parse_page_wiki("[//a b]"
, fxt.tkn_lnke_(0, 7).Lnke_rng_(1, 4).Subs_(fxt.tkn_txt_(5, 6))

View File

@@ -18,7 +18,7 @@ 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.*; import gplx.xowa.langs.cases.*;
public class Xop_lnke_wkr_text_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Text_obj() {
fxt.Test_parse_page_wiki("irc://a", fxt.tkn_lnke_(0, 7).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_text).Lnke_rng_(0, 7));
}

View File

@@ -18,7 +18,7 @@ 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 Xop_lnke_wkr_uncommon_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Err_multiple() {
fxt.Test_parse_page_wiki("[irc://a][irc://b]"
, fxt.tkn_lnke_(0, 9)

View File

@@ -18,7 +18,7 @@ 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 Xop_lnke_wkr_xwiki_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Xwiki() {
fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org"));
fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/wiki/A a]", "<a href='/site/en.wikipedia.org/wiki/A'>a</a>");

View File

@@ -51,7 +51,7 @@ public class Xop_link_parser {
html_anchor_rel = domain_itm.Domain_type().Tid() == Xow_domain_tid_.Int__other ? Xoh_lnki_consts.Tid_a_rel_nofollow : Xoh_lnki_consts.Tid_a_rel_none; // rel=nofollow if not WM wiki; DATE:2015-11-19
break;
case Gfo_protocol_itm.Tid_file: // "file:///" or "File:A.png"
int proto_len = tmp_url.Protocol_bry().length;
int proto_len = Gfo_protocol_itm.Bry_file.length; // "file:"
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_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)
@@ -80,14 +80,14 @@ public class Xop_link_parser {
boolean page_ttl_is_valid = page_ttl != null;
if (page_ttl_is_valid) {
Xow_xwiki_itm xwiki_itm = page_ttl.Wik_itm();
if (xwiki_itm != null) { // is alias; set wiki, page
if (xwiki_itm != null) { // is alias; set wiki, page
wiki_bry = xwiki_itm.Domain_bry();
page_bry = Bry_.Mid(page_bry, xwiki_itm.Key_bry().length + 1, page_bry.length); // +1 for ":"
}
else // is regular page; use ttl.Full_db() to normalize; EX: &nbsp; -> _
page_bry = page_ttl.Full_db();
else // is regular page; use ttl.Full_db() to normalize; EX: &nbsp; -> _
page_bry = page_ttl.Full_db_w_anch(); // add anch; PAGE:en.w:History_of_Nauru; DATE:2015-12-27
}
if (Bry_.Eq(wiki_bry, wiki.Domain_bry())) // NOTE: check against wiki.Key_bry() again; EX: in en_wiki, and http://commons.wikimedia.org/wiki/w:A
if (Bry_.Eq(wiki_bry, wiki.Domain_bry())) // NOTE: check against wiki.Key_bry() again; EX: in en_wiki, and http://commons.wikimedia.org/wiki/w:A
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(page_bry);
else
tmp_bfr.Add(Xoh_href_.Bry__site).Add(wiki_bry).Add(Xoh_href_.Bry__wiki).Add(page_bry);

View File

@@ -30,6 +30,16 @@ public class Xop_lnki_type {
default: throw Err_.new_unhandled(flag);
}
}
public static byte To_flag(byte tid) {
switch (tid) {
case Xop_lnki_type.Tid_null: return Xop_lnki_type.Id_null;
case Xop_lnki_type.Tid_none: return Xop_lnki_type.Id_none;
case Xop_lnki_type.Tid_frameless: return Xop_lnki_type.Id_frameless;
case Xop_lnki_type.Tid_frame: return Xop_lnki_type.Id_frame;
case Xop_lnki_type.Tid_thumb: return Xop_lnki_type.Id_thumb;
default: throw Err_.new_unhandled(tid);
}
}
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

@@ -46,6 +46,8 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
Xop_lnki_tkn lnki = (Xop_lnki_tkn)ctx.Stack_pop_til(root, src, stack_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_lnki_end);
if (!arg_bldr.Bld(ctx, tkn_mkr, this, Xop_arg_wkr_.Typ_lnki, root, lnki, bgn_pos, cur_pos, lnki.Tkn_sub_idx() + 1, root.Subs_len(), src))
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
if (lnki.Ns_id() != Xow_ns_.Tid__main && Bry_.Len_eq_0(lnki.Ttl().Page_txt())) // handle anchor-only pages; EX:[[File:#A]] PAGE:en.w:Spindale,_North_Carolina; DATE:2015-12-28
return Xop_lnki_wkr_.Invalidate_lnki(ctx, src, root, lnki, bgn_pos);
if (Xop_lnki_wkr_.Adjust_for_brack_end_len_of_3(ctx, tkn_mkr, root, src, src_len, cur_pos, lnki)) // convert "]]]" into "]" + "]]", not "]]" + "]"
++cur_pos; // position "]]" at end of "]]]"
cur_pos = Xop_lnki_wkr_.Chk_for_tail(ctx.Lang(), src, cur_pos, src_len, lnki);

View File

@@ -21,7 +21,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*; import gplx.xowa.langs
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.paras.*; import gplx.xowa.wikis.ttls.*;
public class Xop_lnki_wkr__basic_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_wiki("[[a]]", fxt.tkn_lnki_().Trg_tkn_(fxt.tkn_arg_val_txt_(2, 3)));
}
@@ -210,14 +210,9 @@ public class Xop_lnki_wkr__basic_tst {
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">"
, " <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/220px.png\" width=\"0\" height=\"0\" /></a>"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/220px.png\" width=\"0\" height=\"0\" /></a>"
, " <div class=\"thumbcaption\">"
, " <div class=\"magnify\">"
, " <a href=\"/wiki/File:A.png\" class=\"inte" +"rnal\" title=\"Enlarge\">"
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
, " </a>"
, " </div>"
, " b <sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"inte" +"rnal\" title=\"Enlarge\"></a></div>b <sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, " </div>"
, " </div>"
, "</div>"
@@ -265,24 +260,24 @@ 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/%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>");
, "<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=\"xoimg_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
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>"
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_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>"
( "<a href=\"/wiki/B_c\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_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>"
( "<a href=\"/wiki/File:A_b_%C3%A7.ogg\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_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

View File

@@ -19,7 +19,7 @@ package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.
import org.junit.*;
import gplx.xowa.langs.cases.*;
public class Xop_lnki_wkr__ctg_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Pre() { // PURPOSE: Category should trim preceding nl; EX:w:Mount Kailash
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last

View File

@@ -19,7 +19,7 @@ package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.
import org.junit.*;
import gplx.xowa.langs.cases.*; import gplx.xowa.wikis.ttls.*;
public class Xop_lnki_wkr__invalid_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Ignore_invalid_url_encodings() { // PURPOSE: if url encoding is invalid, still render lnki as <a>; EX: fr.w:Bordetella;
fxt.Test_parse_page_all_str("[[%GC]]", "<a href=\"/wiki/%25GC\">%GC</a>");
}
@@ -90,5 +90,8 @@ public class Xop_lnki_wkr__invalid_tst {
// fxt.Init_defn_add("a", "b");
// fxt.Test_parse_page_all_str("{{a|[[}}", "b");
// }
@Test public void Ns_is_not_main_and_starts_with_anchor() { // PURPOSE:page cannot start with # if non-main ns; PAGE:en.w:Spindale,_North_Carolina; DATE:2015-12-28
fxt.Test_parse_page_all_str("[[File:#A]]" , "[[File:#A]]");
}
}

View File

@@ -19,88 +19,88 @@ package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.
import org.junit.*;
import gplx.xowa.langs.cases.*;
public class Xop_lnki_wkr__link_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Link() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=File:B.png|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/File: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>"
( "<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_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_blank() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=|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>"
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_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_external() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=http://www.b.org|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"http://www.b.org\" rel=\"nofollow\" 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>"
( "<a href=\"http://www.b.org\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xoimg_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_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=\"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>"
( "<a href=\"file:///C/B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xoimg_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() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=File:B.png|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/File: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>"
( "<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_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_external_relative() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=//fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"https://fr.wikipedia.org/wiki/\" 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>"
( "<a href=\"https://fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_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_external_absolute() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=http://fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"http://fr.wikipedia.org/wiki/\" 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>"
( "<a href=\"http://fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_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_external_double_http() {// PURPOSE.fix: link=http://a.org?b=http://c.org breaks lnki; DATE:2013-02-03
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=//a.org?b=http://c.org]]", String_.Concat_lines_nl_skip_last
( "<a href=\"https://a.org?b=http://c.org\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
( "<a href=\"https://a.org?b=http://c.org\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@Test public void Link_xwiki_relative() { // NOTE: changed href to return "wiki/" instead of "wiki"; DATE:2013-02-18
fxt.Init_xwiki_add_user_("fr.wikipedia.org");
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=//fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/fr.wikipedia.org/wiki/\" 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>"
( "<a href=\"/site/fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_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_xwiki_relative_domain_only() { // lnki_wtr fails if link is only domain; EX: wikimediafoundation.org; [[Image:Wikispecies-logo.png|35px|link=//species.wikimedia.org]]; // NOTE: changed href to return "/wiki/" instead of ""; DATE:2013-02-18
fxt.Init_xwiki_add_user_("fr.wikipedia.org");
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=//fr.wikipedia.org]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
( "<a href=\"/site/fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@Test public void Link_xwiki_absolute() { // NOTE: changed href to return "wiki/" instead of "wiki"; DATE:2013-02-18
fxt.Init_xwiki_add_user_("fr.wikipedia.org");
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=http://fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/fr.wikipedia.org/wiki/\" 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>"
( "<a href=\"/site/fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_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_xwiki_absolute_upload() { // PURPOSE: link to upload.wikimedia.org omits /wiki/; EX: wikimediafoundation.org: [[File:Page1-250px-WMF_AR11_SHIP_spreads_15dec11_72dpi.png|right|125px|border|20102011 Annual Report|link=https://upload.wikimedia.org/wikipedia/commons/4/48/WMF_AR11_SHIP_spreads_15dec11_72dpi.pdf]]
fxt.Init_xwiki_add_user_("commons.wikimedia.org");
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=http://upload.wikimedia.org/wikipedia/commons/7/70/A.png|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/commons.wikimedia.org/wiki/File:A.png\" 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>"
( "<a href=\"/site/commons.wikimedia.org/wiki/File:A.png\" xowa_title=\"A.png\"><img id=\"xoimg_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_xwiki_relative_deep() {
fxt.Init_xwiki_add_user_("fr.wikipedia.org");
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=//fr.wikipedia.org/wiki/A/b|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/fr.wikipedia.org/wiki/A/b\" 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>"
( "<a href=\"/site/fr.wikipedia.org/wiki/A/b\" xowa_title=\"A.png\"><img id=\"xoimg_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_xwiki_alias() { // [[File:Commons-logo.svg|25x25px|link=http://en.wikipedia.org/wiki/commons:Special:Search/Earth|alt=|Search Commons]]
@@ -108,7 +108,7 @@ public class Xop_lnki_wkr__link_tst {
fxt.Init_xwiki_add_wiki_and_user_("en.wikipedia.org", "en.wikipedia.org"); // DATE:2015-07-22
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=http://en.wikipedia.org/wiki/commons:B|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/commons.wikimedia.org/wiki/B\" 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>"
( "<a href=\"/site/commons.wikimedia.org/wiki/B\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
fxt.Init_xwiki_clear();
}
@@ -117,7 +117,7 @@ public class Xop_lnki_wkr__link_tst {
fxt.Init_xwiki_add_wiki_and_user_("en.wikipedia.org", "en.wikipedia.org"); // DATE:2015-07-22
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=http://en.wikipedia.org/wiki/commons:Special:Search/B|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/commons.wikimedia.org/wiki/Special:Search/B\" 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>"
( "<a href=\"/site/commons.wikimedia.org/wiki/Special:Search/B\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
fxt.Init_xwiki_clear();
}
@@ -125,7 +125,7 @@ public class Xop_lnki_wkr__link_tst {
fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org");
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=commons:Special:Search/B|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/commons.wikimedia.org/wiki/Special:Search/B\" 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>"
( "<a href=\"/site/commons.wikimedia.org/wiki/Special:Search/B\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
fxt.Init_xwiki_clear();
}
@@ -133,14 +133,20 @@ public class Xop_lnki_wkr__link_tst {
fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org");
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=:commons:A/B|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/commons.wikimedia.org/wiki/A/B\" 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>"
( "<a href=\"/site/commons.wikimedia.org/wiki/A/B\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
fxt.Init_xwiki_clear();
}
@Test public void Encode() {// PURPOSE: encode invalid characters in link; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan DATE:2014-07-16
fxt.Test_parse_page_wiki_str
( "[[File:A.png|link=//b?c\">|d]]"
, "<a href=\"https://b?c%22%3E\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"d\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
, "<a href=\"https://b?c%22%3E\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"d\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
);
}
@Test public void Anchor() {// PURPOSE: handle anchors; PAGE:en.w: en.w:History_of_Nauru; DATE:2015-12-27
fxt.Test_parse_page_wiki_str
( "[[File:A.png|link=#b]]"
, "<a href=\"/wiki/Test_page#b\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
);
}
}

View File

@@ -19,91 +19,86 @@ package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.
import org.junit.*;
import gplx.xowa.langs.cases.*;
public class Xop_lnki_wkr__pre_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Previous_pre() { // PURPOSE: if pre is already in effect, end it; EX: en.b:Knowing_Knoppix/Other_applications
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "a"
, " b"
, "[[File:A.png|thumb]]"
, "c"
( "a"
, " b"
, "[[File:A.png|thumb]]"
, "c"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, ""
, "<pre>b" // NOTE: pre is ended; " b\n[[" -> <pre>b</pre><div>"
, "</pre>"
, ""
, "</p>"
, ""
, "<pre>b" // NOTE: pre is ended; " b\n[[" -> <pre>b</pre><div>"
, "</pre>"
, ""
, Html_A_png
, ""
, "<p>c"
, "</p>"
, ""
, ""
, "<p>c"
, "</p>"
, ""
));
}
@Test public void Current_pre_and_thumb() { // PURPOSE: current pre should be ended by thumb; EX: w:Roller coaster; it.w:Provincia_di_Pesaro_e_Urbino; DATE:2014-02-17
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "a"
, " [[File:A.png|thumb]]"
, "b"
( "a"
, " [[File:A.png|thumb]]"
, "b"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, "" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19
, "</p>"
, "" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19
, Html_A_png
, ""
, "<p>b"
, "</p>"
, ""
, ""
, "<p>b"
, "</p>"
, ""
));
}
@Test public void Current_pre_and_halign() { // PURPOSE: current pre should be ended by halign since they also produce divs; EX: w:Trombiculidae; DATE:2014-02-17
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "a"
, " [[File:A.png|right]]"
, "b"
( "a"
, " [[File:A.png|right]]"
, "b"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, "<div class=\"floatright\">" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19
, "<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/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a></div>"
, ""
, "<p>b"
, "</p>"
, ""
, "</p>"
, "<div class=\"floatright\">" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a></div>"
, ""
, "<p>b"
, "</p>"
, ""
));
}
@Test public void Current_pre() { // PURPOSE: current pre should exist if not div; DATE:2014-02-17
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "a"
, " [[File:A.png]]"
, "b"
( "a"
, " [[File:A.png]]"
, "b"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, ""
, "<pre> <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/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>" // NOTE: capture " "; confirmed against MW; DATE:2014-04-14
, "</pre>"
, ""
, "<p>b"
, "</p>"
, ""
, "</p>"
, ""
, "<pre> <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>" // NOTE: capture " "; confirmed against MW; DATE:2014-04-14
, "</pre>"
, ""
, "<p>b"
, "</p>"
, ""
));
}
private static final String Html_A_png = String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">"
, " <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/220px.png\" width=\"0\" height=\"0\" /></a>"
, " <div class=\"thumbcaption\">"
, " <div class=\"magnify\">"
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
, " </a>"
, " </div>"
, " "
, " </div>"
, " </div>"
, "</div>"
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/220px.png\" width=\"0\" height=\"0\" /></a>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>"
, " </div>"
, " </div>"
, "</div>"
);
}

View File

@@ -18,7 +18,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 org.junit.*; import gplx.xowa.wikis.nss.*;
public class Xop_lnki_wkr__subpage_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Disabled() { // PURPOSE: slash being interpreted as subpage; PAGE:en.w:[[/dev/null]]
fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(false);
fxt.Test_parse_page_all_str("[[/dev/null]]", "<a href=\"/wiki//dev/null\">/dev/null</a>");

View File

@@ -19,7 +19,7 @@ package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.
import org.junit.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*;
public class Xop_lnki_wkr__uncommon_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Double_bracket() { // PURPOSE: handle [[[[A]]]] constructions; PAGE:ru.w:Меркатале_ин_Валь_ди_Песа; DATE:2014-02-04
fxt.Test_parse_page_all_str("[[[[Test_1]]]]" , "[[<a href=\"/wiki/Test_1\">Test_1</a>]]");
}
@@ -32,14 +32,14 @@ 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\" 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>"
, "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\"><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_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
fxt.Test_parse_page_all_str("[[A|B|C|D]]" , "<a href=\"/wiki/A\">B|C|D</a>");
}
@Test public void Multiple_captions_file() { // PURPOSE: multiple captions should take last; EX:none; DATE:2014-05-05
fxt.Test_html_wiki_frag("[[File:A|B|C|D|thumb]]" , "</div>\n D\n </div>");
fxt.Test_html_wiki_frag("[[File:A|B|C|D|thumb]]" , "</div>D\n </div>");
}
@Test public void Multiple_captions_pipe() { // PURPOSE.fix: multiple captions caused multiple pipes; PAGE:w:Wikipedia:Administrators'_noticeboard/IncidentArchive24; DATE:2014-06-08
fxt.Test_parse_page_all_str("[[a|b|c d e]]", "<a href=\"/wiki/A\">b|c d e</a>"); // was b|c| |d| |e

View File

@@ -18,7 +18,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 org.junit.*; import gplx.xowa.files.*;
public class Xop_lnki_wkr__video_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Thumbtime() {
fxt.Test_parse_page_wiki("[[File:A.ogv|thumbtime=123]]" , fxt.tkn_lnki_().Thumbtime_(123));
fxt.Test_parse_page_wiki("[[File:A.ogv|thumbtime=1:23]]" , fxt.tkn_lnki_().Thumbtime_(83));

View File

@@ -24,7 +24,7 @@ public class Xop_lnki_wkr__xwiki_tst {
fxt.Wiki().Cfg_parser().Lnki_cfg().Xwiki_repo_mgr().Add_or_mod(Bry_.new_a7("test")); // must add to xwiki_repo_mgr
fxt.Test_parse_page_wiki_str
( "[[test:File:A.png|12x10px]]", 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=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
fxt.Wiki().Cfg_parser_lnki_xwiki_repos_enabled_(false); // disable for other tests
}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_comm_lxr_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("a<!-- b -->c", "ac");
}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_hr_lxr_basic_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {fxt.Test_parse_page_wiki("----" , fxt.tkn_hr_(0, 4));}
@Test public void Basic_w_nl() {fxt.Test_parse_page_wiki("\n----a" , fxt.tkn_para_blank_(0), fxt.tkn_hr_(0, 5), fxt.tkn_txt_(5, 6));}
@Test public void Many() {fxt.Test_parse_page_wiki("---------" , fxt.tkn_hr_(0, 9).Hr_len_(9));}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_hr_lxr_para_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Bos() { // PURPOSE: check that bos rendered correctly; DATE:2014-04-18
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "----"

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_space_lxr_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@After public void term() {fxt.Init_para_n_();}
@Test public void Toc_basic() { // PURPOSE: make sure nbsp char is not converted to space; PAGE:en.w:MacedonianCarthaginian_Treaty; DATE:2014-06-07

View File

@@ -18,7 +18,7 @@ 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 org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
public class Xop_under_lxr_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@After public void term() {fxt.Init_para_n_();}
@Test public void Toc_basic() {

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.mws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public class Xomw_parser_ctx {
public static final int Pos__bos = -1;
}

View File

@@ -0,0 +1,82 @@
/*
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.mws.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.mws.*;
import gplx.core.btries.*; import gplx.xowa.langs.*;
public class Xomw_hdr_wkr {
public void Parse(Bry_bfr bfr, Xomw_parser_ctx pctx, byte[] src, int src_bgn, int src_end) { // REF.MW: /includes/parser/Parser.php|doHeadings
int pos = src_bgn;
int txt_bgn = pos == Xomw_parser_ctx.Pos__bos ? 0 : pos;
byte b = Byte_ascii.Nl;
while (true) {
int nxt = pos + 1;
if ( b == Byte_ascii.Nl
&& nxt < src_end
&& src[nxt] == Byte_ascii.Eq
) { // if \n, check if "="
int rv = Parse_hdr_nl(bfr, pctx, src, src_bgn, src_end, txt_bgn, pos, nxt + 1);
if (rv < 0) {
pos = rv * -1;
}
else
pos = txt_bgn = rv;
}
else
++pos;
if (pos == src_end) {
if (txt_bgn != src_end) // PERF: don't call Add_mid() if hdr is at end of EOS
bfr.Add_mid(src, txt_bgn, src_end);
break;
}
b = src[pos];
}
}
private int Parse_hdr_nl(Bry_bfr bfr, Xomw_parser_ctx pctx, byte[] src, int src_bgn, int src_end, int txt_bgn, int nl_lhs, int pos) {
// calc pos and len
int hdr_lhs_bgn = nl_lhs + 1;
int hdr_lhs_end = Bry_find_.Find_fwd_while(src, pos, src_end, Byte_ascii.Eq);
int nl_rhs = Bry_find_.Find_fwd_or(src, Byte_ascii.Nl, hdr_lhs_end + 1, src_end, src_end); // no "\n"; src_end is rest of text; EX: "\n==<text>EOS
int hdr_rhs_end = Bry_find_.Find_bwd__skip_ws(src, nl_rhs, hdr_lhs_end);
int hdr_rhs_bgn = Bry_find_.Find_bwd__skip(src, hdr_rhs_end - 1, hdr_lhs_end, Byte_ascii.Eq);
int hdr_lhs_len = hdr_lhs_end - hdr_lhs_bgn;
int hdr_rhs_len = hdr_rhs_end - hdr_rhs_bgn;
if (hdr_rhs_len == 0) { // handle rare situations like "\n====\n"
int hdr_lhs_len_half = hdr_lhs_len / 2;
hdr_rhs_len = hdr_lhs_len - hdr_lhs_len_half;
hdr_lhs_len = hdr_lhs_len_half;
hdr_lhs_end = hdr_lhs_bgn + hdr_lhs_len;
hdr_rhs_bgn = hdr_lhs_end;
}
// bld bry
int hdr_len = hdr_lhs_len < hdr_rhs_len ? hdr_lhs_len : hdr_rhs_len;
if (nl_lhs > txt_bgn)
bfr.Add_mid(src, txt_bgn, nl_lhs); // add all txt up to nl_lhs
if (nl_lhs != Xomw_parser_ctx.Pos__bos) bfr.Add_byte_nl();
bfr.Add(Tag__lhs).Add_int_digits(1, hdr_len).Add(Byte_ascii.Angle_end_bry); // <h2>
bfr.Add_mid(src, hdr_lhs_end, hdr_rhs_bgn);
bfr.Add(Tag__rhs).Add_int_digits(1, hdr_len).Add(Byte_ascii.Angle_end_bry); // </h2>
return nl_rhs;
}
private static final byte[]
Tag__lhs = Bry_.new_a7("<h")
, Tag__rhs = Bry_.new_a7("</h")
;
}
// for ( $i = 6; $i >= 1; --$i ) {
// $h = str_repeat( '=', $i );
// $text = preg_replace( "/^$h(.+)$h\\s*$/m", "<h$i>\\1</h$i>", $text );
// }

View File

@@ -0,0 +1,39 @@
/*
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.mws.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.mws.*;
import org.junit.*;
public class Xomw_hdr_wkr_tst {
private final Xomw_hdr_wkr_fxt fxt = new Xomw_hdr_wkr_fxt();
@Test public void Basic() {
fxt.Test__parse("==A==" , "<h2>A</h2>");
fxt.Test__parse("abc\n==A==\ndef" , "abc\n<h2>A</h2>\ndef");
fxt.Test__parse("abc" , "abc");
fxt.Test__parse("abc\ndef" , "abc\ndef");
fxt.Test__parse("abc\n==" , "abc\n<h1></h1>");
}
}
class Xomw_hdr_wkr_fxt {
private final Xomw_hdr_wkr wkr = new Xomw_hdr_wkr();
private final Bry_bfr bfr = Bry_bfr.new_(); private final Xomw_parser_ctx pctx = new Xomw_parser_ctx();
public void Test__parse(String src_str, String expd) {
byte[] src_bry = Bry_.new_u8(src_str);
wkr.Parse(bfr, pctx, src_bry, -1, src_bry.length);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear(), src_str);
}
}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_nl_tab_lxr_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void teardown() {fxt.Init_para_n_();}
@Test public void Basic() { // PURPOSE: \n\t|- should be recognized as tblw; EX:zh.v:西安; DATE:2014-05-06
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl

View File

@@ -38,14 +38,14 @@ public class Xop_para_tkn extends Xop_tkn_itm_base {
}
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>'
case Xop_para_tkn.Tid_para: bfr.Add(Gfh_tag_.P_rhs).Add_byte_nl(); break; // '<p>'
case Xop_para_tkn.Tid_pre: bfr.Add(Gfh_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>'
case Xop_para_tkn.Tid_para: Xoh_html_wtr_.Para__assert_tag_starts_on_nl(bfr, this.Src_bgn()); bfr.Add(Gfh_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(Gfh_tag_.Pre_lhs); break; // '</pre>'
default: throw Err_.new_unhandled(para_bgn);
}
if (space_bgn > 0)

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_para_wkr_para_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void teardown() {fxt.Init_para_n_();}
@Test public void Pre_then_xnde_pre() { // PURPOSE: if ws_pre is in effect, xnde_pre should end it; EX: b:Knowing Knoppix/Other applications
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_para_wkr_pre_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void teardown() {fxt.Init_para_n_();}
@Test public void Pre_ignore_bos() { // PURPOSE: ignore pre at bgn; DATE:2013-07-09
fxt.Test_parse_page_all_str(String_.Concat_lines_nl
@@ -68,11 +68,11 @@ public class Xop_para_wkr_pre_tst {
( "<p>a"
, "</p>"
, " <ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width: 155px\">"
, " <div style=\"width: 155px\">"
, " <div class=\"thumb\" style=\"width: 150px;\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:155px;\">"
, " <div style=\"width:155px;\">"
, " <div class=\"thumb\" style=\"width:150px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"A.png\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" /></a>"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"A.png\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\">"
@@ -94,11 +94,11 @@ public class Xop_para_wkr_pre_tst {
);
fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last
( " <ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">" // NOTE: leading " " matches MW; DATE:2014-06-23
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width: 155px\">"
, " <div style=\"width: 155px\">"
, " <div class=\"thumb\" style=\"width: 150px;\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:155px;\">"
, " <div style=\"width:155px;\">"
, " <div class=\"thumb\" style=\"width:150px;\">"
, " <div style=\"margin:15px auto;\">"
, " <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/120px.png\" width=\"120\" height=\"120\" /></a>"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p>b"

View File

@@ -26,7 +26,7 @@ public class Xop_pre_tkn extends Xop_tkn_itm_base {
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_bgn: bfr.Add(Gfh_tag_.Pre_lhs); break; // '<pre>'
case Xop_pre_tkn.Pre_tid_end: bfr.Add(Bry__pre__rhs); break; // '\n</pre>\n\n'
}
}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__atrs_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Tr() {
fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last
( "{|"

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__basic_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Td() { // Tb_tr_td_te
fxt.Test_parse_page_wiki("{|\n|-\n|a\n|}"
, fxt.tkn_tblw_tb_(0, 11).Subs_

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__dangling_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Dangling_tb_in_xnde() {// PURPOSE: dangling tblw incorrectly auto-closed by </xnde>; PAGE:en.w:Atlanta_Olympics; DATE:2014-03-18
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__double_pipe_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void No_tblw() { // PURPOSE: if || has no tblw, treat as lnki; none; DATE:2014-05-06
fxt.Test_parse_page_all_str("[[A||b|c]]", String_.Concat_lines_nl_skip_last
@@ -35,7 +35,7 @@ public class Xop_tblw_wkr__double_pipe_tst {
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td><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/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
, " <td><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
, " </td>"
, " </tr>"
, "</table>"

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__errs_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Err_row_empty() {
fxt.Test_parse_page_wiki("{|\n|-\n|-\n|a\n|}"
, fxt.tkn_tblw_tb_(0, 14).Subs_

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__nested_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last
( "{|"

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__para_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Para() { // PURPOSE: para causing strange breaks; SEE:[[John F. Kennedy]] and "two Supreme Court appointments"
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__tblx_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Ignore_td() { // PURPOSE: do not parse pipe as td if in <table>; EX:ru.w:Сочи; DATE:2014-02-22
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tblw_wkr__uncommon_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Tr_pops_entire_stack() { // PURPOSE: in strange cases, tr will pop entire stack; PAGE:en.w:Turks_in_Denmark; DATE:2014-03-02
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last

View File

@@ -32,8 +32,8 @@ public class Xop_tblw_ws_itm {
trie_itm(rv, Type_tr, Xop_tblw_lxr_ws.Hook_tr);
trie_itm(rv, Type_th, Xop_tblw_lxr_ws.Hook_th);
trie_itm(rv, Type_tc, Xop_tblw_lxr_ws.Hook_tc);
trie_itm(rv, Type_td, Bry_.new_bytes(Byte_ascii.Pipe));
trie_itm(rv, Type_nl, Bry_.new_bytes(Byte_ascii.Nl));
trie_itm(rv, Type_td, Byte_ascii.Pipe_bry);
trie_itm(rv, Type_nl, Byte_ascii.Nl_bry);
trie_itm_xnde(rv, Xop_xnde_tag_.Tag_table);
trie_itm_xnde(rv, Xop_xnde_tag_.Tag_tr);
trie_itm_xnde(rv, Xop_xnde_tag_.Tag_td);

View File

@@ -18,7 +18,7 @@ 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 org.junit.*; import gplx.xowa.wikis.ttls.*;
public class Xop_subst_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {
fxt.Reset();
fxt.Init_defn_clear();

View File

@@ -23,4 +23,5 @@ public class Xop_tkn_ {
, Anchor = new byte[] {Byte_ascii.Hash}
;
public static final int Lnki_bgn_len = 2, Lnki_end_len = 2;
public static final byte Anchor_byte = Byte_ascii.Hash;
}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_tkn_print_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Text() {tst_Print("a ''b'' c [[d]] e");}
@Test public void Prm() {tst_Print("{{{1}}}");}
@Test public void Prm_dflt() {tst_Print("{{{1|a}}}");}

View File

@@ -65,7 +65,7 @@ public class Xot_defn_tmpl implements Xot_defn {
if (root == null) Parse_tmpl(ctx);
Xoae_page page = ctx.Cur_page();
if (!page.Tmpl_stack_add(full_name)) {
bfr.Add_str_a7("<!-- template loop detected:" + gplx.langs.htmls.Html_utl.Escape_html_as_str(String_.new_u8(name)) + " -->");
bfr.Add_str_a7("<!-- template loop detected:" + gplx.langs.htmls.Gfh_utl.Escape_html_as_str(String_.new_u8(name)) + " -->");
Xoa_app_.Usr_dlg().Log_many("", "", "template loop detected: url=~{0} name=~{1}", ctx.Cur_page().Url().To_str(), name);
return false;
}

View File

@@ -30,7 +30,7 @@ public class Xot_defn_trace_brief_tst {
@Test public void Basic_a_b() {fxt.tst_("{{leaf_a}} {{leaf_b}}" , "0001 leaf_a", "0001 leaf_b");}
}
class Xot_defn_trace_fxt {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
public Xop_ctx Ctx() {return fxt.Ctx();}
public void Init_defn_clear() {fxt.Init_defn_clear();}
public void Init_defn_add(String name, String raw) {fxt.Init_defn_add(name, raw);}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xot_examples_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {
Io_mgr.Instance.InitEngine_mem();
fxt.Reset();

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xot_invk_sandbox_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {
fxt.Reset();
fxt.Init_defn_clear();

View File

@@ -312,7 +312,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
if (defn_func_id == Xol_kwd_grp_.Id_invoke) // NOTE: if #invoke, set frame_ttl to argx, not name; EX:{{#invoke:A}}
invk.Frame_ttl_(Bry_.Add(Xow_ns_.Bry__module_w_colon, Xoa_ttl.Replace_unders(defn_func.Argx_dat()))); // NOTE: always prepend "Module:" to frame_ttl; DATE:2014-06-13; NOTE: always use spaces; DATE:2014-08-14; always use canonical English "Module"; DATE:2015-11-09
Bry_bfr bfr_func = Bry_bfr.new_();
defn_func.Func_evaluate(ctx, src, caller, invk, bfr_func);
defn_func.Func_evaluate(bfr_func, ctx, caller, invk, src);
if (caller.Rslt_is_redirect()) // do not prepend if page is redirect; EX:"#REDIRECT" x> "\n#REDIRECT" DATE:2014-07-11
caller.Rslt_is_redirect_(false); // reset flag; needed for TEST; kludgy, but Rslt_is_redirect is intended for single use
else

View File

@@ -18,7 +18,7 @@ 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 org.junit.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*;
public class Xot_invk_wkr_basic_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic() {
fxt.Test_parse_page_tmpl("{{a}}", fxt.tkn_tmpl_invk_w_name(0, 5, 2, 3));

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xot_invk_wkr_prepend_nl_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() { // PURPOSE: if {| : ; # *, auto add new_line REF.MW:Parser.php|braceSubstitution
fxt.Init_defn_clear();
fxt.Init_defn_add("test_inner", "# a");

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xot_invk_wkr_raw_msg_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_defn_clear();}
@Test public void Raw() { // PURPOSE: {{raw:A}} is same as {{A}}; EX.WIKT:android; {{raw:ja/script}}
fxt.Init_defn_clear();

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xot_invk_wkr_transclude_tst {
@Before public void init() {fxt.Reset();} private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_defn_clear();}
@Test public void Template() { // PURPOSE: {{:Template:Test}} is same as {{Template:Test}}; EX.WIKT:android; japanese and {{:Template:ja/script}}
fxt.Init_defn_add("Test_1", "{{#if:|y|n}}"); // NOTE: must be of form "Test 1"; test_1 will fail

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xot_prm_tkn_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Idx_1() {fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{test|a|b}}" , "a");}
@Test public void Idx_2() {fxt.Test_parse_tmpl_str_test("{{{2}}}" , "{{test|a|b}}" , "b");}

View File

@@ -16,8 +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.langs.htmls.encoders.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.parsers.tmpls.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.kwds.*;
public class Xop_redirect_mgr {
private final Xowe_wiki wiki; private final Gfo_url_encoder url_decoder; private Hash_adp_bry redirect_hash;
@@ -70,24 +69,23 @@ public class Xop_redirect_mgr {
, Xop_tkn_.Lnki_end // "]]"
);
}
public static byte[] Bld_redirect_msg(Xoae_app app, Xowe_wiki wiki, Xoae_page page) {
List_adp list = page.Redirected_ttls();
public static byte[] Bld_redirect_msg(Xoae_app app, Xowe_wiki wiki, List_adp list) {
int list_len = list.Count();
if (list_len == 0) return Bry_.Empty;
Bry_bfr redirect_bfr = app.Utl__bfr_mkr().Get_b512();
Bry_bfr redirect_bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
for (int i = 0; i < list_len; i++) {
if (i != 0) redirect_bfr.Add(Bry_redirect_dlm);
byte[] redirect_ttl = (byte[])list.Get_at(i);
redirect_bfr.Add(Xoh_consts.A_bgn) // '<a href="'
.Add(Xoh_href_.Bry__wiki) // '/wiki/'
.Add(redirect_ttl) // 'PageA'
.Add(Bry_redirect_arg) // ?redirect=no
.Add(Xoh_consts.A_bgn_lnki_0) // '" title="'
.Add(redirect_ttl) // 'PageA'
.Add(Xoh_consts.__end_quote) // '">'
.Add(redirect_ttl) // 'PageA'
.Add(Xoh_consts.A_end) // </a>
;
byte[] ttl_unders = (byte[])list.Get_at(i);
byte[] ttl_spaces = Xoa_ttl.Replace_unders(ttl_unders);
redirect_bfr.Add(Gfh_bldr_.Bry__a_lhs_w_href) // '<a href="'
.Add(Xoh_href_.Bry__wiki) // '/wiki/'
.Add(ttl_unders) // 'PageA'
.Add(Bry_redirect_arg) // ?redirect=no
.Add(Gfh_bldr_.Bry__title__nth) // '" title="'
.Add(ttl_spaces) // 'PageA'
.Add(Gfh_bldr_.Bry__lhs_end_head_w_quote) // '">'
.Add(ttl_spaces) // 'PageA'
.Add(Gfh_bldr_.Bry__a_rhs); // </a>
}
Xol_msg_itm msg_itm = wiki.Lang().Msg_mgr().Itm_by_id_or_null(Xol_msg_itm_.Id_redirectedfrom);
Bry_bfr fmt_bfr = app.Utl__bfr_mkr().Get_b512();

View File

@@ -46,9 +46,12 @@ public class Xop_redirect_mgr_tst {
@Test public void Parse_1st_link_only() { // PURPOSE: do not take pipe from 2nd lnki; PAGE:en.w:Template:pp-semi; DATE:2015-11-14
fxt.Test_redirect("#REDIRECT [[Template:A]][[Category:B|b]]", "Template:A");
}
@Test public void Redirected_html() { // PURPOSE: "Redirected from" message was using "_" instead of " "; PAGE:en.w:Summer_Solstice; DATE:2015-12-29
fxt.Test__redirected_html("A_B", "(Redirected from <a href=\"/wiki/A_B?redirect=no\" title=\"A B\">A B</a>)");
}
}
class Xop_redirect_mgr_fxt {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
public void Clear() {
fxt.Reset();
}
@@ -72,4 +75,10 @@ class Xop_redirect_mgr_fxt {
byte[] actl_bry = actl_ttl == null ? Bry_.Empty : actl_ttl.Full_txt();
Tfds.Eq(expd_str, String_.new_u8(actl_bry));
}
public void Test__redirected_html(String page_str, String expd_str) {
List_adp list = List_adp_.new_();
list.Add(Bry_.new_u8(page_str));
byte[] actl_bry = Xop_redirect_mgr.Bld_redirect_msg(fxt.App(), fxt.Wiki(), list);
Tfds.Eq_str(expd_str, String_.new_u8(actl_bry));
}
}

View File

@@ -23,6 +23,7 @@ public class Xop_xnde_tag {
this.name_bry = Bry_.new_a7(name_str);
this.name_str = name_str;
this.name_len = name_bry.length;
this.xtn_bgn_tag = Bry_.Add(Byte_ascii.Angle_bgn_bry, name_bry);
this.xtn_end_tag = Bry_.Add(Xop_xnde_tag_.Xtn_end_tag_bgn, name_bry); // always force endtag; needed for <noinclude>
this.xtn_end_tag_tmp = new byte[xtn_end_tag.length]; Array_.Copy(xtn_end_tag, xtn_end_tag_tmp);
}
@@ -30,6 +31,7 @@ public class Xop_xnde_tag {
public byte[] Name_bry() {return name_bry;} private final byte[] name_bry;
public String Name_str() {return name_str;} private final String name_str;
public int Name_len() {return name_len;} private final int name_len;
public byte[] Xtn_bgn_tag() {return xtn_bgn_tag;} private final byte[] xtn_bgn_tag;
public byte[] Xtn_end_tag() {return xtn_end_tag;} private final byte[] xtn_end_tag;
public byte[] Xtn_end_tag_tmp() {return xtn_end_tag_tmp;} private final byte[] xtn_end_tag_tmp;
public boolean Xtn() {return xtn;} public Xop_xnde_tag Xtn_() {xtn = true; return this;} private boolean xtn;

View File

@@ -219,10 +219,10 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
private static Xop_tkn_itm Make_bry_tkn(Xop_tkn_mkr tkn_mkr, byte[] src, int bgn_pos, int cur_pos) {
int len = cur_pos - bgn_pos;
byte[] bry = null;
if (len == 1 && src[bgn_pos] == Byte_ascii.Lt) bry = Html_entity_.Lt_bry;
if (len == 1 && src[bgn_pos] == Byte_ascii.Lt) bry = Gfh_entity_.Lt_bry;
else if (len == 2 && src[bgn_pos] == Byte_ascii.Lt
&& src[bgn_pos + 1] == Byte_ascii.Slash) bry = Bry_escape_lt_slash; // NOTE: should use bgn_pos, not cur_pos; DATE:2014-10-22
else bry = Bry_.Add(Html_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, cur_pos)); // +1 to skip <
else bry = Bry_.Add(Gfh_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, cur_pos)); // +1 to skip <
return tkn_mkr.Bry_raw(bgn_pos, cur_pos, bry);
}
private int Make_noinclude(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int gtPos, Xop_xnde_tag tag, int tag_end_pos, boolean tag_is_closing) {
@@ -313,7 +313,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
if ( page.Html_data().Html_restricted()
&& page.Wiki().Domain_tid() != Xow_domain_tid_.Int__home) {
int end_pos = gtPos + 1;
ctx.Subs_add(root, tkn_mkr.Bry_raw(bgn_pos, end_pos, Bry_.Add(gplx.langs.htmls.Html_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, end_pos)))); // +1 to skip <
ctx.Subs_add(root, tkn_mkr.Bry_raw(bgn_pos, end_pos, Bry_.Add(gplx.langs.htmls.Gfh_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, end_pos)))); // +1 to skip <
return end_pos;
}
}
@@ -473,7 +473,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
}
}
if (end_tag.Restricted()) // restricted tags (like <script>) are not placed on stack; for now, just write it out
ctx.Subs_add(root, tkn_mkr.Bry_raw(bgn_pos, cur_pos, Bry_.Add(gplx.langs.htmls.Html_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, cur_pos)))); // +1 to skip <
ctx.Subs_add(root, tkn_mkr.Bry_raw(bgn_pos, cur_pos, Bry_.Add(gplx.langs.htmls.Gfh_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, cur_pos)))); // +1 to skip <
else {
if (pre2_pending) {
pre2_pending = false;
@@ -538,13 +538,13 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
}
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) {
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[] open_bry, 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)) // 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);
return Xop_xnde_wkr_.Find_xtn_end(ctx, src, open_end, src_len, open_bry, 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;
@@ -555,12 +555,12 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
xnde.Tag_close_rng_(open_end, open_end); // NOTE: inline tag, so set TagClose to open_end; should noop
}
else {
byte[] close_bry = tag.Xtn_end_tag_tmp(); // get tmp bry (so as not to new)
byte[] close_bry = tag.Xtn_end_tag_tmp(); // get tmp bry (so as not to new)
if (tag.Langs() != null) { // cur tag has langs; EX:<section>; DATE:2014-07-18
Xop_xnde_tag_lang tag_lang = tag.Langs_get(ctx.Lang().Case_mgr(), ctx.Cur_page().Lang().Lang_id(), src, name_bgn, name_end);
if (tag_lang == null) // tag does not match lang; EX:<trecho> and lang=de;
return ctx.Lxr_make_txt_(open_end);
if (tag_lang != Xop_xnde_tag_lang.Instance) // tag matches; note Xop_xnde_tag_lang._ is a wildcard match; EX:<section>
if (tag_lang != Xop_xnde_tag_lang.Instance) // tag matches; note Xop_xnde_tag_lang._ is a wildcard match; EX:<section>
close_bry = tag_lang.Xtn_end_tag_tmp();
}
int src_offset = open_bgn - 1; // open bgn to start at <; -2 to ignore </ ; +1 to include <
@@ -568,7 +568,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
for (int i = 2; i < close_ary_len; i++) // 2 to ignore </
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);
int close_bgn = Find_xtn_end_lhs(ctx, tag, src, src_len, open_bgn, open_end, tag.Xtn_bgn_tag(), close_bry);
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) {
@@ -608,8 +608,8 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
case Xop_xnde_tag_.Tid_xowa_cmd: xnde_xtn = tkn_mkr.Xnde_xowa_cmd(); break;
case Xop_xnde_tag_.Tid_math: xnde_xtn = tkn_mkr.Xnde_math(); break;
case Xop_xnde_tag_.Tid_poem: xnde_xtn = tkn_mkr.Xnde_poem(); break;
case Xop_xnde_tag_.Tid_ref: xnde_xtn = gplx.xowa.xtns.cite.References_nde.Enabled ? tkn_mkr.Xnde_ref() : null; break;
case Xop_xnde_tag_.Tid_references: xnde_xtn = gplx.xowa.xtns.cite.References_nde.Enabled ? tkn_mkr.Xnde_references() : null; break;
case Xop_xnde_tag_.Tid_ref: xnde_xtn = gplx.xowa.xtns.cites.References_nde.Enabled ? tkn_mkr.Xnde_ref() : null; break;
case Xop_xnde_tag_.Tid_references: xnde_xtn = gplx.xowa.xtns.cites.References_nde.Enabled ? tkn_mkr.Xnde_references() : null; break;
case Xop_xnde_tag_.Tid_gallery: xnde_xtn = tkn_mkr.Xnde_gallery(); break;
case Xop_xnde_tag_.Tid_imageMap: xnde_xtn = tkn_mkr.Xnde_imageMap(); break;
case Xop_xnde_tag_.Tid_hiero: xnde_xtn = tkn_mkr.Xnde_hiero(); break;

View File

@@ -20,8 +20,8 @@ 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 int Find_xtn_end__tid__bgn = 0, Find_xtn_end__tid__end = 1, Find_xtn_end__tid__xtag = 2;
private static final Int_obj_ref Find_xtn_end__key__bgn = Int_obj_ref.new_(Find_xtn_end__tid__bgn), 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();
@@ -35,20 +35,34 @@ class Xop_xnde_wkr_ {
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) {
public static int Find_xtn_end(Xop_ctx ctx, byte[] src, int open_end, int src_end, byte[] open_bry, 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(open_bry, Find_xtn_end__key__bgn);
xtn_end_tag_trie.Add_obj(close_bry, Find_xtn_end__key__end);
int depth = 0;
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;
switch (tid) {
case Find_xtn_end__tid__bgn: // handle nested refs; PAGE:en.w:UK; DATE:2015-12-26
int angle_end_pos = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, i, src_end); if (angle_end_pos == Bry_find_.Not_found) {Xoa_app_.Usr_dlg().Warn_many("", "", "parser.xtn: could not find angle_end: page=~{0}", ctx.Cur_page().Url().To_str()); return Bry_find_.Not_found;}
if (src[angle_end_pos -1] == Byte_ascii.Slash) {}
else
++depth;
break;
case Find_xtn_end__tid__end: // xtn_end found; use it
if (depth == 0)
return i;
else
--depth;
break;
case Find_xtn_end__tid__xtag: // 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;
break;
}
}
}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*; import gplx.xowa.wikis.nss.*;
public class Xop_xnde_wkr__basic_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Escape_lt() { // PURPOSE: some templates have unknown tags; PAGE:en.w:PHP
fxt.Init_para_y_();

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__blockquote_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Pre() { // PURPOSE: preserve leading spaces within blockquote; PAGE:en.w:Tenerife_airport_disaster
fxt.Init_para_y_();

View File

@@ -18,7 +18,7 @@ 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 org.junit.*; import gplx.xowa.parsers.lists.*;
public class Xop_xnde_wkr__err_dangling_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Init_log_(Xop_xnde_log.Dangling_xnde)

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__err_malformed_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Lt_only() {
fxt.Test_parse_page_wiki("<", fxt.tkn_txt_(0, 1));

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__err_misc_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Error_br_removed() {
fxt.Init_para_y_();

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__include_basic_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Tmpl_includeonly() {fxt.Test_parse_tmpl_str_test("a<includeonly>b</includeonly>c" , "{{test}}", "abc");}
@Test public void Tmpl_noinclude() {fxt.Test_parse_tmpl_str_test("a<noinclude>b</noinclude>c" , "{{test}}", "ac");}

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__include_uncommon_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Ex_Tmpl_io_oi() { // PURPOSE: <includeonly> not parsing internals; PAGE:en.w:[[Template:MONTHNAME]]
fxt.Test_parse_tmpl_str_test("<includeonly>{{#if:{{{1}}}|a|b}}</includeonly><noinclude>c</noinclude>", "{{test|1}}", "a");

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__li_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Inside_tblx() { // PURPOSE: auto-close <li> (EX: "<li>a<li>") was causing 3rd <li> to close incorrectly
fxt.Test_parse_page_wiki_str

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__nowiki_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Test_parse_page_wiki_str

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__tblx_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Table() {
fxt.Test_parse_page_wiki("a<table><tr><td>b</td></tr></table>c"
@@ -61,7 +61,7 @@ public class Xop_xnde_wkr__tblx_tst {
( "<table>"
, " <tr>"
, " <td>"
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"B\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/150px.png\" width=\"150\" height=\"0\" /></a>"
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"B\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/150px.png\" width=\"150\" height=\"0\" /></a>"
, " </td>"
, " </tr>"
, "</table>"

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__text_block_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Source_wikitext() { // PURPOSE.ASSERT: wikitext should be rendered literally; DATE:2014-03-11
fxt.Test_parse_page_wiki_str("<source>''a''</source>", "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">''a''</pre></div>");

View File

@@ -18,7 +18,7 @@ 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 org.junit.*;
public class Xop_xnde_wkr__tidy_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Sub_sup_autocorrect() {
fxt.Test_parse_page_wiki_str("<sub>a</sup>b", "<sub>a</sub>b");