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

v2.10.3.1

This commit is contained in:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

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.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.bldrs.css.*;
public class Xob_css_status {
public int Update_tid() {return update_tid;} private int update_tid;
public boolean Fs_exists() {return fs_exists;} private boolean fs_exists;
public Io_url Fs_dir() {return fs_dir;} private Io_url fs_dir;
public boolean Db_exists() {return db_exists;} private boolean db_exists;
public void Fs_exists_(boolean fs_exists, Io_url fs_dir) {
this.fs_exists = fs_exists;
this.fs_dir = fs_dir;
}
public void Db_exists_(boolean db_exists) {
this.db_exists = db_exists;
}
public void Update_tid_none_y_() {this.update_tid = Update_tid_none;}
public void Update_tid_wmf_y_() {this.update_tid = Update_tid_wmf;}
public void Update_tid_db_y_() {this.update_tid = Update_tid_db;}
public static final int Update_tid_none = 0, Update_tid_db = 1, Update_tid_wmf = 2;
public static Xob_css_status Chk(Xow_wiki wiki, Io_url css_dir, String key) {
Xob_css_status rv = new Xob_css_status();
Chk_fs(rv, wiki);
Chk_db(rv, wiki, css_dir);
return rv;
}
private static void Chk_fs(Xob_css_status rv, Xow_wiki wiki) {
Io_url css_dir = wiki.App().Fsys_mgr().Wiki_css_dir(wiki.Domain_str()); // EX: /xowa/user/anonymous/wiki/en.wikipedia.org/html/
Io_url css_fil_wiki = css_dir.GenSubFil(Xoa_css_extractor.Css_wiki_name); // EX: /xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css
boolean exists = Io_mgr.Instance.ExistsFil(css_fil_wiki);
rv.Fs_exists_(exists, css_dir);
}
private static void Chk_db(Xob_css_status rv, Xow_wiki wiki, Io_url css_dir) {
Xowd_db_mgr core_db_mgr = wiki.Data__core_mgr();
if ( core_db_mgr == null
|| core_db_mgr.Props() != null
|| !core_db_mgr.Props().Schema_is_1()
|| core_db_mgr.Tbl__cfg().Select_yn_or(Xow_cfg_consts.Grp__wiki_schema, Xowd_db_file_schema_props.Key__tbl_css_core, Bool_.N)
) {
rv.Db_exists_(false);
if (rv.Fs_exists())
rv.Update_tid_none_y_(); // v1_db and fs_exists; don't do update; legacy behavior
else
rv.Update_tid_wmf_y_(); // v1_db and fs_missing; update from wmf; legacy behavior
}
if (rv.Fs_exists()) {
DateAdp fs_timestamp = Timestamp_load(css_dir);
DateAdp db_timestamp = DateAdp_.Now();
if (db_timestamp.compareTo(fs_timestamp) == CompareAble_.More)
rv.Update_tid_db_y_(); // v2_db and later_version; update from db
else
rv.Update_tid_none_y_(); // v2_db and current version; noop
}
}
public static void Timestamp_save(Io_url css_dir, DateAdp time) {
Io_mgr.Instance.SaveFilStr(css_dir.GenSubFil(Timestamp_filename), time.XtoStr_fmt_yyyyMMdd_HHmmss());
}
public static DateAdp Timestamp_load(Io_url css_dir) {
String rv = Io_mgr.Instance.LoadFilStr(css_dir.GenSubFil(Timestamp_filename));
return rv == null ? DateAdp_.MinValue : DateAdp_.parse_iso8561_or(rv, DateAdp_.MinValue);
}
private static final String Timestamp_filename = "xowa.css.timestamp.txt";
}

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.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
public class Xow_css_mgr {
private final Xow_wiki wiki;
private boolean db_css_exists;
private Xowd_css_core_tbl css_core_tbl; private Xowd_css_file_tbl css_file_tbl;
public Xow_css_mgr(Xow_wiki wiki) {this.wiki = wiki;}
public void Init_by_wiki() {
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
Xowd_db_mgr core_db_mgr = wiki.Data__core_mgr();
if (core_db_mgr == null) {
usr_dlg.Log_many("", "", "db.css.exists; css_missing b/c tdb; wiki=~{0}", wiki.Domain_str());
return;
}
if ( core_db_mgr.Props() == null
|| core_db_mgr.Props().Schema_is_1()) {
usr_dlg.Log_many("", "", "db.css.exists; css_missing b/c v1; wiki=~{0}", wiki.Domain_str());
return;
}
Xowd_db_file core_db = core_db_mgr.Db__core();
this.css_core_tbl = core_db.Tbl__css_core();
this.css_file_tbl = core_db.Tbl__css_file();
if ( core_db == null
|| !core_db.Conn().Meta_tbl_exists(css_core_tbl.Tbl_name())
) {
usr_dlg.Log_many("", "", "db.css.exists; css_missing b/c v2 w/o css; wiki=~{0}", wiki.Domain_str());
return;
}
this.db_css_exists = true;
}
public void Db_del_all() {
if (!db_css_exists) {Xoa_app_.Usr_dlg().Log_many("", "", "db.css.del_all; del_all skipped; wiki=~{0}", wiki.Domain_str()); return;}
css_core_tbl.Delete_all();
css_file_tbl.Delete_all();
}
}

