1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Wiki: Support renamed folders (fix)

This commit is contained in:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,32 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_url__basic__tst {
private final Xoa_url_fxt fxt = new Xoa_url_fxt();
@Test public void Eq_page() {
fxt.Test_eq_page(Bool_.Y, "en.wikipedia.org/wiki/A?redirect=yes", "en.wikipedia.org/wiki/A?redirect=yes");
fxt.Test_eq_page(Bool_.N, "en.wikipedia.org/wiki/A?redirect=no" , "en.wikipedia.org/wiki/A?redirect=yes");
}
}
class Xoa_url_fxt extends Xow_url_parser_fxt { public void Test_eq_page(boolean expd, String lhs_str, String rhs_str) {
Xoa_url lhs_url = parser.Parse(Bry_.new_u8(lhs_str));
Xoa_url rhs_url = parser.Parse(Bry_.new_u8(rhs_str));
Tfds.Eq_bool(expd, lhs_url.Eq_page(rhs_url), "Eq_page");
}
}

View File

@@ -1,56 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.wikis.nss.*;
public class Xoa_url__to_str__tst {
private final Xoa_url__to_str__fxt fxt = new Xoa_url__to_str__fxt();
@Test public void Http() {fxt.Chk_to_str_href(Bool_.N, "http://a.org/b" , "http://a.org/b");}
@Test public void File() {fxt.Chk_to_str_href(Bool_.N, "file:///C/xowa/file/a.png" , "file:///C/xowa/file/a.png");}
@Test public void Abrv__page() {fxt.Chk_to_str_href(Bool_.N, "/wiki/A" , "A");}
@Test public void Abrv__anch() {fxt.Chk_to_str_href(Bool_.N, "#b" , "#b");}
@Test public void Full__page() {fxt.Chk_to_str_href(Bool_.Y, "/wiki/A" , "en.wikipedia.org/wiki/A");}
@Test public void Full__anch() {fxt.Chk_to_str_href(Bool_.Y, "#b" , "en.wikipedia.org/wiki/Page_1#b");}
@Test public void Vnt() {
Xowe_wiki zh_wiki = fxt.Prep_create_wiki("zh.wikipedia.org");
gplx.xowa.langs.vnts.Xol_vnt_regy_fxt.Init__vnt_mgr(zh_wiki.Lang().Vnt_mgr(), 0, String_.Ary("zh-hans", "zh-hant"));
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-hans/A" , "zh.wikipedia.org/zh-hans/A");
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-hant/A" , "zh.wikipedia.org/zh-hant/A");
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-cn/A" , "zh.wikipedia.org/wiki/A");
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/wiki/A" , "zh.wikipedia.org/wiki/A");
}
@Test public void Xwiki() {
fxt.Prep_add_xwiki_to_user("fr.wikipedia.org");
fxt.Chk_to_str_href(Bool_.N, "/site/fr.wikipedia.org/wiki/Page", "fr.wikipedia.org/wiki/Page");
}
@Test public void Alias() {
fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org");
Xow_wiki en_d = fxt.Prep_create_wiki("en.wiktionary.org");
en_d.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Tid__all);
fxt.Chk_to_str_href(Bool_.N, "/wiki/wikt:a" , "en.wiktionary.org/wiki/a");
}
@Test public void Unknown() {fxt.Chk_to_str_href(Bool_.N, "/wiki/{{{extlink}}}" , "");} // {{{extlink}}} not a valid title; return empty
}
class Xoa_url__to_str__fxt extends Xow_url_parser_fxt { private final Xoh_href_parser href_parser = new Xoh_href_parser();
public void Chk_to_str_href(boolean full, String raw, String expd) {Chk_to_str_href(cur_wiki, full, raw, expd);}
public void Chk_to_str_href(Xowe_wiki wiki, boolean full, String raw, String expd) {
href_parser.Parse_as_url(actl_url, Bry_.new_u8(raw), wiki, Bry__page);
this.Test__to_str(full, expd);
}
private static final byte[] Bry__page = Bry_.new_a7("Page_1");
}

View File

@@ -1,25 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoav_url {
public byte[] Wiki_bry() {return wiki_bry;} public void Wiki_bry_(byte[] v) {wiki_bry = v;} private byte[] wiki_bry;
public byte[] Page_bry() {return page_bry;} public void Page_bry_(byte[] v) {page_bry = v;} private byte[] page_bry;
public byte[] Anch_bry() {return anch_bry;} public void Anch_bry_(byte[] v) {anch_bry = v;} private byte[] anch_bry;
public byte[] Qarg_bry() {return qarg_bry;} public void Qarg_bry_(byte[] v) {qarg_bry = v;} private byte[] qarg_bry;
public void Clear() {wiki_bry = page_bry = null;}
}

View File

@@ -1,43 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoav_url_parser {
private static final byte[] Bry_site = Bry_.new_a7("/site/"), Bry_wiki = Bry_.new_a7("/wiki/"), Bry_http = Bry_.new_a7("http:");
public void Parse_xo_href(Xoav_url rv, byte[] src, byte[] cur_wiki_bry) {
rv.Clear();
int pos = Bry_.Has_at_bgn(src, Bry_http) ? Bry_http.length : 0; // DRD: DRD:2.2 adds "http:" to all links
int src_len = src.length;
if (Bry_.Has_at_bgn(src, Bry_site, pos, src_len))
pos = Parse_wiki(rv, src, src_len, pos);
else
rv.Wiki_bry_(cur_wiki_bry);
if (Bry_.Has_at_bgn(src, Bry_wiki, pos, src_len)) pos = Parse_page(rv, src, src_len, pos);
}
private int Parse_wiki(Xoav_url rv, byte[] src, int src_len, int pos) {
int wiki_bgn = pos + Bry_site.length;
int wiki_end = Bry_find_.Find_fwd(src, Byte_ascii.Slash, wiki_bgn, src_len); if (wiki_end == Bry_find_.Not_found) throw Err_.new_wo_type("could not find wiki_end", "src", String_.new_u8(src));
rv.Wiki_bry_(Bry_.Mid(src, wiki_bgn, wiki_end));
return wiki_end;
}
private int Parse_page(Xoav_url rv, byte[] src, int src_len, int pos) {
int page_bgn = pos + Bry_wiki.length;
int page_end = src_len;
rv.Page_bry_(Bry_.Mid(src, page_bgn, page_end));
return page_end;
}
}

