1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-29 23:10:52 +00:00

'v3.4.3.1'

This commit is contained in:
gnosygnu 2016-04-17 23:47:45 -04:00
parent 14471ca656
commit ad140a93fe
102 changed files with 1278 additions and 382 deletions

View File

@ -265,6 +265,12 @@ public class Bry_ {
} }
return true; return true;
} }
public static boolean Has_at_end(byte[] src, byte lkp) {
if (src == null) return false;
int src_len = src.length;
if (src_len == 0) return false;
return src[src_len - 1] == lkp;
}
public static boolean Has_at_end(byte[] src, byte[] lkp) {int src_len = src.length; return Has_at_end(src, lkp, src_len - lkp.length, src_len);} public static boolean Has_at_end(byte[] src, byte[] lkp) {int src_len = src.length; return Has_at_end(src, lkp, src_len - lkp.length, src_len);}
public static boolean Has_at_end(byte[] src, byte[] lkp, int src_bgn, int src_end) { public static boolean Has_at_end(byte[] src, byte[] lkp, int src_bgn, int src_end) {
int lkp_len = lkp.length; int lkp_len = lkp.length;
@ -585,6 +591,9 @@ public class Bry_ {
else if (b2 != 0) return new byte[] {b2, b3}; else if (b2 != 0) return new byte[] {b2, b3};
else return new byte[] {b3}; else return new byte[] {b3};
} }
public static boolean To_bool_or(byte[] raw, boolean or) {
return Bry_.Eq(raw, Bool_.True_bry) ? true : or;
}
public static boolean To_bool_by_int(byte[] ary) { public static boolean To_bool_by_int(byte[] ary) {
int rv = To_int_or(ary, 0, ary.length, Int_.Min_value, Bool_.Y, null); int rv = To_int_or(ary, 0, ary.length, Int_.Min_value, Bool_.Y, null);
switch (rv) { switch (rv) {

View File

@ -21,8 +21,8 @@ public interface GfoInvkAble {
} }
/* /*
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) {} if (ctx.Match(k, Invk__set)) {}
else return GfoInvkAble_.Rv_unhandled; else return GfoInvkAble_.Rv_unhandled;
return this; return this;
} private static final String Invk_set = "set"; } private static final String Invk__set = "set";
*/ */

View File

@ -15,11 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*; package gplx.core.brys; import gplx.*; import gplx.core.*;
import gplx.xowa.wikis.data.tbls.*; public interface Bry_bfr_able {
interface Xowd_page_cmd { void To_bfr(Bry_bfr bfr);
String Cmd_key();
void Cmd_bgn(Xob_bldr bldr);
void Cmd_run(Xowd_page_itm page);
void Cmd_end();
} }

View File

@ -0,0 +1,37 @@
/*
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.core.brys; import gplx.*; import gplx.core.*;
public class Bry_bfr_able_ {
public static byte[][] To_bry_ary(Bry_bfr tmp_bfr, Bry_bfr_able[] ary) {
int len = ary.length;
byte[][] rv = new byte[len][];
for (int i = 0; i < len; ++i) {
Bry_bfr_able itm = ary[i];
if (itm != null) {
itm.To_bfr(tmp_bfr);
rv[i] = tmp_bfr.To_bry_and_clear();
}
}
return rv;
}
public static byte[] To_bry_or_null(Bry_bfr tmp_bfr, Bry_bfr_able itm) {
if (itm == null) return null;
itm.To_bfr(tmp_bfr);
return tmp_bfr.To_bry_and_clear();
}
}

View File

@ -0,0 +1,102 @@
/*
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.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.brys.*;
public class Gftest {
private static Bry_bfr bfr = Bry_bfr.new_();
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary) {Eq__ary(expd_ary, actl_ary, null);}
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary, String msg_fmt, Object... msg_args) {
byte[][] expd_bry_ary = Bry_bfr_able_.To_bry_ary(bfr, expd_ary);
byte[][] actl_bry_ary = Bry_bfr_able_.To_bry_ary(bfr, actl_ary);
boolean[] failures = Calc__failures(Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
if (failures != null) {
bfr.Add(Bry__line_bgn);
if (msg_fmt != null) {
bfr.Add_str_u8(String_.Format(msg_fmt, msg_args));
bfr.Add(Bry__line_mid);
}
Write__failures(bfr, failures, Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
}
private static void Write__failures(Bry_bfr bfr, boolean[] failures, int type_id, Object expd_ary, Object actl_ary) {
int len = failures.length;
int expd_len = Array_.Len(expd_ary);
int actl_len = Array_.Len(actl_ary);
for (int i = 0; i < len; ++i) {
boolean failure = failures[i];
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, 5 - Int_.DigitCount(i), i).Add_byte_colon().Add_byte_space();
Write__itm(bfr, type_id, expd_ary, expd_len, i);
if (failure) {
bfr.Add(Bry__item__eq_n).Add_byte_repeat(Byte_ascii.Space, 3);
Write__itm(bfr, type_id, actl_ary, actl_len, i);
}
}
bfr.Add(Bry__line_end);
}
private static void Write__itm(Bry_bfr bfr, int type_id, Object ary, int len, int idx) {
if (idx < len) {
switch (type_id) {
case Type_adp_.Tid__bry: bfr.Add((byte[])Array_.Get_at(ary, idx)); break;
default: throw Err_.new_unhandled_default(type_id);
}
}
else
bfr.Add(Bry__null);
bfr.Add_byte_nl();
}
private static boolean[] Calc__failures(int tid, Object expd_ary, Object actl_ary) {
int expd_len = Array_.Len(expd_ary);
int actl_len = Array_.Len(actl_ary);
int max_len = expd_len > actl_len ? expd_len : actl_len; if (max_len == 0) return null;
boolean[] rv = null;
for (int i = 0; i < max_len; ++i) {
Object expd_obj = i < expd_len ? Array_.Get_at(expd_ary, i) : null;
Object actl_obj = i < actl_len ? Array_.Get_at(actl_ary, i) : null;
boolean eq = false;
switch (tid) {
case Type_adp_.Tid__bry: eq = Bry_.Eq((byte[])expd_obj, (byte[])actl_obj); break;
}
if (!eq) {
if (rv == null) {
rv = new boolean[max_len];
}
rv[i] = true;
}
}
return rv;
}
private static final byte[] Bry__item__eq_n = Bry_.new_a7("!= ") // Bry__item__eq_y = Bry_.new_a7("== "),
, Bry__null = Bry_.new_a7("<<NULL>>")
, Bry__line_bgn = Bry_.new_a7("\n************************************************************************************************\n")
, Bry__line_mid = Bry_.new_a7("\n------------------------------------------------------------------------------------------------\n")
, Bry__line_end = Bry_.new_a7( "________________________________________________________________________________________________")
;
}
/*
package ns;
import org.junit.*; import gplx.core.tests.*;
public class Cls1_tst {
private final Cls1_fxt fxt = new Cls1_fxt();
@Test public void Basic() {}
}
class Cls1_fxt {
private final Cls1 mgr = new Cls1();
public Cls1_fxt Test() {return this;}
}
*/

View File

@ -66,6 +66,7 @@ public class Db_cfg_tbl implements Rls_able {
public void Upsert_int (String grp, String key, int val) {Upsert_str(grp, key, Int_.To_str(val));} public void Upsert_int (String grp, String key, int val) {Upsert_str(grp, key, Int_.To_str(val));}
public void Upsert_date (String grp, String key, DateAdp val) {Upsert_str(grp, key, val.XtoStr_fmt_yyyyMMdd_HHmmss());} public void Upsert_date (String grp, String key, DateAdp val) {Upsert_str(grp, key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public void Upsert_guid (String grp, String key, Guid_adp val) {Upsert_str(grp, key, val.To_str());} public void Upsert_guid (String grp, String key, Guid_adp val) {Upsert_str(grp, key, val.To_str());}
public void Upsert_bry (String grp, String key, byte[] val) {Upsert_str(grp, key, String_.new_u8(val));}
public void Upsert_str (String grp, String key, String val) { public void Upsert_str (String grp, String key, String val) {
String cur_val = this.Select_str_or(grp, key, null); String cur_val = this.Select_str_or(grp, key, null);
if (cur_val == null) this.Insert_str(grp, key, val); if (cur_val == null) this.Insert_str(grp, key, val);

View File

@ -43,6 +43,10 @@ public class Gfh_tag_ {
, Bry__ul = Bry_.new_a7("ul") , Bry__ul = Bry_.new_a7("ul")
, Bry__td = Bry_.new_a7("td") , Bry__td = Bry_.new_a7("td")
, Bry__th = Bry_.new_a7("th") , Bry__th = Bry_.new_a7("th")
, Bry__div = Bry_.new_a7("div")
, Bry__link = Bry_.new_a7("link")
, Bry__style = Bry_.new_a7("style")
, Bry__script = Bry_.new_a7("script")
; ;
public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7() public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
.Add_bry_int(Bry__a , Id__a) .Add_bry_int(Bry__a , Id__a)

View File

@ -34,7 +34,7 @@ public class Xoa_app_ {
} }
} }
public static final String Name = "xowa"; public static final String Name = "xowa";
public static final String Version = "3.4.2.1"; public static final String Version = "3.4.3.1";
public static String Build_date = "2012-12-30 00:00:00"; public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys_str; public static String Op_sys_str;
public static String User_agent = ""; public static String User_agent = "";

View File

@ -47,7 +47,7 @@ public class Xowe_wiki implements Xow_wiki, GfoInvkAble, GfoEvObj {
file_mgr = new Xow_file_mgr(this); file_mgr = new Xow_file_mgr(this);
parser_mgr = new Xow_parser_mgr(this); parser_mgr = new Xow_parser_mgr(this);
cfg_parser = new Xowc_parser(this); cfg_parser = new Xowc_parser(this);
props.SiteName_(domain_tid).ServerName_(domain_bry); props.Init_props(domain_tid, domain_bry);
props.ContentLanguage_(lang.Key_bry()); props.ContentLanguage_(lang.Key_bry());
stats = new Xow_site_stats_mgr(this); stats = new Xow_site_stats_mgr(this);
Pf_func_.Reg(domain_itm, lang.Func_regy(), lang); Pf_func_.Reg(domain_itm, lang.Func_regy(), lang);

View File

@ -41,6 +41,7 @@ public class Xoax_addon_mgr {
, new gplx.xowa.addons.apps.searchs .Xoax_builds_search_addon() , new gplx.xowa.addons.apps.searchs .Xoax_builds_search_addon()
, new gplx.xowa.addons.apps.file_browsers .Fbrow_addon() , new gplx.xowa.addons.apps.file_browsers .Fbrow_addon()
, new gplx.xowa.addons.updates.files .Xoax_updates_files_addon() , new gplx.xowa.addons.updates.files .Xoax_updates_files_addon()
, new gplx.xowa.addons.builds.htmls .Html__dump_to_fsys__addon()
); );
return this; return this;
} }

View File

@ -39,7 +39,7 @@ public class Fbrow_special_page implements Xows_page {
// write head // write head
Xopage_html_data rv = new Xopage_html_data(Display_ttl, body); Xopage_html_data rv = new Xopage_html_data(Display_ttl, body);
rv.Head_tags().Add(Xopg_tag_itm.New_css(addon_dir.GenSubFil_nest("bin", "file_browser.css"))); rv.Head_tags().Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "file_browser.css")));
return rv; return rv;
} }

View File

@ -42,7 +42,7 @@ class Wikis_list_wtr {
// write to html // write to html
Xopage_html_data rv = new Xopage_html_data(Wikis_list_page.Display_ttl, body); Xopage_html_data rv = new Xopage_html_data(Wikis_list_page.Display_ttl, body);
rv.Head_tags().Add(Xopg_tag_itm.New_css(addon_dir.GenSubFil_nest("bin", "wiki_list.css"))); rv.Head_tags().Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "wiki_list.css")));
return rv; return rv;
} }
private static byte[] Get_root_url() { private static byte[] Get_root_url() {

View File

@ -30,9 +30,6 @@ public class Xopage_html_data {
public void Apply(Xoa_page page) { public void Apply(Xoa_page page) {
page.Html_data().Html_restricted_n_(); page.Html_data().Html_restricted_n_();
page.Html_data().Skip_parse_(Bool_.Y); page.Html_data().Skip_parse_(Bool_.Y);
Bry_bfr bfr = Bry_bfr.new_();
page.Html_data().Custom_head_end_concat(head_tags.To_html(bfr));
page.Html_data().Custom_html_end_concat(tail_tags.To_html(bfr));
page.Html_data().Display_ttl_(display_ttl); page.Html_data().Display_ttl_(display_ttl);
page.Html_data().Custom_body_(this.Body()); page.Html_data().Custom_body_(this.Body());
page.Html_data().Custom_head_tags().Copy(head_tags); page.Html_data().Custom_head_tags().Copy(head_tags);

View File

@ -16,20 +16,21 @@ 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.addons.apps.searchs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.searchs.*; package gplx.xowa.addons.apps.searchs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.searchs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Srch_bldr_wkr implements Xob_page_wkr { public class Srch_bldr_wkr implements Xob_page_wkr {
private final Xowe_wiki wiki; private final Xowe_wiki wiki;
private final Srch_temp_tbl_wkr temp_tbl_wkr = new Srch_temp_tbl_wkr(); private final Srch_temp_tbl_wkr temp_tbl_wkr = new Srch_temp_tbl_wkr();
public Srch_bldr_wkr(Xob_bldr bldr, Xowe_wiki wiki) {this.wiki = wiki;} public Srch_bldr_wkr(Xob_bldr bldr, Xowe_wiki wiki) {this.wiki = wiki;}
public String Wkr_key() {return Xob_cmd_keys.Key_text_search_wkr;} public String Page_wkr__key() {return Xob_cmd_keys.Key_text_search_wkr;}
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
temp_tbl_wkr.Init(Bool_.N, wiki); temp_tbl_wkr.Init(Bool_.N, wiki);
} }
public void Wkr_run(gplx.xowa.wikis.data.tbls.Xowd_page_itm page) { public void Page_wkr__run(gplx.xowa.wikis.data.tbls.Xowd_page_itm page) {
try {temp_tbl_wkr.Exec_by_wkr(page.Id(), page.Ttl_page_db());} try {temp_tbl_wkr.Exec_by_wkr(page.Id(), page.Ttl_page_db());}
catch (Exception e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "search:error: page=~{0} err=~{1}", page.Ttl_page_db(), Err_.Message_gplx_full(e));} catch (Exception e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "search:error: page=~{0} err=~{1}", page.Ttl_page_db(), Err_.Message_gplx_full(e));}
} }
public void Wkr_end() { public void Page_wkr__run_cleanup() {}
public void Page_wkr__end() {
temp_tbl_wkr.Term(); temp_tbl_wkr.Term();
} }
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;} public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}

View File

@ -50,10 +50,10 @@ class Srch_temp_tbl_wkr implements Srch_text_parser_wkr {
Db_conn word_conn = search_temp_tbl.conn; Db_conn word_conn = search_temp_tbl.conn;
// update search_word ids if they exist // update search_word ids if they exist
Srch_db_mgr.Optimize_unsafe_(word_conn, Bool_.Y); // Srch_db_mgr.Optimize_unsafe_(word_conn, Bool_.Y); // NOTE: fails in multi-db due to transaction
Update_word_id(word_conn, wiki); Update_word_id(word_conn, wiki);
Search_word__insert(word_conn); Search_word__insert(word_conn);
Srch_db_mgr.Optimize_unsafe_(word_conn, Bool_.N); // Srch_db_mgr.Optimize_unsafe_(word_conn, Bool_.N);
// create search_link // create search_link
Db_conn page_conn = wiki.Data__core_mgr().Tbl__page().conn; Db_conn page_conn = wiki.Data__core_mgr().Tbl__page().conn;

View File

@ -40,9 +40,9 @@ public class Srch_temp_tbl {
public void Insert_end() { public void Insert_end() {
conn.Txn_end(); conn.Txn_end();
stmt_insert = Db_stmt_.Rls(stmt_insert); stmt_insert = Db_stmt_.Rls(stmt_insert);
Srch_db_mgr.Optimize_unsafe_(conn, Bool_.Y); // Srch_db_mgr.Optimize_unsafe_(conn, Bool_.Y); // NOTE: fails in multi-db due to transaction
conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "word_text__word_id", fld_word_text, fld_word_id)); conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "word_text__word_id", fld_word_text, fld_word_id));
// conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "page_id", fld_page_id)); // conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "page_id", fld_page_id));
Srch_db_mgr.Optimize_unsafe_(conn, Bool_.N); // Srch_db_mgr.Optimize_unsafe_(conn, Bool_.N);
} }
} }

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.builds.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.xowa.bldrs.wkrs.*;
public class Html__dump_to_fsys__addon implements Xoax_addon_itm, Xoax_addon_itm__bldr {
public Xob_cmd[] Cmds_ary() {
return new Xob_cmd[]
{ Html__dump_to_fsys__cmd.Prototype
};
}
public static final byte[] ADDON_KEY = Bry_.new_a7("xowa.builds.htmls");
public byte[] Addon__key() {return ADDON_KEY;}
}

View File

