mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.4.1
This commit is contained in:
@@ -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.core.btries.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_parser { // NOTE: parsers are reused; do not keep any read-write state
|
||||
private final Xowe_wiki wiki;
|
||||
@@ -42,7 +42,8 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
Parse_text_to_html(bfr, ctx.Cur_page(), false, src);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
public void Parse_text_to_html(Bry_bfr trg, Xoae_page page, boolean para_enabled, byte[] src) {
|
||||
public void Parse_text_to_html(Bry_bfr trg, Xoae_page page, boolean para_enabled, byte[] src) {Parse_text_to_html(trg, page, Xoh_wtr_ctx.Basic, para_enabled, src);}
|
||||
public void Parse_text_to_html(Bry_bfr trg, Xoae_page page, Xoh_wtr_ctx hctx, boolean para_enabled, byte[] src) {
|
||||
Xop_ctx ctx = Xop_ctx.new_sub_(wiki, page);
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_root_tkn root = tkn_mkr.Root(src);
|
||||
@@ -51,7 +52,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
|
||||
root.Reset();
|
||||
ctx.Para().Enabled_(para_enabled);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, ctx.Tkn_mkr(), wtxt, Xop_parser_.Doc_bgn_bos);
|
||||
wiki.Html_mgr().Html_wtr().Write_all(trg, ctx, wtxt, root);
|
||||
wiki.Html_mgr().Html_wtr().Write_all(trg, ctx, hctx, wtxt, root);
|
||||
}
|
||||
public Xot_defn_tmpl Parse_text_to_defn_obj(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xow_ns ns, byte[] name, byte[] src) {
|
||||
Xot_defn_tmpl rv = new Xot_defn_tmpl();
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.*; import gplx.core.envs.*;
|
||||
public class Xow_parser_mgr {
|
||||
private final Xowe_wiki wiki; private final Xop_tkn_mkr tkn_mkr;
|
||||
private Xop_parser anchor_encode_parser;
|
||||
|
||||
@@ -62,13 +62,13 @@ public class Xop_lnke_wkr_brack_tst {
|
||||
}
|
||||
@Test public void Encode_xwiki() { // PURPOSE: href title and args should always be encoded; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("commons.wikimedia.org"), Bry_.new_a7("commons.wikimedia.org"));
|
||||
fxt.Test_parse_page_wiki_str // encode page
|
||||
fxt.Test__parse__wtxt_to_html // encode page
|
||||
( "[http://commons.wikimedia.org/%22%3E_A B]"
|
||||
, "<a href=\"/site/commons.wikimedia.org/wiki/%22%3E_A\">B</a>" // '%22%3E' not '">'
|
||||
, "<a href='/site/commons.wikimedia.org/wiki/%22%3E_A'>B</a>" // '%22%3E' not '">'
|
||||
);
|
||||
fxt.Test_parse_page_wiki_str // encode args
|
||||
fxt.Test__parse__wtxt_to_html // encode args
|
||||
( "[http://commons.wikimedia.org/A?b=%22%3E_C D]"
|
||||
, "<a href=\"/site/commons.wikimedia.org/wiki/A?b=%22%3E_C\">D</a>" // '%22%3E' not '">'
|
||||
, "<a href='/site/commons.wikimedia.org/wiki/A?b=%22%3E_C'>D</a>" // '%22%3E' not '">'
|
||||
);
|
||||
}
|
||||
@Test public void Encode_basic() { // PURPOSE: counterpart to Encode_xwiki; DATE:2014-07-15
|
||||
|
||||
@@ -25,18 +25,18 @@ public class Xop_lnke_wkr_relative_tst {
|
||||
);
|
||||
}
|
||||
@Test public void Relative_external() {
|
||||
fxt.Test_parse_page_wiki_str("[//www.a.org a]", "<a href=\"https://www.a.org\" rel=\"nofollow\" class=\"external text\">a</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[//www.a.org a]", "<a href='https://www.a.org' rel='nofollow' class='external text'>a</a>");
|
||||
}
|
||||
@Test public void Relative_internal() {
|
||||
fxt.Init_xwiki_add_user_("en.wikipedia.org");
|
||||
fxt.Test_parse_page_wiki_str("[//en.wikipedia.org/wiki Wikipedia]", "<a href=\"/site/en.wikipedia.org/wiki/\">Wikipedia</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[//en.wikipedia.org/wiki Wikipedia]", "<a href='/site/en.wikipedia.org/wiki/'>Wikipedia</a>");
|
||||
}
|
||||
@Test public void Relative_w_category() { // EX: [//commons.wikimedia.org/wiki/Category:Diomedeidae A]
|
||||
fxt.Init_xwiki_add_user_("en.wikipedia.org");
|
||||
fxt.Test_parse_page_wiki_str("[//en.wikipedia.org/wiki/Category:A A]", "<a href=\"/site/en.wikipedia.org/wiki/Category:A\">A</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[//en.wikipedia.org/wiki/Category:A A]", "<a href='/site/en.wikipedia.org/wiki/Category:A'>A</a>");
|
||||
}
|
||||
@Test public void Relurl() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org"));
|
||||
fxt.Test_parse_page_wiki_str("[[//en.wikipedia.org/ a]]", "[<a href=\"/site/en.wikipedia.org/wiki/\">a</a>]");
|
||||
fxt.Test__parse__wtxt_to_html("[[//en.wikipedia.org/ a]]", "[<a href='/site/en.wikipedia.org/wiki/'>a</a>]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,35 +21,35 @@ public class Xop_lnke_wkr_xwiki_tst {
|
||||
@Before public void init() {fxt.Reset();} private 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_page_wiki_str("[http://en.wikipedia.org/wiki/A a]", "<a href=\"/site/en.wikipedia.org/wiki/A\">a</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/wiki/A a]", "<a href='/site/en.wikipedia.org/wiki/A'>a</a>");
|
||||
}
|
||||
@Test public void Xwiki_relative() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org"));
|
||||
fxt.Test_parse_page_wiki_str("[//en.wikipedia.org/ a]", "<a href=\"/site/en.wikipedia.org/wiki/\">a</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[//en.wikipedia.org/ a]", "<a href='/site/en.wikipedia.org/wiki/'>a</a>");
|
||||
}
|
||||
@Test public void Xwiki_qarg() {// DATE:2013-02-02
|
||||
fxt.Init_xwiki_add_user_("en.wikipedia.org");
|
||||
fxt.Test_parse_page_wiki_str("http://en.wikipedia.org/wiki/Special:Allpages?from=Earth", "<a href=\"/site/en.wikipedia.org/wiki/Special:Allpages?from=Earth\">http://en.wikipedia.org/wiki/Special:Allpages?from=Earth</a>");
|
||||
fxt.Test__parse__wtxt_to_html("http://en.wikipedia.org/wiki/Special:Allpages?from=Earth", "<a href='/site/en.wikipedia.org/wiki/Special:Allpages?from=Earth'>http://en.wikipedia.org/wiki/Special:Allpages?from=Earth</a>");
|
||||
}
|
||||
@Test public void Lang_prefix() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org"));
|
||||
fxt.Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("fr"), Bry_.new_a7("fr.wikipedia.org"));
|
||||
fxt.Test_parse_page_wiki_str("[http://en.wikipedia.org/wiki/fr:A a]", "<a href=\"/site/fr.wikipedia.org/wiki/A\">a</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/wiki/fr:A a]", "<a href='/site/fr.wikipedia.org/wiki/A' rel='nofollow' class='external text'>a</a>");
|
||||
}
|
||||
@Test public void Xwiki_query_arg() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org"));
|
||||
fxt.Test_parse_page_wiki_str("[http://en.wikipedia.org/wiki/A?action=edit a]", "<a href=\"/site/en.wikipedia.org/wiki/A?action=edit\">a</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/wiki/A?action=edit a]", "<a href='/site/en.wikipedia.org/wiki/A?action=edit'>a</a>");
|
||||
}
|
||||
@Test public void Ignore_proto() { // PURPOSE: handle other protocols; PAGE:uk.w:Маскалі; DATE:2015-07-28
|
||||
fxt.Test_parse_page_wiki_str("[mailto:a b]", "<a href=\"mailto:a\" rel=\"nofollow\" class=\"external text\">b</a>");// should be /w/, not /en.wikipedia.org
|
||||
fxt.Test__parse__wtxt_to_html("[mailto:a b]", "<a href='mailto:a' rel='nofollow' class='external text'>b</a>");// should be /w/, not /en.wikipedia.org
|
||||
}
|
||||
@Test public void Ignore_alias() { // PURPOSE: fictitious example to make sure aliases are not subbed for domains; DATE:2015-07-28
|
||||
fxt.Init_xwiki_add_user_("w", "en.wikipedia.org");
|
||||
fxt.Test_parse_page_wiki_str("[https://w/b c]", "<a href=\"https://w/b\" rel=\"nofollow\" class=\"external text\">c</a>");// should be /w/, not /en.wikipedia.org
|
||||
fxt.Test__parse__wtxt_to_html("[https://w/b c]", "<a href='https://w/b' rel='nofollow' class='external text'>c</a>");// should be /w/, not /en.wikipedia.org
|
||||
}
|
||||
@Test public void Xwiki__qargs() { // PURPOSE: fix null ref error; PAGE:en.w:Wikipedia:Template_standardisation/demometa DATE:2015-08-02
|
||||
fxt.Init_xwiki_add_user_("en.wikipedia.org");
|
||||
fxt.Test_parse_page_wiki_str("[http://en.wikipedia.org/w/index.php?action=edit&preload=Template:Afd2+starter&editintro=Template:Afd3+starter&title=Wikipedia:Articles+for+deletion/Template_standardisation/demometa]"
|
||||
, "<a href=\"/site/en.wikipedia.org/wiki/index.php?action==edit=&preload==Template:Afd2+starter=&editintro==Template:Afd3+starter=&title=&=\">[1]</a>");
|
||||
fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/w/index.php?action=edit&preload=Template:Afd2+starter&editintro=Template:Afd3+starter&title=Wikipedia:Articles+for+deletion/Template_standardisation/demometa]"
|
||||
, "<a href='/site/en.wikipedia.org/wiki/index.php?action==edit=&preload==Template:Afd2+starter=&editintro==Template:Afd3+starter=&title=&='>[1]</a>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +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 gplx.core.net.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xop_link_parser {
|
||||
public byte[] Html_xowa_ttl() {return html_xowa_ttl;} private byte[] html_xowa_ttl;
|
||||
public byte Html_anchor_cls() {return html_anchor_cls;} private byte html_anchor_cls;
|
||||
@@ -46,7 +47,8 @@ public class Xop_link_parser {
|
||||
}
|
||||
raw = tmp_bfr.To_bry_and_clear();
|
||||
html_anchor_cls = Xoh_lnki_consts.Tid_a_cls_none;
|
||||
html_anchor_rel = Xoh_lnki_consts.Tid_a_rel_nofollow;
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(wiki_bry);
|
||||
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;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
public class Xop_lnki_align_h_ {
|
||||
public static final byte Null = 0, None = 1, Left = 2, Center = 3, Right = 4;
|
||||
public static final byte Null = 0, None = 1, Left = 2, Center = 3, Right = 4; // SERIALIZED
|
||||
public static final byte[][] Html_names = new byte[][]
|
||||
{ Object_.Bry__null
|
||||
, Bry_.new_a7("none")
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.numbers.*;
|
||||
public class Xop_lnki_arg_parser {
|
||||
private final Btrie_fast_mgr key_trie = Btrie_fast_mgr.cs();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|
||||
public int Tail_bgn() {return tail_bgn;} public Xop_lnki_tkn Tail_bgn_(int v) {tail_bgn = v; return this;} private int tail_bgn = -1;
|
||||
public int Tail_end() {return tail_end;} public Xop_lnki_tkn Tail_end_(int v) {tail_end = v; return this;} private int tail_end = -1;
|
||||
public byte Border() {return border;} public Xop_lnki_tkn Border_(byte v) {border = v; return this;} private byte border = Bool_.__byte;
|
||||
public byte Align_h() {return align_h;} public Xop_lnki_tkn Align_h_(byte v) {if (align_h == Xop_lnki_align_h_.Null) align_h = v; return this;} private byte align_h = Xop_lnki_align_h_.Null;
|
||||
public int Align_h() {return align_h;} public Xop_lnki_tkn Align_h_(int v) {if (align_h == Xop_lnki_align_h_.Null) align_h = v; return this;} private int align_h = Xop_lnki_align_h_.Null;
|
||||
public byte Align_v() {return align_v;} public Xop_lnki_tkn Align_v_(byte v) {align_v = v; return this;} private byte align_v = Byte_.Max_value_127;
|
||||
public int W() {return w;} public Xop_lnki_tkn W_(int v) {w = v; return this;} private int w = Width_null;
|
||||
public int H() {return h;} public Xop_lnki_tkn H_(int v) {h = v; return this;} private int h = Height_null;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Xop_lnki_tkn_chkr extends Xop_tkn_chkr_base {
|
||||
public byte ImgType() {return imgType;} public Xop_lnki_tkn_chkr ImgType_(byte v) {imgType = v; return this;} private byte imgType = Byte_.Max_value_127;
|
||||
public int Width() {return width;} public Xop_lnki_tkn_chkr Width_(int v) {width = v; return this;} private int width = Int_.Min_value;
|
||||
public int Height() {return height;} public Xop_lnki_tkn_chkr Height_(int v) {height = v; return this;} private int height = Int_.Min_value;
|
||||
public byte HAlign() {return hAlign;} public Xop_lnki_tkn_chkr HAlign_(byte v) {hAlign = v; return this;} private byte hAlign = Byte_.Max_value_127;
|
||||
public int HAlign() {return hAlign;} public Xop_lnki_tkn_chkr HAlign_(int v) {hAlign = v; return this;} private int hAlign = Byte_.Max_value_127;
|
||||
public byte VAlign() {return vAlign;} public Xop_lnki_tkn_chkr VAlign_(byte v) {vAlign = v; return this;} private byte vAlign = Byte_.Max_value_127;
|
||||
public byte Border() {return border;} public Xop_lnki_tkn_chkr Border_(byte v) {border = v; return this;} private byte border = Bool_.__byte;
|
||||
public double Upright() {return upright;} public Xop_lnki_tkn_chkr Upright_(double v) {upright = v; return this;} double upright = Xop_lnki_tkn.Upright_null;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Xop_lnki_wkr_ {
|
||||
public static boolean Parse_ttl(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int ttl_bgn, int ttl_end) {
|
||||
Xoae_app app = ctx.App();
|
||||
byte[] ttl_bry = Bry_.Mid(src, ttl_bgn, ttl_end);
|
||||
ttl_bry = Xoa_app_.Utl__encoder_mgr().Http_url_ttl().Decode(ttl_bry);
|
||||
ttl_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url_ttl.Decode(ttl_bry);
|
||||
int ttl_bry_len = ttl_bry.length;
|
||||
Xoa_ttl page_ttl = ctx.Cur_page().Ttl();
|
||||
if (page_ttl.Ns().Subpages_enabled()
|
||||
|
||||
@@ -265,7 +265,7 @@ 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\" rel=\"nofollow\" 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/Заглавная_страница?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
|
||||
fxt.Test_parse_page_wiki_str
|
||||
|
||||
@@ -53,13 +53,13 @@ public class Xop_lnki_wkr__link_tst {
|
||||
@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/\" 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=\"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>"
|
||||
));
|
||||
}
|
||||
@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/\" 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://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>"
|
||||
));
|
||||
}
|
||||
@Test public void Link_external_double_http() {// PURPOSE.fix: link=http://a.org?b=http://c.org breaks lnki; DATE:2013-02-03
|
||||
@@ -72,35 +72,35 @@ public class Xop_lnki_wkr__link_tst {
|
||||
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/\" 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=\"/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>"
|
||||
));
|
||||
}
|
||||
@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/\" 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=\"/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>"
|
||||
));
|
||||
}
|
||||
@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/\" 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=\"/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>"
|
||||
));
|
||||
}
|
||||
@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|2010–2011 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\" 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=\"/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>"
|
||||
));
|
||||
}
|
||||
@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\" 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=\"/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>"
|
||||
));
|
||||
}
|
||||
@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\" 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=\"/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>"
|
||||
));
|
||||
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\" 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=\"/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>"
|
||||
));
|
||||
fxt.Init_xwiki_clear();
|
||||
}
|
||||
|
||||
@@ -46,6 +46,6 @@ public class Xopg_redlink_lnki_list {
|
||||
return;
|
||||
lnki_list.Add(lnki);
|
||||
}
|
||||
public static final String Lnki_id_prefix = "xowa_lnki_";
|
||||
public static final String Lnki_id_prefix = "xolnki_";
|
||||
public static final int Lnki_id_prefix_len = String_.Len(Lnki_id_prefix);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Xop_log_basic_wkr implements GfoInvkAble {
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.parsers.logs.*;
|
||||
import gplx.xowa.xtns.scribunto.*;
|
||||
public class Xop_log_invoke_wkr implements GfoInvkAble {
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
|
||||
public class Xop_log_property_wkr implements GfoInvkAble {
|
||||
private Xop_log_mgr log_mgr; private Db_conn conn; private Db_stmt stmt;
|
||||
|
||||
@@ -23,5 +23,7 @@ public class Xop_ignore_tkn extends Xop_tkn_itm_base {
|
||||
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_ignore;}
|
||||
@Override public void Tmpl_compile(Xop_ctx ctx, byte[] src, Xot_compile_data prep_data) {}
|
||||
@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 = 3, Ignore_tid_xnde_dangling = 4, Ignore_tid_nbsp = 5, Ignore_tid_empty_li = 6, Ignore_tid_pre_at_bos = 7;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,18 @@ public class Xop_pipe_lxr implements Xop_lxr {
|
||||
case Xop_tkn_itm_.Tid_tblw_tb:
|
||||
case Xop_tkn_itm_.Tid_tblw_tr:
|
||||
rv = Xop_tblw_lxr_ws.Make(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, Xop_tblw_wkr.Tblw_type_td, false);
|
||||
if (rv == Xop_tblw_lxr_ws.Tblw_ws_cell_pipe) {
|
||||
int prv_nl_pos = Bry_find_.Find_bwd(src, Byte_ascii.Nl, cur_pos - 1, 0); if (prv_nl_pos == -1) prv_nl_pos = 0; // find prv nl
|
||||
if (Bry_.Match(src, prv_nl_pos, prv_nl_pos + 3, Xop_tblw_lxr.Hook_tr)) { // "\n|-" aka tblw_tr
|
||||
int nl_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl, cur_pos, src_len); if (nl_pos == Bry_find_.Not_found) nl_pos = src_len;
|
||||
ctx.Subs_add(root, tkn_mkr.Ignore(bgn_pos, nl_pos, Xop_ignore_tkn.Ignore_tid_tr_w_td)); // gobble up rest of content between "|" and "\n"; PAGE:lv.w:Starptautiska_kosmosa_stacija; DATE:2015-11-21
|
||||
return nl_pos;
|
||||
}
|
||||
else {
|
||||
ctx.Subs_add(root, tkn_mkr.Pipe(bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
}
|
||||
}
|
||||
if (rv == Xop_tblw_lxr_ws.Tblw_ws_cell_pipe) {
|
||||
ctx.Subs_add(root, tkn_mkr.Pipe(bgn_pos, cur_pos));
|
||||
return cur_pos;
|
||||
|
||||
@@ -101,4 +101,14 @@ public class Xop_tblw_wkr__uncommon_tst {
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Tr_with_pipe_ignores_content() { // PURPOSE: "|-" followed by "|" ignores rest of content; EX: {|\n|-|<b>a</b>\n|} PAGE:lv.w:Starptautiska_kosmosa_stacija; DATE:2015-11-21
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "{|"
|
||||
, "|- |<b>a</b>"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class Arg_bldr {
|
||||
trim = false;
|
||||
switch (wkr_typ) {
|
||||
case Xop_arg_wkr_.Typ_prm : trim = arg_idx == 0; break;
|
||||
case Xop_arg_wkr_.Typ_tmpl: trim = true; break; // NOTE: was "key_exists || arg_idx == 0;"; PAGE:s.w:Gothic_architecture; DATE:2015-11-07
|
||||
case Xop_arg_wkr_.Typ_tmpl: trim = key_exists || arg_idx == 0; break; // NOTE: never set "trim = true"; PAGE:fr.w:Histoire_de_la_marine_française_sous_Louis_XV_et_Louis_XVI DATE:2015-11-17
|
||||
case Xop_arg_wkr_.Typ_lnki: trim = !cur_itm_is_key; break;
|
||||
}
|
||||
if (trim) {
|
||||
|
||||
@@ -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.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xot_defn_tmpl implements Xot_defn {
|
||||
public byte Defn_tid() {return Xot_defn_.Tid_tmpl;}
|
||||
public boolean Defn_require_colon_arg() {return false;}
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.vnts.converts.*; import gplx.xowa.langs.funcs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.wikis.pages.*;
|
||||
|
||||
@@ -233,7 +233,7 @@ public class Xot_invk_wkr_basic_tst {
|
||||
fxt.Init_defn_clear();
|
||||
fxt.Init_defn_add("test_1", "{{test_2|{{{1}}}}}");
|
||||
fxt.Init_defn_add("test_2", "{{{1}}}");
|
||||
fxt.Test_parse_tmpl_str("{{test_1| a }}", " a"); // tmpl.trim_end: always trim end; DATE:2015-11-07
|
||||
fxt.Test_parse_tmpl_str("{{test_1| a }}", " a ");
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Ws_trimmed_key_1() { // PURPOSE: trim prm when passed as key;
|
||||
@@ -254,7 +254,7 @@ public class Xot_invk_wkr_basic_tst {
|
||||
fxt.Init_defn_clear();
|
||||
fxt.Init_defn_add("test_1", "{{test_2|1={{{1}}}{{{2}}}}}");
|
||||
fxt.Init_defn_add("test_2", "{{{1}}}");
|
||||
fxt.Test_parse_tmpl_str("{{test_1| a | b }}", "a b"); // tmpl.trim_end: always trim end; DATE:2015-11-07
|
||||
fxt.Test_parse_tmpl_str("{{test_1| a | b }}", "a b");
|
||||
fxt.Init_defn_clear();
|
||||
}
|
||||
@Test public void Ws_eval_prm() { // PURPOSE: skip ws in prm_idx; EX:it.w:Portale:Giochi_da_tavolo; it.w:Template:Alternate; DATE:2014-02-09
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.miscs.*;
|
||||
public class Xot_tmpl_wtr {
|
||||
public byte[] Write_all(Xop_ctx ctx, Xop_root_tkn root, byte[] src) {
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
import org.junit.*; import gplx.core.strings.*; import gplx.core.type_xtns.*; import gplx.core.stores.*; import gplx.core.envs.*;
|
||||
interface TstRuleMgr {
|
||||
boolean SkipChkVal(String expdTypeKey, TstAtr expd);
|
||||
boolean SkipChkObj(String expdTypeKey, String atrKey, TstObj expd);
|
||||
|
||||
@@ -20,8 +20,8 @@ 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 Url_encoder url_decoder; private Hash_adp_bry redirect_hash;
|
||||
public Xop_redirect_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.url_decoder = Xoa_app_.Utl__encoder_mgr().Http_url_ttl();} // NOTE: must be Url_ttl, not Url; PAGE:en.w:Template:Positionskarte+ -> Template:Location_map+, not Template:Location_map DATE:2014-08-21
|
||||
private final Xowe_wiki wiki; private final Gfo_url_encoder url_decoder; private Hash_adp_bry redirect_hash;
|
||||
public Xop_redirect_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.url_decoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url_ttl;} // NOTE: must be Url_ttl, not Url; PAGE:en.w:Template:Positionskarte+ -> Template:Location_map+, not Template:Location_map DATE:2014-08-21
|
||||
public void Clear() {redirect_hash = null;} // TEST:
|
||||
public boolean Is_redirect(byte[] text, int text_len) {return this.Extract_redirect(text, text_len) != null;}
|
||||
public Xoa_ttl Extract_redirect_loop(byte[] src) {
|
||||
|
||||
@@ -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.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.apps.progs.*;
|
||||
import gplx.core.btries.*; import gplx.core.envs.*; import gplx.xowa.apps.progs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.strings.*; import gplx.langs.htmls.*;
|
||||
import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Xop_xnde_wkr implements Xop_ctx_wkr {
|
||||
|
||||
Reference in New Issue
Block a user