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-03-08 21:27:59 -04:00
parent d279c70606
commit 80b9928b5c
259 changed files with 2841 additions and 2060 deletions

View File

@@ -36,9 +36,9 @@ public class Xof_xfer_mgr {
ext_rule = src_repo.Ext_rules().Get_or_null(ext.Ext());
orig_w = 0; orig_h = 0; file_w = 0; file_h = 0;
} private byte lnki_type;
private Xof_xfer_itm xfer_itm; private double lnki_thumbtime = Xof_doc_thumb.Null; private boolean lnki_thumbable; private int lnki_w, lnki_h, file_w, file_h; private double lnki_upright;
private Xof_xfer_itm xfer_itm; private double lnki_thumbtime = Xof_lnki_time.Null; private boolean lnki_thumbable; private int lnki_w, lnki_h, file_w, file_h; private double lnki_upright;
private Xof_ext ext; private Xof_rule_itm ext_rule; private Xof_repo_itm src_repo, trg_repo; private boolean src_repo_is_wmf; private byte[] ttl, md5; private int orig_w, orig_h, orig_file_len;
private int lnki_page = Xof_doc_page.Null;
private int lnki_page = Xof_lnki_page.Null;
public Xof_meta_itm Meta_itm() {return meta_itm;} private Xof_meta_itm meta_itm;
public boolean Download_allowed_by_ext() {return orig_file_len < ext_rule.Make_max();}
public Xof_xfer_mgr Check_file_exists_before_xfer_n_() {check_file_exists_before_xfer = false; return this;} private boolean check_file_exists_before_xfer = true;
@@ -240,8 +240,8 @@ public class Xof_xfer_mgr {
thumb_pass = Img_rename_by_size(trg_url); // NOTE: lnki cites view_w which will rarely match file_w; PAGE:en.w:Earth;Northwest coast of United States to Central South America at Night.ogv|250px; which is atually 640
if (thumb_pass) {
Xof_meta_thumb thumb = meta_itm.Update_thumb_add(file_w, file_h); // NOTE: only store 1 width; depend on browser to resize to other widths; this matches MW's behavior
if (Xof_doc_thumb.Null_n(lnki_thumbtime)) { // lnki specified seek
thumb.Seeks_add(Xof_doc_thumb.X_int(lnki_thumbtime));
if (Xof_lnki_time.Null_n(lnki_thumbtime)) { // lnki specified seek
thumb.Seeks_add(Xof_lnki_time.X_int(lnki_thumbtime));
meta_itm.Owner_fil().Dirty_();
}
rslt.Clear();
@@ -308,7 +308,7 @@ public class Xof_xfer_mgr {
private boolean Img_rename_by_size(Io_url trg_url) {
if (!Cmd_query_size(trg_url)) return false;
if (file_w != lnki_w) { // NOTE: only rename if file_w is different; this proc can be called if file_w is same, but file_h < 1; EX: A.svg|thumb|30px will call this proc to get size of thumb
String new_name = Xof_doc_thumb.Null_y(lnki_thumbtime) ? file_w + "px" : file_w + "px" + Xof_meta_thumb_parser.Dlm_seek_str + Xof_doc_thumb.X_str(lnki_thumbtime);
String new_name = Xof_lnki_time.Null_y(lnki_thumbtime) ? file_w + "px" : file_w + "px" + Xof_meta_thumb_parser.Dlm_seek_str + Xof_lnki_time.X_str(lnki_thumbtime);
Io_url new_trg = trg_url.GenNewNameOnly(new_name);
if (trg_url.Eq(new_trg)) return true; // HACK: io will delete file if moving unto itself; (i.e.: mv A.png A.png is same as del A.png); problem is that this proc is being called too many times
try {Io_mgr._.MoveFil_args(trg_url, new_trg, true).Exec();}

View File

@@ -20,20 +20,15 @@ import gplx.core.primitives.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.bins.*;
import gplx.xowa.files.gui.*;
public class Xof_xfer_queue {
private ListAdp list = ListAdp_.new_(); private OrderedHash dirty = OrderedHash_.new_(); private Bry_obj_ref dirty_key = Bry_obj_ref.null_();
public Int_obj_ref Elem_id() {return elem_id;} private Int_obj_ref elem_id = Int_obj_ref.neg1_();
public int Count() {return list.Count();}
private final ListAdp xfer_list = ListAdp_.new_(); private final OrderedHash dirty_meta_mgrs = OrderedHash_.new_bry_();
public Int_obj_ref Html_uid() {return html_uid;} private Int_obj_ref html_uid = Int_obj_ref.neg1_();
public int Count() {return xfer_list.Count();}
public void Clear() {
dirty.Clear();
list.Clear();
elem_id.Val_neg1_();
}
public void Add(Xof_xfer_itm xfer_itm) {list.Add(xfer_itm);}
public void Add_dirty_if_new(Xof_meta_mgr meta_mgr) {
byte[] meta_mgr_key = meta_mgr.Wiki().Domain_bry();
if (!dirty.Has(dirty_key.Val_(meta_mgr_key)))
dirty.AddReplace(meta_mgr_key, meta_mgr); // only add if new
dirty_meta_mgrs.Clear();
xfer_list.Clear();
html_uid.Val_neg1_();
}
public void Add(Xof_xfer_itm xfer_itm) {xfer_list.Add(xfer_itm);}
public void Exec(byte exec_tid, Gfo_usr_dlg wtr, Xowe_wiki wiki, Xoae_page page) {
if (wiki.File_mgr().Version() == Xow_file_mgr.Version_2)
Exec_v2(exec_tid, wtr, wiki, page);
@@ -42,45 +37,50 @@ public class Xof_xfer_queue {
}
private void Exec_v1(byte exec_tid, Gfo_usr_dlg wtr, Xowe_wiki wiki, Xoae_page page) {
Xof_meta_mgr meta_mgr = null;
int xfer_len = list.Count();
int xfer_len = xfer_list.Count();
for (int i = 0; i < xfer_len; i++) {
if (wiki.Appe().Usr_dlg().Canceled()) break;
Xof_xfer_itm xfer_itm = (Xof_xfer_itm)list.FetchAt(i);
Xof_xfer_itm xfer_itm = (Xof_xfer_itm)xfer_list.FetchAt(i);
meta_mgr = xfer_itm.Meta_itm().Owner_fil().Owner_mgr();
Add_dirty_if_new(meta_mgr); // only add if new
byte[] meta_mgr_key = meta_mgr.Wiki().Domain_bry();
if (!dirty_meta_mgrs.Has(meta_mgr_key)) dirty_meta_mgrs.Add(meta_mgr_key, meta_mgr); // only add if new
String queue_msg = wtr.Prog_many(GRP_KEY, "download.bgn", "downloading ~{0} of ~{1}: ~{2};", i + ListAdp_.Base1, xfer_len, xfer_itm.Lnki_ttl());
wiki.App().Wmf_mgr().Download_wkr().Download_xrg().Prog_fmt_hdr_(queue_msg);
wiki.File_mgr().Repo_mgr().Xfer_by_meta(xfer_itm, this);
xfer_itm.Set__meta(xfer_itm.Meta_itm(), xfer_itm.Meta_itm().Repo_itm(wiki), wiki.Html_mgr().Img_thumb_width());
xfer_itm.Calc_by_meta();
if (!xfer_itm.Html_pass()) continue; // file not found; don't call Update_img, else invalid src will be passed and caption box will be incorrectly resized; EX:ar.d:جَبَّارَة; DATE:2014-04-13
if (Bry_.Len_gt_0(xfer_itm.Html_view_src()) // only update images that have been found; otherwise "Undefined" shows up in image box
if (Bry_.Len_gt_0(xfer_itm.Html_view_url()) // only update images that have been found; otherwise "Undefined" shows up in image box
&& xfer_itm.Html_elem_tid() != Xof_html_elem.Tid_none) { // skip updates when downloading orig on File page (there won't be any frame to update)
Js_img_mgr.Update_img(page, xfer_itm);
}
}
for (int i = 0; i < dirty.Count(); i++) {
meta_mgr = (Xof_meta_mgr)dirty.FetchAt(i);
for (int i = 0; i < dirty_meta_mgrs.Count(); i++) {
meta_mgr = (Xof_meta_mgr)dirty_meta_mgrs.FetchAt(i);
meta_mgr.Save(true);
}
this.Clear();
}
private void Exec_v2(byte exec_tid, Gfo_usr_dlg wtr, Xowe_wiki wiki, Xoae_page page) {
wiki.File_mgr().Fsdb_mgr().Init_by_wiki(wiki);
wiki.File_mgr().Fsdb_mgr().Fsdb_search_by_list(exec_tid, Xfer_itms_to_fsdb_itms(list, wiki.File_mgr().Patch_upright()), page, page.Tab().Html_itm());
wiki.File_mgr().Fsdb_mgr().Fsdb_search_by_list(exec_tid, Xfer_itms_to_fsdb_itms(xfer_list, wiki.File_mgr().Patch_upright()), page, page.Tab().Html_itm());
}
private ListAdp Xfer_itms_to_fsdb_itms(ListAdp list, int upright_patch) {
private ListAdp Xfer_itms_to_fsdb_itms(ListAdp xfer_list, int upright_patch) {
ListAdp rv = ListAdp_.new_();
int list_len = list.Count();
int list_len = xfer_list.Count();
for (int i = 0; i < list_len; i++) {
Xof_xfer_itm xfer_itm = (Xof_xfer_itm)list.FetchAt(i);
Xof_fsdb_itm fsdb_itm = new Xof_fsdb_itm();
fsdb_itm.Ctor_by_lnki(xfer_itm.Lnki_ttl(), xfer_itm.Lnki_ext(), xfer_itm.Lnki_md5(), xfer_itm.Lnki_type(), xfer_itm.Lnki_w(), xfer_itm.Lnki_h(), upright_patch, xfer_itm.Lnki_upright(), xfer_itm.Lnki_time(), xfer_itm.Lnki_page());
fsdb_itm.Html_uid_(xfer_itm.Html_uid());
fsdb_itm.Html_elem_tid_(xfer_itm.Html_elem_tid());
fsdb_itm.Gallery_mgr_h_(xfer_itm.Gallery_mgr_h());
fsdb_itm.Html_img_wkr_(xfer_itm.Html_img_wkr());
rv.Add(fsdb_itm);
Xof_xfer_itm xfer = (Xof_xfer_itm)xfer_list.FetchAt(i);
Xof_fsdb_itm fsdb = new Xof_fsdb_itm();
fsdb.Ctor_by_lnki(xfer.Lnki_ttl(), xfer.Lnki_type(), xfer.Lnki_w(), xfer.Lnki_h(), upright_patch, xfer.Lnki_upright(), xfer.Lnki_time(), xfer.Lnki_page());
fsdb.Lnki_ext_(xfer.Lnki_ext());
if (xfer.Orig_ext() > 0)
fsdb.Ctor_by_orig(xfer.Orig_repo_id(), xfer.Orig_repo_name(), xfer.Orig_ttl(), xfer.Orig_ext(), xfer.Orig_w(), xfer.Orig_h(), xfer.Orig_redirect());
fsdb.Html_uid_(xfer.Html_uid());
fsdb.Html_elem_tid_(xfer.Html_elem_tid());
fsdb.Gallery_mgr_h_(xfer.Gallery_mgr_h());
fsdb.Html_img_wkr_(xfer.Html_img_wkr());
fsdb.File_exists_(xfer.File_exists());
rv.Add(fsdb);
}
this.Clear();
return rv;

View File

@@ -191,7 +191,7 @@ public class Xof_xfer_queue_html_cases_tst {
}
@Test public void Upright_size_incorrect() {// PURPOSE.fix: incorrect image size being brought down; EX: w:ASCII; [[Image:ASCII Code Chart.svg|thumb|right|upright=1.6]]; 264, but should be 350
fxt .ini_page_create_en_wiki ("File:A.png");
fxt .Lnki_("A.png", true, -1, -1, 1.6, Xof_doc_thumb.Null_as_int) // upright
fxt .Lnki_("A.png", true, -1, -1, 1.6, Xof_lnki_time.Null_as_int) // upright
.Src( fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 830, 328)
, fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/350px-A.png", 350, 138)
)

View File

@@ -19,20 +19,20 @@ package gplx.xowa; import gplx.*;
import gplx.core.primitives.*; import gplx.dbs.*;
import gplx.ios.*; import gplx.xowa.wikis.*; import gplx.xowa.files.*;
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) {
Db_conn_bldr.I.Reg_default_mem();
super.Clear(src_repo_is_wmf);
this.Api_size().Clear();
}
public Xof_xfer_queue_html_fxt Lnki_orig_ (String lnki_ttl) {return Lnki_(lnki_ttl, Bool_.N, Xof_img_size.Size_null_deprecated, Xof_img_size.Size_null_deprecated, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w) {return Lnki_(lnki_ttl, Bool_.Y, lnki_w, Xof_img_size.Size_null_deprecated, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w, int lnki_h) {return Lnki_(lnki_ttl, Bool_.Y, lnki_w, lnki_h, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_orig_ (String lnki_ttl) {return Lnki_(lnki_ttl, Bool_.N, Xof_img_size.Size_null_deprecated, Xof_img_size.Size_null_deprecated, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w) {return Lnki_(lnki_ttl, Bool_.Y, lnki_w, Xof_img_size.Size_null_deprecated, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w, int lnki_h) {return Lnki_(lnki_ttl, Bool_.Y, lnki_w, lnki_h, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
public Xof_xfer_queue_html_fxt Lnki_(String lnki_ttl, boolean thumb, int lnki_w, int lnki_h, double upright, int seek_time) { // NOTE: only one xfer_itm; supports one Lnki_ per test only
Xowe_wiki wiki = this.En_wiki();
xfer_itm = wiki.Html_mgr().Html_wtr().Lnki_wtr().File_wtr().Lnki_eval(wiki.Ctx(), queue, Bry_.new_utf8_(lnki_ttl), thumb ? Xop_lnki_type.Id_thumb : Xop_lnki_type.Id_null, lnki_w, lnki_h, upright, Xof_doc_thumb.X_int(seek_time), Xof_doc_page.Null, false, queue_add_ref);
xfer_itm = wiki.Html_mgr().Html_wtr().Lnki_wtr().File_wtr().Lnki_eval(wiki.Ctx(), queue, Bry_.new_utf8_(lnki_ttl), thumb ? Xop_lnki_type.Id_thumb : Xop_lnki_type.Id_null, lnki_w, lnki_h, upright, Xof_lnki_time.X_int(seek_time), Xof_lnki_page.Null, false, queue_add_ref);
return this;
} private Xof_xfer_itm xfer_itm = new Xof_xfer_itm(); Bool_obj_ref queue_add_ref = Bool_obj_ref.n_();
Xof_xfer_queue queue = new Xof_xfer_queue();
public Xof_xfer_itm Xfer_itm() {return xfer_itm;}
public Xof_xfer_queue_html_fxt Src(Io_fil... v) {return (Xof_xfer_queue_html_fxt)Src_base(v);}
public Xof_xfer_queue_html_fxt Trg(Io_fil... v) {return (Xof_xfer_queue_html_fxt)Trg_base(v);}
@@ -52,8 +52,8 @@ public class Xof_xfer_queue_html_fxt extends Xof_xfer_queue_base_fxt {
wiki.File_mgr().Cfg_download().Enabled_(true);
queue.Exec(Xof_exec_tid.Tid_wiki_page, usr_dlg, wiki, Xoae_page.Empty);
tst_trg_fils();
if (this.html_orig_src != null) Tfds.Eq(this.html_orig_src , String_.new_utf8_(xfer_itm.Html_orig_src()));
if (this.Html_view_src() != null) Tfds.Eq(this.Html_view_src(), String_.new_utf8_(xfer_itm.Html_view_src()));
if (this.html_orig_src != null) Tfds.Eq(this.html_orig_src , String_.new_utf8_(xfer_itm.Html_orig_url()));
if (this.Html_view_src() != null) Tfds.Eq(this.Html_view_src(), String_.new_utf8_(xfer_itm.Html_view_url()));
if (this.Html_w() != -1) Tfds.Eq(this.Html_w(), xfer_itm.Html_w());
if (this.Html_h() != -1) Tfds.Eq(this.Html_h(), xfer_itm.Html_h());
queue.Clear();

View File

@@ -22,7 +22,7 @@ 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);}
@Test public void Missing() { // PURPOSE.fix: missing image was not being marked as missing; DATE:20121227
fxt .Lnki_("A.png", true, 220, -1, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null_as_int)
fxt .Lnki_("A.png", true, 220, -1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src()
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|x||0?0,0|")
)

View File

@@ -71,7 +71,7 @@ public class Xof_xfer_queue_html_wmf_api_tst {
}
@Test public void Upright_defect() { // PURPOSE.fix: upright not working; PAGE:en.w:Beethoven; [[File:Rudolf-habsburg-olmuetz.jpg|thumb|upright|]]; changed upright to = Upright_default; DATE:2014-05-23
fxt .ini_page_api("en_wiki", "A.png", "", 1378, 1829);
fxt .Lnki_("A.png", true, -1, -1, Xof_img_size.Upright_default_marker, Xof_doc_thumb.Null_as_int)
fxt .Lnki_("A.png", true, -1, -1, Xof_img_size.Upright_default_marker, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/170px-A.png", 170, 226))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/170px.png", 170, 226)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?1378,1829|1?170,226")
@@ -80,7 +80,7 @@ public class Xof_xfer_queue_html_wmf_api_tst {
}
@Test public void Height_only() { // PURPOSE.fix: height only was still using old infer-size code; EX:w:[[File:Upper and Middle Manhattan.jpg|x120px]]; DATE:2012-12-27
fxt .ini_page_api("en_wiki", "A.png", "", 12591, 1847);
fxt .Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null_as_int)
fxt .Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/887px-A.png", 887, 130))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/887px.png", 887, 130)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?12591,1847|1?887,130")
@@ -89,7 +89,7 @@ public class Xof_xfer_queue_html_wmf_api_tst {
}
@Test public void Width_only_height_ignored() {// PURPOSE.fix: if height is not specified, do not recalc; needed when true scaled height is 150x151 but WM has 150x158; defect would discard 150x158; EX:[[File:Tokage_2011-07-15.jpg|150px]] simple.wikipedia.org/wiki/2011_Pacific_typhoon_season; DATE:2013-06-03
fxt .ini_page_api("en_wiki", "A.png", "", 4884, 4932);
fxt .Lnki_("A.png", true, 150, -1, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null_as_int)
fxt .Lnki_("A.png", true, 150, -1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/150px-A.png", 150, 158))
.Trg( fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/150px.png", 150, 158)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|y||2?4884,4932|1?150,158")
@@ -97,7 +97,7 @@ public class Xof_xfer_queue_html_wmf_api_tst {
.tst();
}
@Test public void Missing_was_not_being_marked() { // PURPOSE.fix: missing image was not showing up as repo=x in meta; DATE:2013-01-10
fxt .Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null_as_int)
fxt .Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
.Src()
.Trg( fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" , "A.png|x||0?0,0|")
)
@@ -142,7 +142,7 @@ public class Xof_xfer_queue_html_wmf_api_tst {
@Test public void Ogg_audio() { // PURPOSE: ogg is audio; (a) do not download thumb; (b) get from correct wiki; DATE:2013-08-03
fxt .ini_page_create_commons("File:A.ogg");
fxt .ini_page_api("commons", "A.ogg", "", 0, 0);
fxt .Lnki_("A.ogg", false, -1, -1, 1, Xof_doc_thumb.Null_as_int)
fxt .Lnki_("A.ogg", false, -1, -1, 1, Xof_lnki_time.Null_as_int)
.Src( fxt.img_("mem/src/commons.wikimedia.org/4/42/A.ogg", 0, 0))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/raw/4/2/A.ogg", 0, 0)
, fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv" , "A.ogg|0||1?0,0|0?0,0")
@@ -159,7 +159,7 @@ public class Xof_xfer_queue_html_wmf_api_tst {
@Test public void Imap() { // PURPOSE: check that imap downloads orig, even when thumb is requested; DATE:2014-08-08
fxt .ini_page_create_commons("File:A.png");
fxt .ini_page_api("commons", "A.png", "", 180, 160);
fxt .Lnki_("A.png", true, 90, Xof_img_size.Size_null_deprecated, Xof_img_size.Size_null_deprecated, Xof_doc_thumb.Null_as_int); // thumbtime of 2 specified; will be ignored below
fxt .Lnki_("A.png", true, 90, Xof_img_size.Size_null_deprecated, Xof_img_size.Size_null_deprecated, Xof_lnki_time.Null_as_int); // thumbtime of 2 specified; will be ignored below
fxt .Xfer_itm().Html_elem_tid_(Xof_html_elem.Tid_imap);
fxt .Src( fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
.Trg( fxt.img_("mem/trg/commons.wikimedia.org/fit/7/0/A.png/90px.png", 90, 80)