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

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-19 23:58:10 -04:00
parent 96636f3161
commit d4e8590345
1960 changed files with 20790 additions and 9272 deletions

View File

@@ -0,0 +1,29 @@
/*
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.registrys; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
import gplx.xowa.specials.*;
public class Wiki_registry_addon implements Xoax_addon_itm, Xoax_addon_itm__special {
public Xow_special_page[] Special_pages() {
return new Xow_special_page[]
{ gplx.xowa.addons.wikis.registrys.lists.Xow_list_special.Prototype
, gplx.xowa.addons.wikis.registrys.infos.Xow_info_special.Prototype
};
}
public String Addon__key() {return "xowa.apps.wikis.registrys";}
}

View File

@@ -0,0 +1,44 @@
/*
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.registrys.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.registrys.*;
import gplx.langs.mustaches.*;
class Xow_info_doc implements Mustache_doc_itm {
private final Mustache_doc_itm[] ary;
public Xow_info_doc(Xow_info_doc_wiki itm) {this.ary = new Mustache_doc_itm[] {itm};}
public boolean Mustache__write(String key, Mustache_bfr bfr) {return false;}
public Mustache_doc_itm[] Mustache__subs(String key) {
if (String_.Eq(key, "wiki_info")) return ary;
return Mustache_doc_itm_.Ary__empty;
}
}
class Xow_info_doc_wiki implements Mustache_doc_itm {
private final byte[] domain;
private final String date, size, dir;
public Xow_info_doc_wiki(byte[] domain, String date, String dir, String size) {
this.domain = domain; this.date = date; this.dir = dir; this.size = size;
}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "wiki_domain")) bfr.Add_bry(domain);
else if (String_.Eq(key, "wiki_date")) bfr.Add_str_u8(date);
else if (String_.Eq(key, "wiki_dir")) bfr.Add_str_u8(dir);
else if (String_.Eq(key, "wiki_size")) bfr.Add_str_u8(size);
else return false;
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {return Mustache_doc_itm_.Ary__empty;}
}

View File

@@ -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.registrys.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.registrys.*;
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
import gplx.xowa.users.data.*;
class Xow_info_html extends Xow_special_wtr__base {
private final byte[] wiki_domain;
public Xow_info_html(byte[] wiki_domain) {this.wiki_domain = wiki_domain;}
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "wiki", "registry", "info");}
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xow_info.mustache.html");}
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
// load itm from db
app.User().User_db_mgr().Init_site_mgr(); // HACK.USER_DB: init site_mgr for desktop
Xoud_site_row site_itm = app.User().User_db_mgr().Site_mgr().Select_by_domain(wiki_domain);
if (site_itm == null) return null; // handle deleted wikis
String wiki_dir = site_itm.Path();
if (String_.Eq(site_itm.Date(), "")) {
Xow_wiki wiki = app.Wiki_mgri().Get_by_or_make_init_n(wiki_domain);
wiki.Init_by_wiki(); // force init to load Modified_latest
site_itm.Date_(wiki.Props().Modified_latest__yyyy_MM_dd());
app.User().User_db_mgr().Site_mgr().Update(site_itm);
}
return new Xow_info_doc
( new Xow_info_doc_wiki(wiki_domain, site_itm.Date(), wiki_dir
, Calc_file_size(Io_url_.new_dir_(wiki_dir)))
);
}
@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_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xow_info.css")));
}
@Override protected void Handle_invalid(Xoa_app app, Xoa_page page, Xow_special_page special) {
new Xopage_html_data(special.Special__meta().Display_ttl(), Bry_.Add(wiki_domain, Bry_.new_a7(" has been deleted"))).Apply(page);
}
private static String Calc_file_size(Io_url dir) {
Io_url[] urls = Io_mgr.Instance.QueryDir_fils(dir);
int len = urls.length;
long size = 0;
for (int i = 0; i < len; ++i) {
Io_url url = urls[i];
size += Io_mgr.Instance.QueryFil(url).Size();
}
return gplx.core.ios.Io_size_.To_str_new(Bry_bfr_.New(), size, 2);
}
}

View File

@@ -0,0 +1,61 @@
/*
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.registrys.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.registrys.*;
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
public class Xow_info_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());
// if cmd=delete passed; delete "wiki"
byte[] wiki_domain = url_args.Read_bry_or_fail("wiki");
if (url_args.Read_enm_as_int_or(Enm_cmd.Itm, -1) == Enm_cmd.Tid__delete) {
wiki.App().User().User_db_mgr().Site_mgr().Delete_by_domain(wiki_domain);
Xow_wiki delete_wiki = wiki.App().Wiki_mgri().Get_by_or_make_init_n(wiki_domain);
if (delete_wiki != null) { // guard against revisiting url for deleted wiki
if (delete_wiki.Data__core_mgr() != null) // null check needed in case wiki is not loaded
delete_wiki.Data__core_mgr().Rls(); // release connection if open
Delete_wiki_files(delete_wiki.Fsys_mgr().Root_dir());
}
page.Redirect_to_ttl_(gplx.xowa.addons.wikis.registrys.lists.Xow_list_special.Prototype.Special__meta().Ttl_bry());
return;
}
// show info of wikis
new Xow_info_html(wiki_domain).Bld_page_by_mustache(wiki.App(), page, this);
}
private static void Delete_wiki_files(Io_url root_dir) {
Io_url[] urls = Io_mgr.Instance.QueryDir_fils(root_dir);
for (Io_url url : urls) {
try {
Io_mgr.Instance.DeleteFil(url);
} catch (Exception e) {
Gfo_log_.Instance.Warn("failed to delete wiki file", "wiki", url.Raw(), "err", Err_.Message_gplx_log(e));
}
}
}
static class Enm_cmd {//#*nested
public static final int Tid__delete = 0;
public static final Gfo_qarg_enum_itm Itm = new Gfo_qarg_enum_itm("cmd").Add("delete", Tid__delete);
}
Xow_info_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 Xow_info_special(Xow_special_meta.New_xo("XowaWikiInfo", "Wiki Info"));
}

View File

@@ -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.registrys.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.registrys.*;
import gplx.langs.mustaches.*;
class Xow_list_doc implements Mustache_doc_itm {
private final byte[] import_root;
private final Xow_list_doc_wiki[] subs;
public Xow_list_doc(byte[] import_root, Xow_list_doc_wiki[] subs) {this.import_root = import_root; this.subs = subs;}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "import_root")) bfr.Add_bry(import_root);
return false;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
if (String_.Eq(key, "subs")) return subs;
return Mustache_doc_itm_.Ary__empty;
}
}
class Xow_list_doc_wiki implements Mustache_doc_itm {
private final byte[] domain;
private final String date;
public Xow_list_doc_wiki(byte[] domain, String date) {
this.domain = domain; this.date = date;
}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "domain")) bfr.Add_bry(domain);
else if (String_.Eq(key, "date")) bfr.Add_str_u8(date);
else return false;
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {return Mustache_doc_itm_.Ary__empty;}
}

View File

@@ -0,0 +1,53 @@
/*
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.registrys.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.registrys.*;
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.users.data.*;
class Xow_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", "registry", "list");}
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xow_list.mustache.html");}
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
// make list_mgr based on site_wikis
List_adp list = List_adp_.New();
app.User().User_db_mgr().Init_site_mgr();
Xoud_site_row[] site_ary = app.User().User_db_mgr().Site_mgr().Get_all();
int len = site_ary.length;
for (int i = 0; i < len; ++i) {
Xoud_site_row site_itm = site_ary[i];
if (String_.Eq(site_itm.Domain(), gplx.xowa.wikis.domains.Xow_domain_itm_.Str__home)) continue;
list.Add(new Xow_list_doc_wiki(Bry_.new_u8(site_itm.Domain()), site_itm.Date()));
}
return new Xow_list_doc(Get_root_url(), (Xow_list_doc_wiki[])list.To_ary_and_clear(Xow_list_doc_wiki.class));
}
@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());
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xow_list.css")));
}
private static byte[] Get_root_url() {
byte tid = gplx.core.envs.Op_sys.Cur().Tid();
byte[] rv = Bry_.new_a7("/");
switch (tid) {
case gplx.core.envs.Op_sys.Tid_wnt : rv = Bry_.new_a7("C:\\"); break;
}
rv = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(rv);
return rv;
}
}

View File

@@ -0,0 +1,44 @@
/*
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.registrys.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.registrys.*;
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
public class Xow_list_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());
// if cmd=add passed; import "file"; occurs when "file" is selected by file_browser
if (url_args.Read_enm_as_int_or(Enm_cmd.Itm, -1) == Enm_cmd.Tid__add) {
byte[] file = url_args.Read_bry_or_fail("file");
if (wiki.App().Tid_is_edit()) wiki.App().User().User_db_mgr().Init_site_mgr(); // HACK.USER_DB: init site_mgr for desktop
wiki.App().Wiki_mgri().Import_by_url(Io_url_.new_fil_(String_.new_u8(file)));
}
// show list of wikis
new Xow_list_html().Bld_page_by_mustache(wiki.App(), page, this);
}
static class Enm_cmd {//#*nested
public static final int Tid__add = 0;
public static final Gfo_qarg_enum_itm Itm = new Gfo_qarg_enum_itm("cmd").Add("add", Tid__add);
}
Xow_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 Xow_list_special(Xow_special_meta.New_xo("XowaWikiList", "Wikis", "XowaWikis"));
}