mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
uca category support and other changes
This commit is contained in:
@@ -60,6 +60,10 @@ public class Xoh_page_wtr_wkr {
|
||||
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(rv.To_bry_and_clear()));
|
||||
wdata_lang_wtr.Page_(null);
|
||||
|
||||
if (page_mode == Xopg_page_.Tid_read) { // EXPERIMENTAL
|
||||
new gplx.xowa.addons.htmls.includes.Xoh_include_mgr().Write(wiki, page);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -176,7 +180,7 @@ public class Xoh_page_wtr_wkr {
|
||||
}
|
||||
|
||||
// if [[Category]], render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
|
||||
if (ns_id == Xow_ns_.Tid__category) wiki.Html_mgr().Catpage_mgr().Write_catpage(tidy_bfr, wiki, page, hctx);
|
||||
if (ns_id == Xow_ns_.Tid__category) wiki.Ctg__catpage_mgr().Write_catpage(tidy_bfr, page, hctx);
|
||||
|
||||
// tidy html
|
||||
wiki.Html_mgr().Tidy_mgr().Exec_tidy(tidy_bfr, !hctx.Mode_is_hdump(), page.Url_bry_safe());
|
||||
@@ -192,8 +196,9 @@ public class Xoh_page_wtr_wkr {
|
||||
&& !wiki.Html_mgr().Importing_ctgs() // do not show categories if importing categories, page will wait for category import to be done; DATE:2014-10-15
|
||||
) {
|
||||
if (app.Mode().Tid_is_gui()) app.Usr_dlg().Prog_many("", "", "loading categories: count=~{0}", ctgs_len);
|
||||
Xoctg_pagebox_itm[] pagebox_itms = wiki.Html__ctg_pagebox_wtr().Get_catlinks_by_page(wiki, page);
|
||||
wiki.Html__ctg_pagebox_wtr().Write_pagebox(app.Ctg_mgr().Pagecats_grouping_enabled(), bfr, wiki, page, pagebox_itms);
|
||||
Xoctg_pagebox_itm[] pagebox_itms = wiki.Ctg__pagebox_wtr().Get_catlinks_by_page(wiki, page);
|
||||
boolean hidden_enabled = wiki.App().Api_root().Addon().Wikis__ctgs__hidden_enabled();
|
||||
wiki.Ctg__pagebox_wtr().Write_pagebox(hidden_enabled, bfr, wiki, page, pagebox_itms);
|
||||
}
|
||||
|
||||
// translate if variants are enabled
|
||||
|
||||
@@ -23,7 +23,6 @@ import gplx.xowa.parsers.xndes.*;
|
||||
import gplx.xowa.htmls.portal.*; import gplx.xowa.addons.htmls.tocs.*; import gplx.xowa.wikis.modules.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.htmls.tidy.*; import gplx.xowa.htmls.js.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.singles.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xow_html_mgr implements Gfo_invk {
|
||||
private final Gfo_url_encoder fsys_lnx_encoder = Gfo_url_encoder_.New__fsys_lnx().Make();
|
||||
public Xow_html_mgr(Xowe_wiki wiki) {
|
||||
@@ -53,7 +52,6 @@ public class Xow_html_mgr implements Gfo_invk {
|
||||
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private final Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
|
||||
public Xow_portal_mgr Portal_mgr() {return portal_mgr;} private Xow_portal_mgr portal_mgr;
|
||||
public Xow_module_mgr Head_mgr() {return module_mgr;} private Xow_module_mgr module_mgr;
|
||||
public Xoctg_catpage_mgr Catpage_mgr() {return catpage_mgr;} private final Xoctg_catpage_mgr catpage_mgr = new Xoctg_catpage_mgr();
|
||||
public boolean Importing_ctgs() {return importing_ctgs;} public void Importing_ctgs_(boolean v) {importing_ctgs = v;} private boolean importing_ctgs;
|
||||
public int Img_thumb_width() {return img_thumb_width;} private int img_thumb_width = 220;
|
||||
public byte[] Img_xowa_protocol() {return img_xowa_protocol;} private byte[] img_xowa_protocol;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Xow_hdump_mgr {
|
||||
public Xow_hdump_mgr__load Load_mgr() {return load_mgr;} private Xow_hdump_mgr__load load_mgr;
|
||||
public Xoh_hzip_mgr Hzip_mgr() {return hzip_mgr;} private final Xoh_hzip_mgr hzip_mgr = new Xoh_hzip_mgr();
|
||||
public void Init_by_db(Xow_wiki wiki) {
|
||||
byte dflt_zip_tid = gplx.core.ios.streams.Io_stream_.Tid_raw;
|
||||
byte dflt_zip_tid = gplx.core.ios.streams.Io_stream_tid_.Tid__raw;
|
||||
boolean dflt_hzip_enable = false;
|
||||
boolean mode_is_b256 = false;
|
||||
if (wiki.Data__core_mgr() != null) { // TEST: handle null data mgr
|
||||
|
||||
@@ -57,10 +57,11 @@ public class Xow_hdump_mgr__load {
|
||||
byte[] src = Parse(hpg, hpg.Db().Html().Zip_tid(), hpg.Db().Html().Hzip_tid(), hpg.Db().Html().Html_bry());
|
||||
|
||||
// write ctgs
|
||||
Xoctg_pagebox_itm[] pagebox_itms = wiki.Html__ctg_pagebox_wtr().Get_catlinks_by_page(wiki, hpg);
|
||||
Xoctg_pagebox_itm[] pagebox_itms = wiki.Ctg__pagebox_wtr().Get_catlinks_by_page(wiki, hpg);
|
||||
if (pagebox_itms.length > 0) {
|
||||
tmp_bfr.Add(src);
|
||||
wiki.Html__ctg_pagebox_wtr().Write_pagebox(Bool_.Y, tmp_bfr, wiki, hpg, pagebox_itms);
|
||||
tmp_bfr.Add(src);
|
||||
boolean hidden_enabled = wiki.App().Api_root().Addon().Wikis__ctgs__hidden_enabled();
|
||||
wiki.Ctg__pagebox_wtr().Write_pagebox(hidden_enabled, tmp_bfr, wiki, hpg, pagebox_itms);
|
||||
src = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ public class Xow_hdump_mgr__load {
|
||||
}
|
||||
public byte[] Decode_as_bry(Bry_bfr bfr, Xoh_page hpg, byte[] src, boolean mode_is_diff) {hzip_mgr.Hctx().Mode_is_diff_(mode_is_diff); hzip_mgr.Decode(bfr, wiki, hpg, src); return bfr.To_bry_and_clear();}
|
||||
private byte[] Parse(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (zip_tid > gplx.core.ios.streams.Io_stream_.Tid_raw)
|
||||
if (zip_tid > gplx.core.ios.streams.Io_stream_tid_.Tid__raw)
|
||||
src = zip_mgr.Unzip((byte)zip_tid, src);
|
||||
switch (hzip_tid) {
|
||||
case Xoh_hzip_dict_.Hzip__none:
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Xow_hdump_mgr__save {
|
||||
private byte[] Write(Xoh_hzip_bfr bfr, Xow_wiki wiki, Xoh_page hpg, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (hzip_tid != Xoh_hzip_dict_.Hzip__none) src = hzip_mgr.Encode_as_bry((Xoh_hzip_bfr)bfr.Clear(), wiki, hpg, src);
|
||||
src_as_hzip = src;
|
||||
if (zip_tid > gplx.core.ios.streams.Io_stream_.Tid_raw)
|
||||
if (zip_tid > gplx.core.ios.streams.Io_stream_tid_.Tid__raw)
|
||||
src = zip_mgr.Zip((byte)zip_tid, src);
|
||||
return src;
|
||||
}
|
||||
|
||||
@@ -348,6 +348,7 @@ public class Xoh_html_wtr {
|
||||
case Xop_xnde_tag_.Tid__math:
|
||||
case Xop_xnde_tag_.Tid__indicator:
|
||||
case Xop_xnde_tag_.Tid__xowa_html:
|
||||
case Xop_xnde_tag_.Tid__xowa_wiki_setup:
|
||||
case Xop_xnde_tag_.Tid__graph:
|
||||
case Xop_xnde_tag_.Tid__random_selection:
|
||||
case Xop_xnde_tag_.Tid__tabber:
|
||||
@@ -360,7 +361,7 @@ public class Xoh_html_wtr {
|
||||
break;
|
||||
default: // unknown tag
|
||||
if (tag.Restricted()) { // a; img; script; etc..
|
||||
if ( !page.Html_data().Html_restricted() // page is not marked restricted (only [[Special:]])
|
||||
if ( !page.Html_data().Html_restricted() // page is not marked restricted (only [[Special:]])
|
||||
|| page.Wiki().Domain_tid() == Xow_domain_tid_.Tid__home) { // page is in home wiki
|
||||
bfr.Add_mid(src, xnde.Src_bgn(), xnde.Src_end());
|
||||
return;
|
||||
|
||||
@@ -212,7 +212,7 @@ public class Xoh_file_wtr__basic {
|
||||
boolean a_href_is_file = true;
|
||||
if (xowa_title_bry == null) {xowa_title_bry = lnki_ttl; a_href_is_file = false;}
|
||||
link_arg = link_arg_html == null ? lnki_href : link_arg_html; // if parse fails, then assign to lnki_href; EX:link={{{1}}}
|
||||
link_arg = Gfo_url_encoder_.Href_qarg.Encode(link_arg); // must encode quotes; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan; DATE:2014-07-16
|
||||
link_arg = Gfo_url_encoder_.Href_quotes_v2.Encode(link_arg); // must encode quotes; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan; DATE:2014-07-16; changed to use "v2" so not to double encode "%" values; DATE:2016-10-10
|
||||
// if (Bry_.Len_gt_0(tmp_link_parser.Html_xowa_ttl())) lnki_ttl = tmp_link_parser.Html_xowa_ttl(); // DELETE: not sure why this is here; breaks test; DATE:2015-11-28
|
||||
img_fmtr.Add_full_img(bfr, hctx, page, src, xfer_itm, uid, link_arg, a_href_is_file, tmp_link_parser.Html_anchor_cls(), tmp_link_parser.Html_anchor_rel(), anch_ttl, Xoh_file_fmtr__basic.Escape_xowa_title(xowa_title_bry), xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, img_cls_tid, img_cls_other);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.apps.urls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_href_parser__basic__tst {
|
||||
private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt();
|
||||
@Test public void Site__basic() {
|
||||
fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_page).Test__to_str("en.wikipedia.org/wiki/A").Test__page("A");
|
||||
}
|
||||
@Test public void Site__ns_case() {
|
||||
fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/file:A").Test__page("File:A");
|
||||
}
|
||||
@Test public void Site__main_page() {
|
||||
fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/").Test__page("Main_Page").Test__page_is_main_y();
|
||||
}
|
||||
@Test public void Site__anch() {
|
||||
fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A#b_c").Test__page("A").Test__anch("b_c");
|
||||
}
|
||||
@Test public void Site__qarg() {
|
||||
fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A?action=edit").Test__page("A").Test__qargs("?action=edit");
|
||||
}
|
||||
@Test public void Site__invalid_ttl_shouldnt_fail() { // PURPOSE: invalid title shouldn't fail; EX: A{{B}} is invalid (b/c of braces);
|
||||
fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A{{B}}").Test__page("");
|
||||
}
|
||||
@Test public void Site__xwiki_cases_correctly() { // PURPOSE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:Alphabet
|
||||
Xowe_wiki en_wiktionary_org = fxt.Prep_create_wiki("en.wiktionary.org");
|
||||
en_wiktionary_org.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Tid__all);
|
||||
fxt.Prep_add_xwiki_to_user("en.wiktionary.org", "en.wiktionary.org");
|
||||
fxt.Exec__parse_as_url("/site/en.wiktionary.org/wiki/alphabet");
|
||||
fxt.Test__to_str("en.wiktionary.org/wiki/alphabet").Test__page("alphabet");
|
||||
}
|
||||
@Test public void Site__xwiki_compound() { // PURPOSE: [[[w:wikt:]] not handled; DATE:2013-07-25
|
||||
fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org");
|
||||
fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/wikt:")
|
||||
.Test__tid(Xoa_url_.Tid_page)
|
||||
.Test__page("Main_Page")
|
||||
.Test__to_str("en.wiktionary.org/wiki/Main_Page")
|
||||
;
|
||||
}
|
||||
// @Test public void Vnt() {
|
||||
// Xowe_wiki wiki = fxt.Wiki();
|
||||
// fxt.Prep_add_xwiki_to_user("zh.wikipedia.org");
|
||||
// wiki.Lang().Vnt_mgr().Enabled_(true);
|
||||
// wiki.Lang().Vnt_mgr().Vnt_grp().Add(new gplx.xowa.langs.vnts.Vnt_mnu_itm(Bry_.new_a7("zh-hans"), Bry_.new_a7("zh-hant")));
|
||||
// fxt.Exec__parse_as_url("/site/zh.wikipedia.org/zh-hant/A").Test__page("A").Chk_vnt("zh-hant");
|
||||
// }
|
||||
@Test public void Http__basic() {
|
||||
fxt.Exec__parse_as_url("http://a.org/b").Test__tid(Xoa_url_.Tid_inet);
|
||||
}
|
||||
@Test public void Prot__ftp() { // PURPOSE: check that urls with form of "ftp://" return back Tid_ftp; DATE:2014-04-25
|
||||
fxt.Exec__parse_as_url("ftp://a.org").Test__tid(Xoa_url_.Tid_inet);
|
||||
}
|
||||
@Test public void File__basic() {
|
||||
fxt.Exec__parse_as_url("file:///C/xowa/file/a.png").Test__tid(Xoa_url_.Tid_file);
|
||||
}
|
||||
@Test public void Anchor__basic() {
|
||||
fxt.Exec__parse_as_url("#a").Test__tid(Xoa_url_.Tid_anch).Test__to_str("en.wikipedia.org/wiki/Page 1#a").Test__anch("a");
|
||||
}
|
||||
@Test public void Xcmd__basic() {
|
||||
fxt.Exec__parse_as_url("/xcmd/page_edit").Test__tid(Xoa_url_.Tid_xcmd).Test__page("page_edit");
|
||||
}
|
||||
@Test public void Xowa__basic() {
|
||||
fxt.Exec__parse_as_url("xowa-cmd:a%22b*c").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a\"b*c");
|
||||
}
|
||||
// COMMENTED: this seems wrong; [//wikisource.org] should go to https://wikisource.org not https://en.wikisource.org; both sites are different; DATE:2015-08-02
|
||||
// @Test public void Site__user_wiki() {// PURPOSE: outlier for wikisource.org which is alias to en.wikisource.org; alias added in user_wiki; EX: [//wikisource.org a]; in browser, automatically goes to http://wikisource.org; in xowa, should go to /site/en.wikisource.org
|
||||
// fxt.Prep_xwiki(fxt.App().User().Wikii(), "en_wiki_alias", "en.wikipedia.org", null);
|
||||
// fxt.Exec__parse_as_url("/site/en_wiki_alias/wiki/")
|
||||
// .Test__tid(Xoa_url_.Tid_page)
|
||||
// .Test__page("Main_Page")
|
||||
// .Test__to_str("en.wikipedia.org/wiki/Main_Page")
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
class Xoh_href_parser_fxt extends Xow_url_parser_fxt { private final Xoh_href_parser href_parser = new Xoh_href_parser();
|
||||
public Xoh_href_parser_fxt Exec__parse_as_url(String raw) {
|
||||
href_parser.Parse_as_url(actl_url, Bry_.new_u8(raw), cur_wiki, Bry__page_1);
|
||||
return this;
|
||||
}
|
||||
private static final byte[] Bry__page_1 = Bry_.new_a7("Page 1");
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.apps.urls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_href_parser__qargs__tst {
|
||||
private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Exec__parse_as_url("/wiki/A?k1=v1&k2=v2");
|
||||
fxt.Test__page("A");
|
||||
fxt.Test__to_str("en.wikipedia.org/wiki/A?k1=v1&k2=v2");
|
||||
}
|
||||
@Test public void Anch() { // PURPOSE.fix: anchor was being placed before qargs; DATE:2016-10-08
|
||||
fxt.Exec__parse_as_url("/wiki/Category:A?pagefrom=A#mw-pages");
|
||||
fxt.Test__page("Category:A");
|
||||
fxt.Test__to_str("en.wikipedia.org/wiki/Category:A?pagefrom=A#mw-pages"); // was Category:A#mw-page?pagefrom=A
|
||||
}
|
||||
// FUTURE: qargs should be unencoded by default; decoded on request
|
||||
@Test public void Encoded() { // PURPOSE.fix: do not use decoded String; DATE:2016-10-08
|
||||
fxt.Exec__parse_as_url("/wiki/Category:A?pagefrom=A%26B#mw-pages");
|
||||
fxt.Test__page("Category:A");
|
||||
fxt.Test__qargs("?pagefrom=A&B");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.apps.urls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_href_parser__wiki__tst {
|
||||
private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Exec__parse_as_url("/wiki/A").Test__tid(Xoa_url_.Tid_page).Test__to_str("en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void Page__w_question() {
|
||||
fxt.Exec__parse_as_url("/wiki/%3F").Test__page("?");
|
||||
}
|
||||
@Test public void Qarg() {
|
||||
fxt.Exec__parse_as_url("/wiki/A?action=edit").Test__page("A").Test__qargs("?action=edit").Test__to_str("en.wikipedia.org/wiki/A?action=edit");
|
||||
}
|
||||
@Test public void Qarg__w_question() {
|
||||
fxt.Exec__parse_as_url("/wiki/A%3F?action=edit").Test__page("A?").Test__qargs("?action=edit");
|
||||
}
|
||||
@Test public void Anchor() {
|
||||
fxt.Exec__parse_as_url("/wiki/A#b").Test__to_str("en.wikipedia.org/wiki/A#b").Test__anch("b");
|
||||
}
|
||||
@Test public void Xwiki__only() {
|
||||
fxt.Prep_add_xwiki_to_wiki("c", "commons.wikimedia.org");
|
||||
fxt.Exec__parse_as_url("/wiki/c:").Test__page_is_main_y().Test__page("Main_Page").Test__to_str("commons.wikimedia.org/wiki/Main_Page");
|
||||
}
|
||||
@Test public void Encoded() {
|
||||
fxt.Exec__parse_as_url("/wiki/A%22b%22c").Test__page("A\"b\"c");
|
||||
}
|
||||
@Test public void Triple_slash() { // PURPOSE: handle triple slashes; PAGE:esolangs.org/wiki/Language_list; DATE:2015-11-14
|
||||
fxt.Exec__parse_as_url("/wiki////").Test__to_str("en.wikipedia.org/wiki////").Test__wiki("en.wikipedia.org").Test__page("///");
|
||||
}
|
||||
@Test public void Http() { // PURPOSE: variant of triple slashes; DATE:2015-11-14
|
||||
fxt.Exec__parse_as_url("/wiki/http://a").Test__to_str("en.wikipedia.org/wiki/Http://a").Test__wiki("en.wikipedia.org").Test__page("Http://a");
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.apps.urls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_href_parser_tst {
|
||||
private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt();
|
||||
@Test public void Wiki__basic() {
|
||||
fxt.Run_parse_by_href("/wiki/A").Chk_tid(Xoa_url_.Tid_page).Chk_to_str("en.wikipedia.org/wiki/A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Wiki__page__w_question() {
|
||||
fxt.Run_parse_by_href("/wiki/%3F").Chk_page("?");
|
||||
}
|
||||
@Test public void Wiki__qarg() {
|
||||
fxt.Run_parse_by_href("/wiki/A?action=edit").Chk_page("A").Chk_qargs("?action=edit").Chk_to_str("en.wikipedia.org/wiki/A?action=edit");
|
||||
}
|
||||
@Test public void Wiki__qarg__w_question() {
|
||||
fxt.Run_parse_by_href("/wiki/A%3F?action=edit").Chk_page("A?").Chk_qargs("?action=edit");
|
||||
}
|
||||
@Test public void Wiki__anchor() {
|
||||
fxt.Run_parse_by_href("/wiki/A#b").Chk_to_str("en.wikipedia.org/wiki/A#b").Chk_anch("b");
|
||||
}
|
||||
@Test public void Wiki__xwiki__only() {
|
||||
fxt.Prep_add_xwiki_to_wiki("c", "commons.wikimedia.org");
|
||||
fxt.Run_parse_by_href("/wiki/c:").Chk_page_is_main_y().Chk_page("Main_Page").Chk_to_str("commons.wikimedia.org/wiki/Main_Page");
|
||||
}
|
||||
@Test public void Wiki__encoded() {
|
||||
fxt.Run_parse_by_href("/wiki/A%22b%22c").Chk_page("A\"b\"c");
|
||||
}
|
||||
@Test public void Wiki__triple_slash() { // PURPOSE: handle triple slashes; PAGE:esolangs.org/wiki/Language_list; DATE:2015-11-14
|
||||
fxt.Run_parse_by_href("/wiki////").Chk_to_str("en.wikipedia.org/wiki////").Chk_wiki("en.wikipedia.org").Chk_page("///");
|
||||
}
|
||||
@Test public void Wiki__http() { // PURPOSE: variant of triple slashes; DATE:2015-11-14
|
||||
fxt.Run_parse_by_href("/wiki/http://a").Chk_to_str("en.wikipedia.org/wiki/Http://a").Chk_wiki("en.wikipedia.org").Chk_page("Http://a");
|
||||
}
|
||||
@Test public void Site__basic() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A").Chk_tid(Xoa_url_.Tid_page).Chk_to_str("en.wikipedia.org/wiki/A").Chk_page("A");
|
||||
}
|
||||
@Test public void Site__ns_case() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/file:A").Chk_page("File:A");
|
||||
}
|
||||
@Test public void Site__main_page() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/").Chk_page("Main_Page").Chk_page_is_main_y();
|
||||
}
|
||||
@Test public void Site__anch() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A#b_c").Chk_page("A").Chk_anch("b_c");
|
||||
}
|
||||
@Test public void Site__qarg() {
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A?action=edit").Chk_page("A").Chk_qargs("?action=edit");
|
||||
}
|
||||
@Test public void Site__invalid_ttl_shouldnt_fail() { // PURPOSE: invalid title shouldn't fail; EX: A{{B}} is invalid (b/c of braces);
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/A{{B}}").Chk_page("");
|
||||
}
|
||||
@Test public void Site__xwiki_cases_correctly() { // PURPOSE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:Alphabet
|
||||
Xowe_wiki en_wiktionary_org = fxt.Prep_create_wiki("en.wiktionary.org");
|
||||
en_wiktionary_org.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Tid__all);
|
||||
fxt.Prep_add_xwiki_to_user("en.wiktionary.org", "en.wiktionary.org");
|
||||
fxt.Run_parse_by_href("/site/en.wiktionary.org/wiki/alphabet");
|
||||
fxt.Chk_to_str("en.wiktionary.org/wiki/alphabet").Chk_page("alphabet");
|
||||
}
|
||||
@Test public void Site__xwiki_compound() { // PURPOSE: [[[w:wikt:]] not handled; DATE:2013-07-25
|
||||
fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org");
|
||||
fxt.Run_parse_by_href("/site/en.wikipedia.org/wiki/wikt:")
|
||||
.Chk_tid(Xoa_url_.Tid_page)
|
||||
.Chk_page("Main_Page")
|
||||
.Chk_to_str("en.wiktionary.org/wiki/Main_Page")
|
||||
;
|
||||
}
|
||||
// @Test public void Vnt() {
|
||||
// Xowe_wiki wiki = fxt.Wiki();
|
||||
// fxt.Prep_add_xwiki_to_user("zh.wikipedia.org");
|
||||
// wiki.Lang().Vnt_mgr().Enabled_(true);
|
||||
// wiki.Lang().Vnt_mgr().Vnt_grp().Add(new gplx.xowa.langs.vnts.Vnt_mnu_itm(Bry_.new_a7("zh-hans"), Bry_.new_a7("zh-hant")));
|
||||
// fxt.Run_parse_by_href("/site/zh.wikipedia.org/zh-hant/A").Chk_page("A").Chk_vnt("zh-hant");
|
||||
// }
|
||||
@Test public void Http__basic() {
|
||||
fxt.Run_parse_by_href("http://a.org/b").Chk_tid(Xoa_url_.Tid_inet);
|
||||
}
|
||||
@Test public void Prot__ftp() { // PURPOSE: check that urls with form of "ftp://" return back Tid_ftp; DATE:2014-04-25
|
||||
fxt.Run_parse_by_href("ftp://a.org").Chk_tid(Xoa_url_.Tid_inet);
|
||||
}
|
||||
@Test public void File__basic() {
|
||||
fxt.Run_parse_by_href("file:///C/xowa/file/a.png").Chk_tid(Xoa_url_.Tid_file);
|
||||
}
|
||||
@Test public void Anchor__basic() {
|
||||
fxt.Run_parse_by_href("#a").Chk_tid(Xoa_url_.Tid_anch).Chk_to_str("en.wikipedia.org/wiki/Page 1#a").Chk_anch("a");
|
||||
}
|
||||
@Test public void Xcmd__basic() {
|
||||
fxt.Run_parse_by_href("/xcmd/page_edit").Chk_tid(Xoa_url_.Tid_xcmd).Chk_page("page_edit");
|
||||
}
|
||||
@Test public void Xowa__basic() {
|
||||
fxt.Run_parse_by_href("xowa-cmd:a%22b*c").Chk_tid(Xoa_url_.Tid_xcmd).Chk_page("a\"b*c");
|
||||
}
|
||||
// COMMENTED: this seems wrong; [//wikisource.org] should go to https://wikisource.org not https://en.wikisource.org; both sites are different; DATE:2015-08-02
|
||||
// @Test public void Site__user_wiki() {// PURPOSE: outlier for wikisource.org which is alias to en.wikisource.org; alias added in user_wiki; EX: [//wikisource.org a]; in browser, automatically goes to http://wikisource.org; in xowa, should go to /site/en.wikisource.org
|
||||
// fxt.Prep_xwiki(fxt.App().User().Wikii(), "en_wiki_alias", "en.wikipedia.org", null);
|
||||
// fxt.Run_parse_by_href("/site/en_wiki_alias/wiki/")
|
||||
// .Chk_tid(Xoa_url_.Tid_page)
|
||||
// .Chk_page("Main_Page")
|
||||
// .Chk_to_str("en.wikipedia.org/wiki/Main_Page")
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
class Xoh_href_parser_fxt extends Xow_url_parser_fxt { private final Xoh_href_parser href_parser = new Xoh_href_parser();
|
||||
public Xoh_href_parser_fxt Run_parse_by_href(String raw) {
|
||||
href_parser.Parse_as_url(actl_url, Bry_.new_u8(raw), cur_wiki, Bry__page_1);
|
||||
return this;
|
||||
}
|
||||
private static final byte[] Bry__page_1 = Bry_.new_a7("Page 1");
|
||||
}
|
||||
@@ -57,6 +57,7 @@ public class Xow_popup_wrdx_mkr {
|
||||
case Xop_xnde_tag_.Tid__table: case Xop_xnde_tag_.Tid__tr: case Xop_xnde_tag_.Tid__td: case Xop_xnde_tag_.Tid__th:
|
||||
case Xop_xnde_tag_.Tid__caption: case Xop_xnde_tag_.Tid__thead: case Xop_xnde_tag_.Tid__tfoot: case Xop_xnde_tag_.Tid__tbody:
|
||||
case Xop_xnde_tag_.Tid__ref: case Xop_xnde_tag_.Tid__gallery: case Xop_xnde_tag_.Tid__imageMap: case Xop_xnde_tag_.Tid__timeline:
|
||||
case Xop_xnde_tag_.Tid__xowa_wiki_setup:
|
||||
case Xop_xnde_tag_.Tid__xowa_html: // needed for Help:Options, else \n at top of doc; DATE:2014-06-22
|
||||
add_tkn = add_subs = false; // skip tblxs
|
||||
xnde = null;
|
||||
|
||||
Reference in New Issue
Block a user