1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-09-13 21:54:44 -04:00
parent 2145f6382c
commit 5fe27b5b3b
649 changed files with 4726 additions and 3432 deletions

View File

@@ -0,0 +1,67 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
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.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.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.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.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 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_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, wiki_domain);
this.Add(itm);
}
itm.Root_str_(url_str);
itm.Wiki_domain_(wiki_domain);
return itm;
}
}

View File

@@ -0,0 +1,50 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
public class Xof_cfg_download implements GfoInvkAble {
public Xof_cfg_download() {
this.enabled = true; // CFG: set to false b/c some tests only do parsing [[File:A.png]] and repos are not set up
this.redownload = Redownload_none; // CFG: set to none to be as conservative as possible
}
public boolean Enabled() {return enabled;} public Xof_cfg_download Enabled_(boolean v) {enabled = v; return this;} private boolean enabled;
public byte Redownload() {return redownload;} public Xof_cfg_download Redownload_(byte v) {redownload = v; return this;} private byte redownload;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_redownload)) return Redownload_to_str_(redownload);
else if (ctx.Match(k, Invk_redownload_)) redownload = Redownload_parse_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_redownload_toggle)) redownload = redownload == Redownload_none ? Redownload_missing : Redownload_none;
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_enabled_ = "enabled_", Invk_redownload = "redownload", Invk_redownload_ = "redownload_", Invk_redownload_toggle = "redownload_toggle";
byte Redownload_parse_(String s) {
if (String_.Eq(s, "none")) return Redownload_none;
else if (String_.Eq(s, "missing")) return Redownload_missing;
else if (String_.Eq(s, "all")) return Redownload_all;
else throw Err_.new_unhandled(s);
}
public static final byte Redownload_none = 0, Redownload_missing = 1, Redownload_all = 2;
String Redownload_to_str_(byte v) {
switch (v) {
case Redownload_none: return "none";
case Redownload_missing: return "missing";
case Redownload_all: return "all";
default: throw Err_.new_unhandled(v);
}
}
}

View File