View File

@@ -0,0 +1,60 @@
/*
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.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.dbs.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.bldrs.css.*;
public class Xowd_css_core_mgr {
public static void Set(Xowd_css_core_tbl core_tbl, Xowd_css_file_tbl file_tbl, Io_url css_dir, String key) {
Db_conn conn = core_tbl.Conn();
Io_url[] file_list = Io_mgr.Instance.QueryDir_args(css_dir).Recur_().ExecAsUrlAry();
try {
conn.Txn_bgn("schema__css_core__set");
int css_id = core_tbl.Select_id_by_key(key);
DateAdp updated_on = DateAdp_.Now().XtoUtc();
if (css_id == -1)
css_id = core_tbl.Insert(key, updated_on);
else {
core_tbl.Update(css_id, key, updated_on);
file_tbl.Delete(css_id);
}
for (Io_url file : file_list) {
String path = Op_sys.Fsys_path_to_lnx(file.GenRelUrl_orEmpty(css_dir));
byte[] data = Io_mgr.Instance.LoadFilBry(file);
file_tbl.Insert(css_id, path, data);
}
conn.Txn_end();
}
catch (Exception e) {conn.Txn_cxl(); throw e;}
}
public static boolean Get(Xowd_css_core_tbl core_tbl, Xowd_css_file_tbl file_tbl, Io_url css_dir, String key) {
int css_id = core_tbl.Select_id_by_key(key); if (css_id == Xowd_css_core_tbl.Id_null) return false; // unknown key; return false (not found)
Xowd_css_file_itm[] file_list = file_tbl.Select_by_owner(css_id);
// Io_mgr.Instance.DeleteDirDeep(css_dir); // NOTE: do not delete existing files; just overwrite;
int len = file_list.length;
if (len == 0) return false; // no css files in db
for (int i = 0; i < len; ++i) {
Xowd_css_file_itm file = file_list[i];
Io_url file_url = Io_url_.new_fil_(css_dir.Gen_sub_path_for_os(file.Path()));
if (file.Data() == null) continue; // NOTE: sqlite will return 0 length fields as NULL; if no data, just ignore, else error below
Io_mgr.Instance.SaveFilBry(file_url, file.Data());
}
return true;
}
public static final String Key_default = "xowa.default", Key_mobile = "xowa.mobile";
}

View File

@@ -0,0 +1,120 @@
/*
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.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*;
public class Xowd_css_core_mgr_tst {
@Before public void init() {fxt.Clear();} private Xowd_css_core_mgr_fxt fxt = new Xowd_css_core_mgr_fxt();
@Test public void Basic() {
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
( fxt.Make_skin_itm(1, "desktop", "20010101_050200")
);
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a.css", "a_data")
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
);
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
fxt.Test_skin_tbl(skin_ary);
fxt.Test_file_tbl(file_ary);
Io_url trg_dir = Io_url_.mem_dir_("mem/trg/");
fxt.Exec_get(trg_dir, "desktop");
fxt.Test_fs(trg_dir, file_ary);
}
@Test public void Update() { // update css files; keep same skin_id; insert new files
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
( fxt.Make_skin_itm(1, "desktop", "20010101_050500")
);
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a.css", "a_data")
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
);
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a1.css", "a1_data")
, fxt.Make_file_itm(1, "b/b1.png", "b/b1_data")
);
Io_mgr.Instance.DeleteDirDeep(src_dir);
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
fxt.Test_skin_tbl(skin_ary);
fxt.Test_file_tbl(file_ary);
}
}
class Xowd_css_core_mgr_fxt {
private final Bry_bfr bfr = Bry_bfr.reset_(32);
private Xowd_css_core_tbl core_tbl; private Xowd_css_file_tbl file_tbl;
public void Clear() {
Tfds.Now_enabled_y_();
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
Db_conn conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/css.sqlite3"));
this.core_tbl = new Xowd_css_core_tbl(conn);
this.file_tbl = new Xowd_css_file_tbl(conn);
core_tbl.Create_tbl();
file_tbl.Create_tbl();
}
public Xowd_css_core_itm Make_skin_itm(int id, String key, String updated_on) {return new Xowd_css_core_itm(id, key, DateAdp_.parse_gplx(updated_on));}
public Xowd_css_file_itm Make_file_itm(int skin_id, String path, String data) {return new Xowd_css_file_itm(skin_id, path, Bry_.new_u8(data));}
public Xowd_css_file_itm[] Make_file_ary(Xowd_css_file_itm... ary) {return ary;}
public Xowd_css_core_itm[] Make_skin_ary(Xowd_css_core_itm... ary) {return ary;}
public void Init_fs(Io_url css_dir, Xowd_css_file_itm[] file_ary) {
for (Xowd_css_file_itm itm : file_ary)
Io_mgr.Instance.SaveFilBry(css_dir.GenSubFil(itm.Path()), itm.Data());
}
public void Exec_set(Io_url css_dir, String key) {Xowd_css_core_mgr.Set(core_tbl, file_tbl, css_dir, key);}
public void Exec_get(Io_url css_dir, String key) {Xowd_css_core_mgr.Get(core_tbl, file_tbl, css_dir, key);}
public void Test_skin_tbl(Xowd_css_core_itm[] expd) {
Xowd_css_core_itm[] actl = core_tbl.Select_all();
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
}
public void Test_file_tbl(Xowd_css_file_itm[] expd) {
Xowd_css_file_itm[] actl = file_tbl.Select_all();
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
}
public void Test_fs(Io_url css_dir, Xowd_css_file_itm[] expd) {
Io_url[] actl = Io_mgr.Instance.QueryDir_args(css_dir).Recur_().ExecAsUrlAry();
int len = expd.length;
Tfds.Eq(len, actl.length);
for (int i = 0; i < len; ++i) {
Xowd_css_file_itm expd_itm = expd[i];
Tfds.Eq_bry(expd_itm.Data(), Io_mgr.Instance.LoadFilBry(actl[i]));
}
}
private String To_str(Xowd_css_file_itm[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xowd_css_file_itm itm = ary[i];
bfr.Add_int_variable(itm.Css_id()).Add_byte_pipe().Add_str_u8(itm.Path()).Add_byte_pipe().Add(itm.Data()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
private String To_str(Xowd_css_core_itm[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xowd_css_core_itm itm = ary[i];
bfr.Add_int_variable(itm.Id()).Add_byte_pipe().Add_str_u8(itm.Key()).Add_byte_pipe().Add_str_u8(itm.Updated_on().XtoStr_fmt_yyyyMMdd_HHmmss()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
}