mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.2.4.1
This commit is contained in:
@@ -17,16 +17,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xoa_url {
|
||||
public byte[] Raw() {return raw;} public Xoa_url Raw_(byte[] v) {raw = v; return this;} private byte[] raw = Bry_.Empty;
|
||||
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 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 byte Protocol_tid() {return protocol_tid;} public Xoa_url Protocol_tid_(byte v) {protocol_tid = v; return this;} private byte protocol_tid;
|
||||
public byte[] Protocol_bry() {return protocol_bry;} public Xoa_url Protocol_bry_(byte[] v) {protocol_bry = v; return this;} private byte[] protocol_bry;
|
||||
public boolean Protocol_is_relative() {return protocol_is_relative;} public Xoa_url Protocol_is_relative_(boolean v) {protocol_is_relative = v; return this;} private boolean protocol_is_relative;
|
||||
public byte[] Lang_bry() {return lang_bry;} public Xoa_url Lang_bry_(byte[] v) {lang_bry = v; return this;} private byte[] lang_bry;
|
||||
public byte[] Raw() {return raw;} public Xoa_url Raw_(byte[] v) {raw = v; return this;} private byte[] raw = Bry_.Empty;
|
||||
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 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 byte Protocol_tid() {return protocol_tid;} public Xoa_url Protocol_tid_(byte v) {protocol_tid = v; return this;} private byte protocol_tid;
|
||||
public byte[] Protocol_bry() {return protocol_bry;} public Xoa_url Protocol_bry_(byte[] v) {protocol_bry = v; return this;} private byte[] protocol_bry;
|
||||
public boolean Protocol_is_relative() {return protocol_is_relative;} public Xoa_url Protocol_is_relative_(boolean v) {protocol_is_relative = v; return this;} private boolean protocol_is_relative;
|
||||
public byte[] Use_lang() {return use_lang;} public Xoa_url Use_lang_(byte[] v) {use_lang = v; return this;} private byte[] use_lang;
|
||||
public byte[] Lang_bry() {return lang_bry;} public Xoa_url Lang_bry_(byte[] v) {lang_bry = v; return this;} private byte[] lang_bry;
|
||||
public boolean Redirect_force() {return redirect_force;} public Xoa_url Redirect_force_(boolean v) {redirect_force = v; return this;} private boolean redirect_force;
|
||||
public boolean Search_fulltext() {return search_fulltext;} public Xoa_url Search_fulltext_(boolean v) {search_fulltext = v; return this;} private boolean search_fulltext;
|
||||
public boolean Action_is_edit() {return action_is_edit;} public Xoa_url Action_is_edit_(boolean v) {action_is_edit = v; return this;} private boolean action_is_edit;
|
||||
public byte Err() {return err;} public Xoa_url Err_(byte v) {err = v; return this;} private byte err;
|
||||
public byte[][] Segs_ary() {return segs_ary;} public Xoa_url Segs_ary_(byte[][] v) {segs_ary = v; return this;} private byte[][] segs_ary;
|
||||
public byte[] Page_for_lnki() {
|
||||
int raw_len = raw.length;
|
||||
int page_bgn = Page_bgn(raw_len);
|
||||
@@ -35,13 +41,6 @@ public class Xoa_url {
|
||||
else
|
||||
return Bry_.Mid(raw, page_bgn, raw_len);// else take everything after "/wiki/";
|
||||
}
|
||||
public byte[] Use_lang() {return use_lang;} public Xoa_url Use_lang_(byte[] v) {use_lang = v; return this;} private byte[] use_lang;
|
||||
public boolean Redirect_force() {return redirect_force;} public Xoa_url Redirect_force_(boolean v) {redirect_force = v; return this;} private boolean redirect_force;
|
||||
public boolean Search_fulltext() {return search_fulltext;} public Xoa_url Search_fulltext_(boolean v) {search_fulltext = v; return this;} private boolean search_fulltext;
|
||||
public boolean Action_is_edit() {return action_is_edit;} public Xoa_url Action_is_edit_(boolean v) {action_is_edit = v; return this;} private boolean action_is_edit;
|
||||
public byte Err() {return err;} public Xoa_url Err_(byte v) {err = v; return this;} private byte err;
|
||||
public byte[][] Segs_ary() {return segs_ary;} public Xoa_url Segs_ary_(byte[][] v) {segs_ary = v; return this;} private byte[][] segs_ary;
|
||||
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 void Init(byte[] raw) {
|
||||
this.raw = raw;
|
||||
segs_ary = null;
|
||||
@@ -78,6 +77,7 @@ public class Xoa_url {
|
||||
int wiki_pos = Bry_finder.Find_fwd(raw, Xoh_href_parser.Href_wiki_bry, 0, raw_len); // look for /wiki/
|
||||
return wiki_pos == Bry_.NotFound ? Bry_.NotFound : wiki_pos + Xoh_href_parser.Href_wiki_bry.length;
|
||||
}
|
||||
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_safe() {try {return Xto_full_str();} catch (Exception e) {return gplx.Err_.Message_gplx_brief(e);}}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.net.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.net.*; import gplx.xowa.files.*;
|
||||
public class Xoa_url_parser {
|
||||
private Url_encoder encoder = Url_encoder.new_html_href_mw_().Itms_raw_same_many(Byte_ascii.Underline); private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
public Gfo_url_parser Url_parser() {return url_parser;} private Gfo_url_parser url_parser = new Gfo_url_parser(); private Gfo_url gfo_url = new Gfo_url();
|
||||
@@ -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_wiki_domain_.Seg_wikimedia_bry;
|
||||
domain_bry = Xow_domain_.Seg_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."
|
||||
@@ -130,13 +130,13 @@ public class Xoa_url_parser {
|
||||
: ary
|
||||
;
|
||||
}
|
||||
public static Xoa_url Parse_url(Xoa_app app, Xow_wiki cur_wiki, String raw) {
|
||||
public static Xoa_url Parse_url(Xoae_app app, Xowe_wiki cur_wiki, String raw) {
|
||||
byte[] raw_bry = Bry_.new_utf8_(raw);
|
||||
return Parse_url(Xoa_url.blank_(), app, cur_wiki, raw_bry, 0, raw_bry.length, false);
|
||||
}
|
||||
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_bry_bfr_mkr();
|
||||
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, Xowe_wiki cur_wiki, byte[] raw, int bgn, int end, boolean from_url_bar) {
|
||||
Xowe_wiki wiki = null; Bry_bfr_mkr bfr_mkr = app.Utl_bry_bfr_mkr();
|
||||
byte[] cur_wiki_key = cur_wiki.Domain_bry();
|
||||
byte[] page_bry = Bry_.Empty;
|
||||
boolean page_is_main_page = false;
|
||||
@@ -152,9 +152,9 @@ public class Xoa_url_parser {
|
||||
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
|
||||
if ( xwiki_itm != null // null-check
|
||||
&& Bry_.Eq(xwiki_itm.Domain(), 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
|
||||
&& 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());
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(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"
|
||||
@@ -183,7 +183,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());
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(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"
|
||||
@@ -210,14 +210,14 @@ public class Xoa_url_parser {
|
||||
page_bry = Xoa_page_.Main_page_bry_empty;
|
||||
}
|
||||
if (rv.Anchor_bry() != null) {
|
||||
byte[] anchor_bry = app.Encoder_mgr().Id().Encode(rv.Anchor_bry()); // reencode for anchors (which use . encoding, not % encoding); PAGE:en.w:Enlightenment_Spain#Enlightened_despotism_.281759%E2%80%931788.29
|
||||
byte[] anchor_bry = Xoa_app_.Utl_encoder_mgr().Id().Encode(rv.Anchor_bry()); // reencode for anchors (which use . encoding, not % encoding); PAGE:en.w:Enlightenment_Spain#Enlightened_despotism_.281759%E2%80%931788.29
|
||||
rv.Anchor_bry_(anchor_bry);
|
||||
}
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, page_bry);
|
||||
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());
|
||||
wiki = app.Wiki_mgr().Get_by_key_or_make(lang_xwiki.Domain_bry());
|
||||
page_bry = ttl.Page_txt();
|
||||
}
|
||||
}
|
||||
@@ -225,13 +225,13 @@ public class Xoa_url_parser {
|
||||
rv.Page_bry_(page_bry);
|
||||
return rv;
|
||||
}
|
||||
private static Xow_wiki Parse_url__wiki(Xoa_app app, byte[] key) {
|
||||
Xow_wiki rv = null;
|
||||
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);
|
||||
if (xwiki == null)
|
||||
rv = app.User().Wiki();
|
||||
else
|
||||
rv = app.Wiki_mgr().Get_by_key_or_make(xwiki.Domain());
|
||||
rv = app.Wiki_mgr().Get_by_key_or_make(xwiki.Domain_bry());
|
||||
return rv;
|
||||
}
|
||||
private static byte[] Parse_url__combine(Bry_bfr_mkr bry_bfr_mkr, byte[] wiki, byte[][] segs, byte[] page) {
|
||||
@@ -252,7 +252,7 @@ public class Xoa_url_parser {
|
||||
}
|
||||
return bfr.Mkr_rls().Xto_bry_and_clear();
|
||||
}
|
||||
public static Xoa_url Parse_from_url_bar(Xoa_app app, Xow_wiki wiki, String s) {
|
||||
public static Xoa_url Parse_from_url_bar(Xoae_app app, Xowe_wiki wiki, String s) {
|
||||
byte[] bry = Bry_.new_utf8_(s);
|
||||
bry = Parse_from_url_bar__strip_mobile(bry);
|
||||
byte[] fmt = app.Gui_mgr().Url_macro_mgr().Fmt_or_null(bry);
|
||||
@@ -299,5 +299,5 @@ public class Xoa_url_parser {
|
||||
.Add_bry_byte(Bry_arg_fulltext, Id_arg_fulltext)
|
||||
;
|
||||
private static final Hash_adp_bry upload_segs_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_bry(Xow_wiki_domain_.Key_commons_bry);//.Add_bry_bry(Xow_wiki_domain_.Key_species_bry).Add_bry_bry(Xow_wiki_domain_.Key_meta_bry);
|
||||
.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);
|
||||
}
|
||||
|
||||
@@ -139,9 +139,9 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
expd_anchor_is_edit = Bool_.__byte;
|
||||
return this;
|
||||
}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public Xow_wiki Wiki_wikisource() {return wiki_wikisource;} private Xow_wiki wiki_wikisource;
|
||||
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 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;
|
||||
@@ -164,7 +164,7 @@ class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
return this;
|
||||
}
|
||||
public void Test_parse_w_wiki(String raw) {Test_parse_w_wiki(wiki, raw);}
|
||||
public void Test_parse_w_wiki(Xow_wiki w, String 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();
|
||||
tst_mgr.Tst_obj(this, url);
|
||||
|
||||
@@ -28,8 +28,8 @@ 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, Xow_wiki wiki, byte[] cur_page) {Parse(rv, Bry_.new_utf8_(raw), wiki, cur_page);}
|
||||
public void Parse(Xoh_href rv, byte[] raw, Xow_wiki wiki, byte[] cur_page) {
|
||||
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, 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
|
||||
rv.Init(raw, tmp_url.Protocol_tid());
|
||||
@@ -48,7 +48,7 @@ public class Xoh_href_parser {
|
||||
bgn = file_slash_end = Bry_.While_fwd(raw, Byte_ascii.Slash, tmp_url.Protocol_bry().length, raw_len);
|
||||
rv.Tid_(Xoh_href.Tid_xowa);
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always the current wiki
|
||||
byte[] page = wiki.App().Encoder_mgr().Gfs().Decode(Bry_.Mid(raw, bgn, raw_len));
|
||||
byte[] page = Xoa_app_.Utl_encoder_mgr().Gfs().Decode(Bry_.Mid(raw, bgn, raw_len));
|
||||
rv.Page_(page); // page is everything after "/xcmd/"; individual cmds will do further parsing; 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
|
||||
return;
|
||||
}
|
||||
@@ -72,10 +72,10 @@ public class Xoh_href_parser {
|
||||
}
|
||||
}
|
||||
}
|
||||
public byte[] Build_to_bry(Xow_wiki wiki, Xoa_ttl ttl) {Build_to_bfr(tmp_bfr, wiki, ttl, Bool_.N); return tmp_bfr.Xto_bry_and_clear();}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xow_wiki wiki, byte[] raw) {Build_to_bfr(bfr, wiki, Xoa_ttl.parse_(wiki, raw), Bool_.N);}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xow_wiki wiki, Xoa_ttl ttl) {Build_to_bfr(bfr, wiki, ttl, Bool_.N);}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xow_wiki wiki, Xoa_ttl ttl, boolean force_site) {
|
||||
public byte[] Build_to_bry(Xowe_wiki wiki, Xoa_ttl ttl) {Build_to_bfr(tmp_bfr, wiki, ttl, Bool_.N); return tmp_bfr.Xto_bry_and_clear();}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xowe_wiki wiki, byte[] raw) {Build_to_bfr(bfr, wiki, Xoa_ttl.parse_(wiki, raw), Bool_.N);}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xowe_wiki wiki, Xoa_ttl ttl) {Build_to_bfr(bfr, wiki, ttl, Bool_.N);}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xowe_wiki wiki, Xoa_ttl ttl, boolean force_site) {
|
||||
byte[] page = ttl.Full_txt_raw();
|
||||
Xow_xwiki_itm xwiki = ttl.Wik_itm();
|
||||
if (xwiki == null) // not an xwiki; EX: [[wikt:Word]]
|
||||
@@ -97,14 +97,14 @@ public class Xoh_href_parser {
|
||||
else {} // anchor: noop
|
||||
}
|
||||
else { // xwiki
|
||||
if (wiki.App().Xwiki_missing(xwiki.Domain())) { // xwiki is not offline; use http:
|
||||
if (wiki.Appe().Xwiki_missing(xwiki.Domain_bry())) { // xwiki is not offline; use http:
|
||||
bfr.Add(Href_http_bry); // add "http://"; EX: http://
|
||||
bfr.Add(xwiki.Domain()); // add xwiki; EX: en_dict
|
||||
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
|
||||
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
else { // xwiki is avaiable; use /site/
|
||||
bfr.Add(Href_site_bry); // add "/site/"; EX: /site/
|
||||
bfr.Add(xwiki.Domain()); // add xwiki; EX: en_dict
|
||||
bfr.Add(xwiki.Domain_bry()); // add xwiki; EX: en_dict
|
||||
bfr.Add(Href_wiki_bry); // add "/wiki/"; EX: /wiki/
|
||||
}
|
||||
}
|
||||
@@ -128,20 +128,20 @@ public class Xoh_href_parser {
|
||||
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__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, Xow_wiki wiki, byte[] raw, int bgn, int len) {
|
||||
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 = Xoa_ttl.parse_(wiki, ttl_raw);
|
||||
if (ttl == null) {
|
||||
wiki.App().Gui_wtr().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_utf8_(raw, bgn, len));
|
||||
wiki.Appe().Usr_dlg().Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_utf8_(raw, bgn, len));
|
||||
return;
|
||||
}
|
||||
if (ttl.Wik_itm() == null) { // standard href; EX: "/wiki/A"
|
||||
rv.Tid_(Xoh_href.Tid_wiki);
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always the current wiki
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always the current wiki
|
||||
}
|
||||
else { // embedded xwiki prefix; EX: "/wiki/fr:A"
|
||||
rv.Tid_(Xoh_href.Tid_site);
|
||||
rv.Wiki_(ttl.Wik_itm().Domain()); // wiki is the xwiki prefix; EX: "en.wikpedia.org//wiki/fr:A" -> "fr.wikpedia.org/wiki/A"
|
||||
rv.Wiki_(ttl.Wik_itm().Domain_bry()); // wiki is the xwiki prefix; EX: "en.wikpedia.org//wiki/fr:A" -> "fr.wikpedia.org/wiki/A"
|
||||
}
|
||||
byte[] page_bry = encoder.Decode(ttl.Full_txt()); // note that Full is everything except for ns, so it handles "fr:A" ("fr:" being treated as ns, so only "A" will be Full_txt)
|
||||
if (Bry_.Len_eq_0(page_bry)) // handle xwiki hrefs like "fr:"; EX: "/wiki/wikipedia:" on en.wikisource.org/Main Page
|
||||
@@ -151,14 +151,14 @@ public class Xoh_href_parser {
|
||||
rv.Page_(page_bry); // 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) rv.Anchor_(ttl.Anch_txt());
|
||||
}
|
||||
private static void Parse_site(Xoh_href rv, Url_encoder encoder, Xow_wiki wiki, byte[] raw, int bgn, int len) { // /site/; EX: /site/fr.wikipedia.org/wiki/A
|
||||
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));
|
||||
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.App().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().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]
|
||||
if (xwiki != null) {
|
||||
wiki_bry = xwiki.Domain();
|
||||
wiki = wiki.App().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
|
||||
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
|
||||
}
|
||||
rv.Wiki_(wiki_bry);
|
||||
int page_pos = slash + Href_wiki_len;
|
||||
@@ -174,9 +174,9 @@ public class Xoh_href_parser {
|
||||
// rv.Qarg_(qarg_bry);
|
||||
// page_bry = Bry_.Mid(page_bry, 0, qarg_pos);
|
||||
// }
|
||||
Parse_ttl_and_resolve_xwiki(wiki.App().Usr_dlg(), rv, wiki, encoder, page_bry, raw, bgn, len);
|
||||
Parse_ttl_and_resolve_xwiki(wiki.Appe().Usr_dlg(), rv, wiki, encoder, page_bry, raw, bgn, len);
|
||||
}
|
||||
private static void Parse_ttl_and_resolve_xwiki(Gfo_usr_dlg usr_dlg, Xoh_href rv, Xow_wiki wiki, Url_encoder encoder, byte[] page_bry, byte[] raw, int bgn, int len) {
|
||||
private static void Parse_ttl_and_resolve_xwiki(Gfo_usr_dlg usr_dlg, Xoh_href rv, Xowe_wiki wiki, Url_encoder encoder, byte[] page_bry, byte[] raw, int bgn, int len) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, page_bry);
|
||||
if (ttl == null) {
|
||||
usr_dlg.Warn_many("xowa.href.parser", "invalid_wiki", "wiki href does not have valid title: ~{0}", String_.new_utf8_(raw, bgn, len));
|
||||
@@ -184,7 +184,7 @@ public class Xoh_href_parser {
|
||||
return;
|
||||
}
|
||||
if (ttl.Wik_itm() != null) { // page_bry has xwiki; EX: "wikt:A"; note that since this is called by "/site/", there may be two xwikis; EX: "w:wikt:"; Note that more than 2 is not being handled
|
||||
wiki = wiki.App().Wiki_mgr().Get_by_key_or_make(ttl.Wik_itm().Domain());
|
||||
wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_make(ttl.Wik_itm().Domain_bry());
|
||||
rv.Wiki_(wiki.Domain_bry());
|
||||
if (Bry_.Len_eq_0(ttl.Page_txt())) // page_bry is just alias; EX: "wikt:"
|
||||
page_bry = wiki.Props().Main_page();
|
||||
@@ -196,7 +196,7 @@ public class Xoh_href_parser {
|
||||
if (ttl.Anch_bgn() != Bry_.NotFound) // add anchor if it exists
|
||||
rv.Anchor_(ttl.Anch_txt());
|
||||
}
|
||||
private static void Parse_xcmd(Xoh_href rv, Url_encoder encoder, Xow_wiki wiki, byte[] raw, int bgn, int len) { // /xcmd/; note encoder is passed, but don't decode for now; most invk commands have an _ which will get changed to a " ";
|
||||
private static void Parse_xcmd(Xoh_href rv, Url_encoder encoder, Xowe_wiki wiki, byte[] raw, int bgn, int len) { // /xcmd/; note encoder is passed, but don't decode for now; most invk commands have an _ which will get changed to a " ";
|
||||
rv.Tid_(Xoh_href.Tid_xcmd);
|
||||
rv.Wiki_(wiki.Domain_bry()); // wiki is always the current wiki
|
||||
rv.Page_(Bry_.Mid(raw, bgn, len)); // page is everything after "/xcmd/"; individual cmds will do further parsing; 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
|
||||
|
||||
@@ -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");
|
||||
Xow_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_ascii_("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")
|
||||
@@ -186,7 +186,7 @@ public class Xoh_href_parser_tst {
|
||||
// @Test public void Parse_question_w_arg() {fxt.Prep_raw_("/wiki/A%3F?action=edit").Expd_tid_(Xoh_href.Tid_wiki).Expd_full_("en.wikipedia.org/wiki/A??action=edit").Expd_page_("A??action=edit").Test_parse();}
|
||||
}
|
||||
class Xoh_href_parser_fxt {
|
||||
private Xow_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 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");
|
||||
public void Clear() {
|
||||
expd_tid = Xoh_href.Tid_null;
|
||||
@@ -196,9 +196,9 @@ class Xoh_href_parser_fxt {
|
||||
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"));
|
||||
href_parser = new Xoh_href_parser(app.Encoder_mgr().Href(), app.Url_parser().Url_parser());
|
||||
href_parser = new Xoh_href_parser(Xoa_app_.Utl_encoder_mgr().Href(), app.Url_parser().Url_parser());
|
||||
}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
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);
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user