1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00
This commit is contained in:
gnosygnu 2014-08-03 23:31:22 -04:00
parent 7b6e65b088
commit fb8c06c560
191 changed files with 1869 additions and 722 deletions

View File

@ -66,6 +66,12 @@ public class Err_ { //_20110415
public static String Message_lang(Exception e) {return e.getClass() + " " + e.getMessage();}
public static String Message_gplx(Exception e) {return ErrMsgWtr._.Message_gplx(e);}
public static String Message_gplx_brief(Exception e) {return ErrMsgWtr._.Message_gplx_brief(e);}
public static String Message_hdr_or_message(Exception e) {
if (e == null) return "exception is null";
return ClassAdp_.Eq(e.getClass(), Err.class)
? ((Err)e).Hdr()
: Message_lang(e);
}
@gplx.Internal protected static String StackTrace_lang(Exception e) {
String_bldr sb = String_bldr_.new_();
StackTraceElement[] stackTraceAry = e.getStackTrace();

View File

@ -212,7 +212,8 @@ public class Bry_ {
}
public static byte[] Mid_by_len(byte[] src, int bgn, int len) {return Mid(src, bgn, bgn + len);}
public static byte[] Mid_by_len_safe(byte[] src, int bgn, int len) {
if (len > src.length) len = src.length;
int src_len = src.length;
if (len + bgn > src_len) len = (src_len - bgn);
return Mid(src, bgn, bgn + len);
}
public static String MidByLenToStr(byte[] src, int bgn, int len) {

View File

@ -123,6 +123,7 @@ public class Bry_bfr {
public Bry_bfr Add_byte_pipe() {return Add_byte(Byte_ascii.Pipe);}
public Bry_bfr Add_byte_comma() {return Add_byte(Byte_ascii.Comma);}
public Bry_bfr Add_byte_apos() {return Add_byte(Byte_ascii.Apos);}
public Bry_bfr Add_byte_slash() {return Add_byte(Byte_ascii.Slash);}
public Bry_bfr Add_byte_backslash() {return Add_byte(Byte_ascii.Backslash);}
public Bry_bfr Add_byte_quote() {return Add_byte(Byte_ascii.Quote);}
public Bry_bfr Add_byte_space() {return Add_byte(Byte_ascii.Space);}

View File

@ -70,8 +70,10 @@ public class Byte_ascii {
;
}
public static final byte[]
Dot_bry = new byte[] {Byte_ascii.Dot}
Tab_bry = new byte[] {Byte_ascii.Tab}
, NewLine_bry = new byte[] {Byte_ascii.NewLine}
, Dot_bry = new byte[] {Byte_ascii.Dot}
, Comma_bry = new byte[] {Byte_ascii.Comma}
, Colon_bry = new byte[] {Byte_ascii.Colon}
, Lt_bry = new byte[] {Byte_ascii.Lt}
, Gt_bry = new byte[] {Byte_ascii.Gt}

View File

@ -39,7 +39,7 @@ public class Double_ {
int v_as_int = (int)v;
return v == v_as_int
? Int_.XtoStr(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places
: String.format("%g", v); // call "%g" format which should eliminate most, though not all; EX:2449.6000000000004; DATE:2014-07-14
: Float_.XtoStr((float)v); // calling ((float)v).toString is better at removing trailing 0s than String.format("%g", v). note that .net .toString() handles it better; EX:2449.600000000000d; DATE:2014-07-29
}
public static double cast_(Object o) {try {return (Double)o;} catch(Exception e) {throw Err_.type_mismatch_exc_(e, double.class, o);}}
public static double parse_(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.parse_type_exc_(e, double.class, raw);}}

View File

@ -15,12 +15,15 @@ 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.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.xowa.html.modules.popups.*;
public class Xow_module_mgr {
public Xow_module_mgr(Xow_wiki wiki) {this.popup_mgr = new Xow_popup_mgr(wiki);}
public void Init_by_wiki(Xow_wiki wiki) {
popup_mgr.Init_by_wiki(wiki);
package gplx;
import org.junit.*;
public class Double__tst {
private Double__fxt fxt = new Double__fxt();
@Test public void Xto_str_loose() {
fxt.Test_Xto_str_loose(2449.6000000d , "2449.6");
fxt.Test_Xto_str_loose(623.700d , "623.7");
}
public Xow_popup_mgr Popup_mgr() {return popup_mgr;} private Xow_popup_mgr popup_mgr;
}
class Double__fxt {
public void Test_Xto_str_loose(double v, String expd) {Tfds.Eq(expd, Double_.Xto_str_loose(v));}
}

View File

@ -27,7 +27,7 @@ public class Object__tst {
}
@Test public void Xto_str_loose_or_null() {
fxt.Test_xto_str_loose_or_null(null, null);
fxt.Test_xto_str_loose_or_null(2449.6000000000004d, "2449.60");
fxt.Test_xto_str_loose_or_null(2449.6000000000004d, "2449.6");
}
}
class Object__fxt {

View File

@ -392,8 +392,10 @@ public class IoEngine_system extends IoEngine_base {
Io_download_fmt xfer_fmt = xrg.Download_fmt();
prog_dlg = xfer_fmt.usr_dlg;
if (!Web_access_enabled) {
if (prog_dlg != null) {
if (session_fil == null) session_fil = prog_dlg.Log_wtr().Session_dir().GenSubFil("internet.txt");
if (prog_dlg != null) prog_dlg.Log_wtr().Log_msg_to_url_fmt(session_fil, "download disabled: src='~{0}' trg='~{1}'", xrg.Src(), xrg.Trg().Raw());
prog_dlg.Log_wtr().Log_msg_to_url_fmt(session_fil, "download disabled: src='~{0}' trg='~{1}'", xrg.Src(), xrg.Trg().Raw());
}
return false;
}
try {

View File

@ -21,6 +21,9 @@ public class IoEngine_xrg_downloadFil {
public Io_url Trg() {return trg;} public IoEngine_xrg_downloadFil Trg_(Io_url v) {trg = v; return this;} Io_url trg;
public byte Rslt() {return rslt;} public IoEngine_xrg_downloadFil Rslt_(byte v) {rslt = v; return this;} private byte rslt = Rslt_pass;
public Exception Rslt_err() {return rslt_err;} public IoEngine_xrg_downloadFil Rslt_err_(Exception v) {rslt_err = v; return this;} Exception rslt_err;
public String Rslt_err_str() {
return rslt_err == null ? "none" : Err_.Message_gplx_brief(rslt_err);
}
public String User_agent() {return user_agent;} public IoEngine_xrg_downloadFil User_agent_(String v) {user_agent = v; return this;} private String user_agent;
public Gfo_usr_dlg Prog_dlg() {return prog_dlg;} public IoEngine_xrg_downloadFil Prog_dlg_(Gfo_usr_dlg v) {prog_dlg = v; download_fmt.Ctor(prog_dlg); return this;} Gfo_usr_dlg prog_dlg;
public Bry_fmtr Prog_fmtr() {return prog_fmtr;} Bry_fmtr prog_fmtr = Bry_fmtr.new_("~{download_header}: ~{download_read} of ~{download_length} kb;", "download_header", "download_url", "download_read", "download_length");

View File

@ -32,4 +32,5 @@ public interface Gfo_usr_dlg extends GfoInvkAble, Cancelable {
String Prog_one(String grp_key, String msg_key, String fmt, Object arg);
String Prog_direct(String msg);
String Log_direct(String msg);
String Plog_many(String grp_key, String msg_key, String fmt, Object... args);
}

View File

@ -37,6 +37,7 @@ class Gfo_usr_dlg_null implements Gfo_usr_dlg {
public String Prog_one(String grp_key, String msg_key, String fmt, Object arg) {return "";}
public String Prog_direct(String msg) {return "";}
public String Log_direct(String msg) {return "";}
public String Plog_many(String grp_key, String msg_key, String fmt, Object... args) {return "";}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
public static final Gfo_usr_dlg_null _ = new Gfo_usr_dlg_null(); Gfo_usr_dlg_null() {}
}

View File

@ -59,11 +59,10 @@ public class Sqlite_engine_ {
int len = idxs.length;
p.Txn_mgr().Txn_end_all(); // commit any pending transactions
for (int i = 0; i < len; i++) {
p.Txn_mgr().Txn_bgn_if_none();
String index = idxs[i].Xto_sql();
usr_dlg.Prog_many("", "", "creating index: ~{0} ~{1}", file_id, index);
usr_dlg.Plog_many("", "", "creating index: ~{0} ~{1}", file_id, index);
p.Exec_qry(Db_qry_sql.ddl_(index));
p.Txn_mgr().Txn_end_all();
usr_dlg.Log_many("", "", "index created: ~{0} ~{1}", file_id, index);
}
}
public static Db_provider Provider_load_or_fail_(Io_url url) {

View File

@ -25,6 +25,7 @@ import java.sql.*;
public class SqliteDbMain {
public static void main(String[] args) throws Exception {
SqliteDbMain main = new SqliteDbMain();
// main.JdbcInit(args);
// main.Read();
// main.Mass_upload(Io_url_.new_dir_("J:\\gplx\\xowl\\file\\all#meta\\en.wikipedia.org\\"));
// main.CreateMany(20, 0);
@ -38,6 +39,15 @@ public class SqliteDbMain {
'5719' '174'
'5766' '173'
*/
// private void JdbcInit(String[] args) {
// try {
// Class.forName("SQLite.JDBCDriver");
// }
// catch (Exception e) {
// ConsoleAdp._.WriteLine(e.getMessage());
// }
// }
private void CreateMany(int number, int base_val) {
long time_bgn = Env_.TickCount();
Db_provider provider = Sqlite_engine_.Provider_load_or_make_(Io_url_.new_fil_("E:\\test.sqlite3"));

View File

@ -24,10 +24,12 @@ public abstract class Dsv_wkr_base implements GfoInvkAble {
public void Load_by_bry(byte[] src) {
Dsv_tbl_parser tbl_parser = new Dsv_tbl_parser(); // NOTE: this proc should only be called once, so don't bother caching tbl_parser
tbl_parser.Init(this, this.Fld_parsers());
Load_by_bry_bgn();
tbl_parser.Parse(src);
tbl_parser.Rls();
Load_by_bry_end();
}
@gplx.Virtual public void Load_by_bry_bgn() {}
@gplx.Virtual public void Load_by_bry_end() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_load_by_str)) Load_by_bry(m.ReadBry("v"));

View File

@ -23,7 +23,7 @@ public class Xoa_app_ {
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "1.7.4.1";
public static final String Version = "1.8.1.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";
@ -35,7 +35,7 @@ public class Xoa_app_ {
rv.Log_wtr().Queue_enabled_(true);
return rv;
}
public static final byte Mode_console = 0, Mode_gui = 1;
public static final byte Mode_console = 0, Mode_gui = 1, Mode_http = 2;
}
class Xoa_app_boot_mgr {
private Gfo_usr_dlg usr_dlg; private Gfo_log_wtr log_wtr; private String chkpoint = "null";
@ -144,6 +144,7 @@ class Xoa_app_boot_mgr {
app.Gui_wtr().Log_wtr_(app.Log_wtr()); // NOTE: log_wtr must be set for cmd-line (else process will fail);
// run gfs
gplx.xowa.users.prefs.Prefs_rename_mgr._.Check(app.User().Fsys_mgr().App_data_cfg_user_fil());
try {app.Gfs_mgr().Run_url(cmd_file); chkpoint = "run_url";}
catch (Exception e) {
usr_dlg.Warn_many("", "", "script file failed: ~{0} ~{1} ~{2}", chkpoint, cmd_file.Raw(), Err_.Message_gplx(e));
@ -155,8 +156,10 @@ class Xoa_app_boot_mgr {
app.Launch(); chkpoint = "launch";
if (String_.Eq(app_mode, "server"))
app.Tcp_server().Run();
else if (String_.Eq(app_mode, "http_server"))
else if (String_.Eq(app_mode, "http_server")) {
app.Mode_(Xoa_app_.Mode_http);
app.Http_server().Run();
}
else {
if (cmd_text != null)
ConsoleAdp._.WriteLine_utf8(Object_.Xto_str_strict_or_empty(app.Gfs_mgr().Run_str(cmd_text)));

View File

@ -25,11 +25,13 @@ public class Xoapi_html implements GfoInvkAble {
public Xoapi_tidy Tidy() {return tidy;} private Xoapi_tidy tidy = new Xoapi_tidy();
public Xoapi_modules Modules() {return modules;} private Xoapi_modules modules = new Xoapi_modules();
public Xoapi_skins Skins() {return skins;} private Xoapi_skins skins = new Xoapi_skins();
public Xoapi_page Page() {return page;} private Xoapi_page page = new Xoapi_page();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tidy)) return tidy;
else if (ctx.Match(k, Invk_modules)) return modules;
else if (ctx.Match(k, Invk_skins)) return skins;
else if (ctx.Match(k, Invk_page)) return page;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_tidy = "tidy", Invk_modules = "modules", Invk_skins = "skins";
private static final String Invk_tidy = "tidy", Invk_modules = "modules", Invk_skins = "skins", Invk_page = "page";
}

View File

@ -0,0 +1,27 @@
/*
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.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.core.btries.*;
public class Xoapi_page implements GfoInvkAble {
public Xoapi_toggle_mgr Toggle_mgr() {return toggle_mgr;} private Xoapi_toggle_mgr toggle_mgr = new Xoapi_toggle_mgr();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_toggles)) return toggle_mgr;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_toggles = "toggles";
}

View File

@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
public class Xoapi_toggle_itm implements GfoInvkAble {
public Xoapi_toggle_itm(byte[] key_bry) {this.key_bry = key_bry;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Icon_src() {return icon_src;} private byte[] icon_src;
public byte[] Icon_title() {return icon_title;} private byte[] icon_title;
public byte[] Elem_display() {return elem_display;} private byte[] elem_display;
public boolean Visible() {return visible;} private boolean visible;
public Xoapi_toggle_itm Init(Xow_wiki wiki) {
if (Img_src_y == null) {
Io_url img_dir = wiki.App().User().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "portal");
Img_src_y = img_dir.GenSubFil("twisty_down.png").To_http_file_bry();
Img_src_n = img_dir.GenSubFil("twisty_right.png").To_http_file_bry();
}
icon_src = visible ? Img_src_y : Img_src_n;
byte[] img_title_msg = visible ? Img_title_msg_y : Img_title_msg_n;
icon_title = wiki.Msg_mgr().Val_by_key_obj(img_title_msg);
elem_display = visible ? Img_display_y : Img_display_n;
return this;
}
private static byte[] Img_src_y, Img_src_n;
private static final byte[]
Img_title_msg_y = Bry_.new_ascii_("hide"), Img_title_msg_n = Bry_.new_ascii_("show")
, Img_display_y = Bry_.new_ascii_("display:;"), Img_display_n = Bry_.new_ascii_("display:none;")
;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_visible)) return Yn.Xto_str(visible);
else if (ctx.Match(k, Invk_visible_)) visible = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_visible = "visible", Invk_visible_ = "visible_";
}

View File

@ -0,0 +1,51 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.cfgs.*;
public class Xoapi_toggle_mgr implements GfoInvkAble {
private Hash_adp_bry itms = Hash_adp_bry.cs_();
public Xoapi_toggle_mgr() {
itm_wikidata_langs = itms_add(itms, Key_wikidata_langs);
itm_offline_wikis = itms_add(itms, Key_offline_wikis);
}
public Xoapi_toggle_itm Itm_wikidata_langs() {return itm_wikidata_langs;} private Xoapi_toggle_itm itm_wikidata_langs;
public Xoapi_toggle_itm Itm_offline_wikis() {return itm_offline_wikis;} private Xoapi_toggle_itm itm_offline_wikis;
public Xoapi_toggle_itm Get(byte[] key) {return (Xoapi_toggle_itm)itms.Get_by_bry(key);}
public void Save(Xoa_cfg_mgr cfg_mgr) {
Save_itm(cfg_mgr, itm_wikidata_langs, itm_offline_wikis);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return this.Get(m.ReadBry("key"));
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_get = "get";
private static final String Key_wikidata_langs = "wikidata-langs", Key_offline_wikis = "offline-wikis";
private static Xoapi_toggle_itm itms_add(Hash_adp_bry itms, String name_str) {
byte[] name_bry = Bry_.new_utf8_(name_str);
Xoapi_toggle_itm rv = new Xoapi_toggle_itm(name_bry);
itms.Add(name_bry, rv);
return rv;
}
private static void Save_itm(Xoa_cfg_mgr cfg_mgr, Xoapi_toggle_itm... itms) {
int itms_len = itms.length;
for (int i = 0; i < itms_len; ++i) {
Xoapi_toggle_itm itm = itms[i];
cfg_mgr.Set_by_app("xowa.api.html.page.toggles.get('" + String_.new_utf8_(itm.Key_bry()) + "').visible", Yn.Xto_str(itm.Visible()));
}
}
}

View File

@ -58,6 +58,7 @@ public class Xob_cmd_mgr implements GfoInvkAble {
else if (String_.Eq(cmd_key, Xof_wiki_orig_cmd.KEY_oimg)) return Add(new Xof_wiki_orig_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_download_wkr.KEY_oimg)) return Add(new Xob_download_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_page_regy_cmd.KEY_oimg)) return Add(new Xob_page_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_exec_sql.KEY)) return Add(new Xob_cmd_exec_sql(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_wiki_redirect_cmd.KEY_redirect)) return Add(new Xob_wiki_redirect_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_wiki_image_sql.KEY)) return Add(new Xob_wiki_image_sql(bldr, wiki));

View File

@ -0,0 +1,38 @@
/*
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.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
public class Db_idx_mode {
private int tid;
Db_idx_mode(int tid) {this.tid = tid;}
public boolean Tid_is_bgn() {return tid == Tid_bgn;}
public boolean Tid_is_end() {return tid == Tid_end;}
public boolean Tid_is_skip() {return tid == Tid_skip;}
private static final int Tid_skip = 0, Tid_bgn = 1, Tid_end = 2;
private static final String Key_skip = "skip", Key_bgn = "bgn", Key_end = "end";
public static final Db_idx_mode
Itm_skip = new Db_idx_mode(Tid_skip)
, Itm_bgn = new Db_idx_mode(Tid_bgn)
, Itm_end = new Db_idx_mode(Tid_end)
;
public static Db_idx_mode Xto_itm(String key) {
if (String_.Eq(key, Key_skip)) return Itm_skip;
else if (String_.Eq(key, Key_bgn)) return Itm_bgn;
else if (String_.Eq(key, Key_end)) return Itm_end;
else throw Err_.unhandled(key);
}
}

View File

@ -0,0 +1,43 @@
/*
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.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.xowa.dbs.*;
public class Xob_cmd_exec_sql implements Xob_cmd {
private Xow_wiki wiki; private int file_idx = -1; private String sql;
public Xob_cmd_exec_sql(Xob_bldr bldr, Xow_wiki wiki) {this.wiki = wiki;}
public String Cmd_key() {return KEY;} public static final String KEY = "import.sql.exec_sql";
public void Cmd_ini(Xob_bldr bldr) {}
public void Cmd_bgn(Xob_bldr bldr) {
Xoa_app app = wiki.App();
wiki.Init_assert(); // force load; needed to pick up MediaWiki ns for MediaWiki:mainpage
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql();
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
Xodb_file file = fsys_mgr.Get_by_db_idx(file_idx);
app.Usr_dlg().Plog_many("", "", "exec_sql: running sql; file_idx=~{0} sql=~{1}", file_idx, sql);
file.Provider().Exec_sql(sql);
}
public void Cmd_run() {}
public void Cmd_end() {}
public void Cmd_print() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_file_idx_)) file_idx = m.ReadInt("v");
else if (ctx.Match(k, Invk_sql_)) sql = m.ReadStr("v");
return this;
}
private static final String Invk_file_idx_ = "file_idx_", Invk_sql_ = "sql_";
}

View File

@ -35,7 +35,7 @@ public abstract class Xob_init_base implements Xob_cmd, GfoInvkAble {
this.Cmd_run_end(wiki); // save site info
}
public void Cmd_end() {
wiki.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_refresh(); // dirty wiki list so that next refresh will load itm
wiki.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_reset(); // dirty wiki list so that next refresh will load itm
if (wiki.App().Setup_mgr().Dump_mgr().Css_wiki_update()) {
Io_url url = wiki.App().User().Fsys_mgr().Wiki_html_dir(wiki.Domain_str()).GenSubFil(Xoa_css_extractor.Css_wiki_name);
usr_dlg.Log_many("", "", "deleting css: ~{0}", url.Raw());

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.ios.*;
public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInvkAble {
private Db_idx_mode idx_mode = Db_idx_mode.Itm_end;
private Xop_redirect_mgr redirect_mgr; private Io_stream_zip_mgr zip_mgr; private byte data_storage_format;
private Xodb_mgr_sql db_mgr; private Xodb_fsys_mgr fsys_mgr; private Db_provider page_provider; private Db_stmt page_stmt; private Xob_text_stmts_mgr text_stmts_mgr;
private int page_count_all, page_count_main = 0; private int txn_commit_interval = 100000; // 100 k
@ -40,6 +41,7 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
page_stmt = db_mgr.Tbl_page().Insert_stmt(page_provider);
page_provider.Txn_mgr().Txn_bgn_if_none();
text_stmts_mgr = new Xob_text_stmts_mgr(db_mgr, fsys_mgr);
if (idx_mode.Tid_is_bgn()) Idx_create();
}
public void Wkr_run(Xodb_page page) {
int page_id = page.Id();
@ -69,25 +71,33 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
if (page_count_all % txn_commit_interval == 0) text_stmt.Provider().Txn_mgr().Txn_end_all_bgn_if_none();
}
public void Wkr_end() {
usr_dlg.Log_many("", "", "import.page: insert done; committing pages; pages=~{0}", page_count_all);
page_provider.Txn_mgr().Txn_end_all();
page_stmt.Rls();
text_stmts_mgr.Rls();
usr_dlg.Log_many("", "", "import.page: updating core stats");
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
db_mgr.Tbl_site_stats().Update(page_count_main, page_count_all, ns_mgr.Ns_file().Count()); // save page stats
db_mgr.Tbl_xowa_ns().Insert(ns_mgr); // save ns
db_mgr.Tbl_xowa_db().Commit_all(page_provider, db_mgr.Fsys_mgr().Ary()); // save dbs; note that dbs can be saved again later
db_mgr.Tbl_xowa_cfg().Insert_str(Xodb_mgr_sql.Grp_wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_text), Index_page_title, Index_page_random);
if (idx_mode.Tid_is_end()) Idx_create();
}
private void Idx_create() {
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_text), Idx_page_title, Idx_page_random);
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_txn_commit_interval_)) txn_commit_interval = m.ReadInt("v");
return super.Invk(ctx, ikey, k, m);
} private static final String Invk_txn_commit_interval_ = "txn_commit_interval_";
else if (ctx.Match(k, Invk_idx_mode_)) idx_mode = Db_idx_mode.Xto_itm(m.ReadStr("v"));
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk_txn_commit_interval_ = "txn_commit_interval_", Invk_idx_mode_ = "idx_mode_";
public void Wkr_ini(Xob_bldr bldr) {}
public void Wkr_print() {}
private static final Db_idx_itm
Index_page_title = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS page__title ON page (page_namespace, page_title, page_id, page_len, page_is_redirect);") // PERF:page_id for general queries; PERF: page_len for search_suggest; PREF:page_is_redirect for oimg
, Index_page_random = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS page__name_random ON page (page_namespace, page_random_int);")
Idx_page_title = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS page__title ON page (page_namespace, page_title, page_id, page_len, page_is_redirect);") // PERF:page_id for general queries; PERF: page_len for search_suggest; PREF:page_is_redirect for oimg
, Idx_page_random = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS page__name_random ON page (page_namespace, page_random_int);")
;
}
class Xob_text_stmts_mgr {

View File

@ -18,9 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import org.junit.*; import gplx.dbs.*; import gplx.xowa.specials.search.*; import gplx.xowa.bldrs.imports.ctgs.*;
public class Xob_page_sql_tst {
@Before public void init() {fxt.Ctor_fsys();} Db_mgr_fxt fxt = new Db_mgr_fxt();
@After public void term() {fxt.Rls();}
@Before public void init() {if (Xoa_test_.Db_skip()) return; fxt.Ctor_fsys();} Db_mgr_fxt fxt = new Db_mgr_fxt();
@After public void term() {if (Xoa_test_.Db_skip()) return; fxt.Rls();}
@Test public void Basic() {
if (Xoa_test_.Db_skip()) return;
fxt.Init_db_sqlite();
fxt.doc_ary_
( fxt.doc_(2, "2013-06-03 01:23", "A", "text_a")

View File

@ -26,7 +26,7 @@ public abstract class Xob_term_base implements Xob_cmd, GfoInvkAble {
public void Cmd_run() {}
public void Cmd_end() {
Xoa_app app = wiki.App();
app.Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_refresh(); // NOTE: dirty wiki list so that next refresh will load itm
app.Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_reset(); // NOTE: dirty wiki list so that next refresh will load itm
app.Free_mem(false); // clear cache, else import will load new page with old items from cache; DATE:2013-11-21
wiki.Init_needed_(true);// flag init_needed prior to show; dir_info will show page_txt instead of page_gz;
wiki.Init_assert(); // force load; needed to pick up MediaWiki ns for MediaWiki:mainpage

View File

@ -18,8 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import org.junit.*;
public class Xob_category_registry_sql_tst {
@Before public void init() {fxt.Clear();} private Xob_category_registry_sql_fxt fxt = new Xob_category_registry_sql_fxt();
@Before public void init() {if (Xoa_test_.Db_skip()) return; fxt.Clear();} private Xob_category_registry_sql_fxt fxt = new Xob_category_registry_sql_fxt();
@Test public void Basic() {
if (Xoa_test_.Db_skip()) return;
fxt.Init_page_insert(String_.Ary("Ctg3", "Ctg2", "Ctg1"));
fxt.Exec_category_registry_cmd();
fxt.Test_ids(Int_.Ary(3, 2, 1)); // note that Ctg1 is page_id 3

View File

@ -18,9 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.ios.*;
public class Xob_categorylinks_sql extends Xob_categorylinks_base {
private Db_idx_mode idx_mode = Db_idx_mode.Itm_end;
public Xob_categorylinks_sql(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki); this.make_fil_len = Io_mgr.Len_mb;}
@Override public String Cmd_key() {return KEY;} public static final String KEY = "import.sql.categorylinks";
@Override public Io_sort_cmd Make_sort_cmd(Sql_file_parser sql_parser) {return new Xob_categorylinks_sql_make(sql_parser, wiki);}
@Override public Io_sort_cmd Make_sort_cmd(Sql_file_parser sql_parser) {return new Xob_categorylinks_sql_make(sql_parser, wiki, idx_mode);}
public static final String Tbl_categorylinks = String_.Concat_lines_nl
( "CREATE TABLE `categorylinks` ("
, " `cl_from` int(10) unsigned NOT NULL DEFAULT '0',"
@ -33,4 +34,10 @@ public class Xob_categorylinks_sql extends Xob_categorylinks_base {
, " UNIQUE KEY `cl_from` (`cl_from`,`cl_to`),"
, ");"
);
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_idx_mode_)) idx_mode = Db_idx_mode.Xto_itm(m.ReadStr("v"));
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk_idx_mode_ = "idx_mode_";
}

View File

@ -18,7 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.core.flds.*; import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.ctgs.*;
public class Xob_categorylinks_sql_make implements Io_make_cmd {
public Xob_categorylinks_sql_make(Sql_file_parser sql_parser, Xow_wiki wiki) {this.wiki = wiki; this.sql_parser = sql_parser;} private Xow_wiki wiki; Xodb_mgr_sql db_mgr; Sql_file_parser sql_parser;
private Xow_wiki wiki; private Sql_file_parser sql_parser; private Db_idx_mode idx_mode;
private Xodb_mgr_sql db_mgr;
public Xob_categorylinks_sql_make(Sql_file_parser sql_parser, Xow_wiki wiki, Db_idx_mode idx_mode) {
this.wiki = wiki; this.sql_parser = sql_parser; this.idx_mode = idx_mode;
}
public Io_sort_cmd Make_dir_(Io_url v) {return this;}
public void Sort_bgn() {
usr_dlg = wiki.App().Usr_dlg();
@ -38,6 +42,7 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
ctg_stmt = db_mgr.Tbl_category().Insert_stmt(cat_provider);
File_open(category_file);
first_provider = true;
if (idx_mode.Tid_is_bgn()) Idx_create(fsys_mgr);
} Db_provider cl_provider, cat_provider; Gfo_fld_rdr fld_rdr = Gfo_fld_rdr.xowa_(); Db_stmt cl_stmt = Db_stmt_.Null, ctg_stmt = Db_stmt_.Null; int row_count = 0; Gfo_usr_dlg usr_dlg; boolean first_provider;
int[] cur_cat_counts = new int[Xoa_ctg_mgr.Tid__max]; long cur_cat_file_size, cur_cat_file_max; byte[] cur_cat_ttl = Ttl_first; int cur_cat_id; int cur_cat_file_idx;
public byte Line_dlm() {return line_dlm;} public Xob_categorylinks_sql_make Line_dlm_(byte v) {line_dlm = v; return this;} private byte line_dlm = Byte_ascii.Nil;
@ -68,13 +73,17 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Core_provider(), fsys_mgr.Ary());
if (db_mgr.Category_version() == Xoa_ctg_mgr.Version_null) // NOTE: ctg_v1 wkr will set this to v1; only set to v2 if null
db_mgr.Category_version_update(false);
usr_dlg.Log_many("", "", "import.category.v2: insert done; committing; rows=~{0}", row_count);
cat_provider.Txn_mgr().Txn_end_all();
ctg_stmt.Rls();
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_category), Index_categorylinks_from, Index_categorylinks_main);
if (idx_mode.Tid_is_end()) Idx_create(fsys_mgr);
name_id_rdr.Rls();
if (String_.Eq(sql_parser.Src_fil().NameAndExt(), Xob_ctg_v1_sql_make.Url_sql)) // delete temp xowa_categorylinks.sql file created by cat_v1
Io_mgr._.DeleteFil(sql_parser.Src_fil());
}
private void Idx_create(Xodb_fsys_mgr fsys_mgr) {
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_category), Idx_categorylinks_from, Idx_categorylinks_main);
}
int Ctg_grp_end(byte[] new_ctg_ttl) {
if (cur_cat_ttl != Bry_.Empty && cur_cat_id != -1)
db_mgr.Tbl_category().Insert(ctg_stmt, cur_cat_id, cur_cat_counts[Xoa_ctg_mgr.Tid_page], cur_cat_counts[Xoa_ctg_mgr.Tid_subc], cur_cat_counts[Xoa_ctg_mgr.Tid_file], Xoa_ctg_mgr.Hidden_n, cur_cat_file_idx);
@ -131,8 +140,8 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
} Io_line_rdr name_id_rdr;
private static final byte[] Ttl_last = null, Ttl_first = Bry_.Empty;
private static final Db_idx_itm
Index_categorylinks_main = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS categorylinks__cl_main ON categorylinks (cl_to_id, cl_type_id, cl_sortkey, cl_from);")
, Index_categorylinks_from = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS categorylinks__cl_from ON categorylinks (cl_from);")
Idx_categorylinks_main = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS categorylinks__cl_main ON categorylinks (cl_to_id, cl_type_id, cl_sortkey, cl_from);")
, Idx_categorylinks_from = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS categorylinks__cl_from ON categorylinks (cl_from);")
;
}
/*

View File

@ -97,7 +97,7 @@ public class Xodb_fsys_mgr {
for (int i = 0; i < files_ary_len; i++) {
Xodb_file file = files_ary[i];
if (Byte_.In(file.Tid(), tids))
Xodb_fsdb_mgr_.Index_create(usr_dlg, file, idxs);
Sqlite_engine_.Idx_create(usr_dlg, file.Provider(), Int_.XtoStr(file.Id()), idxs);
}
}
public void Overwrite(int file_idx) {Create_sqlite3(src_dir, trg_dir, trg_name, file_idx);}
@ -130,17 +130,3 @@ public class Xodb_fsys_mgr {
public static final int Heap_max_infinite = 0;
public static final long Max_core_db = -1;
}
class Xodb_fsdb_mgr_ {
public static void Index_create(Gfo_usr_dlg usr_dlg, Xodb_file file, Db_idx_itm[] idxs) {
Db_provider provider = file.Provider();
provider.Txn_mgr().Txn_end_all(); // commit any pending transactions
int len = idxs.length;
for (int i = 0; i < len; i++) {
provider.Txn_mgr().Txn_bgn_if_none();
String index = idxs[i].Xto_sql();
usr_dlg.Prog_many("", "", "creating index: ~{0} ~{1}", file.Id(), index);
provider.Exec_sql(index);
provider.Txn_mgr().Txn_end_all();
}
}
}

View File

@ -18,8 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.bldrs.*; import gplx.xowa.ctgs.*; import gplx.dbs.*; import gplx.xowa.dbs.tbls.*;
public class Xodb_load_mgr_sql_tst {
@Before public void init() {fxt.Clear();} private Xodb_load_mgr_sql_fxt fxt = new Xodb_load_mgr_sql_fxt();
@Before public void init() {if (Xoa_test_.Db_skip()) return; fxt.Clear();} private Xodb_load_mgr_sql_fxt fxt = new Xodb_load_mgr_sql_fxt();
@Test public void Load_ctg_ttls() {
if (Xoa_test_.Db_skip()) return;
Xodb_page[] ctgs = fxt.pages_
( fxt.ctg_(1, "Ctg_1", Bool_.Y, 10, 11, 12)
, fxt.ctg_(2, "Ctg_2", Bool_.N, 20, 21, 22)

View File

@ -0,0 +1,101 @@
/*
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
class Hdump_data_mgr {
// private Xow_wiki wiki;
// public void Init_by_wiki(Xow_wiki wiki) {this.wiki = wiki;}
public void Select(int ns_id, Hdump_page_row page, int page_id) {
Hdump_db db = Get_db(ns_id, page_id);
// int reg =
db.Page_tbl().Select(null, page, page_id);
// db.Frag_tbl().Select(list, 1);
// page.Frags_(list.XtoAry());
}
public void Insert(int ns_id, Hdump_page_row page) {
byte[] page_html = page.Page_html();
int page_html_len = page_html.length;
Hdump_db db = Get_db(ns_id, page_html_len);
Hdump_frag_row[] frags = page.Frags();
int frags_len = frags.length;
db.Page_tbl().Insert(page.Page_id(), page.Page_html(), frags_len, 1);
Hdump_frag_tbl frag_tbl = db.Frag_tbl();
for (int i = 0; i < frags_len; ++i) {
Hdump_frag_row frag = frags[i];
frag_tbl.Insert(null, frag.Frag_id(), page.Page_id(), frag.Frag_tid(), frag.Frag_key(), frag.Frag_text());
}
}
public void Update() {
}
private Hdump_db Get_db(int ns_id, int len) {return null;}
}
class Hdump_db {
public Io_url Db_url() {return db_url;} private Io_url db_url = Io_url_.Null;
public void Txn_bgn() {}
public void Txn_end() {}
public void Rls() {}
public Hdump_page_tbl Page_tbl() {return page_tbl;} private Hdump_page_tbl page_tbl = new Hdump_page_tbl();
public Hdump_frag_tbl Frag_tbl() {return frag_tbl;} private Hdump_frag_tbl frag_tbl = new Hdump_frag_tbl();
}
class Hdump_bldr {
public byte[] Do_this() {
// SELECT * FROM page_id
return null;
}
}
class Hdump_rdr {
public void Read(Hdump_page page, Hdump_text_itm[] itms) {
int len = itms.length;
for (int i = 0; i < len; ++i) {
Hdump_text_itm itm = itms[i];
switch (itm.Tid()) {
case Hdump_text_tid.Tid_page: Read_page(page, itm); break;
case Hdump_text_tid.Tid_file: break;
}
}
}
public void Read_page(Hdump_page page, Hdump_text_itm itm) {
page.Version_id_(Bry_.Xto_int(itm.Args()));
page.Html_(itm.Text());
}
public void Read_file(Hdump_page page, Hdump_text_itm file) {
//byte[][] args = null;
}
}
class Hdump_page {
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
public byte[] Html() {return html;} public void Html_(byte[] v) {html = v;} private byte[] html;
public void Generate() {
// swap in each file
// add skin
// swap in display title, content_sub, menu
}
}
class Hdump_itm_file {
public byte[] Ttl() {return ttl;} private byte[] ttl;
public void Init(byte[][] ary) {
ttl = ary[0];
}
}
class Hdump_text_itm {
public int Tid() {return tid;} public void Tid_(int v) {tid = v;} private int tid;
public byte[] Args() {return args;} public void Args_(byte[] v) {args = v;} private byte[] args;
public byte[] Text() {return text;} public void Text_(byte[] v) {text = v;} private byte[] text;
}
class Hdump_text_tid {
public static final int Tid_page = 0, Tid_file = 1, Tid_display = 2, Tid_content_sub = 3, Tid_sidebar = 4;
}

View File

@ -22,6 +22,7 @@ public class Hdump_page_row {
public byte[] Page_html() {return page_html;} private byte[] page_html;
public int Frags_len() {return frags_len;} private int frags_len;
public int Make_id() {return make_id;} private int make_id;
public Hdump_frag_row[] Frags() {return frags;} public void Frags_(Hdump_frag_row[] frags) {this.frags = frags;} private Hdump_frag_row[] frags;
public Hdump_page_row Ctor(int page_id, byte[] page_html, int frags_len, int make_id) {
this.page_id = page_id;
this.page_html = page_html;

View File

@ -18,9 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*; import gplx.ios.*;
public class Hdump_page_tbl {
private Db_provider provider;
private Db_stmt stmt_select, stmt_insert, stmt_update, stmt_delete;
private Io_stream_zip_mgr zip_mgr; private byte zip_tid;
public void Ctor(Io_stream_zip_mgr zip_mgr, byte zip_tid) {this.zip_mgr = zip_mgr; this.zip_tid = zip_tid;}
public void Ctor(Db_provider provider, Io_stream_zip_mgr zip_mgr, byte zip_tid) {this.provider = provider; this.zip_mgr = zip_mgr; this.zip_tid = zip_tid;}
@gplx.Virtual public void Insert(int page_id, byte[] page_html, int frags_len, int make_id) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
try {
page_html = zip_mgr.Zip(zip_tid, page_html);
stmt_insert.Val_int_(page_id).Val_str_by_bry_(page_html).Val_int_(frags_len).Val_int_(make_id).Exec_insert();
} finally {stmt_insert.Rls();}
}
@gplx.Virtual public void Insert(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
try {

View File

@ -19,8 +19,8 @@ package gplx.xowa.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.
import gplx.dbs.*;
public class Xodb_search_title_page_tbl {
public static void Create_table(Db_provider p) {Sqlite_engine_.Tbl_create(p, Tbl_name, Tbl_sql);}
public static void Create_index_unique(Gfo_usr_dlg usr_dlg, Db_provider p) {Sqlite_engine_.Idx_create(usr_dlg, p, "search", Indexes_main_unique);}
public static void Create_index_non_unique(Gfo_usr_dlg usr_dlg, Db_provider p) {Sqlite_engine_.Idx_create(usr_dlg, p, "search", Indexes_main_non_unique);}
public static void Create_index_unique(Gfo_usr_dlg usr_dlg, Db_provider p) {Sqlite_engine_.Idx_create(usr_dlg, p, "search", Idx_main_unique);}
public static void Create_index_non_unique(Gfo_usr_dlg usr_dlg, Db_provider p) {Sqlite_engine_.Idx_create(usr_dlg, p, "search", Idx_main_non_unique);}
public static Db_stmt Insert_stmt(Db_provider p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_stp_word_id, Fld_stp_page_id);}
public static void Insert(Db_stmt stmt, int word_id, int page_id) {
stmt.Clear()
@ -36,7 +36,7 @@ public class Xodb_search_title_page_tbl {
, ");"
);
private static final Db_idx_itm
Indexes_main_unique = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS search_title_page__main ON search_title_page (stp_word_id, stp_page_id);")
, Indexes_main_non_unique = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS search_title_page__main ON search_title_page (stp_word_id, stp_page_id);")
Idx_main_unique = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS search_title_page__main ON search_title_page (stp_word_id, stp_page_id);")
, Idx_main_non_unique = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS search_title_page__main ON search_title_page (stp_word_id, stp_page_id);")
;
}

View File

@ -172,9 +172,10 @@ public class Xog_html_js_cbk implements GfoInvkAble {
if (ctx.Match(k, Invk_parse_to_html)) return Parse_to_html(m);
else if (ctx.Match(k, Invk_wikidata_get_label)) return Wikidata_get_label(m);
else if (ctx.Match(k, Invk_get_page)) return Get_page(m);
else if (ctx.MatchIn(k, Invk_cmd, Invk_scripts_exec)) return Scripts_exec(m);
else if (ctx.Match(k, Invk_scripts_exec)) return Scripts_exec(m);
else if (ctx.Match(k, Invk_popups_get_async_bgn)) return Popups_get_async_bgn(m);
else if (ctx.Match(k, Invk_popups_get_html)) return Popups_get_html(m);
else if (ctx.Match(k, Invk_scripts_exec)) return Scripts_exec(m);
else if (ctx.Match(k, Invk_get_search_suggestions)) return Get_search_suggestions(m);
else if (ctx.Match(k, Invk_get_titles_meta)) return Get_titles_meta(m);
else if (ctx.Match(k, Invk_get_titles_exists)) return Get_titles_exists(m);
@ -183,7 +184,7 @@ public class Xog_html_js_cbk implements GfoInvkAble {
else if (ctx.Match(k, Invk_xowa_exec_test_as_array)) return Xowa_exec_test_as_array(m);
else return GfoInvkAble_.Rv_unhandled;
}
public static final String Invk_parse_to_html = "parse_to_html", Invk_wikidata_get_label = "wikidata_get_label", Invk_get_page = "get_page", Invk_scripts_exec = "scripts_exec"
public static final String Invk_parse_to_html = "parse_to_html", Invk_wikidata_get_label = "wikidata_get_label", Invk_get_page = "get_page", Invk_cmd = "cmd", Invk_scripts_exec = "scripts_exec"
, Invk_get_search_suggestions = "get_search_suggestions", Invk_get_titles_meta = "get_titles_meta", Invk_get_titles_exists = "get_titles_exists", Invk_get_current_url = "get_current_url"
, Invk_xowa_exec_test = "xowa_exec_test", Invk_xowa_exec_test_as_array = "xowa_exec_test_as_array"
, Invk_popups_get_async_bgn = "popups_get_async_bgn"

View File

@ -19,13 +19,14 @@ package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
import gplx.xowa.html.tidy.*; import gplx.xowa.html.utils.*;
public class Xoh_html_mgr implements GfoInvkAble {
public Xoh_html_mgr(Xoa_app app) {
page_mgr = new Xoh_page_mgr(app);
js_cleaner = new Xoh_js_cleaner(app);
}
public void Init_by_app(Xoa_app app) {
tidy_mgr.Init_by_app(app);
}
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
public Xoh_page_mgr Page_mgr() {return page_mgr;} private Xoh_page_mgr page_mgr = new Xoh_page_mgr();
public Xoh_page_mgr Page_mgr() {return page_mgr;} private Xoh_page_mgr page_mgr;
public Xoh_tidy_mgr Tidy_mgr() {return tidy_mgr;} private Xoh_tidy_mgr tidy_mgr = new Xoh_tidy_mgr();
public Xoh_js_cleaner Js_cleaner() {return js_cleaner;} private Xoh_js_cleaner js_cleaner;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {

View File

@ -16,7 +16,8 @@ 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.html; import gplx.*; import gplx.xowa.*;
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.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.*;
public class Xoh_lnki_wtr {
private Xoa_app app; private Xow_wiki wiki; private Xoa_page page; private Xop_ctx ctx;
private Xoh_html_wtr_cfg cfg;
@ -86,6 +87,10 @@ public class Xoh_lnki_wtr {
return;
}
}
// if (wiki.Domain_tid() == gplx.xowa.wikis.Xow_wiki_domain_.Tid_wikivoyage && lnki_ttl.Wik_bgn() != -1) {
// wiki.Xtn_mgr().Xtn_sites().Match(lnki_ttl, page.Html_data().Related_sites());
// return;
// }
if (hctx.Mode_is_alt())
Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr);
else {

View File

@ -16,7 +16,12 @@ 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.html; import gplx.*; import gplx.xowa.*;
import gplx.xowa.html.portal.*;
public class Xoh_page_mgr implements GfoInvkAble {
public Xoh_page_mgr(Xoa_app app) {
this.subpages_bldr = new Xoh_subpages_bldr(app);
}
public Xoh_subpages_bldr Subpages_bldr() {return subpages_bldr;} private Xoh_subpages_bldr subpages_bldr;
public boolean Font_enabled() {return font_enabled;} private boolean font_enabled = false;
public void Font_enabled_(boolean v) {font_enabled = v;}
public String Font_name() {return font_name;} private String font_name = "Arial";

View File

@ -56,7 +56,7 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble {
, "portal_div_personal", "portal_div_ns", "portal_div_view"
, "portal_div_logo", "portal_div_home", "portal_div_xtn", "portal_div_wikis", "portal_sidebar"
, "edit_div_rename", "edit_div_preview"
, "app_version", "app_build_date", "app_root_dir", "js_article_view_vars", "js_wikidata", "js_edit_toolbar", "xowa_mode_is_server"
, "app_version", "app_build_date", "app_root_dir", "js_wikidata", "js_edit_toolbar", "xowa_mode_is_server"
);
public Bry_fmtr Page_edit_fmtr() {return page_edit_fmtr;} private Bry_fmtr page_edit_fmtr = Bry_fmtr.new_(""
, "page_id", "page_name", "page_title", "page_content_sub", "page_data", "page_langs", "page_modified_on_msg", "page_lang_ltr"
@ -65,7 +65,7 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble {
, "portal_div_personal", "portal_div_ns", "portal_div_view"
, "portal_div_logo", "portal_div_home", "portal_div_xtn", "portal_div_wikis", "portal_sidebar"
, "edit_div_rename", "edit_div_preview"
, "app_version", "app_build_date", "app_root_dir", "js_article_view_vars", "js_wikidata", "js_edit_toolbar", "xowa_mode_is_server"
, "app_version", "app_build_date", "app_root_dir", "js_wikidata", "js_edit_toolbar", "xowa_mode_is_server"
);
public Bry_fmtr Page_html_fmtr() {return page_html_fmtr;} private Bry_fmtr page_html_fmtr = Bry_fmtr.new_(""
, "page_id", "page_name", "page_title", "page_content_sub", "page_data", "page_langs", "page_modified_on_msg", "page_lang_ltr"
@ -74,7 +74,7 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble {
, "portal_div_personal", "portal_div_ns", "portal_div_view"
, "portal_div_logo", "portal_div_home", "portal_div_xtn", "portal_div_wikis", "portal_sidebar"
, "edit_div_rename", "edit_div_preview"
, "app_version", "app_build_date", "app_root_dir", "js_article_view_vars", "js_wikidata", "js_edit_toolbar", "xowa_mode_is_server"
, "app_version", "app_build_date", "app_root_dir", "js_wikidata", "js_edit_toolbar", "xowa_mode_is_server"
);
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public byte[] Edit_rename_div_bry(Xoa_ttl ttl) {

View File

@ -71,11 +71,13 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
, mgr.Css_common_bry(), mgr.Css_wiki_bry(), html_content_editable
, page.Html_data().Module_mgr().Init(app, wiki, page).Init_dflts()
, portal_mgr.Div_personal_bry(), portal_mgr.Div_ns_bry(app.Utl_bry_bfr_mkr(), page.Ttl(), wiki.Ns_mgr()), portal_mgr.Div_view_bry(app.Utl_bry_bfr_mkr(), view_tid, page.Html_data().Search_text())
, portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), page.Html_data().Portal_div_xtn(), portal_mgr.Div_wikis_bry(app.Utl_bry_bfr_mkr()), portal_mgr.Sidebar_mgr().Html_bry()
, mgr.Edit_rename_div_bry(page.Ttl()), page.Html_data().Edit_preview()
, portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), Xoh_page_wtr_wkr_.Bld_portal_div_xtn(wiki, page), portal_mgr.Div_wikis_bry(app.Utl_bry_bfr_mkr()), portal_mgr.Sidebar_mgr().Html_bry()
, mgr.Edit_rename_div_bry(page.Ttl())
, page.Html_data().Edit_preview_w_dbg()
, Xoa_app_.Version, Xoa_app_.Build_date
, app.Fsys_mgr().Root_dir().To_http_file_bry()
, wiki.Fragment_mgr().Html_js_table(), js_wikidata_bry, js_edit_toolbar_bry, app.Tcp_server().Running_str()
, js_wikidata_bry, js_edit_toolbar_bry
, app.Tcp_server().Running_str()
);
Xoh_page_wtr_wkr_.Bld_head_end(html_bfr, page);
Xoh_page_wtr_wkr_.Bld_html_end(html_bfr, page);

View File

@ -16,12 +16,19 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
import gplx.html.*;
import gplx.html.*; import gplx.xowa.xtns.relatedSites.*;
public class Xoh_page_wtr_wkr_ {
public static byte[] Bld_portal_div_xtn(Xow_wiki wiki, Xoa_page page) {
// byte[] rv = wiki.Xtn_mgr().Xtn_sites().Html_bldr().Bld_all(page.Html_data().Related_sites());
// rv = Bry_.Add(rv, page.Html_data().Portal_div_xtn().XtoAryAndClear());
// return rv;
return page.Html_data().Portal_div_xtn().XtoAryAndClear();
}
public static byte[] Bld_page_content_sub(Xoa_app app, Xow_wiki wiki, Xoa_page page, Bry_bfr tmp_bfr) {
byte[] subpages = app.Html_mgr().Page_mgr().Subpages_bldr().Bld(page.Ttl());
byte[] page_content_sub = page.Html_data().Content_sub(); // contentSub exists; SEE: {{#isin}}
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page);
return tmp_bfr.Concat_skip_empty(Html_tag_.Br_inl, page_content_sub, redirect_msg).XtoAryAndClear();
return Bry_.Add(subpages, page_content_sub, redirect_msg);
}
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
if (display_ttl != null) return display_ttl; // display_ttl explicitly set; use it

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
import gplx.xowa.ctgs.*; import gplx.xowa.xtns.gallery.*;
import gplx.xowa.html.portal.*; import gplx.xowa.html.tocs.*; import gplx.xowa.html.modules.*;
import gplx.xowa.html.portal.*; import gplx.xowa.html.tocs.*; import gplx.xowa.wikis.modules.*;
public class Xow_html_mgr implements GfoInvkAble {
public Xow_html_mgr(Xow_wiki wiki) {
this.wiki = wiki;
@ -154,6 +154,7 @@ public class Xow_html_mgr implements GfoInvkAble {
else if (ctx.Match(k, Invk_portal)) return portal_mgr;
else if (ctx.Match(k, Invk_imgs)) return imgs_mgr;
else if (ctx.Match(k, Invk_ns_ctg)) return ns_ctg;
else if (ctx.Match(k, Invk_modules)) return module_mgr;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
@ -164,6 +165,7 @@ public class Xow_html_mgr implements GfoInvkAble {
, Invk_lnki_thumb_part_magnify_btn_ = "lnki_thumb_part_magnify_btn_", Invk_lnki_thumb_part_play_btn_ = "lnki_thumb_part_play_btn_", Invk_lnki_thumb_part_info_btn_ = "lnki_thumb_part_info_btn_"
, Invk_article = "article"
, Invk_portal = "portal", Invk_imgs = "imgs", Invk_ns_ctg = "ns_ctg"
, Invk_modules = "modules"
;
public static final String Str_img_class_thumbimage = "thumbimage";
public static final byte[] Bry_anchor_class_image = Bry_.new_ascii_(" class=\"image\""), Bry_anchor_class_blank = Bry_.Empty, Bry_anchor_rel_nofollow = Bry_.new_ascii_(" rel=\"nofollow\""), Bry_anchor_rel_blank = Bry_.Empty, Bry_img_class_thumbimage = Bry_.new_ascii_(" class=\"thumbimage\""), Bry_img_class_none = Bry_.Empty;

View File

@ -0,0 +1,35 @@
/*
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/>.
*/
//namespace gplx.xowa.html.modules {
// using gplx.xowa.gui;
// using gplx.xowa.apis.xowa.html.modules;
// public class Xoh_module_itm__div_toggle : Xoh_module_itm {
// public boolean Enabled() {return enabled;} public void Enabled_y_() {enabled = true;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
// public void Clear() {enabled = false;}
// public byte[] Key() {return Key_const;} private static final byte[] Key_const = Bry_.new_ascii_("div_toggle");
// public void Write_css_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
// public void Write_js_include(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
// public void Write_css_include(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) { }
// public void Write_js_head_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
// public void Write_js_tail_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {
// if (!enabled) return;
// wtr.Write_js_tail_load_lib(app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "modules", "xowa.div_toggle", "xowa.div_toggle.js"));
// }
// public void Write_js_head_global(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
// }
//}

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.xowa.langs.numbers.*;
public class Xoh_module_itm__globals implements Xoh_module_itm {
private Xoh_module_wtr tmp_wtr = new Xoh_module_wtr();
public byte[] Key() {return Key_const;} private static final byte[] Key_const = Bry_.new_ascii_("globals");
public boolean Enabled() {return enabled;} public void Enabled_n_() {enabled = false;} public void Enabled_y_() {enabled = true;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
public void Clear() {enabled = false;}
@ -36,14 +37,18 @@ public class Xoh_module_itm__globals implements Xoh_module_itm {
public void Write_js_tail_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
public void Write_js_head_global(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {
if (!enabled) return;
wtr.Write_js_global_ini_atr_val(Key_mode_is_gui , app.Mode() == Xoa_app_.Mode_gui);
wtr.Write_js_global_ini_atr_val(Key_mode_is_http , app.Mode() == Xoa_app_.Mode_http);
wtr.Write_js_global_ini_atr_val(Key_http_port , app.Http_server().Port());
wtr.Write_js_global_ini_atr_msg(wiki, Key_sort_ascending);
wtr.Write_js_global_ini_atr_msg(wiki, Key_sort_descending);
Xol_lang lang = wiki.Lang(); Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
Bry_bfr bfr = lang.App().Utl_bry_bfr_mkr().Get_b512();
byte[] months_long = Html_js_table_months(bfr, msg_mgr, Xol_msg_itm_.Id_dte_month_name_january, Xol_msg_itm_.Id_dte_month_name_december);
byte[] months_short = Html_js_table_months(bfr, msg_mgr, Xol_msg_itm_.Id_dte_month_abrv_jan, Xol_msg_itm_.Id_dte_month_abrv_dec);
byte[] num_format_separators = Html_js_table_num_format_separators(bfr, lang.Num_mgr().Separators_mgr());
bfr.Mkr_rls();
Bry_bfr tmp_bfr = lang.App().Utl_bry_bfr_mkr().Get_b512();
tmp_wtr.Init(tmp_bfr);
byte[] months_long = Html_js_table_months(tmp_wtr, msg_mgr, Xol_msg_itm_.Id_dte_month_name_january, Xol_msg_itm_.Id_dte_month_name_december);
byte[] months_short = Html_js_table_months(tmp_wtr, msg_mgr, Xol_msg_itm_.Id_dte_month_abrv_jan, Xol_msg_itm_.Id_dte_month_abrv_dec);
byte[] num_format_separators = Html_js_table_num_format_separators(tmp_wtr, lang.Num_mgr().Separators_mgr());
tmp_bfr.Mkr_rls();
wtr.Write_js_global_ini_atr_val(Key_wgContentLanguage , lang.Key_bry());
wtr.Write_js_global_ini_atr_obj(Key_wgSeparatorTransformTable , num_format_separators);
wtr.Write_js_global_ini_atr_obj(Key_wgDigitTransformTable , Num_format_digits);
@ -52,7 +57,10 @@ public class Xoh_module_itm__globals implements Xoh_module_itm {
wtr.Write_js_global_ini_atr_obj(Key_wgMonthNamesShort , months_short);
}
private static final byte[]
Key_sort_descending = Bry_.new_ascii_("sort-descending")
Key_mode_is_gui = Bry_.new_ascii_("mode_is_gui")
, Key_mode_is_http = Bry_.new_ascii_("mode_is_http")
, Key_http_port = Bry_.new_ascii_("http-port")
, Key_sort_descending = Bry_.new_ascii_("sort-descending")
, Key_sort_ascending = Bry_.new_ascii_("sort-ascending")
, Key_wgContentLanguage = Bry_.new_ascii_("wgContentLanguage")
, Key_wgSeparatorTransformTable = Bry_.new_ascii_("wgSeparatorTransformTable")
@ -61,23 +69,22 @@ public class Xoh_module_itm__globals implements Xoh_module_itm {
, Key_wgMonthNames = Bry_.new_ascii_("wgMonthNames")
, Key_wgMonthNamesShort = Bry_.new_ascii_("wgMonthNamesShort")
;
private static byte[] Html_js_table_months(Bry_bfr bfr, Xow_msg_mgr msg_mgr, int january_id, int december_id) {// ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Apos);
for (int i = january_id; i <= december_id; i++) {
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Apos);
bfr.Add(Bry_.Replace(msg_mgr.Val_by_id(i), Byte_ascii.Apos_bry, Apos_escape));
bfr.Add_byte(Byte_ascii.Apos);
private static byte[] Html_js_table_months(Xoh_module_wtr tmp_wtr, Xow_msg_mgr msg_mgr, int january_id, int december_id) {
tmp_wtr.Write_js_ary_bgn();
tmp_wtr.Write_js_ary_itm(Bry_.Empty); // 1st month is always empty
for (int i = january_id; i <= december_id; i++)
tmp_wtr.Write_js_ary_itm(msg_mgr.Val_by_id(i));
tmp_wtr.Write_js_ary_end();
return tmp_wtr.Bfr().XtoAryAndClear();
}
bfr.Add_byte(Byte_ascii.Brack_end);
return bfr.XtoAryAndClear();
} private static final byte[] Apos_escape = Bry_.new_ascii_("\\'");
private static byte[] Html_js_table_num_format_separators(Bry_bfr bfr, Xol_transform_mgr separator_mgr) {
private static byte[] Html_js_table_num_format_separators(Xoh_module_wtr tmp_wtr, Xol_transform_mgr separator_mgr) {
byte[] dec_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__dec);
bfr.Add_byte(Byte_ascii.Brack_bgn) .Add_byte(Byte_ascii.Apos).Add(dec_spr).Add_byte(Byte_ascii.Tab).Add_byte(Byte_ascii.Dot).Add_byte(Byte_ascii.Apos);
byte[] grp_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__grp);
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space) .Add_byte(Byte_ascii.Apos).Add(grp_spr).Add_byte(Byte_ascii.Tab).Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Apos);
bfr.Add_byte(Byte_ascii.Brack_end);
return bfr.XtoAryAndClear();
tmp_wtr.Write_js_ary_bgn();
tmp_wtr.Write_js_ary_itm(Bry_.Add(dec_spr, Byte_ascii.Tab_bry, Byte_ascii.Dot_bry));
tmp_wtr.Write_js_ary_itm(Bry_.Add(grp_spr, Byte_ascii.Tab_bry, Byte_ascii.Comma_bry));
tmp_wtr.Write_js_ary_end();
return tmp_wtr.Bfr().XtoAryAndClear();
}
private static final byte[]
Date_format_default = Bry_.new_ascii_("dmy")

View File

@ -33,15 +33,7 @@ public class Xoh_module_itm__popups implements Xoh_module_itm {
public void Write_js_head_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
public void Write_js_tail_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {
if (!enabled) return;
if (Js_line_2 == null) {
Js_line_2 = Bry_.Add
( Js_line_2_bgn
, app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "modules", "xowa.popups", "xowa.popups.js").To_http_file_bry()
, Js_line_2_end
);
}
wtr.Write_js_line(Js_line_1);
wtr.Write_js_line(Js_line_2);
wtr.Write_js_tail_load_lib(app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "modules", "xowa.popups", "xowa.popups.js"));
}
public void Write_js_head_global(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {
if (!enabled) return;
@ -54,12 +46,9 @@ public class Xoh_module_itm__popups implements Xoh_module_itm {
wtr.Write_js_global_ini_atr_val(Key_win_bind_focus_blur , api_popups.Win_bind_focus_blur());
wtr.Write_js_global_ini_atr_val(Key_win_bind_hover_area , bind_hover_area);
}
private static byte[] Css_url, Js_line_2;
private static byte[] Css_url;
private static final byte[]
Js_line_1 = Bry_.new_ascii_("xowa.js.jquery.init();")
, Js_line_2_bgn = Bry_.new_ascii_("xowa.js.load_lib('")
, Js_line_2_end = Bry_.new_ascii_("');")
, Key_win_show_delay = Bry_.new_ascii_("popups-win-show_delay")
Key_win_show_delay = Bry_.new_ascii_("popups-win-show_delay")
, Key_win_hide_delay = Bry_.new_ascii_("popups-win-hide_delay")
, Key_win_max_w = Bry_.new_ascii_("popups-win-max_w")
, Key_win_max_h = Bry_.new_ascii_("popups-win-max_h")

View File

@ -0,0 +1,39 @@
/*
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.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.xowa.gui.*;
import gplx.xowa.apis.xowa.html.modules.*;
public class Xoh_module_itm__top_icon implements Xoh_module_itm {
public boolean Enabled() {return enabled;} public void Enabled_y_() {enabled = true;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
public void Clear() {enabled = false;}
public byte[] Key() {return Key_const;} private static final byte[] Key_const = Bry_.new_ascii_("top_icon");
public void Write_css_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
public void Write_js_include(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
public void Write_css_include(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {
if (!enabled) return;
if (Css_url == null) Css_url = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "modules", "mw.top_icon", "mw.top_icon.css").To_http_file_bry();
wtr.Write_css_include(Css_url);
}
public void Write_js_head_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
public void Write_js_tail_script(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {
if (!enabled) return;
wtr.Write_js_tail_load_lib(app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "modules", "mw.top_icon", "mw.top_icon.js"));
}
public void Write_js_head_global(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {}
private static byte[] Css_url;
}

View File

@ -20,7 +20,7 @@ public class Xoh_module_mgr implements Bry_fmtr_arg {
private Xoa_app app; private Xow_wiki wiki; private Xoa_page page; private Xoh_module_itm[] itms; private int itms_len;
private Xoh_module_wtr wtr = new Xoh_module_wtr();
public Xoh_module_mgr() {
Itms_add(itm_css, itm_globals, itm_popups, itm_toc, itm_collapsible, itm_navframe, itm_gallery, itm_mathjax, itm_hiero);
Itms_add(itm_css, itm_globals, itm_popups, itm_toc, itm_collapsible, itm_navframe, itm_gallery, itm_mathjax, itm_hiero, itm_top_icon);
}
public Xoh_module_itm__css Itm_css() {return itm_css;} private Xoh_module_itm__css itm_css = new Xoh_module_itm__css();
public Xoh_module_itm__globals Itm_globals() {return itm_globals;} private Xoh_module_itm__globals itm_globals = new Xoh_module_itm__globals();
@ -31,13 +31,14 @@ public class Xoh_module_mgr implements Bry_fmtr_arg {
public Xoh_module_itm__gallery Itm_gallery() {return itm_gallery;} private Xoh_module_itm__gallery itm_gallery = new Xoh_module_itm__gallery();
public Xoh_module_itm__mathjax Itm_mathjax() {return itm_mathjax;} private Xoh_module_itm__mathjax itm_mathjax = new Xoh_module_itm__mathjax();
public Xoh_module_itm__hiero Itm_hiero() {return itm_hiero;} private Xoh_module_itm__hiero itm_hiero = new Xoh_module_itm__hiero();
public Xoh_module_itm__top_icon Itm_top_icon() {return itm_top_icon;} private Xoh_module_itm__top_icon itm_top_icon = new Xoh_module_itm__top_icon();
public Xoh_module_mgr Init(Xoa_app app, Xow_wiki wiki, Xoa_page page) {
this.app = app; this.wiki = wiki; this.page = page;
if (page.Hdr_mgr().Toc_enabled())
itm_toc.Enabled_y_();
return this;
}
public Xoh_module_mgr Init_dflts() {
if (page.Hdr_mgr().Toc_enabled()) itm_toc.Enabled_y_();
if (wiki.Html_mgr().Module_mgr().Itm_top_icon().Enabled()) itm_top_icon.Enabled_y_();
itm_css.Enabled_y_();
itm_globals.Enabled_y_(); // for now, always mark this and rest as exists; DATE:2014-06-09
itm_collapsible.Enabled_y_();

View File

@ -45,6 +45,60 @@ public class Xoh_module_mgr_tst {
, " </script>"
));
}
@Test public void Globals() {
fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "Jan'uary" ); // add apos to simulate apostrophes in Hebrew months; DATE:2014-07-28
fxt.Mgr().Itm_globals().Enabled_y_();
fxt.Test_write(String_.Concat_lines_nl_skip_last
( ""
, " <script type='text/javascript'>"
, " var xowa_root_dir = 'file:///mem/xowa/';"
, " var xowa_mode_is_server = false;"
, " var xowa_global_values = {"
, " 'mode_is_gui' : false,"
, " 'mode_is_http' : false,"
, " 'http-port' : 8080,"
, " 'sort-ascending' : 'Sort ascending',"
, " 'sort-descending' : 'Sort descending',"
, " 'wgContentLanguage' : 'en',"
, " 'wgSeparatorTransformTable' : ['.\t.', ',\t,'],"
, " 'wgDigitTransformTable' : ['', ''],"
, " 'wgDefaultDateFormat' : 'dmy',"
, " 'wgMonthNames' : ['', 'Jan\\'uary', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
, " }"
, " </script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/modules/xowa.core/xowa.core.js\" type='text/javascript'></script>"
));
fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "January" ); // set it back
}
@Test public void Globals_la() { // PURPOSE: la.gfs only specifies "," not "."; make sure both "." and "," show up, or else null ref error during import; DATE:2014-05-13
Xol_lang la_lang = fxt.Wiki().Lang();
gplx.xowa.langs.numbers.Xol_transform_mgr separators_mgr = la_lang.Num_mgr().Separators_mgr();
separators_mgr.Clear();
separators_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_ascii_(" "));
fxt.Mgr().Itm_globals().Enabled_y_();
fxt.Test_write(String_.Concat_lines_nl_skip_last
( ""
, " <script type='text/javascript'>"
, " var xowa_root_dir = 'file:///mem/xowa/';"
, " var xowa_mode_is_server = false;"
, " var xowa_global_values = {"
, " 'mode_is_gui' : false,"
, " 'mode_is_http' : false,"
, " 'http-port' : 8080,"
, " 'sort-ascending' : 'Sort ascending',"
, " 'sort-descending' : 'Sort descending',"
, " 'wgContentLanguage' : 'en',"
, " 'wgSeparatorTransformTable' : ['.\t.', ' \t,']," // note that grp spr (",") is ""
, " 'wgDigitTransformTable' : ['', ''],"
, " 'wgDefaultDateFormat' : 'dmy',"
, " 'wgMonthNames' : ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
, " }"
, " </script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/modules/xowa.core/xowa.core.js\" type='text/javascript'></script>"
));
}
}
class Xoh_module_mgr_fxt {
private Xop_fxt fxt = new Xop_fxt();
@ -52,6 +106,7 @@ class Xoh_module_mgr_fxt {
private Bry_bfr bfr = Bry_bfr.reset_(255);
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public Xoh_module_mgr Mgr() {return mgr;}
public Xol_lang Make_lang(String key) {return wiki.App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_(key));}
public void Clear() {
fxt.Reset();
mgr = fxt.Page().Html_data().Module_mgr();
@ -60,6 +115,10 @@ class Xoh_module_mgr_fxt {
public void Init_msg(byte[] key, String val) {
wiki.Msg_mgr().Get_or_make(key).Atrs_set(Bry_.new_ascii_(val), false, false);
}
public void Init_msg(int id, String val) {
Xol_msg_itm msg_itm = wiki.Lang().Msg_mgr().Itm_by_id_or_null(id);
msg_itm.Atrs_set(Bry_.new_ascii_(val), false, false);
}
public void Test_write(String expd) {
mgr.Write(bfr, fxt.App(), wiki, fxt.Page());
Tfds.Eq_str_lines(expd, bfr.XtoStrAndClear());

View File

@ -19,9 +19,13 @@ package gplx.xowa.html.modules; import gplx.*; import gplx.xowa.*; import gplx.x
import gplx.html.*;
public class Xoh_module_wtr {
private int indent; private int reset_bgn, reset_end;
private boolean js_tail_inited = false;
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr;
public void Init(Bry_bfr bfr) {this.bfr = bfr;}
public void Term() {this.bfr = null;}
public void Term() {
this.bfr = null;
js_tail_inited = true;
}
public void Write_css_include(byte[] url) {
Write_nl_and_indent();
bfr.Add(Css_include_bgn).Add(url).Add(Css_include_end);
@ -77,6 +81,23 @@ public class Xoh_module_wtr {
Write_nl_and_indent();
bfr.Add(Js_globals_ini_var_end);
}
private void Write_js_tail_init() {
if (js_tail_inited) return;
js_tail_inited = true;
Write_js_line(Js_line_1);
}
public void Write_js_tail_load_lib(Io_url url) {
Write_js_tail_init();
Write_nl_and_indent();
bfr.Add(Js_line_2_bgn);
bfr.Add(url.To_http_file_bry());
bfr.Add(Js_line_2_end);
}
private static final byte[]
Js_line_1 = Bry_.new_ascii_("xowa.js.jquery.init();")
, Js_line_2_bgn = Bry_.new_ascii_("xowa.js.load_lib('")
, Js_line_2_end = Bry_.new_ascii_("');")
;
private boolean Reset() {
if (bfr.Len() == reset_end) { // itms wrote nothing
bfr.Delete_rng_to_end(reset_bgn); // delete bgn
@ -109,6 +130,12 @@ public class Xoh_module_wtr {
bfr.Add_byte_apos();
bfr.Add(Js_globals_ini_atr_mid);
}
public void Write_js_ary_bgn() {js_ary_idx = 0; bfr.Add_byte(Byte_ascii.Brack_bgn);}
public void Write_js_ary_itm(byte[] val) {
if (++js_ary_idx != 1) bfr.Add(js_ary_dlm);
Write_js_quote(Byte_ascii.Apos, val);
} private int js_ary_idx = 0; private static final byte[] js_ary_dlm = Bry_.new_ascii_(", ");
public void Write_js_ary_end() {js_ary_idx = 0; bfr.Add_byte(Byte_ascii.Brack_end);}
public void Write_js_var(byte[] key, boolean quote_val, byte[] val) {
Write_nl_and_indent();
bfr.Add(Js_var_bgn);

View File

@ -16,14 +16,13 @@ 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.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.xowa.wikis.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
public class Xoa_available_wikis_mgr implements GfoInvkAble {
private Bry_fmtr itms_as_html_fmtr = Bry_fmtr.new_("\n <li><a href=\"/site/~{domain}/\"~{itm_cls}>~{domain}</a></li>", "domain", "itm_cls");
public Xoa_available_wikis_mgr(Xoa_app app) {this.app = app;} private Xoa_app app;
public String Itms_as_html() {
if (itms_as_html == null) {
boolean popups_enabled = app.Api_root().Html().Modules().Popups().Enabled();
String itm_cls = popups_enabled ? " class='xowa-hover-off'" : "";
String itm_cls = app.Api_root().Html().Modules().Popups().Enabled() ? " class='xowa-hover-off'" : "";
Bry_bfr tmp_bfr = Bry_bfr.new_(); // NOTE: do not use app.Utl_bry_bfr_mkr().Get_k004() as it is being used simultaneously by another caller; TODO: find call
Xow_xwiki_mgr xwiki_mgr = app.User().Wiki().Xwiki_mgr();
xwiki_mgr.Sort_by_key();
@ -37,11 +36,11 @@ public class Xoa_available_wikis_mgr implements GfoInvkAble {
}
return itms_as_html;
} private String itms_as_html;
public void Itms_refresh() {itms_as_html = null;}
public void Itms_reset() {itms_as_html = null;}
public boolean Visible() {return visible;} private boolean visible = true;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_itms_as_html)) return this.Itms_as_html();
else if (ctx.Match(k, Invk_itms_refresh)) Itms_refresh();
else if (ctx.Match(k, Invk_itms_refresh)) Itms_reset();
else if (ctx.Match(k, Invk_visible)) return Yn.Xto_str(visible);
else if (ctx.Match(k, Invk_visible_)) visible = m.ReadYn("v");
else if (ctx.Match(k, Invk_visible_toggle)) {visible = !visible; app.Gui_mgr().Browser_win().Active_html_box().Html_js_eval_proc("xowa-portal-wikis-visible-toggle", Bool_.XtoStr_lower(visible));}

View File

@ -0,0 +1,60 @@
/*
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.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
public class Xoh_subpages_bldr implements Bry_fmtr_arg {
private Xoa_app app;
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255), ttl_bfr = Bry_bfr.reset_(255);
private byte[][] segs;
public Xoh_subpages_bldr(Xoa_app app) {this.app = app;}
public byte[] Bld(Xoa_ttl ttl) {
if (!(ttl.Ns().Subpages_enabled() && ttl.Leaf_bgn() != Bry_.NotFound)) return Bry_.Empty; // only continue if ns has subpages and ttl has leaf; EX:Help:A/B
byte[] raw = ttl.Raw();
this.segs = Bry_.Split(raw, Byte_ascii.Slash);
fmtr_grp.Bld_bfr(tmp_bfr, this);
return tmp_bfr.XtoAryAndClear();
}
public void XferAry(Bry_bfr bfr, int idx) {
int segs_len = segs.length - 1; // last seg is current page; do not print
for (int i = 0; i < segs_len; ++i) {
byte[] dlm = null;
if (i == 0)
dlm = Dlm_1st;
else {
dlm = Dlm_nth;
ttl_bfr.Add_byte_slash();
}
byte[] seg = segs[i];
ttl_bfr.Add(seg);
byte[] seg_ttl = ttl_bfr.XtoAry();
byte[] seg_ttl_enc = app.Href_parser().Encoder().Encode(ttl_bfr.XtoAry());
byte[] href = Bry_.Add(Xoh_href_parser.Href_wiki_bry, seg_ttl_enc); // EX: /wiki/Help:A
fmtr_itm.Bld_bfr(bfr, dlm, href, seg_ttl, seg);
}
ttl_bfr.Clear();
}
private static final byte[] Dlm_1st = Bry_.new_ascii_("&lt; "), Dlm_nth = Bry_.new_ascii_("&lrm; | ");
private static final Bry_fmtr
fmtr_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<span class=\"subpages\">~{itms}"
, "</span>"
), "itms")
, fmtr_itm = Bry_fmtr.new_
( "\n ~{dlm}<a href=\"~{href}\" title=\"~{title}\">~{caption}</a>"
, "dlm", "href", "title", "caption")
;
}

View File

@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import org.junit.*;
public class Xoh_subpages_bldr_tst {
@Before public void init() {fxt.Init();} private Xoh_subpages_bldr_fxt fxt = new Xoh_subpages_bldr_fxt();
@Test public void Basic() {
fxt.Test_bld("Help:A/B/C", String_.Concat_lines_nl_skip_last
( "<span class=\"subpages\">"
, " &lt; <a href=\"/wiki/Help:A\" title=\"Help:A\">Help:A</a>"
, " &lrm; | <a href=\"/wiki/Help:A/B\" title=\"Help:A/B\">B</a>"
, "</span>"
));
}
}
class Xoh_subpages_bldr_fxt {
private Xoa_app app; private Xow_wiki wiki;
private Xoh_subpages_bldr subpages_bldr;
public void Init() {
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_help).Subpages_enabled_(true);
this.subpages_bldr = new Xoh_subpages_bldr(app);
}
public void Test_bld(String ttl_str, String expd) {
byte[] actl = subpages_bldr.Bld(Xoa_ttl.parse_(wiki, Bry_.new_utf8_(ttl_str)));
Tfds.Eq_str_lines(expd, String_.new_utf8_(actl));
}
}

View File

@ -94,8 +94,9 @@ public class Xow_portal_mgr implements GfoInvkAble {
public byte[] Div_logo_bry() {return div_logo_bry;} private byte[] div_logo_bry = Bry_.Empty;
public byte[] Div_home_bry() {return api_skin != null && api_skin.Sidebar_home_enabled() ? div_home_bry : Bry_.Empty;} private byte[] div_home_bry = Bry_.Empty;
public byte[] Div_wikis_bry(Bry_bfr_mkr bfr_mkr) {
gplx.xowa.apis.xowa.html.Xoapi_toggle_itm itm = wiki.App().Api_root().Html().Page().Toggle_mgr().Itm_offline_wikis().Init(wiki.App().User().Wiki());
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
div_wikis_fmtr.Bld_bfr_many(tmp_bfr);
div_wikis_fmtr.Bld_bfr_many(tmp_bfr, itm.Icon_src(), itm.Icon_title(), itm.Elem_display());
return tmp_bfr.Mkr_rls().XtoAryAndClear();
}
public byte[] Missing_ns_cls() {return missing_ns_cls;} public Xow_portal_mgr Missing_ns_cls_(byte[] v) {missing_ns_cls = v; return this;} private byte[] missing_ns_cls; // NOTE: must be null due to Init check above
@ -103,7 +104,7 @@ public class Xow_portal_mgr implements GfoInvkAble {
private Bry_fmtr div_ns_fmtr = Bry_fmtr.new_("~{portal_ns_subj_href};~{portal_ns_subj_cls};~{portal_ns_talk_href};~{portal_ns_talk_cls}", "portal_ns_subj_href", "portal_ns_subj_cls", "portal_ns_talk_href", "portal_ns_talk_cls");
private Bry_fmtr div_view_fmtr = Bry_fmtr.new_("", "portal_view_read_cls", "portal_view_edit_cls", "portal_view_html_cls", "search_text");
private Bry_fmtr div_logo_fmtr = Bry_fmtr.new_("", "portal_nav_main_href", "portal_logo_url");
private Bry_fmtr div_wikis_fmtr = Bry_fmtr.new_("");
private Bry_fmtr div_wikis_fmtr = Bry_fmtr.new_("", "icon_src", "icon_title", "elem_display");
private byte[] Reverse_li(byte[] bry) {
return lang_is_rtl ? Xoh_rtl_utl.Reverse_li(bry) : bry;
}

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/>.
*/
package gplx.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.net.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.net.*; import gplx.xowa.wikis.xwikis.*;
public class Xop_lnke_wkr implements Xop_ctx_wkr {
public void Ctor_ctx(Xop_ctx ctx) {url_parser = ctx.App().Url_parser().Url_parser();} Gfo_url_parser url_parser; Gfo_url_site_data site_data = new Gfo_url_site_data(); Xoa_url_parser xo_url_parser = new Xoa_url_parser(); Xoa_url xo_url_parser_url = Xoa_url.blank_();
public void Page_bgn(Xop_ctx ctx, Xop_root_tkn root) {}

View File

@ -77,6 +77,8 @@ public class Http_server_mgr implements GfoInvkAble {
Xoa_url page_url = app.Url_parser().Parse(page_ttl); // get the url (needed for query args)
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, page_ttl); // get the ttl
Xoa_page page = wiki.GetPageByTtl(page_url, ttl); // get page and parse it
if (app.Gui_mgr().Browser_win().Active_tab() == null) // no active tab
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(); // create at least one active tab; DATE:2014-07-30
app.Gui_mgr().Browser_win().Active_page_(page); // HACK: init gui_mgr's page for output (which server ordinarily doesn't need)
if (page.Missing()) { // if page does not exist, replace with message; else null_ref error; DATE:2014-03-08
page.Data_raw_(Bry_.new_ascii_("'''Page not found.'''"));
@ -223,9 +225,13 @@ class HttpRequest implements Runnable{
if(req.endsWith("wiki")) req+="/Main_Page";
}
if(req.contains("%xowa-cmd%")){
if(req.contains("%xowa-cmd%") || req.contains("/xowa-cmd:")){
System.out.println("Command output:");
String cmd = req.substring(req.indexOf("%xowa-cmd%")+20);
String cmd = "";
if (req.contains("%xowa-cmd%"))
cmd = req.substring(req.indexOf("%xowa-cmd%")+20);
else
cmd = req.substring(req.indexOf("/xowa-cmd:")+10);
System.out.println(cmd);
app.Http_server().Run_xowa_cmd(app, cmd);
dos.writeBytes("Command sent, see console log for more details.");

View File

@ -35,8 +35,8 @@ public class Xous_window_mgr implements GfoInvkAble {
if (startup_tabs.Type() == Xoapi_startup_tabs_tid_.Tid_previous) {
cfg_mgr.Set_by_app("xowa.api.app.startup.tabs.previous" , Calc_previous_tabs(user.App().Gui_mgr().Browser_win().Tab_mgr()));
}
cfg_mgr.Set_by_app("app.gui.html.portal.wikis.visible" , Yn.Xto_str(user.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis().Visible()));
cfg_mgr.Set_by_app("xowa.api.app.env.version_previous" , Xoa_app_.Version);
user.App().Api_root().Html().Page().Toggle_mgr().Save(cfg_mgr);
cfg_mgr.Db_save_txt();
}
private String Calc_previous_tabs(Xog_tab_mgr tab_mgr) {

View File

@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
import gplx.xowa.cfgs.*;
public class Prefs_converter {
Bry_bfr bfr = Bry_bfr.new_();
ListAdp list = ListAdp_.new_();
private Bry_bfr bfr = Bry_bfr.new_();
private ListAdp list = ListAdp_.new_();
public void Check(Xoa_app app) {
int options_version = app.Sys_cfg().Options_version();
if (options_version == 1) {
Io_url cfg_dir = app.User().Fsys_mgr().App_data_cfg_dir();
Io_url cfg_fil = cfg_dir.GenSubFil("user_system_cfg.gfs");
Io_url trg_fil = cfg_fil.GenNewNameAndExt(gplx.xowa.cfgs.Xoa_cfg_db_txt.File_name);
if (Io_mgr._.ExistsFil(trg_fil)) return; // do not overwrite file if it is there (i.e.: it's already converted); needed when running in app_mode = cmd (see HACK in Xob_bldr.Run)
if (!Io_mgr._.ExistsFil(trg_fil)) { // do not overwrite file if it is there (i.e.: it's already converted); needed when running in app_mode = cmd (see HACK in Xob_bldr.Run)
String old_str = Io_mgr._.LoadFilStr_args(cfg_fil).MissingIgnored_(true).Exec();
String new_str = Convert(old_str);
Io_mgr._.SaveFilStr(trg_fil, new_str);
@ -35,6 +35,7 @@ public class Prefs_converter {
app.Log_wtr().Log_msg_to_session_fmt("converted options to v2");
}
}
}
public String Convert(String raw) {
list.Clear();
GfoMsg root_msg = gplx.gfs.Gfs_msg_bldr._.ParseToMsg(raw);

View File

@ -0,0 +1,47 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.users.prefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*;
public class Prefs_rename_mgr {
private ListAdp list = ListAdp_.new_();
public Prefs_rename_mgr() {
List_add(list, "app.cfgs.get('app.gui.html.portal.wikis.visible', 'app').val", "app.cfgs.get('xowa.api.html.page.toggles.get(''offline-wikis'').visible', 'app').val");
}
public boolean Check(Io_url url) {
String cur_str = Io_mgr._.LoadFilStr_args(url).MissingIgnored_().Exec();
boolean cur_str_changed = false;
int list_len = list.Count();
for (int i = 0; i < list_len; ++i) {
Prefs_rename_itm itm = (Prefs_rename_itm)list.FetchAt(i);
if (String_.Has(cur_str, itm.Src())) {
cur_str_changed = true;
cur_str = String_.Replace(cur_str, itm.Src(), itm.Trg());
Gfo_usr_dlg_._.Log_many("", "", "cfg.replace: src=~{src} trg = ~{trg}", itm.Src(), itm.Trg());
}
}
if (cur_str_changed)
Io_mgr._.SaveFilStr(url, cur_str);
return cur_str_changed;
}
private static void List_add(ListAdp list, String src, String trg) {list.Add(new Prefs_rename_itm(src, trg));}
public static final Prefs_rename_mgr _ = new Prefs_rename_mgr();
}
class Prefs_rename_itm {
public Prefs_rename_itm(String src, String trg) {this.src = src; this.trg = trg;}
public String Src() {return src;} private String src;
public String Trg() {return trg;} private String trg;
}

View File

@ -0,0 +1,20 @@
/*
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.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_module__top_icon extends Xow_module_base {
}

View File

@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_module_base implements GfoInvkAble {
public boolean Enabled() {return enabled;} private boolean enabled;
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
}

View File

@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.html.modules.popups.*;
public class Xow_module_mgr implements GfoInvkAble {
private Hash_adp_bry regy = Hash_adp_bry.cs_();
public Xow_module_mgr(Xow_wiki wiki) {
this.popup_mgr = new Xow_popup_mgr(wiki);
regy.Add_str_obj("top_icon", itm_top_icon);
}
public void Init_by_wiki(Xow_wiki wiki) {
popup_mgr.Init_by_wiki(wiki);
}
public Xow_module__top_icon Itm_top_icon() {return itm_top_icon;} private Xow_module__top_icon itm_top_icon = new Xow_module__top_icon();
public Xow_popup_mgr Popup_mgr() {return popup_mgr;} private Xow_popup_mgr popup_mgr;
public Xow_module_base Get(byte[] key) {return (Xow_module_base)regy.Get_by_bry(key);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get";
}

View File

@ -15,16 +15,21 @@ 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.*;
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_xwiki_itm implements gplx.CompareAble {
public Xow_xwiki_itm(byte[] key, byte[] fmt, byte wiki_tid, int lang_id, byte[] domain) {this.key = key; this.fmt = fmt; this.wiki_tid = wiki_tid; this.lang_id = lang_id; this.domain = domain; this.key_str = String_.new_utf8_(key);}
public byte[] Key() {return key;} private byte[] key;
public Xow_xwiki_itm(byte[] key_bry, byte[] fmt, byte wiki_tid, int lang_id, byte[] domain) {
this.key_bry = key_bry; this.key_str = String_.new_utf8_(key_bry);
this.fmt = fmt; this.wiki_tid = wiki_tid; this.lang_id = lang_id; this.domain = domain;
this.name = key_bry;
}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public String Key_str() {return key_str;} private String key_str;
public byte[] Fmt() {return fmt;} private byte[] fmt;
public byte[] Domain() {return domain;} private byte[] domain;
public byte Wiki_tid() {return wiki_tid;} private byte wiki_tid;
public int Lang_id() {return lang_id;} private int lang_id;
public boolean Type_is_lang(int cur_lang_id) {return lang_id != Xol_lang_itm_.Id__unknown && cur_lang_id != lang_id && Bry_.Len_gt_0(fmt);}
public byte[] Name() {return name;} public Xow_xwiki_itm Name_(byte[] v) {name = v; return this;} private byte[] name;
public boolean Offline() {return offline;} public Xow_xwiki_itm Offline_(boolean v) {offline = v; return this;} private boolean offline;
public int compareTo(Object obj) {Xow_xwiki_itm comp = (Xow_xwiki_itm)obj; return Bry_.Compare(key, comp.key);}
public int compareTo(Object obj) {Xow_xwiki_itm comp = (Xow_xwiki_itm)obj; return Bry_.Compare(key_bry, comp.key_bry);}
}

View File

@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_xwiki_itm_ {
public static Xow_xwiki_itm new_mw_(Bry_bfr tmp_bfr, Gfo_url_parser url_parser, Gfo_url tmp_url, byte[] key, byte[] url_php, byte[] name, byte cur_wiki_tid) { // EX: "commons|//commons.wikimedia.org/wiki/Category:$1|Wikimedia Commons" "DMOZ|http://www.dmoz.org/Regional/Europe/$1/"|DMOZ"
byte[] url_gfs = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, url_php);
url_parser.Parse(tmp_url, url_gfs, 0, url_gfs.length);
byte[] domain_bry = tmp_url.Site();
Xow_wiki_domain domain = Xow_wiki_domain_.parse_by_domain(domain_bry);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang());
int lang_id = lang_itm == null ? Xol_lang_itm_.Id__unknown : lang_itm.Id();
return new Xow_xwiki_itm(key, url_gfs, domain.Tid(), lang_id, domain_bry).Name_(name);
}
}

View File

@ -0,0 +1,46 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.*;
public class Xow_xwiki_itm__tst {
@Before public void init() {fxt.Clear();} private Xow_xwiki_itm__fxt fxt = new Xow_xwiki_itm__fxt();
@Test public void Commons() {fxt.Test_new_mw_("commons.wikimedia.org/wiki/$1" , "commons.wikimedia.org" , "commons.wikimedia.org/wiki/~{0}" , Xow_wiki_domain_.Tid_commons , Xol_lang_itm_.Id__unknown);}
@Test public void Wiktionary() {fxt.Test_new_mw_("fr.wiktionary.org/wiki/$1" , "fr.wiktionary.org" , "fr.wiktionary.org/wiki/~{0}" , Xow_wiki_domain_.Tid_wiktionary , Xol_lang_itm_.Id_fr);}
@Test public void Lang() {fxt.Test_new_mw_("fr.wikipedia.org/wiki/$1" , "fr.wikipedia.org" , "fr.wikipedia.org/wiki/~{0}" , Xow_wiki_domain_.Tid_wikipedia , Xol_lang_itm_.Id_fr);}
}
class Xow_xwiki_itm__fxt {
private byte cur_wiki_tid;
private Bry_bfr tmp_bfr;
private Gfo_url_parser url_parser;
private Gfo_url tmp_url;
private byte[] key;
public void Clear() {
cur_wiki_tid = Xow_wiki_domain_.Tid_wikipedia;
tmp_bfr = Bry_bfr.new_(255);
url_parser = new Gfo_url_parser();
tmp_url = new Gfo_url();
key = Bry_.new_ascii_("test");
}
public void Test_new_mw_(String url_php, String expd_domain, String expd_url_fmt, byte expd_wiki_tid, int expd_lang_tid) {
Xow_xwiki_itm itm = Xow_xwiki_itm_.new_mw_(tmp_bfr, url_parser, tmp_url, key, Bry_.new_utf8_(url_php), key, cur_wiki_tid);
Tfds.Eq(expd_domain , String_.new_utf8_(itm.Domain()));
Tfds.Eq(expd_url_fmt , String_.new_utf8_(itm.Fmt()));
Tfds.Eq(expd_wiki_tid , itm.Wiki_tid(), "wiki");
Tfds.Eq(expd_lang_tid , itm.Lang_id(), "lang");
}
}

View File

@ -15,10 +15,11 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.wikis.*;
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_xwiki_mgr implements GfoInvkAble {
public Xow_xwiki_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
private Xow_xwiki_mgr_srl srl;
public Xow_xwiki_mgr(Xow_wiki wiki) {this.wiki = wiki; srl = new Xow_xwiki_mgr_srl(this);}
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public Xow_lang_mgr Lang_mgr() {return lang_mgr;} private Xow_lang_mgr lang_mgr = Xow_lang_mgr.dflt_();
public int Len() {return list.Count();} private OrderedHash list = OrderedHash_.new_bry_(); private Hash_adp_bry hash = Hash_adp_bry.ci_ascii_(); // ASCII:lang_code
public void Clear() {hash.Clear(); list.Clear();}
@ -40,16 +41,6 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
Xow_xwiki_itm itm = new Xow_xwiki_itm(alias, fmt, wiki_tid, lang_tid, domain);
Add_itm(itm, null);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_count)) return list.Count();
else if (ctx.Match(k, Invk_add_bulk)) Add_bulk(m.ReadBry("v"));
else if (ctx.Match(k, Invk_add_bulk_langs)) Add_bulk_langs(m);
else if (ctx.Match(k, Invk_add_bulk_peers)) Add_bulk_peers(m.ReadBry("v"));
else if (ctx.Match(k, Invk_itms_print)) return Exec_itms_print(m.ReadBry("v"));
else if (ctx.Match(k, Invk_clear)) this.Clear();
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Invk_add_bulk = "add_bulk", Invk_add_bulk_langs = "add_bulk_langs", Invk_add_bulk_peers = "add_bulk_peers", Invk_itms_print = "itms_print", Invk_count = "count", Invk_clear = "clear";
public void Sort_by_key() {
list.Sort();
}
@ -92,7 +83,7 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
int wikis_len = list.Count();
for (int i = 0; i < wikis_len; i++) {
Xow_xwiki_itm itm = (Xow_xwiki_itm)list.FetchAt(i);
byte[] key = itm.Key();
byte[] key = itm.Key_bry();
if (Bry_.Eq(key, Xow_wiki_domain_.Key_home_bry)) continue; // skip home
byte[] domain = itm.Domain();
if (seen.Has(domain)) continue;
@ -157,7 +148,7 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
Add_bulk_langs(grp_key, wiki_tid);
}
public void Add_bulk_langs(byte[] grp_key) {Add_bulk_langs(grp_key, wiki.Domain_tid());}
private void Add_bulk_langs(byte[] grp_key, byte wiki_tid) {
public void Add_bulk_langs(byte[] grp_key, byte wiki_tid) {
OrderedHash langs = wiki.App().Lang_mgr().Xto_hash(grp_key);
int len = langs.Count();
byte[] wiki_tid_name = Xow_wiki_domain_.Key_by_tid(wiki_tid);
@ -175,11 +166,28 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
}
lang_mgr.Grps_sort();
} private static final String GRP_KEY = "xowa.wiki.xwikis";
public void Add_itm(Xow_xwiki_itm itm) {Add_itm(itm, null);}
private void Add_itm(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
if ( !hash.Has(xwiki.Key()) // only register xwiki / lang pair once
if ( !hash.Has(xwiki.Key_bry()) // only register xwiki / lang pair once
&& lang != null) // null lang should not be registered
lang_mgr.Itms_reg(xwiki, lang);
hash.AddReplace(xwiki.Key(), xwiki);
list.AddReplace(xwiki.Key(), xwiki);
hash.AddReplace(xwiki.Key_bry(), xwiki);
list.AddReplace(xwiki.Key_bry(), xwiki);
}
public void Add_many(byte[] v) {srl.Load_by_bry(v);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_count)) return list.Count();
else if (ctx.Match(k, Invk_add_bulk)) Add_bulk(m.ReadBry("v"));
else if (ctx.Match(k, Invk_add_bulk_langs)) Add_bulk_langs(m);
else if (ctx.Match(k, Invk_add_bulk_peers)) Add_bulk_peers(m.ReadBry("v"));
else if (ctx.Match(k, Invk_add_many)) Add_many(m.ReadBry("v"));
else if (ctx.Match(k, Invk_itms_print)) return Exec_itms_print(m.ReadBry("v"));
else if (ctx.Match(k, Invk_clear)) this.Clear();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_add_bulk = "add_bulk", Invk_add_bulk_langs = "add_bulk_langs", Invk_add_bulk_peers = "add_bulk_peers", Invk_add_many = "add_many"
, Invk_itms_print = "itms_print", Invk_count = "count", Invk_clear = "clear"
;
}

View File

@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.srls.dsvs.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
class Xow_xwiki_mgr_srl extends Dsv_wkr_base {
private Xow_xwiki_mgr mgr; private Xow_wiki wiki;
private byte[] key, url_fmt, name;
private Gfo_url tmp_url; private Gfo_url_parser url_parser;
public Xow_xwiki_mgr_srl(Xow_xwiki_mgr mgr) {
this.mgr = mgr;
this.wiki = mgr.Wiki();
this.tmp_url = new Gfo_url();
this.url_parser = wiki.App().Url_parser().Url_parser();
}
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser};}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
switch (fld_idx) {
case 0: key = Bry_.Mid(src, bgn, end); return true;
case 1: url_fmt = Bry_.Mid(src, bgn, end); return true;
case 2: name = Bry_.Mid(src, bgn, end); return true;
default: return false;
}
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
Xow_xwiki_itm itm = Xow_xwiki_itm_.new_mw_(tmp_bfr, url_parser, tmp_url, key, url_fmt, name, mgr.Wiki().Domain_tid());
mgr.Add_itm(itm);
}
@Override public void Load_by_bry_bgn() {tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b128();} private Bry_bfr tmp_bfr;
@Override public void Load_by_bry_end() {tmp_bfr.Mkr_rls();}
}

View File

@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.*;
public class Xow_xwiki_mgr_tst {
Xow_xwiki_mgr_fxt fxt = new Xow_xwiki_mgr_fxt();
@ -30,7 +30,7 @@ public class Xow_xwiki_mgr_tst {
@Test public void Add_bulk_langs_grp_itm() {fxt.Langs_ini().Tst_add_bulk_langs("europe_west~ja", fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
@Test public void Add_bulk_langs_grp_commons() {
fxt.Langs_ini();
GfoInvkAble_.InvkCmd_msg(fxt.Wiki().Xwiki_mgr(), Xow_xwiki_mgr.Invk_add_bulk_langs, GfoMsg_.new_parse_(Xow_xwiki_mgr.Invk_add_bulk_langs).Add("grp_key", "europe_west").Add("wiki_type_name", "wikipedia"));
fxt.Wiki().Xwiki_mgr().Add_bulk_langs(Bry_.new_ascii_("europe_west"), Xow_wiki_domain_.Tid_wikipedia);
fxt.Tst_itms(fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"));
}
@Test public void Add_bulk_peers() {fxt.Peers_ini().Tst_add_bulk_peers("peer", fxt.xwiki_null_("commons"), fxt.xwiki_null_("m"), fxt.xwiki_("wikt", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("wiktionary", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("s", "en.wikisource.org", "http://en.wikisource.org/wiki/~{0}"));}
@ -54,7 +54,7 @@ class Xow_xwiki_mgr_fxt {
public Xow_xwiki_itm xwiki_(String key, String domain, String fmt) {return new Xow_xwiki_itm(Bry_.new_utf8_(key), Bry_.new_utf8_(fmt), Xow_wiki_domain_.Tid_other, Xol_lang_itm_.Id__unknown, Bry_.new_utf8_(domain));}
public Xow_xwiki_mgr_fxt Tst_add_bulk(String raw, int lang_tid, byte wiki_tid, String alias, String fmt, String domain) {
Xow_xwiki_itm itm = xwiki_mgr.Add_bulk_row(Xol_lang_itm_.Regy(), Bry_.new_ascii_(raw));
Tfds.Eq(alias, String_.new_ascii_(itm.Key()));
Tfds.Eq(alias, String_.new_ascii_(itm.Key_bry()));
Tfds.Eq(fmt, String_.new_ascii_(itm.Fmt()));
Tfds.Eq(wiki_tid, itm.Wiki_tid(), "wiki_tid");
Tfds.Eq(lang_tid, itm.Lang_id(), "lang_id");
@ -102,7 +102,7 @@ class Xow_xwiki_mgr_fxt {
int len = itms.length;
ListAdp rv = ListAdp_.new_();
for (int i = 0; i < len; i++) {
byte[] alias = itms[i].Key();
byte[] alias = itms[i].Key_bry();
Xow_xwiki_itm itm = xwiki_mgr.Get_by_key(alias);
if (itm == null) itm = xwiki_null_(String_.new_utf8_(alias)); // "null", ignore
rv.Add(itm);
@ -114,9 +114,9 @@ class Xow_xwiki_mgr_fxt {
for (int i = 0; i < len; i++) {
Xow_xwiki_itm itm = itms[i];
if (Bry_.Len_eq_0(itm.Domain())) // "null", ignore
sb.Add(itm.Key()).Add_char_nl();
sb.Add(itm.Key_bry()).Add_char_nl();
else {
sb.Add(itm.Key()).Add_char_pipe().Add(itm.Domain()).Add_char_pipe().Add(itm.Fmt()).Add_char_nl();
sb.Add(itm.Key_bry()).Add_char_pipe().Add(itm.Domain()).Add_char_pipe().Add(itm.Fmt()).Add_char_nl();
}
}
return sb.XtoStrAndClear();

View File

@ -16,13 +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/>.
*/
package gplx.xowa.xtns; import gplx.*; import gplx.xowa.*;
import gplx.xowa.xtns.cite.*;
import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.relatedSites.*;
public class Xow_xtn_mgr implements GfoInvkAble {
private OrderedHash regy = OrderedHash_.new_bry_();
public int Count() {return regy.Count();}
public Cite_xtn_mgr Xtn_cite() {return xtn_cite;} private Cite_xtn_mgr xtn_cite;
public Sites_xtn_mgr Xtn_sites() {return xtn_sites;} private Sites_xtn_mgr xtn_sites;
public Xow_xtn_mgr Ctor_by_app(Xoa_app app) { // NOTE: needed for options
Add(app, new Cite_xtn_mgr());
Add(app, new Sites_xtn_mgr());
Add(app, new gplx.xowa.xtns.scribunto.Scrib_xtn_mgr());
Add(app, new gplx.xowa.xtns.gallery.Gallery_xtn_mgr());
Add(app, new gplx.xowa.xtns.imaps.Imap_xtn_mgr());
@ -72,6 +74,7 @@ public class Xow_xtn_mgr implements GfoInvkAble {
}
private void Set_members(Xox_mgr mgr) {
if (Bry_.Eq(mgr.Xtn_key(), Cite_xtn_mgr.XTN_KEY)) xtn_cite = (Cite_xtn_mgr)mgr;
else if (Bry_.Eq(mgr.Xtn_key(), Sites_xtn_mgr.XTN_KEY)) xtn_sites = (Sites_xtn_mgr)mgr;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_or_fail(m.ReadBry("v"));

View File

@ -47,7 +47,7 @@ class Imap_html_fmtrs {
, " </a>"
), "imap_id", "img_elem_id", "img_alt", "img_src", "img_w", "img_h", "img_cls", "anchor_href", "anchor_title"
)
, Desc_style = Bry_fmtr.new_(" style=\"height:~{div_h}px; width: ~{div_w}px;\"", "div_h", "div_w")
, Desc_style = Bry_fmtr.new_(" style=\"height:~{div_h}px; width: ~{div_w}px;\"", "div_w", "div_h")
, Desc_main = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div style=\"margin-left:~{margin_left}px; margin-top:~{margin_top}px; text-align:left;\">"

View File

@ -138,6 +138,7 @@ class Imap_parser {
}
else {
if (pts_len < reqd_pts) return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_missing_coord");
else if (pts_len > reqd_pts) pts.Del_range(reqd_pts, pts_len - 1); // NOTE: MW allows more points, but doesn't show them; EX: rect 1 2 3 4 5 -> rect 1 2 3 4; PAGE:en.w:Kilauea DATE:2014-07-28
}
pos = Bry_finder.Trim_fwd_space_tab(src, pos, itm_end);
Imap_itm_shape shape_itm = new Imap_itm_shape(shape_tid, (Double_obj_val[])pts.XtoAryAndClear(Double_obj_val.class));

View File

@ -20,6 +20,7 @@ import org.junit.*;
public class Imap_parser_tst {
@Before public void init() {fxt.Reset();} private Imap_parser_fxt fxt = new Imap_parser_fxt();
@Test public void Rect_pass() {fxt.Test_shape("rect 1 2 3 4 [[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));}
@Test public void Rect_pass_many() {fxt.Test_shape("rect 1 2 3 4 5 6[[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));} // PURPOSE: MW allows extra points to be passed; PAGE:en.w:Kilauea DATE:2014-07-28
@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_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

View File

@ -87,7 +87,7 @@ public class Imap_xnde_html_all_tst {
, "desc top-left"
, "</imagemap>"
), String_.Concat_lines_nl_skip_last
( "<div class=\"noresize\" style=\"height:123px; width: 0px;\">"
( "<div class=\"noresize\" style=\"height:0px; width: 123px;\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <img id=\"xowa_file_img_0\" alt=\"a1\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"

View File

@ -77,5 +77,4 @@ public class Listing_xtn_mgr extends Xox_mgr_base {
private Xol_msg_itm Load_msg(Xow_wiki wiki, Xop_ctx sub_ctx, String ttl) {
return wiki.Msg_mgr().Find_or_null(Bry_.new_utf8_(ttl));
}
public static void Create_msgs() {}
}

View File

@ -28,6 +28,7 @@ public class Pfunc_switch extends Pf_func_base {
Arg_itm_tkn dflt_val_tkn = null; byte[] dflt_val_bry = null;
Arg_nde_tkn last_keyless_arg = null;
Bry_bfr tmp = ctx.Wiki().Utl_bry_bfr_mkr().Get_b512();
Xol_kwd_mgr kwd_mgr = ctx.Lang().Kwd_mgr();
for (int i = 0; i < self_args_len; i++) {
Arg_nde_tkn arg = self.Args_get_by_idx(i);
if (arg.KeyTkn_exists()) { // = exists; EX: "|a=1|"
@ -39,7 +40,7 @@ public class Pfunc_switch extends Pf_func_base {
match = Get_or_eval(ctx, src, caller, self, bfr, arg.Val_tkn(), tmp);
break; // stop iterating; explicit match found;
}
else if (Bry_.HasAtBgn(case_key, Dflt_keyword)){// case_key is #default; EX: {{#switch:a|#default=1}}; note that "#defaultabc" is also allowed;
else if (kwd_mgr.Kwd_default_match(case_key)){ // case_key is #default; EX: {{#switch:a|#default=1}}; note that "#defaultabc" is also allowed;
dflt_val_tkn = arg.Val_tkn(); // set dflt_val_tkn; note that there is no "break" b/c multiple #defaults will use last one; EX: {{#switch:a|#default=1|#default=2}} -> 2
dflt_val_bry = null; // set dflt_val_bry to null; EX:{{#switch:a|#defaultabc|#default=2}} -> 2
}
@ -50,7 +51,7 @@ public class Pfunc_switch extends Pf_func_base {
byte[] case_val = Get_or_eval(ctx, src, caller, self, bfr, arg.Val_tkn(), tmp);
if (Pf_func_.Eq_(case_val, argx)) // argx matches case_val; EX: case_val="|a|" and argx="a"
fall_thru_found = true; // set as fall-thru; note that fall-thrus will have "val" in next keyed arg, so need to continue iterating; EX: {{#switch:a|a|b=1|c=2}} "a" is fall-thru, but "b" is next keyed arg with a val
else if (Bry_.HasAtBgn(case_val, Dflt_keyword)){// case_val starts with #default; EX: "|#default|" or "|#defaultabc|"
else if (kwd_mgr.Kwd_default_match(case_val)) { // case_val starts with #default; EX: "|#default|" or "|#defaultabc|"
last_keyless_arg = null; // unflag last keyless arg else |#defaultabc| will be treated as last_keyless_arg and generate "#defaultabc"; DATE:2014-05-29
dflt_val_tkn = null; // unflag dflt_val_tkn; EX: {{#switch:a|b|#default=1|#default}} -> "" x> "1"
int case_val_len = case_val.length;

View File

@ -78,4 +78,14 @@ public class Pfunc_switch_tst {
fxt.Test_parse_tmpl_str_test("{{#switch:b|#default|1}}" , "{{test}}" , "1"); // override "|#default|" with "|2|"
fxt.Test_parse_tmpl_str_test("{{#switch:b|#defaultabc=1}}" , "{{test}}" , "1"); // this is also supported by MW
}
@Test public void Multiple() {
fxt.Wiki().Lang().Kwd_mgr().Kwd_default_match_reset();
Xol_kwd_grp kwd_grp = fxt.Wiki().Lang().Kwd_mgr().Get_or_new(Xol_kwd_grp_.Id_xtn_default);
kwd_grp.Srl_load(Bool_.Y, new byte[][] {Bry_.new_ascii_("#default1"), Bry_.new_ascii_("#default2")});
fxt.Test_parse_tmpl_str_test("{{#switch:|n=n|#default1=y}}" , "{{test}}" , "y");
fxt.Test_parse_tmpl_str_test("{{#switch:|n=n|#default2=y}}" , "{{test}}" , "y");
fxt.Test_parse_tmpl_str_test("{{#switch:a|n=n|#default=y}}" , "{{test}}" , ""); // #default is just a case
fxt.Test_parse_tmpl_str_test("{{#switch:|n=n|#default=y}}" , "{{test}}" , ""); // make sure empty String doesn't throw out of bounds
fxt.Wiki().Lang().Kwd_mgr().Kwd_default_match_reset();
}
}

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/>.
*/
package gplx.xowa.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.wikis.xwikis.*;
public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bb) {
@ -36,7 +37,7 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
trg.Add(Xoa_consts.Url_relative_prefix); // "//"
trg.Add(xwiki.Domain()) // "commons.wikimedia.org"
.Add(Xoh_href_parser.Href_wiki_bry) // "/wiki/"
.Add_mid(ttl_ary, xwiki.Key().length + 1, ttl_ary.length); // "A#b?c=d"; +1 for colon after "commons:"; NOTE: ugly way of getting rest of url, but ttl currently does not have Full_wo_wiki
.Add_mid(ttl_ary, xwiki.Key_bry().length + 1, ttl_ary.length); // "A#b?c=d"; +1 for colon after "commons:"; NOTE: ugly way of getting rest of url, but ttl currently does not have Full_wo_wiki
}
else {
Bry_bfr tmp_bfr = ctx.App().Utl_bry_bfr_mkr().Get_b512().Mkr_rls();

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.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Sites_html_bldr implements Bry_fmtr_arg {
private Sites_xtn_mgr xtn_mgr;
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255), tmp_ttl = Bry_bfr.reset_(255);
private ListAdp list; private int list_len;
public Sites_html_bldr(Sites_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
private Bry_fmtr url_fmtr = Bry_fmtr.keys_("title");
public byte[] Bld_all(ListAdp list) {
list_len = list.Count(); if (list_len == 0) return Bry_.Empty;
this.list = list;
fmtr_grp.Bld_bfr_many(tmp_bfr, xtn_mgr.Msg_related_sites(), this);
return tmp_bfr.XtoAryAndClear();
}
public void XferAry(Bry_bfr bfr, int idx) {
for (int i = 0; i < list_len; ++i) {
Sites_regy_itm itm = (Sites_regy_itm)list.FetchAt(i);
byte[] href = url_fmtr.Fmt_(itm.Xwiki_itm().Fmt()).Bld_bry_many(tmp_ttl, itm.Ttl().Page_db());
fmtr_itm.Bld_bfr(bfr, itm.Cls(), href, itm.Xwiki_itm().Name());
}
}
private static final Bry_fmtr
fmtr_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div id=\"p-relatedsites\" class=\"portal\">"
, " <h3>~{related_sites_hdr}</h3>"
, " <div class=\"body\">"
, " <ul>~{itms}"
, " </ul>"
, " </div>"
, "</div>"
), "related_sites_hdr", "itms")
, fmtr_itm = Bry_fmtr.new_
( "\n <li class=\"interwiki-~{key}\"><a href=\"~{href}\">~{name}</a></li>"
, "key", "href", "name")
;
}

View File

@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Sites_html_bldr_tst {
@Before public void init() {fxt.Clear();} private Sites_html_bldr_fxt fxt = new Sites_html_bldr_fxt();
@Test public void Basic() {
fxt.Init_ttl("commons:A");
fxt.Init_ttl("w:A");
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( "<div id=\"p-relatedsites\" class=\"portal\">"
, " <h3>Related articles</h3>"
, " <div class=\"body\">"
, " <ul>"
, " <li class=\"interwiki-commons\"><a href=\"commons.wikimedia.org/wiki/Category:A\">Wikimedia Commons</a></li>"
, " <li class=\"interwiki-w\"><a href=\"en.wikipedia.org/wiki/A\">Wikipedia</a></li>"
, " </ul>"
, " </div>"
, "</div>"
));
}
}
class Sites_html_bldr_fxt {
private Xoa_app app; private Xow_wiki wiki;
private ListAdp list = ListAdp_.new_();
private Sites_xtn_mgr xtn_mgr;
public void Clear() {
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
wiki.Xwiki_mgr().Add_many(Bry_.new_ascii_("w|en.wikipedia.org/wiki/$1|Wikipedia\ncommons|commons.wikimedia.org/wiki/Category:$1|Wikimedia Commons"));
wiki.Lang().Msg_mgr().Itm_by_key_or_new("relatedarticles-title", "Related articles");
this.xtn_mgr = wiki.Xtn_mgr().Xtn_sites();
xtn_mgr.Enabled_y_();
xtn_mgr.Xtn_init_by_wiki(wiki);
list.Clear();
}
public void Init_ttl(String lnki_ttl) {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_utf8_(lnki_ttl));
xtn_mgr.Match(ttl, list);
}
public void Test_bld(String expd) {
byte[] actl = xtn_mgr.Html_bldr().Bld_all(list);
Tfds.Eq_str_lines(expd, String_.new_utf8_(actl));
}
}

View File

@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.xwikis.*;
public class Sites_regy_itm {
public Sites_regy_itm(Xow_xwiki_itm xwiki_itm, Xoa_ttl ttl) {
this.xwiki_itm = xwiki_itm; this.ttl = ttl;
this.cls = Bry_.Lower_ascii(Bry_.Copy(xwiki_itm.Key_bry()));
}
public Xow_xwiki_itm Xwiki_itm() {return xwiki_itm;} private Xow_xwiki_itm xwiki_itm;
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
public byte[] Cls() {return cls;} private byte[] cls;
}

View File

@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.html.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
public class Sites_xtn_mgr extends Xox_mgr_base {
private Xow_xwiki_mgr xwiki_mgr;
public Sites_xtn_mgr() {
html_bldr = new Sites_html_bldr(this);
}
@Override public boolean Enabled_default() {return false;}
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_ascii_("relatedSites");
@Override public Xox_mgr Clone_new() {return new Sites_xtn_mgr();}
@Override public void Xtn_init_by_wiki(Xow_wiki wiki) {
this.wiki = wiki;
this.xwiki_mgr = wiki.Xwiki_mgr();
if (!Enabled()) return;
msg_related_sites = wiki.Msg_mgr().Val_by_key_obj("relatedarticles-title");
}
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public Sites_html_bldr Html_bldr() {return html_bldr;} private Sites_html_bldr html_bldr;
public byte[] Msg_related_sites() {return msg_related_sites;} private byte[] msg_related_sites;
public void Match(Xoa_ttl lnki_ttl, ListAdp list) {
if (!this.Enabled()) return;
byte[] xwiki_key = lnki_ttl.Wik_txt();
Xow_xwiki_itm xwiki_itm = xwiki_mgr.Get_by_key(xwiki_key); if (xwiki_itm == null) return;
Sites_regy_itm sites_itm = new Sites_regy_itm(xwiki_itm, lnki_ttl);
list.Add(sites_itm);
}
}

View File

@ -161,6 +161,7 @@ public class Scrib_core {
Scrib_lua_mod mod = Mods_get_or_new(mod_name, mod_text);
KeyVal[] func_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_utf8_(fnc_name));
KeyVal[] func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeModule"), func_args); // call init_chunk to get proc dynamically; DATE:2014-07-12
if (func_rslt == null || func_rslt.length == 0) throw Err_.new_("lua.error:function did not return a value; fnc_name=~{0}", String_.new_utf8_(fnc_name));
Scrib_lua_proc proc = (Scrib_lua_proc)func_rslt[1].Val(); // note that init_chunk should have: [0]:true/false result; [1]:proc
func_args = Scrib_kv_utl_.base1_many_(proc);
func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeFunction"), func_args); // call function now
@ -186,18 +187,13 @@ public class Scrib_core {
}
public static Scrib_core Core() {return core;} public static Scrib_core Core_new_(Xoa_app app, Xop_ctx ctx) {core = new Scrib_core(app, ctx); return core;} private static Scrib_core core;
public void Handle_error(String err, String traceback) {
byte[] excerpt = Bry_.Empty;
String excerpt = "";
try {
Xot_invk src_frame = frame_current;
if (src_frame != null)
excerpt = Bry_.Mid(cur_src, src_frame.Src_bgn(), src_frame.Src_end());
excerpt = String_.new_utf8_(cur_src, src_frame.Src_bgn(), src_frame.Src_end());
} catch (Exception e) {Err_.Noop(e);}
app.Usr_dlg().Warn_many("", "", "lua error; page=~{0} excerpt=~{1} err=~{2} ~{3}"
, page.Ttl().Page_db_as_str()
, String_.new_utf8_(excerpt)
, err
, traceback
);
throw Err_.new_(err, page.Ttl().Page_db_as_str(), excerpt, traceback);
}
public static void Core_page_changed(Xoa_page page) {
if (core != null) {

View File

@ -57,7 +57,7 @@ public class Scrib_invoke_func extends Pf_func_base {
invoke_wkr.Eval_end(ctx.Cur_page(), mod_name, fnc_name, log_time_bgn);
}
catch (Exception e) {
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
Error(bfr, wiki.Msg_mgr(), "");
bfr.Add(Html_tag_.Comm_bgn).Add_str(Err_.Message_gplx_brief(e)).Add(Html_tag_.Comm_end);
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", String_.new_utf8_(ctx.Cur_page().Ttl().Raw()), String_.new_utf8_(src, self.Src_bgn(), self.Src_end()), Err_.Message_gplx_brief(e));
Scrib_core.Core_invalidate(); // reset core
@ -65,7 +65,7 @@ public class Scrib_invoke_func extends Pf_func_base {
}
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, String error) {Error(bfr, msg_mgr, Bry_.new_utf8_(error));}
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, byte[] error) {
Bry_fmtr fmtr = Bry_fmtr.new_("<strong class=\"error\"><span class=\"scribunto-error\" id=\"mw-scribunto-error-0\">~{0}: ~{1}.</span></strong>"); // <!--~{0}: ~{1}.-->
Bry_fmtr fmtr = Bry_fmtr.new_("<strong class=\"error\"><span class=\"scribunto-error\" id=\"mw-scribunto-error-0\">~{0} ~{1}</span></strong>"); // <!--~{0}: ~{1}.-->
byte[] script_error_msg = msg_mgr.Val_by_id(Xol_msg_itm_.Id_scribunto_parser_error);
fmtr.Bld_bfr_many(bfr, script_error_msg, error);
}

View File

@ -27,6 +27,7 @@ public class Luaj_engine implements Scrib_engine {
server = new Luaj_server(core, debug_enabled);
proc_mgr = core.Proc_mgr();
Luaj_server_func_recv._.Engine_(this);
Luaj_server_func_dbg._.Core_(core);
}
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {server = (Luaj_server)v;}
public boolean Dbg_print() {return dbg_print;} public void Dbg_print_(boolean v) {dbg_print = v;} private boolean dbg_print;

View File

@ -27,7 +27,7 @@ public class Luaj_server implements Scrib_server {
Globals_singleton = JsePlatform.standardGlobals();
Globals_singleton.load(new DebugLib());
Globals_singleton.load(new MWClient());
Globals_singleton.set("dbg", Luaj_server_func_dbg._);
String root_str = init_args[2];
if (Op_sys.Cur().Tid_is_wnt())
root_str = String_.Replace(root_str, Op_sys.Wnt.Fsys_dir_spr_str(), Op_sys.Lnx.Fsys_dir_spr_str());

View File

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.engines.luaj; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.VarArgFunction;
public class Luaj_server_func_dbg extends VarArgFunction {
private Scrib_core core;
public void Core_(Scrib_core v) {this.core = v;}
public Varargs invoke(Varargs args) {
int len = args.narg();
Bry_bfr bfr = Bry_bfr.new_();
bfr.Add_str("<span class='xowa_dbg' style='color:red'>");
for (int i = 1; i <= len; ++i)
bfr.Add_str(gplx.html.Html_utl.Escape_html_as_str(args.arg(i).strvalue().toString()));
bfr.Add_str("</span><br/>");
core.Page().Html_data().Dbg_(bfr.XtoAryAndClear());
return NONE;
}
public static Luaj_server_func_dbg _ = new Luaj_server_func_dbg();
}

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/>.
*/
package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.pfuncs.ttls.*;
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.wikis.xwikis.*;
public class Scrib_lib_title implements Scrib_lib {
public Scrib_lib_title(Scrib_core core) {this.core = core;} private Scrib_core core;
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;

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/>.
*/
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.wdatas.imports.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.wdatas.imports.*;
import gplx.xowa.langs.*;
public class Wdata_wiki_mgr_fxt {
public Xow_wiki Wiki() {return parser_fxt.Wiki();}

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/>.
*/
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.json.*; import gplx.xowa.wikis.*; import gplx.xowa.xtns.wdatas.*;
import gplx.json.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.xtns.wdatas.*;
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 void XferAry(Bry_bfr bfr, int idx) {

View File

@ -34,7 +34,8 @@ public class Wdata_xwiki_link_wtr_tst {
fxt.Init_external_links_mgr_clear();
fxt.Test_parse_langs("{{noexternallanglinks:de}}", String_.Concat_lines_nl
( "<div id=\"xowa-lang\">"
, " <h5>In other languages (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
, " <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>"
@ -42,6 +43,7 @@ public class Wdata_xwiki_link_wtr_tst {
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Links_w_name_fmt() { // PURPOSE: wikidata changed links node from "enwiki:A" to "enwiki:{name:A,badges:[]}"; DATE:2013-09-14

View File

@ -32,6 +32,10 @@ public class Gfo_usr_dlg_base implements Gfo_usr_dlg {
public String Note_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wtr.Log_msg_to_session(rv); ui_wkr.Write_note(rv); return rv;}
public String Note_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); log_wtr.Log_msg_to_session(rv); ui_wkr.Write_note(rv); return rv;}
public String Note_gui_none(String grp_key, String msg_key, String fmt) {String rv = Bld_msg_none(grp_key, msg_key, fmt ); ui_wkr.Write_note(rv); return rv;}
public String Plog_many(String grp_key, String msg_key, String fmt, Object... args) {
String rv = Log_many(grp_key, msg_key, fmt, args);
return Prog_direct(rv);
}
public Err Fail_many(String grp_key, String msg_key, String fmt, Object... args) {
Err rv = Err_.new_(Bld_msg_many(grp_key, msg_key, fmt, args));
log_wtr.Log_err(Err_.Message_gplx(rv));

View File

@ -45,21 +45,3 @@ public class Xoac_wiki_grp implements Cfg_nde_obj, Xoac_wiki_obj {
public Cfg_nde_obj Itms_get_at(int i) {return (Cfg_nde_obj)itms.FetchAt(i);}
OrderedHash itms = OrderedHash_.new_bry_();
}
class Xoac_wiki_itm implements Cfg_nde_obj, Xoac_wiki_obj {
public Xoac_wiki_itm(byte[] key) {this.key_bry = key;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[][] Aliases() {return aliases;} private byte[][] aliases;
public byte[] Nde_key() {return key_bry;}
public boolean Nde_typ_is_grp() {return false;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_make", "leafs cannot have itms: ~{0} ~{1}", itm_type, itm_key);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_get", "leafs cannot have itms: ~{0}", key);}
public int Nde_subs_len() {return 0;}
public Cfg_nde_obj Nde_subs_get_at(int i) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_get", "leafs cannot have itms: ~{0}", i);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_add", "leafs cannot have itms: ~{0}", String_.new_utf8_(itm_key));}
public void Nde_subs_del(byte[] key) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_del", "leafs cannot delete itms: ~{0}", String_.new_utf8_(key));}
public void Nde_atrs_set(byte[][] ary) {
int ary_len = ary.length;
if (ary_len > 0) aliases = Bry_.Split(ary[0], Byte_ascii.Semic);
}
static final String GRP_KEY = "xowa.wikis.itms";
}

View File

@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
public class Xoac_wiki_itm implements Cfg_nde_obj, Xoac_wiki_obj {
public Xoac_wiki_itm(byte[] key) {this.key_bry = key;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[][] Aliases() {return aliases;} private byte[][] aliases;
public byte[] Nde_key() {return key_bry;}
public boolean Nde_typ_is_grp() {return false;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_make", "leafs cannot have itms: ~{0} ~{1}", itm_type, itm_key);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_get", "leafs cannot have itms: ~{0}", key);}
public int Nde_subs_len() {return 0;}
public Cfg_nde_obj Nde_subs_get_at(int i) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_get", "leafs cannot have itms: ~{0}", i);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_add", "leafs cannot have itms: ~{0}", String_.new_utf8_(itm_key));}
public void Nde_subs_del(byte[] key) {throw Err_mgr._.fmt_(GRP_KEY, "invalid_sub_del", "leafs cannot delete itms: ~{0}", String_.new_utf8_(key));}
public void Nde_atrs_set(byte[][] ary) {
int ary_len = ary.length;
if (ary_len > 0) aliases = Bry_.Split(ary[0], Byte_ascii.Semic);
}
static final String GRP_KEY = "xowa.wikis.itms";
}

View File

@ -18,24 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa; import gplx.*;
import gplx.xowa.langs.numbers.*;
public class Xow_fragment_mgr implements GfoInvkAble {
private static final byte[] Date_format_default = Bry_.new_ascii_("dmy");
private static final byte[] Num_format_digits = Bry_.new_ascii_("['', '']");
public byte[] Html_js_table() {return html_js_table;} private byte[] html_js_table;
public Xow_fragment_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
private Bry_fmtr html_js_table_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
( " var xowa_global_values = {"
, " 'collapsible-collapse' : '~{collapsible-collapse}',"
, " 'collapsible-expand' : '~{collapsible-expand}',"
, " 'sort-descending' : '~{sort-descending}',"
, " 'sort-ascending' : '~{sort-ascending}',"
, " 'wgContentLanguage' : '~{wgContentLanguage}',"
, " 'wgSeparatorTransformTable' : ~{wgSeparatorTransformTable},"
, " 'wgDigitTransformTable' : ~{wgDigitTransformTable},"
, " 'wgDefaultDateFormat' : '~{wgDefaultDateFormat}',"
, " 'wgMonthNames' : ~{wgMonthNames},"
, " 'wgMonthNamesShort' : ~{wgMonthNamesShort},"
, " };"
), "collapsible-collapse", "collapsible-expand", "sort-descending", "sort-ascending", "wgContentLanguage", "wgSeparatorTransformTable", "wgDigitTransformTable", "wgDefaultDateFormat", "wgMonthNames", "wgMonthNamesShort");
public byte[] Html_js_edit_toolbar() {return html_js_edit_toolbar;} private byte[] html_js_edit_toolbar;
private Bry_fmtr html_js_edit_toolbar_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
( " var xowa_edit_i18n = {"
@ -54,33 +37,15 @@ public class Xow_fragment_mgr implements GfoInvkAble {
, " };"
), "bold_tip", "bold_sample", "italic_tip", "italic_sample", "link_tip", "link_sample", "headline_tip", "headline_sample", "ulist_tip", "ulist_sample", "olist_tip", "olist_sample");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_html_js_table_fmt_)) html_js_table_fmtr.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_html_js_table)) return html_js_table;
else if (ctx.Match(k, Invk_html_js_edit_toolbar_fmt_)) html_js_edit_toolbar_fmtr.Fmt_(m.ReadBry("v"));
if (ctx.Match(k, Invk_html_js_edit_toolbar_fmt_)) html_js_edit_toolbar_fmtr.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_html_js_edit_toolbar)) return html_js_edit_toolbar;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_html_js_table_fmt_ = "html_js_table_fmt_", Invk_html_js_table = "html_js_table", Invk_html_js_edit_toolbar_fmt_ = "html_js_edit_toolbar_fmt_", Invk_html_js_edit_toolbar = "html_js_edit_toolbar";
public static final String Invk_html_js_edit_toolbar_fmt_ = "html_js_edit_toolbar_fmt_", Invk_html_js_edit_toolbar = "html_js_edit_toolbar";
public void Evt_lang_changed(Xol_lang lang) {
Bry_bfr bfr = lang.App().Utl_bry_bfr_mkr().Get_b512();
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
byte[] months_long = Html_js_table_months(bfr, msg_mgr, Xol_msg_itm_.Id_dte_month_name_january, Xol_msg_itm_.Id_dte_month_name_december);
byte[] months_short = Html_js_table_months(bfr, msg_mgr, Xol_msg_itm_.Id_dte_month_abrv_jan, Xol_msg_itm_.Id_dte_month_abrv_dec);
byte[] num_format_separators = Html_js_table_num_format_separators(bfr, lang.Num_mgr().Separators_mgr());
html_js_table = html_js_table_fmtr.Bld_bry_many(bfr
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_collapsible_collapse)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_collapsible_expand)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_sort_descending)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_sort_ascending)
, lang.Key_bry()
, num_format_separators
, Num_format_digits
, Date_format_default
, months_long
, months_short
);
msg_mgr = wiki.App().User().Msg_mgr();
Xow_msg_mgr msg_mgr = wiki.App().User().Msg_mgr();
html_js_edit_toolbar = html_js_edit_toolbar_fmtr.Bld_bry_many(bfr
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_tip)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_sample)
@ -97,23 +62,4 @@ public class Xow_fragment_mgr implements GfoInvkAble {
);
bfr.Mkr_rls();
}
byte[] Html_js_table_months(Bry_bfr bfr, Xow_msg_mgr msg_mgr, int january_id, int december_id) {
// ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Apos);
for (int i = january_id; i <= december_id; i++) {
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Apos);
bfr.Add(msg_mgr.Val_by_id(i));
bfr.Add_byte(Byte_ascii.Apos);
}
bfr.Add_byte(Byte_ascii.Brack_end);
return bfr.XtoAryAndClear();
}
private byte[] Html_js_table_num_format_separators(Bry_bfr bfr, Xol_transform_mgr separator_mgr) {
byte[] dec_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__dec);
bfr.Add_byte(Byte_ascii.Brack_bgn) .Add_byte(Byte_ascii.Apos).Add(dec_spr).Add_byte(Byte_ascii.Tab).Add_byte(Byte_ascii.Dot).Add_byte(Byte_ascii.Apos);
byte[] grp_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__grp);
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space) .Add_byte(Byte_ascii.Apos).Add(grp_spr).Add_byte(Byte_ascii.Tab).Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Apos);
bfr.Add_byte(Byte_ascii.Brack_end);
return bfr.XtoAryAndClear();
}
}

View File

@ -21,42 +21,6 @@ import gplx.xowa.langs.numbers.*;
public class Xow_fragment_mgr_tst {
Xow_fragment_mgr_fxt fxt = new Xow_fragment_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Html_js_table_fmt() {
fxt.Test_fragment(Xow_fragment_mgr.Invk_html_js_table, String_.Concat_lines_nl
( " var xowa_global_values = {"
, " 'collapsible-collapse' : 'Collapse',"
, " 'collapsible-expand' : 'Expand',"
, " 'sort-descending' : 'Sort descending',"
, " 'sort-ascending' : 'Sort ascending',"
, " 'wgContentLanguage' : 'en',"
, " 'wgSeparatorTransformTable' : ['.\t.', ',\t,'],"
, " 'wgDigitTransformTable' : ['', ''],"
, " 'wgDefaultDateFormat' : 'dmy',"
, " 'wgMonthNames' : ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
, " };"
));
}
@Test public void Html_js_table_fmt_la() { // PURPOSE: la.gfs only specifies "," not "."; make sure both "." and "," show up, or else null ref error during import; DATE:2014-05-13
Xol_lang la_lang = fxt.Make_lang("la");
Xol_transform_mgr separators_mgr = la_lang.Num_mgr().Separators_mgr();
separators_mgr.Clear();
separators_mgr.Set(Xol_num_mgr.Separators_key__grp, Bry_.new_ascii_(" "));
fxt.Test_fragment(la_lang, Xow_fragment_mgr.Invk_html_js_table, String_.Concat_lines_nl
( " var xowa_global_values = {"
, " 'collapsible-collapse' : 'Collapse',"
, " 'collapsible-expand' : 'Expand',"
, " 'sort-descending' : 'Sort descending',"
, " 'sort-ascending' : 'Sort ascending',"
, " 'wgContentLanguage' : 'la',"
, " 'wgSeparatorTransformTable' : ['.\t.', ' \t,'],"
, " 'wgDigitTransformTable' : ['', ''],"
, " 'wgDefaultDateFormat' : 'dmy',"
, " 'wgMonthNames' : ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
, " };"
));
}
@Test public void Html_js_edit_toolbar_fmt() {
fxt.Test_fragment(Xow_fragment_mgr.Invk_html_js_edit_toolbar, String_.Concat_lines_nl
( " var xowa_edit_i18n = {"

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/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.wikis.xwikis.*;
public class Xow_lang_itm {
public Xow_lang_itm(Xow_lang_grp html_grp, Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
this.html_grp = html_grp; this.xwiki = xwiki; this.lang = lang;

View File

@ -16,17 +16,20 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.html.*;
public class Xow_lang_mgr {
Xow_lang_mgr() {
int len = Xol_lang_itm_.Id__max;
itms = new Xow_lang_itm[len];
}
public Bry_fmtr Html_div() {return html_div;} Bry_fmtr html_div = Bry_fmtr.new_(
String_.Concat_lines_nl_skip_last
public Bry_fmtr Html_div() {return html_div;} Bry_fmtr html_div = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5>~{langs_hdr}~{wikidata_link}</h5>~{grps}"
, " <h5>~{langs_hdr}~{wikidata_link}<a href='javascript:xowa_toggle_visible(\"wikidata-langs\");'><img id='wikidata-langs-toggle-icon' src='~{icon_src}' title='~{icon_title}' /></a></h5>"
, " <div id='wikidata-langs-toggle-elem' style='~{elem_display}'>~{grps}"
, " </div>"
), "grps", "langs_hdr", "wikidata_link");
, "</div>"
), "langs_hdr", "wikidata_link", "icon_src", "icon_title", "elem_display", "grps");
public Bry_fmtr Html_wikidata_link() {return html_wikidata_link;} Bry_fmtr html_wikidata_link = Bry_fmtr.new_(" (<a href=\"/site/www.wikidata.org/wiki/~{qid}\">wikidata</a>)", "qid");
public void Clear() {hash.Clear();}
public void Itms_reg(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
@ -103,8 +106,10 @@ class Xow_lang_html implements Bry_fmtr_arg {
case 0: {
stage = 1;
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b128().Mkr_rls();
byte[] msg_lang = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_page_lang_header);
byte[] wikidata_link = Bry_.Len_eq_0(qid) ? Bry_.Empty : lang_mgr.Html_wikidata_link().Bld_bry_many(tmp_bfr, qid);
lang_mgr.Html_div().Bld_bfr_many(bfr, this, wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_page_lang_header), wikidata_link);
Xoapi_toggle_itm visible_data = wiki.App().Api_root().Html().Page().Toggle_mgr().Itm_wikidata_langs().Init(wiki);
lang_mgr.Html_div().Bld_bfr_many(bfr, msg_lang, wikidata_link, visible_data.Icon_src(), visible_data.Icon_title(), visible_data.Elem_display(), this);
stage = 0;
break;
}

View File

@ -23,7 +23,8 @@ public class Xow_lang_mgr_tst {
@Test public void Basic() {
fxt.tst("[[simple:Earth]] [[fr:Terre]] [[es:Tierra]] [[de:Erde]] [[it:Terre]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5>In other languages</h5>"
, " <h5>In other languages<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>"
@ -40,12 +41,14 @@ public class Xow_lang_mgr_tst {
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Empty() {
fxt.tst("[[simple:]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5>In other languages</h5>"
, " <h5>In other languages<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>"
@ -53,13 +56,15 @@ public class Xow_lang_mgr_tst {
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Unregistered() {
// fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_utf8_("zh"), Bry_.new_utf8_("zh.wikipedia.org"), Bry_.new_utf8_("http://zh.wikipedia.org/~{0}"));
fxt.tst("[[zh:Earth]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5>In other languages</h5>"
, " <h5>In other languages<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>"
@ -67,12 +72,14 @@ public class Xow_lang_mgr_tst {
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Anchor() {// PURPOSE: A#b was not showing anchor "#b"; DATE:2013-10-23
fxt.tst("[[simple:A#b]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5>In other languages</h5>"
, " <h5>In other languages<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>"
@ -80,6 +87,7 @@ public class Xow_lang_mgr_tst {
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
}

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa; import gplx.*;
import gplx.xowa.apps.*;
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.html.*; import gplx.xowa.users.history.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.setup.maints.*; import gplx.xowa.wikis.caches.*;
import gplx.xowa.bldrs.imports.*; import gplx.xowa.xtns.pfuncs.*;
public class Xow_wiki implements GfoInvkAble {

View File

@ -22,6 +22,31 @@ public class Xol_kwd_mgr implements GfoInvkAble {
public int Len() {return grps.length;}
public Btrie_slim_mgr Trie_raw() {if (trie_raw == null) trie_raw = Xol_kwd_mgr.trie_(this, Xol_kwd_grp_.Id_str_rawsuffix); return trie_raw;} private Btrie_slim_mgr trie_raw;
public Btrie_slim_mgr Trie_nosep() {if (trie_nosep == null) trie_nosep = Xol_kwd_mgr.trie_(this, Xol_kwd_grp_.Id_nocommafysuffix); return trie_nosep;} private Btrie_slim_mgr trie_nosep;
public void Kwd_default_match_reset() {kwd_default_init_needed = true;} // TEST:
public boolean Kwd_default_match(byte[] match) { // handle multiple #default keywords; DATE:2014-07-28
if (match == null) return false; // null never matches #default
int match_len = match.length;
if (match_len == 0) return false; // "" never matches default
if (kwd_default_init_needed) {
kwd_default_init_needed = false;
Xol_kwd_grp grp = this.Get_at(Xol_kwd_grp_.Id_xtn_default);
int len = grp.Itms().length;
if (len == 1)
kwd_default_key = grp.Itms()[0].Val();
else {
kwd_default_trie = Btrie_slim_mgr.new_(grp.Case_match());
for (int i = 0; i < len; i++) {
Xol_kwd_itm itm = grp.Itms()[i];
kwd_default_trie.Add_obj(itm.Val(), itm);
}
}
}
return kwd_default_trie == null
? Bry_.HasAtBgn(match, kwd_default_key, 0, match_len)
: kwd_default_trie.Match_bgn(match, 0, match_len) != null
;
}
private Btrie_slim_mgr kwd_default_trie; private byte[] kwd_default_key; private boolean kwd_default_init_needed = true;
public Xol_kwd_grp Get_at(int id) {return grps[id];}
public Xol_kwd_grp Get_or_new(int id) {
Xol_kwd_grp rv = grps[id];

Some files were not shown because too many files have changed in this diff Show More