mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Personal_wikis: Support creation / editing of categories
This commit is contained in:
@@ -95,7 +95,7 @@ public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser, Gfo_invk {
|
||||
init_needed = false;
|
||||
if (String_.Eq(domain_str, "xowa")) return; // HACK: ignore "xowa" for now; WHEN:converting xowa to sqlitedb
|
||||
data_mgr__core_mgr = new Xow_db_mgr(this, fsys_mgr.Root_dir());
|
||||
data_mgr__core_mgr.Init_by_load(gplx.xowa.wikis.data.Xow_db_file__core_.Find_core_fil(this));
|
||||
data_mgr__core_mgr.Init_by_load(gplx.xowa.wikis.data.Xow_db_file__core_.Find_core_fil_or_null(this));
|
||||
app.Html__css_installer().Install(this, Xowd_css_core_mgr.Key_mobile); // must init after data_mgr
|
||||
this.db_core_mgr = Fsdb_db_mgr_.new_detect(this, fsys_mgr.Root_dir(), fsys_mgr.File_dir());
|
||||
if (db_core_mgr == null) // no fsdb; occurs during merge; also, will be null for xowa_db; DATE:2016-05-31
|
||||
|
||||
@@ -19,9 +19,8 @@ package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xow
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Xow_db_file__core_ {
|
||||
public static Io_url Find_core_fil(Xow_wiki wiki) {
|
||||
Io_url wiki_root_dir = wiki.Fsys_mgr().Root_dir();
|
||||
String domain_str = wiki.Domain_str();
|
||||
public static Io_url Find_core_fil_or_null(Xow_wiki wiki) {return Find_core_fil_or_null(wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());}
|
||||
public static Io_url Find_core_fil_or_null(Io_url wiki_root_dir, String domain_str) {
|
||||
Io_url[] ary = Io_mgr.Instance.QueryDir_fils(wiki_root_dir);
|
||||
int ary_len = ary.length; if (ary.length == 0) return null;
|
||||
Io_url rv = Find_core_fil__xowa(ary, ary_len, domain_str);
|
||||
|
||||
@@ -130,7 +130,7 @@ public class Xow_db_mgr {
|
||||
this.Init_by_load(db__core.Url());
|
||||
}
|
||||
public void Create_page(Xowd_page_tbl core_tbl, Xowd_text_tbl text_tbl, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text_zip_data, int text_raw_len, int random_int, int text_db_id, int html_db_id) {
|
||||
core_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_raw_len, random_int, text_db_id, html_db_id);
|
||||
core_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_raw_len, random_int, text_db_id, html_db_id, -1);
|
||||
text_tbl.Insert_cmd_by_batch(page_id, text_zip_data);
|
||||
}
|
||||
private void Dbs__set_by_tid(Xow_db_file db) {
|
||||
|
||||
@@ -52,11 +52,21 @@ public class Xowd_cat_core_tbl implements Db_tbl {
|
||||
public void Update_by_batch(int id, byte hidden) {
|
||||
stmt_update.Clear().Val_byte(fld_hidden, hidden).Crt_int(fld_id, id).Exec_update();
|
||||
}
|
||||
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();;}
|
||||
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
|
||||
public void Update(Xowd_category_itm itm) {
|
||||
conn.Stmt_update_exclude(tbl_name, flds, fld_id).Clear()
|
||||
.Val_int(fld_pages, itm.Count_pages())
|
||||
.Val_int(fld_subcats, itm.Count_subcs())
|
||||
.Val_int(fld_files, itm.Count_files())
|
||||
.Val_bool_as_byte(fld_hidden, itm.Hidden())
|
||||
.Val_int(fld_link_db_id, itm.File_idx())
|
||||
.Crt_int(fld_id, itm.Id())
|
||||
.Exec_update();
|
||||
}
|
||||
public Xowd_category_itm Select(int id) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_id);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_id, id).Exec_select__rls_manual();
|
||||
try {return rdr.Move_next() ? new_itm(rdr) : Xowd_category_itm.Null;} finally {rdr.Rls();}
|
||||
try {return rdr.Move_next() ? Load_itm(rdr) : Xowd_category_itm.Null;} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_by_cat_id_in(Cancelable cancelable, Ordered_hash rv, int bgn, int end) {
|
||||
in_wkr.Init(rv);
|
||||
@@ -76,7 +86,7 @@ public class Xowd_cat_core_tbl implements Db_tbl {
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
}
|
||||
public Xowd_category_itm new_itm(Db_rdr rdr) {
|
||||
public Xowd_category_itm Load_itm(Db_rdr rdr) {
|
||||
return Xowd_category_itm.load_
|
||||
( rdr.Read_int(fld_id)
|
||||
, rdr.Read_int(fld_link_db_id)
|
||||
|
||||
@@ -37,7 +37,7 @@ class Xowd_cat_core_tbl__in_wkr extends Db_in_wkr__base {
|
||||
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_category_itm ctg_data = tbl.new_itm(rdr);
|
||||
Xowd_category_itm ctg_data = tbl.Load_itm(rdr);
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_by(ctg_data.Id_val());
|
||||
page.Xtn_(ctg_data);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public class Xowd_cat_link_tbl implements Db_tbl {
|
||||
public Xowd_cat_link_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = schema_is_1 ? "categorylinks" : "cat_link";
|
||||
fld_from = flds.Add_int ("cl_from");
|
||||
fld_to_id = flds.Add_int ("cl_to_id");
|
||||
fld_from = flds.Add_int ("cl_from"); // page_id
|
||||
fld_to_id = flds.Add_int ("cl_to_id"); // cat_id
|
||||
fld_type_id = flds.Add_byte ("cl_type_id");
|
||||
fld_sortkey = flds.Add_str ("cl_sortkey", 230);
|
||||
fld_timestamp = flds.Add_str ("cl_timestamp", 14);
|
||||
@@ -52,7 +52,6 @@ public class Xowd_cat_link_tbl implements Db_tbl {
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
|
||||
|
||||
public int Select_by_type(List_adp list, int cat_page_id, byte arg_tid, byte[] arg_sortkey, boolean arg_is_from, int limit) {
|
||||
String arg_sortkey_str = arg_sortkey == null ? "" : String_.new_u8(arg_sortkey);
|
||||
gplx.core.criterias.Criteria comp_crt = !arg_is_from
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_category_itm {
|
||||
public int Id() {return id;} private int id;
|
||||
public Int_obj_val Id_val() {if (id_val == null) id_val = new Int_obj_val(id); return id_val;} Int_obj_val id_val;
|
||||
@@ -33,7 +34,15 @@ public class Xowd_category_itm {
|
||||
case Xoa_ctg_mgr.Tid__file: return count_files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Adjust(int ns, int val) {
|
||||
switch (ns) {
|
||||
case Xow_ns_.Tid__category: count_subcs += val; break;
|
||||
case Xow_ns_.Tid__file : count_files += val; break;
|
||||
default : count_pages += val; break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Xowd_category_itm load_(int id, int file_idx, boolean hidden, int count_subcs, int count_files, int count_pages) {
|
||||
Xowd_category_itm rv = new Xowd_category_itm();
|
||||
rv.id = id; rv.file_idx = file_idx; rv.hidden = hidden;
|
||||
|
||||
@@ -77,12 +77,14 @@ public class Xowd_page_tbl implements Db_tbl {
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds.To_fld_ary()));}
|
||||
public void Insert(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) {
|
||||
this.Insert_bgn();
|
||||
this.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, page_is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id);
|
||||
this.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, page_is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id, -1);
|
||||
this.Insert_end();
|
||||
}
|
||||
public void Insert_bgn() {conn.Txn_bgn("page__insert_bulk"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) {
|
||||
public void Insert_cmd_by_batch
|
||||
(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int
|
||||
, int text_db_id, int html_db_id, int cat_db_id) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_id, page_id)
|
||||
.Val_int(fld_ns, ns_id)
|
||||
@@ -95,7 +97,7 @@ public class Xowd_page_tbl implements Db_tbl {
|
||||
.Val_int(fld_html_db_id, html_db_id)
|
||||
.Val_int(fld_redirect_id, -1)
|
||||
.Val_int(fld_score, -1)
|
||||
.Val_int(fld_cat_db_id, -1)
|
||||
.Val_int(fld_cat_db_id, cat_db_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Insert_by_itm(Db_stmt stmt, Xowd_page_itm itm, int html_db_id) {
|
||||
@@ -336,6 +338,10 @@ public class Xowd_page_tbl implements Db_tbl {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_html_db_id);
|
||||
stmt.Val_int(fld_html_db_id, html_db_id).Crt_int(fld_id, page_id).Exec_update();
|
||||
}
|
||||
public void Update__cat_db_id(int page_id, int cat_db_id) {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_cat_db_id);
|
||||
stmt.Val_int(fld_cat_db_id, cat_db_id).Crt_int(fld_id, page_id).Exec_update();
|
||||
}
|
||||
public void Update__ns__ttl(int page_id, int trg_ns, byte[] trg_ttl) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
try {
|
||||
@@ -377,6 +383,6 @@ public class Xowd_page_tbl implements Db_tbl {
|
||||
}
|
||||
}
|
||||
public static final String Page_touched_fmt = "yyyyMMddHHmmss";
|
||||
public static final String TBL_NAME = "page";
|
||||
public static final String TBL_NAME = "page", FLD__page_cat_db_id = "page_cat_db_id";
|
||||
public static Xowd_page_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_page_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user