Html_dump: Include namespace+title in redlink ttl, not just title [#568]

pull/620/head
gnosygnu 5 years ago
parent 88e0398696
commit bb86b026fe

@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class Gfo_test_list_base {
private final List_adp expd = List_adp_.New();
public void Clear() {expd.Clear();}
public void Add(Object itm) {expd.Add(itm);}
public void Test(Object actl_obj) {
int len = expd.Len();
if (len == 0) { // nothing expd; return "pass"
return;
}
String actl = Type_.Is_assignable_from_by_obj(actl_obj, List_adp.class) ? To_str((List_adp)actl_obj) : actl_obj.toString();
Gftest.Eq__ary__lines(To_str(expd), actl );
}
private static String To_str(List_adp list) {
String_bldr sb = String_bldr_.new_();
int len = list.Len();
for (int i = 0; i < len; i++) {
Object obj = list.Get_at(i);
String str = Object_.Xto_str_strict_or_null_mark(obj);
sb.Add(str).Add_char_nl();
}
return sb.To_str_and_clear();
}
}

@ -14,17 +14,28 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.core.makes.tests; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.makes.*;
import gplx.core.tests.*;
import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.htmls.sections.*;
import gplx.xowa.htmls.core.wkrs.lnkis.*;
public class Xoh_make_fxt {
private final Xowe_wiki wiki;
private final Xoh_make_mgr make_mgr;
private final Gfo_test_list_base expd_redlinks = new Gfo_test_list_base();
public Xoh_make_fxt() {
Xoa_app_fxt.repo2_(parser_fxt.App(), parser_fxt.Wiki()); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
parser_fxt.Wiki().Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
parser_fxt.Wiki().Html_mgr().Html_wtr().Cfg().Lnki__id_(Bool_.Y).Lnki__title_(Bool_.Y);
// set member reference
this.wiki = parser_fxt.Wiki();
this.make_mgr = wiki.Html__hdump_mgr().Load_mgr().Make_mgr();
// init parser_fxt
Xoa_app_fxt.repo2_(parser_fxt.App(), wiki); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
wiki.Html__hdump_mgr().Init_by_db(wiki);
wiki.Html_mgr().Html_wtr().Cfg().Lnki__id_(Bool_.Y).Lnki__title_(Bool_.Y);
}
public void Clear() {
parser_fxt.Reset();
page_chkr.Clear();
expd_redlinks.Clear();
}
public Xoh_page_chkr Page_chkr() {return page_chkr;} private final Xoh_page_chkr page_chkr = new Xoh_page_chkr();
public Xop_fxt Parser_fxt() {return parser_fxt;} private final Xop_fxt parser_fxt = new Xop_fxt();
@ -45,24 +56,40 @@ public class Xoh_make_fxt {
itm.Init_at_cache(true, img_w, img_h, url);
return itm;
}
public void Expd__redlinks(String... ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xopg_lnki_itm__hdump itm = new Xopg_lnki_itm__hdump(wiki.Ttl_parse(Bry_.new_u8(ary[i])));
expd_redlinks.Add(itm);
}
}
public void Test__html(String wtxt, String expd) {Test__html(wtxt, expd, true);}
public void Test__html(String wtxt, String expd, boolean escape_apos) {
if (escape_apos) expd = String_.Replace(expd, "'", "\"");
String actl = parser_fxt.Exec__parse_to_hdump(wtxt);
Tfds.Eq_str_lines(expd, actl);
}
public void Test__make(String html) {Test__make(true, html, null);}
public void Test__make(String html, Xoh_page_chkr chkr) {Test__make(true, html, chkr);}
public void Test__make(boolean print_to_console, String html, Xoh_page_chkr chkr) {
html = String_.Replace(html, "'", "\"");
// init hpg
Xoh_page actl = new Xoh_page();
actl.Ctor_by_hview(parser_fxt.Wiki(), Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1);
if (print_to_console)
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
Xoh_make_mgr make_mgr = parser_fxt.Wiki().Html__hdump_mgr().Load_mgr().Make_mgr();
// run make
if (print_to_console) Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
byte[] actl_body = make_mgr.Parse(Bry_.new_u8(html), parser_fxt.Wiki(), actl);
actl.Db().Html().Html_bry_(actl_body);
if (print_to_console)
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
chkr.Check(actl);
if (print_to_console) Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
// check html
if (chkr != null) {
actl.Db().Html().Html_bry_(actl_body);
chkr.Check(actl);
}
// check redlinks
expd_redlinks.Test(wiki.Html__hdump_mgr().Load_mgr().Make_mgr().Hctx().Page().Html_data().Redlink_list());
}
}

@ -57,8 +57,7 @@ public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
}
// increment html_uid and add "id=xolnki_"
byte[] ttl_bry = data.Href_itm().Ttl_page_db();
this.html_uid = Lnki_redlink_reg(hpg, hctx, ttl_bry, html_uid);
this.html_uid = Lnki_redlink_reg(hpg, hctx, data.Href_itm().Ttl_full_txt(), html_uid);
int src_bgn_lhs = data.Src_bgn();
int src_bgn_rhs = src_bgn_lhs + 3; // +3 to skip over "<a "
if (Bry_.Match(src, src_bgn_lhs, src_bgn_rhs, Bry__a__bgn)) {

@ -33,4 +33,8 @@ public class Xoh_lnki_make__basic__tst {
String orig = "<a href='https://simple.wikisource.org/wiki/A' title='A'>b</a>";
fxt.Test__make(orig, fxt.Page_chkr().Body_(orig));
}
@Test public void Redlinks() {// PURPOSE: redlink should have ns and ttl, not just ns; ISSUE#:568 DATE:2019-09-29
fxt.Expd__redlinks("Help:A_\"_b");
fxt.Test__make("<a href='/wiki/Help:A_%22_b' title='Help:A_\"_b'>Help:A \" b</a>");
}
}

@ -19,4 +19,7 @@ public class Xopg_lnki_itm__hdump implements Xopg_lnki_itm {
public Xopg_lnki_itm__hdump(Xoa_ttl ttl) {this.ttl = ttl;}
public Xoa_ttl Ttl() {return ttl;} private final Xoa_ttl ttl;
public int Html_uid() {return html_uid;} private int html_uid; public void Html_uid_(int v) {html_uid = v;}
@Override public String toString() {
return ttl.Full_db_as_str();
}
}

@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.wikis.pages.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.pages.*;
import gplx.core.strings.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
public class Xopg_lnki_list {
private final List_adp list = List_adp_.New();
@ -43,6 +44,14 @@ public class Xopg_lnki_list {
lnki_idx = gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Lnki_id_min; // NOTE: must start at 0, so that ++lnki_idx is > 0; html_wtr checks for > 0; DATE:2014-10-09; OLD_COMMENT: NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
list.Clear();
}
@Override public String toString() {
String_bldr sb = String_bldr_.new_();
int len = list.Len();
for (int i = 0; i < len; i++) {
sb.Add(Object_.Xto_str_strict_or_null_mark(list.Get_at(i))).Add_char_nl();
}
return sb.toString();
}
public static final String Lnki_id_prefix = "xolnki_";
private static final int Anch_bgn_anchor_only = 1; // signifies lnki which is only anchor; EX: [[#anchor]]

Loading…
Cancel
Save