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

Personal_wikis: Add page delete; refactor category updates

This commit is contained in:
gnosygnu
2017-02-15 11:44:30 -05:00
parent b37b5ceddd
commit 12c78cf89f
17 changed files with 252 additions and 47 deletions

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.wikis.ctgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
public class Xodb_cat_link_row {
public Xodb_cat_link_row(int page_id, int cat_id, byte type_id, long timestamp_unix, byte[] sortkey, byte[] sortkey_prefix) {
this.page_id = page_id;
this.cat_id = cat_id;
this.type_id = type_id;
this.timestamp_unix = timestamp_unix;
this.sortkey = sortkey;
this.sortkey_prefix = sortkey_prefix;
}
public int Page_id() {return page_id;} private final int page_id;
public int Cat_id() {return cat_id;} private final int cat_id;
public byte Type_id() {return type_id;} private final byte type_id;
public long Timestamp_unix() {return timestamp_unix;} private final long timestamp_unix;
public byte[] Sortkey() {return sortkey;} private final byte[] sortkey;
public byte[] Sortkey_prefix() {return sortkey_prefix;} private final byte[] sortkey_prefix;
}

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
import gplx.dbs.*;
import gplx.xowa.wikis.data.*;
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
public class Xodb_cat_link_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
@@ -50,6 +51,26 @@ public class Xodb_cat_link_tbl implements Db_tbl {
.Val_bry_as_str(fld__sortkey_prefix , sortkey_prefix)
.Exec_insert();
}
public Xodb_cat_link_row[] Select_by_page_id(int page_id) {
List_adp list = List_adp_.New();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__from).Crt_int(fld__from, page_id).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Xodb_cat_link_row row = new Xodb_cat_link_row
( rdr.Read_int(fld__from)
, rdr.Read_int(fld__to_id)
, rdr.Read_byte(fld__type_id)
, rdr.Read_long(fld__timestamp_unix)
, rdr.Read_bry(fld__sortkey)
, rdr.Read_bry_by_str(fld__sortkey_prefix)
);
list.Add(row);
}
} finally {
rdr.Rls();
}
return (Xodb_cat_link_row[])list.To_ary_and_clear(Xodb_cat_link_row.class);
}
public void Delete_by_page_id(int page_id) {
conn.Stmt_delete(tbl_name, fld__from)
.Crt_int(fld__from, page_id)
@@ -59,6 +80,33 @@ public class Xodb_cat_link_tbl implements Db_tbl {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
public static final String TBL_NAME = "cat_link", FLD__cl_sortkey_prefix = "cl_sortkey_prefix";
public static Xodb_cat_link_tbl[] Get_catlink_tbls(Xow_db_mgr db_mgr) {
List_adp rv = List_adp_.New();
boolean layout_is_lot = db_mgr.Props().Layout_text().Tid_is_lot();
// loop all dbs
int len = db_mgr.Dbs__len();
for (int i = 0; i < len; i++) {
Xow_db_file link_db = db_mgr.Dbs__get_at(i);
switch (link_db.Tid()) {
// if core, add if all or few; skip if lot
case Xow_db_file_.Tid__core:
if (layout_is_lot)
continue;
break;
// if cat_link, add
case Xow_db_file_.Tid__cat_link:
break;
// else, skip
default:
continue;
}
rv.Add(new Xodb_cat_link_tbl(link_db.Conn()));
}
return (Xodb_cat_link_tbl[])rv.To_ary_and_clear(Xodb_cat_link_tbl.class);
}
}
/*
NOTE_1: categorylinks row size: 34 + 20 + 12 + (cat_sortkey.length * 2)

View File

@@ -22,7 +22,7 @@ import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.x
import gplx.xowa.addons.wikis.ctgs.dbs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
import gplx.xowa.addons.wikis.directorys.specials.items.bldrs.*;
public class Xoctg_edit_mgr {
public static void Update(Xowe_wiki wiki, byte[] ttl_bry, int page_id, byte[] old_text, byte[] new_text) {
public static void Update(Xowe_wiki wiki, byte[] ttl_bry, int page_id, Xoa_ttl[] ctg_ttls) {
// only apply to home or other wiki
if (!( wiki.Domain_tid() == Xow_domain_tid_.Tid__other
|| wiki.Domain_tid() == Xow_domain_tid_.Tid__home))
@@ -46,32 +46,8 @@ public class Xoctg_edit_mgr {
Xowd_page_itm tmp_page = new Xowd_page_itm();
db_mgr.Tbl__page().Select_by_id(tmp_page, page_id);
// parse old page
wiki.Parser_mgr().Ctx().Clear_all();
wpg.Db().Text().Text_bry_(old_text);
wiki.Parser_mgr().Parse(wpg, true);
wiki.Html_mgr().Page_wtr_mgr().Gen(wpg, Xopg_page_.Tid_read); // need to write html to fill Wtxt().Ctgs
// cat_core:update; for each category, subtract one from count_page, count_file, or count_subcs
int cat_len = wpg.Wtxt().Ctgs__len();
for (int i = 0; i < cat_len; i++) {
// get cat_core itm for sub_cat
Xoa_ttl sub_ttl = wpg.Wtxt().Ctgs__get_at(i);
page_tbl.Select_by_ttl(tmp_page, sub_ttl);
Xowd_category_itm sub_core_itm = cat_core_tbl.Select(tmp_page.Id());
// subtract one and save it
sub_core_itm.Adjust(ns_id, -1);
cat_core_tbl.Update(sub_core_itm);
}
// cat_link:delete
cat_link_tbl.Delete_by_page_id(page_id);
// parse new page
wiki.Parser_mgr().Ctx().Clear_all();
wpg.Db().Text().Text_bry_(new_text);
wiki.Parser_mgr().Parse(wpg, true);
wiki.Html_mgr().Page_wtr_mgr().Gen(wpg, Xopg_page_.Tid_read); // need to write html to fill Wtxt().Ctgs
// delete old categories
Delete(wiki, page_id);
// get some variables
int timestamp = (int)Datetime_now.Get().Timestamp_unix();
@@ -79,11 +55,11 @@ public class Xoctg_edit_mgr {
Xow_db_file core_db = db_mgr.Db__core();
// cat_core:update; for each category, add one to count_page, count_file, or count_subcs
cat_len = wpg.Wtxt().Ctgs__len();
int ctg_ttls_len = ctg_ttls.length;
cat_link_tbl.Insert_bgn();
for (int i = 0; i < cat_len; i++) {
for (int i = 0; i < ctg_ttls_len; i++) {
// get cat_core itm for sub_cat
Xoa_ttl sub_ttl = wpg.Wtxt().Ctgs__get_at(i);
Xoa_ttl sub_ttl = ctg_ttls[i];
boolean exists = page_tbl.Select_by_ttl(tmp_page, sub_ttl);
// create category if it doesn't exist
@@ -111,4 +87,34 @@ public class Xoctg_edit_mgr {
// update page.cat_db_id
page_tbl.Update__cat_db_id(page_id, core_db.Id());
}
public static void Delete(Xowe_wiki wiki, int page_id) {
// get page_tbl
Xowd_page_tbl page_tbl = wiki.Data__core_mgr().Db__core().Tbl__page();
Xowd_page_itm tmp_page = new Xowd_page_itm();
page_tbl.Select_by_id(tmp_page, page_id);
int ns_id = tmp_page.Ns_id();
// get cat_core_tbl
Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(wiki.Data__core_mgr());
// get cat_link_tbls
Xodb_cat_link_tbl[] cat_link_tbls = Xodb_cat_link_tbl.Get_catlink_tbls(wiki.Data__core_mgr());
// loop cat_link tbls to find linked categories
for (Xodb_cat_link_tbl cat_link_tbl : cat_link_tbls) {
Xodb_cat_link_row[] cat_link_rows = cat_link_tbl.Select_by_page_id(page_id);
// loop linked categories
for (Xodb_cat_link_row cat_link_row : cat_link_rows) {
// get cat_core_itm
Xowd_category_itm sub_core_itm = cat_core_tbl.Select(cat_link_row.Cat_id());
// subtract one and save it
sub_core_itm.Adjust(ns_id, -1);
cat_core_tbl.Update(sub_core_itm);
}
// delete cat_links
cat_link_tbl.Delete_by_page_id(page_id);
}
}
}