mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-05-31 22:44:34 +00:00
Wikibase: Add getBestStatements / getEntityUrl; ParserFunctions: Improve support for relative month
This commit is contained in:
parent
66877212bf
commit
3126b46faf
@ -31,7 +31,7 @@ public class Xoa_app_ {
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final int Version_id = 540;
|
||||
public static final String Version = "4.5.18.1710";
|
||||
public static final String Version = "4.5.18.1711";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Build_date_fmt = "yyyy-MM-dd HH:mm:ss";
|
||||
public static String Op_sys_str;
|
||||
|
@ -18,7 +18,7 @@ import gplx.xowa.users.history.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.specials.*;
|
||||
import gplx.xowa.specials.*;
|
||||
import gplx.xowa.specials.allPages.*; import gplx.xowa.specials.nearby.*; import gplx.xowa.specials.statistics.*; import gplx.xowa.xtns.translates.*; import gplx.xowa.specials.movePage.*;
|
||||
import gplx.xowa.specials.xowa.system_data.*; import gplx.xowa.specials.xowa.default_tab.*; import gplx.xowa.specials.xowa.popup_history.*; import gplx.xowa.addons.wikis.imports.*; import gplx.xowa.specials.xowa.diags.*;
|
||||
import gplx.xowa.specials.xowa.system_data.*; import gplx.xowa.specials.xowa.default_tab.*; import gplx.xowa.specials.xowa.popup_history.*; import gplx.xowa.addons.wikis.imports.*; import gplx.xowa.specials.xowa.diags.*; import gplx.xowa.xtns.wbases.mediawiki.repo.includes.specials.*;
|
||||
import gplx.xowa.xtns.wbases.specials.*;
|
||||
import gplx.xowa.users.data.*; import gplx.xowa.users.bmks.*;
|
||||
import gplx.xowa.specials.mgrs.*; import gplx.xowa.addons.wikis.searchs.specials.*;
|
||||
@ -39,6 +39,7 @@ public class Xow_special_mgr {
|
||||
public Nearby_mgr Page_nearby() {return page_nearby;} private final Nearby_mgr page_nearby = new Nearby_mgr();
|
||||
public Xop_mylanguage_page Page_mylanguage() {return page_mylanguage;} private final Xop_mylanguage_page page_mylanguage = new Xop_mylanguage_page();
|
||||
public Wdata_itemByTitle_page Page_itemByTitle() {return page_itemByTitle;} private final Wdata_itemByTitle_page page_itemByTitle = new Wdata_itemByTitle_page();
|
||||
public Xow_special_page Page_entityPage() {return page_entityPage;} private final Xow_special_page page_entityPage = Wbase_entityPage.Prototype;
|
||||
public Xop_statistics_page Page_statistics() {return page_statistics;} private final Xop_statistics_page page_statistics = new Xop_statistics_page();
|
||||
public Move_page Page_movePage() {return page_movePage;} private final Move_page page_movePage = new Move_page();
|
||||
public System_data_page Page_system_data() {return page_system_data;} private final System_data_page page_system_data = new System_data_page();
|
||||
@ -57,6 +58,7 @@ public class Xow_special_mgr {
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__nearby , page_nearby);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__my_language , page_mylanguage);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__item_by_title , page_itemByTitle);
|
||||
hash.Add_str_obj(Wbase_entityPage.SPECIAL_KEY , page_entityPage);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__statistics , page_statistics);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__move_page , page_movePage);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__system_data , page_system_data);
|
||||
|
@ -98,6 +98,9 @@ public class Xowe_page_mgr {
|
||||
wiki.Html__hdump_mgr().Load_mgr().Load_by_xowe(page);
|
||||
from_html_db = Bry_.Len_gt_0(page.Db().Html().Html_bry());
|
||||
}
|
||||
else {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "page_load: loaded wikitext; page=~{0} wikitext_len=~{1}", ttl.Full_db(), page.Db().Text().Text_bry().length);
|
||||
}
|
||||
}
|
||||
page.Html_data().Hdump_exists_(from_html_db);
|
||||
|
||||
|
@ -42,7 +42,9 @@ class Pxd_eval_year {
|
||||
Pxd_itm_int itm_0 = Pxd_itm_int_.CastOrNull(data_ary[0]);
|
||||
Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]);
|
||||
if (itm_0 == null || itm_1 == null) return; // 0 or 1 is not an int;
|
||||
if (itm_1.Val() > 12) { // if itm_1 is > 12 then can't be month; must be day; PAGE:en.d:tongue-in-chic DATE:2017-04-25
|
||||
// if itm_1 is > 12 then can't be month; must be day; PAGE:en.d:tongue-in-chic DATE:2017-04-25
|
||||
// NOTE: must be "> 12", not ">= 12"; default behavior is "dd-MM-yyyy" PAGE:en.w:Portal:Current_events/December_2001 DATE:2017-11-26
|
||||
if (itm_1.Val() > 12) {
|
||||
if (!Pxd_eval_seg.Eval_as_m(tctx, itm_0)) return;
|
||||
if (!Pxd_eval_seg.Eval_as_d(tctx, itm_1)) return;
|
||||
}
|
||||
@ -88,7 +90,8 @@ class Pxd_eval_seg {
|
||||
case 1:
|
||||
case 2:
|
||||
if ( val > -1 && val < 13 // val is between 0 and 12; possible month;
|
||||
&& tctx.Seg_idxs()[DateAdp_.SegIdx_month] == Pxd_itm_base.Seg_idx_null) { // month is empty; needed else multiple access-date errors in references; PAGE:en.w:Template:Date; en.w:Antipas,_Cotabato; EX:"2 12 November 2016" DATE:2017-04-01
|
||||
&& tctx.Seg_idxs()[DateAdp_.SegIdx_month] == Pxd_itm_base.Seg_idx_null // month is empty; needed else multiple access-date errors in references; PAGE:en.w:Template:Date; en.w:Antipas,_Cotabato; EX:"2 12 November 2016" DATE:2017-04-01
|
||||
) {
|
||||
tctx.Seg_idxs_(itm, DateAdp_.SegIdx_month);
|
||||
return true;
|
||||
}
|
||||
|
@ -148,36 +148,54 @@ class Pxd_itm_month_name extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
}
|
||||
}
|
||||
class Pxd_itm_unit extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
public Pxd_itm_unit(int ary_idx, byte[] name, int seg_idx, int seg_multiple) {Ctor(ary_idx); this.name = name; Seg_idx_(seg_idx); this.seg_multiple = seg_multiple;}
|
||||
public byte[] Name() {return name;} private byte[] name;
|
||||
private int seg_val = 1;
|
||||
private int seg_multiple;
|
||||
private boolean eval_done_by_relative_word;
|
||||
public Pxd_itm_unit(int ary_idx, byte[] name, int seg_idx, int seg_multiple) {
|
||||
Ctor(ary_idx);
|
||||
this.name = name;
|
||||
this.seg_multiple = seg_multiple;
|
||||
Seg_idx_(seg_idx);
|
||||
}
|
||||
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_unit;}
|
||||
@Override public int Eval_idx() {return 10;}
|
||||
int seg_val = 1; int seg_multiple;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public Pxd_itm MakeNew(int ary_idx) {
|
||||
return new Pxd_itm_unit(ary_idx, name, this.Seg_idx(), seg_val);
|
||||
}
|
||||
public void Unit_seg_val_(int v) { // handled by relative; EX: next year
|
||||
seg_val = v; seg_multiple = 1;
|
||||
eval_done_by_relative = true;
|
||||
} private boolean eval_done_by_relative;
|
||||
@Override public boolean Eval(Pxd_parser state) {
|
||||
if (eval_done_by_relative) return true;
|
||||
state.Seg_idxs_(this, this.Seg_idx(), seg_val);
|
||||
Pxd_itm[] tkns = state.Tkns();
|
||||
public void Unit_seg_val_(int v) { // handled by relative_word; EX: next year
|
||||
this.seg_val = v;
|
||||
this.seg_multiple = 1;
|
||||
this.eval_done_by_relative_word = true;
|
||||
}
|
||||
@Override public boolean Eval(Pxd_parser dctx) {
|
||||
if (eval_done_by_relative_word) return true;
|
||||
|
||||
// TOMBSTONE: "dctx.Seg_idxs_(this, this.Seg_idx(), seg_val);"; DATE:2017-11-28
|
||||
|
||||
// search for previous int; EX: "2 month", "-3 year"
|
||||
Pxd_itm[] tkns = dctx.Tkns();
|
||||
Pxd_itm_int itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), false);
|
||||
if (itm_int == null) return false; // PAGE:s.w:Crich_Tramway_Village EX:Yearly DATE:2016-07-06
|
||||
state.Seg_idxs_(itm_int, Pxd_itm_base.Seg_idx_skip);
|
||||
if (itm_int == null) return false; // number may be omitted; EX:"Yearly" PAGE:s.w:Crich_Tramway_Village DATE:2016-07-06
|
||||
|
||||
// deactivate number_tkn; will be handled by relative_word_tkn; TOMBSTONE:"dctx.Seg_idxs_(itm_int, Pxd_itm_base.Seg_idx_skip);" DATE:2017-11-28
|
||||
itm_int.Seg_idx_(Pxd_itm_base.Seg_idx_skip);
|
||||
seg_val = itm_int.Val();
|
||||
|
||||
// search for neg sign; update seg_val if found
|
||||
for (int i = itm_int.Ary_idx(); i > -1; i--) {
|
||||
Pxd_itm itm = tkns[i];
|
||||
switch (itm.Tkn_tid()) {
|
||||
case Pxd_itm_.Tid_dash: // negative sign; stop;
|
||||
// found negative sign -> update seg_val and stop;
|
||||
case Pxd_itm_.Tid_dash:
|
||||
seg_val *= -1;
|
||||
i = -1;
|
||||
break;
|
||||
case Pxd_itm_.Tid_dot: case Pxd_itm_.Tid_int: case Pxd_itm_.Tid_ws: // ignore
|
||||
// found ws -> ignore
|
||||
case Pxd_itm_.Tid_dot: case Pxd_itm_.Tid_int: case Pxd_itm_.Tid_ws:
|
||||
break;
|
||||
default: // word; stop;
|
||||
// found some other word -> stop
|
||||
default:
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
@ -291,26 +309,33 @@ class Pxd_itm_time_relative extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
;
|
||||
Pxd_itm_time_relative() {}
|
||||
}
|
||||
class Pxd_itm_unit_relative extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
public Pxd_itm_unit_relative(int adj, int ary_idx) {Ctor(ary_idx); this.adj = adj;}
|
||||
class Pxd_itm_unit_relative extends Pxd_itm_base implements Pxd_itm_prototype { // EX: "next year"
|
||||
private final int adj;
|
||||
public Pxd_itm_unit_relative(int adj, int ary_idx) {
|
||||
Ctor(ary_idx);
|
||||
this.adj = adj;
|
||||
}
|
||||
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_unit_relative;}
|
||||
@Override public int Eval_idx() {return 5;}
|
||||
public Pxd_itm MakeNew(int ary_idx) {return new Pxd_itm_unit_relative(adj, ary_idx);}
|
||||
@Override public boolean Eval(Pxd_parser state) {
|
||||
// find next token: EX: sec, hour, day, fortnight, month, etc.
|
||||
Pxd_itm itm = Pxd_itm_.Find_fwd_by_tid(state.Tkns(), this.Ary_idx() + 1, Pxd_itm_.Tid_unit);
|
||||
if (itm == null) state.Err_set(Pft_func_time_log.Invalid_date, Bfr_arg_.New_int(adj));
|
||||
|
||||
// cast to unit; may fail; EX:update in "last update" as per "March 2006 [last update]";PAGE:s.w:Synesthesia;DATE:2016-07-06
|
||||
Pxd_itm_unit unit_tkn = (Pxd_itm_unit)itm;
|
||||
if (unit_tkn == null) {state.Err_set(Pft_func_time_log.Invalid_date, Bfr_arg_.New_int(adj)); return false;} // PAGE:s.w:Synesthesia EX:"March 2006 [last update]"; DATE:2016-07-06
|
||||
if (unit_tkn == null) {state.Err_set(Pft_func_time_log.Invalid_date, Bfr_arg_.New_int(adj)); return false;}
|
||||
|
||||
unit_tkn.Unit_seg_val_(adj);
|
||||
return true;
|
||||
}
|
||||
@Override public boolean Time_ini(DateAdpBldr bldr) {return true;}
|
||||
public static final Pxd_itm_unit_relative
|
||||
Next = new Pxd_itm_unit_relative(1)
|
||||
, Prev = new Pxd_itm_unit_relative(-1)
|
||||
, This = new Pxd_itm_unit_relative(0)
|
||||
Next = new Pxd_itm_unit_relative( 1, 0)
|
||||
, Prev = new Pxd_itm_unit_relative(-1, 0)
|
||||
, This = new Pxd_itm_unit_relative( 0, 0)
|
||||
;
|
||||
Pxd_itm_unit_relative(int adj) {this.adj = adj;} private int adj;
|
||||
}
|
||||
class Pxd_itm_unixtime extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
private long unixtime;
|
||||
|
@ -17,7 +17,7 @@ package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import g
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*; import gplx.core.btries.*; import gplx.core.log_msgs.*;
|
||||
class Pxd_parser {
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
byte[] src; int cur_pos, tkn_bgn_pos, src_len, tkn_type;
|
||||
private byte[] src; int cur_pos, tkn_bgn_pos, src_len, tkn_type;
|
||||
public Pxd_itm[] Tkns() {return tkns;} Pxd_itm[] tkns;
|
||||
public int Tkns_len() {return tkns_len;} private int tkns_len;
|
||||
public Pxd_itm[] Data_ary() {return data_ary;} Pxd_itm[] data_ary;
|
||||
|
@ -16,9 +16,16 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
public class Pxd_parser_tst {
|
||||
Bry_bfr bfr = Bry_bfr_.New_w_size(16); Pxd_parser parser = new Pxd_parser();
|
||||
@Before public void init() {Datetime_now.Manual_y_(); Datetime_now.Manual_(test_date);} DateAdp test_date = DateAdp_.parse_fmt("2012-02-27", "yyyy-MM-dd");
|
||||
@After public void teardown() {Datetime_now.Manual_n_();}
|
||||
private final Bry_bfr bfr = Bry_bfr_.New_w_size(16);
|
||||
private final Pxd_parser parser = new Pxd_parser();
|
||||
private final DateAdp test_date = DateAdp_.parse_fmt("2012-02-27", "yyyy-MM-dd");
|
||||
@Before public void init() {
|
||||
Datetime_now.Manual_y_();
|
||||
Datetime_now.Manual_(test_date);
|
||||
}
|
||||
@After public void teardown() {
|
||||
Datetime_now.Manual_n_();
|
||||
}
|
||||
@Test public void Month_name_0__day__year() {tst_date_("Mar 2 2001" , "2001-03-02");} // y:Mar-02-2001;Mar.02.2001;Mar 02, 2001 n:Mar/02/2001;Feb,05,2011
|
||||
@Test public void Month_name_0__day__year__bad_day() {tst_date_("Mar 32 2001" , "Invalid day: 32");}
|
||||
@Test public void Month_name_0__day__year__bad_year() {tst_date_("Mar 3 999" , "0999-03-03");}
|
||||
@ -52,6 +59,8 @@ public class Pxd_parser_tst {
|
||||
@Test public void Unit_day_pos() {tst_date_("+ 3 days" , "2012-03-01");}
|
||||
@Test public void Unit_day_neg() {tst_date_("- 3 days" , "2012-02-24");}
|
||||
@Test public void Unit_day_neg_w_day() {tst_date_("30 May 2012 -1 days" , "2012-05-29");} // PAGE:en.w:Main Page
|
||||
@Test public void Unit_day_neg_w_month() {tst_date_("02-12-2001 -1 month" , "2001-11-02");} // PAGE:en.w:Portal:Current_events/December_2001; DATE:2017-11-26
|
||||
@Test public void Unit_day_neg_w_month_wrap() {tst_date_("02-01-2000 -1 month" , "1999-12-02");} // PAGE:en.w:Portal:Current_events/December_2001; DATE:2017-11-26
|
||||
@Test public void Unit_week() {tst_date_("- 1 week" , "2012-02-26");} // PURPOSE.FIX: "week" was not being handled; error on main Page; EX:da.wikipedia.org/Main_Page
|
||||
@Test public void Time_len_6() {tst_time_("041526" , "04:15:26.000");}
|
||||
@Test public void Time_len_12() {tst_both_("201601020304" , "2016-01-02 03:04:00.000");} // PURPOSE: handle 12 digit datetime; PAGE:en.w:Boron; DATE:2015-07-29
|
||||
|
@ -14,13 +14,19 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
import gplx.xowa.xtns.wbases.mediawiki.client.includes.*; import gplx.xowa.xtns.wbases.mediawiki.client.dataAccess.scribunto.*;
|
||||
public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
private Wbase_entity_accessor entity_accessor;
|
||||
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
public Scrib_lib Init() {procs.Init_by_lib(this, Proc_names); return this;}
|
||||
public Scrib_lib Init() {
|
||||
procs.Init_by_lib(this, Proc_names);
|
||||
this.entity_accessor = new Wbase_entity_accessor(core.App().Wiki_mgr().Wdata_mgr().Doc_mgr);
|
||||
return this;
|
||||
}
|
||||
public Scrib_lib Clone_lib(Scrib_core core) {return new Scrib_lib_wikibase(core);}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
@ -32,10 +38,13 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
switch (key) {
|
||||
case Proc_getLabel: return GetLabel(args, rslt);
|
||||
// getLabelByLanguage
|
||||
case Proc_getEntity: return GetEntity(args, rslt);
|
||||
case Proc_getEntityStatements: return GetEntityStatements(args, rslt);
|
||||
case Proc_getSetting: return GetSetting(args, rslt);
|
||||
case Proc_getEntityUrl: return GetEntityUrl(args, rslt);
|
||||
case Proc_renderSnak: return RenderSnak(args, rslt);
|
||||
// formatValue
|
||||
case Proc_renderSnaks: return RenderSnaks(args, rslt);
|
||||
case Proc_getEntityId: return GetEntityId(args, rslt);
|
||||
case Proc_getUserLang: return GetUserLang(args, rslt);
|
||||
@ -49,16 +58,20 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
}
|
||||
}
|
||||
private static final int
|
||||
Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_getEntityUrl = 3, Proc_renderSnak = 4, Proc_renderSnaks = 5, Proc_getEntityId = 6, Proc_getUserLang = 7
|
||||
, Proc_getDescription = 8, Proc_resolvePropertyId = 9, Proc_getSiteLinkPageName = 10, Proc_incrementExpensiveFunctionCount = 11, Proc_getPropertyOrder = 12, Proc_orderProperties = 13;
|
||||
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_getEntityUrl = "getEntityUrl"
|
||||
, Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang"
|
||||
, Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount"
|
||||
, Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
||||
Proc_getLabel = 0 //, Proc_getLabelByLanguage = 1
|
||||
, Proc_getEntity = 2, Proc_getEntityStatements = 3, Proc_getSetting = 4, Proc_getEntityUrl = 5, Proc_renderSnak = 6//, Proc_formatValue = 7
|
||||
, Proc_renderSnaks = 8, Proc_getEntityId = 9, Proc_getUserLang = 10, Proc_getDescription = 11, Proc_resolvePropertyId = 12
|
||||
, Proc_getSiteLinkPageName = 13, Proc_incrementExpensiveFunctionCount = 14, Proc_getPropertyOrder = 15, Proc_orderProperties = 16;
|
||||
public static final String
|
||||
Invk_getLabel = "getLabel", Invk_getLabelByLanguage = "getLabelByLanguage", Invk_getEntity = "getEntity", Invk_getEntityStatements = "getEntityStatements"
|
||||
, Invk_getSetting = "getSetting", Invk_getEntityUrl = "getEntityUrl", Invk_renderSnak = "renderSnak", Invk_formatValue = "formatValue", Invk_renderSnaks = "renderSnaks"
|
||||
, Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId"
|
||||
, Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount", Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
||||
;
|
||||
private static final String[] Proc_names = String_.Ary
|
||||
( Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_getEntityUrl, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang
|
||||
, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount, Invk_getPropertyOrder, Invk_orderProperties
|
||||
( Invk_getLabel, Invk_getLabelByLanguage, Invk_getEntity, Invk_getEntityStatements, Invk_getSetting, Invk_getEntityUrl, Invk_renderSnak, Invk_formatValue, Invk_renderSnaks
|
||||
, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount
|
||||
, Invk_getPropertyOrder, Invk_orderProperties
|
||||
);
|
||||
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);}
|
||||
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
@ -70,7 +83,11 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
Wbase_prop_mgr prop_mgr = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Prop_mgr();
|
||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
||||
}
|
||||
public boolean GetEntityUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getEntityUrl not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean GetEntityUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] entityId = args.Pull_bry(0);
|
||||
byte[] entity_url = Wbase_client.getDefaultInstance().RepoLinker().getEntityUrl(entityId);
|
||||
return rslt.Init_obj(entity_url);
|
||||
}
|
||||
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
@ -109,7 +126,51 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
||||
}
|
||||
private static Wdata_doc Get_wdoc_or_null(Scrib_proc_args args, Scrib_core core) {
|
||||
public boolean GetEntityStatements(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] prefixedEntityId = args.Pull_bry(0);
|
||||
byte[] propertyId = args.Pull_bry(1);
|
||||
byte[] rank = args.Pull_bry(2);
|
||||
|
||||
Wbase_prop_mgr prop_mgr = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Prop_mgr();
|
||||
Wbase_claim_base[] statements = this.entity_accessor.getEntityStatements(prefixedEntityId, propertyId, rank);
|
||||
if (statements == null)
|
||||
return rslt.Init_null();
|
||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl_claims_prop_ary(prop_mgr, String_.new_u8(propertyId), statements, 1));
|
||||
}
|
||||
/*
|
||||
public function formatValues( $snaksSerialization ) {
|
||||
$this->checkType( 'formatValues', 1, $snaksSerialization, 'table' );
|
||||
try {
|
||||
$ret = [ $this->getSnakSerializationRenderer( 'rich-wikitext' )->renderSnaks( $snaksSerialization ) ];
|
||||
return $ret;
|
||||
} catch ( DeserializationException $e ) {
|
||||
throw new ScribuntoException( 'wikibase-error-deserialize-error' );
|
||||
}
|
||||
}
|
||||
public function getLabelByLanguage( $prefixedEntityId, $languageCode ) {
|
||||
$this->checkType( 'getLabelByLanguage', 1, $prefixedEntityId, 'String' );
|
||||
$this->checkType( 'getLabelByLanguage', 2, $languageCode, 'String' );
|
||||
return [ $this->getLanguageIndependentLuaBindings()->getLabelByLanguage( $prefixedEntityId, $languageCode ) ];
|
||||
}
|
||||
private function getLanguageIndependentLuaBindings() {
|
||||
if ( $this->languageIndependentLuaBindings === null ) {
|
||||
$this->languageIndependentLuaBindings = $this->newLanguageIndependentLuaBindings();
|
||||
}
|
||||
return $this->languageIndependentLuaBindings;
|
||||
}
|
||||
private function newLanguageIndependentLuaBindings() {
|
||||
$wikibaseClient = WikibaseClient::getDefaultInstance();
|
||||
return new WikibaseLanguageIndependentLuaBindings(
|
||||
$wikibaseClient->getStore()->getSiteLinkLookup(),
|
||||
$wikibaseClient->getSettings(),
|
||||
$this->getUsageAccumulator(),
|
||||
$this->getEntityIdParser(),
|
||||
$wikibaseClient->getTermLookup(),
|
||||
$wikibaseClient->getTermsLanguages(),
|
||||
$wikibaseClient->getSettings()->getSetting( 'siteGlobalID' )
|
||||
);
|
||||
} */
|
||||
private static Wdata_doc Get_wdoc_or_null(Scrib_proc_args args, Scrib_core core) {
|
||||
// get qid / pid from scrib_arg[0]; if none, return null;
|
||||
byte[] xid_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(xid_bry)) return null; // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||
|
||||
|
@ -118,6 +118,16 @@ class Scrib_lib_wikibase_srl {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Keyval[] Srl_claims_prop_ary(Wbase_prop_mgr prop_mgr, String pid, Wbase_claim_base[] itms, int base_adj) {
|
||||
Scrib_lib_wikibase_srl_visitor visitor = new Scrib_lib_wikibase_srl_visitor();
|
||||
int len = itms.length;
|
||||
Keyval[] rv = new Keyval[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wbase_claim_base itm = itms[i];
|
||||
rv[i] = Keyval_.int_(i + base_adj, Srl_claims_prop_itm(prop_mgr, visitor, pid, itm, base_adj)); // NOTE: must be super 0 or super 1; DATE:2014-05-09
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_itm(Wbase_prop_mgr prop_mgr, Scrib_lib_wikibase_srl_visitor visitor, String pid, Wbase_claim_base itm, int base_adj) {
|
||||
List_adp list = List_adp_.New();
|
||||
list.Add(Keyval_.new_("id", pid));
|
||||
|
@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Scrib_lib_wikibase_tst {
|
||||
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
|
||||
@ -120,6 +121,30 @@ public class Scrib_lib_wikibase_tst {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "abc_en"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "abc_en");
|
||||
}
|
||||
@Test public void GetEntityStatements__best() {
|
||||
// wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_string(3, "P3_val")).Xto_wdoc());
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2")
|
||||
.Add_claims
|
||||
( wdata_fxt.Make_claim_string(3, "P3_val").Rank_tid_(Wbase_claim_rank_.Tid__preferred)
|
||||
).Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntityStatements, Object_.Ary("q2", "P3", "best"), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " 1="
|
||||
, " id=P3"
|
||||
, " mainsnak="
|
||||
, " datavalue="
|
||||
, " type=string"
|
||||
, " value=P3_val"
|
||||
, " property=P3"
|
||||
, " snaktype=value"
|
||||
, " datatype=string"
|
||||
, " rank=preferred"
|
||||
, " type=statement"
|
||||
));
|
||||
}
|
||||
@Test public void GetEntityUrl() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityUrl, Object_.Ary("Q2" ), "https://www.wikidata.org/wiki/Special:EntityPage/Q2");
|
||||
}
|
||||
}
|
||||
class Wbase_snak_utl_ {
|
||||
public static Keyval[] Get_snaks_ary(Wdata_wiki_mgr_fxt wdata_fxt, Wbase_claim_base... ary) {
|
||||
|
@ -95,7 +95,7 @@ public class Wbase_doc_mgr {
|
||||
}
|
||||
private static final byte[] Bry__redirect = Bry_.new_a7("redirect");
|
||||
|
||||
private static byte[] Prepend_property_if_needed(byte[] bry) {
|
||||
public static byte[] Prepend_property_if_needed(byte[] bry) {
|
||||
int len = bry == null ? 0 : bry.length;
|
||||
return len > 1
|
||||
&& Byte_ascii.Case_lower(bry[0]) == Byte_ascii.Ltr_p
|
||||
|
@ -169,7 +169,7 @@ public class Wdata_prop_val_visitor_ {
|
||||
}
|
||||
Wdata_prop_val_visitor.Write_langtext(bfr, text);
|
||||
}
|
||||
private static int To_pid_int(byte[] pid) {return Bry_.To_int_or(pid, 1, pid.length, -1);} // skip "P" at bgn; EX: "p123" -> 123
|
||||
public static int To_pid_int(byte[] pid) {return Bry_.To_int_or(pid, 1, pid.length, -1);} // skip "P" at bgn; EX: "p123" -> 123
|
||||
private static byte[] To_bry_by_str(Object o) {
|
||||
String rv = String_.cast(o);
|
||||
return rv == null ? null : Bry_.new_u8(rv);
|
||||
|
@ -31,7 +31,7 @@ public abstract class Wbase_claim_base implements CompareAble {
|
||||
public abstract byte Val_tid();
|
||||
public abstract void Welcome(Wbase_claim_visitor visitor);
|
||||
|
||||
public void Rank_tid_(byte v) {this.rank_tid = v;}
|
||||
public Wbase_claim_base Rank_tid_(byte v) {this.rank_tid = v; return this;}
|
||||
public void Wguid_(byte[] v) {this.wguid = v;}
|
||||
public Wbase_claim_base Qualifiers_(Wbase_claim_grp_list v) {qualifiers = v; return this;}
|
||||
public void Qualifiers_order_(int[] v) {qualifiers_order = v;}
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.dataAccess.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*; import gplx.xowa.xtns.wbases.mediawiki.client.dataAccess.*;
|
||||
import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_entity_accessor {
|
||||
private final Wbase_doc_mgr entity_mgr;
|
||||
public Wbase_entity_accessor(Wbase_doc_mgr entity_mgr) {
|
||||
this.entity_mgr = entity_mgr;
|
||||
}
|
||||
public Wbase_claim_base[] getEntityStatements(byte[] prefixedEntityId, byte[] propertyIdSerialization, byte[] rank) {
|
||||
prefixedEntityId = Bry_.Trim(prefixedEntityId);
|
||||
// entityId = $this->entityIdParser->parse( $prefixedEntityId );
|
||||
int propertyId = Wdata_prop_val_visitor_.To_pid_int(propertyIdSerialization);
|
||||
// $this->usageAccumulator->addStatementUsage( $entityId, $propertyId );
|
||||
// $this->usageAccumulator->addOtherUsage( $entityId );
|
||||
|
||||
// for some reason, prefixedEntityId can be ""; PAGE:en.w:Nature_and_Art DATE:2017-11-28
|
||||
if (Bry_.Len_eq_0(prefixedEntityId))
|
||||
return null;
|
||||
|
||||
Wdata_doc entity = null;
|
||||
try {
|
||||
entity = entity_mgr.Get_by_xid_or_null(prefixedEntityId);
|
||||
} catch (Exception ex) { // RevisionedUnresolvedRedirectException ex
|
||||
// We probably hit a double redirect
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "Encountered a UnresolvedRedirectException when trying to load {0}; exc={1}", prefixedEntityId, Err_.Message_lang(ex));
|
||||
return null;
|
||||
}
|
||||
|
||||
int selected_rank = ID_NULL;
|
||||
if (Bry_.Eq(rank, RANK_BEST)) {
|
||||
selected_rank = ID_BEST;
|
||||
}
|
||||
else if (Bry_.Eq(rank, RANK_ALL)) {
|
||||
selected_rank = ID_ALL;
|
||||
}
|
||||
else {
|
||||
throw Err_.new_wo_type("rank must be 'best' or 'all', " + String_.new_u8(rank) + " given");
|
||||
}
|
||||
|
||||
List_adp rv = List_adp_.New();
|
||||
Wbase_claim_grp statements = entity.Claim_list_get(propertyId);
|
||||
if (statements == null)
|
||||
return null;
|
||||
int statements_len = statements.Len();
|
||||
for (int i = 0; i < statements_len; i++) {
|
||||
Wbase_claim_base statement = statements.Get_at(0);
|
||||
if ( selected_rank == ID_ALL
|
||||
|| (selected_rank == ID_BEST && statement.Rank_tid() == Wbase_claim_rank_.Tid__preferred)
|
||||
) {
|
||||
rv.Add(statement);
|
||||
}
|
||||
}
|
||||
// $serialization = $this->newClientStatementListSerializer()->serialize( $statements );
|
||||
// $this->renumber( $serialization );
|
||||
// return $serialization;
|
||||
return (Wbase_claim_base[])rv.To_ary(Wbase_claim_base.class);
|
||||
}
|
||||
|
||||
private static final int ID_NULL = 0, ID_BEST = 1, ID_ALL = 2;
|
||||
private static final byte[]
|
||||
RANK_BEST = Bry_.new_a7("best")
|
||||
, RANK_ALL = Bry_.new_a7("all");
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*;
|
||||
import gplx.xowa.mediawiki.*;
|
||||
public class Wbase_client {
|
||||
private Wbase_repo_linker repoLinker;
|
||||
public Wbase_client(Wbase_settings settings) {
|
||||
this.repoLinker = new Wbase_repo_linker
|
||||
( settings.getSetting(Wbase_settings.Setting_repoUrl)
|
||||
, settings.getSetting(Wbase_settings.Setting_repoArticlePath)
|
||||
, settings.getSetting(Wbase_settings.Setting_repoScriptPath)
|
||||
);
|
||||
}
|
||||
public Wbase_repo_linker RepoLinker() {return repoLinker;}
|
||||
|
||||
private static Wbase_client defaultInstance;
|
||||
public static Wbase_client getDefaultInstance() {
|
||||
if (defaultInstance == null) {
|
||||
defaultInstance = new Wbase_client(Wbase_settings.New_dflt());
|
||||
}
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*;
|
||||
import gplx.xowa.mediawiki.*;
|
||||
// https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/client/includes/RepoLinker.php
|
||||
public class Wbase_repo_linker {
|
||||
private byte[] baseUrl;
|
||||
private byte[] articlePath;
|
||||
// private byte[] scriptPath;
|
||||
public Wbase_repo_linker(byte[] baseUrl, byte[] articlePath, byte[] scriptPath) {
|
||||
this.baseUrl = Bry_.Trim(baseUrl, 0, baseUrl.length, false, true, Bry_.mask_(256, Byte_ascii.Slash_bry)); // getBaseUrl
|
||||
this.articlePath = articlePath;
|
||||
// this.scriptPath = scriptPath;
|
||||
}
|
||||
|
||||
public byte[] getPageUrl(byte[] page) {
|
||||
byte[] encodedPage = this.encodePage(page);
|
||||
return Bry_.Add(this.getBaseUrl(), XophpString.str_replace(Format_Arg1, encodedPage, this.articlePath));
|
||||
}
|
||||
|
||||
private byte[] encodePage(byte[] page) {
|
||||
return gplx.langs.htmls.encoders.Gfo_url_encoder_.Mw_wfUrlencode.Encode(Bry_.Replace(page, Byte_ascii.Space, Byte_ascii.Underline));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Format a link, with url encoding
|
||||
// *
|
||||
// * @param String $url
|
||||
// * @param String $text
|
||||
// * @param array $attribs
|
||||
// *
|
||||
// * @return String (html)
|
||||
// */
|
||||
// public function formatLink( $url, $text, array $attribs = [] ) {
|
||||
// $attribs['class'] = isset( $attribs['class'] )
|
||||
// ? 'extiw ' . $attribs['class']
|
||||
// : 'extiw';
|
||||
// $attribs['href'] = $url;
|
||||
// return Html::element( 'a', $attribs, $text );
|
||||
// }
|
||||
// /**
|
||||
// * Constructs an html link to an entity
|
||||
// *
|
||||
// * @param EntityId $entityId
|
||||
// * @param array $classes
|
||||
// * @param String $text Defaults to the entity id serialization.
|
||||
// *
|
||||
// * @return String (html)
|
||||
// */
|
||||
// public function buildEntityLink( EntityId $entityId, array $classes = [], $text = null ) {
|
||||
// if ( $text === null ) {
|
||||
// $text = $entityId->getSerialization();
|
||||
// }
|
||||
// $class = 'wb-entity-link';
|
||||
// if ( $classes !== [] ) {
|
||||
// $class .= ' ' . implode( ' ', $classes );
|
||||
// }
|
||||
// return $this->formatLink(
|
||||
// $this->getEntityUrl( $entityId ),
|
||||
// $text,
|
||||
// [ 'class' => $class ]
|
||||
// );
|
||||
// }
|
||||
|
||||
public byte[] getEntityTitle(byte[] entityId ) {
|
||||
byte[] title = entityId; // title = entityId.getSerialization();
|
||||
return Bry_.Add(Special_EntityPage, title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a link to an entity
|
||||
*/
|
||||
public byte[] getEntityUrl(byte[] entityId) {
|
||||
byte[] title = this.getEntityTitle(entityId);
|
||||
return this.getPageUrl(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public byte[] getBaseUrl() {
|
||||
// return rtrim( $this->baseUrl, '/' );
|
||||
return this.baseUrl;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return String
|
||||
// */
|
||||
// public function getApiUrl() {
|
||||
// return $this->getBaseUrl() . $this->scriptPath . '/api.php';
|
||||
// }
|
||||
// /**
|
||||
// * @return String
|
||||
// */
|
||||
// public function getIndexUrl() {
|
||||
// return $this->getBaseUrl() . $this->scriptPath . '/index.php';
|
||||
// }
|
||||
// /**
|
||||
// * @param String $url
|
||||
// * @param array $params
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function addQueryParams( $url, array $params ) {
|
||||
// return wfAppendQuery( $url, wfArrayToCgi( $params ) );
|
||||
// }
|
||||
|
||||
private static final byte[]
|
||||
Format_Arg1 = Bry_.new_a7("$1")
|
||||
, Special_EntityPage = Bry_.new_a7("Special:EntityPage/");
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*;
|
||||
public class Wbase_settings {
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public byte[] getSetting(String key) {return getSetting(Bry_.new_u8(key));}
|
||||
public byte[] getSetting(byte[] key) {
|
||||
return (byte[])hash.Get_by_bry(key);
|
||||
}
|
||||
public void setSetting(String key, String val) {setSetting(Bry_.new_u8(key), Bry_.new_u8(val));}
|
||||
public void setSetting(byte[] key, byte[] val) {
|
||||
hash.Add(key, val);
|
||||
}
|
||||
|
||||
public static Wbase_settings New_dflt() {
|
||||
// https://www.mediawiki.org/wiki/Wikibase/Installation/Advanced_configuration
|
||||
return New
|
||||
( "https://www.wikidata.org" // NOTE: should be "//wikidata.org", but "//wikidata.org" will open page in browser, not XOWA
|
||||
, "/wiki/$1"
|
||||
, "/w"
|
||||
);
|
||||
}
|
||||
|
||||
public static Wbase_settings New(String repoUrl, String repoArticlePath, String repoScriptPath) {
|
||||
Wbase_settings rv = new Wbase_settings();
|
||||
rv.setSetting(Setting_repoUrl, repoUrl);
|
||||
rv.setSetting(Setting_repoArticlePath, repoArticlePath);
|
||||
rv.setSetting(Setting_repoScriptPath, repoScriptPath);
|
||||
return rv;
|
||||
}
|
||||
public static final String
|
||||
Setting_repoUrl = "repoUrl"
|
||||
, Setting_repoArticlePath = "repoArticlePath"
|
||||
, Setting_repoScriptPath = "repoScriptPath"
|
||||
;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.repo.includes.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.repo.*; import gplx.xowa.xtns.wbases.mediawiki.repo.includes.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
|
||||
public class Wbase_entityPage implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
if (url.Segs_ary().length != 4) { // EX: www.wikidata.org/wiki/Special:EntityPage/Q2
|
||||
throw Err_.new_wo_type("entityPage url must have format of 'domain/wiki/Special:EntityPage/entityId'", "url", url.To_bry(true, true));
|
||||
}
|
||||
byte[] entityId = url.Segs_ary()[3];
|
||||
byte[] pageId = Wbase_doc_mgr.Prepend_property_if_needed(entityId);
|
||||
|
||||
Xowe_wiki wikie = (Xowe_wiki)wiki;
|
||||
wikie.Data_mgr().Redirect((Xoae_page)page, pageId);
|
||||
}
|
||||
Wbase_entityPage(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final String SPECIAL_KEY = "EntityPage";
|
||||
public static final Xow_special_page Prototype = new Wbase_entityPage(Xow_special_meta.New_xo(SPECIAL_KEY, "Entity Page"));
|
||||
}
|
Loading…
Reference in New Issue
Block a user