View File

@@ -1,43 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoav_url_parser_tst {
@Before public void init() {fxt.Clear();} private final Xoav_url_parser_fxt fxt = new Xoav_url_parser_fxt();
@Test public void Page() {
fxt.Exec_parse_xo_href("http:/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
}
@Test public void Site() {
fxt.Exec_parse_xo_href("http:/site/en.wikipedia.org/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
}
}
class Xoav_url_parser_fxt {
private Xoav_url_parser url_parser = new Xoav_url_parser(); private Xoav_url url = new Xoav_url();
public void Clear() {
cur_wiki = Bry_.new_a7("en.wikipedia.org");
url.Clear();
}
public Xoav_url_parser_fxt Init_cur_wiki(String v) {cur_wiki = Bry_.new_u8(v); return this;} private byte[] cur_wiki;
public Xoav_url_parser_fxt Test_wiki(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Wiki_bry()); return this;}
public Xoav_url_parser_fxt Test_page(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Page_bry()); return this;}
public Xoav_url_parser_fxt Exec_parse_xo_href(String src_str) {
byte[] src_bry = Bry_.new_u8(src_str);
url_parser.Parse_xo_href(url, src_bry, cur_wiki);
return this;
}
}

View File

@@ -1,322 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.files.*;
public class Xow_url_parser {
private final Object thread_lock = new Object();
private final Gfo_url_encoder encoder;
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
private final Gfo_url_parser url_parser = new Gfo_url_parser();
private final Gfo_url_encoder gfs_encoder = Gfo_url_encoder_.New__gfs().Make();
private final Xoa_app app; private final Xow_wiki wiki; private final byte[] domain_bry;
private byte tmp_protocol_tid;
private int tmp_tid;
private byte[] tmp_raw, tmp_orig, tmp_wiki, tmp_page, tmp_anch, tmp_protocol_bry; private Gfo_qarg_itm[] tmp_qargs;
private byte[][] tmp_segs; private int tmp_segs_len;
private boolean tmp_protocol_is_relative, tmp_page_is_main, tmp_wiki_is_missing;
private byte[] tmp_vnt;
private final Xol_vnt_mgr vnt_mgr;
public Xow_url_parser(Xow_wiki wiki) {
this.app = wiki.App();
this.wiki = wiki; this.domain_bry = wiki.Domain_bry();
this.encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Xourl;
this.vnt_mgr = wiki.Type_is_edit() ? wiki.Lang().Vnt_mgr() : null;
}
public Xoa_url Parse_by_urlbar_or_null(String str) {
Xoae_app app = (Xoae_app)wiki.App();
byte[] bry = Strip_mobile_segment(Bry_.new_u8(str));
byte[] fmt = app.Gui_mgr().Url_macro_mgr().Fmt_or_null(bry);
if (fmt != null) bry = fmt;
Xoa_url rv = Xoa_url.blank();
this.Parse(rv, bry, 0, bry.length); if (rv.Page_bry() == null) {Xoa_url_.Invalid_warn(str); return null;}
byte[] wiki_bry = rv.Wiki_bry();
Xow_xwiki_itm xwiki_itm = app.User().Wikii().Xwiki_mgr().Get_by_key(wiki_bry);
if (xwiki_itm == null) {Xoa_url_.Invalid_warn(str); return null;} // if wiki doesn't exist, warn and return nothing; DATE:2015-08-25
if (rv.Page_is_main()) { // Main_Page requested; EX: "zh.wikipedia.org"; "zh.wikipedia.org/wiki/"; DATE:2014-02-16
Xow_wiki wiki_itm = app.Wiki_mgri().Get_by_or_make_init_y(wiki_bry); // NOTE: must call Init to load Main_Page; only call if from url_bar, else all sister wikis will be loaded when parsing Sister_wikis panel
rv.Page_bry_(wiki_itm.Props().Main_page());
}
Xow_wiki parse_wiki = wiki;
if (!Bry_.Eq(wiki_bry, wiki.Domain_bry())) // NOTE: url's wiki is different than current wiki
parse_wiki = app.Wiki_mgr().Get_by_or_make_init_y(wiki_bry); // NOTE: change parse_wiki to url's wiki; needed to handle transition from home to en.d or other case-sensitivity wiki; EX: "d:earth" -> "earth" x> "Earth"; DATE:2016-04-28
Xoa_ttl ttl = parse_wiki .Ttl_parse(rv.Page_bry()); // NOTE: parse to ttl to get proper casing; EX: "earth" -> "Earth" x> "earth"; DATE:2016-03-25
rv.Page_bry_(ttl.Full_db());
return rv;
}
public Gfo_url_parser Url_parser() {return url_parser;}
public Xoa_url Parse(byte[] src) {Xoa_url rv = Xoa_url.blank(); Parse(rv, src); return rv;}
public Xoa_url Parse(byte[] src, int bgn, int end) {Xoa_url rv = Xoa_url.blank(); Parse(rv, src, bgn, end); return rv;}
public boolean Parse(Xoa_url rv, byte[] src) {return Parse(rv, src, 0, src.length);}
public boolean Parse(Xoa_url rv, byte[] src, int bgn, int end) {
synchronized (thread_lock) {
if (end - bgn == 0) {Init_tmp_vars(Gfo_url.Empty); Make(rv); return false;}
tmp_orig = (bgn == 0 && end == src.length) ? src : Bry_.Mid(src, bgn, end);
// src = encoder.Decode(src, bgn, end); // NOTE: must decode any url-encoded parameters; TOMBSTONE:do not auto-decode DATE:2016-10-10
int src_len = end - bgn;
Gfo_url gfo_url = url_parser.Parse(src, bgn, end); // parse to plain gfo_url
Init_tmp_vars(gfo_url);
if (src[0] == Byte_ascii.Hash) // src is anch; EX: #A
Bld_anch();
else {
switch (tmp_protocol_tid) {
case Gfo_protocol_itm.Tid_file:
if (src_len > 5 && src[5] != Byte_ascii.Slash) // src is ttl in [[File]] ns; EX: "File:A.png"
Bld_page_by_file_ns();
else // src is file:///; EX: EX: "file:///C:/A.png"
tmp_tid = Xoa_url_.Tid_file;
break;
case Gfo_protocol_itm.Tid_xowa:
Bld_xowa();
break;
case Gfo_protocol_itm.Tid_http:
case Gfo_protocol_itm.Tid_https:
case Gfo_protocol_itm.Tid_relative_1:
if (tmp_protocol_tid == Gfo_protocol_itm.Tid_relative_1) // interpret relative protocol links to match wiki's protocol; EX: [//a.org] -> https://a.org for all WMF wikis; DATE:2015-07-27
tmp_protocol_tid = wiki.Props().Protocol_tid();
if (app.User().Wikii().Xwiki_mgr().Get_by_key(tmp_wiki) != null)// src is offline wiki; EX: http://fr.wikipedia.org/wiki/A
Bld_page(0);
else if (Bry_.Eq(tmp_wiki, Bry_upload_wikimedia_org)) // src is upload.wikimedia.org; EX: "http://upload.wikimedia.org/wikipedia/commons/a/ab/C.svg"
Bld_page_from_upload_wikimedia_org();
else // src is unknown site: EX: "http://a.org"
tmp_tid = Xoa_url_.Tid_inet;
break;
case Gfo_protocol_itm.Tid_unknown:
Bld_page(0);
break;
default:
tmp_tid = Xoa_url_.Tid_inet;
break;
}
}
Bld_qargs();
if (tmp_page_is_main) tmp_page = Xoa_page_.Main_page_bry_empty;
if (tmp_anch != null) {
byte[] anchor_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Encode(tmp_anch); // reencode for anchors (which use . encoding, not % encoding); PAGE:en.w:Enlightenment_Spain#Enlightened_despotism_.281759%E2%80%931788.29
tmp_anch = anchor_bry;
}
Make(rv);
return true;
}
}
private void Init_tmp_vars(Gfo_url gfo_url) {
tmp_tid = Xoa_url_.Tid_unknown;
tmp_raw = gfo_url.Raw();
tmp_wiki = gfo_url.Segs__get_at_1st();
tmp_page = gfo_url.Segs__get_at_nth();
tmp_anch = gfo_url.Anch(); tmp_qargs = gfo_url.Qargs();
tmp_wiki_is_missing = false;
tmp_page_is_main = false;
tmp_protocol_tid = gfo_url.Protocol_tid();
tmp_protocol_bry = gfo_url.Protocol_bry();
tmp_protocol_is_relative = gfo_url.Protocol_tid() == Gfo_protocol_itm.Tid_relative_1; // gfo_url.Protocol_is_relative();
if (tmp_protocol_is_relative) tmp_protocol_tid = Gfo_protocol_itm.Tid_https;
tmp_vnt = null;
tmp_segs = gfo_url.Segs();
tmp_segs_len = tmp_segs.length;
}
private Xoa_url Make(Xoa_url rv) {
rv.Ctor
( tmp_tid, tmp_orig, tmp_raw, tmp_protocol_tid, tmp_protocol_bry, tmp_protocol_is_relative
, tmp_wiki, tmp_page, tmp_qargs, tmp_anch
, tmp_segs, tmp_vnt, tmp_wiki_is_missing, Bry_.Eq(tmp_wiki, wiki.Domain_bry()), tmp_page_is_main);
return rv;
}
private void Bld_anch() {
tmp_tid = Xoa_url_.Tid_anch;
tmp_wiki = domain_bry; tmp_wiki_is_missing = true;
tmp_page = Bry_.Empty;
}
private void Bld_xowa() {
tmp_tid = Xoa_url_.Tid_xcmd;
tmp_page = Bry_.Mid(tmp_raw, Gfo_protocol_itm.Len_xcmd); // NOTE: just get String after protocol; anchor (#) or query params (?) must not be parsed
tmp_page = gfs_encoder.Decode(tmp_page); // NOTE: should be decoded; EX: %20 -> " "
}
private void Bld_page_by_file_ns() {
tmp_tid = Xoa_url_.Tid_page;
tmp_segs[0] = Bry_.Add(Bry_file, tmp_wiki);
tmp_page = Make_page_from_segs(0);
tmp_wiki = domain_bry; tmp_wiki_is_missing = true;
}
private void Bld_page_from_upload_wikimedia_org() {
// orig: https://upload.wikimedia.org/wikipedia/commons/a/ab/A.jpg
// thum: https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/A.jpg/220px-A.jpg
byte[] domain_type = tmp_segs[1]; // seg[0] = type; EX: "/wikipedia/"
byte[] lang = tmp_segs[2]; // seg[1] = lang; EX: "en", "fr"; "commons"
if (Bry_.Eq(lang, Xow_domain_tid_.Bry__commons)) // commons links will have fmt of "/wikipedia/commons"; must change to wikimedia
domain_type = Xow_domain_tid_.Bry__wikimedia;
tmp_wiki = tmp_bfr.Clear()
.Add(lang).Add_byte(Byte_ascii.Dot) // add lang/type + .; EX: "en."; "fr."; "commons."
.Add(domain_type).Add(Bry_dot_org) // add type + .org; EX: "wikipedia.org"; "wikimedia.org";
.To_bry_and_clear();
if (tmp_segs_len > 6 && Bry_.Eq(tmp_segs[3], Xof_url_bldr.Bry_thumb)) tmp_page = tmp_segs[6]; // if "/thumb/", set page from seg[n-1] to seg[6]; EX: using thumb example above, "A.jpg", not "220px-A.jpg"
tmp_page = Bry_.Add(Bry_file, tmp_page); // always add "File:" ns
}
private boolean Find_wiki(byte[] domain) {
Xow_xwiki_itm xwiki = app.User().Wikii().Xwiki_mgr().Get_by_key(domain); // check if tmp_wiki is known wiki
if (xwiki != null) {
if (!Bry_.Eq(xwiki.Domain_bry(), domain)) // ignore aliases by checking that xwiki.domain == wiki; avoids false lang matches like "so/page" or "C/page"; PAGE: ca.s:So/Natura_del_so; DATE:2014-04-26; PAGE:no.b:C/Variabler; DATE:2014-10-14
xwiki = null;
}
if (xwiki != null) return true;
if (app.Wiki_mgri().Has(domain)) return true;
return Byte_.In(tmp_protocol_tid, Gfo_protocol_itm.Tid_http, Gfo_protocol_itm.Tid_https);
}
private void Bld_page(int bgn_seg) {
tmp_tid = Xoa_url_.Tid_page;
tmp_wiki = tmp_segs[bgn_seg]; // try seg[0] as wiki
int seg_idx = bgn_seg + 1;
boolean wiki_exists = Find_wiki(tmp_wiki);
if (wiki_exists) {
int tmp_seg_idx = Bld_main_page_or_vnt(bgn_seg);
seg_idx = tmp_seg_idx;
int tmp_vnt_seg = bgn_seg + 1;
if (vnt_mgr.Enabled() && tmp_vnt_seg < tmp_segs_len && vnt_mgr.Regy().Has(tmp_segs[tmp_vnt_seg])) { // check if "/zh-hans/"
tmp_vnt = tmp_segs[tmp_vnt_seg];
}
if (tmp_seg_idx == -1) return; // main_page or vnt; exit
}
else {
tmp_wiki = domain_bry; // tmp_wiki is current
tmp_wiki_is_missing = true;
--seg_idx; // move seg_idx back to wiki
}
tmp_page = tmp_segs[seg_idx];
byte[] frag = Bld_page_by_alias(tmp_page); // handle en.wikipedia.org/wiki/fr:A
if (frag != null) {
tmp_segs[seg_idx] = frag; // alias found; set page to rhs; EX: "fr:A" -> "A"
if (frag.length == 0) // handle main_page; EX: "fr:"
tmp_page_is_main = true;
}
tmp_page = Make_page_from_segs(seg_idx); // join segs together; needed for nesting; EX: A/B/C
}
private int Bld_main_page_or_vnt(int bgn_seg) {
int rv = -1;
switch (tmp_segs_len - bgn_seg) {
case 1: // "en.wikipedia.org"
if (Bry_.Eq(tmp_segs[0 + bgn_seg], Xow_domain_itm_.Bry__home)) { // ignore "home" which should always go to "home" of current wiki, not "home" wiki
tmp_wiki = domain_bry;
return 0;
}
else {
tmp_page_is_main = true;
return -1;
}
case 2: // "en.wikipedia.org/"; "en.wikipedia.org/wiki"; "en.wikipedia.org/A"
if (Bry_.Len_eq_0(tmp_segs[1 + bgn_seg])) { // check for "en.wikipedia.org/"
tmp_page_is_main = true;
return -1;
}
else
rv = 1;
break;
case 3:
if (Bry_.Len_gt_0(tmp_segs[2 + bgn_seg])) // check only for "en.wikipedia.org/wiki/" where seg[2] is blank
return 2;
else
rv = 2;
break;
default:
return 2;
}
byte[] mid = tmp_segs[1 + bgn_seg];
if (Bry_.Eq(mid, Bry_wiki)) { // check if "/wiki/"
tmp_page_is_main = true;
return -1;
}
else
return rv;
}
private byte[] Bld_page_by_alias(byte[] bry) {
if (bry == null) return null;
int colon_pos = Bry_find_.Find_fwd(bry, Byte_ascii.Colon); // check for colon; EX: commons:Earth
if (colon_pos == Bry_find_.Not_found) return null; // no colon
Xow_wiki alias_wiki = wiki; // default alias_wiki to cur_wiki
if (!tmp_wiki_is_missing) // tmp_wiki exists; use it for alias wikis; DATE:2015-09-17
alias_wiki = wiki.App().Wiki_mgri().Get_by_or_make_init_n(tmp_wiki);
Xow_xwiki_itm alias_itm = alias_wiki.Xwiki_mgr().Get_by_mid(bry, 0, colon_pos); // check for alias;
if (alias_itm == null) return null; // colon-word is not alias; EX:A:B
Xow_ns_mgr ns_mgr = tmp_wiki_is_missing ? wiki.Ns_mgr() : wiki.App().Dbmeta_mgr().Ns__get_or_load(tmp_wiki);
if (ns_mgr.Names_get_or_null(alias_itm.Key_bry()) != null) // special case to handle collision between "wikipedia" alias and "Wikipedia" namespace; if alias exists as ns, ignore it; EX:sv.wikipedia.org/wiki/Wikipedia:Main_Page DATE:2015-07-31
return null;
byte[] rv = Bry_.Mid(bry, colon_pos + 1);
tmp_wiki = alias_itm.Domain_bry();
return rv;
}
private void Bld_qargs() {
int qargs_len = tmp_qargs.length;
for (int i = 0; i < qargs_len; ++i) {
Gfo_qarg_itm qarg = tmp_qargs[i];
if (Bry_.Eq(qarg.Key_bry(), Qarg__title))
tmp_page = qarg.Val_bry(); // handle /w/index.php?title=Earth
}
}
private byte[] Make_page_from_segs(int bgn) {
if (tmp_segs_len - bgn == 1) return tmp_segs[tmp_segs_len - 1]; // only 1 item; just return it; don't build bry
for (int i = bgn; i < tmp_segs_len; i++) {
if (i != bgn) tmp_bfr.Add_byte(Byte_ascii.Slash);
tmp_bfr.Add(tmp_segs[i]);
}
return tmp_bfr.To_bry_and_clear();
}
public String Build_str(Xoa_url url) { // transform to "canonical" form that fits url box for both XOWA and Mozilla Firefox
tmp_bfr.Add(url.Wiki_bry()); // add wiki; EX: "en.wikipedia.org"
tmp_bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/" EX: "/wiki/"
tmp_bfr.Add(encoder.Decode(url.Page_bry())); // add page; EX: "A"
int args_len = url.Qargs_ary().length;
if (args_len > 0) {
for (int i = 0; i < args_len; i++) {
byte dlm = i == 0 ? Byte_ascii.Question : Byte_ascii.Amp;
tmp_bfr.Add_byte(dlm);
Gfo_qarg_itm arg = url.Qargs_ary()[i];
tmp_bfr.Add(arg.Key_bry()).Add_byte(Byte_ascii.Eq).Add(arg.Val_bry());
}
}
if (url.Anch_bry() != null)
tmp_bfr.Add_byte(Byte_ascii.Hash).Add(url.Anch_bry()); // add anchor; EX: "#B"
return tmp_bfr.To_str_and_clear();
}
private static byte[] Strip_mobile_segment(byte[] v) {// DATE:2014-05-03
int pos = Bry_find_.Find_fwd(v, Byte_ascii.Dot);
if ( pos == Bry_find_.Not_found // no dot; EX: "A"
|| pos + 2 >= v.length // not enough space for .m.; EX: "A.b"
)
return v;
switch (v[pos + 1]) { // check for m
case Byte_ascii.Ltr_M:
case Byte_ascii.Ltr_m:
break;
default:
return v;
}
if (v[pos + 2] != Byte_ascii.Dot) return v;
return Bry_.Add(Bry_.Mid(v, 0, pos), Bry_.Mid(v, pos + 2)); // skip ".m"
}
private static final byte[] Qarg__title = Bry_.new_a7("title");
private static final byte[]
Bry_upload_wikimedia_org = Bry_.new_a7("upload.wikimedia.org")
, Bry_file = Bry_.new_a7("File:") // NOTE: File does not need i18n; is a canonical namespace
, Bry_wiki = Bry_.new_a7("wiki")
;
public static final byte[]
Bry_dot_org = Bry_.new_a7(".org")
;
}

