diff --git a/100_core/src_110_primitive/gplx/Bry_.java b/100_core/src_110_primitive/gplx/Bry_.java index 912dd9441..b4dea0561 100644 --- a/100_core/src_110_primitive/gplx/Bry_.java +++ b/100_core/src_110_primitive/gplx/Bry_.java @@ -142,6 +142,14 @@ public class Bry_ { } return rv; } + public static boolean Ary_eq(byte[][] lhs, byte[][] rhs) { + int lhs_len = lhs.length; + int rhs_len = rhs.length; + if (lhs_len != rhs_len) return false; + for (int i = 0; i < lhs_len; ++i) + if (!Bry_.Eq(lhs[i], rhs[i])) return false; + return true; + } public static byte[] Repeat_space(int len) {return Repeat(Byte_ascii.Space, len);} public static byte[] Repeat(byte b, int len) { byte[] rv = new byte[len]; @@ -689,6 +697,7 @@ public class Bry_ { return Xto_int_or(ary, bgn, end_num, or); } public static float XtoFloatByPos(byte[] ary, int bgn, int end) {return Float_.parse_(String_.new_utf8_(ary, bgn, end));} + public static double Xto_double(byte[] bry) {return Double_.parse_(String_.new_utf8_(bry, 0, bry.length));} public static double XtoDoubleByPosOr(byte[] ary, int bgn, int end, double or) {return Double_.parseOr_(String_.new_utf8_(ary, bgn, end), or);} public static double XtoDoubleByPos(byte[] ary, int bgn, int end) {return Double_.parse_(String_.new_utf8_(ary, bgn, end));} public static DecimalAdp XtoDecimalByPos(byte[] ary, int bgn, int end) {return DecimalAdp_.parse_(String_.new_utf8_(ary, bgn, end));} @@ -1003,5 +1012,5 @@ public class Bry_ { public static byte Get_at_end(byte[] v) { int v_len = v.length; return v_len == 0 ? Byte_ascii.Nil : v[v_len - 1]; - } + } } diff --git a/100_core/src_110_primitive/gplx/Bry_fmtr.java b/100_core/src_110_primitive/gplx/Bry_fmtr.java index 6772fe29a..309043dc3 100644 --- a/100_core/src_110_primitive/gplx/Bry_fmtr.java +++ b/100_core/src_110_primitive/gplx/Bry_fmtr.java @@ -232,6 +232,7 @@ public class Bry_fmtr { public static final Bry_fmtr Null = new Bry_fmtr().Fmt_(""); public static Bry_fmtr tmp_() {return new Bry_fmtr().Fmt_("").Keys_();} public static Bry_fmtr new_(String fmt, String... keys) {return new Bry_fmtr().Fmt_(fmt).Keys_(keys);} // NOTE: keys may seem redundant, but are needed to align ordinals with proc; EX: fmt may be "~{A} ~{B}" or "~{B} ~{A}"; call will always be Bld(a, b); passing in "A", "B" guarantees A is 0 and B is 1; + public static Bry_fmtr new_(byte[] fmt, String... keys) {return new Bry_fmtr().Fmt_(fmt).Keys_(keys);} // NOTE: keys may seem redundant, but are needed to align ordinals with proc; EX: fmt may be "~{A} ~{B}" or "~{B} ~{A}"; call will always be Bld(a, b); passing in "A", "B" guarantees A is 0 and B is 1; public static Bry_fmtr new_() {return new Bry_fmtr();} public static Bry_fmtr keys_(String... keys) {return new Bry_fmtr().Keys_(keys);} public static Bry_fmtr new_bry_(byte[] fmt, String... keys) {return new Bry_fmtr().Fmt_(fmt).Keys_(keys);} diff --git a/100_core/src_311_gfoObj/gplx/GfoMsg.java b/100_core/src_311_gfoObj/gplx/GfoMsg.java index 8263bf1f9..540e781b8 100644 --- a/100_core/src_311_gfoObj/gplx/GfoMsg.java +++ b/100_core/src_311_gfoObj/gplx/GfoMsg.java @@ -64,6 +64,7 @@ public interface GfoMsg { Object ReadObjOr(String k, ParseAble parseAble, Object or); String[]ReadStrAry(String k, String spr); String[]ReadStrAryIgnore(String k, String spr, String ignore); + byte[][]ReadBryAry(String k, byte spr); Object ReadValAt(int i); Object CastObj(String k); Object CastObjOr(String k, Object or); diff --git a/100_core/src_311_gfoObj/gplx/GfoMsg_.java b/100_core/src_311_gfoObj/gplx/GfoMsg_.java index 7cdc3d79e..a74cb9e1c 100644 --- a/100_core/src_311_gfoObj/gplx/GfoMsg_.java +++ b/100_core/src_311_gfoObj/gplx/GfoMsg_.java @@ -169,6 +169,7 @@ class GfoMsg_base implements GfoMsg { public Object ReadObj(String k, ParseAble parseAble) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? parseAble.ParseAsObj((String)rv) : rv;} public Object ReadObjOr(String k, ParseAble parseAble, Object or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? parseAble.ParseAsObj((String)rv) : rv;} public String[] ReadStrAry(String k, String spr) {return String_.Split(ReadStr(k), spr);} + public byte[][] ReadBryAry(String k, byte spr) {return Bry_.Split(ReadBry(k), spr);} public String[] ReadStrAryIgnore(String k, String spr, String ignore) {return String_.Split(String_.Replace(ReadStr(k), ignore, ""), spr);} public Object ReadValAt(int i) {return Args_getAt(i).Val();} @gplx.Virtual protected Object ReadOr(String k, Object defaultOr) { diff --git a/150_gfui/lib/swt.jar b/150_gfui/lib/swt.jar index d492795b3..a7deaa8ba 100644 Binary files a/150_gfui/lib/swt.jar and b/150_gfui/lib/swt.jar differ diff --git a/400_xowa/.classpath b/400_xowa/.classpath index e468907d8..008e709d5 100644 --- a/400_xowa/.classpath +++ b/400_xowa/.classpath @@ -30,6 +30,6 @@ - + diff --git a/400_xowa/lib/jtidy_xowa.jar b/400_xowa/lib/jtidy_xowa.jar new file mode 100644 index 000000000..9dfc67948 Binary files /dev/null and b/400_xowa/lib/jtidy_xowa.jar differ diff --git a/400_xowa/src/gplx/xowa/Xoa_app.java b/400_xowa/src/gplx/xowa/Xoa_app.java index 1642b8257..a82f5eefc 100644 --- a/400_xowa/src/gplx/xowa/Xoa_app.java +++ b/400_xowa/src/gplx/xowa/Xoa_app.java @@ -74,6 +74,7 @@ public class Xoa_app implements GfoInvkAble { setup_mgr.Init_by_app(this); thread_mgr.Usr_dlg_(usr_dlg); html_mgr.Init_by_app(this); + api_root.Init_by_app(this); } public boolean Launch_done() {return stage == Xoa_stage_.Tid_launch;} public void Launch() { @@ -81,6 +82,7 @@ public class Xoa_app implements GfoInvkAble { stage = Xoa_stage_.Tid_launch; user.Cfg_mgr().Setup_mgr().Setup_run_check(this); log_bfr.Add("app.upgrade.done"); gplx.xowa.users.prefs.Prefs_converter._.Check(this); + user.Wiki().Init_assert(); // NOTE: must assert wiki and load langs first, else will be asserted during Portal_mgr().Init(), which will cause IndexOutOfBounds; DATE:2014-10-04 } public byte Stage() {return stage;} public Xoa_app Stage_(byte v) {stage = v; return this;} private byte stage = Xoa_stage_.Tid_ctor; public boolean Term_cbk() { diff --git a/400_xowa/src/gplx/xowa/Xoa_app_.java b/400_xowa/src/gplx/xowa/Xoa_app_.java index a1a77483e..681857542 100644 --- a/400_xowa/src/gplx/xowa/Xoa_app_.java +++ b/400_xowa/src/gplx/xowa/Xoa_app_.java @@ -24,7 +24,7 @@ public class Xoa_app_ { boot_mgr.Run(args); } public static final String Name = "xowa"; - public static final String Version = "1.9.5.1"; + public static final String Version = "1.10.1.1"; public static String Build_date = "2012-12-30 00:00:00"; public static String Op_sys; public static String User_agent = ""; diff --git a/400_xowa/src/gplx/xowa/apis/Xoapi_root.java b/400_xowa/src/gplx/xowa/apis/Xoapi_root.java index 208a7b202..8f8dfb508 100644 --- a/400_xowa/src/gplx/xowa/apis/Xoapi_root.java +++ b/400_xowa/src/gplx/xowa/apis/Xoapi_root.java @@ -30,6 +30,10 @@ public class Xoapi_root implements GfoInvkAble { usr_api.Init_by_kit(app); xtns_api.Init_by_kit(app); } + public void Init_by_app(Xoa_app app) { + Io_url img_dir = app.User().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "portal"); + html_api.Page().Toggle_mgr().Img_dir_(img_dir); + } public Xoapi_app App() {return app_api;} private Xoapi_app app_api = new Xoapi_app(); public Xoapi_nav Nav() {return nav;} private Xoapi_nav nav = new Xoapi_nav(); public Xoapi_gui Gui() {return gui_api;} private Xoapi_gui gui_api = new Xoapi_gui(); diff --git a/400_xowa/src/gplx/xowa/apis/xowa/Xoapi_xtns.java b/400_xowa/src/gplx/xowa/apis/xowa/Xoapi_xtns.java index 728115b74..8b60eb822 100644 --- a/400_xowa/src/gplx/xowa/apis/xowa/Xoapi_xtns.java +++ b/400_xowa/src/gplx/xowa/apis/xowa/Xoapi_xtns.java @@ -21,12 +21,15 @@ public class Xoapi_xtns implements GfoInvkAble { public void Init_by_kit(Xoa_app app) { scribunto.Init_by_kit(app); } - public Xoapi_scribunto Scribunto() {return scribunto;} private Xoapi_scribunto scribunto = new Xoapi_scribunto(); + public Xoapi_scribunto Scribunto() {return scribunto;} private final Xoapi_scribunto scribunto = new Xoapi_scribunto(); + public Xoapi_wikibase Wikibase() {return wikibase;} private final Xoapi_wikibase wikibase = new Xoapi_wikibase(); public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { if (ctx.Match(k, Invk_scribunto)) return scribunto; + else if (ctx.Match(k, Invk_wikibase)) return wikibase; else return GfoInvkAble_.Rv_unhandled; } private static final String Invk_scribunto = "scribunto" + , Invk_wikibase = "wikibase" ; } diff --git a/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_itm.java b/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_itm.java index 2770b4488..e8b33a530 100644 --- a/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_itm.java +++ b/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_itm.java @@ -19,9 +19,10 @@ package gplx.xowa.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx public class Xoapi_toggle_itm implements GfoInvkAble { public Xoapi_toggle_itm(byte[] key_bry) {this.key_bry = key_bry;} public byte[] Key_bry() {return key_bry;} private byte[] key_bry; - public byte[] Icon_src() {return icon_src;} private byte[] icon_src; - public byte[] Icon_title() {return icon_title;} private byte[] icon_title; - public byte[] Elem_display() {return elem_display;} private byte[] elem_display; + public byte[] Icon_src() {return icon_src;} private byte[] icon_src = Bry_.Empty; + public byte[] Icon_title() {return icon_title;} private byte[] icon_title = Bry_.Empty; + public byte[] Elem_display() {return elem_display;} private byte[] elem_display = Bry_.Empty; + public byte[] Html_toggle_hdr_cls() {return html_toggle_hdr_cls;} public Xoapi_toggle_itm Html_toggle_hdr_cls_(byte[] v) {html_toggle_hdr_cls = v; return this;} private byte[] html_toggle_hdr_cls = Bry_.Empty; public boolean Visible() {return visible;} private boolean visible; public Xoapi_toggle_itm Init(Xow_wiki wiki) { if (Img_src_y == null) { @@ -33,18 +34,55 @@ public class Xoapi_toggle_itm implements GfoInvkAble { byte[] img_title_msg = visible ? Img_title_msg_y : Img_title_msg_n; icon_title = wiki.Msg_mgr().Val_by_key_obj(img_title_msg); elem_display = visible ? Img_display_y : Img_display_n; + Html_toggle_gen(); return this; } - private static byte[] Img_src_y, Img_src_n; - private static final byte[] - Img_title_msg_y = Bry_.new_ascii_("hide"), Img_title_msg_n = Bry_.new_ascii_("show") - , Img_display_y = Bry_.new_ascii_("display:;"), Img_display_n = Bry_.new_ascii_("display:none;") - ; + private byte[] img_title_val_y, img_title_val_n; + public Xoapi_toggle_itm Init_fsys(Io_url img_dir) { + if (Img_src_y == null) { + Img_src_y = img_dir.GenSubFil("twisty_down.png").To_http_file_bry(); + Img_src_n = img_dir.GenSubFil("twisty_right.png").To_http_file_bry(); + } + return this; + } + public void Init_msgs(byte[] img_title_val_y, byte[] img_title_val_n) { + this.img_title_val_y = img_title_val_y; + this.img_title_val_n = img_title_val_n; + Html_toggle_gen(); + } + public byte[] Html_toggle_btn() {return html_toggle_btn;} private byte[] html_toggle_btn; + public byte[] Html_toggle_hdr() {return html_toggle_hdr;} private byte[] html_toggle_hdr; + private void Html_toggle_gen() { + if (visible) { + icon_src = Img_src_y; + icon_title = img_title_val_y; + elem_display = Img_display_y; + } + else { + icon_src = Img_src_n; + icon_title = img_title_val_n; + elem_display = Img_display_n; + } + Bry_fmtr fmtr = Bry_fmtr.new_(); Bry_bfr bfr = Bry_bfr.new_(8); + html_toggle_btn + = fmtr.Fmt_("") + .Keys_("key", "src", "title").Bld_bry_many(bfr, key_bry, icon_src, icon_title) + ; + html_toggle_hdr + = fmtr.Fmt_(" id='~{key}-toggle-elem' style='~{display}~{toggle_hdr_cls}'") + .Keys_("key", "display", "toggle_hdr_cls").Bld_bry_many(bfr, key_bry, elem_display, html_toggle_hdr_cls) + ; + } public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { if (ctx.Match(k, Invk_visible)) return Yn.Xto_str(visible); - else if (ctx.Match(k, Invk_visible_)) visible = m.ReadYn("v"); + else if (ctx.Match(k, Invk_visible_)) {this.visible = m.ReadYn("v"); Html_toggle_gen();} else return GfoInvkAble_.Rv_unhandled; return this; } private static final String Invk_visible = "visible", Invk_visible_ = "visible_"; + private static byte[] Img_src_y, Img_src_n; // assume these are the same for all itms + private static final byte[] + Img_title_msg_y = Bry_.new_ascii_("hide"), Img_title_msg_n = Bry_.new_ascii_("show") + , Img_display_y = Bry_.new_ascii_("display:;"), Img_display_n = Bry_.new_ascii_("display:none;") + ; } diff --git a/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_mgr.java b/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_mgr.java index b4d078e6b..7b15b7d65 100644 --- a/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_mgr.java +++ b/400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_toggle_mgr.java @@ -18,34 +18,33 @@ along with this program. If not, see . package gplx.xowa.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.cfgs.*; public class Xoapi_toggle_mgr implements GfoInvkAble { - private Hash_adp_bry itms = Hash_adp_bry.cs_(); - public Xoapi_toggle_mgr() { - itm_wikidata_langs = itms_add(itms, Key_wikidata_langs); - itm_offline_wikis = itms_add(itms, Key_offline_wikis); - } - public Xoapi_toggle_itm Itm_wikidata_langs() {return itm_wikidata_langs;} private Xoapi_toggle_itm itm_wikidata_langs; - public Xoapi_toggle_itm Itm_offline_wikis() {return itm_offline_wikis;} private Xoapi_toggle_itm itm_offline_wikis; - public Xoapi_toggle_itm Get(byte[] key) {return (Xoapi_toggle_itm)itms.Get_by_bry(key);} - public void Save(Xoa_cfg_mgr cfg_mgr) { - Save_itm(cfg_mgr, itm_wikidata_langs, itm_offline_wikis); - } - public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { - if (ctx.Match(k, Invk_get)) return this.Get(m.ReadBry("key")); - else return GfoInvkAble_.Rv_unhandled; - } - private static final String Invk_get = "get"; - private static final String Key_wikidata_langs = "wikidata-langs", Key_offline_wikis = "offline-wikis"; - private static Xoapi_toggle_itm itms_add(Hash_adp_bry itms, String name_str) { - byte[] name_bry = Bry_.new_utf8_(name_str); - Xoapi_toggle_itm rv = new Xoapi_toggle_itm(name_bry); - itms.Add(name_bry, rv); + private OrderedHash hash = OrderedHash_.new_bry_(); + public Xoapi_toggle_itm Get_or_new(String key_str) { + byte[] key_bry = Bry_.new_utf8_(key_str); + Xoapi_toggle_itm rv = (Xoapi_toggle_itm)hash.Fetch(key_bry); + if (rv == null) { + rv = new Xoapi_toggle_itm(key_bry); + hash.Add(key_bry, rv); + } return rv; } - private static void Save_itm(Xoa_cfg_mgr cfg_mgr, Xoapi_toggle_itm... itms) { - int itms_len = itms.length; - for (int i = 0; i < itms_len; ++i) { - Xoapi_toggle_itm itm = itms[i]; + public void Img_dir_(Io_url v) { + int len = hash.Count(); + for (int i = 0; i < len; ++i) { + Xoapi_toggle_itm itm = (Xoapi_toggle_itm)hash.FetchAt(i); + itm.Init_fsys(v); + } + } + public void Save(Xoa_cfg_mgr cfg_mgr) { + int len = hash.Count(); + for (int i = 0; i < len; ++i) { + Xoapi_toggle_itm itm = (Xoapi_toggle_itm)hash.FetchAt(i); cfg_mgr.Set_by_app("xowa.api.html.page.toggles.get('" + String_.new_utf8_(itm.Key_bry()) + "').visible", Yn.Xto_str(itm.Visible())); } } + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Invk_get)) return this.Get_or_new(m.ReadStr("key")); + else return GfoInvkAble_.Rv_unhandled; + } + private static final String Invk_get = "get"; } diff --git a/400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_popups.java b/400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_popups.java index d9f7d21f4..e31ba585e 100644 --- a/400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_popups.java +++ b/400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_popups.java @@ -184,7 +184,7 @@ public class Xoapi_popups implements GfoInvkAble, GfoEvMgrOwner { ; public static final byte[] Dflt_xnde_ignore_ids = Bry_.new_ascii_("coordinates") - , Dflt_tmpl_keeplist = Bry_.new_ascii_("en.wikipedia.org|formatnum;age;age_in_days;age_in_years_and_days*;nts;number_table_sorting*;as_of;gregorian_serial_date;currentminute;currentsecond;dmca;spaced_ndash;trim;month*;convert*;worldpop*;ipa*;lang*;nowrap*;h:*;mvar;math;vgy;audio;iso_639_name;transl;translate;linktext;zh;nihongo*;japanese_name;ko-hhrm|\n") + , Dflt_tmpl_keeplist = Bry_.new_ascii_("en.wikipedia.org|formatnum;age;age_in_days;age_in_years_and_days*;nts;number_table_sorting*;as_of;oldstyledatedy;gregorian_serial_date;currentminute;currentsecond;dmca;spaced_ndash;trim;month*;convert*;worldpop*;ipa*;lang*;nowrap*;h:*;mvar;math;vgy;audio;iso_639_name;transl;translate;linktext;zh;nihongo*;japanese_name;ko-hhrm|\n") , Dflt_html_fmtr_popup = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last ( "
" , "
~{content}" diff --git a/400_xowa/src/gplx/xowa/apis/xowa/xtns/Xoapi_wikibase.java b/400_xowa/src/gplx/xowa/apis/xowa/xtns/Xoapi_wikibase.java new file mode 100644 index 000000000..784bd5e5e --- /dev/null +++ b/400_xowa/src/gplx/xowa/apis/xowa/xtns/Xoapi_wikibase.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.apis.xowa.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; +import gplx.xowa.xtns.wdatas.*; +public class Xoapi_wikibase implements GfoInvkAble, GfoEvMgrOwner { + public Xoapi_wikibase() { + evMgr = GfoEvMgr.new_(this); + } + public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr; + public byte[][] Core_langs() {return core_langs;} private byte[][] core_langs = Bry_.Ary("en"); + public byte[][] Sort_langs() {return sort_langs;} private byte[][] sort_langs = Bry_.Ary("en", "de", "es", "fr", "it", "nl", "pl", "ru", "sv"); + public byte[] Link_wikis() {return link_wikis;} private byte[] link_wikis = Bry_.new_ascii_("enwiki"); + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Invk_core_langs)) return Bry_.Add_w_dlm(Byte_ascii.Semic, core_langs); + else if (ctx.Match(k, Invk_core_langs_)) {core_langs = m.ReadBryAry(k, Byte_ascii.Semic); GfoEvMgr_.PubVal(this, Evt_core_langs_changed, core_langs);} + else if (ctx.Match(k, Invk_sort_langs)) return Bry_.Add_w_dlm(Byte_ascii.Semic, sort_langs); + else if (ctx.Match(k, Invk_sort_langs_)) {sort_langs = m.ReadBryAry(k, Byte_ascii.Semic); GfoEvMgr_.PubVal(this, Evt_sort_langs_changed, sort_langs);} + else if (ctx.Match(k, Invk_link_wikis)) return String_.new_utf8_(link_wikis); + else if (ctx.Match(k, Invk_link_wikis_)) {link_wikis = m.ReadBry(k); GfoEvMgr_.PubVal(this, Evt_link_wikis_changed, link_wikis);} + else return GfoInvkAble_.Rv_unhandled; + return this; + } + private static final String + Invk_core_langs = "core_langs", Invk_core_langs_ = "core_langs_" + , Invk_sort_langs = "sort_langs", Invk_sort_langs_ = "sort_langs_" + , Invk_link_wikis = "link_wikis", Invk_link_wikis_ = "link_wikis_" + ; + public static final String + Evt_core_langs_changed = "core_langs_changed" + , Evt_link_wikis_changed = "link_wikis_changed" + , Evt_sort_langs_changed = "sort_langs_changed" + ; +} diff --git a/400_xowa/src/gplx/xowa/bldrs/imports/Xobc_core_batch.java b/400_xowa/src/gplx/xowa/bldrs/imports/Xobc_core_batch.java index 889fb750e..b6ad91b0d 100644 --- a/400_xowa/src/gplx/xowa/bldrs/imports/Xobc_core_batch.java +++ b/400_xowa/src/gplx/xowa/bldrs/imports/Xobc_core_batch.java @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import gplx.xowa.wikis.*; public class Xobc_core_batch implements GfoInvkAble { public Xobc_core_batch(Xob_bldr bldr, byte[] raw) {this.bldr = bldr; fmtr.Fmt_(raw);} private Xob_bldr bldr; Bry_fmtr fmtr = Bry_fmtr.keys_("bz2_fil", "wiki_key"); @@ -23,7 +24,7 @@ public class Xobc_core_batch implements GfoInvkAble { Io_url[] bz2_fils = Io_mgr._.QueryDir_fils(bldr.App().Fsys_mgr().Wiki_dir().GenSubDir_nest(Dir_dump, "todo")); Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_kb); int bz2_fils_len = bz2_fils.length; - Xob_bz2_file bz2_fil = new Xob_bz2_file(); + Xow_wiki_alias bz2_fil = new Xow_wiki_alias(); for (int i = 0; i < bz2_fils_len; i++) { Io_url bz2_fil_url = bz2_fils[i]; bz2_fil.Fil_(bz2_fil_url).Parse(bz2_fil_url.NameOnly()); diff --git a/400_xowa/src/gplx/xowa/cfgs/Xoa_cfg_grp_tid.java b/400_xowa/src/gplx/xowa/cfgs/Xoa_cfg_grp_tid.java index 7951ba712..9bfe59bd1 100644 --- a/400_xowa/src/gplx/xowa/cfgs/Xoa_cfg_grp_tid.java +++ b/400_xowa/src/gplx/xowa/cfgs/Xoa_cfg_grp_tid.java @@ -32,11 +32,11 @@ public class Xoa_cfg_grp_tid { else if (Bry_.Eq(key, Key_app_bry)) rv.tid = Tid_app; else { Xow_wiki_domain wiki_type = Xow_wiki_domain_.parse_by_domain(key); - if (wiki_type.Tid() == Xow_wiki_domain_.Tid_other) + if (wiki_type.Wiki_tid() == Xow_wiki_domain_.Tid_other) rv.tid = Tid_wiki; else { rv.tid = Tid_type; - rv.wiki_tid = wiki_type.Tid(); + rv.wiki_tid = wiki_type.Wiki_tid(); } } rv.key = key; diff --git a/400_xowa/src/gplx/xowa/gui/Xoa_gui_mgr.java b/400_xowa/src/gplx/xowa/gui/Xoa_gui_mgr.java index bb9daf29c..2ca5131cc 100644 --- a/400_xowa/src/gplx/xowa/gui/Xoa_gui_mgr.java +++ b/400_xowa/src/gplx/xowa/gui/Xoa_gui_mgr.java @@ -16,10 +16,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.gui; import gplx.*; import gplx.xowa.*; -import gplx.gfui.*; import gplx.xowa.specials.search.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.cmds.*; import gplx.xowa.cfgs.gui.*; +import gplx.gfui.*; import gplx.xowa.specials.search.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.cmds.*; import gplx.xowa.cfgs.gui.*; import gplx.xowa.users.*; import gplx.xowa.gui.bnds.*; import gplx.xowa.gui.views.*; import gplx.xowa.gui.urls.url_macros.*; -public class Xoa_gui_mgr implements GfoInvkAble { +public class Xoa_gui_mgr implements GfoEvObj, GfoInvkAble { public Xoa_gui_mgr(Xoa_app app) { + evMgr = GfoEvMgr.new_(this); this.app = app; browser_win = new Xog_win_itm(app, this); bnd_mgr = new Xog_bnd_mgr(browser_win); @@ -28,6 +29,7 @@ public class Xoa_gui_mgr implements GfoInvkAble { menu_mgr = new Xog_menu_mgr(this); search_suggest_mgr = new Xog_search_suggest_mgr(this); } + public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr; public Xoa_app App() {return app;} private Xoa_app app; public Xog_win_itm Browser_win() {return browser_win;} private Xog_win_itm browser_win; public IptCfgRegy Ipt_cfgs() {return ipt_cfgs;} IptCfgRegy ipt_cfgs = new IptCfgRegy(); @@ -66,28 +68,31 @@ public class Xoa_gui_mgr implements GfoInvkAble { menu_mgr.Menu_bldr().Init_by_kit(app, kit, app.User().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "menu")); menu_mgr.Init_by_kit(); bnd_mgr.Init_by_kit(app); + app.User().Wiki().Html_mgr().Init_by_kit(); + GfoEvMgr_.SubSame_many(app.User(), this, Xou_user.Evt_lang_changed); + app.Sys_cfg().Lang_(app.Sys_cfg().Lang()); // NOTE: force refresh of lang. must occur after after gui_mgr init, else menu lbls will break } public void Lang_changed(Xol_lang lang) { menu_mgr.Lang_changed(lang); browser_win.Lang_changed(lang); } public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { - if (ctx.Match(k, Invk_kit)) return kit; - else if (ctx.Match(k, Invk_kit_)) this.kit = Gfui_kit_.Get_by_key(m.ReadStrOr("v", Gfui_kit_.Swt().Key())); - else if (ctx.Match(k, Invk_run)) Run(); - else if (ctx.Match(k, Invk_browser_type)) kit.Cfg_set("HtmlBox", "BrowserType", gplx.gfui.Swt_kit.Cfg_Html_BrowserType_parse(m.ReadStr("v"))); - else if (ctx.Match(k, Invk_xul_runner_path_)) kit.Cfg_set("HtmlBox", "XulRunnerPath", Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("v")).Xto_api()); - else if (ctx.Match(k, Invk_bnds)) return bnd_mgr; - else if (ctx.Match(k, Invk_bindings)) return ipt_cfgs; - else if (ctx.MatchIn(k, Invk_main_win, Invk_browser_win)) - return browser_win; - else if (ctx.Match(k, Invk_win_opts)) return win_cfg; - else if (ctx.Match(k, Invk_layout)) return layout; - else if (ctx.Match(k, Invk_html)) return html_mgr; - else if (ctx.Match(k, Invk_search_suggest)) return search_suggest_mgr; - else if (ctx.Match(k, Invk_menus)) return menu_mgr; - else if (ctx.Match(k, Invk_cmds)) return cmd_mgr; - else if (ctx.Match(k, Invk_url_macros)) return url_macro_mgr; + if (ctx.Match(k, Invk_kit)) return kit; + else if (ctx.Match(k, Invk_kit_)) this.kit = Gfui_kit_.Get_by_key(m.ReadStrOr("v", Gfui_kit_.Swt().Key())); + else if (ctx.Match(k, Invk_run)) Run(); + else if (ctx.Match(k, Invk_browser_type)) kit.Cfg_set("HtmlBox", "BrowserType", gplx.gfui.Swt_kit.Cfg_Html_BrowserType_parse(m.ReadStr("v"))); + else if (ctx.Match(k, Invk_xul_runner_path_)) kit.Cfg_set("HtmlBox", "XulRunnerPath", Bry_fmtr_eval_mgr_.Eval_url(app.Url_cmd_eval(), m.ReadBry("v")).Xto_api()); + else if (ctx.Match(k, Invk_bnds)) return bnd_mgr; + else if (ctx.Match(k, Invk_bindings)) return ipt_cfgs; + else if (ctx.MatchIn(k, Invk_main_win, Invk_browser_win)) return browser_win; + else if (ctx.Match(k, Invk_win_opts)) return win_cfg; + else if (ctx.Match(k, Invk_layout)) return layout; + else if (ctx.Match(k, Invk_html)) return html_mgr; + else if (ctx.Match(k, Invk_search_suggest)) return search_suggest_mgr; + else if (ctx.Match(k, Invk_menus)) return menu_mgr; + else if (ctx.Match(k, Invk_cmds)) return cmd_mgr; + else if (ctx.Match(k, Invk_url_macros)) return url_macro_mgr; + else if (ctx.Match(k, Xou_user.Evt_lang_changed)) Lang_changed((Xol_lang)m.ReadObj("v", ParseAble_.Null)); else throw Err_mgr._.unhandled_(k); return this; } diff --git a/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java b/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java index 89473720f..a3f888895 100644 --- a/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java +++ b/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java @@ -57,24 +57,26 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg { return; } DateAdp page_modified_on_dte = page.Revision_data().Modified_on(); + Xoa_ttl page_ttl = page.Ttl(); int page_ns_id = page_ttl.Ns().Id(); + byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), page_ns_id, page_ttl.Page_db()); byte[] page_modified_on_msg = wiki.Msg_mgr().Val_by_id_args(Xol_msg_itm_.Id_portal_lastmodified, page_modified_on_dte.XtoStr_fmt_yyyy_MM_dd(), page_modified_on_dte.XtoStr_fmt_HHmm()); - byte[] page_body_class = Xoh_page_body_cls.Calc(tmp_bfr, page.Ttl()); + byte[] page_body_class = Xoh_page_body_cls.Calc(tmp_bfr, page_ttl, page_tid); byte[] html_content_editable = wiki.Gui_mgr().Cfg_browser().Content_editable() ? Content_editable_bry : Bry_.Empty; 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_wikidata_bry = Wdata_wiki_mgr.Wiki_page_is_json(wiki.Domain_tid(), page_ns_id) ? app.User().Lang().Fragment_mgr().Html_js_wikidata() : Bry_.Empty; byte[] js_edit_toolbar_bry = view_tid == Xopg_view_mode.Tid_edit ? wiki.Fragment_mgr().Html_js_edit_toolbar() : Bry_.Empty; 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 (). always pass in null - , Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page.Ttl(), page.Html_data().Display_ttl()) + , Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null) // NOTE: page_name does not show display_title (). always pass in null + , Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl()) , page_content_sub , wiki.Html_mgr().Portal_mgr().Div_jump_to() , page_data, wtr_page_lang, page_modified_on_msg, page.Lang().Dir_bry() , mgr.Css_common_bry(), mgr.Css_wiki_bry(), page_body_class, 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().Xtn_search_text()) + , 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()) + , mgr.Edit_rename_div_bry(page_ttl) , page.Html_data().Edit_preview_w_dbg() , Xoa_app_.Version, Xoa_app_.Build_date , app.Fsys_mgr().Root_dir().To_http_file_bry() @@ -87,28 +89,28 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg { public void XferAry(Bry_bfr bfr, int idx) {Write_body(bfr, Xoh_wtr_ctx.Basic, page);} public void Write_body(Bry_bfr bfr, Xoh_wtr_ctx hctx, Xoa_page page) { Xow_wiki wiki = page.Wiki(); Xoa_app app = wiki.App(); - int ns_id = page.Ttl().Ns().Id(); + Xoa_ttl page_ttl = page.Ttl(); int page_ns_id = page_ttl.Ns().Id(); + byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), page_ns_id, page_ttl.Page_db()); // NOTE: can't cache page_tid b/c Write_body is called directly; DATE:2014-10-02 byte[] data_raw = page.Data_raw(); - byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns_id, page.Ttl().Page_db()); boolean page_tid_uses_pre = false; int bfr_page_bgn = bfr.Len(); if (page_mode == Xopg_view_mode.Tid_edit) - Write_body_edit(bfr, data_raw, ns_id, page_tid); + Write_body_edit(bfr, data_raw, page_ns_id, page_tid); else { switch (page_tid) { case Xow_page_tid.Tid_js: case Xow_page_tid.Tid_css: case Xow_page_tid.Tid_lua: Write_body_pre (bfr, app, wiki, data_raw, tmp_bfr); page_tid_uses_pre = true; break; - case Xow_page_tid.Tid_wikitext: Write_body_wikitext (bfr, app, wiki, data_raw, hctx, page, ns_id); break; - case Xow_page_tid.Tid_json: app.Wiki_mgr().Wdata_mgr().Write_json_as_html(bfr, data_raw); break; + case Xow_page_tid.Tid_wikitext: Write_body_wikitext (bfr, app, wiki, data_raw, hctx, page, page_tid, page_ns_id); break; + case Xow_page_tid.Tid_json: app.Wiki_mgr().Wdata_mgr().Write_json_as_html(bfr, page_ttl.Page_db(), data_raw); break; } } if ( wiki.Domain_tid() != Xow_wiki_domain_.Tid_home // allow home wiki to use javascript && !page_tid_uses_pre) { // if .js, .css or .lua, skip test; may have js fragments, but entire text is escaped and put in pre; don't show spurious warning; DATE:2013-11-21 - app.Html_mgr().Js_cleaner().Clean_bfr(wiki, page.Ttl(), bfr, bfr_page_bgn); + app.Html_mgr().Js_cleaner().Clean_bfr(wiki, page_ttl, bfr, bfr_page_bgn); } } - private void Write_body_wikitext(Bry_bfr bfr, Xoa_app app, Xow_wiki wiki, byte[] data_raw, Xoh_wtr_ctx hctx, Xoa_page page, int ns_id) { + private void Write_body_wikitext(Bry_bfr bfr, Xoa_app app, Xow_wiki wiki, byte[] data_raw, Xoh_wtr_ctx hctx, Xoa_page page, byte page_tid, int ns_id) { byte[] hdump_data = page.Hdump_data().Body(); if (Bry_.Len_gt_0(hdump_data)) { bfr.Add(hdump_data); diff --git a/400_xowa/src/gplx/xowa/html/Xow_html_mgr.java b/400_xowa/src/gplx/xowa/html/Xow_html_mgr.java index 5a8cf4135..adf443b60 100644 --- a/400_xowa/src/gplx/xowa/html/Xow_html_mgr.java +++ b/400_xowa/src/gplx/xowa/html/Xow_html_mgr.java @@ -36,11 +36,13 @@ public class Xow_html_mgr implements GfoInvkAble { public void Init_by_wiki(Xow_wiki wiki) { html_wtr.Init_by_wiki(wiki); module_mgr.Init_by_wiki(wiki); - portal_mgr.Init_by_wiki(wiki); } public void Init_by_lang(Xol_lang lang) { portal_mgr.Init_by_lang(lang); } + public void Init_by_kit() { + portal_mgr.Init_by_kit(wiki); + } public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki; public Xoh_html_wtr Html_wtr() {return html_wtr;} private Xoh_html_wtr html_wtr; public Xoh_page_wtr_mgr Page_wtr_mgr() {return page_wtr_mgr;} private Xoh_page_wtr_mgr page_wtr_mgr; diff --git a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_lnki_wtr.java b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_lnki_wtr.java index 69098c938..efd20cf63 100644 --- a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_lnki_wtr.java +++ b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_lnki_wtr.java @@ -49,7 +49,7 @@ public class Xoh_lnki_wtr { Xow_xwiki_itm xwiki_lang = lnki_ttl.Wik_itm(); if ( xwiki_lang != null // lnki is xwiki; EX: [[commons:]] [[en:]] [[wikt:]] && xwiki_lang.Wiki_tid() == wiki.Xwiki_domain_tid() // xwiki is same type as cur wiki; EX: cur=w xwiki=w -> add to xwiki_langs; cur=w xwikid=d -> don't add to xwiki_langs; DATE:2014-09-14 - && xwiki_lang.Type_is_xwiki_lang(wiki.Domain_itm().Lang_orig_id()) // NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10 + && xwiki_lang.Type_is_xwiki_lang(wiki.Domain_itm().Lang_orig_uid())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10 && !lnki_ttl.ForceLiteralLink() // not literal; [[:en:A]] ) { page.Xwiki_langs().Add(lnki_ttl); diff --git a/400_xowa/src/gplx/xowa/html/modules/popups/Xow_popup_parser.java b/400_xowa/src/gplx/xowa/html/modules/popups/Xow_popup_parser.java index 7c1a34d8f..ed0369cba 100644 --- a/400_xowa/src/gplx/xowa/html/modules/popups/Xow_popup_parser.java +++ b/400_xowa/src/gplx/xowa/html/modules/popups/Xow_popup_parser.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.html.modules.popups; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; import gplx.xowa.html.modules.*; -import gplx.core.btries.*; +import gplx.core.btries.*; import gplx.xowa.wikis.*; import gplx.xowa.apis.xowa.html.modules.*; import gplx.xowa.html.modules.popups.keeplists.*; import gplx.xowa.gui.views.*; import gplx.xowa.parsers.hdrs.*; public class Xow_popup_parser { @@ -68,46 +68,51 @@ public class Xow_popup_parser { wtxt_ctx.Cur_page().Ttl_(ttl); // NOTE: must set cur_page, or rel lnkis won't work; EX: [[../A]] } public byte[] Parse(Xow_wiki cur_wiki, Xoa_page page, Xog_tab_itm cur_tab, Xow_popup_itm popup_itm) { // NOTE: must pass cur_wiki for xwiki label; DATE:2014-07-02 - byte[] tmpl_src = page.Data_raw(); int tmpl_len = tmpl_src.length; if (tmpl_len == 0) return Bry_.Empty; - int tmpl_bgn_orig = Xow_popup_parser_.Tmpl_bgn_get_(app, popup_itm, page.Ttl(), hdr_finder, tmpl_src, tmpl_len); - int tmpl_bgn = tmpl_bgn_orig; - int tmpl_read_len_cur = cfg.Tmpl_read_len(); - wrdx_mkr.Init(); - data.Init(cfg, popup_itm, tmpl_len); - Init_ctxs(tmpl_src, page.Ttl()); - while (data.Words_needed_chk()) { - if (Canceled(popup_itm, cur_tab)) return null; - tmpl_root.Clear(); - int tmpl_end = tmpl_bgn + tmpl_read_len_cur; if (tmpl_end > tmpl_len) tmpl_end = tmpl_len; // limit to tmpl_len; EX: page is 16 bytes, but block is 1024 - int new_tmpl_bgn = parser.Parse_to_stack_end(tmpl_root, tmpl_ctx, tkn_mkr, tmpl_src, tmpl_len, tmpl_trie, tmpl_bgn, tmpl_end); - if (Canceled(popup_itm, cur_tab)) return null; - byte[] wtxt_bry = Parse_to_wtxt(tmpl_src); - int wtxt_len = wtxt_bry.length; - wtxt_root.Clear(); - int wtxt_bgn = (tmpl_bgn == Xop_parser_.Doc_bgn_bos) ? Xop_parser_.Doc_bgn_bos : 0; // if first pass, parse from -1; needed for lxrs which assume nl at bos; EX: "*a" - if (Canceled(popup_itm, cur_tab)) return null; - parser.Parse_to_src_end(wtxt_root, wtxt_ctx, tkn_mkr, wtxt_bry, wtxt_trie, wtxt_bgn, wtxt_len); - if ( wtxt_ctx.Stack_len() > 0 // dangling lnki / hdr / tblw - && (tmpl_bgn + tmpl_read_len_cur) < data.Tmpl_max() // too much read; stop and give whatever's available; PAGE:en.w:List_of_air_forces; DATE:2014-06-18 - && tmpl_read_len_cur < tmpl_len // only reparse if tmpl_read_len_cur is < entire page; needed for pages which have dangling items; EX:"a" - ) { - new_tmpl_bgn = tmpl_bgn; - tmpl_read_len_cur = Xow_popup_parser_.Calc_read_len(wtxt_ctx, tmpl_read_len_cur, cfg.Tmpl_read_len(), tmpl_src, tmpl_bgn, tmpl_end); - wtxt_ctx.Clear(); - } - else { - wrdx_mkr.Process_tkn(cfg, data, data.Wrdx_bfr(), wtxt_root, wtxt_bry, wtxt_len); - tmpl_read_len_cur = cfg.Tmpl_read_len(); - } - tmpl_bgn = new_tmpl_bgn; - data.Tmpl_loop_count_add(); - if ( tmpl_bgn == tmpl_len // end of template - || tmpl_bgn - tmpl_bgn_orig > data.Tmpl_max() // too much read; stop and give whatever's available - ) - break; + if (Bry_.Eq(popup_itm.Wiki_domain(), Xow_wiki_domain_.Url_wikidata)) { + data.Wrdx_bfr().Add(app.Wiki_mgr().Wdata_mgr().Popup_text(page)); + } + else { + byte[] tmpl_src = page.Data_raw(); int tmpl_len = tmpl_src.length; if (tmpl_len == 0) return Bry_.Empty; + int tmpl_bgn_orig = Xow_popup_parser_.Tmpl_bgn_get_(app, popup_itm, page.Ttl(), hdr_finder, tmpl_src, tmpl_len); + int tmpl_bgn = tmpl_bgn_orig; + int tmpl_read_len_cur = cfg.Tmpl_read_len(); + wrdx_mkr.Init(); + data.Init(cfg, popup_itm, tmpl_len); + Init_ctxs(tmpl_src, page.Ttl()); + while (data.Words_needed_chk()) { + if (Canceled(popup_itm, cur_tab)) return null; + tmpl_root.Clear(); + int tmpl_end = tmpl_bgn + tmpl_read_len_cur; if (tmpl_end > tmpl_len) tmpl_end = tmpl_len; // limit to tmpl_len; EX: page is 16 bytes, but block is 1024 + int new_tmpl_bgn = parser.Parse_to_stack_end(tmpl_root, tmpl_ctx, tkn_mkr, tmpl_src, tmpl_len, tmpl_trie, tmpl_bgn, tmpl_end); + if (Canceled(popup_itm, cur_tab)) return null; + byte[] wtxt_bry = Parse_to_wtxt(tmpl_src); + int wtxt_len = wtxt_bry.length; + wtxt_root.Clear(); + int wtxt_bgn = (tmpl_bgn == Xop_parser_.Doc_bgn_bos) ? Xop_parser_.Doc_bgn_bos : 0; // if first pass, parse from -1; needed for lxrs which assume nl at bos; EX: "*a" + if (Canceled(popup_itm, cur_tab)) return null; + parser.Parse_to_src_end(wtxt_root, wtxt_ctx, tkn_mkr, wtxt_bry, wtxt_trie, wtxt_bgn, wtxt_len); + if ( wtxt_ctx.Stack_len() > 0 // dangling lnki / hdr / tblw + && (tmpl_bgn + tmpl_read_len_cur) < data.Tmpl_max() // too much read; stop and give whatever's available; PAGE:en.w:List_of_air_forces; DATE:2014-06-18 + && tmpl_read_len_cur < tmpl_len // only reparse if tmpl_read_len_cur is < entire page; needed for pages which have dangling items; EX:"a" + ) { + new_tmpl_bgn = tmpl_bgn; + tmpl_read_len_cur = Xow_popup_parser_.Calc_read_len(wtxt_ctx, tmpl_read_len_cur, cfg.Tmpl_read_len(), tmpl_src, tmpl_bgn, tmpl_end); + wtxt_ctx.Clear(); + } + else { + wrdx_mkr.Process_tkn(cfg, data, data.Wrdx_bfr(), wtxt_root, wtxt_bry, wtxt_len); + tmpl_read_len_cur = cfg.Tmpl_read_len(); + } + tmpl_bgn = new_tmpl_bgn; + data.Tmpl_loop_count_add(); + if ( tmpl_bgn == tmpl_len // end of template + || tmpl_bgn - tmpl_bgn_orig > data.Tmpl_max() // too much read; stop and give whatever's available + ) + break; + } + if (Canceled(popup_itm, cur_tab)) return null; + Parse_wrdx_to_html(popup_itm, data.Wrdx_bfr()); } - if (Canceled(popup_itm, cur_tab)) return null; - Parse_wrdx_to_html(popup_itm, data.Wrdx_bfr()); byte[] rv = html_mkr.Bld(cur_wiki, page, popup_itm, data.Wrdx_bfr()); return (Canceled(popup_itm, cur_tab)) ? null : rv; } diff --git a/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls.java b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls.java index ab9d13e90..df468cede 100644 --- a/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls.java +++ b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls.java @@ -16,11 +16,29 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; +import gplx.xowa.wikis.*; import gplx.xowa.xtns.wdatas.*; public class Xoh_page_body_cls { // REF.MW:Skin.php|getPageClasses - public static byte[] Calc(Bry_bfr tmp_bfr, Xoa_ttl ttl) { + public static byte[] Calc(Bry_bfr tmp_bfr, Xoa_ttl ttl, int page_tid) { tmp_bfr.Add(Bry_id_prefix).Add_int_variable(ttl.Ns().Id()); // ns-0; note that special is ns--1 DATE:2014-09-24 Add_type(tmp_bfr, ttl); // ns-special || ns-talk || ns-subject tmp_bfr.Add_byte_space().Add(Bry_page_prefix).Add(Escape_cls(ttl.Full_db())); // page-Page_title + if (page_tid == Xow_page_tid.Tid_json) { + switch (ttl.Ns().Id()) { + case Xow_ns_.Id_main: + tmp_bfr.Add_byte_space().Add(Bry_wb_entitypage); + tmp_bfr.Add_byte_space().Add(Bry_wb_itempage); + tmp_bfr.Add_byte_space().Add(Bry_wb_itempage).Add_byte(Byte_ascii.Dash).Add(ttl.Page_db()); + break; + case Wdata_wiki_mgr.Ns_property: + tmp_bfr.Add_byte_space().Add(Bry_wb_entitypage); + tmp_bfr.Add_byte_space().Add(Bry_wb_propertypage); + tmp_bfr.Add_byte_space().Add(Bry_wb_propertypage).Add_byte(Byte_ascii.Dash).Add(ttl.Page_db()); + break; + default: + Gfo_usr_dlg_._.Warn_many("", "", "unexpected ns for page_body_cls; ttl=~{0}", String_.new_utf8_(ttl.Raw())); + break; + } + } return tmp_bfr.XtoAryAndClear(); } private static void Add_type(Bry_bfr tmp_bfr, Xoa_ttl ttl) { @@ -105,5 +123,9 @@ public class Xoh_page_body_cls { // REF.MW:Skin.php|getPageClasses , Bry_type_talk = Bry_.new_ascii_("ns-talk") , Bry_type_subject = Bry_.new_ascii_("ns-subject") , Bry_page_prefix = Bry_.new_ascii_("page-") + , Bry_wb_entitypage = Bry_.new_ascii_("wb-entitypage") + , Bry_wb_itempage = Bry_.new_ascii_("wb-itempage") + , Bry_wb_propertypage = Bry_.new_ascii_("wb-propertypage") ; + public static int Page_tid_wikitext = 0, Page_tid_wikidata_qid = 1, Page_tid_wikidata_pid = 2; } diff --git a/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls_tst.java b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls_tst.java index ce05afc0a..ee215fec3 100644 --- a/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls_tst.java +++ b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls_tst.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; -import org.junit.*; +import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.xtns.wdatas.*; public class Xoh_page_body_cls_tst { @Before public void init() {} private Xoh_page_body_cls_fxt fxt = new Xoh_page_body_cls_fxt(); @Test public void Escape_cls() { @@ -29,9 +29,11 @@ public class Xoh_page_body_cls_tst { fxt.Test_escape_cls("a b", "a_b"); // nbsp } @Test public void Calc() { - fxt.Test_calc("A" , "ns-0 ns-subject page-A"); - fxt.Test_calc("Talk:A" , "ns-1 ns-talk page-Talk_A"); - fxt.Test_calc("Wikipedia:Página principal" , "ns-4 ns-subject page-Wikipedia_Página_principal"); + fxt.Test_calc(Xow_page_tid.Tid_wikitext , "A" , "ns-0 ns-subject page-A"); + fxt.Test_calc(Xow_page_tid.Tid_wikitext , "Talk:A" , "ns-1 ns-talk page-Talk_A"); + fxt.Test_calc(Xow_page_tid.Tid_wikitext , "Wikipedia:Página principal" , "ns-4 ns-subject page-Wikipedia_Página_principal"); + fxt.Test_calc(Xow_page_tid.Tid_json , "Q2" , "ns-0 ns-subject page-Q2 wb-entitypage wb-itempage wb-itempage-Q2"); + fxt.Test_calc(Xow_page_tid.Tid_json , "Property:P1" , "ns-120 ns-subject page-Property_P1 wb-entitypage wb-propertypage wb-propertypage-P1"); } } class Xoh_page_body_cls_fxt { @@ -39,13 +41,14 @@ class Xoh_page_body_cls_fxt { public void Test_escape_cls(String raw, String expd) { Tfds.Eq(expd, String_.new_utf8_(Xoh_page_body_cls.Escape_cls(Bry_.new_utf8_(raw)))); } - public void Test_calc(String ttl_str, String expd) { + public void Test_calc(byte page_tid, String ttl_str, String expd) { if (app == null) { app = Xoa_app_fxt.app_(); wiki = Xoa_app_fxt.wiki_tst_(app); tmp_bfr = Bry_bfr.reset_(255); + wiki.Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, Wdata_wiki_mgr.Ns_property_name); } Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_utf8_(ttl_str)); - Tfds.Eq(expd, String_.new_utf8_(Xoh_page_body_cls.Calc(tmp_bfr, ttl))); + Tfds.Eq(expd, String_.new_utf8_(Xoh_page_body_cls.Calc(tmp_bfr, ttl, page_tid))); } } diff --git a/400_xowa/src/gplx/xowa/html/portal/Xow_portal_mgr.java b/400_xowa/src/gplx/xowa/html/portal/Xow_portal_mgr.java index 5b6e576be..3856ff81d 100644 --- a/400_xowa/src/gplx/xowa/html/portal/Xow_portal_mgr.java +++ b/400_xowa/src/gplx/xowa/html/portal/Xow_portal_mgr.java @@ -19,16 +19,17 @@ package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xo import gplx.xowa.wikis.*; import gplx.xowa.gui.*; import gplx.xowa.html.sidebar.*; import gplx.xowa.pages.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.apis.xowa.html.skins.*; public class Xow_portal_mgr implements GfoInvkAble { + private Xow_wiki wiki; private boolean lang_is_rtl; private Xoapi_toggle_itm toggle_itm; public Xow_portal_mgr(Xow_wiki wiki) { this.wiki = wiki; this.sidebar_mgr = new Xowh_sidebar_mgr(wiki); this.missing_ns_cls = Bry_.Eq(wiki.Domain_bry(), Xow_wiki_domain_.Key_home_bry) ? Missing_ns_cls_hide : null; // if home wiki, set missing_ns to application default; if any other wiki, set to null; will be overriden during init - } private Xow_wiki wiki; private boolean lang_is_rtl; + } public void Init_by_lang(Xol_lang lang) { lang_is_rtl = !lang.Dir_ltr(); } private Xoapi_skin_app_base api_skin; - public void Init_by_wiki(Xow_wiki wiki) { + public void Init_by_kit(Xow_wiki wiki) { Xoa_app app = wiki.App(); Xoapi_skins skins = app.Api_root().Html().Skins(); api_skin = app.Mode() == Xoa_app_.Mode_gui ? skins.Desktop() : skins.Server(); @@ -59,9 +60,7 @@ public class Xow_portal_mgr implements GfoInvkAble { private byte[] Init_fmtr(Bry_bfr tmp_bfr, Bry_fmtr_eval_mgr eval_mgr, Bry_fmtr fmtr, Object... fmt_args) { fmtr.Eval_mgr_(eval_mgr); fmtr.Bld_bfr_many(tmp_bfr, fmt_args); - byte[] rv = tmp_bfr.XtoAryAndClear(); - // fmtr.Fmt_(rv); - return rv; + return tmp_bfr.XtoAryAndClear(); } public byte[] Div_personal_bry() {return div_personal_bry;} private byte[] div_personal_bry = Bry_.Empty; public byte[] Div_ns_bry(Bry_bfr_mkr bfr_mkr, Xoa_ttl ttl, Xow_ns_mgr ns_mgr) { @@ -97,9 +96,10 @@ public class Xow_portal_mgr implements GfoInvkAble { public byte[] Div_logo_bry() {return div_logo_bry;} private byte[] div_logo_bry = Bry_.Empty; public byte[] Div_home_bry() {return api_skin != null && api_skin.Sidebar_home_enabled() ? div_home_bry : Bry_.Empty;} private byte[] div_home_bry = Bry_.Empty; public byte[] Div_wikis_bry(Bry_bfr_mkr bfr_mkr) { - gplx.xowa.apis.xowa.html.Xoapi_toggle_itm itm = wiki.App().Api_root().Html().Page().Toggle_mgr().Itm_offline_wikis().Init(wiki.App().User().Wiki()); + if (toggle_itm == null) // TEST:lazy-new b/c Init_by_wiki + toggle_itm = wiki.App().Api_root().Html().Page().Toggle_mgr().Get_or_new("offline-wikis").Init(wiki.App().User().Wiki()); Bry_bfr tmp_bfr = bfr_mkr.Get_k004(); - div_wikis_fmtr.Bld_bfr_many(tmp_bfr, itm.Icon_src(), itm.Icon_title(), itm.Elem_display()); + div_wikis_fmtr.Bld_bfr_many(tmp_bfr, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr()); return tmp_bfr.Mkr_rls().XtoAryAndClear(); } public byte[] Missing_ns_cls() {return missing_ns_cls;} public Xow_portal_mgr Missing_ns_cls_(byte[] v) {missing_ns_cls = v; return this;} private byte[] missing_ns_cls; // NOTE: must be null due to Init check above @@ -107,7 +107,7 @@ public class Xow_portal_mgr implements GfoInvkAble { private Bry_fmtr div_ns_fmtr = Bry_fmtr.new_("~{portal_ns_subj_href};~{portal_ns_subj_cls};~{portal_ns_talk_href};~{portal_ns_talk_cls}", "portal_ns_subj_href", "portal_ns_subj_cls", "portal_ns_talk_href", "portal_ns_talk_cls"); private Bry_fmtr div_view_fmtr = Bry_fmtr.new_("", "portal_view_read_cls", "portal_view_edit_cls", "portal_view_html_cls", "search_text"); private Bry_fmtr div_logo_fmtr = Bry_fmtr.new_("", "portal_nav_main_href", "portal_logo_url"); - private Bry_fmtr div_wikis_fmtr = Bry_fmtr.new_("", "icon_src", "icon_title", "elem_display"); + private Bry_fmtr div_wikis_fmtr = Bry_fmtr.new_("", "toggle_btn", "toggle_hdr"); private byte[] Reverse_li(byte[] bry) { return lang_is_rtl ? Xoh_rtl_utl.Reverse_li(bry) : bry; } diff --git a/400_xowa/src/gplx/xowa/html/tocs/Xow_hdr_mgr.java b/400_xowa/src/gplx/xowa/html/tocs/Xow_hdr_mgr.java index 5a148d0de..ecad1175e 100644 --- a/400_xowa/src/gplx/xowa/html/tocs/Xow_hdr_mgr.java +++ b/400_xowa/src/gplx/xowa/html/tocs/Xow_hdr_mgr.java @@ -23,11 +23,11 @@ public class Xow_hdr_mgr { private HashAdp hdrs_hash = HashAdp_.new_(); private Bry_bfr hdrs_bfr = Bry_bfr.reset_(255); private Bry_obj_ref hdrs_ref = Bry_obj_ref.null_(); public Xow_hdr_mgr(Xow_wiki wiki, Xoa_page page) {this.wiki = wiki; this.page = page;} public boolean Toc_enabled() { - return !toc_hide // check for __NOTOC__ - && hdrs_len != 0 // never show TOC if 0 headers, even when __FORCETOC__ - && ( hdrs_len > 3 // show TOC automatically if 4 or more headers - || toc_manual // or when __TOC__ specified (EX: 2 headers) - || toc_force // or when __FORCETOC__ specified; presumably to (a) show TOC when < 4 headers and (b) let TOC show at default position; __TOC__ would force TOC to show at __TOC__; __FORCETOC__ can be placed at bottom of page + return !toc_hide // check for __NOTOC__ + && hdrs_len != 0 // never show TOC if 0 headers, even when __FORCETOC__ + && ( hdrs_len > Toc_min // show TOC automatically if 4 or more headers + || toc_manual // or when __TOC__ specified (EX: 2 headers) + || toc_force // or when __FORCETOC__ specified; presumably to (a) show TOC when < 4 headers and (b) let TOC show at default position; __TOC__ would force TOC to show at __TOC__; __FORCETOC__ can be placed at bottom of page ) ; } @@ -124,4 +124,5 @@ public class Xow_hdr_mgr { } } } + public static final int Toc_min = 3; } diff --git a/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java b/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java index ee50ca53f..4260d6dfa 100644 --- a/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java +++ b/400_xowa/src/gplx/xowa/setup/maints/Wmf_dump_list_parser_tst.java @@ -41,7 +41,7 @@ public class Wmf_dump_list_parser_tst { , fxt.itm("zh-classicalwiki", "20131128", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-11-28 06:08:56") ); } -// @Test public void Update() { // 2014-07-06 +// @Test public void Update() { // MAINT:QUARTERLY:2014-10-05 // Hash_adp_bry excluded_domains = Hash_adp_bry.cs_().Add_many_str // ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org" // , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org" @@ -57,12 +57,12 @@ public class Wmf_dump_list_parser_tst { // Wmf_dump_itm itm = itms[i]; // byte[] abrv = itm.Wiki_abrv(); // if (Bry_.Eq(abrv, Bry_.new_ascii_("testwikidatawiki"))) continue; -// byte[] domain_bry = Xob_bz2_file.Parse__domain_name(abrv, 0, abrv.length); +// byte[] domain_bry = Xow_wiki_alias.Parse__domain_name(abrv, 0, abrv.length); // if (domain_bry == null) continue; // not a standard WMF wiki; ignore // if (Bry_finder.Find_fwd(domain_bry, Bry_.new_ascii_("wikimania")) != Bry_.NotFound) continue; // if (excluded_domains.Has(domain_bry)) continue; // Xow_wiki_domain domain_itm = Xow_wiki_domain_.parse_by_domain(domain_bry); -// byte[] tid_name = Xto_display_name(Xow_wiki_domain_.Key_by_tid(domain_itm.Tid())); +// byte[] tid_name = Xto_display_name(Xow_wiki_domain_.Key_by_tid(domain_itm.Wiki_tid())); // sql_bfr // .Add_byte(Byte_ascii.Paren_bgn) // .Add_int_variable(counter++) @@ -70,7 +70,7 @@ public class Wmf_dump_list_parser_tst { // .Add_int_variable(1) // .Add_byte(Byte_ascii.Comma) // .Add_byte(Byte_ascii.Apos) -// .Add(domain_itm.Lang_orig()) +// .Add(domain_itm.Lang_orig_key()) // .Add_byte(Byte_ascii.Apos) // .Add_byte(Byte_ascii.Comma) // .Add_byte(Byte_ascii.Apos) diff --git a/400_xowa/src/gplx/xowa/setup/maints/Xoa_maint_mgr.java b/400_xowa/src/gplx/xowa/setup/maints/Xoa_maint_mgr.java index 765ea0df8..525f3cde5 100644 --- a/400_xowa/src/gplx/xowa/setup/maints/Xoa_maint_mgr.java +++ b/400_xowa/src/gplx/xowa/setup/maints/Xoa_maint_mgr.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.setup.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.setup.*; -import gplx.ios.*; +import gplx.ios.*; import gplx.xowa.wikis.*; public class Xoa_maint_mgr implements GfoInvkAble { public Xoa_maint_mgr(Xoa_app app) { this.app = app; @@ -55,8 +55,8 @@ public class Xoa_maint_mgr implements GfoInvkAble { for (int i = 0; i < len; i++) { Wmf_dump_itm itm = itms[i]; byte[] wiki_abrv = itm.Wiki_abrv(); - byte[] wiki_domain = Xob_bz2_file.Parse__domain_name(wiki_abrv, 0, wiki_abrv.length); - if (wiki_domain == Xob_bz2_file.Parse__domain_name_null) continue; // invalid wiki-name; ex: nycwikimedia + byte[] wiki_domain = Xow_wiki_alias.Parse__domain_name(wiki_abrv, 0, wiki_abrv.length); + if (wiki_domain == Xow_wiki_alias.Parse__domain_name_null) continue; // invalid wiki-name; ex: nycwikimedia itms_hash.Add(wiki_domain, itm); } len = app.Wiki_mgr().Count(); diff --git a/400_xowa/src/gplx/xowa/users/Xou_user.java b/400_xowa/src/gplx/xowa/users/Xou_user.java index 343c89b2e..aaddb5809 100644 --- a/400_xowa/src/gplx/xowa/users/Xou_user.java +++ b/400_xowa/src/gplx/xowa/users/Xou_user.java @@ -17,8 +17,9 @@ along with this program. If not, see . */ package gplx.xowa.users; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.users.dbs.*; import gplx.xowa.users.history.*; import gplx.xowa.xtns.scribunto.*; -public class Xou_user implements GfoInvkAble { +public class Xou_user implements GfoEvMgrOwner, GfoInvkAble { public Xou_user(Xoa_app app, Io_url user_dir) { + this.evMgr = GfoEvMgr.new_(this); this.app = app; this.key_str = user_dir.NameOnly(); key_bry = Bry_.new_utf8_(key_str); fsys_mgr = new Xou_fsys_mgr(app, this, user_dir); prefs_mgr = new gplx.xowa.users.prefs.Prefs_mgr(app); @@ -31,11 +32,13 @@ public class Xou_user implements GfoInvkAble { public String Key_str() {return key_str;} private String key_str; public byte[] Key_bry() {return key_bry;} private byte[] key_bry; public void Key_str_(String v) {this.key_str = v; this.key_bry = Bry_.new_utf8_(v);} + public GfoEvMgr EvMgr() {return evMgr;} private final GfoEvMgr evMgr; public Xol_lang Lang() {if (lang == null) {lang = app.Lang_mgr().Get_by_key_or_new(app.Sys_cfg().Lang()); lang.Init_by_load();} return lang;} private Xol_lang lang; public void Lang_(Xol_lang v) { lang = v; this.Msg_mgr().Lang_(v); wiki.Msg_mgr().Clear(); // clear home wiki msgs whenever lang changes; else messages cached from old lang will not be replaced; EX:Read/Edit; DATE:2014-05-26 + GfoEvMgr_.PubVal(this, Evt_lang_changed, lang); } public Xou_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xou_fsys_mgr fsys_mgr; public Xow_wiki Wiki() {if (wiki == null) wiki = Xou_user_.new_or_create_(this, app); return wiki;} private Xow_wiki wiki; @@ -92,6 +95,7 @@ public class Xou_user implements GfoInvkAble { public static final String Invk_available_from_fsys = "available_from_fsys", Invk_available_from_bulk = "available_from_bulk", Invk_bookmarks_add_fmt_ = "bookmarks_add_fmt_" , Invk_name = "name", Invk_wiki = "wiki", Invk_history = "history", Invk_fsys = "fsys", Invk_lang = "lang", Invk_msgs = "msgs", Invk_prefs = "prefs", Invk_cfg = "cfg", Invk_session = "session"; public static final String Key_xowa_user = "anonymous"; + public static final String Evt_lang_changed = "lang_changed"; public void Available_from_fsys() { Io_url bookmarks_dir = fsys_mgr.Home_wiki_dir().GenSubDir_nest("wiki", "home", "ns", "730"); // NOTE: putting bookmark check here (instead of at init) b/c Init runs before xowa.gfs, and Bookmarks needs xowa.gfs to run first if (!Io_mgr._.ExistsDir(bookmarks_dir)) Xou_user_.Bookmarks_make(app, this.Wiki()); diff --git a/400_xowa/src/gplx/xowa/wikis/Xoa_wiki_mgr.java b/400_xowa/src/gplx/xowa/wikis/Xoa_wiki_mgr.java index 2cb9561fc..bcb35f133 100644 --- a/400_xowa/src/gplx/xowa/wikis/Xoa_wiki_mgr.java +++ b/400_xowa/src/gplx/xowa/wikis/Xoa_wiki_mgr.java @@ -32,6 +32,7 @@ public class Xoa_wiki_mgr implements GfoInvkAble { public Xoa_css_extractor Css_installer() {return css_installer;} private Xoa_css_extractor css_installer = new Xoa_css_extractor(); public void Init_by_app() { css_installer.Init_by_app(app); + wdata_mgr.Init_by_app(); } public int Count() {return hash.Count();} public void Del(byte[] key) {hash.Del(key);} @@ -87,7 +88,7 @@ public class Xoa_wiki_mgr implements GfoInvkAble { private static final String Invk_len = "len", Invk_get_at = "get_at"; private Xow_wiki New_wiki(byte[] key) { Xow_wiki_domain wiki_type = Xow_wiki_domain_.parse_by_domain(key); - byte[] lang_key = wiki_type.Lang(); if (lang_key == Xol_lang_itm_.Key__unknown) lang_key = Xol_lang_.Key_en; + byte[] lang_key = wiki_type.Lang_key(); if (lang_key == Xol_lang_itm_.Key__unknown) lang_key = Xol_lang_.Key_en; Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(lang_key); Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(lang.Case_mgr()); Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(String_.new_utf8_(key)); diff --git a/400_xowa/src_210_bldr_core/gplx/xowa/Xob_bz2_file.java b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_alias.java similarity index 91% rename from 400_xowa/src_210_bldr_core/gplx/xowa/Xob_bz2_file.java rename to 400_xowa/src/gplx/xowa/wikis/Xow_wiki_alias.java index 6359d151e..b474e52ba 100644 --- a/400_xowa/src_210_bldr_core/gplx/xowa/Xob_bz2_file.java +++ b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_alias.java @@ -15,15 +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 . */ -package gplx.xowa; import gplx.*; +package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*; import gplx.core.btries.*; import gplx.xowa.wikis.*; -public class Xob_bz2_file { - public Io_url Fil() {return fil;} public Xob_bz2_file Fil_(Io_url v) {fil = v; return this;} Io_url fil; +public class Xow_wiki_alias { + public Io_url Fil() {return fil;} public Xow_wiki_alias Fil_(Io_url v) {fil = v; return this;} Io_url fil; public byte Tid() {return tid;} private byte tid; public byte[] Domain() {return domain;} private byte[] domain; public String Date() {return date;} private String date; // needs to be String to handle "latest" - public Xob_bz2_file Parse(String fil_name) {return Parse(Bry_.new_ascii_(fil_name));} - public Xob_bz2_file Parse(byte[] fil_name) { + public Xow_wiki_alias Parse(String fil_name) {return Parse(Bry_.new_ascii_(fil_name));} + public Xow_wiki_alias Parse(byte[] fil_name) { int fil_name_len = fil_name.length; int dash_0 = Bry_finder.Find_fwd(fil_name, Byte_ascii.Dash, 0 , fil_name_len); if (dash_0 == Bry_.NotFound) throw Err_mgr._.parse_obj_(this, fil_name); int dash_1 = Bry_finder.Find_fwd(fil_name, Byte_ascii.Dash, dash_0 + 1 , fil_name_len); if (dash_1 == Bry_.NotFound) throw Err_mgr._.parse_obj_(this, fil_name); @@ -39,7 +39,7 @@ public class Xob_bz2_file { } public static byte[] Build_alias(Xow_wiki_domain wiki_type) { if (alias_bry_trie == null) Init_aliases(); - byte tid = wiki_type.Tid(); + byte tid = wiki_type.Wiki_tid(); byte[] alias = (byte[])alias_val_hash.Fetch(Byte_obj_ref.new_(tid)); if (alias == null) return null; switch (tid) { @@ -59,7 +59,7 @@ public class Xob_bz2_file { case Xow_wiki_domain_.Tid_wikiquote: case Xow_wiki_domain_.Tid_wikinews: case Xow_wiki_domain_.Tid_wikivoyage: - return Bry_.Add(wiki_type.Lang_orig(), alias); + return Bry_.Add(wiki_type.Lang_orig_key(), alias); default: throw Err_mgr._.unhandled_(tid); } @@ -70,7 +70,7 @@ public class Xob_bz2_file { if (end - bgn == 0) return null; // empty bry; if (alias_bry_trie == null) Init_aliases(); Object o = alias_bry_trie.Match_bgn(src, end - 1, bgn - 1); if (o == null) return Parse__domain_name_null; -// throw Err_mgr._.parse_(typeof(Xob_bz2_file), src); +// throw Err_mgr._.parse_(typeof(Xow_wiki_alias), src); byte domain_tid = ((Byte_obj_ref)o).Val(); Bry_bfr bfr = Bry_bfr.reset_(255); switch (domain_tid) { @@ -129,7 +129,7 @@ public class Xob_bz2_file { public static byte Parse__tid(byte[] src) {return Parse__tid(src, 0, src.length);} public static byte Parse__tid(byte[] src, int bgn, int end) { if (tid_bry_trie == null) Init_tids(); - Object o = tid_bry_trie.Match_bgn(src, bgn, end); if (o == null) throw Err_mgr._.parse_(Xob_bz2_file.class, src); + Object o = tid_bry_trie.Match_bgn(src, bgn, end); if (o == null) throw Err_mgr._.parse_(Xow_wiki_alias.class, src); return ((Byte_obj_ref)o).Val(); } public static void Build_alias_by_lang_tid(Bry_bfr bfr, byte[] lang_key, Byte_obj_ref wiki_tid) { @@ -153,6 +153,12 @@ public class Xob_bz2_file { break; } } + public static Xow_wiki_domain parse_by_wmf_key(byte[] wmf_key) { + byte[] domain_bry = Parse__domain_name(wmf_key, 0, wmf_key.length); + Xow_wiki_domain rv = Xow_wiki_domain_.parse_by_domain(domain_bry); + rv.Wmf_key_(wmf_key); + return rv; + } public static final byte Tid_null = 0, Tid_pages_articles = 1, Tid_pages_meta_current = 2, Tid_categorylinks = 3, Tid_page_props = 4, Tid_image = 5; public static final String Key_null = "" , Key_pages_articles = "pages-articles", Key_pages_meta_current = "pages-meta-current" diff --git a/400_xowa/src_210_bldr_core/gplx/xowa/Xob_bz2_file_tst.java b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_alias_tst.java similarity index 80% rename from 400_xowa/src_210_bldr_core/gplx/xowa/Xob_bz2_file_tst.java rename to 400_xowa/src/gplx/xowa/wikis/Xow_wiki_alias_tst.java index f5e3d08ff..65fc543be 100644 --- a/400_xowa/src_210_bldr_core/gplx/xowa/Xob_bz2_file_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_alias_tst.java @@ -15,11 +15,11 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -package gplx.xowa; import gplx.*; +package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*; import org.junit.*; import gplx.xowa.wikis.*; -public class Xob_bz2_file_tst { - Xob_bz2_file_fxt fxt = new Xob_bz2_file_fxt(); - @Test public void Parse() {fxt.Parse("enwiki-20121201-pages-articles.xml.bz2", "en.wikipedia.org", "20121201", Xob_bz2_file.Tid_pages_articles);} +public class Xow_wiki_alias_tst { + Xow_wiki_alias_fxt fxt = new Xow_wiki_alias_fxt(); + @Test public void Parse() {fxt.Parse("enwiki-20121201-pages-articles.xml.bz2", "en.wikipedia.org", "20121201", Xow_wiki_alias.Tid_pages_articles);} @Test public void Parse__domain_name() { fxt.Parse__domain_name("foundationwiki" , "wikimediafoundation.org"); fxt.Parse__domain_name("wikidatawiki" , "www.wikidata.org"); @@ -38,8 +38,8 @@ public class Xob_bz2_file_tst { fxt.Parse__domain_name("enwikivoyage" , "en.wikivoyage.org"); } @Test public void Parse__tid() { - fxt.Parse__tid("pages-articles.xml" , Xob_bz2_file.Tid_pages_articles); - fxt.Parse__tid("pages-meta-current.xml" , Xob_bz2_file.Tid_pages_meta_current); + fxt.Parse__tid("pages-articles.xml" , Xow_wiki_alias.Tid_pages_articles); + fxt.Parse__tid("pages-meta-current.xml" , Xow_wiki_alias.Tid_pages_meta_current); } @Test public void Build_alias() { fxt.Build_alias("simple.wikipedia.org", "simplewiki"); @@ -50,14 +50,14 @@ public class Xob_bz2_file_tst { fxt.Build_wmf_src_dir("simplewiki", "latest", "http://dumps.wikimedia.your.org/simplewiki/latest/"); } @Test public void Build_wmf_src_name() { - fxt.Build_wmf_src_name("simplewiki", "latest", Xob_bz2_file.Key_pages_articles, "simplewiki-latest-pages-articles.xml.bz2"); + fxt.Build_wmf_src_name("simplewiki", "latest", Xow_wiki_alias.Key_pages_articles, "simplewiki-latest-pages-articles.xml.bz2"); } @Test public void Build_alias_by_lang_tid() { fxt.Build_alias_by_lang_tid("en", Xow_wiki_domain_.Tid_wikipedia, "enwiki"); } } -class Xob_bz2_file_fxt { - Xob_bz2_file file = new Xob_bz2_file(); +class Xow_wiki_alias_fxt { + Xow_wiki_alias file = new Xow_wiki_alias(); public void Parse(String name, String domain, String date, byte tid) { Io_url fil = Io_url_.mem_fil_("mem/xowa/temp/" + name); file.Fil_(fil).Parse(fil.NameOnly()); @@ -65,11 +65,11 @@ class Xob_bz2_file_fxt { Tfds.Eq(date , file.Date()); Tfds.Eq(tid , file.Tid()); } - public void Parse__domain_name(String raw_str, String expd) {byte[] raw = Bry_.new_ascii_(raw_str); Tfds.Eq(expd, String_.new_ascii_(Xob_bz2_file.Parse__domain_name(raw, 0, raw.length)));} - public void Parse__tid(String raw_str, byte expd) {Tfds.Eq(expd, Xob_bz2_file.Parse__tid(raw_str));} + public void Parse__domain_name(String raw_str, String expd) {byte[] raw = Bry_.new_ascii_(raw_str); Tfds.Eq(expd, String_.new_ascii_(Xow_wiki_alias.Parse__domain_name(raw, 0, raw.length)));} + public void Parse__tid(String raw_str, byte expd) {Tfds.Eq(expd, Xow_wiki_alias.Parse__tid(raw_str));} public void Build_alias(String domain_str, String expd) { Xow_wiki_domain domain = Xow_wiki_domain_.parse_by_domain(Bry_.new_ascii_(domain_str)); - byte[] actl = Xob_bz2_file.Build_alias(domain); + byte[] actl = Xow_wiki_alias.Build_alias(domain); Tfds.Eq(expd, String_.new_ascii_(actl)); } private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); public void Build_wmf_src_dir(String alias, String date, String expd) { @@ -81,7 +81,7 @@ class Xob_bz2_file_fxt { Tfds.Eq(expd, String_.new_ascii_(actl)); } public void Build_alias_by_lang_tid(String lang_key, byte wiki_tid, String expd) { - Xob_bz2_file.Build_alias_by_lang_tid(tmp_bfr, Bry_.new_ascii_(lang_key), wiki_tid_ref.Val_(wiki_tid)); + Xow_wiki_alias.Build_alias_by_lang_tid(tmp_bfr, Bry_.new_ascii_(lang_key), wiki_tid_ref.Val_(wiki_tid)); Tfds.Eq_bry(Bry_.new_utf8_(expd), tmp_bfr.XtoAryAndClear()); } static final Byte_obj_ref wiki_tid_ref = Byte_obj_ref.zero_(); } diff --git a/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain.java b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain.java index 3815080c7..8ddef7bb8 100644 --- a/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain.java +++ b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain.java @@ -17,23 +17,22 @@ along with this program. If not, see . */ package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*; public class Xow_wiki_domain { - public Xow_wiki_domain(byte[] raw, byte tid, byte[] lang) { - this.raw = raw; this.tid = tid; this.lang = this.lang_orig = lang; - Lang_orig_id_(); + public Xow_wiki_domain(byte[] domain_bry, byte wiki_tid, byte[] lang_key) { + this.domain_bry = domain_bry; this.wiki_tid = wiki_tid; + this.lang_itm = this.lang_orig_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key); } - public Xow_wiki_domain(byte[] raw, byte tid, byte[] lang, byte[] lang_orig) { - this.raw = raw; this.tid = tid; this.lang = lang; this.lang_orig = lang_orig; - Lang_orig_id_(); + public Xow_wiki_domain(byte[] domain_bry, byte wiki_tid, byte[] lang_key, byte[] lang_orig_key) { + this.domain_bry = domain_bry; this.wiki_tid = wiki_tid; + this.lang_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key); + this.lang_orig_itm = Bry_.Eq(lang_key, lang_orig_key) ? lang_itm : Xol_lang_itm_.Get_by_key_or_intl(lang_orig_key); } - public byte[] Raw() {return raw;} private byte[] raw; - public byte Tid() {return tid;} private byte tid; - public byte[] Lang_orig() {return lang_orig;} private byte[] lang_orig; - public int Lang_orig_id() {return lang_orig_id;} private int lang_orig_id; - public byte[] Lang() {return lang;} private byte[] lang; - private void Lang_orig_id_() { -// if (Bry_.Eq(lang_orig, Commons_bry)) -// lang_orig_id = Xol_lang_itm_.Id_en; -// else - lang_orig_id = Xol_lang_itm_.Get_by_key_or_intl(lang_orig, 0, lang_orig.length).Id(); - } // private static final byte[] Commons_bry = Bry_.new_ascii_("commons"); + public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry; + public byte Wiki_tid() {return wiki_tid;} private final byte wiki_tid; + public Xol_lang_itm Lang_itm() {return lang_itm;} private final Xol_lang_itm lang_itm; + public int Lang_uid() {return lang_itm.Id();} + public byte[] Lang_key() {return lang_itm.Key();} + public Xol_lang_itm Lang_orig_itm() {return lang_orig_itm;} private final Xol_lang_itm lang_orig_itm; + public int Lang_orig_uid() {return lang_orig_itm.Id();} + public byte[] Lang_orig_key() {return lang_orig_itm.Key();} + public byte[] Wmf_key() {return wmf_key;} public void Wmf_key_(byte[] v) {wmf_key = v;} private byte[] wmf_key; } diff --git a/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_.java b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_.java index f1bb89177..5fd2f2698 100644 --- a/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_.java +++ b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_.java @@ -100,15 +100,25 @@ public class Xow_wiki_domain_ { private static final byte Tid_wikimedia = Tid_by_key_null; // NOTE: wikimedia isn't a type, but for PERF, it will be placed in the key_hash public static final String Key_home_str = "home"; private static final byte[] Key_other_bry = Bry_.new_ascii_("other"); + private static final String + Str_wikipedia = "wikipedia", Str_wiktionary = "wiktionary", Str_wikisource = "wikisource", Str_wikivoyage = "wikivoyage" + , Str_wikiquote = "wikiquote", Str_wikibooks = "wikibooks", Str_wikiversity = "wikiversity", Str_wikinews = "wikinews" + ; public static final byte[] - Key_home_bry = Bry_.new_ascii_(Key_home_str) - , Key_wikipedia_bry = Bry_.new_ascii_("wikipedia"), Key_wiktionary_bry = Bry_.new_ascii_("wiktionary"), Key_wikisource_bry = Bry_.new_ascii_("wikisource") - , Key_wikibooks_bry = Bry_.new_ascii_("wikibooks"), Key_wikiversity_bry = Bry_.new_ascii_("wikiversity"), Key_wikiquote_bry = Bry_.new_ascii_("wikiquote") - , Key_wikinews_bry = Bry_.new_ascii_("wikinews"), Key_wikivoyage_bry = Bry_.new_ascii_("wikivoyage") - , Key_commons_bry = Bry_.new_ascii_("commons"), Key_species_bry = Bry_.new_ascii_("species"), Key_meta_bry = Bry_.new_ascii_("meta") - , Key_incubator_bry = Bry_.new_ascii_("incubator"), Key_wikidata_bry = Bry_.new_ascii_("wikidata"), Key_mediawiki_bry = Bry_.new_ascii_("mediawiki") - , Key_wikimediafoundation_bry = Bry_.new_ascii_("wikimediafoundation") - ; + Key_home_bry = Bry_.new_ascii_(Key_home_str) + , Key_wikipedia_bry = Bry_.new_ascii_(Str_wikipedia), Key_wiktionary_bry = Bry_.new_ascii_(Str_wiktionary), Key_wikisource_bry = Bry_.new_ascii_(Str_wikisource) + , Key_wikibooks_bry = Bry_.new_ascii_(Str_wikibooks), Key_wikiversity_bry = Bry_.new_ascii_(Str_wikiversity), Key_wikiquote_bry = Bry_.new_ascii_(Str_wikiquote) + , Key_wikinews_bry = Bry_.new_ascii_(Str_wikinews), Key_wikivoyage_bry = Bry_.new_ascii_(Str_wikivoyage) + , Key_commons_bry = Bry_.new_ascii_("commons"), Key_species_bry = Bry_.new_ascii_("species"), Key_meta_bry = Bry_.new_ascii_("meta") + , Key_incubator_bry = Bry_.new_ascii_("incubator"), Key_wikidata_bry = Bry_.new_ascii_("wikidata"), Key_mediawiki_bry = Bry_.new_ascii_("mediawiki") + , Key_wikimediafoundation_bry = Bry_.new_ascii_("wikimediafoundation") + ; + public static final byte[] + Name_wikipedia_bry = Name_(Key_wikipedia_bry), Name_wiktionary_bry = Name_(Key_wiktionary_bry), Name_wikisource_bry = Name_(Key_wikisource_bry) + , Name_wikibooks_bry = Name_(Key_wikibooks_bry), Name_wikiversity_bry = Name_(Key_wikiversity_bry), Name_wikiquote_bry = Name_(Key_wikiquote_bry) + , Name_wikinews_bry = Name_(Key_wikinews_bry), Name_wikivoyage_bry = Name_(Key_wikivoyage_bry) + ; + private static byte[] Name_(byte[] v) {return Bry_.Upper_1st(Bry_.Copy(v));} private static byte[][] Key__ary = new byte[][] { Key_other_bry, Key_home_bry , Key_wikipedia_bry, Key_wiktionary_bry, Key_wikisource_bry, Key_wikibooks_bry, Key_wikiversity_bry, Key_wikiquote_bry, Key_wikinews_bry, Key_wikivoyage_bry @@ -136,9 +146,12 @@ public class Xow_wiki_domain_ { .Add_bry_byte(Key_wikivoyage_bry, Tid_wikivoyage) .Add_bry_byte(Key_other_bry, Tid_other) ; + public static final String + Str_wikidata = "www.wikidata.org" + ; public static final byte[] Url_commons = Bry_.new_ascii_("commons.wikimedia.org") - , Url_wikidata = Bry_.new_ascii_("www.wikidata.org") + , Url_wikidata = Bry_.new_ascii_(Str_wikidata) , Url_species = Bry_.new_ascii_("species.wikimedia.org") , Url_mediawiki = Bry_.new_ascii_("www.mediawiki.org") , Url_meta = Bry_.new_ascii_("meta.wikimedia.org") diff --git a/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_tst.java b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_tst.java index fc5e343d7..9c974f502 100644 --- a/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/Xow_wiki_domain_tst.java @@ -32,7 +32,7 @@ class Xow_wiki_domain_fxt { public void Clear() {} public void Test_parse(String domain, byte expd_tid, String expd_lang) { Xow_wiki_domain actl = Xow_wiki_domain_.parse_by_domain(Bry_.new_ascii_(domain)); - Tfds.Eq(expd_tid, actl.Tid()); - Tfds.Eq(expd_lang, String_.new_ascii_((actl.Lang()))); + Tfds.Eq(expd_tid, actl.Wiki_tid()); + Tfds.Eq(expd_lang, String_.new_ascii_((actl.Lang_key()))); } } diff --git a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_.java b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_.java index a2a82a598..206e754f0 100644 --- a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_.java +++ b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_.java @@ -22,8 +22,8 @@ public class Xow_xwiki_itm_ { url_parser.Parse(tmp_url, url_gfs, 0, url_gfs.length); byte[] domain_bry = tmp_url.Site(); Xow_wiki_domain domain = Xow_wiki_domain_.parse_by_domain(domain_bry); - Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang()); + Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_key()); int lang_id = lang_itm == null ? Xol_lang_itm_.Id__unknown : lang_itm.Id(); - return new Xow_xwiki_itm(key, url_gfs, domain.Tid(), lang_id, domain_bry).Name_(name); + return new Xow_xwiki_itm(key, url_gfs, domain.Wiki_tid(), lang_id, domain_bry).Name_(name); } } diff --git a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java index f22bb820a..f2c499110 100644 --- a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java +++ b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr.java @@ -33,9 +33,9 @@ public class Xow_xwiki_mgr implements GfoInvkAble { byte wiki_tid = Byte_.Zero; int lang_tid = -1; Xow_wiki_domain wiki_type = Xow_wiki_domain_.parse_by_domain(domain); - wiki_tid = wiki_type.Tid(); - if (Bry_.Len_gt_0(wiki_type.Lang())) { // domain has lang (EX: "en.") - Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang()); + wiki_tid = wiki_type.Wiki_tid(); + if (Bry_.Len_gt_0(wiki_type.Lang_key())) { // domain has lang (EX: "en.") + Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang_key()); if (lang_itm == null) return null; // unknown lang: do not add to wiki collection; EX: en1.wikipedia.org lang_tid = lang_itm.Id(); } @@ -70,13 +70,13 @@ public class Xow_xwiki_mgr implements GfoInvkAble { } Xow_wiki_domain wiki_type = Xow_wiki_domain_.parse_by_domain(wiki_type_bry); int lang_tid = Xol_lang_itm_.Id__unknown; - if (Bry_.Len_gt_0(wiki_type.Lang())) { - Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang()); + if (Bry_.Len_gt_0(wiki_type.Lang_key())) { + Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang_key()); if (lang_itm != null // lang exists && Bry_.Eq(alias, lang_itm.Key())) // alias == lang.key; only assign langs to aliases that have lang key; EX: w|en.wikipedia.org; "w" alias should not be registered for "en"; DATE:2013-07-25 lang_tid = lang_itm.Id(); } - return new Xow_xwiki_itm(alias, Bry_.Add(Xoh_href_parser.Href_http_bry, wiki_type_bry, Xoh_href_parser.Href_wiki_bry, Arg_0), wiki_type.Tid(), lang_tid, wiki_type_bry); + return new Xow_xwiki_itm(alias, Bry_.Add(Xoh_href_parser.Href_http_bry, wiki_type_bry, Xoh_href_parser.Href_wiki_bry, Arg_0), wiki_type.Wiki_tid(), lang_tid, wiki_type_bry); } static final byte[] Arg_0 = Bry_.new_ascii_("~{0}"); String Exec_itms_print(byte[] raw) { Bry_fmtr fmtr = Bry_fmtr.new_bry_(raw, "wiki_key");//, "wiki_type_url", "wiki_lang", "wiki_name", "wiki_logo_url"); diff --git a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr_tst.java index a88a9f7bb..757278aa5 100644 --- a/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_mgr_tst.java @@ -55,7 +55,7 @@ class Xow_xwiki_mgr_fxt { public Xow_xwiki_itm xwiki_null_(String key) {return new Xow_xwiki_itm(Bry_.new_utf8_(key), Bry_.Empty, Xow_wiki_domain_.Tid_other, Xol_lang_itm_.Id__unknown, Bry_.Empty);} public Xow_xwiki_itm xwiki_(String key, String domain, String fmt) { Xow_wiki_domain domain_itm = Xow_wiki_domain_.parse_by_domain(Bry_.new_utf8_(domain)); - return new Xow_xwiki_itm(Bry_.new_utf8_(key), Bry_.new_utf8_(fmt), domain_itm.Tid(), Xol_lang_itm_.Id__unknown, Bry_.new_utf8_(domain)); + return new Xow_xwiki_itm(Bry_.new_utf8_(key), Bry_.new_utf8_(fmt), domain_itm.Wiki_tid(), Xol_lang_itm_.Id__unknown, Bry_.new_utf8_(domain)); } public Xow_xwiki_mgr_fxt Test_add_bulk(String raw, int lang_tid, byte wiki_tid, String alias, String fmt, String domain) { Xow_xwiki_itm itm = xwiki_mgr.Add_bulk_row(Xol_lang_itm_.Regy(), Bry_.new_ascii_(raw)); diff --git a/400_xowa/src/gplx/xowa/xtns/Xow_xtn_mgr.java b/400_xowa/src/gplx/xowa/xtns/Xow_xtn_mgr.java index e88906bd7..828093bf1 100644 --- a/400_xowa/src/gplx/xowa/xtns/Xow_xtn_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/Xow_xtn_mgr.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ package gplx.xowa.xtns; import gplx.*; import gplx.xowa.*; import gplx.core.btries.*; -import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.imaps.*; import gplx.xowa.xtns.relatedSites.*; import gplx.xowa.xtns.insiders.*; import gplx.xowa.xtns.proofreadPage.*; +import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.imaps.*; import gplx.xowa.xtns.relatedSites.*; import gplx.xowa.xtns.insiders.*; import gplx.xowa.xtns.proofreadPage.*; import gplx.xowa.xtns.wdatas.*; public class Xow_xtn_mgr implements GfoInvkAble { private OrderedHash regy = OrderedHash_.new_bry_(); public int Count() {return regy.Count();} @@ -26,12 +26,14 @@ public class Xow_xtn_mgr implements GfoInvkAble { 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 Pp_xtn_mgr Xtn_proofread() {return xtn_proofread;} private Pp_xtn_mgr xtn_proofread; + public Wdata_xtn_mgr Xtn_wikibase() {return xtn_wikibase;} private Wdata_xtn_mgr xtn_wikibase; 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 Pp_xtn_mgr()); + Add(app, new Wdata_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.poems.Poem_xtn_mgr()); @@ -87,15 +89,17 @@ public class Xow_xtn_mgr implements GfoInvkAble { case Tid_insider: xtn_insider = (Insider_xtn_mgr)mgr; break; case Tid_imap: xtn_imap = (Imap_xtn_mgr)mgr; break; case Tid_proofread: xtn_proofread = (Pp_xtn_mgr)mgr; break; + case Tid_wikibase: xtn_wikibase = (Wdata_xtn_mgr)mgr; break; } } - private static final byte Tid_cite = 0, Tid_sites = 1, Tid_insider = 2, Tid_imap = 3, Tid_proofread = 4; + private static final byte Tid_cite = 0, Tid_sites = 1, Tid_insider = 2, Tid_imap = 3, Tid_proofread = 4, Tid_wikibase = 5; 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) .Add_bry_bval(Pp_xtn_mgr.XTN_KEY , Tid_proofread) + .Add_bry_bval(Wdata_xtn_mgr.XTN_KEY , Tid_wikibase) ; public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { if (ctx.Match(k, Invk_get)) return Get_or_fail(m.ReadBry("v")); diff --git a/400_xowa/src/gplx/xowa/xtns/Xox_mgr_base.java b/400_xowa/src/gplx/xowa/xtns/Xox_mgr_base.java index caa10d309..3d97fcf6f 100644 --- a/400_xowa/src/gplx/xowa/xtns/Xox_mgr_base.java +++ b/400_xowa/src/gplx/xowa/xtns/Xox_mgr_base.java @@ -61,7 +61,7 @@ public abstract class Xox_mgr_base implements Xox_mgr { public static void Xtn_load_i18n(Xow_wiki wiki, byte[] xtn_key) { Xoa_app app = wiki.App(); Io_url url = app.Fsys_mgr().Bin_xtns_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); + 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; diff --git a/400_xowa/src/gplx/xowa/xtns/mapSources/Map_dd2dms_func.java b/400_xowa/src/gplx/xowa/xtns/mapSources/Map_dd2dms_func.java index 0c0379b06..a99a645d6 100644 --- a/400_xowa/src/gplx/xowa/xtns/mapSources/Map_dd2dms_func.java +++ b/400_xowa/src/gplx/xowa/xtns/mapSources/Map_dd2dms_func.java @@ -46,6 +46,14 @@ public class Map_dd2dms_func extends Pf_func_base { else map_math.Fail(ctx, src, self, bfr, this.Name()); } + public static void Deg_to_dms(Bry_bfr bfr, boolean coord_is_lng, byte[] coord, int prec) { + Map_math map_math = Map_math._; + if (map_math.Ctor(coord, prec, Bry_.Empty, 2)) { + bfr.Add(map_math.Get_dms(Bry_.Empty, Bry_.Empty)); + byte[] dir = coord_is_lng ? map_math.Coord_dir_ns() : map_math.Coord_dir_ew(); + bfr.Add_byte_space().Add(dir); + } + } public static final Map_dd2dms_func _ = new Map_dd2dms_func(); Map_dd2dms_func() {} private static final byte Key_tid_plus = 1, Key_tid_minus = 2, Key_tid_precision = 3; private static final Hash_adp_bry Key_hash = Hash_adp_bry.cs_() diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java index 3f6a0b353..0dd285de1 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java @@ -187,7 +187,12 @@ public class Scrib_core { } return rv; } - public static Scrib_core Core() {return core;} public static Scrib_core Core_new_(Xoa_app app, Xop_ctx ctx) {core = new Scrib_core(app, ctx); return core;} private static Scrib_core core; + public static Scrib_core Core() {return core;} + public static Scrib_core Core_new_(Xoa_app app, Xop_ctx ctx) { + core = new Scrib_core(app, ctx); + core_invalidate_when_page_changes = false; + return core; + } private static Scrib_core core; public void Handle_error(String err, String traceback) { String excerpt = ""; try { @@ -197,8 +202,12 @@ public class Scrib_core { } catch (Exception e) {Err_.Noop(e);} throw Err_.new_(err, page.Ttl().Page_db_as_str(), excerpt, traceback); } + public static void Core_invalidate_when_page_changes() {core_invalidate_when_page_changes = true;} private static boolean core_invalidate_when_page_changes; public static void Core_page_changed(Xoa_page page) { - if (core != null) { + if ( core != null // core explicitly invalidated + || core_invalidate_when_page_changes // core marked invalidated b/c of error in {{#invoke}} but won't be regen'd until page changes; invalidate now; PAGE:th.d:all; DATE:2014-10-03 + ) { + core_invalidate_when_page_changes = false; if (Bry_.Eq(page.Wiki().Domain_bry(), core.Cur_wiki())) // current page is in same wiki as last page core.When_page_changed(page); else // current page is in different wiki diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java index 9dc3c63c0..d61c8e2aa 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java @@ -60,7 +60,7 @@ public class Scrib_invoke_func extends Pf_func_base { Error(bfr, wiki.Msg_mgr(), ""); bfr.Add(Html_tag_.Comm_bgn).Add_str(Err_.Message_gplx_brief(e)).Add(Html_tag_.Comm_end); ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", String_.new_utf8_(ctx.Cur_page().Ttl().Raw()), String_.new_utf8_(src, self.Src_bgn(), self.Src_end()), Err_.Message_gplx_brief(e)); - Scrib_core.Core_invalidate(); // reset core + Scrib_core.Core_invalidate_when_page_changes(); // NOTE: invalidate core when page changes, not for rest of page, else page with many errors will be very slow due to multiple invalidations; PAGE:th.d:all; DATE:2014-10-03 } } public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, String error) {Error(bfr, msg_mgr, Bry_.new_utf8_(error));} diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java index 9959a4cf7..09fe1a7ec 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java @@ -135,104 +135,17 @@ class Scrib_lib_wikibase_srl { rv[2] = KeyVal_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid())); return rv; } + private static final Scrib_lib_wikibase_srl_visitor visitor = new Scrib_lib_wikibase_srl_visitor(); private static KeyVal[] Srl_claims_prop_itm_core_val(Wdata_claim_itm_core itm) { switch (itm.Snak_tid()) { case Wdata_dict_snak_tid.Tid_somevalue: case Wdata_dict_snak_tid.Tid_novalue: // NOTE: not sure about this logic, but can't find somevalue snaktid formattercode in wikibase; DATE:2014-04-07 return DataValue_nil; default: - switch (itm.Val_tid()) { - case Wdata_dict_val_tid.Tid_string : return Srl_claims_prop_itm_core_str(itm); - case Wdata_dict_val_tid.Tid_entity : return Srl_claims_prop_itm_core_entity(itm); - case Wdata_dict_val_tid.Tid_time : return Srl_claims_prop_itm_core_time(itm); - case Wdata_dict_val_tid.Tid_globecoordinate : return Srl_claims_prop_itm_core_globecoordinate(itm); - case Wdata_dict_val_tid.Tid_quantity : return Srl_claims_prop_itm_core_quantity(itm); - case Wdata_dict_val_tid.Tid_monolingualtext : return Srl_claims_prop_itm_core_monolingualtext(itm); - default: return KeyVal_.Ary_empty; - } + itm.Welcome(visitor); + return visitor.Rv(); } } - private static KeyVal[] Srl_claims_prop_itm_core_str(Wdata_claim_itm_core itm) { - Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)itm; - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Xto_str(itm.Val_tid())); - rv[1] = KeyVal_.new_(Key_value, String_.new_utf8_(claim_str.Val_str())); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_entity(Wdata_claim_itm_core itm) { - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_entity); - rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_entity_value(itm)); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_entity_value(Wdata_claim_itm_core itm) { - Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)itm; - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Wdata_dict_value_entity.Str_entity_type, Wdata_dict_value_entity.Val_entity_type_item_str); - rv[1] = KeyVal_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.Xto_str(claim_entity.Entity_id())); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_time(Wdata_claim_itm_core itm) { - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_time); - rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_time_value(itm)); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_time_value(Wdata_claim_itm_core itm) { - Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)itm; - KeyVal[] rv = new KeyVal[6]; - rv[0] = KeyVal_.new_(Wdata_dict_value_time.Str_time , String_.new_ascii_(claim_time.Time())); - rv[1] = KeyVal_.new_(Wdata_dict_value_time.Str_precision , Wdata_dict_value_time.Val_precision_int); // NOTE: must return int, not str; DATE:2014-02-18 - rv[2] = KeyVal_.new_(Wdata_dict_value_time.Str_before , Wdata_dict_value_time.Val_before_int); - rv[3] = KeyVal_.new_(Wdata_dict_value_time.Str_after , Wdata_dict_value_time.Val_after_int); - rv[4] = KeyVal_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); - rv[5] = KeyVal_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_globecoordinate(Wdata_claim_itm_core itm) { - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_globecoordinate); - rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_globecoordinate_value(itm)); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_globecoordinate_value(Wdata_claim_itm_core itm) { - Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)itm; - KeyVal[] rv = new KeyVal[5]; - rv[0] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lat()))); - rv[1] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lng()))); - rv[2] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_altitude , null); - rv[3] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_str); - rv[4] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_precision , .00001d); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_quantity(Wdata_claim_itm_core itm) { - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_dict_val_tid.Str_quantity); - rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_quantity_value(itm)); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_quantity_value(Wdata_claim_itm_core itm) { - Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)itm; - KeyVal[] rv = new KeyVal[4]; - rv[0] = KeyVal_.new_(Wdata_dict_value_quantity.Str_amount , String_.new_utf8_(claim_quantity.Amount())); - rv[1] = KeyVal_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_utf8_(claim_quantity.Unit())); - rv[2] = KeyVal_.new_(Wdata_dict_value_quantity.Str_upperbound , String_.new_utf8_(claim_quantity.Ubound())); - rv[3] = KeyVal_.new_(Wdata_dict_value_quantity.Str_lowerbound , String_.new_utf8_(claim_quantity.Lbound())); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_monolingualtext(Wdata_claim_itm_core itm) { - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Key_type, Wdata_dict_value_monolingualtext.Str_language); - rv[1] = KeyVal_.new_(Key_value, Srl_claims_prop_itm_core_monolingualtext_value(itm)); - return rv; - } - private static KeyVal[] Srl_claims_prop_itm_core_monolingualtext_value(Wdata_claim_itm_core itm) { - Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)itm; - KeyVal[] rv = new KeyVal[2]; - rv[0] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_utf8_(claim_monolingualtext.Text())); - rv[1] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_utf8_(claim_monolingualtext.Lang())); - return rv; - } - private static final String Key_type = "type", Key_value = "value"; + public static final String Key_type = "type", Key_value = "value"; private static final KeyVal[] DataValue_nil = new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-Fran�ois_Malgaigne; DATE:2014-04-07 -} \ No newline at end of file +} diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java index fbd01f9a1..d25061d6b 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java @@ -233,7 +233,7 @@ public class Scrib_lib_wikibase_srl_tst { ); } @Test public void Claims_globecoordinate() { - fxt.Init_prop(fxt.Wdata_fxt().Make_claim_geo(2, "1.2345", "6.789")); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_geo(2, "6.789", "1.2345")); fxt.Test ( "claims:" , " P2:" diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_visitor.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_visitor.java new file mode 100644 index 000000000..379facd7e --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_visitor.java @@ -0,0 +1,94 @@ +/* +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 . +*/ +package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; +import gplx.xowa.xtns.wdatas.core.*; +class Scrib_lib_wikibase_srl_visitor implements Wdata_claim_visitor { + public KeyVal[] Rv() {return rv;} KeyVal[] rv; + public void Visit_str(Wdata_claim_itm_str itm) { + rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Xto_str(itm.Val_tid())); + rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, String_.new_utf8_(itm.Val_str())); + } + public void Visit_entity(Wdata_claim_itm_entity itm) { + rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_entity); + rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Entity_value(itm)); + } + private static KeyVal[] Entity_value(Wdata_claim_itm_core itm) { + Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)itm; + KeyVal[] rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Wdata_dict_value_entity.Str_entity_type, Wdata_dict_value_entity.Val_entity_type_item_str); + rv[1] = KeyVal_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.Xto_str(claim_entity.Entity_id())); + return rv; + } + public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) { + rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_value_monolingualtext.Str_language); + rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm)); + } + private static KeyVal[] Monolingualtext_value(Wdata_claim_itm_monolingualtext itm) { + KeyVal[] rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_utf8_(itm.Text())); + rv[1] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_utf8_(itm.Lang())); + return rv; + } public void Visit_quantity(Wdata_claim_itm_quantity itm) { + rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_quantity); + rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Quantity_value(itm)); + } + private static KeyVal[] Quantity_value(Wdata_claim_itm_quantity itm) { + KeyVal[] rv = new KeyVal[4]; + rv[0] = KeyVal_.new_(Wdata_dict_value_quantity.Str_amount , String_.new_utf8_(itm.Amount())); + rv[1] = KeyVal_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_utf8_(itm.Unit())); + rv[2] = KeyVal_.new_(Wdata_dict_value_quantity.Str_upperbound , String_.new_utf8_(itm.Ubound())); + rv[3] = KeyVal_.new_(Wdata_dict_value_quantity.Str_lowerbound , String_.new_utf8_(itm.Lbound())); + return rv; + } + public void Visit_time(Wdata_claim_itm_time itm) { + rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_time); + rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Time_value(itm)); + } + private static KeyVal[] Time_value(Wdata_claim_itm_time itm) { + KeyVal[] rv = new KeyVal[6]; + rv[0] = KeyVal_.new_(Wdata_dict_value_time.Str_time , String_.new_ascii_(itm.Time())); + rv[1] = KeyVal_.new_(Wdata_dict_value_time.Str_precision , Wdata_dict_value_time.Val_precision_int); // NOTE: must return int, not str; DATE:2014-02-18 + rv[2] = KeyVal_.new_(Wdata_dict_value_time.Str_before , Wdata_dict_value_time.Val_before_int); + rv[3] = KeyVal_.new_(Wdata_dict_value_time.Str_after , Wdata_dict_value_time.Val_after_int); + rv[4] = KeyVal_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); + rv[5] = KeyVal_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str); + return rv; + } + public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) { + rv = new KeyVal[2]; + rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_globecoordinate); + rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Globecoordinate_value(itm)); + } + private static KeyVal[] Globecoordinate_value(Wdata_claim_itm_globecoordinate itm) { + KeyVal[] rv = new KeyVal[5]; + rv[0] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse_(String_.new_ascii_(itm.Lat()))); + rv[1] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse_(String_.new_ascii_(itm.Lng()))); + rv[2] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_altitude , null); + rv[3] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_str); + rv[4] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_precision , .00001d); + return rv; + } + public void Visit_system(Wdata_claim_itm_system itm) { + rv = KeyVal_.Ary_empty; + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java index de21ab0e1..53a7bf9d3 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java @@ -26,6 +26,7 @@ public class Wdata_doc { } public Json_doc Jdoc() {return jdoc;} private Json_doc jdoc; public byte[] Qid() {return qid;} private byte[] qid; + public byte[][] Sort_langs() {return sort_langs;} public void Sort_langs_(byte[][] v) {sort_langs = v;} private byte[][] sort_langs = Bry_.Ary_empty; public OrderedHash Slink_list() {if (slink_list == null) slink_list = mgr.Wdoc_parser(jdoc).Parse_sitelinks(qid, jdoc); return slink_list;} private OrderedHash slink_list; public OrderedHash Label_list() {if (label_list == null) label_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.Y); return label_list;} private OrderedHash label_list; public OrderedHash Descr_list() {if (descr_list == null) descr_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return descr_list;} private OrderedHash descr_list; diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java index 78a02994c..c70dcb0df 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java @@ -30,7 +30,10 @@ public class Wdata_doc_bldr { } public Wdata_doc_bldr Add_description(String lang, String text) {byte[] key = Bry_.new_utf8_(lang); descr_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_utf8_(text))); return this;} public Wdata_doc_bldr Add_label(String lang, String text) {byte[] key = Bry_.new_utf8_(lang); label_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_utf8_(text))); return this;} - public Wdata_doc_bldr Add_sitelink(String site, String ttl) {byte[] key = Bry_.new_utf8_(site); slink_list.Add(key, new Wdata_sitelink_itm(key, Bry_.new_utf8_(ttl), Bry_.Ary_empty)); return this;} + public Wdata_doc_bldr Add_sitelink(String site, String link, String... bdgs) { + byte[] key = Bry_.new_utf8_(site); slink_list.Add(key, new Wdata_sitelink_itm(key, Bry_.new_utf8_(link), Bry_.Ary(bdgs))); + return this; + } public Wdata_doc_bldr Add_alias(String lang, String... ary){byte[] key = Bry_.new_utf8_(lang); alias_list.Add(key, new Wdata_alias_itm (key, Bry_.Ary(ary))); return this;} public Wdata_doc Xto_wdoc() { Wdata_doc rv = new Wdata_doc(qid, slink_list, label_list, descr_list, alias_list, claim_list); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_val_visitor.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_val_visitor.java new file mode 100644 index 000000000..dd4e69f5e --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_val_visitor.java @@ -0,0 +1,52 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import gplx.xowa.xtns.wdatas.core.*; +class Wdata_prop_val_visitor implements Wdata_claim_visitor { + private Wdata_wiki_mgr wdata_mgr; private Xoa_app app; private Bry_bfr bfr; private byte[] lang_key; + public Wdata_prop_val_visitor(Xoa_app app, Wdata_wiki_mgr wdata_mgr) {this.app = app; this.wdata_mgr = wdata_mgr;} + public void Init(Bry_bfr bfr, byte[] lang_key) {this.bfr = bfr; this.lang_key = lang_key;} + public void Visit_str(Wdata_claim_itm_str itm) {bfr.Add(itm.Val_str());} + public void Visit_time(Wdata_claim_itm_time itm) {bfr.Add(itm.Time());} + public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {bfr.Add(itm.Text());} // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28 + public void Visit_entity(Wdata_claim_itm_entity itm) { + Wdata_doc entity_doc = wdata_mgr.Pages_get(Bry_.Add(Byte_ascii.Ltr_q, itm.Entity_id_bry())); + if (entity_doc == null) return; // NOTE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01 + byte[] label = entity_doc.Label_list_get(lang_key); + if (label == null && !Bry_.Eq(lang_key, Xol_lang_.Key_en)) // NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19 + label = entity_doc.Label_list_get(Xol_lang_.Key_en); + if (label != null) // if label is still not found, don't add null reference + bfr.Add(label); + } + public void Visit_quantity(Wdata_claim_itm_quantity itm) { + byte[] amount_bry = itm.Amount(); + int val = Bry_.Xto_int_or(amount_bry, Ignore_comma, 0, amount_bry.length, 0); + Xol_lang lang = app.Lang_mgr().Get_by_key(lang_key); + bfr.Add(lang.Num_mgr().Format_num(val)); // amount; EX: 1,234 + bfr.Add(Bry_quantity_margin_of_error); // symbol: EX: ± + bfr.Add(itm.Unit()); // unit; EX: 1 + } + public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) { + bfr.Add(itm.Lat()); + bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space); + bfr.Add(itm.Lng()); + } + public void Visit_system(Wdata_claim_itm_system itm) {} + private static final byte[] Ignore_comma = new byte[]{Byte_ascii.Comma}; + private static final byte[] Bry_quantity_margin_of_error = Bry_.new_utf8_("±"); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java index 3bf074831..ac1ab3a3c 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java @@ -16,21 +16,26 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; import gplx.xowa.wikis.*; -import gplx.xowa.html.*; -import gplx.xowa.parsers.logs.*; import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*; -public class Wdata_wiki_mgr implements GfoInvkAble { - private Wdata_doc_parser wdoc_parser_v1, wdoc_parser_v2; +import gplx.json.*; import gplx.xowa.wikis.*; import gplx.xowa.html.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.apis.xowa.xtns.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.users.*; +import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.xtns.wdatas.pfuncs.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.hwtrs.*; +public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble { + private final Wdata_doc_parser wdoc_parser_v1, wdoc_parser_v2; + private final Wdata_prop_val_visitor prop_val_visitor; + private Wdata_hwtr_mgr hwtr_mgr; public Wdata_wiki_mgr(Xoa_app app) { this.app = app; + this.evMgr = GfoEvMgr.new_(this); wdoc_parser_v1 = new Wdata_doc_parser_v1(); wdoc_parser_v2 = new Wdata_doc_parser_v2(); doc_cache = app.Cache_mgr().Doc_cache(); + prop_val_visitor = new Wdata_prop_val_visitor(app, this); } private Xoa_app app; gplx.xowa.apps.caches.Wdata_doc_cache doc_cache; + public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr; public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true; public byte[] Domain() {return domain;} public void Domain_(byte[] v) {domain = v;} private byte[] domain = Bry_.new_ascii_("www.wikidata.org"); public Xow_wiki Wdata_wiki() {if (wdata_wiki == null) wdata_wiki = app.Wiki_mgr().Get_by_key_or_make(domain).Init_assert(); return wdata_wiki;} private Xow_wiki wdata_wiki; public Json_parser Jdoc_parser() {return jdoc_parser;} private Json_parser jdoc_parser = new Json_parser(); + public void Init_by_app() {} public Wdata_doc_parser Wdoc_parser(Json_doc jdoc) { Json_itm_kv itm_0 = Json_itm_kv.cast_(jdoc.Root().Subs_get_at(0)); // get 1st node return Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_type) ? wdoc_parser_v2 : wdoc_parser_v1; // if "type", must be v2 @@ -43,7 +48,7 @@ public class Wdata_wiki_mgr implements GfoInvkAble { doc_cache.Clear(); } private Hash_adp_bry qids_cache = Hash_adp_bry.cs_(), pids_cache = Hash_adp_bry.cs_(); public void Qids_add(Bry_bfr bfr, byte[] lang_key, byte wiki_tid, byte[] ns_num, byte[] ttl, byte[] qid) { - Xob_bz2_file.Build_alias_by_lang_tid(bfr, lang_key, wiki_tid_ref.Val_(wiki_tid)); + Xow_wiki_alias.Build_alias_by_lang_tid(bfr, lang_key, wiki_tid_ref.Val_(wiki_tid)); byte[] qids_key = bfr.Add_byte(Byte_ascii.Pipe).Add(ns_num).Add_byte(Byte_ascii.Pipe).Add(ttl).XtoAry(); qids_cache.Add(qids_key, qid); } @@ -129,58 +134,42 @@ public class Wdata_wiki_mgr implements GfoInvkAble { case Wdata_dict_snak_tid.Tid_novalue : bfr.Add(Wdata_dict_snak_tid.Bry_novalue); break; case Wdata_dict_snak_tid.Tid_somevalue : bfr.Add(Wdata_dict_snak_tid.Bry_somevalue); break; default: { - switch (prop.Val_tid()) { - case Wdata_dict_val_tid.Tid_string: - Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)prop; - bfr.Add(claim_str.Val_str()); - break; - case Wdata_dict_val_tid.Tid_time: - Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)prop; - bfr.Add(claim_time.Time()); - break; - case Wdata_dict_val_tid.Tid_entity: - Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)prop; - Wdata_doc entity_doc = Pages_get(Bry_.Add(Bry_q, claim_entity.Entity_id_bry())); - if (entity_doc == null) return; // NOTE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01 - byte[] label = entity_doc.Label_list_get(lang_key); - if (label == null && !Bry_.Eq(lang_key, Xol_lang_.Key_en)) // NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19 - label = entity_doc.Label_list_get(Xol_lang_.Key_en); - if (label != null) // if label is still not found, don't add null reference - bfr.Add(label); - break; - case Wdata_dict_val_tid.Tid_globecoordinate: { - Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)prop; - bfr.Add(claim_globecoordinate.Lat()); - bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space); - bfr.Add(claim_globecoordinate.Lng()); - break; - } - case Wdata_dict_val_tid.Tid_quantity: { - Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)prop; - byte[] amount_bry = claim_quantity.Amount(); - int val = Bry_.Xto_int_or(amount_bry, Ignore_comma, 0, amount_bry.length, 0); - Xol_lang lang = app.Lang_mgr().Get_by_key(lang_key); - bfr.Add(lang.Num_mgr().Format_num(val)); // amount; EX: 1,234 - bfr.Add(Bry_quantity_margin_of_error); // symbol: EX: ± - bfr.Add(claim_quantity.Unit()); // unit; EX: 1 - break; - } - case Wdata_dict_val_tid.Tid_monolingualtext: { // {{#property:monolingualprop}} -> some phrase (la) - Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)prop; - bfr.Add(claim_monolingualtext.Text()); // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28 - break; - } - default: throw Err_.unhandled(prop.Val_tid()); - } + prop_val_visitor.Init(bfr, lang_key); + prop.Welcome(prop_val_visitor); break; } } } } - private static final byte[] Ignore_comma = new byte[]{Byte_ascii.Comma}; - private static final byte[] Bry_quantity_margin_of_error = Bry_.new_utf8_("±"); public static final byte[] Bry_q = Bry_.new_ascii_("q"), Prop_tmpl_val_dlm = Bry_.new_ascii_(", "); - public void Write_json_as_html(Bry_bfr bfr, byte[] data_raw) {Write_json_as_html(jdoc_parser, bfr, data_raw);} + public byte[] Popup_text(Xoa_page page) { + Hwtr_mgr_assert(); + Wdata_doc wdoc = this.Pages_get_by_ttl_name(page.Ttl().Page_db()); + return hwtr_mgr.Popup(wdoc); + } + public void Write_json_as_html(Bry_bfr bfr, byte[] ttl_bry, byte[] data_raw) { + Hwtr_mgr_assert(); + Wdata_doc wdoc = this.Pages_get_by_ttl_name(ttl_bry); + hwtr_mgr.Init_by_wdoc(wdoc); + bfr.Add(hwtr_mgr.Write(wdoc)); + } + private void Hwtr_mgr_assert() { + if (hwtr_mgr != null) return; + Xoapi_toggle_mgr toggle_mgr = app.Api_root().Html().Page().Toggle_mgr(); + Xoapi_wikibase wikibase_api = app.Api_root().Xtns().Wikibase(); + hwtr_mgr = new Wdata_hwtr_mgr(); + hwtr_mgr.Init_by_ctor(wikibase_api, new Wdata_lbl_wkr_wiki(wikibase_api, this), app.Encoder_mgr().Href(), toggle_mgr, app.User().Wiki().Xwiki_mgr()); + this.Hwtr_msgs_make(); + GfoEvMgr_.SubSame_many(app.User(), this, Xou_user.Evt_lang_changed); + } + private void Hwtr_msgs_make() { + if (!app.Wiki_mgr().Wiki_regy().Has(Xow_wiki_domain_.Url_wikidata)) return; + Xol_lang new_lang = app.User().Lang(); + Xow_wiki cur_wiki = this.Wdata_wiki(); + cur_wiki.Xtn_mgr().Xtn_wikibase().Load_msgs(cur_wiki, new_lang); + Wdata_hwtr_msgs hwtr_msgs = Wdata_hwtr_msgs.new_(cur_wiki.Msg_mgr()); + hwtr_mgr.Init_by_lang(hwtr_msgs); + } public static void Write_json_as_html(Json_parser jdoc_parser, Bry_bfr bfr, byte[] data_raw) { bfr.Add(Xoh_consts.Span_bgn_open).Add(Xoh_consts.Id_atr).Add(Html_json_id).Add(Xoh_consts.__end_quote); // Json_doc json = jdoc_parser.Parse(data_raw); @@ -195,11 +184,12 @@ public class Wdata_wiki_mgr implements GfoInvkAble { return jdoc_parser.Parse(src); } public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { - if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled); - else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v"); - else if (ctx.Match(k, Invk_domain)) return String_.new_utf8_(domain); - else if (ctx.Match(k, Invk_domain_)) domain = m.ReadBry("v"); - else if (ctx.Match(k, Invk_property_wkr)) return m.ReadYnOrY("v") ? Property_wkr_or_new() : GfoInvkAble_.Null; + if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled); + else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v"); + else if (ctx.Match(k, Invk_domain)) return String_.new_utf8_(domain); + else if (ctx.Match(k, Invk_domain_)) domain = m.ReadBry("v"); + else if (ctx.Match(k, Invk_property_wkr)) return m.ReadYnOrY("v") ? Property_wkr_or_new() : GfoInvkAble_.Null; + else if (ctx.Match(k, Xou_user.Evt_lang_changed)) Hwtr_msgs_make(); else return GfoInvkAble_.Rv_unhandled; return this; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java index b1b7e0022..f3227e9ce 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java @@ -42,9 +42,12 @@ public class Wdata_wiki_mgr_fxt { public Wdata_claim_itm_core Make_claim_str(int pid, byte[] val) {return new Wdata_claim_itm_str(pid, Wdata_dict_snak_tid.Tid_value, val);} public Wdata_claim_itm_core Make_claim_time(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_time.Xto_time(val), Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty);} public Wdata_claim_itm_core Make_claim_monolingual(int pid, String lang, String text) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} - public Wdata_claim_itm_core Make_claim_geo(int pid, String lat, String lon) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(lat), Bry_.new_ascii_(lon), Bry_.Empty, Bry_.Empty, Bry_.Empty);} public Wdata_claim_itm_core Make_claim_quantity(int pid, String amount, String unit, String ubound, String lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(amount), Bry_.new_ascii_(unit), Bry_.new_ascii_(ubound), Bry_.new_ascii_(lbound));} public Wdata_claim_itm_core Make_claim_entity(int pid, int val) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Int_.Xto_bry(val));} + public Wdata_claim_itm_core Make_claim_geo(int pid, String lon, String lat) {return Make_claim_geo(pid, lon, lat, ".000277777", null, "Q2");} + public Wdata_claim_itm_core Make_claim_geo(int pid, String lon, String lat, String prc, String alt, String glb) { + return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(lat), Bry_.new_ascii_(lon), Bry_.new_ascii_(alt), Bry_.new_ascii_(prc), Bry_.new_ascii_(glb)); + } public Wdata_claim_grp Make_qualifiers_grp(int pid, Wdata_claim_itm_core... ary) {return new Wdata_claim_grp(Int_obj_ref.new_(pid), ary);} public Wdata_claim_grp_list Make_qualifiers(Wdata_claim_grp... ary) { Wdata_claim_grp_list rv = new Wdata_claim_grp_list(); @@ -168,7 +171,7 @@ public class Wdata_wiki_mgr_fxt { byte[] raw_bry = Bry_.new_ascii_(raw_str); raw_bry = gplx.json.Json_parser_tst.Replace_apos(raw_bry); Bry_bfr bfr = app.Utl_bry_bfr_mkr().Get_b512(); - wdata_mgr.Write_json_as_html(bfr, raw_bry); + Wdata_wiki_mgr.Write_json_as_html(wdata_mgr.Jdoc_parser(), bfr, raw_bry); Tfds.Eq(expd, bfr.Mkr_rls().XtoStrAndClear()); } } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xtn_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xtn_mgr.java new file mode 100644 index 000000000..9d0e3ef51 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xtn_mgr.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import gplx.html.*; import gplx.xowa.wikis.*; +public class Wdata_xtn_mgr extends Xox_mgr_base { + private static final String XTN_KEY_STR = "Wikibase"; public static final byte[] XTN_KEY = Bry_.new_ascii_(XTN_KEY_STR); + @Override public boolean Enabled_default() {return false;} + @Override public byte[] Xtn_key() {return XTN_KEY;} + @Override public Xox_mgr Clone_new() {return new Wdata_xtn_mgr();} + @Override public void Xtn_init_by_wiki(Xow_wiki wiki) { + if (!Enabled()) return; + } + public void Load_msgs(Xow_wiki wdata_wiki, Xol_lang lang) { + wdata_wiki.Msg_mgr().Lang_(lang); + Xtn_load_i18n(wdata_wiki, XTN_KEY_STR, "lib" , "i18n", lang.Key_str() + ".json"); + Xtn_load_i18n(wdata_wiki, XTN_KEY_STR, "repo", "i18n", lang.Key_str() + ".json"); + } + private static void Xtn_load_i18n(Xow_wiki wiki, String... nest_paths) { + Xoa_app app = wiki.App(); + Io_url url = app.Fsys_mgr().Bin_xtns_dir().GenSubFil_nest(nest_paths); + app.Bldr().I18n_parser().Load_msgs(false, wiki.Lang(), url); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_alias_itm.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_alias_itm.java index e61bf8ce5..165ec6dd1 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_alias_itm.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_alias_itm.java @@ -17,10 +17,12 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import gplx.json.*; -public class Wdata_alias_itm { +public class Wdata_alias_itm implements Wdata_lang_sortable { public Wdata_alias_itm(byte[] lang, byte[][] vals) {this.lang = lang; this.vals = vals;} public byte[] Lang() {return lang;} private byte[] lang; public byte[][] Vals() {return vals;} private byte[][] vals; + public byte[] Lang_code() {return lang;} + public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null; @Override public String toString() {// TEST: return String_.Concat_with_str("|", String_.new_utf8_(lang), String_.Concat_with_str("~", String_.Ary(vals))); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java index cf3da9f18..a8b589d2a 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public abstract class Wdata_claim_itm_base implements CompareAble { public Wdata_claim_itm_base Ctor(int pid, byte snak_tid) { this.pid = pid; @@ -26,6 +27,7 @@ public abstract class Wdata_claim_itm_base implements CompareAble { public abstract byte Val_tid(); public byte Snak_tid() {return snak_tid;} private byte snak_tid = Wdata_dict_snak_tid.Tid_value; public byte Rank_tid() {return rank_tid;} public void Rank_tid_(byte v) {this.rank_tid = v;} private byte rank_tid = Wdata_dict_rank.Tid_normal; // TEST: default to normal for tests + public abstract void Welcome(Wdata_claim_visitor visitor); public int compareTo(Object obj) { Wdata_claim_itm_base comp = (Wdata_claim_itm_base)obj; return Int_.Compare(pid, comp.pid); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java index e5c12ae9d..c92bd5211 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public abstract class Wdata_claim_itm_core extends Wdata_claim_itm_base { public byte[] Wguid() {return wguid;} public void Wguid_(byte[] v) {this.wguid = v;} private byte[] wguid; public String Prop_type() {return Prop_type_statement;} private static final String Prop_type_statement = "statement"; diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_entity.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_entity.java index 8f68998eb..eaf20ce28 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_entity.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_entity.java @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public class Wdata_claim_itm_entity extends Wdata_claim_itm_core { public Wdata_claim_itm_entity(int pid, byte snak_tid, byte[] entity_id_bry) { this.Ctor(pid, snak_tid); this.entity_id_bry = entity_id_bry; @@ -24,6 +25,7 @@ public class Wdata_claim_itm_entity extends Wdata_claim_itm_core { public Wdata @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_entity;} public byte[] Entity_id_bry() {return entity_id_bry;} private final byte[] entity_id_bry; public int Entity_id() {return entity_id;} private final int entity_id; + @Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_entity(this);} @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), Int_.Xto_str(entity_id)); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_globecoordinate.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_globecoordinate.java index 09be202a6..7d77bd0dd 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_globecoordinate.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_globecoordinate.java @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public class Wdata_claim_itm_globecoordinate extends Wdata_claim_itm_core { public Wdata_claim_itm_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) { this.Ctor(pid, snak_tid); this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb; @@ -25,8 +26,16 @@ public class Wdata_claim_itm_globecoordinate extends Wdata_claim_itm_core { pub public byte[] Lng() {return lng;} private final byte[] lng; public byte[] Alt() {return alt;} private final byte[] alt; public byte[] Prc() {return prc;} private final byte[] prc; + public DecimalAdp Prc_as_num() { + if (prc_as_num == null) + prc_as_num = Bry_.Eq(prc, null_bry) ? DecimalAdp_.One : DecimalAdp_.parse_(String_.new_ascii_(prc)); + return prc_as_num; + } private DecimalAdp prc_as_num; public byte[] Glb() {return glb;} private final byte[] glb; + public byte[] Glb_ttl() {return glb_ttl;} public void Glb_ttl_(byte[] v) {glb_ttl = v;} private byte[] glb_ttl; + @Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_globecoordinate(this);} @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(lat), String_.new_utf8_(lng), String_.new_utf8_(alt), String_.new_utf8_(prc), String_.new_utf8_(glb)); } + private static final byte[] null_bry = Bry_.new_ascii_("null"); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_monolingualtext.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_monolingualtext.java index dbed601a3..430d4e01c 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_monolingualtext.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_monolingualtext.java @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public class Wdata_claim_itm_monolingualtext extends Wdata_claim_itm_core { public Wdata_claim_itm_monolingualtext(int pid, byte snak_tid, byte[] lang, byte[] text) { this.Ctor(pid, snak_tid); this.lang = lang; this.text = text; @@ -23,6 +24,7 @@ public class Wdata_claim_itm_monolingualtext extends Wdata_claim_itm_core { pub @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_monolingualtext;} public byte[] Lang() {return lang;} private final byte[] lang; public byte[] Text() {return text;} private final byte[] text; + @Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_monolingualtext(this);} @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(lang), String_.new_utf8_(text)); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java index aa8c8ab52..867056f14 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java @@ -16,27 +16,29 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public class Wdata_claim_itm_quantity extends Wdata_claim_itm_core { public Wdata_claim_itm_quantity(int pid, byte snak_tid, byte[] amount, byte[] unit, byte[] ubound, byte[] lbound) { this.Ctor(pid, snak_tid); this.amount = amount; this.unit = unit; this.ubound = ubound; this.lbound = lbound; } @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_quantity;} public byte[] Amount() {return amount;} private final byte[] amount; - public long Amount_as_long() { - if (amount_as_long == Long_.MinValue) amount_as_long = Long_.parse_(String_.new_ascii_(amount)); - return amount_as_long; - } private long amount_as_long = Long_.MinValue; + public DecimalAdp Amount_as_num() { + if (amount_as_num == null) amount_as_num = DecimalAdp_.parse_(String_.new_ascii_(amount)); + return amount_as_num; + } private DecimalAdp amount_as_num; public byte[] Ubound() {return ubound;} private final byte[] ubound; - public long Ubound_as_long() { - if (ubound_as_long == Long_.MinValue) ubound_as_long = Long_.parse_(String_.new_ascii_(ubound)); - return ubound_as_long; - } private long ubound_as_long = Long_.MinValue; + public DecimalAdp Ubound_as_num() { + if (ubound_as_num == null) ubound_as_num = DecimalAdp_.parse_(String_.new_ascii_(ubound)); + return ubound_as_num; + } private DecimalAdp ubound_as_num; public byte[] Lbound() {return lbound;} private final byte[] lbound; - public long Lbound_as_long() { - if (lbound_as_long == Long_.MinValue) lbound_as_long = Long_.parse_(String_.new_ascii_(lbound)); - return lbound_as_long; - } private long lbound_as_long = Long_.MinValue; + public DecimalAdp Lbound_as_num() { + if (lbound_as_num == null) lbound_as_num = DecimalAdp_.parse_(String_.new_ascii_(lbound)); + return lbound_as_num; + } private DecimalAdp lbound_as_num; public byte[] Unit() {return unit;} private final byte[] unit; + @Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_quantity(this);} @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(amount), String_.new_utf8_(unit), String_.new_utf8_(ubound), String_.new_utf8_(lbound)); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java index e8f90c718..f974a832d 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java @@ -16,12 +16,14 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public class Wdata_claim_itm_str extends Wdata_claim_itm_core { public Wdata_claim_itm_str(int pid, byte snak_tid, byte[] val) { this.Ctor(pid, snak_tid); this.val = val; } @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_string;} public byte[] Val_str() {return val;} private final byte[] val; + @Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_str(this);} @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(val)); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_system.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_system.java index ede593b21..ebe086e26 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_system.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_system.java @@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.hwtrs.*; public class Wdata_claim_itm_system extends Wdata_claim_itm_core { public Wdata_claim_itm_system(int pid, byte val_tid, byte snak_tid) { this.Ctor(pid, snak_tid); this.val_tid = val_tid; @@ -24,6 +25,7 @@ public class Wdata_claim_itm_system extends Wdata_claim_itm_core { public Wdata @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid())); } + @Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_system(this);} public static Wdata_claim_itm_system new_novalue(int pid) {return new Wdata_claim_itm_system(pid, Wdata_dict_val_tid.Tid_unknown , Wdata_dict_snak_tid.Tid_novalue);} public static Wdata_claim_itm_system new_somevalue(int pid) {return new Wdata_claim_itm_system(pid, Wdata_dict_val_tid.Tid_unknown , Wdata_dict_snak_tid.Tid_somevalue);} } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java index 330667730..792c57e13 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java @@ -16,9 +16,10 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_claim_itm_time(int pid, byte snak_tid, byte[] time, byte[] timezone, byte[] before, byte[] after, byte[] precision, byte[] calendarmodel) { +import gplx.xowa.xtns.wdatas.hwtrs.*; +public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_claim_itm_time(int pid, byte snak_tid, byte[] time, byte[] timezone, byte[] before, byte[] after, byte[] precision, byte[] calendar) { this.Ctor(pid, snak_tid); - this.time = time; this.before = before; this.after = after; this.precision = precision; this.calendarmodel = calendarmodel; + this.time = time; this.before = before; this.after = after; this.precision = precision; this.calendar = calendar; } @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_time;} public byte[] Time() {return time;} private final byte[] time; @@ -29,8 +30,17 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c public byte[] Before() {return before;} private final byte[] before; public byte[] After() {return after;} private final byte[] after; public byte[] Precision() {return precision;} private final byte[] precision; - public byte[] Calendarmodel() {return calendarmodel;} private final byte[] calendarmodel; + public int Precision_int() { + if (precision_int == Int_.MinValue) + precision_int = Bry_.Xto_int_or(precision, Wdata_date.Fmt_ymdhns); + return precision_int; + } private int precision_int = Int_.MinValue; + public byte[] Calendar() {return calendar;} private final byte[] calendar; + public byte[] Calendar_ttl() {return calendar_ttl;} public void Calendar_ttl_(byte[] v) {calendar_ttl = v;} private byte[] calendar_ttl; + public boolean Calendar_is_julian() {return Bry_.Eq(calendar, Calendar_julian);} @Override public String toString() {// TEST: - return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(time), String_.new_utf8_(before), String_.new_utf8_(after), String_.new_utf8_(precision), String_.new_utf8_(calendarmodel)); + return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(time), String_.new_utf8_(before), String_.new_utf8_(after), String_.new_utf8_(precision), String_.new_utf8_(calendar)); } + @Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_time(this);} + private static final byte[] Calendar_julian = Bry_.new_ascii_("http://www.wikidata.org/entity/Q1985786"); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_visitor.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_visitor.java new file mode 100644 index 000000000..e2dbbd9a4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_visitor.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public interface Wdata_claim_visitor { + void Visit_str(Wdata_claim_itm_str itm); + void Visit_entity(Wdata_claim_itm_entity itm); + void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm); + void Visit_quantity(Wdata_claim_itm_quantity itm); + void Visit_time(Wdata_claim_itm_time itm); + void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm); + void Visit_system(Wdata_claim_itm_system itm); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date.java index 4364da1e5..023db500f 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date.java @@ -40,4 +40,82 @@ public class Wdata_date { int second = Bry_.Xto_int_or(bry, year_end + 13, year_end + 15, -1); return new Wdata_date(year * year_sign, month, day, hour, minute, second); } + public static Wdata_date Xto_julian(Wdata_date date) { + int a = (int)Math_.Floor((14 - date.Month() / 12)); + int y = (int)date.Year() + 4800 - a; + int m = date.Month() + 12 * a - 3; + int julian = date.Day() + (int)Math_.Floor((153 * m + 2) / 5) + 365 * y + (int)Math_.Floor(y / 4) - (int)Math_.Floor(y / 100) + (int)Math_.Floor(y / 400) - 32045; + int c = julian + 32082; + int d = (int)Math_.Floor((4 * c + 3) / 1461); + int e = c - (int)Math_.Floor((1461 * d) / 4); + int n = (int)Math_.Floor((5 * e + 2) / 153); + int new_y = d - 4800 + (int)Math_.Floor(n / 10); + int new_m = n + 3 - 12 * (int)Math_.Floor(n / 10); + int new_d = e - (int)Math_.Floor((153 * n + 2) / 5) + 1; + return new Wdata_date(new_y, new_m, new_d, date.Hour(), date.Minute(), date.Second()); + } + public static void Xto_str(Bry_bfr bfr, Wdata_date date, int precision, byte[][] months, int months_bgn, byte[] dt_spr, byte[] time_spr) { + long year = date.Year(); + switch (precision) { + case Wdata_date.Fmt_ym: // EX: "Feb 2001" + bfr.Add(months[months_bgn + date.Month() - ListAdp_.Base1]); + bfr.Add_byte_space(); + bfr.Add_long_variable(year); + break; + case Wdata_date.Fmt_ymd: // EX: "3 Feb 2001" + bfr.Add_int_variable(date.Day()); + bfr.Add_byte_space(); + bfr.Add(months[months_bgn + date.Month() - ListAdp_.Base1]); + bfr.Add_byte_space(); + bfr.Add_long_variable(date.Year()); + break; + case Wdata_date.Fmt_ymdh: // EX: "4:00 3 Feb 2011" + bfr.Add_int_variable(date.Hour()); + bfr.Add(time_spr); + bfr.Add_int_fixed(0, 2); + bfr.Add_byte_space(); + bfr.Add_int_variable(date.Day()); + bfr.Add_byte_space(); + bfr.Add(months[months_bgn + date.Month() - ListAdp_.Base1]); + bfr.Add_byte_space(); + bfr.Add_long_variable(date.Year()); + break; + case Wdata_date.Fmt_ymdhn: // EX: "4:05 3 Feb 2011" + bfr.Add_int_variable(date.Hour()); + bfr.Add(time_spr); + bfr.Add_int_fixed(date.Minute(), 2); + bfr.Add_byte_space(); + bfr.Add_int_variable(date.Day()); + bfr.Add_byte_space(); + bfr.Add(months[months_bgn + date.Month() - ListAdp_.Base1]); + bfr.Add_byte_space(); + bfr.Add_long_variable(date.Year()); + break; + default: + if (precision <= 9) // y, round to (9 - prec) + bfr.Add_long_variable(date.Year()); + else { // EX: "4:05:06 3 Feb 2011" + bfr.Add_int_variable(date.Hour()); + bfr.Add(time_spr); + bfr.Add_int_fixed(date.Minute(), 2); + bfr.Add(time_spr); + bfr.Add_int_fixed(date.Second(), 2); + bfr.Add_byte_space(); + bfr.Add_int_variable(date.Day()); + bfr.Add_byte_space(); + bfr.Add(months[months_bgn + date.Month() - ListAdp_.Base1]); + bfr.Add_byte_space(); + bfr.Add_long_variable(date.Year()); + } + break; + } + } + public static final int + Fmt_y = 9 + , Fmt_ym = 10 + , Fmt_ymd = 11 + , Fmt_ymdh = 12 + , Fmt_ymdhn = 13 + , Fmt_ymdhns = 14 // anything >13 ? + ; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date_tst.java index b2c1eb99f..605342efa 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date_tst.java @@ -24,8 +24,23 @@ public class Wdata_date_tst { fxt.Test_parse("+00000002001-02-03T04:05:06Z", 2001, 2, 3, 4, 5, 6); fxt.Test_parse("-98765432109-02-03T04:05:06Z", -98765432109L, 2, 3, 4, 5, 6); } + @Test public void Julian() { + fxt.Test_julian(Int_.Ary(1600, 1, 2), Int_.Ary(1600, 1, 18)); + } + @Test public void Xto_str() { + String date = "+00000002001-02-03T04:05:06Z;"; + fxt.Test_xto_str(date, Wdata_date.Fmt_ym , "Feb 2001"); + fxt.Test_xto_str(date, Wdata_date.Fmt_ymd , "3 Feb 2001"); + fxt.Test_xto_str(date, Wdata_date.Fmt_ymdh , "4:00 3 Feb 2001"); + fxt.Test_xto_str(date, Wdata_date.Fmt_ymdhn , "4:05 3 Feb 2001"); + fxt.Test_xto_str(date, Wdata_date.Fmt_ymdhns , "4:05:06 3 Feb 2001"); + fxt.Test_xto_str(date, 0 , "2001"); + } } class Wdata_date_fxt { + private Bry_bfr tmp_bfr = Bry_bfr.new_(16); + private static final byte[][] months_ary = Bry_.Ary("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); + private static final byte[] dt_spr = Byte_ascii.Space_bry, time_spr = Byte_ascii.Colon_bry; public void Test_parse(String raw, long expd_y, int expd_m, int expd_d, int expd_h, int expd_n, int expd_s) { Wdata_date actl_date = Wdata_date.parse(Bry_.new_ascii_(raw)); Tfds.Eq(expd_y, actl_date.Year()); @@ -35,4 +50,16 @@ class Wdata_date_fxt { Tfds.Eq(expd_n, actl_date.Minute()); Tfds.Eq(expd_s, actl_date.Second()); } + public void Test_julian(int[] orig_ary, int[] expd) { + Wdata_date orig = new Wdata_date(orig_ary[0], orig_ary[1], orig_ary[2], 0, 0, 0); + Wdata_date actl = Wdata_date.Xto_julian(orig); + Tfds.Eq(expd[0], (int)actl.Year(), "y"); + Tfds.Eq(expd[1], actl.Month(), "m"); + Tfds.Eq(expd[2], actl.Day(), "d"); + } + public void Test_xto_str(String raw, int precision, String expd) { + Wdata_date date = Wdata_date.parse(Bry_.new_ascii_(raw)); + Wdata_date.Xto_str(tmp_bfr, date, precision, months_ary, 0, dt_spr, time_spr); + Tfds.Eq(expd, tmp_bfr.XtoStrAndClear()); + } } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sortable.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_lang_sortable.java similarity index 88% rename from 400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sortable.java rename to 400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_lang_sortable.java index 629e6b7b2..9c77dd642 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sortable.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_lang_sortable.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -public interface Wdata_sortable { - byte[] Lang(); - int Sort(); void Sort_(int v); +public interface Wdata_lang_sortable { + byte[] Lang_code(); + int Lang_sort(); void Lang_sort_(int v); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_lang_sorter.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_lang_sorter.java new file mode 100644 index 000000000..9bb9d7e09 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_lang_sorter.java @@ -0,0 +1,83 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.apis.xowa.xtns.*; +public class Wdata_lang_sorter implements GfoEvObj, gplx.lists.ComparerAble { + private Hash_adp_bry hash = Hash_adp_bry.cs_(); + public Wdata_lang_sorter() {evMgr = GfoEvMgr.new_(this);} + public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr; + public byte[][] Langs() {return langs;} private byte[][] langs; + public void Langs_(byte[][] langs) { + this.langs = langs; + hash.Clear(); + int len = langs.length; + for (int i = 0; i < len; ++i) { + byte[] lang = langs[i]; + Wdata_lang_sorter_itm itm = new Wdata_lang_sorter_itm(i, lang); + hash.Add_if_new(lang, itm); + } + } + public int compare(Object lhsObj, Object rhsObj) { + Wdata_lang_sortable lhs = (Wdata_lang_sortable)lhsObj; + Wdata_lang_sortable rhs = (Wdata_lang_sortable)rhsObj; + int lhs_lang_sort = lhs.Lang_sort(), rhs_lang_sort = rhs.Lang_sort(); + if (lhs_lang_sort != Sort_none || rhs_lang_sort != Sort_none) // one of the items has a lang order + return Int_.Compare(lhs_lang_sort, rhs_lang_sort); // sort by defined lang order + else + return Bry_.Compare(lhs.Lang_code(), rhs.Lang_code()); // sort by alphabetical + } + public void Init_by_wdoc(Wdata_doc wdoc) { + if ((Bry_.Ary_eq(wdoc.Sort_langs(), langs))) return; + wdoc.Sort_langs_(langs); + Sort_wdoc_list(Bool_.Y, wdoc.Slink_list()); + Sort_wdoc_list(Bool_.N, wdoc.Label_list()); + Sort_wdoc_list(Bool_.N, wdoc.Descr_list()); + Sort_wdoc_list(Bool_.N, wdoc.Alias_list()); + } + private void Sort_wdoc_list(boolean is_slink, OrderedHash list) { + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_lang_sortable itm = (Wdata_lang_sortable)list.FetchAt(i); + if (is_slink) { + Wdata_sitelink_itm slink = (Wdata_sitelink_itm)itm; + byte[] lang_val = slink.Domain_info().Lang_orig_key(); // use orig, not cur; EX: simplewiki has orig of "simple" but lang of "en" + if (Bry_.Len_eq_0(lang_val)) lang_val = slink.Site(); // unknown lang; EX: "xyzwiki" -> ""; make site = lang, else "" lang will sort towards top of list; PAGE:wd.q:20 DATE:2014-10-03 + slink.Lang_(lang_val); + } + itm.Lang_sort_(Sort_calc(itm)); + } + } + private int Sort_calc(Wdata_lang_sortable data_itm) { + Wdata_lang_sorter_itm sort_itm = (Wdata_lang_sorter_itm)hash.Fetch(data_itm.Lang_code()); + int new_sort = sort_itm == null ? Sort_none : sort_itm.Sort(); + data_itm.Lang_sort_(new_sort); + return new_sort; + } + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Xoapi_wikibase.Evt_sort_langs_changed)) Langs_((byte[][])m.ReadObj("v", ParseAble_.Null)); + else return GfoInvkAble_.Rv_unhandled; + return this; + } + public static final int Sort_null = Int_.MinValue; + private static final int Sort_none = Int_.MaxValue; +} +class Wdata_lang_sorter_itm { + public Wdata_lang_sorter_itm(int sort, byte[] lang) {this.sort = sort; this.lang = lang;} + public int Sort() {return sort;} private final int sort; + public byte[] Lang() {return lang;} private final byte[] lang; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java index f96e7cea8..776aaf111 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java @@ -17,12 +17,26 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import gplx.json.*; -public class Wdata_langtext_itm implements Wdata_sortable { - public Wdata_langtext_itm(byte[] lang, byte[] text) {this.lang = lang; this.text = text; this.sort = -1;} - public byte[] Lang() {return lang;} private final byte[] lang; +public class Wdata_langtext_itm implements Wdata_lang_sortable { + public Wdata_langtext_itm(byte[] lang, byte[] text) {this.lang = lang; this.text = text;} + public byte[] Lang() {return lang;} private final byte[] lang; public byte[] Text() {return text;} private final byte[] text; - public int Sort() {return sort;} public void Sort_(int v) {sort = v;} private int sort; + public byte[] Lang_code() {return lang;} + public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null; @Override public String toString() {// TEST: return String_.Concat_with_str("|", String_.new_utf8_(lang), String_.new_utf8_(text)); } + public static byte[] Get_text_or_empty(OrderedHash list, byte[][] langs) { + Wdata_langtext_itm itm = Get_itm_or_null(list, langs); + return itm == null ? Bry_.Empty : itm.Text(); + } + public static Wdata_langtext_itm Get_itm_or_null(OrderedHash list, byte[][] langs) { + if (list == null) return null; + int langs_len = langs.length; + for (int i = 0; i < langs_len; ++i) { + Object itm_obj = list.Fetch(langs[i]); + if (itm_obj != null) return (Wdata_langtext_itm)itm_obj; + } + return null; + } } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sitelink_itm.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sitelink_itm.java index 67209d431..e6ec721b9 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sitelink_itm.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sitelink_itm.java @@ -16,12 +16,16 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; -public class Wdata_sitelink_itm { +import gplx.json.*; import gplx.xowa.wikis.*; +public class Wdata_sitelink_itm implements Wdata_lang_sortable { public Wdata_sitelink_itm(byte[] site, byte[] name, byte[][] badges) {this.site = site; this.name = name; this.badges = badges;} public byte[] Site() {return site;} private final byte[] site; public byte[] Name() {return name;} private final byte[] name; public byte[][] Badges() {return badges;} private final byte[][] badges; + public byte[] Lang() {return lang;} public void Lang_(byte[] v) {lang = v;} private byte[] lang = Bry_.Empty; + public byte[] Lang_code() {return lang;} + public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null; + public Xow_wiki_domain Domain_info() {if (domain_info == null) domain_info = Xow_wiki_alias.parse_by_wmf_key(site); return domain_info;} private Xow_wiki_domain domain_info; @Override public String toString() {// TEST: return String_.Concat_with_str("|", String_.new_utf8_(site), String_.new_utf8_(name), String_.Concat_with_str(",", String_.Ary(badges))); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__claim.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__claim.java new file mode 100644 index 000000000..2216ef8d7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__claim.java @@ -0,0 +1,285 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.apis.xowa.html.*; +class Wdata_fmtr__claim_grp implements Bry_fmtr_arg { + private Wdata_fmtr__claim_tbl fmtr_tbl = new Wdata_fmtr__claim_tbl(); private boolean is_empty; + private Xoapi_toggle_itm toggle_itm; + private Wdata_toc_data toc_data; + public void Init_by_ctor(Wdata_toc_data toc_data, Xoapi_toggle_mgr toggle_mgr, Wdata_lbl_mgr lbl_mgr) {this.toc_data = toc_data; this.toggle_itm = toggle_mgr.Get_or_new("wikidatawiki-claim"); fmtr_tbl.Init_by_ctor(lbl_mgr);} + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + toc_data.Orig_(msgs.Claim_tbl_hdr()); + toggle_itm.Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n()); + fmtr_tbl.Init_by_lang(msgs); + } + public void Init_by_wdoc(byte[] ttl, OrderedHash list) { + int list_count = list.Count(); + this.is_empty = list.Count() == 0; if (is_empty) return; + toc_data.Make(list_count); + fmtr_tbl.Init_by_wdoc(ttl, list); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (is_empty) return; + fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), fmtr_tbl); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "

