mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Parser: Parse image.link args with with xwiki, namespace, but no title
This commit is contained in:
parent
e30828a270
commit
4182c18b1d
@ -33,6 +33,14 @@ public class Xoh_file_mgr {
|
|||||||
public void Init_by_page(Xoh_wtr_ctx hctx, Xoae_page page) {file_wtr.Init_by_page(hctx, page);}
|
public void Init_by_page(Xoh_wtr_ctx hctx, Xoae_page page) {file_wtr.Init_by_page(hctx, page);}
|
||||||
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {Write_or_queue(bfr, page, ctx, hctx, src, lnki, file_wtr.Bld_alt(Bool_.N, ctx, Xoh_wtr_ctx.Alt, src, lnki));}
|
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {Write_or_queue(bfr, page, ctx, hctx, src, lnki, file_wtr.Bld_alt(Bool_.N, ctx, Xoh_wtr_ctx.Alt, src, lnki));}
|
||||||
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) {
|
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) {
|
||||||
|
try {
|
||||||
|
file_wtr.Write_file(bfr, ctx, hctx, src, lnki, this.Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki), alt_text);
|
||||||
|
}
|
||||||
|
catch (Exception e) { // do not let fatal exceptions during link_parse break page; DATE:2017-12-02
|
||||||
|
String link_text = String_.new_u8(src, lnki.Src_bgn(), lnki.Src_end());
|
||||||
|
bfr.Add_str_u8("<span style='color:red'>FAIL.PARSER.LINK:" + link_text + "</span>");
|
||||||
|
Gfo_usr_dlg_.Instance.Warn_many("", "", "fatal err when parsing link; link=~{0} err=~{1}", link_text, Err_.Message_gplx_log(e));
|
||||||
|
}
|
||||||
file_wtr.Write_file(bfr, ctx, hctx, src, lnki, this.Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki), alt_text);
|
file_wtr.Write_file(bfr, ctx, hctx, src, lnki, this.Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki), alt_text);
|
||||||
}
|
}
|
||||||
public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xop_lnki_tkn lnki) {return Lnki_eval(exec_tid, ctx, page, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Upright(), lnki.W(), lnki.H(), lnki.Time(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Tid__media);}
|
public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xop_lnki_tkn lnki) {return Lnki_eval(exec_tid, ctx, page, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Upright(), lnki.W(), lnki.H(), lnki.Time(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Tid__media);}
|
||||||
|
@ -41,4 +41,13 @@ public class Xoh_file_wtr__image__link__tst {
|
|||||||
+ "</a>"));
|
+ "</a>"));
|
||||||
fxt.Init_xwiki_clear();
|
fxt.Init_xwiki_clear();
|
||||||
}
|
}
|
||||||
|
@Test public void Link__xwiki_empty_ns() { // handle NPE in odd case where link has xwiki,ns, but no ttl; EX:"|link=en.w:User_talk:" PAGE:en.w:Wikipedia:Teahouse/The_menu; DATE:2017-12-02
|
||||||
|
fxt.Init_xwiki_add_wiki_and_user_("en", "en.wikipedia.org");
|
||||||
|
fxt.Test_parse_page_wiki_str
|
||||||
|
( "[[File:A.png|link=en:User_talk:|abc]]", String_.Concat_lines_nl_skip_last
|
||||||
|
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\">" // NOTE: href is to "File:A.png", not "en:User_talk:"
|
||||||
|
+ "<img id=\"xoimg_0\" alt=\"abc\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" />"
|
||||||
|
+ "</a>"
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,13 @@ public class Xop_link_parser {
|
|||||||
// title-case by ns; needed to handle "link=w:Help:a" which needs to generate "w:Help:A"
|
// title-case by ns; needed to handle "link=w:Help:a" which needs to generate "w:Help:A"
|
||||||
if (page_ttl_is_valid) { // valid_ttl; parse in same ns to title-case; EX:link=w:Help:a -> Help:A; DATE:2016-01-11
|
if (page_ttl_is_valid) { // valid_ttl; parse in same ns to title-case; EX:link=w:Help:a -> Help:A; DATE:2016-01-11
|
||||||
page_ttl = wiki.Ttl_parse(page_ttl.Full_db_wo_xwiki());
|
page_ttl = wiki.Ttl_parse(page_ttl.Full_db_wo_xwiki());
|
||||||
|
|
||||||
|
// some links can be invalid; EX:"|link=en.w:User_talk:" PAGE:en.w:Wikipedia:Teahouse/The_menu; DATE:2017-12-02
|
||||||
|
if (page_ttl == null) {
|
||||||
|
page_ttl_is_valid = false;
|
||||||
|
page_bry = Bry_.Empty;
|
||||||
|
}
|
||||||
|
else
|
||||||
page_bry = page_ttl.Full_db_w_anch();
|
page_bry = page_ttl.Full_db_w_anch();
|
||||||
}
|
}
|
||||||
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(page_bry);
|
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(page_bry);
|
||||||
|
Loading…
Reference in New Issue
Block a user