mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.5.4.1
This commit is contained in:
@@ -21,7 +21,7 @@ public class Xoa_url {
|
||||
public byte[] Wiki_bry() {return wiki_bry;} public Xoa_url Wiki_bry_(byte[] v) {wiki_bry = v; return this;} private byte[] wiki_bry;
|
||||
public byte[] Page_bry() {return page_bry;} public Xoa_url Page_bry_(byte[] v) {page_bry = v; return this;} private byte[] page_bry;
|
||||
public byte[] Anchor_bry() {return anchor_bry;} public Xoa_url Anchor_bry_(byte[] v) {anchor_bry = v; return this;} private byte[] anchor_bry = null;
|
||||
public String Anchor_str() {return anchor_bry == null ? null : String_.new_utf8_(anchor_bry);}
|
||||
public String Anchor_str() {return anchor_bry == null ? null : String_.new_u8(anchor_bry);}
|
||||
public Gfo_url_arg[] Args() {return args;} public Xoa_url Args_(Gfo_url_arg[] v) {args = v; return this;} private Gfo_url_arg[] args = Gfo_url_arg.Ary_empty;
|
||||
public Xoa_url_arg_hash Args_hash() {if (args_hash == null) args_hash = new Xoa_url_arg_hash().Load(this); return args_hash;} private Xoa_url_arg_hash args_hash;
|
||||
public byte Protocol_tid() {return protocol_tid;} public Xoa_url Protocol_tid_(byte v) {protocol_tid = v; return this;} private byte protocol_tid;
|
||||
@@ -81,7 +81,7 @@ public class Xoa_url {
|
||||
}
|
||||
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && redirect_force == comp.Redirect_force();}
|
||||
public byte[] Xto_full_bry() {return wiki_bry == null ? page_bry : Bry_.Add(wiki_bry, Xoa_consts.Url_wiki_intermediary, page_bry);}
|
||||
public String Xto_full_str() {return String_.new_utf8_(this.Xto_full_bry());}
|
||||
public String Xto_full_str() {return String_.new_u8(this.Xto_full_bry());}
|
||||
public String Xto_full_str_safe() {try {return Xto_full_str();} catch (Exception e) {return gplx.Err_.Message_gplx_brief(e);}}
|
||||
public static final Xoa_url Null = null;
|
||||
public static Xoa_url blank_() {return new Xoa_url();}
|
||||
|
||||
@@ -17,23 +17,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xoa_url_arg_hash {
|
||||
private OrderedHash hash = OrderedHash_.new_bry_();
|
||||
public Gfo_url_arg Get_arg(byte[] key) {return (Gfo_url_arg)hash.Fetch(key);}
|
||||
private Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
public Gfo_url_arg Get_arg(byte[] key) {return (Gfo_url_arg)hash.Get_by(key);}
|
||||
public int Get_val_int_or(byte[] key, int or) {
|
||||
byte[] val_bry = Get_val_bry_or(key, null); if (val_bry == null) return or;
|
||||
return Bry_.Xto_int_or(val_bry, or);
|
||||
}
|
||||
public byte[] Get_val_bry_or(byte[] key, byte[] or) {
|
||||
Gfo_url_arg arg = (Gfo_url_arg)hash.Fetch(key);
|
||||
Gfo_url_arg arg = (Gfo_url_arg)hash.Get_by(key);
|
||||
return arg == null ? or : arg.Val_bry();
|
||||
}
|
||||
public String Get_val_str_or(byte[] key, String or) {
|
||||
Gfo_url_arg arg = (Gfo_url_arg)hash.Fetch(key);
|
||||
return arg == null ? or : String_.new_utf8_(arg.Val_bry());
|
||||
Gfo_url_arg arg = (Gfo_url_arg)hash.Get_by(key);
|
||||
return arg == null ? or : String_.new_u8(arg.Val_bry());
|
||||
}
|
||||
public void Set_val_by_int(byte[] key, int val) {Set_val_by_bry(key, Bry_.new_ascii_(Int_.Xto_str(val)));}
|
||||
public void Set_val_by_int(byte[] key, int val) {Set_val_by_bry(key, Bry_.new_a7(Int_.Xto_str(val)));}
|
||||
public void Set_val_by_bry(byte[] key, byte[] val) {
|
||||
Gfo_url_arg arg = (Gfo_url_arg)hash.Fetch(key);
|
||||
Gfo_url_arg arg = (Gfo_url_arg)hash.Get_by(key);
|
||||
if (arg == null) {
|
||||
arg = new Gfo_url_arg(key, Bry_.Empty);
|
||||
hash.Add(key, arg);
|
||||
@@ -60,7 +60,7 @@ public class Xoa_url_arg_hash {
|
||||
return this;
|
||||
}
|
||||
public void Save(Xoa_url url) {
|
||||
Gfo_url_arg[] ary = (Gfo_url_arg[])hash.Xto_ary(Gfo_url_arg.class);
|
||||
Gfo_url_arg[] ary = (Gfo_url_arg[])hash.To_ary(Gfo_url_arg.class);
|
||||
url.Args_(ary);
|
||||
}
|
||||
public static void Concat_bfr(Bry_bfr bfr, Url_encoder href_encoder, Gfo_url_arg[] ary) {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Xoa_url_parser {
|
||||
byte[] sub_bry = segs_ary[1]; // lang/type seems to be 2nd seg; EX: "en", "fr"; "commons"
|
||||
byte[] lang_bry = sub_bry;
|
||||
if (upload_segs_hash.Has(sub_bry)) { // wikimedia links will have fmt of "/wikipedia/commons"; must change to wikimedia
|
||||
domain_bry = Xow_domain_.Tid_bry_wikimedia;
|
||||
domain_bry = Xow_domain_type_.Key_bry_wikimedia;
|
||||
lang_bry = Xol_lang_itm_.Key__unknown;
|
||||
}
|
||||
tmp_bfr.Clear().Add(sub_bry).Add_byte(Byte_ascii.Dot) // add lang/type + .; EX: "en."; "fr."; "commons."
|
||||
@@ -132,7 +132,7 @@ public class Xoa_url_parser {
|
||||
;
|
||||
}
|
||||
public static Xoa_url Parse_url(Xoae_app app, Xowe_wiki cur_wiki, String raw) {
|
||||
byte[] raw_bry = Bry_.new_utf8_(raw);
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
return Parse_url(Xoa_url.blank_(), app, cur_wiki, raw_bry, 0, raw_bry.length, false);
|
||||
}
|
||||
public static Xoa_url Parse_url(Xoae_app app, Xowe_wiki cur_wiki, byte[] raw, int bgn, int end, boolean from_url_bar) {return Parse_url(Xoa_url.blank_(), app, cur_wiki, raw, bgn, end, from_url_bar);}
|
||||
@@ -151,7 +151,7 @@ public class Xoa_url_parser {
|
||||
else { // parse failed; url doesn't have protocol
|
||||
byte[] wiki_bry = rv.Wiki_bry();
|
||||
if (Bry_.Len_gt_0(wiki_bry)) { // NOTE: wiki_bry is null when passing in Category:A from home_wiki
|
||||
Xow_xwiki_itm xwiki_itm = app.User().Wiki().Xwiki_mgr().Get_by_key(wiki_bry); // check if url.Wiki_bry is actually wiki; note that checking User().Wiki().Xwiki_mgr() to find "offline" wikis
|
||||
Xow_xwiki_itm xwiki_itm = app.Usere().Wiki().Xwiki_mgr().Get_by_key(wiki_bry); // check if url.Wiki_bry is actually wiki; note that checking User().Wiki().Xwiki_mgr() to find "offline" wikis
|
||||
if ( xwiki_itm != null // null-check
|
||||
&& Bry_.Eq(xwiki_itm.Domain_bry(), wiki_bry)// check that xwiki.domain == wiki; avoids false lang matches like "so/page" or "C/page"; EX: "fr.wikipedia.org" vs "fr"; ca.s:So/Natura_del_so; DATE:2014-04-26; PAGE:no.b:C/Variabler; DATE:2014-10-14
|
||||
)
|
||||
@@ -228,9 +228,9 @@ public class Xoa_url_parser {
|
||||
}
|
||||
private static Xowe_wiki Parse_url__wiki(Xoae_app app, byte[] key) {
|
||||
Xowe_wiki rv = null;
|
||||
Xow_xwiki_itm xwiki = app.User().Wiki().Xwiki_mgr().Get_by_key(key);
|
||||
Xow_xwiki_itm xwiki = app.Usere().Wiki().Xwiki_mgr().Get_by_key(key);
|
||||
if (xwiki == null)
|
||||
rv = app.User().Wiki();
|
||||
rv = app.Usere().Wiki();
|
||||
else
|
||||
rv = app.Wiki_mgr().Get_by_key_or_make(xwiki.Domain_bry());
|
||||
return rv;
|
||||
@@ -254,7 +254,7 @@ public class Xoa_url_parser {
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
public static Xoa_url Parse_from_url_bar(Xoae_app app, Xowe_wiki wiki, String s) {
|
||||
byte[] bry = Bry_.new_utf8_(s);
|
||||
byte[] bry = Bry_.new_u8(s);
|
||||
bry = Parse_from_url_bar__strip_mobile(bry);
|
||||
byte[] fmt = app.Gui_mgr().Url_macro_mgr().Fmt_or_null(bry);
|
||||
if (fmt != null) bry = fmt;
|
||||
@@ -283,15 +283,15 @@ public class Xoa_url_parser {
|
||||
}
|
||||
// private static final byte Tid_xowa = (byte)Gfo_url_parser.Protocol_file_tid + 1;
|
||||
private static final byte Id_arg_redirect = 0, Id_arg_uselang = 1, Id_arg_title = 2, Id_arg_action = 3, Id_arg_fulltext = 4, Id_arg_xowa_vnt = 5;
|
||||
private static final byte[] Bry_arg_redirect = Bry_.new_ascii_("redirect"), Bry_arg_uselang = Bry_.new_ascii_("uselang"), Bry_arg_title = Bry_.new_ascii_("title"), Bry_arg_fulltext = Bry_.new_ascii_("fulltext");
|
||||
private static final byte[] Bry_upload_wikimedia_org = Bry_.new_ascii_("upload.wikimedia.org"), Bry_dot_org = Bry_.new_ascii_(".org")
|
||||
, Bry_file = Bry_.new_ascii_("File:"); // NOTE: File does not need i18n; is a canonical namespace
|
||||
public static final byte[] Bry_wiki_name = Bry_.new_ascii_("wiki");
|
||||
private static final byte[] Bry_arg_redirect = Bry_.new_a7("redirect"), Bry_arg_uselang = Bry_.new_a7("uselang"), Bry_arg_title = Bry_.new_a7("title"), Bry_arg_fulltext = Bry_.new_a7("fulltext");
|
||||
private static final byte[] Bry_upload_wikimedia_org = Bry_.new_a7("upload.wikimedia.org"), Bry_dot_org = Bry_.new_a7(".org")
|
||||
, Bry_file = Bry_.new_a7("File:"); // NOTE: File does not need i18n; is a canonical namespace
|
||||
public static final byte[] Bry_wiki_name = Bry_.new_a7("wiki");
|
||||
private static final byte[][] Bry_wiki_name_bry = new byte[][] {Bry_wiki_name};
|
||||
public static final byte[] Bry_arg_action_eq_edit = Bry_.new_ascii_("action=edit")
|
||||
, Bry_arg_action = Bry_.new_ascii_("action")
|
||||
, Bry_arg_action_edit = Bry_.new_ascii_("edit")
|
||||
, Bry_arg_xowa_vnt = Bry_.new_ascii_("xowa_vnt")
|
||||
public static final byte[] Bry_arg_action_eq_edit = Bry_.new_a7("action=edit")
|
||||
, Bry_arg_action = Bry_.new_a7("action")
|
||||
, Bry_arg_action_edit = Bry_.new_a7("edit")
|
||||
, Bry_arg_xowa_vnt = Bry_.new_a7("xowa_vnt")
|
||||
;
|
||||
private static final Hash_adp_bry qry_args_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_byte(Bry_arg_redirect, Id_arg_redirect)
|
||||
@@ -302,5 +302,5 @@ public class Xoa_url_parser {
|
||||
.Add_bry_byte(Bry_arg_xowa_vnt, Id_arg_xowa_vnt)
|
||||
;
|
||||
private static final Hash_adp_bry upload_segs_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_bry(Xow_domain_.Tid_bry_commons);//.Add_bry_bry(Xow_domain_.Tid_bry_species_bry).Add_bry_bry(Xow_domain_.Tid_bry_meta_bry);
|
||||
.Add_bry_bry(Xow_domain_type_.Key_bry_commons);//.Add_bry_bry(Xow_domain_type_.Key_bry_species_bry).Add_bry_bry(Xow_domain_type_.Key_bry_meta_bry);
|
||||
}
|
||||
|
||||
@@ -57,35 +57,35 @@ public class Xoa_url_parser_basic_tst {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Expd_anchor("b").Test_parse_w_wiki("A#b");
|
||||
}
|
||||
@Test public void Upload() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full("commons.wikimedia.org", "commons.wikimedia.org");
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("commons.wikimedia.org", "commons.wikimedia.org");
|
||||
fxt.Reset().Expd_wiki("commons.wikimedia.org").Expd_page("File:C.svg").Test_parse_w_wiki("http://upload.wikimedia.org/wikipedia/commons/a/ab/C.svg");
|
||||
fxt.Reset().Expd_wiki("commons.wikimedia.org").Expd_page("File:A.png").Test_parse_w_wiki("http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220px-A.png");
|
||||
}
|
||||
@Test public void Parse_lang() {
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki().Xwiki_mgr();
|
||||
xwiki_mgr.Add_full(Bry_.new_ascii_("fr"), Bry_.new_ascii_("fr.wikipedia.org"), Bry_.new_ascii_("http://fr.wikipedia.org/~{0}"));
|
||||
xwiki_mgr.Add_full(Bry_.new_a7("fr"), Bry_.new_a7("fr.wikipedia.org"), Bry_.new_a7("http://fr.wikipedia.org/~{0}"));
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("A").Test_parse_w_wiki("http://en.wikipedia.org/wiki/fr:A");
|
||||
}
|
||||
@Test public void Alias_wiki() {
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki().Xwiki_mgr();
|
||||
xwiki_mgr.Add_full(Bry_.new_ascii_("s"), Bry_.new_ascii_("en.wikisource.org"));
|
||||
xwiki_mgr.Add_full(Bry_.new_a7("s"), Bry_.new_a7("en.wikisource.org"));
|
||||
fxt.Expd_wiki("en.wikisource.org").Expd_page("A/b/c").Test_parse_w_wiki("s: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
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki().Xwiki_mgr();
|
||||
xwiki_mgr.Add_full(Bry_.new_ascii_("s"), Bry_.new_ascii_("en.wikisource.org"));
|
||||
xwiki_mgr.Add_full(Bry_.new_a7("s"), Bry_.new_a7("en.wikisource.org"));
|
||||
fxt.Expd_wiki("en.wikisource.org").Expd_page("Project:A").Test_parse_w_wiki("s:Project:A");
|
||||
}
|
||||
@Test public void Domain_only() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("").Test_parse_w_wiki("fr.wikipedia.org");
|
||||
}
|
||||
@Test public void Domain_and_wiki() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("").Test_parse_w_wiki("fr.wikipedia.org/wiki");
|
||||
}
|
||||
@Test public void Domain_and_wiki_w_http() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("").Test_parse_w_wiki("http://fr.wikipedia.org/wiki");
|
||||
}
|
||||
@Test public void Redirect() {
|
||||
@@ -98,15 +98,15 @@ public class Xoa_url_parser_basic_tst {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Expd_action_is_edit_y().Test_parse_w_wiki("A?action=edit");
|
||||
}
|
||||
@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
|
||||
byte[] raw = Bry_.new_ascii_("A?action=edit");
|
||||
byte[] raw = Bry_.new_a7("A?action=edit");
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Tfds.Eq(true, url.Action_is_edit());
|
||||
raw = Bry_.new_ascii_("B");
|
||||
raw = Bry_.new_a7("B");
|
||||
Xoa_url_parser.Parse_url(url, fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Tfds.Eq(false, url.Action_is_edit());
|
||||
}
|
||||
@Test public void Query_arg() { // PURPOSE.fix: query args were not printing out
|
||||
byte[] raw = Bry_.new_ascii_("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes");
|
||||
byte[] raw = Bry_.new_a7("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes");
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Xoa_url_parser parser = new Xoa_url_parser();
|
||||
Tfds.Eq("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes", parser.Build_str(url));
|
||||
@@ -132,8 +132,8 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_(app, "en.wikipedia.org");
|
||||
wiki_wikisource = Xoa_app_fxt.wiki_(app, "en.wikisource.org");
|
||||
app.User().Wiki().Xwiki_mgr().Add_full("en.wikipedia.org", "en.wikipedia.org");
|
||||
app.User().Wiki().Xwiki_mgr().Add_full("en.wikisource.org", "en.wikisource.org");
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_full("en.wikipedia.org", "en.wikipedia.org");
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_full("en.wikisource.org", "en.wikisource.org");
|
||||
}
|
||||
expd_wiki_str = expd_page = expd_anchor = null;
|
||||
expd_anchor_is_edit = Bool_.__byte;
|
||||
@@ -148,13 +148,13 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
public Xoa_url_parser_chkr Expd_anchor(String v) {this.expd_anchor = v; return this;} private String expd_anchor;
|
||||
public Xoa_url_parser_chkr Expd_action_is_edit_y() {this.expd_anchor_is_edit = Bool_.Y_byte; return this;} private byte expd_anchor_is_edit = Bool_.__byte;
|
||||
public Xoa_url_parser_chkr Expd_action_is_edit_n() {this.expd_anchor_is_edit = Bool_.N_byte; return this;}
|
||||
public void Init_xwiki(String alias, String domain) {app.User().Wiki().Xwiki_mgr().Add_full(alias, domain);}
|
||||
public void Init_xwiki(String alias, String domain) {app.Usere().Wiki().Xwiki_mgr().Add_full(alias, domain);}
|
||||
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
Xoa_url actl = (Xoa_url)actl_obj;
|
||||
int rv = 0;
|
||||
rv += mgr.Tst_val(expd_wiki_str == null, path, "wiki", expd_wiki_str, String_.new_utf8_(actl.Wiki_bry()));
|
||||
rv += mgr.Tst_val(expd_page == null, path, "page", expd_page, String_.new_utf8_(actl.Page_bry()));
|
||||
rv += mgr.Tst_val(expd_anchor == null, path, "anchor", expd_anchor, String_.new_utf8_(actl.Anchor_bry()));
|
||||
rv += mgr.Tst_val(expd_wiki_str == null, path, "wiki", expd_wiki_str, String_.new_u8(actl.Wiki_bry()));
|
||||
rv += mgr.Tst_val(expd_page == null, path, "page", expd_page, String_.new_u8(actl.Page_bry()));
|
||||
rv += mgr.Tst_val(expd_anchor == null, path, "anchor", expd_anchor, String_.new_u8(actl.Anchor_bry()));
|
||||
rv += mgr.Tst_val(expd_anchor_is_edit == Bool_.__byte, path, "anchor_is_edit", expd_anchor_is_edit == Bool_.Y_byte, actl.Action_is_edit());
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ public class Xoa_url_parser_url_bar_tst {
|
||||
fxt.Test_parse_from_url_bar("Page_1" , "en.wikipedia.org/wiki/Page_1"); // basic
|
||||
}
|
||||
@Test public void Lang() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full("uk", "uk.wikipedia.org");
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("uk", "uk.wikipedia.org");
|
||||
fxt.Test_parse_from_url_bar("uk" , "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() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full(Bry_.new_ascii_("uk"), Bry_.new_ascii_("uk.wikipedia.org"), Bry_.new_ascii_("http://~{1}.wikipedia.org")); // NOTE: fmt needed for Type_is_lang
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full(Bry_.new_a7("uk"), Bry_.new_a7("uk.wikipedia.org"), Bry_.new_a7("http://~{1}.wikipedia.org")); // NOTE: fmt needed for Type_is_lang
|
||||
fxt.Test_parse_from_url_bar("uk/A" , "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() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full("fr.wikisource.org", "fr.wikisource.org");
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikisource.org", "fr.wikisource.org");
|
||||
fxt.Test_parse_from_url_bar("fr.s:Auteur:Shakespeare" , "fr.wikisource.org/wiki/Auteur:Shakespeare"); // url_macros
|
||||
}
|
||||
@Test public void Home() {
|
||||
@@ -39,9 +39,9 @@ public class Xoa_url_parser_url_bar_tst {
|
||||
fxt.Test_parse_from_url_bar("home/wiki/Main_Page" , "home/wiki/Main_Page"); // home Main_Page should go to home; DATE:2014-02-09
|
||||
}
|
||||
@Test public void Custom() {
|
||||
fxt.App().User().Wiki().Xwiki_mgr().Add_full("zh.wikipedia.org", "zh.wikipedia.org");
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("zh.wikipedia.org", "zh.wikipedia.org");
|
||||
gplx.xowa.wikis.Xoa_wiki_regy.Make_wiki_dir(fxt.App(), "zh.wikipedia.org");
|
||||
fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_ascii_("zh.wikipedia.org")).Props().Main_page_(Bry_.new_ascii_("Zh_Main_Page"));
|
||||
fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("zh.wikipedia.org")).Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
|
||||
fxt.Test_parse_from_url_bar("zh.w:" , "zh.wikipedia.org/wiki/Zh_Main_Page");
|
||||
fxt.Test_parse_from_url_bar("zh.w:Main_Page" , "zh.wikipedia.org/wiki/Main_Page");
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ public class Xoa_url_tst {
|
||||
}
|
||||
class Xoa_url_fxt {
|
||||
public void Clear() {}
|
||||
public Xoa_url url_(String wiki_str, String page_str, boolean redirect_force) {return Xoa_url.blank_().Wiki_bry_(Bry_.new_utf8_(wiki_str)).Page_bry_(Bry_.new_utf8_(page_str)).Redirect_force_(redirect_force);}
|
||||
public Xoa_url url_(String wiki_str, String page_str, boolean redirect_force) {return Xoa_url.blank_().Wiki_bry_(Bry_.new_u8(wiki_str)).Page_bry_(Bry_.new_u8(page_str)).Redirect_force_(redirect_force);}
|
||||
public void Eq_page_tst(Xoa_url lhs, Xoa_url rhs, boolean expd) {Tfds.Eq(expd, lhs.Eq_page(rhs));}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Xoh_href_parser {
|
||||
segs.Add_stubs(Seg__ary);
|
||||
}
|
||||
public Url_encoder Encoder() {return encoder;} private Url_encoder encoder;
|
||||
public void Parse(Xoh_href rv, String raw, Xowe_wiki wiki, byte[] cur_page) {Parse(rv, Bry_.new_utf8_(raw), wiki, cur_page);}
|
||||
public void Parse(Xoh_href rv, String raw, Xowe_wiki wiki, byte[] cur_page) {Parse(rv, Bry_.new_u8(raw), wiki, cur_page);}
|
||||
public void Parse(Xoh_href rv, byte[] raw, Xowe_wiki wiki, byte[] cur_page) {
|
||||
int bgn = 0, raw_len = raw.length; int file_slash_end = 0;
|
||||
url_parser.Parse(tmp_url, raw, 0, raw_len); // parse as regular tmp_url to get protocol
|
||||
@@ -134,17 +134,17 @@ public class Xoh_href_parser {
|
||||
}
|
||||
}
|
||||
public static final String Href_http_str = "http://", Href_file_str = "file:///", Href_wiki_str = "/wiki/", Href_site_str = "/site/", Href_xcmd_str = "/xcmd/";
|
||||
public static final byte[] Href_http_bry = Bry_.new_utf8_(Href_http_str), Href_file_bry = Bry_.new_ascii_(Href_file_str), Href_site_bry = Bry_.new_ascii_(Href_site_str), Href_wiki_bry = Bry_.new_ascii_(Href_wiki_str);
|
||||
public static final byte[] Href_http_bry = Bry_.new_u8(Href_http_str), Href_file_bry = Bry_.new_a7(Href_file_str), Href_site_bry = Bry_.new_a7(Href_site_str), Href_wiki_bry = Bry_.new_a7(Href_wiki_str);
|
||||
|
||||
private static final int Href_wiki_len = Href_wiki_bry.length;
|
||||
static final byte Seg_null_tid = 0, Seg_wiki_tid = 1, Seg_site_tid = 2, Seg_xcmd_tid = 3;
|
||||
private static final byte[] Seg_null_bry = Bry_.new_ascii_("/null/"), Seg_wiki_bry = Bry_.new_ascii_(Href_wiki_str), Seg_site_bry = Bry_.new_ascii_(Href_site_str), Seg_xcmd_bry = Bry_.new_ascii_(Href_xcmd_str);
|
||||
private static final byte[] Seg_null_bry = Bry_.new_a7("/null/"), Seg_wiki_bry = Bry_.new_a7(Href_wiki_str), Seg_site_bry = Bry_.new_a7(Href_site_str), Seg_xcmd_bry = Bry_.new_a7(Href_xcmd_str);
|
||||
private static final byte[][] Seg__ary = new byte[][] {Seg_null_bry, Seg_wiki_bry, Seg_site_bry, Seg_xcmd_bry};
|
||||
private static void Parse_wiki(Xoh_href rv, Url_encoder encoder, Xowe_wiki wiki, byte[] raw, int bgn, int len) {
|
||||
byte[] ttl_raw = Bry_.Mid(raw, bgn, len);
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(ttl_raw);
|
||||
if (ttl == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_utf8_(raw, bgn, len));
|
||||
Xoa_app_.Usr_dlg().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_u8(raw, bgn, len));
|
||||
return;
|
||||
}
|
||||
if (ttl.Wik_itm() == null) { // standard href; EX: "/wiki/A"
|
||||
@@ -164,10 +164,10 @@ public class Xoh_href_parser {
|
||||
if (ttl.Anch_bgn() != Bry_.NotFound) rv.Anchor_(ttl.Anch_txt());
|
||||
}
|
||||
private static void Parse_site(Xoh_href rv, Url_encoder encoder, Xowe_wiki wiki, byte[] raw, int bgn, int len) { // /site/; EX: /site/fr.wikipedia.org/wiki/A
|
||||
int slash = Bry_finder.Find_fwd(raw, Byte_ascii.Slash, bgn, len); if (slash == Bry_.NotFound) throw Err_mgr._.fmt_("xowa.href.parser", "invalid_site", "site href is missing slash: ~{0}", String_.new_utf8_(raw, bgn, len));
|
||||
int slash = Bry_finder.Find_fwd(raw, Byte_ascii.Slash, bgn, len); if (slash == Bry_.NotFound) throw Err_mgr._.fmt_("xowa.href.parser", "invalid_site", "site href is missing slash: ~{0}", String_.new_u8(raw, bgn, len));
|
||||
rv.Tid_(Xoh_href.Tid_site);
|
||||
byte[] wiki_bry = Bry_.Mid(raw, bgn, slash); // wiki is text between "/site/" and next "/"
|
||||
Xow_xwiki_itm xwiki = wiki.Appe().User().Wiki().Xwiki_mgr().Get_by_key(wiki_bry); // NOTE: site may refer to alias in user_wiki; ex: /site/wikisource.org which points to en.wikisource.org; this occurs during lnke substitution; EX: [//wikisource.org Wikisource]
|
||||
Xow_xwiki_itm xwiki = wiki.Appe().Usere().Wiki().Xwiki_mgr().Get_by_key(wiki_bry); // NOTE: site may refer to alias in user_wiki; ex: /site/wikisource.org which points to en.wikisource.org; this occurs during lnke substitution; EX: [//wikisource.org Wikisource]
|
||||
if (xwiki != null) {
|
||||
wiki_bry = xwiki.Domain_bry();
|
||||
wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_make(wiki_bry); // NOTE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:alphabet
|
||||
@@ -191,7 +191,7 @@ public class Xoh_href_parser {
|
||||
private static void Parse_ttl_and_resolve_xwiki(Xoh_href rv, Xowe_wiki wiki, Url_encoder encoder, byte[] page_bry, byte[] raw, int bgn, int len) {
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(page_bry);
|
||||
if (ttl == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_utf8_(raw, bgn, len));
|
||||
Xoa_app_.Usr_dlg().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_u8(raw, bgn, len));
|
||||
rv.Page_(Bry_.Empty);
|
||||
return;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public class Xoh_href_parser {
|
||||
page_bry = wiki.Props().Main_page();
|
||||
else
|
||||
page_bry = ttl.Page_txt();
|
||||
ttl = Xoa_ttl.parse_(wiki, page_bry); if (ttl == null) throw Err_mgr._.fmt_("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_utf8_(raw, bgn, len));
|
||||
ttl = Xoa_ttl.parse_(wiki, page_bry); if (ttl == null) throw Err_mgr._.fmt_("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_u8(raw, bgn, len));
|
||||
}
|
||||
rv.Page_(encoder.Decode(ttl.Full_txt())); // add page; note that it should be decoded; EX: %20 -> " "; also note that anchor (#) or query params (?) are not parsed; the entire String will be reparsed later
|
||||
if (ttl.Anch_bgn() != Bry_.NotFound) // add anchor if it exists
|
||||
|
||||
@@ -164,7 +164,7 @@ public class Xoh_href_parser_tst {
|
||||
@Test public void Parse_xwiki_cases_correctly() { // PURPOSE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:Alphabet
|
||||
fxt .Prep_raw_("/site/en.wiktionary.org/wiki/alphabet")
|
||||
.Init_xwiki_alias("en.wiktionary.org", "en.wiktionary.org");
|
||||
Xowe_wiki en_wiktionary_org = fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_ascii_("en.wiktionary.org"));
|
||||
Xowe_wiki en_wiktionary_org = fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("en.wiktionary.org"));
|
||||
en_wiktionary_org.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Id_all);
|
||||
fxt .Expd_tid_(Xoh_href.Tid_site)
|
||||
.Expd_full_("en.wiktionary.org/wiki/alphabet")
|
||||
@@ -191,24 +191,24 @@ public class Xoh_href_parser_tst {
|
||||
}
|
||||
class Xoh_href_parser_fxt {
|
||||
private Xowe_wiki wiki; private Xoh_href_parser href_parser; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private Xoh_href href = new Xoh_href();
|
||||
private static final byte[] Page_1_ttl = Bry_.new_ascii_("Page 1");
|
||||
private static final byte[] Page_1_ttl = Bry_.new_a7("Page 1");
|
||||
public void Clear() {
|
||||
expd_tid = Xoh_href.Tid_null;
|
||||
prep_raw = expd_full = expd_wiki = expd_page = expd_anch = null;
|
||||
if (app != null) return;
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
wiki.Xwiki_mgr().Add_bulk(Bry_.new_ascii_("wikt|en.wiktionary.org"));
|
||||
app.User().Wiki().Xwiki_mgr().Add_bulk(Bry_.new_ascii_("en.wiktionary.org|en.wiktionary.org"));
|
||||
wiki.Xwiki_mgr().Add_bulk(Bry_.new_a7("wikt|en.wiktionary.org"));
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_bulk(Bry_.new_a7("en.wiktionary.org|en.wiktionary.org"));
|
||||
href_parser = new Xoh_href_parser(Xoa_app_.Utl__encoder_mgr().Href(), app.Url_parser().Url_parser());
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xoh_href_parser_fxt Init_xwiki_alias(String alias, String domain) {
|
||||
app.User().Wiki().Xwiki_mgr().Add_full(alias, domain);
|
||||
app.Usere().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
|
||||
wiki.Xwiki_mgr().Add_many(Bry_.new_u8(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);}
|
||||
@@ -223,9 +223,9 @@ class Xoh_href_parser_fxt {
|
||||
public void Test_parse() {
|
||||
href_parser.Parse(href, prep_raw, wiki, Page_1_ttl);
|
||||
if (expd_tid != Xoh_href.Tid_null) Tfds.Eq(expd_tid, href.Tid());
|
||||
if (expd_wiki != null) Tfds.Eq(expd_wiki, String_.new_utf8_(href.Wiki()));
|
||||
if (expd_page != null) Tfds.Eq(expd_page, String_.new_utf8_(href.Page()));
|
||||
if (expd_anch != null) Tfds.Eq(expd_anch, String_.new_utf8_(href.Anchor()));
|
||||
if (expd_wiki != null) Tfds.Eq(expd_wiki, String_.new_u8(href.Wiki()));
|
||||
if (expd_page != null) Tfds.Eq(expd_page, String_.new_u8(href.Page()));
|
||||
if (expd_anch != null) Tfds.Eq(expd_anch, String_.new_u8(href.Anchor()));
|
||||
if (expd_full != null) {
|
||||
href.Print_to_bfr(tmp_bfr, true);
|
||||
Tfds.Eq(expd_full, tmp_bfr.Xto_str_and_clear());
|
||||
@@ -237,7 +237,7 @@ class Xoh_href_parser_fxt {
|
||||
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
public void Test_build(String raw, String expd) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_utf8_(raw));
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(raw));
|
||||
href_parser.Build_to_bfr(tmp_bfr, app, wiki.Domain_bry(), ttl);
|
||||
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user