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

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
/*
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.addons.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.addons.bldrs.files.cmds.*;
import gplx.xowa.addons.bldrs.mass_parses.inits.*; import gplx.xowa.addons.bldrs.mass_parses.parses.*; import gplx.xowa.addons.bldrs.mass_parses.makes.*; import gplx.xowa.addons.bldrs.mass_parses.resumes.*;
import gplx.xowa.addons.bldrs.files.cksums.*; import gplx.xowa.addons.bldrs.files.checks.*;
import gplx.xowa.addons.bldrs.app_cfgs.wm_server_cfgs.*;
public class Xoax_builds_files_addon implements Xoax_addon_itm, Xoax_addon_itm__bldr {
public Xob_cmd[] Bldr_cmds() {
return new Xob_cmd[]
{ Xobldr__lnki_temp__create.Prototype
, Xobldr__lnki_regy__create.Prototype
, Xobldr__page_regy__create.Prototype
, Xobldr__orig_regy__create.Prototype
, Xobldr__orig_regy__find_missing.Prototype
, Xobldr__xfer_temp__insert_thm.Prototype
, Xobldr__xfer_temp__insert_orig.Prototype
, Xobldr__xfer_regy__create.Prototype
, Xobldr__xfer_regy__update_downloaded.Prototype
, Xobldr__fsdb_db__create_data.Prototype
, Xobldr__fsdb_db__create_orig.Prototype
, Xobldr__page_file_map__create.Prototype
, Xobldr__text_db__make_page.Prototype
, Xobldr__text_db__drop_page.Prototype
, Xobldr__redirect__create.Prototype
, Xobldr__image__create.Prototype
, Xomp_init_cmd.Prototype
, Xomp_parse_cmd.Prototype
, Xomp_make_cmd.Prototype
, Xomp_resume_cmd.Prototype
, Xocksum_calc_cmd.Prototype
, Xocheck_cmd.Prototype
, Xowm_server_cfg_cmd.Prototype
};
}
public String Addon__key() {return "xowa.builds.images";}
}

View File

@@ -0,0 +1,30 @@
/*
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.addons.bldrs.files.checks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xocheck_cmd extends Xob_cmd__base { // checks fsdb; needed for en.w and multiple monthly updates
public Xocheck_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
new Xocheck_mgr().Exec(wiki);
}
@Override public String Cmd_key() {return BLDR_CMD_KEY;} private static final String BLDR_CMD_KEY = "fsdb.check";
public static final Xob_cmd Prototype = new Xocheck_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xocheck_cmd(bldr, wiki);}
}

View File

@@ -0,0 +1,89 @@
/*
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.addons.bldrs.files.checks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.ios.streams.*;
import gplx.dbs.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*;
import gplx.xowa.addons.bldrs.wmdumps.imglinks.*;
import gplx.xowa.htmls.*;
// TODO.XO:cache files in memory, else commonly used files (Wiki.png) will be loaded from fsdb for every usage on page
// TODO.XO:save results to db to verify unused images (images in fsdb, but not loaded during this code)
class Xocheck_mgr {
private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private final Xof_img_size img_size = new Xof_img_size();
private Xowe_wiki wiki;
public void Exec(Xowe_wiki wiki) {
// init
this.wiki = wiki;
wiki.File__bin_mgr().Wkrs__del(gplx.xowa.files.bins.Xof_bin_wkr_.Key_http_wmf); // must happen after init_file_mgr_by_load; remove wmf wkr, else will try to download images during parsing
wiki.File_mgr().Fsdb_mode().Tid__v2__mp__y_();
wiki.App().Cfg().Set_bool_app("xowa.app.web.enabled", false); // never enable inet; rely solely on local dbs;
// select list of pages
Xoh_page hpg = new Xoh_page();
Xowd_page_tbl page_tbl = wiki.Data__core_mgr().Db__core().Tbl__page();
Db_rdr rdr = page_tbl.Conn().Stmt_sql("SELECT page_id, page_namespace, page_title, page_html_db_id FROM page WHERE page_html_db_id != -1;").Exec_select__rls_auto();
int page_count = 0, file_count = 0;
// loop over each page
while (rdr.Move_next()) {
// init page meta
Xoa_ttl page_ttl = wiki.Ttl_parse(rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"));
Xoa_url page_url = Xoa_url.New(wiki, page_ttl);
Xow_db_file html_db = wiki.Data__core_mgr().Dbs__get_by_id_or_fail(rdr.Read_int("page_html_db_id"));
int page_id = rdr.Read_int("page_id");
// load html
hpg.Ctor_by_hview(wiki, page_url, page_ttl, page_id);
if (!html_db.Tbl__html().Select_by_page(hpg)) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not load html for page; page_id=~{0}", page_id);
continue;
}
wiki.Html__hdump_mgr().Load_mgr().Parse(hpg, hpg.Db().Html().Zip_tid(), hpg.Db().Html().Hzip_tid(), hpg.Db().Html().Html_bry());
// load images
int imgs_len = hpg.Img_mgr().Len();
for (int i = 0; i < imgs_len; i++) {
Xof_fsdb_itm fsdb = hpg.Img_mgr().Get_at(i);
try {Check_images(page_ttl, fsdb);}
catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "file failed; page_ttl=~{0} img_name=~{1} err=~{2}", page_ttl.Page_db(), fsdb.Lnki_ttl(), Err_.Message_gplx_log(e));
}
file_count++;
}
// prog
page_count++;
if ((page_count % 10000) == 0) {
Gfo_usr_dlg_.Instance.Prog_many("", "", "checking pages; pages=~{0} files=~{1}", page_count, file_count);
}
}
}
private void Check_images(Xoa_ttl page_ttl, Xof_fsdb_itm fsdb) {
// get orig
Xof_orig_itm orig = wiki.File__orig_mgr().Find_by_ttl_or_null(fsdb.Lnki_ttl());
if (orig == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "file missing; page_ttl=~{0} img_name=~{1}", page_ttl.Page_db(), fsdb.Lnki_ttl());
return;
}
Xof_file_wkr.Eval_orig(orig, fsdb, url_bldr, wiki.File__repo_mgr(), img_size);
Io_stream_rdr img_rdr = wiki.File__bin_mgr().Find_as_rdr(Xof_exec_tid.Tid_wiki_page, fsdb);
img_rdr.Rls();
}
}

View File

@@ -0,0 +1,30 @@
/*
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.addons.bldrs.files.cksums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xocksum_calc_cmd extends Xob_cmd__base {
public Xocksum_calc_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
new Xocksum_calc_mgr().Exec(wiki);
}
@Override public String Cmd_key() {return BLDR_CMD_KEY;} private static final String BLDR_CMD_KEY = "fsdb.cksums.calc";
public static final Xob_cmd Prototype = new Xocksum_calc_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xocksum_calc_cmd(bldr, wiki);}
}

View File

@@ -0,0 +1,79 @@
/*
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.addons.bldrs.files.cksums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.ios.streams.*; import gplx.core.security.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.cksums.dbs.*;
import gplx.xowa.files.*; import gplx.fsdb.*; import gplx.fsdb.data.*;
public class Xocksum_calc_mgr {
public void Exec(Xowe_wiki wiki) {
// get conn variables
Xocksum_cksum_db db = Xocksum_cksum_db.Get(wiki);
Db_conn conn = db.Conn();
Xocksum_cksum_tbl tbl = db.Tbl__cksum();
conn.Meta_tbl_assert(tbl);
// insert missing items
tbl.Insert_missing();
tbl.Create_idx();
// get updates
int count = 0;
Hash_algo md5_algo = Hash_algo_.New__md5();
List_adp updates = List_adp_.New();
String cur_date = Datetime_now.Get().XtoStr_gplx();
Db_stmt select_stmt = tbl.Select_samples_stmt(10000);
while (true) {
// get cksum_rows
Xocksum_cksum_row[] rows = tbl.Select_samples(select_stmt);
// loop cksum_rows and (a) get bin_data; (b) if md5 diff, then add to updates
int len = rows.length; if (len == 0) break;
for (int i = 0; i < len; ++i) {
Xocksum_cksum_row row = rows[i];
byte[] bin_bry = Get_bin(wiki, row);
if (bin_bry == null) {
Gfo_usr_dlg_.Instance.Prog_many("", "", "null; fil_id=~{0} thm_id=~{1}", row.Fil_id(), row.Thm_id());
bin_bry = Bry_.Empty;
}
row.Bin_size_(bin_bry.length);
byte[] md5 = md5_algo.Hash_bry_as_bry(bin_bry);
if (!Bry_.Eq(md5, row.Cksum_val())) {
row.Cksum_val_(md5);
updates.Add(row);
}
}
// run updates
conn.Txn_bgn("cksum_update");
len = updates.Len();
for (int i = 0; i < len; ++i) {
Xocksum_cksum_row row = (Xocksum_cksum_row)updates.Get_at(i);
tbl.Update(row.Fil_id(), row.Thm_id(), row.Bin_db_id(), row.Bin_size(), row.Cksum_tid(), 0, row.Cksum_val(), cur_date);
if (++count % 2000 == 0) Gfo_usr_dlg_.Instance.Prog_many("", "", "updating; rows=~{0}", count);
}
updates.Clear();
conn.Txn_end();
}
select_stmt.Rls();
}
private byte[] Get_bin(Xowe_wiki wiki, Xocksum_cksum_row row) {
int bin_id = row.Thm_id() == -1 ? row.Fil_id() : row.Thm_id();
Fsd_bin_itm bin_itm = wiki.File__mnt_mgr().Mnts__get_main().Bin_mgr().Dbs__get_at(row.Bin_db_id()).Select_as_itm(bin_id);
return bin_itm.Bin_data();
}
}

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.addons.bldrs.files.cksums.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.cksums.*;
import gplx.dbs.*; import gplx.fsdb.meta.*;
public class Xocksum_cksum_db {
public Xocksum_cksum_db(Db_conn conn) {
this.conn = conn;
this.tbl__cksum = new Xocksum_cksum_tbl(conn);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Xocksum_cksum_tbl Tbl__cksum() {return tbl__cksum;} private final Xocksum_cksum_tbl tbl__cksum;
public static Xocksum_cksum_db Get(Xowe_wiki wiki) {
return new Xocksum_cksum_db(wiki.File__fsdb_core().File__abc_file__at(Fsm_mnt_mgr.Mnt_idx_main).Conn());
}
}

View File

@@ -0,0 +1,41 @@
/*
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.addons.bldrs.files.cksums.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.cksums.*;
public class Xocksum_cksum_row {
public Xocksum_cksum_row(int fil_id, int thm_id, int bin_db_id, long bin_size, byte cksum_tid, int cksum_count, byte[] cksum_val, String cksum_date) {
this.fil_id = fil_id;
this.thm_id = thm_id;
this.bin_db_id = bin_db_id;
this.bin_size = bin_size;
this.cksum_tid = cksum_tid;
this.cksum_count = cksum_count;
this.cksum_val = cksum_val;
this.cksum_date = cksum_date;
}
public int Fil_id() {return fil_id;} private final int fil_id;
public int Thm_id() {return thm_id;} private final int thm_id;
public int Bin_db_id() {return bin_db_id;} private final int bin_db_id;
public long Bin_size() {return bin_size;} private long bin_size;
public byte Cksum_tid() {return cksum_tid;} private final byte cksum_tid;
public int Cksum_count() {return cksum_count;} private final int cksum_count;
public byte[] Cksum_val() {return cksum_val;} private byte[] cksum_val;
public String Cksum_date() {return cksum_date;} private final String cksum_date;
public void Bin_size_(long v) {this.bin_size = v;}
public void Cksum_val_(byte[] v) {this.cksum_val = v;}
}

View File

@@ -0,0 +1,107 @@
/*
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.addons.bldrs.files.cksums.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.cksums.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.addons.wikis.ctgs.*;
public class Xocksum_cksum_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld__fil_id, fld__thm_id, fld__bin_db_id, fld__bin_len, fld__cksum_tid, fld__cksum_count, fld__cksum_val, fld__cksum_date;
private Db_stmt stmt__update;
public Xocksum_cksum_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "fsdb_cksum";
this.fld__fil_id = flds.Add_int("fil_id");
this.fld__thm_id = flds.Add_int("thm_id");
this.fld__bin_db_id = flds.Add_int("bin_db_id");
this.fld__bin_len = flds.Add_long("bin_size");
this.fld__cksum_tid = flds.Add_byte("cksum_tid");
this.fld__cksum_count = flds.Add_int("cksum_count");
this.fld__cksum_val = flds.Add_str("cksum_val", 255);
this.fld__cksum_date = flds.Add_str("cksum_date", 16);
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "fil_id__thm_id", fld__fil_id, fld__thm_id));
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld__cksum_val, fld__cksum_val));
}
public void Insert_missing() {
// insert from fsdb_fil
conn.Exec_sql(Db_sql_.Make_by_fmt(String_.Ary
( "INSERT INTO fsdb_cksum (fil_id, thm_id, bin_db_id, bin_size, cksum_tid, cksum_count, cksum_val, cksum_date)"
, "SELECT f.fil_id, -1, f.fil_bin_db_id, f.fil_size, {0}, 0, '', ''"
, "FROM fsdb_fil f"
, " LEFT JOIN fsdb_cksum c ON c.fil_id = f.fil_id AND c.thm_id = -1"
, "WHERE c.fil_id IS NULL"
, "AND f.fil_bin_db_id != -1"
), Cksum_tid__md5));
// insert from fsdb_fil
conn.Exec_sql(Db_sql_.Make_by_fmt(String_.Ary
( "INSERT INTO fsdb_cksum (fil_id, thm_id, bin_db_id, bin_size, cksum_tid, cksum_count, cksum_val, cksum_date)"
, "SELECT t.thm_owner_id, t.thm_id, t.thm_bin_db_id, t.thm_size, {0}, 0, '', ''"
, "FROM fsdb_thm t"
, " LEFT JOIN fsdb_cksum c ON c.fil_id = t.thm_owner_id AND c.thm_id = t.thm_id"
, "WHERE c.fil_id IS NULL"
), Cksum_tid__md5));
}
public Db_stmt Select_samples_stmt(int count) {
return conn.Stmt_sql(Db_sql_.Make_by_fmt(String_.Ary
( "SELECT *"
, "FROM fsdb_cksum"
, "WHERE cksum_val = ''"
// , "ORDER BY cksum_count, cksum_date"
, "LIMIT {0}"
), count));
}
public Xocksum_cksum_row[] Select_samples(Db_stmt stmt) {
List_adp rv = List_adp_.New();
Db_rdr rdr = stmt.Exec_select__rls_manual();
try {
while (rdr.Move_next()) {
rv.Add(new Xocksum_cksum_row
( rdr.Read_int("fil_id")
, rdr.Read_int("thm_id")
, rdr.Read_int("bin_db_id")
, rdr.Read_long("bin_size")
, rdr.Read_byte("cksum_tid")
, rdr.Read_int("cksum_count")
, rdr.Read_bry_by_str("cksum_val")
, rdr.Read_str("cksum_date")
));
}
} finally {rdr.Rls();}
return (Xocksum_cksum_row[])rv.To_ary_and_clear(Xocksum_cksum_row.class);
}
public void Update(int fil_id, int thm_id, int bin_db_id, long bin_size, byte cksum_tid, int cksum_count, byte[] cksum_val, String cksum_date) {
if (stmt__update == null) stmt__update = conn.Stmt_update_exclude(tbl_name, flds, fld__fil_id, fld__thm_id);
stmt__update.Clear()
.Val_int(fld__bin_db_id, bin_db_id).Val_long(fld__bin_len, bin_size)
.Val_byte(fld__cksum_tid, cksum_tid).Val_int(fld__cksum_count, cksum_count)
.Val_bry_as_str(fld__cksum_val, cksum_val).Val_str(fld__cksum_date, cksum_date)
.Crt_int(fld__fil_id, fil_id).Crt_int(fld__thm_id, thm_id)
.Exec_update();
}
public void Rls() {
this.stmt__update = Db_stmt_.Rls(stmt__update);
}
public static final byte Cksum_tid__md5 = 1;
}

View File

@@ -0,0 +1,34 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.htmls.core.bldrs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.wikis.data.*;
class Xob_hdump_tbl_retriever__ns_to_db implements Xob_hdump_tbl_retriever {
private final Xob_ns_to_db_mgr ns_to_db_mgr;
public Xob_hdump_tbl_retriever__ns_to_db(Xowe_wiki wiki) {
Xow_db_mgr core_data_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__html(core_data_mgr.Db__core()), core_data_mgr, Xobldr_cfg.Max_size__html(wiki.App()));
Xob_ns_file_itm.Init_ns_bldr_data(Xow_db_file_.Tid__html_data, wiki.Ns_mgr(), gplx.xowa.bldrs.Xobldr_cfg.Ns_file_map__each);
}
public Xowd_html_tbl Get_html_tbl(Xow_ns ns, int prv_row_len) {
Xow_db_file html_db = ns_to_db_mgr.Get_by_ns(ns.Bldr_data(), prv_row_len); // get html_db
return html_db.Tbl__html();
}
public void Commit() {ns_to_db_mgr.Commit();}
public void Rls_all() {ns_to_db_mgr.Rls_all();}
}

View File

@@ -0,0 +1,385 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.stores.*; import gplx.core.envs.*; import gplx.core.ios.streams.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.engines.sqlite.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.dbs.*; import gplx.fsdb.*; import gplx.core.ios.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.fsdb.*;
import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
import gplx.xowa.addons.bldrs.files.dbs.*; import gplx.xowa.addons.bldrs.files.utls.*;
public class Xobldr__fsdb_db__create_data extends Xob_cmd__base implements Xob_cmd {
private Db_conn bldr_conn; private Db_cfg_tbl bldr_cfg_tbl;
private Xof_bin_mgr src_bin_mgr; private Xof_bin_wkr__fsdb_sql src_fsdb_wkr; private boolean src_bin_mgr__cache_enabled = Bool_.N; private String src_bin_mgr__fsdb_version; private String[] src_bin_mgr__fsdb_skip_wkrs; private boolean src_bin_mgr__wmf_enabled;
private Fsm_mnt_itm trg_mnt_itm; private Fsm_cfg_mgr trg_cfg_mgr; private Fsm_atr_fil trg_atr_fil; private Fsm_bin_fil trg_bin_fil; private long trg_bin_db_max; private String trg_bin_mgr__fsdb_version;
private final Xof_bin_updater trg_bin_updater = new Xof_bin_updater(); private Xob_bin_db_mgr bin_db_mgr; private int[] ns_ids; private int prv_lnki_tier_id = -1;
private long download_size_max = Io_mgr.Len_mb_long * 5; private int[] download_keep_tier_ids = Int_.Ary(0);
private Xobu_poll_mgr poll_mgr; private int poll_interval; private long time_bgn;
private int select_interval = 2500, progress_interval = 1, commit_interval = 1, delete_interval = 5000;
private boolean exec_done, resume_enabled; private int exec_count, exec_count_max = Int_.Max_value, exec_fail, exec_fail_max = 10000; // 115 errors over 900k images
private int tier_id_bmk = -1, tier_id_val = -1; private int page_id_bmk = -1, page_id_val = -1, page_id_end = Int_.Max_value; private int lnki_id_bmk = -1, lnki_id_val = -1;
private boolean exit_after_commit, exit_now;
public Xobldr__fsdb_db__create_data(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);
if (bldr != null) {
this.poll_mgr = new Xobu_poll_mgr(bldr.App());
wiki.File__fsdb_mode().Tid__v2__bld__y_();
this.src_bin_mgr = new Xof_bin_mgr(new Fsm_mnt_mgr(), wiki.File__repo_mgr(), app.File__img_mgr().Wkr_resize_img(), app.Wmf_mgr().Download_wkr().Download_xrg().Download_fmt());
}
}
@Override public void Cmd_bgn(Xob_bldr bldr) {
wiki.Init_assert();
this.poll_interval = poll_mgr.Poll_interval();
this.bin_db_mgr = new Xob_bin_db_mgr(ns_ids);
// src_bin_mgr
if (src_bin_mgr__fsdb_version != null) {
this.src_fsdb_wkr = Xof_bin_wkr__fsdb_sql.new_(wiki.File__mnt_mgr());
src_bin_mgr.Wkrs__add(src_fsdb_wkr);
src_fsdb_wkr.Mnt_mgr().Ctor_by_load(new_src_bin_db_mgr(wiki, src_bin_mgr__fsdb_version));
src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Txn_bgn(); // NOTE: txn on atr speeds up from 50 -> 300; DATE:2015-03-21
if (src_bin_mgr__fsdb_skip_wkrs != null) {
src_fsdb_wkr.Skip_mgr_init(src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Cfg_mgr(), src_bin_mgr__fsdb_skip_wkrs);
}
if (src_bin_mgr__cache_enabled) {
usr_dlg.Prog_many("", "", "src_bin_mgr.cache.bgn");
src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Atr_mgr().Db__core().Fil_cache_enabled_y_();
usr_dlg.Prog_many("", "", "src_bin_mgr.cache.end");
}
}
if (src_bin_mgr__wmf_enabled) {
Xof_bin_wkr__http_wmf wmf_wkr = Xof_bin_wkr__http_wmf.new_(wiki);
src_bin_mgr.Wkrs__add(wmf_wkr);
wmf_wkr.Fail_timeout_(0); // 1000; NOTE: set Fail_timeout here; DATE:2014-06-21; NOTE: do not put in ctor, or else will be 1st wkr; DATE:2014-06-28
}
// trg_mnt_itm
this.trg_bin_db_max = Xobldr_cfg.Max_size__file(app);
Io_url trg_file_dir_v1 = String_.Eq(trg_bin_mgr__fsdb_version, "v1") ? wiki.Fsys_mgr().File_dir().GenNewNameOnly(wiki.Domain_str() + "-prv") : wiki.Fsys_mgr().File_dir(); // NOTE: convoluted way of setting trg to -prv if trg_bin_mgr__fsdb_version_v1 is set; otherwise set to "en.wikipedia.org" which will noop; DATE:2015-12-02
Fsdb_db_mgr trg_db_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), trg_file_dir_v1);
if (trg_db_mgr == null) trg_db_mgr = Fsdb_db_mgr__v2_bldr.Get_or_make(wiki, Bool_.Y);
Fsm_mnt_mgr trg_mnt_mgr = new Fsm_mnt_mgr(); trg_mnt_mgr.Ctor_by_load(trg_db_mgr);
trg_mnt_mgr.Mnts__get_insert_idx_(Fsm_mnt_mgr.Mnt_idx_main); // NOTE: do not delete; mnt_mgr default to Mnt_idx_user; DATE:2014-04-25
this.trg_mnt_itm = trg_mnt_mgr.Mnts__get_insert();
Fsm_mnt_mgr.Patch(trg_mnt_itm.Cfg_mgr().Tbl()); // NOTE: always patch again; fsdb_make may be run separately without lnki_temp; DATE:2014-04-26
this.trg_atr_fil = trg_mnt_itm.Atr_mgr().Db__core();
this.trg_cfg_mgr = trg_mnt_itm.Cfg_mgr();
bin_db_mgr.Init_by_mnt_mgr(trg_mnt_mgr);
trg_atr_fil.Conn().Txn_bgn("bldr__fsdb_make__trg_atr_fil");
if (!trg_atr_fil.Conn().Eq(trg_cfg_mgr.Tbl().Conn())) // need to create txn for v1; DATE:2015-07-04
trg_cfg_mgr.Tbl().Conn().Txn_bgn("bldr__fsdb_make__trg_cfg_fil");
// bldr_db
Xob_db_file bldr_db = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir());
this.bldr_conn = bldr_db.Conn();
this.bldr_cfg_tbl = bldr_db.Tbl__cfg(); // NOTE: cfg and atr is in same db; use it
bldr_cfg_tbl.Conn().Txn_bgn("bldr__fsdb_make__bldr_cfg_tbl");
}
@Override public void Cmd_run() {
Init_bldr_bmks();
this.time_bgn = System_.Ticks();
int total_pending = Xob_xfer_regy_tbl.Select_total_pending(bldr_conn);
// if (total_pending > 250000 && src_bin_mgr__fsdb_version == null)
usr_dlg.Note_many("", "", "total pending: ~{0}", total_pending);
List_adp list = List_adp_.New();
boolean loop = true;
while (loop) {
byte rslt = Select_fsdb_itms(list);
switch (rslt) {
case Select_rv_stop:
if (bin_db_mgr.Tier_id_is_last(tier_id_val))
loop = false;
else {
++tier_id_val;
page_id_val = 0;
continue;
}
break;
case Select_rv_next_page: ++page_id_val; lnki_id_val = 0; continue;
case Select_rv_process: break;
}
if (!loop) break; // no more ttls found
int len = list.Count();
usr_dlg.Prog_many("", "", "fetched pages: ~{0}", len);
for (int i = 0; i < len; ++i) {
Xodb_tbl_oimg_xfer_itm fsdb = (Xodb_tbl_oimg_xfer_itm)list.Get_at(i);
Download_itm(fsdb);
if ( exit_now
|| exec_count >= exec_count_max
|| exec_fail >= exec_fail_max
|| page_id_val >= page_id_end
) {
this.Txn_sav();
return;
}
}
}
exec_done = true;
}
private void Init_bldr_bmks() {
if (!resume_enabled) // clear cfg entries if resume disabled; note that disabled by default; DATE:2014-10-24
bldr_cfg_tbl.Delete_grp(Cfg_fsdb_make);
Db_cfg_hash bmk_hash = bldr_cfg_tbl.Select_as_hash(Cfg_fsdb_make);
String tier_id_str = bmk_hash.Get_by(Cfg_tier_id_bmk).To_str_or(null);
if (tier_id_str == null) { // bmks not found; new db;
bldr_conn.Txn_bgn("bldr__fsdb_make__bldr_conn");
bldr_cfg_tbl.Insert_int(Cfg_fsdb_make, Cfg_tier_id_bmk , tier_id_bmk);
bldr_cfg_tbl.Insert_int(Cfg_fsdb_make, Cfg_page_id_bmk , page_id_bmk);
bldr_cfg_tbl.Insert_int(Cfg_fsdb_make, Cfg_lnki_id_bmk , lnki_id_bmk);
bldr_conn.Txn_end();
if (tier_id_bmk == -1) tier_id_bmk = 0;
if (page_id_bmk == -1) page_id_bmk = 0;
if (lnki_id_bmk == -1) lnki_id_bmk = 0;
}
else {
if (tier_id_bmk == -1) {
tier_id_bmk = Int_.parse(tier_id_str);
usr_dlg.Note_many("", "", "restoring from bmk: tier_id=~{0}", tier_id_bmk);
}
if (page_id_bmk == -1) {
page_id_bmk = bmk_hash.Get_by(Cfg_page_id_bmk).To_int();
usr_dlg.Note_many("", "", "restoring from bmk: page_id=~{0}", page_id_bmk);
}
if (lnki_id_bmk == -1) {
lnki_id_bmk = bmk_hash.Get_by(Cfg_lnki_id_bmk).To_int();
usr_dlg.Note_many("", "", "restoring from bmk: lnki_id=~{0}", lnki_id_bmk);
}
}
tier_id_val = tier_id_bmk;
page_id_val = page_id_bmk;
lnki_id_val = lnki_id_bmk;
}
private byte Select_fsdb_itms(List_adp list) {
list.Clear();
boolean pages_found = false, links_found = false;
DataRdr rdr = Xob_xfer_regy_tbl.Select_by_tier_page(bldr_conn, tier_id_val, page_id_val, select_interval);
try {
while (rdr.MoveNextPeer()) {
pages_found = true; // at least one page found; set true
Xodb_tbl_oimg_xfer_itm itm = Xodb_tbl_oimg_xfer_itm.new_rdr_( rdr);
if ( itm.Lnki_page_id() == page_id_val // same page_id
&& itm.Lnki_id() <= lnki_id_val // ... but lnki_id < last
)
continue; // ... ignore; note that select is by page_id, not page_id + link_id; needed else restarts would not resume exactly at same point;
links_found = true;
list.Add(itm);
}
} finally {rdr.Rls();}
if (pages_found && !links_found) return Select_rv_next_page; // pages found, but all links processed
else if (!pages_found) return Select_rv_stop; // no more pages found
else return Select_rv_process; // pages and links found
}
private void Download_itm(Xodb_tbl_oimg_xfer_itm fsdb) {
try {
tier_id_val = fsdb.Lnki_tier_id();
page_id_val = fsdb.Lnki_page_id();
lnki_id_val = fsdb.Lnki_id();
fsdb.Orig_repo_name_(fsdb.Orig_repo_id() == Xof_repo_tid_.Tid__local ? wiki.Domain_bry() : Xow_domain_itm_.Bry__commons);
Download_exec(fsdb);
++exec_count;
if (exec_count % progress_interval == 0) Print_progress(fsdb);
if (exec_count % poll_interval == 0) poll_mgr.Poll();
if (exec_count % commit_interval == 0) Txn_sav();
if (exec_count % delete_interval == 0) Delete_files();
}
catch (Exception exc) {
++exec_fail;
usr_dlg.Warn_many("", "", "download error; ttl=~{0} w=~{1} err=~{2}", fsdb.Orig_ttl(), fsdb.Lnki_w(), Err_.Message_gplx_full(exc));
}
}
private void Download_exec(Xodb_tbl_oimg_xfer_itm fsdb) {
Io_stream_rdr src_rdr = src_bin_mgr.Find_as_rdr(Xof_exec_tid.Tid_wiki_page, fsdb);
try {
if (src_rdr == Io_stream_rdr_.Noop) { // download failed
++exec_fail;
usr_dlg.Warn_many("", "", "failed: ttl=~{0}", String_.Format("[[File:{0}|{1}px]]", fsdb.Orig_ttl(), fsdb.Html_w()));
Print_progress(fsdb);
}
else { // download passed
long src_rdr_len = src_rdr.Len();
int lnki_tier_id = fsdb.Lnki_tier_id();
if ( src_rdr_len > download_size_max
&& !Int_.In(lnki_tier_id, download_keep_tier_ids)) {
usr_dlg.Warn_many("", "", "skipped; ttl=~{0} w=~{1} size=~{2} tier=~{3}", fsdb.Orig_ttl(), fsdb.Lnki_w(), src_rdr_len, lnki_tier_id);
return;
}
if (trg_bin_fil == null) // no trg_bin_fil
Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
else if (trg_bin_fil.Bin_len() + src_rdr_len > trg_bin_db_max) // or trg_bin_fil is out of space
Make_trg_bin_file(Bool_.N, fsdb, src_rdr_len);
else if (prv_lnki_tier_id != lnki_tier_id) { // or tier has changed
if ( prv_lnki_tier_id != -1
&& !bin_db_mgr.Schema_is_1()) // do not increment dbs for v1
Make_trg_bin_file(Bool_.Y, fsdb, src_rdr_len);
prv_lnki_tier_id = lnki_tier_id;
}
trg_bin_updater.Save_bin(trg_mnt_itm, trg_atr_fil, trg_bin_fil, fsdb, src_rdr, src_rdr_len);
}
}
finally {src_rdr.Rls();}
}
private void Make_trg_bin_file(boolean try_nth, Xodb_tbl_oimg_xfer_itm fsdb, long src_rdr_len) {
boolean is_solo = trg_mnt_itm.Db_mgr().File__solo_file();
boolean make = true, use_txn = !is_solo; // solo file; should never open txn
if (trg_bin_fil != null && use_txn) // pre-existing bin_file;
trg_bin_fil.Conn().Txn_end(); // close txn before making new db
int tier_id = fsdb.Lnki_tier_id();
Xob_bin_db_itm nth_bin_db = bin_db_mgr.Get_nth_by_tier(tier_id);
if (try_nth) { // try_nth is true; occurs for new runs or changed tier
if ( nth_bin_db.Id() != -1 // nth exists;
&& nth_bin_db.Db_len() + src_rdr_len < trg_bin_db_max) { // if src_rdr_len exceeds
make = false; // do not make; use existing
}
}
if (make) { // no nth; make it;
int ns_id = bin_db_mgr.Get_ns_id(tier_id);
int pt_id = bin_db_mgr.Increment_pt_id(nth_bin_db);
String new_bin_db_name = bin_db_mgr.Gen_name(wiki.Domain_str(), ns_id, pt_id);
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__make(new_bin_db_name);
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
Fsdb_db_file trg_bin_db = trg_mnt_itm.Db_mgr().File__bin_file__at(trg_mnt_itm.Id(), trg_bin_fil.Id(), new_bin_db_name);
if (!bin_db_mgr.Schema_is_1())
Fsdb_db_mgr__v2_bldr.Make_cfg_data(wiki, trg_atr_fil.Url_rel(), trg_bin_db, Xow_db_file_.Tid__file_data, trg_bin_fil.Id() + List_adp_.Base1);
}
}
else { // nth available; use it
this.trg_bin_fil = trg_mnt_itm.Bin_mgr().Dbs__get_at(nth_bin_db.Id());
trg_bin_fil.Bin_len_(nth_bin_db.Db_len());
}
if (use_txn)
trg_bin_fil.Conn().Txn_bgn("bldr__fsdb_make__trg_bin_fil");
}
private void Txn_sav() {
usr_dlg.Prog_many("", "", "committing data: count=~{0} failed=~{1}", exec_count, exec_fail);
bldr_cfg_tbl.Update_int(Cfg_fsdb_make, Cfg_page_id_bmk, page_id_val);
bldr_cfg_tbl.Update_int(Cfg_fsdb_make, Cfg_lnki_id_bmk, lnki_id_val);
bldr_cfg_tbl.Conn().Txn_sav();
trg_cfg_mgr.Next_id_commit();
trg_atr_fil.Conn().Txn_sav();
if (!trg_atr_fil.Conn().Eq(trg_cfg_mgr.Tbl().Conn())) // need to create txn for v1
trg_cfg_mgr.Tbl().Conn().Txn_sav();
if (src_bin_mgr__fsdb_version != null && src_bin_mgr__fsdb_skip_wkrs != null) {
src_fsdb_wkr.Skip_mgr().Skip_term(src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Cfg_mgr());
}
if (!trg_mnt_itm.Db_mgr().File__solo_file())
trg_bin_fil.Conn().Txn_sav();
if (exit_after_commit) exit_now = true;
}
@Override public void Cmd_end() {
usr_dlg.Note_many("", "", "fsdb_make.done: count=~{0} rate=~{1}", exec_count, Decimal_adp_.divide_safe_(exec_count, System_.Ticks__elapsed_in_sec(time_bgn)).To_str("#,###.000"));
if (src_fsdb_wkr != null) {
src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Txn_end(); // NOTE: src_fsdb_wkr will be null if no src db defined
}
trg_atr_fil.Conn().Txn_end(); trg_atr_fil.Conn().Rls_conn();
if (!trg_atr_fil.Conn().Eq(trg_cfg_mgr.Tbl().Conn())) // need to create txn for v1
trg_cfg_mgr.Tbl().Conn().Txn_end();
trg_cfg_mgr.Tbl().Conn().Rls_conn();
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
trg_bin_fil.Conn().Txn_end(); trg_bin_fil.Conn().Rls_conn();
}
if (exec_done) {
bldr_cfg_tbl.Delete_grp(Cfg_fsdb_make); // delete bmks for future reruns; DATE:2014-08-20
Io_mgr.Instance.DeleteFil_args(wiki.Fsys_mgr().Root_dir().GenSubFil("xowa.file.make.cfg.gfs")).MissingFails_off().Exec();
}
bldr_conn.Rls_conn();
}
private void Print_progress(Xodb_tbl_oimg_xfer_itm itm) {
int time_elapsed = System_.Ticks__elapsed_in_sec(time_bgn);
usr_dlg.Prog_many("", "", "prog: num=~{0} err=~{1} time=~{2} rate=~{3} page=~{4} lnki=~{5} ttl=~{6}", exec_count, exec_fail, time_elapsed, Math_.Div_safe_as_int(exec_count, time_elapsed), page_id_val, lnki_id_val, itm.Orig_ttl());
}
private void Delete_files() {}// TODO_OLD: purge /xowa/file/ dir to free up hard disk space
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tier_id_bmk_)) tier_id_bmk = m.ReadInt("v");
else if (ctx.Match(k, Invk_page_id_bmk_)) page_id_bmk = m.ReadInt("v");
else if (ctx.Match(k, Invk_lnki_id_bmk_)) lnki_id_bmk = m.ReadInt("v");
else if (ctx.Match(k, Invk_select_interval_)) select_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_commit_interval_)) commit_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_progress_interval_)) progress_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_delete_interval_)) delete_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_exec_count_max_)) exec_count_max = m.ReadInt("v");
else if (ctx.Match(k, Invk_exec_fail_max_)) exec_fail_max = m.ReadInt("v");
else if (ctx.Match(k, Invk_exit_after_commit_)) exit_after_commit = m.ReadYn("v");
else if (ctx.Match(k, Invk_exit_now_)) exit_now = m.ReadYn("v");
else if (ctx.Match(k, Invk_resume_enabled_)) resume_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_ns_ids_)) ns_ids = Int_.Ary_parse(m.ReadStr("v"), "|");
else if (ctx.Match(k, Invk_src_bin_mgr__fsdb_version_)) src_bin_mgr__fsdb_version = m.ReadStr("v");
else if (ctx.Match(k, Invk_src_bin_mgr__fsdb_skip_wkrs_)) src_bin_mgr__fsdb_skip_wkrs = m.ReadStrAry("v", "|");
else if (ctx.Match(k, Invk_src_bin_mgr__wmf_enabled_)) src_bin_mgr__wmf_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_src_bin_mgr__cache_enabled_)) src_bin_mgr__cache_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_trg_bin_mgr__fsdb_version_)) trg_bin_mgr__fsdb_version = m.ReadStr("v");
else if (ctx.Match(k, Invk_poll_mgr)) return poll_mgr;
else if (ctx.Match(k, Invk_download_keep_tier_ids)) download_keep_tier_ids = Int_.Ary_parse(m.ReadStr("v"), "|");
else if (ctx.Match(k, Invk_download_size_max)) download_size_max = Io_size_.To_long_by_msg_mb(m, download_size_max);
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_tier_id_bmk_ = "tier_id_bmk_", Invk_page_id_bmk_ = "page_id_bmk_", Invk_lnki_id_bmk_ = "lnki_id_bmk_"
, Invk_select_interval_ = "select_interval_", Invk_commit_interval_ = "commit_interval_", Invk_progress_interval_ = "progress_interval_", Invk_delete_interval_ = "delete_interval_"
, Invk_exec_count_max_ = "exec_count_max_", Invk_exec_fail_max_ = "exec_fail_max_", Invk_exit_now_ = "exit_now_", Invk_exit_after_commit_ = "exit_after_commit_"
, Invk_resume_enabled_ = "resume_enabled_", Invk_poll_mgr = "poll_mgr"
, Invk_src_bin_mgr__fsdb_version_ = "src_bin_mgr__fsdb_version_", Invk_src_bin_mgr__fsdb_skip_wkrs_ = "src_bin_mgr__fsdb_skip_wkrs_"
, Invk_src_bin_mgr__wmf_enabled_ = "src_bin_mgr__wmf_enabled_"
, Invk_src_bin_mgr__cache_enabled_ = "src_bin_mgr__cache_enabled_", Invk_ns_ids_ = "ns_ids_"
, Invk_trg_bin_mgr__fsdb_version_ = "trg_bin_mgr__fsdb_version_"
, Invk_download_size_max = "download_size_max", Invk_download_keep_tier_ids = "download_keep_tier_ids"
;
public static final String BLDR_CMD_KEY = "file.fsdb_make";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__fsdb_db__create_data(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__fsdb_db__create_data(bldr, wiki);}
public static Fsdb_db_mgr new_src_bin_db_mgr(Xow_wiki wiki, String version) {
String domain_str = wiki.Domain_str();
Fsdb_db_mgr rv = null; Io_url url = null;
if (String_.Eq(version, "v1")) {
url = wiki.Fsys_mgr().File_dir().OwnerDir().GenSubDir(domain_str + "-prv"); // v1: EX: /xowa/file/en.wikipedia.org-prv/
rv = new Fsdb_db_mgr__v1(url);
}
else if (String_.Eq(version, "v2")) {
url = wiki.Fsys_mgr().Root_dir().GenSubDir("prv"); // v2: EX: /xowa/wiki/en.wikipedia.org/prv/
rv = Fsdb_db_mgr_.new_detect(wiki, url, url); // note that v2 is prioritized over v1
}
else throw Err_.new_wo_type("fsdb.make:unknown fsdb_type", "version", version);
if (rv == null) throw Err_.new_wo_type("fsdb.make:source fsdb not found", "version", version, "url", url.Raw());
return rv;
}
private static final byte Select_rv_stop = 0, Select_rv_process = 1, Select_rv_next_page = 2;
private static final String Cfg_fsdb_make = "bldr.fsdb_make", Cfg_tier_id_bmk = "tier_id_bmk", Cfg_page_id_bmk = "page_id_bmk", Cfg_lnki_id_bmk = "lnki_id_bmk";
public static byte Status_null = 0, Status_pass = 1, Status_fail = 2;
}
class Xodb_tbl_oimg_xfer_itm extends Xof_fsdb_itm { public int Lnki_id() {return lnki_id;} private int lnki_id;
public int Lnki_tier_id() {return lnki_tier_id;} private int lnki_tier_id;
public int Lnki_page_id() {return lnki_page_id;} private int lnki_page_id;
public static Xodb_tbl_oimg_xfer_itm new_rdr_(DataRdr rdr) {
Xodb_tbl_oimg_xfer_itm rv = new Xodb_tbl_oimg_xfer_itm();
rv.lnki_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_id);
rv.lnki_page_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_page_id);
rv.lnki_tier_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_tier_id);
rv.Init_at_fsdb_make
( rdr.ReadBryByStr(Xob_xfer_regy_tbl.Fld_lnki_ttl)
, rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_ext)
, rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_w), rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_h) // set lnki_size; Xof_bin_mgr uses lnki_size
, Xof_lnki_time.Db_load_double(rdr, Xob_xfer_regy_tbl.Fld_lnki_time)
, Xof_lnki_page.Db_load_int(rdr, Xob_xfer_regy_tbl.Fld_lnki_page)
, rdr.ReadByte(Xob_xfer_regy_tbl.Fld_orig_repo)
, rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_w)
, rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_h)
, Bry_.Empty
, rdr.ReadByte(Xob_xfer_regy_tbl.Fld_file_is_orig) == Bool_.Y_byte
);
return rv;
}
}

View File

@@ -0,0 +1,122 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.files.*; import gplx.fsdb.*;
public class Xobldr__fsdb_db__create_orig extends Xob_cmd__base {
private Db_conn conn; private boolean schema_1;
public Xobldr__fsdb_db__create_orig(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_bgn(Xob_bldr bldr) {
Xof_fsdb_mode fsdb_mode = wiki.File__fsdb_mode();
fsdb_mode.Tid__v2__bld__y_();
wiki.Init_assert();
Fsdb_db_mgr db_core_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
this.schema_1 = db_core_mgr.File__schema_is_1();
conn = db_core_mgr.File__orig_tbl_ary()[gplx.fsdb.meta.Fsm_mnt_mgr.Mnt_idx_main].Conn();
Io_url make_db_url = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Url();
Sqlite_engine_.Db_attach(conn, "make_db", make_db_url.Raw());
}
@Override public void Cmd_run() {
String tbl_name = "orig_reg", fld_status = "orig_status";
if (schema_1) {
tbl_name = "wiki_orig";
fld_status = "status";
}
conn.Exec_sql_plog_txn("orig_wkr.deleting orig_reg" , String_.Format(Sql_delete_wiki_orig, tbl_name)); // always delete orig_reg, else will not pick up changed sizes / moved repos; DATE:2014-07-21
conn.Exec_sql_plog_txn("orig_wkr.inserting xfer direct" , String_.Format(Sql_create_xfer_direct, tbl_name, fld_status));
conn.Exec_sql_plog_txn("orig_wkr.inserting xfer redirect" , String_.Format(Sql_create_xfer_redirect, tbl_name, fld_status));
conn.Exec_sql_plog_txn("orig_wkr.inserting orig direct" , String_.Format(Sql_create_orig_direct, tbl_name, fld_status));
conn.Exec_sql_plog_txn("orig_wkr.inserting orig redirect" , String_.Format(Sql_create_orig_redirect, tbl_name, fld_status));
}
private static final String
Sql_delete_wiki_orig = "DELETE FROM {0};"
, Sql_create_xfer_direct = String_.Concat_lines_nl
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " xfer.lnki_ttl"
, ", 1 --pass"
, ", xfer.orig_repo"
, ", xfer.lnki_ext"
, ", xfer.orig_w"
, ", xfer.orig_h"
, ", ''"
, "FROM make_db.xfer_regy xfer"
, " LEFT JOIN {0} cur ON xfer.lnki_ttl = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL"
)
, Sql_create_xfer_redirect = String_.Concat_lines_nl
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " xfer.orig_redirect_src"
, ", 1 --pass"
, ", xfer.orig_repo"
, ", xfer.lnki_ext"
, ", xfer.orig_w"
, ", xfer.orig_h"
, ", xfer.lnki_ttl"
, "FROM make_db.xfer_regy xfer"
, " LEFT JOIN {0} cur ON xfer.orig_redirect_src = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL"
, "AND Coalesce(xfer.orig_redirect_src, '') != ''"
)
, Sql_create_orig_direct = String_.Concat_lines_nl
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " orig.lnki_ttl"
, ", 0 --unknown"
, ", orig.orig_repo"
, ", orig.lnki_ext"
, ", orig.orig_w"
, ", orig.orig_h"
, ", ''"
, "FROM make_db.orig_regy orig"
, " LEFT JOIN {0} cur ON orig.lnki_ttl = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL" // not already in orig_reg
, "AND orig.orig_repo IS NOT NULL" // not found in oimg_image.sqlite3
, "AND Coalesce(orig.orig_w , -1) != -1" // ignore entries that are either ext_id = 0 ("File:1") or don't have any width / height info (makes it useless); need to try to get again from wmf_api
, "AND Coalesce(orig.orig_redirect_ttl, '') == ''" // direct
)
, Sql_create_orig_redirect = String_.Concat_lines_nl
( "INSERT INTO {0} "
, "(orig_ttl, {1}, orig_repo, orig_ext, orig_w, orig_h, orig_redirect)"
, "SELECT DISTINCT"
, " orig.orig_redirect_ttl"
, ", 0 --unknown"
, ", orig.orig_repo"
, ", orig.lnki_ext"
, ", orig.orig_w"
, ", orig.orig_h"
, ", ''"
, "FROM make_db.orig_regy orig"
, " LEFT JOIN {0} cur ON orig.orig_redirect_ttl = cur.orig_ttl"
, "WHERE cur.orig_ttl IS NULL" // not already in orig_reg
, "AND orig.orig_repo IS NOT NULL" // not found in oimg_image.sqlite3
, "AND Coalesce(orig.orig_w, -1) != -1" // ignore entries that are either ext_id = 0 ("File:1") or don't have any width / height info (makes it useless); need to try to get again from wmf_api
, "AND Coalesce(orig.orig_redirect_ttl, '') != ''" // redirect
)
;
public static final String BLDR_CMD_KEY = "file.orig_reg";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__fsdb_db__create_orig(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__fsdb_db__create_orig(bldr, wiki);}
}

View File

@@ -0,0 +1,129 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.core.ios.*; import gplx.xowa.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.sql_dumps.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xobldr__image__create extends Xob_itm_dump_base implements Xob_cmd, Gfo_invk, Xosql_dump_cbk {
private Xosql_dump_parser parser;
private Db_conn conn = null; private Db_stmt stmt = null;
private Xob_image_tbl tbl_image = new Xob_image_tbl();
private byte[] cur_ttl, cur_media_type, cur_minor_mime, cur_timestamp; private int cur_size, cur_width, cur_height, cur_bits, cur_ext_id;
private int commit_count = 10000;
public Xobldr__image__create(Xob_bldr bldr, Xowe_wiki wiki) {
this.parser = new Xosql_dump_parser(this, "img_name", "img_size", "img_width", "img_height", "img_bits", "img_media_type", "img_minor_mime", "img_timestamp");
this.Cmd_ctor(bldr, wiki);
}
public Io_url Src_fil() {return src_fil;} public Xobldr__image__create Src_fil_(Io_url v) {src_fil = v; return this;} private Io_url src_fil;
public Xosql_dump_parser Parser() {return parser;}
public void Cmd_init(Xob_bldr bldr) {}
public void Cmd_bgn(Xob_bldr bldr) {
wiki.Init_assert(); // NOTE: must init wiki for db_mgr_as_sql
Init_dump(BLDR_CMD_KEY);
if (src_fil == null) {
src_fil = Xob_page_wkr_cmd.Find_fil_by(wiki.Fsys_mgr().Root_dir(), "*-image.sql");
if (src_fil == null) throw Err_.new_wo_type(".sql file not found in dir", "dir", wiki.Fsys_mgr().Root_dir());
}
parser.Src_fil_(src_fil);
this.conn = Xob_db_file.New__wiki_image(wiki.Fsys_mgr().Root_dir()).Conn();
conn.Txn_bgn("bldr__image");
this.tbl_image = new Xob_image_tbl();
tbl_image.Create_table(conn);
this.stmt = tbl_image.Insert_stmt(conn);
}
public void Cmd_run() {
parser.Parse(bldr.Usr_dlg());
tbl_image.Create_index(conn);
conn.Txn_end();
}
public void On_fld_done(int fld_idx, byte[] src, int val_bgn, int val_end) {
switch (fld_idx) {
case Fld_img_name: cur_ttl = Bry_.Mid(src, val_bgn, val_end); break;
case Fld_img_size: cur_size = Bry_.To_int_or(src, val_bgn, val_end, -1); break;
case Fld_img_width: cur_width = Bry_.To_int_or(src, val_bgn, val_end, -1); break;
case Fld_img_height: cur_height = Bry_.To_int_or(src, val_bgn, val_end, -1); break;
case Fld_img_bits: cur_bits = Bry_.To_int_or(src, val_bgn, val_end, -1); break;
case Fld_img_media_type: cur_media_type = Bry_.Mid(src, val_bgn, val_end); break;
case Fld_img_minor_mime: cur_minor_mime = Bry_.Mid(src, val_bgn, val_end); break;
case Fld_img_timestamp: cur_timestamp = Bry_.Mid(src, val_bgn, val_end); break;
}
}
public void On_row_done() {
cur_ext_id = Calc_ext_id(show_issues ? app.Usr_dlg() : Gfo_usr_dlg_.Noop, cur_ttl, cur_media_type, cur_minor_mime, cur_width, cur_height);
tbl_image.Insert(stmt, cur_ttl, cur_media_type, cur_minor_mime, cur_size, cur_width, cur_height, cur_bits, cur_ext_id, cur_timestamp);
++commit_count;
if ((commit_count % 10000) == 0) {
usr_dlg.Prog_many("", "", "committing: count=~{0} last=~{1}", commit_count, String_.new_u8(cur_ttl));
conn.Txn_sav();
}
}
public void Cmd_end() {}
public void Cmd_term() {}
private boolean show_issues = true;
private static final int Fld_img_name = 0, Fld_img_size = 1, Fld_img_width = 2, Fld_img_height = 3, Fld_img_bits = 4, Fld_img_media_type = 5, Fld_img_minor_mime = 6, Fld_img_timestamp = 7;
// Fld_img_name = 0, Fld_img_size = 1, Fld_img_width = 2, Fld_img_height = 3, Fld_img_bits = 5, Fld_img_media_type = 6, Fld_img_minor_mime = 8, Fld_img_timestamp = 12;
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_src_fil_)) src_fil = m.ReadIoUrl("v");
else if (ctx.Match(k, Invk_show_issues_)) show_issues = m.ReadYn("v");
else return super.Invk(ctx, ikey, k, m);
return this;
} private static final String Invk_src_fil_ = "src_fil_", Invk_show_issues_ = "show_issues_";
public static int Calc_ext_id(Gfo_usr_dlg usr_dlg, byte[] file, byte[] media_type, byte[] minor_mime, int w, int h) {
Xof_ext file_ext = Xof_ext_.new_by_ttl_(file); int file_ext_id = file_ext.Id();
Xof_ext mime_ext = Xof_mime_minor_.ext_(minor_mime); int mime_ext_id = mime_ext.Id();
int media_type_id = Xof_media_type.Xto_byte(String_.new_u8(media_type));
if (file_ext_id != mime_ext_id) { // file_ext_id != mime_ext_id; EX: "A.png" actually has a minor_mime of "jpg"
boolean update = false, notify = true;
switch (file_ext_id) {
case Xof_ext_.Id_jpg: case Xof_ext_.Id_jpeg:
if (Int_.In(mime_ext_id, Xof_ext_.Id_jpg, Xof_ext_.Id_jpeg)) notify = false; // skip: both jpg
break;
case Xof_ext_.Id_tif: case Xof_ext_.Id_tiff:
if (Int_.In(mime_ext_id, Xof_ext_.Id_tif, Xof_ext_.Id_tiff)) notify = false; // skip: both tif
break;
case Xof_ext_.Id_ogg: case Xof_ext_.Id_oga: case Xof_ext_.Id_ogv:
if (Int_.In(mime_ext_id, Xof_ext_.Id_ogg, Xof_ext_.Id_oga, Xof_ext_.Id_ogv)) notify = false; // skip: both tif
break;
case Xof_ext_.Id_png:
if (Int_.In(mime_ext_id, Xof_ext_.Id_jpg, Xof_ext_.Id_jpeg))
update = true;
break;
}
if (update)
file_ext_id = mime_ext_id;
else {
if (notify)
usr_dlg.Log_many("", "", "image.ext_calc.mismatch_exts: file=~{0} mime=~{1}", String_.new_u8(file), String_.new_u8(minor_mime));
}
}
if ( file_ext_id == Xof_ext_.Id_ogg // file_ext is ".ogg"
&& media_type_id == Xof_media_type.Tid_video // media_type is "VIDEO"
) {
if (w > 0 && h > 0) // some .ogg files are "VIDEO" but have 0 width, 0 height
file_ext_id = Xof_ext_.Id_ogv; // manually specify ogv
else
usr_dlg.Log_many("", "", "image.ext_calc.ogg_video_with_null_size: media_type=~{0} minor_mime=~{1} w=~{2} h=~{3} file=~{4}", String_.new_u8(media_type), String_.new_u8(minor_mime), w, h, String_.new_u8(file));
}
return file_ext_id;
}
public static final String BLDR_CMD_KEY = "wiki.image";
public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__image__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__image__create(bldr, wiki);}
}

View File

@@ -0,0 +1,51 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import org.junit.*; import gplx.core.ios.*; import gplx.xowa.files.*;
public class Xobldr__image__create_tst {
private Xobldr__image__create_fxt fxt = new Xobldr__image__create_fxt();
@Test public void Basic() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_png, 220, 110) .Test(Xof_ext_.Id_png);} // A.png -> png
@Test public void Ogg_VIDEO() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 220, 110) .Test(Xof_ext_.Id_ogv);} // A.ogg and VIDEO -> ogv
@Test public void Ogg_VIDEO_null_size() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 0, 0) .Test(Xof_ext_.Id_ogg);} // A.ogg but 0,0 -> ogg (not ogv)
@Test public void Png_is_jpg() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpg);} // A.png and jpg -> jpg
@Test public void Jpeg_is_jpeg() {fxt.Init_("A.jpeg" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpeg);} // A.jpeg and jpg -> jpeg (unchanged)
}
class Xobldr__image__create_fxt {
private byte[] name, media_type, minor_mime; int w, h;
public Xobldr__image__create_fxt Init_png() {Name_("A.png").Media_type_(Xof_media_type.Name_bitmap).Minor_mime_(Xof_ext_.Bry_png).W_(220).H_(110);
return this;
}
public Xobldr__image__create_fxt Init_(String name, String media_type, byte[] minor_mime, int w, int h) {
Name_(name);
Media_type_(media_type);
Minor_mime_(minor_mime);
W_(w);
H_(h);
return this;
}
public Xobldr__image__create_fxt Name_(String v) {name = Bry_.new_a7(v); return this;}
public Xobldr__image__create_fxt Media_type_(String v) {media_type = Bry_.new_a7(v); return this;}
public Xobldr__image__create_fxt Minor_mime_(byte[] v) {minor_mime = v; return this;}
public Xobldr__image__create_fxt Minor_mime_(String v) {return Minor_mime_(Bry_.new_a7(v));}
public Xobldr__image__create_fxt W_(int v) {w = v; return this;}
public Xobldr__image__create_fxt H_(int v) {h = v; return this;}
public Xobldr__image__create_fxt Test(int expd) {
Tfds.Eq(expd, Xobldr__image__create.Calc_ext_id(Gfo_usr_dlg_.Noop, name, media_type, minor_mime, w, h));
return this;
}
}

View File

@@ -0,0 +1,33 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xobldr__lnki_regy__create extends Xob_cmd__base implements Xob_cmd {
public Xobldr__lnki_regy__create(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Db_conn conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
Xob_lnki_regy_tbl.Create_table(conn);
Xob_lnki_regy_tbl.Create_data(usr_dlg, conn, Xobldr__lnki_temp__create.Ns_file_is_case_match_all(wiki));
}
public static final String BLDR_CMD_KEY = "file.lnki_regy";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__lnki_regy__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__lnki_regy__create(bldr, wiki);}
}

View File

@@ -0,0 +1,191 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.files.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.xndes.*;
import gplx.xowa.htmls.core.bldrs.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wbases.*;
import gplx.fsdb.meta.*; import gplx.xowa.files.fsdb.*; import gplx.fsdb.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.parsers.vnts.*;
import gplx.xowa.parsers.lnkis.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.addons.bldrs.files.dbs.*; import gplx.xowa.addons.bldrs.mass_parses.parses.*; import gplx.xowa.addons.bldrs.mass_parses.parses.utls.*;
import gplx.xowa.addons.bldrs.wmdumps.imglinks.*;
public class Xobldr__lnki_temp__create extends Xob_dump_mgr_base implements gplx.xowa.parsers.lnkis.files.Xop_file_logger {
private Xob_lnki_temp_tbl tbl; private boolean wdata_enabled = true, xtn_ref_enabled = true, gen_html, gen_hdump, load_all_imglinks;
private Xop_log_invoke_wkr invoke_wkr; private Xop_log_property_wkr property_wkr;
private boolean ns_file_is_case_match_all = true; private Xowe_wiki commons_wiki;
private final Xob_hdump_bldr hdump_bldr = new Xob_hdump_bldr(); private Vnt_convert_lang converter_lang;
public Xobldr__lnki_temp__create(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
@Override public byte Init_redirect() {return Bool_.N_byte;} // lnki_temp does not look at redirect pages
@Override public int[] Init_ns_ary() {return ns_ids;} private int[] ns_ids = Int_.Ary(Xow_ns_.Tid__main);
@Override protected void Init_reset(Db_conn conn) {
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
cfg_tbl.Delete_all();
invoke_wkr.Init_reset();
property_wkr.Init_reset();
}
@Override protected Db_conn Init_db_file() {
ctx.Lnki().File_logger_(this);
Xob_db_file make_db = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir());
Db_conn make_conn = make_db.Conn();
this.tbl = new Xob_lnki_temp_tbl(make_conn); tbl.Create_tbl();
this.gen_hdump = hdump_bldr.Init(wiki, make_conn, new Xob_hdump_tbl_retriever__ns_to_db(wiki));
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
if (vnt_mgr.Enabled()) {
this.converter_lang = vnt_mgr.Convert_lang();
converter_lang.Log__init(make_conn);
}
return make_conn;
}
@Override protected void Cmd_bgn_end() {
ns_file_is_case_match_all = Ns_file_is_case_match_all(wiki); // NOTE: must call after wiki.init
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Ctgs_enabled_(false); // disable categories else progress messages written (also for PERF)
if (wiki.File__bin_mgr() != null)
wiki.File__bin_mgr().Wkrs__del(gplx.xowa.files.bins.Xof_bin_wkr_.Key_http_wmf); // remove wmf wkr, else will try to download images during parsing
commons_wiki = app.Wiki_mgr().Get_by_or_make(Xow_domain_itm_.Bry__commons);
// create imglinks
Xof_orig_wkr__img_links orig_wkr = new Xof_orig_wkr__img_links(wiki);
wiki.File__orig_mgr().Wkrs__set(orig_wkr);
if (load_all_imglinks) Xof_orig_wkr__img_links_.Load_all(orig_wkr);
Xow_wiki_utl_.Clone_repos(wiki);
// init log_mgr / property_wkr
Xop_log_mgr log_mgr = ctx.App().Log_mgr();
log_mgr.Log_dir_(wiki.Fsys_mgr().Root_dir()); // put log in wiki dir, instead of user.temp
invoke_wkr = this.Invoke_wkr(); // set member reference
invoke_wkr = log_mgr.Make_wkr_invoke();
property_wkr = this.Property_wkr(); // set member reference
property_wkr = log_mgr.Make_wkr_property();
wiki.Appe().Wiki_mgr().Wdata_mgr().Enabled_(wdata_enabled);
if (!xtn_ref_enabled) gplx.xowa.xtns.cites.References_nde.Enabled = false;
// init log wkrs
gplx.xowa.xtns.gallery.Gallery_xnde.Log_wkr = log_mgr.Make_wkr().Save_src_str_(Bool_.Y);
gplx.xowa.xtns.imaps.Imap_xnde.Log_wkr = log_mgr.Make_wkr();
gplx.xowa.parsers.xndes.Xop_xnde_wkr.Timeline_log_wkr = log_mgr.Make_wkr();
gplx.xowa.xtns.scores.Score_xnde.Log_wkr = log_mgr.Make_wkr();
gplx.xowa.xtns.hieros.Hiero_xnde.Log_wkr = log_mgr.Make_wkr();
gplx.xowa.xtns.math.Xomath_xnde.Log_wkr = log_mgr.Make_wkr().Save_src_str_(Bool_.Y); // enabled; DATE:2015-10-10
// init fsdb
Xof_fsdb_mgr__sql trg_fsdb_mgr = new Xof_fsdb_mgr__sql();
wiki.File__fsdb_mode().Tid__v2__bld__y_();
Fsdb_db_mgr__v2 fsdb_core = Fsdb_db_mgr__v2_bldr.Get_or_make(wiki, Bool_.Y);
trg_fsdb_mgr.Init_by_wiki(wiki);
Fsm_mnt_mgr trg_mnt_mgr = trg_fsdb_mgr.Mnt_mgr();
wiki.File_mgr().Init_file_mgr_by_load(wiki); // must happen after fsdb.make
wiki.File__bin_mgr().Wkrs__del(gplx.xowa.files.bins.Xof_bin_wkr_.Key_http_wmf); // must happen after init_file_mgr_by_load; remove wmf wkr, else will try to download images during parsing
wiki.File__orig_mgr().Wkrs__del(gplx.xowa.files.origs.Xof_orig_wkr_.Tid_wmf_api);
trg_mnt_mgr = new Fsm_mnt_mgr(); trg_mnt_mgr.Ctor_by_load(fsdb_core);
trg_mnt_mgr.Mnts__get_insert_idx_(Fsm_mnt_mgr.Mnt_idx_main);
Fsm_mnt_mgr.Patch(trg_mnt_mgr.Mnts__get_main().Cfg_mgr().Tbl()); // NOTE: see fsdb_make; DATE:2014-04-26
tbl.Insert_bgn();
log_mgr.Txn_bgn();
}
@Override public void Exec_pg_itm_hook(int ns_ord, Xow_ns ns, Xowd_page_itm db_page, byte[] page_src) {
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ns.Gen_ttl(db_page.Ttl_page_db()));
byte[] ttl_bry = ttl.Page_db();
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns.Id(), ttl_bry);
if (page_tid != Xow_page_tid.Tid_wikitext) return; // ignore js, css, lua, json
Xoae_page page = ctx.Page();
page.Clear_all();
page.Bldr__ns_ord_(ns_ord);
page.Ttl_(ttl);
page.Db().Page().Id_(db_page.Id());
page.Html_data().Redlink_list().Clear();
page.Url_(Xoa_url.New(wiki, ttl));
if (ns.Id_is_tmpl())
parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, page_src);
else {
parser.Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), page_src);
if ( gen_html
&& page.Redirect_trail().Itms__len() == 0) // don't generate html for redirected pages
wiki.Html_mgr().Page_wtr_mgr().Gen(ctx.Page().Root_(root), Xopg_page_.Tid_read);
if (gen_hdump)
hdump_bldr.Insert(ctx, page.Root_(root));
root.Clear();
}
}
@Override public void Exec_commit_hook() {
tbl.Conn().Txn_sav();
// if (converter_lang != null) converter_lang.Log__save();
if (gen_hdump) {
hdump_bldr.Commit();
}
}
@Override public void Exec_end_hook() {
// if (converter_lang != null) converter_lang.Log__rls();
if (gen_hdump) hdump_bldr.Term();
String err_filter_mgr = invoke_wkr.Err_filter_mgr().Print();
if (String_.Len_gt_0(err_filter_mgr)) usr_dlg.Warn_many("", "", err_filter_mgr);
wiki.Appe().Log_mgr().Txn_end();
tbl.Insert_end();
}
public void Log_file(Xop_ctx ctx, Xop_lnki_tkn lnki, byte caller_tid) {
if (lnki.Ttl().ForceLiteralLink()) return; // ignore literal links which creat a link to file, but do not show the image; EX: [[:File:A.png|thumb|120px]] creates a link to File:A.png, regardless of other display-oriented args
byte[] ttl = lnki.Ttl().Page_db();
Xof_ext ext = Xof_ext_.new_by_ttl_(ttl);
double lnki_time = lnki.Time();
int lnki_page = lnki.Page();
byte[] ttl_commons = Xomp_lnki_temp_wkr.To_commons_ttl(ns_file_is_case_match_all, commons_wiki, ttl);
if ( Xof_lnki_page.Null_n(lnki_page) // page set
&& Xof_lnki_time.Null_n(lnki_time)) // thumbtime set
usr_dlg.Warn_many("", "", "page and thumbtime both set; this may be an issue with fsdb: page=~{0} ttl=~{1}", ctx.Page().Ttl().Page_db_as_str(), String_.new_u8(ttl));
if (lnki.Ns_id() == Xow_ns_.Tid__media)
caller_tid = Xop_file_logger_.Tid__media;
tbl.Insert_cmd_by_batch(ctx.Page().Bldr__ns_ord(), ctx.Page().Db().Page().Id(), ttl, ttl_commons, Byte_.By_int(ext.Id()), lnki.Lnki_type(), caller_tid, lnki.W(), lnki.H(), lnki.Upright(), lnki_time, lnki_page);
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_wdata_enabled_)) wdata_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_xtn_ref_enabled_)) xtn_ref_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_ns_ids_)) ns_ids = Int_.Ary_parse(m.ReadStr("v"), "|");
else if (ctx.Match(k, Invk_ns_ids_by_aliases)) ns_ids = Xobldr__lnki_temp__create_.Ns_ids_by_aliases(wiki, m.ReadStrAry("v", "|"));
else if (ctx.Match(k, Invk_gen_html_)) gen_html = m.ReadYn("v");
else if (ctx.Match(k, Invk__load_all_imglinks_)) load_all_imglinks = m.ReadYn("v");
else if (ctx.Match(k, Invk_hdump_bldr)) return hdump_bldr;
else if (ctx.Match(k, Invk_property_wkr)) return this.Property_wkr();
else if (ctx.Match(k, Invk_invoke_wkr)) return this.Invoke_wkr();
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk_wdata_enabled_ = "wdata_enabled_", Invk_xtn_ref_enabled_ = "xtn_ref_enabled_", Invk_gen_html_ = "gen_html_"
, Invk_ns_ids_ = "ns_ids_", Invk_ns_ids_by_aliases = "ns_ids_by_aliases"
, Invk_invoke_wkr = "invoke_wkr", Invk_property_wkr = "property_wkr", Invk_hdump_bldr = "hdump_bldr"
, Invk__load_all_imglinks_ = "load_all_imglinks_"
;
public static final String BLDR_CMD_KEY = "file.lnki_temp";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__lnki_temp__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__lnki_temp__create(bldr, wiki);}
private Xop_log_invoke_wkr Invoke_wkr() {
if (invoke_wkr == null) invoke_wkr = ((Scrib_xtn_mgr)bldr.App().Xtn_mgr().Get_or_fail(Scrib_xtn_mgr.XTN_KEY)).Invoke_wkr_or_new();
return invoke_wkr;
}
private Xop_log_property_wkr Property_wkr() {
if (property_wkr == null) property_wkr = bldr.App().Wiki_mgr().Wdata_mgr().Property_wkr_or_new();
return property_wkr;
}
public static boolean Ns_file_is_case_match_all(Xow_wiki wiki) {return wiki.Ns_mgr().Ns_file().Case_match() == Xow_ns_case_.Tid__all;}
}

View File

@@ -0,0 +1,53 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.wikis.nss.*;
class Xobldr__lnki_temp__create_ {
public static int[] Ns_ids_by_aliases(Xowe_wiki wiki, String[] aliases) {
int[] rv = Xobldr__lnki_temp__create_.Ids_by_aliases(wiki.Ns_mgr(), aliases);
int aliases_len = aliases.length;
int ids_len = rv.length;
for (int i = 0; i < aliases_len; i++) {
String alias = aliases[i];
int id = i < ids_len ? rv[i] : -1;
wiki.Appe().Usr_dlg().Note_many("", "", "ns: ~{0} <- ~{1}", Int_.To_str_fmt(id, "0000"), alias);
}
if (aliases_len != ids_len) throw Err_.new_wo_type("mismatch in aliases and ids", "aliases", aliases_len, "ids", ids_len);
return rv;
}
private static int[] Ids_by_aliases(Xow_ns_mgr ns_mgr, String[] aliases) {
List_adp list = List_adp_.New();
int len = aliases.length;
for (int i = 0; i < len; i++) {
String alias = aliases[i];
if (String_.Eq(alias, Xow_ns_.Key__main))
list.Add(ns_mgr.Ns_main());
else {
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_u8(alias));
if (ns != null)
list.Add(ns);
}
}
len = list.Count();
int[] rv = new int[len];
for (int i = 0; i < len; i++) {
rv[i] = ((Xow_ns)list.Get_at(i)).Id();
}
return rv;
}
}

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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import org.junit.*;
public class Xobldr__lnki_temp__create__tst {
private Xobldr__lnki_temp__create__fxt fxt = new Xobldr__lnki_temp__create__fxt();
@Test public void Xto_commons() {
fxt.Init__to_commons(true);
fxt.Test__to_commons("a", "A");
fxt.Test__to_commons("A", null);
fxt.Init__to_commons(false);
fxt.Test__to_commons("a", null);
fxt.Test__to_commons("A", null);
}
}
class Xobldr__lnki_temp__create__fxt {
private boolean wiki_ns_file_is_case_match_all;
private Xowe_wiki commons_wiki;
public Xobldr__lnki_temp__create__fxt Init__to_commons(boolean wiki_ns_file_is_case_match_all) {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki_ns_file_is_case_match_all = wiki_ns_file_is_case_match_all;
this.commons_wiki = Xoa_app_fxt.Make__wiki__edit(app); // commons_wiki will default to Xow_ns.Id_file of case_match_1st
return this;
}
public void Test__to_commons(String ttl, String expd) {
Tfds.Eq(expd, String_.new_u8(gplx.xowa.addons.bldrs.mass_parses.parses.utls.Xomp_lnki_temp_wkr.To_commons_ttl(wiki_ns_file_is_case_match_all, commons_wiki, Bry_.new_u8(ttl))));
}
}

View File

@@ -0,0 +1,48 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.wikis.domains.*;
public class Xobldr__orig_regy__create extends Xob_cmd__base {
private boolean repo_0_is_remote = false;
public Xobldr__orig_regy__create(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Db_conn conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
Xob_orig_regy_tbl.Create_table(conn);
Xowe_wiki commons_wiki = bldr.App().Wiki_mgr().Get_by_or_make(Xow_domain_itm_.Bry__commons).Init_assert();
Xowe_wiki repo_0 = wiki, repo_1 = commons_wiki;
if (repo_0_is_remote) { // NOTE: default is false; local_wiki will be preferred over commons_wiki
repo_0 = commons_wiki;
repo_1 = wiki;
}
repo_0.Init_assert(); repo_1.Init_assert();
Xob_db_file file_registry_db = Xob_db_file.New__page_regy(commons_wiki.Fsys_mgr().Root_dir());
Xob_orig_regy_tbl.Create_data(bldr.Usr_dlg(), conn, file_registry_db, repo_0_is_remote, repo_0, repo_1, Xobldr__lnki_temp__create.Ns_file_is_case_match_all(wiki));
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_repo_0_is_remote_)) this.repo_0_is_remote = m.ReadYn("v");
else return super.Invk(ctx, ikey, k, m);
return this;
} private static final String Invk_repo_0_is_remote_ = "repo_0_is_remote_";
public static final String BLDR_CMD_KEY = "file.orig_regy";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__orig_regy__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__orig_regy__create(bldr, wiki);}
}

View File

@@ -0,0 +1,90 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.files.*; import gplx.xowa.files.origs.*; import gplx.xowa.apps.wms.apis.origs.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xobldr__orig_regy__find_missing extends Xob_cmd__base {
private int fail_max = 100000;
public Xobldr__orig_regy__find_missing(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
// got orig_tbl
Db_conn conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
Xob_orig_regy_tbl.Create_table(conn);
// get counts; fail if too many
int fail_count = conn.Exec_select_count_as_int("orig_regy", 0);
if (fail_count > fail_max) throw Err_.new_wo_type("bldr.find_missing: too many missing: missing=~{0} max=~{1}", fail_count, fail_max);
Gfo_usr_dlg_.Instance.Note_many("", "", "bldr.find_missing: found=~{0}", fail_count);
// select into list; ignore any which are invalid titles
List_adp list = List_adp_.New();
byte[] wiki_abrv = wiki.Domain_itm().Abrv_xo();
int invalid_count = 0;
String sql = "SELECT lnki_ttl FROM orig_regy WHERE orig_page_id IS NULL";
Db_rdr rdr = conn.Stmt_sql(sql).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
// get lnki_ttl; check if valid
byte[] lnki_ttl = rdr.Read_bry("lnki_ttl");
Xoa_ttl ttl = wiki.Ttl_parse(lnki_ttl);
if (ttl == null) {
invalid_count++;
continue;
}
// create itm and add to list
Xof_fsdb_itm itm = new Xof_fsdb_itm();
itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, wiki_abrv, lnki_ttl, Byte_.Zero, Xof_img_size.Upright_null, -1, -1, -1, -1, Xof_patch_upright_tid_.Tid_all);
list.Add(itm);
}
} finally {rdr.Rls();}
Gfo_usr_dlg_.Instance.Note_many("", "", "bldr.find_missing: invalid=~{0}", invalid_count);
// call api with list
Xof_orig_wkr__wmf_api wkr = new Xof_orig_wkr__wmf_api(new Xoapi_orig_wmf(), wiki.App().Wmf_mgr().Download_wkr(), wiki.File__repo_mgr(), wiki.Domain_bry());
wkr.Find_by_list(null, null);
// loop list and update
conn.Txn_bgn("bldr.find_missing");
Db_stmt update_stmt = conn.Stmt_update("orig_regy", String_.Ary("lnki_ttl")
, "orig_commons_flag", "orig_repo"
, "orig_page_id", "orig_redirect_id", "orig_redirect_ttl"
, "orig_file_id", "orig_file_ttl", "orig_file_ext"
, "orig_size", "orig_w", "orig_h", "orig_bits", "orig_media_type", "orig_minor_mime", "orig_timestamp");
int len = list.Len();
for (int i = 0; i < len; i++) {
Xof_fsdb_itm itm = (Xof_fsdb_itm)list.Get_at(i);
update_stmt
.Val_int("orig_w", itm.Orig_w()).Val_int("orig_h", itm.Orig_h())
.Crt_bry_as_str("lnki_ttl", itm.Lnki_ttl()).Exec_update();
}
conn.Txn_end();
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__fail_max_)) this.fail_max = m.ReadInt("v");
else return super.Invk(ctx, ikey, k, m);
return this;
} private static final String Invk__fail_max_ = "fail_max_";
public static final String BLDR_CMD_KEY = "file.orig_regy.find_missing";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__orig_regy__find_missing(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__orig_regy__find_missing(bldr, wiki);}
}

View File

@@ -0,0 +1,162 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xobldr__page_file_map__create extends Xob_cmd__base {
private Db_conn conn;
public Xobldr__page_file_map__create(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
this.conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
Append__fsdb_id();
Create__fsdb_idxs();
Update__fsdb_id();
Create__page_file_map();
}
private void Append__fsdb_id() { // NOTE: append the field; do not create with table b/c will be extra baggage during all REPLACE INTO
String[] tbls = String_.Ary("xfer_regy", "xfer_temp", "lnki_regy", "lnki_temp", "fsdb_regy");
String fld = "fsdb_id";
for (String tbl : tbls) {
if (!conn.Meta_fld_exists(tbl, fld))
conn.Meta_fld_append(tbl, Dbmeta_fld_itm.new_int(fld).Default_(-1)); // EX: ALTER TABLE xfer_regy ADD fsdb_id INTEGER DEFAULT -1;
}
}
private void Create__fsdb_idxs() {
// EX: CREATE INDEX xfer_regy__fsdb_regy ON xfer_regy (lnki_ttl, file_is_orig, orig_repo, file_w, lnki_time, lnki_page);
Dbmeta_idx_itm[] idxs = new Dbmeta_idx_itm[]
{ Dbmeta_idx_itm.new_normal_by_tbl("xfer_regy", "page_file_map_1", "lnki_ttl", "file_is_orig", "orig_repo", "file_w", "lnki_time", "lnki_page")
, Dbmeta_idx_itm.new_normal_by_tbl("xfer_temp", "page_file_map_1", "lnki_ttl" , "lnki_w", "lnki_h", "lnki_upright", "lnki_time", "lnki_page")
, Dbmeta_idx_itm.new_normal_by_tbl("xfer_temp", "page_file_map_2", "orig_redirect_src", "lnki_w", "lnki_h", "lnki_upright", "lnki_time", "lnki_page")
, Dbmeta_idx_itm.new_normal_by_tbl("lnki_regy", "page_file_map_1", "lnki_ttl", "lnki_w", "lnki_h", "lnki_upright", "lnki_time", "lnki_page")
, Dbmeta_idx_itm.new_normal_by_tbl("lnki_temp", "page_file_map_1", "lnki_ttl", "lnki_w", "lnki_h", "lnki_upright", "lnki_time", "lnki_page")
, Dbmeta_idx_itm.new_normal_by_tbl("fsdb_regy", "page_file_map_1", "fsdb_id", "fsdb_fil_id", "fsdb_thm_id")
};
for (Dbmeta_idx_itm idx : idxs) {
if (!conn.Meta_idx_exists(idx.Name()))
conn.Meta_idx_create(idx);
}
}
private void Update__fsdb_id() {
conn.Exec_sql_concat_w_msg
( "updating fsdb_id.xfer_regy"
, "UPDATE xfer_regy "
, "SET fsdb_id = Coalesce"
, "(("
, "SELECT fsdb_id "
, "FROM fsdb_regy fr"
, "WHERE fr.fsdb_name = xfer_regy.lnki_ttl"
, "AND fr.fsdb_is_orig = xfer_regy.file_is_orig"
, "AND fr.fsdb_repo = xfer_regy.orig_repo"
, "AND fr.fsdb_w = xfer_regy.file_w"
, "AND fr.fsdb_time = xfer_regy.lnki_time"
, "AND fr.fsdb_page = xfer_regy.lnki_page"
, "), -1);"
);
conn.Exec_sql_concat_w_msg
( "updating fsdb_id.xfer_temp"
, "UPDATE xfer_temp"
, "SET fsdb_id = Coalesce"
, "(("
, "SELECT fsdb_id "
, "FROM xfer_regy xr"
, "WHERE xr.lnki_ttl = xfer_temp.lnki_ttl"
, "AND xr.file_is_orig = xfer_temp.file_is_orig"
, "AND xr.orig_repo = xfer_temp.orig_repo"
, "AND xr.file_w = xfer_temp.file_w"
, "AND xr.lnki_time = xfer_temp.lnki_time"
, "AND xr.lnki_page = xfer_temp.lnki_page"
, "), -1);"
);
conn.Exec_sql_concat_w_msg
( "updating fsdb_id.lnki_regy.redirect"
, "UPDATE lnki_regy"
, "SET fsdb_id = Coalesce"
, "(("
, "SELECT fsdb_id "
, "FROM xfer_temp xt"
, "WHERE xt.orig_redirect_src = lnki_regy.lnki_ttl"
, "AND xt.lnki_w = lnki_regy.lnki_w"
, "AND xt.lnki_h = lnki_regy.lnki_h"
, "AND xt.lnki_upright = lnki_regy.lnki_upright"
, "AND xt.lnki_time = lnki_regy.lnki_time"
, "AND xt.lnki_page = lnki_regy.lnki_page"
, "), -1);"
);
conn.Exec_sql_concat_w_msg
( "updating fsdb_id.lnki_regy.direct"
, "UPDATE lnki_regy"
, "SET fsdb_id = Coalesce"
, "(("
, "SELECT fsdb_id "
, "FROM xfer_temp xt"
, "WHERE xt.lnki_ttl = lnki_regy.lnki_ttl"
, "AND xt.lnki_w = lnki_regy.lnki_w"
, "AND xt.lnki_h = lnki_regy.lnki_h"
, "AND xt.lnki_upright = lnki_regy.lnki_upright"
, "AND xt.lnki_time = lnki_regy.lnki_time"
, "AND xt.lnki_page = lnki_regy.lnki_page"
, "), -1)"
, "WHERE Coalesce(fsdb_id, -1) = -1"
, ";"
);
conn.Exec_sql_concat_w_msg
( "updating fsdb_id.lnki_temp"
, "UPDATE lnki_temp"
, "SET fsdb_id = Coalesce"
, "(("
, "SELECT fsdb_id "
, "FROM lnki_regy lr"
, "WHERE lr.lnki_ttl = lnki_temp.lnki_ttl"
, "AND lr.lnki_w = lnki_temp.lnki_w"
, "AND lr.lnki_h = lnki_temp.lnki_h"
, "AND lr.lnki_upright = lnki_temp.lnki_upright"
, "AND lr.lnki_time = lnki_temp.lnki_time"
, "AND lr.lnki_page = lnki_temp.lnki_page"
, "), -1);"
);
}
private void Create__page_file_map() {
Xob_db_file map_db = Xob_db_file.New__page_file_map(wiki);
Db_conn map_conn = map_db.Conn();
Page_file_map_tbl map_tbl = new Page_file_map_tbl(map_conn, "page_file_map");
map_conn.Meta_tbl_remake(map_tbl.Meta());
map_conn.Env_db_attach("make_db", conn);
map_conn.Exec_sql_concat_w_msg
( "inserting page_file_map"
, "INSERT INTO page_file_map (page_id, fil_id, thm_id, sort_id, count_of)"
, "SELECT lt.lnki_page_id"
, ", fr.fsdb_fil_id"
, ", fr.fsdb_thm_id"
, ", -1"
, ", Count(fr.fsdb_thm_id)"
, "FROM make_db.lnki_temp lt"
, " JOIN make_db.fsdb_regy fr ON lt.fsdb_id = fr.fsdb_id"
, "GROUP BY lt.lnki_page_id"
, ", fr.fsdb_fil_id"
, ", fr.fsdb_thm_id"
, ";"
);
map_conn.Env_db_detach("make_db");
map_conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl("page_file_map", "main", "fil_id", "thm_id"));
}
public static final String BLDR_CMD_KEY = "file.page_file_map.create";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__page_file_map__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__page_file_map__create(bldr, wiki);}
}

View File

@@ -0,0 +1,52 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.addons.bldrs.files.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.files.repos.*;
public class Xobldr__page_regy__create extends Xob_cmd__base {
private boolean build_commons = false;
public Xobldr__page_regy__create(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Xowe_wiki commons_wiki = bldr.App().Wiki_mgr().Get_by_or_make(Xow_domain_itm_.Bry__commons).Init_assert();
Db_conn page_regy_provider = Xob_db_file.New__page_regy(commons_wiki.Fsys_mgr().Root_dir()).Conn();
commons_wiki.Init_assert();
if (build_commons) {
Xob_page_regy_tbl.Reset_table(page_regy_provider);
Xob_page_regy_tbl.Create_data(bldr.Usr_dlg(), page_regy_provider, Xof_repo_tid_.Tid__remote, commons_wiki);
Sqlite_engine_.Idx_create(usr_dlg, page_regy_provider, "repo_page", Xob_page_regy_tbl.Idx_main);
}
else {
if (!Bry_.Eq(commons_wiki.Domain_bry(), wiki.Domain_bry())) { // skip local wiki if cur wiki is commons
wiki.Init_assert();
Xob_page_regy_tbl.Delete_local(page_regy_provider);
Xob_page_regy_tbl.Create_data(bldr.Usr_dlg(), page_regy_provider, Xof_repo_tid_.Tid__local, wiki);
}
}
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_build_commons_)) build_commons = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_build_commons_ = "build_commons_";
public static final String BLDR_CMD_KEY = "file.page_regy";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__page_regy__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__page_regy__create(bldr, wiki);}
}

View File

@@ -0,0 +1,65 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.utils.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xobldr__redirect__create extends Xob_dump_mgr_base {
private Db_conn conn; private Xob_redirect_tbl redirect_tbl;
private Xodb_mgr_sql db_mgr; private Xop_redirect_mgr redirect_mgr; private Gfo_url_encoder encoder;
public Xobldr__redirect__create(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); this.Reset_db_y_();}
@Override public int[] Init_ns_ary() {return Int_.Ary(Xow_ns_.Tid__file);} // restrict to file ns
@Override public byte Init_redirect() {return Bool_.Y_byte;} // restrict to redirects
@Override protected void Init_reset(Db_conn conn) {
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
cfg_tbl.Delete_all();
conn.Exec_sql("DELETE FROM " + Xob_redirect_tbl.Tbl_name);
}
@Override protected Db_conn Init_db_file() {
this.db_mgr = wiki.Db_mgr_as_sql();
redirect_mgr = wiki.Redirect_mgr();
encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url_ttl;
redirect_tbl = new Xob_redirect_tbl(wiki.Fsys_mgr().Root_dir(), gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url_ttl).Create_table();
conn = redirect_tbl.Conn();
conn.Txn_bgn("bldr__redirect");
return conn;
}
@Override protected void Cmd_bgn_end() {}
@Override public void Exec_pg_itm_hook(int ns_ord, Xow_ns ns, Xowd_page_itm page, byte[] page_src) {
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(page_src);
byte[] redirect_ttl_bry = Xoa_ttl.Replace_spaces(redirect_ttl.Page_db()); // NOTE: spaces can still exist b/c redirect is scraped from #REDIRECT which sometimes has a mix; EX: "A_b c"
redirect_ttl_bry = encoder.Decode(redirect_ttl_bry);
redirect_tbl.Insert(page.Id(), Xoa_ttl.Replace_spaces(page.Ttl_page_db()), -1, redirect_ttl.Ns().Id(), redirect_ttl_bry, redirect_ttl.Anch_txt(), 1);
}
@Override public void Exec_commit_hook() {
conn.Txn_sav();
}
@Override public void Exec_end_hook() {
conn.Txn_end();
redirect_tbl.Create_indexes(usr_dlg);
redirect_tbl.Update_trg_redirect_id(db_mgr.Core_data_mgr().Db__core().Url(), 4);
}
public static final String BLDR_CMD_KEY = "wiki.redirect";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__redirect__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__redirect__create(bldr, wiki);}
}

View File

@@ -0,0 +1,44 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.wikis.dbs.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xobldr__text_db__drop_page extends Xob_cmd__base {
public Xobldr__text_db__drop_page(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
int len = db_mgr.Dbs__len();
for (int i = 0; i < len; i++) {
Xow_db_file db_file = db_mgr.Dbs__get_at(i);
switch (db_file.Tid()) {
case Xow_db_file_.Tid__wiki_solo:
case Xow_db_file_.Tid__text_solo:
case Xow_db_file_.Tid__text:
db_file.Conn().Meta_tbl_delete(Xob_page_dump_tbl.Tbl_name);
break;
}
}
}
public static final String BLDR_CMD_KEY = "wiki.page_dump.drop";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__text_db__drop_page(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__text_db__drop_page(bldr, wiki);}
}

View File

@@ -0,0 +1,46 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.wikis.dbs.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xobldr__text_db__make_page extends Xob_cmd__base {
public Xobldr__text_db__make_page(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
Io_url page_db_url = db_mgr.Db__core().Url();
int len = db_mgr.Dbs__len();
for (int i = 0; i < len; i++) {
Xow_db_file db_file = db_mgr.Dbs__get_at(i);
switch (db_file.Tid()) {
case Xow_db_file_.Tid__wiki_solo:
case Xow_db_file_.Tid__text_solo:
case Xow_db_file_.Tid__text:
Xob_page_dump_tbl tbl = new Xob_page_dump_tbl(db_file.Conn());
tbl.Create_data(page_db_url, db_file.Id());
break;
}
}
}
public static final String BLDR_CMD_KEY = "wiki.page_dump.make";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__text_db__make_page(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__text_db__make_page(bldr, wiki);}
}

View File

@@ -0,0 +1,37 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xobldr__xfer_regy__create extends Xob_cmd__base {
public Xobldr__xfer_regy__create(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Db_conn conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
conn.Txn_bgn("bldr__xfer_regy");
Xob_xfer_regy_tbl.Create_table(conn);
Xob_xfer_regy_tbl.Create_data(usr_dlg, conn);
Xob_xfer_regy_tbl.Create_index(usr_dlg, conn);
Xob_xfer_regy_log_tbl.Create_table(conn);
conn.Txn_end();
}
public static final String BLDR_CMD_KEY = "file.xfer_regy";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__xfer_regy__create(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__xfer_regy__create(bldr, wiki);}
}

View File

@@ -0,0 +1,70 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.addons.bldrs.files.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.fsdb.meta.*;
public class Xobldr__xfer_regy__update_downloaded extends Xob_cmd__base implements Xob_cmd {
public Xobldr__xfer_regy__update_downloaded(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert(); // NOTE: must init wiki to set up db_core; DATE:2015-08-17
Db_conn make_conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
this.Create_fsdb_regy(make_conn);
this.Update_xfer_regy(make_conn);
}
private void Create_fsdb_regy(Db_conn make_conn) {
wiki.File_mgr().Init_file_mgr_by_load(wiki); // NOTE: uses ./file.core.xowa; never uses -prv/file.core.xowa or /prv/file.core.xowa; DATE:2015-09-10
Fsm_mnt_itm mnt_itm = wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Mnts__get_main(); // 0 = fsdb.main
// connect to fsdb_db; create fsdb_regy
Db_conn fsdb_conn = mnt_itm.Atr_mgr().Db__core().Conn(); // 0 = fsdb.atr.00
make_conn.Env_db_attach("fsdb_db", fsdb_conn);
make_conn.Meta_tbl_delete(Xob_fsdb_regy_tbl_.Tbl_name);
Sqlite_engine_.Tbl_create_and_delete(make_conn, Xob_fsdb_regy_tbl_.Tbl_name, Xob_fsdb_regy_tbl_.Tbl_sql);
// insert fil into fsdb_regy
make_conn.Txn_bgn("bldr__xfer_regy_update");
make_conn.Exec_sql(Xob_fsdb_regy_tbl_.Insert_fsdb_fil);
String fsdb_thm_tbl = mnt_itm.Db_mgr().File__schema_is_1() ? "fsdb_xtn_thm" : "fsdb_thm";
// insert thm into fsdb_regy
String insert_sql_fsdb_thm
= wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Mnts__get_main().Cfg_mgr().Schema_thm_page()
? String_.Format(Xob_fsdb_regy_tbl_.Insert_fsdb_thm, fsdb_thm_tbl)
: Xob_fsdb_regy_tbl_.Insert_fsdb_thm_v0
;
make_conn.Exec_sql(insert_sql_fsdb_thm);
// end txn; cleanup
make_conn.Txn_end();
Sqlite_engine_.Idx_create(make_conn, Xob_fsdb_regy_tbl_.Idx_main);
Sqlite_engine_.Db_detach(make_conn, "fsdb_db");
}
private void Update_xfer_regy(Db_conn make_conn) {
make_conn.Txn_bgn("bldr__xfer_regy_update_status");
make_conn.Exec_sql(Xob_fsdb_regy_tbl_.Update_regy_nil);
make_conn.Exec_sql(Xob_fsdb_regy_tbl_.Update_regy_fil);
make_conn.Exec_sql(Xob_fsdb_regy_tbl_.Update_regy_thm);
make_conn.Txn_end();
}
public static final String BLDR_CMD_KEY = "file.xfer_regy_update";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__xfer_regy__update_downloaded(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__xfer_regy__update_downloaded(bldr, wiki);}
}

View File

@@ -0,0 +1,108 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.stores.*; import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.files.*; import gplx.xowa.files.exts.*; import gplx.xowa.parsers.lnkis.*;
public class Xobldr__xfer_temp__insert_orig extends Xob_cmd__base {
private byte[] ext_rules_key = Bry_.Empty;
public Xobldr__xfer_temp__insert_orig(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Db_conn conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
Xob_xfer_temp_tbl.Create_table(conn);
Db_stmt trg_stmt = Xob_xfer_temp_tbl.Insert_stmt(conn);
conn.Txn_bgn("bldr__xfer_temp");
DataRdr rdr = conn.Exec_sql_as_old_rdr(Sql_select_clause);
long[] ext_maxs = Calc_ext_max();
while (rdr.MoveNextPeer()) {
int lnki_ext = rdr.ReadByte(Xob_lnki_regy_tbl.Fld_lnki_ext);
String orig_media_type = rdr.ReadStrOr(Xob_orig_regy_tbl.Fld_orig_media_type, ""); // convert nulls to ""
lnki_ext = rdr.ReadInt(Xob_orig_regy_tbl.Fld_orig_file_ext);
int lnki_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_id);
int lnki_tier_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_tier_id);
byte orig_repo = rdr.ReadByte(Xob_orig_regy_tbl.Fld_orig_repo);
int orig_page_id = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_page_id, -1);
if (orig_page_id == -1) continue; // no orig found; ignore
String join_ttl = rdr.ReadStr(Xob_orig_regy_tbl.Fld_orig_file_ttl);
String redirect_src = rdr.ReadStr(Xob_orig_regy_tbl.Fld_lnki_ttl);
if (String_.Eq(join_ttl, redirect_src)) // lnki_ttl is same as redirect_src; not a redirect
redirect_src = "";
int orig_w = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_w, -1);
int orig_h = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_h, -1);
int orig_size = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_size, -1);
if (orig_size > ext_maxs[lnki_ext]) continue;
int lnki_page_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_page_id);
Xob_xfer_temp_tbl.Insert(trg_stmt, lnki_id, lnki_tier_id, lnki_page_id, orig_repo, orig_page_id, join_ttl, redirect_src, lnki_ext, Xop_lnki_type.Id_none, orig_media_type
, Bool_.Y // orig is y
, orig_w, orig_h
, orig_w, orig_h // file_w, file_h is same as orig_w,orig_h; i.e.: make same file_w as orig_w
, Xof_img_size.Null, Xof_img_size.Null // html_w, html_h is -1; i.e.: will not be displayed in page at specific size (this matches logic in Xobldr__xfer_temp__insert_thm)
, rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_w)
, rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_h)
, Xop_lnki_tkn.Upright_null
, Xof_lnki_time.Null
, Xof_lnki_page.Null
, 0);
}
conn.Txn_end();
}
private long[] Calc_ext_max() {
Xof_rule_grp ext_rules = wiki.Appe().File_mgr().Ext_rules().Get_or_new(ext_rules_key);
long[] rv = new long[Xof_ext_.Id__max];
for (int i = 0; i < Xof_ext_.Id__max; i++) {
byte[] ext = Xof_ext_.Get_ext_by_id_(i);
Xof_rule_itm ext_rule = ext_rules.Get_or_null(ext);
long max = ext_rule == null ? 0 : ext_rule.Make_max();
rv[i] = max;
}
return rv;
}
private static final String
Sql_select_clause = String_.Concat_lines_nl
( "SELECT DISTINCT"
, " l.lnki_id"
// , ", lnki_ttl"
, ", l.lnki_ext"
, ", l.lnki_page_id"
, ", o.orig_repo"
, ", o.orig_page_id"
// , ", orig_file_id"
, ", o.orig_file_ttl"
, ", o.orig_file_ext"
, ", o.lnki_ttl"
, ", o.orig_size"
, ", o.orig_w"
, ", o.orig_h"
, ", o.orig_media_type"
// , ", orig_bits"
, "FROM lnki_regy l"
, " JOIN orig_regy o ON o.lnki_ttl = l.lnki_ttl"
, "WHERE o.orig_file_ttl IS NOT NULL"
, "ORDER BY o.orig_file_ttl DESC"
);
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_ext_rules_)) ext_rules_key = m.ReadBry("v");
else return super.Invk (ctx, ikey, k, m);
return this;
} private static final String Invk_ext_rules_ = "ext_rules_";
public static final String BLDR_CMD_KEY = "file.xfer_temp.orig";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__xfer_temp__insert_orig(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__xfer_temp__insert_orig(bldr, wiki);}
}

View File

@@ -0,0 +1,81 @@
/*
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.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.dbs.*; import gplx.core.stores.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.addons.bldrs.files.utls.*;
import gplx.xowa.files.*;
public class Xobldr__xfer_temp__insert_thm extends Xob_cmd__base {
public Xobldr__xfer_temp__insert_thm(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Db_conn conn = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
Xob_xfer_temp_tbl.Create_table(conn);
Db_stmt trg_stmt = Xob_xfer_temp_tbl.Insert_stmt(conn);
conn.Txn_bgn("bldr__xfer_temp_thumb");
DataRdr rdr = conn.Exec_sql_as_old_rdr(String_.Concat_lines_nl
( "SELECT l.lnki_id"
, ", l.lnki_tier_id"
, ", l.lnki_page_id"
, ", l.lnki_ext"
, ", l.lnki_type"
, ", l.lnki_src_tid"
, ", l.lnki_w"
, ", l.lnki_h"
, ", l.lnki_upright"
, ", l.lnki_time"
, ", l.lnki_page"
, ", l.lnki_count"
, ", o.orig_repo"
, ", o.orig_page_id"
, ", o.orig_file_ttl"
, ", o.orig_file_ext"
, ", o.orig_file_id"
, ", o.lnki_ttl"
, ", o.orig_w"
, ", o.orig_h"
, ", o.orig_media_type"
, ", o.orig_minor_mime"
, "FROM lnki_regy l"
, " JOIN orig_regy o ON o.lnki_ttl = l.lnki_ttl"
, "WHERE o.orig_file_ttl IS NOT NULL"
, "ORDER BY o.orig_file_ttl, o.orig_repo DESC, l.lnki_w DESC" // NOTE: local=1,common=0; DATE:2015-03-22
));
Xob_xfer_temp_itm temp_itm = new Xob_xfer_temp_itm();
Xof_img_size img_size = new Xof_img_size();
byte[] cur_ttl = Bry_.Empty; byte cur_repo = Byte_.Max_value_127;
while (rdr.MoveNextPeer()) {
temp_itm.Clear();
temp_itm.Load(rdr);
if (Bry_.Eq(cur_ttl, temp_itm.Orig_file_ttl())) { // same ttl; DATE:2015-03-22
if (temp_itm.Orig_repo() != cur_repo) // if repo is different, ignore 2nd; handles images in both repos; take 1st only (which should be local)
continue;
}
else { // new ttl; update ttl, repo
cur_ttl = temp_itm.Orig_file_ttl();
cur_repo = temp_itm.Orig_repo();
}
if (temp_itm.Chk(img_size))
temp_itm.Insert(trg_stmt, img_size);
}
conn.Txn_end();
}
public static final String BLDR_CMD_KEY = "file.xfer_temp.thumb";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__xfer_temp__insert_thm(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__xfer_temp__insert_thm(bldr, wiki);}
}

View File

@@ -0,0 +1,38 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*;
public class Page_file_map_tbl implements Db_tbl {
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_page_id, fld_fil_id, fld_thm_id, fld_sort_id, fld_count_of;
public final Db_conn conn;
public Page_file_map_tbl(Db_conn conn, String tbl_name) {
this.conn = conn;
this.tbl_name = tbl_name;
this.fld_page_id = flds.Add_int("page_id");
this.fld_fil_id = flds.Add_int("fil_id");
this.fld_thm_id = flds.Add_int("thm_id");
this.fld_sort_id = flds.Add_int("sort_id");
this.fld_count_of = flds.Add_int("count_of");
this.meta = Dbmeta_tbl_itm.New(tbl_name, flds);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(meta);}
public Dbmeta_tbl_itm Meta() {return meta;} private final Dbmeta_tbl_itm meta;
public void Rls() {}
}

View File

@@ -0,0 +1,132 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*;
public class Xob_fsdb_regy_tbl_ {
public static final String Tbl_name = "fsdb_regy";
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE fsdb_regy "
, "( fsdb_id integer NOT NULL PRIMARY KEY AUTOINCREMENT"
, ", fsdb_name varchar(255) NOT NULL"
, ", fsdb_is_orig tinyint NOT NULL"
, ", fsdb_repo tinyint NOT NULL"
, ", fsdb_w integer NOT NULL"
, ", fsdb_time double NOT NULL"
, ", fsdb_page integer NOT NULL"
, ", fsdb_db_id integer NOT NULL"
, ", fsdb_size bigint NOT NULL"
, ", fsdb_status tinyint NOT NULL"
, ", fsdb_fil_id integer NOT NULL"
, ", fsdb_thm_id integer NOT NULL"
, ", fsdb_deleted tinyint NOT NULL"
, ");"
);
public static final Db_idx_itm Idx_main = Db_idx_itm.sql_("CREATE INDEX fsdb_regy__main ON fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page);");
public static final String
Insert_fsdb_fil = String_.Concat_lines_nl
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status, fsdb_fil_id, fsdb_thm_id, fsdb_deleted)"
, "SELECT f.fil_name"
, ", 1"
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
, ", -1"
, ", -1"
, ", -1"
, ", f.fil_bin_db_id"
, ", f.fil_size"
, ", 0"
, ", f.fil_id"
, ", -1"
, ", 0"
, "FROM fsdb_db.fsdb_fil f"
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
, "WHERE f.fil_bin_db_id != -1"
, ";"
)
, Insert_fsdb_thm = String_.Concat_lines_nl
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status, fsdb_fil_id, fsdb_thm_id, fsdb_deleted)"
, "SELECT f.fil_name"
, ", 0"
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
, ", t.thm_w"
, ", t.thm_time"
, ", t.thm_page"
, ", t.thm_bin_db_id"
, ", t.thm_size"
, ", 0"
, ", f.fil_id"
, ", t.thm_id"
, ", 0"
, "FROM fsdb_db.fsdb_fil f"
, " JOIN fsdb_db.{0} t ON f.fil_id = t.thm_owner_id"
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
, ";"
)
, Insert_fsdb_thm_v0 = String_.Concat_lines_nl
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status, fsdb_fil_id, fsdb_thm_id, fsdb_deleted)"
, "SELECT f.fil_name"
, ", 0"
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
, ", t.thm_w"
, ", t.thm_thumbtime"
, ", -1"
, ", t.thm_bin_db_id"
, ", t.thm_size"
, ", 0"
, ", f.fil_id"
, ", t.thm_id"
, ", 0"
, "FROM fsdb_db.fsdb_fil f"
, " JOIN fsdb_db.{0} t ON f.fil_id = t.thm_owner_id"
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
, ";"
)
, Update_regy_nil = "UPDATE xfer_regy SET xfer_status = 0;"
, Update_regy_fil = String_.Concat_lines_nl
( "REPLACE INTO xfer_regy "
, "( lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
, ", xfer_status"
, ")"
, "SELECT "
, " lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
, ", CASE WHEN f.fsdb_name IS NOT NULL THEN 1 ELSE 0 END"
, "FROM xfer_regy x"
, " LEFT JOIN fsdb_regy f ON x.lnki_ttl = f.fsdb_name"
, "WHERE x.file_is_orig = 1 AND f.fsdb_is_orig = 1"
, "AND x.orig_repo = f.fsdb_repo"
, ";"
)
, Update_regy_thm = String_.Concat_lines_nl
( "REPLACE INTO xfer_regy "
, "( lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
, ", xfer_status"
, ")"
, "SELECT "
, " lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
, ", CASE WHEN f.fsdb_name IS NOT NULL THEN 1 ELSE 0 END"
, "FROM xfer_regy x"
, " LEFT JOIN fsdb_regy f ON x.lnki_ttl = f.fsdb_name AND x.file_w = f.fsdb_w"
, " AND x.lnki_time = f.fsdb_time AND x.lnki_page = f.fsdb_page"
, "WHERE x.file_is_orig = 0 AND f.fsdb_is_orig = 0"
, "AND x.orig_repo = f.fsdb_repo"
, ";"
);
}

View File

@@ -0,0 +1,58 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
public class Xob_image_tbl {
public Xob_image_tbl Create_table(Db_conn p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql); return this;}
public Xob_image_tbl Create_index(Db_conn p) {Sqlite_engine_.Idx_create(p, Idx_img_name); return this;}
public Db_stmt Insert_stmt(Db_conn p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_img_name, Fld_img_media_type, Fld_img_minor_mime, Fld_img_size, Fld_img_width, Fld_img_height, Fld_img_bits, Fld_img_ext_id, Fld_img_timestamp);}
public void Insert(Db_stmt stmt, byte[] ttl, byte[] media_type, byte[] minor_mime, int size, int w, int h, int bits, int ext_id, byte[] img_timestamp) {
stmt.Clear()
.Val_bry_as_str(ttl)
.Val_bry_as_str(media_type)
.Val_bry_as_str(minor_mime)
.Val_int(size)
.Val_int(w)
.Val_int(h)
.Val_int(bits)
.Val_int(ext_id)
.Val_bry_as_str(img_timestamp)
.Exec_insert();
}
public static final String Tbl_name = "image"
, Fld_img_name = "img_name", Fld_img_media_type = "img_media_type", Fld_img_minor_mime = "img_minor_mime"
, Fld_img_size = "img_size", Fld_img_width = "img_width", Fld_img_height = "img_height", Fld_img_bits = "img_bits", Fld_img_ext_id = "img_ext_id"
, Fld_img_timestamp = "img_timestamp"
;
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS image"
, "( img_name varchar(255) NOT NULL -- varbinary(255)"
, ", img_media_type varchar(64) NOT NULL -- enum('UNKNOWN','BITMAP','DRAWING','AUDIO','VIDEO','MULTIMEDIA','OFFICE','TEXT','EXECUTABLE','ARCHIVE')"
, ", img_minor_mime varchar(32) NOT NULL -- DEFAULT 'unknown'"
, ", img_size integer NOT NULL -- int(8) unsigned"
, ", img_width integer NOT NULL -- int(5)"
, ", img_height integer NOT NULL -- int(5)"
, ", img_bits smallint NOT NULL -- int(3)"
, ", img_ext_id int NOT NULL -- xowa"
, ", img_timestamp varchar(14) NOT NULL -- 20140101155749"
, ");"
);
private static final Db_idx_itm
Idx_img_name = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS image__img_name ON image (img_name, img_timestamp);")
;
}

View File

@@ -0,0 +1,115 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
public class Xob_lnki_regy_tbl {
public static void Create_table(Db_conn p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_conn p, boolean wiki_ns_for_file_is_case_match_all) {
p.Exec_sql(Sql_create_data);
Sqlite_engine_.Idx_create(usr_dlg, p, "lnki_regy", Idx_ttl);
if (wiki_ns_for_file_is_case_match_all)
Sqlite_engine_.Idx_create(usr_dlg, p, "lnki_regy_commons", Idx_ttl_commons);
}
public static final String Tbl_name = "lnki_regy"
, Fld_lnki_id = "lnki_id", Fld_lnki_tier_id = "lnki_tier_id", Fld_lnki_page_id = "lnki_page_id", Fld_lnki_page_ns = "lnki_page_ns"
, Fld_lnki_ttl = "lnki_ttl", Fld_lnki_commons_ttl = "lnki_commons_ttl"
, Fld_lnki_ext = "lnki_ext", Fld_lnki_type = "lnki_type", Fld_lnki_src_tid = "lnki_src_tid"
, Fld_lnki_w = "lnki_w", Fld_lnki_h = "lnki_h", Fld_lnki_upright = "lnki_upright", Fld_lnki_time = "lnki_time", Fld_lnki_page = "lnki_page"
, Fld_lnki_count = "lnki_count"
;
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS lnki_regy"
, "( lnki_id integer NOT NULL PRIMARY KEY"
, ", lnki_tier_id integer NOT NULL"
, ", lnki_page_id integer NOT NULL"
, ", lnki_ttl varchar(255) NOT NULL"
, ", lnki_commons_ttl varchar(255) NULL"
, ", lnki_commons_flag integer NULL"
, ", lnki_ext integer NOT NULL"
, ", lnki_type integer NOT NULL"
, ", lnki_src_tid integer NOT NULL"
, ", lnki_w integer NOT NULL"
, ", lnki_h integer NOT NULL"
, ", lnki_upright double NOT NULL"
, ", lnki_time double NOT NULL"
, ", lnki_page integer NOT NULL"
, ", lnki_count integer NOT NULL"
, ");"
);
public static final String Sql_create_data = String_.Concat_lines_nl
( "INSERT INTO lnki_regy (lnki_id, lnki_tier_id, lnki_page_id, lnki_ttl, lnki_commons_ttl, lnki_ext, lnki_type, lnki_src_tid, lnki_w, lnki_h, lnki_upright, lnki_time, lnki_page, lnki_count)"
, "SELECT Min(lnki_id)"
, ", Min(lnki_tier_id)"
, ", Min(lnki_page_id)"
, ", lnki_ttl"
, ", lnki_commons_ttl"
, ", lnki_ext"
, ", lnki_type"
, ", lnki_src_tid"
, ", lnki_w"
, ", lnki_h"
, ", lnki_upright"
, ", lnki_time"
, ", lnki_page"
, ", Count(lnki_ttl)"
, "FROM lnki_temp"
, "GROUP BY"
, " lnki_ttl"
, ", lnki_commons_ttl"
, ", lnki_ext"
, ", lnki_type"
, ", lnki_src_tid"
, ", lnki_w"
, ", lnki_h"
, ", lnki_upright"
, ", lnki_time"
, ", lnki_page"
, ";"
)
, Sql_cs_mark_changed = String_.Concat_lines_nl
( "REPLACE INTO lnki_regy"
, "SELECT l.lnki_id"
, ", l.lnki_tier_id"
, ", l.lnki_page_id"
, ", l.lnki_ttl"
, ", l.lnki_commons_ttl"
, ", CASE WHEN o.lnki_ttl IS NULL THEN NULL ELSE 1 END"
, ", l.lnki_ext"
, ", l.lnki_type"
, ", l.lnki_src_tid"
, ", l.lnki_w"
, ", l.lnki_h"
, ", l.lnki_upright"
, ", l.lnki_time"
, ", l.lnki_page"
, ", l.lnki_count"
, "FROM lnki_regy l"
, " LEFT JOIN orig_regy o ON o.lnki_ttl = l.lnki_commons_ttl AND o.orig_commons_flag = 2"
, ";"
)
, Sql_cs_update_ttls = String_.Concat_lines_nl
( "UPDATE lnki_regy"
, "SET lnki_ttl = lnki_commons_ttl"
, "WHERE lnki_commons_flag = 1"
, ";"
);
private static final Db_idx_itm
Idx_ttl = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS lnki_regy__ttl ON lnki_regy (lnki_ttl, lnki_ext, lnki_id, lnki_page_id);")
, Idx_ttl_commons = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS lnki_regy__ttl ON lnki_regy (lnki_commons_ttl, lnki_ext, lnki_id, lnki_page_id);")
;
}

View File

@@ -0,0 +1,65 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.files.*;
public class Xob_lnki_temp_tbl implements Db_tbl {
private static final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private static final String tbl_name = "lnki_temp";
public static final String
Fld_lnki_id = flds.Add_int_pkey_autonum("lnki_id"); // NOTE: insertion order index; public b/c not used and want to bypass warning
private static final String
Fld_lnki_tier_id = flds.Add_int("lnki_tier_id")
, Fld_lnki_page_id = flds.Add_int("lnki_page_id")
, Fld_lnki_ttl = flds.Add_str("lnki_ttl", 255)
, Fld_lnki_commons_ttl = flds.Add_str_null("lnki_commons_ttl", 255)
, Fld_lnki_ext = flds.Add_int("lnki_ext")
, Fld_lnki_type = flds.Add_int("lnki_type")
, Fld_lnki_src_tid = flds.Add_int("lnki_src_tid")
, Fld_lnki_w = flds.Add_int("lnki_w")
, Fld_lnki_h = flds.Add_int("lnki_h")
, Fld_lnki_upright = flds.Add_double("lnki_upright")
, Fld_lnki_time = flds.Add_double("lnki_time") // NOTE: thumbtime is float; using double b/c upright is double and would like to keep datatypes same; https://bugzilla.wikimedia.org/show_bug.cgi?id=39014
, Fld_lnki_page = flds.Add_int("lnki_page")
;
private Db_stmt stmt_insert;
public Xob_lnki_temp_tbl(Db_conn conn) {this.conn = conn;}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert_bgn() {conn.Txn_bgn("bldr__lnki_temp"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_stmt_make() {stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_commit() {conn.Txn_sav();}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int tier_id, int page_id, byte[] ttl, byte[] ttl_commons, byte ext_id, byte img_type, byte lnki_src_tid, int w, int h, double upright, double time, int page) {
stmt_insert.Clear()
.Val_int (Fld_lnki_tier_id , tier_id)
.Val_int (Fld_lnki_page_id , page_id)
.Val_bry_as_str (Fld_lnki_ttl , ttl)
.Val_bry_as_str (Fld_lnki_commons_ttl , ttl_commons)
.Val_byte (Fld_lnki_ext , ext_id)
.Val_byte (Fld_lnki_type , img_type)
.Val_int (Fld_lnki_src_tid , lnki_src_tid)
.Val_int (Fld_lnki_w , w)
.Val_int (Fld_lnki_h , h)
.Val_double (Fld_lnki_upright , upright)
.Val_double (Fld_lnki_time , Xof_lnki_time.Db_save_double(time))
.Val_int (Fld_lnki_page , page)
.Exec_insert();
}
public void Rls() {}
}

View File

@@ -0,0 +1,222 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.files.repos.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.domains.*;
import gplx.dbs.engines.sqlite.*;
import gplx.xowa.bldrs.*;
public class Xob_orig_regy_tbl {
public static void Create_table(Db_conn p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_conn p, Xob_db_file file_registry_db, boolean repo_0_is_remote, Xowe_wiki repo_0_wiki, Xowe_wiki repo_1_wiki, boolean wiki_ns_for_file_is_case_match_all) {
usr_dlg.Prog_many("", "", "inserting lnki_regy");
p.Exec_sql(Sql_create_data);
Sqlite_engine_.Idx_create(usr_dlg, p, "orig_regy", Idx_ttl_local);
Sqlite_engine_.Db_attach(p, "page_db", file_registry_db.Url().Raw());
Io_url repo_0_dir = repo_0_wiki.Fsys_mgr().Root_dir(), repo_1_dir = repo_1_wiki.Fsys_mgr().Root_dir();
byte repo_0_tid = Xof_repo_tid_.Tid__local, repo_1_tid = Xof_repo_tid_.Tid__remote;
boolean local_is_remote = Bry_.Eq(repo_0_wiki.Domain_bry(), repo_1_wiki.Domain_bry());
Xowe_wiki local_wiki = repo_0_wiki;
if ( repo_0_is_remote // .gfs manually marked specifes repo_0 as remote
|| ( Bry_.Eq(repo_0_wiki.Domain_bry(), Xow_domain_itm_.Bry__commons) // repo_0 = commons; force repo_0 to be remote; else all orig_repo will be 1; DATE:2014-02-01
&& local_is_remote // repo_0 = repo_1
)
) {
repo_0_tid = Xof_repo_tid_.Tid__remote;
repo_1_tid = Xof_repo_tid_.Tid__local;
local_wiki = repo_1_wiki;
}
Create_data_for_repo(usr_dlg, p, local_wiki, Byte_.By_int(repo_0_tid), repo_0_dir.GenSubFil(Xob_db_file.Name__wiki_image));
if (!local_is_remote) { // only run for repo_1 if local != remote; only affects commons
Create_data_for_repo(usr_dlg, p, local_wiki, Byte_.By_int(repo_1_tid), repo_1_dir.GenSubFil(Xob_db_file.Name__wiki_image));
if (wiki_ns_for_file_is_case_match_all) {
Io_url repo_remote_dir = repo_0_is_remote ? repo_0_dir : repo_1_dir;
Create_data_for_cs(usr_dlg, p, local_wiki, repo_remote_dir);
}
}
Sqlite_engine_.Db_detach(p, "page_db");
Sqlite_engine_.Idx_create(usr_dlg, p, "orig_regy", Idx_xfer_temp);
}
private static void Create_data_for_repo(Gfo_usr_dlg usr_dlg, Db_conn conn, Xowe_wiki local_wiki, byte repo_tid, Io_url join) {
usr_dlg.Note_many("", "", "inserting page for xowa.wiki.image: ~{0}", join.OwnerDir().NameOnly());
boolean wiki_has_cs_file = repo_tid == Xof_repo_tid_.Tid__remote && local_wiki.Ns_mgr().Ns_file().Case_match() == Xow_ns_case_.Tid__all;
String lnki_ttl_fld = wiki_has_cs_file ? "Coalesce(o.lnki_commons_ttl, o.lnki_ttl)" : "o.lnki_ttl"; // NOTE: use lnki_commons_ttl if [[File]] is cs PAGE:en.d:water EX:[[image:wikiquote-logo.png|50px|none|alt=]]; DATE:2014-09-05
if (wiki_has_cs_file)
Sqlite_engine_.Idx_create(usr_dlg, conn, "orig_regy", Idx_ttl_remote);
new Db_attach_mgr(conn, new Db_attach_itm("image_db", join))
.Exec_sql_w_msg("orig_regy:updating page" , Sql_update_repo_page , repo_tid, lnki_ttl_fld)
.Exec_sql_w_msg("orig_regy:updating redirect" , Sql_update_repo_redirect , repo_tid, lnki_ttl_fld);
}
private static void Create_data_for_cs(Gfo_usr_dlg usr_dlg, Db_conn p, Xowe_wiki local_wiki, Io_url repo_remote_dir) {
p.Exec_sql(Xob_orig_regy_tbl.Sql_cs_mark_dupes); // orig_regy: find dupes; see note in SQL
p.Exec_sql(Xob_orig_regy_tbl.Sql_cs_update_ttls); // orig_regy: update lnki_ttl with lnki_commons_ttl
Create_data_for_repo(usr_dlg, p, local_wiki, Xof_repo_tid_.Tid__remote, repo_remote_dir.GenSubFil(Xob_db_file.Name__wiki_image));
p.Exec_sql(Xob_lnki_regy_tbl.Sql_cs_mark_changed); // lnki_regy: update lnki_commons_flag
p.Exec_sql(Xob_lnki_regy_tbl.Sql_cs_update_ttls); // lnki_regy: update cs
}
public static final String Tbl_name = "orig_regy"
, Fld_lnki_id = "lnki_id", Fld_lnki_ttl = "lnki_ttl", Fld_lnki_ext = "lnki_ext", Fld_lnki_count = "lnki_count"
, Fld_orig_repo = "orig_repo", Fld_orig_page_id = "orig_page_id"
, Fld_orig_redirect_id = "orig_redirect_id", Fld_orig_redirect_ttl = "orig_redirect_ttl", Fld_orig_file_id = "orig_file_id", Fld_orig_file_ttl = "orig_file_ttl"
, Fld_orig_size = "orig_size", Fld_orig_w = "orig_w", Fld_orig_h = "orig_h", Fld_orig_bits = "orig_bits"
, Fld_orig_media_type = "orig_media_type", Fld_orig_minor_mime = "orig_minor_mime", Fld_orig_file_ext = "orig_file_ext", Fld_orig_timestamp = "orig_timestamp"
;
private static final Db_idx_itm
Idx_ttl_local = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS orig_regy__ttl_local ON orig_regy (lnki_ttl);")
, Idx_ttl_remote = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS orig_regy__ttl_remote ON orig_regy (lnki_commons_ttl, lnki_ttl);")
, Idx_xfer_temp = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS orig_regy__xfer_temp ON orig_regy (lnki_ttl, orig_file_ttl, orig_repo, orig_timestamp);")
;
private static final String
Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS orig_regy"
, "( lnki_id integer NOT NULL PRIMARY KEY" // NOTE: must be PRIMARY KEY, else later REPLACE INTO will create dupe rows
, ", lnki_ttl varchar(256) NOT NULL"
, ", lnki_commons_ttl varchar(256) NULL"
, ", orig_commons_flag integer NULL"
, ", lnki_ext integer NOT NULL"
, ", lnki_count integer NOT NULL"
, ", orig_repo integer NULL"
, ", orig_page_id integer NULL"
, ", orig_redirect_id integer NULL"
, ", orig_redirect_ttl varchar(256) NULL"
, ", orig_file_id integer NULL"
, ", orig_file_ttl varchar(256) NULL"
, ", orig_file_ext integer NULL"
, ", orig_size integer NULL"
, ", orig_w integer NULL"
, ", orig_h integer NULL"
, ", orig_bits smallint NULL"
, ", orig_media_type varchar(64) NULL"
, ", orig_minor_mime varchar(32) NULL"
, ", orig_timestamp varchar(14) NULL"
, ");"
)
, Sql_create_data = String_.Concat_lines_nl
( "INSERT INTO orig_regy (lnki_id, lnki_ttl, lnki_commons_ttl, orig_commons_flag, lnki_ext, lnki_count, orig_timestamp)"
, "SELECT Min(lnki_id)"
, ", lnki_ttl"
, ", lnki_commons_ttl"
, ", NULL"
, ", lnki_ext"
, ", Sum(lnki_count)"
, ", ''"
, "FROM lnki_regy"
, "GROUP BY lnki_ttl"
, ", lnki_ext"
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
, ";"
)
, Sql_update_repo_page = String_.Concat_lines_nl
( "REPLACE INTO orig_regy"
, "SELECT o.lnki_id"
, ", o.lnki_ttl"
, ", o.lnki_commons_ttl"
, ", o.orig_commons_flag"
, ", o.lnki_ext"
, ", o.lnki_count"
, ", {0}"
, ", m.src_id"
, ", NULL"
, ", NULL"
, ", m.src_id"
, ", m.src_ttl"
, ", i.img_ext_id"
, ", i.img_size"
, ", i.img_width"
, ", i.img_height"
, ", i.img_bits"
, ", i.img_media_type"
, ", i.img_minor_mime"
, ", i.img_timestamp"
, "FROM orig_regy o"
, " JOIN <image_db>image i ON {1} = i.img_name"
, " JOIN page_db.page_regy m ON m.repo_id = {0} AND m.itm_tid = 0 AND {1} = m.src_ttl"
, "WHERE o.orig_file_ttl IS NULL" // NOTE: only insert if file doesn't exist; changed from timestamp b/c old images may exist in both wikis; EX:ar.n:File:Facebook.png; DATE:2014-08-20
// , "WHERE i.img_timestamp > o.orig_timestamp" // NOTE: this handles an image in local and remote by taking later version; DATE:2014-07-22
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
, ";"
)
, Sql_update_repo_redirect = String_.Concat_lines_nl
( "REPLACE INTO orig_regy"
, "SELECT o.lnki_id"
, ", o.lnki_ttl"
, ", o.lnki_commons_ttl"
, ", o.orig_commons_flag"
, ", o.lnki_ext"
, ", o.lnki_count"
, ", {0}"
, ", m.src_id"
, ", m.trg_id"
, ", m.trg_ttl"
, ", m.trg_id"
, ", m.trg_ttl"
, ", i.img_ext_id"
, ", i.img_size"
, ", i.img_width"
, ", i.img_height"
, ", i.img_bits"
, ", i.img_media_type"
, ", i.img_minor_mime"
, ", i.img_timestamp"
, "FROM orig_regy o"
, " JOIN page_db.page_regy m ON m.repo_id = {0} AND m.itm_tid = 1 AND {1} = m.src_ttl"
, " JOIN <image_db>image i ON m.trg_ttl = i.img_name"
, "WHERE o.orig_file_ttl IS NULL" // NOTE: only insert if file doesn't exist; changed from timestamp b/c old images may exist in both wikis; EX:ar.n:File:Facebook.png; DATE:2014-08-20
// , "WHERE i.img_timestamp > o.orig_timestamp" // NOTE: this handles an image in local and remote by taking later version; DATE:2014-07-22
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
, ";"
)
, Sql_cs_mark_dupes = String_.Concat_lines_nl
( "REPLACE INTO orig_regy"
, "SELECT o.lnki_id"
, ", o.lnki_ttl"
, ", o.lnki_commons_ttl"
, ", 1"
, ", o.lnki_ext"
, ", o.lnki_count"
, ", o.orig_repo"
, ", o.orig_page_id"
, ", o.orig_redirect_id"
, ", o.orig_redirect_ttl"
, ", o.orig_file_id"
, ", o.orig_file_ttl"
, ", o.orig_file_ext"
, ", o.orig_size"
, ", o.orig_w"
, ", o.orig_h"
, ", o.orig_bits"
, ", o.orig_media_type"
, ", o.orig_minor_mime"
, ", o.orig_timestamp"
, "FROM orig_regy o"
, " JOIN orig_regy o2 ON o.lnki_commons_ttl = o2.lnki_ttl" // EX: 2 rows in table (1) A.jpg; and (2) "a.jpg,A.jpg"; do not insert row (2) b/c row (1) exists;
, "WHERE o.orig_file_ttl IS NULL" // NOTE: don't use timestamp logic here
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
, ";"
)
, Sql_cs_update_ttls = String_.Concat_lines_nl
( "UPDATE orig_regy"
, "SET lnki_ttl = lnki_commons_ttl"
, ", orig_commons_flag = 2"
, "WHERE orig_file_ttl IS NULL" // orig not found
, "AND lnki_commons_ttl IS NOT NULL" // orig commons ttl exists
, "AND orig_commons_flag IS NULL" // orig is not dupe
, ";"
)
;
}

View File

@@ -0,0 +1,47 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*;
public class Xob_page_dump_tbl {
public final static String Tbl_name = "page_dump";
private final String fld_id, fld_title, fld_namespace, fld_is_redirect;
private final Db_conn conn; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public Xob_page_dump_tbl(Db_conn conn) {
this.conn = conn;
this.fld_id = flds.Add_int_pkey("page_id");
this.fld_title = flds.Add_str("page_title", 255);
this.fld_namespace = flds.Add_int("page_namespace");
this.fld_is_redirect = flds.Add_int("page_is_redirect");
}
public void Create_data(Io_url page_db_url, int text_db_id) {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(Tbl_name, flds));
conn.Stmt_delete(Tbl_name).Exec_delete(); // always clear tables again; allows commands to be rerun; DATE:2015-08-04
new Db_attach_mgr(conn, new Db_attach_itm("page_db", page_db_url))
.Exec_sql_w_msg("text_db_prep.clone_page", Sql_insert_data, text_db_id);
conn.Meta_idx_create(Dbmeta_idx_itm.new_unique_by_tbl(Tbl_name, "main", fld_id, fld_namespace, fld_is_redirect, fld_title));
}
private static final String Sql_insert_data = String_.Concat_lines_nl
( "INSERT INTO page_dump (page_id, page_title, page_namespace, page_is_redirect)"
, "SELECT p.page_id"
, ", p.page_title"
, ", p.page_namespace"
, ", p.page_is_redirect"
, "FROM <page_db>page p"
, "WHERE p.page_text_db_id = {0};"
);
}

View File

@@ -0,0 +1,87 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.files.repos.*; import gplx.dbs.engines.sqlite.*;
import gplx.xowa.bldrs.*;
public class Xob_page_regy_tbl {
public static void Reset_table(Db_conn p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_conn p, byte repo_tid, Xowe_wiki wiki) {
Xow_db_file db_core = wiki.Db_mgr_as_sql().Core_data_mgr().Db__core();
Create_data__insert_page(usr_dlg, p, repo_tid, db_core.Url());
Create_data__insert_redirect(usr_dlg, p, repo_tid, wiki.Fsys_mgr().Root_dir().GenSubFil(Xob_db_file.Name__wiki_redirect));
}
public static void Delete_local(Db_conn p) {
p.Exec_sql("DELETE FROM page_regy WHERE repo_id = " + Xof_repo_tid_.Tid__local);
}
private static void Create_data__insert_page(Gfo_usr_dlg usr_dlg, Db_conn cur, byte repo_tid, Io_url join) {
usr_dlg.Note_many("", "", "inserting page: ~{0}", join.NameOnly());
Sqlite_engine_.Db_attach(cur, "page_db", join.Raw());
cur.Exec_sql(String_.Format(Sql_create_page, repo_tid));
Sqlite_engine_.Db_detach(cur, "page_db");
}
private static void Create_data__insert_redirect(Gfo_usr_dlg usr_dlg, Db_conn cur, byte repo_tid, Io_url join) {
if (!Io_mgr.Instance.ExistsFil(join)) return; // redirect_db will not exist when commons.wikimedia.org is set up on new machine
usr_dlg.Note_many("", "", "inserting redirect: ~{0}", join.OwnerDir().NameOnly());
Sqlite_engine_.Db_attach(cur, "redirect_db", join.Raw());
cur.Exec_sql(String_.Format(Sql_create_redirect, repo_tid));
Sqlite_engine_.Db_detach(cur, "redirect_db");
}
public static final String Tbl_name = "page_regy"
, Fld_uid = "uid", Fld_repo_id = "repo_id", Fld_itm_tid = "itm_tid"
, Fld_src_id = "src_id", Fld_src_ttl = "src_ttl"
, Fld_trg_id = "trg_id", Fld_trg_ttl = "trg_ttl"
;
public static final Db_idx_itm
Idx_main = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS page_regy__main ON page_regy (repo_id, itm_tid, src_ttl, src_id, trg_id, trg_ttl);")
;
private static final String
Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS page_regy"
, "( uid integer NOT NULL PRIMARY KEY AUTOINCREMENT" // NOTE: must be PRIMARY KEY, else later REPLACE INTO will create dupe rows
, ", repo_id integer NOT NULL"
, ", itm_tid tinyint NOT NULL"
, ", src_id integer NOT NULL"
, ", src_ttl varchar(255) NOT NULL"
, ", trg_id integer NOT NULL"
, ", trg_ttl varchar(255) NOT NULL"
, ");"
)
, Sql_create_page = String_.Concat_lines_nl
( "INSERT INTO page_regy (repo_id, itm_tid, src_id, src_ttl, trg_id, trg_ttl)"
, "SELECT {0}"
, ", 0" // 0=page
, ", p.page_id"
, ", p.page_title"
, ", -1"
, ", ''"
, "FROM page_db.page p"
, ";"
)
, Sql_create_redirect = String_.Concat_lines_nl
( "INSERT INTO page_regy (repo_id, itm_tid, src_id, src_ttl, trg_id, trg_ttl)"
, "SELECT {0}"
, ", 1" // 1=redirect
, ", r.src_id"
, ", r.src_ttl"
, ", r.trg_id"
, ", r.trg_ttl"
, "FROM redirect_db.redirect r"
, ";"
)
;
}

View File

@@ -0,0 +1,167 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.bldrs.*;
public class Xob_redirect_tbl {
private Gfo_url_encoder encoder; private Db_stmt insert_stmt;
public Xob_redirect_tbl(Io_url root_dir, Gfo_url_encoder encoder) {
this.db_file = Xob_db_file.New__wiki_redirect(root_dir);
this.conn = db_file.Conn();
this.encoder = encoder;
}
public Xob_db_file Db_file() {return db_file;} private Xob_db_file db_file;
public Db_conn Conn() {return conn;} private Db_conn conn;
public Xob_redirect_tbl Create_table() {Sqlite_engine_.Tbl_create(conn, Tbl_name, Tbl_sql); return this;}
public void Create_indexes(Gfo_usr_dlg usr_dlg) {
Sqlite_engine_.Idx_create(usr_dlg, conn, Xob_db_file.Name__wiki_redirect, Idx_trg_id, Idx_trg_ttl);
}
public void Update_trg_redirect_id(Io_url core_url, int max_redirected_depth) {
Sqlite_engine_.Db_attach(conn, "page_db", core_url.Raw()); // link database with page table
conn.Exec_sql(Sql_get_page_data); // fill in page_id, page_ns, page_is_redirect for trg_ttl; EX: Page_A has "#REDIRECT Page_B"; Page_B is in redirect tbl; find its id, ttl, redirect status
for (int i = 0; i < max_redirected_depth; i++) { // loop to find redirected redirects; note that it is bounded by depth (to guard against circular redirects)
int affected = conn.Exec_sql(Sql_get_redirect_redirects); // find redirects that are also redirects
if (affected == 0) break; // no more redirected redirects; stop
conn.Exec_sql(Sql_get_redirect_page_data); // get page data for redirects
}
Sqlite_engine_.Db_detach(conn, "page_db");
}
public void Update_src_redirect_id(Io_url core_url, Db_conn core_provider) {
// core_provider.Exec_sql(Sql_ddl__page_redirect_id); // create page.page_redirect_id
Sqlite_engine_.Idx_create(conn, Idx_trg_src);
Sqlite_engine_.Db_attach(conn, "page_db", core_url.Raw()); // link database with page table
conn.Exec_sql(Sql_update_redirect_id); // update page_redirect_id
Sqlite_engine_.Db_detach(conn, "page_db");
}
public void Insert(int src_id, byte[] src_bry, Xoa_ttl trg_ttl) {
byte[] redirect_ttl_bry = Xoa_ttl.Replace_spaces(trg_ttl.Page_db()); // NOTE: spaces can still exist b/c redirect is scraped from #REDIRECT which sometimes has a mix; EX: "A_b c"
redirect_ttl_bry = encoder.Decode(redirect_ttl_bry);
this.Insert(src_id, Xoa_ttl.Replace_spaces(src_bry), -1, trg_ttl.Ns().Id(), redirect_ttl_bry, trg_ttl.Anch_txt(), 1);
}
public void Insert(int src_id, byte[] src_ttl, int trg_id, int trg_ns, byte[] trg_ttl, byte[] trg_anchor, int count) {
if (insert_stmt == null) insert_stmt = Db_stmt_.new_insert_(conn, Tbl_name, Fld_src_id, Fld_src_ttl, Fld_trg_id, Fld_trg_ns, Fld_trg_ttl, Fld_trg_anchor, Fld_trg_is_redirect, Fld_redirect_count);
insert_stmt.Clear()
.Val_int(src_id)
.Val_bry_as_str(src_ttl)
.Val_int(trg_id)
.Val_int(trg_ns)
.Val_bry_as_str(trg_ttl)
.Val_bry_as_str(trg_anchor)
.Val_byte((byte)1)
.Val_int(count)
.Exec_insert();
}
public void Rls_all() {
insert_stmt.Rls();
conn.Rls_conn();
}
public static final String Tbl_name = "redirect";
private static final String
Fld_src_id = "src_id", Fld_src_ttl = "src_ttl", Fld_trg_id = "trg_id", Fld_trg_ns = "trg_ns", Fld_trg_ttl = "trg_ttl", Fld_trg_anchor = "trg_anchor"
, Fld_trg_is_redirect = "trg_is_redirect", Fld_redirect_count = "redirect_count";
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS redirect"
, "( src_id integer NOT NULL PRIMARY KEY"
, ", src_ttl varchar(255) NOT NULL"
, ", trg_id integer NOT NULL"
, ", trg_ns integer NOT NULL"
, ", trg_ttl varchar(255) NOT NULL"
, ", trg_anchor varchar(255) NOT NULL"
, ", trg_is_redirect tinyint NOT NULL"
, ", redirect_count integer NOT NULL"
, ");"
);
private static final Db_idx_itm
Idx_trg_ttl = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS redirect__trg_ttl ON redirect (trg_ttl);")
, Idx_trg_id = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS redirect__trg_id ON redirect (trg_id);")
, Idx_trg_src = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS redirect__trg_src ON redirect (src_id, trg_id);")
;
// public static final String
// Sql_ddl__page_redirect_id = "ALTER TABLE page ADD COLUMN page_redirect_id integer NOT NULL DEFAULT '-1'"
// ;
private static final String
Sql_get_page_data = String_.Concat_lines_nl // get data from page table for initial redirect dump
( "REPLACE INTO redirect "
, "SELECT t.src_id"
, ", t.src_ttl"
, ", j.page_id"
, ", t.trg_ns"
, ", t.trg_ttl"
, ", t.trg_anchor"
, ", j.page_is_redirect"
, ", t.redirect_count"
, "FROM redirect t"
, " JOIN page_db.page j "
, " ON t.trg_ns = j.page_namespace"
, " AND t.trg_ttl = j.page_title"
, " AND t.trg_is_redirect = 1 -- limit to redirects"
, ";"
)
, Sql_get_redirect_redirects = String_.Concat_lines_nl // find redirects that are redirected
( "REPLACE INTO redirect"
, "SELECT t.src_id"
, ", t.src_ttl"
, ", j.trg_id"
, ", -1"
, ", ''"
, ", ''"
, ", 1"
, ", t.redirect_count + 1"
, "FROM redirect t"
, " JOIN redirect j "
, " ON t.trg_id = j.src_id"
, " AND t.trg_is_redirect = 1"
, ";"
, ""
)
, Sql_get_redirect_page_data = String_.Concat_lines_nl // get data from page table for redirected redirects
( "REPLACE INTO redirect"
, "SELECT t.src_id"
, ", t.src_ttl"
, ", t.trg_id"
, ", j.page_namespace"
, ", j.page_title"
, ", t.trg_anchor"
, ", j.page_is_redirect"
, ", t.redirect_count"
, "FROM redirect t"
, " JOIN page_db.page j "
, " ON t.trg_id = j.page_id "
, " AND t.trg_is_redirect = 1 -- limit to redirects"
, ";"
)
, Sql_update_redirect_id = String_.Concat_lines_nl_skip_last
( "REPLACE INTO"
, " page_db.page (page_id, page_namespace, page_title, page_is_redirect, page_touched, page_len, page_random_int, page_text_db_id, page_html_db_id, page_redirect_id, page_score)"
, "SELECT p.page_id"
, ", p.page_namespace"
, ", p.page_title"
, ", p.page_is_redirect"
, ", p.page_touched"
, ", p.page_len"
, ", p.page_random_int"
, ", p.page_text_db_id"
, ", p.page_html_db_id"
, ", r.trg_id"
, ", p.page_score"
, "FROM redirect r"
, " JOIN page_db.page p ON r.src_id = p.page_id"
)
;
}

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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*;
public class Xob_xfer_regy_log_tbl {
public static void Create_table(Db_conn p) {gplx.dbs.engines.sqlite.Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
public static Db_stmt Insert_stmt(Db_conn p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_lnki_id, Fld_xfer_status, Fld_xfer_bin_tid, Fld_xfer_bin_msg);}
public static void Insert(Db_stmt stmt, byte status, int id, byte wkr_tid, String wkr_msg) {
stmt.Clear()
.Val_int(id)
.Val_byte(status)
.Val_byte(wkr_tid)
.Val_str(wkr_msg)
.Exec_insert();
}
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS xfer_regy_log"
, "( lnki_id integer NOT NULL"
, ", xfer_status tinyint NOT NULL" // 0=todo; 1=fail; 2=pass; 3=done
, ", xfer_bin_tid tinyint NOT NULL"
, ", xfer_bin_msg varchar(255) NOT NULL"
, ");"
);
public static final String Tbl_name = "xfer_regy_log"
, Fld_lnki_id = "lnki_id", Fld_xfer_status = "xfer_status", Fld_xfer_bin_tid = "xfer_bin_tid", Fld_xfer_bin_msg = "xfer_bin_msg"
;
}

View File

@@ -0,0 +1,136 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.stores.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
import gplx.xowa.bldrs.*;
public class Xob_xfer_regy_tbl {
public static final String Tbl_name = "xfer_regy"
, Fld_lnki_id = "lnki_id", Fld_lnki_tier_id = "lnki_tier_id", Fld_lnki_page_id = "lnki_page_id", Fld_lnki_ttl = "lnki_ttl", Fld_lnki_ext = "lnki_ext"
, Fld_lnki_time = "lnki_time", Fld_lnki_page = "lnki_page", Fld_lnki_count = "lnki_count"
, Fld_orig_repo = "orig_repo", Fld_orig_page_id = "orig_page_id", Fld_orig_redirect_src = "orig_redirect_src", Fld_orig_media_type = "orig_media_type"
, Fld_orig_w = "orig_w", Fld_orig_h = "orig_h"
, Fld_file_w = "file_w", Fld_file_h = "file_h", Fld_file_is_orig = "file_is_orig"
, Fld_xfer_status = "xfer_status"
;
public static void Create_table(Db_conn p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_conn p) {
p.Exec_sql(Sql_create_data_orig);
p.Exec_sql(Sql_create_data_thumb);
}
public static void Create_index(Gfo_usr_dlg usr_dlg, Db_conn p) {Sqlite_engine_.Idx_create(usr_dlg, p, Xob_db_file.Name__file_make, Idx_lnki_page_id, Idx_lnki_ttl);}
public static DataRdr Select(Db_conn conn, byte repo_id, byte[] ttl, int limit) {
Db_qry qry = Db_qry_.select_().Cols_all_()
.From_(Tbl_name)
.Where_(gplx.core.criterias.Criteria_.And_many(Db_crt_.New_mte(Fld_orig_repo, repo_id), Db_crt_.New_mt(Fld_lnki_ttl, String_.new_u8(ttl)), Db_crt_.New_eq(Fld_xfer_status, 0)))
.Order_asc_many_(Fld_xfer_status, Fld_orig_repo, Fld_lnki_ttl, Fld_file_w)
.Limit_(limit)
;
return conn.Exec_qry_as_old_rdr(qry);
}
public static Db_stmt Select_by_page_id_stmt(Db_conn p) {return p.Stmt_sql(Sql_select_clause);}
public static DataRdr Select_by_page_id(Db_stmt stmt, int page_id, int limit) {return stmt.Val_int(page_id).Val_int(limit).Exec_select();}
private static final String
Sql_select_clause = String_.Concat_lines_nl
( "SELECT *"
, "FROM xfer_regy"
, "WHERE xfer_status = 0"
, "AND lnki_page_id >= ?"
, "ORDER BY lnki_tier_id, lnki_page_id, lnki_id"
, "LIMIT ?"
)
, Sql_select_total_pending = String_.Concat_lines_nl
( "SELECT Count(*) AS CountAll"
, "FROM xfer_regy"
, "WHERE xfer_status = 0"
)
;
public static DataRdr Select_by_tier_page(Db_conn conn, int tier_id, int page_id, int select_interval) {
Db_qry qry = Db_qry_.select_().Cols_all_()
.From_(Tbl_name)
.Where_(gplx.core.criterias.Criteria_.And_many(Db_crt_.New_eq(Fld_xfer_status, 0), Db_crt_.New_eq(Fld_lnki_tier_id, tier_id), Db_crt_.New_mte(Fld_lnki_page_id, page_id)))
.Order_asc_many_(Fld_lnki_tier_id, Fld_lnki_page_id, Fld_lnki_id)
.Limit_(select_interval)
;
return conn.Exec_qry_as_old_rdr(qry);
}
public static int Select_total_pending(Db_conn p) {
DataRdr rdr = p.Exec_sql_as_old_rdr(Sql_select_total_pending);
int rv = 0;
if (rdr.MoveNextPeer())
rv = rdr.ReadInt("CountAll");
rdr.Rls();
return rv;
}
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS xfer_regy"
, "( lnki_id integer NOT NULL PRIMARY KEY"
, ", lnki_tier_id integer NOT NULL"
, ", lnki_page_id integer NOT NULL"
, ", lnki_ttl varchar(255) NOT NULL"
, ", lnki_ext integer NOT NULL"
, ", lnki_time double NOT NULL"
, ", lnki_page integer NOT NULL"
, ", lnki_count integer NOT NULL"
, ", orig_repo tinyint NOT NULL"
, ", orig_page_id integer NOT NULL"
, ", orig_redirect_src varchar(255) NOT NULL"
, ", orig_media_type varchar(64) NOT NULL"
, ", orig_w integer NOT NULL"
, ", orig_h integer NOT NULL"
, ", file_is_orig tinyint NOT NULL"
, ", file_w integer NOT NULL"
, ", file_h integer NOT NULL"
, ", xfer_status integer NOT NULL"
, ");"
);
private static final String Sql_create_data_orig = String_.Concat_lines_nl
( "INSERT INTO xfer_regy "
, "( lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
, ", xfer_status"
, ")"
, "SELECT "
, " Min(lnki_id), Min(lnki_tier_id), Min(lnki_page_id), Min(orig_page_id), orig_repo, lnki_ttl, Max(orig_redirect_src), lnki_ext, orig_media_type" // NOTE: Max(orig_redirect_src) not Min (else would get '')
, ", file_is_orig, orig_w, orig_h, -1, -1, lnki_time, lnki_page, Sum(lnki_count)"
, ", 0"
, "FROM xfer_temp x"
, "WHERE file_is_orig = 1"
, "GROUP BY orig_repo, lnki_ttl, lnki_ext, orig_media_type, file_is_orig, orig_w, orig_h, lnki_time, lnki_page"
);
private static final String Sql_create_data_thumb = String_.Concat_lines_nl
( "INSERT INTO xfer_regy "
, "( lnki_id, lnki_tier_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
, ", xfer_status"
, ")"
, "SELECT "
, " Min(lnki_id), Min(lnki_tier_id), Min(lnki_page_id), Min(orig_page_id), orig_repo, lnki_ttl, Max(orig_redirect_src), lnki_ext, orig_media_type"
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, Sum(lnki_count)"
, ", 0"
, "FROM xfer_temp x"
, "WHERE file_is_orig = 0"
, "GROUP BY orig_repo, lnki_ttl, lnki_ext, orig_media_type, file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page"
);
private static final Db_idx_itm
// Idx_select = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS xfer_regy__select ON xfer_regy (xfer_status, orig_repo, lnki_ttl, file_w);")
Idx_lnki_page_id = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS xfer_regy__lnki_page_id ON xfer_regy (xfer_status, lnki_tier_id, lnki_page_id, lnki_id, orig_repo, file_is_orig, lnki_ttl, lnki_ext, lnki_time, lnki_page, file_w, file_h);")
, Idx_lnki_ttl = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS xfer_regy__lnki_ttl ON xfer_regy (lnki_ttl);") // needed for troubleshooting
;
public static byte Status_todo = 0, Status_pass = 1, Status_fail = 2, Status_ignore_processed = 3;
}

View File

@@ -0,0 +1,88 @@
/*
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.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.files.*;
public class Xob_xfer_temp_tbl {
public static void Create_table(Db_conn p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
public static Db_stmt Insert_stmt(Db_conn p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_lnki_id, Fld_lnki_tier_id, Fld_lnki_page_id, Fld_orig_repo, Fld_orig_page_id, Fld_lnki_ttl, Fld_orig_redirect_src, Fld_lnki_ext, Fld_lnki_type, Fld_orig_media_type, Fld_file_is_orig, Fld_orig_w, Fld_orig_h, Fld_file_w, Fld_file_h, Fld_html_w, Fld_html_h, Fld_lnki_w, Fld_lnki_h, Fld_lnki_upright, Fld_lnki_time, Fld_lnki_page, Fld_lnki_count);}
public static void Insert(Db_stmt stmt, int lnki_id, int lnki_tier_id, int lnki_page_id, byte repo_id
, int page_id, String ttl, String redirect_src, int ext_id, byte lnki_type, String orig_media_type
, boolean file_is_orig, int orig_w, int orig_h, int file_w, int file_h, int html_w, int html_h
, int lnki_w, int lnki_h, double lnki_upright, double thumbtime, int page, int count) {
stmt.Clear()
.Val_int(lnki_id)
.Val_int(lnki_tier_id)
.Val_int(lnki_page_id)
.Val_byte(repo_id)
.Val_int(page_id)
.Val_str(ttl)
.Val_str(redirect_src)
.Val_int(ext_id)
.Val_byte(lnki_type)
.Val_str(orig_media_type)
.Val_bool_as_byte(file_is_orig)
.Val_int(orig_w)
.Val_int(orig_h)
.Val_int(file_w)
.Val_int(file_h)
.Val_int(html_w)
.Val_int(html_h)
.Val_int(lnki_w)
.Val_int(lnki_h)
.Val_double(lnki_upright)
.Val_double(Xof_lnki_time.Db_save_double(thumbtime))
.Val_int(page)
.Val_int(count)
.Exec_insert();
}
public static final String Tbl_name = "xfer_temp"
, Fld_lnki_id = "lnki_id", Fld_lnki_tier_id = "lnki_tier_id", Fld_lnki_page_id = "lnki_page_id", Fld_lnki_ttl = "lnki_ttl", Fld_lnki_ext = "lnki_ext", Fld_lnki_type = "lnki_type"
, Fld_lnki_w = "lnki_w", Fld_lnki_h = "lnki_h", Fld_lnki_upright = "lnki_upright", Fld_lnki_time = "lnki_time", Fld_lnki_page = "lnki_page", Fld_lnki_count = "lnki_count"
, Fld_orig_repo = "orig_repo", Fld_orig_page_id = "orig_page_id", Fld_orig_redirect_src = "orig_redirect_src", Fld_orig_media_type = "orig_media_type"
, Fld_orig_w = "orig_w", Fld_orig_h = "orig_h"
, Fld_file_w = "file_w", Fld_file_h = "file_h", Fld_file_is_orig = "file_is_orig"
, Fld_html_w = "html_w", Fld_html_h = "html_h"
;
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS xfer_temp"
, "( lnki_id integer NOT NULL PRIMARY KEY"
, ", lnki_tier_id integer NOT NULL"
, ", lnki_page_id integer NOT NULL"
, ", lnki_ttl varchar(255) NOT NULL"
, ", lnki_ext integer NOT NULL"
, ", lnki_type integer NOT NULL"
, ", lnki_w integer NOT NULL"
, ", lnki_h integer NOT NULL"
, ", lnki_upright double NOT NULL"
, ", lnki_time double NOT NULL"
, ", lnki_page integer NOT NULL"
, ", lnki_count integer NOT NULL"
, ", orig_repo integer NOT NULL"
, ", orig_page_id integer NOT NULL"
, ", orig_redirect_src varchar(255) NOT NULL"
, ", orig_media_type varchar(64) NOT NULL"
, ", orig_w integer NOT NULL"
, ", orig_h integer NOT NULL"
, ", file_is_orig tinyint NOT NULL"
, ", file_w integer NOT NULL"
, ", file_h integer NOT NULL"
, ", html_w integer NOT NULL"
, ", html_h integer NOT NULL"
, ");"
);
}

View File

@@ -0,0 +1,30 @@
/*
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.addons.bldrs.files.shrinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xoshrink_cmd extends Xob_cmd__base {
public Xoshrink_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
new Xoshrink_mgr().Exec(wiki);
}
@Override public String Cmd_key() {return BLDR_CMD_KEY;} private static final String BLDR_CMD_KEY = "fsdb.shrink";
public static final Xob_cmd Prototype = new Xoshrink_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xoshrink_cmd(bldr, wiki);}
}

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.addons.bldrs.files.shrinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.envs.*;
import gplx.dbs.*;
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
class Xoshrink_mgr {
private Io_url src_url, trg_url;
private Process_adp convert_cmd;
public void Exec(Xowe_wiki wiki) {
// init
src_url = wiki.Fsys_mgr().Root_dir().GenSubFil_nest("tmp", "shrink", "src.file");
trg_url = wiki.Fsys_mgr().Root_dir().GenSubFil_nest("tmp", "shrink", "trg.file");
Io_url convert_exe_url = wiki.Appe().Prog_mgr().App_resize_img().Exe_url();
convert_cmd = Process_adp.New(Gfo_usr_dlg_.Instance, wiki.Appe().Url_cmd_eval(), Process_adp.Run_mode_sync_timeout, 1 * 60, convert_exe_url.Raw(), "-resample ~{w}x~{h}");
// get bin_mgr
Fsm_bin_mgr bin_mgr = wiki.File__mnt_mgr().Mnts__get_main().Bin_mgr();
int len = bin_mgr.Dbs__len();
// loop bin_dbs
for (int i = 0; i < len; i++) {
Shrink(bin_mgr.Dbs__get_at(i));
}
}
private void Shrink(Fsm_bin_fil fil) {
// init
Fsd_bin_tbl tbl = fil.Tbl();
Db_conn conn = fil.Conn();
// prep for update
conn.Txn_bgn("tbl_update");
Db_stmt stmt = conn.Stmt_update(tbl.Tbl_name(), String_.Ary(tbl.fld__owner_id), tbl.fld__data);
// get rdr
Db_rdr rdr = conn.Stmt_select_all(tbl.Tbl_name(), tbl.Flds()).Exec_select__rls_auto();
try {
// loop each row and convert
while (rdr.Move_next()) {
// db.read and fs.save
int id = rdr.Read_int(tbl.fld__owner_id);
byte[] data = rdr.Read_bry(tbl.fld__data);
Io_mgr.Instance.SaveFilBry(src_url, data);
// convert
convert_cmd.Run();// get w and h
// fs.load and db.save
data = Io_mgr.Instance.LoadFilBry(trg_url);
tbl.Update(stmt, id, data);
}
} finally {
conn.Txn_end();
rdr.Rls();
stmt.Rls();
}
}
}

View File

@@ -0,0 +1,57 @@
/*
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.addons.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.fsdb.meta.*;
public class Xob_bin_db_itm {
public Xob_bin_db_itm(int id, Io_url db_url, int ns_id, int pt_id) {this.id = id; this.db_url = db_url; this.ns_id = ns_id; this.pt_id = pt_id;}
public int Id() {return id;} private int id;
public int Ns_id() {return ns_id;} private final int ns_id;
public int Pt_id() {return pt_id;} private int pt_id;
public long Db_len() {return db_len;} public void Db_len_(long v) {this.db_len = v;} private long db_len;
public Io_url Db_url() {return db_url;} public void Db_url_(Io_url v) {db_url = v;} private Io_url db_url;
public void Set(int id, int pt_id, Io_url db_url) {
this.id = id; this.pt_id = pt_id; this.db_url = db_url;
}
public static String Gen_name_v1(int pt_id) {
return String_.Format("fsdb.bin.{0}.sqlite3", Int_.To_str_pad_bgn_zero(pt_id, 4));
}
public static String Gen_name_v2(String domain_str, int ns_id, int pt_id) {
String ns_id_str = Int_.To_str_pad_bgn_zero(ns_id, 3);
String pt_id_str = Int_.To_str_pad_bgn_zero(pt_id, 3);
return String_.Format("{0}-file-ns.{1}-db.{2}.xowa", domain_str, ns_id_str, pt_id_str);
}
public static Xob_bin_db_itm new_v1(Fsm_bin_fil fil) {
byte[] name = Bry_.new_u8(fil.Url_rel()); // EX: "fsdb.bin.0000.sqlite3"
int ns_id = 0; // assume v1 dbs are all in main ns
int pt_id = Bry_.To_int_or(name, 9 , 13, Int_.Min_value); if (pt_id == Int_.Min_value) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Raw());
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
}
public static Xob_bin_db_itm new_v2(Fsm_bin_fil fil) {
byte[] ns_bgn_tkn = Bry_.new_a7("file-ns."), ns_end_tkn = Bry_.new_a7("-db."), pt_end_tkn = Bry_.new_a7(".xowa");
int ns_bgn_tkn_len = ns_bgn_tkn.length, ns_end_tkn_len = ns_end_tkn.length;
byte[] name = Bry_.new_u8(fil.Url_rel()); // EX: en.wikipedia.org-file-ns.000-db.001.xowa
int ns_bgn = Bry_find_.Find_fwd(name, ns_bgn_tkn, 0); if (ns_bgn == Bry_find_.Not_found) throw Err_.new_wo_type("bin_db_itm.parse: invalid ns_bgn", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Raw());
ns_bgn += ns_bgn_tkn_len;
int ns_end = Bry_find_.Find_fwd(name, ns_end_tkn, ns_bgn); if (ns_end == Bry_find_.Not_found) throw Err_.new_wo_type("bin_db_itm.parse: invalid ns_end", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Raw());
int pt_bgn = ns_end + ns_end_tkn_len;
int pt_end = Bry_find_.Find_fwd(name, pt_end_tkn, pt_bgn); if (pt_end == Bry_find_.Not_found) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_end", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Raw());
int ns_id = Bry_.To_int_or(name, ns_bgn, ns_end, Int_.Min_value); if (ns_id == Int_.Min_value) throw Err_.new_wo_type("bin_db_itm.parse: invalid ns_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Raw());
int pt_id = Bry_.To_int_or(name, pt_bgn, pt_end, Int_.Min_value); if (pt_id == Int_.Min_value) throw Err_.new_wo_type("bin_db_itm.parse: invalid pt_id", "name", fil.Url_rel(), "conn", fil.Conn().Conn_info().Raw());
return new Xob_bin_db_itm(fil.Id(), fil.Url(), ns_id, pt_id);
}
}

View File

@@ -0,0 +1,72 @@
/*
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.addons.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.primitives.*; import gplx.core.ios.*;
import gplx.fsdb.meta.*;
public class Xob_bin_db_mgr {
private final int[] ns_ids; private final int ns_ids_len;
private final Ordered_hash nth_hash = Ordered_hash_.New(); private final Int_obj_ref tier_key = Int_obj_ref.New_neg1();
public Xob_bin_db_mgr(int[] ns_ids) {
this.ns_ids = ns_ids; this.ns_ids_len = ns_ids.length;
}
public boolean Schema_is_1() {return schema_is_1;} private boolean schema_is_1;
public void Init_by_mnt_mgr(Fsm_mnt_mgr trg_mnt_mgr) {
Fsm_mnt_itm trg_mnt_itm = trg_mnt_mgr.Mnts__get_main();
this.schema_is_1 = trg_mnt_itm.Db_mgr().File__schema_is_1();
Fsm_bin_mgr bin_db_mgr = trg_mnt_itm.Bin_mgr();
int len = ns_ids_len;
for (int i = 0; i < len; ++i) { // iterate ns_ids and add default nth
int ns_id = ns_ids[i];
Xob_bin_db_itm nth = new Xob_bin_db_itm(-1, null, ns_id, 0);
nth_hash.Add(Int_obj_ref.New(ns_ids[i]), nth);
}
len = bin_db_mgr.Dbs__len();
for (int i = 0; i < len; ++i) { // iterate bin_dbs to find max pt_id for each ns
Fsm_bin_fil fil = bin_db_mgr.Dbs__get_at(i);
Xob_bin_db_itm itm = schema_is_1 ? Xob_bin_db_itm.new_v1(fil) : Xob_bin_db_itm.new_v2(fil);
int ns_id = itm.Ns_id();
Xob_bin_db_itm nth = (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(ns_id));
if ( nth != null // occurs when existing fsdb_dbb has "file-ns.014-db.001", but 14 no longer specified in fsdb_make; DATE:2016-09-23
&& itm.Pt_id() > nth.Pt_id()) // update max pt_id
nth.Set(itm.Id(), itm.Pt_id(), itm.Db_url()); // note that ns_id is same
}
len = nth_hash.Count();
for (int i = 0; i < len; ++i) { // iterated tiers to calculate max_size
Xob_bin_db_itm nth = (Xob_bin_db_itm)nth_hash.Get_at(i);
if (nth.Id() == -1) continue; // ignore default nth
IoItmFil nth_itm = Io_mgr.Instance.QueryFil(nth.Db_url());
nth.Db_len_(nth_itm.Size());
}
}
public boolean Tier_id_is_last(int tier_id) {return tier_id >= ns_ids_len;} // assumes tier_id is 0 based; EX: 0,1,2 for
public int Get_ns_id(int tier_id) {return ns_ids[tier_id];}
public int Increment_pt_id(Xob_bin_db_itm itm) {
itm.Set(-1, itm.Pt_id() + 1, null);
itm.Db_len_(0);
return itm.Pt_id();
}
public String Gen_name(String domain_str, int ns_id, int pt_id) {
return schema_is_1 ? Xob_bin_db_itm.Gen_name_v1(pt_id) : Xob_bin_db_itm.Gen_name_v2(domain_str, ns_id, pt_id);
}
public Xob_bin_db_itm Get_nth_by_tier(int tier_id) {
if (schema_is_1) return (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(0)); // v1 is always in ns_0
if (tier_id >= ns_ids_len) throw Err_.new_wo_type("tier out of range", "tier_id", tier_id, "len", ns_ids_len);
int ns_id = ns_ids[tier_id];
return (Xob_bin_db_itm)nth_hash.Get_by(tier_key.Val_(ns_id));
}
}

View File

@@ -0,0 +1,141 @@
/*
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.addons.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.stores.*;
import gplx.dbs.*; import gplx.xowa.files.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xob_xfer_temp_itm {
public int Lnki_id() {return lnki_id;} private int lnki_id;
public int Lnki_tier_id() {return lnki_tier_id;} private int lnki_tier_id;
public byte Orig_repo() {return orig_repo;} private byte orig_repo;
public int Lnki_ext() {return lnki_ext;} private int lnki_ext;
public byte[] Orig_file_ttl() {return orig_file_ttl;} private byte[] orig_file_ttl;
public String Orig_media_type() {return orig_media_type;} private String orig_media_type;
public String Orig_minor_mime() {return orig_minor_mime;} private String orig_minor_mime;
public byte Orig_media_type_tid() {return orig_media_type_tid;} private byte orig_media_type_tid;
public int Orig_page_id() {return orig_page_id;} private int orig_page_id;
public String Join_ttl() {return join_ttl;} private String join_ttl;
public String Redirect_src() {return redirect_src;} private String redirect_src;
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
public byte Lnki_src_tid() {return lnki_src_tid;} private byte lnki_src_tid;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public int Lnki_count() {return lnki_count;} private int lnki_count;
public int Lnki_page_id() {return lnki_page_id;} private int lnki_page_id;
public int Orig_w() {return orig_w;} private int orig_w;
public int Orig_h() {return orig_h;} private int orig_h;
public int Orig_ext_id() {return orig_ext_id;} private int orig_ext_id;
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_thumbtime() {return lnki_thumbtime;} private double lnki_thumbtime;
public int Lnki_page() {return lnki_page;} private int lnki_page;
public void Clear() {
orig_file_ttl = null;
lnki_ext = lnki_type = lnki_src_tid
= orig_repo = orig_media_type_tid = Byte_.Max_value_127;
chk_tid = Chk_tid_none;
lnki_id = lnki_tier_id = lnki_w = lnki_h = lnki_count = lnki_page_id
= orig_w = orig_h = orig_page_id = Int_.Neg1;
join_ttl = redirect_src = orig_media_type = null;
lnki_upright = Xop_lnki_tkn.Upright_null;
lnki_thumbtime = Xof_lnki_time.Null;
lnki_page = Xof_lnki_page.Null;
}
public void Load(DataRdr rdr) {
lnki_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_id);
lnki_tier_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_tier_id);
lnki_page_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_page_id);
lnki_ext = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_ext);
lnki_type = rdr.ReadByte(Xob_lnki_regy_tbl.Fld_lnki_type);
lnki_src_tid = rdr.ReadByte(Xob_lnki_regy_tbl.Fld_lnki_src_tid);
lnki_w = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_w);
lnki_h = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_h);
lnki_upright = rdr.ReadDouble(Xob_lnki_regy_tbl.Fld_lnki_upright);
lnki_thumbtime = Xof_lnki_time.Db_load_double(rdr, Xob_lnki_regy_tbl.Fld_lnki_time);
lnki_page = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_page);
lnki_count = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_count);
orig_file_ttl = rdr.ReadBryByStr(Xob_lnki_regy_tbl.Fld_lnki_ttl);
orig_repo = rdr.ReadByte(Xob_orig_regy_tbl.Fld_orig_repo);
orig_page_id = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_page_id, -1);
join_ttl = rdr.ReadStr(Xob_orig_regy_tbl.Fld_orig_file_ttl);
redirect_src = rdr.ReadStr(Xob_orig_regy_tbl.Fld_lnki_ttl);
orig_w = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_w, -1);
orig_h = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_h, -1);
orig_media_type = rdr.ReadStrOr(Xob_orig_regy_tbl.Fld_orig_media_type, ""); // convert nulls to ""
orig_minor_mime = rdr.ReadStrOr(Xob_orig_regy_tbl.Fld_orig_minor_mime, ""); // convert nulls to ""
orig_ext_id = rdr.ReadInt(Xob_orig_regy_tbl.Fld_orig_file_ext);
}
public static final byte
Chk_tid_none = 0
, Chk_tid_orig_page_id_is_null = 1
, Chk_tid_orig_media_type_is_audio = 2
, Chk_tid_ns_is_media = 3
, Chk_tid_orig_w_is_0 = 4
;
public byte Chk_tid() {return chk_tid;} private byte chk_tid;
public boolean Chk(Xof_img_size img_size) {
if (String_.Eq(join_ttl, redirect_src)) // join_ttl is same as redirect_src; not a redirect; EX:(direct) join="A.png";redirect_src="A.png"; (redirect) join="A.png";redirect_src="B.png" (i.e.: B redirects to A)
redirect_src = "";
// else { // redirect; make sure extension matches; EX: A.png redirects to B.png; lnki_ext will be .png (the lnki's ext); should be .png (the actual file's ext)
// Xof_ext join_ext = Xof_ext_.new_by_ttl_(Bry_.new_u8(join_ttl));
// lnki_ext = join_ext.Id();
// }
lnki_ext = orig_ext_id;
orig_media_type_tid = Xof_media_type.Xto_byte(orig_media_type);
if ( Xof_lnki_time.Null_n(lnki_thumbtime) // thumbtime defined
&& orig_media_type_tid != Xof_media_type.Tid_video // video can have thumbtime
)
lnki_thumbtime = Xof_lnki_time.Null; // set thumbtime to NULL; actually occurs for one file: [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
if ( Xof_lnki_page.Null_n(lnki_page)
&& !Xof_ext_.Id_supports_page(orig_ext_id)) // djvu / pdf can have page parameters, which are currently being stored in thumbtime; DATE:2014-01-18
lnki_page = Xof_lnki_page.Null;
if (orig_page_id == -1) { // no orig found (i.e.: not in local's / remote's image.sql);
chk_tid = Chk_tid_orig_page_id_is_null;
return false;
}
if (orig_media_type_tid == Xof_media_type.Tid_audio) { // ignore: audio will never have thumbs
chk_tid = Chk_tid_orig_media_type_is_audio;
return false;
}
if (orig_w <= 0) { // ignore files that have an orig_w of 0; note that ogg files that are sometimes flagged as VIDEO; EX:2009_10_08_Marc_Randazza_interview.ogg; DATE:2014-08-20
chk_tid = Chk_tid_orig_w_is_0;
return false;
}
if (lnki_ext == Xof_ext_.Id_mid) { // NOTE: .mid does not have orig_media_type of "AUDIO"
chk_tid = Chk_tid_orig_media_type_is_audio;
return false;
}
if (lnki_src_tid == Xop_file_logger_.Tid__media) {
chk_tid = Chk_tid_ns_is_media;
return false;
}
int upright_patch = Xof_patch_upright_tid_.Tid_all; // all future blds will have upright_patch
img_size.Html_size_calc(Xof_exec_tid.Tid_wiki_page, lnki_w, lnki_h, lnki_type, upright_patch, lnki_upright, lnki_ext, orig_w, orig_h, Xof_img_size.Thumb_width_img);
return true;
}
public void Insert(Db_stmt stmt, Xof_img_size img_size) {
boolean file_is_orig = img_size.File_is_orig();
int file_w = img_size.File_w();
int file_h = img_size.File_h();
if (file_is_orig)
file_w = file_h = -1;
Xob_xfer_temp_tbl.Insert(stmt, lnki_id, lnki_tier_id, lnki_page_id, orig_repo, orig_page_id, join_ttl, redirect_src, lnki_ext, lnki_type, orig_media_type
, file_is_orig, orig_w, orig_h, file_w, file_h, img_size.Html_w(), img_size.Html_h(), lnki_w, lnki_h
, lnki_upright, lnki_thumbtime, lnki_page, lnki_count);
}
}

View File

@@ -0,0 +1,192 @@
/*
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.addons.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import org.junit.*;
import gplx.core.gfo_ndes.*;
import gplx.core.stores.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xob_xfer_temp_itm_tst {
private Xob_xfer_temp_itm_fxt fxt = new Xob_xfer_temp_itm_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Pass() {fxt.Test_pass().Test_itm_chk_fail_id_none();}
@Test public void Missing_orig() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_page_id_is_null , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_page_id, null));}
@Test public void File_is_audio() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type, Xof_media_type.Name_audio));}
@Test public void File_is_mid() {
fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext, Xof_ext_.Id_mid));
}
@Test public void Redirect_src_is_empty() { // orig_cmd sets all direct files to have "orig_join" == "lnki_ttl"
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "A.png")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
);
fxt.Test_lnki_redirect_src(""); // confirm redirect_src set to ""
}
@Test public void Redirect_src_has_val() { // orig_cmd sets all redirect files to have "orig_join" = redirect and "lnki_ttl" as orig; EX: A.png redirects to B.png; orig_join will be B.png (the actual image) and redirect_src will be A.png (the original lnki)
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.png")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
);
fxt.Test_lnki_redirect_src("A.png"); // confirm redirect_src set to ""
}
@Test public void Redirect_should_take_trg_ext() {// if "A.png" redirects to "B.jpg", ext_id should be ".jpg" (the actual file) not ".png (lnki_ext_id)
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.jpg")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg) // .png b/c B.jpg
);
fxt.Test_lnki_ext_id(Xof_ext_.Id_jpg); // confirm ext changed to .jpg
}
@Test public void Thumbtime_check() {// PURPOSE: one image actually had a thumbtime defined; EX: General_Dynamics_F-16_Fighting_Falcon; [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
);
fxt.Test_lnki_thumbtime(Xof_lnki_time.Null);
fxt.Reset().Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
);
fxt.Test_lnki_thumbtime(3);
}
@Test public void Page_check() {
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
);
fxt.Test_lnki_page(Xof_lnki_page.Null);
fxt.Reset().Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_pdf)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
);
fxt.Test_lnki_page(3);
fxt.Reset().Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_djvu)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
);
fxt.Test_lnki_page(3);
}
@Test public void Media_should_be_ignored() {// ignore [[Media:]] for xfer_thumb (needed for xfer_orig)
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_src_tid , Xop_file_logger_.Tid__media)
);
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_ns_is_media);
}
@Test public void Orig_width_is_0() {// PURPOSE: ignore files with an orig width of 0; note that ogg files that are sometimes flagged as VIDEO; EX:2009_10_08_Marc_Randazza_interview.ogg; DATE:2014-08-20
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.ogg")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video) // VIDEO
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_w , 0) // no width defined in image table
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_h , 0)
);
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_orig_w_is_0);
}
}
class Xob_xfer_temp_itm_fxt {
private Xob_xfer_temp_itm itm = new Xob_xfer_temp_itm();
private Xof_img_size img_size = new Xof_img_size();
private DataRdr_mem rdr;
private GfoNde nde;
public static String[] Flds = new String[]
{ Xob_lnki_regy_tbl.Fld_lnki_ext
, Xob_lnki_regy_tbl.Fld_lnki_id
, Xob_lnki_regy_tbl.Fld_lnki_tier_id
, Xob_orig_regy_tbl.Fld_orig_repo
, Xob_orig_regy_tbl.Fld_orig_file_ttl
, Xob_orig_regy_tbl.Fld_orig_file_ext
, Xob_orig_regy_tbl.Fld_lnki_ttl
, Xob_lnki_regy_tbl.Fld_lnki_type
, Xob_lnki_regy_tbl.Fld_lnki_src_tid
, Xob_lnki_regy_tbl.Fld_lnki_w
, Xob_lnki_regy_tbl.Fld_lnki_h
, Xob_lnki_regy_tbl.Fld_lnki_count
, Xob_lnki_regy_tbl.Fld_lnki_page_id
, Xob_orig_regy_tbl.Fld_orig_w
, Xob_orig_regy_tbl.Fld_orig_h
, Xob_orig_regy_tbl.Fld_orig_page_id
, Xob_lnki_regy_tbl.Fld_lnki_upright
, Xob_lnki_regy_tbl.Fld_lnki_time
, Xob_lnki_regy_tbl.Fld_lnki_page
, Xob_orig_regy_tbl.Fld_orig_media_type
, Xob_orig_regy_tbl.Fld_orig_minor_mime
}
;
public Xob_xfer_temp_itm_fxt Reset() {
itm.Clear();
return this;
}
public Xob_xfer_temp_itm_fxt Init_rdr_image() {
GfoFldList flds = GfoFldList_.str_(Flds);
nde = GfoNde_.vals_(flds, Object_.Ary
( Xof_ext_.Id_png, 1, 1, Xof_repo_tid_.Tid__remote
, "A.png", Xof_ext_.Id_png, "A.png", Xop_lnki_type.Id_thumb, Xop_file_logger_.Tid__file
, 220, 200, 1, 2, 440, 400, 3
, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null
, Xof_media_type.Name_bitmap, "png"
));
GfoNdeList subs = GfoNdeList_.new_();
subs.Add(nde);
GfoNde root = GfoNde_.root_(nde);
rdr = DataRdr_mem.new_(root, flds, subs);
rdr.MoveNextPeer();
return this;
}
public Xob_xfer_temp_itm_fxt Init_rdr(String key, Object val) {
nde.Write(key, val);
return this;
}
public Xob_xfer_temp_itm_fxt Test_pass() {return Test_bgn();}
public Xob_xfer_temp_itm_fxt Test_fail(byte fail_tid, Keyval... kvs) {
Test_bgn(kvs);
this.Test_itm_chk_fail_id(fail_tid);
return this;
}
public Xob_xfer_temp_itm_fxt Test_bgn(Keyval... kvs) {
Init_rdr_image();
int len = kvs.length;
for (int i = 0; i < len; i++) {
Keyval kv = kvs[i];
Init_rdr(kv.Key(), kv.Val());
}
this.Exec_load();
this.Exec_chk();
return this;
}
public Xob_xfer_temp_itm_fxt Test_atr(String key, Object val) {
Tfds.Eq(rdr.Read(key), val);
return this;
}
public Xob_xfer_temp_itm_fxt Exec_load() {
itm.Load(rdr);
return this;
}
public Xob_xfer_temp_itm_fxt Exec_chk() {
itm.Chk(img_size);
return this;
}
public Xob_xfer_temp_itm_fxt Test_lnki_ext_id(int expd) {Tfds.Eq(expd, itm.Lnki_ext()); return this;}
public Xob_xfer_temp_itm_fxt Test_lnki_thumbtime(double expd) {Tfds.Eq(expd, itm.Lnki_thumbtime()); return this;}
public Xob_xfer_temp_itm_fxt Test_lnki_page(int expd) {Tfds.Eq(expd, itm.Lnki_page()); return this;}
public Xob_xfer_temp_itm_fxt Test_lnki_redirect_src(String expd) {Tfds.Eq(expd, itm.Redirect_src()); return this;}
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id_none() {return Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_none);}
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id(byte expd) {
Tfds.Eq(expd, itm.Chk_tid());
return this;
}
}

View File

@@ -0,0 +1,38 @@
/*
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.addons.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
public class Xobu_poll_mgr implements Gfo_invk {
public Xobu_poll_mgr(Xoae_app app) {this.app = app;} private Xoae_app app;
public int Poll_interval() {return poll_interval;} private int poll_interval = 1000;
private Io_url poll_file;
public void Poll() {
if (poll_file == null) poll_file = app.Fsys_mgr().Root_dir().GenSubFil("bldr_poll.gfs");
if (!Io_mgr.Instance.ExistsFil(poll_file)) return; // file doesn't exist
String poll_text = Io_mgr.Instance.LoadFilStr(poll_file);
Io_mgr.Instance.DeleteFil(poll_file);
app.Usr_dlg().Note_many("", "", "poll file found: ~{0}", poll_file.Raw());
app.Gfs_mgr().Run_str(poll_text);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_poll_interval_)) poll_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_poll_file_)) poll_file = m.ReadIoUrl("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_poll_interval_ = "poll_interval_", Invk_poll_file_ = "poll_file_";
}