@@ -0,0 +1,45 @@
/*
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.files; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa2.files.commons.*; import gplx.xowa.xtns.math.*;
import gplx.xowa.wmfs.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
public class Xof_file_mgr implements GfoInvkAble {
public Xoa_repo_mgr Repo_mgr() {return repo_mgr;} private Xoa_repo_mgr repo_mgr;
public Xof_img_mgr Img_mgr() {return img_mgr;} private final Xof_img_mgr img_mgr = new Xof_img_mgr();
public Xof_cache_mgr Cache_mgr() {return cache_mgr;} private Xof_cache_mgr cache_mgr;
public Xof_math_mgr Math_mgr() {return math_mgr;} private final Xof_math_mgr math_mgr = new Xof_math_mgr();
public Xof_rule_mgr Ext_rules() {return ext_rules;} private final Xof_rule_mgr ext_rules = new Xof_rule_mgr();
public Xoa_wmf_mgr Wmf_mgr() {return wmf_mgr;} private Xoa_wmf_mgr wmf_mgr;
public void Ctor_by_app(Xoae_app app) {
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
this.cache_mgr = new Xof_cache_mgr(usr_dlg, app.Wiki_mgr(), repo_mgr);
this.repo_mgr = new Xoa_repo_mgr(app.Fsys_mgr(), ext_rules);
this.wmf_mgr = new Xoa_wmf_mgr(usr_dlg, app.Wiki_mgr());
img_mgr.Init_by_app(app.Wmf_mgr(), app.Prog_mgr());
math_mgr.Init_by_app(app);
}
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;
else if (ctx.Match(k, Invk_ext_rules)) return ext_rules;
else if (ctx.Match(k, Invk_math)) return math_mgr;
else if (ctx.Match(k, Invk_download)) return wmf_mgr; // NOTE: do not rename "download" to wmf_mgr
else if (ctx.Match(k, Invk_cache_mgr)) return cache_mgr;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_repos = "repos", Invk_img_mgr= "img_mgr", Invk_ext_rules = "ext_rules", Invk_math = "math", Invk_download = "download", Invk_cache_mgr = "cache_mgr";
}

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.ios.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_fsdb_itm implements Xof_file_itm {
private int lnki_upright_patch;
public byte[] Lnki_wiki_abrv() {return lnki_wiki_abrv;} private byte[] lnki_wiki_abrv;

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.files.repos.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_fsdb_itm_fxt {
private byte[] wiki_abrv;
private byte[] lnki_ttl;

View File

@@ -16,6 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_img_size {
public int Html_w() {return html_w;} private int html_w;
public int Html_h() {return html_h;} private int html_h;

View File

@@ -16,7 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_img_size_tst {
private final Xof_img_size_fxt fxt = new Xof_img_size_fxt();
@Before public void init() {

View File

@@ -16,7 +16,10 @@ 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.files; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
import gplx.xowa.tdbs.metas.*;
import gplx.xowa.parsers.utils.*;
public class Xof_xfer_itm implements Xof_file_itm {
public Xof_xfer_itm() {
lnki_type = orig_repo_id = Byte_.Max_value_127;

View File

@@ -16,7 +16,8 @@ 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.files; import gplx.*; import gplx.xowa.*;
import gplx.gfui.*;
import gplx.core.primitives.*;
import gplx.gfui.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_itm_ {
public static void Calc_xfer_size(Int_2_ref rv, byte lnki_type, int thumb_default_w, int file_w, int file_h, int lnki_w, int lnki_h, boolean lnki_thumb, double lnki_upright, Xof_ext ext, int exec_tid) {
boolean ext_is_svg = ext.Id_is_svg();

View File

@@ -16,8 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
import org.junit.*;
import gplx.gfui.*; import gplx.xowa.files.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.gfui.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_itm_tst {
@Before public void init() {fxt.ini();} Xof_xfer_itm_fxt fxt = new Xof_xfer_itm_fxt();
@Test public void Box() {tst_Calc_view("40,50" , "40,40" , "40,40");} // EX:[[File:Crystal Clear app kedit.svg|50x40px]]

View File

@@ -19,6 +19,7 @@ package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.tdbs.metas.*;
public class Xow_file_mgr implements GfoInvkAble {
private Xof_wkr_mgr wkr_mgr;
public Xow_file_mgr(Xowe_wiki wiki) {

View File

@@ -16,7 +16,7 @@ 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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import org.junit.*;
import org.junit.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_file_ext__png_tst {
@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
@After public void term() {fxt.Rls();}

View File

@@ -19,6 +19,7 @@ package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gpl
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.gui.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.*;
import gplx.fsdb.data.*;
import gplx.xowa.parsers.lnkis.*;
class Xof_file_fxt {
private Xoae_app app; private Xof_fsdb_mgr__sql fsdb_mgr; private Xowe_wiki wiki; private Xof_orig_mgr orig_mgr;
private final Fsd_thm_itm tmp_thm = Fsd_thm_itm.new_(); private final Fsd_img_itm tmp_img = new Fsd_img_itm();

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.xtns.gallery.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.gui.views.*;
import gplx.xowa.parsers.lnkis.*;
public class Js_img_mgr {
public static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Xof_file_itm itm) {
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_view_url(), itm.Orig_w(), itm.Orig_h(), itm.Html_orig_url(), itm.Orig_ttl(), itm.Html_gallery_mgr_h());

View File

@@ -19,6 +19,7 @@ package gplx.xowa.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xo
import org.junit.*;
import gplx.dbs.*; import gplx.xowa.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_orig_tbl_tst {
@Before public void init() {fxt.Clear();} private Xof_orig_tbl_fxt fxt = new Xof_orig_tbl_fxt();
@Test public void Select_in() {

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.flds.*;
import gplx.dbs.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.tdbs.metas.*;
public class Xof_orig_wkr__xo_meta implements Xof_orig_wkr {
private final Io_url wiki_meta_dir; private final byte dir_spr_byte; private final Bry_bfr url_bfr = Bry_bfr.new_(255);
private final Gfo_fld_rdr meta_rdr = Gfo_fld_rdr.xowa_(); private final Xof_meta_thumb_parser parser = new Xof_meta_thumb_parser();

View File

@@ -0,0 +1,31 @@
/*
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.parsers.utils.*;
public class Xofw_file_finder_rslt {
public byte[] Ttl() {return ttl;} private byte[] ttl;
public byte[] Redirect() {return redirect;} private byte[] redirect;
public int Repo_idx() {return repo_idx;} private int repo_idx;
public byte[] Repo_wiki_key() {return repo_wiki_key;} private byte[] repo_wiki_key;
public void Init(byte[] ttl) {
this.ttl = ttl; redirect = Xop_redirect_mgr.Redirect_null_bry; repo_wiki_key = null; repo_idx = Byte_.Max_value_127;
}
public void Done(int repo_idx, byte[] repo_wiki_key, byte[] redirect) {
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key; this.redirect = redirect;
}
}

View File

@@ -0,0 +1,23 @@
/*
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
public interface Xofw_wiki_finder {
void Find(List_adp repo_pairs, Xof_xfer_itm file);
boolean Locate(Xofw_file_finder_rslt rv, List_adp repo_pairs, byte[] ttl_bry);
}

View File

@@ -0,0 +1,73 @@
/*
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.wikis.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.parsers.utils.*;
public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
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.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;}
Xoa_ttl ttl = Xoa_ttl.parse(repo_wiki, ttl_bry);
Xow_ns file_ns = repo_wiki.Ns_mgr().Ns_file();
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.Orig_ttl_and_redirect_(ttl.Page_txt(), redirect);
file.Orig_repo_id_(i);
return;
}
file.Orig_repo_id_(-1);
}
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.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);
if (!found) continue; // ttl does not exist in src_wiki; continue; EX: file does not exist in commons, but exists in en_wiki
byte[] redirect = Get_redirect(src_wiki, file_ns, tmp_db_page);
rv.Done(i, src_wiki_key, redirect);
return true;
}
return false;
}
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();
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src, src.length);
return redirect_ttl == Xop_redirect_mgr.Redirect_null_ttl ? Xop_redirect_mgr.Redirect_null_bry : redirect_ttl.Page_db();
}
else
return Xop_redirect_mgr.Redirect_null_bry;
}
private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
}

View File

@@ -0,0 +1,43 @@
/*
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.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.files.*; import gplx.xowa.tdbs.metas.*;
public class Xofw_wiki_wkr_mock implements Xofw_wiki_finder {
int repo_idx; byte[] repo_wiki_key;
public Xofw_wiki_wkr_mock Clear_en_wiki() {return Clear(1, Bry_en_wiki);}
public Xofw_wiki_wkr_mock Clear_commons() {return Clear(0, Bry_commons);}
Xofw_wiki_wkr_mock Clear(int repo_idx, byte[] repo_wiki_key) {
this.repo_idx = repo_idx; this.repo_wiki_key = repo_wiki_key;
if_ttl = then_redirect = Bry_.Empty;
return this;
}
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_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.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, 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);
return true;
}
}

View File

@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.files.xfers.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.parsers.utils.*;
import gplx.xowa.tdbs.metas.*;
public class Xowe_repo_mgr implements Xow_repo_mgr, GfoInvkAble {
private Xowe_wiki wiki; private final List_adp repos = List_adp_.new_();
public Xowe_repo_mgr(Xowe_wiki wiki) {

View File

@@ -19,6 +19,7 @@ package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xo
import gplx.core.primitives.*; import gplx.gfui.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.downloads.*;
import gplx.xowa.wmfs.*; import gplx.xowa.wmfs.apis.*;
import gplx.xowa.tdbs.metas.*;
public class Xof_xfer_mgr {
public Xof_xfer_mgr(Xof_file_mgr file_mgr, Xowmf_mgr wmf_mgr) {this.file_mgr = file_mgr; this.wmf_mgr = wmf_mgr;} private final Xof_file_mgr file_mgr; private final Xowmf_mgr wmf_mgr;
public Xof_xfer_rslt Rslt() {return rslt;} private Xof_xfer_rslt rslt = new Xof_xfer_rslt();

View File

@@ -19,6 +19,7 @@ package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xo
import gplx.core.primitives.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.origs.*;
import gplx.xowa.files.gui.*;
import gplx.xowa.tdbs.metas.*;
public class Xof_xfer_queue {
private final List_adp xfer_list = List_adp_.new_(); private final Ordered_hash dirty_meta_mgrs = Ordered_hash_.new_bry_();
public Int_obj_ref Html_uid() {return html_uid;} private Int_obj_ref html_uid = Int_obj_ref.neg1_();

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*; import gplx.dbs.*;
import gplx.ios.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.files.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_queue_html_fxt extends Xof_xfer_queue_base_fxt {
private final Xof_xfer_queue queue = new Xof_xfer_queue();
@Override public void Clear(boolean src_repo_is_wmf) {

View File

@@ -16,8 +16,7 @@ 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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*;
import gplx.xowa.files.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_queue_html_offline_tst {
Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
@Before public void init() {fxt.Clear(true); fxt.Src_commons_repo().Tarball_(true); fxt.Src_en_wiki_repo().Tarball_(true);}

View File

@@ -16,7 +16,7 @@ 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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import org.junit.*;
import org.junit.*; import gplx.xowa.parsers.lnkis.*;
public class Xof_xfer_queue_html_wmf_api_tst {
private final Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
@Before public void init() {fxt.Clear(true); fxt.Src_commons_repo().Wmf_api_(true); fxt.Src_en_wiki_repo().Wmf_api_(true);}