1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
/*
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.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
public class Xop_log_basic_tbl {
private Db_stmt stmt_insert;
public Xop_log_basic_tbl(Db_conn conn){this.conn = conn; this.Create_table();}
public Db_conn Conn() {return conn;} private Db_conn conn;
private void Create_table() {Sqlite_engine_.Tbl_create(conn, Tbl_name, Tbl_sql);}
public void Delete() {conn.Exec_qry(Db_qry_delete.new_all_(Tbl_name));}
public void Insert(int log_tid, String log_msg, int log_time, int page_id, String page_ttl, int args_len, String args_str, int src_len, String src_str) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(conn, Tbl_name, Fld_log_tid, Fld_log_msg, Fld_log_time, Fld_page_id, Fld_page_ttl, Fld_args_len, Fld_args_str, Fld_src_len, Fld_src_str);
stmt_insert.Clear()
.Val_int(log_tid)
.Val_str(log_msg)
.Val_int(log_time)
.Val_int(page_id)
.Val_str(page_ttl)
.Val_int(args_len)
.Val_str(args_str)
.Val_int(src_len)
.Val_str(src_str)
.Exec_insert();
}
public void Rls() {
stmt_insert.Rls();
}
public static final String Tbl_name = "log_basic_temp"
, Fld_log_tid = "log_tid", Fld_log_msg = "log_msg", Fld_log_time = "log_time"
, Fld_page_id = "page_id", Fld_page_ttl = "page_ttl"
, Fld_args_len = "args_len", Fld_args_str = "args_str"
, Fld_src_len = "src_len", Fld_src_str = "src_str"
;
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS log_basic_temp"
, "( log_id integer NOT NULL PRIMARY KEY AUTOINCREMENT"
, ", log_tid integer NOT NULL"
, ", log_msg varchar(255) NOT NULL"
, ", log_time integer NOT NULL"
, ", page_id integer NOT NULL"
, ", page_ttl varchar(255) NOT NULL"
, ", args_len integer NOT NULL"
, ", args_str varchar(4096) NOT NULL"
, ", src_len integer NOT NULL"
, ", src_str varchar(4096) NOT NULL"
, ");"
);
}

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.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.dbs.*;
public class Xop_log_basic_wkr implements GfoInvkAble {
private Xop_log_mgr log_mgr; private Xop_log_basic_tbl log_tbl;
private boolean save_page_ttl, save_log_time, save_args_len, save_args_str;
public boolean Save_src_str() {return save_src_str;} public Xop_log_basic_wkr Save_src_str_(boolean v) {save_src_str = v; return this;} private boolean save_src_str;
public Xop_log_basic_wkr(Xop_log_mgr log_mgr, Xop_log_basic_tbl log_tbl) {this.log_mgr = log_mgr; this.log_tbl = log_tbl;}
public boolean Log_bgn(Xoae_page page, byte[] src, Xop_xnde_tkn xnde) {return true;}
public void Log_end_xnde(Xoae_page page, int log_tid, byte[] src, Xop_xnde_tkn xnde_tkn) {
Xop_xatr_itm[] atrs_ary = xnde_tkn.Atrs_ary();
Log_end(page, Null_log_bgn, log_tid, Null_log_msg, src
, xnde_tkn.Src_bgn(), xnde_tkn.Src_end()
, atrs_ary == null ? 0 : atrs_ary.length
, xnde_tkn.Atrs_bgn(), xnde_tkn.Atrs_end()
);
}
public void Log_end(Xoae_page page, long log_bgn, int log_tid, byte[] log_msg, byte[] src, int src_bgn, int src_end, int args_len, int args_bgn, int args_end) {
log_tbl.Insert
( log_tid
, log_msg == Xop_log_basic_wkr.Null_log_msg ? "" : String_.new_u8(log_msg)
, save_log_time ? Env_.TickCount_elapsed_in_frac(log_bgn) : Xop_log_basic_wkr.Null_log_time
, page.Revision_data().Id()
, save_page_ttl ? String_.new_u8(page.Ttl().Full_db()) : Xop_log_basic_wkr.Null_page_ttl
, save_args_len ? args_len : Xop_log_basic_wkr.Null_args_len
, save_args_str ? String_.new_u8(src, args_bgn, args_end) : Xop_log_basic_wkr.Null_args_str
, src_end - src_bgn
, save_src_str ? String_.new_u8(src, src_bgn, src_end) : Xop_log_basic_wkr.Null_src_str
);
log_mgr.Commit_chk();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_save_page_ttl_)) save_page_ttl = m.ReadYn("v");
else if (ctx.Match(k, Invk_save_log_time_)) save_log_time = m.ReadYn("v");
else if (ctx.Match(k, Invk_save_args_len_)) save_args_len = m.ReadYn("v");
else if (ctx.Match(k, Invk_save_args_str_)) save_args_str = m.ReadYn("v");
else if (ctx.Match(k, Invk_save_src_str_)) save_src_str = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_save_page_ttl_ = "save_page_ttl_", Invk_save_log_time_ = "save_log_time_"
, Invk_save_args_len_ = "save_args_len_", Invk_save_args_str_ = "save_args_str_", Invk_save_src_str_ = "save_src_str_"
;
public static final Xop_log_basic_wkr Null = null;
public static final int Null_page_id = -1, Null_log_bgn = -1, Null_log_time = -1, Null_args_len = -1, Null_src_len = -1;
public static final String Null_page_ttl = "", Null_args_str = "", Null_src_str = "";
public static final byte[] Null_log_msg = null;
public static final int
Tid_gallery = 1
, Tid_imageMap = 2
, Tid_timeline = 3
, Tid_score = 4
, Tid_hiero = 5
;
}

View File

@@ -0,0 +1,82 @@
/*
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.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.parsers.logs.*;
import gplx.xowa.xtns.scribunto.*;
public class Xop_log_invoke_wkr implements GfoInvkAble {
private Xop_log_mgr log_mgr;
private Db_conn conn; private Db_stmt stmt;
private boolean log_enabled = true;
private Hash_adp_bry exclude_mod_names = Hash_adp_bry.cs_();
public Scrib_err_filter_mgr Err_filter_mgr() {return err_filter_mgr;} private final Scrib_err_filter_mgr err_filter_mgr = new Scrib_err_filter_mgr();
public Xop_log_invoke_wkr(Xop_log_mgr log_mgr, Db_conn conn) {
this.log_mgr = log_mgr;
this.conn = conn;
if (log_enabled) {
Xop_log_invoke_tbl.Create_table(conn);
stmt = Xop_log_invoke_tbl.Insert_stmt(conn);
}
}
public void Init_reset() {Xop_log_invoke_tbl.Delete(conn);}
public boolean Eval_bgn(Xoae_page page, byte[] mod_name, byte[] fnc_name) {return !exclude_mod_names.Has(mod_name);}
public void Eval_end(Xoae_page page, byte[] mod_name, byte[] fnc_name, long invoke_time_bgn) {
if (log_enabled && stmt != null) {
int eval_time = (int)(Env_.TickCount() - invoke_time_bgn);
Xop_log_invoke_tbl.Insert(stmt, page.Ttl().Rest_txt(), mod_name, fnc_name, eval_time);
log_mgr.Commit_chk();
}
}
private void Exclude_mod_names_add(String[] v) {
int len = v.length;
for (int i = 0; i < len; i++) {
byte[] bry = Bry_.new_u8(v[i]);
exclude_mod_names.Add_bry_bry(bry);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_exclude_mod_names_add)) Exclude_mod_names_add(m.ReadStrAry("v", "|"));
else if (ctx.Match(k, Invk_log_enabled_)) log_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_err_filter)) return err_filter_mgr;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_exclude_mod_names_add = "exclude_mod_names_add", Invk_log_enabled_ = "log_enabled_", Invk_err_filter = "err_filter";
}
class Xop_log_invoke_tbl {
public static void Create_table(Db_conn conn) {Sqlite_engine_.Tbl_create(conn, Tbl_name, Tbl_sql);}
public static void Delete(Db_conn conn) {conn.Exec_qry(Db_qry_delete.new_all_(Tbl_name));}
public static Db_stmt Insert_stmt(Db_conn conn) {return Db_stmt_.new_insert_(conn, Tbl_name, Fld_invk_page_ttl, Fld_invk_mod_name, Fld_invk_fnc_name, Fld_invk_eval_time);}
public static void Insert(Db_stmt stmt, byte[] page_ttl, byte[] mod_name, byte[] fnc_name, int eval_time) {
stmt.Clear()
.Val_bry_as_str(page_ttl)
.Val_bry_as_str(mod_name)
.Val_bry_as_str(fnc_name)
.Val_int(eval_time)
.Exec_insert();
}
public static final String Tbl_name = "log_invoke_temp", Fld_invk_page_ttl = "invk_page_ttl", Fld_invk_mod_name = "invk_mod_name", Fld_invk_fnc_name = "invk_fnc_name", Fld_invk_eval_time = "invk_eval_time";
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS log_invoke_temp"
, "( invk_id integer NOT NULL PRIMARY KEY AUTOINCREMENT"
, ", invk_page_ttl varchar(255) NOT NULL"
, ", invk_mod_name varchar(255) NOT NULL"
, ", invk_fnc_name varchar(255) NOT NULL"
, ", invk_eval_time integer NOT NULL"
, ");"
);
}

View File

@@ -0,0 +1,68 @@
/*
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.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.dbs.*; import gplx.xowa.bldrs.*;
public class Xop_log_mgr implements GfoInvkAble {
private Db_conn conn;
private Xoae_app app; private Xop_log_basic_tbl log_tbl;
private int exec_count = 0, commit_interval = 1000;
public Xop_log_mgr(Xoae_app app) {this.app = app;}
public Io_url Log_dir() {return log_dir;}
public Xop_log_mgr Log_dir_(Io_url v) {
log_dir = v;
// if (conn != null) { // COMMENTED: need to implement a conn.Renew()
// conn.Rls(); // invalidate conn; note that during build other cmds will bind Conn which will place temp.log in /temp/ dir instead of /wiki/ dir; DATE:2014-04-16
// }
return this;
} private Io_url log_dir;
private Db_conn Conn() {
if (conn == null) {
if (log_dir == null) log_dir = app.Usere().Fsys_mgr().App_temp_dir();
Xob_db_file db_file = Xob_db_file.new__temp_log(log_dir);
conn = db_file.Conn();
}
return conn;
}
public Xop_log_invoke_wkr Make_wkr_invoke() {return new Xop_log_invoke_wkr(this, this.Conn());}
public Xop_log_property_wkr Make_wkr_property() {return new Xop_log_property_wkr(this, this.Conn());}
public Xop_log_basic_wkr Make_wkr() {
if (log_tbl == null)
log_tbl = new Xop_log_basic_tbl(this.Conn());
return new Xop_log_basic_wkr(this, log_tbl);
}
public void Commit_chk() {
++exec_count;
if ((exec_count % commit_interval) == 0)
conn.Txn_sav();
}
public void Delete_all() {
log_tbl.Delete();
}
public void Txn_bgn() {conn.Txn_bgn();}
public void Txn_end() {conn.Txn_end();}
public void Rls() {
if (log_tbl != null) log_tbl.Rls();
if (conn != null) {conn.Rls_conn(); conn = null;}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_commit_interval_)) commit_interval = m.ReadInt("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_commit_interval_ = "commit_interval_";
}

View File

@@ -0,0 +1,77 @@
/*
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.parsers.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
public class Xop_log_property_wkr implements GfoInvkAble {
private Xop_log_mgr log_mgr; private Db_conn conn; private Db_stmt stmt;
private boolean log_enabled = true;
private boolean include_all = true;
private Hash_adp_bry include_props = Hash_adp_bry.cs_();
public Xop_log_property_wkr(Xop_log_mgr log_mgr, Db_conn conn) {
this.log_mgr = log_mgr;
this.conn = conn;
if (log_enabled) {
Xob_log_property_temp_tbl.Create_table(conn);
stmt = Xob_log_property_temp_tbl.Insert_stmt(conn);
}
}
public void Init_reset() {Xob_log_property_temp_tbl.Delete(conn);}
public boolean Eval_bgn(Xoae_page page, byte[] prop) {return include_all || include_props.Has(prop);}
public void Eval_end(Xoae_page page, byte[] prop, long invoke_time_bgn) {
if (log_enabled && stmt != null) {
int eval_time = (int)(Env_.TickCount() - invoke_time_bgn);
Xob_log_property_temp_tbl.Insert(stmt, page.Ttl().Rest_txt(), prop, eval_time);
log_mgr.Commit_chk();
}
}
private void Include_props_add(String[] v) {
int len = v.length;
for (int i = 0; i < len; i++) {
byte[] bry = Bry_.new_u8(v[i]);
include_props.Add_bry_bry(bry);
}
include_all = false; // set include_all to false, since specific items added
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_include_props_add)) Include_props_add(m.ReadStrAry("v", "|"));
else if (ctx.Match(k, Invk_log_enabled_)) log_enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_include_props_add = "include_props_add", Invk_log_enabled_ = "log_enabled_";
}
class Xob_log_property_temp_tbl {
public static void Create_table(Db_conn conn) {Sqlite_engine_.Tbl_create(conn, Tbl_name, Tbl_sql);}
public static void Delete(Db_conn conn) {conn.Exec_qry(Db_qry_delete.new_all_(Tbl_name));}
public static Db_stmt Insert_stmt(Db_conn conn) {return Db_stmt_.new_insert_(conn, Tbl_name, Fld_prop_page_ttl, Fld_prop_prop_name, Fld_prop_eval_time);}
public static void Insert(Db_stmt stmt, byte[] page_ttl, byte[] prop_name, int eval_time) {
stmt.Clear()
.Val_bry_as_str(page_ttl)
.Val_bry_as_str(prop_name)
.Val_int(eval_time)
.Exec_insert();
}
public static final String Tbl_name = "log_property_temp", Fld_prop_page_ttl = "prop_page_ttl", Fld_prop_prop_name = "prop_prop_name", Fld_prop_eval_time = "prop_eval_time";
private static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS log_property_temp"
, "( prop_id integer NOT NULL PRIMARY KEY AUTOINCREMENT"
, ", prop_page_ttl varchar(255) NOT NULL"
, ", prop_prop_name varchar(255) NOT NULL"
, ", prop_eval_time integer NOT NULL"
, ");"
);
}