mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
v1.10.1.1
This commit is contained in:
parent
81c8e2554c
commit
cd5a440404
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);}
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Binary file not shown.
@ -30,6 +30,6 @@
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/140_dbs"/>
|
||||
<classpathentry kind="lib" path="lib/luaj_xowa.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jtidy_xowa.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/100_jre_1_7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
BIN
400_xowa/lib/jtidy_xowa.jar
Normal file
BIN
400_xowa/lib/jtidy_xowa.jar
Normal file
Binary file not shown.
@ -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() {
|
||||
|
@ -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 = "";
|
||||
|
@ -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();
|
||||
|
@ -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"
|
||||
;
|
||||
}
|
||||
|
@ -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_("<a href='javascript:xowa_toggle_visible(\"~{key}\");'><img id='~{key}-toggle-icon' src='~{src}' title='~{title}' /></a>")
|
||||
.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;")
|
||||
;
|
||||
}
|
||||
|
@ -18,34 +18,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
|
||||
import gplx.xowa.cfgs.*;
|
||||
public class Xoapi_toggle_mgr implements GfoInvkAble {
|
||||
private Hash_adp_bry itms = Hash_adp_bry.cs_();
|
||||
public Xoapi_toggle_mgr() {
|
||||
itm_wikidata_langs = itms_add(itms, Key_wikidata_langs);
|
||||
itm_offline_wikis = itms_add(itms, Key_offline_wikis);
|
||||
}
|
||||
public Xoapi_toggle_itm Itm_wikidata_langs() {return itm_wikidata_langs;} private Xoapi_toggle_itm itm_wikidata_langs;
|
||||
public Xoapi_toggle_itm Itm_offline_wikis() {return itm_offline_wikis;} private Xoapi_toggle_itm itm_offline_wikis;
|
||||
public Xoapi_toggle_itm Get(byte[] key) {return (Xoapi_toggle_itm)itms.Get_by_bry(key);}
|
||||
public void Save(Xoa_cfg_mgr cfg_mgr) {
|
||||
Save_itm(cfg_mgr, itm_wikidata_langs, itm_offline_wikis);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return this.Get(m.ReadBry("key"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_get = "get";
|
||||
private static final String Key_wikidata_langs = "wikidata-langs", Key_offline_wikis = "offline-wikis";
|
||||
private static Xoapi_toggle_itm itms_add(Hash_adp_bry itms, String name_str) {
|
||||
byte[] name_bry = Bry_.new_utf8_(name_str);
|
||||
Xoapi_toggle_itm rv = new Xoapi_toggle_itm(name_bry);
|
||||
itms.Add(name_bry, rv);
|
||||
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";
|
||||
}
|
||||
|
@ -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
|
||||
( "<div dir=~{page_lang_ltr}>"
|
||||
, " <div>~{content}"
|
||||
|
48
400_xowa/src/gplx/xowa/apis/xowa/xtns/Xoapi_wikibase.java
Normal file
48
400_xowa/src/gplx/xowa/apis/xowa/xtns/Xoapi_wikibase.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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"
|
||||
;
|
||||
}
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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());
|
||||
|
@ -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;
|
||||
|
@ -16,10 +16,11 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui; 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;
|
||||
}
|
||||
|
@ -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 (<i>). 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 (<i>). 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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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:"<i>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:"<i>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;
|
||||
}
|
||||
|
@ -16,11 +16,29 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.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;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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)));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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();
|
||||
|
@ -17,8 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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());
|
||||
|
@ -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));
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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"
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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_();
|
||||
}
|
@ -17,23 +17,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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())));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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));
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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"));
|
||||
|
@ -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;
|
||||
|
@ -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_()
|
||||
|
@ -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
|
||||
|
@ -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));}
|
||||
|
@ -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<EFBFBD>ois_Malgaigne; DATE:2014-04-07
|
||||
}
|
||||
}
|
||||
|
@ -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:"
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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_("±");
|
||||
}
|
@ -16,21 +16,26 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.json.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.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); // <span id="xowa-wikidata-json">
|
||||
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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
38
400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xtn_mgr.java
Normal file
38
400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xtn_mgr.java
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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);
|
||||
}
|
||||
}
|
@ -17,10 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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)));
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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);
|
||||
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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";
|
||||
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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));
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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");
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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));
|
||||
}
|
||||
|
@ -16,27 +16,29 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.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));
|
||||
}
|
||||
|
@ -16,12 +16,14 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.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));
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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);}
|
||||
}
|
||||
|
@ -16,9 +16,10 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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);
|
||||
}
|
@ -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 ?
|
||||
;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.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);
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
@ -17,12 +17,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,16 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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)));
|
||||
}
|
||||
|
285
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__claim.java
Normal file
285
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__claim.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
( ""
|
||||
, " <h2 class='wb-section-heading' dir='auto' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
|
||||
, " <div class='wb-claimlistview'~{toggle_hdr}>"
|
||||
, " <div class='wb-claims' id=''>"
|
||||
, " <div class='wb-claimgrouplistview'>"
|
||||
, " <div class='wb-claimlists'>~{tbls}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <div class='wb-claimlistview'>"
|
||||
, " <div class='wb-claims' id='P~{pid}'>~{itms}"
|
||||
, " </div>"
|
||||
, " <div class='wb-claimgrouplistview-groupname'>"
|
||||
, " <div class='wb-claim-name' dir='auto'>"
|
||||
, " P~{pid} - <a href='/wiki/Property:P~{pid}' title='Property:P~{pid}'>~{pid_lbl}</a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <div class='wb-statement wb-statementview wb-claimview'>"
|
||||
, " <div class='wb-statement-rank'>"
|
||||
, " <div class='wb-rankselector ui-state-disabled'>"
|
||||
, " <span class='ui-icon ui-icon-rankselector wb-rankselector-~{rank_name}' title='~{rank_name} rank'/>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class='wb-claim wb-claim'>" // omit -Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e
|
||||
, " <div class='wb-claim-mainsnak' dir='auto'>"
|
||||
, " <div class='wb-snak wb-snakview'>"
|
||||
, " <div class='wb-snak-property-container'>"
|
||||
, " <div class='wb-snak-property' dir='auto'></div>"
|
||||
, " </div>"
|
||||
, " <div class='wb-snak-value-container' dir='auto'>"
|
||||
, " <div class='wb-snak-typeselector'></div>"
|
||||
, " <div class='wb-snak-value wb-snakview-variation-valuesnak'>~{value}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>~{qualifiers}"
|
||||
, " </div>~{references}"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <div class='wb-claim-qualifiers wb-statement-qualifiers'>"
|
||||
, " <div class='wb-listview'>~{itms}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <div class='wb-snaklistview'>"
|
||||
, " <div class='wb-snaklistview-listview'>"
|
||||
, " <div class='wb-snak wb-snakview'>"
|
||||
, " <div class='wb-snak-property-container'>"
|
||||
, " <div class='wb-snak-property' dir='auto'>"
|
||||
, " <a href='/wiki/Property:P~{pid}' title='Property:P~{pid}'>~{pid_lbl}</a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class='wb-snak-value-container' dir='auto'>"
|
||||
, " <div class='wb-snak-typeselector'></div>"
|
||||
, " <div class='wb-snak-value wb-snakview-variation-valuesnak'>~{value}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
// , " <div class='wb-statement-references-heading'>1 reference</div>"
|
||||
, " <div class='wb-statement-references'>"
|
||||
, " <div class='wb-listview'>"
|
||||
, " <div class='wb-referenceview'>" // OMIT: wb-referenceview-8e7d51e38606193465d2a1e9d41ba490e06682a6
|
||||
, " <div class='wb-referenceview-heading'></div>"
|
||||
, " <div class='wb-referenceview-listview'>"
|
||||
, " <div class='wb-snaklistview'>"
|
||||
, " <div class='wb-snaklistview-listview'>~{itms}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <div class='wb-snak wb-snakview'>"
|
||||
, " <div class='wb-snak-property-container'>"
|
||||
, " <div class='wb-snak-property' dir='auto'>"
|
||||
, " <a href='/wiki/Property:~{pid}' title='Property:~{pid}'>~{pid_lbl}</a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class='wb-snak-value-container' dir='auto'>"
|
||||
, " <div class='wb-snak-typeselector'></div>"
|
||||
, " <div class='wb-snak-value wb-snakview-variation-valuesnak'>~{value}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "pid", "pid_lbl", "value"
|
||||
);
|
||||
}
|
@ -16,24 +16,31 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.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
|
||||
( ""
|
||||
, "<h2>~{hdr}</h2>"
|
||||
, ""
|
||||
, "~{json}"
|
||||
), "hdr", "json");
|
||||
, " <h2 class='wb-section-heading' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
|
||||
, " <pre~{toggle_hdr}>~{json}"
|
||||
, " </pre>"
|
||||
), "hdr_href", "hdr_text", "toggle_btn", "toggle_hdr", "json");
|
||||
}
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
( ""
|
||||
, " <div class='wikibase-sitelinkgroupview'>"
|
||||
, " <div class='wikibase-sitelinkgroupview-heading-container'>"
|
||||
, " <h2 class='wb-section-heading wikibase-sitelinkgroupview-heading' dir='auto' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
|
||||
, " </div>"
|
||||
, " <table class='wikibase-sitelinklistview'~{toggle_hdr}>"
|
||||
, " <colgroup>"
|
||||
, " <col class='wikibase-sitelinklistview-sitename' />"
|
||||
, " <col class='wikibase-sitelinklistview-siteid' />"
|
||||
, " <col class='wikibase-sitelinklistview-link' />"
|
||||
, " </colgroup>"
|
||||
, " <thead>"
|
||||
, " <tr class='wikibase-sitelinklistview-columnheaders'>"
|
||||
, " <th class='wikibase-sitelinkview-sitename'>~{hdr_lang_name}</th>"
|
||||
, " <th class='wikibase-sitelinkview-siteid'>~{hdr_lang_code}</th>"
|
||||
, " <th class='wikibase-sitelinkview-link'>~{hdr_page}</th>"
|
||||
, " </tr>"
|
||||
, " </thead>"
|
||||
, " <tbody>~{rows}"
|
||||
, " </tbody>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <tr class='wikibase-sitelinkview'>"
|
||||
, " <td class='wikibase-sitelinkview-sitename' lang='~{lang_code}' dir='auto'>~{lang_name}</td>"
|
||||
, " <td class='wikibase-sitelinkview-siteid'>~{lang_code}</td>"
|
||||
, " <td class='wikibase-sitelinkview-link' lang='~{lang_code}' dir='auto'>~{text}</td>"
|
||||
, " </tr>"
|
||||
), "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
|
||||
( ""
|
||||
, " <tr class='wikibase-sitelinkview'>"
|
||||
, " <td class='wikibase-sitelinkview-sitename' lang='~{lang_code}' dir='auto'>~{lang_name}</td>"
|
||||
, " <td class='wikibase-sitelinkview-siteid'>~{lang_code}</td>"
|
||||
, " <td class='wikibase-sitelinkview-link' lang='~{lang_code}' dir='auto'>~{text}</td>"
|
||||
, " </tr>"
|
||||
), "lang_code", "lang_name", "text"
|
||||
);
|
||||
}
|
100
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__oview.java
Normal file
100
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__oview.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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_("<a href='/site/~{domain_bry}/wiki/~{page_href}'>~{page_text}</a>", "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
|
||||
( ""
|
||||
, " <h1 id='wb-firstHeading-~{ttl}' class='wb-firstHeading'>"
|
||||
, " <div class='wikibase-labelview '>"
|
||||
, " <div class='wikibase-labelview-container'>"
|
||||
, " <span class='wikibase-labelview-text'>~{ttl_label}</span>"
|
||||
, " <span class='wikibase-labelview-entityid'>(~{ttl})</span>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </h1>"
|
||||
, " <div class='wikibase-descriptionview ' dir='auto'>"
|
||||
, " <div class='wikibase-descriptionview-container'>"
|
||||
, " <span class='wikibase-descriptionview-text'>~{ttl_descr}</span>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <hr class='wb-hr' />"
|
||||
, " <div class='wikibase-aliasesview '>"
|
||||
, " <div class='wikibase-aliasesview-container'>"
|
||||
, " <span class='wikibase-aliasesview-label'>~{hdr_aliases}</span>"
|
||||
, " <ul class='wikibase-aliasesview-list'>~{ttl_aliases}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <li class='wikibase-aliasesview-list-item'>~{itm}</li>"
|
||||
), "itm"
|
||||
);
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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
|
||||
( ""
|
||||
, "<h2>~{hdr}</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>~{site_lbl}</th>"
|
||||
, " <th>~{link_lbl}</th>"
|
||||
, " <th>~{bdgs_lbl}</th>"
|
||||
, " </tr>~{rows}"
|
||||
, "</table>"
|
||||
), "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
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <td><a href='/site/~{domain}/wiki/'><code>~{site}</code></a></td>"
|
||||
, " <td><a href='/site/~{domain}/wiki/~{page}'>~{page}</a></td>"
|
||||
, " </tr>"
|
||||
), "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
|
||||
// }
|
173
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__slink.java
Normal file
173
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__slink.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
( ""
|
||||
, " <div class='wikibase-sitelinkgrouplistview'>"
|
||||
, " <div class='wb-listview'>~{grps}"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <div class='wikibase-sitelinkgroupview' data-wb-sitelinks-group='wikipedia'>"
|
||||
, " <div class='wikibase-sitelinkgroupview-heading-container'>"
|
||||
, " <h2 class='wb-section-heading wikibase-sitelinkgroupview-heading' dir='auto' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
|
||||
, " </div>"
|
||||
, " <table class='wikibase-sitelinklistview'~{toggle_hdr}>"
|
||||
, " <colgroup>"
|
||||
, " <col class='wikibase-sitelinklistview-sitename' />"
|
||||
, " <col class='wikibase-sitelinklistview-siteid' />"
|
||||
, " <col class='wikibase-sitelinklistview-link' />"
|
||||
, " </colgroup>"
|
||||
, " <thead>"
|
||||
, " <tr class='wikibase-sitelinklistview-columnheaders'>"
|
||||
, " <th class='wikibase-sitelinkview-sitename'>~{hdr_lang}</th>"
|
||||
, " <th class='wikibase-sitelinkview-siteid'>~{hdr_wiki}</th>"
|
||||
, " <th class='wikibase-sitelinkview-link'>~{hdr_page}</th>"
|
||||
, " </tr>"
|
||||
, " </thead>"
|
||||
, " <tbody>~{rows}"
|
||||
, " </tbody>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <tr class='wikibase-sitelinkview'>" // wikibase-sitelinkview-~{wmf_key} data-wb-siteid='~{wmf_key}'
|
||||
, " <td class='wikibase-sitelinkview-sitename' lang='~{lang_code}' dir='auto'>~{lang_name}</td>" // wikibase-sitelinkview-sitename-~{wmf_key}
|
||||
, " <td class='wikibase-sitelinkview-siteid'>~{wmf_key}</td>" // wikibase-sitelinkview-siteid-~{wmf_key}
|
||||
, " <td class='wikibase-sitelinkview-link' lang='~{lang_code}' dir='auto'>" // wikibase-sitelinkview-link-~{wmf_key}
|
||||
, " <span class='wikibase-sitelinkview-badges'>~{badges}"
|
||||
, " </span>"
|
||||
, " <span class='wikibase-sitelinkview-page'>"
|
||||
, " <a href='~{href_site}~{href_domain}/wiki/~{href_page}' hreflang='~{lang_code}' dir='auto'>~{page_name}</a>"
|
||||
, " </span>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
), "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 <span class='wb-badge wb-badge-~{ttl} wb-badge-~{cls}' title='~{name}'></span>"
|
||||
, "ttl", "cls", "name"
|
||||
);
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
( ""
|
||||
, " <div id='toc' class='toc wb-toc'>"
|
||||
, " <div id='toctitle'>"
|
||||
, " <h2>~{hdr}</h2>"
|
||||
, " </div>"
|
||||
, " <ul>~{itms}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
), "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
|
||||
( ""
|
||||
, " <li class='toclevel-1 tocsection-~{idx}'>"
|
||||
, " <a href='#~{href}'>"
|
||||
, " <span class='toctext'>~{text}</span>"
|
||||
, " </a>"
|
||||
, " </li>"
|
||||
), "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} <sup><small>(~{len})</small></sup>", "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;
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
( ""
|
||||
, "<p>"
|
||||
, " <div id='toc' class='toc'>"
|
||||
, " <div id='toctitle'><h2>~{hdr}</h2></div>"
|
||||
, " <ul>~{itms}"
|
||||
, " </ul>"
|
||||
, " </div}"
|
||||
, "</p>"
|
||||
), "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_
|
||||
( " <li class='toclevel-1 tocsection-~{idx}'><a href='#~{hdr}'><span class='tocnumber'>~{idx}</span> <span class='toctext'>~{hdr}</span></a></li>"
|
||||
, "idx", "href", "text");
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
( ""
|
||||
, "<h2>~{hdr}</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>~{lang_lbl}</th>"
|
||||
, " <th>~{text_lbl}</th>"
|
||||
, " </tr>~{rows}"
|
||||
, "</table>"
|
||||
), "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
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <td><code>~{lang}</code></td>"
|
||||
, " <td>~{text}</td>"
|
||||
, " </tr>"
|
||||
), "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
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <td><code>~{lang}</code></td>"
|
||||
, " <td>~{text}</td>"
|
||||
, " </tr>"
|
||||
), "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
|
||||
( ""
|
||||
, "<h2>~{hdr}</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>~{prop_id}</th>"
|
||||
, " <th>~{prop_name}</th>"
|
||||
, " <th>~{val}</th>"
|
||||
, " <th>~{ref}</th>"
|
||||
, " <th>~{qual}</th>"
|
||||
, " <th>~{rank}</th>"
|
||||
, " </tr>~{rows}"
|
||||
, "</table>"
|
||||
), "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
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <td>~{prop_id}</td>"
|
||||
, " <td>~{prop_name}</td>"
|
||||
, " <td>~{val}</td>"
|
||||
, " <td>~{ref}</td>"
|
||||
, " <td>~{qual}</td>"
|
||||
, " <td>~{rank}</td>"
|
||||
, " </tr>"
|
||||
), "prop_id", "prop_name", "val", "ref", "qual", "rank"
|
||||
);
|
||||
}
|
@ -16,50 +16,74 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.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("<div id='wb-item' class='wikibase-entityview wb-item' lang='en' dir='ltr'>");
|
||||
fmtr_main.Bld_bfr_many(bfr, fmtr_oview, "", "", "", "", "", "", "");
|
||||
bfr.Add_str("</div>");
|
||||
return bfr.XtoAryAndClear();
|
||||
}
|
||||
public byte[] Write(Wdata_doc wdoc) {
|
||||
bfr.Add_str("<div id='wb-item' class='wikibase-entityview wb-item' lang='en' dir='ltr'>");
|
||||
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("</div>");
|
||||
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_("<a href='/wiki/~{href}'>~{text}</a>", "href", "text");
|
||||
}
|
||||
|
@ -17,214 +17,296 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
( ""
|
||||
, "<h2>Labels</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>Language</th>"
|
||||
, " <th>Label</th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><code>en</code></td>"
|
||||
, " <td>en_label</td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><code>de</code></td>"
|
||||
, " <td>de_label</td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@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
|
||||
( ""
|
||||
, "<h2>Descriptions</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>Language</th>"
|
||||
, " <th>Description</th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><code>en</code></td>"
|
||||
, " <td>en_descr</td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><code>de</code></td>"
|
||||
, " <td>de_descr</td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@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
|
||||
( ""
|
||||
, "<h2>Aliases</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>Language</th>"
|
||||
, " <th>Alias</th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><code>en</code></td>"
|
||||
, " <td>en_1<br/>en_2</td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><code>de</code></td>"
|
||||
, " <td>de_1</td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@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
|
||||
( ""
|
||||
, "<h2>Links</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>Site</th>"
|
||||
, " <th>Link</th>"
|
||||
, " <th>Badges</th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><a href='/site/en.wikipedia.org/wiki/'><code>enwiki</code></a></td>"
|
||||
, " <td><a href='/site/en.wikipedia.org/wiki/Earth'>Earth</a></td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td><a href='/site/de.wikipedia.org/wiki/'><code>dewiki</code></a></td>"
|
||||
, " <td><a href='/site/de.wikipedia.org/wiki/Erde'>Erde</a></td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@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
|
||||
( ""
|
||||
, "<h2>Claims</h2>"
|
||||
, ""
|
||||
, "<table class='wikitable'>"
|
||||
, " <tr>"
|
||||
, " <th>Id</th>"
|
||||
, " <th>Name</th>"
|
||||
, " <th>Value</th>"
|
||||
, " <th>References</th>"
|
||||
, " <th>Qualifiers</th>"
|
||||
, " <th>Rank</th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>1</td>"
|
||||
, " <td>prop_1</td>"
|
||||
, " <td>abc</td>"
|
||||
, " <td></td>"
|
||||
, " <td></td>"
|
||||
, " <td>normal</td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@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
|
||||
( ""
|
||||
, "<h2>JSON</h2>"
|
||||
, ""
|
||||
, "<span id=\"xowa-wikidata-json\">"
|
||||
, "{ \"node\":"
|
||||
, " [ \"val_0\""
|
||||
, " , \"val_1\""
|
||||
, " ]"
|
||||
, "}"
|
||||
, "</span>"
|
||||
));
|
||||
}
|
||||
@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
|
||||
// ( ""
|
||||
// , "<h2>Labels</h2>"
|
||||
// , ""
|
||||
// , "<table class='wikitable'>"
|
||||
// , " <tr>"
|
||||
// , " <th>Language</th>"
|
||||
// , " <th>Label</th>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><code>en</code></td>"
|
||||
// , " <td>en_label</td>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><code>de</code></td>"
|
||||
// , " <td>de_label</td>"
|
||||
// , " </tr>"
|
||||
// , "</table>"
|
||||
// ));
|
||||
// }
|
||||
// @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
|
||||
// ( ""
|
||||
// , "<h2>Descriptions</h2>"
|
||||
// , ""
|
||||
// , "<table class='wikitable'>"
|
||||
// , " <tr>"
|
||||
// , " <th>Language</th>"
|
||||
// , " <th>Description</th>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><code>en</code></td>"
|
||||
// , " <td>en_descr</td>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><code>de</code></td>"
|
||||
// , " <td>de_descr</td>"
|
||||
// , " </tr>"
|
||||
// , "</table>"
|
||||
// ));
|
||||
// }
|
||||
// @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
|
||||
// ( ""
|
||||
// , "<h2>Aliases</h2>"
|
||||
// , ""
|
||||
// , "<table class='wikitable'>"
|
||||
// , " <tr>"
|
||||
// , " <th>Language</th>"
|
||||
// , " <th>Alias</th>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><code>en</code></td>"
|
||||
// , " <td>en_1<br/>en_2</td>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><code>de</code></td>"
|
||||
// , " <td>de_1</td>"
|
||||
// , " </tr>"
|
||||
// , "</table>"
|
||||
// ));
|
||||
// }
|
||||
// @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
|
||||
// ( ""
|
||||
// , " <div class='wikibase-sitelinkgrouplistview'>"
|
||||
// , " <div class='wb-listview'>"
|
||||
// , " <div class='wikibase-sitelinkgroupview' data-wb-sitelinks-group='wikipedia'>"
|
||||
// , " <div class='wikibase-sitelinkgroupview-heading-container'>"
|
||||
// , " <h2 class='wb-section-heading wikibase-sitelinkgroupview-heading' dir='auto' id='sitelinks-wikipedia'>Links (Wikipedia)</h2>"
|
||||
// , " </div>"
|
||||
// , " <table class='wikibase-sitelinklistview'>"
|
||||
// , " <colgroup>"
|
||||
// , " <col class='wikibase-sitelinklistview-sitename' />"
|
||||
// , " <col class='wikibase-sitelinklistview-siteid' />"
|
||||
// , " <col class='wikibase-sitelinklistview-link' />"
|
||||
// , " </colgroup>"
|
||||
// , " <thead>"
|
||||
// , " <tr class='wikibase-sitelinklistview-columnheaders'>"
|
||||
// , " <th class='wikibase-sitelinkview-sitename'>Language</th>"
|
||||
// , " <th class='wikibase-sitelinkview-siteid'>Code</th>"
|
||||
// , " <th class='wikibase-sitelinkview-link'>Linked page</th>"
|
||||
// , " </tr>"
|
||||
// , " </thead>"
|
||||
// , " <tbody>"
|
||||
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-enwiki' data-wb-siteid='enwiki'>"
|
||||
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-enwiki' lang='en' dir='auto'>English</td>"
|
||||
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-enwiki'>enwiki</td>"
|
||||
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-enwiki' lang='en' dir='auto'>"
|
||||
// , " <span class='wikibase-sitelinkview-badges'>"
|
||||
// , " <span class='wb-badge wb-badge-Q1 wb-badge-featuredarticle' title='featured article'></span>"
|
||||
// , " <span class='wb-badge wb-badge-Q2 wb-badge-goodarticle' title='good article'></span>"
|
||||
// , " </span>"
|
||||
// , " <span class='wikibase-sitelinkview-page'>"
|
||||
// , " <a href='https://en.wikipedia.org/wiki/Earth' hreflang='en' dir='auto'>Earth</a>"
|
||||
// , " </span>"
|
||||
// , " </td>"
|
||||
// , " </tr>"
|
||||
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-dewiki' data-wb-siteid='dewiki'>"
|
||||
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-dewiki' lang='de' dir='auto'>Deutsch</td>"
|
||||
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-dewiki'>dewiki</td>"
|
||||
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-dewiki' lang='de' dir='auto'>"
|
||||
// , " <span class='wikibase-sitelinkview-badges'>"
|
||||
// , " </span>"
|
||||
// , " <span class='wikibase-sitelinkview-page'>"
|
||||
// , " <a href='https://de.wikipedia.org/wiki/Erde' hreflang='de' dir='auto'>Erde</a>"
|
||||
// , " </span>"
|
||||
// , " </td>"
|
||||
// , " </tr>"
|
||||
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-frwiki' data-wb-siteid='frwiki'>"
|
||||
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-frwiki' lang='fr' dir='auto'>Français</td>"
|
||||
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-frwiki'>frwiki</td>"
|
||||
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-frwiki' lang='fr' dir='auto'>"
|
||||
// , " <span class='wikibase-sitelinkview-badges'>"
|
||||
// , " </span>"
|
||||
// , " <span class='wikibase-sitelinkview-page'>"
|
||||
// , " <a href='https://fr.wikipedia.org/wiki/Terre' hreflang='fr' dir='auto'>Terre</a>"
|
||||
// , " </span>"
|
||||
// , " </td>"
|
||||
// , " </tr>"
|
||||
// , " </tbody>"
|
||||
// , " </table>"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// ));
|
||||
// }
|
||||
// @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
|
||||
// ( ""
|
||||
// , "<p>"
|
||||
// , " <div id='toc' class='toc'>"
|
||||
// , " <div id='toctitle'><h2>Contents</h2></div>"
|
||||
// , " <ul>"
|
||||
// , " <li class='toclevel-1 tocsection-1'><a href='#Links_(Wikipedia)'><span class='tocnumber'>1</span> <span class='toctext'>Links (Wikipedia)</span></a></li>"
|
||||
// , " <li class='toclevel-1 tocsection-2'><a href='#Links_(Wiktionary)'><span class='tocnumber'>2</span> <span class='toctext'>Links (Wiktionary)</span></a></li>"
|
||||
// , " <li class='toclevel-1 tocsection-3'><a href='#Links_(Wikiquote)'><span class='tocnumber'>3</span> <span class='toctext'>Links (Wikiquote)</span></a></li>"
|
||||
// , " <li class='toclevel-1 tocsection-4'><a href='#JSON'><span class='tocnumber'>4</span> <span class='toctext'>JSON</span></a></li>"
|
||||
// , " </ul>"
|
||||
// , " </div>"
|
||||
// , "</p>"
|
||||
// , ""
|
||||
// , "<h2>Links (Wikipedia)</h2>"
|
||||
// , ""
|
||||
// , "<p>"
|
||||
// , " <table class='wikitable'>"
|
||||
// , " <tr>"
|
||||
// , " <th>Site</th>"
|
||||
// , " <th>Link</th>"
|
||||
// , " <th>Badges</th>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><a href='/site/en.wikipedia.org/wiki/'><code>enwiki</code></a></td>"
|
||||
// , " <td><a href='/site/en.wikipedia.org/wiki/Earth'>Earth</a></td>"
|
||||
// , " <td></td>"
|
||||
// , " </tr>"
|
||||
// , " </table>"
|
||||
// , "</p>"
|
||||
// , ""
|
||||
// , "<h2>Links (Wiktionary)</h2>"
|
||||
// , ""
|
||||
// , "<p>"
|
||||
// , " <table class='wikitable'>"
|
||||
// , " <tr>"
|
||||
// , " <th>Site</th>"
|
||||
// , " <th>Link</th>"
|
||||
// , " <th>Badges</th>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><a href='/site/en.wiktionary.org/wiki/'><code>enwiktionary</code></a></td>"
|
||||
// , " <td><a href='/site/en.wiktionary.org/wiki/Earth'>Earth</a></td>"
|
||||
// , " <td></td>"
|
||||
// , " </tr>"
|
||||
// , " </table>"
|
||||
// , "</p>"
|
||||
// , ""
|
||||
// , "<h2>Links (Wikiquote)</h2>"
|
||||
// , ""
|
||||
// , "<p>"
|
||||
// , " <table class='wikitable'>"
|
||||
// , " <tr>"
|
||||
// , " <th>Site</th>"
|
||||
// , " <th>Link</th>"
|
||||
// , " <th>Badges</th>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td><a href='/site/en.wikiquote.org/wiki/'><code>enwikiquote</code></a></td>"
|
||||
// , " <td><a href='/site/en.wikiquote.org/wiki/Earth'>Earth</a></td>"
|
||||
// , " <td></td>"
|
||||
// , " </tr>"
|
||||
// , " </table>"
|
||||
// , "</p>"
|
||||
// ));
|
||||
// }
|
||||
// @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
|
||||
// ( ""
|
||||
// , "<h2>Claims</h2>"
|
||||
// , ""
|
||||
// , "<table class='wikitable'>"
|
||||
// , " <tr>"
|
||||
// , " <th>Id</th>"
|
||||
// , " <th>Name</th>"
|
||||
// , " <th>Value</th>"
|
||||
// , " <th>References</th>"
|
||||
// , " <th>Qualifiers</th>"
|
||||
// , " <th>Rank</th>"
|
||||
// , " </tr>"
|
||||
// , " <tr>"
|
||||
// , " <td>1</td>"
|
||||
// , " <td>prop_1</td>"
|
||||
// , " <td>abc</td>"
|
||||
// , " <td></td>"
|
||||
// , " <td></td>"
|
||||
// , " <td>normal</td>"
|
||||
// , " </tr>"
|
||||
// , "</table>"
|
||||
// ));
|
||||
// }
|
||||
// @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
|
||||
// ( ""
|
||||
// , "<h2>JSON</h2>"
|
||||
// , ""
|
||||
// , "<pre style=\"overflow:auto\">"
|
||||
// , "{ \"node\":"
|
||||
// , " [ \"val_0\""
|
||||
// , " , \"val_1\""
|
||||
// , " ]"
|
||||
// , "}"
|
||||
// , "</pre>"
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
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}", "<sup>jul</sup>"
|
||||
@ -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);}
|
||||
}
|
||||
|
@ -16,40 +16,28 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
@ -17,42 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -17,30 +17,122 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
22
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr.java
Normal file
22
400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_wkr.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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");
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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)
|
||||
, "<a href='/wiki/Q1'>item_1</a>"
|
||||
);
|
||||
}
|
||||
@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 (<a href='/wiki/Q2'>Earth</a>)"
|
||||
);
|
||||
}
|
||||
@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"
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.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) {}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);}
|
||||
|
@ -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() {
|
||||
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.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;}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>~{langs_hdr}~{wikidata_link}<a href='javascript:xowa_toggle_visible(\"wikidata-langs\");'><img id='wikidata-langs-toggle-icon' src='~{icon_src}' title='~{icon_title}' /></a></h5>"
|
||||
, " <div id='wikidata-langs-toggle-elem' style='~{elem_display}'>~{grps}"
|
||||
, " <h5>~{langs_hdr}~{wikidata_link}~{toggle_btn}</h5>"
|
||||
, " <div~{toggle_hdr}>~{grps}"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
), "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_(" (<a href=\"/site/www.wikidata.org/wiki/~{qid}\">wikidata</a>)", "qid");
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Itms_reg(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ public class Xol_fragment_mgr implements GfoInvkAble {
|
||||
, " 'deprecated' : '~{deprecated}'"
|
||||
, " };"
|
||||
, " </script>"
|
||||
, " <script src=\"~{app_root_dir}bin/any/javascript/xowa/wikidata/wikidata.js\" type='text/javascript'></script>"
|
||||
// , " <script src=\"~{app_root_dir}bin/any/javascript/xowa/wikidata/wikidata.js\" type='text/javascript'></script>"
|
||||
)
|
||||
, "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"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user