@ -15,43 +15,54 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.addons.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.updates.*; package gplx.xowa.addons.builds.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.dbs.*; import gplx.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.htmls.core.htmls.*; 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.fsdb.*; import gplx.fsdb.meta.*; import gplx.xowa.files.*;
import gplx.langs.mustaches.*; import gplx.langs.mustaches.*;
public class Xobldr__deletion_db__temp extends Xob_cmd__base { import gplx.xowa.wikis.pages.*;
private Io_url template_url, dump_root; public class Html__dump_to_fsys__cmd extends Xob_cmd__base {
public Xobldr__deletion_db__temp(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);} 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() { @Override public void Cmd_run() {
// init mustache
Mustache_tkn_parser parser = new Mustache_tkn_parser(); Mustache_tkn_parser parser = new Mustache_tkn_parser();
Mustache_tkn_itm root = parser.Parse(Io_mgr.Instance.LoadFilBry(template_url)); Mustache_tkn_itm root = parser.Parse(Io_mgr.Instance.LoadFilBry(template_url));
Mustache_render_ctx ctx = new Mustache_render_ctx(); Mustache_render_ctx ctx = new Mustache_render_ctx();
Bry_bfr bfr = Bry_bfr.new_(); Bry_bfr bfr = Bry_bfr.new_();
Mustache_bfr mbfr = new Mustache_bfr(bfr); Mustache_bfr mbfr = new Mustache_bfr(bfr);
Xo_page_dump_to_html page_itm = new Xo_page_dump_to_html(); 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(); wiki.Init_assert();
gplx.xowa.wikis.data.tbls.Xowd_page_tbl page_tbl = wiki.Data__core_mgr().Db__core().Tbl__page(); 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_conn conn = page_tbl.conn;
Db_rdr rdr = conn.Exec_rdr("SELECT page_id, page_title, page_touched FROM page WHERE page_namespace = 0;"); Db_rdr rdr = conn.Exec_rdr("SELECT page_id, page_title, page_touched FROM page WHERE page_namespace = 0;");
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.File_dump(Bry_.new_a7("/page/"), Bry_.new_a7(".html"));
while (rdr.Move_next()) { while (rdr.Move_next()) {
String page_ttl = rdr.Read_str("page_title"); String page_ttl_str = rdr.Read_str("page_title");
try { try {
Xoa_ttl ttl = wiki.Ttl_parse(Bry_.new_u8(page_ttl)); // load page
DateAdp page_modified_last = DateAdp_.parse_fmt(rdr.Read_str("page_touched"), gplx.xowa.wikis.data.tbls.Xowd_page_tbl.Page_touched_fmt); Xoa_ttl page_ttl = wiki.Ttl_parse(Bry_.new_u8(page_ttl_str));
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(wiki.Utl__url_parser().Parse(Bry_.new_u8(page_ttl)), ttl); 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_by_ttl(wiki.Utl__url_parser().Parse(page_ttl.Page_db()), page_ttl);
wiki.Parser_mgr().Parse(page, true); 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().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, hctx, page); page.Wikie().Html_mgr().Page_wtr_mgr().Wkr(gplx.xowa.wikis.pages.Xopg_page_.Tid_read).Write_body(bfr, 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_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
page_itm.Init(page_ttl, Bry_.Empty, Bry_.Empty, html_src); 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)); root.Render(mbfr, ctx.Init(page_itm));
Io_url dump_fil_url = Io_url_.new_fil_(dump_root.Gen_sub_path_for_os(page_ttl) + ".html");
if (Io_mgr.Instance.QueryFil(dump_fil_url).ModifiedTime().Eq(page_modified_last)) continue;
Io_mgr.Instance.SaveFilBry(dump_fil_url, mbfr.To_bry_and_clear()); Io_mgr.Instance.SaveFilBry(dump_fil_url, mbfr.To_bry_and_clear());
Io_mgr.Instance.UpdateFilModifiedTime(dump_fil_url, page_modified_last); Io_mgr.Instance.UpdateFilModifiedTime(dump_fil_url, page_modified_on);
} catch (Exception e) { } catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "err: ~{0}", Err_.Message_gplx_log(e)); Gfo_usr_dlg_.Instance.Warn_many("", "", "err: ~{0}", Err_.Message_gplx_log(e));
} }
@ -59,37 +70,19 @@ public class Xobldr__deletion_db__temp extends Xob_cmd__base {
} }
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { @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"); if (ctx.Match(k, Invk__template_url_)) this.template_url = m.ReadIoUrl("v");
else if (ctx.Match(k, Invk__dump_root_)) this.dump_root = 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 GfoInvkAble_.Rv_unhandled; else return GfoInvkAble_.Rv_unhandled;
return this; return this;
} private static final String Invk__template_url_ = "template_url_", Invk__dump_root_ = "dump_root_"; }
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"; public static final String BLDR_CMD_KEY = "html.dump_to_file";
@Override public String Cmd_key() {return BLDR_CMD_KEY;} @Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xobldr__deletion_db__temp(null, null); 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 Xobldr__deletion_db__temp(bldr, wiki);} @Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Html__dump_to_fsys__cmd(bldr, wiki);}
}
class Xo_page_dump_to_html implements Mustache_doc_itm {
private String page_title;
private byte[] page_head_extra;
private byte[] page_caption;
private byte[] page_body;
public Xo_page_dump_to_html Init(String page_title, byte[] page_head_extra, byte[] page_caption, byte[] page_body) {
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_str_u8(page_title);
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;
}
} }

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.builds.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
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;
}
}

View File

