1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.9.4.1'

This commit is contained in:
gnosygnu
2016-09-25 22:05:47 -04:00
parent 35d78f6106
commit e3b393650d
211 changed files with 3148 additions and 2197 deletions

View File

@@ -19,18 +19,18 @@ package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.fsdb.data.*; import gplx.fsdb.meta.*; import gplx.xowa.files.fsdb.*;
public class Xof_bin_updater {
private final Fsd_img_itm tmp_img_itm = new Fsd_img_itm(); private final Fsd_thm_itm tmp_thm_itm = Fsd_thm_itm.new_(); private final Fsd_fil_itm tmp_fil_itm = new Fsd_fil_itm();
private final Fsd_thm_itm tmp_thm_itm = Fsd_thm_itm.new_();
public int Save_bin(Fsm_mnt_itm mnt, Fsm_atr_fil atr_fil, Fsm_bin_fil bin_fil, Xof_fsdb_itm fsdb, Io_stream_rdr rdr, long rdr_len) {
int db_uid = -1;
int orig_ext_id = fsdb.Orig_ext().Id();
if (fsdb.File_is_orig()) {
if (fsdb.Orig_ext().Id_is_image()) { // does not add .pdf and .djvu b/c latter do not have w,h for fsdb_img
mnt.Insert_img(tmp_img_itm, atr_fil, bin_fil, fsdb.Orig_repo_name(), fsdb.Orig_ttl(), orig_ext_id, fsdb.Orig_w(), fsdb.Orig_h(), rdr_len, rdr);
db_uid = tmp_img_itm.Fil_id();
if (fsdb.Orig_ext().Id_is_image()) {
Fsd_img_itm img = mnt.Insert_img(atr_fil, bin_fil, fsdb.Orig_repo_name(), fsdb.Orig_ttl(), orig_ext_id, fsdb.Orig_w(), fsdb.Orig_h(), rdr_len, rdr);
db_uid = img.Fil_id();
}
else {
mnt.Insert_fil(tmp_fil_itm, atr_fil, bin_fil, fsdb.Orig_repo_name(), fsdb.Orig_ttl(), orig_ext_id, rdr_len, rdr);
db_uid = tmp_fil_itm.Fil_id();
else { // adds .pdf and .djvu b/c latter does not have w,h for fsdb_img
Fsd_fil_itm fil = mnt.Insert_fil(atr_fil, bin_fil, fsdb.Orig_repo_name(), fsdb.Orig_ttl(), orig_ext_id, rdr_len, rdr);
db_uid = fil.Fil_id();
}
}
else {

View File

@@ -17,5 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
public class Xof_exec_tid {
public static final int Tid_wiki_page = 1, Tid_wiki_file = 2, Tid_viewer_app = 3;
public static final int
Tid_wiki_page = 1 // regular page; EX: en.w:Earth
, Tid_wiki_file = 2 // "File:" ns; EX: en.w:File:A.png
, Tid_viewer_app = 3 // called by viewer_app
;
}

View File

@@ -44,6 +44,7 @@ public class Xof_file_fxt {
return this;
}
public void Exec_orig_add(boolean repo_is_commons, String orig_ttl, int orig_ext_id, int orig_w, int orig_h, String orig_redirect) {
wiki.File_mgr().Orig_mgr().Insert(Xof_repo_itm_.Repo_by_bool(repo_is_commons), Bry_.new_u8(orig_ttl), orig_ext_id, orig_w, orig_h, Bry_.new_u8(orig_redirect));
byte repo_tid = repo_is_commons ? Xof_repo_tid_.Tid__remote : Xof_repo_tid_.Tid__local;
wiki.File_mgr().Orig_mgr().Insert(repo_tid, Bry_.new_u8(orig_ttl), orig_ext_id, orig_w, orig_h, Bry_.new_u8(orig_redirect));
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.threads.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.fsdb.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*; import gplx.xowa.guis.cbks.js.*;
public class Xof_file_wkr implements Gfo_thread_wkr {
private final Xof_orig_mgr orig_mgr; private final Xof_bin_mgr bin_mgr; private final Fsm_mnt_mgr mnt_mgr; private final Xou_cache_mgr cache_mgr;
@@ -97,7 +97,7 @@ public class Xof_file_wkr implements Gfo_thread_wkr {
try {
if (file_rdr != Io_stream_rdr_.Noop) {
Xof_repo_itm repo = repo_mgr.Get_trg_by_id_or_null(fsdb.Orig_repo_id(), fsdb.Lnki_ttl(), page.Url_bry_safe());
Io_url file_url = url_bldr.Init_for_trg_file(Xof_repo_itm_.Mode_by_bool(!fsdb.File_is_orig()), repo, fsdb.Orig_ttl(), fsdb.Orig_ttl_md5(), fsdb.Orig_ext(), fsdb.File_w(), fsdb.Lnki_time(), fsdb.Lnki_page()).Xto_url();
Io_url file_url = url_bldr.Init_for_trg_file(repo, Xof_img_mode_.By_bool(!fsdb.File_is_orig()), fsdb.Orig_ttl(), fsdb.Orig_ttl_md5(), fsdb.Orig_ext(), fsdb.File_w(), fsdb.Lnki_time(), fsdb.Lnki_page()).Xto_url();
Io_stream_wtr_.Save_rdr(file_url, file_rdr, Io_download_fmt.Null);
fsdb.File_size_(file_rdr.Len()); // must update file size for cache
fsdb.Init_at_lnki_by_near(fsdb.File_w()); // change lnki to be file_w,-1

View File

@@ -31,7 +31,7 @@ public class Xof_fsdb_itm implements Xof_file_itm {
public double Lnki_time() {return lnki_time;} private double lnki_time = Xof_lnki_time.Null;
public int Lnki_page() {return lnki_page;} private int lnki_page = Xof_lnki_page.Null;
public int User_thumb_w() {return user_thumb_w;} private int user_thumb_w = Xof_img_size.Thumb_width_img;
public byte Orig_repo_id() {return orig_repo_id;} private byte orig_repo_id = Xof_repo_itm_.Repo_null;
public byte Orig_repo_id() {return orig_repo_id;} private byte orig_repo_id = Xof_repo_tid_.Tid__null;
public byte[] Orig_repo_name() {return orig_repo_name;} private byte[] orig_repo_name;
public byte[] Orig_ttl() {return orig_ttl;} private byte[] orig_ttl;
public byte[] Orig_ttl_md5() {return orig_ttl_md5;} private byte[] orig_ttl_md5;
@@ -123,7 +123,7 @@ public class Xof_fsdb_itm implements Xof_file_itm {
this.file_exists_in_cache = file_exists_in_cache;
this.html_w = w; this.html_h = h; this.html_view_url = view_url;
}
public void Init_by_wm_parse(byte[] lnki_wiki_abrv, boolean repo_is_commons, boolean file_is_orig, byte[] file_ttl_bry, int file_w, double file_time, int file_page) {
public void Init_by_wm_parse(byte[] lnki_wiki_abrv, boolean repo_is_commons, boolean file_is_orig, byte[] file_ttl_bry, Xof_ext orig_ext, int file_w, double file_time, int file_page) {
this.hdump_mode = Hdump_mode__v2;
// lnki
@@ -134,12 +134,13 @@ public class Xof_fsdb_itm implements Xof_file_itm {
this.lnki_wiki_abrv = lnki_wiki_abrv;
this.lnki_time = file_time;
this.lnki_page = file_page;
this.lnki_exec_tid = Xof_exec_tid.Tid_wiki_page;
// orig
this.orig_repo_id = repo_is_commons ? Xof_repo_itm_.Repo_remote : Xof_repo_itm_.Repo_local;
this.orig_repo_id = repo_is_commons ? Xof_repo_tid_.Tid__remote : Xof_repo_tid_.Tid__local;
this.file_is_orig = file_is_orig;
this.Orig_ttl_(file_ttl_bry);
this.orig_ext = Xof_ext_.new_by_ttl_(file_ttl_bry);
this.orig_ext = orig_ext;
// html
this.file_w = this.html_w = file_w;

View File

@@ -44,7 +44,7 @@ public class Xof_fsdb_itm_fxt {
this.lnki_h = Xof_img_size.Size__neg1;
this.lnki_time = Xof_lnki_time.Null;
this.lnki_page = Xof_lnki_page.Null;
this.orig_repo_id = Xof_repo_itm_.Repo_null;
this.orig_repo_id = Xof_repo_tid_.Tid__null;
this.orig_repo_name = orig_ttl = orig_redirect = null;
this.orig_ext = null;
}
@@ -55,7 +55,7 @@ public class Xof_fsdb_itm_fxt {
}
public Xof_fsdb_itm_fxt Orig__commons__lnki() {
this.orig_repo_name = Xow_domain_itm_.Bry__commons;
this.orig_repo_id = Xof_repo_itm_.Repo_remote;
this.orig_repo_id = Xof_repo_tid_.Tid__remote;
this.orig_ttl = lnki_ttl;
this.orig_ext = Xof_ext_.new_by_ttl_(orig_ttl);
this.orig_w = 880;
@@ -64,7 +64,7 @@ public class Xof_fsdb_itm_fxt {
}
public Xof_fsdb_itm_fxt Orig__enwiki__lnki() {
this.orig_repo_name = Xow_domain_itm_.Bry__enwiki;
this.orig_repo_id = Xof_repo_itm_.Repo_local;
this.orig_repo_id = Xof_repo_tid_.Tid__local;
this.orig_ttl = lnki_ttl;
this.orig_ext = Xof_ext_.new_by_ttl_(orig_ttl);
this.orig_w = 880;
@@ -77,5 +77,5 @@ public class Xof_fsdb_itm_fxt {
rv.Init_at_orig(orig_repo_id, orig_repo_name, orig_ttl, orig_ext, orig_w, orig_h, orig_redirect);
return rv;
}
private final static byte[] Abrv__en_w = Bry_.new_a7("en.w");
private final static byte[] Abrv__en_w = Bry_.new_a7("en.w");
}

View File

@@ -18,50 +18,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.envs.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.imgs.*;
public class Xof_url_bldr {
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(400);
private final Gfo_url_encoder encoder_src_http = Gfo_url_encoder_.New__http_url().Make(); // NOTE: changed from new_html_href_mw_ to new_url_ on 2012-11-19; issues with A%2Cb becoming A%252Cb
private byte[] ttl; private byte[] md5; private Xof_ext ext; private boolean file_is_thumb; private int file_w;
private double time = Xof_lnki_time.Null; private int page = Xof_lnki_page.Null; private byte time_dlm = Byte_ascii.At;
private byte repo_tid;
private byte[] root; private byte dir_spr; private boolean fsys_is_wnt; private boolean wmf_dir_hive; private boolean wmf_protocol_is_file; private int md5_dir_depth; private byte[] area;
public Xof_url_bldr Root_(byte[] v) {root = v; return this;}
public Xof_url_bldr Init_by_root(byte[] root, boolean fsys_is_wnt, byte dir_spr, boolean wmf_dir_hive, boolean wmf_protocol_is_file, int md5_dir_depth) {
public Xof_url_bldr Init_by_repo(byte repo_tid, byte[] root, boolean fsys_is_wnt, byte dir_spr, boolean wmf_dir_hive, boolean wmf_protocol_is_file, int md5_dir_depth) {
this.repo_tid = repo_tid;
this.root = root; this.dir_spr = dir_spr; this.wmf_dir_hive = wmf_dir_hive; this.wmf_protocol_is_file = wmf_protocol_is_file; this.md5_dir_depth = md5_dir_depth;
this.fsys_is_wnt = fsys_is_wnt;
return this;
}
public Xof_url_bldr Init_by_itm(byte mode, byte[] ttl, byte[] md5, Xof_ext ext, int file_w, double time, int page) {
this.ttl = ttl; this.md5 = md5; this.ext = ext; this.file_w = file_w; this.time = time; this.page = page;
if (wmf_protocol_is_file && fsys_is_wnt) this.ttl = Xof_repo_itm_.Ttl_invalid_fsys_chars(tmp_bfr, ttl); // NOTE: changed ttl does not change md5
this.file_is_thumb = mode == Xof_repo_itm_.Mode_thumb;
this.area = Xof_repo_itm_.Mode_names_key[mode];
if (wmf_protocol_is_file && fsys_is_wnt) this.ttl = Xof_itm_ttl_.Remove_invalid(tmp_bfr, ttl); // NOTE: changed ttl does not change md5
this.file_is_thumb = mode == Xof_img_mode_.Tid__thumb;
this.area = Xof_img_mode_.Names_ary[mode];
return this;
}
public Xof_url_bldr Init_for_src_file(byte mode, Xof_repo_itm repo, byte[] ttl, byte[] md5, Xof_ext ext, int file_w, double time, int page) {
public Xof_url_bldr Init_for_src_file(Xof_repo_itm repo, byte mode, byte[] ttl, byte[] md5, Xof_ext ext, int file_w, double time, int page) {
this.repo_tid = repo.Tid();
this.wmf_dir_hive = Bool_.Y; this.wmf_protocol_is_file = repo.Tarball();
this.dir_spr = repo.Dir_spr(); this.root = repo.Root_bry(); this.area = repo.Mode_names()[mode];
this.ttl = repo.Gen_name_src(tmp_bfr, ttl); this.md5 = md5; this.ext = ext;
this.file_is_thumb = mode == Xof_repo_itm_.Mode_thumb; this.file_w = file_w; this.time = time; this.page = page;
this.file_is_thumb = mode == Xof_img_mode_.Tid__thumb; this.file_w = file_w; this.time = time; this.page = page;
return this;
}
public Xof_url_bldr Init_for_trg_file(byte mode, Xof_repo_itm repo, byte[] ttl, byte[] md5, Xof_ext ext, int file_w, double time, int page) {
return Init(Bool_.N, Bool_.N, repo.Dir_spr(), repo.Root_bry()
public Xof_url_bldr Init_for_trg_file(Xof_repo_itm repo, byte mode, byte[] ttl, byte[] md5, Xof_ext ext, int file_w, double time, int page) {
return Init(repo.Tid(), Bool_.N, Bool_.N, repo.Dir_spr(), repo.Root_bry()
, repo.Mode_names()[mode], repo.Dir_depth(), repo.Gen_name_trg(tmp_bfr, ttl, md5, ext), md5, ext, mode, file_w, time, page);
}
public Xof_url_bldr Init_for_trg_html(byte mode, Xof_repo_itm repo, byte[] ttl, byte[] md5, Xof_ext ext, int file_w, double time, int page) {
return Init(Bool_.N, Bool_.N, Byte_ascii.Slash, repo.Root_http()
public Xof_url_bldr Init_for_trg_html(Xof_repo_itm repo, byte mode, byte[] ttl, byte[] md5, Xof_ext ext, int file_w, double time, int page) {
return Init(repo.Tid(), Bool_.N, Bool_.N, Byte_ascii.Slash, repo.Root_http()
, repo.Mode_names()[mode], repo.Dir_depth(), repo.Gen_name_trg(tmp_bfr, ttl, md5, ext), md5, ext, mode, file_w, time, page);
}
private Xof_url_bldr Init(boolean wmf_dir_hive, boolean wmf_protocol_is_file, byte dir_spr
private Xof_url_bldr Init(byte repo_tid, boolean wmf_dir_hive, boolean wmf_protocol_is_file, byte dir_spr
, byte[] root, byte[] area, int md5_dir_depth
, byte[] ttl, byte[] md5, Xof_ext ext
, byte file_mode, int file_w, double time, int page
) {
this.repo_tid = repo_tid;
this.wmf_dir_hive = wmf_dir_hive; this.wmf_protocol_is_file = wmf_protocol_is_file; this.dir_spr = dir_spr;
this.root = root; this.area = area; this.md5_dir_depth = md5_dir_depth;
this.ttl = ttl; this.md5 = md5; this.ext = ext;
this.file_is_thumb = file_mode == Xof_repo_itm_.Mode_thumb; this.file_w = file_w; this.time = time; this.page = page;
this.file_is_thumb = file_mode == Xof_img_mode_.Tid__thumb; this.file_w = file_w; this.time = time; this.page = page;
return this;
}
public byte[] Xto_bry() {Bld(); byte[] rv = tmp_bfr.To_bry_and_clear(); Clear(); return rv;}
@@ -69,27 +73,38 @@ public class Xof_url_bldr {
public Io_url Xto_url() {Bld(); Io_url rv = Io_url_.new_fil_(tmp_bfr.To_str()); Clear(); return rv;}
public Io_url Xto_url_by_http() {Bld(); Io_url rv = Io_url_.New__http_or_fail(tmp_bfr.To_str()); Clear(); return rv;}
public Io_url To_url_trg(Xof_repo_itm repo_itm, Xof_fsdb_itm itm, boolean orig) {
byte mode = orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb;
return this.Init_for_trg_file(mode, repo_itm, itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext(), itm.File_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
byte mode = orig ? Xof_img_mode_.Tid__orig : Xof_img_mode_.Tid__thumb;
return this.Init_for_trg_file(repo_itm, mode, itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext(), itm.File_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
}
public Io_url To_url_trg(Xof_repo_itm repo_itm, Xof_file_itm itm, boolean orig) {
byte mode = orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb;
return this.Init_for_trg_file(mode, repo_itm, itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext(), itm.File_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
byte mode = orig ? Xof_img_mode_.Tid__orig : Xof_img_mode_.Tid__thumb;
return this.Init_for_trg_file(repo_itm, mode, itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext(), itm.File_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
}
public Io_url To_url_trg(Xof_repo_itm repo_itm, gplx.xowa.files.caches.Xou_cache_itm itm, boolean orig) {
byte mode = orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb;
return this.Init_for_trg_file(mode, repo_itm, itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext_itm(), itm.File_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
byte mode = orig ? Xof_img_mode_.Tid__orig : Xof_img_mode_.Tid__thumb;
return this.Init_for_trg_file(repo_itm, mode, itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext_itm(), itm.File_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
}
private static final byte[] Bry__http = Bry_.new_a7("http");
private void Bld() {
Add_core();
if (file_is_thumb) {
if (wmf_dir_hive) Add_thumb_wmf();
else Add_thumb_xowa();
if (repo_tid == Xof_repo_tid_.Tid__math) {
tmp_bfr.Add(root); // add root; EX: "C:\xowa\file\"; assume trailing dir_spr
boolean root_is_http = Bry_.Has_at_bgn(root, Bry__http);
if (root_is_http)
tmp_bfr.Add_mid(ttl, 0, ttl.length - 4); // -4 to remove ".svg". note that XO stores ".svg", but WM doesn't; EX: "596f8baf206a81478afd4194b44138715dc1a05c.svg"
else
tmp_bfr.Add(ttl);
}
else {
Add_core();
if (file_is_thumb) {
if (wmf_dir_hive) Add_thumb_wmf();
else Add_thumb_xowa();
}
}
}
private Xof_url_bldr Add_core() {
tmp_bfr.Add(root); // add root; EX: "C:\xowa\file\"; assume trailing dir_spr
if (area != null && !(wmf_dir_hive && !file_is_thumb)) // !(wmf_dir_hive && !thumb) means never add if wmf_dir_hive and orig
if (area != null && !(wmf_dir_hive && !file_is_thumb)) // !(wmf_dir_hive && !thumb) means never add if wmf_dir_hive and orig
tmp_bfr.Add(area).Add_byte(dir_spr); // add area; EX: "thumb\"
byte b0 = md5[0];
if (wmf_dir_hive) {
@@ -101,9 +116,9 @@ public class Xof_url_bldr {
tmp_bfr.Add_byte(md5[i]).Add_byte(dir_spr); // add md5_0123 EX: "0/1/2/3"
}
if (wmf_dir_hive) {
if (wmf_protocol_is_file) // sitting on local file system (as opposed to http)
if (wmf_protocol_is_file) // sitting on local file system (as opposed to http)
tmp_bfr.Add(ttl); // NOTE: file_names are not url-encoded; this includes symbols (') and foreign characters (ö)
else // wmf_http
else // wmf_http
tmp_bfr.Add(encoder_src_http.Encode(ttl)); // NOTE: file_names must be url-encoded; JAVA will default to native charset which on Windows will be 1252; foreign character urls will fail due to conversion mismatch (1252 on windows; UTF-8 on WMF); PAGE:en.w:Möbius strip
}
else
@@ -156,7 +171,7 @@ public class Xof_url_bldr {
break;
}
int ttl_len = ttl.length;
if (ttl_len > 160) { // long file name
if (ttl_len > 160) { // long file name
tmp_bfr.Add(Bry_thumnbail_w_dot);
tmp_bfr.Add(ext.Ext());
}
@@ -169,7 +184,7 @@ public class Xof_url_bldr {
tmp_bfr.Add_byte(Byte_ascii.Dot).Add(Xof_ext_.Bry_png); // add .png; EX: "A.svg" -> "A.svg.png" NOTE: MediaWiki always adds as lowercase
break;
case Xof_ext_.Id_pdf:
case Xof_ext_.Id_tif: // add .jpg EX: "A.tif" -> "A.tif.jpg" NOTE: MediaWiki always adds as lowercase
case Xof_ext_.Id_tif: // add .jpg EX: "A.tif" -> "A.tif.jpg" NOTE: MediaWiki always adds as lowercase
case Xof_ext_.Id_tiff:
case Xof_ext_.Id_ogg:
case Xof_ext_.Id_ogv:
@@ -195,6 +210,7 @@ public class Xof_url_bldr {
time = Xof_lnki_time.Null;
ext = null;
tmp_bfr.Clear();
repo_tid = Xof_repo_tid_.Tid__null;
return this;
}
public static final byte[]

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 org.junit.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
public class Xof_url_bldr__tst {
private Xof_url_bldr__fxt fxt = new Xof_url_bldr__fxt();
@Before public void init() {fxt.Clear().Dir_spr_http_();}
@Test public void Ogv() {fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px--A.ogv.jpg").Test();}
@Test public void Ogv__seek() {fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px-seek%3D5-A.ogv.jpg").Seek_(5).Test();}
@Test public void Ogv__no_w() {fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_( -1).Expd_src_("http://test/thumb/d/d0/A.ogv/-1px--A.ogv.jpg").Test();} // TODO_OLD: use orig_w, not -1
@Test public void Xcf() {fxt.Root_("http://test/").Md5_("44").Ttl_("A.xcf").W_(220).Expd_src_("http://test/thumb/4/44/A.xcf/220px-A.xcf.png").Test();}
@Test public void Bmp() {fxt.Root_("http://test/").Md5_("70").Ttl_("A.bmp").W_(220).Expd_src_("http://test/thumb/7/70/A.bmp/220px-A.bmp.png").Test();}
@Test public void Pdf() {fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page1-220px-A.pdf.jpg").Test();}
@Test public void Pdf__page_2() {fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page2-220px-A.pdf.jpg").Page_(2).Test();}
@Test public void Long() {
String filename = String_.Repeat("A", 200) + ".png";
fxt.Root_("http://test/").Md5_("14").Ttl_(filename).W_(220)
.Expd_src_("http://test/thumb/1/14/" + filename + "/220px-thumbnail.png")
.Test()
;
}
@Test public void Math__http() {fxt.Repo_tid_(Xof_repo_tid_.Tid__math).Fsys_is_wnt_(Bool_.N).Root_("http://test/").Ttl_("random_md5.svg").Expd_src_("http://test/random_md5").Test();} // NOTE: strip ".svg" if online
@Test public void Math__file() {fxt.Repo_tid_(Xof_repo_tid_.Tid__math).Fsys_is_wnt_(Bool_.Y).Root_("file://xowa/").Ttl_("random_md5.svg").Expd_src_("file://xowa/random_md5.svg").Test();} // NOTE: keep ".svg" if online
}
class Xof_url_bldr__fxt {
private final Xof_url_bldr url_bldr = new Xof_url_bldr();
public Xof_url_bldr__fxt Clear() {
dir_spr = Byte_.Zero; ext = null; root = md5 = ttl = expd_src = null;
seek = Xof_lnki_time.Null;
page = Xof_lnki_page.Null;
w = Xof_img_size.Null;
return this;
}
public Xof_url_bldr__fxt Dir_spr_http_() {return Dir_spr_(Byte_ascii.Slash);}
public Xof_url_bldr__fxt Dir_spr_fsys_wnt_() {return Dir_spr_(Byte_ascii.Backslash);}
public Xof_url_bldr__fxt Dir_spr_(byte v) {dir_spr = v; return this;} private byte dir_spr;
public Xof_url_bldr__fxt Root_(String v) {root = v; return this;} private String root;
public Xof_url_bldr__fxt Md5_(String v) {md5 = v; return this;} private String md5;
public Xof_url_bldr__fxt Ttl_(String v) {ttl = v; ext = Xof_ext_.new_by_ttl_(Bry_.new_u8(v)); return this;} private String ttl; Xof_ext ext;
public Xof_url_bldr__fxt W_(int v) {this.w = v; return this;} private int w;
public Xof_url_bldr__fxt Page_(int v) {page = v; return this;} private int page = Xof_lnki_page.Null;
public Xof_url_bldr__fxt Seek_(int v) {seek = v; return this;} private double seek = Xof_lnki_time.Null;
public Xof_url_bldr__fxt Repo_tid_(byte v) {repo_tid = v; return this;} private byte repo_tid = Xof_repo_tid_.Tid__null;
public Xof_url_bldr__fxt Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;} private boolean fsys_is_wnt;
public Xof_url_bldr__fxt Expd_src_(String v) {expd_src = v; return this;} private String expd_src;
public Xof_url_bldr__fxt Test() {
url_bldr.Init_by_repo(repo_tid, Bry_.new_u8(root), fsys_is_wnt, dir_spr, Bool_.Y, Bool_.N, 2);
url_bldr.Init_by_itm (Xof_img_mode_.Tid__thumb, Bry_.new_u8(ttl), Bry_.new_u8_safe(md5), ext, w, seek, page);
Tfds.Eq(expd_src, url_bldr.Xto_str());
return this;
}
}

View File

@@ -1,63 +0,0 @@
/*
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 org.junit.*; import gplx.xowa.files.repos.*;
public class Xof_url_bldr_tst {
private Xof_url_bldr_fxt fxt = new Xof_url_bldr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Ogv() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px--A.ogv.jpg").Test();}
@Test public void Ogv__seek() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px-seek%3D5-A.ogv.jpg").Seek_(5).Test();}
@Test public void Ogv__no_w() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_( -1).Expd_src_("http://test/thumb/d/d0/A.ogv/-1px--A.ogv.jpg").Test();} // TODO_OLD: use orig_w, not -1
@Test public void Xcf() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("44").Ttl_("A.xcf").W_(220).Expd_src_("http://test/thumb/4/44/A.xcf/220px-A.xcf.png").Test();}
@Test public void Bmp() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("70").Ttl_("A.bmp").W_(220).Expd_src_("http://test/thumb/7/70/A.bmp/220px-A.bmp.png").Test();}
@Test public void Pdf() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page1-220px-A.pdf.jpg").Test();}
@Test public void Pdf__page_2() {fxt.Dir_spr_http_().Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page2-220px-A.pdf.jpg").Page_(2).Test();}
@Test public void Long() {
String filename = String_.Repeat("A", 200) + ".png";
fxt.Dir_spr_http_().Root_("http://test/").Md5_("14").Ttl_(filename).W_(220)
.Expd_src_("http://test/thumb/1/14/" + filename + "/220px-thumbnail.png")
.Test()
;
}
}
class Xof_url_bldr_fxt {
private final Xof_url_bldr url_bldr = new Xof_url_bldr();
public Xof_url_bldr_fxt Clear() {
dir_spr = Byte_.Zero; ext = null; root = md5 = ttl = expd_src = null;
seek = Xof_lnki_time.Null;
page = Xof_lnki_page.Null;
w = Xof_img_size.Null;
return this;
}
public Xof_url_bldr_fxt Dir_spr_http_() {return Dir_spr_(Byte_ascii.Slash);}
public Xof_url_bldr_fxt Dir_spr_fsys_wnt_() {return Dir_spr_(Byte_ascii.Backslash);}
public Xof_url_bldr_fxt Dir_spr_(byte v) {dir_spr = v; return this;} private byte dir_spr;
public Xof_url_bldr_fxt Root_(String v) {root = v; return this;} private String root;
public Xof_url_bldr_fxt Md5_(String v) {md5 = v; return this;} private String md5;
public Xof_url_bldr_fxt Ttl_(String v) {ttl = v; ext = Xof_ext_.new_by_ttl_(Bry_.new_u8(v)); return this;} private String ttl; Xof_ext ext;
public Xof_url_bldr_fxt W_(int v) {this.w = v; return this;} private int w;
public Xof_url_bldr_fxt Page_(int v) {page = v; return this;} private int page = Xof_lnki_page.Null;
public Xof_url_bldr_fxt Seek_(int v) {seek = v; return this;} private double seek = Xof_lnki_time.Null;
public Xof_url_bldr_fxt Expd_src_(String v) {expd_src = v; return this;} private String expd_src;
public Xof_url_bldr_fxt Test() {
url_bldr.Init_by_root(Bry_.new_u8(root), Bool_.N, dir_spr, Bool_.Y, Bool_.N, 2);
url_bldr.Init_by_itm (Xof_repo_itm_.Mode_thumb, Bry_.new_u8(ttl), Bry_.new_u8(md5), ext, w, seek, page);
Tfds.Eq(expd_src, url_bldr.Xto_str());
return this;
}
}

View File

@@ -17,7 +17,7 @@ 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.guis.cbks.js.*; import gplx.xowa.files.repos.*;
import gplx.xowa.guis.cbks.js.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.wikis.tdbs.metas.*;
import gplx.xowa.parsers.utils.*;
public class Xof_xfer_itm implements Xof_file_itm {
@@ -181,8 +181,8 @@ public class Xof_xfer_itm implements Xof_file_itm {
file_is_orig = img_size.File_is_orig();
}
}
private Io_url Trg_view_url(byte mode_id, int width) {return tmp_url_bldr.Init_for_trg_file(mode_id, trg_repo_itm, lnki_ttl, orig_ttl_md5, orig_ext, width, lnki_time, lnki_page).Xto_url();}
public Io_url Trg_orig_url(byte mode_id, int width) {return tmp_url_bldr.Init_for_trg_file(mode_id, trg_repo_itm, lnki_ttl, orig_ttl_md5, orig_ext, width, lnki_time, lnki_page).Xto_url();}
private Io_url Trg_view_url(byte mode_id, int width) {return tmp_url_bldr.Init_for_trg_file(trg_repo_itm, mode_id, lnki_ttl, orig_ttl_md5, orig_ext, width, lnki_time, lnki_page).Xto_url();}
public Io_url Trg_orig_url(byte mode_id, int width) {return tmp_url_bldr.Init_for_trg_file(trg_repo_itm, mode_id, lnki_ttl, orig_ttl_md5, orig_ext, width, lnki_time, lnki_page).Xto_url();}
public boolean Calc_by_meta() {return Calc_by_meta(false);}
public boolean Calc_by_meta(boolean caller_is_file_page) {
file_exists = false;
@@ -198,19 +198,19 @@ public class Xof_xfer_itm implements Xof_file_itm {
html_w = Xof_img_size.Thumb_width_ogv;
if (!file_is_orig) { // file is thumb
if (orig_ext.Id_is_video()) { // video is a special case; src is thumb_w but html_w / html_h is based on calc
html_orig_url = Trg_view_url(Xof_repo_itm_.Mode_orig, Xof_img_size.Size__neg1);
html_orig_url = Trg_view_url(Xof_img_mode_.Tid__orig, Xof_img_size.Size__neg1);
if (meta_itm.Thumbs_indicates_oga() && orig_ext.Id_is_ogv()) {orig_ext = Xof_ext_.new_by_ext_(Xof_ext_.Bry_oga); return true;} // if audio, do not thumb; NOTE: must happen after html_orig_bry, b/c html must still be generated to auto-download files; NOTE: must change ext to oga b/c ogg may trigger video code elsewhere
Xof_meta_thumb thumb = meta_itm.Thumbs_get_vid(Xof_lnki_time.X_int(lnki_time));
if (thumb != null) {
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, thumb.Width(), thumb.Height(), html_w, html_h, !file_is_orig, lnki_upright);
html_w = calc_size.Val_0(); html_h = calc_size.Val_1();
html_view_url = Trg_view_url(Xof_repo_itm_.Mode_thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
html_view_url = Trg_view_url(Xof_img_mode_.Tid__thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
file_exists = true;
return true;
}
}
else { // regular thumb
html_orig_url = Trg_view_url(Xof_repo_itm_.Mode_orig, Xof_img_size.Size__neg1);
html_orig_url = Trg_view_url(Xof_img_mode_.Tid__orig, Xof_img_size.Size__neg1);
if (orig_ext.Id_is_audio()) return true; // if audio, do not thumb; even if user requests thumb;
Xof_meta_thumb[] thumbs = meta_itm.Thumbs(); int thumbs_len = thumbs.length; Xof_meta_thumb thumb = null;
if (lnki_h > 0 && orig_w < 1 && thumbs_len > 0) { // if height is specified and no orig, then iterate over thumbs to find similar height; NOTE: this is a fallback case; orig_w/h is optimal; EX: c:Jacques-Louis David and <gallery>
@@ -230,7 +230,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, meta_itm.Orig_w(), meta_itm.Orig_h(), html_w, html_h, !file_is_orig, lnki_upright, limit_size); // calc html_h and html_w; can differ from lnki_w, lnki_h; note that -1 width is handled by thumb_w_img
html_w = calc_size.Val_0();
if (html_h != -1) html_h = calc_size.Val_1(); // NOTE: if -1 (no height specified) do not set height; EX:Tokage_2011-07-15.jpg; DATE:2013-06-03
html_view_url = Trg_view_url(Xof_repo_itm_.Mode_thumb, this.File_w());
html_view_url = Trg_view_url(Xof_img_mode_.Tid__thumb, this.File_w());
thumb = meta_itm.Thumbs_get_img(html_w, 0);
if (thumb == null) { // exact thumb not found
if (html_w == meta_itm.Orig_w() // html_w matches orig_w; occurs when thumb,upright requested, but upright size is larger than orig; PAGE:en.w:St. Petersburg
@@ -238,7 +238,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
&& meta_itm.Orig_exists() == Xof_meta_itm.Exists_y
) {
html_h = meta_itm.Orig_h();
html_view_url = Trg_view_url(Xof_repo_itm_.Mode_orig, -1);
html_view_url = Trg_view_url(Xof_img_mode_.Tid__orig, -1);
file_exists = true;
return true;
}
@@ -255,7 +255,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
}
}
else { // file is orig
byte mode_id = orig_ext.Id_is_svg() ? Xof_repo_itm_.Mode_thumb : Xof_repo_itm_.Mode_orig; // svgs will always return thumb; EX:[[A.svg]] -> A.svg.png
byte mode_id = orig_ext.Id_is_svg() ? Xof_img_mode_.Tid__thumb : Xof_img_mode_.Tid__orig; // svgs will always return thumb; EX:[[A.svg]] -> A.svg.png
html_view_url = html_orig_url = Trg_view_url(mode_id, this.File_w());
if (meta_itm.Thumbs_indicates_oga() && orig_ext.Id_is_ogv()) {orig_ext = Xof_ext_.new_by_ext_(Xof_ext_.Bry_oga); return true;} // if audio, do not thumb; NOTE: must happen after html_orig_bry, b/c html must still be generated to auto-download files; NOTE: must change ext to oga b/c ogg may trigger video code elsewhere
if (orig_ext.Id_is_audio()) return true; // if audio, return true; SEE:NOTE_2
@@ -263,7 +263,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
Xof_meta_thumb thumb = meta_itm.Thumbs_get_vid(Xof_lnki_time.X_int(lnki_time)); // get thumb at lnki_time; NOTE: in most cases this will just be the 1st thumb; note that orig video files don't have an official thumb
if (thumb != null) {
html_w = thumb.Width(); html_h = thumb.Height(); // NOTE: take thumb_size; do not rescale to html_w, html_h b/c html_w will default to 220; native width of thumbnail should be used; DATE:2013-04-11
html_view_url = Trg_view_url(Xof_repo_itm_.Mode_thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
html_view_url = Trg_view_url(Xof_img_mode_.Tid__thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
file_exists = true;
return true;
}
@@ -283,7 +283,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
private boolean Calc_by_meta_found(byte lnki_type, int model_w, int model_h) {
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, model_w, model_h, html_w, html_h, !file_is_orig, lnki_upright, false); // recalc html_w, html_h; note that false passed b/c truncation is not needed
html_w = calc_size.Val_0(); html_h = calc_size.Val_1();
html_view_url = Trg_view_url(Xof_repo_itm_.Mode_thumb, model_w); // note that thumb.Width is used (the actual file width), not html_w
html_view_url = Trg_view_url(Xof_img_mode_.Tid__thumb, model_w); // note that thumb.Width is used (the actual file width), not html_w
file_exists = true;
return true;
}

View File

@@ -17,21 +17,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files.bins; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.core.envs.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
public abstract class Xof_bin_wkr__fsys_base implements Xof_bin_wkr, Gfo_invk {
public Xof_bin_wkr__fsys_base() {}
public abstract byte Tid();
public abstract String Key();
public boolean Resize_allowed() {return resize_allowed;} public void Resize_allowed_(boolean v) {resize_allowed = v;} private boolean resize_allowed = false;
public Io_stream_rdr Get_as_rdr(Xof_fsdb_itm itm, boolean is_thumb, int w) {
Io_url src_url = this.Get_src_url(Xof_repo_itm_.Mode_by_bool(is_thumb), String_.new_u8(itm.Orig_repo_name()), itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext(), w, itm.Lnki_time(), itm.Lnki_page());
Io_url src_url = this.Get_src_url(Xof_img_mode_.By_bool(is_thumb), String_.new_u8(itm.Orig_repo_name()), itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext(), w, itm.Lnki_time(), itm.Lnki_page());
return (src_url == Io_url_.Empty) ? gplx.core.ios.streams.Io_stream_rdr_.Noop : gplx.core.ios.streams.Io_stream_rdr_.file_(src_url);
}
public boolean Get_to_fsys(Xof_fsdb_itm itm, boolean is_thumb, int w, Io_url bin_url) {
return Get_to_fsys(itm.Orig_repo_name(), itm.Orig_ttl(), itm.Orig_ttl_md5(), itm.Orig_ext(), is_thumb, w, itm.Lnki_time(), itm.Lnki_page(), bin_url);
}
private boolean Get_to_fsys(byte[] orig_repo, byte[] orig_ttl, byte[] orig_md5, Xof_ext orig_ext, boolean lnki_is_thumb, int file_w, double lnki_time, int lnki_page, Io_url file_url) {
Io_url src_url = this.Get_src_url(Xof_repo_itm_.Mode_by_bool(lnki_is_thumb), String_.new_u8(orig_repo), orig_ttl, orig_md5, orig_ext, file_w, lnki_time, lnki_page);
Io_url src_url = this.Get_src_url(Xof_img_mode_.By_bool(lnki_is_thumb), String_.new_u8(orig_repo), orig_ttl, orig_md5, orig_ext, file_w, lnki_time, lnki_page);
if (src_url == Io_url_.Empty) return false;
byte[] bin = Io_mgr.Instance.LoadFilBry(src_url);
return bin != Io_mgr.LoadFilBry_fail;
@@ -56,13 +56,15 @@ class Xof_bin_wkr__fsys_wmf extends Xof_bin_wkr__fsys_wmf_base {
@Override public byte Tid() {return Xof_bin_wkr_.Tid_fsys_wmf;}
@Override public String Key() {return Xof_bin_wkr_.Key_fsys_wmf;}
@Override public void Init_by_root() {
this.Url_bldr().Init_by_root(Bry_.Empty, Op_sys.Cur().Tid_is_wnt(), Op_sys.Cur().Fsys_dir_spr_byte(), Bool_.Y, Bool_.Y, Xof_repo_itm_.Dir_depth_wmf);
this.Url_bldr().Init_by_repo(Xof_repo_tid_.Tid__null, Bry_.Empty, Op_sys.Cur().Tid_is_wnt(), Op_sys.Cur().Fsys_dir_spr_byte(), Bool_.Y, Bool_.Y, Md5_dir_depth__wmf);
}
private static final int Md5_dir_depth__wmf = 2;
}
class Xof_bin_wkr__fsys_xowa extends Xof_bin_wkr__fsys_wmf_base {
@Override public byte Tid() {return Xof_bin_wkr_.Tid_fsys_xowa;}
@Override public String Key() {return Xof_bin_wkr_.Key_fsys_xowa;}
@Override public void Init_by_root() {
this.Url_bldr().Init_by_root(Bry_.Empty, Op_sys.Cur().Tid_is_wnt(), Op_sys.Cur().Fsys_dir_spr_byte(), Bool_.N, Bool_.N, Xof_repo_itm_.Dir_depth_xowa);
this.Url_bldr().Init_by_repo(Xof_repo_tid_.Tid__null, Bry_.Empty, Op_sys.Cur().Tid_is_wnt(), Op_sys.Cur().Fsys_dir_spr_byte(), Bool_.N, Bool_.N, Md5_dir_depth__xowa);
}
private static final int Md5_dir_depth__xowa = 4;
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.bins; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.core.threads.*;
import gplx.xowa.apps.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.wikis.domains.*;
public class Xof_bin_wkr__http_wmf implements Xof_bin_wkr {
private final Xow_repo_mgr repo_mgr; private final IoEngine_xrg_downloadFil download_wkr;
@@ -37,12 +37,12 @@ public class Xof_bin_wkr__http_wmf implements Xof_bin_wkr {
boolean rv = rdr.Exists(); // NOTE: use Exists which detects for response_code 200, not content length > 0; DATE:2015-05-20
if (!rv) {
Handle_error();
if (!rv && fsdb.Orig_repo_id() == Xof_repo_itm_.Repo_local) { // image is not found in local; check commons; occurs with bldr which relies on inaccurate data in image dumps; PAGE:en.w:Apollo_13; DATE:2015-08-05
if (!rv && fsdb.Orig_repo_id() == Xof_repo_tid_.Tid__local) { // image is not found in local; check commons; occurs with bldr which relies on inaccurate data in image dumps; PAGE:en.w:Apollo_13; DATE:2015-08-05
src = Make_src(Xow_domain_itm_.Bry__commons, fsdb.Orig_ttl(), fsdb.Orig_ttl_md5(), fsdb.Orig_ext(), is_thumb, w, fsdb.Lnki_time(), fsdb.Lnki_page(), Io_url_.Empty);
rdr = download_mgr.Download_as_rdr(src);
rv = rdr.Exists();
if (rv)
fsdb.Change_repo(Xof_repo_itm_.Repo_remote, Xow_domain_itm_.Bry__commons); // set commons.wikimedia.org; DATE:2015-08-05
fsdb.Change_repo(Xof_repo_tid_.Tid__remote, Xow_domain_itm_.Bry__commons); // set commons.wikimedia.org; DATE:2015-08-05
else
Handle_error();
}
@@ -66,15 +66,15 @@ public class Xof_bin_wkr__http_wmf implements Xof_bin_wkr {
Thread_adp_.Sleep(fail_timeout); // as per WMF policy, pause 1 second for every cache miss; http://lists.wikimedia.org/pipermail/wikitech-l/2013-September/071948.html
}
private void Init_download(byte[] orig_repo, byte[] orig_ttl, byte[] orig_md5, Xof_ext orig_ext, boolean lnki_is_thumb, int file_w, double lnki_time, int lnki_page, Io_url file_url) {
byte mode = lnki_is_thumb ? Xof_repo_itm_.Mode_thumb : Xof_repo_itm_.Mode_orig;
byte mode = lnki_is_thumb ? Xof_img_mode_.Tid__thumb : Xof_img_mode_.Tid__orig;
Xof_repo_pair repo_itm = repo_mgr.Repos_get_by_wiki(orig_repo);
String src = url_bldr.Init_for_src_file(mode, repo_itm.Src(), orig_ttl, orig_md5, orig_ext, file_w, lnki_time, lnki_page).Xto_str();
String src = url_bldr.Init_for_src_file(repo_itm.Src(), mode, orig_ttl, orig_md5, orig_ext, file_w, lnki_time, lnki_page).Xto_str();
download_wkr.Init(src, file_url);
}
private String Make_src(byte[] orig_repo, byte[] orig_ttl, byte[] orig_md5, Xof_ext orig_ext, boolean lnki_is_thumb, int file_w, double lnki_time, int lnki_page, Io_url file_url) {
byte mode = lnki_is_thumb ? Xof_repo_itm_.Mode_thumb : Xof_repo_itm_.Mode_orig;
byte mode = lnki_is_thumb ? Xof_img_mode_.Tid__thumb : Xof_img_mode_.Tid__orig;
Xof_repo_pair repo_itm = repo_mgr.Repos_get_by_wiki(orig_repo);
return url_bldr.Init_for_src_file(mode, repo_itm.Src(), orig_ttl, orig_md5, orig_ext, file_w, lnki_time, lnki_page).Xto_str();
return url_bldr.Init_for_src_file(repo_itm.Src(), mode, orig_ttl, orig_md5, orig_ext, file_w, lnki_time, lnki_page).Xto_str();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_fail_timeout_)) fail_timeout = m.ReadInt("v");

View File

@@ -31,7 +31,7 @@ public class Xof_bin_wkr__http_wmf__tst {
fxt.Exec__Get_as_rdr(fsdb_itm, Bool_.Y, 220); // look in enwiki
fxt.Test__Get_as_rdr__rdr("test_data"); // test that enwiki tries commons again
Tfds.Eq_str("commons.wikimedia.org", fsdb_itm.Orig_repo_name(), "repo_name"); // test that it's now commons
Tfds.Eq_byte(Xof_repo_itm_.Repo_remote, fsdb_itm.Orig_repo_id(), "repo_tid"); // test that it's now commons
Tfds.Eq_byte(Xof_repo_tid_.Tid__remote, fsdb_itm.Orig_repo_id(), "repo_tid"); // test that it's now commons
}
@Test public void Long_filename_becomes_thumbnail() {
String filename = String_.Repeat("A", 200) + ".png";

View File

@@ -17,7 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*;
import gplx.dbs.*; import gplx.fsdb.*; import gplx.xowa.wikis.*; import gplx.xowa.files.repos.*;
import gplx.dbs.*; import gplx.fsdb.*; import gplx.xowa.wikis.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
class Xofc_fil_mgr {
private Xof_cache_mgr cache_mgr;
private final Xofc_fil_tbl tbl = new Xofc_fil_tbl(); private final Ordered_hash hash = Ordered_hash_.New_bry(); private final Bry_bfr key_bldr = Bry_bfr_.Reset(255);
@@ -118,7 +119,7 @@ class Xofc_fil_mgr {
finally {tbl.Conn().Txn_end();}
}
private void Fsys_delete(Xof_url_bldr url_bldr, Xoae_wiki_mgr wiki_mgr, Xoa_repo_mgr repo_mgr, Xofc_dir_mgr dir_mgr, Xofc_fil_itm itm) {
byte mode_id = itm.Is_orig() ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb;
byte mode_id = itm.Is_orig() ? Xof_img_mode_.Tid__orig : Xof_img_mode_.Tid__thumb;
byte[] wiki_domain = dir_mgr.Get_by_id(itm.Dir_id()).Name();
Xowe_wiki wiki = wiki_mgr.Get_by_or_make(wiki_domain);
wiki.Init_assert();
@@ -126,7 +127,7 @@ class Xofc_fil_mgr {
byte[] ttl = itm.Name();
byte[] md5 = Xof_file_wkr_.Md5(ttl);
int itm_ext_id = itm.Ext().Id();
Io_url fil_url = url_bldr.Init_for_trg_file(mode_id, trg_repo, ttl, md5, itm.Ext(), itm.W()
Io_url fil_url = url_bldr.Init_for_trg_file(trg_repo, mode_id, ttl, md5, itm.Ext(), itm.W()
, Xof_lnki_time.Convert_to_xowa_thumbtime (itm_ext_id, itm.Time())
, Xof_lnki_time.Convert_to_xowa_page (itm_ext_id, itm.Time())
).Xto_url();

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.users.data.*;
public class Xou_cache_mgr {
private final Xoa_wiki_mgr wiki_mgr; private final Xou_cache_tbl cache_tbl; private final Db_cfg_tbl cfg_tbl; private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(512);
@@ -169,8 +169,8 @@ public class Xou_cache_mgr {
byte[] orig_md5 = cache.Orig_ttl_md5();
Xof_ext orig_ext = cache.Orig_ext_itm();
orig_ttl = trg_repo.Gen_name_trg(tmp_bfr, orig_ttl, orig_md5, orig_ext);
byte mode_id = cache.File_is_orig() ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb;
return url_bldr.Init_for_trg_file(mode_id, trg_repo, orig_ttl, orig_md5, orig_ext, cache.File_w()
byte mode_id = cache.File_is_orig() ? Xof_img_mode_.Tid__orig : Xof_img_mode_.Tid__thumb;
return url_bldr.Init_for_trg_file(trg_repo, mode_id, orig_ttl, orig_md5, orig_ext, cache.File_w()
, Xof_lnki_time.Convert_to_xowa_thumbtime (orig_ext.Id(), cache.File_time())
, Xof_lnki_time.Convert_to_xowa_page (orig_ext.Id(), cache.File_page())
).Xto_url();

View File

@@ -78,7 +78,7 @@ class Xou_cache_mgr_fxt {
byte[] wiki_domain = Bry_.new_a7(wiki);
byte[] file_ttl = Bry_.new_a7(file);
rv.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, wiki_domain, file_ttl, Byte_.Zero, 1, 1, 1 ,1, 1, 1);
rv.Init_at_orig(Xof_repo_itm_.Repo_local, wiki_domain, file_ttl, Xof_ext_.new_by_id_(Xof_ext_.Id_png), 120, 120, Bry_.Empty);
rv.Init_at_orig(Xof_repo_tid_.Tid__local, wiki_domain, file_ttl, Xof_ext_.new_by_id_(Xof_ext_.Id_png), 120, 120, Bry_.Empty);
rv.File_size_(size);
return rv;
}

View File

@@ -24,7 +24,7 @@ import gplx.xowa.wikis.nss.*;
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();
private final Fsd_thm_itm tmp_thm = Fsd_thm_itm.new_();
public void Rls() {}
public void Reset() {
Io_mgr.Instance.InitEngine_mem(); // NOTE: files are downloaded to mem_engine, regardless of Db being mem or sqlite; always reset
@@ -61,7 +61,7 @@ class Xof_file_fxt {
if (arg.Is_thumb())
mnt_itm.Insert_thm(tmp_thm, atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Time(), arg.Page(), arg.Bin().length, gplx.core.ios.streams.Io_stream_rdr_.mem_(arg.Bin()));
else
mnt_itm.Insert_img(tmp_img, atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Bin().length, gplx.core.ios.streams.Io_stream_rdr_.mem_(arg.Bin()));
mnt_itm.Insert_img(atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Bin().length, gplx.core.ios.streams.Io_stream_rdr_.mem_(arg.Bin()));
}
public void Exec_get(Xof_exec_arg arg) {
byte[] ttl_bry = arg.Ttl();
@@ -119,7 +119,7 @@ class Xof_orig_arg {
public static Xof_orig_arg new_comm_redirect(String src, String trg) {return new_(Bool_.Y, src, 440, 400, trg);}
private static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h) {return new_(repo_is_commons, page, w, h, null);}
public static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h, String redirect_str) {
byte repo = repo_is_commons ? Xof_repo_itm_.Repo_remote : Xof_repo_itm_.Repo_local;
byte repo = repo_is_commons ? Xof_repo_tid_.Tid__remote : Xof_repo_tid_.Tid__local;
byte[] redirect = redirect_str == null ? Bry_.Empty : Bry_.new_u8(redirect_str);
return new Xof_orig_arg(repo, Bry_.new_u8(page), w, h, redirect);
}

View File

@@ -0,0 +1,26 @@
/*
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.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
public class Xof_img_mode_ {
public static final byte
Tid__orig = 0
, Tid__thumb = 1
;
public static byte By_bool(boolean is_thumb) {return is_thumb ? Tid__thumb : Tid__orig;}
public static final byte[][] Names_ary = new byte[][] {Bry_.new_a7("orig"), Bry_.new_a7("thumb")};
}

View File

@@ -0,0 +1,42 @@
/*
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.*;
public class Xof_itm_ttl_ {
public static byte[] Remove_invalid(Bry_bfr bfr, byte[] ttl) {
int ttl_len = ttl.length;
for (int i = 0; i < ttl_len; i++) {
byte b = ttl[i];
if (gplx.core.envs.Op_sys_.Wnt_invalid_char(b)) b = Byte_ascii.Underline;
bfr.Add_byte(b);
}
return bfr.To_bry_and_clear();
}
public static byte[] Shorten(Bry_bfr bfr, byte[] ttl, int ttl_max, byte[] md5, byte[] ext_bry) {
byte[] rv = ttl;
int exceed_len = rv.length - ttl_max;
if (exceed_len > 0) {
bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
bfr.Add_byte(Byte_ascii.Dot); // add dot; EX: "."
bfr.Add(ext_bry); // add ext; EX: ".png"
rv = bfr.To_bry_and_clear();
}
return rv;
}
}

View File

@@ -16,8 +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.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.btries.*; import gplx.core.consoles.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*;
import gplx.core.consoles.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.wikis.domains.*;
public class Xof_repo_itm implements Gfo_invk {
private final Xoa_fsys_mgr app_fsys; private final Xof_rule_mgr ext_rule_mgr;
@@ -25,23 +25,33 @@ public class Xof_repo_itm implements Gfo_invk {
this.key = key; this.app_fsys = app_fsys; this.ext_rule_mgr = ext_rule_mgr;
Wiki_domain_(wiki_domain);
}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Wiki_domain() {return wiki_domain;} private byte[] wiki_domain;
public byte[] Wiki_abrv_xo() {return wiki_abrv_xo;} private byte[] wiki_abrv_xo;
public byte[] Root_bry() {return root_bry;} private byte[] root_bry;
public byte[] Root_http() {return root_http;} private byte[] root_http = Bry_.Empty;
public String Root_str() {return root_str;} private String root_str;
public byte Dir_spr() {return dir_spr;} private byte dir_spr;
public boolean Fsys_is_wnt() {return fsys_is_wnt;} public Xof_repo_itm Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;} private boolean fsys_is_wnt;
public boolean Shorten_ttl() {return shorten_ttl;} public Xof_repo_itm Shorten_ttl_(boolean v) {shorten_ttl = v; return this;} private boolean shorten_ttl = true;
public boolean Wmf_fsys() {return wmf_fsys;} public Xof_repo_itm Wmf_fsys_(boolean v) {wmf_fsys = v; return this;} private boolean wmf_fsys;
public boolean Wmf_api() {return wmf_api;} public Xof_repo_itm Wmf_api_(boolean v) {wmf_api = v; return this;} private boolean wmf_api;
public boolean Tarball() {return tarball;} public Xof_repo_itm Tarball_(boolean v) {tarball = v; return this;} private boolean tarball;
public byte[][] Mode_names() {return mode_names;} private byte[][] mode_names = new byte[][] {Xof_repo_itm_.Mode_names_key[0], Xof_repo_itm_.Mode_names_key[1]};
public int Dir_depth() {return dir_depth;} public Xof_repo_itm Dir_depth_(int v) {dir_depth = v; return this;} private int dir_depth = 4;
public Xof_rule_grp Ext_rules() {return ext_rules;} private Xof_rule_grp ext_rules;
public byte[] Key() {return key;} private final byte[] key; // EX: "src_http_commons"
public byte Tid() {return tid;} private byte tid; // EX: Xof_repo_tid_.Tid__remote
public byte[] Wiki_domain() {return wiki_domain;} private byte[] wiki_domain; // EX: "commons.wikimedia.org"
public byte[] Wiki_abrv_xo() {return wiki_abrv_xo;} private byte[] wiki_abrv_xo; // EX: "c"
public byte Dir_spr() {return dir_spr;} private byte dir_spr; // EX: "/"
public int Dir_depth() {return dir_depth;} private int dir_depth = 4; // EX: "/1/2/3/4" vs "/1/2"
public byte[] Root_bry() {return root_bry;} private byte[] root_bry; // EX:
public byte[] Root_http() {return root_http;} private byte[] root_http = Bry_.Empty; // EX:
public String Root_str() {return root_str;} private String root_str;
public boolean Fsys_is_wnt() {return fsys_is_wnt;} private boolean fsys_is_wnt;
public boolean Shorten_ttl() {return shorten_ttl;} private boolean shorten_ttl = true;
public boolean Wmf_fsys() {return wmf_fsys;} private boolean wmf_fsys;
public boolean Wmf_api() {return wmf_api;} private boolean wmf_api;
public boolean Tarball() {return tarball;} private boolean tarball;
public byte[][] Mode_names() {return mode_names;} private byte[][] mode_names = new byte[][] {Xof_img_mode_.Names_ary[0], Xof_img_mode_.Names_ary[1]};
public Xof_rule_grp Ext_rules() {return ext_rules;} private Xof_rule_grp ext_rules;
public boolean Primary() {return primary;} private boolean primary;
public Xof_repo_itm Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;}
public Xof_repo_itm Shorten_ttl_(boolean v) {shorten_ttl = v; return this;}
public Xof_repo_itm Wmf_fsys_(boolean v) {wmf_fsys = v; return this;}
public Xof_repo_itm Wmf_api_(boolean v) {wmf_api = v; return this;}
public Xof_repo_itm Tarball_(boolean v) {tarball = v; return this;}
public Xof_repo_itm Ext_rules_(byte[] ext_rules_key) {ext_rules = ext_rule_mgr.Get_or_new(ext_rules_key); return this;}
public boolean Primary() {return primary;} public Xof_repo_itm Primary_(boolean v) {primary = v; return this;} private boolean primary;
public Xof_repo_itm Dir_depth_(int v) {dir_depth = v; return this;}
public Xof_repo_itm Primary_(boolean v) {primary = v; return this;}
public void Wiki_domain_(byte[] v) {
this.wiki_domain = v;
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(v);
@@ -70,11 +80,11 @@ public class Xof_repo_itm implements Gfo_invk {
}
public byte[] Gen_name_src(Bry_bfr tmp_bfr, byte[] name) {
if (!fsys_is_wnt || wmf_fsys) return name;
return Xof_repo_itm_.Ttl_invalid_fsys_chars(tmp_bfr, name);
return Xof_itm_ttl_.Remove_invalid(tmp_bfr, name);
}
public byte[] Gen_name_trg(Bry_bfr tmp_bfr, byte[] bry, byte[] md5, Xof_ext ext) {
byte[] rv = Gen_name_src(tmp_bfr, bry);
return shorten_ttl ? Xof_repo_itm_.Ttl_shorten_ttl(tmp_bfr, rv, Ttl__max_len, md5, ext.Ext()) : rv;
return shorten_ttl ? Xof_itm_ttl_.Shorten(tmp_bfr, rv, Ttl__max_len, md5, ext.Ext()) : rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) throw Err_.new_unimplemented_w_msg("deprecated repo_itm.owner");
@@ -83,9 +93,10 @@ public class Xof_repo_itm implements Gfo_invk {
else if (ctx.Match(k, Invk_ext_rules_)) Ext_rules_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_wmf_api_)) wmf_api = m.ReadYn("v");
else if (ctx.Match(k, Invk_tarball_)) tarball = m.ReadYn("v");
else if (ctx.Match(k, Invk_tid_)) tid = Xof_repo_tid_.By_str(m.ReadStr("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_owner = "owner", Invk_fsys_ = "fsys_", Invk_ext_rules_ = "ext_rules_", Invk_primary_ = "primary_", Invk_wmf_api_ = "wmf_api_", Invk_tarball_ = "tarball_";
private static final String Invk_owner = "owner", Invk_fsys_ = "fsys_", Invk_ext_rules_ = "ext_rules_", Invk_primary_ = "primary_", Invk_wmf_api_ = "wmf_api_", Invk_tarball_ = "tarball_", Invk_tid_ = "tid_";
public static final int Ttl__max_len = 180;
}

View File

@@ -1,56 +0,0 @@
/*
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.core.btries.*; import gplx.core.envs.*;
public class Xof_repo_itm_ {
public static final int Dir_depth_null = -1, Dir_depth_wmf = 2, Dir_depth_xowa = 4;
public static final byte Mode_orig = 0, Mode_thumb = 1, Mode_nil = Byte_.Max_value_127;
public static byte Mode_by_bool(boolean is_thumb) {return is_thumb ? Mode_thumb : Mode_orig;}
public static final byte[][] Mode_names_key = new byte[][] {Bry_.new_a7("orig"), Bry_.new_a7("thumb")};
public static final byte Repo_remote = 0, Repo_local = 1, Repo_unknown = 126, Repo_null = Byte_.Max_value_127;
public static byte Repo_by_bool(boolean is_commons) {return is_commons ? Repo_remote : Repo_local;}
public static boolean Repo_is_known(byte repo) {
switch (repo) {
case Repo_remote:
case Repo_local: return true;
default: return false;
}
}
public static byte[] Ttl_invalid_fsys_chars(Bry_bfr bfr, byte[] ttl) {
int ttl_len = ttl.length;
for (int i = 0; i < ttl_len; i++) {
byte b = ttl[i];
if (Op_sys_.Wnt_invalid_char(b)) b = Byte_ascii.Underline;
bfr.Add_byte(b);
}
return bfr.To_bry_and_clear();
}
public static byte[] Ttl_shorten_ttl(Bry_bfr bfr, byte[] ttl, int ttl_max, byte[] md5, byte[] ext_bry) {
byte[] rv = ttl;
int exceed_len = rv.length - ttl_max;
if (exceed_len > 0) {
bfr.Add_mid(rv, 0, ttl_max - 33); // add truncated title; 33=_.length + md5.length
bfr.Add_byte(Byte_ascii.Underline); // add underline; EX: "_"
bfr.Add(md5); // add md5; EX: "abcdefghijklmnopqrstuvwxyz0123456"
bfr.Add_byte(Byte_ascii.Dot); // add dot; EX: "."
bfr.Add(ext_bry); // add ext; EX: ".png"
rv = bfr.To_bry_and_clear();
}
return rv;
}
}

View File

@@ -17,15 +17,16 @@ 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.*;
public class Xof_repo_pair implements Gfo_invk {
public Xof_repo_pair(byte repo_idx, byte[] wiki_domain, Xof_repo_itm src, Xof_repo_itm trg) {
this.repo_idx = repo_idx; this.wiki_domain = wiki_domain; this.src = src; this.trg = trg;
public Xof_repo_pair(byte id, byte[] wiki_domain, Xof_repo_itm src, Xof_repo_itm trg) {
this.id = id; this.wiki_domain = wiki_domain; this.src = src; this.trg = trg;
}
public byte Repo_idx() {return repo_idx;} private byte repo_idx;
public byte[] Wiki_domain() {return wiki_domain;} private final byte[] wiki_domain;
public Xof_repo_itm Src() {return src;} private final Xof_repo_itm src;
public Xof_repo_itm Trg() {return trg;} private final Xof_repo_itm trg;
public byte Id() {return id;} private byte id;
public byte[] Wiki_domain() {return wiki_domain;} private final byte[] wiki_domain;
public Xof_repo_itm Src() {return src;} private final Xof_repo_itm src;
public Xof_repo_itm Trg() {return trg;} private final Xof_repo_itm trg;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_repo_id_)) repo_idx = m.ReadByte("v");
if (ctx.Match(k, Invk_repo_id_)) id = m.ReadByte("v");
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_repo_id_ = "repo_id_";

View File

@@ -0,0 +1,36 @@
/*
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.*;
public class Xof_repo_tid_ {
public static final byte
Tid__remote = 0 // EX: "https://commons.wikimedia.org/wiki/File:A.png"
, Tid__local = 1 // EX: "https://en.wikipedia.org/wiki/File:A.png"
, Tid__xtns = 2 // EX: "https://en.wikipedia.org/w/extensions/ImageMap/desc-20.png?15600"
, Tid__math = 3 // EX: "https://wikimedia.org/api/rest_v1/media/math/render/svg/596f8baf206a81478afd4194b44138715dc1a05c"
, Tid__null = Byte_.Max_value_127
;
public static byte By_str(String v) {
if (String_.Eq(v, "self")) return Tid__local;
else if (String_.Eq(v, "comm")) return Tid__remote;
else if (String_.Eq(v, "math")) return Tid__math;
else throw Err_.new_unhandled_default(v);
}
public static final byte[]
Bry__math = Bry_.new_a7("wikimedia.org/math") // EX: https://wikimedia.org/api/rest_v1/media/math/render/svg/596f8baf206a81478afd4194b44138715dc1a05c
;
}

View File

@@ -55,7 +55,7 @@ public class Xowe_repo_mgr implements Xow_repo_mgr, Gfo_invk {
int len = repos.Count();
for (int i = 0; i < len; i++) {
Xof_repo_pair pair = (Xof_repo_pair)repos.Get_at(i);
if (pair.Repo_idx() == id) return pair;
if (pair.Id() == id) return pair;
}
return null;
}

View File

@@ -17,7 +17,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.gfui.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.downloads.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.downloads.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.bldrs.wms.*; import gplx.xowa.apps.wms.apis.*; import gplx.xowa.apps.wms.apis.origs.*;
import gplx.xowa.wikis.tdbs.metas.*;
public class Xof_xfer_mgr {
@@ -74,8 +74,8 @@ public class Xof_xfer_mgr {
}
// BLOCK: orig; get orig for convert; note that Img_download will not download file again if src exists
src_str = this.Src_url(src_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size__neg1);
trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size__neg1);
src_str = this.Src_url(src_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size__neg1);
trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size__neg1);
if (!Img_download(src_str, trg_url, false)) return false;
trg_url = rslt.Trg();
@@ -84,7 +84,7 @@ public class Xof_xfer_mgr {
rslt.Clear(); // clear error from failed thumb
Io_url src_url = trg_url;
if (orig_ext.Id_is_djvu()) { // NOTE: this block converts djvu -> tiff b/c vanilla imageMagick cannot do djvu -> jpeg
trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_thumb, lnki_w).GenNewExt(".tiff"); // NOTE: manually change orig_ext to tiff; note that djvu has view type of jpeg
trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__thumb, lnki_w).GenNewExt(".tiff"); // NOTE: manually change orig_ext to tiff; note that djvu has view type of jpeg
wiki.Appe().File_mgr().Img_mgr().Wkr_convert_djvu_to_tiff().Exec(src_url, trg_url);
if (!Cmd_query_size(trg_url)) return false;
// meta_itm.Update_orig_size(file_w, file_h); // NOTE that thumb size is always orig size
@@ -93,7 +93,7 @@ public class Xof_xfer_mgr {
boolean limit = !orig_ext.Id_is_svg(); // do not limit if svg
Xof_xfer_itm_.Calc_xfer_size(calc_size, xfer_itm.Lnki_type(), wiki.Html_mgr().Img_thumb_width(), file_w, file_h, lnki_w, lnki_h, lnki_thumbable, xfer_itm.Lnki_upright(), limit); // NOTE: always recalc w/h; needed for (a) when width < 1 and (b) when w/h are wrong; xfer=160,160, lnki=65,50, actl should be 50,50; PAGE:en.w:[[Image:Gnome-mime-audio-openclipart.svg|65x50px|center|link=|alt=]]
lnki_w = calc_size.Val_0(); lnki_h = calc_size.Val_1();
trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__thumb, lnki_w);
if (!Img_convert(src_url, trg_url)) return false; // convert failed; exit
if (orig_ext.Id_is_djvu()) Io_mgr.Instance.DeleteFil(src_url); // convert passed; if djvu, delete intermediary .tiff file;
}
@@ -110,7 +110,7 @@ public class Xof_xfer_mgr {
xfer_itm.Orig_repo_id_(Xof_meta_itm.Repo_same); // set repo to "same"
else { // wmf returned other wiki (which is 99% likely to be commons)
Xof_repo_pair trg_repo_pair = wiki.File_mgr().Repo_mgr().Repos_get_by_wiki(rslts.Orig_wiki()); // need to do this b/c commons is not always first; see wikinews; DATE:2013-12-04
int trg_repo_idx = trg_repo_pair == null ? 0 : (int)trg_repo_pair.Repo_idx(); // 0=commons
int trg_repo_idx = trg_repo_pair == null ? 0 : (int)trg_repo_pair.Id(); // 0=commons
xfer_itm.Orig_repo_id_(trg_repo_idx);
}
if (!Bry_.Eq(rslts.Orig_page(), orig_ttl)) {
@@ -139,7 +139,7 @@ public class Xof_xfer_mgr {
if (!wmf_api_found) return false; // not found in wmf_api; exit now
}
else if (src_repo.Tarball()) {
String src_str = this.Src_url(src_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size__neg1);
String src_str = this.Src_url(src_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size__neg1);
meta_itm.Orig_exists_(Xof_meta_itm.Exists_unknown); // mark exists unknown; note need to assertively mark unknown b/c it may have been marked n in previous pass through multiple repos; DATE:20121227
meta_itm.Vrtl_repo_(Xof_meta_itm.Repo_unknown); // mark repo unknown;
if (!Cmd_query_size(Io_url_.new_fil_(src_str))) {
@@ -163,8 +163,8 @@ public class Xof_xfer_mgr {
lnki_w = calc_size.Val_0();
if (lnki_h != -1) lnki_h = calc_size.Val_1(); // NOTE: if -1 (no height specified) do not set height; EX:Tokage_2011-07-15.jpg; DATE:2013-06-03
src_str = src_repo.Tarball() ? this.Src_url(src_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size_null) : this.Src_url(src_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
src_str = src_repo.Tarball() ? this.Src_url(src_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size_null) : this.Src_url(src_repo, Xof_img_mode_.Tid__thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__thumb, lnki_w);
if (Make_img_exec(src_str, trg_url)) { // download passed
trg_url = rslt.Trg();
if (lnki_w > 0 && lnki_h > 0) { // lnki specified width and height; check against xfer; needed when w/h are wrong; lnki=65,50 but xfer=160,160; actl should be 50,50; PAGE:en.w:[[Image:Gnome-mime-audio-openclipart.svg|65x50px|center|link=|alt=]]; SEE:NOTE_1
@@ -191,23 +191,23 @@ public class Xof_xfer_mgr {
Xof_xfer_itm_.Calc_xfer_size(calc_size, xfer_itm.Lnki_type(), wiki.Html_mgr().Img_thumb_width(), meta_itm.Orig_w(), meta_itm.Orig_h(), lnki_w, lnki_h, lnki_thumbable, lnki_upright, limit);
lnki_w = calc_size.Val_0(); lnki_h = calc_size.Val_1();
src_str = src_repo.Tarball() ? this.Src_url(src_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size_null) : this.Src_url(src_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
src_str = src_repo.Tarball() ? this.Src_url(src_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size_null) : this.Src_url(src_repo, Xof_img_mode_.Tid__thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__thumb, lnki_w);
return Make_img_exec(src_str, trg_url);
}
else { // no orig dimensions; do download
if (lnki_w == Xof_img_size.Null)
lnki_w = wiki.Html_mgr().Img_thumb_width(); // set lnki_w to default thumb_width (220)
src_str = src_repo.Tarball() ? this.Src_url(src_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size_null) : this.Src_url(src_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
src_str = src_repo.Tarball() ? this.Src_url(src_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size_null) : this.Src_url(src_repo, Xof_img_mode_.Tid__thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__thumb, lnki_w);
if (Make_img_exec(src_str, trg_url)) { // download
if (src_repo.Tarball()) return true; // convert worked; no need to download again;
int old_lnki_w = lnki_w;
lnki_w = (file_w * lnki_h) / file_h; // calculate correct width for specified height;
lnki_w = Xof_xfer_itm_.Calc_w(file_w, file_h, lnki_h);
if (lnki_w == old_lnki_w) return true; // download at 220 actually worked; this will probably occur very infrequently, but if so, exit
src_str = this.Src_url(src_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
src_str = this.Src_url(src_repo, Xof_img_mode_.Tid__thumb, lnki_w);
trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__thumb, lnki_w);
if (Make_img_exec(src_str, trg_url)) { // download again
trg_url = rslt.Trg();
Xof_xfer_itm_.Calc_xfer_size(calc_size, xfer_itm.Lnki_type(), wiki.Html_mgr().Img_thumb_width(), file_w, file_h, lnki_w, lnki_h, lnki_thumbable, lnki_upright);// calculate again using width and height
@@ -235,8 +235,8 @@ public class Xof_xfer_mgr {
boolean thumb_pass = false;
Make_other(); // NOTE: must go before thumb b/c rslt.Pass() is modified by both
if (src_repo_is_wmf) { // src is wmf >>> copy down thumb; NOTE: thumb not available in tar
String src_str = this.Src_url(src_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
Io_url trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_thumb, lnki_w);
String src_str = this.Src_url(src_repo, Xof_img_mode_.Tid__thumb, lnki_w);
Io_url trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__thumb, lnki_w);
thumb_pass = Cmd_download(src_str, trg_url, false); // NOTE: ogg audios may sometimes have thumb, but 0 size; thumb_pass will be true, but will fail on thumb_rename; PAGE:en.w:Beethoven; [[File:Ludwig van Beethoven - Symphonie 5 c-moll - 1. Allegro con brio.ogg]]
if (thumb_pass) {
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
@@ -257,8 +257,8 @@ public class Xof_xfer_mgr {
}
boolean Make_other() {
if (!Orig_max_download() && !force_orig) return false;
String src_str = this.Src_url(src_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size__neg1);
Io_url trg_url = this.Trg_url(trg_repo, Xof_repo_itm_.Mode_orig, Xof_img_size.Size__neg1);
String src_str = this.Src_url(src_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size__neg1);
Io_url trg_url = this.Trg_url(trg_repo, Xof_img_mode_.Tid__orig, Xof_img_size.Size__neg1);
return Cmd_download(src_str, trg_url, true);
}
boolean Orig_max_download() {
@@ -353,8 +353,8 @@ public class Xof_xfer_mgr {
file_w = file_size.Width(); file_h = file_size.Height();
return true;
}
String Src_url(Xof_repo_itm repo, byte mode, int lnki_w) {return url_bldr.Init_for_src_file(mode, repo, orig_ttl, orig_ttl_md5, orig_ext, lnki_w, lnki_thumbtime, lnki_page).Xto_str();}
Io_url Trg_url(Xof_repo_itm repo, byte mode, int lnki_w) {return url_bldr.Init_for_trg_file(mode, repo, orig_ttl, orig_ttl_md5, orig_ext, lnki_w, lnki_thumbtime, lnki_page).Xto_url();}
String Src_url(Xof_repo_itm repo, byte mode, int lnki_w) {return url_bldr.Init_for_src_file(repo, mode, orig_ttl, orig_ttl_md5, orig_ext, lnki_w, lnki_thumbtime, lnki_page).Xto_str();}
Io_url Trg_url(Xof_repo_itm repo, byte mode, int lnki_w) {return url_bldr.Init_for_trg_file(repo, mode, orig_ttl, orig_ttl_md5, orig_ext, lnki_w, lnki_thumbtime, lnki_page).Xto_url();}
private Xof_url_bldr url_bldr = new Xof_url_bldr();
}
/*