~{hdr_text}~{toggle_btn}

" + , "
" + , "
" + , "
" + , "
~{tbls}" + , "
" + , "
" + , "
" + , "
" + ), "hdr_href", "hdr_text", "toggle_btn", "toggle_hdr", "tbls"); +} +class Wdata_fmtr__claim_tbl implements Bry_fmtr_arg { + private Wdata_fmtr__claim_row fmtr_row = new Wdata_fmtr__claim_row(); private Wdata_lbl_mgr lbl_mgr; + private OrderedHash list; private byte[] ttl; + public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr; fmtr_row.Init_by_ctor(lbl_mgr);} + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + fmtr_row.Init_by_lang(msgs); + } + public void Init_by_wdoc(byte[] ttl, OrderedHash list) { + this.list = list; + this.ttl = ttl; + } + public void XferAry(Bry_bfr bfr, int idx) { + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_claim_grp grp = (Wdata_claim_grp)list.FetchAt(i); + if (grp.Len() == 0) continue; // NOTE: group will be empty when claims are empty; EX: "claims": []; PAGE:wd.p:585; DATE:2014-10-03 + int pid = grp.Id(); + byte[] pid_lbl = lbl_mgr.Get_text__pid(pid); + fmtr_row.Init_by_grp(ttl, grp); + fmtr.Bld_bfr_many(bfr, pid, pid_lbl, fmtr_row); + } + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
" + , "
~{itms}" + , "
" + , "
" + , "
" + , " P~{pid} - ~{pid_lbl}" + , "
" + , "
" + , "
" + ), "pid", "pid_lbl", "itms"); +} +class Wdata_fmtr__claim_row implements Bry_fmtr_arg { + private byte[] ttl; + private Wdata_visitor__html_wtr claim_html_wtr = new Wdata_visitor__html_wtr(); + private Wdata_fmtr__qual_tbl fmtr_qual = new Wdata_fmtr__qual_tbl(); + private Wdata_fmtr__ref_tbl fmtr_ref = new Wdata_fmtr__ref_tbl(); + private Wdata_lbl_mgr lbl_mgr; private Wdata_hwtr_msgs msgs; + private Wdata_claim_grp claim_grp; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) { + this.lbl_mgr = lbl_mgr; + fmtr_qual.Init_by_ctor(lbl_mgr); + fmtr_ref.Init_by_ctor(lbl_mgr); + } + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + this.msgs = msgs; + fmtr_qual.Init_by_lang(msgs); + fmtr_ref.Init_by_lang(msgs); + } + public void Init_by_grp(byte[] ttl, Wdata_claim_grp claim_grp) { + this.ttl = ttl; this.claim_grp = claim_grp; + } + public void XferAry(Bry_bfr bfr, int idx) { + int len = claim_grp.Len(); + claim_html_wtr.Init(ttl, tmp_bfr, msgs, lbl_mgr); + for (int i = 0; i < len; ++i) { + Wdata_claim_itm_core itm = claim_grp.Get_at(i); + itm.Welcome(claim_html_wtr); + byte[] val = tmp_bfr.XtoAryAndClear(); + fmtr_qual.Init_by_claim(ttl, itm); + fmtr_ref.Init_by_claim(ttl, itm); + row_fmtr.Bld_bfr_many(bfr, Wdata_dict_rank.Xto_str(itm.Rank_tid()), val, fmtr_qual, fmtr_ref); + } + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
" + , "
" + , "
" + , " " + , "
" + , "
" + , "
" // omit -Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e + , "
" + , "
" + , "
" + , "
" + , "
" + , "
" + , "
" + , "
~{value}" + , "
" + , "
" + , "
" + , "
~{qualifiers}" + , "
~{references}" + , "
" + ), "rank_name", "value", "qualifiers", "references" + ); +} +class Wdata_fmtr__qual_tbl implements Bry_fmtr_arg { + private Wdata_fmtr__qual_row fmtr_row = new Wdata_fmtr__qual_row(); private Wdata_claim_itm_core claim; + public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {fmtr_row.Init_by_ctor(lbl_mgr);} + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + fmtr_row.Init_by_lang(msgs); + } + public void Init_by_claim(byte[] ttl, Wdata_claim_itm_core claim) { + this.claim = claim; + fmtr_row.Init_by_grp(ttl, claim.Qualifiers()); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (claim.Qualifiers() == null || claim.Qualifiers().Len() == 0) return; + fmtr.Bld_bfr_many(bfr, fmtr_row); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
" + , "
~{itms}" + , "
" + , "
" + ), "itms"); +} +class Wdata_fmtr__qual_row implements Bry_fmtr_arg { + private byte[] ttl; private Wdata_visitor__html_wtr claim_html_wtr = new Wdata_visitor__html_wtr(); + private Wdata_lbl_mgr lbl_mgr; private Wdata_hwtr_msgs msgs; + private Wdata_claim_grp_list quals; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr;} + public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.msgs = msgs;} + public void Init_by_grp(byte[] ttl, Wdata_claim_grp_list quals) {this.ttl = ttl; this.quals = quals;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = quals.Len(); + claim_html_wtr.Init(ttl, tmp_bfr, msgs, lbl_mgr); + for (int i = 0; i < len; ++i) { + Wdata_claim_grp grp = quals.Get_at(i); + int grp_len = grp.Len(); + for (int j = 0; j < grp_len; ++j) { + Wdata_claim_itm_core itm = grp.Get_at(j); + itm.Welcome(claim_html_wtr); + byte[] val = tmp_bfr.XtoAryAndClear(); + row_fmtr.Bld_bfr_many(bfr, grp.Id(), lbl_mgr.Get_text__pid(grp.Id()), val); + } + } + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
" + , "
" + , "
" + , "
" + , "
" + , " ~{pid_lbl}" + , "
" + , "
" + , "
" + , "
" + , "
~{value}" + , "
" + , "
" + , "
" + , "
" + , "
" + ), "pid", "pid_lbl", "value" + ); +} +class Wdata_fmtr__ref_tbl implements Bry_fmtr_arg { + private Wdata_fmtr__ref_row fmtr_row = new Wdata_fmtr__ref_row(); private Wdata_claim_itm_core claim; + public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {fmtr_row.Init_by_ctor(lbl_mgr);} + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + fmtr_row.Init_by_lang(msgs); + } + public void Init_by_claim(byte[] ttl, Wdata_claim_itm_core claim) { + this.claim = claim; + fmtr_row.Init_by_grp(ttl, claim.References()); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (claim.References() == null) return; + fmtr.Bld_bfr_many(bfr, fmtr_row); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" +// , "
1 reference
" + , "
" + , "
" + , "
" // OMIT: wb-referenceview-8e7d51e38606193465d2a1e9d41ba490e06682a6 + , "
" + , "
" + , "
" + , "
~{itms}" + , "
" + , "
" + , "
" + , "
" + , "
" + , "
" + ), "itms"); +} +class Wdata_fmtr__ref_row implements Bry_fmtr_arg { + private byte[] ttl; private Wdata_visitor__html_wtr claim_html_wtr = new Wdata_visitor__html_wtr(); + private Wdata_lbl_mgr lbl_mgr; private Wdata_hwtr_msgs msgs; + private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + private Wdata_references_grp[] ref_grps; + public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr;} + public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.msgs = msgs;} + public void Init_by_grp(byte[] ttl, Wdata_references_grp[] ref_grps) {this.ttl = ttl; this.ref_grps = ref_grps;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = ref_grps.length; + claim_html_wtr.Init(ttl, tmp_bfr, msgs, lbl_mgr); + for (int i = 0; i < len; ++i) { + Wdata_references_grp grp_itm = ref_grps[i]; + Wdata_claim_grp_list grp = grp_itm.References(); + int grp_len = grp.Len(); + for (int j = 0; j < grp_len; ++j) { + Wdata_claim_grp grp2 = grp.Get_at(j); + int grp2_len = grp2.Len(); + for (int k = 0; k < grp2_len; ++k) { + Wdata_claim_itm_core itm = grp2.Get_at(k); + itm.Welcome(claim_html_wtr); + byte[] val = tmp_bfr.XtoAryAndClear(); + row_fmtr.Bld_bfr_many(bfr, grp2.Id(), lbl_mgr.Get_text__pid(grp2.Id()), val); + } + } + } + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
" + , "
" + , "
" + , " ~{pid_lbl}" + , "
" + , "
" + , "
" + , "
" + , "
~{value}" + , "
" + , "
" + , "
" + ), "pid", "pid_lbl", "value" + ); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__json.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__json.java index 111b875d3..204e22ac6 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__json.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__json.java @@ -16,24 +16,31 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; +import gplx.json.*; import gplx.xowa.html.*; import gplx.xowa.apis.xowa.html.*; class Wdata_fmtr__json implements Bry_fmtr_arg { - private byte[] tbl_hdr; private Json_doc jdoc; private Json_parser jdoc_parser; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); - public void Init_by_ctor(Json_parser jdoc_parser) {this.jdoc_parser = jdoc_parser;} - public void Init_by_lang(byte[] tbl_hdr) {this.tbl_hdr = tbl_hdr;} - public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, Json_doc jdoc) { - fmtr_toc.Add(tbl_hdr); + private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + private Xoapi_toggle_itm toggle_itm; private Wdata_toc_data toc_data; private Json_doc jdoc; + public void Init_by_ctor(Wdata_toc_data toc_data, Xoapi_toggle_mgr toggle_mgr) { + this.toc_data = toc_data.Itms_len_enable_n_(); + this.toggle_itm = toggle_mgr.Get_or_new("wikidatawiki-json").Html_toggle_hdr_cls_(Bry_.new_ascii_("overflow:auto;")); + } + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + toc_data.Orig_(msgs.Json_div_hdr()); + toggle_itm.Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n()); + } + public void Init_by_wdoc(Json_doc jdoc) { this.jdoc = jdoc; + toc_data.Make(0); } public void XferAry(Bry_bfr bfr, int idx) { - if (jdoc == null) return; - Wdata_wiki_mgr.Write_json_as_html(jdoc_parser, tmp_bfr, jdoc.Src()); - fmtr.Bld_bfr_many(bfr, tbl_hdr, tmp_bfr.XtoAryAndClear()); + if (jdoc == null) return; // TEST: wdoc doesn't have jdoc + jdoc.Root().Print_as_json(tmp_bfr, 0); + fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), tmp_bfr.XtoAryAndClear()); } - private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last ( "" - , "

