mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.6.4.1
This commit is contained in:
@@ -131,13 +131,13 @@ public class Xoa_url_parser {
|
||||
: ary
|
||||
;
|
||||
}
|
||||
public static Xoa_url Parse_url(Xoae_app app, Xowe_wiki cur_wiki, String raw) {
|
||||
public static Xoa_url Parse_url(Xoa_app app, Xow_wiki cur_wiki, String 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);}
|
||||
public static Xoa_url Parse_url(Xoa_url rv, Xoae_app app, Xow_wiki cur_wiki, byte[] raw, int bgn, int end, boolean from_url_bar) {
|
||||
Xowe_wiki wiki = null; Bry_bfr_mkr bfr_mkr = app.Utl__bfr_mkr();
|
||||
public static Xoa_url Parse_url(Xoa_app app, Xow_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);}
|
||||
public static Xoa_url Parse_url(Xoa_url rv, Xoa_app app, Xow_wiki cur_wiki, byte[] raw, int bgn, int end, boolean from_url_bar) {
|
||||
Xow_wiki wiki = null; Bry_bfr_mkr bfr_mkr = app.Utl__bfr_mkr();
|
||||
byte[] cur_wiki_key = cur_wiki.Domain_bry();
|
||||
byte[] page_bry = Bry_.Empty;
|
||||
boolean page_is_main_page = false;
|
||||
@@ -151,15 +151,15 @@ 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.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
|
||||
Xow_xwiki_itm xwiki_itm = app.User().Wikii().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
|
||||
)
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(xwiki_itm.Domain_bry());
|
||||
wiki = app.Wiki_mgri().Get_by_key_or_make_3(xwiki_itm.Domain_bry());
|
||||
}
|
||||
if (rv.Page_bry() == null) { // 1 seg; EX: "Earth"; "fr.wikipedia.org"
|
||||
if (wiki != null) { // wiki_bry is known wiki; EX: "fr.wikipedia.org"
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_bry); // call get again, but this time "make" it
|
||||
wiki = app.Wiki_mgri().Get_by_key_or_make_3(wiki_bry); // call get again, but this time "make" it
|
||||
page_is_main_page = true;
|
||||
}
|
||||
else { // otherwise, assume page name
|
||||
@@ -184,7 +184,7 @@ public class Xoa_url_parser {
|
||||
if (colon_pos != Bry_.NotFound) { // alias found
|
||||
Xow_xwiki_itm xwiki = cur_wiki.Xwiki_mgr().Get_by_mid(page_bry, 0, colon_pos);
|
||||
if (xwiki != null) {
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(xwiki.Domain_bry());
|
||||
wiki = app.Wiki_mgri().Get_by_key_or_make_3(xwiki.Domain_bry());
|
||||
page_bry = Bry_.Mid(page_bry, colon_pos + 1, page_bry.length);
|
||||
if (rv.Segs_ary().length == 0) // handle xwiki without segs; EX: commons:Commons:Media_of_the_day; DATE:2014-02-19
|
||||
rv.Segs_ary_(new byte[][] {Bry_wiki_name, page_bry}); // create segs of "/wiki/Page"
|
||||
@@ -202,10 +202,11 @@ public class Xoa_url_parser {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (page_is_main_page) { // Main_Page requested; EX: "zh.wikipedia.org"; "zh.wikipedia.org/wiki/"; DATE:2014-02-16
|
||||
if (page_is_main_page) { // Main_Page requested; EX: "zh.wikipedia.org"; "zh.wikipedia.org/wiki/"; DATE:2014-02-16
|
||||
if (from_url_bar) {
|
||||
wiki.Init_assert(); // NOTE: must call Init_assert to load Main_Page; only call if from url_bar, else all sister wikis will be loaded when parsing Sister_wikis panel
|
||||
page_bry = wiki.Props().Main_page();
|
||||
wiki.Init_by_wiki(); // NOTE: must call Init_assert to load Main_Page; only call if from url_bar, else all sister wikis will be loaded when parsing Sister_wikis panel
|
||||
// page_bry = ((Xowe_wiki)wiki).Props().Main_page();
|
||||
page_bry = wiki.Data__core_mgr().Mw_props().Main_page();
|
||||
}
|
||||
else
|
||||
page_bry = Xoa_page_.Main_page_bry_empty;
|
||||
@@ -218,7 +219,7 @@ public class Xoa_url_parser {
|
||||
if (ttl != null) { // can still be empty; EX: "en.wikipedia.org"
|
||||
Xow_xwiki_itm lang_xwiki = ttl.Wik_itm();
|
||||
if (lang_xwiki != null && lang_xwiki.Type_is_xwiki_lang(wiki.Lang().Lang_id())) { // format of http://en.wikipedia.org/wiki/fr:A
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(lang_xwiki.Domain_bry());
|
||||
wiki = app.Wiki_mgri().Get_by_key_or_make_3(lang_xwiki.Domain_bry());
|
||||
page_bry = ttl.Page_txt();
|
||||
}
|
||||
}
|
||||
@@ -226,13 +227,13 @@ public class Xoa_url_parser {
|
||||
rv.Page_bry_(page_bry);
|
||||
return rv;
|
||||
}
|
||||
private static Xowe_wiki Parse_url__wiki(Xoae_app app, byte[] key) {
|
||||
Xowe_wiki rv = null;
|
||||
Xow_xwiki_itm xwiki = app.Usere().Wiki().Xwiki_mgr().Get_by_key(key);
|
||||
private static Xow_wiki Parse_url__wiki(Xoa_app app, byte[] key) {
|
||||
Xow_wiki rv = null;
|
||||
Xow_xwiki_itm xwiki = app.User().Wikii().Xwiki_mgr().Get_by_key(key);
|
||||
if (xwiki == null)
|
||||
rv = app.Usere().Wiki();
|
||||
rv = app.User().Wikii();
|
||||
else
|
||||
rv = app.Wiki_mgr().Get_by_key_or_make(xwiki.Domain_bry());
|
||||
rv = app.Wiki_mgri().Get_by_key_or_make_3(xwiki.Domain_bry());
|
||||
return rv;
|
||||
}
|
||||
private static byte[] Parse_url__combine(Bry_bfr_mkr bry_bfr_mkr, byte[] wiki, byte[][] segs, byte[] page) {
|
||||
|
||||
@@ -62,17 +62,17 @@ public class Xoa_url_parser_basic_tst {
|
||||
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();
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki_en_w().Xwiki_mgr();
|
||||
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();
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki_en_w().Xwiki_mgr();
|
||||
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();
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki_en_w().Xwiki_mgr();
|
||||
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");
|
||||
}
|
||||
@@ -92,22 +92,22 @@ public class Xoa_url_parser_basic_tst {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Test_parse_w_wiki("A?redirect=no");
|
||||
}
|
||||
@Test public void Namespace_in_different_wiki() { // PURPOSE.fix: namespaced titles would default to default_wiki instead of current_wiki
|
||||
fxt.Expd_wiki("en.wikisource.org").Expd_page("Category:A").Test_parse_w_wiki(fxt.Wiki_wikisource(), "Category:A");
|
||||
fxt.Expd_wiki("en.wikisource.org").Expd_page("Category:A").Test_parse_w_wiki(fxt.Wiki_en_s(), "Category:A");
|
||||
}
|
||||
@Test public void Action_is_edit() {
|
||||
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_a7("A?action=edit");
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki_en_w(), raw, 0, raw.length, false);
|
||||
Tfds.Eq(true, url.Action_is_edit());
|
||||
raw = Bry_.new_a7("B");
|
||||
Xoa_url_parser.Parse_url(url, fxt.App(), fxt.Wiki(), raw, 0, raw.length, false);
|
||||
Xoa_url_parser.Parse_url(url, fxt.App(), fxt.Wiki_en_w(), 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_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 url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki_en_w(), 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));
|
||||
}
|
||||
@@ -130,8 +130,8 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
public Xoa_url_parser_chkr Reset() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_(app, "en.wikipedia.org");
|
||||
wiki_wikisource = Xoa_app_fxt.wiki_(app, "en.wikisource.org");
|
||||
wiki_en_w = Xoa_app_fxt.wiki_(app, "en.wikipedia.org");
|
||||
wiki_en_s = Xoa_app_fxt.wiki_(app, "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");
|
||||
}
|
||||
@@ -140,8 +140,8 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
return this;
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xowe_wiki Wiki_wikisource() {return wiki_wikisource;} private Xowe_wiki wiki_wikisource;
|
||||
public Xowe_wiki Wiki_en_w() {return wiki_en_w;} private Xowe_wiki wiki_en_w;
|
||||
public Xowe_wiki Wiki_en_s() {return wiki_en_s;} private Xowe_wiki wiki_en_s;
|
||||
public Class<?> TypeOf() {return Xoa_url.class;}
|
||||
public Xoa_url_parser_chkr Expd_wiki(String v) {this.expd_wiki_str = v; return this;} private String expd_wiki_str;
|
||||
public Xoa_url_parser_chkr Expd_page(String v) {this.expd_page = v; return this;} private String expd_page;
|
||||
@@ -159,11 +159,11 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
return rv;
|
||||
}
|
||||
public Xoa_url_parser_chkr Test_parse_from_url_bar(String raw, String expd) {
|
||||
Xoa_url actl_url = Xoa_url_parser.Parse_from_url_bar(app, wiki, raw);
|
||||
Xoa_url actl_url = Xoa_url_parser.Parse_from_url_bar(app, wiki_en_w, raw);
|
||||
Tfds.Eq(expd, actl_url.Xto_full_str());
|
||||
return this;
|
||||
}
|
||||
public void Test_parse_w_wiki(String raw) {Test_parse_w_wiki(wiki, raw);}
|
||||
public void Test_parse_w_wiki(String raw) {Test_parse_w_wiki(wiki_en_w, raw);}
|
||||
public void Test_parse_w_wiki(Xowe_wiki w, String raw) {
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(app, w, raw);
|
||||
Tst_mgr tst_mgr = new Tst_mgr();
|
||||
|
||||
@@ -35,13 +35,19 @@ public class Xoa_url_parser_url_bar_tst {
|
||||
fxt.Test_parse_from_url_bar("fr.s:Auteur:Shakespeare" , "fr.wikisource.org/wiki/Auteur:Shakespeare"); // url_macros
|
||||
}
|
||||
@Test public void Home() {
|
||||
Init_db(fxt.App().Usere().Wiki());
|
||||
fxt.Test_parse_from_url_bar("home" , "en.wikipedia.org/wiki/home"); // home should go to current wiki's home; DATE:2014-02-09
|
||||
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().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_a7("zh.wikipedia.org")).Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("zh.wikipedia.org", "zh.wikipedia.org");
|
||||
Xowe_wiki zh_wiki = fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("zh.wikipedia.org"));
|
||||
Init_db(zh_wiki);
|
||||
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_a7("zh.wikipedia.org")).Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
|
||||
zh_wiki.Data__core_mgr().Mw_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");
|
||||
}
|
||||
@@ -54,4 +60,10 @@ public class Xoa_url_parser_url_bar_tst {
|
||||
fxt.Test_parse_from_url_bar("A.b.m." , "en.wikipedia.org/wiki/A.b.m."); // false-match
|
||||
fxt.Test_parse_from_url_bar("en.x.wikipedia.org/wiki/A" , "en.wikipedia.org/wiki/en.x.wikipedia.org/A"); // fail
|
||||
}
|
||||
public static void Init_db(Xowe_wiki wiki) {
|
||||
Xoa_test_.Db_init(true, Xoa_test_.Url_root());
|
||||
wiki.Ns_mgr().Init_w_defaults();
|
||||
Xowe_wiki_bldr.Create(wiki, 1, "dump.xml");
|
||||
wiki.Data__core_mgr().Db__core().Tbl__ns().Insert(wiki.Ns_mgr());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class Xoh_href_parser {
|
||||
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(Href_https_bry); // add "https://"; EX: https://
|
||||
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
|
||||
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
@@ -133,8 +133,10 @@ public class Xoh_href_parser {
|
||||
encoder.Encode(bfr_encoder, ttl_full, anch_bgn, ttl_full.length); // add anchor
|
||||
}
|
||||
}
|
||||
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_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);
|
||||
public static final String Href_file_str = "file:///", Href_wiki_str = "/wiki/", Href_site_str = "/site/", Href_xcmd_str = "/xcmd/";
|
||||
public static final byte[]
|
||||
Href_https_bry = Bry_.new_u8("https://") // NOTE: must be "https:" or wmf api won't work; DATE:2015-06-17
|
||||
, 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;
|
||||
|
||||
Reference in New Issue
Block a user