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:
@@ -23,4 +23,12 @@ public class Xoa_ctg_mgr {
|
||||
public static final byte Hidden_n = Byte_.Zero, Hidden_y = (byte)1;
|
||||
public static final String Html__cls__str = "CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory";
|
||||
public static final byte[] Html__cls__bry = Bry_.new_a7(Html__cls__str);
|
||||
|
||||
public static byte To_tid_by_ns(int ns) {
|
||||
switch (ns) {
|
||||
case gplx.xowa.wikis.nss.Xow_ns_.Tid__category: return Tid__subc;
|
||||
case gplx.xowa.wikis.nss.Xow_ns_.Tid__file : return Tid__file;
|
||||
default : return Tid__page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ public class Xodb_cat_link_tbl implements Db_tbl {
|
||||
private Db_stmt stmt_insert;
|
||||
public Xodb_cat_link_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "cat_link";
|
||||
this.fld__from = flds.Add_int ("cl_from");
|
||||
this.fld__to_id = flds.Add_int ("cl_to_id");
|
||||
this.fld__type_id = flds.Add_byte ("cl_type_id");
|
||||
this.tbl_name = TBL_NAME;
|
||||
this.fld__from = flds.Add_int ("cl_from"); // page_id
|
||||
this.fld__to_id = flds.Add_int ("cl_to_id"); // cat_id
|
||||
this.fld__type_id = flds.Add_byte ("cl_type_id"); // page,file,subc
|
||||
this.fld__timestamp_unix = flds.Add_long ("cl_timestamp_unix");
|
||||
this.fld__sortkey = flds.Add_bry ("cl_sortkey");
|
||||
this.fld__sortkey_prefix = flds.Add_str ("cl_sortkey_prefix", 255);
|
||||
this.fld__sortkey = flds.Add_bry ("cl_sortkey"); // uca key
|
||||
this.fld__sortkey_prefix = flds.Add_str (FLD__cl_sortkey_prefix, 255); // page_title; needed for sorting under letter on catpage
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
@@ -50,9 +50,15 @@ public class Xodb_cat_link_tbl implements Db_tbl {
|
||||
.Val_bry_as_str(fld__sortkey_prefix , sortkey_prefix)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Delete_by_page_id(int page_id) {
|
||||
conn.Stmt_delete(tbl_name, fld__from)
|
||||
.Crt_int(fld__from, page_id)
|
||||
.Exec_delete();
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
public static final String TBL_NAME = "cat_link", FLD__cl_sortkey_prefix = "cl_sortkey_prefix";
|
||||
}
|
||||
/*
|
||||
NOTE_1: categorylinks row size: 34 + 20 + 12 + (cat_sortkey.length * 2)
|
||||
@@ -63,9 +69,9 @@ variable_data length : cat_sortkey.length * 2 sortkey is used for row and cl_mai
|
||||
|
||||
Note the following
|
||||
. ints are 4 bytes
|
||||
. tinyint is assumed to be 4 bytes (should be 1, but sqlite only has one numeric datatype, so import all 4?)
|
||||
. tinyint is assumed to be 4 bytes (should be 1, but sqlite only has one numeric datatype, so using all 4?)
|
||||
. varchar(14) is assumed to be 14 bytes (should be 15? +1 for length of varchar?)
|
||||
. calculations work out "too well". comparing 4 databases gets +/- .25 bytes per row. however
|
||||
.. - bytes should not be possible
|
||||
.. +.25 bytes is too low (18 MB out of 5.5 GB).*; there must be other bytes used for page breaks / fragmentation
|
||||
.. +.25 bytes is too low (18 MB out of 5.5 GB); there must be other bytes used for page breaks / fragmentation
|
||||
*/
|
||||
|
||||
@@ -17,63 +17,98 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.edits; 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.parsers.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.domains.*;
|
||||
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 void Update(Xowe_wiki wiki, byte[] ttl_bry, int page_id, byte[] old_text, byte[] new_text) {
|
||||
// // get page
|
||||
// Xoa_ttl ttl = wiki.Ttl_parse(ttl_bry);
|
||||
// Xoae_page wpg = Xoae_page.New_edit(wiki, ttl);
|
||||
// wpg.Db().Page().Id_(page_id);
|
||||
// wpg.Db().Text().Text_bry_(old_text);
|
||||
//
|
||||
// // parse page
|
||||
// Xop_ctx pctx = wiki.Parser_mgr().Ctx().Clear_all();
|
||||
// wiki.Parser_mgr().Parse(wpg, true);
|
||||
//
|
||||
// // get cat_link_db
|
||||
// Xoax_ctg_addon cat_addon = Xoax_ctg_addon.Get(wiki);
|
||||
// Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(wiki.Data__core_mgr());
|
||||
//
|
||||
// // get cat_link_conn
|
||||
// Xowd_page_itm tmp_page = new Xowd_page_itm();
|
||||
// wiki.Data__core_mgr().Db__core().Tbl__page().Select_by_id(tmp_page, page_id);
|
||||
// Db_conn cat_link_conn = wiki.Data__core_mgr().Props().Layout_text().Tid_is_lot()
|
||||
// ? wiki.Data__core_mgr().Dbs__get_by_id_or_fail(tmp_page.Cat_db_id()).Conn()
|
||||
// : wiki.Data__core_mgr().Db__core().Conn();
|
||||
// Xowd_cat_link_tbl cat_link_tbl = new Xowd_cat_link_tbl(cat_link_conn, Bool_.N);
|
||||
//
|
||||
// // delete old
|
||||
// int cat_len = wpg.Wtxt().Ctgs__len();
|
||||
// for (int i = 0; i < cat_len; i++) {
|
||||
// Xoa_ttl ctg_ttl = wpg.Wtxt().Ctgs__get_at(i);
|
||||
// wiki.Data__core_mgr().Db__core().Tbl__page().Select_by_ttl(tmp_page, ctg_ttl);
|
||||
//// int ctg_id = tmp_page.Cat_db_id();
|
||||
//// Object data = cat_core_tbl.Select_by_cat_id(ctg_id);
|
||||
//// data.cat_pages--
|
||||
//// cat_core_Tbl.Save(data);
|
||||
// }
|
||||
//// cat_link_tbl.Delete_by_page_id(page_id);
|
||||
//
|
||||
// // insert new
|
||||
// wpg.Db().Text().Text_bry_(new_text);
|
||||
// wiki.Parser_mgr().Parse(wpg, true);
|
||||
//
|
||||
// cat_len = wpg.Wtxt().Ctgs__len();
|
||||
// Xodb_wiki_db wiki_db_mgr = Xodb_wiki_db.Make(Xodb_wiki_db_tid.Tid__core, wiki.Data__core_mgr().Db__core().Url());
|
||||
// for (int i = 0; i < cat_len; i++) {
|
||||
// Xoa_ttl ctg_ttl = wpg.Wtxt().Ctgs__get_at(i);
|
||||
// boolean exists = wiki.Data__core_mgr().Db__core().Tbl__page().Select_by_ttl(tmp_page, ctg_ttl);
|
||||
// int ctg_id = tmp_page.Cat_db_id();
|
||||
// if (!exists) {
|
||||
// ctg_id = Xopg_db_mgr.Create(wiki_db_mgr, gplx.xowa.wikis.nss.Xow_ns_.Tid__category, ctg_ttl.Page_db(), Bry_.Empty);
|
||||
// }
|
||||
//// Object data = cat_core_tbl.Select_by_cat_id(ctg_id);
|
||||
//// data.cat_pages++
|
||||
//// cat_core_Tbl.Save(data);
|
||||
//// cat_link_tbl.Insert_by_page_id(page_id, ctg_id);
|
||||
// }
|
||||
public static void Update(Xowe_wiki wiki, byte[] ttl_bry, int page_id, byte[] old_text, byte[] new_text) {
|
||||
// only apply to home or other wiki
|
||||
if (!( wiki.Domain_tid() == Xow_domain_tid_.Tid__other
|
||||
|| wiki.Domain_tid() == Xow_domain_tid_.Tid__home))
|
||||
return;
|
||||
|
||||
// get page
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(ttl_bry);
|
||||
int ns_id = ttl.Ns().Id();
|
||||
Xoae_page wpg = Xoae_page.New_edit(wiki, ttl);
|
||||
wpg.Db().Page().Id_(page_id);
|
||||
|
||||
// get page_tbl
|
||||
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
Xowd_page_tbl page_tbl = db_mgr.Db__core().Tbl__page();
|
||||
|
||||
// get cat_core_tbl
|
||||
Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(db_mgr);
|
||||
|
||||
// get cat_link_tbl
|
||||
Xodb_cat_link_tbl cat_link_tbl = new Xodb_cat_link_tbl(cat_core_tbl.Conn());
|
||||
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
|
||||
|
||||
// get some variables
|
||||
int timestamp = (int)Datetime_now.Get().Timestamp_unix();
|
||||
Xoctg_collation_mgr collation_mgr = wiki.Ctg__catpage_mgr().Collation_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();
|
||||
cat_link_tbl.Insert_bgn();
|
||||
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);
|
||||
boolean exists = page_tbl.Select_by_ttl(tmp_page, sub_ttl);
|
||||
|
||||
// create category if it doesn't exist
|
||||
int sub_id = tmp_page.Id();
|
||||
if (!exists) {
|
||||
sub_id = Xopg_db_mgr.Create
|
||||
( core_db.Tbl__page(), core_db.Tbl__text(), core_db.Tbl__ns(), core_db.Tbl__cfg()
|
||||
, gplx.xowa.wikis.nss.Xow_ns_.Tid__category, sub_ttl.Page_db(), Bry_.Empty, -1);
|
||||
cat_core_tbl.Insert_bgn();
|
||||
cat_core_tbl.Insert_cmd_by_batch(sub_id, 0, 0, 0, Bool_.N_byte, -1);
|
||||
cat_core_tbl.Insert_end();
|
||||
}
|
||||
|
||||
Xowd_category_itm sub_core_itm = cat_core_tbl.Select(sub_id);
|
||||
|
||||
// adjust it and save it
|
||||
sub_core_itm.Adjust(ns_id, 1);
|
||||
cat_core_tbl.Update(sub_core_itm);
|
||||
|
||||
// cat_link:add
|
||||
cat_link_tbl.Insert_cmd_by_batch(page_id, sub_id, Xoa_ctg_mgr.To_tid_by_ns(ns_id), timestamp, collation_mgr.Get_sortkey(wpg.Ttl().Page_db()), wpg.Ttl().Page_db());
|
||||
}
|
||||
cat_link_tbl.Insert_end();
|
||||
|
||||
// update page.cat_db_id
|
||||
page_tbl.Update__cat_db_id(page_id, core_db.Id());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,24 +21,27 @@ import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wi
|
||||
import gplx.xowa.addons.wikis.directorys.dbs.*;
|
||||
import gplx.xowa.addons.wikis.directorys.specials.items.bldrs.*;
|
||||
public class Xopg_db_mgr {
|
||||
public static int Create(Xodb_wiki_db core_db, int ns_id, byte[] ttl_page_db, byte[] text_raw) {
|
||||
Db_cfg_tbl cfg_tbl = Db_cfg_tbl.Get_by_key(core_db, Xowd_cfg_tbl_.Tbl_name);
|
||||
public static int Create
|
||||
( Xowd_page_tbl page_tbl, Xowd_text_tbl text_tbl, Xowd_site_ns_tbl ns_tbl, Db_cfg_tbl cfg_tbl
|
||||
, int ns_id, byte[] ttl_page_db, byte[] text_raw, int cat_db_id) {
|
||||
// get next page_id
|
||||
int page_id = cfg_tbl.Select_int_or("db", "page.id_next", 1);
|
||||
cfg_tbl.Upsert_int("db", "page.id_next", page_id + 1);
|
||||
|
||||
int page_id = cfg_tbl.Select_int_or("db", "page.id_next", -1);
|
||||
Xowd_page_tbl page_tbl = Xowd_page_tbl.Get_by_key(core_db);
|
||||
Xowd_text_tbl text_tbl = Xowd_text_tbl.Get_by_key(core_db);
|
||||
// zip if needed
|
||||
byte[] text_zip = text_tbl.Zip(text_raw);
|
||||
|
||||
// TODO.XO: should call redirect mgr
|
||||
boolean redirect = Bool_.N;
|
||||
|
||||
// do insert
|
||||
page_tbl.Insert_bgn();
|
||||
text_tbl.Insert_bgn();
|
||||
Xowd_site_ns_tbl ns_tbl = Xowd_site_ns_tbl.Get_by_key(core_db);
|
||||
int ns_count = ns_tbl.Select_ns_count(ns_id) + 1;
|
||||
try {
|
||||
page_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_page_db, redirect, Datetime_now.Get(), text_raw.length, ns_count, 0, -1);
|
||||
page_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_page_db, redirect, Datetime_now.Get(), text_raw.length, ns_count, 0, -1, cat_db_id);
|
||||
text_tbl.Insert_cmd_by_batch(page_id, text_zip);
|
||||
Xowd_site_ns_tbl.Get_by_key(core_db).Update_ns_count(ns_id, ns_count);
|
||||
ns_tbl.Update_ns_count(ns_id, ns_count);
|
||||
} finally {
|
||||
page_tbl.Insert_end();
|
||||
text_tbl.Insert_end();
|
||||
|
||||
@@ -59,7 +59,13 @@ public class Xow_db_mkr {
|
||||
|
||||
// insert data: page
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, mainpage_name);
|
||||
Xopg_db_mgr.Create(core_db, Xow_ns_.Tid__main, mainpage_name, mainpage_text);
|
||||
Xopg_db_mgr.Create
|
||||
( Xowd_page_tbl.Get_by_key(core_db)
|
||||
, Xowd_text_tbl.Get_by_key(core_db)
|
||||
, Xowd_site_ns_tbl.Get_by_key(core_db)
|
||||
, Db_cfg_tbl.Get_by_key(core_db, Xowd_cfg_tbl_.Tbl_name)
|
||||
, Xow_ns_.Tid__main, mainpage_name, mainpage_text
|
||||
, -1);
|
||||
|
||||
// create tbls: fsdb
|
||||
core_db.Tbls__add(Bool_.Y
|
||||
|
||||
@@ -16,9 +16,14 @@ 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.directorys.specials.items.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*; import gplx.xowa.addons.wikis.directorys.specials.*; import gplx.xowa.addons.wikis.directorys.specials.items.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
public class Xow_wiki_factory {
|
||||
public static Xowe_wiki Load_personal(Xoae_app app, byte[] domain, Io_url dir_url) {
|
||||
// create the rv
|
||||
// upgrade db
|
||||
Upgrade_db(domain, dir_url);
|
||||
|
||||
// create the wiki
|
||||
Xowe_wiki rv = new Xowe_wiki
|
||||
( app
|
||||
, gplx.xowa.langs.Xol_lang_itm_.Lang_en_make(app.Lang_mgr())
|
||||
@@ -41,7 +46,35 @@ public class Xow_wiki_factory {
|
||||
|
||||
// HACK: remove CC copyright message; should change to option
|
||||
rv.Msg_mgr().Get_or_make(Bry_.new_a7("wikimedia-copyright")).Atrs_set(Bry_.Empty, false, false);
|
||||
|
||||
return rv;
|
||||
}
|
||||
private static void Upgrade_db(byte[] domain, Io_url dir_url) {
|
||||
// get conn
|
||||
Io_url core_db_url = gplx.xowa.wikis.data.Xow_db_file__core_.Find_core_fil_or_null(dir_url, String_.new_u8(domain));
|
||||
if (core_db_url == null) {
|
||||
throw Err_.new_wo_type("failed to find core_db for wiki; wiki=~{domain} dir=~{dir_url}", domain, dir_url);
|
||||
}
|
||||
Db_conn core_db_conn = Db_conn_bldr.Instance.Get_or_fail(core_db_url);
|
||||
|
||||
// cat_link: if cat_link.cl_sortkey_prefix doesn't exist, then cat_link is old format; drop it and add the new one
|
||||
try {
|
||||
if (!core_db_conn.Meta_fld_exists(Xodb_cat_link_tbl.TBL_NAME, Xodb_cat_link_tbl.FLD__cl_sortkey_prefix)) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "xo.personal:cat_link upgrade; fil=~{0}", core_db_url.Raw());
|
||||
core_db_conn.Meta_tbl_delete(Xodb_cat_link_tbl.TBL_NAME);
|
||||
core_db_conn.Meta_tbl_assert(new Xodb_cat_link_tbl(core_db_conn));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "xo.personal:cat_link upgrade failed; err=~{0}", Err_.Message_gplx_log(e));
|
||||
}
|
||||
|
||||
// page.cat_db_id: if page.cat_db_id doesn't exist, then add it
|
||||
try {
|
||||
if (!core_db_conn.Meta_fld_exists(Xowd_page_tbl.TBL_NAME, Xowd_page_tbl.FLD__page_cat_db_id)) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "xo.personal:page.page_cat_db_id upgrade; fil=~{0}", core_db_url.Raw());
|
||||
core_db_conn.Meta_fld_append(Xowd_page_tbl.TBL_NAME, Dbmeta_fld_itm.new_int(Xowd_page_tbl.FLD__page_cat_db_id).Default_(-1));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "xo.personal:page.page_cat_db_id upgrade failed; err=~{0}", Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user