~{hdr}

" - , "" - , "~{json}" - ), "hdr", "json"); + , "

~{hdr_text}~{toggle_btn}

" + , " ~{json}" + , " " + ), "hdr_href", "hdr_text", "toggle_btn", "toggle_hdr", "json"); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__langtext.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__langtext.java new file mode 100644 index 000000000..0262eea9b --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__langtext.java @@ -0,0 +1,119 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.html.*; import gplx.xowa.wikis.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.apis.xowa.html.*; +class Wdata_fmtr__langtext_tbl implements Bry_fmtr_arg { + private Wdata_toc_data toc_data; private Wdata_lang_sorter lang_sorter; private Xoapi_toggle_itm toggle_itm; private Wdata_fmtr__langtext_row fmtr_row; + private byte[] col_hdr_lang_name, col_hdr_lang_code, col_hdr_text; private int list_len; + public void Init_by_ctor(Wdata_toc_data toc_data, Wdata_lang_sorter lang_sorter, Xoapi_toggle_mgr toggle_mgr, String toggle_itm_key, Wdata_fmtr__langtext_row fmtr_row) { + this.toc_data = toc_data; this.lang_sorter = lang_sorter; this.fmtr_row = fmtr_row; + this.toggle_itm = toggle_mgr.Get_or_new(toggle_itm_key); + } + public void Init_by_lang(Wdata_hwtr_msgs msgs, byte[] tbl_hdr, byte[] col_hdr_text) { + this.col_hdr_lang_name = msgs.Langtext_col_lang_name(); this.col_hdr_lang_code = msgs.Langtext_col_lang_code(); this.col_hdr_text = col_hdr_text; + toc_data.Orig_(tbl_hdr); + toggle_itm.Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n()); + } + public void Init_by_wdoc(OrderedHash list) { + this.list_len = list.Count(); if (list_len == 0) return; + toc_data.Make(list_len); + list.SortBy(lang_sorter); + fmtr_row.Init_by_page(list); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (list_len == 0) return; + fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), col_hdr_lang_name, col_hdr_lang_code, col_hdr_text, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), fmtr_row); + } + private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
" + , "
" + , "

