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

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

View File

@@ -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.bldrs.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.bldrs.wkrs.*;
public class Html__dump_to_fsys__addon implements Xoax_addon_itm, Xoax_addon_itm__bldr {
public Xob_cmd[] Bldr_cmds() {
return new Xob_cmd[]
{ Html__dump_to_fsys__cmd.Prototype
};
}
public String Addon__key() {return "xowa.builds.htmls";}
}

View File

@@ -0,0 +1,88 @@
/*
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.bldrs.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.xowa.files.*;
import gplx.langs.mustaches.*;
import gplx.xowa.wikis.pages.*;
public class Html__dump_to_fsys__cmd extends Xob_cmd__base {
private Io_url template_url, fsys_root;
private byte[] http_root, page_root;
private boolean skip_unchanged = true;
public Html__dump_to_fsys__cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
// init mustache
Mustache_tkn_parser parser = new Mustache_tkn_parser();
Mustache_tkn_itm root = parser.Parse(Io_mgr.Instance.LoadFilBry(template_url));
Mustache_render_ctx ctx = new Mustache_render_ctx();
Bry_bfr bfr = Bry_bfr_.New();
Mustache_bfr mbfr = new Mustache_bfr(bfr);
Html_page_itm page_itm = new Html_page_itm();
// load rdr
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.File_dump(page_root, Bry_.new_a7(".html"));
wiki.Init_assert();
gplx.xowa.wikis.data.tbls.Xowd_page_tbl page_tbl = wiki.Data__core_mgr().Db__core().Tbl__page();
Db_conn conn = page_tbl.Conn();
Db_rdr rdr = conn.Exec_rdr("SELECT page_id, page_title, page_touched FROM page WHERE page_namespace = 0;");
while (rdr.Move_next()) {
String page_ttl_str = rdr.Read_str("page_title");
try {
// load page
Xoa_ttl page_ttl = wiki.Ttl_parse(Bry_.new_u8(page_ttl_str));
DateAdp page_modified_on = DateAdp_.parse_fmt(rdr.Read_str("page_touched"), gplx.xowa.wikis.data.tbls.Xowd_page_tbl.Page_touched_fmt);
Io_url dump_fil_url = Io_url_.new_fil_(fsys_root.Gen_sub_path_for_os(page_ttl_str) + ".html");
if (skip_unchanged && Io_mgr.Instance.QueryFil(dump_fil_url).ModifiedTime().Eq(page_modified_on)) continue;
// parse page
Xoae_page page = wiki.Data_mgr().Load_page_and_parse(wiki.Utl__url_parser().Parse(page_ttl.Page_db()), page_ttl);
wiki.Parser_mgr().Parse(page, true);
page.Wikie().Html_mgr().Page_wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
page.Wikie().Html_mgr().Page_wtr_mgr().Wkr(gplx.xowa.wikis.pages.Xopg_page_.Tid_read).Write_body(bfr, wiki.Parser_mgr().Ctx(), hctx, page);
byte[] html_src = bfr.To_bry_and_clear();//page.Wikie().Html_mgr().Page_wtr_mgr().Gen(page, gplx.xowa.wikis.pages.Xopg_page_.Tid_read); // NOTE: must use wiki of page, not of owner tab; DATE:2015-03-05
byte[] html_head = page.Html_data().Custom_head_tags().To_html__style(bfr);
// fmt with mustache; write to file
page_itm.Init(http_root, page_root, page_ttl.Page_txt(), html_head, Bry_.Empty, html_src);
root.Render(mbfr, ctx.Init(page_itm));
Io_mgr.Instance.SaveFilBry(dump_fil_url, mbfr.To_bry_and_clear());
Io_mgr.Instance.UpdateFilModifiedTime(dump_fil_url, page_modified_on);
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "err: ~{0}", Err_.Message_gplx_log(e));
}
}
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__template_url_)) this.template_url = m.ReadIoUrl("v");
else if (ctx.Match(k, Invk__fsys_root_)) this.fsys_root = m.ReadIoUrl("v");
else if (ctx.Match(k, Invk__http_root_)) this.http_root = m.ReadBry("v");
else if (ctx.Match(k, Invk__page_root_)) this.page_root = m.ReadBry("v");
else if (ctx.Match(k, Invk__skip_unchanged_)) this.skip_unchanged = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk__template_url_ = "template_url_", Invk__fsys_root_ = "fsys_root_"
, Invk__http_root_ = "http_root_", Invk__page_root_ = "page_root_"
, Invk__skip_unchanged_ = "skip_unchanged_";
public static final String BLDR_CMD_KEY = "html.dump_to_file";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Html__dump_to_fsys__cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Html__dump_to_fsys__cmd(bldr, wiki);}
}

View File

@@ -0,0 +1,49 @@
/*
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.bldrs.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.langs.mustaches.*;
class Html_page_itm implements Mustache_doc_itm {
private byte[] http_root;
private byte[] page_root;
private byte[] page_title;
private byte[] page_head_extra;
private byte[] page_caption;
private byte[] page_body;
public Html_page_itm Init(byte[] http_root, byte[] page_root, byte[] page_title, byte[] page_head_extra, byte[] page_caption, byte[] page_body) {
this.http_root = http_root;
this.page_root = page_root;
this.page_title = page_title;
this.page_head_extra = page_head_extra;
this.page_caption = page_caption;
this.page_body = page_body;
return this;
}
public boolean Mustache__write(String key, Mustache_bfr mbfr) {
if (String_.Eq(key, "page_title")) mbfr.Add_bry(page_title);
else if (String_.Eq(key, "http_root")) mbfr.Add_bry(http_root);
else if (String_.Eq(key, "page_root")) mbfr.Add_bry(page_root);
else if (String_.Eq(key, "page_head_extra")) mbfr.Add_bry(page_head_extra);
else if (String_.Eq(key, "page_caption")) mbfr.Add_bry(page_caption);
else if (String_.Eq(key, "page_body")) mbfr.Add_bry(page_body);
else return false;
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
return Mustache_doc_itm_.Ary__empty;
}
}