1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.8.2.1'

This commit is contained in:
gnosygnu
2016-08-07 21:36:50 -04:00
parent b0fdf78a41
commit e4a2af026b
165 changed files with 2534 additions and 1247 deletions

View File

@@ -70,7 +70,7 @@ public class Scrib_invoke_func extends Pf_func_base {
if ( err_filter_mgr == null // no err_filter_mgr defined;
|| err_filter_mgr.Count_eq_0( ) // err_filter_mgr exists, but no definitions
|| !err_filter_mgr.Match(String_.new_u8(mod_name), String_.new_u8(fnc_name), err.To_str__msg_only())) // NOTE: must be To_str__msg_only; err_filter_mgr has defintion and it doesn't match current; print warn; DATE:2015-07-24
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", ctx.Page().Ttl().Raw(), String_.new_u8(src, self.Src_bgn(), self.Src_end()), err.To_str__log());
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", ctx.Page().Ttl().Raw(), Bry_.Replace(Bry_.Mid(src, self.Src_bgn(), self.Src_end()), Byte_ascii.Nl, Byte_ascii.Tab), err.To_str__log());
wiki.Parser_mgr().Scrib().Terminate_when_page_changes_y_(); // NOTE: terminate core when page changes; not terminating now, else page with many errors will be very slow due to multiple remakes of core; PAGE:th.d:all; DATE:2014-10-03
}
}

View File