~{hdr_text}~{toggle_btn}

" + , "
" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " ~{rows}" + , " " + , "
~{hdr_lang_name}~{hdr_lang_code}~{hdr_page}
" + , "
" + ), "hdr_href", "hdr_text", "hdr_lang_name", "hdr_lang_code", "hdr_page", "toggle_btn", "toggle_hdr", "rows" + ); +} +interface Wdata_fmtr__langtext_row extends Bry_fmtr_arg { + void Init_by_page(OrderedHash list); +} +class Wdata_fmtr__langtext_row_base implements Wdata_fmtr__langtext_row { + private OrderedHash list; + public void Init_by_page(OrderedHash list) {this.list = list;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_langtext_itm itm = (Wdata_langtext_itm)list.FetchAt(i); + Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(itm.Lang()); + row_fmtr.Bld_bfr_many(bfr, itm.Lang(), Html_utl.Escape_html_as_bry(lang_itm.Local_name()), Html_utl.Escape_html_as_bry(itm.Text())); + } + } + private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " ~{lang_name}" + , " ~{lang_code}" + , " ~{text}" + , " " + ), "lang_code", "lang_name", "text" + ); +} +class Wdata_fmtr__alias_row implements Wdata_fmtr__langtext_row { + private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private OrderedHash list; + public void Init_by_page(OrderedHash list) {this.list = list;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_alias_itm itm = (Wdata_alias_itm)list.FetchAt(i); + byte[][] vals_ary = itm.Vals(); + int vals_len = vals_ary.length; + for (int j = 0; j < vals_len; ++j) { + byte[] val = vals_ary[j]; + if (j != 0) tmp_bfr.Add(Html_tag_.Br_inl); + tmp_bfr.Add(Html_utl.Escape_html_as_bry(val)); + } + Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(itm.Lang()); + row_fmtr.Bld_bfr_many(bfr, lang_itm.Key(), Html_utl.Escape_html_as_bry(lang_itm.Local_name()), tmp_bfr.XtoAryAndClear()); + } + } + private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " ~{lang_name}" + , " ~{lang_code}" + , " ~{text}" + , " " + ), "lang_code", "lang_name", "text" + ); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__oview.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__oview.java new file mode 100644 index 000000000..9a9f6863b --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__oview.java @@ -0,0 +1,100 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.apis.xowa.xtns.*; +class Wdata_fmtr__oview_tbl implements Bry_fmtr_arg { + private Xoapi_wikibase wikibase_api; private Url_encoder href_encoder; + private Wdata_fmtr__oview_alias_itm fmtr_aliases = new Wdata_fmtr__oview_alias_itm(); + private Bry_fmtr slink_fmtr = Bry_fmtr.new_("~{page_text}", "domain_bry", "page_href", "page_text"); + private Bry_bfr tmp_bfr = Bry_bfr.new_(255); + private Wdata_doc wdoc; + private byte[] hdr_alias_y, hdr_alias_n; + public void Init_by_ctor(Xoapi_wikibase wikibase_api, Url_encoder href_encoder) {this.wikibase_api = wikibase_api; this.href_encoder = href_encoder;} + public void Init_by_lang(byte[] lang_0, Wdata_hwtr_msgs msgs) { + this.hdr_alias_y = msgs.Oview_alias_y(); + this.hdr_alias_n = msgs.Oview_alias_n(); + } + public void Init_by_wdoc(Wdata_doc wdoc) { + this.wdoc = wdoc; + } + public void XferAry(Bry_bfr bfr, int idx) { + byte[][] core_langs = wikibase_api.Core_langs(); + byte[] oview_label = Wdata_langtext_itm.Get_text_or_empty(wdoc.Label_list(), core_langs); + byte[] oview_descr = Wdata_langtext_itm.Get_text_or_empty(wdoc.Descr_list(), core_langs); + byte[][] oview_alias = Alias_get_or_empty(wdoc.Alias_list(), core_langs); + byte[] aliases_hdr = oview_alias == Bry_.Ary_empty ? hdr_alias_n : hdr_alias_y; + fmtr_aliases.Init_by_itm(oview_alias); + Wdata_sitelink_itm slink = (Wdata_sitelink_itm)wdoc.Slink_list().Fetch(wikibase_api.Link_wikis()); + if (slink != null) { + oview_label = slink_fmtr.Bld_bry_many(tmp_bfr, slink.Domain_info().Domain_bry(), href_encoder.Encode(slink.Name()), oview_label); + } + row_fmtr.Bld_bfr_many(bfr, wdoc.Qid(), oview_label, oview_descr, aliases_hdr, fmtr_aliases); + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "

