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-10 23:10:23 -04:00
parent fb8c06c560
commit 67b04263a7
131 changed files with 2285 additions and 1355 deletions

View File

@ -72,6 +72,7 @@ public class Byte_ascii {
public static final byte[]
Tab_bry = new byte[] {Byte_ascii.Tab}
, NewLine_bry = new byte[] {Byte_ascii.NewLine}
, Bang_bry = new byte[] {Byte_ascii.Bang}
, Dot_bry = new byte[] {Byte_ascii.Dot}
, Comma_bry = new byte[] {Byte_ascii.Comma}
, Colon_bry = new byte[] {Byte_ascii.Colon}

View File

@ -30,7 +30,8 @@ public class Swt_app_main {
public static void main(String[] args) {
// Drag_drop();
// List_fonts();
keystrokes(args);
// keystrokes(args);
Permission_denied();
}
static void Drag_drop() {
final Display display = new Display();

View File

@ -228,7 +228,9 @@ class Swt_html_lnr_location implements LocationListener {
String location = arg.location;
if (String_.Eq(location, "about:blank")) return; // location changing event fires once when page is loaded; ignore
if ( html_box.Html_doc_html_load_tid() == Gxw_html_load_tid_.Tid_url // navigating to file://page.html will fire location event; ignore if url mode
&& String_.HasAtEnd(location, ".html"))
&& String_.HasAtBgn(location, "file:")
&& String_.HasAtEnd(location, ".html")
)
return;
try {
GfoEvMgr_.PubObj(host, evt, "v", location);

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.json; import gplx.*;
public class Json_parser {
public Json_factory Factory() {return factory;} Json_factory factory = new Json_factory();
public Json_factory Factory() {return factory;} private Json_factory factory = new Json_factory();
private byte[] src; private int src_len, pos; private NumberParser num_parser = new NumberParser();
private static final byte[] Bry_bool_rue = Bry_.new_ascii_("rue"), Bry_bool_alse = Bry_.new_ascii_("alse"), Bry_null_ull = Bry_.new_ascii_("ull");
public Json_doc Parse(byte[] src) {

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.php; import gplx.*;
public class Php_text_itm_parser {
public static final byte Rslt_orig = 0, Rslt_dirty = 1, Rslt_fmt = 2;
public boolean Quote_is_single() {return quote_is_single;} public Php_text_itm_parser Quote_is_single_(boolean v) {quote_is_single = v; return this;} private boolean quote_is_single;
public byte[] Parse_as_bry(ListAdp tmp_list, byte[] raw, Byte_obj_ref rslt_ref, Bry_bfr tmp_bfr) {
Parse(tmp_list, raw, rslt_ref);
byte[] rv = raw;
@ -49,34 +50,52 @@ public class Php_text_itm_parser {
switch (b) {
case Byte_ascii.Backslash:
if (txt_bgn != -1) {tmp_list.Add(new Php_text_itm_text(txt_bgn, i)); txt_bgn = -1; rslt_val = Rslt_dirty;}
if (i == raw_last) throw Err_mgr._.fmt_auto_(GRP_KEY, "backslash_is_last_char", String_.new_utf8_(raw));
boolean pos_is_last = i == raw_last;
int next_pos = i + 1;
byte next_char = raw[next_pos];
switch (next_char) {
case Byte_ascii.Ltr_N:
case Byte_ascii.Ltr_n: next_char = Byte_ascii.NewLine; break;
case Byte_ascii.Ltr_T:
case Byte_ascii.Ltr_t: next_char = Byte_ascii.Tab; break;
case Byte_ascii.Ltr_R:
case Byte_ascii.Ltr_r: next_char = Byte_ascii.CarriageReturn; break;
case Byte_ascii.Ltr_U:
case Byte_ascii.Ltr_u: { // EX: "\u007C"
rslt_val = Rslt_dirty;
Parse_utf16(tmp_list, raw, next_pos + 1, raw_len); // +1 to skip u
i = next_pos + 4; // +4 to skip utf16 seq; EX: \u007C; +4 for 007C
continue;
}
case Byte_ascii.Ltr_X:
case Byte_ascii.Ltr_x: { // EX: "\xc2"
rslt_val = Rslt_dirty;
byte[] literal = Bry_.Add(CONST_utf_prefix, Bry_.Mid(raw, next_pos + 1, next_pos + 3));
tmp_list.Add(new Php_text_itm_utf16(i, i + 4, literal));
i = next_pos + 2; // +2 to skip rest; EX: \xc2; +2 for c2
continue;
byte next_char = pos_is_last ? Byte_ascii.Nil : raw[next_pos];
if (quote_is_single) { // NOTE: q1 is simpler than q2; REF.MW:http://php.net/manual/en/language.types.String.php; DATE:2014-08-06
switch (next_char) {
case Byte_ascii.Apos: next_char = Byte_ascii.Apos; break;
case Byte_ascii.Backslash: next_char = Byte_ascii.Backslash; break;
default: next_char = Byte_ascii.Nil; break;
}
}
tmp_list.Add(new Php_text_itm_escaped(i, next_pos, next_char)); rslt_val = Rslt_dirty;
i = next_pos;
else {
if (pos_is_last) throw Err_mgr._.fmt_auto_(GRP_KEY, "backslash_is_last_char", String_.new_utf8_(raw));
switch (next_char) {
case Byte_ascii.Backslash: next_char = Byte_ascii.Backslash; break;
case Byte_ascii.Quote: next_char = Byte_ascii.Quote; break;
case Byte_ascii.Ltr_N:
case Byte_ascii.Ltr_n: next_char = Byte_ascii.NewLine; break;
case Byte_ascii.Ltr_T:
case Byte_ascii.Ltr_t: next_char = Byte_ascii.Tab; break;
case Byte_ascii.Ltr_R:
case Byte_ascii.Ltr_r: next_char = Byte_ascii.CarriageReturn; break;
case Byte_ascii.Ltr_U:
case Byte_ascii.Ltr_u: { // EX: "\u007C"
rslt_val = Rslt_dirty;
Parse_utf16(tmp_list, raw, next_pos + 1, raw_len); // +1 to skip u
i = next_pos + 4; // +4 to skip utf16 seq; EX: \u007C; +4 for 007C
continue;
}
case Byte_ascii.Ltr_X:
case Byte_ascii.Ltr_x: { // EX: "\xc2"
rslt_val = Rslt_dirty;
byte[] literal = Bry_.Add(CONST_utf_prefix, Bry_.Mid(raw, next_pos + 1, next_pos + 3));
tmp_list.Add(new Php_text_itm_utf16(i, i + 4, literal));
i = next_pos + 2; // +2 to skip rest; EX: \xc2; +2 for c2
continue;
}
default: next_char = Byte_ascii.Nil; break;
}
}
if (next_char == Byte_ascii.Nil) {
if (txt_bgn == -1) txt_bgn = i;
}
else {
tmp_list.Add(new Php_text_itm_escaped(i, next_pos, next_char)); rslt_val = Rslt_dirty;
i = next_pos;
}
break;
case Byte_ascii.Dollar:
if (txt_bgn != -1) {tmp_list.Add(new Php_text_itm_text(txt_bgn, i)); txt_bgn = -1;}

View File

@ -18,13 +18,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.php; import gplx.*;
import org.junit.*;
public class Php_text_itm_tst {
@Test public void Basic() {Tst_("abcde", "abcde");}
@Test public void Escaped() {Tst_("a\\$b\\\"c\\td\\ne", "a$b\"c\td\ne");}
@Test public void Fmt() {Tst_("a$1b$2c", "a~{0}b~{1}c");}
@Test public void Utf16() {Tst_("a\\u007Cd", "a|d");}
@Test public void Utf8_nbsp() {Tst_("a\\xc2\\xa0d", "a\\u00c2\\u00a0d");}
private void Tst_(String raw_str, String expd) {
Php_text_itm_parser parser = new Php_text_itm_parser();
@Before public void init() {fxt.Clear();} private Php_text_itm_fxt fxt = new Php_text_itm_fxt();
@Test public void Q1_basic() {fxt.Init_q1().Test_parse("abcde" , "abcde");}
@Test public void Q1_apos() {fxt.Init_q1().Test_parse("a\\'b" , "a'b");}
@Test public void Q1_backslash() {fxt.Init_q1().Test_parse("a\\\\b" , "a\\b");}
@Test public void Q1_backslash_eos() {fxt.Init_q1().Test_parse("a\\" , "a\\");} // PURPOSE: allow single trailing backslash; DATE:2014-08-06
@Test public void Q1_noop() {fxt.Init_q1().Test_parse("a\\$\\nb" , "a\\$\\nb");}
@Test public void Q2_basic() {fxt.Init_q2().Test_parse("abcde" , "abcde");}
@Test public void Q2_quote() {fxt.Init_q2().Test_parse("a\\\"b" , "a\"b");}
@Test public void Q2_backslash() {fxt.Init_q2().Test_parse("a\\\\b" , "a\\b");}
@Test public void Q2_noop() {fxt.Init_q2().Test_parse("a\\%\\cb" , "a\\%\\cb");}
@Test public void Q2_ws() {fxt.Init_q2().Test_parse("a\\tb\\nc" , "a\tb\nc");}
@Test public void Q2_fmt() {fxt.Init_q2().Test_parse("a$1b$2c" , "a~{0}b~{1}c");}
@Test public void Q2_utf_pipe() {fxt.Init_q2().Test_parse("a\\u007Cd" , "a|d");}
@Test public void Q2_hex_nbsp() {fxt.Init_q2().Test_parse("a\\xc2\\xa0d" , "a\\u00c2\\u00a0d");}
}
class Php_text_itm_fxt {
private Php_text_itm_parser parser;
public void Clear() {parser = new Php_text_itm_parser();}
public Php_text_itm_fxt Init_q1() {parser.Quote_is_single_(Bool_.Y); return this;}
public Php_text_itm_fxt Init_q2() {parser.Quote_is_single_(Bool_.N); return this;}
public void Test_parse(String raw_str, String expd) {
ListAdp list = ListAdp_.new_();
byte[] raw = Bry_.new_utf8_(raw_str);
parser.Parse(list, raw);

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.8.1.1";
public static final String Version = "1.8.2.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";
@ -151,6 +151,7 @@ class Xoa_app_boot_mgr {
if (app_mode_gui)
GfuiEnv_.ShowMsg(Err_.Message_gplx(e));
}
gplx.xowa.apps.setups.Xoa_setup_mgr.Delete_old_files(app);
// launch
app.Launch(); chkpoint = "launch";

View File

@ -24,12 +24,16 @@ public class Xoa_fsys_mgr implements GfoInvkAble {
bin_extensions_dir = bin_any_dir.GenSubDir_nest("xowa", "xtns");
file_dir = root_dir.GenSubDir("file");
wiki_dir = root_dir.GenSubDir("wiki");
cfg_lang_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "lang", "core");
cfg_wiki_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "wiki", "core");
temp_dir = root_dir.GenSubDir("tmp");
app_mgr = new Launcher_app_mgr(app);
}
public Io_url Root_dir() {return root_dir;} private Io_url root_dir;
public Io_url File_dir() {return file_dir;} private Io_url file_dir;
public Io_url Wiki_dir() {return wiki_dir;} public Xoa_fsys_mgr Wiki_dir_(Io_url v) {wiki_dir = v; return this;} private Io_url wiki_dir;
public Io_url Cfg_lang_core_dir() {return cfg_lang_core_dir;} private Io_url cfg_lang_core_dir;
public Io_url Cfg_wiki_core_dir() {return cfg_wiki_core_dir;} private Io_url cfg_wiki_core_dir;
public Io_url Temp_dir() {return temp_dir;} public Xoa_fsys_mgr Temp_dir_(Io_url v) {temp_dir = v; return this;} private Io_url temp_dir; // set to /xowa/user/<name>/temp
public Io_url Bin_any_dir() {return bin_any_dir;} private Io_url bin_any_dir;
public Io_url Bin_extensions_dir() {return bin_extensions_dir;} private Io_url bin_extensions_dir;

View File

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.apps.versions.*;
public class Xoa_setup_mgr {
public static void Delete_old_files(Xoa_app app) {
String version_previous = app.Api_root().App().Env().Version_previous();
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
Delete_old_dir(usr_dlg, version_previous, "1.8.2.1", app.Fsys_mgr().Root_dir().GenSubDir_nest("user", "anonymous", "lang"));
Delete_old_dir(usr_dlg, version_previous, "1.8.2.1", app.Fsys_mgr().Root_dir().GenSubDir_nest("user", "anonymous", "wiki", "#cfg"));
}
@gplx.Internal protected static void Delete_old_dir(Gfo_usr_dlg usr_dlg, String version_prv, String version_del, Io_url dir) {
if (Xoa_version_.Compare(version_prv, version_del) != CompareAble_.Less) return;
usr_dlg.Log_many("", "", "setup:checking if dir exists: version_prv=~{0} version_del=~{1} dir=~{2}", version_prv, version_del, dir.Raw());
if (!Io_mgr._.ExistsDir(dir)) return;
usr_dlg.Log_many("", "", "setup:deleting dir", version_prv, version_del, dir.Raw());
Io_mgr._.DeleteDirDeep(dir);
}
}

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.apps.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_setup_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoa_setup_mgr_fxt fxt = new Xoa_setup_mgr_fxt();
@Test public void Compare() {
fxt.Test_delete_old_dir("mem/dir/", "1.8.1.1" , "1.8.2.1", Bool_.Y); // version is earlier than checkpoint; delete
fxt.Test_delete_old_dir("mem/dir/", "1.8.2.1" , "1.8.2.1", Bool_.N); // version is not earlier than checkpoint; don't delete
fxt.Test_delete_old_dir("mem/dir/", "" , "1.8.2.1", Bool_.Y); // version is empty; delete;
}
}
class Xoa_setup_mgr_fxt {
public void Clear() {}
public void Test_delete_old_dir(String dir_str, String version_prv, String version_del, boolean expd) {
Io_url dir = Io_url_.new_fil_(dir_str);
Io_mgr._.CreateDirIfAbsent(dir);
Xoa_setup_mgr.Delete_old_dir(Gfo_usr_dlg_.Null, version_prv, version_del, dir);
Tfds.Eq(expd, !Io_mgr._.ExistsDir(dir), version_prv + "|" + version_del);
}
}

View File

@ -24,7 +24,7 @@ public class Xoa_version_ {
}
private static int Compare_as_int(String[] lhs_ary, String[] rhs_ary) {
int lhs_ary_len = lhs_ary.length;
int rhs_ary_len = lhs_ary.length;
int rhs_ary_len = rhs_ary.length;
int len_comp = Int_.Compare(lhs_ary_len, rhs_ary_len);
if (len_comp != CompareAble_.Same) return len_comp;
for (int i = 0; i < lhs_ary_len; ++i) {

View File

@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_version_tst {
@Before public void init() {fxt.Clear();} private Xoa_version_fxt fxt = new Xoa_version_fxt();
@Test public void Compare() {
fxt.Test_compare("1.8.1.1", "1.8.2.1" , CompareAble_.Less); // rev:less
fxt.Test_compare("1.8.2.1", "1.8.1.1" , CompareAble_.More); // rev:more
fxt.Test_compare("1.8.1.1", "1.8.1.1" , CompareAble_.Same); // rev:same
fxt.Test_compare("1.7.9.1", "1.8.1.1" , CompareAble_.Less); // min:less
fxt.Test_compare("", "1.8.1.1" , CompareAble_.Less); // empty:less
fxt.Test_compare("1.8.1.1", "" , CompareAble_.More); // empty:more
fxt.Test_compare("", "" , CompareAble_.Same); // empty:more
}
}
class Xoa_version_fxt {
public void Clear() {}
public void Test_compare(String lhs, String rhs, int expd) {
Tfds.Eq(expd, Xoa_version_.Compare(lhs, rhs), lhs + "|" + rhs);
}
}

View File

@ -27,7 +27,7 @@ public class Xob_wiki_cfg_bldr implements GfoInvkAble {
}
private void Exec_fil(Xoac_wiki_cfg_bldr_fil fil) {
String wiki_key = fil.Wiki();
Io_url cfg_file = app.User().Fsys_mgr().Wiki_root_dir().GenSubFil_nest("#cfg", "system", wiki_key + ".gfs");
Io_url cfg_file = app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki_key + ".gfs");
String cfg_text = Io_mgr._.LoadFilStr_args(cfg_file).MissingIgnored_().Exec();
int len = fil.Itms_count();
String_bldr sb = String_bldr_.new_();

View File

@ -172,7 +172,7 @@ class Xob_wiki_cfg_bldr_fxt {
KeyVal kv = (KeyVal)hash.FetchAt(i);
String wiki = kv.Key();
String expd = (String)kv.Val();
String actl = Io_mgr._.LoadFilStr(app.User().Fsys_mgr().Wiki_root_dir().GenSubFil_nest("#cfg", "system", wiki + ".gfs"));
String actl = Io_mgr._.LoadFilStr(app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki + ".gfs"));
Tfds.Eq_str_lines(expd, actl);
}
}

View File

@ -56,7 +56,7 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
int random_int = ns.Count() + 1;
ns.Count_(random_int);
text = zip_mgr.Zip(data_storage_format, text);
int text_stmt_idx = text_stmts_mgr.Get_by_ns(ns.Bldr_file_idx(), text.length);
int text_stmt_idx = text_stmts_mgr.Get_by_ns(ns.Bldr_file_idx(), text.length); // NOTE: was text.length, but want text_len which is original page_len, not compressed; DATE:2014-08-04
Db_stmt text_stmt = text_stmts_mgr.Get_at(text_stmt_idx);
try {
db_mgr.Page_create(page_stmt, text_stmt, page_id, page.Ns_id(), page.Ttl_wo_ns(), redirect, modified, text, random_int, text_stmt_idx);

View File

@ -0,0 +1,81 @@
/*
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.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.json.*; import gplx.php.*; import gplx.gfs.*;
interface Json_itm_wkr {
void Read_kv_sub(byte[] key, byte[] val);
}
abstract class Json_itm_wkr__base implements Json_itm_wkr {
private Json_parser json_parser = new Json_parser();
private Php_text_itm_parser php_quote_parser = new Php_text_itm_parser().Quote_is_single_(true); // assume values are equivalent to php single quote; DATE:2014-08-06
public void Exec(byte[] src) {
ListAdp tmp_list = ListAdp_.new_(); Byte_obj_ref tmp_result = Byte_obj_ref.zero_(); Bry_bfr tmp_bfr = Bry_bfr.reset_(16);
Json_doc jdoc = json_parser.Parse(src);
this.Exec_bgn();
Json_itm_nde root = jdoc.Root();
int subs_len = root.Subs_len();
for (int i = 0; i < subs_len; ++i) {
Json_itm itm = root.Subs_get_at(i);
switch (itm.Tid()) {
case Json_itm_.Tid_kv:
Json_itm_kv kv = (Json_itm_kv)itm;
if (kv.Key().Data_eq(Name_metadata)) continue; // ignore @metadata node
byte[] kv_key = kv.Key().Data_bry();
byte[] kv_val = kv.Val().Data_bry();
kv_val = php_quote_parser.Parse_as_bry(tmp_list, kv_val, tmp_result, tmp_bfr);
Read_kv_sub(kv_key, kv_val);
break;
}
}
this.Exec_end();
}
@gplx.Virtual public void Exec_bgn() {}
@gplx.Virtual public void Exec_end() {}
public abstract void Read_kv_sub(byte[] key, byte[] val);
private static final byte[] Name_metadata = Bry_.new_ascii_("@metadata");
}
class Json_itm_wkr__gfs extends Json_itm_wkr__base {
private Gfs_bldr gfs_bldr = new Gfs_bldr();
private Xol_csv_parser csv_parser = Xol_csv_parser._;
private Bry_bfr bfr;
public byte[] Xto_bry() {return gfs_bldr.Xto_bry();}
@Override public void Exec_bgn() {
bfr = gfs_bldr.Bfr();
gfs_bldr.Add_proc_init_many("this", "messages", "load_text").Add_paren_bgn().Add_nl();
gfs_bldr.Add_quote_xtn_bgn();
}
@Override public void Exec_end() {
gfs_bldr.Add_quote_xtn_end().Add_paren_end().Add_term_nl();
}
@Override public void Read_kv_sub(byte[] key, byte[] val) {
csv_parser.Save(bfr, key); // key
bfr.Add_byte_pipe(); // |
csv_parser.Save(bfr, val); // val
bfr.Add_byte_nl(); // \n
}
}
class Json_itm_wkr__msgs extends Json_itm_wkr__base {
private Xol_msg_mgr msg_mgr; private boolean dirty;
public void Ctor(boolean dirty, Xol_msg_mgr msg_mgr) {this.dirty = dirty; this.msg_mgr = msg_mgr;}
@Override public void Read_kv_sub(byte[] key, byte[] val) {
Xol_msg_itm msg_itm = msg_mgr.Itm_by_key_or_new(key);
Xol_msg_itm_.update_val_(msg_itm, val);
if (dirty) // bldr needs to dirty message to generate lang.gfs; DATE:2014-08-05
msg_itm.Dirty_(true);
}
}

View File

@ -15,20 +15,17 @@ 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_func_tst {
@Before public void init() {fxt.Reset();} private Sites_func_fxt fxt = new Sites_func_fxt();
@Test public void Basic() {
package gplx.xowa.bldrs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
public class Xob_i18n_parser {
public void Load_msgs(boolean dirty, Xol_lang lang, Io_url i18n_fil) {
String i18n_str = Io_mgr._.LoadFilStr_args(i18n_fil).MissingIgnored_().Exec(); if (String_.Len_eq_0(i18n_str)) return;
Json_itm_wkr__msgs wkr = new Json_itm_wkr__msgs();
wkr.Ctor(dirty, lang.Msg_mgr());
wkr.Exec(Bry_.new_utf8_(i18n_str));
}
public byte[] Xto_gfs(byte[] raw) {
Json_itm_wkr__gfs wkr = new Json_itm_wkr__gfs();
wkr.Exec(raw);
return wkr.Xto_bry();
}
}
class Sites_func_fxt {
private Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
}
// public void Test_parse(String raw, String expd) {
// fxt.Test_parse_tmpl_str_test(raw, "{{test}}" , "");
// Tfds.Eq(expd, String_.new_utf8_(fxt.Page().Html_content_sub()));
// }
}

View File

@ -18,33 +18,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.bldrs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import org.junit.*;
import gplx.intl.*;
public class Xob_lang_json_parser_tst {
@Before public void init() {fxt.Clear();} private Xob_lang_json_parser_fxt fxt = new Xob_lang_json_parser_fxt();
@Test public void Core_keywords() {
fxt.Test_parse(String_.Concat_lines_nl_skip_last
public class Xob_i18n_parser_tst {
@Before public void init() {fxt.Clear();} private Xob_i18n_parser_fxt fxt = new Xob_i18n_parser_fxt();
@Test public void Basic() {
fxt.Test_xto_gfs(String_.Concat_lines_nl_skip_last
( "{"
, " \"@metadata\": {"
, " \"authors\": []"
, " },"
, "\"key_1\": \"val_1\","
, "\"key_2\": \"val_2\","
, "\"key_3\": \"val $1\","
, "}"
), String_.Concat_lines_nl_skip_last
( "this.messages.load_text("
, "<:['"
, "key_1|val_1"
, "key_2|val_2"
, "key_3|val ~{0}"
, "']:>"
, ");"
));
}
// @Test public void Load_msgs_validate() {
// fxt.Test_load_msgs_dir("C:\\xowa\\bin\\any\\xowa\\xtns\\Insider\\i18n\\");
// }
}
class Xob_lang_json_parser_fxt {
private Xob_lang_json_parser parser = new Xob_lang_json_parser();
class Xob_i18n_parser_fxt {
private Xob_i18n_parser parser = new Xob_i18n_parser();
public void Clear() {
}
public void Test_parse(String raw, String expd) {
byte[] actl = parser.Parse(Bry_.new_utf8_(raw));
public void Test_xto_gfs(String raw, String expd) {
byte[] actl = parser.Xto_gfs(Bry_.new_utf8_(raw));
Tfds.Eq_str_lines(expd, String_.new_utf8_(actl));
}
public void Test_load_msgs_dir(String dir_str) {
Xoa_app app = Xoa_app_fxt.app_();
Xow_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
Io_url dir_url = Io_url_.new_dir_(dir_str);
Io_url[] fil_urls = Io_mgr._.QueryDir_fils(dir_url);
int len = fil_urls.length;
for (int i = 0; i < len; ++i) {
parser.Load_msgs(false, wiki.Lang(), fil_urls[i]);
}
}
}

View File

@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.json.*; import gplx.gfs.*;
public class Xob_lang_json_parser {
private Json_parser json_parser = new Json_parser();
private Gfs_bldr gfs_bldr = new Gfs_bldr();
private Xol_csv_parser csv_parser = Xol_csv_parser._;
public Xob_lang_json_parser() {}
public byte[] Parse(byte[] raw) {
Json_doc jdoc = json_parser.Parse(raw);
Json_itm_nde jnde = jdoc.Root();
gfs_bldr.Add_proc_init_many("this", "messages", "load_text").Add_paren_bgn().Add_nl();
gfs_bldr.Add_quote_xtn_bgn();
int subs_len = jnde.Subs_len();
Bry_bfr bfr = gfs_bldr.Bfr();
for (int i = 0; i < subs_len; ++i)
Parse_sub(bfr, raw, jnde.Subs_get_at(i));
gfs_bldr.Add_quote_xtn_end().Add_paren_end().Add_term_nl();
return gfs_bldr.Xto_bry();
}
private void Parse_sub(Bry_bfr bfr, byte[] raw, Json_itm itm) {
switch (itm.Tid()) {
case Json_itm_.Tid_kv:
Json_itm_kv kv = (Json_itm_kv)itm;
if (kv.Key().Data_eq(Name_metadata)) return; // ignore @metadata node
byte[] key_bry = kv.Key().Data_bry();
byte[] val_bry = kv.Val().Data_bry();
csv_parser.Save(bfr, key_bry); // key
bfr.Add_byte_pipe(); // |
csv_parser.Save(bfr, val_bry); // val
bfr.Add_byte_nl(); // \n
break;
}
}
private static final byte[] Name_metadata = Bry_.new_ascii_("@metadata");
}

View File

@ -26,10 +26,10 @@ public class Xobc_utl_make_lang implements GfoInvkAble {
} private Xoa_app app; Xol_mw_lang_parser lang_parser;
public Xobc_utl_make_lang_kwds Kwd_mgr() {return kwd_mgr;} private Xobc_utl_make_lang_kwds kwd_mgr;
public void Bld_all() {
Io_url lang_root = app.User().Fsys_mgr().Root_dir().GenSubDir("lang");
Io_url lang_root = app.Fsys_mgr().Cfg_lang_core_dir().OwnerDir(); // OwnerDir to get "/lang/" in "/cfg/lang/core/"
lang_parser.Parse_mediawiki(app, lang_root.GenSubDir("mediawiki"), kwd_mgr);
kwd_mgr.Add_words();
lang_parser.Save_langs(app, lang_root.GenSubDir(Xol_mw_lang_parser.Dir_name_xowa), manual_text_bgn_hash, manual_text_end_hash);
lang_parser.Save_langs(app, lang_root.GenSubDir(Xol_mw_lang_parser.Dir_name_core), manual_text_bgn_hash, manual_text_end_hash);
app.Usr_dlg().Prog_many("", "", "done");
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {

View File

@ -151,16 +151,13 @@ class Xobc_utl_make_lang_fxt {
public Xobcl_kwd_row row_(String key, String... itms) {return new Xobcl_kwd_row(Bry_.new_ascii_(key), Bry_.Ary(itms));}
public void Parse_rows(String raw, Xobcl_kwd_row... expd) {Tfds.Eq_str_lines(Xto_str(expd), Xto_str(Xobc_utl_make_lang_kwds.Parse(Bry_.new_ascii_(raw))));}
public void Ini_file_mw_core(String lang, String raw) {
Io_url fil = app.User().Fsys_mgr().Root_dir().GenSubFil_nest("lang", "mediawiki", "messages", "Messages" + String_.UpperFirst(lang) + ".php");
Io_url fil = app.Fsys_mgr().Cfg_lang_core_dir().OwnerDir().GenSubFil_nest("mediawiki", "core_php", "Messages" + String_.UpperFirst(lang) + ".php");
Io_mgr._.SaveFilStr(fil, raw);
}
public void Tst_file_xo(String lang, String expd) {
Io_url fil = Xol_lang_.xo_lang_fil_(app, lang);
Tfds.Eq_str_lines(expd, Io_mgr._.LoadFilStr(fil));
}
// public void Parse_trailing_colon(String raw, String[] langs, params Xobcl_kwd_row[] expd) {
// Tfds.Eq_str_lines(Xto_str(expd), Xto_str(Xobc_utl_make_lang_kwds.Parse(Bry_.new_ascii_(raw))));
// }
private String Xto_str(Xobcl_kwd_row[] expd) {
int len = expd.length;
for (int i = 0; i < len; i++) {

View File

@ -21,12 +21,12 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
public class Xol_mw_lang_parser {
private Php_parser parser = new Php_parser(); private Php_evaluator evaluator;
public Xol_mw_lang_parser(Gfo_msg_log msg_log) {evaluator = new Php_evaluator(msg_log);}
public void Bld_all(Xoa_app app, Io_url user_root) {Bld_all(app, user_root, Xol_lang_transform_null._);}
public static final String Dir_name_xowa = Xoa_app_.Name;
public void Bld_all(Xoa_app app, Io_url user_root, Xol_lang_transform lang_transform) {
Io_url lang_root = user_root.GenSubDir("lang");
public void Bld_all(Xoa_app app) {Bld_all(app, Xol_lang_transform_null._);}
public static final String Dir_name_core = "core";
public void Bld_all(Xoa_app app, Xol_lang_transform lang_transform) {
Io_url lang_root = app.Fsys_mgr().Cfg_lang_core_dir().OwnerDir();
Parse_mediawiki(app, lang_root.GenSubDir("mediawiki"), lang_transform);
Save_langs(app, lang_root.GenSubDir(Xol_mw_lang_parser.Dir_name_xowa), OrderedHash_.new_bry_(), OrderedHash_.new_bry_());
Save_langs(app, lang_root.GenSubDir(Xol_mw_lang_parser.Dir_name_core), OrderedHash_.new_bry_(), OrderedHash_.new_bry_());
}
public void Save_langs(Xoa_app app, Io_url xowa_root, OrderedHash manual_text_bgn, OrderedHash manual_text_end) {
Xoa_lang_mgr lang_mgr = app.Lang_mgr();
@ -61,11 +61,13 @@ public class Xol_mw_lang_parser {
}
public void Parse_mediawiki(Xoa_app app, Io_url mediawiki_root, Xol_lang_transform lang_transform) {
Bry_bfr bfr = Bry_bfr.new_();
Parse_file_messages(app, mediawiki_root, bfr, lang_transform);
Parse_file_extensions(app, mediawiki_root, bfr, lang_transform);
Parse_file_core_php(app, mediawiki_root, bfr, lang_transform);
Parse_file_xtns_php(app, mediawiki_root, bfr, lang_transform);
Parse_file_json(app, bfr, lang_transform, mediawiki_root.GenSubDir("core_json"));
Parse_file_json(app, bfr, lang_transform, mediawiki_root.GenSubDir("xtns_json"));
}
private void Parse_file_messages(Xoa_app app, Io_url mediawiki_root, Bry_bfr bfr, Xol_lang_transform lang_transform) {
Io_url dir = mediawiki_root.GenSubDir("messages");
private void Parse_file_core_php(Xoa_app app, Io_url mediawiki_root, Bry_bfr bfr, Xol_lang_transform lang_transform) {
Io_url dir = mediawiki_root.GenSubDir("core_php");
Io_url[] urls = Io_mgr._.QueryDir_fils(dir);
int len = urls.length;
for (int i = 0; i < len; i++) {
@ -76,11 +78,11 @@ public class Xol_mw_lang_parser {
String text = Io_mgr._.LoadFilStr(url);
Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(Bry_.new_utf8_(lang_key));
this.Parse_core(text, lang, bfr, lang_transform);
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText("failed to parse " + url.Raw() + Err_.Message_gplx_brief(exc) + "\n");}
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText("failed to parse " + url.NameOnly() + Err_.Message_gplx_brief(exc) + "\n");}
}
}
private void Parse_file_extensions(Xoa_app app, Io_url mediawiki_root, Bry_bfr bfr, Xol_lang_transform lang_transform) {
Io_url dir = mediawiki_root.GenSubDir("extensions");
private void Parse_file_xtns_php(Xoa_app app, Io_url mediawiki_root, Bry_bfr bfr, Xol_lang_transform lang_transform) {
Io_url dir = mediawiki_root.GenSubDir("xtns_php");
Io_url[] urls = Io_mgr._.QueryDir_fils(dir);
int len = urls.length;
for (int i = 0; i < len; i++) {
@ -89,7 +91,24 @@ public class Xol_mw_lang_parser {
String text = Io_mgr._.LoadFilStr(url);
boolean prepend_hash = String_.Eq("ParserFunctions.i18n.magic", url.NameOnly());
this.Parse_xtn(text, url, app, bfr, prepend_hash, lang_transform);
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText("failed to parse " + url.Raw() + Err_.Message_gplx_brief(exc));}
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText("failed to parse " + url.NameOnly() + Err_.Message_gplx_brief(exc));}
}
}
private void Parse_file_json(Xoa_app app, Bry_bfr bfr, Xol_lang_transform lang_transform, Io_url root_dir) {
Io_url[] dirs = Io_mgr._.QueryDir_args(root_dir).DirOnly_().ExecAsUrlAry();
int dirs_len = dirs.length;
gplx.xowa.bldrs.langs.Xob_i18n_parser i18n_parser = app.Bldr().I18n_parser();
for (int i = 0; i < dirs_len; i++) {
Io_url dir = dirs[i];
Io_url[] fils = Io_mgr._.QueryDir_args(dir).ExecAsUrlAry();
int fils_len = fils.length;
for (int j = 0; j < fils_len; ++j) {
Io_url fil = fils[j];
try {
Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(Bry_.new_utf8_(fil.NameOnly()));
i18n_parser.Load_msgs(true, lang, fil);
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText(String_.Format("failed to parse json file; url={0} err={1}", fil.Raw(), Err_.Message_gplx_brief(exc)));}
}
}
}
public void Parse_core(String text, Xol_lang lang, Bry_bfr bfr, Xol_lang_transform lang_transform) {
@ -182,7 +201,7 @@ public class Xol_mw_lang_parser {
Parse_magicwords(line, lang.Key_bry(), lang.Kwd_mgr(), prepend_hash, lang_transform);
break;
}
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText("failed to parse " + url.Raw() + Err_.Message_gplx_brief(exc) + "\n");}
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText("failed to parse " + url.NameOnly() + Err_.Message_gplx_brief(exc) + "\n");}
}
}
}

View File

@ -97,7 +97,7 @@ public class Xol_mw_lang_parser_tst {
fxt.Num_fmt_tst("1234,56", "1 234 56"); // NOTE: nbsp here; also, nbsp is repeated. see dewiki and {{formatnum:1234,56}}
}
@Test public void Digit_transform_table() {
fxt.Save_file("mem/xowa/user/test_user/lang/mediawiki/messages/MessagesFr.php"
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_php/MessagesFr.php"
, "$digitTransformTable = array("
, " '0' => 'nulla',"
, " '1' => 'I',"
@ -112,7 +112,7 @@ public class Xol_mw_lang_parser_tst {
, ");"
);
fxt.Run_bld_all();
fxt.Tst_file("mem/xowa/user/test_user/lang/xowa/fr.gfs", String_.Concat_lines_nl
fxt.Tst_file("mem/xowa/bin/any/xowa/cfg/lang/core/fr.gfs", String_.Concat_lines_nl
( "numbers {"
, " digits {"
, " clear;"
@ -133,12 +133,12 @@ public class Xol_mw_lang_parser_tst {
));
}
@Test public void Digit_grouping_pattern() {
fxt.Save_file("mem/xowa/user/test_user/lang/mediawiki/messages/MessagesFr.php"
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_php/MessagesFr.php"
, "$digitGroupingPattern = '##,##,###'"
, ");"
);
fxt.Run_bld_all();
fxt.Tst_file("mem/xowa/user/test_user/lang/xowa/fr.gfs", String_.Concat_lines_nl
fxt.Tst_file("mem/xowa/bin/any/xowa/cfg/lang/core/fr.gfs", String_.Concat_lines_nl
( "numbers {"
, " digit_grouping_pattern = '##,##,###';"
, "}"
@ -147,52 +147,73 @@ public class Xol_mw_lang_parser_tst {
));
}
@Test public void Bld() {
// mem/xowa/user/test_user/lang/mediawiki/messages/
fxt.Save_file("mem/xowa/user/test_user/lang/mediawiki/messages/MessagesFr.php"
, "$fallback = 'zh-hans';"
, "$rtl = true;"
, "$namespaceNames = array(NS_FILE => 'Filex');"
, "$namespaceAliases = array('File Discussion' => NS_FILE_TALK);"
, "$magicWords = array('currentmonth' => array(0, 'CUR_MONTH'));"
, "$messages = array('sunday' => 'sunday');"
);
fxt.Save_file("mem/xowa/user/test_user/lang/mediawiki/extensions/Test.il8n.php"
, "$magicWords['fr'] = array('currentyear' => array(0, 'CUR_YEAR'));"
, "$messages['fr'] = array('monday' => 'monday');"
);
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_php/MessagesFr.php"
, "$fallback = 'zh-hans';"
, "$rtl = true;"
, "$namespaceNames = array(NS_FILE => 'Filex');"
, "$namespaceAliases = array('File Discussion' => NS_FILE_TALK);"
, "$magicWords = array('currentmonth' => array(0, 'CUR_MONTH'));"
, "$messages = array('sunday' => 'sunday');"
);
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/xtns_php/Test.il8n.php"
, "$magicWords['fr'] = array('currentyear' => array(0, 'CUR_YEAR'));"
, "$messages['fr'] = array('monday' => 'monday');"
);
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_json/Messages/fr.json"
, "{"
, " \"@metadata\": {"
, " \"authors\": []"
, " },"
, "\"key_1\": \"val_1\","
, "\"key_2\": \"val $1\","
, "}"
);
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/xtns_json/Test2/fr.json"
, "{"
, " \"@metadata\": {"
, " \"authors\": []"
, " },"
, "\"key_3\": \"val_3\","
, "\"key_4\": \"val $1\","
, "}"
);
fxt.Run_bld_all();
fxt.Tst_file("mem/xowa/user/test_user/lang/xowa/fr.gfs", String_.Concat_lines_nl
( "this"
, ".fallback_load('zh-hans')"
, ".dir_rtl_('y')"
, ".ns_names"
, " .load_text("
, "<:['"
, "6|Filex"
, "']:>"
, ").lang"
, ".ns_aliases"
, " .load_text("
, "<:['"
, "7|File Discussion"
, "']:>"
, ").lang"
, ".keywords"
, " .load_text("
, "<:['"
, "currentmonth|0|CUR_MONTH~"
, "currentyear|0|CUR_YEAR~"
, "']:>"
, ").lang"
, ".messages"
, " .load_text("
, "<:['"
, "sunday|sunday"
, "monday|monday"
, "']:>"
, ").lang"
, ";"
));
fxt.Tst_file("mem/xowa/bin/any/xowa/cfg/lang/core/fr.gfs", String_.Concat_lines_nl
( "this"
, ".fallback_load('zh-hans')"
, ".dir_rtl_('y')"
, ".ns_names"
, " .load_text("
, "<:['"
, "6|Filex"
, "']:>"
, ").lang"
, ".ns_aliases"
, " .load_text("
, "<:['"
, "7|File Discussion"
, "']:>"
, ").lang"
, ".keywords"
, " .load_text("
, "<:['"
, "currentmonth|0|CUR_MONTH~"
, "currentyear|0|CUR_YEAR~"
, "']:>"
, ").lang"
, ".messages"
, " .load_text("
, "<:['"
, "sunday|sunday"
, "monday|monday"
, "key_1|val_1"
, "key_2|val ~{0}"
, "key_3|val_3"
, "key_4|val ~{0}"
, "']:>"
, ").lang"
, ";"
));
}
@Test public void Dir_ltr() {
fxt.Parse_core("$rtl = 'true';");
@ -228,11 +249,8 @@ class Xol_mw_lang_parser_fxt {
GfoInvkAble_.InvkCmd_val(wiki, Xow_wiki.Invk_lang_, Bry_.new_ascii_("fr"));
}
public Xol_lang Lang() {return lang;} private Xol_lang lang;
public void Run_smoke(Io_url user_root) {
parser.Bld_all(app, user_root);
}
public void Num_fmt_tst(String raw, String expd) {Tfds.Eq(expd, String_.new_utf8_(lang.Num_mgr().Format_num(Bry_.new_utf8_(raw))));}
public void Run_bld_all() {parser.Bld_all(app, app.User().Fsys_mgr().Root_dir());}
public void Run_bld_all() {parser.Bld_all(app);}
public void Save_file(String path, String... lines) {
Io_mgr._.SaveFilStr(Io_url_.mem_fil_(path), String_.Concat_lines_nl(lines));
}

View File

@ -0,0 +1,54 @@
/*
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.*;
public class Bry_rdr {
private byte[] src; private int src_len;
public Bry_rdr Src_(byte[] src, int src_len) {this.src = src; this.src_len = src_len; pos = 0; return this;} public Bry_rdr Src_(byte[] src) {return Src_(src, src.length);}
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} private int pos;
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.MinValue;
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
public int Read_int_to(byte to_char) {
int bgn = pos;
int rv = 0;
while (pos < src_len) {
byte b = src[pos++];
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
rv = (rv * 10) + (b - Byte_ascii.Num_0);
break;
default:
return b == to_char ? rv : or_int;
}
}
return bgn == pos ? or_int : rv;
}
public byte[] Read_bry_to_pipe() {return Read_bry_to(Byte_ascii.Pipe);}
public byte[] Read_bry_to(byte to_char) {
int bgn = pos;
while (pos < src_len) {
byte b = src[pos];
if (b == to_char)
return Bry_.Mid(src, bgn, pos++);
else
++pos;
}
return bgn == pos ? or_bry : Bry_.Mid(src, bgn, src_len);
}
}

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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import org.junit.*;
public class Bry_rdr_tst {
@Before public void init() {fxt.Clear();} private Bry_rdr_fxt fxt = new Bry_rdr_fxt();
@Test public void Int() {
fxt.Init_src("12|3456|789");
fxt.Test_read_int(12);
fxt.Test_read_int(3456);
fxt.Test_read_int(789);
fxt.Test_read_int(Int_.MinValue);
}
@Test public void Bry() {
fxt.Init_src("abc|d||ef");
fxt.Test_read_bry("abc");
fxt.Test_read_bry("d");
fxt.Test_read_bry("");
fxt.Test_read_bry("ef");
fxt.Test_read_bry(null);
}
}
class Bry_rdr_fxt {
private Bry_rdr rdr;
public void Clear() {rdr = new Bry_rdr();}
public Bry_rdr_fxt Init_src(String v) {rdr.Src_(Bry_.new_utf8_(v)); return this;}
public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;}
public void Test_read_int(int expd_val) {
Tfds.Eq(expd_val, rdr.Read_int_to_pipe());
}
public void Test_read_bry(String expd_str) {
byte[] actl_bry = rdr.Read_bry_to_pipe();
String actl_str = actl_bry == null ? null : String_.new_utf8_(actl_bry);
Tfds.Eq(expd_str, actl_str);
}
}

View File

@ -1,101 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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

@ -16,13 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.ios.*;
public class Hdump_skin_row {
public int Skin_id() {return skin_id;} private int skin_id;
public byte[] Skin_html() {return skin_html;} private byte[] skin_html;
public Hdump_skin_row Ctor(int skin_id, byte[] skin_html) {
this.skin_id = skin_id;
this.skin_html = skin_html;
return this;
import gplx.dbs.*;
public class Hdump_db_mgr {
public Db_provider Db_provider_by_page(int page_id) {
return null;
}
public int Next_insert_id() {return 0;}
}

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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
class Hdump_file_itm {
// lnki_ttl|lnki_ext|lnki_type|lnki_w|lnki_h|lnki_align_x|lnki_align_y|lnki_border|lnki_upright|lnki_time|lnki_page|lnki_media_icon|lnki_alt|lnki_caption
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte Lnki_tid() {return lnki_tid;} private byte lnki_tid;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public byte Lnki_align_x() {return lnki_align_x;} private byte lnki_align_x;
public byte Lnki_align_y() {return lnki_align_y;} private byte lnki_align_y;
public byte Lnki_border() {return lnki_border;} private byte lnki_border;
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_time() {return lnki_time;} private double lnki_time;
public int Lnki_page() {return lnki_page;} private int lnki_page;
public boolean Lnki_media_icon() {return lnki_media_icon;} private boolean lnki_media_icon;
public byte[] Lnki_alt() {return lnki_alt;} private byte[] lnki_alt;
public byte[] Lnki_caption() {return lnki_caption;} private byte[] lnki_caption;
public void Parse(byte[] src) {
int len = src.length;
int pos = 0;
int fld_idx = 0, fld_bgn = 0;
while (pos < len) {
byte b = src[pos];
if (b == Byte_ascii.Pipe) {
switch (fld_idx) {
case 0: lnki_ttl = Bry_.Mid(src, fld_bgn, pos); break;
case 2: lnki_tid = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 3: lnki_w = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
case 4: lnki_h = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
case 5: lnki_align_x = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 6: lnki_align_y = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 7: lnki_border = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 8: lnki_upright = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
case 9: lnki_time = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
case 10: lnki_page = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
case 11: lnki_media_icon = src[pos] == Byte_ascii.Ltr_y; break;
case 12: lnki_alt = Bry_.Mid(src, fld_bgn, pos); break;
case 13: lnki_caption = Bry_.Mid(src, fld_bgn, pos); break;
}
++fld_idx;
}
}
}
}

View File

@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.ios.*;
public class Hdump_frag_row {
public int Frag_id() {return frag_id;} private int frag_id;
public int Page_id() {return page_id;} private int page_id;
public int Frag_tid() {return frag_tid;} private int frag_tid;
public byte[] Frag_key() {return frag_key;} private byte[] frag_key;
public byte[] Frag_text() {return frag_text;} private byte[] frag_text;
public Hdump_frag_row Ctor(int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
this.frag_id = frag_id;
this.page_id = page_id;
this.frag_tid = frag_tid;
this.frag_key = frag_key;
this.frag_text = frag_text;
return this;
}
}
class Hdump_frag_tid {
public static final int Tid_file = 1, Tid_title = 2, Tid_sidebar = 3;
public static final String Key_file = "file", Key_title = "title", Key_sidebar = "sidebar";
public static String Xto_key(int v) {
switch (v) {
case Tid_file : return Key_file;
case Tid_title : return Key_title;
case Tid_sidebar : return Key_sidebar;
default : throw Err_.unhandled(v);
}
}
public static byte Xto_tid(String v) {
if (String_.Eq(v, Key_file)) return Tid_file;
else if (String_.Eq(v, Key_title)) return Tid_title;
else if (String_.Eq(v, Key_sidebar)) return Tid_sidebar;
else throw Err_.unhandled("v");
}
}

View File

@ -1,93 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*; import gplx.ios.*;
public class Hdump_frag_tbl {
private Db_stmt stmt_select, stmt_insert, stmt_update, stmt_delete;
@gplx.Virtual public void Insert(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
try {
stmt_insert.Val_int_(frag_id).Val_int_(page_id).Val_int_(frag_tid).Val_str_by_bry_(frag_key).Val_str_by_bry_(frag_text).Exec_insert();
} finally {stmt_insert.Rls();}
}
@gplx.Virtual public void Update(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
if (stmt_update == null) stmt_update = Db_stmt_.new_update_(provider, Tbl_name, Flds_all);
try {
stmt_update.Val_int_(frag_id).Val_int_(page_id).Val_int_(frag_tid).Val_str_by_bry_(frag_key).Val_str_by_bry_(frag_text).Exec_update();
} finally {stmt_update.Rls();}
}
@gplx.Virtual public void Select(Db_provider provider, Hdump_frag_row rv, int frag_id) {
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_frag_id), Flds_all);
try {
DataRdr rdr = stmt_select.Val_int_(frag_id).Exec_select();
rv.Ctor
( rdr.ReadInt(Fld_frag_id)
, rdr.ReadInt(Fld_page_id)
, rdr.ReadInt(Fld_frag_tid)
, rdr.ReadBryByStr(Fld_frag_key)
, rdr.ReadBryByStr(Fld_frag_text)
);
rdr.Rls();
} finally {stmt_select.Rls();}
}
@gplx.Virtual public void Delete(Db_provider provider, int frag_id) {
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_frag_id);
try {
stmt_delete.Val_int_(frag_id).Exec_delete();
} finally {stmt_delete.Rls();}
}
@gplx.Virtual public void Delete_all(Db_provider provider) {
Db_qry_.delete_tbl_(Tbl_name).Exec_qry(provider);
}
public void Rls() {
stmt_select = stmt_insert = stmt_update = stmt_delete = null;
}
public static final String Tbl_name = "html_frag"
, Fld_frag_id = "frag_id", Fld_page_id = "page_id", Fld_frag_tid = "frag_tid"
, Fld_frag_key = "frag_key", Fld_frag_text = "frag_text";
private static final String[] Flds_all = new String[] {Fld_frag_id, Fld_page_id, Fld_frag_tid, Fld_frag_key, Fld_frag_text};
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS html_frag"
, "( frag_id integer NOT NULL PRIMARY KEY"
, ", page_id integer NOT NULL"
, ", frag_tid integer NOT NULL"
, ", frag_key varchar(255) NOT NULL"
, ", frag_text mediumblob NOT NULL"
, ");"
);
}
class Hdump_frag_tbl_mem extends Hdump_frag_tbl { private OrderedHash hash = OrderedHash_.new_();
@Override public void Insert(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
Hdump_frag_row row = new Hdump_frag_row().Ctor(frag_id, page_id, frag_tid, frag_key, frag_text);
hash.Add(frag_id, row);
}
@Override public void Update(Db_provider provider, int frag_id, int page_id, int frag_tid, byte[] frag_key, byte[] frag_text) {
Hdump_frag_row row = (Hdump_frag_row)hash.Fetch(frag_id);
row.Ctor(frag_id, page_id, frag_tid, frag_key, frag_text);
}
@Override public void Select(Db_provider provider, Hdump_frag_row rv, int frag_id) {
Hdump_frag_row row = (Hdump_frag_row)hash.Fetch(frag_id);
rv.Ctor(row.Frag_id(), row.Page_id(), row.Frag_tid(), row.Frag_key(), row.Frag_text());
}
@Override public void Delete(Db_provider provider, int frag_id) {
hash.Del(frag_id);
}
@Override public void Delete_all(Db_provider provider) {
hash.Clear();
}
}

View File

@ -16,18 +16,18 @@ 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.*;
import gplx.ios.*;
public class Hdump_page_row {
public int Page_id() {return page_id;} private int page_id;
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;
this.frags_len = frags_len;
this.make_id = make_id;
return this;
public class Hdump_img_itm {
public Hdump_img_itm(int img_id, byte[] img_src, int img_w, int img_h) {
this.img_id = img_id;
this.img_src = img_src;
this.img_w = img_w;
this.img_h = img_h;
}
public int Img_id() {return img_id;} private int img_id;
public byte[] Img_src() {return img_src;} private byte[] img_src;
public int Img_w() {return img_w;} private int img_w;
public int Img_h() {return img_h;} private int img_h;
public void Write_html(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, img_src, img_w, img_h);
} private static final Bry_fmtr fmtr = Bry_fmtr.new_(" src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
}

View File

@ -0,0 +1,72 @@
/*
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.*;
import gplx.dbs.*; import gplx.ios.*;
import gplx.core.btries.*; import gplx.xowa.pages.*;
class Hdump_load_mgr {
private Hdump_db_mgr db_mgr;
private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
private int page_version;
private byte[] page_text, display_ttl, content_sub;
private ListAdp sidebar_divs = ListAdp_.new_(), img_itms = ListAdp_.new_();
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private ListAdp tmp_text_itms = ListAdp_.new_();
private Bry_rdr bry_rdr = new Bry_rdr();
public Hdump_load_mgr(Hdump_db_mgr db_mgr) {this.db_mgr = db_mgr;}
public void Clear() {
page_version = -1;
page_text = display_ttl = content_sub = null;
sidebar_divs.Clear();
img_itms.Clear();
}
public void Load(Hdump_page_itm page, int page_id, byte[] page_url) {
Db_provider provider = db_mgr.Db_provider_by_page(page_id);
text_tbl.Select_by_page(tmp_text_itms, provider, page_id);
Load_itm(page, page_id, page_url, tmp_text_itms);
}
public void Load_itm(Hdump_page_itm page, int page_id, byte[] page_url, ListAdp itms) {
this.Clear();
int len = itms.Count();
for (int i = 0; i < len; ++i) {
Hdump_text_row itm = (Hdump_text_row)itms.FetchAt(i);
switch (itm.Tid()) {
case Hdump_text_row_tid.Tid_body: Load_itm_body(itm); break;
case Hdump_text_row_tid.Tid_img: Load_itm_img(itm); break;
case Hdump_text_row_tid.Tid_sidebar_div: sidebar_divs.Add(zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data())); break;
case Hdump_text_row_tid.Tid_display_ttl: display_ttl = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); break;
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); break;
}
}
page.Init(page_id, page_url, page_version, display_ttl, content_sub, page_text
, (byte[][])sidebar_divs.XtoAryAndClear(byte[].class)
, (Hdump_img_itm[])img_itms.XtoAryAndClear(Hdump_img_itm.class)
);
}
public void Load_itm_body(Hdump_text_row itm) {
page_version = Bry_.Xto_int(itm.Meta());
page_text = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data());
}
public void Load_itm_img(Hdump_text_row itm) {
bry_rdr.Src_(itm.Meta());
int img_id = itm.Sub_id();
byte[] img_src = bry_rdr.Read_bry_to_pipe();
int img_w = bry_rdr.Read_int_to_pipe();
int img_h = bry_rdr.Read_int_to_pipe();
Hdump_img_itm img_itm = new Hdump_img_itm(img_id, img_src, img_w, img_h);
img_itms.Add(img_itm);
}
}

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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
public class Hdump_page_itm {
public int Page_id() {return page_id;} private int page_id;
public byte[] Page_url() {return page_url;} private byte[] page_url;
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
public byte[] Page_body() {return page_body;} private byte[] page_body;
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs;
public Hdump_img_itm[] Img_itms() {return img_itms;} private Hdump_img_itm[] img_itms;
public void Init(int page_id, byte[] page_url, int version_id, byte[] display_ttl, byte[] content_sub, byte[] page_body, byte[][] sidebar_divs, Hdump_img_itm[] img_itms) {
this.page_id = page_id;
this.page_url = page_url;
this.version_id = version_id;
this.display_ttl = display_ttl;
this.content_sub = content_sub;
this.page_body = page_body;
this.sidebar_divs = sidebar_divs;
this.img_itms = img_itms;
}
}

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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
class Hdump_page_itm_save {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
private Hdump_text_tbl text_tbl = new Hdump_text_tbl();
private Hdump_db_mgr text_db_mgr = new Hdump_db_mgr();
public void Insert(Db_provider provider, Xoa_page page) {
int page_id = page.Revision_data().Id();
Xopg_html_data html_data = page.Html_data();
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_body, Version_id, Bry_.Empty, Bry_.Empty);
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
Insert_sidebars(provider, page_id, page, html_data.Xtn_skin_mgr());
}
private void Insert_if_exists(Db_provider provider, int page_id, int tid, byte[] val) {
if (Bry_.Len_gt_0(val))
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, tid, Version_id, Bry_.Empty, val);
}
private void Insert_sidebars(Db_provider provider, int page_id, Xoa_page page, Xopg_xtn_skin_mgr xtn_skin_mgr) {
int len = xtn_skin_mgr.Count();
for (int i = 0; i < len; ++i) {
Xopg_xtn_skin_itm itm = xtn_skin_mgr.Get_at(i);
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
itm.Write(tmp_bfr, page);
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_sidebar_div, Version_id, Bry_.Empty, tmp_bfr.XtoAryAndClear());
}
}
}
private static final int Version_id = 0;
}

View File

@ -1,104 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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 {
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 Update(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
if (stmt_update == null) stmt_update = Db_stmt_.new_update_(provider, Tbl_name, Flds_all);
try {
page_html = zip_mgr.Zip(zip_tid, page_html);
stmt_update.Val_int_(page_id).Val_str_by_bry_(page_html).Val_int_(frags_len).Val_int_(make_id).Exec_update();
} finally {stmt_update.Rls();}
}
@gplx.Virtual public void Select(Db_provider provider, Hdump_page_row rv, int page_id) {
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Flds_all);
try {
DataRdr rdr = stmt_select.Val_int_(page_id).Exec_select();
rv.Ctor
( rdr.ReadInt(Fld_page_id)
, zip_mgr.Unzip(zip_tid, rdr.ReadBry(Fld_page_html))
, rdr.ReadInt(Fld_frags_len)
, rdr.ReadInt(Fld_make_id)
);
rdr.Rls();
} finally {stmt_select.Rls();}
}
@gplx.Virtual public void Delete(Db_provider provider, int page_id) {
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
try {
stmt_delete.Val_int_(page_id).Exec_delete();
} finally {stmt_delete.Rls();}
}
@gplx.Virtual public void Delete_all(Db_provider provider) {
Db_qry_.delete_tbl_(Tbl_name).Exec_qry(provider);
}
public void Rls() {
stmt_select = stmt_insert = stmt_update = stmt_delete = null;
zip_mgr = null;
}
public static final String Tbl_name = "html_page"
, Fld_page_id = "page_id", Fld_page_html = "page_html", Fld_frags_len = "frags_len", Fld_make_id= "make_id";
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_page_html, Fld_frags_len, Fld_make_id};
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS html_page"
, "( page_id integer NOT NULL PRIMARY KEY"
, ", page_html mediumblob NOT NULL"
, ", frags_len integer NOT NULL"
, ", make_id integer NOT NULL"
, ");"
);
}
class Hdump_page_tbl_mem extends Hdump_page_tbl { private OrderedHash hash = OrderedHash_.new_();
@Override public void Insert(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
Hdump_page_row row = new Hdump_page_row().Ctor(page_id, page_html, frags_len, make_id);
hash.Add(page_id, row);
}
@Override public void Update(Db_provider provider, int page_id, byte[] page_html, int frags_len, int make_id) {
Hdump_page_row row = (Hdump_page_row)hash.Fetch(page_id);
row.Ctor(page_id, page_html, frags_len, make_id);
}
@Override public void Select(Db_provider provider, Hdump_page_row rv, int page_id) {
Hdump_page_row row = (Hdump_page_row)hash.Fetch(page_id);
rv.Ctor(row.Page_id(), row.Page_html(), row.Frags_len(), row.Make_id());
}
@Override public void Delete(Db_provider provider, int page_id) {
hash.Del(page_id);
}
@Override public void Delete_all(Db_provider provider) {
hash.Clear();
}
}

View File

@ -1,86 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
import gplx.dbs.*; import gplx.ios.*;
public class Hdump_skin_tbl {
private Db_stmt stmt_select, stmt_insert, stmt_update, stmt_delete;
@gplx.Virtual public void Insert(Db_provider provider, int skin_id, byte[] skin_text) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
try {
stmt_insert.Val_int_(skin_id).Val_str_by_bry_(skin_text).Exec_insert();
} finally {stmt_insert.Rls();}
}
@gplx.Virtual public void Update(Db_provider provider, int skin_id, byte[] skin_text) {
if (stmt_update == null) stmt_update = Db_stmt_.new_update_(provider, Tbl_name, Flds_all);
try {
stmt_update.Val_int_(skin_id).Val_str_by_bry_(skin_text).Exec_update();
} finally {stmt_update.Rls();}
}
@gplx.Virtual public void Select(Db_provider provider, Hdump_skin_row rv, int skin_id) {
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_skin_id), Flds_all);
try {
DataRdr rdr = stmt_select.Val_int_(skin_id).Exec_select();
rv.Ctor
( rdr.ReadInt(Fld_skin_id)
, rdr.ReadBryByStr(Fld_skin_text)
);
rdr.Rls();
} finally {stmt_select.Rls();}
}
@gplx.Virtual public void Delete(Db_provider provider, int skin_id) {
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_skin_id);
try {
stmt_delete.Val_int_(skin_id).Exec_delete();
} finally {stmt_delete.Rls();}
}
@gplx.Virtual public void Delete_all(Db_provider provider) {
Db_qry_.delete_tbl_(Tbl_name).Exec_qry(provider);
}
public void Rls() {
stmt_select = stmt_insert = stmt_update = stmt_delete = null;
}
public static final String Tbl_name = "html_skin"
, Fld_skin_id = "skin_id", Fld_skin_text = "skin_text";
private static final String[] Flds_all = new String[] {Fld_skin_id, Fld_skin_text};
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS html_skin"
, "( skin_id integer NOT NULL PRIMARY KEY"
, ", skin_text mediumblob NOT NULL"
, ");"
);
}
class Hdump_skin_tbl_mem extends Hdump_skin_tbl { private OrderedHash hash = OrderedHash_.new_();
@Override public void Insert(Db_provider provider, int skin_id, byte[] skin_text) {
Hdump_skin_row row = new Hdump_skin_row().Ctor(skin_id, skin_text);
hash.Add(skin_id, row);
}
@Override public void Update(Db_provider provider, int skin_id, byte[] skin_text) {
Hdump_skin_row row = (Hdump_skin_row)hash.Fetch(skin_id);
row.Ctor(skin_id, skin_text);
}
@Override public void Select(Db_provider provider, Hdump_skin_row rv, int skin_id) {
Hdump_skin_row row = (Hdump_skin_row)hash.Fetch(skin_id);
rv.Ctor(row.Skin_id(), row.Skin_html());
}
@Override public void Delete(Db_provider provider, int skin_id) {
hash.Del(skin_id);
}
@Override public void Delete_all(Db_provider provider) {
hash.Clear();
}
}

View File

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
class Hdump_text_row {
public int Id() {return id;} private int id;
public int Page_id() {return page_id;} private int page_id;
public int Tid() {return tid;} private int tid;
public int Version() {return version;} private int version;
public byte[] Meta() {return meta;} private byte[] meta;
public byte[] Data() {return data;} private byte[] data;
public int Sub_id() {return sub_id;} public void Sub_id_(int v) {sub_id = v;} private int sub_id;
public Hdump_text_row Init(int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
this.id = id; this.page_id = page_id; this.tid = tid; this.version = version; this.meta = meta; this.data = data;
return this;
}
}
class Hdump_text_row_tid {
public static final int Tid_body = 0, Tid_img = 1, Tid_display_ttl = 2, Tid_content_sub = 3, Tid_sidebar_div = 4;
}

View File

@ -0,0 +1,81 @@
/*
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.*;
import gplx.dbs.*;
class Hdump_text_tbl {
private Db_stmt stmt_select, stmt_insert;//, stmt_update, stmt_delete;
@gplx.Virtual public void Insert(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
stmt_insert.Val_int_(id).Val_int_(page_id).Val_int_(tid).Val_int_(version).Val_str_by_bry_(meta).Val_str_by_bry_(data).Exec_insert();
}
@gplx.Virtual public void Select_by_page(ListAdp rv, Db_provider provider, int page_id) {
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Flds_all);
try {
DataRdr rdr = stmt_select.Val_int_(page_id).Exec_select();
while(rdr.MoveNextPeer()) {
Hdump_text_row row = new Hdump_text_row().Init
( rdr.ReadInt(Fld_text_id)
, rdr.ReadInt(Fld_page_id)
, rdr.ReadInt(Fld_text_tid)
, rdr.ReadInt(Fld_text_version)
, rdr.ReadBryByStr(Fld_text_meta)
, rdr.ReadBryByStr(Fld_text_data)
);
rv.Add(row);
}
rdr.Rls();
} finally {stmt_select.Rls();}
}
public static final String Tbl_name = "html_text"
, Fld_text_id = "text_id", Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_version = "text_version"
, Fld_text_meta = "text_meta", Fld_text_data = "text_data";
private static final String[] Flds_all = new String[] {Fld_text_id, Fld_page_id, Fld_text_tid, Fld_text_version, Fld_text_meta, Fld_text_data};
public static final String Tbl_sql = String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS html_text"
, "( text_id integer NOT NULL PRIMARY KEY"
, ", page_id integer NOT NULL"
, ", text_tid integer NOT NULL"
, ", text_version integer NOT NULL"
, ", text_meta varchar(4000) NOT NULL"
, ", text_data mediumblob NOT NULL"
, ");"
);
}
class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashAdp_.new_();
@Override public void Insert(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
Hdump_text_row row = new Hdump_text_row().Init(id, page_id, tid, version, meta, data);
ListAdp rows = Get_or_new(pages, page_id);
rows.Add(row);
}
@Override public void Select_by_page(ListAdp rv, Db_provider provider, int page_id) {
ListAdp rows = Get_or_new(pages, page_id);
int len = rows.Count();
for (int i = 0; i < len; ++i) {
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i);
rv.Add(row);
}
}
private static ListAdp Get_or_new(HashAdp pages, int page_id) {
ListAdp rv = (ListAdp)pages.Fetch(page_id);
if (rv == null) {
rv = ListAdp_.new_();
pages.Add(page_id, rv);
}
return rv;
}
}

View File

@ -0,0 +1,66 @@
/*
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.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
import gplx.core.btries.*;
class Hdump_html_fmtr__body implements Bry_fmtr_arg {
private Bry_rdr bry_rdr = new Bry_rdr();
private Hdump_page_itm page;
private Gfo_usr_dlg usr_dlg; private byte[] app_dir = Bry_.Empty;
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] app_dir) {this.usr_dlg = usr_dlg; this.app_dir = app_dir;}
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
public void XferAry(Bry_bfr bfr, int idx) {
byte[] src = page.Page_body(); int len = src.length;
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
bry_rdr.Src_(src);
int pos = 0; int rng_bgn = -1;
while (pos < len) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
if (o == null) {
if (rng_bgn == -1) rng_bgn = pos;
}
else {
if (rng_bgn != -1) {
bfr.Add_mid(src, rng_bgn, pos);
rng_bgn = -1;
}
byte tid = ((Byte_obj_val)o).Val();
pos = trie.Match_pos(); // position after match; EX: "~{xo.img." positions after "."
switch (tid) {
case Tid_app_dir: bfr.Add(app_dir); break;
case Tid_img: pos = Write_img(bfr, page, src, imgs, imgs_len, pos); break;
}
++pos; // + 1 to skip trailing }
}
}
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
}
private int Write_img(Bry_bfr bfr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int idx_bgn) {
int idx_val = bry_rdr.Read_int_to(Byte_ascii.Curly_end);
int idx_end = bry_rdr.Pos();
if (idx_val == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url(), Bry_.Mid(src, idx_bgn, idx_end)); return idx_end;}
if (!Int_.Between(idx_val, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url(), idx_val, imgs_len); return idx_end;}
imgs[idx_val].Write_html(bfr);
return idx_end;
}
private static final byte Tid_app_dir = 0, Tid_img = 1;
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_()
.Add_str_byte("~{xo.dir" , Tid_app_dir)
.Add_str_byte("~{xo.img." , Tid_img)
;
}

View File

@ -15,13 +15,16 @@ 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.xtns.pfuncs.*;
public class Sites_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_relatedSites;}
@Override public Pf_func New(int id, byte[] name) {return new Sites_func().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
package gplx.xowa.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
class Hdump_html_fmtr__sidebars implements Bry_fmtr_arg {
private Hdump_page_itm page;
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
public void XferAry(Bry_bfr bfr, int idx) {
byte[][] sidebar_divs = page.Sidebar_divs();
int sidebar_divs_len = sidebar_divs.length;
for (int i = 0; i < sidebar_divs_len; ++i) {
byte[] sidebar_div = sidebar_divs[i];
bfr.Add(sidebar_div);
}
}
public static final Sites_func _ = new Sites_func(); Sites_func() {}
}

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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
class Hdump_html_mgr {
private Hdump_html_fmtr__sidebars sidebars_fmtr = new Hdump_html_fmtr__sidebars();
private Hdump_html_fmtr__body body_fmtr = new Hdump_html_fmtr__body();
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] app_dir) {body_fmtr.Init_by_app(usr_dlg, app_dir);}
public void Write(Bry_bfr bfr, Bry_fmtr skin_fmtr, Hdump_page_itm page) {
body_fmtr.Init_by_page(page);
sidebars_fmtr.Init_by_page(page);
skin_fmtr.Bld_bfr_many(bfr, page.Display_ttl(), page.Content_sub(), sidebars_fmtr, body_fmtr);
}
}

View File

@ -15,17 +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; import gplx.*; import gplx.xowa.*;
public class Xoh_xtn_mgr {
private OrderedHash itms = OrderedHash_.new_bry_();
public Xoh_xtn_itm Get_or_null(byte[] key) {return (Xoh_xtn_itm)itms.Fetch(key);}
public void Clear() {itms.Clear();}
public void Add(Xoh_xtn_itm itm) {itms.Add(itm.Key(), itm);}
public void Exec() {
int len = itms.Count();
for (int i = 0; i < len; i++) {
Xoh_xtn_itm itm = (Xoh_xtn_itm)itms.FetchAt(i);
itm.Exec();
}
package gplx.xowa.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
import org.junit.*;
public class Hdump_html_mgr_tst {
@Before public void init() {fxt.Clear();} private Hdump_html_mgr_fxt fxt = new Hdump_html_mgr_fxt();
@Test public void Basic() {
// fxt.Test_save("A b c", fxt.itm_text_("A b c"));
}
}
class Hdump_html_mgr_fxt {
public void Clear() {
}
}

View File

@ -17,5 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
public class Xof_html_elem {
public static final byte Tid_none = 0, Tid_img = 1, Tid_vid = 2, Tid_gallery = 3, Tid_gallery_v2 = 4;
public static final byte Tid_none = 0, Tid_img = 1, Tid_vid = 2, Tid_gallery = 3, Tid_gallery_v2 = 4, Tid_imap = 5;
}

View File

@ -101,7 +101,10 @@ public class Xof_xfer_itm implements Xof_file_itm {
lnki_thumbtime = Xof_doc_thumb.Null; // disable thumbtime
return this;
}
public void Atrs_by_meta(Xof_meta_itm meta_itm, Xof_repo_itm trg_repo, int thumb_w_img) {this.meta_itm = meta_itm; this.trg_repo = trg_repo; this.thumb_w_img = thumb_w_img;} private int thumb_w_img;
public void Atrs_by_meta(Xof_meta_itm meta_itm, Xof_repo_itm trg_repo, int thumb_w_img) {
this.meta_itm = meta_itm; this.trg_repo = trg_repo; this.thumb_w_img = thumb_w_img;
this.orig_w = meta_itm.Orig_w(); this.orig_h = meta_itm.Orig_h(); // orig_w / orig_h needed for imap; DATE:2014-08-08
} private int thumb_w_img;
public void Atrs_by_meta_only(Xof_meta_itm meta_itm) {this.meta_itm = meta_itm; Atrs_by_ttl(meta_itm.Ttl(), meta_itm.Ptr_ttl());}
public Xof_xfer_itm Atrs_by_ttl(byte[] ttl, byte[] redirect) {
this.lnki_redirect = redirect;

View File

@ -20,34 +20,38 @@ import gplx.xowa.xtns.gallery.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.gui.views.*;
public class Js_img_mgr {
public static void Update_img(Xoa_page page, Xof_xfer_itm itm) {
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), String_.new_utf8_(itm.Html_view_src()), String_.new_utf8_(itm.Html_orig_src()), itm.Gallery_mgr_h(), itm.Html_img_wkr());
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), String_.new_utf8_(itm.Html_view_src()), itm.Orig_w(), itm.Orig_h(), String_.new_utf8_(itm.Html_orig_src()), itm.Gallery_mgr_h(), itm.Html_img_wkr());
}
public static void Update_img(Xoa_page page, Xof_fsdb_itm itm) {
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_url().To_http_file_str(), itm.Html_orig_url().To_http_file_str(), itm.Gallery_mgr_h(), itm.Html_img_wkr());
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_url().To_http_file_str(), itm.Orig_w(), itm.Orig_h(), itm.Html_orig_url().To_http_file_str(), itm.Gallery_mgr_h(), itm.Html_img_wkr());
}
public static void Update_link_missing(Xog_html_itm html_itm, String html_id) {
html_itm.Html_elem_atr_set_append(html_id, "class", " new");
}
private static void Update_img(Xoa_page page, int uid, byte lnki_type, byte elem_tid, int w, int h, String view_src, String orig_src, int gallery_mgr_h, Js_img_wkr img_wkr) {
private static void Update_img(Xoa_page page, int uid, byte lnki_type, byte elem_tid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src, int gallery_mgr_h, Js_img_wkr img_wkr) {
if (Env_.Mode_testing()) return;
Xog_html_itm html_itm = page.Tab().Html_itm();
if (elem_tid == Xof_html_elem.Tid_gallery_v2) {
img_wkr.Html_update(page, html_itm, w, h, view_src, orig_src);
return;
switch (elem_tid) {
case Xof_html_elem.Tid_gallery_v2:
img_wkr.Html_update(page, html_itm, uid, html_w, html_h, html_src, orig_w, orig_h, orig_src);
return;
}
String html_id = "xowa_file_img_" + uid;
html_itm.Html_img_update(html_id, view_src, w, h);
html_itm.Html_img_update(html_id, html_src, html_w, html_h);
if (Xop_lnki_type.Id_is_thumbable(lnki_type)) { // thumb needs to set cls and width
html_itm.Html_atr_set(html_id, "class", gplx.xowa.html.Xow_html_mgr.Str_img_class_thumbimage);
html_itm.Html_atr_set("xowa_file_div_" + uid, "style", "width:" + w + "px;");
html_itm.Html_atr_set("xowa_file_div_" + uid, "style", "width:" + html_w + "px;");
}
switch (elem_tid) {
case Xof_html_elem.Tid_gallery:
html_itm.Html_atr_set("xowa_gallery_div3_" + uid, "style", "margin:" + Gallery_html_wtr_utl.Calc_vpad(gallery_mgr_h, h) + "px auto;");
html_itm.Html_atr_set("xowa_gallery_div3_" + uid, "style", "margin:" + Gallery_html_wtr_utl.Calc_vpad(gallery_mgr_h, html_h) + "px auto;");
break;
case Xof_html_elem.Tid_imap:
img_wkr.Html_update(page, html_itm, uid, html_w, html_h, html_src, orig_w, orig_h, orig_src);
break;
case Xof_html_elem.Tid_vid:
String html_id_vid = "xowa_file_play_" + uid;
html_itm.Html_atr_set(html_id_vid, "style", "width:" + w + "px;max-width:" + (w - 2) + "px;");
html_itm.Html_atr_set(html_id_vid, "style", "width:" + html_w + "px;max-width:" + (html_w - 2) + "px;");
html_itm.Html_atr_set(html_id_vid, "href", orig_src);
break;
}

View File

@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.gui.views.*;
public interface Js_img_wkr {
void Html_update(Xoa_page page, Xog_html_itm html_itm, int w, int h, String view_src, String orig_src);
void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src);
}

View File

@ -103,6 +103,7 @@ public class Xog_bnd_mgr {
Init_itm(Xog_cmd_itm_.Key_nav_help_change_log , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_help_diagnostics , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_help_about , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_help_xowa_main , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_setup_import_from_list , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_nav_setup_import_from_script , Xog_bnd_box_.Tid_browser , "");

View File

@ -35,6 +35,7 @@ public class Xog_cmd_itm_ {
, Key_nav_help_about = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.about" , "home/wiki/Help:About")
, Key_nav_help_change_log = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.change_log" , "home/wiki/Help:Change_log")
, Key_nav_help_diagnostics = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.diagnostics" , "home/wiki/Help:Diagnostics")
, Key_nav_help_xowa_main = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.help.xowa_main" , "home/wiki/Main_Page")
, Key_nav_setup_import_from_list = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.setup.import_from_list" , "home/wiki/Help:Import/List")
, Key_nav_setup_import_from_script = new_page_(Xog_ctg_itm_.Tid_nav_pages , "xowa.nav.setup.import_from_script" , "home/wiki/Help:Import/Script")

View File

@ -70,6 +70,7 @@ class Xog_menu_mgr_src {
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_xowa_main)
. Add_btn(Xog_cmd_itm_.Key_nav_help_change_log)
. Add_btn(Xog_cmd_itm_.Key_nav_help_diagnostics)
. Add_btn(Xog_cmd_itm_.Key_nav_cfg_menu)
@ -148,6 +149,7 @@ class Xog_menu_mgr_src {
. Add_grp_end()
. Add_grp_bgn(Xog_cmd_itm_.Key_gui_menus_group_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_help)
. Add_btn(Xog_cmd_itm_.Key_nav_help_xowa_main)
. Add_btn(Xog_cmd_itm_.Key_nav_help_change_log)
. Add_btn(Xog_cmd_itm_.Key_nav_help_diagnostics)
. Add_btn(Xog_cmd_itm_.Key_nav_cfg_menu)

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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.core.btries.*; import gplx.gfui.*; import gplx.html.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*;
import gplx.core.btries.*; import gplx.gfui.*; import gplx.html.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*; import gplx.xowa.html.modules.*;
public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
private Xoa_app app;
public Xog_html_itm(Xog_tab_itm owner_tab) {
@ -114,13 +114,19 @@ public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_gallery_packed_exec, m);
module_packed_done = true;
}
private boolean module_packed_done = false;
public void Html_popups_bind_hover_to_doc() {
if (!String_.Eq(owner_tab.Tab_key(), owner_tab.Tab_mgr().Active_tab().Tab_key())) return; // do not exec unless active;
GfoMsg m = GfoMsg_.new_cast_(Invk_html_popups_bind_hover_to_doc);
GfoInvkAble_.InvkCmd_msg(cmd_sync, Invk_html_popups_bind_hover_to_doc, m);
module_popups_done = true;
}
private boolean module_packed_done = false, module_popups_done = false;
public void Tab_selected(Xoa_page page) {
if ( page.Html_data().Module_mgr().Itm_gallery().Enabled()
&& !module_packed_done
) {
Xoh_module_mgr module_mgr = page.Html_data().Module_mgr();
if (module_mgr.Itm_gallery().Enabled() && !module_packed_done)
this.Html_gallery_packed_exec();
}
if (module_mgr.Itm_popups().Enabled() && !module_popups_done)
this.Html_popups_bind_hover_to_doc();
}
public void Scroll_page_by_bmk_gui() {GfoInvkAble_.InvkCmd(cmd_async, Invk_scroll_page_by_bmk);}
private void Scroll_page_by_bmk() {
@ -165,6 +171,7 @@ public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
else if (ctx.Match(k, Invk_html_elem_delete)) html_box.Html_elem_delete(m.ReadStr("elem_id"));
else if (ctx.Match(k, Invk_html_elem_replace_html)) html_box.Html_elem_replace_html(m.ReadStr("id"), m.ReadStr("html"));
else if (ctx.Match(k, Invk_html_gallery_packed_exec)) html_box.Html_gallery_packed_exec();
else if (ctx.Match(k, Invk_html_popups_bind_hover_to_doc)) html_box.Html_js_eval_script("xowa_popups_bind_doc();");
else if (ctx.Match(k, Invk_scroll_page_by_bmk)) Scroll_page_by_bmk();
else if (ctx.Match(k, Invk_scroll_page_by_id)) Scroll_page_by_id(m.ReadStr("v"));
else if (ctx.Match(k, Invk_html_elem_focus)) html_box.Html_elem_focus(m.ReadStr("v"));
@ -173,7 +180,7 @@ public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
return this;
}
private static final String
Invk_html_gallery_packed_exec = "html_gallery_packed_exec"
Invk_html_gallery_packed_exec = "html_gallery_packed_exec", Invk_html_popups_bind_hover_to_doc = "html_popups_bind_hover_to_doc"
, Invk_html_img_update = "html_img_update", Invk_html_elem_atr_set = "html_elem_atr_set"
, Invk_html_elem_atr_set_append = "html_elem_atr_set_append", Invk_html_elem_delete = "html_elem_delete", Invk_html_elem_replace_html = "html_elem_replace_html"
, Invk_scroll_page_by_bmk = "scroll_page_by_bmk", Invk_scroll_page_by_id = "scroll_page_by_id"

View File

@ -176,8 +176,12 @@ public class Xog_tab_itm implements GfoInvkAble {
usr_dlg.Prog_one("", "", "downloading images: ~{0}", xfer_len);
try {
page.File_queue().Exec(gplx.xowa.files.Xof_exec_tid.Tid_wiki_page, usr_dlg, wiki, page);
if (page.Html_data().Gallery_packed_exists()) // packed_gallery exists; fire js once; PAGE:en.w:National_Sculpture_Museum_(Valladolid); DATE:2014-07-21
if (page.Html_data().Xtn_gallery_packed_exists()) // packed_gallery exists; fire js once; PAGE:en.w:National_Sculpture_Museum_(Valladolid); DATE:2014-07-21
html_itm.Html_gallery_packed_exec();
if ( page.Html_data().Xtn_imap_exists() // imap exists; DATE:2014-08-07
&& page.Html_data().Module_mgr().Itm_popups().Enabled()
)
html_itm.Html_popups_bind_hover_to_doc(); // rebind all elements to popup
}
catch (Exception e) {usr_dlg.Warn_many("", "", "page.thread.image: page=~{0} err=~{1}", page_ttl_str, Err_.Message_gplx_brief(e));}
}

View File

@ -412,7 +412,7 @@ public class Xoh_html_wtr {
break;
default: // unknown tag
if (tag.Restricted()) { // a; img; script; etc..
if ( !page.Html_data().Restricted() // page is not marked restricted (only [[Special:]])
if ( !page.Html_data().Html_restricted() // page is not marked restricted (only [[Special:]])
|| page.Wiki().Domain_tid() == Xow_wiki_domain_.Tid_home) { // page is in home wiki
bfr.Add_mid(src, xnde.Src_bgn(), xnde.Src_end());
return;

View File

@ -137,11 +137,18 @@ public class Xoh_lnki_file_wtr_basic_tst {
Tst_img_title("[[File:A.png|thumb|a b]]", "Enlarge"); // caption should not replace text
fxt.Wtr_cfg().Lnki_title_(false);
}
@Test public void Img_title__caption_has_lnki() { // PURPOSE: caption with lnki should show in title; PAGE:en.w:Earth; DATE:2014-08-06
fxt.Wtr_cfg().Lnki_title_(true);
Tst_img_title("[[File:A.png|frameless|[[A]]]]" , "A"); // ttl only
Tst_img_title("[[File:A.png|frameless|[[A|B]]]]" , "B"); // caption
Tst_img_title("[[File:A.png|frameless|[[A]]b]]" , "Ab"); // tail
fxt.Wtr_cfg().Lnki_title_(false);
}
@Test public void Lnki_alt_is_text() { // PURPOSE: (a) alt should default to caption; (b) alt should not show html chars (like <a src=")
fxt.Wtr_cfg().Lnki_title_(true);
fxt.Test_parse_page_all_str
( "[[File:A.png|a[[b]]c]]"
, "<a href=\"/wiki/File:A.png\" class=\"image\" title=\"a\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"abc\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
, "<a href=\"/wiki/File:A.png\" class=\"image\" title=\"aBc\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"abc\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
);
fxt.Wtr_cfg().Lnki_title_(false);
}
@ -213,7 +220,7 @@ public class Xoh_lnki_file_wtr_basic_tst {
fxt.Wtr_cfg().Lnki_title_(true);
fxt.Test_parse_page_wiki_str("[[File:A.png|none|[[File:B.png|20px|d]] c]]", String_.Concat_lines_nl_skip_last
( "<div class=\"floatnone\">"
, "<a href=\"/wiki/File:A.png\" class=\"image\" title=\" c\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"d c\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a></div>"
, "<a href=\"/wiki/File:A.png\" class=\"image\" title=\"d c\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"d c\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a></div>"
, ""
));
fxt.Wtr_cfg().Lnki_title_(false);

View File

@ -87,10 +87,7 @@ 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 (lnki.Xtn_sites_link()) return; // lnki marked for relatedSites; don't write to page
if (hctx.Mode_is_alt())
Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr);
else {

View File

@ -16,8 +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.html.portal.*;
import gplx.xowa.wikis.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.wdatas.*;
import gplx.html.*; import gplx.xowa.html.portal.*; import gplx.xowa.pages.skins.*;
import gplx.xowa.wikis.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.wdatas.*;
public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
private Xop_ctx ctx; private Xoa_page page; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public Xoh_page_wtr_wkr(byte page_mode) {this.page_mode = page_mode;} private byte page_mode;
@ -62,16 +62,15 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
byte[] page_content_sub = Xoh_page_wtr_wkr_.Bld_page_content_sub(app, wiki, page, tmp_bfr);
byte[] js_wikidata_bry = Wdata_wiki_mgr.Wiki_page_is_json(wiki.Domain_tid(), page.Ttl().Ns().Id()) ? app.User().Lang().Fragment_mgr().Html_js_wikidata() : Bry_.Empty;
byte[] js_edit_toolbar_bry = view_tid == Xog_page_mode.Tid_edit ? wiki.Fragment_mgr().Html_js_edit_toolbar() : Bry_.Empty;
page.Xtn_mgr().Exec();
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
fmtr.Bld_bfr_many(html_bfr, page.Revision_data().Id()
, Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page.Ttl(), null) // NOTE: page_name does not show display_title (<i>). always pass in null
, Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page.Ttl(), page.Display_ttl())
, Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page.Ttl(), page.Html_data().Display_ttl())
, page_content_sub, page_data, wtr_page_lang, page_modified_on_msg, page.Lang().Dir_bry()
, 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(), 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()
, 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().Xtn_search_text())
, portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar), portal_mgr.Div_wikis_bry(app.Utl_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

View File

@ -18,12 +18,6 @@ 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.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}}

View File

@ -30,6 +30,17 @@ public class Xohp_title_wkr implements Bry_fmtr_arg {
Arg_nde_tkn arg_nde = (Arg_nde_tkn)tkn;
Bld_recurse(bfr, arg_nde.Val_tkn());
break;
case Xop_tkn_itm_.Tid_lnki:
Xop_lnki_tkn tkn_as_lnki = (Xop_lnki_tkn)tkn;
if (tkn_as_lnki.Caption_exists())
Bld_recurse(bfr, tkn_as_lnki.Caption_tkn());
else {
if (tkn_as_lnki.Ttl() != null) // guard against invalid ttls
bfr.Add(tkn_as_lnki.Ttl().Page_txt());
}
if (tkn_as_lnki.Tail_bgn() != -1)
bfr.Add_mid(src, tkn_as_lnki.Tail_bgn(), tkn_as_lnki.Tail_end());
break;
default: // all other tkns, just iterate over subs for txt tkns
if (tkn.Tkn_tid() == Xop_tkn_itm_.Tid_xnde) {
Xop_xnde_tkn xnde = (Xop_xnde_tkn)tkn;

View File

@ -95,7 +95,7 @@ public class Xow_popup_mgr implements GfoInvkAble, GfoEvObj {
synchronized (async_thread_guard) {
if (itm.Canceled()) return null;
cur_page.Popup_mgr().Itms().AddReplace(itm.Popup_id(), itm);
app.Href_parser().Parse(temp_href, itm.Page_href(), wiki, cur_page.Ttl().Page_url());
app.Href_parser().Parse(temp_href, itm.Page_href(), wiki, cur_page.Ttl().Full_url()); // NOTE: use Full_url, not Page_url, else anchors won't work for non-main ns; PAGE:en.w:Project:Sandbox; DATE:2014-08-07
Xow_wiki popup_wiki = app.Wiki_mgr().Get_by_key_or_null(temp_href.Wiki());
popup_wiki.Init_assert();
Xoa_ttl popup_ttl = Xoa_ttl.parse_(popup_wiki, temp_href.Page_and_anchor());

View File

@ -62,7 +62,7 @@ public class Xow_popup_parser {
private void Init_ctxs(byte[] tmpl_src, Xoa_ttl ttl) {
tmpl_ctx.Clear();
tmpl_ctx.Cur_page().Ttl_(ttl); // NOTE: must set cur_page, else page-dependent templates won't work; EX: {{FULLPAGENAME}}; PAGE:en.w:June_20; DATE:2014-06-20
tmpl_ctx.Cur_page().Html_data().Restricted_(data.Html_restricted()); // NOTE: must set data.Html_restricted() if Special:XowaPopupHistory
tmpl_ctx.Cur_page().Html_data().Html_restricted_(data.Html_restricted()); // NOTE: must set data.Html_restricted() if Special:XowaPopupHistory
tmpl_ctx.Page_bgn(tmpl_root, tmpl_src);
Wtxt_ctx_init(true, tmpl_src);
wtxt_ctx.Cur_page().Ttl_(ttl); // NOTE: must set cur_page, or rel lnkis won't work; EX: [[../A]]
@ -188,7 +188,7 @@ public class Xow_popup_parser {
}
private void Wtxt_ctx_init(boolean incremental, byte[] bry) {
wtxt_ctx.Clear();
wtxt_ctx.Cur_page().Html_data().Restricted_(data.Html_restricted());
wtxt_ctx.Cur_page().Html_data().Html_restricted_(data.Html_restricted());
wtxt_ctx.Para().Enabled_(!incremental); // NOTE: if incremental, disable para; easier to work with \n rather than <p>; also, must be enabled before Page_bgn; DATE:2014-06-18DATE:2014-06-18
wtxt_ctx.Lnke().Dangling_goes_on_stack_(incremental);
wtxt_ctx.Page_bgn(wtxt_root, bry);

View File

@ -96,7 +96,7 @@ public class Xoa_lang_mgr implements GfoInvkAble {
}
public void Bld_xowa() {
Xol_mw_lang_parser lang_parser = new Xol_mw_lang_parser(app.Msg_log());
lang_parser.Bld_all(app, app.User().Fsys_mgr().Root_dir());
lang_parser.Bld_all(app);
}
public OrderedHash Xto_hash(byte[] raw) {
byte[][] keys = Bry_.Split(raw, Byte_ascii.Tilde);

View File

@ -69,7 +69,7 @@ public class Xol_func_name_regy {
finder.Func_set(func, -1);
else if (src[match_pos] == Pf_func_.Name_dlm) // next char is :
finder.Func_set(func, match_pos);
else { // func is close, but not quite: ex: #ifx: or padlefts:
else { // func is close, but not quite: ex: #ifx: or padlefts:
return finder;
}
break;
@ -95,7 +95,7 @@ public class Xol_func_name_regy {
Xot_defn rv = null;
if (cs_obj != null) { // match found for cs; could be false_match; EX: NAME"+"SPACE and NAME"+"SPACENUMBER
rv = (Xot_defn)cs_obj;
if (rv.Name().length == end - bgn) // func_name matchese cur_name; DATE:2013-04-15
if (rv.Name().length == end - bgn) // func_name matches cur_name; DATE:2013-04-15
return rv;
// else {} // func_name doesn't match cur_name; continue below; EX: NAME"+"SPACENUMBER passed in and matches NAME"+"SPACE (which is cs); note that NAME"+"SPACENUMBER only exists in ci
}

View File

@ -32,6 +32,6 @@ public class Xol_cnv_mgr implements GfoInvkAble {
if (ctx.Match(k, Invk_get)) return Get_or_make(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get";
public static Io_url Bld_url(Xoa_app app, String lang) {return Bld_url(app.User().Fsys_mgr().Root_dir(), lang);}
public static Io_url Bld_url(Io_url dir, String lang) {return dir.GenSubFil_nest("lang", "xowa", "variants", lang + ".gfs");}
public static Io_url Bld_url(Xoa_app app, String lang) {return Bld_url(app.Fsys_mgr().Cfg_lang_core_dir(), lang);}
public static Io_url Bld_url(Io_url dir, String lang) {return dir.GenSubFil_nest("variants", lang + ".gfs");}
}

View File

@ -32,8 +32,8 @@ public class Xol_mw_parse_tst {
));
}
// @Test public void Run() {
// Io_url src_dir = Io_url_.new_dir_("C:\\xowa\\user\\anonymous\\lang\\mediawiki\\converts\\");
// Io_url trg_dir = Io_url_.new_dir_("C:\\xowa\\user\\anonymous\\");
// Io_url src_dir = Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\lang\\mediawiki\\converts\\");
// Io_url trg_dir = Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\lang\\");
// fxt.Test_run(src_dir, trg_dir);
// }
}

View File

@ -0,0 +1,75 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.pages; import gplx.*; import gplx.xowa.*;
import gplx.html.*; import gplx.xowa.html.modules.*; import gplx.xowa.pages.skins.*;
public class Xopg_html_data {
private OrderedHash ctg_hash;
public boolean Html_restricted() {return html_restricted;} private boolean html_restricted = true;
public void Html_restricted_(boolean v) {html_restricted = v;} public void Html_restricted_n_() {Html_restricted_(Bool_.N);} public void Html_restricted_y_() {Html_restricted_(Bool_.Y);}
public byte[] Display_ttl() {return display_ttl;} public Xopg_html_data Display_ttl_(byte[] v) {display_ttl = v; return this;} private byte[] display_ttl;
public byte[] Content_sub() {return content_sub;} public void Content_sub_(byte[] v) {content_sub = v;} private byte[] content_sub;
public String Bmk_pos() {return html_bmk_pos;} public void Bmk_pos_(String v) {html_bmk_pos = v;} private String html_bmk_pos;
public Bry_bfr Portal_div_xtn() {return portal_div_xtn;} private Bry_bfr portal_div_xtn = Bry_bfr.reset_(255);
public byte[] Edit_preview_w_dbg() {return Bry_.Add(xtn_scribunto_dbg, edit_preview);} public void Edit_preview_(byte[] v) {edit_preview = v;} private byte[] edit_preview = Bry_.Empty;
public int Lnke_autonumber_next() {return lnke_autonumber++;} private int lnke_autonumber = 1;
public Xopg_xtn_skin_mgr Xtn_skin_mgr() {return xtn_skin_mgr;} private Xopg_xtn_skin_mgr xtn_skin_mgr = new Xopg_xtn_skin_mgr();
public boolean Xtn_gallery_packed_exists() {return xtn_gallery_packed_exists;} public void Xtn_gallery_packed_exists_y_() {xtn_gallery_packed_exists = true;} private boolean xtn_gallery_packed_exists;
public boolean Xtn_imap_exists() {return xtn_imap_exists;} public void Xtn_imap_exists_y_() {xtn_imap_exists = true;} private boolean xtn_imap_exists;
public int Xtn_imap_next_id() {return ++xtn_imap_next_id;} private int xtn_imap_next_id; // NOTE: must keep separate imap_id b/c html_elem_id is not always set;
public byte[] Xtn_search_text() {return xtn_search_txt;} public void Xtn_search_text_(byte[] v) {xtn_search_txt = v;} private byte[] xtn_search_txt = Bry_.Empty;
public byte[] Xtn_scribunto_dbg() {return xtn_scribunto_dbg;} public void Xtn_scribunto_dbg_(byte[] v) {xtn_scribunto_dbg = Bry_.Add(xtn_scribunto_dbg, v);} private byte[] xtn_scribunto_dbg = Bry_.Empty;
public Xoh_module_mgr Module_mgr() {return module_mgr;} private Xoh_module_mgr module_mgr = new Xoh_module_mgr();
public byte[] Custom_html() {return custom_html;} public Xopg_html_data Custom_html_(byte[] v) {custom_html = v; return this;} private byte[] custom_html;
public byte[] Custom_name() {return custom_name;} public Xopg_html_data Custom_name_(byte[] v) {custom_name = v; return this;} private byte[] custom_name;
public byte[] Custom_head_end() {return custom_head_end;}
public byte[] Custom_html_end() {return custom_html_end;}
public void Custom_head_end_concat(byte[] v) {
if (v == null)
custom_head_end = v;
else
custom_head_end = Bry_.Add(custom_head_end, v);
} private byte[] custom_head_end;
public void Custom_html_end_concat(byte[] v) {
if (v == null)
custom_html_end = v;
else
custom_html_end = Bry_.Add(custom_html_end, v);
} private byte[] custom_html_end;
public void Clear() {
html_restricted = true;
display_ttl = null;
content_sub = Bry_.Empty;
lnke_autonumber = 1;
xtn_skin_mgr.Clear();
xtn_gallery_packed_exists = false;
xtn_imap_next_id = 0;
xtn_imap_exists = false;
xtn_search_txt = Bry_.Empty;
xtn_scribunto_dbg = Bry_.Empty;
module_mgr.Clear();
custom_html = custom_html_end = custom_head_end = custom_name = null;
if (ctg_hash != null) ctg_hash.Clear();
}
public byte[][] Ctgs_to_ary() {return ctg_hash == null ? Bry_.Ary_empty : (byte[][])ctg_hash.XtoAry(byte[].class);}
public void Ctgs_add(Xoa_ttl ttl) {
if (ctg_hash == null) ctg_hash = OrderedHash_.new_bry_();
byte[] ttl_bry = ttl.Page_txt();
if (ctg_hash.Has(ttl_bry)) return;
ctg_hash.Add(ttl_bry, ttl_bry);
}
}

View File

@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.pages.skins; import gplx.*; import gplx.xowa.*; import gplx.xowa.pages.*;
public class Xopg_xtn_skin_fmtr_arg implements Bry_fmtr_arg {
private Xoa_page page; private byte xtn_skin_tid;
public Xopg_xtn_skin_fmtr_arg(Xoa_page page, byte xtn_skin_tid) {
this.page = page; this.xtn_skin_tid = xtn_skin_tid;
}
public void XferAry(Bry_bfr bfr, int idx) {
Xopg_xtn_skin_mgr mgr = page.Html_data().Xtn_skin_mgr();
int len = mgr.Count();
for (int i = 0; i < len; ++i) {
Xopg_xtn_skin_itm itm = mgr.Get_at(i);
if (itm.Tid() == xtn_skin_tid)
itm.Write(bfr, page);
}
}
}

View File

@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.pages.skins; import gplx.*; import gplx.xowa.*; import gplx.xowa.pages.*;
public interface Xopg_xtn_skin_itm {
byte Tid();
byte[] Key();
void Write(Bry_bfr bfr, Xoa_page page);
}

View File

@ -15,8 +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.html; import gplx.*; import gplx.xowa.*;
public interface Xoh_xtn_itm {
byte[] Key();
void Exec();
package gplx.xowa.pages.skins; import gplx.*; import gplx.xowa.*; import gplx.xowa.pages.*;
public class Xopg_xtn_skin_itm_tid {
public static final byte Tid_sidebar = 0;
}

View File

@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.pages.skins; import gplx.*; import gplx.xowa.*; import gplx.xowa.pages.*;
public class Xopg_xtn_skin_mgr {
private OrderedHash hash = OrderedHash_.new_bry_();
public int Count() {return hash.Count();}
public void Add(Xopg_xtn_skin_itm itm) {hash.Add_if_new(itm.Key(), itm);}
public Xopg_xtn_skin_itm Get_at(int i) {return (Xopg_xtn_skin_itm)hash.FetchAt(i);}
public Xopg_xtn_skin_itm Get_or_null(byte[] key) {return (Xopg_xtn_skin_itm)hash.Fetch(key);}
public void Clear() {hash.Clear();}
}

View File

@ -68,7 +68,7 @@ public class Xows_page_allpages implements GfoInvkAble, Bry_fmtr_arg, Xows_page
public int Rslt_list_len() {return rslt_list_len;} public void Rslt_list_len_(int v) {rslt_list_len = v;} private int rslt_list_len;
public Xodb_page[] Rslt_list_ttls() {return rslt_list_ttls;} private Xodb_page[] rslt_list_ttls;
public void Special_gen(Xoa_url url, Xoa_page page, Xow_wiki wiki, Xoa_ttl ttl) {
wiki.Ctx().Cur_page().Display_ttl_(wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_sp_allpages_hdr));
wiki.Ctx().Cur_page().Html_data().Display_ttl_(wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_sp_allpages_hdr));
url.Page_bry_(Bry_.Add(Bry_.new_ascii_("Special:"), ttl.Page_txt_wo_qargs())); // HACK: need to re-set Page b/c href_parser does not eliminate qargs; DATE:2013-02-08
if (wiki.Domain_tid() == Xow_wiki_domain_.Tid_home) {wiki.App().Usr_dlg().Prog_many(GRP_KEY, "home.invalid", "AllPages not implemented for home wiki"); return;}
if (rslt_list_ttls == null) this.Itms_per_page_(itms_per_page);
@ -121,7 +121,7 @@ public class Xows_page_allpages implements GfoInvkAble, Bry_fmtr_arg, Xows_page
html_all.Bld_bfr_many(tmp_bfr, this, anchor_prv, anchor_nxt);
page.Data_raw_(tmp_bfr.XtoAryAndClear());
tmp_bfr.Mkr_rls();
page.Html_data().Restricted_n_();
page.Html_data().Html_restricted_n_();
}
byte[] Build_html_end(Bry_bfr bfr, Xodb_page itm, boolean fwd) {
Xoa_ttl ttl = Xows_page_allpages.ttl_(wiki, init_ns, itm); if (ttl == null) return Bry_.Empty; // occurs when range is empty; EX: Module:A in simplewikibooks

View File

@ -173,7 +173,7 @@ class Xows_page_allpages_fxt {
parserx.Parse(init_url, Xows_page_allpages.Ttl_full_bry);
Xoa_ttl init_ttl = Make_init_ttl();
allpages.Special_gen(init_url, wiki.Ctx().Cur_page(), wiki, init_ttl);
if (expd_display_ttl != null) Tfds.Eq(expd_display_ttl, String_.new_utf8_(wiki.Ctx().Cur_page().Display_ttl()));
if (expd_display_ttl != null) Tfds.Eq(expd_display_ttl, String_.new_utf8_(wiki.Ctx().Cur_page().Html_data().Display_ttl()));
if (expd_address_page != null) Tfds.Eq(expd_address_page, String_.new_utf8_(init_url.Page_bry()));
return this;
}

View File

@ -29,7 +29,7 @@ public class Move_page implements Xows_page {
return;
}
byte[] html = Bld_html(page);
page.Html_data().Restricted_n_(); // [[Special:]] pages allow all HTML
page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML
page.Data_raw_(html);
}
private void Exec_rename(Xow_wiki wiki, Xoa_page page) {

View File

@ -29,7 +29,7 @@ public class Nearby_mgr implements Xows_page {
public int Results_max() {return results_max;} public Nearby_mgr Results_max_(int v) {results_max = v; return this;} private int results_max = 1;
public void Special_gen(Xoa_url calling_url, Xoa_page page, Xow_wiki wiki, Xoa_ttl ttl) {
page.Data_raw_(Bld_html(wiki));
page.Html_data().Restricted_n_(); // [[Special:]] pages allow all HTML
page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML
// wiki.ParsePage(page, false); // do not clear else previous Search_text will be lost
}
byte[] Bld_html(Xow_wiki wiki) {

View File

@ -55,7 +55,7 @@ public class Xosrh_core implements GfoInvkAble, Xows_page {
html_mgr.Bld_html(tmp_bfr, this, cur_grp, search_bry, page_idx, page_mgr.Pages_len());
page.Data_raw_(tmp_bfr.Mkr_rls().XtoAryAndClear());
wiki.ParsePage(page, false); // do not clear else previous Search_text will be lost
page.Html_data().Search_text_(search_bry);
page.Html_data().Xtn_search_text_(search_bry);
}
else { // page found; return it;
wiki.ParsePage(find_page, true);

View File

@ -23,7 +23,7 @@ public class Xop_statistics_page implements Xows_page {
private Xop_statistics_stats_ns_grp stats_ns = new Xop_statistics_stats_ns_grp();
public void Special_gen(Xoa_url calling_url, Xoa_page page, Xow_wiki wiki, Xoa_ttl ttl) {
byte[] html = Build_html(wiki);
page.Html_data().Restricted_n_(); // [[Special:]] pages allow all HTML
page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML
page.Data_raw_(html);
}
public byte[] Build_html(Xow_wiki wiki) {

View File

@ -29,7 +29,7 @@ public class Popup_history_page implements Xows_page {
fmtr_main.Bld_bfr_many(bfr, itm.Page_href(), itm.Page_ttl().Full_txt());
}
page.Data_raw_(bfr.Trim_end(Byte_ascii.NewLine).Mkr_rls().XtoAryAndClear());
page.Html_data().Restricted_n_();
page.Html_data().Html_restricted_n_();
}
private Bry_fmtr fmtr_main = Bry_fmtr.new_("<a href='~{href}'>~{ttl}</a>\n\n", "href", "ttl"); // NOTE: need to use anchor (as opposed to lnki or lnke) b/c xwiki will not work on all wikis
public static final byte[] Ttl_name_bry = Bry_.new_ascii_("XowaPopupHistory");

View File

@ -16,18 +16,22 @@ 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.relatedSites.*;
import gplx.core.btries.*;
import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.imaps.*; import gplx.xowa.xtns.relatedSites.*; import gplx.xowa.xtns.insiders.*;
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 Imap_xtn_mgr Xtn_imap() {return xtn_imap;} private Imap_xtn_mgr xtn_imap;
public Sites_xtn_mgr Xtn_sites() {return xtn_sites;} private Sites_xtn_mgr xtn_sites;
public Insider_xtn_mgr Xtn_insider() {return xtn_insider;} private Insider_xtn_mgr xtn_insider;
public Xow_xtn_mgr Ctor_by_app(Xoa_app app) { // NOTE: needed for options
Add(app, new Cite_xtn_mgr());
Add(app, new Imap_xtn_mgr());
Add(app, new Sites_xtn_mgr());
Add(app, new Insider_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());
Add(app, new gplx.xowa.xtns.poems.Poem_xtn_mgr());
Add(app, new gplx.xowa.xtns.hieros.Hiero_xtn_mgr());
Add(app, new gplx.xowa.xtns.scores.Score_xtn_mgr());
@ -73,9 +77,22 @@ public class Xow_xtn_mgr implements GfoInvkAble {
return xtn;
}
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;
byte[] xtn_key = mgr.Xtn_key();
Object o = xtn_tid_trie.Match_exact(xtn_key, 0, xtn_key.length); if (o == null) return;
switch (((Byte_obj_val)o).Val()) {
case Tid_cite: xtn_cite = (Cite_xtn_mgr)mgr; break;
case Tid_sites: xtn_sites = (Sites_xtn_mgr)mgr; break;
case Tid_insider: xtn_insider = (Insider_xtn_mgr)mgr; break;
case Tid_imap: xtn_imap = (Imap_xtn_mgr)mgr; break;
}
}
private static final byte Tid_cite = 0, Tid_sites = 1, Tid_insider = 2, Tid_imap = 3;
private static final Btrie_slim_mgr xtn_tid_trie = Btrie_slim_mgr.cs_()
.Add_bry_bval(Cite_xtn_mgr.XTN_KEY , Tid_cite)
.Add_bry_bval(Sites_xtn_mgr.XTN_KEY , Tid_sites)
.Add_bry_bval(Insider_xtn_mgr.XTN_KEY , Tid_insider)
.Add_bry_bval(Imap_xtn_mgr.XTN_KEY , Tid_imap)
;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_or_fail(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;

View File

@ -56,6 +56,11 @@ public abstract class Xox_mgr_base implements Xox_mgr {
}
Xox_mgr_base.Xtn_write_escape(app, bfr, src, xnde.Tag_close_bgn(), xnde.Tag_close_end());
}
public static void Xtn_load_i18n(Xow_wiki wiki, byte[] xtn_key) {
Xoa_app app = wiki.App();
Io_url url = app.Fsys_mgr().Bin_extensions_dir().GenSubFil_nest(String_.new_utf8_(xtn_key), "i18n", wiki.Lang().Key_str() + ".json");
wiki.App().Bldr().I18n_parser().Load_msgs(false, wiki.Lang(), url);
}
private static final byte[] Xowa_not_implemented = Bry_.new_ascii_("XOWA does not support this extension: ");
public static final byte Parse_content_tid_none = 0, Parse_content_tid_escape = 1, Parse_content_tid_html = 2;
}

View File

@ -43,16 +43,16 @@ public class Gallery_itm implements Js_img_wkr {
this.xnde = xnde; this.xfer_itm = xfer_itm;;
this.wiki = wiki; this.ctx = ctx; this.src = src; this.gallery_li_id_bry = gallery_li_id_bry; this.gallery_itm_idx = gallery_itm_idx;
} private Gallery_xnde xnde; private Xof_xfer_itm xfer_itm; private Xow_wiki wiki; private Xop_ctx ctx; private byte[] src; private byte[] gallery_li_id_bry; private int gallery_itm_idx;
public void Html_update(Xoa_page page, Xog_html_itm html_itm, int w, int h, String view_src, String orig_src) {
public void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src) {
Gallery_mgr_base gallery_mgr = xnde.Gallery_mgr();
Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_k004(), tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
try {
xfer_itm.Init_xfer_by_gallery_update(w, h, view_src, orig_src);
xfer_itm.Init_xfer_by_gallery_update(html_w, html_h, html_src, orig_src);
gallery_mgr.Write_html_itm(bfr, tmp_bfr, wiki.App(), wiki, ctx.Cur_page(), ctx, wiki.Html_mgr().Html_wtr(), src, xnde, Bry_.Empty, gallery_itm_idx, xfer_itm);
String itm_html = bfr.XtoStrAndClear();
html_itm.Html_elem_replace_html(String_.new_utf8_(gallery_li_id_bry), itm_html);
if (gallery_itm_idx == xnde.Itms_len() - 1 && Gallery_mgr_base_.Mode_is_packed(xnde.Mode()))
page.Html_data().Gallery_packed_exists_y_(); // set flag for packed_gallery; don't fire multiple times; PAGE:en.w:National_Sculpture_Museum_(Valladolid); DATE:2014-07-21
page.Html_data().Xtn_gallery_packed_exists_y_(); // set flag for packed_gallery; don't fire multiple times; PAGE:en.html_w:National_Sculpture_Museum_(Valladolid); DATE:2014-07-21
}
finally {
bfr.Mkr_rls(); tmp_bfr.Mkr_rls();

View File

@ -29,11 +29,9 @@ class Imap_desc_tid {
public static Btrie_slim_mgr trie_(Xow_wiki wiki) {
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_utf_8_();
trie_add(rv, Key_tr, Key_br, Key_bl, Key_tl, Key_none);
// if (wiki.Lang().Lang_id() != Xol_lang_itm_.Id_en) {
byte[][] lang_types = Parse_lang_types(wiki);
if (lang_types != null)
trie_add(rv, lang_types);
// }
byte[][] lang_types = Parse_lang_types(wiki);
if (lang_types != null)
trie_add(rv, lang_types);
return rv;
}
private static void trie_add(Btrie_slim_mgr trie, byte[]... ary) {
@ -45,19 +43,19 @@ class Imap_desc_tid {
}
private static byte[][] Parse_lang_types(Xow_wiki wiki) {
byte[] val = wiki.Msg_mgr().Val_by_key_obj("imagemap_desc_types");
if (Bry_.Len_eq_0(val)) return null; // no msg in lang; return;
byte[][] ary = Bry_.Split(val, Byte_ascii.Comma);
if (Bry_.Len_eq_0(val)) return null; // no msg in lang; return;
byte[][] ary = Bry_.Split(val, Byte_ascii.Comma); // msg is 5 words concatenated by comma: EX:top-right,bottom-right-bottom-left,top-left,none
int ary_len = ary.length;
if (ary_len != 5) wiki.App().Usr_dlg().Warn_many("", "", "imap_desc does not have 5 items; wiki=~{0} val=~{1}", wiki.Domain_bry(), val);
for (int i = 0; i < 5; ++i)
ary[i] = Bry_.Trim(ary[i]); // note that items will have trailing ws; EX: "top-right, bottom-right, bottom-left, top-left, none"
ary[i] = Bry_.Trim(ary[i]); // note that items will have trailing ws; EX: "top-right, bottom-right, bottom-left, top-left, none"
return ary;
}
public static byte parse_(Btrie_slim_mgr trie, byte[] src, int bgn, int end) {
Object rv = trie.Match_bgn(src, bgn, end);
return rv == null ? Tid_null : ((Byte_obj_val)rv).Val();
}
public static void calc_desc_margins(Int_2_ref rv, byte tid, int html_w, int html_h) {
public static void Calc_desc_margins(Int_2_ref rv, byte tid, int html_w, int html_h) {
int margin_l
= tid == Tid_tl || tid == Tid_bl
? 0

View File

@ -18,12 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
class Imap_html_fmtrs {
public static final Bry_fmtr
Map = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div class=\"noresize\"~{desc_style}>"
, " <map name=\"imageMap_1_~{imap_id}\">~{shapes}"
, " </map>~{img}"
All = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div id='imap_div_~{imap_id}' class=\"noresize\"~{desc_style}>~{map}~{img}"
, " </div>"
), "imap_id", "desc_style", "img", "shapes"
), "imap_id", "desc_style", "map", "img"
)
, Map = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <map name=\"imageMap_1_~{imap_id}\">~{shapes}"
, " </map>"
), "imap_id", "shapes"
)
, Area = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "\n <area href=\"~{href}\" shape=\"~{shape}\" coords=\"~{coords}\" alt=\"~{title}\" title=\"~{title}\"/>"

View File

@ -41,7 +41,7 @@ class Imap_img_fmtr_arg implements Bry_fmtr_arg {
fmtr.Bld_bfr_many(bfr, map.Id(), img_elem_id, img_alt, img_src, img_w, img_h, img_cls, anchor_href, anchor_text);
Imap_itm_desc itm_desc = map.Desc();
if (itm_desc != null) {
Imap_desc_tid.calc_desc_margins(margin_calc, itm_desc.Desc_tid(), img_w, img_h);
Imap_desc_tid.Calc_desc_margins(margin_calc, itm_desc.Desc_tid(), img_w, img_h);
Imap_xtn_mgr xtn_mgr = map.Xtn_mgr();
Imap_html_fmtrs.Desc_main.Bld_bfr_many(bfr, margin_calc.Val_0(), margin_calc.Val_1(), img_href, xtn_mgr.Desc_msg(), xtn_mgr.Desc_icon_url());
}

View File

@ -16,49 +16,45 @@ 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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.files.*; import gplx.xowa.html.*;
class Imap_map implements Bry_fmtr_arg, Xoh_lnki_file_wkr {
import gplx.xowa.files.*; import gplx.xowa.html.*; import gplx.xowa.files.gui.*; import gplx.xowa.gui.views.*;
public class Imap_map implements Xoh_lnki_file_wkr, Js_img_wkr {
private static final Imap_map_fmtr map_fmtr_arg = new Imap_map_fmtr();
public Imap_map(int id) {this.id = id;}
public Imap_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Imap_xtn_mgr xtn_mgr;
public void Init(Imap_xtn_mgr xtn_mgr, int id, byte[] img_src, Imap_itm_img img, Imap_itm_dflt dflt, Imap_itm_desc desc, Imap_itm_shape[] shapes, Imap_err[] errs) {
this.xtn_mgr = xtn_mgr;
this.id = id; this.img_src = img_src; this.img = img; this.dflt = dflt; this.desc = desc; this.shapes = shapes; this.errs = errs;
@gplx.Internal protected void Init(Imap_xtn_mgr xtn_mgr, byte[] img_src, Imap_itm_img img, Imap_itm_dflt dflt, Imap_itm_desc desc, Imap_itm_shape[] shapes, Imap_err[] errs) {
this.xtn_mgr = xtn_mgr; this.img_src = img_src; this.img = img; this.dflt = dflt; this.desc = desc; this.shapes = shapes; this.errs = errs;
}
public int Id() {return id;} private int id;
public byte[] Img_src() {return img_src;} private byte[] img_src;
public Imap_itm_img Img() {return img;} private Imap_itm_img img;
public Imap_itm_dflt Dflt() {return dflt;} private Imap_itm_dflt dflt;
public Imap_itm_desc Desc() {return desc;} private Imap_itm_desc desc;
public Imap_itm_shape[] Shapes() {return shapes;} private Imap_itm_shape[] shapes;
public Imap_err[] Errs() {return errs;} private Imap_err[] errs;
public void Write_img_full(Bry_bfr bfr, Xof_xfer_itm xfer_itm, int elem_id, byte[] lnki_href, byte[] html_view_src, int html_w, int html_h, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_cls, byte[] anchor_rel, byte[] anchor_title, byte[] itm_cls) {
pts_fmtr_arg.Scale_(Calc_scale(xfer_itm.Orig_w(), xfer_itm.Orig_h(), html_w, html_h));
img_fmtr_arg.Init(this, elem_id, lnki_alt_text, html_view_src, html_w, html_h, itm_cls, lnki_href);
@gplx.Internal protected Imap_itm_img Img() {return img;} private Imap_itm_img img;
@gplx.Internal protected Imap_itm_dflt Dflt() {return dflt;} private Imap_itm_dflt dflt;
@gplx.Internal protected Imap_itm_desc Desc() {return desc;} private Imap_itm_desc desc;
@gplx.Internal protected Imap_itm_shape[] Shapes() {return shapes;} private Imap_itm_shape[] shapes;
@gplx.Internal protected Imap_err[] Errs() {return errs;} private Imap_err[] errs;
private byte[] lnki_alt_text, itm_cls, lnki_href;
public void Write_img_full(Bry_bfr bfr, Xof_xfer_itm xfer_itm, int html_uid, byte[] lnki_href, byte[] html_src, int html_w, int html_h, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_cls, byte[] anchor_rel, byte[] anchor_title, byte[] itm_cls) {
xfer_itm.Html_img_wkr_(this);
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_imap);
this.lnki_alt_text = lnki_alt_text; this.itm_cls = itm_cls; this.lnki_href = lnki_href;
Write_imap_div(bfr, html_uid, html_w, html_h, html_src, xfer_itm.Orig_w(), xfer_itm.Orig_h());
}
public void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src) {
Xow_wiki wiki = xtn_mgr.Wiki();
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
Write_imap_div(tmp_bfr, html_uid, html_w, html_h, Bry_.new_utf8_(html_src), orig_w, orig_h);
html_itm.Html_elem_replace_html("imap_div_" + Int_.XtoStr(html_uid), tmp_bfr.Mkr_rls().XtoStrAndClear());
}
private void Write_imap_div(Bry_bfr bfr, int html_uid, int html_w, int html_h, byte[] html_src, int orig_w, int orig_h) {
byte[] desc_style = Calc_desc_style(html_w, html_h);
Imap_html_fmtrs.Map.Bld_bfr_many(bfr, id, desc_style, img_fmtr_arg, this);
map_fmtr_arg.Init(id, shapes, Calc_scale(orig_w, orig_h, html_w, html_h));
img_fmtr_arg.Init(this, html_uid, lnki_alt_text, html_src, html_w, html_h, itm_cls, lnki_href);
Imap_html_fmtrs.All.Bld_bfr_many(bfr, html_uid, desc_style, map_fmtr_arg, img_fmtr_arg);
}
private byte[] Calc_desc_style(int html_w, int html_h) {
if (desc == null) return Bry_.Empty;
Bry_bfr tmp_bfr = xtn_mgr.Wiki().Utl_bry_bfr_mkr().Get_b128().Mkr_rls();
return Imap_html_fmtrs.Desc_style.Bld_bry_many(tmp_bfr, html_w, html_h);
}
public void XferAry(Bry_bfr bfr, int idx) {
int shapes_len = shapes.length;
Bry_fmtr fmtr = Imap_html_fmtrs.Area;
for (int i = 0; i < shapes_len; ++i) {
Imap_itm_shape shape = shapes[i];
Fmt_shape(bfr, fmtr, pts_fmtr_arg, shape);
}
}
public static void Fmt_shape(Bry_bfr bfr, Bry_fmtr fmtr, Imap_pts_fmtr_arg pts_fmtr, Imap_itm_shape shape) {
pts_fmtr_arg.Pts_(shape.Shape_pts());
fmtr.Bld_bfr_many(bfr
, shape.Link_href()
, Imap_itm_.Xto_key(shape.Itm_tid())
, pts_fmtr_arg
, shape.Link_text()
);
}
private static final Imap_pts_fmtr_arg pts_fmtr_arg = new Imap_pts_fmtr_arg();
private static final Imap_img_fmtr_arg img_fmtr_arg = new Imap_img_fmtr_arg();
private static double Calc_scale(int orig_w, int orig_h, int html_w, int html_h) {
int denominator = orig_w + orig_h;

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.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
class Imap_map_fmtr implements Bry_fmtr_arg {
private int imap_id;
public void Init(int imap_id, Imap_itm_shape[] shapes, double scale) {this.imap_id = imap_id; shapes_fmtr_arg.Init(shapes, scale);}
public Imap_pts_fmtr_arg Pts_fmtr() {return shapes_fmtr_arg.Pts_fmtr();}
public void XferAry(Bry_bfr bfr, int idx) {
Imap_html_fmtrs.Map.Bld_bfr_many(bfr, imap_id, shapes_fmtr_arg);
}
private static final Imap_shapes_fmtr shapes_fmtr_arg = new Imap_shapes_fmtr();
}
class Imap_shapes_fmtr implements Bry_fmtr_arg {
private Imap_itm_shape[] shapes;
public void Init(Imap_itm_shape[] shapes, double scale) {this.shapes = shapes; pts_fmtr_arg.Scale_(scale);}
public Imap_pts_fmtr_arg Pts_fmtr() {return pts_fmtr_arg;}
public void XferAry(Bry_bfr bfr, int idx) {
int shapes_len = shapes.length;
Bry_fmtr fmtr = Imap_html_fmtrs.Area;
for (int i = 0; i < shapes_len; ++i) {
Imap_itm_shape shape = shapes[i];
Fmt_shape(bfr, fmtr, pts_fmtr_arg, shape);
}
}
@gplx.Internal protected static void Fmt_shape(Bry_bfr bfr, Bry_fmtr fmtr, Imap_pts_fmtr_arg pts_fmtr, Imap_itm_shape shape) {
pts_fmtr_arg.Pts_(shape.Shape_pts());
fmtr.Bld_bfr_many(bfr
, shape.Link_href()
, Imap_itm_.Xto_key(shape.Itm_tid())
, pts_fmtr_arg
, shape.Link_text()
);
}
private static final Imap_pts_fmtr_arg pts_fmtr_arg = new Imap_pts_fmtr_arg();
}

View File

@ -42,12 +42,12 @@ class Imap_parser {
shapes.Clear(); pts.Clear(); errs.Clear();
}
public Imap_map Parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
Imap_map rv = new Imap_map();
Imap_map rv = new Imap_map(ctx.Cur_page().Html_data().Xtn_imap_next_id());
Init(wiki, ctx.Cur_page().Url(), wiki.App().Usr_dlg());
this.Parse(rv, ctx.Cur_page().Html_data().Imap_id_next(), src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
this.Parse(rv, src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
return rv;
}
public void Parse(Imap_map rv, int imap_id, byte[] src, int src_bgn, int src_end) {
public void Parse(Imap_map rv, byte[] src, int src_bgn, int src_end) {
this.Clear();
this.src = src;
itm_bgn = src_bgn; itm_end = src_bgn - 1;
@ -84,7 +84,7 @@ class Imap_parser {
} catch (Exception e) {usr_dlg.Warn_many("", "", "imap.parse:skipping line; page=~{0} line=~{1} err=~{2}", page_url.Xto_full_str_safe(), Bry_.Mid_by_len_safe(src, itm_bgn, itm_end), Err_.Message_gplx(e));}
++itm_idx;
}
rv.Init(xtn_mgr, imap_id, imap_img_src, imap_img, imap_dflt, imap_desc, (Imap_itm_shape[])shapes.XtoAryAndClear(Imap_itm_shape.class), (Imap_err[])errs.XtoAryAndClear(Imap_err.class));
rv.Init(xtn_mgr, imap_img_src, imap_img, imap_dflt, imap_desc, (Imap_itm_shape[])shapes.XtoAryAndClear(Imap_itm_shape.class), (Imap_err[])errs.XtoAryAndClear(Imap_err.class));
}
private void Parse_comment(int itm_bgn, int itm_end) {} // noop comments; EX: "# comment\n"
private void Parse_invalid(int itm_bgn, int itm_end) {usr_dlg.Warn_many("", "", "imap has invalid line: page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_utf8_(src, itm_bgn, itm_end));}
@ -122,7 +122,7 @@ class Imap_parser {
default:
int new_pos = Parse_shape_num(shape_tid, b, pos, num_bgn, pos, itm_end);
if (new_pos == -1) return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_invalid_coord");
if (new_pos == pos)
if (new_pos == pos) // occurs when char is text
reading_numbers = false;
else
pos = Bry_finder.Trim_fwd_space_tab(src, new_pos, itm_end);
@ -174,8 +174,9 @@ class Imap_parser {
}
private int Parse_shape_num(byte shape_tid, byte b, int pos, int num_bgn, int num_end, int itm_end) {
double num = 0;
boolean shape_is_poly = shape_tid == Imap_itm_.Tid_shape_poly;
if (num_bgn == -1) { // 1st char is non-numeric; EX: "poly a"
if ( shape_tid == Imap_itm_.Tid_shape_poly // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"poly1"; PAGE:uk.w:Стратосфера; DATE:2014-07-26
if ( shape_is_poly // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"poly1"; PAGE:uk.w:Стратосфера; DATE:2014-07-26
&& b != Byte_ascii.Brack_bgn // skip logic if "[" which may be beginning of lnki / lnke
) {
num_end = Bry_finder.Find_fwd_until_space_or_tab(src, pos, itm_end); // gobble up rest of word and search forward for space / tab to
@ -188,12 +189,14 @@ class Imap_parser {
else
num = Bry_.XtoDoubleByPosOr(src, num_bgn, num_end, Double_.NaN);
if (Double_.IsNaN(num)) {
if (shape_tid == Imap_itm_.Tid_shape_poly) // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"poly 1a"
if (shape_is_poly) // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"poly 1a"
num = 0;
else
return -1; // invalid number; EX: "1.2.3"
}
pts.Add(Double_obj_val.new_(num));
if (shape_is_poly && src[num_end] == Byte_ascii.Comma) // PHP ignores trailing comma when casting numbers; EX:echo('123,' + 1) -> 124; PAGE:de.w:Kaimnitz; DATE:2014-08-05
++num_end;
return Bry_finder.Trim_fwd_space_tab(src, num_end, itm_end);
}
private void Parse_img(Imap_map imap, int itm_bgn, int itm_end) {

View File

@ -24,6 +24,7 @@ public class Imap_parser_tst {
@Test public void Circle_pass() {fxt.Test_shape("circle 1 2 3 [[A]]" , fxt.itm_circle_("[[A]]", 1, 2, 3));}
@Test public void Poly_pass() {fxt.Test_shape("poly 1 2 3 4 5 6 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4, 5, 6));}
@Test public void Poly_pass_chars() {fxt.Test_shape("poly a b [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:uk.w:Стратосфера; DATE:2014-07-26
@Test public void Poly_pass_commas() {fxt.Test_shape("poly 1,2,3,4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4));} // PURPOSE: commas should be ignored; PAGE:de.w:Kaimnitz; DATE:2014-08-05
@Test public void Rect_fail() {fxt.Test_shape_err("rect 1 2 3 [[A]]" , "imagemap_missing_coord");}
@Test public void Circle_fail() {fxt.Test_shape_err("circle 1 2 [[A]]" , "imagemap_missing_coord");}
@Test public void Poly_fail_odd() {fxt.Test_shape_err("poly 1 2 3 [[A]]" , "imagemap_poly_odd");}
@ -66,12 +67,12 @@ class Imap_parser_fxt extends Imap_fxt_base {
parser = new Imap_parser(xtn_mgr);
parser.Init(wiki, url, Gfo_usr_dlg_.Null);
parser.Clear();
imap = new Imap_map();
imap = new Imap_map(1);
}
public void Test_shape(String raw_str, Imap_itm_shape expd) {
raw_str = "File:A.png\n" + raw_str;
byte[] raw = Bry_.new_utf8_(raw_str);
parser.Parse(imap, 1, raw, 0, raw.length);
parser.Parse(imap, raw, 0, raw.length);
Imap_itm_shape[] actl_ary = imap.Shapes();
Imap_itm_shape actl = actl_ary == null | actl_ary.length != 1 ? null : (Imap_itm_shape)actl_ary[0];
if (actl == null && expd == null) {} // noop; test passed
@ -88,7 +89,7 @@ class Imap_parser_fxt extends Imap_fxt_base {
public void Test_shape_err(String raw_str, String expd_err) {
raw_str = "File:A.png\n" + raw_str;
byte[] raw = Bry_.new_utf8_(raw_str);
parser.Parse(imap, 1, raw, 0, raw.length);
parser.Parse(imap, raw, 0, raw.length);
Imap_err[] err_ary = imap.Errs();
Tfds.Eq(1, err_ary.length, "expd 1 err");
Tfds.Eq(expd_err, err_ary[0].Err_key());

View File

@ -21,9 +21,11 @@ public class Imap_xnde implements Xox_xnde {
private Imap_xtn_mgr xtn_mgr;
private Imap_map imap_data;
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
xtn_mgr = (Imap_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Imap_xtn_mgr.Xtn_key_static);
xtn_mgr = wiki.Xtn_mgr().Xtn_imap();
xtn_mgr.Xtn_assert();
ctx.Cur_page().Html_data().Module_mgr().Itm_popups().Bind_hover_area_(true);
Xoa_page page = ctx.Cur_page();
page.Html_data().Module_mgr().Itm_popups().Bind_hover_area_(true);
page.Html_data().Xtn_imap_exists_y_();
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
imap_data = xtn_mgr.Parser().Parse(wiki, ctx, root, src, xnde);
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);

View File

@ -30,7 +30,7 @@ public class Imap_xnde_html_all_tst {
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:123px;\">"
, " <div class=\"noresize\">"
, " <div id='imap_div_0' class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " <area href=\"/wiki/B\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
, " <area href=\"/wiki/C\" shape=\"rect\" coords=\"0,0,4,8\" alt=\"c1\" title=\"c1\"/>"
@ -61,7 +61,7 @@ public class Imap_xnde_html_all_tst {
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:123px;\">"
, " <div class=\"noresize\">"
, " <div id='imap_div_0' class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <a href=\"/wiki/B\" title=\"b1\">"
@ -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:0px; width: 123px;\">"
( "<div id='imap_div_0' 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\"/>"
@ -109,7 +109,7 @@ public class Imap_xnde_html_all_tst {
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:123px;\">"
, " <div class=\"noresize\">"
, " <div id='imap_div_0' class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " <area href=\"http://b.org\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
, " </map>"
@ -153,7 +153,7 @@ public class Imap_xnde_html_all_tst {
( "<table>"
, " <tr>"
, " <td> z"
, "<div class=\"noresize\">"
, "<div id='imap_div_0' class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <img id=\"xowa_file_img_0\" alt=\"b\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>" // NOTE: width must be 123, not 0
@ -181,7 +181,7 @@ class Imap_xnde_html_fxt {
public void Test_html_full_frag(String raw, String expd) {fxt.Test_html_full_frag(raw, expd);}
public String Frag_html_full() {
return String_.Concat_lines_nl_skip_last
( "<div class=\"noresize\">"
( "<div id='imap_div_0' class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" usemap=\"#imageMap_1_1\"/>"

View File

@ -27,7 +27,7 @@ class Imap_html_bldr_fxt extends Imap_fxt_base {
private Bry_bfr bfr = Bry_bfr.new_();
private Imap_pts_fmtr_arg pts_fmtr_arg = new Imap_pts_fmtr_arg();
public void Test_shape_html(Imap_itm_shape shape, String expd) {
Imap_map.Fmt_shape(bfr, Imap_html_fmtrs.Area, pts_fmtr_arg, shape);
Imap_shapes_fmtr.Fmt_shape(bfr, Imap_html_fmtrs.Area, pts_fmtr_arg, shape);
Tfds.Eq(expd, bfr.XtoStrAndClear());
}
}

View File

@ -21,7 +21,7 @@ import gplx.core.btries.*;
public class Imap_xtn_mgr extends Xox_mgr_base implements GfoInvkAble {
private boolean init;
@Override public boolean Enabled_default() {return true;}
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_ascii_("imageMap");
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_ascii_("imageMap");
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
@gplx.Internal protected Imap_parser Parser() {return parser;} private Imap_parser parser;
public void Desc_assert() {

View File

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.insiders; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.pages.skins.*;
public class Insider_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_insider;}
@Override public Pf_func New(int id, byte[] name) {return new Insider_func().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] val = Eval_argx(ctx, src, caller, self);
Xopg_xtn_skin_mgr skin_mgr = ctx.Cur_page().Html_data().Xtn_skin_mgr();
Insider_xtn_skin_itm skin_itm = (Insider_xtn_skin_itm)skin_mgr.Get_or_null(Insider_xtn_skin_itm.KEY);
if (skin_itm == null) {
skin_itm = new Insider_xtn_skin_itm(ctx.Wiki().Xtn_mgr().Xtn_insider().Html_bldr());
skin_mgr.Add(skin_itm);
}
skin_itm.Add(val);
}
public static final Insider_func _ = new Insider_func(); Insider_func() {}
}

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.xtns.insiders; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Insider_func_tst {
@Before public void init() {fxt.Reset();} private Insider_func_fxt fxt = new Insider_func_fxt();
@Test public void Basic() {
fxt.Test_parse("{{#insider:A}}x{{#insider:B}}", "x", "A", "B");
}
}
class Insider_func_fxt {
private Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
}
public void Test_parse(String raw, String expd, String... insiders) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", expd);
Insider_xtn_skin_itm skin_itm = (Insider_xtn_skin_itm)fxt.Page().Html_data().Xtn_skin_mgr().Get_or_null(Insider_xtn_skin_itm.KEY);
ListAdp list = skin_itm.Itms();
byte[][] brys = (byte[][])list.XtoAry(byte[].class);
Tfds.Eq_ary_str(insiders, String_.Ary(brys));
}
}

View File

@ -0,0 +1,73 @@
/*
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.insiders; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.pages.skins.*;
class Insider_xtn_skin_itm implements Xopg_xtn_skin_itm {
private ListAdp itms = ListAdp_.new_();
private Insider_html_bldr html_bldr;
public Insider_xtn_skin_itm(Insider_html_bldr html_bldr) {this.html_bldr = html_bldr;}
public byte Tid() {return Xopg_xtn_skin_itm_tid.Tid_sidebar;}
public byte[] Key() {return KEY;} public static final byte[] KEY = Bry_.new_utf8_("Insider");
public ListAdp Itms() {return itms;}
public void Add(byte[] itm) {itms.Add(itm);}
public void Write(Bry_bfr bfr, Xoa_page page) {
html_bldr.Bld_all(bfr, page, itms);
}
}
public class Insider_html_bldr implements Bry_fmtr_arg {
private Insider_xtn_mgr xtn_mgr;
private Bry_bfr tmp_ttl = Bry_bfr.reset_(255);
private ListAdp list; private int list_len;
private Hash_adp_bry hash = Hash_adp_bry.cs_();
public Insider_html_bldr(Insider_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
public void Bld_all(Bry_bfr bfr, Xoa_page page, ListAdp list) {
this.list = list; this.list_len = list.Count();
hash.Clear();
fmtr_grp.Bld_bfr_many(bfr, xtn_mgr.Msg_sidebar_ttl(), xtn_mgr.Msg_about_page(), xtn_mgr.Msg_about_ttl(), this);
}
public void XferAry(Bry_bfr bfr, int idx) {
Xow_wiki wiki = xtn_mgr.Wiki();
Xoh_href_parser href_parser = wiki.App().Href_parser();
for (int i = 0; i < list_len; ++i) {
byte[] itm = (byte[])list.FetchAt(i);
Xoa_ttl user_ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_user, itm);
if (user_ttl == null) continue;
byte[] user_ttl_bry = user_ttl.Full_db();
if (hash.Has(user_ttl_bry)) continue;
hash.Add(user_ttl_bry, user_ttl_bry);
href_parser.Encoder().Encode(tmp_ttl, user_ttl_bry);
user_ttl_bry = tmp_ttl.XtoAryAndClear();
fmtr_itm.Bld_bfr(bfr, user_ttl_bry, itm);
}
}
private static final Bry_fmtr
fmtr_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div id='p-insiders' class='portal' role='navigation'>"
, " <h3>~{hdr}</h3>"
, " <div class='body'>"
, " <ul>~{itms}"
, " <li class='interwiki-insider'><a class='xowa-hover-off' href='/wiki/~{about_href}'>~{about_text}</a></li>"
, " </ul>"
, " </div>"
, "</div>"
), "hdr", "about_href", "about_text", "itms")
, fmtr_itm = Bry_fmtr.new_
( "\n <li class='interwiki-insider'><a class='xowa-hover-off' href='/wiki/~{href}'>~{name}</a></li>"
, "href", "name")
;
}

View File

@ -0,0 +1,62 @@
/*
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.insiders; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Insider_html_bldr_tst {
@Before public void init() {fxt.Clear();} private Insider_html_bldr_fxt fxt = new Insider_html_bldr_fxt();
@Test public void Basic() {
fxt.Init_insider("A");
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( "<div id='p-insiders' class='portal' role='navigation'>"
, " <h3>Docent</h3>"
, " <div class='body'>"
, " <ul>"
, " <li class='interwiki-insider'><a class='xowa-hover-off' href='/wiki/User:A'>A</a></li>"
, " <li class='interwiki-insider'><a class='xowa-hover-off' href='/wiki/Docent_page'>About Docents</a></li>"
, " </ul>"
, " </div>"
, "</div>"
));
}
}
class Insider_html_bldr_fxt {
private Xoa_app app; private Xow_wiki wiki; private Xoa_page page;
private Insider_xtn_mgr xtn_mgr;
private Insider_xtn_skin_itm skin_itm;
public void Clear() {
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
Xop_fxt.Init_msg(wiki, "insider-title", "Docent");
Xop_fxt.Init_msg(wiki, "insider-about", "About Docents");
Xop_fxt.Init_msg(wiki, "insider-about-page", "Docent_page");
this.xtn_mgr = wiki.Xtn_mgr().Xtn_insider();
xtn_mgr.Enabled_y_();
xtn_mgr.Xtn_init_by_wiki(wiki);
this.page = wiki.Ctx().Cur_page();
skin_itm = new Insider_xtn_skin_itm(xtn_mgr.Html_bldr());
page.Html_data().Xtn_skin_mgr().Add(skin_itm);
}
public void Init_insider(String lnki_ttl) {
skin_itm.Add(Bry_.new_utf8_(lnki_ttl));
}
public void Test_bld(String expd) {
Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
skin_itm.Write(tmp_bfr, page);
Tfds.Eq_str_lines(expd, tmp_bfr.XtoStrAndClear());
}
}

View File

@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.insiders; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.html.*; import gplx.xowa.wikis.*;
public class Insider_xtn_mgr extends Xox_mgr_base {
public Insider_xtn_mgr() {
html_bldr = new Insider_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_("Insider");
@Override public Xox_mgr Clone_new() {return new Insider_xtn_mgr();}
@Override public void Xtn_init_by_wiki(Xow_wiki wiki) {
this.wiki = wiki;
if (!Enabled()) return;
Xox_mgr_base.Xtn_load_i18n(wiki, XTN_KEY);
msg_sidebar_ttl = wiki.Msg_mgr().Val_by_key_obj("insider-title");
msg_about_ttl = wiki.Msg_mgr().Val_by_key_obj("insider-about");
msg_about_page = wiki.Msg_mgr().Val_by_key_obj("insider-about-page");
}
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
public Insider_html_bldr Html_bldr() {return html_bldr;} private Insider_html_bldr html_bldr;
public byte[] Msg_sidebar_ttl() {return msg_sidebar_ttl;} private byte[] msg_sidebar_ttl;
public byte[] Msg_about_ttl() {return msg_about_ttl;} private byte[] msg_about_ttl;
public byte[] Msg_about_page() {return msg_about_page;} private byte[] msg_about_page;
}

View File

@ -20,7 +20,7 @@ import gplx.html.*;
import gplx.xowa.wikis.*;
public class Listing_xtn_mgr extends Xox_mgr_base {
@Override public boolean Enabled_default() {return false;}
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_ascii_("listings");
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_ascii_("Listings");
@Override public Xox_mgr Clone_new() {return new Listing_xtn_mgr();}
@Override public void Xtn_init_by_wiki(Xow_wiki wiki) {
if (!Enabled()) return;

View File

@ -202,10 +202,11 @@ public class Pf_func_ {
, Xol_kwd_grp_.Id_mapSources_geoLink
, Xol_kwd_grp_.Id_geoCrumbs_isin
, Xol_kwd_grp_.Id_relatedArticles
, Xol_kwd_grp_.Id_relatedSites
, Xol_kwd_grp_.Id_insider
, Xol_kwd_grp_.Id_massMessage_target
, Xol_kwd_grp_.Id_cascadingSources
, Xol_kwd_grp_.Id_pendingChangesLevel
, Xol_kwd_grp_.Id_bang
};
public static Xot_defn Get_prototype(int id) {
switch (id) {
@ -355,13 +356,14 @@ public class Pf_func_ {
case Xol_kwd_grp_.Id_geoCrumbs_isin: return gplx.xowa.xtns.geoCrumbs.Geoc_isin_func._;
case Xol_kwd_grp_.Id_relatedArticles: return gplx.xowa.xtns.relatedArticles.Articles_func._;
case Xol_kwd_grp_.Id_relatedSites: return gplx.xowa.xtns.relatedSites.Sites_func._;
case Xol_kwd_grp_.Id_insider: return gplx.xowa.xtns.insiders.Insider_func._;
case Xol_kwd_grp_.Id_massMessage_target: return gplx.xowa.xtns.massMessage.Message_target_func._;
case Xol_kwd_grp_.Id_cascadingSources:
case Xol_kwd_grp_.Id_pendingChangesLevel:
return new Pf_func_noop(id);
case Xol_kwd_grp_.Id_bang: return Pf_func_bang._;
default: throw Err_mgr._.unhandled_(id);
}
}
@ -372,3 +374,10 @@ class Pf_func_noop extends Pf_func_base {
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {}
@Override public Pf_func New(int id, byte[] name) {return new Pf_func_noop(id).Name_(name);}
}
class Pf_func_bang extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_bang;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {bfr.Add_byte_pipe();}
@Override public Pf_func New(int id, byte[] name) {return this;}
public static final Pf_func_bang _ = new Pf_func_bang();
Pf_func_bang() {this.Name_(Byte_ascii.Bang_bry);}
}

View File

@ -36,13 +36,13 @@ class Pfunc_i18n_fxt {
return this;
} private Xoa_app app; private Xop_fxt fxt; Xol_lang lang; Xow_wiki wiki;
public Pfunc_i18n_fxt Reg_func(String name, boolean case_match, String word) {
Io_url url = Io_url_.mem_fil_("mem/xowa/user/test_user/lang/xowa/" + lang_key + ".gfs");
Io_url url = Io_url_.mem_fil_("mem/xowa/bin/any/xowa/cfg/lang/core/" + lang_key + ".gfs");
String func = "keywords.load_text('" + name + "|" + (case_match ? "1" : "0") + "|" + name + "~" + word + "~');";
Io_mgr._.SaveFilStr(url, func);
return this;
}
public Pfunc_i18n_fxt Reg_msg(String key, String val) {
Io_url url = Io_url_.mem_fil_("mem/xowa/user/test_user/lang/xowa/" + lang_key + ".gfs");
Io_url url = Io_url_.mem_fil_("mem/xowa/bin/any/xowa/cfg/lang/core/" + lang_key + ".gfs");
String func = "messages.load_text('" + key + "|" + val + "');";
Io_mgr._.SaveFilStr(url, func);
return this;

View File

@ -27,7 +27,7 @@ public class Pfunc_displaytitle extends Pf_func_base {
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
wiki.Html_mgr().Html_wtr().Write_tkn(tmp_bfr, new_ctx, gplx.xowa.html.Xoh_html_wtr_ctx.Display_title, new_root.Data_mid(), new_root, 0, new_root);
byte[] val_html = tmp_bfr.Mkr_rls().XtoAryAndClear();
ctx.Cur_page().Display_ttl_(val_html);
ctx.Cur_page().Html_data().Display_ttl_(val_html);
}
public static final Pfunc_displaytitle _ = new Pfunc_displaytitle(); Pfunc_displaytitle() {}
}

View File

@ -36,6 +36,6 @@ class Pfunc_displaytitle_fxt {
}
public void Test(String raw, String expd) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", "");
Tfds.Eq(expd, String_.new_utf8_(fxt.Page().Display_ttl()));
Tfds.Eq(expd, String_.new_utf8_(fxt.Page().Html_data().Display_ttl()));
}
}

View File

@ -16,26 +16,28 @@ 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.relatedArticles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*;
import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.html.*; import gplx.xowa.pages.skins.*; import gplx.xowa.xtns.pfuncs.*;
public class Articles_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_relatedArticles;}
@Override public Pf_func New(int id, byte[] name) {return new Articles_func().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] argx = this.Eval_argx(ctx, src, caller, self);
Articles_html_xtn_itm xtn_itm = (Articles_html_xtn_itm)ctx.Cur_page().Xtn_mgr().Get_or_null(Articles_html_xtn_itm.Const_key);
Articles_xtn_skin_itm xtn_itm = (Articles_xtn_skin_itm)ctx.Cur_page().Html_data().Xtn_skin_mgr().Get_or_null(Articles_xtn_skin_itm.KEY);
if (xtn_itm == null) {
xtn_itm = new Articles_html_xtn_itm();
xtn_itm.Init(ctx.Wiki(), ctx.Cur_page());
ctx.Cur_page().Xtn_mgr().Add(xtn_itm);
xtn_itm = new Articles_xtn_skin_itm();
ctx.Cur_page().Html_data().Xtn_skin_mgr().Add(xtn_itm);
}
Parse(xtn_itm, argx);
}
private void Parse(Articles_html_xtn_itm xtn_itm, byte[] argx) {
int pos = Bry_finder.Find_fwd(argx, Const_dlm); if (pos == Bry_finder.Not_found) return;
byte[] ttl = Bry_.Trim(Bry_.Mid(argx, 0, pos));
byte[] text = Bry_.Trim(Bry_.Mid(argx, pos + Const_dlm.length));
xtn_itm.Add(new Articles_itm(ttl, text));
private void Parse(Articles_xtn_skin_itm xtn_itm, byte[] argx) {
int pos = Bry_finder.Find_fwd(argx, Const_dlm);
if (pos == Bry_finder.Not_found) // && missing; argx is both ttl and text
xtn_itm.Add(new Articles_itm(argx, argx));
else { // && exists; split by &&
byte[] ttl = Bry_.Trim(Bry_.Mid(argx, 0, pos));
byte[] text = Bry_.Trim(Bry_.Mid(argx, pos + Const_dlm.length));
xtn_itm.Add(new Articles_itm(ttl, text));
}
}
public static final Articles_func _ = new Articles_func(); Articles_func() {}
private static final byte[] Const_dlm = new byte[] {Byte_ascii.Amp, Byte_ascii.Amp};
@ -59,15 +61,15 @@ class Articles_itm_fmtr implements Bry_fmtr_arg {
private static final Bry_fmtr fmtr = Bry_fmtr.new_("\n <li class=\"interwiki-relart\"><a href=\"/wiki/~{ttl}\">~{text}</a></li>", "ttl", "text");
public static final Articles_itm_fmtr _ = new Articles_itm_fmtr(); Articles_itm_fmtr() {}
}
class Articles_html_xtn_itm implements Xoh_xtn_itm {
private Xow_wiki wiki; private Xoa_page page;
class Articles_xtn_skin_itm implements Xopg_xtn_skin_itm {
private ListAdp itms = ListAdp_.new_();
public byte[] Key() {return Const_key;} public static final byte[] Const_key = Bry_.new_utf8_("related_articles");
public void Init(Xow_wiki wiki, Xoa_page page) {this.wiki = wiki; this.page = page;}
public byte Tid() {return Xopg_xtn_skin_itm_tid.Tid_sidebar;}
public byte[] Key() {return KEY;} public static final byte[] KEY = Bry_.new_utf8_("RelatedArticles");
public void Add(Articles_itm itm) {itms.Add(itm);}
public void Exec() {
public void Write(Bry_bfr bfr, Xoa_page page) {
Xow_wiki wiki = page.Wiki();
itms_fmtr.Init(wiki, itms);
html_fmtr.Bld_bfr_many(page.Html_data().Portal_div_xtn(), wiki.Msg_mgr().Val_by_key_obj("relatedarticles-title"), itms_fmtr);
html_fmtr.Bld_bfr_many(bfr, wiki.Msg_mgr().Val_by_key_obj("relatedarticles-title"), itms_fmtr);
}
private static final Articles_itm_fmtr itms_fmtr = Articles_itm_fmtr._;
private static final Bry_fmtr html_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last

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