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
2015-04-27 00:27:52 -04:00
parent 299e19d455
commit f4b95f5ce6
126 changed files with 1840 additions and 671 deletions

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.core.btries.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.net.*; import gplx.xowa.parsers.lnkes.*;
import gplx.xowa.wikis.*;
public class Xoh_href_parser {
private Gfo_url_parser url_parser; private Gfo_url tmp_url = new Gfo_url();
private Btrie_slim_mgr segs = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:XO_const.en; /wiki/, /site/ etc.
@@ -72,10 +73,14 @@ public class Xoh_href_parser {
}
}
}
public byte[] Build_to_bry(Xow_wiki wiki, Xoa_ttl ttl) {Build_to_bfr(tmp_bfr, wiki, ttl, Bool_.N); return tmp_bfr.Xto_bry_and_clear();}
public void Build_to_bfr(Bry_bfr bfr, Xow_wiki wiki, byte[] raw) {Build_to_bfr(bfr, wiki, wiki.Ttl_parse(raw), Bool_.N);}
public void Build_to_bfr(Bry_bfr bfr, Xow_wiki wiki, Xoa_ttl ttl) {Build_to_bfr(bfr, wiki, ttl, Bool_.N);}
public void Build_to_bfr(Bry_bfr bfr, Xow_wiki wiki, Xoa_ttl ttl, boolean force_site) {
public byte[] Build_to_bry(Xow_wiki wiki, Xoa_ttl ttl) {
synchronized (tmp_bfr) {
Build_to_bfr(tmp_bfr, wiki.App(), wiki.Domain_bry(), ttl, Bool_.N);
return tmp_bfr.Xto_bry_and_clear();
}
}
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, byte[] domain_bry, Xoa_ttl ttl) {Build_to_bfr(bfr, app, domain_bry, ttl, Bool_.N);}
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, byte[] domain_bry, Xoa_ttl ttl, boolean force_site) {
byte[] page = ttl.Full_txt_raw();
Xow_xwiki_itm xwiki = ttl.Wik_itm();
if (xwiki == null) // not an xwiki; EX: [[wikt:Word]]
@@ -88,7 +93,7 @@ public class Xoh_href_parser {
if (ttl.Anch_bgn() != 1) { // not an anchor-only; EX: "#A"
if (force_site) { // popup parser always writes as "/site/"
bfr.Add(Href_site_bry); // add "/site/"; EX: /site/
bfr.Add(wiki.Domain_bry()); // add xwiki; EX: en_dict
bfr.Add(domain_bry); // add xwiki; EX: en_dict
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
}
else
@@ -97,10 +102,17 @@ public class Xoh_href_parser {
else {} // anchor: noop
}
else { // xwiki
if (wiki.App().Xwiki_mgr__missing(xwiki.Domain_bry())) { // xwiki is not offline; use http:
bfr.Add(Href_http_bry); // add "http://"; EX: http://
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
if (app.Xwiki_mgr__missing(xwiki.Domain_bry())) { // xwiki is not offline; use http:
Bry_fmtr url_fmtr = xwiki.Url_fmtr();
if (url_fmtr == null) {
bfr.Add(Href_http_bry); // add "http://"; EX: http://
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
}
else { // url_fmtr exists; DATE:2015-04-22
url_fmtr.Bld_bfr(bfr, bfr_encoder.Xto_bry_and_clear()); // use it and pass bfr_encoder for page_name;
return;
}
}
else { // xwiki is avaiable; use /site/
bfr.Add(Href_site_bry); // add "/site/"; EX: /site/

View File

@@ -182,6 +182,10 @@ public class Xoh_href_parser_tst {
@Test public void Parse_protocol() { // PURPOSE: check that urls with form of "ftp://" return back Tid_ftp; DATE:2014-04-25
fxt .Test_parse_protocol("ftp://a.org", Xoo_protocol_itm.Tid_ftp);
}
@Test public void Build_xwiki_wikimedia_mail() { // PURPOSE: DATE:2015-04-22
fxt .Init_xwiki_by_many("mail|https://lists.wikimedia.org/mailman/listinfo/$1|Wikitech Mailing List");
fxt.Test_build("mail:A" , "https://lists.wikimedia.org/mailman/listinfo/A");
}
// @Test public void Parse_question_ttl() {fxt.Prep_raw_("/wiki/%3F").Expd_tid_(Xoh_href.Tid_wiki).Expd_full_("en.wikipedia.org/wiki/?").Expd_page_("?").Test_parse();}
// @Test public void Parse_question_w_arg() {fxt.Prep_raw_("/wiki/A%3F?action=edit").Expd_tid_(Xoh_href.Tid_wiki).Expd_full_("en.wikipedia.org/wiki/A??action=edit").Expd_page_("A??action=edit").Test_parse();}
}
@@ -203,6 +207,10 @@ class Xoh_href_parser_fxt {
app.User().Wiki().Xwiki_mgr().Add_full(alias, domain);
return this;
}
public Xoh_href_parser_fxt Init_xwiki_by_many(String raw) {
wiki.Xwiki_mgr().Add_many(Bry_.new_utf8_(raw)); // need to add to wiki's xwiki_mgr for ttl_parse
return this;
}
public Xoh_href_parser_fxt Init_hover_full_y_() {return Init_hover_full_(Bool_.Y);}
public Xoh_href_parser_fxt Init_hover_full_n_() {return Init_hover_full_(Bool_.N);}
public Xoh_href_parser_fxt Init_hover_full_(boolean v) {wiki.Gui_mgr().Cfg_browser().Link_hover_full_(v); return this;}
@@ -230,7 +238,7 @@ class Xoh_href_parser_fxt {
}
public void Test_build(String raw, String expd) {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_utf8_(raw));
href_parser.Build_to_bfr(tmp_bfr, wiki, ttl);
href_parser.Build_to_bfr(tmp_bfr, app, wiki.Domain_bry(), ttl);
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
}
public void Test_parse_protocol(String raw, byte expd_tid) {