@ -33,7 +33,7 @@ public class Pglnk_page_link_temp_tbl implements Rls_able {
public String Tbl_name() {return tbl_name;} public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));} public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public void Create_idx() {conn.Meta_idx_create(Gfo_usr_dlg_.Instance, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_src_id, fld_trg_ns, fld_trg_ttl));} public void Create_idx() {conn.Meta_idx_create(Gfo_usr_dlg_.Instance, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_src_id, fld_trg_ns, fld_trg_ttl));}
public void Insert_bgn() {conn.Txn_bgn("schema__page_link__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);} public void Insert_bgn() {conn.Txn_bgn("page_link__insert_bulk"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);} public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert(int src_id, int trg_ns, byte[] trg_ttl) { public void Insert(int src_id, int trg_ns, byte[] trg_ttl) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds); if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);

View File

@ -0,0 +1,36 @@
/*
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.builds.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.core.brys.*;
class Volume_make_itm implements Bry_bfr_able {
public int Uid = 0;
public int Prep_id = 0;
public int Item_type = 0; // 0=page;1=thm
public int Item_id = 0; // either page_id or fsdb_id
public String Item_name = ""; // friendly-name
public byte[] Item_ttl = Bry_.Empty; // actual name
public long Item_size = 0; // size of page / file
public void To_bfr(Bry_bfr bfr) {
}
}
/*
1|p|Earth|123|100
1|f|Earth.png|124|200
1|f|Moon.png|125|300
4|p|Sun|123|100
*/

View File

@ -0,0 +1,63 @@
/*
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.builds.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.wikis.nss.*;
interface Volume_page_loader {
boolean Load(Volume_page_itm rv, byte[] ttl);
}
class Volume_page_loader__wiki implements Volume_page_loader {
private final Xowe_wiki wiki;
public Volume_page_loader__wiki(Xowe_wiki wiki) {this.wiki = wiki;}
public boolean Load(Volume_page_itm rv, byte[] ttl) {
Xoa_ttl page_ttl = wiki.Ttl_parse(ttl); if (page_ttl == null) return false;
Xoa_url page_url = wiki.Utl__url_parser().Parse(ttl);
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(page_url, page_ttl);
Load_links(rv, page.Lnki_list());
return true;
}
private void Load_links(Volume_page_itm rv, List_adp list) {
int len = list.Len();
//gplx.xowa.wikis.data.tbls.Xowd_page_tbl page_tbl; page_tbl.Select_in__ttl
for (int i = 0; i < len; i++) {
Xop_lnki_tkn lnki = (Xop_lnki_tkn)list.Get_at(i);
int ns_id = lnki.Ns_id();
switch (ns_id) {
case Xow_ns_.Tid__special:
case Xow_ns_.Tid__media:
break;
case Xow_ns_.Tid__file:
break; // file
default:
Volume_make_itm make_itm = new Volume_make_itm();
make_itm.Item_ttl = lnki.Ttl().Page_db();
make_itm.Item_size = 1;
rv.Link_list().Add(make_itm);
break;
}
}
}
}
class Volume_page_itm {
public void Init(Xoa_ttl page_ttl, Xoa_url page_url) {
this.page_ttl = page_ttl; this.page_url = page_url;
}
public Xoa_ttl Page_ttl() {return page_ttl;} private Xoa_ttl page_ttl;
public Xoa_url Page_url() {return page_url;} private Xoa_url page_url;
public List_adp Link_list() {return link_list;} private final List_adp link_list = List_adp_.new_();
public List_adp File_list() {return file_list;} private final List_adp file_list = List_adp_.new_();
}

View 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.builds.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.core.brys.*;
import gplx.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Volume_prep_cmd extends Xob_cmd__base {
private Io_url prep_url, make_url;
public Volume_prep_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Volume_prep_itm[] page_itms = new Volume_prep_rdr().Parse(prep_url);
Volume_prep_mgr prep_mgr = new Volume_prep_mgr(new Volume_page_loader__wiki(wiki));
Volume_make_itm[] make_itms = prep_mgr.Calc_makes(page_itms);
Bry_bfr bfr = Bry_bfr.new_();
for (Volume_make_itm make_itm : make_itms) {
make_itm.To_bfr(bfr);
bfr.Add_byte_nl();
}
Io_mgr.Instance.SaveFilBfr(make_url, bfr);
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__prep_url_)) prep_url = m.ReadIoUrl("v");
else if (ctx.Match(k, Invk__make_url_)) make_url = m.ReadIoUrl("v");
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk__prep_url_ = "prep_url_", Invk__make_url_ = "make_url_";
public static final String BLDR_CMD_KEY = "volume.prep";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Volume_prep_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Volume_prep_cmd(bldr, wiki);}
}

View File

@ -0,0 +1,36 @@
/*
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.builds.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import gplx.core.brys.*;
class Volume_prep_itm implements Bry_bfr_able {
public int Prep_id = 0;
public byte[] Page_ttl = null;
public long Max_bytes = 0;
public int Max_depth = 2;
public int Max_article_count = -1;
public int Max_link_count_per_page = -1;
public boolean Skip_navbox = false;
public int Max_file_count = -1;
public long Max_file_size = -1;
public boolean Skip_audio = true;
public static final Volume_prep_itm[] Ary_empty = new Volume_prep_itm[0];
public void To_bfr(Bry_bfr bfr) {
bfr.Add(Page_ttl);
}
}
// Earth|2|100|10|100|100MB

View File

@ -0,0 +1,76 @@
/*
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.builds.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
class Volume_prep_mgr {
private final Volume_page_loader loader;
private final Volume_page_itm tmp_page = new Volume_page_itm();
private final List_adp list = List_adp_.new_();
public Volume_prep_mgr(Volume_page_loader loader) {this.loader = loader;}
public Volume_make_itm[] Calc_makes(Volume_prep_itm[] ary) {
Volume_prep_ctx ctx = new Volume_prep_ctx();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Volume_prep_itm itm = ary[i];
ctx.Init(ctx, itm);
Calc_make(ctx, itm.Page_ttl);
}
return (Volume_make_itm[])list.To_ary_and_clear(Volume_make_itm.class);
}
private void Calc_make(Volume_prep_ctx ctx, byte[] page_ttl) {
if (!loader.Load(tmp_page, page_ttl)) return;
if (ctx.Bytes_max != -1 && ctx.Bytes_count > ctx.Bytes_max) return;
if (ctx.Depth_count > ctx.Depth_max) return;
List_adp files_list = tmp_page.File_list();
int files_len = files_list.Len();
for (int i = 0; i < files_len; ++i) {
Volume_make_itm file_itm = (Volume_make_itm)files_list.Get_at(i);
list.Add(file_itm);
}
List_adp links_list = tmp_page.Link_list();
int links_len = links_list.Len();
for (int i = 0; i < links_len; ++i) {
if (ctx.Page_max != -1 && ctx.Page_count++ > ctx.Page_max) return;
Volume_make_itm link_itm = (Volume_make_itm)links_list.Get_at(i);
list.Add(link_itm);
ctx.Depth_count++;
Calc_make(ctx, link_itm.Item_ttl);
ctx.Depth_count--;
}
}
}
class Volume_prep_ctx {
public long Bytes_count;
public long Bytes_max;
public int Page_count;
public int Page_max;
public int Depth_count;
public int Depth_max;
public void Init(Volume_prep_ctx prv_ctx, Volume_prep_itm itm) {
this.Bytes_count = prv_ctx.Bytes_count;
this.Bytes_max = itm.Max_bytes;
this.Page_count = 1;
this.Page_max = itm.Max_article_count;
this.Depth_count = 0;
this.Depth_max = itm.Max_depth;
}
// public int Max_link_count_per_page = -1;
// public int Max_file_count = -1;
// public long Max_file_size = -1;
// public boolean Skip_navbox = false;
// public boolean Skip_audio = true;
}

View File

@ -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.builds.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
class Volume_prep_rdr {
public Volume_prep_itm[] Parse(Io_url url) {return Parse(Io_mgr.Instance.LoadFilBryOr(url, null));}
public Volume_prep_itm[] Parse(byte[] src) {
if (src == null) return Volume_prep_itm.Ary_empty;
List_adp rv = List_adp_.new_();
byte[][] lines = Bry_split_.Split_lines(src);
int lines_len = lines.length;
for (int i = 0; i < lines_len; ++i) {
Volume_prep_itm itm = Parse_line_or_null(lines[i]);
if (itm != null) rv.Add(itm);
}
return (Volume_prep_itm[])rv.To_ary_and_clear(Volume_prep_itm.class);
}
private Volume_prep_itm Parse_line_or_null(byte[] line) {
byte[][] flds = Bry_split_.Split(line, Byte_ascii.Pipe);
int flds_len = flds.length; if (flds_len == 0) return null;
Volume_prep_itm rv = new Volume_prep_itm();
for (int i = 0; i < flds_len; ++i) {
byte[] fld = flds[i];
switch (i) {
case 0: rv.Page_ttl = fld; break;
default: throw Err_.new_unhandled_default(i);
}
}
return rv;
}
}

View File

@ -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.builds.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.builds.*;
import org.junit.*; import gplx.core.tests.*;
public class Volume_prep_rdr_tst {
private final Volume_prep_rdr_fxt fxt = new Volume_prep_rdr_fxt();
@Test public void Parse() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last("A", "", "B")
, fxt.Make__itm("A")
, fxt.Make__itm("B")
);
}
}
class Volume_prep_rdr_fxt {
private final Volume_prep_rdr rdr = new Volume_prep_rdr();
public Volume_prep_rdr_fxt Test__parse(String raw, Volume_prep_itm... expd) {
Gftest.Eq__ary(expd, rdr.Parse(Bry_.new_u8(raw)));
return this;
}
public Volume_prep_itm Make__itm(String page_ttl) {
Volume_prep_itm rv = new Volume_prep_itm();
rv.Page_ttl = Bry_.new_u8(page_ttl);
return rv;
}
}

View File

@ -24,7 +24,6 @@ public class Xoax_updates_files_addon implements Xoax_addon_itm, Xoax_addon_itm_
{ Xobldr__deletion_db__make.Prototype { Xobldr__deletion_db__make.Prototype
, Xobldr__deletion_db__exec.Prototype , Xobldr__deletion_db__exec.Prototype
, Xobldr__deletion_db__small_files.Prototype , Xobldr__deletion_db__small_files.Prototype
, Xobldr__deletion_db__temp.Prototype
}; };
} }

View File

@ -15,9 +15,10 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.specials.randoms; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; package gplx.xowa.addons.wikis.randoms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.addons.wikis.randoms.dbs.*;
public class Rndm_mgr implements Rls_able { public class Rndm_mgr implements Rls_able {
private Rndm_core_tbl core_tbl; private final Rndm_core_row core_row = new Rndm_core_row(); private Rndm_core_tbl core_tbl; private final Rndm_core_row core_row = new Rndm_core_row();
private Rndm_range_tbl rng_tbl; private Rndm_range_tbl rng_tbl;

View File

@ -15,18 +15,16 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.specials.randoms; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; package gplx.xowa.addons.wikis.randoms.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.randoms.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xob_rnd_cmd implements Xob_cmd { public class Rndm_bldr_cmd extends Xob_cmd__base {
private final Xowe_wiki wiki;
private int rndm_uid = 0; private String rndm_where_sql = "AND ~{page_namespace} = 0 AND ~{page_is_redirect} = 0"; private int rndm_interval = 1000; private int rndm_uid = 0; private String rndm_where_sql = "AND ~{page_namespace} = 0 AND ~{page_is_redirect} = 0"; private int rndm_interval = 1000;
public Xob_rnd_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.wiki = wiki;} public Rndm_bldr_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
public String Cmd_key() {return Xob_cmd_keys.Key_util_random;} @Override public void Cmd_run() {
public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return null;} // wiki.Special_mgr().Page_random().Mgr().Rebuild(rndm_uid, rndm_where_sql, rndm_interval);
public void Cmd_run() { Tfds.Write(rndm_uid, rndm_where_sql, rndm_interval);
wiki.Special_mgr().Page_random().Mgr().Rebuild(rndm_uid, rndm_where_sql, rndm_interval);
} }
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { @Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_rndm_uid_)) rndm_uid = m.ReadInt("v"); if (ctx.Match(k, Invk_rndm_uid_)) rndm_uid = m.ReadInt("v");
else if (ctx.Match(k, Invk_rndm_where_sql_)) rndm_where_sql = m.ReadStr("v"); else if (ctx.Match(k, Invk_rndm_where_sql_)) rndm_where_sql = m.ReadStr("v");
else if (ctx.Match(k, Invk_rndm_interval_)) rndm_interval = m.ReadInt("v"); else if (ctx.Match(k, Invk_rndm_interval_)) rndm_interval = m.ReadInt("v");
@ -34,8 +32,8 @@ public class Xob_rnd_cmd implements Xob_cmd {
return this; return this;
} private static final String Invk_rndm_uid_ = "rndm_uid_", Invk_rndm_where_sql_ = "rndm_where_sql_", Invk_rndm_interval_ = "rndm_interval_"; } private static final String Invk_rndm_uid_ = "rndm_uid_", Invk_rndm_where_sql_ = "rndm_where_sql_", Invk_rndm_interval_ = "rndm_interval_";
public void Cmd_init(Xob_bldr bldr) {} public static final String BLDR_CMD_KEY = "wiki.random";
public void Cmd_bgn(Xob_bldr bldr) {} @Override public String Cmd_key() {return BLDR_CMD_KEY;}
public void Cmd_end() {} public static final Xob_cmd Prototype = new Rndm_bldr_cmd(null, null);
public void Cmd_term() {} @Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Rndm_bldr_cmd(bldr, wiki);}
} }

View File

@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.specials.randoms; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; package gplx.xowa.addons.wikis.randoms.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.randoms.*;
public class Rndm_core_row { public class Rndm_core_row {
public void Load(int uid, String where_sql, int total, int interval) {this.uid = uid; this.where_sql = where_sql; this.total = total; this.interval = interval;} public void Load(int uid, String where_sql, int total, int interval) {this.uid = uid; this.where_sql = where_sql; this.total = total; this.interval = interval;}
public int uid; public int uid;

View File

@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.specials.randoms; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; package gplx.xowa.addons.wikis.randoms.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.randoms.*;
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*; import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*;
public class Rndm_core_tbl implements Rls_able { public class Rndm_core_tbl implements Rls_able {
private final String tbl_name = "rndm_core"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_(); private final String tbl_name = "rndm_core"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();

View File

@ -15,10 +15,10 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.specials.randoms; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; package gplx.xowa.addons.wikis.randoms.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.randoms.*;
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*; import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*;
public class Rndm_range_tbl implements Rls_able { public class Rndm_range_tbl implements Rls_able {
private final String tbl_name = "rng_range"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_(); private final String tbl_name = "rndm_range"; private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
private final String fld_rng_uid, fld_rng_idx, fld_rng_page_id; private final String fld_rng_uid, fld_rng_idx, fld_rng_page_id;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert; private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
public Rndm_range_tbl(Db_conn conn) { public Rndm_range_tbl(Db_conn conn) {

View File

@ -20,6 +20,8 @@ import gplx.xowa.parsers.lnkis.cfgs.*;
public class Xowc_parser implements GfoInvkAble { public class Xowc_parser implements GfoInvkAble {
public Xowc_parser(Xowe_wiki wiki) { public Xowc_parser(Xowe_wiki wiki) {
lnki_cfg = new Xoc_lnki_cfg(wiki); lnki_cfg = new Xoc_lnki_cfg(wiki);
if (wiki.Domain_tid() == gplx.xowa.wikis.domains.Xow_domain_tid_.Int__home)
display_title_restrict = false;
} }
public Xoc_lnki_cfg Lnki_cfg() {return lnki_cfg;} private Xoc_lnki_cfg lnki_cfg; public Xoc_lnki_cfg Lnki_cfg() {return lnki_cfg;} private Xoc_lnki_cfg lnki_cfg;
public Xowc_xtns Xtns() {return xtns;} private Xowc_xtns xtns = new Xowc_xtns(); public Xowc_xtns Xtns() {return xtns;} private Xowc_xtns xtns = new Xowc_xtns();

View File

@ -42,7 +42,10 @@ public class Xocfg_bnd_mgr implements GfoInvkAble, Gfo_sort_able {
private Xocfg_bnd_itm_srl Init(String key) {return new Xocfg_bnd_itm_srl(app, key);} private Xocfg_bnd_itm_srl Init(String key) {return new Xocfg_bnd_itm_srl(app, key);}
public Xocfg_bnd_itm Get_at(int i) {return (Xocfg_bnd_itm)regy.Get_at(i);} public Xocfg_bnd_itm Get_at(int i) {return (Xocfg_bnd_itm)regy.Get_at(i);}
public int Len() {return regy.Count();} public int Len() {return regy.Count();}
public void Sort(gplx.core.lists.ComparerAble comparer) {regy.Sort_by(comparer);} public void Sort(gplx.core.lists.ComparerAble comparer) {
if (regy == null) Init(); // NOTE: null when called during html.dump_to_file for home/wiki/Options/Shortcuts; DATE:2016-04-12
regy.Sort_by(comparer);
}
private void Set_bulk(byte[] src) { private void Set_bulk(byte[] src) {
try { try {
bnd_mgr_srl.Load_by_bry(src); bnd_mgr_srl.Load_by_bry(src);

View File

@ -35,7 +35,7 @@ class Xoa_site_cfg_loader__db implements Xoa_site_cfg_loader {
public void Save_bry(int loader_tid, String db_key, byte[] val) { public void Save_bry(int loader_tid, String db_key, byte[] val) {
byte[] meta = Bry_.new_a7(Bld_meta(loader_tid)); byte[] meta = Bry_.new_a7(Bld_meta(loader_tid));
byte[] data = Bry_.Len_eq_0(val) ? meta : Bry_.Add(meta, Byte_ascii.Nl_bry, val); byte[] data = Bry_.Len_eq_0(val) ? meta : Bry_.Add(meta, Byte_ascii.Nl_bry, val);
cfg_tbl.Assert_bry(Grp__xowa_wm_api, db_key, data); cfg_tbl.Upsert_bry(Grp__xowa_wm_api, db_key, data);
} }
public static String Bld_meta(int loader_tid) { public static String Bld_meta(int loader_tid) {
return String_.Format("//#xowa|{0}|{1}|{2}", Xoa_app_.Version, Xoa_site_cfg_loader_.Get_key(loader_tid), DateAdp_.Now().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss()); return String_.Format("//#xowa|{0}|{1}|{2}", Xoa_app_.Version, Xoa_site_cfg_loader_.Get_key(loader_tid), DateAdp_.Now().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss());

View File

@ -47,15 +47,14 @@ public class Xoa_site_cfg_loader__inet implements Xoa_site_cfg_loader {
int len = itm_ary.length; int len = itm_ary.length;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
Xoa_site_cfg_itm__base itm = itm_ary[i]; Xoa_site_cfg_itm__base itm = itm_ary[i];
byte[] itm_key = itm.Key_bry(); // if (db_hash.Has(itm_key)) continue; // TOMBSTONE: always add itm to url, even if in db; note that fallback gets saved to db; DATE:2016-04-13
if (db_hash.Has(itm_key)) continue;
if (first) if (first)
first = false; first = false;
else else
bfr.Add_byte_pipe(); bfr.Add_byte_pipe();
bfr.Add(itm.Key_bry()); bfr.Add(itm.Key_bry());
} }
return Xowm_api_mgr.Bld_api_url(domain_str, Qarg__bgn + bfr.To_str_and_rls()); return first ? null : Xowm_api_mgr.Bld_api_url(domain_str, Qarg__bgn + bfr.To_str_and_rls());
} }
private static final byte[] Bry__query = Bry_.new_a7("query"); private static final byte[] Bry__query = Bry_.new_a7("query");
public static final String public static final String

View File

@ -56,11 +56,6 @@ public class Xoa_site_cfg_mgr_tst {
fxt.Exec_load(); fxt.Exec_load();
fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__interwikimap, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 2, "w", "https://en.wikipedia.org", "c", "https://commons.wikimedia.org")); fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__interwikimap, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 2, "w", "https://en.wikipedia.org", "c", "https://commons.wikimedia.org"));
} }
@Test public void Inet__once() {
fxt.Init_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 1, "math", "source"));
fxt.Exec_load();
fxt.Test_inet_qarg("interwikimap"); // should not have extensiontags
}
// @Test public void Print() { // @Test public void Print() {
// String s = fxt.Make_api(fxt.Make_api_interwikimap("k1", "v1", "k2", "v2"), fxt.Make_api_extensiontags2("k3", "v3", "k4", "v4")); // String s = fxt.Make_api(fxt.Make_api_interwikimap("k1", "v1", "k2", "v2"), fxt.Make_api_extensiontags2("k3", "v3", "k4", "v4"));
// Tfds.Dbg(s); // Tfds.Dbg(s);

View File

@ -68,12 +68,12 @@ public class Xob_base_fxt {
cmd.Cmd_end(); cmd.Cmd_end();
} }
public static void Run_wkr(Xob_bldr bldr, Xob_page_wkr wkr, Xowd_page_itm[] page_ary) { public static void Run_wkr(Xob_bldr bldr, Xob_page_wkr wkr, Xowd_page_itm[] page_ary) {
wkr.Wkr_bgn(bldr); wkr.Page_wkr__bgn();
int page_ary_len = page_ary.length; int page_ary_len = page_ary.length;
for (int i = 0; i < page_ary_len; i++) { for (int i = 0; i < page_ary_len; i++) {
Xowd_page_itm page = page_ary[i]; Xowd_page_itm page = page_ary[i];
wkr.Wkr_run(page); wkr.Page_wkr__run(page);
} }
wkr.Wkr_end(); wkr.Page_wkr__end();
} }
} }

View File

@ -62,7 +62,7 @@ public class Xob_fxt {
return rv; return rv;
} }
public Xob_fxt Run_ctg() { public Xob_fxt Run_ctg() {
Xobd_parser parser = new Xobd_parser(); Xobd_parser parser = new Xobd_parser(bldr);
gplx.xowa.bldrs.cmds.ctgs.Xob_ctg_v1_base ctg_wkr = new gplx.xowa.bldrs.cmds.ctgs.Xob_ctg_v1_txt().Ctor(bldr, wiki); gplx.xowa.bldrs.cmds.ctgs.Xob_ctg_v1_base ctg_wkr = new gplx.xowa.bldrs.cmds.ctgs.Xob_ctg_v1_txt().Ctor(bldr, wiki);
byte[] bry = Bry_.new_a7("[[Category:"); byte[] bry = Bry_.new_a7("[[Category:");
ctg_wkr.Wkr_hooks().Add(bry, bry); ctg_wkr.Wkr_hooks().Add(bry, bry);
@ -75,12 +75,12 @@ public class Xob_fxt {
return this; return this;
} }
private void Run_wkr(Xob_page_wkr wkr) { private void Run_wkr(Xob_page_wkr wkr) {
wkr.Wkr_bgn(bldr); wkr.Page_wkr__bgn();
for (int i = 0; i < doc_ary.length; i++) { for (int i = 0; i < doc_ary.length; i++) {
Xowd_page_itm page = doc_ary[i]; Xowd_page_itm page = doc_ary[i];
wkr.Wkr_run(page); wkr.Page_wkr__run(page);
} }
wkr.Wkr_end(); wkr.Page_wkr__end();
} }
private void tst_fils(Io_url[] ary) { private void tst_fils(Io_url[] ary) {
Io_fil[] actls = Get_actl(ary); Io_fil[] actls = Get_actl(ary);
@ -105,7 +105,7 @@ public class Xob_fxt {
} }
public Xob_fxt Run_page_title() {return Run(new gplx.xowa.bldrs.cmds.texts.tdbs.Xob_page_txt(bldr, wiki));} public Xob_fxt Run_page_title() {return Run(new gplx.xowa.bldrs.cmds.texts.tdbs.Xob_page_txt(bldr, wiki));}
public Xob_fxt Run(Xobd_parser_wkr... wkrs) { public Xob_fxt Run(Xobd_parser_wkr... wkrs) {
Xobd_parser parser_wkr = new Xobd_parser(); Xobd_parser parser_wkr = new Xobd_parser(bldr);
int len = wkrs.length; int len = wkrs.length;
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
parser_wkr.Wkr_add(wkrs[i]); parser_wkr.Wkr_add(wkrs[i]);
@ -116,12 +116,12 @@ public class Xob_fxt {
int doc_ary_len = doc_ary.length; int doc_ary_len = doc_ary.length;
for (int j = 0; j < wkrs.length; j++) { for (int j = 0; j < wkrs.length; j++) {
Xob_page_wkr wkr = wkrs[j]; Xob_page_wkr wkr = wkrs[j];
wkr.Wkr_bgn(bldr); wkr.Page_wkr__bgn();
for (int i = 0; i < doc_ary_len; i++) { for (int i = 0; i < doc_ary_len; i++) {
Xowd_page_itm page = doc_ary[i]; Xowd_page_itm page = doc_ary[i];
wkr.Wkr_run(page); wkr.Page_wkr__run(page);
} }
wkr.Wkr_end(); wkr.Page_wkr__end();
} }
Test_expd_files(); Test_expd_files();
return this; return this;

View File

@ -27,7 +27,7 @@ public class Xob_page_wkr_cmd implements Xob_cmd {
public void Cmd_run() { public void Cmd_run() {
Xob_page_wkr[] wkr_ary = (Xob_page_wkr[])wkrs.To_ary(Xob_page_wkr.class); int wkr_ary_len = wkr_ary.length; Xob_page_wkr[] wkr_ary = (Xob_page_wkr[])wkrs.To_ary(Xob_page_wkr.class); int wkr_ary_len = wkr_ary.length;
for (int i = 0; i < wkr_ary_len; i++) for (int i = 0; i < wkr_ary_len; i++)
wkr_ary[i].Wkr_bgn(bldr); wkr_ary[i].Page_wkr__bgn();
Io_buffer_rdr fil = Io_buffer_rdr.Null; Xowd_page_itm page = new Xowd_page_itm(); Xow_ns_mgr ns_mgr = wiki.Ns_mgr(); Io_buffer_rdr fil = Io_buffer_rdr.Null; Xowd_page_itm page = new Xowd_page_itm(); Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
Xob_xml_parser parser = bldr.Dump_parser().Data_bfr_len_(Io_mgr.Len_mb); Xob_xml_parser parser = bldr.Dump_parser().Data_bfr_len_(Io_mgr.Len_mb);
long fil_len = 0; long fil_len = 0;
@ -46,7 +46,7 @@ public class Xob_page_wkr_cmd implements Xob_cmd {
prv_pos = cur_pos; prv_pos = cur_pos;
try { try {
for (int i = 0; i < wkr_ary_len; i++) for (int i = 0; i < wkr_ary_len; i++)
wkr_ary[i].Wkr_run(page); wkr_ary[i].Page_wkr__run(page);
} }
catch (Exception e) { catch (Exception e) {
Err_.Noop(e); Err_.Noop(e);
@ -57,6 +57,8 @@ public class Xob_page_wkr_cmd implements Xob_cmd {
Console_adp__sys.Instance.Write_str_w_nl(msg); Console_adp__sys.Instance.Write_str_w_nl(msg);
} }
} }
for (int i = wkr_ary_len - 1; i > -1; --i) // NOTE: release in reverse order; needed to make sure txns are released correctly
wkr_ary[i].Page_wkr__run_cleanup();
} }
catch (Exception e) { catch (Exception e) {
String msg = Err_.Message_lang(e); String msg = Err_.Message_lang(e);
@ -67,17 +69,17 @@ public class Xob_page_wkr_cmd implements Xob_cmd {
finally {fil.Rls();} finally {fil.Rls();}
bldr.Usr_dlg().Prog_none("", "", "reading completed: performing post-processing clean-up"); bldr.Usr_dlg().Prog_none("", "", "reading completed: performing post-processing clean-up");
for (int i = wkr_ary_len - 1; i > -1; --i) // NOTE: release in reverse order; needed to make sure txns are released correctly for (int i = wkr_ary_len - 1; i > -1; --i) // NOTE: release in reverse order; needed to make sure txns are released correctly
wkr_ary[i].Wkr_end(); wkr_ary[i].Page_wkr__end();
} }
public void Cmd_bgn(Xob_bldr bldr) {} public void Cmd_bgn(Xob_bldr bldr) {}
public void Cmd_init(Xob_bldr bldr) {} public void Cmd_init(Xob_bldr bldr) {}
public void Cmd_end() {} public void Cmd_end() {}
public void Cmd_term() {} public void Cmd_term() {}
public void Wkr_add(Xob_page_wkr wkr) {wkrs.Add(wkr.Wkr_key(), wkr);} private Ordered_hash wkrs = Ordered_hash_.New(); public void Wkr_add(Xob_page_wkr wkr) {wkrs.Add(wkr.Page_wkr__key(), wkr);} private Ordered_hash wkrs = Ordered_hash_.New();
public Xob_page_wkr Wkr_get(String key) {return (Xob_page_wkr)wkrs.Get_by(key);} public Xob_page_wkr Wkr_get(String key) {return (Xob_page_wkr)wkrs.Get_by(key);}
public Xobd_parser Page_parser_assert() { public Xobd_parser Page_parser_assert() {
if (page_parser == null) { if (page_parser == null) {
page_parser = new Xobd_parser(); page_parser = new Xobd_parser(bldr);
this.Wkr_add(page_parser); this.Wkr_add(page_parser);
} }
return page_parser; return page_parser;

View File

@ -16,18 +16,20 @@ 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*; package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*; import gplx.core.btries.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.data.tbls.*;
public class Xobd_parser implements Xob_page_wkr { public class Xobd_parser implements Xob_page_wkr {
private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; ctg.v1 assumes [[Category: private final Xob_bldr bldr;
private List_adp wkr_list = List_adp_.new_(); private final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; ctg.v1 assumes [[Category:
public String Wkr_key() {return KEY;} static final String KEY = "page_parser"; private final List_adp wkr_list = List_adp_.new_();
public String Page_wkr__key() {return KEY;} static final String KEY = "page_parser";
public Xobd_parser(Xob_bldr bldr) {this.bldr = bldr;}
public void Wkr_add(Xobd_parser_wkr wkr) {wkr_list.Add(wkr);} public void Wkr_add(Xobd_parser_wkr wkr) {wkr_list.Add(wkr);}
public void Wkr_bgn(Xob_bldr app) { public void Page_wkr__bgn() {
int wkr_list_len = wkr_list.Count(); int wkr_list_len = wkr_list.Count();
for (int i = 0; i < wkr_list_len; i++) { for (int i = 0; i < wkr_list_len; i++) {
Xobd_parser_wkr wkr = (Xobd_parser_wkr)wkr_list.Get_at(i); Xobd_parser_wkr wkr = (Xobd_parser_wkr)wkr_list.Get_at(i);
wkr.Wkr_bgn(app); wkr.Wkr_bgn(bldr);
int hooks_len = wkr.Wkr_hooks().Count(); int hooks_len = wkr.Wkr_hooks().Count();
for (int j = 0; j < hooks_len; j++) { for (int j = 0; j < hooks_len; j++) {
byte[] bry = (byte[])wkr.Wkr_hooks().Get_at(j); byte[] bry = (byte[])wkr.Wkr_hooks().Get_at(j);
@ -35,7 +37,7 @@ public class Xobd_parser implements Xob_page_wkr {
} }
} }
} }
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
byte[] src = page.Text(); int src_len = src.length; byte[] src = page.Text(); int src_len = src.length;
int pos = 0; int pos = 0;
while (true) { while (true) {
@ -49,7 +51,8 @@ public class Xobd_parser implements Xob_page_wkr {
} }
} }
} }
public void Wkr_end() { public void Page_wkr__run_cleanup() {}
public void Page_wkr__end() {
int wkr_list_len = wkr_list.Count(); int wkr_list_len = wkr_list.Count();
for (int i = 0; i < wkr_list_len; i++) { for (int i = 0; i < wkr_list_len; i++) {
Xobd_parser_wkr wkr = (Xobd_parser_wkr)wkr_list.Get_at(i); Xobd_parser_wkr wkr = (Xobd_parser_wkr)wkr_list.Get_at(i);

View File

@ -32,17 +32,17 @@ class Xowd_page_wkr_ctg_fxt {
byte[] src; byte[] src;
public Xowd_page_wkr_ctg_fxt ini_(String s) {src = Bry_.new_u8(s); return this;} public Xowd_page_wkr_ctg_fxt ini_(String s) {src = Bry_.new_u8(s); return this;}
public Xowd_page_wkr_ctg_fxt tst_(String... expd) { public Xowd_page_wkr_ctg_fxt tst_(String... expd) {
Xobd_parser mgr = new Xobd_parser();
Xoae_app app = Xoa_app_fxt.Make__app__edit(); Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app); Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xob_bldr bldr = Xoa_app_fxt.bldr_(app); Xob_bldr bldr = Xoa_app_fxt.bldr_(app);
Xobd_parser mgr = new Xobd_parser(bldr);
Xobd_parser_wkr_ctg_tstr wkr = (Xobd_parser_wkr_ctg_tstr)new Xobd_parser_wkr_ctg_tstr().Ctor(bldr, wiki); Xobd_parser_wkr_ctg_tstr wkr = (Xobd_parser_wkr_ctg_tstr)new Xobd_parser_wkr_ctg_tstr().Ctor(bldr, wiki);
byte[] bry = Bry_.new_a7("[[Category:"); byte[] bry = Bry_.new_a7("[[Category:");
wkr.Wkr_hooks().Add(bry, bry); wkr.Wkr_hooks().Add(bry, bry);
mgr.Wkr_add(wkr); mgr.Wkr_add(wkr);
Xowd_page_itm page = new Xowd_page_itm().Text_(src);//.Ttl_(Bry_.new_a7("Test"), new Xow_ns_mgr()); Xowd_page_itm page = new Xowd_page_itm().Text_(src);//.Ttl_(Bry_.new_a7("Test"), new Xow_ns_mgr());
mgr.Wkr_bgn(bldr); mgr.Page_wkr__bgn();
mgr.Wkr_run(page); mgr.Page_wkr__run(page);
byte[][] ttl = (byte[][])wkr.Found().To_ary(byte[].class); byte[][] ttl = (byte[][])wkr.Found().To_ary(byte[].class);
String[] actl = new String[ttl.length]; String[] actl = new String[ttl.length];
for (int i = 0; i < actl.length; i++) { for (int i = 0; i < actl.length; i++) {

View File

@ -28,8 +28,8 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xob_page_wkr, Gf
private DateAdp modified_latest = DateAdp_.MinValue; private int page_count_all, page_count_main = 0; private int commit_interval = 100000; // 100 k private DateAdp modified_latest = DateAdp_.MinValue; private int page_count_all, page_count_main = 0; private int commit_interval = 100000; // 100 k
private Dg_match_mgr dg_match_mgr; private Xob_ns_to_db_mgr ns_to_db_mgr; private Dg_match_mgr dg_match_mgr; private Xob_ns_to_db_mgr ns_to_db_mgr;
public Xob_page_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);} public Xob_page_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Wkr_key() {return Xob_cmd_keys.Key_text_page;} public String Page_wkr__key() {return Xob_cmd_keys.Key_text_page;}
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
Xoae_app app = wiki.Appe(); Xoae_app app = wiki.Appe();
Xoapi_import import_cfg = app.Api_root().Bldr().Wiki().Import(); Xoapi_import import_cfg = app.Api_root().Bldr().Wiki().Import();
this.redirect_mgr = wiki.Redirect_mgr(); this.redirect_mgr = wiki.Redirect_mgr();
@ -50,7 +50,7 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xob_page_wkr, Gf
page_core_tbl.Insert_bgn(); page_core_tbl.Insert_bgn();
usr_dlg.Prog_many("", "", "import.page.bgn"); usr_dlg.Prog_many("", "", "import.page.bgn");
} }
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
int id = page.Id(); int id = page.Id();
DateAdp modified = page.Modified_on(); if (modified.compareTo(modified_latest) == CompareAble_.More) modified_latest = modified; DateAdp modified = page.Modified_on(); if (modified.compareTo(modified_latest) == CompareAble_.More) modified_latest = modified;
byte[] text_raw = page.Text(); int text_raw_len = page.Text_len(); byte[] text_raw = page.Text(); int text_raw_len = page.Text_len();
@ -77,9 +77,12 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xob_page_wkr, Gf
if (dg_match_mgr != null) dg_match_mgr.Commit(); if (dg_match_mgr != null) dg_match_mgr.Commit();
} }
} }
public void Wkr_end() { public void Page_wkr__run_cleanup() {
usr_dlg.Log_many("", "", "import.page: insert done; committing pages; pages=~{0}", page_count_all); usr_dlg.Log_many("", "", "import.page: insert done; committing pages; pages=~{0}", page_count_all);
page_core_tbl.Insert_end(); ns_to_db_mgr.Rls_all(); ns_to_db_mgr.Rls_all();
page_core_tbl.Insert_end();
}
public void Page_wkr__end() {
if (dg_match_mgr != null) dg_match_mgr.Rls(); if (dg_match_mgr != null) dg_match_mgr.Rls();
usr_dlg.Log_many("", "", "import.page: updating core stats"); usr_dlg.Log_many("", "", "import.page: updating core stats");
Xow_ns_mgr ns_mgr = wiki.Ns_mgr(); Xow_ns_mgr ns_mgr = wiki.Ns_mgr();

View File

@ -21,16 +21,16 @@ import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.
import gplx.xowa.langs.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.langs.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.data.tbls.*;
public abstract class Srch_bldr_wkr_base extends Xob_itm_dump_base implements Xob_page_wkr { public abstract class Srch_bldr_wkr_base extends Xob_itm_dump_base implements Xob_page_wkr {
private final Ordered_hash list = Ordered_hash_.New(); private Xol_lang_itm lang; private final Ordered_hash list = Ordered_hash_.New(); private Xol_lang_itm lang;
public abstract String Wkr_key(); public abstract String Page_wkr__key();
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
make_dir = wiki.Tdb_fsys_mgr().Ns_dir(); make_dir = wiki.Tdb_fsys_mgr().Ns_dir();
this.Init_dump(this.Wkr_key(), make_dir); this.Init_dump(this.Page_wkr__key(), make_dir);
lang = wiki.Lang(); // wiki.Appe().Lang_mgr().Lang_en(); // NOTE: was .Lang_en which is wrong (should match lang of wiki); DATE:2013-05-11 lang = wiki.Lang(); // wiki.Appe().Lang_mgr().Lang_en(); // NOTE: was .Lang_en which is wrong (should match lang of wiki); DATE:2013-05-11
tmp_wtr_mgr = new Xob_tmp_wtr_mgr(new Xob_tmp_wtr_wkr__ttl(temp_dir, dump_fil_len)); tmp_wtr_mgr = new Xob_tmp_wtr_mgr(new Xob_tmp_wtr_wkr__ttl(temp_dir, dump_fil_len));
if (wiki.Db_mgr().Tid() == Xodb_mgr_sql.Tid_sql) // if sqlite, hard-code to ns_main; aggregates all ns into one if (wiki.Db_mgr().Tid() == Xodb_mgr_sql.Tid_sql) // if sqlite, hard-code to ns_main; aggregates all ns into one
ns_main = wiki.Ns_mgr().Ns_main(); ns_main = wiki.Ns_mgr().Ns_main();
} private Xob_tmp_wtr_mgr tmp_wtr_mgr; private Xow_ns ns_main; } private Xob_tmp_wtr_mgr tmp_wtr_mgr; private Xow_ns ns_main;
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
// if (page.Ns_id() != Xow_ns_.Tid__main) return; // limit to main ns for now // if (page.Ns_id() != Xow_ns_.Tid__main) return; // limit to main ns for now
try { try {
byte[] ttl = page.Ttl_page_db(); byte[] ttl = page.Ttl_page_db();
@ -51,7 +51,8 @@ public abstract class Srch_bldr_wkr_base extends Xob_itm_dump_base implements Xo
} }
} catch (Exception e) {bldr.Usr_dlg().Warn_many("", "", "search_index:fatal error: err=~{0}", Err_.Message_gplx_full(e));} // never let single page crash entire import } catch (Exception e) {bldr.Usr_dlg().Warn_many("", "", "search_index:fatal error: err=~{0}", Err_.Message_gplx_full(e));} // never let single page crash entire import
} }
public void Wkr_end() { public void Page_wkr__run_cleanup() {}
public void Page_wkr__end() {
tmp_wtr_mgr.Flush_all(bldr.Usr_dlg()); tmp_wtr_mgr.Flush_all(bldr.Usr_dlg());
dump_bfr.ClearAndReset(); dump_bfr.ClearAndReset();
Xobdc_merger.Ns(bldr.Usr_dlg(), tmp_wtr_mgr.Regy(), Xotdb_dir_info_.Name_search_ttl, temp_dir, make_dir, sort_mem_len, Io_line_rdr_key_gen_.first_pipe, this.Make_cmd_site()); Xobdc_merger.Ns(bldr.Usr_dlg(), tmp_wtr_mgr.Regy(), Xotdb_dir_info_.Name_search_ttl, temp_dir, make_dir, sort_mem_len, Io_line_rdr_key_gen_.first_pipe, this.Make_cmd_site());

View File

@ -20,16 +20,17 @@ import gplx.core.ios.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.da
import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xob_make_id_wkr extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble { public class Xob_make_id_wkr extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble {
public Xob_make_id_wkr(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);} public Xob_make_id_wkr(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Wkr_key() {return KEY;} public static final String KEY = "core.make_id"; public String Page_wkr__key() {return KEY;} public static final String KEY = "core.make_id";
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
this.Init_dump(KEY, wiki.Tdb_fsys_mgr().Site_dir().GenSubDir(Xotdb_dir_info_.Name_id)); this.Init_dump(KEY, wiki.Tdb_fsys_mgr().Site_dir().GenSubDir(Xotdb_dir_info_.Name_id));
} }
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
byte[] ttl = page.Ttl_page_db(); byte[] ttl = page.Ttl_page_db();
if (dump_bfr.Len() + row_fixed_len + ttl.length > dump_fil_len) Io_mgr.Instance.AppendFilBfr(dump_url_gen.Nxt_url(), dump_bfr); if (dump_bfr.Len() + row_fixed_len + ttl.length > dump_fil_len) Io_mgr.Instance.AppendFilBfr(dump_url_gen.Nxt_url(), dump_bfr);
Xotdb_page_itm_.Txt_id_save(dump_bfr, page); Xotdb_page_itm_.Txt_id_save(dump_bfr, page);
} }
public void Wkr_end() { public void Page_wkr__run_cleanup() {}
public void Page_wkr__end() {
this.Term_dump(new Xob_make_cmd_site(bldr.Usr_dlg(), make_dir, make_fil_len)); this.Term_dump(new Xob_make_cmd_site(bldr.Usr_dlg(), make_dir, make_fil_len));
if (delete_temp) Io_mgr.Instance.DeleteDirDeep(temp_dir); if (delete_temp) Io_mgr.Instance.DeleteDirDeep(temp_dir);
} }

View File

@ -23,8 +23,8 @@ import gplx.xowa.parsers.utils.*;
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.xdats.*; import gplx.xowa.wikis.tdbs.stats.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.xdats.*; import gplx.xowa.wikis.tdbs.stats.*;
public class Xob_page_txt extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble { public class Xob_page_txt extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble {
public Xob_page_txt(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);} public Xob_page_txt(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Wkr_key() {return Xob_cmd_keys.Key_tdb_make_page;} public String Page_wkr__key() {return Xob_cmd_keys.Key_tdb_make_page;}
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
redirect_mgr = wiki.Redirect_mgr(); page_storage_type = wiki.Appe().Setup_mgr().Dump_mgr().Data_storage_format(); redirect_mgr = wiki.Redirect_mgr(); page_storage_type = wiki.Appe().Setup_mgr().Dump_mgr().Data_storage_format();
fsys_mgr = wiki.Tdb_fsys_mgr(); fsys_mgr = wiki.Tdb_fsys_mgr();
make_dir = fsys_mgr.Ns_dir(); make_dir = fsys_mgr.Ns_dir();
@ -36,7 +36,7 @@ public class Xob_page_txt extends Xob_itm_dump_base implements Xob_page_wkr, Gfo
int page_file_len = 512 * Io_mgr.Len_kb, title_file_len = 64 * Io_mgr.Len_kb; Xob_tmp_wtr_mgr ttl_wtr_mgr; int page_file_len = 512 * Io_mgr.Len_kb, title_file_len = 64 * Io_mgr.Len_kb; Xob_tmp_wtr_mgr ttl_wtr_mgr;
Xob_xdat_file_wtr[] page_wtr_regy = new Xob_xdat_file_wtr[Ns_ordinal_max]; static final int Ns_ordinal_max = Xow_ns_mgr_.Ordinal_max; // ASSUME: no more than 128 ns in a wiki Xob_xdat_file_wtr[] page_wtr_regy = new Xob_xdat_file_wtr[Ns_ordinal_max]; static final int Ns_ordinal_max = Xow_ns_mgr_.Ordinal_max; // ASSUME: no more than 128 ns in a wiki
Xob_stat_type data_rpt_typ; Xob_stat_mgr stat_mgr = new Xob_stat_mgr(); byte page_storage_type; Xob_stat_type data_rpt_typ; Xob_stat_mgr stat_mgr = new Xob_stat_mgr(); byte page_storage_type;
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
int id = page.Id(); byte[] ttl_wo_ns = page.Ttl_page_db(), text = page.Text(); int ttl_len = ttl_wo_ns.length, text_len = text.length; Xow_ns ns = page.Ns(); int id = page.Id(); byte[] ttl_wo_ns = page.Ttl_page_db(), text = page.Text(); int ttl_len = ttl_wo_ns.length, text_len = text.length; Xow_ns ns = page.Ns();
boolean redirect = redirect_mgr.Is_redirect(text, text_len); boolean redirect = redirect_mgr.Is_redirect(text, text_len);
page.Redirected_(redirect); page.Redirected_(redirect);
@ -54,7 +54,8 @@ public class Xob_page_txt extends Xob_itm_dump_base implements Xob_page_wkr, Gfo
if (ttl_wtr.FlushNeeded(Xotdb_page_itm_.Txt_ttl_len__fixed + ttl_len)) ttl_wtr.Flush(bldr.Usr_dlg()); if (ttl_wtr.FlushNeeded(Xotdb_page_itm_.Txt_ttl_len__fixed + ttl_len)) ttl_wtr.Flush(bldr.Usr_dlg());
Xotdb_page_itm_.Txt_ttl_save(ttl_wtr.Bfr(), id, file_idx, row_idx, redirect, text_len, ttl_wo_ns); Xotdb_page_itm_.Txt_ttl_save(ttl_wtr.Bfr(), id, file_idx, row_idx, redirect, text_len, ttl_wo_ns);
} }
public void Wkr_end() { public void Page_wkr__run_cleanup() {}
public void Page_wkr__end() {
Flush_page(page_wtr_regy); Flush_page(page_wtr_regy);
ttl_wtr_mgr.Flush_all(bldr.Usr_dlg()); ttl_wtr_mgr.Flush_all(bldr.Usr_dlg());
Xobdc_merger.Ns(bldr.Usr_dlg(), ttl_wtr_mgr.Regy(), Xotdb_dir_info_.Name_title, temp_dir, make_dir, sort_mem_len, Io_line_rdr_key_gen_.last_pipe, new Io_sort_cmd_ns(bldr.Usr_dlg())); Xobdc_merger.Ns(bldr.Usr_dlg(), ttl_wtr_mgr.Regy(), Xotdb_dir_info_.Name_title, temp_dir, make_dir, sort_mem_len, Io_line_rdr_key_gen_.last_pipe, new Io_sort_cmd_ns(bldr.Usr_dlg()));

View File

@ -20,16 +20,17 @@ import gplx.core.ios.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wik
import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xob_parse_dump_templates_cmd extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble { public class Xob_parse_dump_templates_cmd extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble {
public Xob_parse_dump_templates_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);} public Xob_parse_dump_templates_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Wkr_key() {return KEY;} public static final String KEY = "parse.dump_templates"; public String Page_wkr__key() {return KEY;} public static final String KEY = "parse.dump_templates";
public static final int FixedLen_page = 1 + 5 + 1 + 5 + 1 + 1 + 1; // \tid|date|title|text\n public static final int FixedLen_page = 1 + 5 + 1 + 5 + 1 + 1 + 1; // \tid|date|title|text\n
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
Init_dump(KEY); Init_dump(KEY);
} }
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
if (page.Ns_id() != Xow_ns_.Tid__template) return; if (page.Ns_id() != Xow_ns_.Tid__template) return;
int id = page.Id(); byte[] title = page.Ttl_page_db(), text = page.Text(); int title_len = title.length, text_len = text.length; int id = page.Id(); byte[] title = page.Ttl_page_db(), text = page.Text(); int title_len = title.length, text_len = text.length;
if (FixedLen_page + title_len + text_len + dump_bfr.Len() > dump_fil_len) super.Flush_dump(); if (FixedLen_page + title_len + text_len + dump_bfr.Len() > dump_fil_len) super.Flush_dump();
Xotdb_page_itm_.Txt_page_save(dump_bfr, id, page.Modified_on(), title, text, true); Xotdb_page_itm_.Txt_page_save(dump_bfr, id, page.Modified_on(), title, text, true);
} }
public void Wkr_end() {super.Flush_dump();} public void Page_wkr__run_cleanup() {}
public void Page_wkr__end() {super.Flush_dump();}
} }

View File

@ -19,7 +19,7 @@ package gplx.xowa.bldrs.cmds.texts.tdbs; import gplx.*; import gplx.xowa.*; impo
import gplx.xowa.addons.apps.searchs.bldrs.*; import gplx.xowa.addons.apps.searchs.bldrs.*;
public class Xob_search_tdb extends Srch_bldr_wkr_base { public class Xob_search_tdb extends Srch_bldr_wkr_base {
public Xob_search_tdb(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);} public Xob_search_tdb(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
@Override public String Wkr_key() {return Xob_cmd_keys.Key_tdb_make_search_title;} @Override public String Page_wkr__key() {return Xob_cmd_keys.Key_tdb_make_search_title;}
@Override public gplx.core.ios.Io_make_cmd Make_cmd_site() { @Override public gplx.core.ios.Io_make_cmd Make_cmd_site() {
return new Xob_make_cmd_site(bldr.Usr_dlg(), this.make_dir, this.make_fil_len); return new Xob_make_cmd_site(bldr.Usr_dlg(), this.make_dir, this.make_fil_len);
} }

View File

@ -15,10 +15,11 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*; package gplx.xowa.bldrs.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
public interface Xob_page_wkr extends GfoInvkAble { public interface Xob_page_wkr extends GfoInvkAble {
String Wkr_key(); String Page_wkr__key();
void Wkr_bgn(Xob_bldr bldr); void Page_wkr__bgn();
void Wkr_run(gplx.xowa.wikis.data.tbls.Xowd_page_itm page); void Page_wkr__run(gplx.xowa.wikis.data.tbls.Xowd_page_itm page);
void Wkr_end(); void Page_wkr__run_cleanup(); // close txns opened during Page_wkr__run
void Page_wkr__end();
} }

View File

@ -81,7 +81,7 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble {
public static final String Invk_page_read_ = "page_read_", Invk_page_edit_ = "page_edit_", Invk_page_html_ = "page_html_", Invk_xowa_div_edit_rename_ = "xowa_div_edit_rename_"; public static final String Invk_page_read_ = "page_read_", Invk_page_edit_ = "page_edit_", Invk_page_html_ = "page_html_", Invk_xowa_div_edit_rename_ = "xowa_div_edit_rename_";
private static final String[] Fmtr_keys = new String[] private static final String[] Fmtr_keys = new String[]
{ "app_root_dir", "app_version", "app_build_date", "xowa_mode_is_server" { "app_root_dir", "app_version", "app_build_date", "xowa_mode_is_server"
, "page_id", "page_name", "page_title", "page_modified_on_msg", "page_heading" , "page_id", "page_name", "page_heading", "page_modified_on_msg"
, "html_css_common_path", "html_css_wiki_path", "xowa_head" , "html_css_common_path", "html_css_wiki_path", "xowa_head"
, "page_lang_ltr", "page_indicators", "page_content_sub", "page_jumpto", "page_pgbnr", "page_body_cls", "html_content_editable" , "page_lang_ltr", "page_indicators", "page_content_sub", "page_jumpto", "page_pgbnr", "page_body_cls", "html_content_editable"
, "page_data", "page_langs" , "page_data", "page_langs"

View File

@ -87,14 +87,14 @@ public class Xoh_page_wtr_wkr {
page_ttl = Xoa_ttl.parse(wiki, page_ttl.Ns().Id(), converted_title); page_ttl = Xoa_ttl.parse(wiki, page_ttl.Ns().Id(), converted_title);
} }
byte[] page_name = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null); // NOTE: page_name does not show display_title (<i>). always pass in null byte[] page_name = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null); // NOTE: page_name does not show display_title (<i>). always pass in null
byte[] page_display = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl()); byte[] page_display_title = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl());
page.Html_data().Custom_tab_name_(page_name); // set tab_name to page_name; note that if null, gui code will ignore and use Ttl.Page_txt; PAGE: zh.w:釣魚臺列嶼主權問題 DATE:2015-10-05 page.Html_data().Custom_tab_name_(page_name); // set tab_name to page_name; note that if null, gui code will ignore and use Ttl.Page_txt; PAGE: zh.w:釣魚臺列嶼主權問題 DATE:2015-10-05
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert(); Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
fmtr.Bld_bfr_many(bfr fmtr.Bld_bfr_many(bfr
, root_dir_bry, Xoa_app_.Version, Xoa_app_.Build_date, app.Tcp_server().Running_str() , root_dir_bry, Xoa_app_.Version, Xoa_app_.Build_date, app.Tcp_server().Running_str()
, page.Revision_data().Id() , page.Revision_data().Id()
, page_name, page_display , page_name, page.Html_data().Page_heading().Init(page.Html_data(), page_display_title)
, modified_on_msg, page.Html_data().Page_heading().Init(page) , modified_on_msg
, mgr.Css_common_bry(), mgr.Css_wiki_bry(), page.Html_data().Head_mgr().Init(app, wiki, page).Init_dflts() , mgr.Css_common_bry(), mgr.Css_wiki_bry(), page.Html_data().Head_mgr().Init(app, wiki, page).Init_dflts()
, page.Lang().Dir_ltr_bry(), page.Html_data().Indicators(), page_content_sub, wiki.Html_mgr().Portal_mgr().Div_jump_to(), wiki.Xtn_mgr().Xtn_pgbnr().Write_html(ctx, page, hctx, page_data), page_body_class, html_content_editable , page.Lang().Dir_ltr_bry(), page.Html_data().Indicators(), page_content_sub, wiki.Html_mgr().Portal_mgr().Div_jump_to(), wiki.Xtn_mgr().Xtn_pgbnr().Write_html(ctx, page, hctx, page_data), page_body_class, html_content_editable
, page_data, wdata_lang_wtr , page_data, wdata_lang_wtr
@ -102,8 +102,8 @@ public class Xoh_page_wtr_wkr {
, portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar), portal_mgr.Div_wikis_bry(app.Utl__bfr_mkr()), portal_mgr.Sidebar_mgr().Html_bry() , portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar), portal_mgr.Div_wikis_bry(app.Utl__bfr_mkr()), portal_mgr.Sidebar_mgr().Html_bry()
, mgr.Edit_rename_div_bry(page_ttl), page.Html_data().Edit_preview_w_dbg(), js_edit_toolbar_bry , mgr.Edit_rename_div_bry(page_ttl), page.Html_data().Edit_preview_w_dbg(), js_edit_toolbar_bry
); );
Xoh_page_wtr_wkr_.Bld_head_end(bfr, page); // add after </head> Xoh_page_wtr_wkr_.Bld_head_end(bfr, tmp_bfr, page); // add after </head>
Xoh_page_wtr_wkr_.Bld_html_end(bfr, page); // add after </html> Xoh_page_wtr_wkr_.Bld_html_end(bfr, tmp_bfr, page); // add after </html>
} }
public void Write_body(Bry_bfr bfr, Xoh_wtr_ctx hctx, Xoae_page page) { public void Write_body(Bry_bfr bfr, Xoh_wtr_ctx hctx, Xoae_page page) {
synchronized (thread_lock_2) { synchronized (thread_lock_2) {

View File

@ -35,9 +35,9 @@ public class Xoh_page_wtr_wkr_ {
else else
return ttl.Full_txt_w_ttl_case(); // NOTE: include ns with ttl as per defect d88a87b3 return ttl.Full_txt_w_ttl_case(); // NOTE: include ns with ttl as per defect d88a87b3
} }
public static void Bld_head_end(Bry_bfr html_bfr, Xoae_page page) { public static void Bld_head_end(Bry_bfr html_bfr, Bry_bfr tmp_bfr, Xoae_page page) {
byte[] head_end = page.Html_data().Custom_head_end(); byte[] head_end = page.Html_data().Custom_head_tags().To_html(tmp_bfr);
if (head_end == null) return; if (Bry_.Len_eq_0(head_end)) return;
int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Gfh_tag_.Head_rhs); int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Gfh_tag_.Head_rhs);
if (insert_pos == Bry_find_.Not_found) { if (insert_pos == Bry_find_.Not_found) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </head>"); Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </head>");
@ -45,8 +45,8 @@ public class Xoh_page_wtr_wkr_ {
} }
html_bfr.Insert_at(insert_pos, head_end); html_bfr.Insert_at(insert_pos, head_end);
} }
public static void Bld_html_end(Bry_bfr html_bfr, Xoae_page page) { public static void Bld_html_end(Bry_bfr html_bfr, Bry_bfr tmp_bfr, Xoae_page page) {
byte[] html_end = page.Html_data().Custom_html_end(); byte[] html_end = page.Html_data().Custom_tail_tags().To_html(tmp_bfr);
if (html_end == null) return; if (html_end == null) return;
int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Gfh_tag_.Html_rhs, html_bfr.Len()); int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Gfh_tag_.Html_rhs, html_bfr.Len());
if (insert_pos == Bry_find_.Not_found) { if (insert_pos == Bry_find_.Not_found) {

View File

@ -21,9 +21,17 @@ import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkes.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public class Xoh_lnke_html { public class Xoh_lnke_html {
private static final byte[] Disabled_button = Bry_.new_a7("&#x2297;");
public void Write_html(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke) { public void Write_html(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke) {
int href_bgn = lnke.Lnke_href_bgn(), href_end = lnke.Lnke_href_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa; int href_bgn = lnke.Lnke_href_bgn(), href_end = lnke.Lnke_href_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
byte lnke_type = Calc_type(lnke); byte lnke_type = Calc_type(lnke);
if (proto_is_xowa && hctx.Mode() == Xoh_wtr_ctx.Mode_file_dump) { // if protocol and file-dump, then don't write link; DATE:2016-04-12
bfr.Add(Gfh_tag_.Div_lhs);
Write_caption(bfr, html_wtr, hctx, ctx, src, lnke, href_bgn, href_end, proto_is_xowa);
bfr.Add(Gfh_entity_.Nbsp_num_bry).Add(Disabled_button);
bfr.Add(Gfh_tag_.Div_rhs);
return;
}
if (!hctx.Mode_is_alt()) { // do not write "<a ...>" if mode is alt if (!hctx.Mode_is_alt()) { // do not write "<a ...>" if mode is alt
bfr.Add(Gfh_bldr_.Bry__a_lhs_w_href); bfr.Add(Gfh_bldr_.Bry__a_lhs_w_href);
if (Write_href(bfr, hctx, ctx, src, lnke, href_bgn, href_end, proto_is_xowa)) if (Write_href(bfr, hctx, ctx, src, lnke, href_bgn, href_end, proto_is_xowa))

View File

@ -99,7 +99,9 @@ public class Xoh_href_wtr {
encoder.Encode(encoder_bfr, ttl_full, page_bgn, page_end); // add page encoder.Encode(encoder_bfr, ttl_full, page_bgn, page_end); // add page
if (hctx.Mode() == Xoh_wtr_ctx.Mode_file_dump) { if (hctx.Mode() == Xoh_wtr_ctx.Mode_file_dump) {
byte[] href_end = hctx.Anch__href__end(); byte[] href_end = hctx.Anch__href__end();
if (href_end != null) encoder_bfr.Add(href_end); if ( href_end != null
&& page_end - page_bgn > 0) // handle [[#A]] which will have no page; else will dump "home/page/.html#A"; DATE:2016-04-12
encoder_bfr.Add(href_end);
} }
encoder.Encode(encoder_bfr, ttl_full, anch_bgn, ttl_full.length); // add anchor encoder.Encode(encoder_bfr, ttl_full, anch_bgn, ttl_full.length); // add anchor
} }

View File

@ -42,9 +42,15 @@ public class Xow_parser_mgr {
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw()); Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw());
if (clear) {page.Clear_all();} if (clear) {page.Clear_all();}
Xoa_ttl ttl = page.Ttl(); Xoa_ttl ttl = page.Ttl();
if ( Xow_page_tid.Identify(wiki.Domain_tid(), ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10 if ( Xow_page_tid.Identify(wiki.Domain_tid(), ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) { // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10
main.Parse_text_to_wdom(root, ctx, tkn_mkr, page.Data_raw(), Xop_parser_.Doc_bgn_bos); byte[] data_raw = page.Data_raw();
// if (wiki.Domain_tid() == gplx.xowa.wikis.domains.Xow_domain_tid_.Int__home) {
// data_raw = Bry_.Add(Temp__page_title, data_raw);
// }
main.Parse_text_to_wdom(root, ctx, tkn_mkr, data_raw , Xop_parser_.Doc_bgn_bos);
}
page.Root_(root); page.Root_(root);
root.Data_htm_(root.Root_src()); root.Data_htm_(root.Root_src());
} }
// private static final byte[] Temp__page_title = Bry_.new_a7("{{PageTitle}}");
} }

View File

@ -347,7 +347,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
if ( cache_itm != null if ( cache_itm != null
// && Bry_.Eq(cache_itm.Ttl().Full_db(), ctx.Page().Page_ttl().Full_db()) // make sure that transcluded item is not same as page_ttl; DATE:2014-01-10 // && Bry_.Eq(cache_itm.Ttl().Full_db(), ctx.Page().Page_ttl().Full_db()) // make sure that transcluded item is not same as page_ttl; DATE:2014-01-10
) { ) {
transclude_src = cache_itm.Wtxt(); transclude_src = cache_itm.Wtxt__direct();
page_ttl = cache_itm.Ttl(); page_ttl = cache_itm.Ttl();
} }
} }
@ -372,7 +372,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
} }
public static Xot_defn_tmpl Load_defn(Xowe_wiki wiki, Xop_ctx ctx, Xot_invk_tkn invk_tkn, Xoa_ttl ttl, byte[] name_ary) { public static Xot_defn_tmpl Load_defn(Xowe_wiki wiki, Xop_ctx ctx, Xot_invk_tkn invk_tkn, Xoa_ttl ttl, byte[] name_ary) {
Xow_page_cache_itm tmpl_page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl); Xow_page_cache_itm tmpl_page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl);
byte[] tmpl_page_bry = tmpl_page_itm == null ? null : tmpl_page_itm.Wtxt(); byte[] tmpl_page_bry = tmpl_page_itm == null ? null : tmpl_page_itm.Wtxt__direct();
Xot_defn_tmpl rv = null; Xot_defn_tmpl rv = null;
if (tmpl_page_bry != null) { if (tmpl_page_bry != null) {
byte old_parse_tid = ctx.Parse_tid(); // NOTE: reusing ctxs is a bad idea; will change Parse_tid and cause strange errors; however, keeping for PERF reasons byte old_parse_tid = ctx.Parse_tid(); // NOTE: reusing ctxs is a bad idea; will change Parse_tid and cause strange errors; however, keeping for PERF reasons
@ -409,7 +409,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
Xow_page_cache_itm cache_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl); Xow_page_cache_itm cache_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl);
if ( cache_itm != null) { if ( cache_itm != null) {
if (!Bry_.Eq(cache_itm.Ttl().Full_db(), ctx.Page().Ttl().Full_db())) { // make sure that transcluded item is not same as page_ttl; DATE:2014-01-10 if (!Bry_.Eq(cache_itm.Ttl().Full_db(), ctx.Page().Ttl().Full_db())) { // make sure that transcluded item is not same as page_ttl; DATE:2014-01-10
transclude_tmpl = ctx.Wiki().Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), page_ttl.Ns(), page_ttl.Page_db(), cache_itm.Wtxt()); transclude_tmpl = ctx.Wiki().Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), page_ttl.Ns(), page_ttl.Page_db(), cache_itm.Wtxt__direct());
page_ttl = cache_itm.Ttl(); page_ttl = cache_itm.Ttl();
} }
} }

View File

@ -19,7 +19,7 @@ package gplx.xowa.specials.randoms; import gplx.*; import gplx.xowa.*; import gp
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.nss.*;
public class Xows_page_random implements Xows_page { public class Xows_page_random implements Xows_page {
public Xows_page_random(Xowe_wiki wiki) {} public Xows_page_random(Xowe_wiki wiki) {}
public Rndm_mgr Mgr() {return mgr;} private final Rndm_mgr mgr = new Rndm_mgr(); // public Rndm_mgr Mgr() {return mgr;} private final Rndm_mgr mgr = new Rndm_mgr();
public Xows_special_meta Special__meta() {return Xows_special_meta_.Itm__random;} public Xows_special_meta Special__meta() {return Xows_special_meta_.Itm__random;}
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) { public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei; Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;

View File

@ -22,7 +22,7 @@ public class Xow_page_cache {
public Xow_page_cache(Xowe_wiki wiki) {this.wiki = wiki;} public Xow_page_cache(Xowe_wiki wiki) {this.wiki = wiki;}
public byte[] Get_or_load_as_src(Xoa_ttl ttl) { public byte[] Get_or_load_as_src(Xoa_ttl ttl) {
Xow_page_cache_itm rv = Get_or_load_as_itm(ttl); Xow_page_cache_itm rv = Get_or_load_as_itm(ttl);
return rv == null ? null : rv.Wtxt(); return rv == null ? null : rv.Wtxt__direct();
} }
public Xow_page_cache_itm Get_or_load_as_itm(Xoa_ttl ttl) { public Xow_page_cache_itm Get_or_load_as_itm(Xoa_ttl ttl) {
byte[] ttl_full_db = ttl.Full_db(); byte[] ttl_full_db = ttl.Full_db();

View File

@ -17,11 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_page_cache_itm { public class Xow_page_cache_itm {
public Xow_page_cache_itm(Xoa_ttl ttl, byte[] wtxt, byte[] redirected_src_wtxt) { public Xow_page_cache_itm(Xoa_ttl ttl, byte[] wtxt__direct, byte[] wtxt__redirect) {
this.ttl = ttl; this.wtxt = wtxt; this.redirected_src_wtxt = redirected_src_wtxt; this.ttl = ttl; this.wtxt__direct = wtxt__direct; this.wtxt__redirect = wtxt__redirect;
} }
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl; public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
public byte[] Wtxt() {return wtxt;} private byte[] wtxt; public byte[] Wtxt__direct() {return wtxt__direct;} private byte[] wtxt__direct;
public byte[] Redirected_src_wtxt() {return redirected_src_wtxt;} private byte[] redirected_src_wtxt; public byte[] Wtxt__redirect() {return wtxt__redirect;} private byte[] wtxt__redirect;
public byte[] Wtxt__redirect_or_direct() {
return wtxt__redirect == null ? wtxt__direct : wtxt__redirect;
}
public static final Xow_page_cache_itm Null = null; public static final Xow_page_cache_itm Null = null;
} }

View File

@ -24,7 +24,7 @@ public class Xowd_db_file_ {
, Tid_wiki_solo = 8, Tid_text_solo = 9 , Tid_wiki_solo = 8, Tid_text_solo = 9
, Tid_html_solo = 10, Tid_html_data = 11 , Tid_html_solo = 10, Tid_html_data = 11
, Tid_file_solo = 12, Tid_file_core = 13, Tid_file_data = 14, Tid_file_user = 15 , Tid_file_solo = 12, Tid_file_core = 13, Tid_file_data = 14, Tid_file_user = 15
, Tid_search_link = 16 , Tid_search_link = 16, Tid_random = 17
; ;
private static final String private static final String
Key_core = "core", Key_text = "text", Key_cat = "xtn.category", Key_search_core = "xtn.search.core", Key_wbase = "core.wbase" Key_core = "core", Key_text = "text", Key_cat = "xtn.category", Key_search_core = "xtn.search.core", Key_wbase = "core.wbase"
@ -32,7 +32,7 @@ public class Xowd_db_file_ {
, Key_text_solo = "text.solo", Key_wiki_solo = "wiki.solo" , Key_text_solo = "text.solo", Key_wiki_solo = "wiki.solo"
, Key_html_solo = "html.solo", Key_html_data = "html" , Key_html_solo = "html.solo", Key_html_data = "html"
, Key_file_solo = "file.solo", Key_file_core = "file.core", Key_file_data = "file.data", Key_file_user = "file.user" , Key_file_solo = "file.solo", Key_file_core = "file.core", Key_file_data = "file.data", Key_file_user = "file.user"
, Key_search_link = "xtn.search.link" , Key_search_link = "xtn.search.link", Key_random = "xtn.random"
; ;
public static String To_key(byte v) { public static String To_key(byte v) {
switch (v) { switch (v) {
@ -52,6 +52,7 @@ public class Xowd_db_file_ {
case Tid_file_data: return Key_file_data; case Tid_file_data: return Key_file_data;
case Tid_file_user: return Key_file_user; case Tid_file_user: return Key_file_user;
case Tid_search_link: return Key_search_link; case Tid_search_link: return Key_search_link;
case Tid_random: return Key_random;
default: throw Err_.new_unhandled(v); default: throw Err_.new_unhandled(v);
} }
} }

View File

@ -63,6 +63,10 @@ public class Xowd_db_mgr {
Dbs__set_by_tid(rv); Dbs__set_by_tid(rv);
return rv; return rv;
} }
public Xowd_db_file Dbs__remake_by_tid(byte tid) {
Dbs__delete_by_tid(tid);
return Dbs__make_by_tid(tid);
}
public void Dbs__delete_by_tid(byte... tids) { public void Dbs__delete_by_tid(byte... tids) {
int len = dbs__ary_len; int len = dbs__ary_len;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {

View File

@ -69,7 +69,7 @@ public class Xowd_page_tbl implements Rls_able {
this.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, page_is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id); this.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, page_is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id);
this.Insert_end(); this.Insert_end();
} }
public void Insert_bgn() {conn.Txn_bgn("schema__page__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);} public void Insert_bgn() {conn.Txn_bgn("page__insert_bulk"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);} public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) { public void Insert_cmd_by_batch(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) {
stmt_insert.Clear() stmt_insert.Clear()

View File

@ -29,8 +29,8 @@ public class Xow_wiki_props implements GfoInvkAble {
public byte Protocol_tid() {return protocol_tid;} private final byte protocol_tid = gplx.core.net.Gfo_protocol_itm.Tid_https; // NOTE: default protocol to https; handles external links like [//a.org]; may need to be changed for wikia or other non-WMF wikis; DATE:2015-07-27 public byte Protocol_tid() {return protocol_tid;} private final byte protocol_tid = gplx.core.net.Gfo_protocol_itm.Tid_https; // NOTE: default protocol to https; handles external links like [//a.org]; may need to be changed for wikia or other non-WMF wikis; DATE:2015-07-27
public byte[] Site_name() {return site_name;} private byte[] site_name = Bry_.Empty; public byte[] Site_name() {return site_name;} private byte[] site_name = Bry_.Empty;
public byte[] ServerName() {return serverName;} public Xow_wiki_props ServerName_(byte[] v) {serverName = v; server = Bry_.Add(bry_http, v); return this;} private byte[] serverName = Bry_.new_a7("localhost"); public byte[] Server_name() {return server_name;} private byte[] server_name = Bry_.new_a7("localhost");
public byte[] Server() {return server;} private byte[] server = Bry_.new_a7("http://localhost"); static final byte[] bry_http = Bry_.new_a7("http://"); public byte[] Server() {return server;} private byte[] server = Bry_.new_a7("http://localhost");
public byte[] ArticlePath() {return articlePath;} public Xow_wiki_props ArticlePath_(byte[] v) {articlePath = v; return this;} private byte[] articlePath = Xoh_href_.Bry__wiki; public byte[] ArticlePath() {return articlePath;} public Xow_wiki_props ArticlePath_(byte[] v) {articlePath = v; return this;} private byte[] articlePath = Xoh_href_.Bry__wiki;
public byte[] ScriptPath() {return scriptPath;} public Xow_wiki_props ScriptPath_(byte[] v) {scriptPath = v; return this;} private byte[] scriptPath = Bry_.new_a7("/wiki"); public byte[] ScriptPath() {return scriptPath;} public Xow_wiki_props ScriptPath_(byte[] v) {scriptPath = v; return this;} private byte[] scriptPath = Bry_.new_a7("/wiki");
public byte[] StylePath() {return stylePath;} public Xow_wiki_props StylePath_(byte[] v) {stylePath = v; return this;} private byte[] stylePath = Bry_.new_a7("/wiki/skins"); public byte[] StylePath() {return stylePath;} public Xow_wiki_props StylePath_(byte[] v) {stylePath = v; return this;} private byte[] stylePath = Bry_.new_a7("/wiki/skins");
@ -42,7 +42,12 @@ public class Xow_wiki_props implements GfoInvkAble {
public byte[] Siteinfo_misc() {return siteinfo_misc;} public byte[] Siteinfo_misc() {return siteinfo_misc;}
public byte[] Siteinfo_mainpage() {return siteinfo_mainpage;} private byte[] siteinfo_mainpage = Bry_.Empty; public byte[] Siteinfo_mainpage() {return siteinfo_mainpage;} private byte[] siteinfo_mainpage = Bry_.Empty;
public DateAdp Modified_latest() {return modified_latest;} private DateAdp modified_latest; public DateAdp Modified_latest() {return modified_latest;} private DateAdp modified_latest;
public Xow_wiki_props SiteName_(int v) {site_name = Bry_.new_a7(String_.UpperFirst(String_.new_a7(Xow_domain_tid_.Get_type_as_bry(v)))); return this;} public Xow_wiki_props Init_props(int domain_tid, byte[] domain_bry) {
this.site_name = Bry_.new_a7(String_.UpperFirst(String_.new_a7(Xow_domain_tid_.Get_type_as_bry(domain_tid)))); // EX: "Wikipedia"
this.server_name = domain_bry; // EX: "en.wikipedia.org"
this.server = Bry_.Add(gplx.core.net.Gfo_protocol_itm.Itm_https.Text_bry(), domain_bry); // EX: "https://en.wikipedia.org"
return this;
}
public Xow_wiki_props Siteinfo_misc_(byte[] v) { public Xow_wiki_props Siteinfo_misc_(byte[] v) {
siteinfo_misc = v; siteinfo_misc = v;
int pipe_0 = Bry_find_.Find_fwd(v, Byte_ascii.Pipe); int pipe_0 = Bry_find_.Find_fwd(v, Byte_ascii.Pipe);

View File

@ -60,20 +60,6 @@ public class Xopg_html_data {
public byte[] Custom_html() {return custom_html;} public Xopg_html_data Custom_html_(byte[] v) {custom_html = v; return this;} private byte[] custom_html; public byte[] Custom_html() {return custom_html;} public Xopg_html_data Custom_html_(byte[] v) {custom_html = v; return this;} private byte[] custom_html;
public byte[] Custom_body() {return custom_body;} public Xopg_html_data Custom_body_(byte[] v) {custom_body = v; return this;} private byte[] custom_body; public byte[] Custom_body() {return custom_body;} public Xopg_html_data Custom_body_(byte[] v) {custom_body = v; return this;} private byte[] custom_body;
public byte[] Custom_tab_name() {return custom_tab_name;} public Xopg_html_data Custom_tab_name_(byte[] v) {custom_tab_name = v; return this;} private byte[] custom_tab_name; public byte[] Custom_tab_name() {return custom_tab_name;} public Xopg_html_data Custom_tab_name_(byte[] v) {custom_tab_name = v; return this;} private byte[] custom_tab_name;
public byte[] Custom_head_end() {return custom_head_end;}
public byte[] Custom_html_end() {return custom_html_end;}
public void Custom_head_end_concat(byte[] v) {
if (v == null)
custom_head_end = v;
else
custom_head_end = Bry_.Add(custom_head_end, v);
} private byte[] custom_head_end;
public void Custom_html_end_concat(byte[] v) {
if (v == null)
custom_html_end = v;
else
custom_html_end = Bry_.Add(custom_html_end, v);
} private byte[] custom_html_end;
public void Clear() { public void Clear() {
html_restricted = true; html_restricted = true;
display_ttl = content_sub = display_ttl_vnt = null; display_ttl = content_sub = display_ttl_vnt = null;
@ -88,7 +74,7 @@ public class Xopg_html_data {
xtn_scribunto_dbg = Bry_.Empty; xtn_scribunto_dbg = Bry_.Empty;
xtn_pgbnr = null; xtn_pgbnr = null;
module_mgr.Clear(); module_mgr.Clear();
custom_html = custom_html_end = custom_head_end = custom_tab_name = null; custom_html = custom_tab_name = null;
if (ctg_hash != null) ctg_hash.Clear(); if (ctg_hash != null) ctg_hash.Clear();
indicators.Clear(); indicators.Clear();
this.mode_wtxt_shown = false; this.mode_wtxt_shown = false;

View File

@ -19,15 +19,15 @@ package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xo
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*; import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
public class Xopg_page_heading implements Bfr_arg { public class Xopg_page_heading implements Bfr_arg {
private Xopg_html_data html_data; private Xopg_html_data html_data;
private Xoa_ttl page_ttl; private byte[] display_title;
public Xopg_page_heading Init(Xoae_page page) { public Xopg_page_heading Init(Xopg_html_data html_data, byte[] display_title) {
this.html_data = page.Html_data(); this.html_data = html_data;
this.page_ttl = page.Ttl(); this.display_title = display_title;
return this; return this;
} }
public void Bfr_arg__add(Bry_bfr bfr) { public void Bfr_arg__add(Bry_bfr bfr) {
if (html_data.Xtn_pgbnr() != null) return; // pgbnr exists; don't add title if (html_data.Xtn_pgbnr() != null) return; // pgbnr exists; don't add title
fmtr.Bld_many(bfr, page_ttl.Page_txt()); fmtr.Bld_many(bfr, display_title);
} }
private final Bry_fmt fmtr = Bry_fmt.New(Bry_.New_u8_nl_apos("<h1 id='firstHeading' class='firstHeading'><span>~{page_title}</span></h1>"), "page_title"); private final Bry_fmt fmtr = Bry_fmt.New(Bry_.New_u8_nl_apos("<h1 id='firstHeading' class='firstHeading'><span>~{page_title}</span></h1>"), "page_title");
} }

View File

@ -16,18 +16,19 @@ 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.langs.htmls.*;
public class Xopg_tag_itm { public class Xopg_tag_itm {
public Xopg_tag_itm(String name, String text, Keyval... atrs_ary) { public Xopg_tag_itm(byte[] name, byte[] text, Keyval... atrs_ary) {
this.Name = name; this.Name = name;
this.Text = text; this.Text = text;
this.Atrs_ary = atrs_ary; this.Atrs_ary = atrs_ary;
} }
public final String Name; public final byte[] Name;
public final String Text; public final byte[] Text;
public final Keyval[] Atrs_ary; public final Keyval[] Atrs_ary;
public void To_html(Bry_bfr bfr) { public void To_html(Bry_bfr bfr) {
bfr.Add_byte(Byte_ascii.Angle_bgn); bfr.Add_byte(Byte_ascii.Angle_bgn);
bfr.Add_str_a7(Name); bfr.Add(Name);
int len = Atrs_ary.length; int len = Atrs_ary.length;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
bfr.Add_byte_space(); bfr.Add_byte_space();
@ -39,20 +40,27 @@ public class Xopg_tag_itm {
bfr.Add_byte(Byte_ascii.Quote); bfr.Add_byte(Byte_ascii.Quote);
} }
bfr.Add_byte(Byte_ascii.Angle_end); bfr.Add_byte(Byte_ascii.Angle_end);
if (String_.Eq(Name, "link")) return; if (Bry_.Eq(Name, Gfh_tag_.Bry__link)) return;
if (Text != null) bfr.Add_str_u8(Text); if (Text != null) {
bfr.Add_byte_nl();
bfr.Add(Text);
bfr.Add_byte_nl();
}
bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash); bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash);
bfr.Add_str_a7(Name); bfr.Add(Name);
bfr.Add_byte(Byte_ascii.Angle_end); bfr.Add_byte(Byte_ascii.Angle_end);
} }
public static Xopg_tag_itm New_css(Io_url href) { public static Xopg_tag_itm New_css_file(Io_url href) {
return new Xopg_tag_itm("link" , null, Keyval_.new_("type", "text/css"), Keyval_.new_("rel", "stylesheet"), Keyval_.new_("href", href.To_http_file_str())); return new Xopg_tag_itm(Gfh_tag_.Bry__link , null, Keyval_.new_("type", "text/css"), Keyval_.new_("rel", "stylesheet"), Keyval_.new_("href", href.To_http_file_str()));
} }
public static Xopg_tag_itm New_script_file(Io_url src) { public static Xopg_tag_itm New_css_code(byte[] code) {
return new Xopg_tag_itm("script", null, Keyval_.new_("type", "text/javascript"), Keyval_.new_("src", src.To_http_file_str())); return new Xopg_tag_itm(Gfh_tag_.Bry__style , code, Keyval_.new_("type", "text/css"));
} }
public static Xopg_tag_itm New_script_code(String code) { public static Xopg_tag_itm New_js_file(Io_url src) {
return new Xopg_tag_itm("script", code, Keyval_.new_("type", "text/javascript")); return new Xopg_tag_itm(Gfh_tag_.Bry__script , null, Keyval_.new_("type", "text/javascript"), Keyval_.new_("src", src.To_http_file_str()));
}
public static Xopg_tag_itm New_js_code(byte[] code) {
return new Xopg_tag_itm(Gfh_tag_.Bry__script , code, Keyval_.new_("type", "text/javascript"));
} }
} }

View File

@ -35,4 +35,17 @@ public class Xopg_tag_mgr {
} }
return bfr.To_bry_and_clear(); return bfr.To_bry_and_clear();
} }
public byte[] To_html__style(Bry_bfr bfr) {
int len = this.Len();
for (int i = 0; i < len; ++i) {
Xopg_tag_itm tag = this.Get_at(i);
if ( Bry_.Eq(tag.Name, gplx.langs.htmls.Gfh_tag_.Bry__style)
&& tag.Text != null
) {
tag.To_html(bfr);
bfr.Add_byte_nl();
}
}
return bfr.To_bry_and_clear();
}
} }

View File

@ -43,4 +43,9 @@ public class Xox_xnde_ {
rv.Init(ctx.Page().Url_bry_safe(), src, xnde.Tag_open_end(), xnde.Tag_close_bgn()); rv.Init(ctx.Page().Url_bry_safe(), src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
return rv; return rv;
} }
public static byte[] Extract_body_or_null(byte[] src, Xop_xnde_tkn xnde) {
int body_bgn = xnde.Tag_open_end();
int body_end = xnde.Tag_close_bgn();
return body_bgn != -1 && body_end > body_bgn ? Bry_.Mid(src, body_bgn, body_end) : null;
}
} }

View File

@ -45,7 +45,7 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
Bry_bfr tmp_bfr = ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls(); Bry_bfr tmp_bfr = ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls();
switch (tid) { switch (tid) {
case Tid_local: tmp_bfr.Add(ctx.Wiki().Props().ArticlePath());break; case Tid_local: tmp_bfr.Add(ctx.Wiki().Props().ArticlePath());break;
case Tid_full: tmp_bfr.Add(Bry_relative_url).Add(ctx.Wiki().Props().ServerName()).Add(ctx.Wiki().Props().ArticlePath()); break; case Tid_full: tmp_bfr.Add(Bry_relative_url).Add(ctx.Wiki().Props().Server_name()).Add(ctx.Wiki().Props().ArticlePath()); break;
case Tid_canonical: tmp_bfr.Add(ctx.Wiki().Props().Server()).Add(ctx.Wiki().Props().ArticlePath()); break; case Tid_canonical: tmp_bfr.Add(ctx.Wiki().Props().Server()).Add(ctx.Wiki().Props().ArticlePath()); break;
default: throw Err_.new_unhandled(tid); default: throw Err_.new_unhandled(tid);
} }

View File

@ -22,11 +22,11 @@ public class Pfunc_urlfunc_tst {
@Before public void init() {fxt.Reset();} @Before public void init() {fxt.Reset();}
@Test public void Localurl() {fxt.Test_parse_tmpl_str_test("{{localurl:a&b! c}}" , "{{test}}", "/wiki/A%26b!_c");} @Test public void Localurl() {fxt.Test_parse_tmpl_str_test("{{localurl:a&b! c}}" , "{{test}}", "/wiki/A%26b!_c");}
@Test public void Fullurl() {fxt.Test_parse_tmpl_str_test("{{fullurl:a&b! c}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c");} @Test public void Fullurl() {fxt.Test_parse_tmpl_str_test("{{fullurl:a&b! c}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c");}
@Test public void Canonicalurl() {fxt.Test_parse_tmpl_str_test("{{canonicalurl:a&b! c}}" , "{{test}}", "http://en.wikipedia.org/wiki/A%26b!_c");} @Test public void Canonicalurl() {fxt.Test_parse_tmpl_str_test("{{canonicalurl:a&b! c}}" , "{{test}}", "https://en.wikipedia.org/wiki/A%26b!_c");}
@Test public void Canonicalurl_case() {fxt.Test_parse_tmpl_str_test("{{CANONICALURL:a&b! c}}" , "{{test}}", "http://en.wikipedia.org/wiki/A%26b!_c");} @Test public void Canonicalurl_case() {fxt.Test_parse_tmpl_str_test("{{CANONICALURL:a&b! c}}" , "{{test}}", "https://en.wikipedia.org/wiki/A%26b!_c");}
@Test public void Localurle() {fxt.Test_parse_tmpl_str_test("{{localurle:a&b! c}}" , "{{test}}", "/wiki/A%26b!_c");} @Test public void Localurle() {fxt.Test_parse_tmpl_str_test("{{localurle:a&b! c}}" , "{{test}}", "/wiki/A%26b!_c");}
@Test public void Fullurle() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c");} @Test public void Fullurle() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c");}
@Test public void Canonicalurle() {fxt.Test_parse_tmpl_str_test("{{canonicalurle:a&b! c}}" , "{{test}}", "http://en.wikipedia.org/wiki/A%26b!_c");} @Test public void Canonicalurle() {fxt.Test_parse_tmpl_str_test("{{canonicalurle:a&b! c}}" , "{{test}}", "https://en.wikipedia.org/wiki/A%26b!_c");}
@Test public void Fullurl_arg() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c|action=edit}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c?action=edit");} @Test public void Fullurl_arg() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c|action=edit}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c?action=edit");}
@Test public void Random() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c|action=edit}}" , "{{test|a|b|c}}", "//en.wikipedia.org/wiki/A%26b!_c?action=edit");} @Test public void Random() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c|action=edit}}" , "{{test|a|b|c}}", "//en.wikipedia.org/wiki/A%26b!_c?action=edit");}
@Test public void Xwiki() { @Test public void Xwiki() {

View File

@ -27,7 +27,7 @@ public class Pfunc_wiki_props extends Pf_func_base {
switch (id) { switch (id) {
case Xol_kwd_grp_.Id_site_sitename: bfr.Add(props.Site_name()); break; case Xol_kwd_grp_.Id_site_sitename: bfr.Add(props.Site_name()); break;
case Xol_kwd_grp_.Id_site_server: bfr.Add(props.Server()); break; case Xol_kwd_grp_.Id_site_server: bfr.Add(props.Server()); break;
case Xol_kwd_grp_.Id_site_servername: bfr.Add(props.ServerName()); break; case Xol_kwd_grp_.Id_site_servername: bfr.Add(props.Server_name()); break;
case Xol_kwd_grp_.Id_site_articlepath: bfr.Add(props.ArticlePath()); break; case Xol_kwd_grp_.Id_site_articlepath: bfr.Add(props.ArticlePath()); break;
case Xol_kwd_grp_.Id_site_scriptpath: bfr.Add(props.ScriptPath()); break; case Xol_kwd_grp_.Id_site_scriptpath: bfr.Add(props.ScriptPath()); break;
case Xol_kwd_grp_.Id_site_stylepath: bfr.Add(props.StylePath()); break; case Xol_kwd_grp_.Id_site_stylepath: bfr.Add(props.StylePath()); break;

View File

@ -22,7 +22,7 @@ public class Pfunc_wiki_stats_tst {
@Before public void setup() {fxt.Reset();} @Before public void setup() {fxt.Reset();}
@Test public void SiteName() {fxt.Test_parse_tmpl_str_test("{{SITENAME}}" , "{{test}}", "Wikipedia");} @Test public void SiteName() {fxt.Test_parse_tmpl_str_test("{{SITENAME}}" , "{{test}}", "Wikipedia");}
@Test public void ServerName() {fxt.Test_parse_tmpl_str_test("{{SERVERNAME}}" , "{{test}}", "en.wikipedia.org");} @Test public void ServerName() {fxt.Test_parse_tmpl_str_test("{{SERVERNAME}}" , "{{test}}", "en.wikipedia.org");}
@Test public void Server() {fxt.Test_parse_tmpl_str_test("{{SERVER}}" , "{{test}}", "http://en.wikipedia.org");} @Test public void Server() {fxt.Test_parse_tmpl_str_test("{{SERVER}}" , "{{test}}", "https://en.wikipedia.org");}
@Test public void ArticlePath() {fxt.Test_parse_tmpl_str_test("{{ARTICLEPATH}}" , "{{test}}", "/wiki/");} // FUTURE: should be /wiki/$1 @Test public void ArticlePath() {fxt.Test_parse_tmpl_str_test("{{ARTICLEPATH}}" , "{{test}}", "/wiki/");} // FUTURE: should be /wiki/$1
@Test public void ScriptPath() {fxt.Test_parse_tmpl_str_test("{{SCRIPTPATH}}" , "{{test}}", "/wiki");} @Test public void ScriptPath() {fxt.Test_parse_tmpl_str_test("{{SCRIPTPATH}}" , "{{test}}", "/wiki");}
@Test public void StylePath() {fxt.Test_parse_tmpl_str_test("{{STYLEPATH}}" , "{{test}}", "/wiki/skins");} @Test public void StylePath() {fxt.Test_parse_tmpl_str_test("{{STYLEPATH}}" , "{{test}}", "/wiki/skins");}

View File

@ -87,13 +87,18 @@ class Luaj_value_ {
if (o == null) return LuaValue.NIL; if (o == null) return LuaValue.NIL;
Class<?> c = Type_adp_.ClassOf_obj(o); Class<?> c = Type_adp_.ClassOf_obj(o);
if (Object_.Eq(c, Bool_.Cls_ref_type)) return LuaValue.valueOf((Boolean)o); if (Object_.Eq(c, Bool_.Cls_ref_type)) return LuaValue.valueOf((Boolean)o);
else if (Object_.Eq(c, Byte_.Cls_ref_type)) return LuaValue.valueOf((Byte)o);
else if (Object_.Eq(c, Int_.Cls_ref_type)) return LuaValue.valueOf((Integer)o); else if (Object_.Eq(c, Int_.Cls_ref_type)) return LuaValue.valueOf((Integer)o);
else if (Object_.Eq(c, Double_.Cls_ref_type)) return LuaValue.valueOf((Double)o);
else if (Object_.Eq(c, String_.Cls_ref_type)) return LuaValue.valueOf((String)o); else if (Object_.Eq(c, String_.Cls_ref_type)) return LuaValue.valueOf((String)o);
else if (Object_.Eq(c, Double_.Cls_ref_type)) return LuaValue.valueOf((Double)o);
else if (Object_.Eq(c, byte[].class)) return LuaValue.valueOf(String_.new_u8((byte[])o)); else if (Object_.Eq(c, byte[].class)) return LuaValue.valueOf(String_.new_u8((byte[])o));
else if (Object_.Eq(c, Keyval.class)) return X_kv_ary_to_tbl(server, (Keyval)o); else if (Object_.Eq(c, Keyval.class)) return X_kv_ary_to_tbl(server, (Keyval)o);
else if (Object_.Eq(c, Keyval[].class)) return X_kv_ary_to_tbl(server, (Keyval[])o); else if (Object_.Eq(c, Keyval[].class)) return X_kv_ary_to_tbl(server, (Keyval[])o);
else if (Object_.Eq(c, Long_.Cls_ref_type)) return LuaValue.valueOf((Long)o);
else if (Object_.Eq(c, Scrib_lua_proc.class)) return server.Get_closure_by_id(((Scrib_lua_proc)o).Id()); else if (Object_.Eq(c, Scrib_lua_proc.class)) return server.Get_closure_by_id(((Scrib_lua_proc)o).Id());
else if (Object_.Eq(c, Float_.Cls_ref_type)) return LuaValue.valueOf((Float)o);
else if (Object_.Eq(c, Char_.Cls_ref_type)) return LuaValue.valueOf((char)o);
else if (Object_.Eq(c, Short_.Cls_ref_type)) return LuaValue.valueOf((Short)o);
else return LuaValue.NIL; else return LuaValue.NIL;
} }
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, Keyval... ary) { private static LuaTable X_kv_ary_to_tbl(Luaj_server server, Keyval... ary) {

View File

@ -145,7 +145,7 @@ public class Scrib_lib_site implements Scrib_lib {
private void Bld_info(Keyval[] rv) { private void Bld_info(Keyval[] rv) {
Xow_wiki_props props = core.Wiki().Props(); Xow_wiki_props props = core.Wiki().Props();
rv[0] = Keyval_.new_("siteName" , props.Site_name()); rv[0] = Keyval_.new_("siteName" , props.Site_name());
rv[1] = Keyval_.new_("server" , props.Server()); rv[1] = Keyval_.new_("server" , Bry_.Add(gplx.core.net.Gfo_protocol_itm.Bry_relative, props.Server_name())); // NOTE: should generate "//en.wikipedia.org", not "de.wikipedia.org"; PAGE:de.w:Giro_d<EFBFBD>Italia_1996 DATE:2016-04-17
rv[2] = Keyval_.new_("scriptPath" , props.ScriptPath()); rv[2] = Keyval_.new_("scriptPath" , props.ScriptPath());
rv[3] = Keyval_.new_("stylePath" , props.StylePath()); rv[3] = Keyval_.new_("stylePath" , props.StylePath());
rv[4] = Keyval_.new_("currentVersion" , props.Current_version()); rv[4] = Keyval_.new_("currentVersion" , props.Current_version());

View File

@ -67,7 +67,7 @@ public class Scrib_lib_site_tst {
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl_skip_last fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl_skip_last
( "1=" ( "1="
, " siteName=Wikipedia" , " siteName=Wikipedia"
, " server=http://en.wikipedia.org" , " server=//en.wikipedia.org"
, " scriptPath=/wiki" , " scriptPath=/wiki"
, " stylePath=/wiki/skins" , " stylePath=/wiki/skins"
, " currentVersion=1.21wmf11" , " currentVersion=1.21wmf11"

View File

@ -179,13 +179,13 @@ public class Scrib_lib_title implements Scrib_lib {
Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl); Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl);
byte[] rv = null; byte[] rv = null;
if (page_itm != null) { if (page_itm != null) {
byte[] redirected_src = page_itm.Redirected_src_wtxt(); byte[] redirected_src = page_itm.Wtxt__redirect();
if (redirected_src != null) { // page is redirect; use its src, not its target's src; DATE:2014-07-11 if (redirected_src != null) { // page is redirect; use its src, not its target's src; DATE:2014-07-11
rv = redirected_src; rv = redirected_src;
core.Frame_parent().Rslt_is_redirect_(true); // flag frame as redirect, so that \n won't be prepended; EX:"#REDIRECT" x> "\n#REDIRECT" core.Frame_parent().Rslt_is_redirect_(true); // flag frame as redirect, so that \n won't be prepended; EX:"#REDIRECT" x> "\n#REDIRECT"
} }
else else
rv = page_itm.Wtxt(); rv = page_itm.Wtxt__direct();
} }
return rv == null ? rslt.Init_obj(null) : rslt.Init_obj(String_.new_u8(rv)); return rv == null ? rslt.Init_obj(null) : rslt.Init_obj(String_.new_u8(rv));
} }

View File

@ -40,11 +40,11 @@ public class Scrib_lib_title_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl") , "//en.wikipedia.org/wiki/Main_Page"); fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl") , "//en.wikipedia.org/wiki/Main_Page");
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "action=edit") , "//en.wikipedia.org/wiki/Main_Page?action=edit"); fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "action=edit") , "//en.wikipedia.org/wiki/Main_Page?action=edit");
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "localUrl") , "/wiki/Main_Page"); fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "localUrl") , "/wiki/Main_Page");
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl") , "http://en.wikipedia.org/wiki/Main_Page"); fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl") , "https://en.wikipedia.org/wiki/Main_Page");
// fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "", "http") , "http://en.wikipedia.org/wiki/Main_Page"); // TODO // fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "", "http") , "http://en.wikipedia.org/wiki/Main_Page"); // TODO
} }
@Test public void GetUrl__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; fr.w:Wikip<EFBFBD>dia:Image_du_jour/Date; DATE:2013-12-24 @Test public void GetUrl__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; fr.w:Wikip<EFBFBD>dia:Image_du_jour/Date; DATE:2013-12-24
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", Keyval_.Ary(Keyval_.new_("action", "edit"), Keyval_.new_("preload", "b"))), "http://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b"); fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", Keyval_.Ary(Keyval_.new_("action", "edit"), Keyval_.new_("preload", "b"))), "https://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
} }
@Test public void MakeTitle() { @Test public void MakeTitle() {
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Module", "A") , ttl_fast(828, "Module", "A")); fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Module", "A") , ttl_fast(828, "Module", "A"));

View File

@ -25,7 +25,7 @@ public class Scrib_lib_uri_tst {
@Test public void Url() { @Test public void Url() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" ), "/wiki/A%26b!_c"); fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" ), "/wiki/A%26b!_c");
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl , Object_.Ary("a&b! c" ), "//en.wikipedia.org/wiki/A%26b!_c"); fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl , Object_.Ary("a&b! c" ), "//en.wikipedia.org/wiki/A%26b!_c");
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_canonicalUrl , Object_.Ary("a&b! c" ), "http://en.wikipedia.org/wiki/A%26b!_c"); fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_canonicalUrl , Object_.Ary("a&b! c" ), "https://en.wikipedia.org/wiki/A%26b!_c");
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" , "action=edit" ), "/wiki/A%26b!_c?action=edit"); fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" , "action=edit" ), "/wiki/A%26b!_c?action=edit");
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("Media:A.png" ), "/wiki/File:A.png"); fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("Media:A.png" ), "/wiki/File:A.png");
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("[bad]" ), Scrib_invoke_func_fxt.Null_rslt); // handle invalid titles; EX:it.w:Billy_the_Kid; DATE:2014-01-20 fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("[bad]" ), Scrib_invoke_func_fxt.Null_rslt); // handle invalid titles; EX:it.w:Billy_the_Kid; DATE:2014-01-20

View File

@ -55,7 +55,7 @@ class Xob_wbase_json_dump_db {
this.page_modified_on = DateAdp_.Now(); this.page_modified_on = DateAdp_.Now();
this.page_core_tbl = db_mgr.Tbl__page(); this.page_core_tbl = db_mgr.Tbl__page();
page_tbl.Insert_bgn(); page_tbl.Insert_bgn();
qid_cmd.Wkr_bgn(bldr); qid_cmd.Page_wkr__bgn();
pid_cmd.Pid_bgn(); pid_cmd.Pid_bgn();
} }
private int page_id = 0, page_count_main = 0; private int page_id = 0, page_count_main = 0;

View File

@ -21,16 +21,16 @@ import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble { public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble {
private Json_parser parser; private Json_parser parser;
public Xob_wdata_pid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;} public Xob_wdata_pid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
public abstract String Wkr_key(); public abstract String Page_wkr__key();
public abstract void Pid_bgn(); public abstract void Pid_bgn();
public abstract void Pid_add(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl); public abstract void Pid_add(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl);
public abstract void Pid_end(); public abstract void Pid_end();
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
this.Init_dump(this.Wkr_key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append) this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser(); parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
this.Pid_bgn(); this.Pid_bgn();
} }
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
if (page.Ns_id() != Wdata_wiki_mgr.Ns_property) return; if (page.Ns_id() != Wdata_wiki_mgr.Ns_property) return;
Json_doc jdoc = parser.Parse(page.Text()); Json_doc jdoc = parser.Parse(page.Text());
if (jdoc == null) { if (jdoc == null) {
@ -39,6 +39,7 @@ public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xo
} }
Parse_jdoc(jdoc); Parse_jdoc(jdoc);
} }
public void Page_wkr__run_cleanup() {}
public void Parse_jdoc(Json_doc jdoc) { public void Parse_jdoc(Json_doc jdoc) {
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc); Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
byte[] qid = wdoc_parser.Parse_qid(jdoc); byte[] qid = wdoc_parser.Parse_qid(jdoc);
@ -49,6 +50,6 @@ public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xo
this.Pid_add(label.Lang(), label.Text(), qid); this.Pid_add(label.Lang(), label.Text(), qid);
} }
} }
public void Wkr_end() {this.Pid_end();} public void Page_wkr__end() {this.Pid_end();}
static final String GRP_KEY = "xowa.wdata.pid_wkr"; static final String GRP_KEY = "xowa.wdata.pid_wkr";
} }

View File

@ -19,7 +19,7 @@ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
public class Xob_wdata_pid_sql extends Xob_wdata_pid_base { public class Xob_wdata_pid_sql extends Xob_wdata_pid_base {
private Xowd_wbase_pid_tbl tbl; private Xowd_wbase_pid_tbl tbl;
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;} @Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;}
@Override public void Pid_bgn() { @Override public void Pid_bgn() {
Xowd_db_mgr db_mgr = wiki.Data__core_mgr(); Xowd_db_mgr db_mgr = wiki.Data__core_mgr();
tbl = db_mgr.Db__wbase().Tbl__wbase_pid(); tbl = db_mgr.Db__wbase().Tbl__wbase_pid();

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xob_wdata_pid_txt extends Xob_wdata_pid_base { public class Xob_wdata_pid_txt extends Xob_wdata_pid_base {
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_pid;} @Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_pid;}
@Override public void Pid_bgn() { @Override public void Pid_bgn() {
pid_bldr = new Wdata_idx_bldr_pid(this, bldr, wiki, dump_fil_len); pid_bldr = new Wdata_idx_bldr_pid(this, bldr, wiki, dump_fil_len);
} Wdata_idx_bldr_pid pid_bldr; } Wdata_idx_bldr_pid pid_bldr;

View File

@ -23,22 +23,23 @@ import gplx.xowa.bldrs.wms.sites.*;
public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble { public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble {
private Json_parser parser; private Xob_wbase_ns_parser ns_parser; private final Xob_wbase_ns_parser_rslt ns_parser_rslt = new Xob_wbase_ns_parser_rslt(); private Json_parser parser; private Xob_wbase_ns_parser ns_parser; private final Xob_wbase_ns_parser_rslt ns_parser_rslt = new Xob_wbase_ns_parser_rslt();
public Xob_wdata_qid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;} public Xob_wdata_qid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
public abstract String Wkr_key(); public abstract String Page_wkr__key();
public abstract void Qid_bgn(); public abstract void Qid_bgn();
public abstract void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid); public abstract void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid);
public abstract void Qid_end(); public abstract void Qid_end();
public void Wkr_bgn(Xob_bldr bldr) { public void Page_wkr__bgn() {
this.Init_dump(this.Wkr_key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append) this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
this.parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser(); this.parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
this.ns_parser = new Xob_wbase_ns_parser(bldr.App().Fsys_mgr().Cfg_site_meta_fil()); this.ns_parser = new Xob_wbase_ns_parser(bldr.App().Fsys_mgr().Cfg_site_meta_fil());
this.Qid_bgn(); this.Qid_bgn();
} }
public void Wkr_run(Xowd_page_itm page) { public void Page_wkr__run(Xowd_page_itm page) {
if (page.Ns_id() != Xow_ns_.Tid__main) return; // qid pages are only in the Main Srch_rslt_cbk if (page.Ns_id() != Xow_ns_.Tid__main) return; // qid pages are only in the Main Srch_rslt_cbk
Json_doc jdoc = parser.Parse(page.Text()); Json_doc jdoc = parser.Parse(page.Text());
if (jdoc == null) {bldr.Usr_dlg().Warn_many("", "", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db())); return;} if (jdoc == null) {bldr.Usr_dlg().Warn_many("", "", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db())); return;}
this.Parse_jdoc(jdoc); this.Parse_jdoc(jdoc);
} }
public void Page_wkr__run_cleanup() {}
public void Parse_jdoc(Json_doc jdoc) { public void Parse_jdoc(Json_doc jdoc) {
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc); Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
byte[] qid = wdoc_parser.Parse_qid(jdoc); byte[] qid = wdoc_parser.Parse_qid(jdoc);
@ -56,7 +57,7 @@ public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xo
this.Qid_add(sitelink.Site(), sitelink_ns, Xoa_ttl.Replace_spaces(sitelink_ttl), qid); // NOTE: always convert spaces to underscores; EX: "A B" -> "A_B" DATE:2015-04-21 this.Qid_add(sitelink.Site(), sitelink_ns, Xoa_ttl.Replace_spaces(sitelink_ttl), qid); // NOTE: always convert spaces to underscores; EX: "A B" -> "A_B" DATE:2015-04-21
} }
} }
public void Wkr_end() { public void Page_wkr__end() {
this.Qid_end(); this.Qid_end();
// wiki.Data__core_mgr().Db__wbase().Tbl__cfg().Insert_int("", "", 1); // wiki.Data__core_mgr().Db__wbase().Tbl__cfg().Insert_int("", "", 1);
} }

View File

@ -19,7 +19,7 @@ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
public class Xob_wdata_qid_sql extends Xob_wdata_qid_base { public class Xob_wdata_qid_sql extends Xob_wdata_qid_base {
private Xowd_wbase_qid_tbl tbl; private Xowd_wbase_qid_tbl tbl;
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_qid;} @Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_qid;}
@Override public void Qid_bgn() { @Override public void Qid_bgn() {
Xowd_db_mgr db_mgr = wiki.Db_mgr_as_sql().Core_data_mgr(); Xowd_db_mgr db_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
boolean db_is_all_or_few = db_mgr.Props().Layout_text().Tid_is_all_or_few(); boolean db_is_all_or_few = db_mgr.Props().Layout_text().Tid_is_all_or_few();

View File

@ -19,7 +19,7 @@ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.*;
public class Xob_wdata_qid_txt extends Xob_wdata_qid_base { public class Xob_wdata_qid_txt extends Xob_wdata_qid_base {
private Wdata_idx_bldr_qid qid_bldr; private Wdata_idx_bldr_qid qid_bldr;
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_qid;} @Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_qid;}
@Override public void Qid_bgn() {qid_bldr = new Wdata_idx_bldr_qid().Ctor(this, bldr, wiki, dump_fil_len);} @Override public void Qid_bgn() {qid_bldr = new Wdata_idx_bldr_qid().Ctor(this, bldr, wiki, dump_fil_len);}
@Override public void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid) { @Override public void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid) {
qid_bldr.Add(String_.new_u8(wiki_key), Int_.To_str_pad_bgn_zero(ns_id, 3), ttl, qid); qid_bldr.Add(String_.new_u8(wiki_key), Int_.To_str_pad_bgn_zero(ns_id, 3), ttl, qid);

View File

@ -78,9 +78,9 @@ public class Random_selection_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
int options_len = options_ary.length; int options_len = options_ary.length;
for (int i = 0; i < options_len; ++i) { for (int i = 0; i < options_len; ++i) {
Rndsel_option_itm option = options_ary[i]; Rndsel_option_itm option = options_ary[i];
rnd -= option.Weight(); rnd -= option.Weight;
if (rnd <= 0) { if (rnd <= 0) {
option_bry = option.Text(); option_bry = option.Text;
break; break;
} }
} }
@ -105,7 +105,7 @@ public class Random_selection_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
public static int Rnd_test = -1; public static int Rnd_test = -1;
} }
class Rndsel_option_itm { class Rndsel_option_itm {
public Rndsel_option_itm(int weight, byte[] text) {this.weight = weight; this.text = text;} public Rndsel_option_itm(int weight, byte[] text) {this.Weight = weight; this.Text = text;}
public int Weight() {return weight;} private final int weight; public final int Weight;
public byte[] Text() {return text;} private final byte[] text; public final byte[] Text;
} }

View File

@ -0,0 +1,51 @@
/*
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.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.htmls.*;
class Tabber_tab_itm {
public Tabber_tab_itm(boolean active, byte[] name, byte[] text) {
this.Active = active;
this.Name = name;
this.Text = text;
}
public final boolean Active;
public final byte[] Name;
public final byte[] Text;
public static void Write(Bry_bfr bfr, byte[] id, Tabber_tab_itm[] ary) {
bfr.Add_str_a7("<div id=\"tabber-");
bfr.Add(id);
bfr.Add_str_a7("\" class=\"tabber\">\n");
int len = ary.length;
for (int i = 0; i < len; ++i) {
Tabber_tab_itm itm = ary[i];
bfr.Add_str_a7("<div class=\"tabbertab\" title=\"");
bfr.Add(Gfh_utl.Escape_html_as_bry(itm.Name));
bfr.Add_str_a7("\"");
if (itm.Active) {
bfr.Add_str_a7(" data-active=\"true\"");
}
bfr.Add_str_a7(">\n");
bfr.Add(Gfh_tag_.P_lhs);
bfr.Add(itm.Text);
bfr.Add(Gfh_tag_.P_rhs).Add_byte_nl();
bfr.Add(Gfh_tag_.Div_rhs).Add_byte_nl();
}
bfr.Add(Gfh_tag_.Div_rhs);
}
}

View File

@ -19,43 +19,45 @@ package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xo
import gplx.xowa.htmls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Tabber_xnde implements Xox_xnde { public class Tabber_xnde implements Xox_xnde {
private static final byte[] Spr__tab_itms = Bry_.new_a7("|-|"); private byte[] id;
private byte[] html; private Tabber_tab_itm[] tab_itms_ary;
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {} public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) { public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn); ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
Bry_bfr tmp_bfr = Bry_bfr.new_();
tmp_bfr.Add_str_a7("<div id=\"tabber-\" "); // TODO: add key which is md5 of inner src
tmp_bfr.Add_str_a7("class=\"tabber\">\n");
// split on "|-|"; EX: "A|-|B" -> tab_1='A'; tab_2='B' // split on "|-|"; EX: "A|-|B" -> tab_1='A'; tab_2='B'
byte[][] tab_itms = Bry_split_.Split(src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), Spr__tab_itms); List_adp tab_itms_list = List_adp_.new_();
byte[] xnde_body = Xox_xnde_.Extract_body_or_null(src, xnde); if (xnde_body == null) return;
this.id = Id_test == null ? gplx.core.security.HashAlgo_.Md5.Calc_hash_bry(xnde_body) : Id_test;
byte[][] tab_itms = Bry_split_.Split(xnde_body, Spr__tab_itms);
for (int i = 0; i < tab_itms.length; ++i) { for (int i = 0; i < tab_itms.length; ++i) {
byte[] tab_itm = tab_itms[i]; byte[] tab_itm = tab_itms[i];
tab_itm = Bry_.Trim(tab_itm); tab_itm = Bry_.Trim(tab_itm);
int tab_itm_len = tab_itm.length; if (tab_itm_len == 0) continue; int tab_itm_len = tab_itm.length; if (tab_itm_len == 0) continue;
// split on "="; EX: A=B -> tab_name='A'; tab_body = 'B' // split on "="; EX: A=B -> tab_name='A'; tab_body = 'B'
byte[][] tab_parts = Bry_split_.Split(tab_itm, Byte_ascii.Eq); byte[] tab_head = null, tab_body = null;
byte[] tab_head = tab_parts[0]; int eq_pos = Bry_find_.Find_fwd(tab_itm, Byte_ascii.Eq);
byte[] tab_body = tab_parts.length == 1 ? Bry_.Empty : Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), tab_parts[1], false); if (eq_pos == Bry_find_.Not_found) {
tab_head = tab_itm;
tmp_bfr.Add_str_a7("<div class=\"tabbertab\" title=\""); tab_body = Bry_.Empty;
tmp_bfr.Add(Gfh_utl.Escape_html_as_bry(tab_head));
tmp_bfr.Add_str_a7("\">\n");
tmp_bfr.Add(Gfh_tag_.P_lhs);
tmp_bfr.Add(tab_body);
tmp_bfr.Add(Gfh_tag_.P_rhs).Add_byte_nl();
tmp_bfr.Add(Gfh_tag_.Div_rhs).Add_byte_nl();
} }
tmp_bfr.Add(Gfh_tag_.Div_rhs); else {
html = tmp_bfr.To_bry_and_clear(); tab_head = Bry_.Mid(tab_itm, 0, eq_pos);
tab_body = Bry_.Mid(tab_itm, eq_pos + 1, tab_itm_len);
tab_body = Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), tab_body, false);
}
tab_itms_list.Add(new Tabber_tab_itm(Bool_.N, tab_head, tab_body));
}
tab_itms_ary = (Tabber_tab_itm[])tab_itms_list.To_ary_and_clear(Tabber_tab_itm.class);
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_(); ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end); ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
} }
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) { public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
if (html != null) bfr.Add(html); if (tab_itms_ary != null) Tabber_tab_itm.Write(bfr, id, tab_itms_ary);
} }
public static byte[] Id_test;
private static final byte[] Spr__tab_itms = Bry_.new_a7("|-|");
} }

View File

@ -19,7 +19,10 @@ package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xo
import org.junit.*; import org.junit.*;
public class Tabber_xnde_tst { public class Tabber_xnde_tst {
private final Xop_fxt fxt = new Xop_fxt(); private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();} @Before public void init() {
fxt.Reset();
Tabber_xnde.Id_test = Bry_.new_a7("test");
}
@Test public void Basic() { @Test public void Basic() {
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
( "<tabber>" ( "<tabber>"
@ -28,7 +31,7 @@ public class Tabber_xnde_tst {
, "tab2=''b''" , "tab2=''b''"
, "</tabber>" , "</tabber>"
), String_.Concat_lines_nl_skip_last ), String_.Concat_lines_nl_skip_last
( "<div id=\"tabber-\" class=\"tabber\">" ( "<div id=\"tabber-test\" class=\"tabber\">"
, "<div class=\"tabbertab\" title=\"tab1\">" , "<div class=\"tabbertab\" title=\"tab1\">"
, "<p><i>a</i></p>" , "<p><i>a</i></p>"
, "</div>" , "</div>"
@ -38,17 +41,30 @@ public class Tabber_xnde_tst {
, "</div>" , "</div>"
)); ));
} }
@Test public void Eq_missing() { @Test public void Eq__missing() {
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
( "<tabber>" ( "<tabber>"
, "tab1" , "tab1"
, "</tabber>" , "</tabber>"
), String_.Concat_lines_nl_skip_last ), String_.Concat_lines_nl_skip_last
( "<div id=\"tabber-\" class=\"tabber\">" ( "<div id=\"tabber-test\" class=\"tabber\">"
, "<div class=\"tabbertab\" title=\"tab1\">" , "<div class=\"tabbertab\" title=\"tab1\">"
, "<p></p>" , "<p></p>"
, "</div>" , "</div>"
, "</div>" , "</div>"
)); ));
} }
@Test public void Eq__many() {
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
( "<tabber>"
, "tab1=A=B"
, "</tabber>"
), String_.Concat_lines_nl_skip_last
( "<div id=\"tabber-test\" class=\"tabber\">"
, "<div class=\"tabbertab\" title=\"tab1\">"
, "<p>A=B</p>"
, "</div>"
, "</div>"
));
}
} }

View File

@ -18,14 +18,136 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Tabview_xnde implements Xox_xnde { public class Tabview_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {} private byte[] id;
private Tabber_tab_itm[] tab_itms_ary;
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
switch (xatr_id) {
case Xatr__id: id = xatr.Val_as_bry(); break;
}
}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) { public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn); ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
ctx.Page().Html_data().Head_mgr().Itm__graph().Enabled_y_(); Xox_xnde_.Parse_xatrs(wiki, this, xatrs_hash, src, xnde);
// get id
id = Keep_alphanum(id);
if (Bry_.Len_eq_0(id)) id = Int_.To_bry(global_id++);
// parse src
byte[] tabs_src = Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
tabs_src = Bry_.Trim(tabs_src); // if(isset($tabs[0]) && $tabs[0] == "") {unset($tabs[0]);} if($tabs[count($tabs)] == "") {unset($tabs[count($tabs)]);}
byte[][] tabs_ary = Bry_split_.Split_lines(tabs_src);
List_adp tabs_list = List_adp_.new_();
int tabs_len = tabs_ary.length;
for (int i = 0; i < tabs_len; ++i) {
Tabview_tab_itm itm = Tabview_tab_itm.Parse(wiki, ctx, tabs_ary[i]);
if (itm != null)
tabs_list.Add(itm);
}
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
Tabview_tab_itm[] ary = (Tabview_tab_itm[])tabs_list.To_ary_and_clear(Tabview_tab_itm.class);
tab_itms_ary = Tabview_tab_itm.To_tabber_ary(ary);
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end); ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
} }
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) { public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
bfr.Add_mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()); if (tab_itms_ary != null) Tabber_tab_itm.Write(bfr, id, tab_itms_ary);
// write html
//Bry_bfr bfr = Bry_bfr.new_();
//bfr.Add_str_a7("<div id=\"flytabs_");
//bfr.Add(id);
//bfr.Add_str_a7("\">\n<ul>\n");
//int ary_len = ary.length;
//for (int i = 0; i < ary_len; ++i) {
// Tabview_tab_itm itm = ary[i];
// bfr.Add_str_a7("<li><a href=");
// // href
// bfr.Add_str_a7("><span>");
// bfr.Add(itm.Tab_name);
// bfr.Add_str_a7("</span></a></li>");
//}
//bfr.Add_str_a7("</ul>\n</div>\n");
}
private int global_id = 0;
public static final byte Xatr__id = 0;
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7().Add_str_byte("id", Xatr__id);
private static byte[] Keep_alphanum(byte[] src) {
if (src == null) return null;
int src_len = src.length; if (src_len == 0) return src;
Bry_bfr bfr = null;
for (int i = 0; i < src_len; ++i) {
byte b = src[i];
if ( Byte_ascii.Is_ltr(b)
|| Byte_ascii.Is_num(b)) {
if (bfr != null) bfr.Add_byte(b);
}
else { // not alphanum;
if (bfr == null) { // 1st occurrence; create bfr and add initial to it
bfr = Bry_bfr.new_();
bfr.Add_mid(src, 0, i);
}
}
}
return bfr == null ? src : bfr.To_bry_and_clear();
}
}
class Tabview_tab_itm {
public Tabview_tab_itm(boolean active, boolean cache, byte[] tab_name, byte[] page_ttl_bry, byte[] page_body) {
this.Active = active;
this.Cache = cache;
this.Tab_name = tab_name;
this.Page_ttl_bry = page_ttl_bry;
this.Page_body = page_body;
}
public final boolean Active;
public final boolean Cache;
public final byte[] Tab_name;
public final byte[] Page_ttl_bry;
public final byte[] Page_body;
public static Tabview_tab_itm Parse(Xowe_wiki wiki, Xop_ctx ctx, byte[] src) {
byte[][] args_ary = Bry_split_.Split(src, Byte_ascii.Pipe);
int args_len = args_ary.length;
boolean cache = false, active = false;
byte[] tab_name = null, page_ttl_bry = null, page_body = null;
for (int i = 0; i < args_len; ++i) {
byte[] args_itm = args_ary[i];
switch (i) {
case 0:
page_ttl_bry = args_itm;
if (Bry_.Has_at_bgn(page_ttl_bry, Byte_ascii.Angle_bgn) || Bry_.Has_at_end(page_ttl_bry, Byte_ascii.Angle_end)) return null;
Xoa_ttl page_ttl = wiki.Ttl_parse(page_ttl_bry);
if (page_ttl == null) return null;
gplx.xowa.wikis.caches.Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl);
if (page_itm == null) return null;
page_body = page_itm.Wtxt__redirect_or_direct();
page_body = Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), page_body, false);
break;
case 1:
tab_name = args_itm;
if (Bry_.Has_at_bgn(tab_name, Byte_ascii.Angle_bgn) || Bry_.Has_at_end(tab_name, Byte_ascii.Angle_end)) return null;
break;
case 2:
cache = Bry_.To_bool_or(args_itm, false);
break;
case 3:
active = Bry_.To_bool_or(args_itm, false);
break;
}
}
return new Tabview_tab_itm(active, cache, tab_name, page_ttl_bry, page_body);
}
public static Tabber_tab_itm[] To_tabber_ary(Tabview_tab_itm[] ary) {
int len = ary.length;
Tabber_tab_itm[] rv = new Tabber_tab_itm[len];
for (int i = 0; i < len; ++i) {
Tabview_tab_itm src = ary[i];
rv[i] = new Tabber_tab_itm(src.Active, src.Tab_name, src.Page_body);
}
return rv;
} }
} }

View File

@ -0,0 +1,42 @@
/*
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.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Tabview_xnde_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic() {
fxt.Init_page_create("A", "''a''");
fxt.Init_page_create("B", "''b''");
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
( "<tabview id='test'>"
, "A|tab1"
, "B|tab2||true"
, "</tabview>"
), String_.Concat_lines_nl_skip_last
( "<div id=\"tabber-test\" class=\"tabber\">"
, "<div class=\"tabbertab\" title=\"tab1\">"
, "<p><i>a</i></p>"
, "</div>"
, "<div class=\"tabbertab\" title=\"tab2\" data-active=\"true\">"
, "<p><i>b</i></p>"
, "</div>"
, "</div>"
));
}
}

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.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.htmls.*;
class Xo_custom_html_pos_ {
public static final byte Tid__head_end = 1, Tid__tail = 2;
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
.Add_str_byte("head_end", Tid__head_end)
.Add_str_byte("tail", Tid__tail)
;
public static byte To_tid(byte[] bry) {
byte tid = hash.Get_as_byte_or(bry, Byte_.Max_value_127);
if (tid == Byte_.Max_value_127) throw Err_.new_wo_type("unknown pos", "pos", bry);
return tid;
}
}
class Xo_custom_html_type_ {
public static final byte Tid__css_code = 1, Tid__js_code = 2;
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
.Add_bry_byte(Gfh_tag_.Bry__style , Tid__css_code)
.Add_bry_byte(Gfh_tag_.Bry__script , Tid__js_code)
;
public static byte[] To_bry(byte tid) {
switch (tid) {
case Tid__css_code: return Gfh_tag_.Bry__style;
case Tid__js_code : return Gfh_tag_.Bry__script;
default: throw Err_.new_unhandled_default(tid);
}
}
public static byte To_tid(byte[] bry) {
byte tid = hash.Get_as_byte_or(bry, Byte_.Max_value_127); if (tid == Byte_.Max_value_127) throw Err_.new_wo_type("unknown type", "type", bry);
return tid;
}
}

View File

@ -16,18 +16,16 @@ 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; package gplx.xowa.xtns.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*; import gplx.xowa.htmls.core.htmls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner1 { import gplx.xowa.wikis.pages.*;
private byte pos_val = Pos_head_end; public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner2 {
public Xop_root_tkn Xtn_root() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_root should not be called");} private byte tag_pos = Xo_custom_html_pos_.Tid__head_end, tag_type = Xo_custom_html_type_.Tid__css_code;
public byte[] Xtn_html() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_html should not be called");} public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) { switch (xatr_id) {
if (xatr_id_obj == null) return; case Xatr__pos: tag_pos = Xo_custom_html_pos_.To_tid(xatr.Val_as_bry()); break;
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj; case Xatr__type: tag_type = Xo_custom_html_type_.To_tid(xatr.Val_as_bry()); break;
switch (xatr_id.Val()) { default: throw Err_.new_unhandled(xatr_id);
case Xatr_pos_id: pos_val = Pos_val(xatr.Val_as_bry()); break;
default: throw Err_.new_unhandled(xatr_id.Val());
} }
} }
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) { public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
@ -35,32 +33,27 @@ public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner1 {
wiki.Appe().Usr_dlg().Warn_many("", "", "xowa_html command only allowed in xowa_home"); wiki.Appe().Usr_dlg().Warn_many("", "", "xowa_html command only allowed in xowa_home");
return; return;
} }
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn(); // parse xnde for tag_name, tag_body
if (src[itm_bgn] == Byte_ascii.Nl) ++itm_bgn; // ignore 1st \n; Xox_xnde_.Parse_xatrs(wiki, this, xatr_hash, src, xnde);
// if (src[itm_end - 1] == Byte_ascii.Nl) --itm_end; // ignore last \n; byte[] name = Xo_custom_html_type_.To_bry(tag_type);
byte[] raw = Bry_.Mid(src, itm_bgn, itm_end); int raw_bgn = xnde.Tag_open_end(), raw_end = xnde.Tag_close_bgn();
if (pos_val == Pos_head_end) raw_bgn = Bry_find_.Find_fwd_while_ws(src, raw_bgn, raw_end);
ctx.Page().Html_data().Custom_head_end_concat(raw); raw_end = Bry_find_.Find_bwd__skip_ws(src, raw_end, raw_bgn);
else if (src[raw_bgn] == Byte_ascii.Nl) ++raw_bgn;
ctx.Page().Html_data().Custom_html_end_concat(raw); if (src[raw_bgn] == Byte_ascii.Nl) ++raw_bgn;
byte[] raw = Bry_.Mid(src, raw_bgn, raw_end);
// add to custom tags
Xopg_html_data html_data = ctx.Page().Html_data();
Xopg_tag_mgr tag_mgr = tag_pos == Xo_custom_html_pos_.Tid__tail ? html_data.Custom_tail_tags() : html_data.Custom_head_tags();
tag_mgr.Add(new Xopg_tag_itm(name, raw));
} }
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {} public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
private static byte Pos_val(byte[] bry) {
Object o = pos_val_hash.Get_by_bry(bry); public Xop_root_tkn Xtn_root() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_root should not be called");}
if (o == null) throw Err_.new_wo_type("unknown pos", "pos", String_.new_u8(bry)); public byte[] Xtn_html() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_html should not be called");}
return ((Byte_obj_val)o).Val();
} private static final byte Xatr__pos = 1, Xatr__type = 2;
private static final byte Pos_head_end = 1, Pos_html_end = 2; private static final Hash_adp_bry xatr_hash = Hash_adp_bry.ci_a7().Add_str_byte("pos", Xatr__pos).Add_str_byte("type", Xatr__type);
private static final byte[]
Xatr_pos_key = Bry_.new_a7("pos")
, Xatr_pos_val__head_end = Bry_.new_a7("head.end")
, Xatr_pos_val__html_end = Bry_.new_a7("html.end")
;
private static final Hash_adp_bry pos_val_hash = Hash_adp_bry.ci_a7()
.Add_bry_byte(Xatr_pos_val__head_end, Pos_head_end)
.Add_bry_byte(Xatr_pos_val__html_end, Pos_html_end)
;
private static final byte Xatr_pos_id = 1;
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7().Add_bry_byte(Xatr_pos_key, Xatr_pos_id);
} }

View File

@ -23,14 +23,14 @@ public class Xox_xowa_html_cmd_tst {
@Before public void init() {fxt.Clear();} private Xox_xowa_html_cmd_fxt fxt = new Xox_xowa_html_cmd_fxt(); @Before public void init() {fxt.Clear();} private Xox_xowa_html_cmd_fxt fxt = new Xox_xowa_html_cmd_fxt();
@Test public void Head_end() { @Test public void Head_end() {
fxt.Test_parse_w_skin fxt.Test_parse_w_skin
( "<xowa_html pos='head.end'>test</xowa_html>" ( "<xowa_html pos='head_end'>test</xowa_html>"
, "<html><head>test</head><body></body></html>" , "<html><head><style>\ntest\n</style>\n</head><body></body></html>"
); );
} }
@Test public void Html_end() { @Test public void Tail() {
fxt.Test_parse_w_skin fxt.Test_parse_w_skin
( "<xowa_html pos='html.end'>test</xowa_html>" ( "<xowa_html pos='tail'>test</xowa_html>"
, "<html><head></head><body></body>test</html>" , "<html><head></head><body></body><style>\ntest\n</style>\n</html>"
); );
} }
} }