mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Personal_wiki: Refactor special pages
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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.directorys; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
|
||||
import gplx.xowa.addons.wikis.directorys.dbs.*;
|
||||
import gplx.xowa.addons.wikis.directorys.specials.items.*; import gplx.xowa.addons.wikis.directorys.specials.lists.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.specials.*;
|
||||
public class Xowdir_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ Xowdir_item_special.Prototype
|
||||
, Xowdir_list_special.Prototype
|
||||
};
|
||||
}
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ Xowdir_item_bridge.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
public String Addon__key() {return ADDON__KEY;} private static final String ADDON__KEY = "xowa.user.wiki.regy";
|
||||
// public static Xowdir_addon Addon__get(Xow_wiki wiki) {
|
||||
// Xowdir_addon rv = (Xowdir_addon)wiki.Addon_mgr().Itms__get_or_null(ADDON__KEY);
|
||||
// if (rv == null) {
|
||||
// rv = new Xowdir_addon(wiki.App().User().User_db_mgr().Conn());
|
||||
// wiki.Addon_mgr().Itms__add(rv);
|
||||
// }
|
||||
// return rv;
|
||||
// }
|
||||
public static void Init(Xoae_app app) {
|
||||
// exit if none found
|
||||
Db_conn conn = app.User().User_db_mgr().Conn();
|
||||
if (!conn.Meta_tbl_exists(Xowdir_wiki_tbl.Tbl_name_dflt)) return;
|
||||
|
||||
// register
|
||||
Xowdir_db_mgr db_mgr = new Xowdir_db_mgr(conn);
|
||||
Xowdir_wiki_itm[] itms = db_mgr.Tbl__wiki().Select_all();
|
||||
int len = itms.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowdir_wiki_itm itm = itms[i];
|
||||
try {
|
||||
gplx.xowa.addons.wikis.directorys.specials.items.bldrs.Xow_wiki_factory.Load_personal(app, Bry_.new_u8(itm.Domain()), itm.Url().OwnerDir());
|
||||
} catch (Exception exc) {// handles failures if wiki is deleted, but item is still in wiki_list table
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "personal_wiki: failed to open personal wiki; domain=~{0} url=~{1} err=~{2}", itm.Domain(), itm.Url(), Err_.Message_gplx_log(exc));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xowdir_db_mgr {
|
||||
public Xowdir_db_mgr(Db_conn conn) {
|
||||
tbl__wiki = new Xowdir_wiki_tbl(conn);
|
||||
conn.Meta_tbl_assert(tbl__wiki);
|
||||
}
|
||||
public Xowdir_wiki_tbl Tbl__wiki() {return tbl__wiki;} private final Xowdir_wiki_tbl tbl__wiki;
|
||||
}
|
||||
@@ -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.addons.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
public class Xowdir_wiki_itm {
|
||||
public Xowdir_wiki_itm(int id, String domain, Io_url url, Xowdir_wiki_json json) {
|
||||
this.id = id;
|
||||
this.domain = domain;
|
||||
this.url = url;
|
||||
this.json = json;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Domain() {return domain;} private final String domain;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Xowdir_wiki_json Json() {return json;} private final Xowdir_wiki_json json;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xowdir_wiki_json {
|
||||
public Xowdir_wiki_json(String name, String mainpage) {
|
||||
this.name = name;
|
||||
this.mainpage = mainpage;
|
||||
}
|
||||
public String Name() {return name;} private String name; public void Name_(String v) {name = v;}
|
||||
public String Mainpage() {return mainpage;} private String mainpage; public void Mainpage_(String v) {mainpage = v;}
|
||||
public String To_str(Json_wtr wtr) {
|
||||
wtr.Doc_nde_bgn();
|
||||
|
||||
wtr.Nde_bgn("core");
|
||||
wtr.Kv_str("name", name);
|
||||
wtr.Kv_str("mainpage", mainpage);
|
||||
wtr.Nde_end();
|
||||
|
||||
wtr.Doc_nde_end();
|
||||
return wtr.To_str_and_clear();
|
||||
}
|
||||
|
||||
public static Xowdir_wiki_json New_by_json(Json_parser json_parser, String json) {
|
||||
Json_doc jdoc = json_parser.Parse(json);
|
||||
String name = jdoc.Get_val_as_str_or(Bry_.Ary("core", "name"), "");
|
||||
String mainpage = jdoc.Get_val_as_str_or(Bry_.Ary("core", "mainpage"), "");
|
||||
return new Xowdir_wiki_json(name, mainpage);
|
||||
}
|
||||
public static Xowdir_wiki_json New_dflt() {
|
||||
return new Xowdir_wiki_json("", "Main_Page");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xowdir_wiki_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__wiki_id, fld__wiki_domain, fld__wiki_core_url, fld__wiki_json;
|
||||
private final Db_conn conn;
|
||||
private final Json_parser json_parser = new Json_parser();
|
||||
public Xowdir_wiki_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = Tbl_name_dflt;
|
||||
this.fld__wiki_id = flds.Add_int_pkey("wiki_id");
|
||||
this.fld__wiki_domain = flds.Add_str("wiki_domain", 255); // EX: "en.wikipedia.org"
|
||||
this.fld__wiki_core_url = flds.Add_str("wiki_core_url", 255); // EX: "/xowa/wiki/en.wikipedia.org/en.wikipedia.org-core.xowa"
|
||||
this.fld__wiki_json = flds.Add_text("wiki_json"); // EX: '{category_level="1",search_level="2", ...}'
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public boolean Upsert(int id, String domain, Io_url core_url, String json) {
|
||||
return Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__wiki_id), id, domain, core_url.Xto_api(), json);
|
||||
}
|
||||
public Xowdir_wiki_itm[] Select_all() {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
List_adp list = List_adp_.New();
|
||||
while (rdr.Move_next()) {
|
||||
list.Add(Make(rdr));
|
||||
}
|
||||
return (Xowdir_wiki_itm[])list.To_ary_and_clear(Xowdir_wiki_itm.class);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public Xowdir_wiki_itm Select_by_key_or_null(String key) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__wiki_domain).Crt_str(fld__wiki_domain, key).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Make(rdr) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public Xowdir_wiki_itm Select_by_id_or_null(int id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__wiki_id).Crt_int(fld__wiki_id, id).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Make(rdr) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Delete_by_id(int id) {
|
||||
conn.Stmt_delete(tbl_name, fld__wiki_id).Crt_int(fld__wiki_id, id).Exec_delete();
|
||||
}
|
||||
private Xowdir_wiki_itm Make(Db_rdr rdr) {
|
||||
return new Xowdir_wiki_itm
|
||||
( rdr.Read_int(fld__wiki_id), rdr.Read_str(fld__wiki_domain)
|
||||
, Io_url_.new_fil_(rdr.Read_str(fld__wiki_core_url))
|
||||
, Xowdir_wiki_json.New_by_json(json_parser, rdr.Read_str(fld__wiki_json))
|
||||
);
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
public static final String Tbl_name_dflt = "user_wiki";
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.directorys.specials.items; 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.langs.jsons.*;
|
||||
import gplx.xowa.addons.wikis.directorys.dbs.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xowdir_item_bridge implements Bridge_cmd_itm {
|
||||
private Xowdir_item_mgr itm_mgr;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.itm_mgr = new Xowdir_item_mgr(app);
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__save: itm_mgr.Save(args); break;
|
||||
case Proc__delete: itm_mgr.Delete(args); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static final byte Proc__save = 0, Proc__delete = 1;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("save" , Proc__save)
|
||||
.Add_str_byte("delete" , Proc__delete)
|
||||
;
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("wiki.directory.item");
|
||||
public static final Xowdir_item_bridge Prototype = new Xowdir_item_bridge(); Xowdir_item_bridge() {}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.directorys.specials.items; 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.langs.mustaches.*; import gplx.xowa.addons.wikis.directorys.dbs.*;
|
||||
public class Xowdir_item_doc implements Mustache_doc_itm {
|
||||
private final boolean mode_is_new;
|
||||
private final int id;
|
||||
private final String domain, name, dir, mainpage;
|
||||
public Xowdir_item_doc(int id, String domain, String name, String dir, String mainpage) {
|
||||
this.mode_is_new = id == -1;
|
||||
this.id = id;
|
||||
this.domain = domain;
|
||||
this.name = name;
|
||||
this.dir = dir;
|
||||
this.mainpage = mainpage;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "id")) bfr.Add_int(id);
|
||||
else if (String_.Eq(key, "domain")) bfr.Add_str_u8(domain);
|
||||
else if (String_.Eq(key, "name")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(key, "dir")) bfr.Add_str_u8(dir);
|
||||
else if (String_.Eq(key, "mainpage")) bfr.Add_str_u8(mainpage);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "mode_is_new")) return Mustache_doc_itm_.Ary__bool(mode_is_new);
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
|
||||
public static final Xowdir_item_doc[] Ary_empty = new Xowdir_item_doc[0];
|
||||
public static Xowdir_item_doc New(Xowdir_wiki_itm itm) {return new Xowdir_item_doc(itm.Id(), itm.Domain(), itm.Json().Name(), itm.Url().OwnerDir().Xto_api(), itm.Json().Mainpage());}
|
||||
public static Xowdir_item_doc[] New_ary(Xowdir_wiki_itm[] itms_ary) {
|
||||
int len = itms_ary.length;
|
||||
Xowdir_item_doc[] rv = new Xowdir_item_doc[itms_ary.length];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = New(itms_ary[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.directorys.specials.items; 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.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.wikis.directorys.dbs.*;
|
||||
class Xowdir_item_html extends Xow_special_wtr__base {
|
||||
private final String domain;
|
||||
public Xowdir_item_html(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return Addon_dir(app);}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xowdir_item.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
Db_conn conn = app.User().User_db_mgr().Conn();
|
||||
Xowdir_db_mgr db_mgr = new Xowdir_db_mgr(conn);
|
||||
Xowdir_wiki_itm itm = db_mgr.Tbl__wiki().Select_by_key_or_null(domain);
|
||||
if (itm == null)
|
||||
itm = new Xowdir_wiki_itm(-1, "", Io_url_.Empty, Xowdir_wiki_json.New_dflt());
|
||||
return Xowdir_item_doc.New(itm);
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
|
||||
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
|
||||
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xowdir_item.css")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("bin", "xowdir_item.js")));
|
||||
}
|
||||
public static Io_url Addon_dir(Xoa_app app) {
|
||||
return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "wiki", "directory", "item");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
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.directorys.specials.items; 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.langs.jsons.*;
|
||||
import gplx.dbs.sys.*; import gplx.xowa.addons.wikis.directorys.dbs.*; import gplx.xowa.addons.wikis.directorys.specials.items.bldrs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
class Xowdir_item_mgr {
|
||||
private final Xoa_app app;
|
||||
private final Json_wtr json_wtr = new Json_wtr();
|
||||
private gplx.xowa.guis.cbks.Xog_cbk_trg cbk_trg = gplx.xowa.guis.cbks.Xog_cbk_trg.New(Xowdir_item_special.Prototype.Special__meta().Ttl_bry());
|
||||
public Xowdir_item_mgr(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Save(Json_nde args) {Save(args.Get_as_int("id"), args.Get_as_str("domain"), args.Get_as_str("name"), args.Get_as_str("dir"), args.Get_as_str("mainpage"));}
|
||||
public void Save(int id, String domain, String name, String dir_str, String mainpage_name) {
|
||||
boolean itm_is_new = false;
|
||||
// get next id if none provided
|
||||
if (id == -1) {
|
||||
itm_is_new = true;
|
||||
Db_sys_mgr sys_mgr = new Db_sys_mgr(app.User().User_db_mgr().Conn());
|
||||
id = sys_mgr.Autonum_next("user.wikis.id");
|
||||
}
|
||||
|
||||
Xowdir_db_mgr db_mgr = new Xowdir_db_mgr(app.User().User_db_mgr().Conn());
|
||||
Io_url dir_url = Io_url_.new_dir_infer(dir_str);
|
||||
|
||||
// validate
|
||||
String err_msg = Validate(app, db_mgr, domain, name, dir_url, mainpage_name);
|
||||
if (err_msg != null) {
|
||||
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.wiki_directory.notify__recv", gplx.core.gfobjs.Gfobj_nde.New().Add_str("msg_text", err_msg));
|
||||
return;
|
||||
}
|
||||
|
||||
// upsert into user_db.wiki_list
|
||||
Io_url fil_url = dir_url.GenSubFil(domain + ".xowa");
|
||||
Xowdir_wiki_json json = Xowdir_wiki_json.New_dflt();
|
||||
json.Name_(name);
|
||||
db_mgr.Tbl__wiki().Upsert(id, domain, fil_url, json.To_str(json_wtr));
|
||||
|
||||
if (itm_is_new) {
|
||||
// create the actual wiki
|
||||
byte[] mainpage_text = Io_mgr.Instance.LoadFilBryOr(Xowdir_item_html.Addon_dir(app).GenSubFil_nest("res", "page", "Main_Page.txt"), Bry_.Empty);
|
||||
Xow_db_mkr.Create_wiki(new Xodb_wiki_data(domain, fil_url), Bry_.new_u8(mainpage_name), mainpage_text);
|
||||
|
||||
// load it
|
||||
Xow_wiki_factory.Load_personal((Xoae_app)app, Bry_.new_u8(domain), dir_url);
|
||||
|
||||
// navigate to it
|
||||
app.Gui__cbk_mgr().Send_redirect(cbk_trg, "/site/" + domain + "/wiki/" + mainpage_name);
|
||||
}
|
||||
else {
|
||||
// navigate back to wiki_directory
|
||||
app.Gui__cbk_mgr().Send_redirect(cbk_trg, "/site/home/wiki/Special:XowaWikiDirectory");
|
||||
}
|
||||
}
|
||||
public void Delete(Json_nde args) {Delete(args.Get_as_int("id"));}
|
||||
public void Delete(int id) {
|
||||
// get item by id
|
||||
Xowdir_db_mgr db_mgr = new Xowdir_db_mgr(app.User().User_db_mgr().Conn());
|
||||
Xowdir_wiki_itm itm = db_mgr.Tbl__wiki().Select_by_id_or_null(id);
|
||||
if (itm == null) throw Err_.new_wo_type("wiki does not exist", "id", id);
|
||||
|
||||
// delete it
|
||||
db_mgr.Tbl__wiki().Delete_by_id(id);
|
||||
|
||||
// navigate back to wiki_directory
|
||||
app.Gui__cbk_mgr().Send_redirect(cbk_trg, "/site/home/wiki/Special:XowaWikiDirectory");
|
||||
}
|
||||
private String Validate(Xoa_app app, Xowdir_db_mgr db_mgr, String domain, String name, Io_url dir_url, String mainpage_name) {
|
||||
// domain
|
||||
if (String_.Len_eq_0(domain))
|
||||
return "Domain cannot be empty: " + domain;
|
||||
if (db_mgr.Tbl__wiki().Select_by_key_or_null(domain) != null)
|
||||
return "Domain already exists: " + domain;
|
||||
if (String_.Len(domain) > 63)
|
||||
return "Domain must be 63 characters or less: " + domain;
|
||||
if (!Is_valid_domain_name(Bry_.new_u8(domain)))
|
||||
return "Domain is invalid; can only have letters, numbers, or a dot. If a dash exists, it cannot be at the start or the end: " + domain ;
|
||||
|
||||
// name
|
||||
if (String_.Len_eq_0(name))
|
||||
return "Name cannot be empty: " + name;
|
||||
if (String_.Len(name) > 255)
|
||||
return "Name must: be 255 characters or less: " + name;
|
||||
|
||||
// dir
|
||||
String dir_str = dir_url.Raw();
|
||||
if (String_.Len_eq_0(dir_str))
|
||||
return "Folder cannot be empty: " + dir_str;
|
||||
Io_mgr.Instance.CreateDirIfAbsent(dir_url);
|
||||
if (!Io_mgr.Instance.ExistsDir(dir_url))
|
||||
return "Folder could not be created: " + dir_str;
|
||||
|
||||
// mainpage_name
|
||||
byte[] mainpage_name_bry = Bry_.new_u8(mainpage_name);
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(app.User().Wikii(), mainpage_name_bry);
|
||||
if (ttl == null)
|
||||
return "Main Page has invalid characters. Please see the new wiki help page for more info: " + mainpage_name;
|
||||
|
||||
Bry_bfr tmp = Bry_bfr_.New();
|
||||
byte[] ucase_1st = app.User().Wikii().Lang().Case_mgr().Case_build_1st_upper(tmp, mainpage_name_bry, 0, mainpage_name_bry.length);
|
||||
if (!Bry_.Eq(mainpage_name_bry, ucase_1st))
|
||||
return "Main Page must start with an uppercase letter.";
|
||||
|
||||
// valid returns null
|
||||
return null;
|
||||
}
|
||||
private static boolean Is_valid_domain_name(byte[] src) {
|
||||
int len = src.length;
|
||||
if (len > 63) return false;
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte b = src[i];
|
||||
// alpha-num is valid
|
||||
if (Byte_ascii.Is_ltr(b) || Byte_ascii.Is_num(b))
|
||||
continue;
|
||||
|
||||
// hyphens are only valid at start or end
|
||||
if (b == Byte_ascii.Dash) {
|
||||
if (i != 0 || i != len - 1)
|
||||
continue;
|
||||
}
|
||||
|
||||
// allow dots; EX: en.wikipedia.org
|
||||
if (b == Byte_ascii.Dot)
|
||||
continue;
|
||||
|
||||
// else, invalid
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.directorys.specials.items; 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.specials.*; import gplx.core.net.qargs.*;
|
||||
public class Xowdir_item_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
|
||||
String domain = url_args.Read_str_or("domain", "");
|
||||
|
||||
new Xowdir_item_html(domain).Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
Xowdir_item_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xowdir_item_special(Xow_special_meta.New_xo("XowaWikiItem", "Wiki Details"));
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.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.core.ios.streams.*;
|
||||
public class Xodb_wiki_data {
|
||||
public Xodb_wiki_data(String domain, Io_url core_url) {
|
||||
this.domain = domain;
|
||||
this.core_url = core_url;
|
||||
}
|
||||
public String Domain() {return domain;} private final String domain;
|
||||
public Io_url Core_url() {return core_url;} private final Io_url core_url;
|
||||
public byte Text_zip_tid() {return text_zip_tid;} private byte text_zip_tid = Io_stream_tid_.Tid__raw;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.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.*;
|
||||
public class Xodb_wiki_db implements Db_tbl_owner {
|
||||
private final Ordered_hash tbls = Ordered_hash_.New();
|
||||
public Xodb_wiki_db(int tid, Io_url url, Db_conn conn) {
|
||||
this.tid = tid;
|
||||
this.url = url;
|
||||
this.conn = conn;
|
||||
}
|
||||
public int Tid() {return tid;} private final int tid;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Db_tbl Tbls__get_by_key(String key) {return (Db_tbl)tbls.Get_by(key);}
|
||||
public void Tbls__add(boolean create, Db_tbl... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_tbl tbl = ary[i];
|
||||
tbls.Add(tbl.Tbl_name(), tbl);
|
||||
if (create)
|
||||
tbl.Create_tbl();
|
||||
}
|
||||
}
|
||||
|
||||
public static Xodb_wiki_db Make(int tid, Io_url url) {
|
||||
Db_conn conn = Db_conn_bldr.Instance.Get_or_new(url).Conn();
|
||||
return new Xodb_wiki_db(tid, url, conn);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.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.*;
|
||||
public class Xodb_wiki_db_tid {
|
||||
public static final int Tid__core = 0;
|
||||
}
|
||||
@@ -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.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.*;
|
||||
public class Xodb_wiki_mgr {
|
||||
public Xodb_wiki_mgr(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
public String Domain() {return domain;} private final String domain;
|
||||
public Xodb_wiki_db Dbs__get_core() {return dbs__core;} private Xodb_wiki_db dbs__core;
|
||||
public void Dbs__add(Xodb_wiki_db file) {
|
||||
if (file.Tid() == Xodb_wiki_db_tid.Tid__core)
|
||||
dbs__core = file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.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.dbs.cfgs.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
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);
|
||||
|
||||
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);
|
||||
byte[] text_zip = text_tbl.Zip(text_raw);
|
||||
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);
|
||||
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);
|
||||
} finally {
|
||||
page_tbl.Insert_end();
|
||||
text_tbl.Insert_end();
|
||||
}
|
||||
return page_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
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.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.dbs.cfgs.*; import gplx.dbs.sys.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.site_stats.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.addons.wikis.directorys.dbs.*;
|
||||
public class Xow_db_mkr {
|
||||
public static Xodb_wiki_mgr Create_wiki(Xodb_wiki_data data, byte[] mainpage_name, byte[] mainpage_text) {
|
||||
// create db
|
||||
Xodb_wiki_mgr wiki_mgr = new Xodb_wiki_mgr(data.Domain());
|
||||
wiki_mgr.Dbs__add(Xodb_wiki_db.Make(Xodb_wiki_db_tid.Tid__core, data.Core_url()));
|
||||
|
||||
// create tbls: wiki
|
||||
Xodb_wiki_db core_db = wiki_mgr.Dbs__get_core();
|
||||
Db_conn core_conn = core_db.Conn();
|
||||
core_db.Tbls__add(Bool_.Y
|
||||
, Xowd_cfg_tbl_.New(core_conn)
|
||||
, new Xowd_xowa_db_tbl(core_conn, Bool_.N)
|
||||
, new Xowd_site_ns_tbl(core_conn, Bool_.N)
|
||||
, new Xowd_site_stats_tbl(core_conn, Bool_.N)
|
||||
, new Xowd_page_tbl(core_conn, Bool_.N)
|
||||
, new Xowd_text_tbl(core_conn, Bool_.N, data.Text_zip_tid())
|
||||
);
|
||||
|
||||
// create tbls: cat; may want to do "if (props.Layout_text().Tid_is_all_or_few())" // create in advance else will fail for v2; import wiki -> wiki loads and tries to load categories; v2 category processes and builds tbl; DATE:2015-03-22
|
||||
core_db.Tbls__add(Bool_.Y
|
||||
, new Xowd_cat_core_tbl(core_conn, Bool_.N)
|
||||
, new Xowd_cat_link_tbl(core_conn, Bool_.N)
|
||||
);
|
||||
|
||||
// insert data: wiki
|
||||
Xowd_xowa_db_tbl.Get_by_key(core_db).Upsert(0, Xow_db_file_.Tid__core, core_db.Url().NameAndExt(), "", -1, Guid_adp_.New_str());
|
||||
Xowd_site_ns_tbl.Get_by_key(core_db).Insert(Xow_ns_mgr_.default_(Xol_case_mgr_.U8()));
|
||||
Xowd_site_stats_tbl.Get_by_key(core_db).Update(0, 0, 0);
|
||||
|
||||
// insert data: cfg
|
||||
Db_cfg_tbl cfg_tbl = Db_cfg_tbl.Get_by_key(core_db, Xowd_cfg_tbl_.Tbl_name);
|
||||
Xowd_core_db_props props = new Xowd_core_db_props(2, Xow_db_layout.Itm_all, Xow_db_layout.Itm_all, Xow_db_layout.Itm_all, Io_stream_tid_.Tid__raw, Io_stream_tid_.Tid__raw, Bool_.N, Bool_.N);
|
||||
props.Cfg_save(cfg_tbl);
|
||||
cfg_tbl.Insert_str(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__modified_latest, Datetime_now.Get().XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
|
||||
// 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);
|
||||
|
||||
// create tbls: fsdb
|
||||
core_db.Tbls__add(Bool_.Y
|
||||
, new Fsm_mnt_tbl(core_conn, Bool_.N)
|
||||
, new Fsm_atr_tbl(core_conn, Bool_.N)
|
||||
, new Fsm_bin_tbl(core_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main)
|
||||
, new Fsd_dir_tbl(core_conn, Bool_.N)
|
||||
, new Fsd_fil_tbl(core_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main)
|
||||
, new Fsd_thm_tbl(core_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main, Bool_.Y)
|
||||
, new Xof_orig_tbl(core_conn, Bool_.N)
|
||||
);
|
||||
|
||||
// insert data: fsdb
|
||||
Fsm_mnt_mgr.Patch_core(cfg_tbl);
|
||||
Fsm_atr_tbl.Get_by_key(core_db).Insert(Fsm_mnt_mgr.Mnt_idx_main, core_db.Url().NameAndExt());
|
||||
cfg_tbl.Insert_int("core", "mnt.insert_idx", Fsm_mnt_mgr.Mnt_idx_user);
|
||||
|
||||
return wiki_mgr;
|
||||
}
|
||||
}
|
||||
/*
|
||||
xowa_cfg
|
||||
xowa_db
|
||||
site_ns
|
||||
site_stats
|
||||
|
||||
page
|
||||
text
|
||||
|
||||
cat_core
|
||||
cat_link
|
||||
|
||||
fsdb_mnt
|
||||
fsdb_dba
|
||||
fsdb_dbb
|
||||
fsdb_dir
|
||||
fsdb_fil
|
||||
fsdb_thm
|
||||
orig_reg
|
||||
|
||||
search_link
|
||||
search_link_reg
|
||||
search_word
|
||||
|
||||
css_core
|
||||
css_file
|
||||
*/
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.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.*;
|
||||
public class Xow_wiki_factory {
|
||||
public static Xowe_wiki Load_personal(Xoae_app app, byte[] domain, Io_url dir_url) {
|
||||
// create the rv
|
||||
Xowe_wiki rv = new Xowe_wiki
|
||||
( app
|
||||
, gplx.xowa.langs.Xol_lang_itm_.Lang_en_make(app.Lang_mgr())
|
||||
, gplx.xowa.wikis.nss.Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.U8())
|
||||
, gplx.xowa.wikis.domains.Xow_domain_itm_.parse(domain)
|
||||
, dir_url);
|
||||
|
||||
// register it in app.Wikis; note that this must occur before initialization
|
||||
app.Wiki_mgr().Add(rv);
|
||||
|
||||
// do more initialization
|
||||
rv.Init_by_wiki__force_and_mark_inited();
|
||||
rv.Db_mgr_as_sql().Save_mgr().Create_enabled_(true);
|
||||
|
||||
// register it for the url-bar; EX: test.me.org/wiki/Main_Page
|
||||
app.User().Wikii().Xwiki_mgr().Add_by_atrs(domain, domain);
|
||||
|
||||
// add an xwiki to xowa.home
|
||||
rv.Xwiki_mgr().Add_by_atrs("xowa.home", "home");
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.directorys.specials.lists; 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.langs.mustaches.*;
|
||||
import gplx.xowa.addons.wikis.directorys.specials.items.*;
|
||||
class Xowdir_list_doc implements Mustache_doc_itm {
|
||||
private final Xowdir_item_doc[] itms_ary;
|
||||
public Xowdir_list_doc(Xowdir_item_doc[] itms_ary) {
|
||||
this.itms_ary = itms_ary;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "itms")) return itms_ary;
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
@@ -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.addons.wikis.directorys.specials.lists; 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.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.wikis.directorys.dbs.*; import gplx.xowa.addons.wikis.directorys.specials.items.*;
|
||||
class Xowdir_list_html extends Xow_special_wtr__base {
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "wiki", "directory", "list");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xowdir_list.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
Db_conn conn = app.User().User_db_mgr().Conn();
|
||||
Xowdir_db_mgr db_mgr = new Xowdir_db_mgr(conn);
|
||||
Xowdir_wiki_itm[] itms_ary = db_mgr.Tbl__wiki().Select_all();
|
||||
return new Xowdir_list_doc(Xowdir_item_doc.New_ary(itms_ary));
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
|
||||
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xowdir_list.css")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("bin", "xowdir_list.js")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.directorys.specials.lists; 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.specials.*; import gplx.core.net.qargs.*;
|
||||
public class Xowdir_list_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
new Xowdir_list_html().Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
Xowdir_list_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xowdir_list_special(Xow_special_meta.New_xo("XowaWikiDirectory", "Wiki List"));
|
||||
}
|
||||
Reference in New Issue
Block a user