@@ -101,6 +101,7 @@ class Luaj_value_ {
else if (Object_.Eq(c, Float_.Cls_ref_type)) return LuaValue.valueOf((Float)o);
else if (Object_.Eq(c, Char_.Cls_ref_type)) return LuaValue.valueOf((Character)o);
else if (Object_.Eq(c, Short_.Cls_ref_type)) return LuaValue.valueOf((Short)o);
else if (Object_.Eq(c, Decimal_adp.class)) return LuaValue.valueOf(((Decimal_adp)o).To_double()); // DATE:2016-08-01
else return LuaValue.NIL;
}
private static LuaTable Kv_ary_to_lua_tbl(Luaj_server server, Keyval... ary) {

View File

@@ -136,7 +136,7 @@ class Scrib_lib_message_data {
&& raw_msg_key == null // ignore if raw_msg; note that raw_msg can generate empty String; EX:raw_msg={{empty}} -> ""; PAGE:it.w:L'Internazionale DATE:2015-02-25
) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
bfr.Add(gplx.langs.htmls.Gfh_entity_.Lt_bry).Add(msg_key).Add(gplx.langs.htmls.Gfh_entity_.Gt_bry); // NOTE: Message.php has logic that says: if plain, "< >", else "&lt; &gt;"; for now, always use escaped
bfr.Add(gplx.langs.htmls.entitys.Gfh_entity_.Lt_bry).Add(msg_key).Add(gplx.langs.htmls.entitys.Gfh_entity_.Gt_bry); // NOTE: Message.php has logic that says: if plain, "< >", else "&lt; &gt;"; for now, always use escaped
return bfr.To_bry_and_rls();
}
switch (fmt_tid) {

View File

@@ -52,60 +52,78 @@ public class Scrib_lib_text implements Scrib_lib {
public boolean UnstripNoWiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(args.Pull_str(0));} // NOTE: XOWA does not use MediaWiki strip markers; just return original; DATE:2015-01-20
public boolean KillMarkers(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(args.Pull_str(0));} // NOTE: XOWA does not use MediaWiki strip markers; just return original; DATE:2015-01-20
public boolean GetEntityTable(Scrib_proc_args args, Scrib_proc_rslt rslt) {
if (Gfh_entity_ == null) Gfh_entity_ = Scrib_lib_text_html_entities.new_();
return rslt.Init_obj(Gfh_entity_);
} private static Keyval[] Gfh_entity_;
if (html_entities == null) html_entities = Scrib_lib_text_html_entities.new_();
return rslt.Init_obj(html_entities);
} private static Keyval[] html_entities;
public boolean JsonEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Object itm = args.Pull_obj(0);
Class<?> itm_type = itm.getClass();
Keyval[] itm_as_kvy = null;
// try to determine if node or array; EX: {a:1, b:2} vs [a:1, b:2]
Keyval[] itm_as_nde = null;
Object itm_as_ary = null;
if (Type_adp_.Eq(itm_type, Keyval[].class)) itm_as_kvy = (Keyval[])itm;
else if (Type_adp_.Is_array(itm_type)) itm_as_ary = Array_.cast(itm);
int flags = args.Cast_int_or(1, 0);
synchronized (reindex_data) {
if ( itm_as_kvy != null
&& itm_as_kvy.length > 0
&& !Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys)
) {
json_util.Reindex_arrays(reindex_data, itm_as_kvy, true);
if (reindex_data.Rv_is_kvy()) {
itm_as_kvy = reindex_data.Rv_as_kvy();
itm_as_ary = null;
}
else {
itm_as_ary = reindex_data.Rv_as_ary();
itm_as_kvy = null;
}
}
byte[] rv = null;
if (itm_as_kvy != null)
rv = json_util.Encode_as_nde(itm_as_kvy, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
else
rv = json_util.Encode_as_ary(itm_as_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
return rslt.Init_obj(rv);
Class<?> itm_type = itm.getClass();
boolean itm_is_nde = Type_adp_.Eq(itm_type, Keyval[].class);
// additional logic to classify "[]" as ary, not nde; note that this is done by checking len of itm_as_nde
if (itm_is_nde) {
itm_as_nde = (Keyval[])itm;
int itm_as_nde_len = itm_as_nde.length;
if (itm_as_nde_len == 0) { // Keyval[0] could be either "[]" or "{}"; for now, classify as "[]" per TextLibraryTests.lua; 'json encode, empty table (could be either [] or {}, but change should be announced)'; DATE:2016-08-01
itm_as_nde = null;
itm_is_nde = false;
}
}
if (!itm_is_nde)
itm_as_ary = Array_.cast(itm);
// reindex ndes unless preserve_keys
int flags = args.Cast_int_or(1, 0);
if ( itm_is_nde
&& !Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys)
) {
json_util.Reindex_arrays(reindex_data, itm_as_nde, true);
if (reindex_data.Rv_is_kvy()) {
itm_as_nde = reindex_data.Rv_as_kvy();
itm_as_ary = null;
}
else {
itm_as_ary = reindex_data.Rv_as_ary();
itm_as_nde = null;
itm_is_nde = false;
}
}
// encode and return
byte[] rv = itm_is_nde
? json_util.Encode_as_nde(itm_as_nde, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all)
: json_util.Encode_as_ary(itm_as_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all)
;
if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
return rslt.Init_obj(rv);
}
public boolean JsonDecode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
// init
byte[] json = args.Pull_bry(0);
int flags = args.Cast_int_or(1, 0);
int opts = Scrib_lib_text__json_util.Opt__force_assoc;
if (Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__try_fixing))
opts = Bitmask_.Add_int(opts, Scrib_lib_text__json_util.Flag__try_fixing);
synchronized (procs) {
byte rv_tid = json_util.Decode(core.App().Utl__json_parser(), json, opts);
if (rv_tid == Bool_.__byte) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to decode String " + String_.new_u8(json));
if (rv_tid == Bool_.Y_byte && !(Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))) {
Keyval[] rv_as_kvy = (Keyval[])json_util.Decode_rslt_as_nde();
synchronized (reindex_data) {
json_util.Reindex_arrays(reindex_data, rv_as_kvy, false);
return rslt.Init_obj(reindex_data.Rv_is_kvy() ? reindex_data.Rv_as_kvy() : reindex_data.Rv_as_ary());
}
}
else
return rslt.Init_obj(json_util.Decode_rslt_as_ary());
// decode json to Object; note that Bool_.Y means ary and Bool_.N means ary
byte rv_tid = json_util.Decode(core.App().Utl__json_parser(), json, opts);
if (rv_tid == Bool_.__byte) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to decode String " + String_.new_u8(json));
if (rv_tid == Bool_.Y_byte) {
Keyval[] rv_as_kvy = (Keyval[])json_util.Decode_rslt_as_nde();
// reindex unless preserve_keys passed
if (!(Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))) {
json_util.Reindex_arrays(reindex_data, rv_as_kvy, false);
rv_as_kvy = reindex_data.Rv_is_kvy() ? (Keyval[])reindex_data.Rv_as_kvy() : (Keyval[])reindex_data.Rv_as_ary();
}
return rslt.Init_obj(rv_as_kvy);
}
else
return rslt.Init_obj(json_util.Decode_rslt_as_ary());
}
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean Init_text_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {

View File

@@ -79,12 +79,12 @@ class Scrib_lib_text__json_util {
}
}
public Keyval[] Decode_rslt_as_nde() {return decode_rslt_as_nde;} private Keyval[] decode_rslt_as_nde;
public Object Decode_rslt_as_ary() {return decode_rslt_as_ary;} private Object decode_rslt_as_ary;
public Keyval[] Decode_rslt_as_ary() {return decode_rslt_as_ary;} private Keyval[] decode_rslt_as_ary;
public byte Decode(Json_parser parser, byte[] src, int flag) {
synchronized (wtr) {
Json_doc jdoc = parser.Parse(src);
if (jdoc.Root_grp().Tid() == Json_itm_.Tid__ary) {
this.decode_rslt_as_ary = Decode_ary(jdoc.Root_ary());
this.decode_rslt_as_ary = Decode_ary_top(jdoc.Root_ary());
return Bool_.N_byte;
}
else {
@@ -105,12 +105,21 @@ class Scrib_lib_text__json_util {
private Object Decode_obj(Json_itm itm) {
int itm_tid = itm.Tid();
switch (itm_tid) {
case Json_itm_.Tid__ary: return Decode_ary(Json_ary.cast(itm));
case Json_itm_.Tid__ary: return Decode_ary_sub(Json_ary.cast(itm));
case Json_itm_.Tid__nde: return Decode_nde(Json_nde.cast(itm));
default: return itm.Data();
}
}
private Object Decode_ary(Json_ary ary) {
private Keyval[] Decode_ary_top(Json_ary ary) { // NOTE: top-level arrays must be returned as numbered nodes; EX: [{1:a}, {2:b}, {3:c}] not [a, b, c]; DATE:2016-08-01
int len = ary.Len();
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; ++i) {
Json_itm itm = ary.Get_at(i);
rv[i] = Keyval_.int_(i + List_adp_.Base1, Decode_obj(itm));
}
return rv;
}
private Object Decode_ary_sub(Json_ary ary) {
int len = ary.Len();
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i) {

View File

@@ -25,15 +25,6 @@ public class Scrib_lib_text_json_tst {
lib = fxt.Core().Lib_text();
lib.Init();
}
@Test public void Nde__empty() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
( "{"
, "}"
)
, Keyval_.Ary_empty
);
}
@Test public void Nde__key_obj__primitives() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
, Json_doc.Make_str_by_apos
@@ -135,27 +126,36 @@ public class Scrib_lib_text_json_tst {
json_fxt.Test_json_decode(fxt, lib
, Scrib_lib_text__json_util.Flag__preserve_keys
, Json_doc.Make_str_by_apos
( "[ 1"
, ", 'abc'"
, ", true"
, ", false"
, "]"
( "{ '1':1"
, ", '2':'abc'"
, ", '3':true"
, ", '4':false"
, "}"
)
, new Object[]
, Kv_ary_utl.new_(Bool_.Y, new Object[]
{ 1
, "abc"
, true
, false
}
);
));
}
// @Test public void Nde__empty() { // NOTE: based on MW
// json_fxt.Test_json_roundtrip(fxt, lib
// , Json_doc.Make_str_by_apos
// ( "{"
// , "}"
// )
// , Keyval_.Ary_empty
// );
// }
@Test public void Ary__empty() { // NOTE: based on MW
json_fxt.Test_json_roundtrip(fxt, lib
json_fxt.Test_json_encode(fxt, lib, Scrib_lib_text__json_util.Flag__none
, Kv_ary_utl.new_(Bool_.Y, new Object[] {})
, Json_doc.Make_str_by_apos
( "["
, "]"
)
, Object_.Ary_empty
);
}
@Test public void Ary__obj() { // NOTE: based on MW
@@ -187,7 +187,7 @@ public class Scrib_lib_text_json_tst {
, " ]"
, "]"
)
, new Object[] {1, 2, 3, new Object[] {4, 5, new Object[] {6, 7, 8}, 9}}
, Kv_ary_utl.new_(Bool_.Y, new Object[] {1, 2, 3, new Object[] {4, 5, new Object[] {6, 7, 8}, 9}})
);
}
@Test public void Nde__smoke() {
@@ -237,7 +237,7 @@ public class Scrib_lib_text_json_tst {
}
}
class Scrib_lib_json_fxt {
private final Json_wtr wtr = new Json_wtr();
private final Json_wtr wtr = new Json_wtr();
public void Test_json_roundtrip(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, String json, Object obj) {
Test_json_decode(fxt, lib, Scrib_lib_text__json_util.Flag__none, json, obj);
Test_json_encode(fxt, lib, Scrib_lib_text__json_util.Flag__none, obj, json);

View File

@@ -20,7 +20,7 @@ import gplx.core.primitives.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.files.commons.*; import gplx.xowa.files.origs.*;
import gplx.xowa.bldrs.wms.apis.*;
import gplx.xowa.apps.wms.apis.*;
public class Scrib_lib_title implements Scrib_lib {
public Scrib_lib_title(Scrib_core core) {this.core = core;} private Scrib_core core;
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
@@ -149,6 +149,7 @@ public class Scrib_lib_title implements Scrib_lib {
return rslt.Init_obj(rv);
}
public boolean GetFileInfo(Scrib_proc_args args, Scrib_proc_rslt rslt) {
// init; get ttl
byte[] ttl_bry = args.Pull_bry(0);
Xowe_wiki wiki = core.Wiki();
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
@@ -156,22 +157,20 @@ public class Scrib_lib_title implements Scrib_lib {
|| !ttl.Ns().Id_is_file_or_media()
) return rslt.Init_obj(GetFileInfo_absent);
if (ttl.Ns().Id_is_media()) ttl = Xoa_ttl.Parse(wiki, Xow_ns_.Tid__file, ttl.Page_db()); // if [[Media:]] change to [[File:]]; theoretically, this should be changed in Get_page, but not sure if I want to put this logic that low; DATE:2014-01-07
// Xoae_page file_page = Pfunc_filepath.Load_page(wiki, ttl); // EXPENSIVE
// boolean exists = !file_page.Missing();
// if (!exists) return rslt.Init_obj(Keyval_.Ary(Keyval_.new_("exists", false))); // NOTE: do not reinstate; will exit early if commons is not installed; DATE:2015-01-25; NOTE: Media objects are often flagged as absent in offline mode
// NOTE: MW registers image if deleted; XOWA doesn't register b/c needs width / height also, not just image name
// get file info from db / wmf
wiki.File_mgr().Init_file_mgr_by_load(wiki);
Xof_orig_itm itm = wiki.File__orig_mgr().Find_by_ttl_or_null(ttl.Page_db());
if (itm == Xof_orig_itm.Null) return rslt.Init_obj(GetFileInfo_absent);
Keyval[] rv = Keyval_.Ary
( Keyval_.new_("exists" , true)
, Keyval_.new_("width" , itm.W())
, Keyval_.new_("height" , itm.H())
, Keyval_.new_("pages" , null) // TODO_OLD: get pages info
);
Xof_orig_itm itm = wiki.File__orig_mgr().Find_by_ttl_or_null(ttl.Page_db()); // NOTE: MW registers image if deleted; XOWA doesn't register b/c needs width / height also, not just image name
Keyval[] rv = itm == Xof_orig_itm.Null
? GetFileInfo_absent
: Keyval_.Ary
( Keyval_.new_("exists" , true)
, Keyval_.new_("width" , itm.W())
, Keyval_.new_("height" , itm.H())
, Keyval_.new_("pages" , null) // TODO_OLD: get pages info
);
return rslt.Init_obj(rv);
}
private static final Keyval[] GetFileInfo_absent = Keyval_.Ary(Keyval_.new_("exists", false));
} private static final Keyval[] GetFileInfo_absent = Keyval_.Ary(Keyval_.new_("exists", false), Keyval_.new_("width", 0), Keyval_.new_("height", 0)); // NOTE: must supply non-null values for w / h, else Modules will fail with nil errors; PAGE:pl.w:Andrespol DATE:2016-08-01
public boolean GetContent(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte[] ttl_bry = args.Pull_bry(0);
Xowe_wiki wiki = core.Wiki();

View File

@@ -22,7 +22,7 @@ public class Scrib_lib_title_tst {
@Before public void init() {
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
fxt.Clear();
fxt.Core().Wiki().File__fsdb_mode().Tid_v2_bld_y_();
fxt.Core().Wiki().File__fsdb_mode().Tid__v2__bld__y_();
lib = fxt.Core().Lib_title().Init();
}
@Test public void NewTitle() {
@@ -145,6 +145,8 @@ public class Scrib_lib_title_tst {
return String_.Concat_lines_nl_skip_last
( "1="
, " exists=false"
, " width=0"
, " height=0"
);
}
private static String file_info_exists(String ttl, int w, int h) {