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,45 +21,47 @@ public class Xoa_repo_mgr implements GfoInvkAble {
|
||||
private final Xoa_fsys_mgr app_fsys; private final Xof_rule_mgr ext_rule_mgr;
|
||||
public Xoa_repo_mgr(Xoa_fsys_mgr app_fsys, Xof_rule_mgr ext_rule_mgr) {this.app_fsys = app_fsys; this.ext_rule_mgr = ext_rule_mgr;}
|
||||
public int Count() {return hash.Count();}
|
||||
public Xof_repo_itm Get_at(int i) {return (Xof_repo_itm)hash.FetchAt(i);}
|
||||
public Xof_repo_itm Get_by(byte[] key) {return (Xof_repo_itm)hash.Fetch(key);}
|
||||
public Xof_repo_itm Get_at(int i) {return (Xof_repo_itm)hash.Get_at(i);}
|
||||
public Xof_repo_itm Get_by(byte[] key) {return (Xof_repo_itm)hash.Get_by(key);}
|
||||
public Xof_repo_itm Get_by_primary(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.FetchAt(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_key()) && repo.Primary()) return repo;
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_domain()) && repo.Primary()) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Get_by_wmf_fsys(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.FetchAt(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_key()) && repo.Wmf_fsys()) return repo;
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_domain()) && repo.Wmf_fsys()) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Get_by_wiki_key(byte[] key) {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.FetchAt(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_key())) return repo;
|
||||
Xof_repo_itm repo = (Xof_repo_itm)hash.Get_at(i);
|
||||
if (Bry_.Eq(key, repo.Wiki_domain())) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Add(Xof_repo_itm itm) {hash.Add(itm.Key(), itm); return itm;} private OrderedHash hash = OrderedHash_.new_bry_();
|
||||
public Xof_repo_itm Add(Xof_repo_itm itm) {hash.Add(itm.Key(), itm); return itm;} private Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_set)) return Set(m.ReadStr("key"), m.ReadStr("url"), m.ReadStr("wiki"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_set = "set";
|
||||
public Xof_repo_itm Set(String key, String url_str, String wiki) {
|
||||
byte[] key_bry = Bry_.new_utf8_(key);
|
||||
Xof_repo_itm itm = (Xof_repo_itm)hash.Fetch(key_bry);
|
||||
byte[] key_bry = Bry_.new_u8(key);
|
||||
Xof_repo_itm itm = (Xof_repo_itm)hash.Get_by(key_bry);
|
||||
byte[] wiki_domain = Bry_.new_u8(wiki);
|
||||
if (itm == null) {
|
||||
itm = new Xof_repo_itm(key_bry, app_fsys, ext_rule_mgr);
|
||||
itm = new Xof_repo_itm(key_bry, app_fsys, ext_rule_mgr, wiki_domain);
|
||||
this.Add(itm);
|
||||
}
|
||||
itm.Root_str_(url_str).Wiki_key_(Bry_.new_utf8_(wiki));
|
||||
itm.Root_str_(url_str);
|
||||
itm.Wiki_domain_(wiki_domain);
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,6 @@ public class Xof_file_mgr implements GfoInvkAble {
|
||||
img_mgr.Init_by_app(app.Wmf_mgr(), app.Prog_mgr());
|
||||
math_mgr.Init_by_app(app);
|
||||
}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
Io_url db_url = app.User().Fsys_mgr().Root_dir().OwnerDir().GenSubFil_ary("xowa.user.", app.User().Key_str(), ".sqlite3");
|
||||
Db_conn_bldr_data conn_data = Db_conn_bldr.I.Get_or_new(db_url);
|
||||
boolean schema_is_1 = Bool_.Y;
|
||||
cache_mgr.Init_for_db(conn_data.Conn(), conn_data.Created(), schema_is_1);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_repos)) return repo_mgr;
|
||||
else if (ctx.Match(k, Invk_img_mgr)) return img_mgr;
|
||||
|
||||
@@ -26,10 +26,10 @@ class Xofo_file {
|
||||
public int Bits() {return bits;} private int bits;
|
||||
public int Repo_id() {return repo_id;} public Xofo_file Repo_id_(int v) {this.repo_id = v; return this;} private int repo_id = -1;
|
||||
public byte[] Status_msg() {return status_msg;} public Xofo_file Status_msg_(byte[] v) {status_msg = v; return this;} private byte[] status_msg = Bry_.Empty;
|
||||
public int[] Thumbs() {return (int[])thumbs.Xto_ary(int.class);} private OrderedHash thumbs = OrderedHash_.new_();
|
||||
public int[] Thumbs() {return (int[])thumbs.To_ary(int.class);} private Ordered_hash thumbs = Ordered_hash_.new_();
|
||||
public Xofo_lnki[] Links() {return lnkis;} private Xofo_lnki[] lnkis = Xofo_lnki.Ary_empty; int links_len;
|
||||
public void Links_(ListAdp list) {
|
||||
lnkis = (Xofo_lnki[])list.Xto_ary(Xofo_lnki.class);
|
||||
public void Links_(List_adp list) {
|
||||
lnkis = (Xofo_lnki[])list.To_ary(Xofo_lnki.class);
|
||||
links_len = lnkis.length;
|
||||
list.Clear();
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class Xofo_file {
|
||||
wtr.Write_int_variable_fld(orig_h);
|
||||
wtr.Write_int_variable_fld(bits);
|
||||
}
|
||||
public Xofo_file Load_by_xfer_rdr(Gfo_fld_rdr fld_parser, Xofo_lnki_parser lnki_parser, Io_line_rdr rdr, ListAdp link_list) {
|
||||
public Xofo_file Load_by_xfer_rdr(Gfo_fld_rdr fld_parser, Xofo_lnki_parser lnki_parser, Io_line_rdr rdr, List_adp link_list) {
|
||||
byte[] bfr = rdr.Bfr();
|
||||
fld_parser.Ini(bfr, rdr.Itm_pos_bgn());
|
||||
Load_ttl_atrs(fld_parser);
|
||||
|
||||
@@ -52,7 +52,7 @@ class Xofo_lnki_parser extends Obj_ary_parser_base {
|
||||
int fld_val = -1;
|
||||
if (fld_idx < 3) {
|
||||
fld_val = Bry_.Xto_int_or(bry, fld_bgn, i, Int_.MinValue);
|
||||
if (fld_val == Int_.MinValue) throw Err_.new_fmt_("invalid int: {0}", String_.new_utf8_(bry, fld_bgn, i));
|
||||
if (fld_val == Int_.MinValue) throw Err_.new_fmt_("invalid int: {0}", String_.new_u8(bry, fld_bgn, i));
|
||||
switch (fld_idx) {
|
||||
case 0: lnki.Lnki_type_((byte)fld_val); break;
|
||||
case 1: lnki.Lnki_w_(fld_val); break;
|
||||
@@ -67,7 +67,7 @@ class Xofo_lnki_parser extends Obj_ary_parser_base {
|
||||
}
|
||||
else if (Bry_.Match(bry, fld_bgn, eq_pos, Xop_lnki_arg_parser.Bry_thumbtime)) {
|
||||
fld_val = Bry_.Xto_int_or(bry, eq_pos + 1, i, Int_.MinValue); // +1 to position after eq
|
||||
if (fld_val == Int_.MinValue) throw Err_.new_fmt_("invalid int: {0}", String_.new_utf8_(bry, eq_pos + 1, i));
|
||||
if (fld_val == Int_.MinValue) throw Err_.new_fmt_("invalid int: {0}", String_.new_u8(bry, eq_pos + 1, i));
|
||||
lnki.Lnki_thumbtime_(Xof_lnki_time.X_int(fld_val));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class Xofo_lnki_parser_fxt {
|
||||
public Xofo_lnki_parser_fxt Raw_(String v) {raw = v; return this;} private String raw;
|
||||
public Xofo_lnki_parser_fxt Expd_(Xofo_lnki_chkr... v) {expd = v; return this;} private Xofo_lnki_chkr[] expd;
|
||||
public Xofo_lnki_parser_fxt tst() {
|
||||
byte[] bry = Bry_.new_utf8_(raw);
|
||||
byte[] bry = Bry_.new_u8(raw);
|
||||
Xofo_lnki[] actl = parser.Parse_ary(bry, 0, bry.length);
|
||||
tst_mgr.Tst_ary("", expd, actl);
|
||||
return this;
|
||||
|
||||
@@ -18,6 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public interface Xofw_wiki_finder {
|
||||
void Find(ListAdp repo_pairs, Xof_xfer_itm file);
|
||||
boolean Locate(Xofw_file_finder_rslt rv, ListAdp repo_pairs, byte[] ttl_bry);
|
||||
void Find(List_adp repo_pairs, Xof_xfer_itm file);
|
||||
boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
public Xofw_wiki_wkr_base(Xowe_wiki wiki, Xoa_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xowe_wiki wiki; Xoa_wiki_mgr wiki_mgr;
|
||||
public void Find(ListAdp repo_pairs, Xof_xfer_itm file) {
|
||||
public Xofw_wiki_wkr_base(Xowe_wiki wiki, Xoae_wiki_mgr wiki_mgr) {this.wiki = wiki; this.wiki_mgr = wiki_mgr;} private Xowe_wiki wiki; Xoae_wiki_mgr wiki_mgr;
|
||||
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl_bry = file.Lnki_ttl();
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.FetchAt(i);
|
||||
byte[] wiki_key = repo_pair.Src().Wiki_key();
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
|
||||
byte[] wiki_key = repo_pair.Src().Wiki_domain();
|
||||
if (repo_pair.Src().Wmf_api()) continue;
|
||||
Xowe_wiki repo_wiki = wiki_mgr.Get_by_key_or_null(wiki_key);
|
||||
if (repo_wiki == null) {continue;}
|
||||
@@ -33,21 +33,21 @@ public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
boolean found = repo_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl.Page_db());
|
||||
if (!found) {continue;}
|
||||
byte[] redirect = Get_redirect(repo_wiki, file_ns, tmp_db_page);
|
||||
file.Set__ttl(ttl.Page_txt(), redirect);
|
||||
file.Trg_repo_idx_(i);
|
||||
file.Orig_ttl_and_redirect_(ttl.Page_txt(), redirect);
|
||||
file.Orig_repo_id_(i);
|
||||
return;
|
||||
}
|
||||
file.Trg_repo_idx_(-1);
|
||||
file.Orig_repo_id_(-1);
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, ListAdp repo_pairs, byte[] ttl_bry) {
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); // NOTE: parse_(ttl_bry) should be the same across all wikis; i.e.: there should be no aliases/namespaces
|
||||
Xow_ns file_ns = wiki.Ns_mgr().Ns_file(); // NOTE: file_ns should also be the same across all wikis; being used for data_mgr.Parse below
|
||||
byte[] ttl_db_key = ttl.Page_db();
|
||||
rv.Init(ttl_db_key);
|
||||
int repo_pairs_len = repo_pairs.Count();
|
||||
for (int i = 0; i < repo_pairs_len; i++) {
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.FetchAt(i);
|
||||
byte[] src_wiki_key = repo_pair.Src().Wiki_key();
|
||||
Xof_repo_pair repo_pair = (Xof_repo_pair)repo_pairs.Get_at(i);
|
||||
byte[] src_wiki_key = repo_pair.Src().Wiki_domain();
|
||||
Xowe_wiki src_wiki = wiki_mgr.Get_by_key_or_null(src_wiki_key);
|
||||
if (src_wiki == null) continue; // src_wiki defined as repo_pair in cfg, but it has not been downloaded; continue; EX: commons set up but not downloaded
|
||||
boolean found = src_wiki.Db_mgr().Load_mgr().Load_by_ttl(tmp_db_page, file_ns, ttl_db_key);
|
||||
@@ -57,8 +57,8 @@ public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
|
||||
byte[] Get_redirect(Xowe_wiki wiki, Xow_ns file_ns, Xowd_page_itm db_page) {
|
||||
}
|
||||
private byte[] Get_redirect(Xowe_wiki wiki, Xow_ns file_ns, Xowd_page_itm db_page) {
|
||||
if (db_page.Redirected()) {
|
||||
wiki.Db_mgr().Load_mgr().Load_page(db_page, file_ns, false);
|
||||
byte[] src = db_page.Text();
|
||||
@@ -68,4 +68,5 @@ public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
else
|
||||
return Xop_redirect_mgr.Redirect_null_bry;
|
||||
}
|
||||
private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
|
||||
}
|
||||
|
||||
@@ -25,15 +25,16 @@ public class Xofw_wiki_wkr_mock implements Xofw_wiki_finder {
|
||||
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key;
|
||||
if_ttl = then_redirect = Bry_.Empty;
|
||||
return this;
|
||||
} static final byte[] Bry_commons = Bry_.new_ascii_("commons.wikimedia.org"), Bry_en_wiki = Bry_.new_ascii_("en.wikipedia.org");
|
||||
}
|
||||
private static final byte[] Bry_commons = Bry_.new_a7("commons.wikimedia.org"), Bry_en_wiki = Bry_.new_a7("en.wikipedia.org");
|
||||
public Xofw_wiki_wkr_mock Repo_idx_(int v) {this.repo_idx = v; return this;}
|
||||
public Xofw_wiki_wkr_mock Redirect_(String if_ttl_str, String then_redirect_str) {this.if_ttl = Bry_.new_utf8_(if_ttl_str); this.then_redirect = Bry_.new_utf8_(then_redirect_str); return this;} private byte[] if_ttl, then_redirect;
|
||||
public void Find(ListAdp repo_pairs, Xof_xfer_itm file) {
|
||||
public Xofw_wiki_wkr_mock Redirect_(String if_ttl_str, String then_redirect_str) {this.if_ttl = Bry_.new_u8(if_ttl_str); this.then_redirect = Bry_.new_u8(then_redirect_str); return this;} private byte[] if_ttl, then_redirect;
|
||||
public void Find(List_adp repo_pairs, Xof_xfer_itm file) {
|
||||
byte[] ttl = file.Lnki_ttl();
|
||||
if (Bry_.Eq(ttl, if_ttl) && repo_idx != -1) {file.Set__ttl(ttl, then_redirect); file.Trg_repo_idx_(repo_idx);}
|
||||
else {file.Set__ttl(ttl, Bry_.Empty); file.Trg_repo_idx_(Xof_meta_itm.Repo_unknown);} // FUTURE: this should be missing, but haven't implemented unknown yet
|
||||
if (Bry_.Eq(ttl, if_ttl) && repo_idx != -1) {file.Orig_ttl_and_redirect_(ttl, then_redirect); file.Orig_repo_id_(repo_idx);}
|
||||
else {file.Orig_ttl_and_redirect_(ttl, Bry_.Empty) ; file.Orig_repo_id_(Xof_meta_itm.Repo_unknown);} // FUTURE: this should be missing, but haven't implemented unknown yet
|
||||
}
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, ListAdp repo_pairs, byte[] ttl) {
|
||||
public boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl) {
|
||||
rv.Init(ttl);
|
||||
byte[] redirect = Bry_.Eq(ttl, if_ttl) ? then_redirect : null;
|
||||
rv.Done(repo_idx, repo_wiki_key, redirect);
|
||||
|
||||
Reference in New Issue
Block a user