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

'v3.7.4.1'

This commit is contained in:
gnosygnu
2016-07-25 21:59:51 -04:00
parent 7a851a41a5
commit 8e91ac0bc4
175 changed files with 2079 additions and 933 deletions

View File

@@ -0,0 +1,27 @@
/*
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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
public class Xocfg_meta_itm {
public Xocfg_meta_itm(String key, String type, String dflt, String version) {
this.key = key; this.type = type; this.dflt = dflt; this.version = version;
}
public String Key() {return key;} private final String key;
public String Type() {return type;} private String type;
public String Dflt() {return dflt;} private String dflt;
public String Version() {return version;} private String version;
}

View File

@@ -0,0 +1,40 @@
/*
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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*;
public class Xocfg_meta_tbl implements Rls_able {
private final String tbl_name; public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_key, fld_type, fld_dflt, fld_version;
private final Db_conn conn;
public Xocfg_meta_tbl(Db_conn conn) {
this.conn = conn;
tbl_name = Tbl_name;
fld_key = flds.Add_str_pkey ("cfg_key" , 1024); // EX: "xowa.net.web_enabled"
fld_type = flds.Add_str ("cfg_type" , 255); // EX: "yn"
fld_dflt = flds.Add_str ("cfg_dflt" , 1024); // EX: "n"
fld_version = flds.Add_str ("cfg_version" , 16); // EX: "v1.1.1.1"
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Insert(String key, String type, String dflt, String version) {
Db_stmt stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear().Val_str(fld_key, key).Val_str(fld_type, type).Val_str(fld_dflt, dflt).Val_str(fld_version, version)
.Exec_insert();
}
public void Rls() {}
public static final String Tbl_name = "cfg_meta";
}

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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
public class Xou_cfg_itm {
public Xou_cfg_itm(int usr, String ctx, String key, String val) {
this.usr = usr; this.ctx = ctx; this.key = key; this.val = val;
this.uid = Xou_cfg_mgr.Bld_uid(usr, ctx, key);
}
public String Uid() {return uid;} private final String uid;
public int Usr() {return usr;} private final int usr;
public String Ctx() {return ctx;} private final String ctx;
public String Key() {return key;} private final String key;
public String Val() {return val;} private String val;
public void Val_(String v) {this.val = v;}
}

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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*;
public class Xou_cfg_mgr {
private Xou_cfg_tbl tbl;
private final Hash_adp hash = Hash_adp_.New();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public void Init_by_app(Db_conn conn) {
tbl = new Xou_cfg_tbl(conn);
tbl.Conn().Meta_tbl_assert(tbl);
this.Reg(tbl.Select_by_usr_ctx(Usr__anonymous, Ctx__app));
}
public String Get_app_str_or(String key, String or) { // NOTE: app-level is always loaded at start; don't check db
synchronized (hash) { // LOCK:app-level
String uid = Bld_uid(tmp_bfr, Usr__anonymous, Ctx__app, key);
Xou_cfg_itm itm = (Xou_cfg_itm)hash.Get_by(uid);
return itm == null ? or : itm.Val();
}
}
public void Set_app_bry(String key, byte[] val) {this.Set_app_str(key, String_.new_u8(val));}
public void Set_app_str(String key, String val) {
synchronized (hash) { // LOCK:app-level
// update val in reg
String uid = Bld_uid(tmp_bfr, Usr__anonymous, Ctx__app, key);
boolean insert = false;
Xou_cfg_itm itm = (Xou_cfg_itm)hash.Get_by(uid);
if (itm == null) {
itm = new Xou_cfg_itm(Usr__anonymous, Ctx__app, key, val);
hash.Add(uid, itm);
insert = true;
}
itm.Val_(val);
// save to db
tbl.Upsert(insert, itm.Usr(), itm.Ctx(), itm.Key(), itm.Val());
}
}
private void Reg(Xou_cfg_itm[] itms) {
synchronized (hash) { // LOCK:app-level
for (Xou_cfg_itm itm : itms)
hash.Add(itm.Uid(), itm);
}
}
private static final int Usr__anonymous = 1;
private static final String Ctx__app = "app";
public static String Bld_uid(int usr, String ctx, String key) {
return String_.Concat(Int_.To_str(usr), "|", ctx, "|", key);
}
private static String Bld_uid(Bry_bfr tmp_bfr, int usr, String ctx, String key) {
tmp_bfr.Add_int_variable(usr).Add_byte_pipe();
tmp_bfr.Add_str_a7(ctx).Add_byte_pipe();
tmp_bfr.Add_str_u8(key);
return tmp_bfr.To_str_and_clear();
}
}

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.users.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.dbs.*;
public class Xou_cfg_tbl implements Db_tbl {
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_key, fld_usr, fld_ctx, fld_val;
public Xou_cfg_tbl(Db_conn conn) {
this.conn = conn;
this.fld_usr = flds.Add_int ("cfg_usr"); // EX: 1=anonymous; others will require usr_regy
this.fld_ctx = flds.Add_str ("cfg_ctx", 1024); // EX: "app"; "en.w"
this.fld_key = flds.Add_str ("cfg_key", 1024); // EX: "xowa.net.web_enabled"
this.fld_val = flds.Add_str ("cfg_val", 4096); // EX: "y"
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 = "user_cfg";
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_key, fld_key)
));
}
public void Upsert(boolean insert, int usr, String ctx, String key, String val) {
if (insert)
Insert(usr, ctx, key, val);
else
Update(usr, ctx, key, val);
}
private void Insert(int usr, String ctx, String key, String val) {
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
stmt.Clear().Val_int(fld_usr, usr).Val_str(fld_ctx, ctx).Val_str(fld_key, key).Val_str(fld_val, val).Exec_insert();
stmt.Rls();
}
private void Update(int usr, String ctx, String key, String val) {
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_usr, fld_ctx, fld_key), fld_val);
stmt.Clear().Val_str(fld_val, val).Crt_int(fld_usr, usr).Crt_str(fld_ctx, ctx).Crt_str(fld_key, key).Exec_update();
stmt.Rls();
}
public Xou_cfg_itm[] Select_by_usr_ctx(int usr, String ctx) {
List_adp list = List_adp_.New();
Db_stmt stmt_select = conn.Stmt_select(tbl_name, flds, fld_usr, fld_ctx);
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_usr, usr).Crt_str(fld_ctx, ctx).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
list.Add(Make_itm(rdr));
}
} finally {rdr.Rls();}
return (Xou_cfg_itm[])list.To_ary_and_clear(Xou_cfg_itm.class);
}
public void Rls() {}
private Xou_cfg_itm Make_itm(Db_rdr rdr) {
return new Xou_cfg_itm(rdr.Read_int(fld_usr), rdr.Read_str(fld_ctx), rdr.Read_str(fld_key), rdr.Read_str(fld_val));
}
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.core.threads.*; import gplx.dbs.*; import gplx.dbs.metas.updates.*; import gplx.dbs.metas.*;
import gplx.xowa.files.caches.*;
import gplx.xowa.users.bmks.*; import gplx.xowa.users.history.*;
import gplx.xowa.users.cfgs.*; import gplx.xowa.users.bmks.*; import gplx.xowa.users.history.*;
public class Xou_db_mgr {
private final Xoa_app app;
private final Xoud_id_mgr id_mgr;
@@ -35,6 +35,7 @@ public class Xou_db_mgr {
public Xoud_bmk_mgr Bmk_mgr() {return bmk_mgr;} private final Xoud_bmk_mgr bmk_mgr = new Xoud_bmk_mgr();
public Xou_cache_mgr Cache_mgr() {return cache_mgr;} private Xou_cache_mgr cache_mgr;
public Xou_file_itm_finder File__xfer_itm_finder() {return xfer_itm_finder;} private Xou_file_itm_finder xfer_itm_finder;
public Xou_cfg_mgr Cfg() {return cfg;} private final Xou_cfg_mgr cfg = new Xou_cfg_mgr();
public void Init_by_app(boolean drd, Io_url db_url) {
Db_conn_bldr_data db_conn_bldr = Db_conn_bldr.Instance.Get_or_new(db_url);
this.conn = db_conn_bldr.Conn(); boolean created = db_conn_bldr.Created();
@@ -42,6 +43,7 @@ public class Xou_db_mgr {
this.cache_mgr = new Xou_cache_mgr(app.Wiki_mgri(), app.Fsys_mgr().File_dir(), db_file);
this.xfer_itm_finder = new Xou_file_itm_finder(cache_mgr);
this.bmk_mgr.Conn_(conn, created);
cfg.Init_by_app(conn);
// this.history_mgr.Conn_(conn, created);
if (drd) {
this.Init_site_mgr();

View File

@@ -24,7 +24,7 @@ public class Xou_history_html implements gplx.core.brys.Bfr_arg, Xow_special_pag
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
this.app = wiki.Appe(); this.mgr = app.Usere().History_mgr();
mgr.Sort();
Bry_bfr bfr = app.Utl__bfr_mkr().Get_m001();
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_m001();
html_grp.Bld_bfr_many(bfr, this);
page.Db().Text().Text_bry_(bfr.To_bry_and_rls());
}