1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

v1.10.4.1

This commit is contained in:
gnosygnu 2014-10-26 22:13:39 -04:00
parent 7d8984f6a8
commit eddb6bebc7
71 changed files with 1265 additions and 366 deletions

View File

@ -698,6 +698,7 @@ public class Bry_ {
} }
public static float XtoFloatByPos(byte[] ary, int bgn, int end) {return Float_.parse_(String_.new_utf8_(ary, bgn, end));} public static float XtoFloatByPos(byte[] ary, int bgn, int end) {return Float_.parse_(String_.new_utf8_(ary, bgn, end));}
public static double Xto_double(byte[] bry) {return Double_.parse_(String_.new_utf8_(bry, 0, bry.length));} public static double Xto_double(byte[] bry) {return Double_.parse_(String_.new_utf8_(bry, 0, bry.length));}
public static double Xto_double_or(byte[] bry, double or) {return Double_.parseOr_(String_.new_utf8_(bry, 0, bry.length), or);}
public static double XtoDoubleByPosOr(byte[] ary, int bgn, int end, double or) {return Double_.parseOr_(String_.new_utf8_(ary, bgn, end), or);} public static double XtoDoubleByPosOr(byte[] ary, int bgn, int end, double or) {return Double_.parseOr_(String_.new_utf8_(ary, bgn, end), or);}
public static double XtoDoubleByPos(byte[] ary, int bgn, int end) {return Double_.parse_(String_.new_utf8_(ary, bgn, end));} public static double XtoDoubleByPos(byte[] ary, int bgn, int end) {return Double_.parse_(String_.new_utf8_(ary, bgn, end));}
public static DecimalAdp XtoDecimalByPos(byte[] ary, int bgn, int end) {return DecimalAdp_.parse_(String_.new_utf8_(ary, bgn, end));} public static DecimalAdp XtoDecimalByPos(byte[] ary, int bgn, int end) {return DecimalAdp_.parse_(String_.new_utf8_(ary, bgn, end));}

View File

@ -24,5 +24,7 @@ public class Enm_ {
boolean has = find == (val & find); boolean has = find == (val & find);
return (has ^ enable) ? val ^ find : val; return (has ^ enable) ? val ^ find : val;
} }
public static boolean Has_byte(byte val, byte find) {return find == (val & find);}
public static byte Add_byte(byte flag, byte itm) {return (byte)(flag | itm);}
static int Ordinal_lang(Object v) {return ((Enum)v).ordinal();} static int Ordinal_lang(Object v) {return ((Enum)v).ordinal();}
} }

View File

@ -15,7 +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.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx;
public class Hdump_text_row_tid { // NOTE: SERIALIZED public class Base64_utl {
public static final int Tid_body = 0, Tid_data = 1; public static void Encode(Bry_bfr bfr, byte[] bry, int bgn, int end) {
for (int i = bgn; i < end; ++i) {
}
}
} }

View File

@ -93,6 +93,8 @@ class Swt_lnr_key implements KeyListener {
case 16777235: val = IptKey_.F10.Val(); break; case 16777235: val = IptKey_.F10.Val(); break;
case 16777236: val = IptKey_.F11.Val(); break; case 16777236: val = IptKey_.F11.Val(); break;
case 16777237: val = IptKey_.F12.Val(); break; case 16777237: val = IptKey_.F12.Val(); break;
case 16777259: val = IptKey_.Equal.Val(); break;
case 16777261: val = IptKey_.Minus.Val(); break;
case 16777300: val = IptKey_.ScrollLock.Val(); break; case 16777300: val = IptKey_.ScrollLock.Val(); break;
case 16777301: val = IptKey_.Pause.Val(); break; case 16777301: val = IptKey_.Pause.Val(); break;
case 327680: val = IptKey_.Insert.Val(); break; case 327680: val = IptKey_.Insert.Val(); break;

View File

@ -54,7 +54,6 @@ public class Html_utl {
public static byte[] Escape_html_as_bry(byte[] bry) {return Escape_html(false, Bry_bfr.new_(), bry, 0, bry.length, true, true, true, true, true);} public static byte[] Escape_html_as_bry(byte[] bry) {return Escape_html(false, Bry_bfr.new_(), bry, 0, bry.length, true, true, true, true, true);}
public static byte[] Escape_html_as_bry(byte[] bry, boolean lt, boolean gt, boolean amp, boolean quote, boolean apos) public static byte[] Escape_html_as_bry(byte[] bry, boolean lt, boolean gt, boolean amp, boolean quote, boolean apos)
{return Escape_html(false, Bry_bfr.new_(), bry, 0, bry.length, lt, gt, amp, quote, apos);} {return Escape_html(false, Bry_bfr.new_(), bry, 0, bry.length, lt, gt, amp, quote, apos);}
public static void Escape_html_to_bfr(Bry_bfr bfr, byte[] bry, int bgn, int end, boolean escape_lt, boolean escape_gt, boolean escape_amp, boolean escape_quote, boolean escape_apos) { public static void Escape_html_to_bfr(Bry_bfr bfr, byte[] bry, int bgn, int end, boolean escape_lt, boolean escape_gt, boolean escape_amp, boolean escape_quote, boolean escape_apos) {
Escape_html(true, bfr, bry, bgn, end, escape_lt, escape_gt, escape_amp, escape_quote, escape_apos); Escape_html(true, bfr, bry, bgn, end, escape_lt, escape_gt, escape_amp, escape_quote, escape_apos);
} }

View File

@ -24,7 +24,7 @@ public class Xoa_app_ {
boot_mgr.Run(args); boot_mgr.Run(args);
} }
public static final String Name = "xowa"; public static final String Name = "xowa";
public static final String Version = "1.10.3.1"; public static final String Version = "1.10.4.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; public static String Op_sys;
public static String User_agent = ""; public static String User_agent = "";

View File

@ -22,7 +22,7 @@ public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
private int select_interval = 2500, progress_interval = 1, commit_interval = 1, delete_interval = 5000; private int select_interval = 2500, progress_interval = 1, commit_interval = 1, delete_interval = 5000;
private int exec_count, exec_count_max = Int_.MaxValue; private int exec_count, exec_count_max = Int_.MaxValue;
private int exec_fail, exec_fail_max = 2000; // 115 over 900k private int exec_fail, exec_fail_max = 2000; // 115 over 900k
private boolean exec_done; private boolean exec_done, resume_enabled = false;
private int page_id_bmk = -1, lnki_id_bmk = -1; private int page_id_bmk = -1, lnki_id_bmk = -1;
private int page_id_val = -1, lnki_id_val = -1; private int page_id_val = -1, lnki_id_val = -1;
private int page_id_end = Int_.MaxValue; private int page_id_end = Int_.MaxValue;
@ -128,6 +128,10 @@ public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
db_select_stmt = Xob_xfer_regy_tbl.Select_by_page_id_stmt(provider); db_select_stmt = Xob_xfer_regy_tbl.Select_by_page_id_stmt(provider);
} }
private boolean Init_bmk(Xodb_xowa_cfg_tbl tbl_cfg) { private boolean Init_bmk(Xodb_xowa_cfg_tbl tbl_cfg) {
if (!resume_enabled) { // clear cfg entries if resume disabled; note that disabled by default; DATE:2014-10-24
tbl_cfg.Delete(Cfg_fsdb_make, Cfg_page_id_bmk);
tbl_cfg.Delete(Cfg_fsdb_make, Cfg_lnki_id_bmk);
}
String page_id_str = tbl_cfg.Select_val(Cfg_fsdb_make, Cfg_page_id_bmk); String page_id_str = tbl_cfg.Select_val(Cfg_fsdb_make, Cfg_page_id_bmk);
if (page_id_str == null) { // bmks not found; new db; insert; if (page_id_str == null) { // bmks not found; new db; insert;
tbl_cfg.Insert_str(Cfg_fsdb_make, Cfg_page_id_bmk , Int_.Xto_str(page_id_bmk)); tbl_cfg.Insert_str(Cfg_fsdb_make, Cfg_page_id_bmk , Int_.Xto_str(page_id_bmk));
@ -286,6 +290,7 @@ public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
else if (ctx.Match(k, Invk_app_restart_enabled_)) app_restart_enabled = m.ReadBool("v"); else if (ctx.Match(k, Invk_app_restart_enabled_)) app_restart_enabled = m.ReadBool("v");
else if (ctx.Match(k, Invk_db_restart_tries_max_)) db_reset_tries_max = m.ReadInt("v"); else if (ctx.Match(k, Invk_db_restart_tries_max_)) db_reset_tries_max = m.ReadInt("v");
else if (ctx.Match(k, Invk_trg_fsdb_mgr)) return trg_fsdb_mgr; else if (ctx.Match(k, Invk_trg_fsdb_mgr)) return trg_fsdb_mgr;
else if (ctx.Match(k, Invk_resume_enabled_)) resume_enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled; else return GfoInvkAble_.Rv_unhandled;
return this; return this;
} }
@ -299,6 +304,7 @@ public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
, Invk_app_restart_enabled_ = "app_restart_enabled_" , Invk_app_restart_enabled_ = "app_restart_enabled_"
, Invk_db_restart_tries_max_ = "db_restart_tries_max_" , Invk_db_restart_tries_max_ = "db_restart_tries_max_"
, Invk_trg_fsdb_mgr = "trg_fsdb_mgr" , Invk_trg_fsdb_mgr = "trg_fsdb_mgr"
, Invk_resume_enabled_ = "resume_enabled_"
; ;
public static byte Status_null = 0, Status_pass = 1, Status_fail = 2; public static byte Status_null = 0, Status_pass = 1, Status_fail = 2;
} }

View File