" + , "
" + , "
" + , " ~{ttl_label}" + , " (~{ttl})" + , "
" + , "
" + , "

" + , "
" + , "
" + , " ~{ttl_descr}" + , "
" + , "
" + , "
" + , "
" + , "
" + , " ~{hdr_aliases}" + , "
    ~{ttl_aliases}" + , "
" + , "
" + , "
" + ), "ttl", "ttl_label", "ttl_descr", "hdr_aliases", "ttl_aliases" + ); + private static byte[][] Alias_get_or_empty(OrderedHash list, byte[][] langs) { + if (list == null) return Bry_.Ary_empty; + int langs_len = langs.length; + for (int i = 0; i < langs_len; ++i) { + Object itm_obj = list.Fetch(langs[i]); + if (itm_obj != null) { + Wdata_alias_itm itm = (Wdata_alias_itm)itm_obj; + return itm.Vals(); + } + } + return Bry_.Ary_empty; + } +} +class Wdata_fmtr__oview_alias_itm implements Bry_fmtr_arg { + private byte[][] ary; + public void Init_by_itm(byte[][] ary) {this.ary = ary;} + public void XferAry(Bry_bfr bfr, int idx) { + if (ary == null) return; + int len = ary.length; + for (int i = 0; i < len; ++i) + row_fmtr.Bld_bfr_many(bfr, ary[i]); + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
  • ~{itm}
  • " + ), "itm" + ); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__sitelink_tbl.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__sitelink_tbl.java deleted file mode 100644 index 676fc9e84..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__sitelink_tbl.java +++ /dev/null @@ -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 . -*/ -package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.html.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.wikis.*; -class Wdata_fmtr__sitelink_tbl implements Bry_fmtr_arg { - private Wdata_fmtr__sitelink_row fmtr_row = new Wdata_fmtr__sitelink_row(); - private Wdata_hwtr_msgs msgs; private byte[] col_hdr_lang, col_hdr_text, col_hdr_bdgs; private int list_len; - public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {fmtr_row.Init_by_ctor(lbl_regy);} - public void Init_by_lang(Wdata_hwtr_msgs msgs) { - this.col_hdr_lang = msgs.Slink_col_hdr_site(); this.col_hdr_text = msgs.Slink_col_hdr_text(); this.col_hdr_bdgs = msgs.Slink_col_hdr_bdgs(); - this.msgs = msgs; - } - public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, OrderedHash list) { - this.list_len = list.Count(); if (list_len == 0) return; - fmtr_toc.Add(msgs.Slink_tbl_hdr()); - fmtr_row.Init_by_page(list); - } - public void XferAry(Bry_bfr bfr, int idx) { - if (list_len == 0) return; - fmtr.Bld_bfr_many(bfr, msgs.Slink_tbl_hdr(), col_hdr_lang, col_hdr_text, col_hdr_bdgs, fmtr_row); - } - private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , "

    ~{hdr}

    " - , "" - , "" - , " " - , " " - , " " - , " " - , " ~{rows}" - , "
    ~{site_lbl}~{link_lbl}~{bdgs_lbl}
    " - ), "hdr", "site_lbl", "link_lbl", "bdgs_lbl", "rows" - ); -} -class Wdata_fmtr__sitelink_row implements Wdata_fmtr__row { - private Wdata_lbl_mgr lbl_regy; private OrderedHash list; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); - public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {this.lbl_regy = lbl_regy;} - public void Init_by_page(OrderedHash list) {this.list = list;} - public void XferAry(Bry_bfr bfr, int idx) { - lbl_regy.getClass(); - int len = list.Count(); - for (int i = 0; i < len; ++i) { - Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i); - byte[] site = itm.Site(); - byte[] domain_bry = Xob_bz2_file.Parse__domain_name(site, 0, site.length); - byte[][] badges_ary = itm.Badges(); - int badges_len = badges_ary.length; - for (int j = 0; j < badges_len; ++j) { - byte[] val = badges_ary[j]; - if (j != 0) tmp_bfr.Add(Html_tag_.Br_inl); - tmp_bfr.Add(Html_utl.Escape_html_as_bry(val)); - } - row_fmtr.Bld_bfr_many(bfr, site, domain_bry, itm.Name()); - } - } - private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , " " - , " ~{site}" - , " ~{page}" - , " " - ), "site", "domain", "page" - ); -} -// class Wdata_slink_grp { -// public Wdata_slink_grp(int tid, byte[] tbl_hdr) {this.tid = tid; this.tbl_hdr = tbl_hdr;} -// public int Tid() {return tid;} private final int tid; -// public byte[] Tbl_hdr() {return tbl_hdr;} private final byte[] tbl_hdr; -// public OrderedHash Rows() {return rows;} private final OrderedHash rows = OrderedHash_.new_(); -// public static Wdata_slink_grp[] new_(OrderedHash list) { -// ListAdp rv = ListAdp_.new_(); -// int list_len = list.Count(); -// for (int i = 0; i < list_len; ++i) { -// Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i); -// byte[] site = itm.Site(); -// byte[] domain = Xob_bz2_file.Parse__domain_name(site, 0, site.length); -// Xow_wiki_domain domain_tid = Xow_wiki_domain_.parse_by_domain(domain); -// domain_tid.Tid -// } -//// ListAdp list -//// int grps_len = 0; -//// OrderedHash[] grps = new OrderedHash[grps_len]; -// // sort by tid -// // iterate and add to list -// return (Wdata_slink_grp[])rv.XtoAryAndClear(typeof(ListAdp)); -// } -// // , Tid_wikipedia = 2, Tid_wiktionary = 3, Tid_wikisource = 4, Tid_wikibooks = 5, Tid_wikiversity = 6, Tid_wikiquote = 7, Tid_wikinews = 8, Tid_wikivoyage = 9, Tid_commons = 10 -// } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__slink.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__slink.java new file mode 100644 index 000000000..3038c3ef2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__slink.java @@ -0,0 +1,173 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.html.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.wikis.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*; +class Wdata_fmtr__slink_grp implements Bry_fmtr_arg { + private final Wdata_fmtr__slink_tbl fmtr_tbl = new Wdata_fmtr__slink_tbl(); private boolean is_empty; + public void Init_by_ctor(Wdata_lang_sorter lang_sorter, Xoapi_toggle_mgr toggle_mgr, Wdata_lbl_mgr lbl_regy, Url_encoder href_encoder, Wdata_fmtr__toc_div fmtr_toc, Xow_xwiki_mgr xwiki_mgr) { + fmtr_tbl.Init_by_ctor(lang_sorter, toggle_mgr, lbl_regy, href_encoder, fmtr_toc, xwiki_mgr); + } + public void Init_by_lang(Wdata_hwtr_msgs msgs) {fmtr_tbl.Init_by_lang(msgs);} + public void Init_by_wdoc(OrderedHash list) { + this.is_empty = list.Count() == 0; if (is_empty) return; + fmtr_tbl.Init_by_wdoc(list); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (is_empty) return; + fmtr.Bld_bfr_many(bfr, fmtr_tbl); + } + private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "
    ~{grps}" + , "
    " + , "
    " + ), "grps" + ); +} +class Wdata_fmtr__slink_tbl implements Bry_fmtr_arg { + private final Wdata_fmtr__slink_row fmtr_row = new Wdata_fmtr__slink_row(); + private final Wdata_slink_grp[] grps = new Wdata_slink_grp[Wdata_slink_grp.Idx__len]; + private Wdata_lang_sorter lang_sorter; private Wdata_hwtr_msgs msgs; + public void Init_by_ctor(Wdata_lang_sorter lang_sorter, Xoapi_toggle_mgr toggle_mgr, Wdata_lbl_mgr lbl_regy, Url_encoder href_encoder, Wdata_fmtr__toc_div fmtr_toc, Xow_xwiki_mgr xwiki_mgr) { + this.lang_sorter = lang_sorter; + fmtr_row.Init_by_ctor(lbl_regy, href_encoder, xwiki_mgr); + for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) { + byte[] wiki_name = Wdata_slink_grp.Name_by_tid(i); + String toggle_itm_key = "wikidatawiki-slink-" + String_.new_ascii_(wiki_name); + Xoapi_toggle_itm toggle_itm = toggle_mgr.Get_or_new(toggle_itm_key); + Wdata_toc_data toc_data = new Wdata_toc_data(fmtr_toc, href_encoder); + grps[i] = new Wdata_slink_grp(i, wiki_name, toggle_itm, toc_data); + } + } + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + this.msgs = msgs; + for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) { + Wdata_slink_grp grp = grps[i]; + grp.Toc_data().Orig_(Wdata_slink_grp.Msg_by_tid(msgs, i)); + grp.Toggle_itm().Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n()); + } + } + public void Init_by_wdoc(OrderedHash list) { + Wdata_slink_grp.Sift(grps, list); + for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) { + Wdata_slink_grp grp = grps[i]; + int itms_count = grp.Rows().Count(); + if (itms_count == 0) continue; + grp.Toc_data().Make(itms_count); + grp.Rows().SortBy(lang_sorter); + } + } + public void XferAry(Bry_bfr bfr, int idx) { + for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) { + Wdata_slink_grp grp = grps[i]; + if (grp.Rows().Count() == 0) continue; + fmtr_row.Init_by_page(grp.Rows()); + Xoapi_toggle_itm toggle_itm = grp.Toggle_itm(); + fmtr.Bld_bfr_many(bfr, grp.Toc_data().Href(), grp.Toc_data().Text(), msgs.Langtext_col_lang_name(), msgs.Langtext_col_lang_code(), msgs.Slink_col_hdr_text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), fmtr_row); + } + } + private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "
    " + , "

    ~{hdr_text}~{toggle_btn}

    " + , "
    " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " ~{rows}" + , " " + , "
    ~{hdr_lang}~{hdr_wiki}~{hdr_page}
    " + , "
    " + ), "hdr_href", "hdr_text", "hdr_lang", "hdr_wiki", "hdr_page", "toggle_btn", "toggle_hdr", "rows" + ); +} +class Wdata_fmtr__slink_row implements Bry_fmtr_arg { + private final Wdata_fmtr__slink_badges fmtr_badges = new Wdata_fmtr__slink_badges(); private Xow_xwiki_mgr xwiki_mgr; + private Url_encoder href_encoder; private OrderedHash list; + public void Init_by_ctor(Wdata_lbl_mgr lbl_regy, Url_encoder href_encoder, Xow_xwiki_mgr xwiki_mgr) { + this.href_encoder = href_encoder; this.xwiki_mgr = xwiki_mgr; + fmtr_badges.Init_by_ctor(lbl_regy); + } + public void Init_by_page(OrderedHash list) {this.list = list;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i); + Xow_wiki_domain domain_info = itm.Domain_info(); + byte[] wmf_key = domain_info.Wmf_key(); + Xol_lang_itm lang_itm = domain_info.Lang_itm(); + byte[] lang_key = lang_itm.Key(); + byte[] lang_name = lang_itm.Local_name(); + byte[] domain_bry = domain_info.Domain_bry(); + byte[] page_name = itm.Name(); + fmtr_badges.Init_by_itm(itm.Badges()); + byte[] href_site = xwiki_mgr.Get_by_key(domain_bry) == null ? Href_site_http : Href_site_xowa; + fmtr_row.Bld_bfr_many(bfr, lang_name, lang_key, wmf_key, href_site, domain_bry, href_encoder.Encode(page_name), Html_utl.Escape_html_as_bry(itm.Name()), fmtr_badges); + } + } + private static final byte[] Href_site_xowa = Bry_.new_ascii_("/site/"), Href_site_http = Bry_.new_ascii_("https://"); + private final Bry_fmtr fmtr_row = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , " " // wikibase-sitelinkview-~{wmf_key} data-wb-siteid='~{wmf_key}' + , " ~{lang_name}" // wikibase-sitelinkview-sitename-~{wmf_key} + , " ~{wmf_key}" // wikibase-sitelinkview-siteid-~{wmf_key} + , " " // wikibase-sitelinkview-link-~{wmf_key} + , " ~{badges}" + , " " + , " " + , " ~{page_name}" + , " " + , " " + , " " + ), "lang_name", "lang_code", "wmf_key", "href_site", "href_domain", "href_page", "page_name", "badges" + ); +} +class Wdata_fmtr__slink_badges implements Bry_fmtr_arg { + private Wdata_lbl_mgr lbl_regy; private byte[][] badges; + public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {this.lbl_regy = lbl_regy;} + public void Init_by_itm(byte[][] badges) {this.badges = badges;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = badges.length; + for (int i = 0; i < len; ++i) { + byte[] ttl = badges[i]; + Wdata_lbl_itm lbl = lbl_regy.Get_itm__ttl(ttl); + byte[] name = Bry_.Empty, cls = Bry_.Empty; + if (lbl != null) { + name = lbl.Text(); + cls = Bry_.Replace(lbl.Text_en(), Byte_ascii.Space_bry, Bry_.Empty); // NOTE: use Text_en; "featured article" -> "featuredarticle"; same for "good article" -> "goodarticle" + } + fmtr_row.Bld_bfr_many(bfr, ttl, cls, name); + } + } + private final Bry_fmtr fmtr_row = Bry_fmtr.new_ + ( "\n " + , "ttl", "cls", "name" + ); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc.java new file mode 100644 index 000000000..e291fc279 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc.java @@ -0,0 +1,77 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +class Wdata_fmtr__toc_div implements Bry_fmtr_arg { + private final ListAdp itms = ListAdp_.new_(); private final Wdata_fmtr__toc_itm fmtr_itm = new Wdata_fmtr__toc_itm(); + private byte[] tbl_hdr; + public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.tbl_hdr = msgs.Toc_tbl_hdr();} + public void Init_by_wdoc(Wdata_doc wdoc) {itms.Clear();} + public void Add(Wdata_toc_data toc_data) {itms.Add(toc_data);} + public void XferAry(Bry_bfr bfr, int idx) { + int itms_len = itms.Count(); + if (itms_len <= gplx.xowa.html.tocs.Xow_hdr_mgr.Toc_min) return; + fmtr_itm.Init_by_itm((Wdata_toc_data[])itms.XtoAryAndClear(Wdata_toc_data.class)); + fmtr.Bld_bfr_many(bfr, tbl_hdr, fmtr_itm); + } + private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "
    " + , "

    ~{hdr}

    " + , "
    " + , "
      ~{itms}" + , "
    " + , "
    " + ), "hdr", "itms"); +} +class Wdata_fmtr__toc_itm implements Bry_fmtr_arg { + private Wdata_toc_data[] ary; + public void Init_by_itm(Wdata_toc_data[] v) {this.ary = v;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = ary.length; + for (int i = 0; i < len; ++i) { + Wdata_toc_data itm = ary[i]; + fmtr.Bld_bfr_many(bfr, i + ListAdp_.Base1, itm.Href(), itm.Text()); + } + } + private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "
  • " + , " " + , " ~{text}" + , " " + , "
  • " + ), "idx", "href", "text"); +} +class Wdata_toc_data { + private final Wdata_fmtr__toc_div fmtr_toc; + private final Url_encoder href_encoder; + private final Bry_fmtr text_fmtr = Bry_fmtr.new_("~{orig} (~{len})", "orig", "len"); + private final Bry_bfr tmp_bfr = Bry_bfr.new_(8); + public Wdata_toc_data(Wdata_fmtr__toc_div fmtr_toc, Url_encoder href_encoder) {this.fmtr_toc = fmtr_toc; this.href_encoder = href_encoder;} + public Wdata_toc_data Make(int itms_len) { + this.text = itms_len_enable ? text_fmtr.Bld_bry_many(tmp_bfr, orig, itms_len) : orig; + this.href = href_encoder.Encode(orig); + fmtr_toc.Add(this); + return this; + } + public Wdata_toc_data Itms_len_enable_n_() {itms_len_enable = false; return this;} private boolean itms_len_enable = true; + public byte[] Orig() {return orig;} public void Orig_(byte[] v) {orig = v;} private byte[] orig; + public byte[] Href() {return href;} private byte[] href; + public byte[] Text() {return text;} private byte[] text; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc_div.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc_div.java deleted file mode 100644 index 9cc019d9d..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc_div.java +++ /dev/null @@ -1,57 +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 . -*/ -package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -class Wdata_fmtr__toc_div implements Bry_fmtr_arg { - private Wdata_fmtr__toc_itm fmtr_itm = new Wdata_fmtr__toc_itm(); - private byte[] tbl_hdr; private ListAdp itms = ListAdp_.new_(); - public void Init_by_ctor(Url_encoder href_encoder) {fmtr_itm.Init_by_ctor(href_encoder);} - public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.tbl_hdr = msgs.Toc_tbl_hdr();} - public void Init_by_wdoc(Wdata_doc wdoc) {itms.Clear();} - public void Add(byte[] hdr) {itms.Add(hdr);} - public void XferAry(Bry_bfr bfr, int idx) { - int itms_len = itms.Count(); - if (itms_len < 3) return; - fmtr_itm.Init_by_page((byte[][])itms.XtoAryAndClear(byte[].class)); - fmtr.Bld_bfr_many(bfr, tbl_hdr, fmtr_itm); - } - private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , "

    " - , "

    " - , "

    ~{hdr}

    " - , "
      ~{itms}" - , "
    " - , " " - ), "hdr", "itms"); -} -class Wdata_fmtr__toc_itm implements Bry_fmtr_arg { - private byte[][] hdrs; private Url_encoder href_encoder; - public void Init_by_ctor(Url_encoder href_encoder) {this.href_encoder = href_encoder;} - public void Init_by_page(byte[][] hdrs) {this.hdrs = hdrs;} - public void XferAry(Bry_bfr bfr, int idx) { - int len = hdrs.length; - for (int i = 0; i < len; ++i) { - byte[] hdr = hdrs[i]; - fmtr.Bld_bfr_many(bfr, i + ListAdp_.Base1, href_encoder.Encode(hdr), hdr); - } - } - private Bry_fmtr fmtr = Bry_fmtr.new_ - ( "
  • ~{idx} ~{hdr}
  • " - , "idx", "href", "text"); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtrs.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtrs.java deleted file mode 100644 index 62d0825a1..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtrs.java +++ /dev/null @@ -1,216 +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 . -*/ -package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.html.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; -import gplx.xowa.wikis.*; -interface Wdata_fmtr__row extends Bry_fmtr_arg { - void Init_by_page(OrderedHash list); -} -class Wdata_fmtr__langtext_tbl implements Bry_fmtr_arg { - private Wdata_fmtr__row fmtr_row; - private byte[] tbl_hdr, col_hdr_lang, col_hdr_text; private int list_len; - public void Init_by_ctor(Wdata_fmtr__row fmtr_row) {this.fmtr_row = fmtr_row;} - public void Init_by_lang(byte[] tbl_hdr, byte[] col_hdr_lang, byte[] col_hdr_text) { - this.tbl_hdr = tbl_hdr; this.col_hdr_lang = col_hdr_lang; this.col_hdr_text = col_hdr_text; - } - public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, OrderedHash list) { - this.list_len = list.Count(); if (list_len == 0) return; - fmtr_toc.Add(tbl_hdr); - fmtr_row.Init_by_page(list); - } - public void XferAry(Bry_bfr bfr, int idx) { - if (list_len == 0) return; - fmtr.Bld_bfr_many(bfr, tbl_hdr, col_hdr_lang, col_hdr_text, fmtr_row); - } - private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , "

    ~{hdr}

    " - , "" - , "" - , " " - , " " - , " " - , " ~{rows}" - , "
    ~{lang_lbl}~{text_lbl}
    " - ), "hdr", "lang_lbl", "text_lbl", "rows"); -} -class Wdata_fmtr__langtext_row implements Wdata_fmtr__row { - private OrderedHash list; - public void Init_by_page(OrderedHash list) {this.list = list;} - public void XferAry(Bry_bfr bfr, int idx) { - int len = list.Count(); - for (int i = 0; i < len; ++i) { - Wdata_langtext_itm itm = (Wdata_langtext_itm)list.FetchAt(i); - row_fmtr.Bld_bfr_many(bfr, itm.Lang(), Html_utl.Escape_html_as_bry(itm.Text())); - } - } - private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , " " - , " ~{lang}" - , " ~{text}" - , " " - ), "lang", "text"); -} -class Wdata_fmtr__alias_row implements Wdata_fmtr__row { - private OrderedHash list; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); - public void Init_by_page(OrderedHash list) {this.list = list;} - public void XferAry(Bry_bfr bfr, int idx) { - int len = list.Count(); - for (int i = 0; i < len; ++i) { - Wdata_alias_itm itm = (Wdata_alias_itm)list.FetchAt(i); - byte[][] vals_ary = itm.Vals(); - int vals_len = vals_ary.length; - for (int j = 0; j < vals_len; ++j) { - byte[] val = vals_ary[j]; - if (j != 0) tmp_bfr.Add(Html_tag_.Br_inl); - tmp_bfr.Add(Html_utl.Escape_html_as_bry(val)); - } - row_fmtr.Bld_bfr_many(bfr, itm.Lang(), tmp_bfr.XtoAryAndClear()); - } - } - private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , " " - , " ~{lang}" - , " ~{text}" - , " " - ), "lang", "text"); -} -class Wdata_fmtr__claim_tbl implements Bry_fmtr_arg { - public Wdata_fmtr__claim_row Fmtr_row() {return fmtr_row;} private Wdata_fmtr__claim_row fmtr_row = new Wdata_fmtr__claim_row(); private int list_len; - private byte[] tbl_hdr, col_hdr_prop_id, col_hdr_prop_name, col_hdr_val, col_hdr_ref, col_hdr_qual, col_hdr_rank; - public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {fmtr_row.Init_by_ctor(lbl_regy);} - public void Init_by_lang(Wdata_hwtr_msgs msgs, byte[] tbl_hdr, byte[] col_hdr_prop_id, byte[] col_hdr_prop_name, byte[] col_hdr_val, byte[] col_hdr_ref, byte[] col_hdr_qual, byte[] col_hdr_rank) { - fmtr_row.Init_by_lang(msgs); - this.tbl_hdr = tbl_hdr; this.col_hdr_prop_id = col_hdr_prop_id; this.col_hdr_prop_name = col_hdr_prop_name; - this.col_hdr_val = col_hdr_val; this.col_hdr_ref = col_hdr_ref; this.col_hdr_qual = col_hdr_qual; this.col_hdr_rank = col_hdr_rank; - } - public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, OrderedHash list) { - this.list_len = list.Count(); if (list_len == 0) return; - fmtr_toc.Add(tbl_hdr); - fmtr_row.Init_by_page(list); - } - public void XferAry(Bry_bfr bfr, int idx) { - if (list_len == 0) return; - fmtr.Bld_bfr_many(bfr, tbl_hdr, col_hdr_prop_id, col_hdr_prop_name, col_hdr_val, col_hdr_ref, col_hdr_qual, col_hdr_rank, fmtr_row); - } - private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , "

    ~{hdr}

    " - , "" - , "" - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " ~{rows}" - , "
    ~{prop_id}~{prop_name}~{val}~{ref}~{qual}~{rank}
    " - ), "hdr", "prop_id", "prop_name", "val", "ref", "qual", "rank", "rows"); -} -class Wdata_fmtr__claim_row implements Wdata_fmtr__row { - private Wdata_lbl_mgr lbl_regy; private Wdata_hwtr_msgs msgs; - private OrderedHash list; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); - public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {this.lbl_regy = lbl_regy;} - public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.msgs = msgs;} - public void Init_by_page(OrderedHash list) {this.list = list;} - public void XferAry(Bry_bfr bfr, int idx) { - lbl_regy.getClass(); - int len = list.Count(); - for (int i = 0; i < len; ++i) { - Wdata_claim_grp grp = (Wdata_claim_grp)list.FetchAt(i); - int grp_len = grp.Len(); - for (int j = 0; j < grp_len; ++j) { - Wdata_claim_itm_core itm = grp.Get_at(j); - byte[] val = Calc_val(itm); - byte[] pid_name = lbl_regy.Pid_regy().Get_text_or_empty(itm.Pid()); - row_fmtr.Bld_bfr_many(bfr, itm.Pid(), pid_name, val, "", "", Wdata_dict_rank.Xto_str(itm.Rank_tid())); - } - } - } - public byte[] Calc_val(Wdata_claim_itm_core itm) { - switch (itm.Val_tid()) { - case Wdata_dict_val_tid.Tid_string: - return ((Wdata_claim_itm_str)itm).Val_str(); - case Wdata_dict_val_tid.Tid_monolingualtext: - Wdata_claim_itm_monolingualtext monolingual = (Wdata_claim_itm_monolingualtext)itm; - tmp_bfr.Add_byte(Byte_ascii.Brack_bgn).Add(monolingual.Lang()).Add_byte(Byte_ascii.Brack_end).Add_byte(Byte_ascii.Space); - tmp_bfr.Add(monolingual.Text()); - return tmp_bfr.XtoAryAndClear(); - case Wdata_dict_val_tid.Tid_time: - Wdata_claim_itm_time time = (Wdata_claim_itm_time)itm; - Wdata_date date = time.Time_as_date(); - tmp_bfr.Add_long_variable(date.Year()); - tmp_bfr.Add_byte(Byte_ascii.Dash) .Add_int_fixed(date.Month() , 2); - tmp_bfr.Add_byte(Byte_ascii.Dash) .Add_int_fixed(date.Day() , 2); - tmp_bfr.Add_byte(Byte_ascii.Space) .Add_int_fixed(date.Hour() , 2); - tmp_bfr.Add_byte(Byte_ascii.Colon) .Add_int_fixed(date.Minute(), 2); - tmp_bfr.Add_byte(Byte_ascii.Colon) .Add_int_fixed(date.Second(), 2); - return tmp_bfr.XtoAryAndClear(); - case Wdata_dict_val_tid.Tid_quantity: - Wdata_claim_itm_quantity quantity = (Wdata_claim_itm_quantity)itm; - long amount = quantity.Amount_as_long(); - long ubound = quantity.Ubound_as_long(); - long lbound = quantity.Lbound_as_long(); - long udiff = ubound - amount; - long ldiff = amount - lbound; - tmp_bfr.Add(quantity.Amount()).Add_byte_space(); - if (udiff == ldiff) { // delta is same in both directions; EX: amount=50 ubound=60 lbound=40 -> udiff == ldiff == 10 - if (udiff != 0) // skip if 0 - tmp_bfr.Add(msgs.Sym_plusminus()).Add_long_variable(udiff); - } - else { // delta is diff in both directions; EX: amount=50 ubound=60 lbound=30 -> udiff == 10, ldiff == 20 - if (udiff != 0) // skip if 0 - tmp_bfr.Add(msgs.Sym_plus()).Add_long_variable(udiff); - if (ldiff != 0) { // skip if 0 - if (udiff != 0) tmp_bfr.Add(Time_plus_minus_spr); - tmp_bfr.Add(msgs.Sym_minus()).Add_long_variable(ldiff); - } - } - byte[] unit = quantity.Unit(); - if (!Bry_.Eq(unit, Wdata_claim_itm_quantity.Unit_1)) - tmp_bfr.Add_byte_space().Add(unit); - return tmp_bfr.XtoAryAndClear(); - case Wdata_dict_val_tid.Tid_globecoordinate: - case Wdata_dict_val_tid.Tid_bad: - // Wdata_claim_itm_globecoordinate globecoordinate = (Wdata_claim_itm_globecoordinate)itm; - break; - case Wdata_dict_val_tid.Tid_entity: - Wdata_claim_itm_entity entity = (Wdata_claim_itm_entity)itm; - return lbl_regy.Qid_regy().Get_text_or_empty(entity.Entity_id()); - case Wdata_dict_val_tid.Tid_unknown: - return Wdata_dict_val_tid.Bry_unknown; - } - return null; - } private static final byte[] Time_plus_minus_spr = Bry_.new_ascii_(" / "); - private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last - ( "" - , " " - , " ~{prop_id}" - , " ~{prop_name}" - , " ~{val}" - , " ~{ref}" - , " ~{qual}" - , " ~{rank}" - , " " - ), "prop_id", "prop_name", "val", "ref", "qual", "rank" - ); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr.java index 2f586c417..fd5db842b 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr.java @@ -16,50 +16,74 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.json.*; +import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.xtns.*; public class Wdata_hwtr_mgr { private final Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_mb); @gplx.Internal protected Wdata_fmtr__toc_div Fmtr_toc() {return fmtr_toc;} private final Wdata_fmtr__toc_div fmtr_toc = new Wdata_fmtr__toc_div(); @gplx.Internal protected Wdata_fmtr__json Fmtr_json() {return fmtr_json;} private final Wdata_fmtr__json fmtr_json = new Wdata_fmtr__json(); - @gplx.Internal protected Wdata_fmtr__claim_tbl Fmtr_claim() {return fmtr_claim;} private final Wdata_fmtr__claim_tbl fmtr_claim = new Wdata_fmtr__claim_tbl(); + @gplx.Internal protected Wdata_fmtr__claim_grp Fmtr_claim() {return fmtr_claim;} private final Wdata_fmtr__claim_grp fmtr_claim = new Wdata_fmtr__claim_grp(); private final Wdata_fmtr__langtext_tbl fmtr_label = new Wdata_fmtr__langtext_tbl(); private final Wdata_fmtr__langtext_tbl fmtr_descr = new Wdata_fmtr__langtext_tbl(); private final Wdata_fmtr__langtext_tbl fmtr_alias = new Wdata_fmtr__langtext_tbl(); - private final Wdata_fmtr__sitelink_tbl fmtr_slink = new Wdata_fmtr__sitelink_tbl(); - public Bry_fmtr Fmtr_main() {return fmtr_main;} private final Bry_fmtr fmtr_main = Bry_fmtr.new_("~{toc}~{claims}~{labels}~{aliases}~{descriptions}~{links}~{json}", "toc", "claims", "labels", "aliases", "descriptions", "links", "json"); + private final Wdata_fmtr__slink_grp fmtr_slink = new Wdata_fmtr__slink_grp(); + private final Wdata_fmtr__oview_tbl fmtr_oview = new Wdata_fmtr__oview_tbl(); + private Wdata_lang_sorter lang_sorter = new Wdata_lang_sorter(); + public Bry_fmtr Fmtr_main() {return fmtr_main;} private final Bry_fmtr fmtr_main = Bry_fmtr.new_("~{oview}~{toc}~{claims}~{links}~{labels}~{descriptions}~{aliases}~{json}", "oview", "toc", "claims", "links", "labels", "descriptions", "aliases", "json"); public Wdata_hwtr_msgs Msgs() {return msgs;} private Wdata_hwtr_msgs msgs; @gplx.Internal protected Wdata_lbl_mgr Lbl_mgr() {return lbl_mgr;} private final Wdata_lbl_mgr lbl_mgr = new Wdata_lbl_mgr(); - @gplx.Internal protected void Init_by_ctor(Json_parser jdoc_parser, Wdata_lbl_wkr lbl_wkr, Url_encoder href_encoder) { + public void Init_by_ctor(Xoapi_wikibase wikibase_api, Wdata_lbl_wkr lbl_wkr, Url_encoder href_encoder, Xoapi_toggle_mgr toggle_mgr, Xow_xwiki_mgr xwiki_mgr) { lbl_mgr.Wkr_(lbl_wkr); - fmtr_toc.Init_by_ctor(href_encoder); - fmtr_claim.Init_by_ctor(lbl_mgr); - fmtr_label.Init_by_ctor(new Wdata_fmtr__langtext_row()); - fmtr_alias.Init_by_ctor(new Wdata_fmtr__alias_row()); - fmtr_descr.Init_by_ctor(new Wdata_fmtr__langtext_row()); - fmtr_slink.Init_by_ctor(lbl_mgr); - fmtr_json.Init_by_ctor(jdoc_parser); + fmtr_oview.Init_by_ctor(wikibase_api, href_encoder); + fmtr_claim.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), toggle_mgr, lbl_mgr); + fmtr_slink.Init_by_ctor(lang_sorter, toggle_mgr, lbl_mgr, href_encoder, fmtr_toc, xwiki_mgr); + fmtr_label.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), lang_sorter, toggle_mgr, "wikidatawiki-label", new Wdata_fmtr__langtext_row_base()); + fmtr_descr.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), lang_sorter, toggle_mgr, "wikidatawiki-descr", new Wdata_fmtr__langtext_row_base()); + fmtr_alias.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), lang_sorter, toggle_mgr, "wikidatawiki-alias", new Wdata_fmtr__alias_row()); + fmtr_json .Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), toggle_mgr); + lang_sorter.Langs_(wikibase_api.Sort_langs()); + GfoEvMgr_.SubSame_many(wikibase_api, lang_sorter, Xoapi_wikibase.Evt_sort_langs_changed); } public void Init_by_lang(Wdata_hwtr_msgs msgs) { this.msgs = msgs; - fmtr_claim.Init_by_lang(msgs, msgs.Claim_tbl_hdr(), msgs.Claim_col_hdr_prop_id(), msgs.Claim_col_hdr_prop_name(), msgs.Claim_col_hdr_val(), msgs.Claim_col_hdr_ref(), msgs.Claim_col_hdr_qual(), msgs.Claim_col_hdr_rank()); - fmtr_label.Init_by_lang(msgs.Label_tbl_hdr(), msgs.Label_col_hdr_lang(), msgs.Label_col_hdr_text()); - fmtr_alias.Init_by_lang(msgs.Alias_tbl_hdr(), msgs.Alias_col_hdr_lang(), msgs.Alias_col_hdr_text()); - fmtr_descr.Init_by_lang(msgs.Descr_tbl_hdr(), msgs.Descr_col_hdr_lang(), msgs.Descr_col_hdr_text()); + fmtr_toc.Init_by_lang(msgs); + fmtr_oview.Init_by_lang(lang_sorter.Langs()[0], msgs); + fmtr_claim.Init_by_lang(msgs); fmtr_slink.Init_by_lang(msgs); - fmtr_json.Init_by_lang(msgs.Json_tbl_hdr()); + fmtr_label.Init_by_lang(msgs, msgs.Label_tbl_hdr(), msgs.Label_col_hdr()); + fmtr_descr.Init_by_lang(msgs, msgs.Descr_tbl_hdr(), msgs.Descr_col_hdr()); + fmtr_alias.Init_by_lang(msgs, msgs.Alias_tbl_hdr(), msgs.Alias_col_hdr()); + fmtr_json.Init_by_lang(msgs); } public void Init_by_wdoc(Wdata_doc wdoc) { + lang_sorter.Init_by_wdoc(wdoc); fmtr_toc .Init_by_wdoc(wdoc); - fmtr_claim.Init_by_wdoc(fmtr_toc, wdoc.Claim_list()); - fmtr_label.Init_by_wdoc(fmtr_toc, wdoc.Label_list()); - fmtr_alias.Init_by_wdoc(fmtr_toc, wdoc.Alias_list()); - fmtr_descr.Init_by_wdoc(fmtr_toc, wdoc.Descr_list()); - fmtr_slink.Init_by_wdoc(fmtr_toc, wdoc.Slink_list()); - fmtr_json.Init_by_wdoc (fmtr_toc, wdoc.Jdoc()); - lbl_mgr.Gather_labels(wdoc); + fmtr_oview.Init_by_wdoc(wdoc); + fmtr_claim.Init_by_wdoc(wdoc.Qid(), wdoc.Claim_list()); + fmtr_slink.Init_by_wdoc(wdoc.Slink_list()); + fmtr_label.Init_by_wdoc(wdoc.Label_list()); + fmtr_descr.Init_by_wdoc(wdoc.Descr_list()); + fmtr_alias.Init_by_wdoc(wdoc.Alias_list()); + fmtr_json.Init_by_wdoc (wdoc.Jdoc()); + lbl_mgr.Gather_labels(wdoc, lang_sorter); } - public byte[] Write(Wdata_doc wdoc) { - fmtr_main.Bld_bfr_many(bfr, "", fmtr_claim, fmtr_label, fmtr_alias, fmtr_descr, fmtr_slink, fmtr_json); + public byte[] Popup(Wdata_doc wdoc) { + fmtr_oview .Init_by_wdoc(wdoc); + fmtr_label.Init_by_wdoc(wdoc.Label_list()); + fmtr_descr.Init_by_wdoc(wdoc.Descr_list()); + fmtr_alias.Init_by_wdoc(wdoc.Alias_list()); + bfr.Add_str("
    "); + fmtr_main.Bld_bfr_many(bfr, fmtr_oview, "", "", "", "", "", "", ""); + bfr.Add_str("
    "); return bfr.XtoAryAndClear(); } + public byte[] Write(Wdata_doc wdoc) { + bfr.Add_str("
    "); + fmtr_main.Bld_bfr_many(bfr, fmtr_oview, fmtr_toc, fmtr_claim, fmtr_slink, fmtr_label, fmtr_descr, fmtr_alias, fmtr_json); + bfr.Add_str("
    "); + return bfr.XtoAryAndClear(); + } + public static void Write_link_wikidata(Bry_bfr bfr, byte[] href, byte[] text) { + text = gplx.html.Html_utl.Escape_html_as_bry(text); + fmtr_link_wikidata.Bld_bfr_many(bfr, href, text); + } private static final Bry_fmtr fmtr_link_wikidata = Bry_fmtr.new_("~{text}", "href", "text"); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr_tst.java index 7a72335b2..2ab268e80 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr_tst.java @@ -17,214 +17,296 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import org.junit.*; -import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.xtns.*; public class Wdata_hwtr_mgr_tst { @Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt(); - @Test public void Write_label() { - fxt.Test_doc(fxt.Wdoc_bldr() - .Add_label("en", "en_label") - .Add_label("de", "de_label").Xto_wdoc(), String_.Concat_lines_nl_skip_last - ( "" - , "

    Labels

    " - , "" - , "" - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , "
    LanguageLabel
    enen_label
    dede_label
    " - )); - } - @Test public void Write_descr() { - fxt.Test_doc(fxt.Wdoc_bldr() - .Add_description("en", "en_descr") - .Add_description("de", "de_descr").Xto_wdoc(), String_.Concat_lines_nl_skip_last - ( "" - , "

    Descriptions

    " - , "" - , "" - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , "
    LanguageDescription
    enen_descr
    dede_descr
    " - )); - } - @Test public void Write_alias() { - fxt.Test_doc(fxt.Wdoc_bldr() - .Add_alias("en", "en_1", "en_2") - .Add_alias("de", "de_1").Xto_wdoc(), String_.Concat_lines_nl_skip_last - ( "" - , "

    Aliases

    " - , "" - , "" - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , "
    LanguageAlias
    enen_1
    en_2
    dede_1
    " - )); - } - @Test public void Write_slink() { - fxt.Test_doc(fxt.Wdoc_bldr() - .Add_sitelink("enwiki", "Earth") - .Add_sitelink("dewiki", "Erde").Xto_wdoc(), String_.Concat_lines_nl_skip_last - ( "" - , "

    Links

    " - , "" - , "" - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , "
    SiteLinkBadges
    enwikiEarth
    dewikiErde
    " - )); - } - @Test public void Write_claim() { - fxt - .Init_resolved_pid(1, "prop_1") - .Test_doc(fxt.Wdoc_bldr() - .Add_claims - ( fxt.Wdata_fxt().Make_claim_str(1, "abc") - ).Xto_wdoc(), String_.Concat_lines_nl_skip_last - ( "" - , "

    Claims

    " - , "" - , "" - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , "
    IdNameValueReferencesQualifiersRank
    1prop_1abcnormal
    " - )); - } - @Test public void Write_claim_monolingualtext() { - fxt - .Test_claim_val - ( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto") - , "[en] Motto" - ); - } - @Test public void Write_claim_time() { - fxt - .Test_claim_val - ( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06") - , "2001-02-03 04:05:06" - ); - } - @Test public void Write_claim_quantity_ubound_lbound() { - fxt - .Test_claim_val - ( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "units", "60", "30") - , "50 +10 / -20 units" - ); - } - @Test public void Write_claim_quantity_same() { - fxt - .Test_claim_val - ( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "units", "60", "40") - , "50 ±10 units" - ); - } - @Test public void Write_claim_entity() { - fxt - .Init_resolved_qid(1, "item_1") - .Test_claim_val - ( fxt.Wdata_fxt().Make_claim_entity(1, 1) - , "item_1" - ); - } - @Test public void Write_json() { - Json_doc jdoc = Json_doc.new_apos_("{ 'node':['val_0', 'val_1'] }"); - Wdata_doc wdoc = new Wdata_doc(Bry_.Empty, null, jdoc); - fxt.Test_json(wdoc, String_.Concat_lines_nl_skip_last - ( "" - , "

    JSON

    " - , "" - , "" - , "{ \"node\":" - , " [ \"val_0\"" - , " , \"val_1\"" - , " ]" - , "}" - , "" - )); - } + @Test public void Stub() {} +// @Test public void Write_label() { +// fxt.Test_doc(fxt.Wdoc_bldr() +// .Add_label("en", "en_label") +// .Add_label("de", "de_label").Xto_wdoc(), String_.Concat_lines_nl_skip_last +// ( "" +// , "

    Labels

    " +// , "" +// , "" +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    LanguageLabel
    enen_label
    dede_label
    " +// )); +// } +// @Test public void Write_descr() { +// fxt.Test_doc(fxt.Wdoc_bldr() +// .Add_description("en", "en_descr") +// .Add_description("de", "de_descr").Xto_wdoc(), String_.Concat_lines_nl_skip_last +// ( "" +// , "

    Descriptions

    " +// , "" +// , "" +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    LanguageDescription
    enen_descr
    dede_descr
    " +// )); +// } +// @Test public void Write_alias() { +// fxt.Test_doc(fxt.Wdoc_bldr() +// .Add_alias("en", "en_1", "en_2") +// .Add_alias("de", "de_1").Xto_wdoc(), String_.Concat_lines_nl_skip_last +// ( "" +// , "

    Aliases

    " +// , "" +// , "" +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    LanguageAlias
    enen_1
    en_2
    dede_1
    " +// )); +// } +// @Test public void Write_slink_tbl_one() { +// fxt +// .Init_resolved_qid(1, "featured article").Init_resolved_qid(2, "good article") +// .Test_doc(fxt.Wdoc_bldr() +// .Add_sitelink("enwiki", "Earth", "Q1", "Q2") +// .Add_sitelink("dewiki", "Erde") +// .Add_sitelink("frwiki", "Terre") +// .Xto_wdoc(), String_.Concat_lines_nl_skip_last +// ( "" +// , "
    " +// , "
    " +// , "
    " +// , "
    " +// , " " +// , "
    " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    LanguageCodeLinked page
    Englishenwiki
    Deutschdewiki
    Françaisfrwiki
    " +// , "
    " +// , "
    " +// , "
    " +// )); +// } +// @Test public void Write_slink_tbl_many() { +// fxt.Test_doc(fxt.Wdoc_bldr() +// .Add_sitelink("enwiki" , "Earth") +// .Add_sitelink("enwiktionary", "Earth") +// .Add_sitelink("enwikiquote" , "Earth") +// .Xto_wdoc(), String_.Concat_lines_nl_skip_last +// ( "" +// , "

    " +// , "

    " +// , "

    Contents

    " +// , " " +// , "
    " +// , "

    " +// , "" +// , "

    Links (Wikipedia)

    " +// , "" +// , "

    " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    SiteLinkBadges
    enwikiEarth
    " +// , "

    " +// , "" +// , "

    Links (Wiktionary)

    " +// , "" +// , "

    " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    SiteLinkBadges
    enwiktionaryEarth
    " +// , "

    " +// , "" +// , "

    Links (Wikiquote)

    " +// , "" +// , "

    " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    SiteLinkBadges
    enwikiquoteEarth
    " +// , "

    " +// )); +// } +// @Test public void Write_claim() { +// Wdata_wiki_mgr_fxt mkr = fxt.Wdata_fxt(); +// fxt +// .Init_resolved_pid(1, "prop_1") +// .Test_doc(fxt.Wdoc_bldr() +// .Add_claims +// ( mkr.Make_claim_str(1, "abc").Qualifiers_(mkr.Make_qualifiers(mkr.Make_qualifiers_grp(2, mkr.Make_claim_str(2, "qual_2")))) +// ).Xto_wdoc(), String_.Concat_lines_nl_skip_last +// ( "" +// , "

    Claims

    " +// , "" +// , "" +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , " " +// , "
    IdNameValueReferencesQualifiersRank
    1prop_1abcnormal
    " +// )); +// } +// @Test public void Write_json() { +// Json_doc jdoc = Json_doc.new_apos_("{ 'node':['val_0', 'val_1'] }"); +// Wdata_doc wdoc = new Wdata_doc(Bry_.Empty, null, jdoc); +// fxt.Test_json(wdoc, String_.Concat_lines_nl_skip_last +// ( "" +// , "

    JSON

    " +// , "" +// , "
    "
    +//			, "{ \"node\":"
    +//			, "  [ \"val_0\""
    +//			, "  , \"val_1\""
    +//			, "  ]"
    +//			, "}"
    +//			, "
    " +// )); +// } } class Wdata_hwtr_mgr_fxt { - private Wdata_hwtr_mgr doc_hwtr; private OrderedHash resolved_pids = OrderedHash_.new_bry_(), resolved_qids = OrderedHash_.new_bry_(); + private Wdata_hwtr_mgr doc_hwtr; private OrderedHash resolved_ttls = OrderedHash_.new_bry_(); public Wdata_wiki_mgr_fxt Wdata_fxt() {return wdata_fxt;} private Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt(); public void init() { if (doc_hwtr == null) { doc_hwtr = new Wdata_hwtr_mgr(); Wdata_hwtr_msgs msgs = new Wdata_hwtr_msgs(Make_msgs()); - doc_hwtr.Init_by_ctor(new Json_parser(), new Wdata_lbl_wkr__test(resolved_pids, resolved_qids), Url_encoder.new_html_href_mw_()); + doc_hwtr.Init_by_ctor(new Xoapi_wikibase(), new Wdata_lbl_wkr__test(resolved_ttls), Url_encoder.new_html_href_mw_(), new Xoapi_toggle_mgr(), new Xow_xwiki_mgr()); doc_hwtr.Init_by_lang(msgs); } - resolved_pids.Clear(); - resolved_qids.Clear(); + resolved_ttls.Clear(); + doc_hwtr.Lbl_mgr().Clear(); } private byte[][] Make_msgs() { return Bry_.Ary - ( "Contents" - , "Labels", "Language", "Label" - , "Aliases", "Language", "Alias" - , "Descriptions", "Language", "Description" - , "Links" - , "Links (Wikipedia)", "Links (Wiktionary)", "Links (Wikisource)", "Links (Wikivoyage)" - , "Links (Wikiquote)", "Links (Wikibooks)", "Links (Wikiversity)", "Links (Wikinews)", "Links (Special wikis)" - , "Site", "Link", "Badges" - , "Claims", "Id", "Name", "Value", "References", "Qualifiers", "Rank" + ( "hide", "show", "Contents" + , "Also known as:", "No aliases defined." + , "Language", "Code" + , "Links (~{wiki_type})", "other sites", "Linked page" + , "Labels", "Label" + , "Aliases", "Alias" + , "Descriptions", "Description" + , "Statements" , "JSON" , ", ", " ", "(~{0})" , "+", "-", "±" , "—", "?" - , "preferred", "normal", "deprecated" , "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" , "~{0}0s", "~{0}. century", "~{0}. millenium", "~{0}0,000 years", "~{0}00,000 years", "~{0} million years", "~{0}0 million years", "~{0}00 million years", "~{0} billion years" , "~{0} BC", "~{0} ago", "in ~{0}", "jul" @@ -234,8 +316,8 @@ class Wdata_hwtr_mgr_fxt { ); } public Wdata_doc_bldr Wdoc_bldr() {return wdoc_bldr;} private Wdata_doc_bldr wdoc_bldr = new Wdata_doc_bldr(); - public Wdata_hwtr_mgr_fxt Init_resolved_pid(int pid, String lbl) {resolved_pids.Add(Wdata_lbl_itm.Make_ttl(Bool_.Y, pid), new Wdata_langtext_itm(Bry_.new_ascii_("en"), Bry_.new_ascii_(lbl))); return this;} - public Wdata_hwtr_mgr_fxt Init_resolved_qid(int qid, String lbl) {resolved_qids.Add(Wdata_lbl_itm.Make_ttl(Bool_.N, qid), new Wdata_langtext_itm(Bry_.new_ascii_("en"), Bry_.new_ascii_(lbl))); return this;} + public Wdata_hwtr_mgr_fxt Init_resolved_pid(int pid, String lbl) {resolved_ttls.Add(Wdata_lbl_itm.Make_ttl(Bool_.Y, pid), new Wdata_langtext_itm(Bry_.new_ascii_("en"), Bry_.new_ascii_(lbl))); return this;} + public Wdata_hwtr_mgr_fxt Init_resolved_qid(int qid, String lbl) {resolved_ttls.Add(Wdata_lbl_itm.Make_ttl(Bool_.N, qid), new Wdata_langtext_itm(Bry_.new_ascii_("en"), Bry_.new_ascii_(lbl))); return this;} public void Test_doc(Wdata_doc wdoc, String expd) { doc_hwtr.Init_by_wdoc(wdoc); byte[] actl = doc_hwtr.Write(wdoc); @@ -243,22 +325,22 @@ class Wdata_hwtr_mgr_fxt { } public void Test_claim_val(Wdata_claim_itm_core claim, String expd) { doc_hwtr.Init_by_wdoc(wdoc_bldr.Add_claims(claim).Xto_wdoc()); - byte[] actl = doc_hwtr.Fmtr_claim().Fmtr_row().Calc_val(claim); + Bry_bfr tmp_bfr = Bry_bfr.new_(); + Wdata_visitor__html_wtr html_wtr = new Wdata_visitor__html_wtr().Init(Bry_.Empty, tmp_bfr, doc_hwtr.Msgs(), doc_hwtr.Lbl_mgr()); + claim.Welcome(html_wtr); + byte[] actl = tmp_bfr.XtoAryAndClear(); Tfds.Eq(expd, String_.new_utf8_(actl)); } public void Test_json(Wdata_doc wdoc, String expd) { Wdata_fmtr__json fmtr_json = doc_hwtr.Fmtr_json(); - fmtr_json.Init_by_wdoc(doc_hwtr.Fmtr_toc(), wdoc.Jdoc()); + fmtr_json.Init_by_wdoc(wdoc.Jdoc()); Bry_bfr tmp_bfr = Bry_bfr.new_(); fmtr_json.XferAry(tmp_bfr, 0); Tfds.Eq_str_lines(expd, tmp_bfr.XtoStrAndClear()); } } class Wdata_lbl_wkr__test implements Wdata_lbl_wkr { - private OrderedHash resolved_pids, resolved_qids; - public Wdata_lbl_wkr__test(OrderedHash resolved_pids, OrderedHash resolved_qids) {this.resolved_pids = resolved_pids; this.resolved_qids = resolved_qids;} - public void Resolve(Wdata_lbl_list pid_regy, Wdata_lbl_list qid_regy) { - pid_regy.Resolve(resolved_pids); - qid_regy.Resolve(resolved_qids); - } + private OrderedHash found; + public Wdata_lbl_wkr__test(OrderedHash found) {this.found = found;} + public void Resolve(Wdata_lbl_mgr lbl_mgr, Wdata_lang_sorter sorter) {lbl_mgr.Resolve(found);} } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_msgs.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_msgs.java index 0c1387ae1..5ddb59a8a 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_msgs.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_msgs.java @@ -16,40 +16,28 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.xowa.langs.msgs.*; +import gplx.xowa.langs.msgs.*; import gplx.xowa.wikis.*; public class Wdata_hwtr_msgs { public Wdata_hwtr_msgs(byte[][] brys) { int offset = 0; // String[] strs = String_.Ary(brys); // TEST - toc_tbl_hdr = brys[offset + 0]; - label_tbl_hdr = brys[offset + 1]; - label_col_hdr_lang = brys[offset + 2]; - label_col_hdr_text = brys[offset + 3]; - alias_tbl_hdr = brys[offset + 4]; - alias_col_hdr_lang = brys[offset + 5]; - alias_col_hdr_text = brys[offset + 6]; - descr_tbl_hdr = brys[offset + 7]; - descr_col_hdr_lang = brys[offset + 8]; - descr_col_hdr_text = brys[offset + 9]; offset += 10; - slink_tbl_hdr = brys[offset + 0]; - slink_tbl_hdr_w = brys[offset + 1]; - slink_tbl_hdr_d = brys[offset + 2]; - slink_tbl_hdr_s = brys[offset + 3]; - slink_tbl_hdr_v = brys[offset + 4]; - slink_tbl_hdr_q = brys[offset + 5]; - slink_tbl_hdr_b = brys[offset + 6]; - slink_tbl_hdr_u = brys[offset + 7]; - slink_tbl_hdr_n = brys[offset + 8]; - slink_tbl_hdr_x = brys[offset + 9]; offset += 10; - slink_col_hdr_site = brys[offset + 0]; - slink_col_hdr_text = brys[offset + 1]; - slink_col_hdr_bdgs = brys[offset + 2]; - claim_tbl_hdr = brys[offset + 3]; - claim_col_hdr_prop_id = brys[offset + 4]; - claim_col_hdr_prop_name = brys[offset + 5]; - claim_col_hdr_val = brys[offset + 6]; - claim_col_hdr_ref = brys[offset + 7]; - claim_col_hdr_qual = brys[offset + 8]; - claim_col_hdr_rank = brys[offset + 9]; - json_tbl_hdr = brys[offset + 10]; offset += 11; + this.ary = brys; + toggle_title_n = brys[offset + 0]; + toggle_title_y = brys[offset + 1]; + toc_tbl_hdr = brys[offset + 2]; + oview_alias_y = brys[offset + 3]; + oview_alias_n = brys[offset + 4]; offset += 5; + langtext_col_lang_name = brys[offset + 0]; + langtext_col_lang_code = brys[offset + 1]; + slink_tbl_hdr_fmt = brys[offset + 2]; + slink_tbl_hdr_fmt_other = brys[offset + 3]; + slink_col_hdr_text = brys[offset + 4]; offset += 5; + label_tbl_hdr = brys[offset + 0]; + label_col_hdr = brys[offset + 1]; + alias_tbl_hdr = brys[offset + 2]; + alias_col_hdr = brys[offset + 3]; + descr_tbl_hdr = brys[offset + 4]; + descr_col_hdr = brys[offset + 5]; + claim_tbl_hdr = brys[offset + 6]; + json_div_hdr = brys[offset + 7]; offset += 8; sym_list_comma = brys[offset + 0]; sym_list_word = brys[offset + 1]; sym_fmt_parentheses = brys[offset + 2]; @@ -57,10 +45,8 @@ public class Wdata_hwtr_msgs { sym_minus = brys[offset + 4]; sym_plusminus = brys[offset + 5]; offset += 6; val_tid_novalue = brys[offset + 0]; - val_tid_somevalue = brys[offset + 1]; - rank_preferred = brys[offset + 2]; - rank_normal = brys[offset + 3]; - rank_deprecated = brys[offset + 4]; offset += 5; + val_tid_somevalue = brys[offset + 1]; offset += 2; + this.month_bgn_idx = offset; time_month_01 = brys[offset + 0]; time_month_02 = brys[offset + 1]; time_month_03 = brys[offset + 2]; @@ -94,23 +80,34 @@ public class Wdata_hwtr_msgs { geo_unit_minute = brys[offset + 5]; geo_unit_second = brys[offset + 6]; geo_meters = brys[offset + 7]; + Bry_fmtr fmtr = Bry_fmtr.new_( slink_tbl_hdr_fmt, "wiki_type"); + Bry_bfr bfr = Bry_bfr.new_(64); + slink_tbl_hdr_w = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wikipedia_bry); + slink_tbl_hdr_d = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wiktionary_bry); + slink_tbl_hdr_s = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wikisource_bry); + slink_tbl_hdr_v = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wikivoyage_bry); + slink_tbl_hdr_q = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wikiquote_bry); + slink_tbl_hdr_b = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wikibooks_bry); + slink_tbl_hdr_u = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wikiversity_bry); + slink_tbl_hdr_n = fmtr.Bld_bry_many(bfr, Xow_wiki_domain_.Name_wikinews_bry); + slink_tbl_hdr_x = fmtr.Bld_bry_many(bfr, slink_tbl_hdr_fmt_other); } - public static Wdata_hwtr_msgs new_(Xow_wiki wiki) { - byte[][] brys = new_brys(wiki - , "toc" - , "xowa-wikidata-labels" , "xowa-wikidata-language" , "xowa-wikidata-label" - , "xowa-wikidata-aliasesHead" , "xowa-wikidata-language" , "xowa-wikidata-aliases" - , "xowa-wikidata-descriptions" , "xowa-wikidata-language" , "xowa-wikidata-description" - , "xowa-wikidata-links" - , "xowa-wikidata-links-wiki" , "xowa-wikidata-links-wiktionary" , "xowa-wikidata-links-wikisource", "xowa-wikidata-links-wikivoyage" - , "xowa-wikidata-links-wikiquote" , "xowa-wikidata-links-wikibooks" , "xowa-wikidata-links-wikiversity", "xowa-wikidata-links-wikinews", "xowa-wikidata-links-special" - , "xowa-wikidata-wiki" , "xowa-wikidata-link" , "xowa-wikidata-badges" - , "xowa-wikidata-claims" , "xowa-wikidata-property-id" , "xowa-wikidata-property", "xowa-wikidata-value", "xowa-wikidata-references", "xowa-wikidata-qualifiers", "Wikibase-diffview-rank" + public byte[][] Ary() {return ary;} private final byte[][] ary; + public int Month_bgn_idx() {return month_bgn_idx;} private final int month_bgn_idx; + public static Wdata_hwtr_msgs new_(Xow_msg_mgr msg_mgr) { + byte[][] brys = new_brys(msg_mgr + , "hide", "show", "toc" + , "wikibase-aliases-label" , "wikibase-aliases-empty" + , "wikibase-sitelinks-sitename-columnheading" , "wikibase-sitelinks-siteid-columnheading" + , "xowa-wikidata-sitelinks-hdr" , "xowa-wikidata-sitelinks-hdr-special", "wikibase-sitelinks-link-columnheading" + , "xowa-wikidata-labels-hdr" , "xowa-wikidata-labels-col" + , "xowa-wikidata-aliases-hdr" , "xowa-wikidata-aliases-col" + , "xowa-wikidata-descriptions-hdr" , "xowa-wikidata-descriptions-col" + , "wikibase-statements" , "xowa-wikidata-json" , "comma-separator", "word-separator", "parentheses" , "xowa-wikidata-plus", "xowa-wikidata-minus", "xowa-wikidata-plusminus" , "xowa-wikidata-novalue", "xowa-wikidata-somevalue" - , "xowa-wikidata-preferred", "xowa-wikidata-normal", "xowa-wikidata-deprecated" , "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" , "xowa-wikidata-decade", "xowa-wikidata-century", "xowa-wikidata-millenium", "xowa-wikidata-years1e4", "xowa-wikidata-years1e5", "xowa-wikidata-years1e6", "xowa-wikidata-years1e7", "xowa-wikidata-years1e8", "xowa-wikidata-years1e9" , "ago", "xowa-wikidata-bc", "xowa-wikidata-inTime" @@ -121,24 +118,28 @@ public class Wdata_hwtr_msgs { ); return new Wdata_hwtr_msgs(brys); } - private static byte[][] new_brys(Xow_wiki wiki, String... ids) { + private static byte[][] new_brys(Xow_msg_mgr msg_mgr, String... ids) { int len = ids.length; byte[][] rv = new byte[len][]; for (int i = 0; i < len; ++i) - rv[i] = gplx.html.Html_utl.Escape_html_as_bry(wiki.Msg_mgr().Val_by_key_obj(ids[i])); + rv[i] = gplx.html.Html_utl.Escape_html_as_bry(msg_mgr.Val_by_key_obj(ids[i])); return rv; } + public byte[] Toggle_title_y() {return toggle_title_y;} private byte[] toggle_title_y; + public byte[] Toggle_title_n() {return toggle_title_n;} private byte[] toggle_title_n; public byte[] Toc_tbl_hdr() {return toc_tbl_hdr;} private final byte[] toc_tbl_hdr; + public byte[] Oview_alias_y() {return oview_alias_y;} private final byte[] oview_alias_y; + public byte[] Oview_alias_n() {return oview_alias_n;} private final byte[] oview_alias_n; + public byte[] Langtext_col_lang_name() {return langtext_col_lang_name;} private final byte[] langtext_col_lang_name; + public byte[] Langtext_col_lang_code() {return langtext_col_lang_code;} private final byte[] langtext_col_lang_code; public byte[] Label_tbl_hdr() {return label_tbl_hdr;} private final byte[] label_tbl_hdr; - public byte[] Label_col_hdr_lang() {return label_col_hdr_lang;} private final byte[] label_col_hdr_lang; - public byte[] Label_col_hdr_text() {return label_col_hdr_text;} private final byte[] label_col_hdr_text; + public byte[] Label_col_hdr() {return label_col_hdr;} private final byte[] label_col_hdr; public byte[] Alias_tbl_hdr() {return alias_tbl_hdr;} private final byte[] alias_tbl_hdr; - public byte[] Alias_col_hdr_lang() {return alias_col_hdr_lang;} private final byte[] alias_col_hdr_lang; - public byte[] Alias_col_hdr_text() {return alias_col_hdr_text;} private final byte[] alias_col_hdr_text; + public byte[] Alias_col_hdr() {return alias_col_hdr;} private final byte[] alias_col_hdr; public byte[] Descr_tbl_hdr() {return descr_tbl_hdr;} private final byte[] descr_tbl_hdr; - public byte[] Descr_col_hdr_lang() {return descr_col_hdr_lang;} private final byte[] descr_col_hdr_lang; - public byte[] Descr_col_hdr_text() {return descr_col_hdr_text;} private final byte[] descr_col_hdr_text; - public byte[] Slink_tbl_hdr() {return slink_tbl_hdr;} private final byte[] slink_tbl_hdr; + public byte[] Descr_col_hdr() {return descr_col_hdr;} private final byte[] descr_col_hdr; + public byte[] Slink_tbl_hdr_fmt() {return slink_tbl_hdr_fmt;} private final byte[] slink_tbl_hdr_fmt; + public byte[] Slink_tbl_hdr_fmt_other() {return slink_tbl_hdr_fmt_other;} private final byte[] slink_tbl_hdr_fmt_other; public byte[] Slink_tbl_hdr_w() {return slink_tbl_hdr_w;} private final byte[] slink_tbl_hdr_w; public byte[] Slink_tbl_hdr_d() {return slink_tbl_hdr_d;} private final byte[] slink_tbl_hdr_d; public byte[] Slink_tbl_hdr_s() {return slink_tbl_hdr_s;} private final byte[] slink_tbl_hdr_s; @@ -148,22 +149,11 @@ public class Wdata_hwtr_msgs { public byte[] Slink_tbl_hdr_u() {return slink_tbl_hdr_u;} private final byte[] slink_tbl_hdr_u; public byte[] Slink_tbl_hdr_n() {return slink_tbl_hdr_n;} private final byte[] slink_tbl_hdr_n; public byte[] Slink_tbl_hdr_x() {return slink_tbl_hdr_x;} private final byte[] slink_tbl_hdr_x; - public byte[] Slink_col_hdr_site() {return slink_col_hdr_site;} private final byte[] slink_col_hdr_site; public byte[] Slink_col_hdr_text() {return slink_col_hdr_text;} private final byte[] slink_col_hdr_text; - public byte[] Slink_col_hdr_bdgs() {return slink_col_hdr_bdgs;} private final byte[] slink_col_hdr_bdgs; public byte[] Claim_tbl_hdr() {return claim_tbl_hdr;} private final byte[] claim_tbl_hdr; - public byte[] Claim_col_hdr_prop_id() {return claim_col_hdr_prop_id;} private final byte[] claim_col_hdr_prop_id; - public byte[] Claim_col_hdr_prop_name() {return claim_col_hdr_prop_name;} private final byte[] claim_col_hdr_prop_name; - public byte[] Claim_col_hdr_val() {return claim_col_hdr_val;} private final byte[] claim_col_hdr_val; - public byte[] Claim_col_hdr_ref() {return claim_col_hdr_ref;} private final byte[] claim_col_hdr_ref; - public byte[] Claim_col_hdr_qual() {return claim_col_hdr_qual;} private final byte[] claim_col_hdr_qual; - public byte[] Claim_col_hdr_rank() {return claim_col_hdr_rank;} private final byte[] claim_col_hdr_rank; - public byte[] Json_tbl_hdr() {return json_tbl_hdr;} private final byte[] json_tbl_hdr; + public byte[] Json_div_hdr() {return json_div_hdr;} private final byte[] json_div_hdr; public byte[] Val_tid_novalue() {return val_tid_novalue;} private final byte[] val_tid_novalue; public byte[] Val_tid_somevalue() {return val_tid_somevalue;} private final byte[] val_tid_somevalue; - public byte[] Rank_preferred() {return rank_preferred;} private final byte[] rank_preferred; - public byte[] Rank_normal() {return rank_normal;} private final byte[] rank_normal; - public byte[] Rank_deprecated() {return rank_deprecated;} private final byte[] rank_deprecated; public byte[] Sym_list_comma() {return sym_list_comma;} private final byte[] sym_list_comma; public byte[] Sym_list_word() {return sym_list_word;} private final byte[] sym_list_word; public byte[] Sym_fmt_parentheses() {return sym_fmt_parentheses;} private final byte[] sym_fmt_parentheses; diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lang_sorter.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lang_sorter.java deleted file mode 100644 index 6d069de12..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lang_sorter.java +++ /dev/null @@ -1,45 +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 . -*/ -package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.xowa.xtns.wdatas.core.*; -class Wdata_lang_sorter implements gplx.lists.ComparerAble { - private Hash_adp_bry hash = Hash_adp_bry.cs_(); - public void Langs_(byte[][] langs) { - hash.Clear(); - int len = langs.length; - for (int i = 0; i < len; ++i) { - byte[] lang = langs[i]; - Wdata_lang_sorter_itm itm = new Wdata_lang_sorter_itm(i, lang); - hash.Add_if_new(lang, itm); - } - } - public int compare(Object lhsObj, Object rhsObj) { - Wdata_sortable lhs = (Wdata_sortable)lhsObj; if (lhs.Sort() == -1) Sort_calc(lhs); - Wdata_sortable rhs = (Wdata_sortable)rhsObj; if (rhs.Sort() == -1) Sort_calc(rhs); - return Int_.Compare(lhs.Sort(), rhs.Sort()); - } - private void Sort_calc(Wdata_sortable data_itm) { - Wdata_lang_sorter_itm sort_itm = (Wdata_lang_sorter_itm)hash.Fetch(data_itm.Lang()); - if (sort_itm != null) data_itm.Sort_(sort_itm.Sort()); - } -} -class Wdata_lang_sorter_itm { - public Wdata_lang_sorter_itm(int sort, byte[] lang) {this.sort = sort; this.lang = lang;} - public int Sort() {return sort;} private final int sort; - public byte[] Lang() {return lang;} private final byte[] lang; -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_list.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_itm.java similarity index 55% rename from 400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_list.java rename to 400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_itm.java index 526c3fe64..1ab6ca4e7 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_list.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_itm.java @@ -17,42 +17,18 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; -class Wdata_lbl_list { - private HashAdp hash = HashAdp_.new_(); private Int_obj_ref hash_temp_key = Int_obj_ref.neg1_(); - public Wdata_lbl_list(boolean is_pid) {this.is_pid = is_pid;} private boolean is_pid; - public ListAdp Queue() {return queue;} private ListAdp queue = ListAdp_.new_(); - public byte[] Get_text_or_empty(int id) { - Wdata_lbl_itm rv_itm = (Wdata_lbl_itm)hash.Fetch(hash_temp_key.Val_(id)); - return rv_itm == null ? Bry_.Empty : rv_itm.Text(); - } - public void Queue_if_missing(int id) { - boolean has = hash.Has(hash_temp_key.Val_(id)); - if (!has) { - Wdata_lbl_itm itm = new Wdata_lbl_itm(is_pid, id); - hash.Add(Int_obj_ref.new_(id), itm); - queue.Add(itm); - } - } - public void Resolve(OrderedHash found) { - int len = queue.Count(); - for (int i = 0; i < len; ++i) { - Wdata_lbl_itm pending_itm = (Wdata_lbl_itm)queue.FetchAt(i); - Wdata_langtext_itm found_itm = (Wdata_langtext_itm)found.Fetch(pending_itm.Ttl()); - if (found_itm != null) - pending_itm.Load_vals(found_itm.Lang(), found_itm.Text()); - } - queue.Clear(); - } -} -class Wdata_lbl_itm { - public Wdata_lbl_itm(boolean is_pid, int id) { - this.is_pid = is_pid; this.id = id; this.ttl = Make_ttl(is_pid, id); +public class Wdata_lbl_itm { + public Wdata_lbl_itm(boolean is_pid, int id, boolean text_en_enabled) { + this.is_pid = is_pid; this.id = id; this.text_en_enabled = text_en_enabled; + this.ttl = Make_ttl(is_pid, id); } public boolean Is_pid() {return is_pid;} private final boolean is_pid; public int Id() {return id;} private final int id; public byte[] Ttl() {return ttl;} private final byte[] ttl; public byte[] Lang() {return lang;} private byte[] lang; public byte[] Text() {return text;} private byte[] text; + public byte[] Text_en() {return text_en;} public void Text_en_(byte[] v) {text_en = v;} private byte[] text_en = Bry_.Empty; + public boolean Text_en_enabled() {return text_en_enabled;} private boolean text_en_enabled; public void Load_vals(byte[] lang, byte[] text) {this.lang = lang; this.text = text;} public static byte[] Make_ttl(boolean is_pid, int id) { return is_pid @@ -61,4 +37,11 @@ class Wdata_lbl_itm { ; } private static final byte[] Ttl_prefix_pid = Bry_.new_ascii_("Property:P"), Ttl_prefix_qid = Bry_.new_ascii_("Q"); + private static final byte[] Extract_ttl_qid = Bry_.new_ascii_("http://www.wikidata.org/entity/"); + public static byte[] Extract_ttl(byte[] href) { + if (Bry_.HasAtBgn(href, Extract_ttl_qid)) // qid + return Bry_.Mid(href, Extract_ttl_qid.length, href.length); + else // possibly support pid in future, but so far, nothing referencing just "Property:P##" + return null; + } } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_mgr.java index e1627c04c..4f1926fde 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_mgr.java @@ -17,30 +17,122 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; -class Wdata_lbl_mgr { - public Wdata_lbl_list Pid_regy() {return pid_regy;} private Wdata_lbl_list pid_regy = new Wdata_lbl_list(Bool_.Y); - public Wdata_lbl_list Qid_regy() {return qid_regy;} private Wdata_lbl_list qid_regy = new Wdata_lbl_list(Bool_.N); - public void Wkr_(Wdata_lbl_wkr v) {this.wkr = v;} private Wdata_lbl_wkr wkr; - public void Gather_labels(Wdata_doc wdoc) { +public class Wdata_lbl_mgr { + private Hash_adp_bry ttl_hash = Hash_adp_bry.ci_ascii_(); + private HashAdp qid_hash = HashAdp_.new_(), pid_hash = HashAdp_.new_(); private Int_obj_ref int_hash_key = Int_obj_ref.neg1_(); + private Wdata_visitor__lbl_gatherer lbl_gatherer; + public Wdata_lbl_mgr() { + lbl_gatherer = new Wdata_visitor__lbl_gatherer(this); + } + public void Clear() {ttl_hash.Clear(); qid_hash.Clear(); pid_hash.Clear(); queue.Clear();} + public ListAdp Queue() {return queue;} private ListAdp queue = ListAdp_.new_(); + @gplx.Internal protected void Wkr_(Wdata_lbl_wkr v) {this.wkr = v;} private Wdata_lbl_wkr wkr; + public Wdata_lbl_itm Get_itm__ttl(byte[] ttl) { + Wdata_lbl_itm rv = (Wdata_lbl_itm)ttl_hash.Fetch(ttl); + if (rv == null) Gfo_usr_dlg_._.Warn_many("", "", "wdata.hwtr:unknown entity; ttl=~{0}", String_.new_utf8_(ttl)); // NOTE: should not happen + return rv; + } + public byte[] Get_text__ttl(byte[] ttl, byte[] or) { + Wdata_lbl_itm rv_itm = Get_itm__ttl(ttl); + return rv_itm == null ? or : rv_itm.Text(); + } + public byte[] Get_text__qid(int id) {return Get_text(Bool_.N, id);} + public byte[] Get_text__pid(int id) {return Get_text(Bool_.Y, id);} + private byte[] Get_text(boolean is_pid, int id) { + HashAdp hash = is_pid ? pid_hash : qid_hash; + Wdata_lbl_itm rv_itm = (Wdata_lbl_itm)hash.Fetch(int_hash_key.Val_(id)); + if (rv_itm != null) return rv_itm.Text(); // found; return lbl + Gfo_usr_dlg_._.Warn_many("", "", "wdata.hwtr:unknown entity; is_pid=~{0} id=~{1}", Yn.Xto_str(is_pid), id); // NOTE: should not happen + return Wdata_lbl_itm.Make_ttl(is_pid, id); // missing; return ttl; EX: "Property:P1", "Q1"; + } + public void Queue_if_missing__ttl(byte[] ttl) {Queue_if_missing__ttl(ttl, Bool_.N);} + public void Queue_if_missing__ttl(byte[] ttl, boolean get_en) { + if (ttl == null) {Gfo_usr_dlg_._.Warn_many("", "", "wdata.hwtr:unknown href; href=~{0}", String_.new_utf8_(ttl)); return;} + boolean has = ttl_hash.Has(ttl); + if (!has) Queue_add(qid_hash, Bool_.N, Qid_int(ttl), get_en); + } + public void Queue_if_missing__qid(int id) {Queue_if_missing(Bool_.N, id);} + public void Queue_if_missing__pid(int id) {Queue_if_missing(Bool_.Y, id);} + private void Queue_if_missing(boolean is_pid, int id) { + HashAdp hash = is_pid ? pid_hash : qid_hash; + boolean has = hash.Has(int_hash_key.Val_(id)); + if (!has) Queue_add(hash, is_pid, id, Bool_.N); + } + private void Queue_add(HashAdp hash, boolean is_pid, int id, boolean get_en) { + Wdata_lbl_itm itm = new Wdata_lbl_itm(is_pid, id, get_en); + hash.Add(Int_obj_ref.new_(id), itm); + ttl_hash.Add(itm.Ttl(), itm); + queue.Add(itm); + } + public void Resolve(OrderedHash found) { + int len = queue.Count(); + for (int i = 0; i < len; ++i) { + Wdata_lbl_itm pending_itm = (Wdata_lbl_itm)queue.FetchAt(i); + Wdata_langtext_itm found_itm = (Wdata_langtext_itm)found.Fetch(pending_itm.Ttl()); + if (found_itm != null) + pending_itm.Load_vals(found_itm.Lang(), found_itm.Text()); + } + queue.Clear(); + } + public void Gather_labels(Wdata_doc wdoc, Wdata_lang_sorter sorter) { OrderedHash claim_list = wdoc.Claim_list(); int len = claim_list.Count(); for (int i = 0; i < len; ++i) { Wdata_claim_grp grp = (Wdata_claim_grp)claim_list.FetchAt(i); int grp_len = grp.Len(); for (int j = 0; j < grp_len; ++j) { - Wdata_claim_itm_base itm = (Wdata_claim_itm_base)grp.Get_at(j); - pid_regy.Queue_if_missing(itm.Pid()); - switch (itm.Val_tid()) { - case Wdata_dict_val_tid.Tid_entity: - Wdata_claim_itm_entity entity = (Wdata_claim_itm_entity)itm; - qid_regy.Queue_if_missing(entity.Entity_id()); - break; + Wdata_claim_itm_core itm = (Wdata_claim_itm_core)grp.Get_at(j); + this.Queue_if_missing__pid(itm.Pid()); + itm.Welcome(lbl_gatherer); + Wdata_claim_grp_list qual_list = itm.Qualifiers(); + if (qual_list != null) { + int qual_list_len = qual_list.Len(); + for (int k = 0; k < qual_list_len; ++k) { + Wdata_claim_grp qual_grp = qual_list.Get_at(k); + int qual_grp_len = qual_grp.Len(); + for (int m = 0; m < qual_grp_len; ++m) { + Wdata_claim_itm_base qual = qual_grp.Get_at(m); + this.Queue_if_missing__pid(qual.Pid()); + qual.Welcome(lbl_gatherer); + } + } + } + Wdata_references_grp[] ref_grp_ary = itm.References(); + if (ref_grp_ary != null) { + int ref_grp_ary_len = ref_grp_ary.length; + for (int k = 0; k < ref_grp_ary_len; ++k) { + Wdata_references_grp ref_grp = ref_grp_ary[k]; + Wdata_claim_grp_list ref_list = ref_grp.References(); + int ref_list_len = ref_list.Len(); + for (int m = 0; m < ref_list_len; ++m) { + Wdata_claim_grp claim_grp = ref_list.Get_at(m); + int claim_grp_len = claim_grp.Len(); + for (int n = 0; n < claim_grp_len; ++n) { + Wdata_claim_itm_core claim = claim_grp.Get_at(n); + this.Queue_if_missing__pid(claim.Pid()); + claim.Welcome(lbl_gatherer); + } + } + } } } } - wkr.Resolve(pid_regy, qid_regy); + OrderedHash slink_list = wdoc.Slink_list(); + len = slink_list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_sitelink_itm itm = (Wdata_sitelink_itm)slink_list.FetchAt(i); + byte[][] badges = itm.Badges(); + int badges_len = badges.length; + for (int j = 0; j < badges_len; ++j) { + byte[] badge = badges[j]; + this.Queue_if_missing__ttl(badge, Bool_.Y); // badges has qid; EX: ["Q1", "Q2"] + } + } + wkr.Resolve(this, sorter); + } + public static int Qid_int(byte[] qid) { + byte qid_0 = qid[0]; + if (qid_0 != Byte_ascii.Ltr_Q && qid_0 != Byte_ascii.Ltr_q) return -1; + return Bry_.Xto_int_or(qid, 1, qid.length, -1); } } -interface Wdata_lbl_wkr { - void Resolve(Wdata_lbl_list pid_regy, Wdata_lbl_list qid_regy); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr.java new file mode 100644 index 000000000..956d20dc2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr.java @@ -0,0 +1,22 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; +public interface Wdata_lbl_wkr { + void Resolve(Wdata_lbl_mgr lbl_mgr, Wdata_lang_sorter sorter); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr_wiki.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr_wiki.java new file mode 100644 index 000000000..55ccdce45 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr_wiki.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.apis.xowa.xtns.*; +public class Wdata_lbl_wkr_wiki implements Wdata_lbl_wkr { + private Wdata_wiki_mgr wdata_mgr; + private Xoapi_wikibase wikibase_api; + public Wdata_lbl_wkr_wiki(Xoapi_wikibase wikibase_api, Wdata_wiki_mgr wdata_mgr) {this.wikibase_api = wikibase_api; this.wdata_mgr = wdata_mgr;} + public void Resolve(Wdata_lbl_mgr lbl_mgr, Wdata_lang_sorter sorter) { + ListAdp queue = lbl_mgr.Queue(); + int len = queue.Count(); + for (int i = 0; i < len; ++i) { + Wdata_lbl_itm itm = (Wdata_lbl_itm)queue.FetchAt(i); + Wdata_doc wdoc = wdata_mgr.Pages_get(itm.Ttl()); + OrderedHash labels = wdoc.Label_list(); + if (labels.Count() == 0) continue; + labels.SortBy(sorter); + Wdata_langtext_itm label = Wdata_langtext_itm.Get_itm_or_null(wdoc.Label_list(), wikibase_api.Core_langs()); + if (label == null) + itm.Load_vals(Bry_.Empty, itm.Ttl()); // NOTE: use itm.Ttl() in case no label is found for the core_lang + else { + itm.Load_vals(label.Lang(), label.Text()); + if (itm.Text_en_enabled()) { + Wdata_langtext_itm en_label = (Wdata_langtext_itm)labels.Fetch(Xol_lang_.Key_en); + itm.Text_en_(en_label == null ? Bry_.Empty : en_label.Text()); + } + } + } + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_slink_grp.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_slink_grp.java new file mode 100644 index 000000000..0a2bddb99 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_slink_grp.java @@ -0,0 +1,82 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.wikis.*; import gplx.xowa.apis.xowa.html.*; +class Wdata_slink_grp { + public Wdata_slink_grp(int tid, byte[] wiki_name, Xoapi_toggle_itm toggle_itm, Wdata_toc_data toc_data) { + this.tid = tid; this.wiki_name = wiki_name; this.toggle_itm = toggle_itm; this.toc_data = toc_data; + } + public int Tid() {return tid;} private final int tid; + public byte[] Wiki_name() {return wiki_name;} private final byte[] wiki_name; + public Wdata_toc_data Toc_data() {return toc_data;} private final Wdata_toc_data toc_data; + public Xoapi_toggle_itm Toggle_itm() {return toggle_itm;} private Xoapi_toggle_itm toggle_itm; + public OrderedHash Rows() {return rows;} private final OrderedHash rows = OrderedHash_.new_(); + public static void Sift(Wdata_slink_grp[] rv, OrderedHash list) { + for (int i = 0; i < Idx__len; ++i) + rv[i].Rows().Clear(); + int list_len = list.Count(); + for (int i = 0; i < list_len; ++i) { + Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i); + int idx = Idx_by_tid(itm.Domain_info().Wiki_tid()); + rv[idx].Rows().Add(itm.Site(), itm); + } + } + public static int Idx_by_tid(int tid) { + switch (tid) { + case Xow_wiki_domain_.Tid_wikipedia: return Idx_w; + case Xow_wiki_domain_.Tid_wiktionary: return Idx_d; + case Xow_wiki_domain_.Tid_wikisource: return Idx_s; + case Xow_wiki_domain_.Tid_wikivoyage: return Idx_v; + case Xow_wiki_domain_.Tid_wikiquote: return Idx_q; + case Xow_wiki_domain_.Tid_wikibooks: return Idx_b; + case Xow_wiki_domain_.Tid_wikiversity: return Idx_u; + case Xow_wiki_domain_.Tid_wikinews: return Idx_n; + default: return Idx_x; + } + } + public static byte[] Msg_by_tid(Wdata_hwtr_msgs msgs, int tid) { + switch (tid) { + case Idx_w: return msgs.Slink_tbl_hdr_w(); + case Idx_d: return msgs.Slink_tbl_hdr_d(); + case Idx_s: return msgs.Slink_tbl_hdr_s(); + case Idx_v: return msgs.Slink_tbl_hdr_v(); + case Idx_q: return msgs.Slink_tbl_hdr_q(); + case Idx_b: return msgs.Slink_tbl_hdr_b(); + case Idx_u: return msgs.Slink_tbl_hdr_u(); + case Idx_n: return msgs.Slink_tbl_hdr_n(); + case Idx_x: return msgs.Slink_tbl_hdr_x(); + default: throw Err_.unhandled(tid); + } + } + public static byte[] Name_by_tid(int idx) { + switch (idx) { + case Idx_w: return Xow_wiki_domain_.Key_wikipedia_bry; + case Idx_d: return Xow_wiki_domain_.Key_wiktionary_bry; + case Idx_s: return Xow_wiki_domain_.Key_wikisource_bry; + case Idx_v: return Xow_wiki_domain_.Key_wikivoyage_bry; + case Idx_q: return Xow_wiki_domain_.Key_wikiquote_bry; + case Idx_b: return Xow_wiki_domain_.Key_wikibooks_bry; + case Idx_u: return Xow_wiki_domain_.Key_wikiversity_bry; + case Idx_n: return Xow_wiki_domain_.Key_wikinews_bry; + case Idx_x: return Name_special; + default: throw Err_.unhandled(idx); + } + } + public static final int Idx__len = 9, Idx_w = 0, Idx_d = 1, Idx_s = 2, Idx_v = 3, Idx_q = 4, Idx_b = 5, Idx_u = 6, Idx_n = 7, Idx_x = 8; + private static final byte[] Name_special = Bry_.new_ascii_("special"); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__html_wtr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__html_wtr.java new file mode 100644 index 000000000..5c0799d6b --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__html_wtr.java @@ -0,0 +1,113 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; +class Wdata_visitor__html_wtr implements Wdata_claim_visitor { + private byte[] ttl; private Bry_bfr tmp_bfr; private Wdata_hwtr_msgs msgs; private Wdata_lbl_mgr lbl_mgr; + public Wdata_visitor__html_wtr Init(byte[] ttl, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wdata_lbl_mgr lbl_mgr) { + this.ttl = ttl; this.tmp_bfr = tmp_bfr; this.msgs = msgs; this.lbl_mgr = lbl_mgr; + return this; + } + public void Visit_str(Wdata_claim_itm_str itm) { + tmp_bfr.Add(itm.Val_str()); + } + public void Visit_entity(Wdata_claim_itm_entity itm) { + int entity_id = itm.Entity_id(); + byte[] text = lbl_mgr.Get_text__qid(entity_id); + Wdata_hwtr_mgr.Write_link_wikidata(tmp_bfr, Bry_.Add(Byte_ascii.Ltr_Q, Int_.Xto_bry(entity_id)), text); + } + public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) { + tmp_bfr.Add(itm.Text()); + tmp_bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Brack_bgn).Add(itm.Lang()).Add_byte(Byte_ascii.Brack_end); + } + public void Visit_quantity(Wdata_claim_itm_quantity itm) { + try { + DecimalAdp val = itm.Amount_as_num(); + DecimalAdp hi = itm.Ubound_as_num(); + DecimalAdp lo = itm.Lbound_as_num(); + DecimalAdp hi_diff = hi.Op_subtract(val); + DecimalAdp lo_diff = val.Op_subtract(lo); + float hi_diff_val = (float)hi_diff.Xto_double(); + float lo_diff_val = (float)lo_diff.Xto_double(); + tmp_bfr.Add(itm.Amount()).Add_byte_space(); + if (hi_diff.Eq(lo_diff)) { // delta is same in both directions; EX: val=50 hi=60 lo=40 -> hi_diff == lo_diff == 10 + if (hi_diff_val != 0) // skip if 0 + tmp_bfr.Add(msgs.Sym_plusminus()).Add_str(hi_diff.Xto_str()); + } + else { // delta is diff in both directions; EX: val=50 hi=60 lo=30 -> hi_diff == 10, lo_diff == 20 + if (hi_diff_val != 0) // skip if 0 + tmp_bfr.Add(msgs.Sym_plus()).Add_str(hi_diff.Xto_str()); + if (lo_diff_val != 0) { // skip if 0 + if (hi_diff_val != 0) tmp_bfr.Add(Time_plus_minus_spr); + tmp_bfr.Add(msgs.Sym_minus()).Add_str(lo_diff.Xto_str()); + } + } + byte[] unit = itm.Unit(); + if (!Bry_.Eq(unit, Wdata_claim_itm_quantity.Unit_1)) + tmp_bfr.Add_byte_space().Add(unit); + } catch (Exception e) { + Gfo_usr_dlg_._.Warn_many("", "", "failed to write quantity; ttl=~{0} pid=~{1} err=~{2}", String_.new_utf8_(ttl), itm.Pid(), Err_.Message_gplx_brief(e)); + } + } private static final byte[] Time_plus_minus_spr = Bry_.new_ascii_(" / "); + public void Visit_time(Wdata_claim_itm_time itm) { + try { + Wdata_date date = itm.Time_as_date(); + boolean calendar_is_julian = itm.Calendar_is_julian(); + byte[] calendar_display = null; + if (calendar_is_julian) { + date = Wdata_date.Xto_julian(date); + calendar_display = msgs.Time_julian(); + } + Wdata_date.Xto_str(tmp_bfr, date, itm.Precision_int(), msgs.Ary(), msgs.Month_bgn_idx(), Byte_ascii.Space_bry, Byte_ascii.Colon_bry); +// tmp_bfr.Add_long_variable(date.Year()); +// tmp_bfr.Add_byte(Byte_ascii.Dash) .Add_int_fixed(date.Month() , 2); +// tmp_bfr.Add_byte(Byte_ascii.Dash) .Add_int_fixed(date.Day() , 2); +// tmp_bfr.Add_byte(Byte_ascii.Space) .Add_int_fixed(date.Hour() , 2); +// tmp_bfr.Add_byte(Byte_ascii.Colon) .Add_int_fixed(date.Minute(), 2); +// tmp_bfr.Add_byte(Byte_ascii.Colon) .Add_int_fixed(date.Second(), 2); + if (calendar_display != null) + tmp_bfr.Add_byte_space().Add(calendar_display); + } catch (Exception e) { + Gfo_usr_dlg_._.Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", String_.new_utf8_(ttl), itm.Pid(), Err_.Message_gplx_brief(e)); + } + } + public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) { + try { + DecimalAdp precision_frac = itm.Prc_as_num(); // precision is a decimal; EX: .00027777 + int precision_int = Math_.Log10(DecimalAdp_.One.Op_divide(precision_frac).Xto_int()); // convert precision to log10 integer; EX: .00027777 -> 3600 -> 3 + gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(tmp_bfr, Bool_.Y, itm.Lng(), precision_int); + tmp_bfr.Add_byte_comma().Add_byte_space(); + gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(tmp_bfr, Bool_.N, itm.Lat(), precision_int); + byte[] glb_ttl = itm.Glb_ttl(); + if (glb_ttl != null) { + byte[] glb_lbl = lbl_mgr.Get_text__ttl(glb_ttl, itm.Glb()); + tmp_bfr.Add_byte_space().Add_byte(Byte_ascii.Paren_bgn); + Wdata_hwtr_mgr.Write_link_wikidata(tmp_bfr, glb_ttl, glb_lbl); + tmp_bfr.Add_byte(Byte_ascii.Paren_end); + } + } catch (Exception e) { + Gfo_usr_dlg_._.Warn_many("", "", "failed to write globecoordinate; ttl=~{0} pid=~{1} err=~{2}", String_.new_utf8_(ttl), itm.Pid(), Err_.Message_gplx_brief(e)); + } + } + public void Visit_system(Wdata_claim_itm_system itm) { + switch (itm.Snak_tid()) { + case Wdata_dict_snak_tid.Tid_somevalue: tmp_bfr.Add(msgs.Val_tid_somevalue()); break; + case Wdata_dict_snak_tid.Tid_novalue: tmp_bfr.Add(msgs.Val_tid_novalue()); break; + } + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__html_wtr_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__html_wtr_tst.java new file mode 100644 index 000000000..1bb5cf689 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__html_wtr_tst.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.apis.xowa.html.*; +public class Wdata_visitor__html_wtr_tst { + @Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt(); + @Test public void Monolingualtext() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto") + , "Motto [en]" + ); + } + @Test public void Time() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06") + , "4:05:06 3 Feb 2001" + ); + } + @Test public void Quantity_ubound_lbound() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "units", "60", "30") + , "50 +10 / -20 units" + ); + } + @Test public void Quantity_same() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "units", "60", "40") + , "50 ±10 units" + ); + } + @Test public void Quantity_frac() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_quantity(1, "+0.12345", "units", "+0.12346", "+0.12344") + , "+0.12345 ±0.00001 units" + ); + } + @Test public void Entity() { + fxt + .Init_resolved_qid(1, "item_1") + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_entity(1, 1) + , "item_1" + ); + } + @Test public void Globecoordinate() { + fxt + .Init_resolved_qid(2, "Earth") + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2") + , "51° 30' 26" N, 0° 7' 39" W (Earth)" + ); + } + @Test public void Globecoordinate_null() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "") + , "51° 30' 26" N, 0° 7' 39" W" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__lbl_gatherer.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__lbl_gatherer.java new file mode 100644 index 000000000..5012ad83d --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_visitor__lbl_gatherer.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; +class Wdata_visitor__lbl_gatherer implements Wdata_claim_visitor { + private Wdata_lbl_mgr lbl_mgr; + public Wdata_visitor__lbl_gatherer(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr;} + public void Visit_entity(Wdata_claim_itm_entity itm) { + lbl_mgr.Queue_if_missing__qid(itm.Entity_id()); + } + public void Visit_time(Wdata_claim_itm_time itm) { + byte[] ttl = Wdata_lbl_itm.Extract_ttl(itm.Calendar()); + itm.Calendar_ttl_(ttl); + lbl_mgr.Queue_if_missing__ttl(ttl); + } + public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) { + byte[] ttl = Wdata_lbl_itm.Extract_ttl(itm.Glb()); + itm.Glb_ttl_(ttl); + lbl_mgr.Queue_if_missing__ttl(ttl); + } + public void Visit_str(Wdata_claim_itm_str itm) {} + public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {} + public void Visit_quantity(Wdata_claim_itm_quantity itm) {} + public void Visit_system(Wdata_claim_itm_system itm) {} +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java index 38fdea05c..9fdc8b8a6 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java @@ -246,7 +246,10 @@ class Wdata_claim_tbl extends Wdata_tbl_base { } @Override public String[] Fld_ary() {return new String[] {Fld_claim_id, Fld_page_id, Fld_prop_id, Fld_val_tid, Fld_entity_tid, Fld_entity_id, Fld_val_text, Fld_guid, Fld_rank, Fld_ref_count, Fld_qual_count};} private int next_claim_id = 0; + private Xob_wdata_db_visitor visitor; @Override public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) { + if (visitor == null) visitor = new Xob_wdata_db_visitor(wdata_mgr); + visitor.Init(lang_key); OrderedHash list = wdoc.Claim_list(); int list_len = list.Count(); for (int i = 0; i < list_len; i++) { @@ -256,45 +259,9 @@ class Wdata_claim_tbl extends Wdata_tbl_base { byte[] claim_val = Bry_.Empty; for (int j = 0; j < itms_len; j++) { Wdata_claim_itm_core claim = claim_grp.Get_at(j); - byte val_tid = claim.Val_tid(); - switch (val_tid) { - case Wdata_dict_val_tid.Tid_string: - Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)claim; - claim_val = claim_str.Val_str(); - break; - case Wdata_dict_val_tid.Tid_time: - Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)claim; - claim_val = claim_time.Time(); - break; - case Wdata_dict_val_tid.Tid_quantity: - Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)claim; - claim_val = claim_quantity.Amount(); - break; - case Wdata_dict_val_tid.Tid_monolingualtext: - Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)claim; - claim_val = Bry_.Add_w_dlm(Byte_ascii.Pipe, claim_monolingualtext.Lang(), claim_monolingualtext.Text()); - break; - case Wdata_dict_val_tid.Tid_entity: - Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)claim; - entity_id = claim_entity.Entity_id(); - Wdata_doc entity_doc = wdata_mgr.Pages_get(Bry_.Add(Wdata_wiki_mgr.Bry_q, claim_entity.Entity_id_bry())); - if (entity_doc != null) // NOTE: invalid document could be cited; EX: Q3235 cites prop p832 as Q14916523 - claim_val = entity_doc.Label_list_get(lang_key); - break; - case Wdata_dict_val_tid.Tid_globecoordinate: - case Wdata_dict_val_tid.Tid_bad: { - Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)claim; - claim_val = Bry_.Add_w_dlm(Byte_ascii.Comma, claim_globecoordinate.Lat(), claim_globecoordinate.Lng()); - break; - } - default: - if ( claim.Snak_tid() == Wdata_dict_snak_tid.Tid_somevalue // somevalue has no val_tid; not sure why; see Q17 and prop 138 - || claim.Snak_tid() == Wdata_dict_snak_tid.Tid_novalue) {} // novalue has no val_tid; see q30 and official language - else - throw Err_.unhandled(val_tid); - break; - } - Exec_insert(++next_claim_id, page_id, claim_grp.Id(), val_tid, claim.Snak_tid(), entity_id, claim_val, claim.Wguid(), claim.Rank_tid(), 0, 0); + claim.Welcome(visitor); + claim_val = visitor.Rv(); + Exec_insert(++next_claim_id, page_id, claim_grp.Id(), claim.Val_tid(), claim.Snak_tid(), entity_id, claim_val, claim.Wguid(), claim.Rank_tid(), 0, 0); } } } @@ -434,3 +401,19 @@ class Wdata_qual_tbl extends Wdata_tbl_base { } private static final String Fld_qual_id = "qual_id", Fld_page_id = "page_id", Fld_val_text = "val_text"; } +class Xob_wdata_db_visitor implements Wdata_claim_visitor { + private final Wdata_wiki_mgr wdata_mgr; private byte[] lang_key; + public Xob_wdata_db_visitor(Wdata_wiki_mgr wdata_mgr) {this.wdata_mgr = wdata_mgr;} + public void Init(byte[] lang_key) {this.lang_key = lang_key;} + public byte[] Rv() {return rv;} private byte[] rv; + public void Visit_str(Wdata_claim_itm_str itm) {rv = itm.Val_str();} + public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {rv = Bry_.Add_w_dlm(Byte_ascii.Pipe, itm.Lang(), itm.Text());} + public void Visit_quantity(Wdata_claim_itm_quantity itm) {rv = itm.Amount();} + public void Visit_time(Wdata_claim_itm_time itm) {rv = itm.Time();} + public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) {rv = Bry_.Add_w_dlm(Byte_ascii.Comma, itm.Lat(), itm.Lng());} + public void Visit_system(Wdata_claim_itm_system itm) {rv = Bry_.Empty;} + public void Visit_entity(Wdata_claim_itm_entity itm) { + Wdata_doc entity_doc = wdata_mgr.Pages_get(Bry_.Add(Wdata_wiki_mgr.Bry_q, itm.Entity_id_bry())); + rv = entity_doc == null ? Bry_.Empty : entity_doc.Label_list_get(lang_key); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java index 5e0b158a8..907028c8f 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java @@ -142,6 +142,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser { return rv; } private static void Claims_list_to_hash__add(OrderedHash rv, int pid, ListAdp temp_itms) { + if (temp_itms.Count() == 0) return; // NOTE: will be empty when claims are empty; EX: "claims": []; PAGE:wd.p:585; DATE:2014-10-03 Int_obj_ref claim_grp_key = Int_obj_ref.new_(pid); Wdata_claim_grp claim_grp = new Wdata_claim_grp(claim_grp_key, (Wdata_claim_itm_core[])temp_itms.XtoAryAndClear(Wdata_claim_itm_core.class)); rv.Add(claim_grp_key, claim_grp); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_external_lang_links_data.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_external_lang_links_data.java index 2df8f5d57..2b863de87 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_external_lang_links_data.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_external_lang_links_data.java @@ -20,7 +20,7 @@ import gplx.xowa.xtns.pfuncs.*; public class Wdata_external_lang_links_data { private ListAdp langs_list = ListAdp_.new_(); private Hash_adp_bry langs_hash = Hash_adp_bry.ci_ascii_(); // ASCII:lang_code public boolean Enabled() {return enabled;} private boolean enabled; public Wdata_external_lang_links_data Enabled_(boolean v) {enabled = v; return this;} - public boolean Sort() {return sort;} private boolean sort; public Wdata_external_lang_links_data Sort_(boolean v) {sort = v; return this;} + public boolean Sort() {return sort;} public Wdata_external_lang_links_data Sort_(boolean v) {sort = v; return this;} private boolean sort; public int Langs_len() {return langs_list.Count();} public Wdata_external_lang_links_data Langs_add(byte[] v) {langs_hash.Add(v, v); langs_list.Add(v); return this;} public byte[] Langs_get_at(int i) {return (byte[])langs_list.FetchAt(i);} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java index d34e7bcca..84dda8c09 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java @@ -50,7 +50,7 @@ public class Wdata_pf_property_tst { } @Test public void Geodata() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_geo(1, "1.2345", "6.789"))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_geo(1, "6.789", "1.2345"))); fxt.Test_parse("{{#property:p1}}", "1.2345, 6.789"); } @Test public void Quantity() { diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page.java b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page.java index 69112c06a..9e77c3dd7 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; -import gplx.xowa.specials.*; +import gplx.xowa.wikis.*; import gplx.xowa.specials.*; public class Wdata_itemByTitle_page implements Xows_page { private Xoa_url_arg_hash arg_hash = new Xoa_url_arg_hash(); private static final byte[] Arg_site = Bry_.new_ascii_("site"), Arg_page = Bry_.new_ascii_("page"); @@ -54,7 +54,7 @@ public class Wdata_itemByTitle_page implements Xows_page { } private static boolean Navigate(Gfo_usr_dlg usr_dlg, Xoa_app app, Wdata_wiki_mgr wdata_mgr, Xoa_page page, byte[] site_bry, byte[] page_bry) { page_bry = app.Encoder_mgr().Url().Decode(page_bry); // NOTE: space is converted to + on postback to url; decode - byte[] wiki_domain = Xob_bz2_file.Parse_wmf_key(site_bry); if (wiki_domain == null) {usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_utf8_(site_bry)); return false;} + byte[] wiki_domain = Xow_wiki_alias.Parse_wmf_key(site_bry); if (wiki_domain == null) {usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_utf8_(site_bry)); return false;} Xow_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_domain); if (wiki == null) {usr_dlg.Warn_many("", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_utf8_(wiki_domain)); return false;} Xoa_ttl wdata_ttl = Xoa_ttl.parse_(wiki, page_bry); if (wdata_ttl == null) {usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_utf8_(page_bry)); return false;} Wdata_doc doc = wdata_mgr.Pages_get(wiki, wdata_ttl); if (doc == null) {usr_dlg.Warn_many("", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_utf8_(wdata_ttl.Raw())); return false;} diff --git a/400_xowa/src_100_app/gplx/xowa/Xoa_sys_cfg.java b/400_xowa/src_100_app/gplx/xowa/Xoa_sys_cfg.java index aa43866cc..963ccae36 100644 --- a/400_xowa/src_100_app/gplx/xowa/Xoa_sys_cfg.java +++ b/400_xowa/src_100_app/gplx/xowa/Xoa_sys_cfg.java @@ -26,7 +26,6 @@ public class Xoa_sys_cfg implements GfoInvkAble { Xol_lang lang = app.Lang_mgr().Get_by_key_or_load(lang_key); app.User().Lang_(lang); app.User().Wiki().Html_mgr().Portal_mgr().Init(); - app.Gui_mgr().Lang_changed(lang); } return this; } private byte[] lang_key = Xol_lang_.Key_en; diff --git a/400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr.java b/400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr.java index 097b8ee76..a826639c8 100644 --- a/400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr.java +++ b/400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr.java @@ -21,15 +21,14 @@ public class Xow_lang_mgr { Xow_lang_mgr() { int len = Xol_lang_itm_.Id__max; itms = new Xow_lang_itm[len]; - } public Bry_fmtr Html_div() {return html_div;} Bry_fmtr html_div = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last ( "
    " - , "
    ~{langs_hdr}~{wikidata_link}
    " - , "
    ~{grps}" + , "
    ~{langs_hdr}~{wikidata_link}~{toggle_btn}
    " + , " ~{grps}" , "
    " , "
    " - ), "langs_hdr", "wikidata_link", "icon_src", "icon_title", "elem_display", "grps"); + ), "langs_hdr", "wikidata_link", "toggle_btn", "toggle_hdr", "grps"); public Bry_fmtr Html_wikidata_link() {return html_wikidata_link;} Bry_fmtr html_wikidata_link = Bry_fmtr.new_(" (wikidata)", "qid"); public void Clear() {hash.Clear();} public void Itms_reg(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) { @@ -96,11 +95,14 @@ public class Xow_lang_mgr { } } class Xow_lang_html implements Bry_fmtr_arg { - int stage = 0; + private Xow_lang_mgr lang_mgr; Xow_wiki wiki; ListAdp ttl_list; private byte[] qid; + private Xoapi_toggle_itm toggle_itm; + private int stage = 0; public Xow_lang_html Init(Xow_lang_mgr lang_mgr, Xow_wiki wiki, ListAdp ttl_list, int ttl_list_len, byte[] qid) { - this.lang_mgr = lang_mgr; this.wiki = wiki; this.ttl_list = ttl_list; this.ttl_list_len = ttl_list_len; this.qid = qid; + this.lang_mgr = lang_mgr; this.wiki = wiki; this.ttl_list = ttl_list; this.qid = qid; + toggle_itm = wiki.App().Api_root().Html().Page().Toggle_mgr().Get_or_new("wikidata-langs"); return this; - } private Xow_lang_mgr lang_mgr; Xow_wiki wiki; ListAdp ttl_list; int ttl_list_len; byte[] qid; + } public void XferAry(Bry_bfr bfr, int idx) { switch (stage) { case 0: { @@ -108,8 +110,8 @@ class Xow_lang_html implements Bry_fmtr_arg { Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b128().Mkr_rls(); byte[] msg_lang = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_page_lang_header); byte[] wikidata_link = Bry_.Len_eq_0(qid) ? Bry_.Empty : lang_mgr.Html_wikidata_link().Bld_bry_many(tmp_bfr, qid); - Xoapi_toggle_itm visible_data = wiki.App().Api_root().Html().Page().Toggle_mgr().Itm_wikidata_langs().Init(wiki); - lang_mgr.Html_div().Bld_bfr_many(bfr, msg_lang, wikidata_link, visible_data.Icon_src(), visible_data.Icon_title(), visible_data.Elem_display(), this); + toggle_itm.Init(wiki); + lang_mgr.Html_div().Bld_bfr_many(bfr, msg_lang, wikidata_link, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), this); stage = 0; break; } diff --git a/400_xowa/src_120_wiki/gplx/xowa/Xow_msg_mgr.java b/400_xowa/src_120_wiki/gplx/xowa/Xow_msg_mgr.java index 385bc877f..815acb4f7 100644 --- a/400_xowa/src_120_wiki/gplx/xowa/Xow_msg_mgr.java +++ b/400_xowa/src_120_wiki/gplx/xowa/Xow_msg_mgr.java @@ -25,7 +25,10 @@ public class Xow_msg_mgr implements GfoInvkAble { this.msg_mgr = new Xol_msg_mgr(wiki, false); } public void Clear() {msg_mgr.Clear();} - public void Lang_(Xol_lang v) {this.lang = v;} + public void Lang_(Xol_lang v) { + this.lang = v; + this.Clear(); + } public byte[] Val_by_id_args(int id, Object... args) {return Val_by_id_priv(id, args);} public byte[] Val_by_id(int id) {return Val_by_id_priv(id, null);} private byte[] Val_by_id_priv(int id, Object[] args) { diff --git a/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java b/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java index d282c1937..2d9128b37 100644 --- a/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java +++ b/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java @@ -27,7 +27,7 @@ public class Xow_wiki implements GfoInvkAble { this.app = app; this.ns_mgr = ns_mgr; this.lang = lang; domain_str = wiki_dir.NameOnly(); domain_bry = Bry_.new_utf8_(domain_str); domain_itm = Xow_wiki_domain_.parse_by_domain(domain_bry); - domain_tid = domain_itm.Tid(); + domain_tid = domain_itm.Wiki_tid(); xwiki_domain_tid = Xow_wiki_domain_.Xwiki_tid(domain_tid); fsys_mgr = new Xow_fsys_mgr(this, wiki_dir); redirect_mgr = new Xop_redirect_mgr(this); @@ -64,7 +64,7 @@ public class Xow_wiki implements GfoInvkAble { } Wdata_wiki_abrv_(); db_mgr = new gplx.xowa.dbs.Xodb_mgr_txt(this, data_mgr); - domain_abrv = Xob_bz2_file.Build_alias(Xow_wiki_domain_.parse_by_domain(domain_bry)); + domain_abrv = Xow_wiki_alias.Build_alias(Xow_wiki_domain_.parse_by_domain(domain_bry)); maint_mgr = new Xow_maint_mgr(this); cache_mgr = new Xow_cache_mgr(this); } @@ -101,7 +101,7 @@ public class Xow_wiki implements GfoInvkAble { public byte[] Wdata_wiki_abrv() {return wdata_wiki_abrv;} private byte[] wdata_wiki_abrv; private byte wdata_wiki_tid; private void Wdata_wiki_abrv_() { Bry_bfr bfr = app.Utl_bry_bfr_mkr().Get_b128(); - Xob_bz2_file.Build_alias_by_lang_tid(bfr, wdata_wiki_lang, Byte_obj_ref.new_(wdata_wiki_tid)); + Xow_wiki_alias.Build_alias_by_lang_tid(bfr, wdata_wiki_lang, Byte_obj_ref.new_(wdata_wiki_tid)); wdata_wiki_abrv = bfr.Mkr_rls().XtoAryAndClear(); } diff --git a/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr.java b/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr.java index fb64f0f2c..e03d1825e 100644 --- a/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr.java +++ b/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr.java @@ -185,7 +185,7 @@ public class Xol_fragment_mgr implements GfoInvkAble { , " 'deprecated' : '~{deprecated}'" , " };" , " " - , " " +// , " " ) , "languages", "toc", "labels", "aliasesHead", "descriptions", "links", "claims", "json", "language", "wiki", "label", "aliases", "description", "link", "property", "value", "references", "qualifiers" , "comma_separator", "word_separator", "parentheses", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", "ago", "novalue", "somevalue" diff --git a/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr_tst.java b/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr_tst.java index 65336a163..d0dda1bc1 100644 --- a/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr_tst.java +++ b/400_xowa/src_140_lang/gplx/xowa/Xol_fragment_mgr_tst.java @@ -98,7 +98,7 @@ public class Xol_fragment_mgr_tst { , " 'deprecated' : 'deprecated'" , " };" , " " - , " " +// , " " )); } } diff --git a/400_xowa/src_140_lang/gplx/xowa/Xol_lang_itm_.java b/400_xowa/src_140_lang/gplx/xowa/Xol_lang_itm_.java index 7a1e2fe3d..12770f725 100644 --- a/400_xowa/src_140_lang/gplx/xowa/Xol_lang_itm_.java +++ b/400_xowa/src_140_lang/gplx/xowa/Xol_lang_itm_.java @@ -868,6 +868,7 @@ Regy_add(regy, Id_zu, "zu", "isiZulu"); return lang_itm; } public static Xol_lang_itm Get_by_key(byte[] key) {if (regy == null) Regy(); return (Xol_lang_itm)regy.Get_by_bry(key);} + public static Xol_lang_itm Get_by_key_or_intl(byte[] key) {return Get_by_key_or_intl(key, 0, key.length);} public static Xol_lang_itm Get_by_key_or_intl(byte[] key, int bgn, int end) { if (regy == null) Regy(); Xol_lang_itm rv = (Xol_lang_itm)regy.Get_by_mid(key, bgn, end); diff --git a/400_xowa/src_240_install/gplx/xowa/Xoa_css_extractor.java b/400_xowa/src_240_install/gplx/xowa/Xoa_css_extractor.java index fe726aed5..9f7a86d5f 100644 --- a/400_xowa/src_240_install/gplx/xowa/Xoa_css_extractor.java +++ b/400_xowa/src_240_install/gplx/xowa/Xoa_css_extractor.java @@ -167,11 +167,14 @@ public class Xoa_css_extractor { return mainpage_html != null; } private byte[] Mainpage_download_html() { - String log_msg = usr_dlg.Prog_many("", "main_page.download", "downloading main page for '~{0}'", wiki_domain); - byte[] main_page_html = download_xrg.Prog_fmt_hdr_(log_msg).Exec_as_bry(mainpage_url); - if (main_page_html == null) usr_dlg.Warn_many("", "", "failed to download main_page: src_url=~{0};", mainpage_url); + String main_page_url_temp = mainpage_url; + if (Bry_.Eq(wiki_domain, Xow_wiki_domain_.Url_wikidata)) // if wikidata, download css for a Q* page; Main_Page has less css; DATE:2014-09-30 + main_page_url_temp = main_page_url_temp + "/wiki/Q2"; + String log_msg = usr_dlg.Prog_many("", "main_page.download", "downloading main page for '~{0}'", main_page_url_temp); + byte[] main_page_html = download_xrg.Prog_fmt_hdr_(log_msg).Exec_as_bry(main_page_url_temp); + if (main_page_html == null) usr_dlg.Warn_many("", "", "failed to download main_page: src_url=~{0};", main_page_url_temp); return main_page_html; - } + } private void Failover(Io_url trg_fil) { usr_dlg.Note_many("", "", "copying failover file: trg_fil=~{0};", trg_fil.Raw()); Io_mgr._.CopyFil(failover_dir.GenSubFil(trg_fil.NameAndExt()), trg_fil, true); diff --git a/400_xowa/src_240_install/gplx/xowa/Xob_dump_file.java b/400_xowa/src_240_install/gplx/xowa/Xob_dump_file.java index 13682cf3a..b86205047 100644 --- a/400_xowa/src_240_install/gplx/xowa/Xob_dump_file.java +++ b/400_xowa/src_240_install/gplx/xowa/Xob_dump_file.java @@ -30,12 +30,12 @@ public class Xob_dump_file { public Xob_dump_file Ctor(String wiki_domain, String dump_date, String dump_file_type) { this.dump_date = dump_date; this.dump_file_type = dump_file_type; this.wiki_type = Xow_wiki_domain_.parse_by_domain(Bry_.new_ascii_(wiki_domain)); - this.wiki_alias = Xob_bz2_file.Build_alias(wiki_type); + this.wiki_alias = Xow_wiki_alias.Build_alias(wiki_type); byte[] dump_file_bry = Bry_.new_utf8_(dump_file_type); - byte dump_file_tid = Xob_bz2_file.Parse__tid(dump_file_bry); + byte dump_file_tid = Xow_wiki_alias.Parse__tid(dump_file_bry); byte[] ext = Xob_dump_file_.Ext_xml_bz2; switch (dump_file_tid) { - case Xob_bz2_file.Tid_page_props: case Xob_bz2_file.Tid_categorylinks: case Xob_bz2_file.Tid_image: + case Xow_wiki_alias.Tid_page_props: case Xow_wiki_alias.Tid_categorylinks: case Xow_wiki_alias.Tid_image: ext = Xob_dump_file_.Ext_sql_gz; break; } diff --git a/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_base.java b/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_base.java index 8bb189a1f..9de1bee46 100644 --- a/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_base.java +++ b/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_base.java @@ -15,8 +15,8 @@ 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 . */ - package gplx.xowa; import gplx.*; -import gplx.threads.*; +package gplx.xowa; import gplx.*; +import gplx.threads.*; import gplx.xowa.wikis.*; abstract class Xoi_cmd_base implements Gfo_thread_cmd { public void Ctor(Xoi_setup_mgr install_mgr, String wiki_key) { this.install_mgr = install_mgr; this.wiki_key = wiki_key; @@ -68,11 +68,11 @@ abstract class Xoi_cmd_base implements Gfo_thread_cmd { return this; } private static final String Invk_process_async = "run_async", Invk_owner = "owner"; } -class Xoi_cmd_category2_page_props extends Xoi_cmd_wiki_download { public Xoi_cmd_category2_page_props(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date) {this.Ctor_download_(install_mgr, wiki_key, dump_date, Xob_bz2_file.Key_page_props);} +class Xoi_cmd_category2_page_props extends Xoi_cmd_wiki_download { public Xoi_cmd_category2_page_props(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date) {this.Ctor_download_(install_mgr, wiki_key, dump_date, Xow_wiki_alias.Key_page_props);} @Override public String Download_file_ext() {return ".sql.gz2";} public static final String KEY_category2 = "wiki.category2.download.page_props"; } -class Xoi_cmd_category2_categorylinks extends Xoi_cmd_wiki_download { public Xoi_cmd_category2_categorylinks(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date) {this.Ctor_download_(install_mgr, wiki_key, dump_date, Xob_bz2_file.Key_categorylinks);} +class Xoi_cmd_category2_categorylinks extends Xoi_cmd_wiki_download { public Xoi_cmd_category2_categorylinks(Xoi_setup_mgr install_mgr, String wiki_key, String dump_date) {this.Ctor_download_(install_mgr, wiki_key, dump_date, Xow_wiki_alias.Key_categorylinks);} @Override public String Download_file_ext() {return ".sql.gz2";} public static final String KEY_category2 = "wiki.category2.download.categorylinks"; } diff --git a/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki.java b/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki.java index 514a37ca2..1ff99fdcc 100644 --- a/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki.java +++ b/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki.java @@ -41,7 +41,7 @@ class Xoi_cmd_wiki_download extends Gfo_thread_cmd_download implements Gfo_threa Dump_servers_offline_msg_shown = true; } } - Xow_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(dump_file.Wiki_type().Raw()); + Xow_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(dump_file.Wiki_type().Domain_bry()); Io_url root_dir = wiki.Fsys_mgr().Root_dir(); Io_url[] trg_fil_ary = Io_mgr._.QueryDir_args(root_dir).FilPath_("*." + dump_type + Download_file_ext() + "*").ExecAsUrlAry(); Io_url trg = trg_fil_ary.length == 0 ? root_dir.GenSubFil(dump_file.File_name()) : trg_fil_ary[0]; diff --git a/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki_tst.java b/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki_tst.java index 928e4dba2..e167b092d 100644 --- a/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki_tst.java +++ b/400_xowa/src_240_install/gplx/xowa/Xoi_cmd_wiki_tst.java @@ -30,7 +30,7 @@ public class Xoi_cmd_wiki_tst { Xob_dump_file dump_file = new Xob_dump_file(); for (int i = 0; i < ary_len; i++) { String itm = ary[i]; - dump_file.Ctor(itm, "latest", Xob_bz2_file.Key_pages_articles); + dump_file.Ctor(itm, "latest", Xow_wiki_alias.Key_pages_articles); int count = 0; while (count++ < 10) { dump_file.Server_url_(Xob_dump_file_.Server_wmf); @@ -46,7 +46,7 @@ public class Xoi_cmd_wiki_tst { Tfds.WriteText(String_.Format("passed: {0}\n", itm)); bfr.Add_str(itm).Add_byte_pipe(); bfr.Add_str(dump_file.File_url()).Add_byte_pipe(); - bfr.Add(Xow_wiki_domain_.Key_by_tid(dump_file.Wiki_type().Tid())).Add_byte_pipe(); + bfr.Add(Xow_wiki_domain_.Key_by_tid(dump_file.Wiki_type().Wiki_tid())).Add_byte_pipe(); // Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang_key()); // if (lang_itm == null) lang_itm = Xol_lang_itm_.Get_by_key(Xol_lang_.Key_en); // commons, species, meta, etc will have no lang // bfr.Add(lang_itm.Local_name()).Add_byte_pipe(); diff --git a/LICENSE.txt b/LICENSE.txt index 23714921b..518ea5c74 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,15 +1,624 @@ -XOWA: the XOWA Offline Wiki Application -Copyright (c) 2012 gnosygnu@gmail.com +/*************************************************************************** + 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. + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 -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 -[http://www.gnu.org/licenses/agpl.txt GNU Affero General Public License] for more details. + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS diff --git a/README.txt b/README.txt index 50274cc21..b25a0693a 100644 --- a/README.txt +++ b/README.txt @@ -1,48 +1,69 @@ == Overview == -XOWA is an offline Wikipedia application. It is meant to be used with the dumps at https://dumps.wikimedia.org. +XOWA is an offline Wikipedia application. It can run an offline copy of Wikipedia on your computer by using any of the dumps at https://dumps.wikimedia.org. It can run as a standalone GUI application, as a Firefox addon, or as a HTTP server. -This is the initial draft of a README. Most of the instructions below are Windows-centric, and will be updated later to a more machine-agnostic form. +== License == +XOWA is released under the AGPLv3 license. See LICENSE.txt for more information. -In addition, the enclosed build.xml assumes a Windows environment with an XOWA installation at C:\xowa. This too will be updated at a later date to be more portable. +== Operating Systems == +XOWA runs on Linux, Windows, and Mac OS X. These instructions will assume the user is on a 64-bit Linux system. However, if you're on a different system, the same instructions still apply. Simply substitute "linux_64" with the appropriate XOWA operating system name from below: +* Linux 64-bit : "linux_64" +* Linux 32-bit : "linux" +* Windows 64-bit : "windows_64" +* Windows 32-bit : "windows" +* Mac OS X 64-bit : "macosx_64" +* Mac OS X 32-bit : "macosx" -== Requirements == +== Software Requirements == XOWA is written in Java and requires 1.6 or above. It has seven dependencies: # JUnit 4.8.2 (default version with Eclipse) # [https://download.eclipse.org/eclipse/downloads/drops4/R-4.2.1-201209141800/#SWT SWT 4.2.1]: GUI library -# [https://sourceforge.net/projects/xowa/files/support/luaj/ luaj_xowa.jar]: Lua library -# [https://sourceforge.net/projects/jtidy/files/JTidy/r938/jtidy-r938.jar/download jtidy-r938.jar]: HTML tidy library +# [https://github.com/gnosygnu/luaj_xowa luaj_xowa.jar]: Lua library +# [https://github.com/gnosygnu/jtidy_xowa jtidy_xowa.jar]: HTML tidy library # [https://bitbucket.org/xerial/sqlite-jdbc/downloads sqlite-jdbc-3.7.15-SNAPSHOT-2.jar]: Database library # [https://dev.mysql.com/downloads/connector/j/ mysql-connector-java-5.1.12-bin.jar]: Database library # [https://jdbc.postgresql.org/download.html postgresql-8.4-701.jdbc4.jar]: Database library Note that the last two libraries are not currently used in XOWA. -== Environment == -The '''xowa_source.7z''' was built with Eclipse Indigo on Windows. For simplicity's sake, the remainder of these instructions will target Windows machines. There are no OS dependencies, so the same instructions apply to other OS's, except the paths will need to be updated. +== Compilation instructions (ANT command-line) == +=== Setup the XOWA app === +* Download the latest XOWA app package for your operating system. For example, if you're on a 64-bit Linux system, "xowa_app_linux_64_v1.9.5.1.zip". +* Unzip the XOWA app package to a directory. For the sake of simplicity, these instructions assume this directory is "/xowa/" +* Review your directories. You should have the following: +** An XOWA jar: "/xowa/xowa_linux_64.jar" +** An XOWA "/bin/any/" directory with several jar files. For example, "/xowa/bin/any/java/apache/commons-compress-1.5.jar" +** An XOWA "/bin/linux_64/" directory with an SWT jar: "/xowa/bin/linux_64/swt/swt.jar" -There are no explicit dependencies on Eclipse, so the source code should be usable in other Java IDEs. +=== Setup the XOWA source === +* Download the latest XOWA source archive. For example: "xowa_source_v1.9.5.1.7z" +* Unzip the source to "/xowa/dev". When you're done, you'll have a file called "/xowa/dev/build.xml" as well as others +: NOTE: if you're not on a Linux 64-bit system, overwrite the swt jar at "/xowa/dev/150_gfui/lib/swt.jar" with the copy from your "/bin/OS" directory. For example, if you're on a 64 bit Windows system, replace "/xowa/dev/150_gfui/lib/swt.jar" with "/bin/windows_64/swt/swt/jar" -== Instructions == -* Download '''xowa_app_windows_*''' and unzip to the proper directory. The following will be required: -** All files under {{fsysname|C:\xowa\user\anonymous\}} -** The main cfg file: {{fsysname|C:\xowa\xowa.gfs}} -** The swt.jar at {{fsysname|C:\xowa\bin\your_platform_name\swt\swt.jar}} -* Download '''xowa_source.7z''' -* Unzip it to {{fsysname|C:\xowa\dev\}}. You will have a folder called {{fsysname|C:\xowa\dev\400_xowa}} as well as many others. -* Move the swt.jar from {{fsysname|C:\xowa\bin\your_platform_name\swt\swt.jar}} to {{fsysname|C:\xowa\dev\150_gfui\lib\swt\swt.jar}} -* Launch Eclipse. Choose a workbench folder of {{fsysname|C:\xowa\dev}} -* Select all four projects. Do File -> Refresh. +=== Run the ant file === +* Open up a console, and run "ant -buildfile build.xml -Dplat_name=linux_64" + +== IDE instructions (Eclipse) == +=== Environment === +The '''xowa_source.7z''' was built with Eclipse Indigo. There are no OS dependencies, nor are there dependencies on Eclipse. + +=== Setup === +* Follow the steps in these two sections from above: +** Setup the XOWA app +** Setup the XOWA source +* Launch Eclipse. Choose a workbench folder of "/xowa/dev" +* If the projects don't load, do File -> Import -> Existing Projects Into Workspace +* Select all projects. Do File -> Refresh. * Right-click on 400_xowa in the Package Explorer. Select Debug As -> Java Application. Select Xowa_main. XOWA should launch. * Right-click on 400_xowa in the Package Explorer. Select Debug As -> JUnit Test. All tests should pass. -== Eclipse-specific settings == +=== Eclipse-specific settings === This section documents specific project customizations that differ from the standard Eclipse defaults. -=== Project properties === +==== Project properties ==== Resource -> Text file encoding -> Other -> UTF-8 -=== Preferences === +==== Preferences ==== These settings are available under Window -> Preferences *Disable Spelling @@ -51,11 +72,11 @@ These settings are available under Window -> Preferences :Java -> Compiler -> Errors/Warnings :: Annotations -> Unhandled token in '@SuppressWarnings' :: Potential programming problems -> Serializable class without serialVersionUID -:: Generic Types -> Unnecessary generic type operation +:: Generic Types -> Unnecessary generic type operation (In Eclipse Luna: "Unchecked generic type operation") :: Generic Types -> Usage of a raw type :: Unnecessary Code -> Unused import -=== Configuration arguments === +==== Configuration arguments ==== *Configuration arguments :Run -> Debug Configurations -> Arguments -::--root_dir C:\xowa\ --show_license n --show_args n +::--root_dir /xowa/ --show_license n --show_args n diff --git a/build.xml b/build.xml index 89eeeae06..d9df93a22 100644 --- a/build.xml +++ b/build.xml @@ -1,52 +1,52 @@ - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - - - - - + + + + + diff --git a/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 b/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 index 6778de16f..344a1a0ed 100644 Binary files a/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 and b/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 differ