View File

@@ -1,42 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xow_url_parser__proto_tst {
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
@Test public void Relative() {
tstr.Exec__parse("//en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A");
}
@Test public void Http__basic() {
tstr.Exec__parse("http://en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A");
}
@Test public void Upload__basic() {
tstr.Prep_add_xwiki_to_user("commons.wikimedia.org"); // NOTE: need to add xwiki to be able to resolve "/commons/"
tstr.Exec__parse("http://upload.wikimedia.org/wikipedia/commons/a/ab/C.svg").Test__wiki("commons.wikimedia.org").Test__page("File:C.svg"); // orig
tstr.Exec__parse("http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220px-A.png").Test__wiki("commons.wikimedia.org").Test__page("File:A.png"); // thum
}
@Test public void File__basic() {
tstr.Exec__parse("file:///C:/a/b/c").Test__tid(Xoa_url_.Tid_file);
}
@Test public void Ftp__basic() {
tstr.Exec__parse("ftp://en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_inet);
}
@Test public void Extended() {
tstr.Exec__parse("http://en.wikipedia.org/w/index.php?A=B").Test__wiki("en.wikipedia.org").Test__page("index.php").Test__qargs("?A=B").Test__anch(null);
}
}

View File

@@ -1,64 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xow_url_parser__qarg__tst {
private final Xow_url_parser_fxt fxt = new Xow_url_parser_fxt();
@Test public void Redirect() {
fxt.Exec__parse("A?redirect=no").Test__wiki("en.wikipedia.org").Test__page("A").Test__qargs("?redirect=no");
}
@Test public void Action_is_edit() {
fxt.Exec__parse("A?action=edit").Test__wiki("en.wikipedia.org").Test__page("A").Test__action_is_edit_y();
}
@Test public void Assert_state_cleared() { // PURPOSE.fix: action_is_edit (et. al.) was not being cleared on parse even though Xoa_url reused; DATE:20121231
fxt.Exec__parse("A?action=edit") .Test__action_is_edit_y();
fxt.Exec__parse_reuse("B") .Test__action_is_edit_n();
}
@Test public void Query_arg() { // PURPOSE.fix: query args were not printing out
fxt.Exec__parse("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes").Test__build_str_is_same();
}
@Test public void Dupe_key() {
fxt.Exec__parse("A?B=C1&B=C2").Test__page("A").Test__qargs("?B=C1&B=C2");
}
@Test public void Question_is_eos() {
fxt.Exec__parse("A?").Test__wiki("en.wikipedia.org").Test__page("A?").Test__qargs("");
}
@Test public void Question_is_page() {
fxt.Exec__parse("A?B").Test__wiki("en.wikipedia.org").Test__page("A?B").Test__qargs("");
}
@Test public void Question_is_anchor() {
fxt.Exec__parse("A#b?c").Test__wiki("en.wikipedia.org").Test__page("A").Test__anch("b.3Fc");
}
@Test public void Title_remove_w() { // PURPOSE: fix /w/ showing up as seg; DATE:2014-05-30
fxt.Exec__parse("http://en.wikipedia.org/w/index.php?title=A").Test__wiki("en.wikipedia.org").Test__page("A");
}
@Test public void Ctg() {
fxt.Exec__parse("Category:A?pagefrom=A#mw-pages").Test__page("Category:A").Test__qargs("?pagefrom=A").Test__anch("mw-pages");
}
@Test public void Anch() {
fxt.Exec__parse("A?k1=v1#anch");
fxt.Test__page("A");
fxt.Test__anch("anch");
fxt.Test__qargs("?k1=v1");
fxt.Test__to_str("en.wikipedia.org/wiki/A?k1=v1#anch");
}
// DELETED: this is wrong as url should not handle html_entities like &#61; instead # should strictly designate anch_href; DATE:2016-10-10
// @Test public void Encoded() {
// fxt.Exec__parse("en.wikipedia.org/wiki/A?action&#61;edit&preload&#61;B").Test__wiki("en.wikipedia.org").Test__page("A").Test__qargs("?action=&#61;edit=&preload=&=").Test__anch("61.3BB"); // NOTE: this is wrong; fix later
// }
}

View File

@@ -1,56 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xow_url_parser__ttl_tst {
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
@Test public void Name() {
tstr.Exec__parse("A").Test__wiki("en.wikipedia.org").Test__page("A");
}
@Test public void Sub_1() {
tstr.Exec__parse("A/b").Test__wiki("en.wikipedia.org").Test__page("A/b");
}
@Test public void Sub_2() {
tstr.Exec__parse("A/b/c").Test__wiki("en.wikipedia.org").Test__page("A/b/c");
}
@Test public void Anch() {
tstr.Exec__parse("A#b").Test__wiki("en.wikipedia.org").Test__page("A").Test__anch("b");
}
@Test public void Anch_w_slash() { // PURPOSE: A/b#c/d was not parsing correctly; PAGE:en.w:Enlightenment_Spain#Enlightened_despotism_.281759%E2%80%931788.29
tstr.Exec__parse("A/b#c/d").Test__page("A/b").Test__anch("c.2Fd");
}
@Test public void Ns_category() {
tstr.Exec__parse("Category:A").Test__wiki("en.wikipedia.org").Test__page("Category:A");
}
@Test public void Main_page__basic() {
tstr.Exec__parse("en.wikipedia.org") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
tstr.Exec__parse("en.wikipedia.org/") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
tstr.Exec__parse("en.wikipedia.org/wiki") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
tstr.Exec__parse("en.wikipedia.org/wiki/") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
tstr.Exec__parse("en.wikipedia.org/wiki/A") .Test__wiki("en.wikipedia.org").Test__page_is_main_n();
}
@Test public void Ns_file__basic() {// PURPOSE: "File:A" should not be mistaken for "file:///" ns
tstr.Exec__parse("File:A").Test__wiki("en.wikipedia.org").Test__page("File:A");
}
@Test public void Ns_file__nested() {// PURPOSE: handle fictitious "File:A/B/C.png"
tstr.Exec__parse("File:A/B/C.png").Test__wiki("en.wikipedia.org").Test__page("File:A/B/C.png"); // should not be C.png b/c of Gfo_url_parser_old
}
@Test public void Anch__basic() {// DATE:2015-07-26
tstr.Exec__parse("#A").Test__tid(Xoa_url_.Tid_anch).Test__wiki_is_missing(true).Test__page("").Test__anch("A");
}
}

View File

@@ -1,68 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xow_url_parser__url_bar_tst {
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
@Test public void Basic() {
tstr.Exec__parse_from_url_bar("Page_1").Test__to_str("en.wikipedia.org/wiki/Page_1"); // basic
}
@Test public void Lang() {
tstr.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org");
tstr.Exec__parse_from_url_bar("uk").Test__to_str("en.wikipedia.org/wiki/Uk"); // lang-like page (uk=Ukraine) should not try to open wiki; DATE:2014-02-07
}
@Test public void Lang_like() {
tstr.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org", "http://~{1}.wikipedia.org"); // NOTE: fmt needed for Type_is_lang
tstr.Exec__parse_from_url_bar("uk/A").Test__to_str("en.wikipedia.org/wiki/Uk/A"); // uk/A should not try be interpreted as wiki="uk" page="A"; DATE:2014-04-26
}
@Test public void Macro() {
tstr.Prep_add_xwiki_to_user("fr.wikisource.org");
tstr.Exec__parse_from_url_bar("fr.s:Auteur:Shakespeare").Test__to_str("fr.wikisource.org/wiki/Auteur:Shakespeare"); // url_macros
}
@Test public void Main_page__home() {
tstr.Exec__parse_from_url_bar("home").Test__to_str("en.wikipedia.org/wiki/Home"); // home should go to current wiki's home; DATE:2014-02-09
tstr.Exec__parse_from_url_bar("home/wiki/Main_Page").Test__to_str("home/wiki/Main_Page"); // home Main_Page should go to home; DATE:2014-02-09
}
@Test public void Main_page__zhw() {
Xowe_wiki zh_wiki = tstr.Prep_create_wiki("zh.wikipedia.org");
zh_wiki.Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
tstr.Exec__parse_from_url_bar("zh.w:Main_Page") .Test__page_is_main_n().Test__to_str("zh.wikipedia.org/wiki/Main_Page");
tstr.Exec__parse_from_url_bar("zh.w:") .Test__page_is_main_y().Test__to_str("zh.wikipedia.org/wiki/Zh_Main_Page");
tstr.Exec__parse_from_url_bar("en.w:") .Test__page_is_main_y().Test__to_str("en.wikipedia.org/wiki/Main_Page"); // old bug: still stuck at zh main page due to reused objects
}
@Test public void Mobile() { // PURPOSE: handle mobile links; DATE:2014-05-03
tstr.Exec__parse_from_url_bar("en.m.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/A"); // basic
tstr.Exec__parse_from_url_bar("en.M.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/A"); // upper
tstr.Exec__parse_from_url_bar("A" ).Test__to_str("en.wikipedia.org/wiki/A"); // bounds-check: 0
tstr.Exec__parse_from_url_bar("A." ).Test__to_str("en.wikipedia.org/wiki/A."); // bounds-check: 1
tstr.Exec__parse_from_url_bar("A.b" ).Test__to_str("en.wikipedia.org/wiki/A.b"); // bounds-check: 2
tstr.Exec__parse_from_url_bar("A.b.m." ).Test__to_str("en.wikipedia.org/wiki/A.b.m."); // false-match
tstr.Exec__parse_from_url_bar("en.x.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/En.x.wikipedia.org/wiki/A"); // fail
}
@Test public void Missing_page() {
tstr.Exec__parse_from_url_bar("http://a.org").Test__is_null(); // unknown wiki; return null;
tstr.Exec__parse_from_url_bar("http://en.wikipedia.org").Test__to_str("en.wikipedia.org/wiki/Main_Page"); // known wiki; return Main_Page
}
@Test public void Invalid_names() {
tstr.Exec__parse_from_url_bar("http://a/b/c").Test__is_null(); // unknown url
tstr.Exec__parse_from_url_bar("war").Test__to_str("en.wikipedia.org/wiki/War"); // word looks like lang, but is actually page; default to current
}
@Test public void Proper_case() {
tstr.Exec__parse_from_url_bar("a" ).Test__to_str("en.wikipedia.org/wiki/A"); // "a" -> "A" x> "a"
}
}

View File

@@ -1,41 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xow_url_parser__wiki_tst {
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
@Test public void Basic() {
tstr.Exec__parse("en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_page).Test__wiki("en.wikipedia.org").Test__page("A");
}
@Test public void No_wiki() { // PURPOSE: no "/wiki/"
tstr.Exec__parse("en.wikipedia.org/A").Test__wiki("en.wikipedia.org").Test__page("A");
}
@Test public void Nested() {
tstr.Exec__parse("en.wikipedia.org/wiki/A/b").Test__wiki("en.wikipedia.org").Test__page("A/b");
}
@Test public void Slash() {
tstr.Exec__parse("en.wikipedia.org/wiki//A").Test__wiki("en.wikipedia.org").Test__page("/A");
tstr.Exec__parse("en.wikipedia.org/wiki/A//b").Test__wiki("en.wikipedia.org").Test__page("A//b");
tstr.Exec__parse("en.wikipedia.org/wiki///A").Test__wiki("en.wikipedia.org").Test__page("//A");
}
@Test public void Vnt() {
Xowe_wiki wiki = tstr.Wiki();
gplx.xowa.langs.vnts.Xol_vnt_regy_fxt.Init__vnt_mgr(wiki.Lang().Vnt_mgr(), 0, String_.Ary("zh-hans", "zh-hant"));
tstr.Exec__parse("en.wikipedia.org/zh-hans/A").Test__wiki("en.wikipedia.org").Test__page("A").Test__vnt("zh-hans");
}
}

View File

@@ -1,31 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xow_url_parser__xcmd_tst {
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
@Test public void Basic() {
tstr.Exec__parse("xowa-cmd:xowa.app.version").Test__tid(Xoa_url_.Tid_xcmd).Test__page("xowa.app.version");
}
@Test public void Encoded() {
tstr.Exec__parse("xowa-cmd:a%22b*c").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a\"b*c");
}
@Test public void Ignore_anchor_and_qargs() {
tstr.Exec__parse("xowa-cmd:a/b/c?d=e#f").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a/b/c?d=e#f");
}
}

View File

@@ -1,80 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*; import gplx.xowa.wikis.nss.*;
public class Xow_url_parser__xwiki_tst {
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
@Test public void Commons() { // PURPOSE: "C" was being picked up as an xwiki to commons; PAGE:no.b:C/Variabler; DATE:2014-10-14
tstr.Prep_add_xwiki_to_user("c", "commons.wikimedia.org"); // add alias of "c"
tstr.Exec__parse("C/D").Test__tid(Xoa_url_.Tid_page).Test__wiki("en.wikipedia.org").Test__page("C/D"); // should use current wiki (enwiki), not xwiki to commons; also, page should be "C/D", not "D"
}
@Test public void Parse_lang() {
tstr.Prep_add_xwiki_to_wiki("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/~{0}");
tstr.Exec__parse("http://en.wikipedia.org/wiki/fr:A").Test__tid(Xoa_url_.Tid_page).Test__wiki("fr.wikipedia.org").Test__page("A");
}
@Test public void Alias_wiki() {
tstr.Prep_add_xwiki_to_wiki("s", "en.wikisource.org");
tstr.Exec__parse("s:A/b/c").Test__wiki("en.wikisource.org").Test__page("A/b/c");
}
@Test public void Xwiki_no_segs() { // PURPOSE: handle xwiki without full url; EX: "commons:Commons:Media_of_the_day"; DATE:2014-02-19
tstr.Prep_add_xwiki_to_wiki("s", "en.wikisource.org");
tstr.Exec__parse("s:Project:A").Test__wiki("en.wikisource.org").Test__page("Project:A");
}
@Test public void Domain_only() {
tstr.Prep_add_xwiki_to_user("fr.wikipedia.org");
tstr.Exec__parse("fr.wikipedia.org").Test__wiki("fr.wikipedia.org").Test__page("");
}
@Test public void Domain_and_wiki() {
tstr.Prep_add_xwiki_to_user("fr.wikipedia.org");
tstr.Exec__parse("fr.wikipedia.org/wiki").Test__wiki("fr.wikipedia.org").Test__page("");
}
@Test public void Domain_and_wiki_w_http() {
tstr.Prep_add_xwiki_to_user("fr.wikipedia.org");
tstr.Exec__parse("http://fr.wikipedia.org/wiki").Test__wiki("fr.wikipedia.org").Test__page("");
}
@Test public void Namespace_in_different_wiki() { // PURPOSE.fix: namespaced titles would default to default_wiki instead of current_wiki
Xowe_wiki en_s = tstr.Prep_create_wiki("en.wikisource.org");
tstr.Exec__parse(en_s, "Category:A").Test__wiki("en.wikisource.org").Test__page("Category:A");
}
@Test public void Case_sensitive() {
// tstr.Exec__parse("en.wikipedia.org/wiki/a").Test__wiki("en.wikipedia.org").Test__page("A");
Xowe_wiki en_d = tstr.Prep_create_wiki("en.wiktionary.org");
Xow_ns_mgr ns_mgr = en_d.Ns_mgr();
ns_mgr.Ns_main().Case_match_(Xow_ns_case_.Tid__all);
tstr.Exec__parse("en.wiktionary.org/wiki/a").Test__wiki("en.wiktionary.org").Test__page("a");
ns_mgr.Ns_category().Case_match_(Xow_ns_case_.Tid__all);
tstr.Exec__parse("en.wiktionary.org/wiki/Category:a").Test__wiki("en.wiktionary.org").Test__page("Category:a");
tstr.Exec__parse("en.wiktionary.org/wiki/A/B/C").Test__page("A/B/C");
}
@Test public void Xwiki__to_enwiki() { // PURPOSE: handle alias of "wikipedia" and sv.wikipedia.org/wiki/Wikipedia:Main_Page; DATE:2015-07-31
Xowe_wiki xwiki = tstr.Prep_create_wiki("sv.wikipedia.org");
tstr.Prep_xwiki(xwiki, "wikipedia", "en.wikipedia.org", null);
tstr.Prep_get_ns_mgr_from_meta("sv.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Wikipedia");
tstr.Exec__parse(xwiki, "sv.wikipedia.org/wiki/wikipedia:X").Test__wiki("sv.wikipedia.org").Test__page("wikipedia:X");
tstr.Exec__parse(xwiki, "sv.wikipedia.org/wiki/Wikipedia:X").Test__wiki("sv.wikipedia.org").Test__page("Wikipedia:X");
}
@Test public void Xwiki__to_ns() { // PURPOSE: handle alias of "wikipedia" in current, but no "Wikipedia" ns in other wiki; PAGE:pt.w:Wikipedia:P<>gina_de_testes DATE:2015-09-17
tstr.Prep_create_wiki("pt.wikipedia.org");
tstr.Prep_get_ns_mgr_from_meta("pt.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Project"); // clear ns_mgr and add only "Project" ns, not "Wikipedia" ns
tstr.Prep_xwiki(tstr.Wiki(), "wikipedia", "en.wikipedia.org", null); // add alias of "wikipedia" in current wiki
tstr.Exec__parse(tstr.Wiki(), "pt.wikipedia.org/wiki/Wikipedia:X").Test__wiki("pt.wikipedia.org").Test__page("Wikipedia:X"); // should get "pt.wikipedia.org", not "en.wikipedia.org" (through alias)
}
}

View File

@@ -1,83 +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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.wikis.nss.*;
public class Xow_url_parser_fxt {
protected final Xoae_app app; protected final Xowe_wiki cur_wiki;
protected final Xow_url_parser parser;
protected Xoa_url actl_url;
public Xow_url_parser_fxt() {
this.app = Xoa_app_fxt.Make__app__edit();
this.cur_wiki = Prep_create_wiki("en.wikipedia.org");
this.parser = cur_wiki.Utl__url_parser();
this.actl_url = Xoa_url.blank(); // default to blank for subclasses
}
public Xoae_app App() {return app;}
public Xowe_wiki Wiki() {return cur_wiki;}
public Xowe_wiki Prep_create_wiki(String domain) {
Xowe_wiki rv = Xoa_app_fxt.Make__wiki__edit(app, domain);
Prep_add_xwiki_to_user(domain);
return rv;
}
public Xow_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain) {return Prep_xwiki(cur_wiki, alias, domain, null);}
public Xow_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain, String fmt) {return Prep_xwiki(cur_wiki, alias, domain, fmt);}
public Xow_url_parser_fxt Prep_add_xwiki_to_user(String domain) {return Prep_xwiki(app.Usere().Wiki(), domain, domain, null);}
public Xow_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, null);}
public Xow_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain, String fmt) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, fmt);}
public Xow_url_parser_fxt Prep_xwiki(Xow_wiki wiki, String alias, String domain, String fmt) {
wiki.Xwiki_mgr().Add_by_atrs(Bry_.new_u8(alias), Bry_.new_u8(domain), Bry_.new_u8_safe(fmt));
return this;
}
public Xow_ns_mgr Prep_get_ns_mgr_from_meta(String wiki) {
return app.Dbmeta_mgr().Ns__get_or_load(Bry_.new_u8(wiki));
}
public Xow_url_parser_fxt Exec__parse(String actl_str) {return Exec__parse(cur_wiki, actl_str);}
public Xow_url_parser_fxt Exec__parse(Xow_wiki wiki, String actl_str) {
this.actl_url = wiki.Utl__url_parser().Parse(Bry_.new_u8(actl_str));
return this;
}
public Xow_url_parser_fxt Exec__parse_reuse(String actl_str) {
this.actl_url = parser.Parse(Bry_.new_u8(actl_str));
return this;
}
public Xow_url_parser_fxt Exec__parse_from_url_bar(String raw) {
this.actl_url = parser.Parse_by_urlbar_or_null(raw);
return this;
}
public Xow_url_parser_fxt Test__tid(int v) {Tfds.Eq_int(v, actl_url.Tid() , "tid"); return this;}
public Xow_url_parser_fxt Test__is_null() {Tfds.Eq_bool(true, actl_url == null); return this;}
public Xow_url_parser_fxt Test__vnt(String v) {Tfds.Eq_str(v, actl_url.Vnt_bry() , "vnt"); return this;}
public Xow_url_parser_fxt Test__wiki(String v) {Tfds.Eq_str(v, actl_url.Wiki_bry() , "wiki"); return this;}
public Xow_url_parser_fxt Test__wiki_is_missing(boolean v) {Tfds.Eq_bool(v, actl_url.Wiki_is_missing(), "wiki_is_missing"); return this;}
public Xow_url_parser_fxt Test__page(String v) {Tfds.Eq_str(v, actl_url.Page_bry() , "page"); return this;}
public Xow_url_parser_fxt Test__qargs(String v) {Tfds.Eq_str(v, actl_url.Qargs_mgr().To_bry(), "qargs"); return this;}
public Xow_url_parser_fxt Test__page_is_main_y() {return Test__page_is_main(Bool_.Y);}
public Xow_url_parser_fxt Test__page_is_main_n() {return Test__page_is_main(Bool_.N);}
public Xow_url_parser_fxt Test__page_is_main(boolean v) {Tfds.Eq_bool(v, actl_url.Page_is_main() , "page_is_main"); return this;}
public Xow_url_parser_fxt Test__anch(String v) {Tfds.Eq_str(v, actl_url.Anch_bry(), "anch"); return this;}
public Xow_url_parser_fxt Test__action_is_edit_y() {return Test__action_is_edit_(Bool_.Y);}
public Xow_url_parser_fxt Test__action_is_edit_n() {return Test__action_is_edit_(Bool_.N);}
private Xow_url_parser_fxt Test__action_is_edit_(boolean v) {Tfds.Eq_bool(v, actl_url.Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit), "action_is_edit"); return this;}
public Xow_url_parser_fxt Test__to_str(String v) {return Test__to_str(Bool_.Y, v);}
public Xow_url_parser_fxt Test__to_str(boolean full, String v) {Tfds.Eq_str(v, actl_url.To_bry(full, Bool_.Y), "To_bry"); return this;}
public Xow_url_parser_fxt Test__build_str_is_same() {
Xow_url_parser parser = new Xow_url_parser(cur_wiki);
Tfds.Eq_str(actl_url.Raw(), parser.Build_str(actl_url), "build_str");
return this;
}
}