@ -69,21 +69,21 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xop_lnki_log
trg_mnt_mgr.Insert_to_mnt_(Fsdb_mnt_mgr.Mnt_idx_main); trg_mnt_mgr.Insert_to_mnt_(Fsdb_mnt_mgr.Mnt_idx_main);
Fsdb_mnt_mgr.Patch(trg_mnt_mgr); // NOTE: see fsdb_make; DATE:2014-04-26 Fsdb_mnt_mgr.Patch(trg_mnt_mgr); // NOTE: see fsdb_make; DATE:2014-04-26
if (gen_hdump) { if (gen_hdump) {
hdump_bldr = new Xob_hdump_bldr(wiki, provider, hdump_max); hdump_bldr = new Xob_hdump_bldr(wiki.Db_mgr_as_sql(), provider, hdump_max);
hdump_bldr.Bld_init();
} }
provider.Txn_mgr().Txn_bgn_if_none(); provider.Txn_mgr().Txn_bgn_if_none();
log_mgr.Txn_bgn(); log_mgr.Txn_bgn();
} }
@Override public void Exec_pg_itm_hook(Xow_ns ns, Xodb_page db_page, byte[] page_src) { @Override public void Exec_pg_itm_hook(Xow_ns ns, Xodb_page db_page, byte[] page_src) {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ns.Gen_ttl(db_page.Ttl_wo_ns())); Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ns.Gen_ttl(db_page.Ttl_wo_ns()));
// Io_mgr._.AppendFilStr("C:\\debug.txt", String_.new_utf8_(ttl.Full_txt()) + "\n");
byte[] ttl_bry = ttl.Page_db(); byte[] ttl_bry = ttl.Page_db();
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns.Id(), ttl_bry); byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns.Id(), ttl_bry);
if (page_tid != Xow_page_tid.Tid_wikitext) return; // ignore js, css, lua, json if (page_tid != Xow_page_tid.Tid_wikitext) return; // ignore js, css, lua, json
Xoa_page page = ctx.Cur_page(); Xoa_page page = ctx.Cur_page();
page.Clear(); page.Clear();
page.Ttl_(ttl).Revision_data().Id_(db_page.Id()); page.Ttl_(ttl).Revision_data().Id_(db_page.Id());
page.Lnki_redlinks_mgr().Page_bgn(); page.Lnki_redlinks_mgr().Clear();
if (ns.Id_tmpl()) if (ns.Id_tmpl())
parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, page_src); parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, page_src);
else { else {

View File

@ -27,7 +27,7 @@ public class Xof_fsdb_mgr_ {
for (int i = 0; i < itms_len; i++) { for (int i = 0; i < itms_len; i++) {
if (usr_dlg.Canceled()) return; if (usr_dlg.Canceled()) return;
Xof_fsdb_itm itm = (Xof_fsdb_itm)itms.FetchAt(i); Xof_fsdb_itm itm = (Xof_fsdb_itm)itms.FetchAt(i);
Itm_process(fsdb_mgr, file_dir, usr_dlg, itm, fsdb_list, repo_mgr, url_bldr, exec_tid); Itm_process(fsdb_mgr, page, file_dir, usr_dlg, itm, fsdb_list, repo_mgr, url_bldr, exec_tid);
} }
itms_len = fsdb_list.Count(); if (itms_len == 0) return; // all items found; return; itms_len = fsdb_list.Count(); if (itms_len == 0) return; // all items found; return;
Reg_search(fsdb_mgr, file_dir, usr_dlg, page, exec_tid, fsdb_list, itms_len, repo_mgr); Reg_search(fsdb_mgr, file_dir, usr_dlg, page, exec_tid, fsdb_list, itms_len, repo_mgr);
@ -89,11 +89,11 @@ public class Xof_fsdb_mgr_ {
); );
} }
private Xof_img_size img_size = new Xof_img_size(); private Xof_img_size img_size = new Xof_img_size();
private void Itm_process(Xof_fsdb_mgr fsdb_mgr, Io_url file_dir, Gfo_usr_dlg usr_dlg, Xof_fsdb_itm itm, ListAdp fsdb_list, Xow_repo_mgr repo_mgr, Xof_url_bldr url_bldr, byte exec_tid) { private void Itm_process(Xof_fsdb_mgr fsdb_mgr, Xoa_page page, Io_url file_dir, Gfo_usr_dlg usr_dlg, Xof_fsdb_itm itm, ListAdp fsdb_list, Xow_repo_mgr repo_mgr, Xof_url_bldr url_bldr, byte exec_tid) {
switch (itm.Rslt_reg()) { switch (itm.Rslt_reg()) {
case Xof_wiki_orig_wkr_.Tid_found_orig: case Xof_wiki_orig_wkr_.Tid_found_orig:
itm.Html__init(repo_mgr, url_bldr, img_size, exec_tid); itm.Html__init(repo_mgr, url_bldr, img_size, exec_tid);
// Js_img_mgr.Update_img(usr_dlg, itm); // DELETE: DATE:2014-02-01 Js_img_mgr.Update_img(page, itm); // NOTE: needed when opening 2+ tabs and missing image is on 2+ pages; 2nd page will have img as Xof_wiki_orig_wkr_.Tid_found_orig; DATE:2014-10-20
if (!Env_.Mode_testing()) { if (!Env_.Mode_testing()) {
Cache_fil_itm cache_fil_itm = fsdb_mgr.Cache_mgr().Reg(fsdb_mgr.Wiki(), itm, 0); Cache_fil_itm cache_fil_itm = fsdb_mgr.Cache_mgr().Reg(fsdb_mgr.Wiki(), itm, 0);
if (cache_fil_itm.Fil_size() == 0) { if (cache_fil_itm.Fil_size() == 0) {

View File

@ -77,6 +77,7 @@ public class Xog_tab_itm_edit_mgr {
Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win(); Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
if (Bry_.Eq(page.Ttl().Page_db(), wiki.Props().Main_page())) { if (Bry_.Eq(page.Ttl().Page_db(), wiki.Props().Main_page())) {
win_itm.Usr_dlg().Warn_many("", "", "The Main Page cannot be renamed"); win_itm.Usr_dlg().Warn_many("", "", "The Main Page cannot be renamed");
win_itm.Kit().Ask_ok("", "", "The Main Page cannot be renamed");
return; return;
} }
byte[] new_text = Bry_.new_utf8_(tab.Html_itm().Get_elem_value(Xog_html_itm.Elem_id__xowa_edit_rename_box)); byte[] new_text = Bry_.new_utf8_(tab.Html_itm().Get_elem_value(Xog_html_itm.Elem_id__xowa_edit_rename_box));

View File

@ -16,67 +16,71 @@ 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.hdumps; import gplx.*; import gplx.xowa.*; package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.dbs.*; import gplx.dbs.*; import gplx.ios.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*;
public class Xob_hdump_bldr { public class Xob_hdump_bldr {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb); private Xodb_fsys_mgr fsys_mgr; private Xodb_file core_db; private Xodb_xowa_db_tbl db_tbl; private Xodb_xowa_cfg_tbl cfg_tbl; private Db_stmt cfg_update_stmt;
private Xow_wiki wiki; private Xodb_file core_db; private Xodb_xowa_cfg_tbl cfg_tbl; private Db_stmt cfg_update_stmt;
private int hdump_db_id; private long hdump_db_size, hdump_db_max; private Db_provider hdump_db_provider; private int hdump_db_id; private long hdump_db_size, hdump_db_max; private Db_provider hdump_db_provider;
private Xodb_hdump_mgr hdump_mgr; private Hdump_save_mgr hdump_save_mgr; private Xodb_hdump_mgr hdump_mgr; private Hdump_save_mgr hdump_save_mgr;
public Xob_hdump_bldr(Xow_wiki wiki, Db_provider make_provider, long hdump_db_max) { public Xob_hdump_bldr(Xodb_mgr_sql db_mgr, Db_provider make_provider, long hdump_db_max) {
this.wiki = wiki; this.hdump_db_max = hdump_db_max; this.hdump_db_max = hdump_db_max;
core_db = wiki.Db_mgr_as_sql().Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_core); this.fsys_mgr = db_mgr.Fsys_mgr();
hdump_mgr = wiki.Db_mgr_as_sql().Hdump_mgr(); hdump_save_mgr = hdump_mgr.Save_mgr(); core_db = fsys_mgr.Get_tid_root(Xodb_file_tid.Tid_core);
db_tbl = db_mgr.Tbl_xowa_db();
cfg_tbl = new Xodb_xowa_cfg_tbl().Provider_(make_provider); cfg_update_stmt = cfg_tbl.Update_stmt(); cfg_tbl = new Xodb_xowa_cfg_tbl().Provider_(make_provider); cfg_update_stmt = cfg_tbl.Update_stmt();
Xodb_hdump_mgr_setup.Assert_col__page_html_db_id(core_db.Provider(), cfg_tbl); Xodb_hdump_mgr_setup.Assert_col__page_html_db_id(core_db.Provider(), cfg_tbl);
Init_hdump_db(Db_get_last_or_make(wiki), cfg_tbl.Select_val_as_long_or(Cfg_grp_hdump_make, Cfg_itm_hdump_size, 0)); hdump_mgr = db_mgr.Hdump_mgr(); hdump_save_mgr = hdump_mgr.Save_mgr();
hdump_save_mgr.Hdump_stats_enable_y_(make_provider);
}
public void Bld_init() {
Db_init(Db_get_last_or_make(fsys_mgr), cfg_tbl.Select_val_as_long_or(Cfg_grp_hdump_make, Cfg_itm_hdump_size, 0));
hdump_db_provider.Txn_mgr().Txn_bgn_if_none(); hdump_db_provider.Txn_mgr().Txn_bgn_if_none();
} }
public void Insert_page(Xoa_page page) {
hdump_mgr.Write(tmp_bfr, page);
int body_len = hdump_save_mgr.Insert_body(page, page.Revision_data().Id());
hdump_db_size += body_len;
if (hdump_db_size > hdump_db_max) {
Db_term(core_db, hdump_db_provider, hdump_db_id);
Init_hdump_db(wiki.Db_mgr_as_sql().Fsys_mgr().Make(Xodb_file_tid.Tid_html), 0);
Db_init(hdump_db_provider);
}
}
public void Commit() {
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql(); db_mgr.Tbl_xowa_db().Commit_all(db_mgr.Fsys_mgr()); // commit new html_dbs
hdump_db_provider.Txn_mgr().Txn_end_all_bgn_if_none();
cfg_tbl.Update(cfg_update_stmt, Cfg_grp_hdump_make, Cfg_itm_hdump_size, Long_.Xto_str(hdump_db_size));
}
public void Bld_term() { public void Bld_term() {
this.Commit(); this.Commit();
Db_term(core_db, hdump_db_provider, hdump_db_id); Db_term(core_db, hdump_db_provider, hdump_db_id);
} }
private void Init_hdump_db(Xodb_file db_file, long hdump_db_size) { private Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
this.hdump_db_id = db_file.Id(); public void Insert_page(Xoa_page page) {
this.hdump_db_provider = db_file.Provider(); hdump_mgr.Write2(tmp_bfr, page);
this.hdump_db_size = hdump_db_size; hdump_db_size += hdump_save_mgr.Insert_body(page, page.Revision_data().Id());
this.hdump_save_mgr.Tbl().Provider_(hdump_db_provider); if (hdump_db_size > hdump_db_max) {
Db_term(core_db, hdump_db_provider, hdump_db_id);
Db_init(Db_make(fsys_mgr), 0);
} }
private static Xodb_file Db_get_last_or_make(Xow_wiki wiki) { }
Xodb_fsys_mgr fsys_mgr = wiki.Db_mgr_as_sql().Fsys_mgr(); public void Commit() {
db_tbl.Commit_all(fsys_mgr); // commit new html_dbs
hdump_db_provider.Txn_mgr().Txn_end_all_bgn_if_none(); // commit entries
cfg_tbl.Update(cfg_update_stmt, Cfg_grp_hdump_make, Cfg_itm_hdump_size, Long_.Xto_str(hdump_db_size)); // update cfg; should happen after commit entries
}
private static Xodb_file Db_get_last_or_make(Xodb_fsys_mgr fsys_mgr) {
Xodb_file rv = fsys_mgr.Get_tid_root(Xodb_file_tid.Tid_html); Xodb_file rv = fsys_mgr.Get_tid_root(Xodb_file_tid.Tid_html);
if (rv == null) { if (rv == null) rv = Db_make(fsys_mgr);
rv = fsys_mgr.Make(Xodb_file_tid.Tid_html); return rv;
Db_init(rv.Provider()); }
} private void Db_init(Xodb_file db_file, long hdump_db_size) {
this.hdump_db_id = db_file.Id();
this.hdump_db_size = hdump_db_size;
this.hdump_db_provider = db_file.Provider();
this.hdump_save_mgr.Tbl().Provider_(hdump_db_provider);
}
private static Xodb_file Db_make(Xodb_fsys_mgr fsys_mgr) {
Xodb_file rv = fsys_mgr.Make(Xodb_file_tid.Tid_html);
rv.Provider().Exec_sql(Xodb_wiki_page_html_tbl.Tbl_sql);
return rv; return rv;
} }
private static void Db_init(Db_provider p) {p.Exec_sql(Hdump_text_tbl.Tbl_sql);}
private static void Db_term(Xodb_file core_db_file, Db_provider hdump_db_provider, int hdump_db_id) { private static void Db_term(Xodb_file core_db_file, Db_provider hdump_db_provider, int hdump_db_id) {
hdump_db_provider.Txn_mgr().Txn_end_all(); hdump_db_provider.Txn_mgr().Txn_end_all(); // commit transactions
Sqlite_engine_.Idx_create(hdump_db_provider, Hdump_text_tbl.Idx_core); Sqlite_engine_.Idx_create(hdump_db_provider, Xodb_wiki_page_html_tbl.Idx_core); // create index
Sqlite_engine_.Db_attach(hdump_db_provider, "page_db", core_db_file.Url().Raw()); Sqlite_engine_.Db_attach(hdump_db_provider, "page_db", core_db_file.Url().Raw()); // update page_db.page with page_html_db_id
hdump_db_provider.Txn_mgr().Txn_bgn(); hdump_db_provider.Txn_mgr().Txn_bgn();
hdump_db_provider.Exec_sql(String_.Format(Sql_update_page, hdump_db_id)); // update all page_html_db_id entries in page_db hdump_db_provider.Exec_sql(String_.Format(Sql_update_page_html_db_id, hdump_db_id));
hdump_db_provider.Txn_mgr().Txn_end(); hdump_db_provider.Txn_mgr().Txn_end();
Sqlite_engine_.Db_detach(hdump_db_provider, "page_db"); Sqlite_engine_.Db_detach(hdump_db_provider, "page_db");
hdump_db_provider.Conn_term(); // release provider
} }
private static final String Cfg_grp_hdump_make = "hdump.make", Cfg_itm_hdump_size = "hdump.size"; private static final String Cfg_grp_hdump_make = "hdump.make", Cfg_itm_hdump_size = "hdump.size";
private static final String Sql_update_page = String_.Concat_lines_nl_skip_last private static final String Sql_update_page_html_db_id = String_.Concat_lines_nl_skip_last
( "REPLACE INTO page_db.page (page_id, page_namespace, page_title, page_is_redirect, page_touched, page_len, page_random_int, page_file_idx, page_redirect_id, page_html_db_id)" ( "REPLACE INTO page_db.page (page_id, page_namespace, page_title, page_is_redirect, page_touched, page_len, page_random_int, page_file_idx, page_redirect_id, page_html_db_id)"
, "SELECT p.page_id" , "SELECT p.page_id"
, ", p.page_namespace" , ", p.page_namespace"
@ -89,6 +93,6 @@ public class Xob_hdump_bldr {
, ", p.page_redirect_id" , ", p.page_redirect_id"
, ", {0}" , ", {0}"
, "FROM page_db.page p" , "FROM page_db.page p"
, " JOIN html_text h ON p.page_id = h.page_id" , " JOIN wiki_page_html h ON p.page_id = h.page_id"
); );
} }

View File

@ -17,24 +17,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*; package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.html.*; import gplx.xowa.gui.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.html.*; import gplx.xowa.gui.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.htmls.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.htmls.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.hzips.*;
public class Xodb_hdump_mgr { public class Xodb_hdump_mgr {
private Xodb_file hdump_db_file; private Xodb_file hdump_db_file; private Xoa_hzip_mgr hzip_mgr;
public Xodb_hdump_mgr(Xow_wiki wiki) { public Xodb_hdump_mgr(Xow_wiki wiki) {
this.wiki = wiki; this.wiki = wiki;
load_mgr = new Hdump_load_mgr(); load_mgr = new Hdump_load_mgr();
Tbl_(new Hdump_text_tbl()); Tbl_(new Xodb_wiki_page_html_tbl());
text_tbl.Init_by_wiki(wiki); text_tbl.Init_by_wiki(wiki);
Xoa_app app = wiki.App(); Xoa_app app = wiki.App();
html_mgr.Init_by_app(app.Usr_dlg(), app.Fsys_mgr(), app.Encoder_mgr().Fsys()); html_mgr.Init_by_app(app.Usr_dlg(), app.Fsys_mgr(), app.Encoder_mgr().Fsys());
hzip_mgr = new Xoa_hzip_mgr(app.Usr_dlg(), wiki);
} }
public Xow_wiki Wiki() {return wiki;} private final Xow_wiki wiki; public Xow_wiki Wiki() {return wiki;} private final Xow_wiki wiki;
@gplx.Internal protected Hdump_load_mgr Load_mgr() {return load_mgr;} private Hdump_load_mgr load_mgr; @gplx.Internal protected Hdump_load_mgr Load_mgr() {return load_mgr;} private Hdump_load_mgr load_mgr;
@gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr(); @gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr();
public Hdump_html_body Html_mgr() {return html_mgr;} private Hdump_html_body html_mgr = new Hdump_html_body(); public Hdump_html_body Html_mgr() {return html_mgr;} private Hdump_html_body html_mgr = new Hdump_html_body();
public Hdump_text_tbl Text_tbl() {return text_tbl;} private Hdump_text_tbl text_tbl; public Xodb_wiki_page_html_tbl Text_tbl() {return text_tbl;} private Xodb_wiki_page_html_tbl text_tbl;
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled; public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
@gplx.Internal protected void Tbl_mem_() {Tbl_(new Hdump_text_tbl_mem());} @gplx.Internal protected void Tbl_mem_() {Tbl_(new Xodb_wiki_page_html_tbl_mem());}
public int Html_db_id_default(int page_len) { public int Html_db_id_default(int page_len) {
return -1; return -1;
} }
@ -58,11 +59,22 @@ public class Xodb_hdump_mgr {
wkr.Write_body(bfr, Xoh_wtr_ctx.Hdump, page); wkr.Write_body(bfr, Xoh_wtr_ctx.Hdump, page);
page.Hdump_data().Body_(bfr.Xto_bry_and_clear()); page.Hdump_data().Body_(bfr.Xto_bry_and_clear());
} }
public void Write2(Bry_bfr tmp_bfr, Xoa_page page) {
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read);
wkr.Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page);
hzip_mgr.Save(tmp_bfr, page.Url().Xto_full_bry(), tmp_bfr.Xto_bry_and_clear());
page.Hdump_data().Body_(tmp_bfr.Xto_bry_and_clear());
hpg.Init(tmp_bfr, page);
} private Hdump_page hpg = new Hdump_page();
public void Load(Xow_wiki wiki, Xoa_page page, int html_db_id) { public void Load(Xow_wiki wiki, Xoa_page page, int html_db_id) {
if (!Enabled_chk()) return; if (!Enabled_chk()) return;
page.Root_(new Xop_root_tkn()); page.Root_(new Xop_root_tkn());
Hdump_page hpg = new Hdump_page().Init(page.Revision_data().Id(), page.Url(), page.Ttl()); Hdump_page hpg = new Hdump_page().Init(page.Revision_data().Id(), page.Url(), page.Ttl());
load_mgr.Load(hpg, wiki.Db_mgr_as_sql().Fsys_mgr(), html_db_id, page.Revision_data().Id(), page.Ttl()); load_mgr.Load(hpg, wiki.Db_mgr_as_sql().Fsys_mgr(), html_db_id, page.Revision_data().Id(), page.Ttl());
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
hzip_mgr.Load(tmp_bfr, page.Url().Xto_full_bry(), hpg.Page_body());
hpg.Page_body_(tmp_bfr.Mkr_rls().Xto_bry_and_clear());
Load_page(wiki, page, hpg); Load_page(wiki, page, hpg);
} }
private void Load_page(Xow_wiki wiki, Xoa_page page, Hdump_page hpg) { private void Load_page(Xow_wiki wiki, Xoa_page page, Hdump_page hpg) {
@ -76,7 +88,7 @@ public class Xodb_hdump_mgr {
Hdump_page_body_srl.Load_html_modules(html_data.Module_mgr(), hpg); Hdump_page_body_srl.Load_html_modules(html_data.Module_mgr(), hpg);
tmp_bfr.Mkr_rls(); tmp_bfr.Mkr_rls();
} }
private void Tbl_(Hdump_text_tbl v) { private void Tbl_(Xodb_wiki_page_html_tbl v) {
text_tbl = v; text_tbl = v;
save_mgr.Tbl_(text_tbl); save_mgr.Tbl_(text_tbl);
// load_mgr.Tbl_(text_tbl); // load_mgr.Tbl_(text_tbl);

View File

@ -20,18 +20,18 @@ import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.pages.*;
public class Xodb_hdump_mgr__save_tst { public class Xodb_hdump_mgr__save_tst {
@Before public void init() {fxt.Clear();} private Xodb_hdump_mgr__save_fxt fxt = new Xodb_hdump_mgr__save_fxt(); @Before public void init() {fxt.Clear();} private Xodb_hdump_mgr__save_fxt fxt = new Xodb_hdump_mgr__save_fxt();
@Test public void Body() { // @Test public void Body() {
fxt.Test_save("abc", fxt.Make_row_body(0, "abc")); // fxt.Test_save("abc", fxt.Make_row_body(0, "abc"));
} // }
@Test public void Img() { // @Test public void Img() {
fxt.Test_save("a[[File:A.png|test_caption]]b[[File:B.png|test_caption]]" // fxt.Test_save("a[[File:A.png|test_caption]]b[[File:B.png|test_caption]]"
, fxt.Make_row_body(2, "a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\" xowa_img='0' /></a>b<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_1\" alt=\"test_caption\" xowa_img='1' /></a>") // , fxt.Make_row_body(2, "a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\" xowa_img='0' /></a>b<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_1\" alt=\"test_caption\" xowa_img='1' /></a>")
, fxt.Make_row_img // , fxt.Make_row_img
( fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png) // ( fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png)
, fxt.Make_xfer("B.png", 1, 0, 0, Bool_.Y, Xof_ext_.Id_png) // , fxt.Make_xfer("B.png", 1, 0, 0, Bool_.Y, Xof_ext_.Id_png)
) // )
); // );
} // }
@Test public void Display_title() { @Test public void Display_title() {
fxt.Test_write("{{DISPLAYTITLE:A}}bcd", String_.Concat_lines_nl_skip_last fxt.Test_write("{{DISPLAYTITLE:A}}bcd", String_.Concat_lines_nl_skip_last
( "0|0" ( "0|0"
@ -63,13 +63,13 @@ public class Xodb_hdump_mgr__save_tst {
, "<xo_5/>bcd" , "<xo_5/>bcd"
)); ));
} }
@Test public void Redlink() { // @Test public void Redlink() {
fxt.Init_redlinks(1); // fxt.Init_redlinks(1);
fxt.Test_save("[[A]] [[B]]" // fxt.Test_save("[[A]] [[B]]"
, fxt.Make_row_body(0, "<a href=\"/wiki/A\" xowa_redlink='1'>A</a> <a href=\"/wiki/B\" xowa_redlink='2'>B</a>") // , fxt.Make_row_body(0, "<a href=\"/wiki/A\" xowa_redlink='1'>A</a> <a href=\"/wiki/B\" xowa_redlink='2'>B</a>")
, fxt.Make_row_redlink(1) // , fxt.Make_row_redlink(1)
); // );
} // }
} }
class Xodb_hdump_mgr__save_fxt extends Xodb_hdump_mgr__base_fxt { class Xodb_hdump_mgr__save_fxt extends Xodb_hdump_mgr__base_fxt {
private int page_id = 0; private int page_id = 0;
@ -77,31 +77,31 @@ class Xodb_hdump_mgr__save_fxt extends Xodb_hdump_mgr__base_fxt {
private ListAdp expd_rows = ListAdp_.new_(); private ListAdp expd_rows = ListAdp_.new_();
@Override public void Clear_end() { @Override public void Clear_end() {
hdump_mgr.Tbl_mem_(); hdump_mgr.Tbl_mem_();
hdump_mgr.Text_tbl().Provider_(Hdump_text_tbl_mem.Null_provider); hdump_mgr.Text_tbl().Provider_(Xodb_wiki_page_html_tbl_mem.Null_provider);
init_redlinks = null; init_redlinks = null;
} }
public void Init_redlinks(int... uids) { public void Init_redlinks(int... uids) {
this.init_redlinks = uids; this.init_redlinks = uids;
page.Lnki_redlinks_mgr().Page_bgn(); page.Lnki_redlinks_mgr().Clear();
} private int[] init_redlinks; } private int[] init_redlinks;
public Hdump_text_row Make_row_body(int imgs_count, String body) { public Xodb_wiki_page_html_row Make_row_body(int imgs_count, String body) {
page.Hdump_data().Body_(Bry_.new_utf8_(body)); page.Hdump_data().Body_(Bry_.new_utf8_(body));
page.Hdump_data().Data_count_imgs_(imgs_count); page.Hdump_data().Data_count_imgs_(imgs_count);
Hdump_page_body_srl.Save(tmp_bfr, page); Hdump_page_body_srl.Save(tmp_bfr, page);
return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, tmp_bfr.Xto_bry_and_clear()); return new Xodb_wiki_page_html_row(page_id, Xodb_wiki_page_html_row.Tid_page, tmp_bfr.Xto_bry_and_clear());
} }
public Hdump_text_row Make_row_img(Hdump_data_img__base... itms) { public Xodb_wiki_page_html_row Make_row_img(Hdump_data_img__base... itms) {
ListAdp tmp_list = ListAdp_.new_(); ListAdp tmp_list = ListAdp_.new_();
tmp_list.AddMany((Object[])itms); tmp_list.AddMany((Object[])itms);
byte[] imgs_bry = Hdump_save_mgr.Write_imgs(tmp_bfr, tmp_list); byte[] imgs_bry = Hdump_save_mgr.Write_imgs(tmp_bfr, tmp_list);
return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_data, imgs_bry); return new Xodb_wiki_page_html_row(page_id, Xodb_wiki_page_html_row.Tid_data, imgs_bry);
} }
public Hdump_text_row Make_row_redlink(int... uids) { public Xodb_wiki_page_html_row Make_row_redlink(int... uids) {
Xopg_redlink_mgr redlink_mgr = new Xopg_redlink_mgr(); Xopg_redlink_mgr redlink_mgr = new Xopg_redlink_mgr();
for (int uid : uids) for (int uid : uids)
redlink_mgr.Add(uid); redlink_mgr.Add(uid);
byte[] redlinks_bry = Hdump_save_mgr.Write_redlinks(tmp_bfr, redlink_mgr); byte[] redlinks_bry = Hdump_save_mgr.Write_redlinks(tmp_bfr, redlink_mgr);
return new Hdump_text_row(page_id, Hdump_data_tid.Tid_redlink, redlinks_bry); return new Xodb_wiki_page_html_row(page_id, Hdump_data_tid.Tid_redlink, redlinks_bry);
} }
@Override public void Exec_write(String raw) { @Override public void Exec_write(String raw) {
super.Exec_write(raw); super.Exec_write(raw);
@ -118,18 +118,18 @@ class Xodb_hdump_mgr__save_fxt extends Xodb_hdump_mgr__base_fxt {
Hdump_page_body_srl.Save(tmp_bfr, page); Hdump_page_body_srl.Save(tmp_bfr, page);
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear()); Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
} }
public void Test_save(String raw, Hdump_text_row... expd) { public void Test_save(String raw, Xodb_wiki_page_html_row... expd) {
this.Exec_write(raw); this.Exec_write(raw);
hdump_mgr.Save_mgr().Update(page); hdump_mgr.Save_mgr().Update(page);
hdump_mgr.Text_tbl().Select_by_page(expd_rows, 0); hdump_mgr.Text_tbl().Select_by_page(expd_rows, 0);
Hdump_text_row[] actl = (Hdump_text_row[])expd_rows.Xto_ary_and_clear(Hdump_text_row.class); Xodb_wiki_page_html_row[] actl = (Xodb_wiki_page_html_row[])expd_rows.Xto_ary_and_clear(Xodb_wiki_page_html_row.class);
Tfds.Eq_ary_str(Xto_str_ary(tmp_bfr, expd), Xto_str_ary(tmp_bfr, actl)); Tfds.Eq_ary_str(Xto_str_ary(tmp_bfr, expd), Xto_str_ary(tmp_bfr, actl));
} }
private static String[] Xto_str_ary(Bry_bfr bfr, Hdump_text_row[] ary) { private static String[] Xto_str_ary(Bry_bfr bfr, Xodb_wiki_page_html_row[] ary) {
int len = ary.length; int len = ary.length;
String[] rv = new String[len]; String[] rv = new String[len];
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
Hdump_text_row itm = ary[i]; Xodb_wiki_page_html_row itm = ary[i];
bfr .Add_int_variable(itm.Page_id()) bfr .Add_int_variable(itm.Page_id())
.Add_byte_pipe().Add_int_variable(itm.Tid()) .Add_byte_pipe().Add_int_variable(itm.Tid())
.Add_byte_pipe().Add(itm.Data()) .Add_byte_pipe().Add(itm.Data())
@ -146,5 +146,5 @@ class Hdump_text_row_img {
public int Img_h() {return img_h;} private int img_h; public int Img_h() {return img_h;} private int img_h;
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl; public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte[] Img_src_rel() {return img_src_rel;} private byte[] img_src_rel; public byte[] Img_src_rel() {return img_src_rel;} private byte[] img_src_rel;
// return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img, 0, Hdump_save_mgr.Write_img(bfr, uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel))) // return new Xodb_wiki_page_html_row(page_id, Xodb_wiki_page_html_row.Tid_img, 0, Hdump_save_mgr.Write_img(bfr, uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel)))
} }

View File

@ -39,16 +39,17 @@ public class Xodb_hdump_mgr_setup {
try { try {
core_provider.Exec_sql(Sql_ddl__page_html_db_id); core_provider.Exec_sql(Sql_ddl__page_html_db_id);
cfg_tbl.Insert_str(Xodb_fsys_mgr.Cfg_grp_db_meta, Cfg_itm_html_db_exists, "y"); cfg_tbl.Insert_str(Xodb_fsys_mgr.Cfg_grp_db_meta, Cfg_itm_html_db_exists, "y");
cfg_tbl.Provider().Txn_mgr().Txn_end_all_bgn_if_none();
} catch (Exception e) {Gfo_usr_dlg_._.Warn_many("", "", "failed to update core: db=~{0} err=~{1}", core_provider.Conn_info().Str_raw(), Err_.Message_gplx(e));} } catch (Exception e) {Gfo_usr_dlg_._.Warn_many("", "", "failed to update core: db=~{0} err=~{1}", core_provider.Conn_info().Str_raw(), Err_.Message_gplx(e));}
} }
private static Xodb_file Create_db(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) { private static Xodb_file Create_db(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {
Xodb_file html_db_file = fsys_mgr.Make(Xodb_file_tid.Tid_html); Xodb_file html_db_file = fsys_mgr.Make(Xodb_file_tid.Tid_html);
html_db_file.Provider().Exec_sql(Hdump_text_tbl.Tbl_sql); html_db_file.Provider().Exec_sql(Xodb_wiki_page_html_tbl.Tbl_sql);
db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Provider_core(), db_mgr.Fsys_mgr().Files_ary()); db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Provider_core(), db_mgr.Fsys_mgr().Files_ary());
return html_db_file; return html_db_file;
} }
private static void Create_idx(Xodb_file html_db_file) { private static void Create_idx(Xodb_file html_db_file) {
Sqlite_engine_.Idx_create(html_db_file.Provider(), Hdump_text_tbl.Idx_core); Sqlite_engine_.Idx_create(html_db_file.Provider(), Xodb_wiki_page_html_tbl.Idx_core);
} }
private static final String Cfg_itm_html_db_exists = "html_db.exists"; private static final String Cfg_itm_html_db_exists = "html_db.exists";
public static final String public static final String

View File

@ -22,8 +22,8 @@ public class Xodbv_page_tbl {
, Fld_page_id = "page_id", Fld_page_ns = "page_namespace", Fld_page_title = "page_title" , Fld_page_id = "page_id", Fld_page_ns = "page_namespace", Fld_page_title = "page_title"
, Fld_page_is_redirect = "page_is_redirect", Fld_page_touched = "page_touched", Fld_page_len = "page_len" , Fld_page_is_redirect = "page_is_redirect", Fld_page_touched = "page_touched", Fld_page_len = "page_len"
, Fld_page_random_int = "page_random_int", Fld_page_file_idx = "page_file_idx" , Fld_page_random_int = "page_random_int", Fld_page_file_idx = "page_file_idx"
, Fld_page_html_db_id = "page_html_db_id"; , Fld_page_html_db_id = "page_html_db_id", Fld_page_redirect_id = "page_redirect_id";
private static final String[] Select_by_id_flds__hdump = new String[] {Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx, Fld_page_html_db_id}; private static final String[] Select_by_id_flds__hdump = new String[] {Fld_page_id, Fld_page_ns, Fld_page_title, Fld_page_touched, Fld_page_is_redirect, Fld_page_len, Fld_page_file_idx, Fld_page_html_db_id, Fld_page_redirect_id};
public boolean Select_by_ttl(Xodb_page rv, Db_provider provider, Xow_ns ns, byte[] ttl) { public boolean Select_by_ttl(Xodb_page rv, Db_provider provider, Xow_ns ns, byte[] ttl) {
Db_rdr rdr = Db_rdr_.Null; Db_stmt stmt = Db_stmt_.Null; Db_rdr rdr = Db_rdr_.Null; Db_stmt stmt = Db_stmt_.Null;
try { try {
@ -36,6 +36,18 @@ public class Xodbv_page_tbl {
} finally {rdr.Close(); stmt.Rls();} } finally {rdr.Close(); stmt.Rls();}
return false; return false;
} }
public boolean Select_by_id(Xodb_page rv, Db_provider provider, int page_id) {
Db_rdr rdr = Db_rdr_.Null; Db_stmt stmt = Db_stmt_.Null;
try {
stmt = Db_stmt_.new_select_as_rdr(provider, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_page_id), Select_by_id_flds__hdump));
rdr = stmt.Val_int_(page_id).Exec_select_as_rdr();
if (rdr.Move_next()) {
Read_page__all(rv, rdr);
return true;
}
} finally {rdr.Close(); stmt.Rls();}
return false;
}
public static void Read_page__all(Xodb_page page, Db_rdr rdr) { public static void Read_page__all(Xodb_page page, Db_rdr rdr) {
page.Id_ (rdr.Read_int(0)); page.Id_ (rdr.Read_int(0));
page.Ns_id_ (rdr.Read_int(1)); page.Ns_id_ (rdr.Read_int(1));
@ -45,6 +57,7 @@ public class Xodbv_page_tbl {
page.Text_len_ (rdr.Read_int(5)); page.Text_len_ (rdr.Read_int(5));
page.Text_db_id_ (rdr.Read_int(6)); page.Text_db_id_ (rdr.Read_int(6));
page.Html_db_id_ (rdr.Read_int(7)); page.Html_db_id_ (rdr.Read_int(7));
page.Redirect_id_ (rdr.Read_int(8));
} }
private static final String Page_touched_fmt = "yyyyMMddHHmmss"; private static final String Page_touched_fmt = "yyyyMMddHHmmss";
} }

View File

@ -30,10 +30,19 @@ public class Xowd_hdump_mgr {
public void Load(Hdump_page rv, byte[] ttl_bry) { public void Load(Hdump_page rv, byte[] ttl_bry) {
Xoa_ttl ttl = wiki.Ttl_parse(ttl_bry); Xoa_ttl ttl = wiki.Ttl_parse(ttl_bry);
wiki_db_mgr.Tbl_mgr().Tbl__page().Select_by_ttl(dbpg, app.Db_mgr().Get(wiki_db_mgr.Key__core()), ttl.Ns(), ttl.Page_db()); wiki_db_mgr.Tbl_mgr().Tbl__page().Select_by_ttl(dbpg, app.Db_mgr().Get(wiki_db_mgr.Key__core()), ttl.Ns(), ttl.Page_db());
if (dbpg.Redirect_id() != -1) Select_by_id(rv, dbpg);
if (dbpg.Html_db_id() == -1) return; // should return "not found" message if (dbpg.Html_db_id() == -1) return; // should return "not found" message
load_mgr.Load2(rv, app.Db_mgr().Get(wiki_db_mgr.Key_by_idx(dbpg.Html_db_id())), dbpg.Id(), ttl); load_mgr.Load2(rv, app.Db_mgr().Get(wiki_db_mgr.Key_by_idx(dbpg.Html_db_id())), dbpg.Id(), ttl);
Bry_bfr bfr = app.Utl_bfr_mkr().Get_m001(); Bry_bfr bfr = app.Utl_bfr_mkr().Get_m001();
html_body.Init_by_page(wiki.Domain_bry(), rv).Write(bfr); html_body.Init_by_page(wiki.Domain_bry(), rv).Write(bfr);
rv.Page_body_(bfr.Mkr_rls().Xto_bry_and_clear()); rv.Page_body_(bfr.Mkr_rls().Xto_bry_and_clear());
} }
private void Select_by_id(Hdump_page hpg, Xodb_page dbpg) {
int redirect_count = 0;
while (redirect_count < 5) {
int redirect_id = dbpg.Redirect_id();
wiki_db_mgr.Tbl_mgr().Tbl__page().Select_by_id(dbpg, app.Db_mgr().Get(wiki_db_mgr.Key__core()), redirect_id);
if (redirect_id == -1) break;
}
}
} }

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.dbs.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.oimgs.*; import gplx.dbs.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.oimgs.*;
class Hdump_img_bldr_cmd extends Xob_itm_basic_base implements Xob_cmd { class Hdump_img_bldr_cmd extends Xob_itm_basic_base implements Xob_cmd {
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private Xodb_wiki_page_html_tbl text_tbl = new Xodb_wiki_page_html_tbl();
public Hdump_img_bldr_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);} public Hdump_img_bldr_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
public String Cmd_key() {return Key_const;} public static final String Key_const = "hdump.make.imgs"; public String Cmd_key() {return Key_const;} public static final String Key_const = "hdump.make.imgs";
public void Cmd_ini(Xob_bldr bldr) {} public void Cmd_ini(Xob_bldr bldr) {}

View File

@ -21,6 +21,12 @@ public class Hdump_module_mgr {
public boolean Imap_exists() {return imap_exists;} public void Imap_exists_(boolean v) {imap_exists = v;} private boolean imap_exists; public boolean Imap_exists() {return imap_exists;} public void Imap_exists_(boolean v) {imap_exists = v;} private boolean imap_exists;
public boolean Gallery_packed_exists() {return gallery_packed_exists;} public void Gallery_packed_exists_(boolean v) {gallery_packed_exists = v;} private boolean gallery_packed_exists; public boolean Gallery_packed_exists() {return gallery_packed_exists;} public void Gallery_packed_exists_(boolean v) {gallery_packed_exists = v;} private boolean gallery_packed_exists;
public boolean Hiero_exists() {return hiero_exists;} public void Hiero_exists_(boolean v) {hiero_exists = v;} private boolean hiero_exists; public boolean Hiero_exists() {return hiero_exists;} public void Hiero_exists_(boolean v) {hiero_exists = v;} private boolean hiero_exists;
public void Init(boolean math, boolean imap, boolean packed, boolean hiero) {
this.math_exists = math;
this.imap_exists = imap;
this.gallery_packed_exists = packed;
this.hiero_exists = hiero;
}
public void Clear() { public void Clear() {
math_exists = imap_exists = gallery_packed_exists = hiero_exists = false; math_exists = imap_exists = gallery_packed_exists = hiero_exists = false;
} }

View File

@ -16,6 +16,7 @@ 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.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
public class Hdump_page { public class Hdump_page {
public int Page_id() {return page_id;} private int page_id; public int Page_id() {return page_id;} private int page_id;
public Xoa_url Page_url() {return page_url;} private Xoa_url page_url; public Xoa_url Page_url() {return page_url;} private Xoa_url page_url;
@ -39,4 +40,27 @@ public class Hdump_page {
gly_itms.Clear(); gly_itms.Clear();
return this; return this;
} }
public void Init(Bry_bfr tmp_bfr, Xoa_page page) {
page_id = page.Revision_data().Id();
page_body = page.Hdump_data().Body();
Xopg_html_data html_data = page.Html_data();
gplx.xowa.html.modules.Xoh_module_mgr mod_mgr = html_data.Module_mgr();
module_mgr.Init(mod_mgr.Itm_mathjax().Enabled(), mod_mgr.Itm_popups().Bind_hover_area(), mod_mgr.Itm_gallery().Enabled(), mod_mgr.Itm_hiero().Enabled());
display_ttl = html_data.Display_ttl();
content_sub = html_data.Content_sub();
sidebar_div = Save_sidebars(tmp_bfr, page, html_data);
}
private static byte[] Save_sidebars(Bry_bfr tmp_bfr, Xoa_page page, Xopg_html_data html_data) {
Xopg_xtn_skin_mgr mgr = html_data.Xtn_skin_mgr();
int len = mgr.Count();
boolean sidebar_exists = false;
for (int i = 0; i < len; ++i) {
Xopg_xtn_skin_itm itm = mgr.Get_at(i);
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
sidebar_exists = true;
itm.Write(tmp_bfr, page);
}
}
return sidebar_exists ? tmp_bfr.Xto_bry_and_clear() : null;
}
} }

View File

@ -16,9 +16,10 @@ 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.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_text_row { public class Xodb_wiki_page_html_row {
public Hdump_text_row(int page_id, int tid, byte[] data) {this.page_id = page_id; this.tid = tid; this.data = data;} public Xodb_wiki_page_html_row(int page_id, int tid, byte[] data) {this.page_id = page_id; this.tid = tid; this.data = data;}
public int Page_id() {return page_id;} private int page_id; public int Page_id() {return page_id;} private final int page_id;
public int Tid() {return tid;} private int tid; public int Tid() {return tid;} private final int tid;
public byte[] Data() {return data;} private byte[] data; public byte[] Data() {return data;} private final byte[] data;
public static final int Tid_page = 0, Tid_data = 1; // SERIALIZED
} }

View File

@ -17,45 +17,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*;
public class Hdump_text_tbl { public class Xodb_wiki_page_html_tbl {
public static final String Tbl_name = "html_text", Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_data = "text_data"; private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
private Xodb_mgr db_mgr; private Io_stream_zip_mgr zip_mgr;
private Db_stmt stmt_select, stmt_insert, stmt_delete; private Db_stmt stmt_select, stmt_insert, stmt_delete;
public void Init_by_wiki(Xow_wiki wiki) {this.db_mgr = wiki.Db_mgr(); this.zip_mgr = wiki.App().Zip_mgr();} public void Init_by_wiki(Xow_wiki wiki) {
public Db_provider Provider() {return provider;} public Hdump_text_tbl Provider_(Db_provider v) {this.Rls_all(); provider = v; return this;} private Db_provider provider; this.zip_mgr = wiki.App().Zip_mgr();
@gplx.Virtual public void Delete_by_page(int page_id) {
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
try {stmt_delete.Clear().Val_int_(page_id).Exec_delete();}
catch (Exception exc) {stmt_delete = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
} }
public byte Zip_tid() {return zip_tid;} public void Zip_tid_(byte v) {zip_tid = v;} private byte zip_tid = Io_stream_.Tid_gzip;
public Db_provider Provider() {return provider;} public Xodb_wiki_page_html_tbl Provider_(Db_provider v) {this.Rls_all(); provider = v; return this;} private Db_provider provider;
@gplx.Virtual public int Insert(int page_id, int tid, byte[] data) { @gplx.Virtual public int Insert(int page_id, int tid, byte[] data) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all); if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds__all);
if (zip_mgr != null) data = zip_mgr.Zip(db_mgr.Data_storage_format(), data);
try { try {
stmt_insert.Clear().Val_int_(page_id).Val_int_(tid).Val_str_by_bry_(data).Exec_insert(); data = zip_mgr.Zip(zip_tid, data);
stmt_insert.Clear().Val_int_(page_id).Val_int_(tid).Val_bry_(data).Exec_insert();
return data.length; return data.length;
} }
catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
} }
private static final String[] Select_by_page_flds = new String[] {Fld_page_id, Fld_text_tid, Fld_text_data}; @gplx.Virtual public void Delete(int page_id) {
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
try {stmt_delete.Clear().Val_int_(page_id).Exec_delete();}
catch (Exception exc) {stmt_delete = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
}
@gplx.Virtual public void Select_by_page(ListAdp rv, int page_id) { @gplx.Virtual public void Select_by_page(ListAdp rv, int page_id) {
if (stmt_select == null) stmt_select = Db_stmt_.new_select_as_rdr(provider, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_page_id), Select_by_page_flds)); if (stmt_select == null) stmt_select = Db_stmt_.new_select_as_rdr(provider, Db_qry__select_in_tbl.new_(Tbl_name, String_.Ary(Fld_page_id), Flds__all));
try { try {
Db_rdr rdr = stmt_select.Clear().Val_int_(page_id).Exec_select_as_rdr(); Db_rdr rdr = stmt_select.Clear().Val_int_(page_id).Exec_select_as_rdr();
while(rdr.Move_next()) { while (rdr.Move_next()) {
byte[] data = rdr.Read_bry(2); Xodb_wiki_page_html_row row = new Xodb_wiki_page_html_row
if (zip_mgr != null) data = zip_mgr.Unzip(db_mgr.Data_storage_format(), data);
Hdump_text_row row = new Hdump_text_row
( rdr.Read_int(0) ( rdr.Read_int(0)
, rdr.Read_int(1) , rdr.Read_int(1)
, data , zip_mgr.Unzip(zip_tid, rdr.Read_bry(2))
); );
rv.Add(row); rv.Add(row);
} }
rdr.Close(); rdr.Close();
} }
catch (Exception exc) {stmt_select = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail catch (Exception exc) {stmt_select = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
finally {if (stmt_select != null) stmt_select.Rls();}
} }
public void Rls_all() { public void Rls_all() {
if (stmt_select != null) {stmt_select.Rls(); stmt_select = null;} if (stmt_select != null) {stmt_select.Rls(); stmt_select = null;}
@ -63,15 +61,16 @@ public class Hdump_text_tbl {
if (stmt_delete != null) {stmt_delete.Rls(); stmt_delete = null;} if (stmt_delete != null) {stmt_delete.Rls(); stmt_delete = null;}
provider = null; provider = null;
} }
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_text_tid, Fld_text_data}; public static final String Tbl_name = "wiki_page_html", Fld_page_id = "page_id", Fld_html_tid = "html_tid", Fld_html_data = "html_data";
private static final String[] Flds__all = new String[] {Fld_page_id, Fld_html_tid, Fld_html_data};
public static final String Tbl_sql = String_.Concat_lines_nl public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS html_text" ( "CREATE TABLE IF NOT EXISTS wiki_page_html"
, "( page_id integer NOT NULL" , "( page_id integer NOT NULL"
, ", text_tid integer NOT NULL" , ", html_tid integer NOT NULL"
, ", text_data mediumblob NOT NULL" , ", html_data blob NOT NULL"
, ");" , ");"
); );
public static final Db_idx_itm public static final Db_idx_itm
Idx_core = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS html_text__core ON html_text (page_id, text_tid);") Idx_core = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS wiki_page_html__core ON wiki_page_html (page_id, html_tid);")
; ;
} }

View File

@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.dbs.*; import gplx.dbs.*;
public class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashAdp_.new_(); public class Xodb_wiki_page_html_tbl_mem extends Xodb_wiki_page_html_tbl { private HashAdp pages = HashAdp_.new_();
@Override public int Insert(int page_id, int tid, byte[] data) { @Override public int Insert(int page_id, int tid, byte[] data) {
Hdump_text_row row = new Hdump_text_row(page_id, tid, data); Xodb_wiki_page_html_row row = new Xodb_wiki_page_html_row(page_id, tid, data);
ListAdp rows = Get_or_new(pages, page_id); ListAdp rows = Get_or_new(pages, page_id);
rows.Add(row); rows.Add(row);
return data.length; return data.length;
@ -28,11 +28,11 @@ public class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages
ListAdp rows = Get_or_new(pages, page_id); ListAdp rows = Get_or_new(pages, page_id);
int len = rows.Count(); int len = rows.Count();
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i); Xodb_wiki_page_html_row row = (Xodb_wiki_page_html_row)rows.FetchAt(i);
rv.Add(row); rv.Add(row);
} }
} }
@Override public void Delete_by_page(int page_id) {pages.Del(page_id);} @Override public void Delete(int page_id) {pages.Del(page_id);}
private static ListAdp Get_or_new(HashAdp pages, int page_id) { private static ListAdp Get_or_new(HashAdp pages, int page_id) {
ListAdp rv = (ListAdp)pages.Fetch(page_id); ListAdp rv = (ListAdp)pages.Fetch(page_id);
if (rv == null) { if (rv == null) {

View File

@ -26,7 +26,7 @@ public class Hdump_html_consts {
public static final byte public static final byte
Tid_dir = 1, Tid_img = 2, Tid_img_style = 3, Tid_file_play = 4, Tid_file_info = 5, Tid_file_mgnf = 6 Tid_dir = 1, Tid_img = 2, Tid_img_style = 3, Tid_file_play = 4, Tid_file_info = 5, Tid_file_mgnf = 6
, Tid_hiero_dir = 7, Tid_gallery_box_max = 8, Tid_gallery_box_w = 9, Tid_gallery_img_w = 10, Tid_gallery_img_pad = 11 , Tid_hiero_dir = 7, Tid_gallery_box_max = 8, Tid_gallery_box_w = 9, Tid_gallery_img_w = 10, Tid_gallery_img_pad = 11
, Tid_redlink = 12 , Tid_redlink = 12, Tid_toc = 13
; ;
public static final byte[] public static final byte[]
Key_dir = Bry_.new_ascii_("~{xowa_dir}") Key_dir = Bry_.new_ascii_("~{xowa_dir}")
@ -41,6 +41,7 @@ public class Hdump_html_consts {
, Key_gallery_img_w = Bry_.new_ascii_("xowa_gly_img_w='") , Key_gallery_img_w = Bry_.new_ascii_("xowa_gly_img_w='")
, Key_gallery_img_pad = Bry_.new_ascii_("xowa_gly_img_pad='") , Key_gallery_img_pad = Bry_.new_ascii_("xowa_gly_img_pad='")
, Key_redlink = Bry_.new_ascii_("xowa_redlink='") , Key_redlink = Bry_.new_ascii_("xowa_redlink='")
, Key_toc = Bry_.new_ascii_("~{xowa_toc}")
; ;
public static final byte[] public static final byte[]
Html_redlink_bgn = Bry_.Add(Bry_.new_ascii_("\" "), Key_redlink) Html_redlink_bgn = Bry_.Add(Bry_.new_ascii_("\" "), Key_redlink)
@ -60,6 +61,7 @@ public class Hdump_html_consts {
trie_itm(rv, Tid_gallery_img_w , Byte_ascii.Apos , Key_gallery_img_w); trie_itm(rv, Tid_gallery_img_w , Byte_ascii.Apos , Key_gallery_img_w);
trie_itm(rv, Tid_gallery_img_pad , Byte_ascii.Apos , Key_gallery_img_pad); trie_itm(rv, Tid_gallery_img_pad , Byte_ascii.Apos , Key_gallery_img_pad);
trie_itm(rv, Tid_redlink , Byte_ascii.Apos , Key_redlink); trie_itm(rv, Tid_redlink , Byte_ascii.Apos , Key_redlink);
trie_itm(rv, Tid_toc , Byte_ascii.Nil , Key_toc);
return rv; return rv;
} }
private static void trie_itm(Btrie_slim_mgr trie, byte tid, byte subst_end_byte, byte[] key_bry) { private static void trie_itm(Btrie_slim_mgr trie, byte tid, byte subst_end_byte, byte[] key_bry) {

View File

@ -0,0 +1,34 @@
/*
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.hdumps.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
class Xoa_hzip_dict {// SERIALIZED
public static final byte Escape = Byte_.int_(255);
public static final byte[] Escape_bry = Bry_.ints_(255);
public static final byte
Tid_a_end = 0
, Tid_lnki_ttl = 1
, Tid_lnki_capt = 2
, Tid_lnke = 3 // <a href="http://xowa.sourceforge.net/blog.html" class="external text" rel="nofollow">blog</a> -> 255,4,h,xowa.sourceforge/blog.html,255,blog,255,0
;
public static final byte[]
Bry_a_end = Bry_.ints_(Escape, Tid_a_end)
, Bry_lnki_ttl = Bry_.ints_(Escape, Tid_lnki_ttl)
, Bry_lnki_capt = Bry_.ints_(Escape, Tid_lnki_capt)
, Bry_lnke = Bry_.ints_(Escape, Tid_lnke) // <a href="http://xowa.sourceforge.net/blog.html" class="external text" rel="nofollow">blog</a> -> 255,4,h,xowa.sourceforge/blog.html,255,blog,255,0
;
}

View File

@ -0,0 +1,110 @@
/*
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.hdumps.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.html.*;
public class Xoa_hzip_itm__lnki {
private Xoa_hzip_mgr hzip_mgr; private Xow_wiki wiki;
public Xoa_hzip_itm__lnki(Xoa_hzip_mgr hzip_mgr, Xow_wiki wiki) {this.hzip_mgr = hzip_mgr; this.wiki = wiki;}
public int Save(Bry_bfr bfr, byte[] src, int src_len, int bgn, int pos) {
int xtid_bgn = pos + Find_xtid_len; if (!Bry_.Match(src, pos, xtid_bgn, Find_xtid_bry)) return Xoa_hzip_mgr.Unhandled; // next atr should be "xtid='"
int xtid_end = Bry_finder.Find_fwd(src, Byte_ascii.Apos, xtid_bgn); if (xtid_end == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.xtid_end_missing", bgn, xtid_bgn);
Object xtid_obj = Xtids.Get_by_mid(src, xtid_bgn, xtid_end); if (xtid_obj == null) return hzip_mgr.Warn_by_pos("a.xtid_invalid", xtid_bgn, xtid_end);
byte xtid = ((Byte_obj_val)xtid_obj).Val();
switch (xtid) {
case Xtid_ttl_int: return Save_basic(bfr, src, src_len, bgn, xtid_end, Bool_.N);
case Xtid_capt_int: return Save_basic(bfr, src, src_len, bgn, xtid_end, Bool_.Y);
default: return hzip_mgr.Warn_by_pos("a.xtid_unknown", xtid_bgn, xtid_end);
}
}
private int Save_basic(Bry_bfr bfr, byte[] src, int src_len, int bgn, int pos, boolean caption) {
int ttl_bgn = Bry_finder.Find_fwd(src, Find_href_bry, pos, src_len); if (ttl_bgn == Bry_finder.Not_found) return Xoa_hzip_mgr.Unhandled;//hzip_mgr.Warn_by_pos_add_dflt("a.ttl_bgn_missing", bgn, pos);
ttl_bgn += Find_href_len;
int ttl_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, ttl_bgn , src_len); if (ttl_end == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.ttl_end_missing", bgn, ttl_bgn);
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.Mid(src, ttl_bgn, ttl_end)); if (ttl == null) return hzip_mgr.Warn_by_pos("a.ttl_invalid", ttl_bgn, ttl_end);
int a_lhs_end = Bry_finder.Find_fwd(src, Byte_ascii.Gt, ttl_end, src_len); if (a_lhs_end == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.a_lhs_end_missing", bgn, ttl_end);
++a_lhs_end; // skip >
int a_rhs_bgn = Bry_finder.Find_fwd(src, Find_a_rhs_bgn_bry, a_lhs_end, src_len); if (a_rhs_bgn == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.a_rhs_bgn_missing", bgn, ttl_end);
if (caption)
bfr.Add(Xoa_hzip_dict.Bry_lnki_capt);
else
bfr.Add(Xoa_hzip_dict.Bry_lnki_ttl);
bfr.Add_byte((byte)ttl.Ns().Ord()); // ASSUME:NS_MAX_255
if (caption)
bfr.Add(ttl.Page_db());
else {
int capt_len = a_rhs_bgn - a_lhs_end;
int ttl_len = ttl_end - ttl_bgn;
if (capt_len == ttl_len && Bry_.Match(src, ttl_bgn, ttl_end, src, a_lhs_end, a_rhs_bgn))
bfr.Add(ttl.Page_db());
else
bfr.Add_mid(src, a_lhs_end, a_rhs_bgn);
}
bfr.Add_byte(Xoa_hzip_dict.Escape);
if (caption) {
bfr.Add_mid(src, a_lhs_end, a_rhs_bgn);
bfr.Add(Xoa_hzip_dict.Bry_a_end);
}
return a_rhs_bgn + Find_a_rhs_bgn_len;
}
public int Load_ttl(Bry_bfr bfr, byte[] src, int src_len, int bgn, byte tid) {
byte ns_ord = src[bgn];
Xow_ns ns = wiki.Ns_mgr().Ords_get_at(ns_ord);
int ttl_bgn = bgn + 1;
int ttl_end = Bry_finder.Find_fwd(src, Xoa_hzip_dict.Escape, ttl_bgn, src_len); if (ttl_end == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.ttl_end_missing", bgn, ttl_bgn);
byte[] ttl_bry = Bry_.Mid(src, ttl_bgn, ttl_end);
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ns.Id(), ttl_bry);
bfr.Add_str("<a href='/wiki/").Add(ttl.Full_db()).Add_str("' title='");
int rv = ttl_end + 1;
if (tid == Xoa_hzip_dict.Tid_lnki_ttl) {
if (ns.Id() != 0) ttl_bry = ttl.Full_db();
bfr.Add(Html_utl.Escape_html_as_bry(ttl_bry)).Add_str("'>").Add(ttl_bry);
}
else {
int capt_end = Bry_finder.Find_fwd(src, Xoa_hzip_dict.Bry_a_end, rv, src_len); if (capt_end == Bry_finder.Not_found) return hzip_mgr.Warn_by_pos_add_dflt("a.capt_end_missing", bgn, rv);
ttl_bry = Bry_.Mid(src, rv, capt_end);
bfr.Add(Html_utl.Escape_html_as_bry(ttl_bry)).Add_str("'>").Add(ttl_bry);
rv = capt_end + Xoa_hzip_dict.Bry_a_end.length;
}
bfr.Add_str("</a>");
return rv;
}
public void Html(Bry_bfr bfr, boolean caption) {bfr.Add(caption ? Html_capt : Html_ttl);}
private static final byte[] Html_ttl = Bry_.new_ascii_("<a xtid='a_ttl' href=\""), Html_capt = Bry_.new_ascii_("<a xtid='a_capt' href=\"");
private static final byte[]
Find_xtid_bry = Bry_.new_ascii_("xtid='")
, Find_href_bry = Bry_.new_ascii_("href=\"/wiki/")
, Find_a_rhs_bgn_bry = Bry_.new_ascii_("</a>")
;
private static final int
Find_xtid_len = Find_xtid_bry.length
, Find_href_len = Find_href_bry.length
, Find_a_rhs_bgn_len = Find_a_rhs_bgn_bry.length
;
private static final byte[]
Xtid_ttl_bry = Bry_.new_ascii_("a_ttl")
, Xtid_capt_bry = Bry_.new_ascii_("a_capt")
;
private static final byte
Xtid_ttl_int = 0
, Xtid_capt_int = 1
;
private static final Hash_adp_bry Xtids = Hash_adp_bry.cs_()
.Add_bry_byte(Xtid_ttl_bry , Xtid_ttl_int)
.Add_bry_byte(Xtid_capt_bry , Xtid_capt_int)
;
}

View File

@ -0,0 +1,118 @@
/*
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.hdumps.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import org.junit.*; import gplx.xowa.html.*;
public class Xoa_hzip_itm__lnki_tst {
@Before public void init() {fxt.Clear();} private Xoa_hzip_itm__lnki_fxt fxt = new Xoa_hzip_itm__lnki_fxt();
@Test public void Srl_ttl() {
byte[][] brys = Bry_.Ary(Xoa_hzip_dict.Bry_lnki_ttl, Bry_.ints_(2), Bry_.new_ascii_("A"), Xoa_hzip_dict.Escape_bry);
fxt.Test_save(brys, "<a xtid='a_ttl' href=\"/wiki/A\" id='xowa_lnki_0' title='A'>A</a>");
fxt.Test_load(brys, "<a href='/wiki/A' title='A'>A</a>");
}
@Test public void Srl_ttl_alt_case() {
byte[][] brys = Bry_.Ary(Xoa_hzip_dict.Bry_lnki_ttl, Bry_.ints_(2), Bry_.new_ascii_("a"), Xoa_hzip_dict.Escape_bry);
fxt.Test_save(brys, "<a xtid='a_ttl' href=\"/wiki/A\" id='xowa_lnki_0' title='A'>a</a>");
fxt.Test_load(brys, "<a href='/wiki/A' title='a'>a</a>");
}
@Test public void Srl_ttl_ns() {
byte[][] brys = Bry_.Ary(Xoa_hzip_dict.Bry_lnki_ttl, Bry_.ints_(12), Bry_.new_ascii_("A"), Xoa_hzip_dict.Escape_bry);
fxt.Test_save(brys, "<a xtid='a_ttl' href=\"/wiki/Template:A\" id='xowa_lnki_0' title='Template:A'>Template:A</a>");
fxt.Test_load(brys, "<a href='/wiki/Template:A' title='Template:A'>Template:A</a>");
}
@Test public void Srl_ttl_smoke() {
byte[][] brys = Bry_.Ary(Bry_.new_ascii_("a_1"), Xoa_hzip_dict.Bry_lnki_ttl, Bry_.ints_(2), Bry_.new_ascii_("A"), Xoa_hzip_dict.Escape_bry, Bry_.new_ascii_("a_2"));
fxt.Test_save(brys, "a_1<a xtid='a_ttl' href=\"/wiki/A\" id='xowa_lnki_0' title='A'>A</a>a_2");
fxt.Test_load(brys, "a_1<a href='/wiki/A' title='A'>A</a>a_2");
}
@Test public void Srl_capt() {
byte[][] brys = Bry_.Ary(Xoa_hzip_dict.Bry_lnki_capt, Bry_.ints_(2), Bry_.new_ascii_("A"), Xoa_hzip_dict.Escape_bry, Bry_.new_ascii_("A1"), Xoa_hzip_dict.Bry_a_end);
fxt.Test_save(brys, "<a xtid='a_capt' href=\"/wiki/A\" id='xowa_lnki_0' title='A'>A1</a>");
fxt.Test_load(brys, "<a href='/wiki/A' title='A1'>A1</a>");
}
@Test public void Srl_noop() {
fxt.Test_save("<a href='/wiki/A'>A</a>", Bry_.new_utf8_("<a href='/wiki/A'>A</a>"));
}
@Test public void Html_ttl() {
fxt.Test_html("[[A]]", "<a xtid='a_ttl' href=\"/wiki/A\" xowa_redlink='1'>A</a>");
}
@Test public void Html_capt() {
fxt.Test_html("[[A|a]]", "<a xtid='a_capt' href=\"/wiki/A\" xowa_redlink='1'>a</a>");
}
}
class Xoa_hzip_itm__lnki_fxt {
private Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_mb); private Xoa_hzip_mgr hzip_mgr; private Xow_wiki wiki;
public void Clear() {
if (hzip_mgr == null) {
Xoa_app app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
hzip_mgr = new Xoa_hzip_mgr(Gfo_usr_dlg_._, wiki);
}
}
public void Test_save(byte[][] expd_brys, String html) {Test_save(html, expd_brys);}
public void Test_save(String html, byte[]... expd_brys) {
byte[] expd = Bry_.Add(expd_brys);
hzip_mgr.Save(bfr, Bry_.Empty, Bry_.new_utf8_(html));
Tfds.Eq_ary(expd, bfr.Xto_bry_and_clear());
}
public void Test_load(byte[][] src_brys, String expd) {
byte[] src = Bry_.Add(src_brys);
hzip_mgr.Load(bfr, Bry_.Empty, src);
Tfds.Eq_ary(Bry_.new_utf8_(expd), bfr.Xto_bry_and_clear());
}
public void Test_html(String html, String expd) {
Xop_ctx ctx = wiki.Ctx(); Xop_parser parser = wiki.Parser(); Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
ctx.Para().Enabled_n_();
ctx.Cur_page().Lnki_redlinks_mgr().Clear();
byte[] html_bry = Bry_.new_utf8_(html);
Xop_root_tkn root = ctx.Tkn_mkr().Root(html_bry);
parser.Parse_page_all_clear(root, ctx, tkn_mkr, html_bry);
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump;
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
html_wtr.Write_all(bfr, ctx, hctx, html_bry, root);
Tfds.Eq(expd, bfr.Xto_str_and_clear());
}
}
class Xoa_hzip_itm__href {
// <a href="/wiki/File:The_Earth_seen_from_Apollo_17.jpg" class="image" xowa_title="The Earth seen from Apollo 17.jpg">
// <a href="/site/simple.wikipedia.org/wiki/Template:Solar_System?action=edit"><span title="Edit this template" style="">e</span></a> // xwiki [[simple:xx
// <a href="http://planetarynames.wr.usgs.gov/jsp/append5.jsp" class="external text" rel="nofollow">"Descriptor Terms (Feature Types)"</a>
// 255,5,
public static final byte
Tid_proto_none = 0
, Tid_proto_http = 1
, Tid_proto_https = 2
, Tid_proto_other = 3
;
public static final byte
Tid_domain_com = 0
, Tid_domain_org = 1
, Tid_domain_net = 2
, Tid_domain_gov = 3
, Tid_domain_other = 4
;
public static final byte
Tid_ext_none = 0
, Tid_ext_htm = 1
, Tid_ext_html = 2
, Tid_ext_php = 3
, Tid_ext_jsp = 4
, Tid_ext_asp = 5
, Tid_ext_aspx = 6
, Tid_ext_other = 7
;
}

View File

@ -0,0 +1,93 @@
/*
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.hdumps.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.btries.*;
public class Xoa_hzip_mgr {
private Gfo_usr_dlg usr_dlg;
private byte[] page_url; private byte[] src; private int src_len;
public Xoa_hzip_mgr(Gfo_usr_dlg usr_dlg, Xow_wiki wiki) {
this.usr_dlg = usr_dlg;
itm__lnki = new Xoa_hzip_itm__lnki(this, wiki);
}
public Xoa_hzip_itm__lnki Itm__lnki() {return itm__lnki;} private Xoa_hzip_itm__lnki itm__lnki;
public void Save(Bry_bfr bfr, byte[] page_url, byte[] src) {
this.page_url = page_url; this.src = src;
this.src_len = src.length;
int pos = 0, add_bgn = -1;
bfr.Clear();
while (pos < src_len) {
byte b = src[pos];
Object o = save_trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) {
if (add_bgn == -1) add_bgn = pos;
++pos;
}
else {
if (add_bgn != -1) {bfr.Add_mid(src, add_bgn, pos); add_bgn = -1;}
byte tid = ((Byte_obj_val)o).Val();
int match_bgn = pos;
int match_end = save_trie.Match_pos();
switch (tid) {
case Tid_a: pos = itm__lnki.Save(bfr, src, src_len, match_bgn, match_end); break;
default: Warn_by_pos("save.tid.unknown", match_bgn, match_end); pos = match_end; continue;
}
if (pos == Unhandled) {
bfr.Add_mid(src, match_bgn, match_end);
pos = match_end;
}
}
}
if (add_bgn != -1) bfr.Add_mid(src, add_bgn, src_len);
}
public void Load(Bry_bfr bfr, byte[] page_url, byte[] src) {
this.page_url = page_url; this.src = src;
this.src_len = src.length;
int pos = 0, add_bgn = -1;
bfr.Clear();
while (pos < src_len) {
byte b = src[pos];
if (b == Xoa_hzip_dict.Escape) {
if (add_bgn != -1) {bfr.Add_mid(src, add_bgn, pos); add_bgn = -1;}
int itm_pos = pos + 2; if (itm_pos >= src_len) {Warn_by_pos("load.eos", pos, itm_pos); break;}
int tid_pos = pos + 1;
byte tid = src[tid_pos];
switch (tid) {
case Xoa_hzip_dict.Tid_lnki_ttl :
case Xoa_hzip_dict.Tid_lnki_capt: pos = itm__lnki.Load_ttl(bfr, src, src_len, itm_pos, tid); break;
}
}
else {
if (add_bgn == -1) add_bgn = pos;
++pos;
}
}
if (add_bgn != -1) bfr.Add_mid(src, add_bgn, src_len);
}
public int Warn_by_pos_add_dflt(String err, int bgn, int end) {return Warn_by_pos(err, bgn, end, 32);}
public int Warn_by_pos(String err, int bgn, int end) {return Warn_by_pos(err, bgn, end, 0);}
private int Warn_by_pos(String err, int bgn, int end, int end_adj) {
end += end_adj; if (end > src_len) end = src_len;
usr_dlg.Warn_many("", "", "hzip failed: page=~{0} err=~{1} mid=~{2}", String_.new_utf8_(page_url), err, String_.new_utf8_(src, bgn, end));
return bgn;
}
public static final int Unhandled = -1;
private static final byte Tid_a = 0;
private Btrie_slim_mgr save_trie = Btrie_slim_mgr.cs_()
.Add_str_byte("<a ", Tid_a)
;
}

View File

@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*;
import gplx.xowa.dbs.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.skins.*; import gplx.xowa.dbs.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.skins.*; import gplx.xowa.hdumps.srls.*;
public class Hdump_load_mgr { public class Hdump_load_mgr {
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private Bry_rdr rdr = new Bry_rdr(); // private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr(); private Xodb_wiki_page_html_tbl text_tbl = new Xodb_wiki_page_html_tbl(); private Bry_rdr rdr = new Bry_rdr();
private ListAdp tmp_rows = ListAdp_.new_(), img_itms = ListAdp_.new_(); private ListAdp tmp_rows = ListAdp_.new_(), img_itms = ListAdp_.new_();
public Hdump_load_mgr() {} public Hdump_load_mgr() {}
public byte Zip_tid() {return zip_tid;} public void Zip_tid_(byte v) {zip_tid = v;} private byte zip_tid = gplx.ios.Io_stream_.Tid_file; public void Zip_tid_(byte v) {text_tbl.Zip_tid_(v);}
public void Load2(Hdump_page hpg, Db_provider provider, int page_id, Xoa_ttl page_ttl) { public void Load2(Hdump_page hpg, Db_provider provider, int page_id, Xoa_ttl page_ttl) {
text_tbl.Provider_(provider).Select_by_page(tmp_rows, page_id); text_tbl.Provider_(provider).Select_by_page(tmp_rows, page_id);
Load_rows(hpg, page_id, Xoa_url.blank_(), page_ttl, tmp_rows); Load_rows(hpg, page_id, Xoa_url.blank_(), page_ttl, tmp_rows);
@ -37,15 +37,15 @@ public class Hdump_load_mgr {
img_itms.Clear(); img_itms.Clear();
int len = rows.Count(); int len = rows.Count();
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i); Xodb_wiki_page_html_row row = (Xodb_wiki_page_html_row)rows.FetchAt(i);
switch (row.Tid()) { switch (row.Tid()) {
case Hdump_text_row_tid.Tid_body: Hdump_page_body_srl.Load(hpg, rdr, row.Data()); break; case Xodb_wiki_page_html_row.Tid_page: srl_mgr.Load(hpg, row.Data()); break;
case Hdump_text_row_tid.Tid_data: Load_data(hpg, row); break; case Xodb_wiki_page_html_row.Tid_data: Load_data(hpg, row); break;
} }
} }
rows.Clear(); rows.Clear();
} } private Hpg_srl_mgr srl_mgr = Hpg_srl_mgr._i_;
public void Load_data(Hdump_page hpg, Hdump_text_row row) { public void Load_data(Hdump_page hpg, Xodb_wiki_page_html_row row) {
rdr.Src_(row.Data()); rdr.Src_(row.Data());
while (!rdr.Pos_is_eos()) { while (!rdr.Pos_is_eos()) {
int tid = rdr.Read_int_to_pipe(); int tid = rdr.Read_int_to_pipe();

View File

@ -19,19 +19,19 @@ package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.x
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.dbs.*; import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.dbs.*;
public class Hdump_load_mgr_tst { public class Hdump_load_mgr_tst {
@Before public void init() {fxt.Clear();} private Hdump_load_mgr_fxt fxt = new Hdump_load_mgr_fxt(); @Before public void init() {fxt.Clear();} private Hdump_load_mgr_fxt fxt = new Hdump_load_mgr_fxt();
@Test public void Body() { // @Test public void Body() {
fxt.Init_row_body("<body/>", null, null, null); // fxt.Init_row_body("<body/>", null, null, null);
fxt.Expd_body("<body/>"); // fxt.Expd_body("<body/>");
fxt.Test_load(0); // fxt.Test_load(0);
} // }
@Test public void Body_all() { // @Test public void Body_all() {
fxt.Init_row_body("<body/>", "test_display_ttl", "test_content_sub", "test_sidebar_div"); // fxt.Init_row_body("<body/>", "test_display_ttl", "test_content_sub", "test_sidebar_div");
fxt.Expd_body("<body/>"); // fxt.Expd_body("<body/>");
fxt.Expd_display_ttl("test_display_ttl"); // fxt.Expd_display_ttl("test_display_ttl");
fxt.Expd_content_sub("test_content_sub"); // fxt.Expd_content_sub("test_content_sub");
fxt.Expd_sidebar_div("test_sidebar_div"); // fxt.Expd_sidebar_div("test_sidebar_div");
fxt.Test_load(0); // fxt.Test_load(0);
} // }
@Test public void Img() { @Test public void Img() {
fxt.Init_row_img fxt.Init_row_img
( fxt.Make_img("A.png", 0, 220, 110) ( fxt.Make_img("A.png", 0, 220, 110)
@ -65,7 +65,7 @@ class Hdump_load_mgr_fxt {
Bry_bfr bfr = Bry_bfr.new_(255); Bry_bfr bfr = Bry_bfr.new_(255);
tmp_list.AddMany((Object[])itms); tmp_list.AddMany((Object[])itms);
byte[] imgs_bry = Hdump_save_mgr.Write_imgs(bfr, tmp_list); byte[] imgs_bry = Hdump_save_mgr.Write_imgs(bfr, tmp_list);
init_rows.Add(new Hdump_text_row(0, Hdump_text_row_tid.Tid_data, imgs_bry)); init_rows.Add(new Xodb_wiki_page_html_row(0, Xodb_wiki_page_html_row.Tid_data, imgs_bry));
} }
public Hdump_load_mgr_fxt Init_row_body(String body, String display_ttl, String content_sub, String sidebar_div) { public Hdump_load_mgr_fxt Init_row_body(String body, String display_ttl, String content_sub, String sidebar_div) {
Bry_bfr tmp_bfr = Bry_bfr.reset_(255); Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
@ -77,10 +77,10 @@ class Hdump_load_mgr_fxt {
if (sidebar_div != null) page.Html_data().Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_mock(Bry_.new_utf8_(sidebar_div))); if (sidebar_div != null) page.Html_data().Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_mock(Bry_.new_utf8_(sidebar_div)));
page.Hdump_data().Body_(Bry_.new_utf8_(body)); page.Hdump_data().Body_(Bry_.new_utf8_(body));
Hdump_page_body_srl.Save(tmp_bfr, page); Hdump_page_body_srl.Save(tmp_bfr, page);
init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, tmp_bfr.Xto_bry_and_clear())); init_rows.Add(new Xodb_wiki_page_html_row(page_id, Xodb_wiki_page_html_row.Tid_page, tmp_bfr.Xto_bry_and_clear()));
return this; return this;
} }
public Hdump_load_mgr_fxt Init_row_img (String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_data, Bry_.new_utf8_(data))); return this;} public Hdump_load_mgr_fxt Init_row_img (String data) {init_rows.Add(new Xodb_wiki_page_html_row(page_id, Xodb_wiki_page_html_row.Tid_data, Bry_.new_utf8_(data))); return this;}
public Hdump_load_mgr_fxt Expd_body(String v) {this.expd_body = v; return this;} public Hdump_load_mgr_fxt Expd_body(String v) {this.expd_body = v; return this;}
public Hdump_load_mgr_fxt Expd_display_ttl(String v) {this.expd_display_ttl = v; return this;} public Hdump_load_mgr_fxt Expd_display_ttl(String v) {this.expd_display_ttl = v; return this;}
public Hdump_load_mgr_fxt Expd_content_sub(String v) {this.expd_content_sub = v; return this;} public Hdump_load_mgr_fxt Expd_content_sub(String v) {this.expd_content_sub = v; return this;}

View File

@ -28,7 +28,7 @@ public class Hdump_page_body_srl {
Save_html_modules(bfr, html_data); Save_html_modules(bfr, html_data);
Save_data(bfr, Tid_display_ttl , html_data.Display_ttl()); Save_data(bfr, Tid_display_ttl , html_data.Display_ttl());
Save_data(bfr, Tid_content_sub , html_data.Content_sub()); Save_data(bfr, Tid_content_sub , html_data.Content_sub());
Save_sidebars(bfr, page, html_data); Save_sidebars(bfr, page , html_data);
Save_data(bfr, Tid_body , hdump_data.Body()); Save_data(bfr, Tid_body , hdump_data.Body());
} }
private static void Save_html_modules(Bry_bfr bfr, Xopg_html_data html_data) { private static void Save_html_modules(Bry_bfr bfr, Xopg_html_data html_data) {
@ -106,7 +106,7 @@ public class Hdump_page_body_srl {
hpg.Version_id_(rdr.Read_int_to_pipe()); hpg.Version_id_(rdr.Read_int_to_pipe());
hpg.Img_count_(rdr.Read_int_to_nl()); hpg.Img_count_(rdr.Read_int_to_nl());
} }
private static final int private static final int // SERIALIZED
Tid_html_module = 1 Tid_html_module = 1
, Tid_display_ttl = 2 , Tid_display_ttl = 2
, Tid_content_sub = 3 , Tid_content_sub = 3

View File

@ -16,16 +16,17 @@ 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.hdumps.saves; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; package gplx.xowa.hdumps.saves; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.srls.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*; import gplx.xowa.hdumps.loads.*;
public class Hdump_save_mgr { public class Hdump_save_mgr {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb); private Bry_bfr tmp_bfr = Bry_bfr.reset_(1 * Io_mgr.Len_mb);
public Hdump_text_tbl Tbl() {return text_tbl;} public void Tbl_(Hdump_text_tbl v) {text_tbl = v;} private Hdump_text_tbl text_tbl; public Xodb_wiki_page_html_tbl Tbl() {return text_tbl;} public void Tbl_(Xodb_wiki_page_html_tbl v) {text_tbl = v;} private Xodb_wiki_page_html_tbl text_tbl;
public void Update(Xoa_page page) { public void Update(Xoa_page page) {
int page_id = page.Revision_data().Id(); int page_id = page.Revision_data().Id();
text_tbl.Delete_by_page(page_id); text_tbl.Delete(page_id);
this.Insert(page); this.Insert(page);
} }
public void Hdump_stats_enable_y_(Db_provider p) {hdump_stats_tbl = new Hdump_stats_tbl().Provider_(p).Create_tbl();} private Hdump_stats_tbl hdump_stats_tbl;
public void Insert(Xoa_page page) { public void Insert(Xoa_page page) {
int page_id = page.Revision_data().Id(); int page_id = page.Revision_data().Id();
Insert_body(page, page_id); Insert_body(page, page_id);
@ -35,10 +36,13 @@ public class Hdump_save_mgr {
if (imgs_bry != null) text_tbl.Insert(page_id, Hdump_data_tid.Tid_img, imgs_bry); if (imgs_bry != null) text_tbl.Insert(page_id, Hdump_data_tid.Tid_img, imgs_bry);
} }
public int Insert_body(Xoa_page page, int page_id) { public int Insert_body(Xoa_page page, int page_id) {
Hdump_page_body_srl.Save(tmp_bfr, page); hpg.Init(tmp_bfr, page);
srl_mgr.Save(hpg, tmp_bfr);
byte[] body_bry = tmp_bfr.Xto_bry_and_clear(); byte[] body_bry = tmp_bfr.Xto_bry_and_clear();
return text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_body, body_bry); int insert_len = text_tbl.Insert(page_id, Xodb_wiki_page_html_row.Tid_page, body_bry);
} if (hdump_stats_tbl != null) hdump_stats_tbl.Insert(hpg, page.Root().Root_src().length, body_bry.length, insert_len);
return insert_len;
} private Hpg_srl_mgr srl_mgr = Hpg_srl_mgr._i_; private Hdump_page hpg = new Hdump_page();
public static byte[] Write_imgs(Bry_bfr bfr, ListAdp imgs) { public static byte[] Write_imgs(Bry_bfr bfr, ListAdp imgs) {
int len = imgs.Count(); if (len == 0) return null; // no images; exit early, else will write blank String int len = imgs.Count(); if (len == 0) return null; // no images; exit early, else will write blank String
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
@ -56,3 +60,53 @@ public class Hdump_save_mgr {
return bfr.Xto_bry_and_clear(); return bfr.Xto_bry_and_clear();
} }
} }
class Hdump_stats_tbl {
private Db_stmt stmt_insert;
public Db_provider Provider() {return provider;} public Hdump_stats_tbl Provider_(Db_provider v) {this.Rls_all(); provider = v; return this;} private Db_provider provider;
public Hdump_stats_tbl Create_tbl() {Sqlite_engine_.Tbl_create_and_delete(provider, Tbl_name, Tbl_sql); return this;}
public void Insert(Hdump_page hpg, int wtxt_len, int row_orig_len, int row_zip_len) {
Hdump_module_mgr js_mgr = hpg.Module_mgr();
Insert
( hpg.Page_id(), wtxt_len, row_orig_len, row_zip_len
, Len_or_0(hpg.Page_body()), Len_or_0(hpg.Display_ttl()), Len_or_0(hpg.Content_sub()), Len_or_0(hpg.Sidebar_div())
, js_mgr.Math_exists(), js_mgr.Imap_exists(), js_mgr.Gallery_packed_exists(), js_mgr.Hiero_exists()
);
}
private int Len_or_0(byte[] bry) {return bry == null ? 0 : bry.length;}
public void Insert(int page_id, int wtxt_len, int row_orig_len, int row_zip_len, int body_len, int display_ttl_len, int content_sub_len, int sidebar_div_len, boolean js_math, boolean js_imap, boolean js_packed, boolean js_hiero) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds__all);
try {
stmt_insert.Clear()
.Val_int_(page_id).Val_int_(wtxt_len).Val_int_(row_orig_len).Val_int_(row_zip_len).Val_int_(body_len).Val_int_(display_ttl_len).Val_int_(content_sub_len).Val_int_(sidebar_div_len)
.Val_byte_by_bool_(js_math).Val_byte_by_bool_(js_imap).Val_byte_by_bool_(js_packed).Val_byte_by_bool_(js_hiero)
.Exec_insert();
}
catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
}
public void Rls_all() {
if (stmt_insert != null) {stmt_insert.Rls(); stmt_insert = null;}
provider = null;
}
public static final String Tbl_name = "hdump_stats"
, Fld_page_id = "page_id", Fld_wtxt_len = "wtxt_len", Fld_row_orig_len = "row_orig_len", Fld_row_zip_len = "row_zip_len"
, Fld_body_len = "body_len", Fld_display_ttl_len = "display_ttl_len", Fld_content_sub_len = "content_sub_len", Fld_sidebar_div_len = "sidebar_div_len"
, Fld_js_math = "js_math", Fld_js_imap = "js_imap", Fld_js_packed = "js_packed", Fld_js_hiero = "js_hiero"
;
private static final String[] Flds__all = new String[] {Fld_page_id, Fld_wtxt_len, Fld_row_orig_len, Fld_row_zip_len, Fld_body_len, Fld_display_ttl_len, Fld_content_sub_len, Fld_sidebar_div_len, Fld_js_math, Fld_js_imap, Fld_js_packed, Fld_js_hiero};
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS hdump_stats"
, "( page_id integer NOT NULL PRIMARY KEY"
, ", wtxt_len integer NOT NULL"
, ", row_orig_len integer NOT NULL"
, ", row_zip_len integer NOT NULL"
, ", body_len integer NOT NULL"
, ", display_ttl_len integer NOT NULL"
, ", content_sub_len integer NOT NULL"
, ", sidebar_div_len integer NOT NULL"
, ", js_math integer NOT NULL"
, ", js_imap integer NOT NULL"
, ", js_packed integer NOT NULL"
, ", js_hiero integer NOT NULL"
, ");"
);
}

View File

@ -0,0 +1,156 @@
/*
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.hdumps.srls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
public interface Hpg_srl_itm {
byte Tid();
int Load(Hdump_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref);
void Save(Hdump_page hpg, Bry_bfr bfr);
}
class Hpg_srl_itm_ {
public static final byte // SERIALIZED
Tid_body = 0
, Tid_html_module = 1
, Tid_display_ttl = 2
, Tid_content_sub = 3
, Tid_sidebar_div = 4
;
public static final Hpg_srl_itm[] Itms = new Hpg_srl_itm[] // NOTE: ary_idx must match tid above
{ new Hpg_srl_itm__body()
, new Hpg_srl_itm__html_module()
, new Hpg_srl_itm__display_ttl()
, new Hpg_srl_itm__content_sub()
, new Hpg_srl_itm__sidebar_div()
};
private static final int Base_255_int = 255;
private static final byte Base_255_byte = (byte)255;
public static void Save_bin_int_abrv(Bry_bfr bfr, int val_int) { // save int in binary little endian form; range from -2,080,766,977 to 2,147,483,648; 255^4 or 4,228,250,625
if (val_int == 0) {bfr.Add_byte(Byte_ascii.Nil); return;}
long val = val_int;
if (val < 0) val = Int_.MaxValue + -val;
int count = 0;
while (val > 0) {
byte mod = (byte)(val % Base_255_int);
int adj = 0;
if (mod == 0) {mod = Base_255_byte; adj = 1;} // if 0, then set byte to 255; also set adj to 1 to properly decrement value
bfr.Add_byte(mod);
++count;
val = (val - adj) / Base_255_int;
}
if (count < 4) bfr.Add_byte(Byte_ascii.Nil);
}
public static int Load_bin_int_abrv(byte[] bry, int bry_len, int bgn, Int_obj_ref count_ref) {
int end = bgn + 4; // read no more than 4 bytes
int count = 0;
long rv = 0; int mult = 1;
for (int i = bgn; i < end; ++i) {
if (i == bry_len) break;
else {
++count;
int b = bry[i] & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
if (b == 0) break;
rv += (b * mult);
mult *= Base_255_int;
}
}
if (rv > Int_.MaxValue) {
rv -= Int_.MaxValue;
rv *= -1;
}
count_ref.Val_(count);
return (int)rv;
}
}
abstract class Hpg_srl_itm__blob_base implements Hpg_srl_itm {
public abstract byte Tid();
public void Save_tid_n_() {save_tid = false;} private boolean save_tid = true;
public void Save(Hdump_page hpg, Bry_bfr bfr) {
byte[] bry = Save_itm(hpg); if (bry == null) return;
int len = bry.length; if (len == 0) return;
if (save_tid) // body won't save tid
bfr.Add_byte(this.Tid());
Hpg_srl_itm_.Save_bin_int_abrv(bfr, len);
bfr.Add(bry);
}
public int Load(Hdump_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref) {
int itm_len = Hpg_srl_itm_.Load_bin_int_abrv(bry, bry_len, itm_bgn, count_ref); if (itm_len == -1) throw Err_.new_("bry_itm has invalid len: page={0} tid={1}", hpg.Page_id(), this.Tid());
int data_bgn = itm_bgn + count_ref.Val();
if (itm_len == 0) return data_bgn;
int data_end = data_bgn + itm_len;
byte[] itm_data = Bry_.Mid(bry, data_bgn, data_end);
this.Load_itm(hpg, itm_data);
return data_end - itm_bgn;
}
public abstract void Load_itm(Hdump_page hpg, byte[] data);
public abstract byte[] Save_itm(Hdump_page hpg);
}
class Hpg_srl_itm__body extends Hpg_srl_itm__blob_base {
public Hpg_srl_itm__body() {this.Save_tid_n_();}
@Override public byte Tid() {return Hpg_srl_itm_.Tid_body;}
@Override public byte[] Save_itm(Hdump_page hpg) {return hpg.Page_body();}
@Override public void Load_itm(Hdump_page hpg, byte[] data) {hpg.Page_body_(data);}
}
class Hpg_srl_itm__display_ttl extends Hpg_srl_itm__blob_base {
@Override public byte Tid() {return Hpg_srl_itm_.Tid_display_ttl;}
@Override public byte[] Save_itm(Hdump_page hpg) {return hpg.Display_ttl();}
@Override public void Load_itm(Hdump_page hpg, byte[] data) {hpg.Display_ttl_(data);}
}
class Hpg_srl_itm__content_sub extends Hpg_srl_itm__blob_base {
@Override public byte Tid() {return Hpg_srl_itm_.Tid_content_sub;}
@Override public byte[] Save_itm(Hdump_page hpg) {return hpg.Content_sub();}
@Override public void Load_itm(Hdump_page hpg, byte[] data) {hpg.Content_sub_(data);}
}
class Hpg_srl_itm__sidebar_div extends Hpg_srl_itm__blob_base {
@Override public byte Tid() {return Hpg_srl_itm_.Tid_sidebar_div;}
@Override public byte[] Save_itm(Hdump_page hpg) {return hpg.Sidebar_div();}
@Override public void Load_itm(Hdump_page hpg, byte[] data) {hpg.Sidebar_div_(data);}
}
class Hpg_srl_itm__html_module implements Hpg_srl_itm {
public byte Tid() {return Hpg_srl_itm_.Tid_html_module;}
public int Load(Hdump_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref) {
itm_bgn += 2; // skip bin_int_abrv of [1, 0]
byte flag = bry[itm_bgn];
hpg.Module_mgr().Init(Enm_.Has_byte(flag, Tid_math), Enm_.Has_byte(flag, Tid_imap), Enm_.Has_byte(flag, Tid_packed), Enm_.Has_byte(flag, Tid_hiero));
return 3;
}
public void Save(Hdump_page hpg, Bry_bfr bfr) {
byte flag = Calc_flag(hpg);
if (flag == 0) return;
bfr.Add_byte(this.Tid());
Hpg_srl_itm_.Save_bin_int_abrv(bfr, 1);
bfr.Add_byte(flag);
}
private static byte Calc_flag(Hdump_page hpg) {
Hdump_module_mgr module_mgr = hpg.Module_mgr();
return Calc_flag(module_mgr.Math_exists(), module_mgr.Imap_exists(), module_mgr.Gallery_packed_exists(), module_mgr.Hiero_exists());
}
public static byte Calc_flag(boolean math, boolean imap, boolean packed, boolean hiero) {
byte rv = 0;
if (math) rv = Enm_.Add_byte(rv, Tid_math);
if (imap) rv = Enm_.Add_byte(rv, Tid_imap);
if (packed) rv = Enm_.Add_byte(rv, Tid_packed);
if (hiero) rv = Enm_.Add_byte(rv, Tid_hiero);
return rv;
}
private static final byte // SERIALIZED; only supports 8 different types
Tid_math = 1
, Tid_imap = 2
, Tid_packed = 4
, Tid_hiero = 8
;
}

View File

@ -0,0 +1,52 @@
/*
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.hdumps.srls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import org.junit.*;
public class Hpg_srl_itm__tst {
@Before public void init() {fxt.Clear();} private Hpg_srl_itm__fxt fxt = new Hpg_srl_itm__fxt();
@Test public void Srl() {
fxt.Test_srl( 0, 0);
fxt.Test_srl( 1, 1, 0);
fxt.Test_srl( 255, 255, 0);
fxt.Test_srl( 256, 1, 1, 0);
fxt.Test_srl( 257, 2, 1, 0);
fxt.Test_srl( 510, 255, 1, 0);
fxt.Test_srl( 511, 1, 2, 0);
fxt.Test_srl( 512, 2, 2, 0);
fxt.Test_srl( 65280, 255, 255, 0);
fxt.Test_srl( 65281, 1, 1, 1, 0);
fxt.Test_srl( 16646655, 255, 255, 255, 0);
fxt.Test_srl( 16646656, 1, 1, 1, 1);
fxt.Test_srl( 16646657, 2, 1, 1, 1);
fxt.Test_srl(Int_.MaxValue, 127, 129, 130, 129);
fxt.Test_srl( -1, 128, 129, 130, 129);
fxt.Test_srl( -2, 129, 129, 130, 129);
}
}
class Hpg_srl_itm__fxt {
private Bry_bfr bfr = Bry_bfr.reset_(8); private Int_obj_ref read = Int_obj_ref.zero_();
public void Clear() {bfr.Clear();}
public void Test_srl(int val, int... bytes) {
Hpg_srl_itm_.Save_bin_int_abrv(bfr, val);
byte[] save = bfr.Xto_bry_and_clear();
Tfds.Eq_ary(Bry_.ints_(bytes), save, "save");
int load = Hpg_srl_itm_.Load_bin_int_abrv(save, save.length, 0, read);
Tfds.Eq(val, load, "load");
Tfds.Eq(bytes.length, read.Val(), "load_read");
}
}

View File

@ -0,0 +1,99 @@
/*
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.hdumps.srls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import org.junit.*; import gplx.xowa.hdumps.core.*;
public class Hpg_srl_itm_tst {
@Before public void init() {fxt.Clear();} private Hpg_srl_itm_fxt fxt = new Hpg_srl_itm_fxt();
@Test public void Body() {
fxt.Test_page(fxt.Make_page().Body_("A"), fxt.Make_srl_body("A"));
}
@Test public void Html_modules() {
fxt.Test_page(fxt.Make_page().Body_("A").Html_modules_(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N), fxt.Make_srl_body("A"), fxt.Make_srl_html_modules(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N));
}
@Test public void Body_all() {
fxt.Test_page(fxt.Make_page().Body_("A").Html_modules_(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N).Display_ttl_("B").Content_sub_("C").Sidebar_div_("D")
, fxt.Make_srl_body("A")
, fxt.Make_srl_html_modules(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N)
, fxt.Make_srl_display_ttl("B")
, fxt.Make_srl_content_sub("C")
, fxt.Make_srl_sidebar_div("D")
);
}
}
class Hpg_srl_itm_fxt {
private Bry_bfr bfr = Bry_bfr.reset_(8);
public void Clear() {bfr.Clear();}
public Hdump_page_mok Make_page() {return new Hdump_page_mok();}
public Hpg_srl_itm_mok Make_srl_body(String s) {return Make_srl(Hpg_srl_itm_.Tid_body, s);}
public Hpg_srl_itm_mok Make_srl_display_ttl(String s) {return Make_srl(Hpg_srl_itm_.Tid_display_ttl, s);}
public Hpg_srl_itm_mok Make_srl_content_sub(String s) {return Make_srl(Hpg_srl_itm_.Tid_content_sub, s);}
public Hpg_srl_itm_mok Make_srl_sidebar_div(String s) {return Make_srl(Hpg_srl_itm_.Tid_sidebar_div, s);}
public Hpg_srl_itm_mok Make_srl(byte tid, String s) {return new Hpg_srl_itm_mok(tid, Bry_.new_utf8_(s));}
public Hpg_srl_itm_mok Make_srl_html_modules(boolean... v) {
return new Hpg_srl_itm_mok(Hpg_srl_itm_.Tid_html_module, new byte[] {Hpg_srl_itm__html_module.Calc_flag(v[0], v[1], v[2], v[3])});
}
public void Test_page(Hdump_page_mok hpg_mok, Hpg_srl_itm_mok... expd_itms) {
Hdump_page hpg = hpg_mok.Xto_hdump_page();
Hpg_srl_mgr._i_.Save(hpg, bfr);
byte[] actl = bfr.Xto_bry_and_clear();
Tfds.Eq_ary(Hpg_srl_itm_mok.Xto_bry(bfr, expd_itms), actl);
Hdump_page actl_hpg = new Hdump_page();
Hpg_srl_mgr._i_.Load(actl_hpg, actl);
Hpg_srl_mgr._i_.Save(hpg, bfr);
Tfds.Eq_ary(actl, bfr.Xto_bry_and_clear());
}
}
class Hdump_page_mok {
public byte[] Body() {return body;} public Hdump_page_mok Body_(String v) {body = Bry_.new_utf8_(v); return this;} private byte[] body;
public boolean[] Html_modules() {return html_modules;} public Hdump_page_mok Html_modules_(boolean... v) {html_modules = v; return this;} private boolean[] html_modules;
public byte[] Display_ttl() {return display_ttl;} public Hdump_page_mok Display_ttl_(String v) {display_ttl = Bry_.new_utf8_(v); return this;} private byte[] display_ttl;
public byte[] Content_sub() {return content_sub;} public Hdump_page_mok Content_sub_(String v) {content_sub = Bry_.new_utf8_(v); return this;} private byte[] content_sub;
public byte[] Sidebar_div() {return sidebar_div;} public Hdump_page_mok Sidebar_div_(String v) {sidebar_div = Bry_.new_utf8_(v); return this;} private byte[] sidebar_div;
public Hdump_page Xto_hdump_page() {
Hdump_page rv = new Hdump_page();
rv.Page_body_(body);
Hdump_module_mgr mod_mgr = rv.Module_mgr();
if (html_modules != null) {
mod_mgr.Math_exists_(html_modules[0]);
mod_mgr.Imap_exists_(html_modules[1]);
mod_mgr.Gallery_packed_exists_(html_modules[2]);
mod_mgr.Hiero_exists_(html_modules[3]);
}
rv.Display_ttl_(display_ttl);
rv.Content_sub_(content_sub);
rv.Sidebar_div_(sidebar_div);
return rv;
}
}
class Hpg_srl_itm_mok {
public Hpg_srl_itm_mok(byte tid, byte[] data) {this.tid = tid; this.data = data;}
public byte Tid() {return tid;} private final byte tid;
public int Len() {return data.length;}
public byte[] Data() {return data;} private final byte[] data;
public static byte[] Xto_bry(Bry_bfr bfr, Hpg_srl_itm_mok[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Hpg_srl_itm_mok itm = ary[i];
if (itm.Tid() != Hpg_srl_itm_.Tid_body)
bfr.Add_byte(itm.Tid());
Hpg_srl_itm_.Save_bin_int_abrv(bfr, itm.Len());
bfr.Add(itm.Data());
}
return bfr.Xto_bry_and_clear();
}
}

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.hdumps.srls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
public class Hpg_srl_mgr {
private Int_obj_ref count_ref = Int_obj_ref.zero_();
public Hpg_srl_mgr(Hpg_srl_itm[] itm_ary) {this.itm_ary = itm_ary;}
public Hpg_srl_itm Itm_body() {return itm_body;} private final Hpg_srl_itm itm_body = new Hpg_srl_itm__body();
public Hpg_srl_itm[] Itm_ary() {return itm_ary;} private final Hpg_srl_itm[] itm_ary;
public void Load(Hdump_page hpg, byte[] bry) {
if (bry == null) return;
int bry_len = bry.length; if (bry_len == 0) return;
int pos = itm_body.Load(hpg, bry, bry_len, 0, count_ref); // assume every page has a body; saves 1 byte by not specifying tid for body
while (pos < bry_len) {
byte itm_tid = bry[pos]; // itm_tid is always 1-byte
Hpg_srl_itm itm_parser = itm_ary[itm_tid]; // itm_tid always matches itm_ary's idx
pos += itm_parser.Load(hpg, bry, bry_len, pos + 1, count_ref) + 1; // +1 to skip tid
}
}
public void Save(Hdump_page hpg, Bry_bfr bfr) {
for (Hpg_srl_itm itm : itm_ary)
itm.Save(hpg, bfr);
}
public static final Hpg_srl_mgr _i_ = new Hpg_srl_mgr(Hpg_srl_itm_.Itms);
}

View File

@ -42,7 +42,7 @@ public class Xoh_html_wtr {
public void Write_all(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_root_tkn root) { public void Write_all(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_root_tkn root) {
try { try {
indent_level = 0; this.page = ctx.Cur_page(); indent_level = 0; this.page = ctx.Cur_page();
page.Xwiki_langs().Clear(); // HACK: always clear langs; necessary for reload page.Slink_list().Clear(); // HACK: always clear langs; necessary for reload
lnki_wtr.Init_by_page(ctx, hctx, src, ctx.Cur_page()); lnki_wtr.Init_by_page(ctx, hctx, src, ctx.Cur_page());
Write_tkn(bfr, ctx, hctx, src, null, -1, root); Write_tkn(bfr, ctx, hctx, src, null, -1, root);
} }
@ -106,7 +106,7 @@ public class Xoh_html_wtr {
@gplx.Virtual public void Hdr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hdr_tkn hdr) { @gplx.Virtual public void Hdr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hdr_tkn hdr) {
// page.Hdrs_id_bld(hdr, src); // page.Hdrs_id_bld(hdr, src);
if (hdr.Hdr_html_first() && cfg.Toc_show() && !page.Hdr_mgr().Toc_manual()) { // __TOC__ not specified; place at top; NOTE: if __TOC__ was specified, then it would be placed wherever __TOC__ appears if (hdr.Hdr_html_first() && cfg.Toc_show() && !page.Hdr_mgr().Toc_manual()) { // __TOC__ not specified; place at top; NOTE: if __TOC__ was specified, then it would be placed wherever __TOC__ appears
wiki.Html_mgr().Toc_mgr().Html(ctx.Cur_page(), src, bfr); wiki.Html_mgr().Toc_mgr().Html(ctx.Cur_page(), hctx, src, bfr);
} }
int hdr_len = hdr.Hdr_len(); int hdr_len = hdr.Hdr_len();
if (hdr_len > 0) { // NOTE: need to check hdr_len b/c it could be dangling if (hdr_len > 0) { // NOTE: need to check hdr_len b/c it could be dangling
@ -289,7 +289,7 @@ public class Xoh_html_wtr {
if (hctx.Mode_is_alt()) return; if (hctx.Mode_is_alt()) return;
switch (under.Under_tid()) { switch (under.Under_tid()) {
case Xol_kwd_grp_.Id_toc: case Xol_kwd_grp_.Id_toc:
wiki.Html_mgr().Toc_mgr().Html(page, src, bfr); wiki.Html_mgr().Toc_mgr().Html(page, hctx, src, bfr);
break; break;
case Xol_kwd_grp_.Id_notoc: case Xol_kwd_grp_.Id_forcetoc: // NOTE: skip output; changes flag on page only case Xol_kwd_grp_.Id_notoc: case Xol_kwd_grp_.Id_forcetoc: // NOTE: skip output; changes flag on page only
break; break;

View File

@ -37,7 +37,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
case Xopg_view_mode.Tid_edit: fmtr = mgr.Page_edit_fmtr(); break; case Xopg_view_mode.Tid_edit: fmtr = mgr.Page_edit_fmtr(); break;
case Xopg_view_mode.Tid_html: fmtr = mgr.Page_read_fmtr(); view_mode = Xopg_view_mode.Tid_read; break; // set view_mode to read, so that "read" is highlighted in HTML case Xopg_view_mode.Tid_html: fmtr = mgr.Page_read_fmtr(); view_mode = Xopg_view_mode.Tid_read; break; // set view_mode to read, so that "read" is highlighted in HTML
case Xopg_view_mode.Tid_read: fmtr = mgr.Page_read_fmtr(); case Xopg_view_mode.Tid_read: fmtr = mgr.Page_read_fmtr();
ctx.Cur_page().Lnki_redlinks_mgr().Page_bgn(); // not sure if this is the best place to put it, but redlinks (a) must only fire once; (b) must fire before html generation; (c) cannot fire during edit (preview will handle separately) ctx.Cur_page().Lnki_redlinks_mgr().Clear(); // not sure if this is the best place to put it, but redlinks (a) must only fire once; (b) must fire before html generation; (c) cannot fire during edit (preview will handle separately)
break; break;
} }
Write_page(html_bfr, app, wiki, mgr, page, view_mode, fmtr, this); Write_page(html_bfr, app, wiki, mgr, page, view_mode, fmtr, this);

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.html.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.users.history.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.xtns.relatedSites.*; import gplx.html.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.users.history.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.xtns.relatedSites.*;
import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.hdumps.hzips.*;
public class Xoh_lnki_wtr { public class Xoh_lnki_wtr {
private Xoa_app app; private Xow_wiki wiki; private Xoa_page page; private Xop_ctx ctx; private Xoa_app app; private Xow_wiki wiki; private Xoa_page page; private Xop_ctx ctx;
private Xoh_html_wtr_cfg cfg; private Xoh_html_wtr_cfg cfg;
@ -25,6 +25,7 @@ public class Xoh_lnki_wtr {
private Xop_lnki_caption_wtr_tkn caption_tkn_wtr; private Xop_lnki_caption_wtr_tkn caption_tkn_wtr;
private Xop_lnki_caption_wtr_bry caption_bry_wtr; private Xop_lnki_caption_wtr_bry caption_bry_wtr;
private Xop_lnki_logger_redlinks_mgr redlinks_mgr; private Xop_lnki_logger_redlinks_mgr redlinks_mgr;
private Xoa_hzip_mgr hzip_mgr;
public Xoh_lnki_wtr(Xoh_html_wtr html_wtr, Xow_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr_cfg cfg) { public Xoh_lnki_wtr(Xoh_html_wtr html_wtr, Xow_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr_cfg cfg) {
caption_tkn_wtr = new Xop_lnki_caption_wtr_tkn(html_wtr); caption_tkn_wtr = new Xop_lnki_caption_wtr_tkn(html_wtr);
caption_bry_wtr = new Xop_lnki_caption_wtr_bry(); caption_bry_wtr = new Xop_lnki_caption_wtr_bry();
@ -52,7 +53,8 @@ public class Xoh_lnki_wtr {
&& xwiki_lang.Type_is_xwiki_lang(wiki.Domain_itm().Lang_orig_uid())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10 && xwiki_lang.Type_is_xwiki_lang(wiki.Domain_itm().Lang_orig_uid())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10
&& !lnki_ttl.ForceLiteralLink() // not literal; [[:en:A]] && !lnki_ttl.ForceLiteralLink() // not literal; [[:en:A]]
) { ) {
page.Xwiki_langs().Add(lnki_ttl); Wdata_sitelink_itm slink = new Wdata_sitelink_itm(null, null, null).Page_ttl_(lnki_ttl);
page.Slink_list().Add(slink);
return; return;
} }
boolean literal_link = lnki_ttl.ForceLiteralLink(); // NOTE: if literal link, then override ns behavior; for File, do not show image; for Ctg, do not display at bottom of page boolean literal_link = lnki_ttl.ForceLiteralLink(); // NOTE: if literal link, then override ns behavior; for File, do not show image; for Ctg, do not display at bottom of page
@ -95,6 +97,11 @@ public class Xoh_lnki_wtr {
if (hctx.Mode_is_alt()) if (hctx.Mode_is_alt())
Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr); Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr);
else { else {
if (hctx.Mode_is_hdump()) {
if (hzip_mgr == null) hzip_mgr = new Xoa_hzip_mgr(wiki.App().Usr_dlg(), wiki);
hzip_mgr.Itm__lnki().Html(bfr, lnki.Caption_exists());
}
else
bfr.Add(Xoh_consts.A_bgn); // '<a href="' bfr.Add(Xoh_consts.A_bgn); // '<a href="'
app.Href_parser().Build_to_bfr(bfr, wiki, lnki_ttl, hctx.Mode_is_popup()); // '/wiki/A' app.Href_parser().Build_to_bfr(bfr, wiki, lnki_ttl, hctx.Mode_is_popup()); // '/wiki/A'
if (cfg.Lnki_id()) { if (cfg.Lnki_id()) {

View File

@ -186,7 +186,7 @@ public class Xow_toc_mgr implements Bry_fmtr_arg {
} }
} }
} }
public void Html(Xoa_page page, byte[] src, Bry_bfr bfr) { public void Html(Xoa_page page, Xoh_wtr_ctx hctx, byte[] src, Bry_bfr bfr) {
if (!page.Hdr_mgr().Toc_enabled()) return; // REF.MW: Parser.php|formatHeadings if (!page.Hdr_mgr().Toc_enabled()) return; // REF.MW: Parser.php|formatHeadings
this.page = page; this.page = page;
byte[] bry_contents = page.Wiki().Msg_mgr().Val_by_id(Xol_msg_itm_.Id_toc); byte[] bry_contents = page.Wiki().Msg_mgr().Val_by_id(Xol_msg_itm_.Id_toc);

View File

@ -515,7 +515,7 @@ class Xow_toc_mgr_fxt {
byte[] raw_bry = Bry_.new_utf8_(raw); byte[] raw_bry = Bry_.new_utf8_(raw);
Xop_root_tkn root = fxt.Ctx().Tkn_mkr().Root(raw_bry); Xop_root_tkn root = fxt.Ctx().Tkn_mkr().Root(raw_bry);
fxt.Parser().Parse_page_all_clear(root, fxt.Ctx(), fxt.Ctx().Tkn_mkr(), raw_bry); fxt.Parser().Parse_page_all_clear(root, fxt.Ctx(), fxt.Ctx().Tkn_mkr(), raw_bry);
toc_mgr.Html(fxt.Page(), raw_bry, tmp); toc_mgr.Html(fxt.Page(), Xoh_wtr_ctx.Basic, raw_bry, tmp);
Tfds.Eq_ary(String_.SplitLines_nl(expd), String_.SplitLines_nl(tmp.Xto_str_and_clear()), raw); Tfds.Eq_ary(String_.SplitLines_nl(expd), String_.SplitLines_nl(tmp.Xto_str_and_clear()), raw);
} }
public void Test_html_all(String raw, String expd) { public void Test_html_all(String raw, String expd) {

View File

@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.pages; import gplx.*; import gplx.xowa.*;
public class Xopg_revision_data {
public int Id() {return id;} public Xopg_revision_data Id_(int v) {id = v; return this;} private int id;
public DateAdp Modified_on() {return modified_on;} public Xopg_revision_data Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on = DateAdp_.MinValue;
public byte[] User() {return user;} public Xopg_revision_data User_(byte[] v) {user = v; return this;} private byte[] user = Bry_.Empty;
public byte[] Protection_level() {return protection_level;} public Xopg_revision_data Protection_level_(byte[] v) {protection_level = v; return this;} private byte[] protection_level = Bry_.Empty;
public int Html_db_id() {return html_db_id;} public void Html_db_id_(int v) {html_db_id = v;} private int html_db_id = -1;
public void Clear() {}// NOTE: do not clear data b/c saving in Edit will call clear and id will be reset to 0
}

View File

@ -26,7 +26,7 @@ public class Xop_lnki_logger_redlinks_mgr {
public ListAdp Lnki_list() {return lnki_list;} private ListAdp lnki_list = ListAdp_.new_(); public ListAdp Lnki_list() {return lnki_list;} private ListAdp lnki_list = ListAdp_.new_();
public boolean Log_enabled() {return log_enabled;} private boolean log_enabled = false; public boolean Log_enabled() {return log_enabled;} private boolean log_enabled = false;
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} private Gfo_usr_dlg usr_dlg = null; public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} private Gfo_usr_dlg usr_dlg = null;
public void Page_bgn() { public void Clear() {
request_idx++; request_idx++;
Xoa_app app = page.App(); Xoa_app app = page.App();
log_enabled = app.User().Cfg_mgr().Log_mgr().Log_redlinks(); log_enabled = app.User().Cfg_mgr().Log_mgr().Log_redlinks();

View File

@ -105,39 +105,34 @@ class Imap_parser {
Init_link_owner(imap_dflt, src, itm_bgn, itm_end); Init_link_owner(imap_dflt, src, itm_bgn, itm_end);
} }
private boolean Parse_shape(byte shape_tid, int tid_end_pos, int itm_bgn, int itm_end, int reqd_pts) { private boolean Parse_shape(byte shape_tid, int tid_end_pos, int itm_bgn, int itm_end, int reqd_pts) {
int num_bgn = -1; // differs from MW parser which looks for link via regx, and then chops off rest; regx is difficult due to lnke; doing opposite approach which is eat numbers until something else boolean shape_is_poly = shape_tid == Imap_itm_.Tid_shape_poly;
int pos = Bry_finder.Trim_fwd_space_tab(src, tid_end_pos, itm_end); int pos = Bry_finder.Trim_fwd_space_tab(src, tid_end_pos, itm_end); // gobble any leading spaces
boolean reading_numbers = true; int grp_end = Bry_finder.Find_fwd(src, Byte_ascii.Brack_bgn, pos, itm_end); // find first "["; note that this is a lazy way of detecting start of lnki / lnke; MW has complicated regex, but hopefully this will be enough; DATE:2014-10-22
int comma_pos_0 = -1; if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "No valid link was found");}
while (reading_numbers) { int num_bgn = -1, comma_pos = -1;
boolean last = pos == itm_end; while (true) {
boolean last = pos == grp_end;
byte b = last ? Byte_ascii.Space : src[pos]; byte b = last ? Byte_ascii.Space : src[pos];
switch (b) { switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4: case Byte_ascii.Comma: if (comma_pos == -1) comma_pos = pos; break;
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9: default: if (num_bgn == -1) num_bgn = pos; break;
case Byte_ascii.Dash: case Byte_ascii.Dot: case Byte_ascii.Space: case Byte_ascii.Tab:
if (num_bgn == -1) if (num_bgn != -1) {
num_bgn = pos; byte[] num_bry = comma_pos == -1 ? Bry_.Mid(src, num_bgn, pos) : Bry_.Mid(src, num_bgn, comma_pos); // if commas exist, treat first as decimal; echo(intval(round('1,2,3,4' * 1))) -> 1; PAGE:fr.w:Gouesnou; DATE:2014-08-12
++pos; double num = Bry_.Xto_double_or(num_bry, Double_.NaN);
break; if (Double_.IsNaN(num)) {
case Byte_ascii.Comma: if (shape_is_poly) // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"word1"; PAGE:uk.w:Стратосфера; DATE:2014-07-26
if (comma_pos_0 == -1) comma_pos_0 = pos; num = 0;
if (num_bgn == -1)
num_bgn = pos;
++pos;
break;
default:
int new_pos = Parse_shape_num(shape_tid, b, pos, num_bgn, pos, itm_end, comma_pos_0);
if (new_pos == -1) return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_invalid_coord");
if (new_pos == pos) // occurs when char is text
reading_numbers = false;
else else
pos = Bry_finder.Trim_fwd_space_tab(src, new_pos, itm_end); return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_invalid_coord");
num_bgn = -1; }
comma_pos_0 = -1; num_bgn = -1; comma_pos = -1;
pts.Add(Double_obj_val.new_(num));
}
break; break;
} }
if (last) reading_numbers = false; if (last) break;
++pos;
} }
int pts_len = pts.Count(); int pts_len = pts.Count();
if (reqd_pts == Reqd_poly) { if (reqd_pts == Reqd_poly) {
@ -181,33 +176,6 @@ class Imap_parser {
} }
return null; return null;
} }
private int Parse_shape_num(byte shape_tid, byte b, int pos, int num_bgn, int num_end, int itm_end, int comma_pos_0) {
double num = 0;
boolean shape_is_poly = shape_tid == Imap_itm_.Tid_shape_poly;
if (num_bgn == -1) { // 1st char is non-numeric; EX: "poly a"
if ( shape_is_poly // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"poly1"; PAGE:uk.w:Стратосфера; DATE:2014-07-26
&& b != Byte_ascii.Brack_bgn // skip logic if "[" which may be beginning of lnki / lnke
) {
num_end = Bry_finder.Find_fwd_until_space_or_tab(src, pos, itm_end); // gobble up rest of word and search forward for space / tab to
if (num_end == Bry_finder.Not_found) return -1; // space / tab not found; return -1 (fail)
num = 0;
}
else
return num_end;
}
else {
int parse_end = comma_pos_0 == -1 ? num_end : comma_pos_0; // if commas exist, treat first as decimal; echo(intval(round('1,2,3,4' * 1))) -> 1; PAGE:fr.w:Gouesnou; DATE:2014-08-12
num = Bry_.XtoDoubleByPosOr(src, num_bgn, parse_end, Double_.NaN);
}
if (Double_.IsNaN(num)) {
if (shape_is_poly) // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"poly 1a"
num = 0;
else
return -1; // invalid number; EX: "1.2.3"
}
pts.Add(Double_obj_val.new_(num));
return Bry_finder.Trim_fwd_space_tab(src, num_end, itm_end);
}
private int Parse_img(Imap_map imap, int itm_bgn, int itm_end, int src_end) { private int Parse_img(Imap_map imap, int itm_bgn, int itm_end, int src_end) {
int img_bgn = Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end); // trim ws int img_bgn = Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end); // trim ws
int img_end = Parse_img__get_img_end(itm_end, src_end); int img_end = Parse_img__get_img_end(itm_end, src_end);

View File

@ -24,6 +24,7 @@ public class Imap_parser_tst {
@Test public void Circle_pass() {fxt.Test_shape("circle 1 2 3 [[A]]" , fxt.itm_circle_("[[A]]", 1, 2, 3));} @Test public void Circle_pass() {fxt.Test_shape("circle 1 2 3 [[A]]" , fxt.itm_circle_("[[A]]", 1, 2, 3));}
@Test public void Poly_pass() {fxt.Test_shape("poly 1 2 3 4 5 6 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4, 5, 6));} @Test public void Poly_pass() {fxt.Test_shape("poly 1 2 3 4 5 6 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4, 5, 6));}
@Test public void Poly_pass_chars() {fxt.Test_shape("poly a b [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:uk.w:Стратосфера; DATE:2014-07-26 @Test public void Poly_pass_chars() {fxt.Test_shape("poly a b [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:uk.w:Стратосфера; DATE:2014-07-26
@Test public void Poly_pass_chars_2() {fxt.Test_shape("poly 1a 2a [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:ru.w:Системный_блок; DATE:2014-10-22
@Test public void Poly_pass_dots() {fxt.Test_shape("poly 1.2 3.4 [[A]]" , fxt.itm_poly_("[[A]]", 1.2d, 3.4d));} // PURPOSE: make sure decimals are handled correctly @Test public void Poly_pass_dots() {fxt.Test_shape("poly 1.2 3.4 [[A]]" , fxt.itm_poly_("[[A]]", 1.2d, 3.4d));} // PURPOSE: make sure decimals are handled correctly
@Test public void Poly_pass_commas() {fxt.Test_shape("poly 1, 2, 3, 4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4));} // PURPOSE: commas should be ignored; PAGE:de.w:Kaimnitz; DATE:2014-08-05 @Test public void Poly_pass_commas() {fxt.Test_shape("poly 1, 2, 3, 4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4));} // PURPOSE: commas should be ignored; PAGE:de.w:Kaimnitz; DATE:2014-08-05
@Test public void Poly_pass_commas_2() {fxt.Test_shape("poly 1,2 3,4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 3));} // PURPOSE: commas should be ignored for purpose of parse; PAGE:fr.w:Gouesnou; DATE:2014-08-12 @Test public void Poly_pass_commas_2() {fxt.Test_shape("poly 1,2 3,4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 3));} // PURPOSE: commas should be ignored for purpose of parse; PAGE:fr.w:Gouesnou; DATE:2014-08-12

View File

@ -16,14 +16,15 @@ 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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*; package gplx.xowa.xtns.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.pages.*;
public class Pfunc_rev_props extends Pf_func_base { public class Pfunc_rev_props extends Pf_func_base {
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) { @Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] argx = Eval_argx(ctx, src, caller, self); byte[] argx = Eval_argx(ctx, src, caller, self);
Xoa_revision_data revision_data = ctx.Cur_page().Revision_data(); Xopg_revision_data rev_data = ctx.Cur_page().Revision_data();
switch (id) { switch (id) {
case Xol_kwd_grp_.Id_page_id: case Xol_kwd_grp_.Id_page_id:
case Xol_kwd_grp_.Id_rev_id: bfr.Add_int_variable(ctx.Cur_page().Revision_data().Id()); break; // NOTE: making rev_id and page_id interchangeable; XOWA does not store rev_id case Xol_kwd_grp_.Id_rev_id: bfr.Add_int_variable(ctx.Cur_page().Revision_data().Id()); break; // NOTE: making rev_id and page_id interchangeable; XOWA does not store rev_id
case Xol_kwd_grp_.Id_rev_user: bfr.Add(revision_data.User()); break; case Xol_kwd_grp_.Id_rev_user: bfr.Add(rev_data.User()); break;
case Xol_kwd_grp_.Id_rev_pagesize: case Xol_kwd_grp_.Id_rev_pagesize:
if (argx.length > 0) { if (argx.length > 0) {
Xoa_ttl argx_ttl = Xoa_ttl.parse_(ctx.Wiki(), argx); Xoa_ttl argx_ttl = Xoa_ttl.parse_(ctx.Wiki(), argx);
@ -39,7 +40,7 @@ public class Pfunc_rev_props extends Pf_func_base {
} }
bfr.Add_byte(Byte_ascii.Num_0); bfr.Add_byte(Byte_ascii.Num_0);
break; break;
case Xol_kwd_grp_.Id_rev_protectionlevel: bfr.Add(revision_data.Protection_level()); break; case Xol_kwd_grp_.Id_rev_protectionlevel: bfr.Add(rev_data.Protection_level()); break;
default: throw Err_.unhandled(id); default: throw Err_.unhandled(id);
} }
} }

View File

@ -43,10 +43,10 @@ public class Poem_nde implements Xox_xnde {
boolean indent_enabled = false; boolean indent_enabled = false;
if (line_is_1st) line_is_1st = false; if (line_is_1st) line_is_1st = false;
else { else {
if (Bry_.Match(src, line_bgn, line_bgn + Comment_marker.length, Comment_marker)) if (Bry_.Match(src, line_bgn, line_bgn + Xowa_br_mark.length, Xowa_br_mark)) // "<br/>\n" already inserted by XOWA; do not insert again; DATE:2014-10-20
bfr.Add_byte_nl(); bfr.Add_byte_nl();
else else
bfr.Add(Html_tag_.Br_inl).Add_byte_nl().Add(Comment_marker); // add "<br/>\n" unless 1st line; EX: "<poem>\n\s" should not add leading "<br/>\n" bfr.Add(Html_tag_.Br_inl).Add_byte_nl().Add(Xowa_br_mark); // add "<br/>\n" unless 1st line; EX: "<poem>\n\s" should not add leading "<br/>\n"
} }
switch (src[line_bgn]) { switch (src[line_bgn]) {
case Byte_ascii.Space: // "\n\s" -> "\n&#160;" case Byte_ascii.Space: // "\n\s" -> "\n&#160;"
@ -78,6 +78,6 @@ public class Poem_nde implements Xox_xnde {
, Div_poem_end = Bry_.new_ascii_("\n</p>\n</div>") , Div_poem_end = Bry_.new_ascii_("\n</p>\n</div>")
, Indent_bgn = Bry_.new_ascii_("\n<span class='mw-poem-indented' style='display: inline-block; margin-left: ") , Indent_bgn = Bry_.new_ascii_("\n<span class='mw-poem-indented' style='display: inline-block; margin-left: ")
, Indent_end = Bry_.new_ascii_("em;'>") , Indent_end = Bry_.new_ascii_("em;'>")
, Comment_marker = Bry_.new_ascii_("<!--xowa-->") , Xowa_br_mark = Bry_.new_ascii_("<!--xowa.br-->")
; ;
} }

View File

@ -260,7 +260,7 @@ public class Poem_nde_tst {
, "b<br/>" , "b<br/>"
, " <div class=\"poem\">" , " <div class=\"poem\">"
, "<p>" , "<p>"
, "c<br/>" // NOTE: 1 <br/> not 2 , "c<br/>" // NOTE: "<br/>" not "<br/><br/>"
, "d<br/>" , "d<br/>"
, " " , " "
, "</p>" , "</p>"

View File

@ -208,7 +208,8 @@ public class Scrib_core {
|| core_invalidate_when_page_changes // core marked invalidated b/c of error in {{#invoke}} but won't be regen'd until page changes; invalidate now; PAGE:th.d:all; DATE:2014-10-03 || core_invalidate_when_page_changes // core marked invalidated b/c of error in {{#invoke}} but won't be regen'd until page changes; invalidate now; PAGE:th.d:all; DATE:2014-10-03
) { ) {
core_invalidate_when_page_changes = false; core_invalidate_when_page_changes = false;
if (Bry_.Eq(page.Wiki().Domain_bry(), core.Cur_wiki())) // current page is in same wiki as last page if ( core != null // null check
&& Bry_.Eq(page.Wiki().Domain_bry(), core.Cur_wiki())) // current page is in same wiki as last page
core.When_page_changed(page); core.When_page_changed(page);
else // current page is in different wiki else // current page is in different wiki
Core_invalidate(); // invalidate scrib engine; note that lua will cache chunks by Module name and two modules in two different wikis can have the same name, but different data: EX:Module:Citation/CS1/Configuration and enwiki / zhwiki; DATE:2014-03-21 Core_invalidate(); // invalidate scrib engine; note that lua will cache chunks by Module name and two modules in two different wikis can have the same name, but different data: EX:Module:Citation/CS1/Configuration and enwiki / zhwiki; DATE:2014-03-21

View File

@ -97,20 +97,20 @@ class Scrib_lib_wikibase_srl {
KeyVal[] rv = new KeyVal[len]; KeyVal[] rv = new KeyVal[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Wdata_claim_itm_core itm = grp.Get_at(i); Wdata_claim_itm_core itm = grp.Get_at(i);
rv[i] = KeyVal_.int_(i + base_adj, Srl_claims_prop_itm(pid, itm)); // NOTE: must be super 0 or super 1; DATE:2014-05-09 rv[i] = KeyVal_.int_(i + base_adj, Srl_claims_prop_itm(pid, itm, base_adj)); // NOTE: must be super 0 or super 1; DATE:2014-05-09
} }
return rv; return rv;
} }
private static KeyVal[] Srl_claims_prop_itm(String pid, Wdata_claim_itm_core itm) { private static KeyVal[] Srl_claims_prop_itm(String pid, Wdata_claim_itm_core itm, int base_adj) {
ListAdp list = ListAdp_.new_(); ListAdp list = ListAdp_.new_();
list.Add(KeyVal_.new_("id", String_.new_utf8_(itm.Wguid()))); list.Add(KeyVal_.new_("id", pid));
list.Add(KeyVal_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm))); list.Add(KeyVal_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm)));
list.Add(KeyVal_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid()))); list.Add(KeyVal_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid())));
list.Add(KeyVal_.new_("type", itm.Prop_type())); list.Add(KeyVal_.new_("type", itm.Prop_type()));
Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(itm.Qualifiers())); Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(itm.Qualifiers(), base_adj));
return (KeyVal[])list.Xto_ary_and_clear(KeyVal.class); return (KeyVal[])list.Xto_ary_and_clear(KeyVal.class);
} }
private static KeyVal[] Srl_qualifiers(Wdata_claim_grp_list list) { private static KeyVal[] Srl_qualifiers(Wdata_claim_grp_list list, int base_adj) {
if (list == null) return null; if (list == null) return null;
int list_len = list.Len(); if (list_len == 0) return KeyVal_.Ary_empty; int list_len = list.Len(); if (list_len == 0) return KeyVal_.Ary_empty;
ListAdp rv = ListAdp_.new_(); ListAdp rv = ListAdp_.new_();
@ -122,7 +122,7 @@ class Scrib_lib_wikibase_srl {
String itm_pid = grp.Id_str(); String itm_pid = grp.Id_str();
for (int j = 0; j < grp_len; ++j) { for (int j = 0; j < grp_len; ++j) {
Wdata_claim_itm_core itm = grp.Get_at(j); Wdata_claim_itm_core itm = grp.Get_at(j);
pid_list.Add(KeyVal_.int_(j + ListAdp_.Base1, Srl_claims_prop_itm_core(itm_pid, itm))); pid_list.Add(KeyVal_.int_(j + base_adj, Srl_claims_prop_itm_core(itm_pid, itm))); // NOTE: was originally "+ 1"; changed to base_adj; PAGE:ru.w:Tor ru.w:Кактусовые DATE:2014-10-25
} }
rv.Add(KeyVal_.new_(itm_pid, (KeyVal[])pid_list.Xto_ary_and_clear(KeyVal.class))); rv.Add(KeyVal_.new_(itm_pid, (KeyVal[])pid_list.Xto_ary_and_clear(KeyVal.class)));
} }
@ -147,5 +147,5 @@ class Scrib_lib_wikibase_srl {
} }
} }
public static final String Key_type = "type", Key_value = "value"; public static final String Key_type = "type", Key_value = "value";
private static final KeyVal[] DataValue_nil = new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-Fran<EFBFBD>ois_Malgaigne; DATE:2014-04-07 private static final KeyVal[] DataValue_nil = new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
} }

View File

@ -125,7 +125,7 @@ public class Scrib_lib_wikibase_srl_tst {
( "claims:" ( "claims:"
, " P2:" , " P2:"
, " 1:" , " 1:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'string'" , " type:'string'"
@ -143,7 +143,7 @@ public class Scrib_lib_wikibase_srl_tst {
( "claims:" ( "claims:"
, " P2:" , " P2:"
, " 1:" , " 1:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:''" , " type:''"
@ -161,7 +161,7 @@ public class Scrib_lib_wikibase_srl_tst {
( "claims:" ( "claims:"
, " P2:" , " P2:"
, " 1:" , " 1:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'wikibase-entityid'" , " type:'wikibase-entityid'"
@ -181,7 +181,7 @@ public class Scrib_lib_wikibase_srl_tst {
, "claims:" , "claims:"
, " P2:" , " P2:"
, " 0:" , " 0:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'wikibase-entityid'" , " type:'wikibase-entityid'"
@ -194,7 +194,7 @@ public class Scrib_lib_wikibase_srl_tst {
, " type:'statement'" , " type:'statement'"
, " p2:" , " p2:"
, " 0:" , " 0:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'wikibase-entityid'" , " type:'wikibase-entityid'"
@ -214,7 +214,7 @@ public class Scrib_lib_wikibase_srl_tst {
( "claims:" ( "claims:"
, " P2:" , " P2:"
, " 1:" , " 1:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'time'" , " type:'time'"
@ -238,7 +238,7 @@ public class Scrib_lib_wikibase_srl_tst {
( "claims:" ( "claims:"
, " P2:" , " P2:"
, " 1:" , " 1:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'globecoordinate'" , " type:'globecoordinate'"
@ -261,7 +261,7 @@ public class Scrib_lib_wikibase_srl_tst {
( "claims:" ( "claims:"
, " P2:" , " P2:"
, " 1:" , " 1:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'quantity'" , " type:'quantity'"
@ -277,6 +277,26 @@ public class Scrib_lib_wikibase_srl_tst {
, "" , ""
); );
} }
@Test public void Claims_monolingualtext() {// PURPOSE.fix: type was mistakenly "language" instead of "monolingualtext" DATE:2014-10-21
fxt.Init_prop(fxt.Wdata_fxt().Make_claim_monolingual(2, "en", "en_text"));
fxt.Test
( "claims:"
, " P2:"
, " 1:"
, " id:'P2'"
, " mainsnak:"
, " datavalue:"
, " type:'monolingualtext'"
, " value:"
, " text:'en_text'"
, " language:'en'"
, " property:'P2'"
, " snaktype:'value'"
, " rank:'normal'"
, " type:'statement'"
, ""
);
}
@Test public void Qualifiers() { @Test public void Qualifiers() {
Wdata_wiki_mgr_fxt wdata_fxt = fxt.Wdata_fxt(); Wdata_wiki_mgr_fxt wdata_fxt = fxt.Wdata_fxt();
fxt.Init_prop(wdata_fxt.Make_claim_str(2, "Earth").Qualifiers_(wdata_fxt.Make_qualifiers(wdata_fxt.Make_qualifiers_grp(3, wdata_fxt.Make_claim_time(3, "2001-02-03 04:05:06"))))); fxt.Init_prop(wdata_fxt.Make_claim_str(2, "Earth").Qualifiers_(wdata_fxt.Make_qualifiers(wdata_fxt.Make_qualifiers_grp(3, wdata_fxt.Make_claim_time(3, "2001-02-03 04:05:06")))));
@ -284,7 +304,7 @@ public class Scrib_lib_wikibase_srl_tst {
( "claims:" ( "claims:"
, " P2:" , " P2:"
, " 1:" , " 1:"
, " id:null" , " id:'P2'"
, " mainsnak:" , " mainsnak:"
, " datavalue:" , " datavalue:"
, " type:'string'" , " type:'string'"

View File

@ -38,7 +38,7 @@ class Scrib_lib_wikibase_srl_visitor implements Wdata_claim_visitor {
} }
public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) { public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {
rv = new KeyVal[2]; rv = new KeyVal[2];
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_value_monolingualtext.Str_language); rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_monolingualtext);
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm)); rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm));
} }
private static KeyVal[] Monolingualtext_value(Wdata_claim_itm_monolingualtext itm) { private static KeyVal[] Monolingualtext_value(Wdata_claim_itm_monolingualtext itm) {

View File

@ -165,8 +165,8 @@ public class Wdata_wiki_mgr_fxt {
int len = list.Count(); int len = list.Count();
String[] rv = new String[len]; String[] rv = new String[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Xoa_ttl itm = (Xoa_ttl)list.FetchAt(i); Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i);
rv[i] = String_.new_ascii_(itm.Page_db()); rv[i] = String_.new_ascii_(itm.Page_ttl().Page_db());
} }
tmp_langs.Clear(); tmp_langs.Clear();
return rv; return rv;

View File

@ -20,13 +20,13 @@ import gplx.json.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; i
public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg { public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg {
public Wdata_xwiki_link_wtr Page_(Xoa_page page) {this.page = page; return this;} private Xoa_page page; public Wdata_xwiki_link_wtr Page_(Xoa_page page) {this.page = page; return this;} private Xoa_page page;
public void XferAry(Bry_bfr bfr, int idx) { public void XferAry(Bry_bfr bfr, int idx) {
ListAdp langs = page.Xwiki_langs(); ListAdp slink_list = page.Slink_list();
byte[] qid = Write_wdata_links(langs, page.Wiki(), page.Ttl(), page.Wdata_external_lang_links()); byte[] qid = Write_wdata_links(slink_list, page.Wiki(), page.Ttl(), page.Wdata_external_lang_links());
int langs_len = langs.Count(); int slink_list_len = slink_list.Count();
if (langs_len > 0) if (slink_list_len > 0)
page.Wiki().Xwiki_mgr().Lang_mgr().Html_bld(bfr, page.Wiki(), langs, qid); page.Wiki().Xwiki_mgr().Lang_mgr().Html_bld(bfr, page.Wiki(), slink_list, qid);
} }
public static byte[] Write_wdata_links(ListAdp langs, Xow_wiki wiki, Xoa_ttl ttl, Wdata_external_lang_links_data external_links_mgr) { public static byte[] Write_wdata_links(ListAdp slink_list, Xow_wiki wiki, Xoa_ttl ttl, Wdata_external_lang_links_data external_links_mgr) {
try { try {
switch (wiki.Domain_tid()) { switch (wiki.Domain_tid()) {
case Xow_wiki_domain_.Tid_home: // home will never be in wikidata case Xow_wiki_domain_.Tid_home: // home will never be in wikidata
@ -41,8 +41,8 @@ public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg {
Xow_wiki_abrv wiki_abrv = new Xow_wiki_abrv(); Xow_wiki_abrv wiki_abrv = new Xow_wiki_abrv();
int len = links.Count(); int len = links.Count();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Wdata_sitelink_itm sitelink = (Wdata_sitelink_itm)links.FetchAt(i); Wdata_sitelink_itm slink = (Wdata_sitelink_itm)links.FetchAt(i);
byte[] xwiki_key = sitelink.Site(); byte[] xwiki_key = slink.Site();
Xow_wiki_abrv_.parse_(wiki_abrv, xwiki_key, 0, xwiki_key.length); Xow_wiki_abrv_.parse_(wiki_abrv, xwiki_key, 0, xwiki_key.length);
if (wiki_abrv.Domain_tid() == Xow_wiki_abrv_.Tid_null) { if (wiki_abrv.Domain_tid() == Xow_wiki_abrv_.Tid_null) {
wiki.App().Usr_dlg().Warn_many("", "", "unknown wiki in wikidata: ttl=~{0} wiki=~{1}", ttl.Page_db_as_str(), String_.new_utf8_(xwiki_key)); wiki.App().Usr_dlg().Warn_many("", "", "unknown wiki in wikidata: ttl=~{0} wiki=~{1}", ttl.Page_db_as_str(), String_.new_utf8_(xwiki_key));
@ -53,18 +53,19 @@ public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg {
if (external_links_mgr_enabled && external_links_mgr.Langs_hide(lang_key, 0, lang_key.length)) continue; if (external_links_mgr_enabled && external_links_mgr.Langs_hide(lang_key, 0, lang_key.length)) continue;
tmp_bfr.Add(lang_key); tmp_bfr.Add(lang_key);
tmp_bfr.Add_byte(Byte_ascii.Colon); tmp_bfr.Add_byte(Byte_ascii.Colon);
tmp_bfr.Add(sitelink.Name()); tmp_bfr.Add(slink.Name());
Xoa_ttl lang_ttl = Xoa_ttl.parse_(wiki, tmp_bfr.Xto_bry_and_clear()); Xoa_ttl slink_ttl = Xoa_ttl.parse_(wiki, tmp_bfr.Xto_bry_and_clear());
if (lang_ttl == null) continue; // invalid ttl if (slink_ttl == null) continue; // invalid ttl
Xow_xwiki_itm xwiki_itm = lang_ttl.Wik_itm(); Xow_xwiki_itm xwiki_itm = slink_ttl.Wik_itm();
if ( xwiki_itm == null // not a known xwiki; EX: [[zzz:abc]] if ( xwiki_itm == null // not a known xwiki; EX: [[zzz:abc]]
|| Bry_.Eq(xwiki_itm.Domain(), wiki.Domain_bry()) // skip if same as self; i.e.: do not include links to enwiki if already in enwiki || Bry_.Eq(xwiki_itm.Domain(), wiki.Domain_bry()) // skip if same as self; i.e.: do not include links to enwiki if already in enwiki
) continue; ) continue;
langs.Add(lang_ttl); slink.Page_ttl_(slink_ttl);
slink_list.Add(slink);
} }
tmp_bfr.Mkr_rls(); tmp_bfr.Mkr_rls();
if (external_links_mgr_enabled && external_links_mgr.Sort()) if (external_links_mgr_enabled && external_links_mgr.Sort())
langs.SortBy(Xoa_ttl_sorter._); slink_list.SortBy(Xoa_ttl_sorter._);
return doc.Qid(); return doc.Qid();
} catch (Exception e) {Err_.Noop(e); return Qid_null;} } catch (Exception e) {Err_.Noop(e); return Qid_null;}
} }

View File

@ -39,7 +39,7 @@ public class Wdata_xwiki_link_wtr_tst {
, " <h4>grp1</h4>" , " <h4>grp1</h4>"
, " <table style='width: 100%;'>" , " <table style='width: 100%;'>"
, " <tr>" , " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>" , " </tr>"
, " </table>" , " </table>"
, " </div>" , " </div>"
@ -77,6 +77,26 @@ public class Wdata_xwiki_link_wtr_tst {
fxt.Init_pages_add(wdata_doc); fxt.Init_pages_add(wdata_doc);
fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr"); fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr");
} }
@Test public void Badges() {
fxt.Init_xwikis_add("de", "fr");
fxt.Init_qids_add("en", Xow_wiki_domain_.Tid_wikipedia, "Q1_en", "Q1");
fxt.Init_pages_add(fxt.Wdoc_bldr("Q1").Add_sitelink("enwiki", "Q1_en").Add_sitelink("dewiki", "Q1_de", "Q17437796").Add_sitelink("frwiki", "Q1_fr", "Q17437798").Xto_wdoc());
fxt.Test_parse_langs("", String_.Concat_lines_nl
( "<div id=\"xowa-lang\">"
, " <h5>In other languages (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)<a href='javascript:xowa_toggle_visible(\"wikidata-langs\");'><img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-goodarticle'><a hreflang=\"fr\" title=\"Q1 fr\" href=\"/site/fr.wikipedia.org/wiki/Q1 fr\">Q1 fr</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-featuredarticle'><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
// @Test public void No_wikidata_link() { // @Test public void No_wikidata_link() {
// fxt.Init_xwikis_add("fr", "de"); // fxt.Init_xwikis_add("fr", "de");
// fxt.Test_parse_langs("[[fr:A]]", String_.Concat_lines_nl // fxt.Test_parse_langs("[[fr:A]]", String_.Concat_lines_nl

View File

@ -26,6 +26,7 @@ public class Wdata_sitelink_itm implements Wdata_lang_sortable {
public byte[] Lang_code() {return lang;} public byte[] Lang_code() {return lang;}
public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null; public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null;
public Xow_wiki_domain Domain_info() {if (domain_info == null) domain_info = Xow_wiki_alias.parse_by_wmf_key(site); return domain_info;} private Xow_wiki_domain domain_info; public Xow_wiki_domain Domain_info() {if (domain_info == null) domain_info = Xow_wiki_alias.parse_by_wmf_key(site); return domain_info;} private Xow_wiki_domain domain_info;
public Xoa_ttl Page_ttl() {return page_ttl;} public Wdata_sitelink_itm Page_ttl_(Xoa_ttl v) {page_ttl = v; return this;} private Xoa_ttl page_ttl; // PERF: cache title to avoid creating new Object for "In Other langs"; DATE:2014-10-20
@Override public String toString() {// TEST: @Override public String toString() {// TEST:
return String_.Concat_with_str("|", String_.new_utf8_(site), String_.new_utf8_(name), String_.Concat_with_str(",", String_.Ary(badges))); return String_.Concat_with_str("|", String_.new_utf8_(site), String_.new_utf8_(name), String_.Concat_with_str(",", String_.Ary(badges)));
} }

View File

@ -32,13 +32,13 @@ public class Xow_lang_grp implements GfoInvkAble {
Xow_lang_itm[] itms_ary = this.Itms(); Xow_lang_itm[] itms_ary = this.Itms();
int itms_len = itms_ary.length; int itms_len = itms_ary.length;
for (int i = 0; i < itms_len; i++) for (int i = 0; i < itms_len; i++)
itms_ary[i].Atrs_set(null, false); // clear out pre-existing page names; needed b/c this struct is a singleton for entire wiki itms_ary[i].Atrs_set(null, false, null); // clear out pre-existing page names; needed b/c this struct is a singleton for entire wiki
itms_active_len = 0; itms_active_len = 0;
} }
public Bry_fmtr Html_all() {return html_all;} Bry_fmtr html_all; public Xow_lang_grp Html_all_(String s) {html_all = Bry_fmtr.new_(s, "all_name", "grps"); return this;} public Bry_fmtr Html_all() {return html_all;} Bry_fmtr html_all; public Xow_lang_grp Html_all_(String s) {html_all = Bry_fmtr.new_(s, "all_name", "grps"); return this;}
public byte[] Html_grp_bgn() {return html_grp_bgn;} private byte[] html_grp_bgn = Bry_.new_ascii_("\n <tr>"); public byte[] Html_grp_bgn() {return html_grp_bgn;} private byte[] html_grp_bgn = Bry_.new_ascii_("\n <tr>");
public byte[] Html_grp_end() {return html_grp_end;} private byte[] html_grp_end = Bry_.new_ascii_("\n </tr>"); public byte[] Html_grp_end() {return html_grp_end;} private byte[] html_grp_end = Bry_.new_ascii_("\n </tr>");
public Bry_fmtr Html_itm() {return html_itm;} Bry_fmtr html_itm; public Xow_lang_grp Html_itm_(String s) {html_itm = Bry_fmtr.new_(s, "lang_code", "lang_domain", "lang_name", "lang_href", "pagename_translation"); return this;} public Bry_fmtr Html_itm() {return html_itm;} Bry_fmtr html_itm; public Xow_lang_grp Html_itm_(String s) {html_itm = Bry_fmtr.new_(s, "lang_code", "lang_domain", "lang_name", "lang_href", "pagename_translation", "page_badge"); return this;}
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) { public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) {
Xow_lang_itm[] itms_ary = this.Itms(); Xow_lang_itm[] itms_ary = this.Itms();
if (sort_mode == Xow_lang_grp.Sort_mode_page_name) if (sort_mode == Xow_lang_grp.Sort_mode_page_name)
@ -69,7 +69,7 @@ public class Xow_lang_grp implements GfoInvkAble {
)); ));
rv.Html_itm_(String_.Concat_lines_nl_skip_last rv.Html_itm_(String_.Concat_lines_nl_skip_last
( "" ( ""
, " <td style='width: 10%; padding-bottom: 5px;'>~{lang_name}</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"~{lang_code}\" title=\"~{pagename_translation}\" href=\"~{lang_href}\">~{pagename_translation}</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>~{lang_name}</td><td style='width: 20%; padding-bottom: 5px;'><li~{page_badge}><a hreflang=\"~{lang_code}\" title=\"~{pagename_translation}\" href=\"~{lang_href}\">~{pagename_translation}</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
)); ));
return rv; return rv;
} private Xow_lang_grp() {} } private Xow_lang_grp() {}

View File

@ -27,11 +27,12 @@ public class Xow_lang_itm {
public byte[] Page_name() {return page_name;} private byte[] page_name; public byte[] Page_name() {return page_name;} private byte[] page_name;
public boolean Page_name_has() {return Bry_.Len_gt_0(page_name);} public boolean Page_name_has() {return Bry_.Len_gt_0(page_name);}
public boolean Empty_xwiki() {return empty_xwiki;} private boolean empty_xwiki; public boolean Empty_xwiki() {return empty_xwiki;} private boolean empty_xwiki;
public byte[][] Page_badges() {return page_badges;} private byte[][] page_badges;
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) { public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) {
html_grp.Html_itm().Bld_bfr(bfr, lang.Key_bry(), xwiki.Domain(), lang.Local_name_bry(), page_name); html_grp.Html_itm().Bld_bfr(bfr, lang.Key_bry(), xwiki.Domain(), lang.Local_name_bry(), page_name);
} }
public void Atrs_set(byte[] page_name, boolean empty_xwiki) { public void Atrs_set(byte[] page_name, boolean empty_xwiki, byte[][] page_badges) {
this.page_name = page_name; this.empty_xwiki = empty_xwiki; this.page_name = page_name; this.empty_xwiki = empty_xwiki; this.page_badges = page_badges;
html_grp.Itms_active_len_add_one_(); html_grp.Itms_active_len_add_one_();
} }
} }

View File

@ -16,7 +16,7 @@ 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; import gplx.*; package gplx.xowa; import gplx.*;
import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.xtns.wdatas.core.*;
public class Xow_lang_mgr { public class Xow_lang_mgr {
Xow_lang_mgr() { Xow_lang_mgr() {
int len = Xol_lang_itm_.Id__max; int len = Xol_lang_itm_.Id__max;
@ -67,15 +67,16 @@ public class Xow_lang_mgr {
else return GfoInvkAble_.Rv_unhandled; else return GfoInvkAble_.Rv_unhandled;
return this; return this;
} private static final String Invk_get = "get", Invk_sort = "sort"; } private static final String Invk_get = "get", Invk_sort = "sort";
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki, ListAdp ttl_list, byte[] qid) { public void Html_bld(Bry_bfr bfr, Xow_wiki wiki, ListAdp slink_list, byte[] qid) {
int grp_len = hash.Count(); int grp_len = hash.Count();
for (int i = 0; i < grp_len; i++) { for (int i = 0; i < grp_len; i++) {
Xow_lang_grp grp = (Xow_lang_grp)hash.FetchAt(i); Xow_lang_grp grp = (Xow_lang_grp)hash.FetchAt(i);
grp.Itms_reset(); grp.Itms_reset();
} }
int ttl_list_len = ttl_list.Count(); int slink_len = slink_list.Count();
for (int i = 0; i < ttl_list_len; i++) { for (int i = 0; i < slink_len; i++) {
Xoa_ttl ttl = (Xoa_ttl)ttl_list.FetchAt(i); Wdata_sitelink_itm slink = (Wdata_sitelink_itm)slink_list.FetchAt(i);
Xoa_ttl ttl = slink.Page_ttl();
Xow_xwiki_itm xwiki = ttl.Wik_itm(); Xow_xwiki_itm xwiki = ttl.Wik_itm();
int lang_id = xwiki.Lang_id(); int lang_id = xwiki.Lang_id();
Xow_lang_itm itm = itms[lang_id]; // NOTE: handles ttls like [[fr:]] and [[:fr;]] which have an empty Page_txt, but a valued Full_txt_raw Xow_lang_itm itm = itms[lang_id]; // NOTE: handles ttls like [[fr:]] and [[:fr;]] which have an empty Page_txt, but a valued Full_txt_raw
@ -85,9 +86,9 @@ public class Xow_lang_mgr {
ttl_bry = wiki.Ctx().Cur_page().Ttl().Page_txt(); ttl_bry = wiki.Ctx().Cur_page().Ttl().Page_txt();
empty_xwiki = true; empty_xwiki = true;
} }
itm.Atrs_set(ttl_bry, empty_xwiki); itm.Atrs_set(ttl_bry, empty_xwiki, slink.Badges());
} }
html_bldr.Init(this, wiki, ttl_list, ttl_list_len, qid); html_bldr.Init(this, wiki, slink_list, slink_len, qid);
html_bldr.XferAry(bfr, -1); html_bldr.XferAry(bfr, -1);
} private Xow_lang_itm[] itms = null; Xow_lang_html html_bldr = new Xow_lang_html(); } private Xow_lang_itm[] itms = null; Xow_lang_html html_bldr = new Xow_lang_html();
public static Xow_lang_mgr dflt_() { public static Xow_lang_mgr dflt_() {
@ -139,12 +140,13 @@ class Xow_lang_html implements Bry_fmtr_arg {
byte[] domain = itm.Lang_domain(); byte[] domain = itm.Lang_domain();
byte[] page_name = itm.Page_name(); byte[] page_name = itm.Page_name();
byte[] local_name = itm.Lang_name(); byte[] local_name = itm.Lang_name();
byte[] badge_cls = Badge_cls(tmp_bfr, itm.Page_badges());
if (wiki.App().User().Wiki().Xwiki_mgr().Get_by_key(domain) == null) if (wiki.App().User().Wiki().Xwiki_mgr().Get_by_key(domain) == null)
tmp_bfr.Add(Xoh_href_parser.Href_http_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry); tmp_bfr.Add(Xoh_href_parser.Href_http_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
else else
tmp_bfr.Add(Xoh_href_parser.Href_site_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry); tmp_bfr.Add(Xoh_href_parser.Href_site_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
if (!itm.Empty_xwiki()) tmp_bfr.Add(page_name); if (!itm.Empty_xwiki()) tmp_bfr.Add(page_name);
grp.Html_itm().Bld_bfr_many(bfr, lang_key, domain, local_name, tmp_bfr.Xto_bry_and_clear(), page_name); grp.Html_itm().Bld_bfr_many(bfr, lang_key, domain, local_name, tmp_bfr.Xto_bry_and_clear(), page_name, badge_cls);
++grp_counter; ++grp_counter;
if (grp_counter == 3) { if (grp_counter == 3) {
row_opened = false; row_opened = false;
@ -160,4 +162,30 @@ class Xow_lang_html implements Bry_fmtr_arg {
break; break;
} }
} private Xow_lang_grp grp; Bry_bfr tmp_bfr = Bry_bfr.reset_(255); } private Xow_lang_grp grp; Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
private static byte[] Badge_cls(Bry_bfr bfr, byte[][] badges) {
if (badges == null) badges = Bry_.Ary_empty;
int badges_len = badges.length;
bfr.Add(Cls_bgn);
if (badges_len == 0)
bfr.Add(Badge_none_cls);
else {
for (int i = 0; i < badges_len; ++i) {
if (i != 0) bfr.Add_byte_comma();
byte[] badge = badges[i];
if (Bry_.Eq(badge, Badge_good_qid)) bfr.Add(Badge_good_cls);
else if (Bry_.Eq(badge, Badge_feat_qid)) bfr.Add(Badge_feat_cls);
else Gfo_usr_dlg_._.Warn_many("", "", "unknown badge: badge~{0}", String_.new_utf8_(badge));
}
}
bfr.Add_byte_apos();
return bfr.Xto_bry_and_clear();
}
private static final byte[]
Badge_good_qid = Bry_.new_ascii_("Q17437798")
, Badge_good_cls = Bry_.new_ascii_("badge-goodarticle")
, Badge_feat_qid = Bry_.new_ascii_("Q17437796")
, Badge_feat_cls = Bry_.new_ascii_("badge-featuredarticle")
, Badge_none_cls = Bry_.new_ascii_("badge-none")
, Cls_bgn = Bry_.new_ascii_(" class='")
;
} }

View File

@ -59,7 +59,7 @@ public class Xow_lang_mgr_fxt {
wiki.Html_mgr().Html_wtr().Write_all(bfr, ctx, raw_bry, root); wiki.Html_mgr().Html_wtr().Write_all(bfr, ctx, raw_bry, root);
Bry_bfr html_bfr = Bry_bfr.new_(); Bry_bfr html_bfr = Bry_bfr.new_();
wiki.Xwiki_mgr().Lang_mgr().Html_bld(html_bfr, wiki, ctx.Cur_page().Xwiki_langs(), gplx.xowa.xtns.wdatas.Wdata_xwiki_link_wtr.Qid_null); wiki.Xwiki_mgr().Lang_mgr().Html_bld(html_bfr, wiki, ctx.Cur_page().Slink_list(), gplx.xowa.xtns.wdatas.Wdata_xwiki_link_wtr.Qid_null);
Tfds.Eq_str_lines(expd, html_bfr.Xto_str_and_clear()); Tfds.Eq_str_lines(expd, html_bfr.Xto_str_and_clear());
} }
} }

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa; import gplx.*; package gplx.xowa; import gplx.*;
import org.junit.*; import org.junit.*;
public class Xow_lang_mgr_tst { public class Xow_lang_mgr_tst {
Xow_lang_mgr_fxt fxt = new Xow_lang_mgr_fxt(); private Xow_lang_mgr_fxt fxt = new Xow_lang_mgr_fxt();
@Before public void init() {fxt.Clear();} @Before public void init() {fxt.Clear();}
@Test public void Basic() { @Test public void Basic() {
fxt.tst("[[simple:Earth]] [[fr:Terre]] [[es:Tierra]] [[de:Erde]] [[it:Terre]]", String_.Concat_lines_nl_skip_last fxt.tst("[[simple:Earth]] [[fr:Terre]] [[es:Tierra]] [[de:Erde]] [[it:Terre]]", String_.Concat_lines_nl_skip_last
@ -28,16 +28,16 @@ public class Xow_lang_mgr_tst {
, " <h4>grp1</h4>" , " <h4>grp1</h4>"
, " <table style='width: 100%;'>" , " <table style='width: 100%;'>"
, " <tr>" , " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"simple\" title=\"Earth\" href=\"/site/simple.wikipedia.org/wiki/Earth\">Earth</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"Earth\" href=\"/site/simple.wikipedia.org/wiki/Earth\">Earth</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>Spanish</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"es\" title=\"Tierra\" href=\"/site/es.wikipedia.org/wiki/Tierra\">Tierra</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>Spanish</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"es\" title=\"Tierra\" href=\"/site/es.wikipedia.org/wiki/Tierra\">Tierra</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>Italian</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"it\" title=\"Terre\" href=\"/site/it.wikipedia.org/wiki/Terre\">Terre</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>Italian</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"it\" title=\"Terre\" href=\"/site/it.wikipedia.org/wiki/Terre\">Terre</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>" , " </tr>"
, " </table>" , " </table>"
, " <h4>grp2</h4>" , " <h4>grp2</h4>"
, " <table style='width: 100%;'>" , " <table style='width: 100%;'>"
, " <tr>" , " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"fr\" title=\"Terre\" href=\"/site/fr.wikipedia.org/wiki/Terre\">Terre</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"fr\" title=\"Terre\" href=\"/site/fr.wikipedia.org/wiki/Terre\">Terre</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"de\" title=\"Erde\" href=\"/site/de.wikipedia.org/wiki/Erde\">Erde</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"de\" title=\"Erde\" href=\"/site/de.wikipedia.org/wiki/Erde\">Erde</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>" , " </tr>"
, " </table>" , " </table>"
, " </div>" , " </div>"
@ -52,7 +52,7 @@ public class Xow_lang_mgr_tst {
, " <h4>grp1</h4>" , " <h4>grp1</h4>"
, " <table style='width: 100%;'>" , " <table style='width: 100%;'>"
, " <tr>" , " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"simple\" title=\"Test page\" href=\"/site/simple.wikipedia.org/wiki/\">Test page</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"Test page\" href=\"/site/simple.wikipedia.org/wiki/\">Test page</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>" , " </tr>"
, " </table>" , " </table>"
, " </div>" , " </div>"
@ -68,7 +68,7 @@ public class Xow_lang_mgr_tst {
, " <h4>grp1</h4>" , " <h4>grp1</h4>"
, " <table style='width: 100%;'>" , " <table style='width: 100%;'>"
, " <tr>" , " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Chinese</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"zh\" title=\"Earth\" href=\"http://zh.wikipedia.org/wiki/Earth\">Earth</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>Chinese</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"zh\" title=\"Earth\" href=\"http://zh.wikipedia.org/wiki/Earth\">Earth</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>" , " </tr>"
, " </table>" , " </table>"
, " </div>" , " </div>"
@ -83,7 +83,7 @@ public class Xow_lang_mgr_tst {
, " <h4>grp1</h4>" , " <h4>grp1</h4>"
, " <table style='width: 100%;'>" , " <table style='width: 100%;'>"
, " <tr>" , " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"simple\" title=\"A#b\" href=\"/site/simple.wikipedia.org/wiki/A#b\">A#b</a></td><td style='width: 3%; padding-bottom: 5px;'></td>" , " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"A#b\" href=\"/site/simple.wikipedia.org/wiki/A#b\">A#b</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>" , " </tr>"
, " </table>" , " </table>"
, " </div>" , " </div>"

View File

@ -81,6 +81,7 @@ public class Xof_xfer_queue {
fsdb_itm.Html_img_wkr_(xfer_itm.Html_img_wkr()); fsdb_itm.Html_img_wkr_(xfer_itm.Html_img_wkr());
rv.Add(fsdb_itm); rv.Add(fsdb_itm);
} }
this.Clear();
return rv; return rv;
} }
private static final String GRP_KEY = "xowa.xfer.queue"; private static final String GRP_KEY = "xowa.xfer.queue";

View File

@ -32,7 +32,7 @@ public class Xoa_page {
public Xoa_app App() {return app;} private Xoa_app app; public Xoa_app App() {return app;} private Xoa_app app;
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki; public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public Xol_lang Lang() {return lang;} public Xoa_page Lang_(Xol_lang v) {lang = v; return this;} private Xol_lang lang; public Xol_lang Lang() {return lang;} public Xoa_page Lang_(Xol_lang v) {lang = v; return this;} private Xol_lang lang;
public Xoa_revision_data Revision_data() {return revision_data;} private Xoa_revision_data revision_data = new Xoa_revision_data(); public Xopg_revision_data Revision_data() {return rev_data;} private Xopg_revision_data rev_data = new Xopg_revision_data();
public Xopg_html_data Html_data() {return html_data;} private Xopg_html_data html_data = new Xopg_html_data(); public Xopg_html_data Html_data() {return html_data;} private Xopg_html_data html_data = new Xopg_html_data();
public Xoa_ttl Ttl() {return ttl;} public Xoa_page Ttl_(Xoa_ttl v) {ttl = v; url.Wiki_bry_(wiki.Domain_bry()).Page_bry_(v.Full_url()); return this;} private Xoa_ttl ttl; public Xoa_ttl Ttl() {return ttl;} public Xoa_page Ttl_(Xoa_ttl v) {ttl = v; url.Wiki_bry_(wiki.Domain_bry()).Page_bry_(v.Full_url()); return this;} private Xoa_ttl ttl;
public Xoa_url Url() {return url;} public Xoa_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = Xoa_url.blank_(); public Xoa_url Url() {return url;} public Xoa_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = Xoa_url.blank_();
@ -56,7 +56,7 @@ public class Xoa_page {
public Xop_lnki_logger_redlinks_mgr Lnki_redlinks_mgr() {return lnki_redlinks_mgr;} private Xop_lnki_logger_redlinks_mgr lnki_redlinks_mgr; public Xop_lnki_logger_redlinks_mgr Lnki_redlinks_mgr() {return lnki_redlinks_mgr;} private Xop_lnki_logger_redlinks_mgr lnki_redlinks_mgr;
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr(); public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr(); public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr();
public ListAdp Xwiki_langs() {return xwiki_langs;} private ListAdp xwiki_langs = ListAdp_.new_(); public ListAdp Slink_list() {return slink_list;} private ListAdp slink_list = ListAdp_.new_();
public Wdata_external_lang_links_data Wdata_external_lang_links() {return wdata_external_lang_links;} private Wdata_external_lang_links_data wdata_external_lang_links = new Wdata_external_lang_links_data(); public Wdata_external_lang_links_data Wdata_external_lang_links() {return wdata_external_lang_links;} private Wdata_external_lang_links_data wdata_external_lang_links = new Wdata_external_lang_links_data();
public boolean Pages_recursed() {return pages_recursed;} public void Pages_recursed_(boolean v) {pages_recursed = v; } private boolean pages_recursed; public boolean Pages_recursed() {return pages_recursed;} public void Pages_recursed_(boolean v) {pages_recursed = v; } private boolean pages_recursed;
public Xopg_tmpl_prepend_mgr Tmpl_prepend_mgr() {return tmpl_prepend_mgr;} private Xopg_tmpl_prepend_mgr tmpl_prepend_mgr = new Xopg_tmpl_prepend_mgr(); public Xopg_tmpl_prepend_mgr Tmpl_prepend_mgr() {return tmpl_prepend_mgr;} private Xopg_tmpl_prepend_mgr tmpl_prepend_mgr = new Xopg_tmpl_prepend_mgr();
@ -84,14 +84,14 @@ public class Xoa_page {
hdump_data.Clear(); hdump_data.Clear();
wdata_external_lang_links.Reset(); wdata_external_lang_links.Reset();
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this); gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(this);
xwiki_langs.Clear(); slink_list.Clear();
html_data.Clear(); html_data.Clear();
lnki_file_mgr.Clear(); lnki_file_mgr.Clear();
pages_recursed = false; pages_recursed = false;
tmpl_stack_ary = Bry_.Ary_empty; tmpl_stack_ary = Bry_.Ary_empty;
tmpl_stack_ary_len = tmpl_stack_ary_max = 0; tmpl_stack_ary_len = tmpl_stack_ary_max = 0;
popup_mgr.Clear(); popup_mgr.Clear();
revision_data.Clear(); rev_data.Clear();
tmpl_prepend_mgr.Clear(); tmpl_prepend_mgr.Clear();
} }
public static final Xoa_page Empty = new Xoa_page().Missing_(); public static final Xoa_page Empty = new Xoa_page().Missing_();

View File

@ -1,27 +0,0 @@
/*
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; import gplx.*;
public class Xoa_revision_data {
public int Id() {return id;} public Xoa_revision_data Id_(int v) {id = v; return this;} private int id;
public DateAdp Modified_on() {return modified_on;} public Xoa_revision_data Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on = DateAdp_.MinValue;
public byte[] User() {return user;} public Xoa_revision_data User_(byte[] v) {user = v; return this;} private byte[] user = Bry_.Empty;
public byte[] Protection_level() {return protection_level;} public Xoa_revision_data Protection_level_(byte[] v) {protection_level = v; return this;} private byte[] protection_level = Bry_.Empty;
public int Html_db_id() {return html_db_id;} public void Html_db_id_(int v) {html_db_id = v;} private int html_db_id = -1;
public void Clear() {// NOTE: do not clear data b/c saving in Edit will call clear and id will be reset to 0
}
}

View File

@ -63,7 +63,7 @@ public class Xop_lnki_wkr__xwiki_tst {
( "[[:fr:A]]", String_.Concat_lines_nl_skip_last ( "[[:fr:A]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/site/fr.wikipedia.org/wiki/A\">A</a>" ( "<a href=\"/site/fr.wikipedia.org/wiki/A\">A</a>"
)); ));
Tfds.Eq(0, fxt.Page().Xwiki_langs().Count()); Tfds.Eq(0, fxt.Page().Slink_list().Count());
} }
@Test public void Simple_and_english() { // PURPOSE: s.w xwiki links to en were not working b/c s.w and en had same super lang of English; PAGE:s.q:Anonymous DATE:2014-09-10 @Test public void Simple_and_english() { // PURPOSE: s.w xwiki links to en were not working b/c s.w and en had same super lang of English; PAGE:s.q:Anonymous DATE:2014-09-10
Xoa_app app = Xoa_app_fxt.app_(); Xoa_app app = Xoa_app_fxt.app_();
@ -74,7 +74,7 @@ public class Xop_lnki_wkr__xwiki_tst {
( "[[en:A]]" ( "[[en:A]]"
, "" , ""
); );
Tfds.Eq(1, fxt.Page().Xwiki_langs().Count()); // test 1 xwiki lang Tfds.Eq(1, fxt.Page().Slink_list().Count()); // test 1 xwiki lang
} }
@Test public void Species_and_commons() { // PURPOSE: species xwiki links to commons should not put link in wikidata langs; PAGE:species:Scarabaeidae DATE:2014-09-10 @Test public void Species_and_commons() { // PURPOSE: species xwiki links to commons should not put link in wikidata langs; PAGE:species:Scarabaeidae DATE:2014-09-10
Xoa_app app = Xoa_app_fxt.app_(); Xoa_app app = Xoa_app_fxt.app_();
@ -85,7 +85,7 @@ public class Xop_lnki_wkr__xwiki_tst {
( "[[commons:A]]" ( "[[commons:A]]"
, "<a href=\"/site/commons.wikimedia.org/wiki/A\">commons:A</a>" , "<a href=\"/site/commons.wikimedia.org/wiki/A\">commons:A</a>"
); );
Tfds.Eq(0, fxt.Page().Xwiki_langs().Count()); // no xwiki langs Tfds.Eq(0, fxt.Page().Slink_list().Count()); // no xwiki langs
} }
@Test public void Wiktionary_and_wikipedia() { // PURPOSE: do not create xwiki links if same lang and differet type; PAGE:s.d:water DATE:2014-09-14 @Test public void Wiktionary_and_wikipedia() { // PURPOSE: do not create xwiki links if same lang and differet type; PAGE:s.d:water DATE:2014-09-14
Xoa_app app = Xoa_app_fxt.app_(); Xoa_app app = Xoa_app_fxt.app_();
@ -96,7 +96,7 @@ public class Xop_lnki_wkr__xwiki_tst {
( "[[w:A]]" ( "[[w:A]]"
, "<a href=\"/site/simple.wikipedia.org/wiki/A\">w:A</a>" , "<a href=\"/site/simple.wikipedia.org/wiki/A\">w:A</a>"
); );
Tfds.Eq(0, fxt.Page().Xwiki_langs().Count()); // test 0 xwiki lang Tfds.Eq(0, fxt.Page().Slink_list().Count()); // test 0 xwiki lang
} }
@Test public void Species_and_wikipedia() { // PURPOSE: species creates xwiki links to wikipedia; PAGE:species:Puccinia DATE:2014-09-14 @Test public void Species_and_wikipedia() { // PURPOSE: species creates xwiki links to wikipedia; PAGE:species:Puccinia DATE:2014-09-14
Xoa_app app = Xoa_app_fxt.app_(); Xoa_app app = Xoa_app_fxt.app_();
@ -107,7 +107,7 @@ public class Xop_lnki_wkr__xwiki_tst {
( "[[fr:A]]" ( "[[fr:A]]"
, "" , ""
); );
Tfds.Eq(1, fxt.Page().Xwiki_langs().Count()); // 1 xwiki lang Tfds.Eq(1, fxt.Page().Slink_list().Count()); // 1 xwiki lang
} }
private void Reg_xwiki_alias(String alias, String domain) { private void Reg_xwiki_alias(String alias, String domain) {
Xop_fxt.Reg_xwiki_alias(fxt.Wiki(), alias, domain); Xop_fxt.Reg_xwiki_alias(fxt.Wiki(), alias, domain);

View File

@ -103,9 +103,9 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
} }
if (tag_obj == null) { // not a known xml tag; EX: "<abcd>"; "if 5 < 7 then" if (tag_obj == null) { // not a known xml tag; EX: "<abcd>"; "if 5 < 7 then"
if (ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki) { if (ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki) {
if (ctx_cur_tid_is_tblw_atr_owner) // <unknown_tag is occurring inside tblw element (EX: {| style='margin:1em<f'); just add to txt tkn if (ctx_cur_tid_is_tblw_atr_owner) // unknown_tag is occurring inside tblw element (EX: {| style='margin:1em<f'); just add to txt tkn
return ctx.Lxr_make_txt_(cur_pos); return ctx.Lxr_make_txt_(cur_pos);
else { // <unknown_tag is occurring anyhwere else; escape < to &lt; and resume from character just after it; else { // unknown_tag is occurring anyhwere else; escape < to &lt; and resume from character just after it;
ctx.Subs_add(root, Make_bry_tkn(tkn_mkr, src, bgn_pos, cur_pos)); ctx.Subs_add(root, Make_bry_tkn(tkn_mkr, src, bgn_pos, cur_pos));
return cur_pos; return cur_pos;
} }
@ -218,9 +218,9 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
private static Xop_tkn_itm Make_bry_tkn(Xop_tkn_mkr tkn_mkr, byte[] src, int bgn_pos, int cur_pos) { private static Xop_tkn_itm Make_bry_tkn(Xop_tkn_mkr tkn_mkr, byte[] src, int bgn_pos, int cur_pos) {
int len = cur_pos - bgn_pos; int len = cur_pos - bgn_pos;
byte[] bry = null; byte[] bry = null;
if (len == 1 && src[cur_pos] == Byte_ascii.Lt) bry = Html_entity_.Lt_bry; if (len == 1 && src[bgn_pos] == Byte_ascii.Lt) bry = Html_entity_.Lt_bry;
else if (len == 2 && src[cur_pos] == Byte_ascii.Lt else if (len == 2 && src[bgn_pos] == Byte_ascii.Lt
&& src[cur_pos + 1] == Byte_ascii.Slash) bry = Bry_escape_lt_slash; && src[bgn_pos + 1] == Byte_ascii.Slash) bry = Bry_escape_lt_slash; // NOTE: should use bgn_pos, not cur_pos; DATE:2014-10-22
else bry = Bry_.Add(Html_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, cur_pos)); // +1 to skip < else bry = Bry_.Add(Html_entity_.Lt_bry, Bry_.Mid(src, bgn_pos + 1, cur_pos)); // +1 to skip <
return tkn_mkr.Bry_raw(bgn_pos, cur_pos, bry); return tkn_mkr.Bry_raw(bgn_pos, cur_pos, bry);
} }

View File

@ -66,4 +66,9 @@ public class Xop_xnde_wkr__err_malformed_tst {
, "</div>" , "</div>"
)); ));
} }
@Test public void Incomplete_tag() { // PURPOSE: handle incomplete tag sequences; DATE:2014-10-22
fxt.Test_parse_page_all_str("<", "&lt;");
fxt.Test_parse_page_all_str("</", "&lt;/");
fxt.Test_parse_page_all_str("</<", "&lt;/&lt;"); // this used to fail
}
} }

View File

@ -164,7 +164,7 @@ public class Xop_xnde_wkr__include_uncommon_tst {
); );
fxt.Init_defn_clear(); fxt.Init_defn_clear();
} }
@Test public void Pre_and_includeonly() { @Test public void Pre_and_includeonly() { // PAGE:https://en.wikipedia.org/wiki/BSD_licenses DATE:2014-05-23
fxt.Init_defn_add("pre2", "<pre<includeonly></includeonly>>{{{1}}}</pre>"); fxt.Init_defn_add("pre2", "<pre<includeonly></includeonly>>{{{1}}}</pre>");
fxt.Test_parse_page_all_str fxt.Test_parse_page_all_str
( "{{pre2|a}}" ( "{{pre2|a}}"

View File

@ -65,10 +65,15 @@ public class Xop_subst_tst {
fxt.Init_log_(Xop_ttl_log.Invalid_char); fxt.Init_log_(Xop_ttl_log.Invalid_char);
fxt.Test_parse_page_tmpl_str("{{test|Template:[xyz]}}", "%7B%7BTemplate%3ATemplate%3A%5Bxyz%5D%7D%7D"); // url-encoded version of {{safesubst:Template:xyz}} fxt.Test_parse_page_tmpl_str("{{test|Template:[xyz]}}", "%7B%7BTemplate%3ATemplate%3A%5Bxyz%5D%7D%7D"); // url-encoded version of {{safesubst:Template:xyz}}
} }
@Test public void Nowiki() { // PURPOSE: stack overflow; PAGE:Близкиерузья_(Сезон_2) DATE:2014-10-21
fxt.Init_defn_add("ET", "");
fxt.Init_defn_add("ds", "<includeonly>{{subst:</includeonly><includeonly>ET|<nowiki>{{subst:ds}}</nowiki>}}</includeonly>");
fxt.Test_parse_page_tmpl_str("{{subst:ds}}", ""); // {{subst:ds}} causes stack overflow; {{ds}} does not
}
// NOTE: these are actually not good tests; MW does subst just before save; it doesn't do subst on load; in this case, the tests are testing load (which will noop); they need to test save (which xowa doesn't do) // NOTE: these are actually not good tests; MW does subst just before save; it doesn't do subst on load; in this case, the tests are testing load (which will noop); they need to test save (which xowa doesn't do)
// @Test public void Tmpl_txt_subst() {fxt.Test_parse_tmpl_str_test("{{subst:xo_print|a}}" , "{{test}}" , "a");} // @Test public void Tmpl_txt_subst() {fxt.Test_parse_tmpl_str_test("{{subst:xo_print|a}}" , "{{test}}" , "a");}
// @Test public void Tmpl_txt_subst_prm() {fxt.Test_parse_tmpl_str_test("{{subst:xo_print|{{{1}}}}}" , "{{test|a}}" , "a");} // @Test public void Tmpl_txt_subst_prm() {fxt.Test_parse_tmpl_str_test("{{subst:xo_print|{{{1}}}}}" , "{{test|a}}" , "a");}
//@Test public void Tmpl_txt_safesubst_prm() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}ns:Category}}" , "{{test}}" , "Category");} //@Test public void Tmpl_txt_safesubst_prm() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}ns:Category}}" , "{{test}}" , "Category");}
//@Test public void Tmpl_txt_subst_immed() {fxt.Test_parse_tmpl_str_test("{{xo_print{{subst:!}}a}}" , "{{test}}" , "a");} //@Test public void Tmpl_txt_subst_immed() {fxt.Test_parse_tmpl_str_test("{{xo_print{{subst:!}}a}}" , "{{test}}" , "a");}

View File

@ -67,7 +67,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
name_ary_len = name_ary.length; name_ary_len = name_ary.length;
name_bgn = Bry_finder.Find_fwd_while_not_ws(name_ary, 0, name_ary_len); name_bgn = Bry_finder.Find_fwd_while_not_ws(name_ary, 0, name_ary_len);
if ( name_ary_len == 0 // name is blank; can occur with failed inner tmpl; EX: {{ {{does not exist}} }} if ( name_ary_len == 0 // name is blank; can occur with failed inner tmpl; EX: {{ {{does not exist}} }}
|| name_bgn == name_ary_len // name is ws; EX: {{test| }} -> {{{{{1}}}}}is whitespace String; PAGE:en.d:wear_one's_heart_on_one's_sleeve; EX:{{t+|fr|avoir le c<EFBFBD>ur sur la main| }} || name_bgn == name_ary_len // name is ws; EX: {{test| }} -> {{{{{1}}}}}is whitespace String; PAGE:en.d:wear_one's_heart_on_one's_sleeve; EX:{{t+|fr|avoir le cœur sur la main| }}
) { ) {
bfr.Add(Ary_unknown_bgn).Add(Ary_dynamic_is_blank).Add(Ary_unknown_end); // FUTURE: excerpt actual String; WHEN: add raw to defn bfr.Add(Ary_unknown_bgn).Add(Ary_dynamic_is_blank).Add(Ary_unknown_end); // FUTURE: excerpt actual String; WHEN: add raw to defn
return false; return false;
@ -104,9 +104,8 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk {
bfr.Add(Xop_curly_bgn_lxr.Hook).Add(name_ary); bfr.Add(Xop_curly_bgn_lxr.Hook).Add(name_ary);
for (int i = 0; i < args_len; i++) { for (int i = 0; i < args_len; i++) {
Arg_nde_tkn nde = args[i]; Arg_nde_tkn nde = args[i];
// bfr.Add_byte(Byte_ascii.Pipe); bfr.Add_byte(Byte_ascii.Pipe); // add |
Xot_fmtr_prm._.Write(Byte_ascii.Pipe); bfr.Add_mid(src, nde.Src_bgn(), nde.Src_end()); // add entire arg; "k=v"; note that src must be added, not evaluated, else <nowiki> may be dropped and cause stack overflow; PAGE:ru.w:Близкиерузья_(Сезон_2) DATE:2014-10-21
nde.Tmpl_fmt(ctx, src, Xot_fmtr_prm._);
} }
Xot_fmtr_prm._.Print(bfr); Xot_fmtr_prm._.Print(bfr);
bfr.Add(Xop_curly_end_lxr.Hook); bfr.Add(Xop_curly_end_lxr.Hook);