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:
@@ -36,7 +36,7 @@ public class Ref_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
if (xatr_id_obj == null) return;
|
||||
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
|
||||
switch (xatr_id.Val()) {
|
||||
case Xatr_id_name: name = wiki.Appe().Sanitizer().Escape_id(xatr.Val_as_bry()); break;
|
||||
case Xatr_id_name: name = wiki.Sanitizer().Escape_id(xatr.Val_as_bry()); break;
|
||||
case Xatr_id_follow: follow = xatr.Val_as_bry(); break;
|
||||
case Xatr_id_group: group = xatr.Val_as_bry(); break;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class Gallery_mgr_base__basic__tst {
|
||||
}
|
||||
@Test public void Hdump__div_1_w() {// PURPOSE: handle hdump and div_1_width == 115 instead of 15; PAGE:en.w:National_Gallery_of_Art; DATE:2016-06-19
|
||||
fxt.Fxt().Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump);
|
||||
fxt.Fxt().Wiki().File__fsdb_mode().Tid_v2_bld_y_(); // NOTE: must set to v2 mode; dflt will call old v1 img code which "guesses" at html_h;
|
||||
fxt.Fxt().Wiki().File__fsdb_mode().Tid__v2__bld__y_(); // NOTE: must set to v2 mode; dflt will call old v1 img code which "guesses" at html_h;
|
||||
fxt.Test_html_frag("<gallery widths=200px heights=200px perrow=5>File:A.png|a</gallery>", "<div style=\"margin:15px auto;\">");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
class Hiero_html_wtr {
|
||||
private Hiero_phoneme_mgr phoneme_mgr;
|
||||
private Bry_bfr temp_bfr = Bry_bfr_.Reset(255);
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xow
|
||||
import gplx.xowa.files.*; import gplx.xowa.guis.cbks.js.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.xtns.imaps.itms.*; import gplx.xowa.xtns.imaps.htmls.*;
|
||||
public class Imap_map implements Xoh_file_img_wkr, Js_img_wkr {
|
||||
public class Imap_map implements Xoh_file_fmtr, Js_img_wkr {
|
||||
private byte img_cls_tid; private Imap_xtn_mgr xtn_mgr;
|
||||
private byte[] a_href, img_alt, img_cls_other;
|
||||
public Imap_map(int id) {this.id = id;}
|
||||
@@ -35,7 +35,7 @@ public class Imap_map implements Xoh_file_img_wkr, Js_img_wkr {
|
||||
public Imap_err[] Errs() {return errs;} private Imap_err[] errs;
|
||||
public boolean Invalid() {return img == null;} // invalid if missing image; PAGE:en.w:Wikipedia:WikiProject_Games/Advert EX: <imagemap>|thumb;</imagemap>; DATE:2014-08-12
|
||||
|
||||
public void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoae_page page, byte[] src, Xof_file_itm xfer_itm, int uid
|
||||
public void Add_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoae_page page, byte[] src, Xof_file_itm xfer_itm, int uid
|
||||
, byte[] a_href, boolean a_href_is_file, byte a_cls, byte a_rel, byte[] a_title, byte[] a_xowa_title
|
||||
, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte img_cls, byte[] img_cls_other
|
||||
) {
|
||||
|
||||
@@ -40,10 +40,10 @@ public class Imap_img_arg implements gplx.core.brys.Bfr_arg {
|
||||
if (hctx.Mode_is_hdump()) {
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.Get();
|
||||
try {
|
||||
byte[] data_xowa_image = Xoh_file_html_fmtr__hdump.Bld_xowa_image_data(tmp_bfr, Xop_lnki_type.Id_none, img_w, img_h, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null);
|
||||
byte[] data_xowa_image = Xoh_file_fmtr__hdump.Bld_xowa_image_data(tmp_bfr, Xop_lnki_type.Id_none, img_w, img_h, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null);
|
||||
byte[] data_xowa_title = Gfh_atr_.Make(tmp_bfr, Xoh_img_xoimg_data.Bry__data_xowa_title, lnki_ttl);
|
||||
byte[] usemap = tmp_bfr.Add(Imap_xtn_mgr.Bry__usemap__html).Add_int_variable(map.Id()).Add_byte_quote().To_bry_and_clear();
|
||||
Xoh_file_html_fmtr__hdump.Bld_anch_n(tmp_bfr, data_xowa_title, data_xowa_image, Xoh_img_cls_.Tid__thumbimage, Bry_.Empty, Bry_.Empty, usemap);
|
||||
Xoh_file_fmtr__hdump.Add_anch_n(tmp_bfr, data_xowa_title, data_xowa_image, Xoh_img_cls_.Tid__thumbimage, Bry_.Empty, Bry_.Empty, usemap);
|
||||
bfr.Add_byte_nl().Add_byte_repeat(Byte_ascii.Space, 6);
|
||||
bfr.Add_bfr_and_clear(tmp_bfr);
|
||||
} finally {tmp_bfr.Mkr_rls();}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.htmls.*; import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.vnts.*;
|
||||
public class Xof_math_html_wtr {
|
||||
private final Bry_fmtr math_fmtr_latex = Bry_fmtr.new_("<img id='xowa_math_img_~{math_idx}' src='' width='' height=''/><span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>", "math_idx", "math_text");
|
||||
@@ -62,8 +62,8 @@ public class Xof_math_html_wtr {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Lt: if (mathjax) escaped = gplx.langs.htmls.Gfh_entity_.Lt_bry; break;
|
||||
case Byte_ascii.Gt: if (mathjax) escaped = gplx.langs.htmls.Gfh_entity_.Gt_bry; break;
|
||||
case Byte_ascii.Lt: if (mathjax) escaped = gplx.langs.htmls.entitys.Gfh_entity_.Lt_bry; break;
|
||||
case Byte_ascii.Gt: if (mathjax) escaped = gplx.langs.htmls.entitys.Gfh_entity_.Gt_bry; break;
|
||||
// case Byte_ascii.Amp: escaped = Const_amp; break; // TOMBSTONE:never escape ampersand; PAGE:s.w:Matrix_(mathematics); DATE:2014-07-19
|
||||
// case Byte_ascii.Quote: if (mathjax) escaped = gplx.langs.htmls.Gfh_entity_.Quote_bry; break; // TOMBSTONE:do not escape quote; PAGE:s.w:Matrix_(mathematics); DATE:2014-07-19
|
||||
default:
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.envs.*; import gplx.core.caches.*;
|
||||
import gplx.xowa.bldrs.wms.apis.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.apps.wms.apis.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Pfunc_ifexist_mgr {
|
||||
private final Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
|
||||
@@ -26,6 +26,6 @@ public class Pfunc_rev_props_tst {
|
||||
@Test public void Page_size() {fxt.Test_parse_tmpl_str_test("{{PAGESIZE:Test page}}" , "{{test}}", "0");}
|
||||
@Test public void Revision_size() {fxt.Test_parse_tmpl_str_test("{{REVISIONSIZE}}" , "{{test}}", "8");}
|
||||
@Test public void Protection_level() {fxt.Test_parse_tmpl_str_test("{{PROTECTIONLEVEL}}" , "{{test}}", "normal");}
|
||||
@Test public void Protection_expiry() {fxt.Test_parse_tmpl_str_test("{{PROTECTIONEXPIRY}}" , "{{test}}", "infinite");}
|
||||
@Test public void Protection_expiry() {fxt.Test_parse_tmpl_str_test("{{PROTECTIONEXPIRY}}" , "{{test}}", "infinity");}
|
||||
@Test public void PageSize_invalid_ttl() {fxt.Test_parse_tmpl_str_test("{{PAGESIZE:{{{100}}}|R}}" , "{{test}}", "0");}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Pfunc_filepath extends Pf_func_base {
|
||||
byte[] url = wiki.Parser_mgr().Url_bldr().Init_for_trg_html(Xof_repo_itm_.Mode_orig, trg_repo, ttl_bry, xfer_itm.Orig_ttl_md5(), xfer_itm.Orig_ext(), Xof_img_size.Size__neg1, Xof_lnki_time.Null, Xof_lnki_page.Null).Xto_bry();
|
||||
bfr.Add(url);
|
||||
}
|
||||
private static Pfunc_filepath_itm Load_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
public static Pfunc_filepath_itm Load_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
// try to get from cache
|
||||
Gfo_cache_mgr cache_mgr = wiki.Cache_mgr().Commons_cache();
|
||||
byte[] cache_key = ttl.Page_url();
|
||||
@@ -69,9 +69,3 @@ public class Pfunc_filepath extends Pf_func_base {
|
||||
return cache_itm;
|
||||
}
|
||||
}
|
||||
class Pfunc_filepath_itm implements Rls_able {
|
||||
public Pfunc_filepath_itm(boolean exists, byte[] page_url) {this.exists = exists; this.page_url = page_url;}
|
||||
public boolean Exists() {return exists;} private final boolean exists;
|
||||
public byte[] Page_url() {return page_url;} private final byte[] page_url;
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
public class Pfunc_filepath_itm implements Rls_able {
|
||||
public Pfunc_filepath_itm(boolean exists, byte[] page_url) {this.exists = exists; this.page_url = page_url;}
|
||||
public boolean Exists() {return exists;} private final boolean exists;
|
||||
public byte[] Page_url() {return page_url;} private final byte[] page_url;
|
||||
public void Rls() {}
|
||||
}
|
||||
@@ -61,6 +61,6 @@ public class Pfunc_filepath_tst {
|
||||
}
|
||||
// private static void Init_orig_mgr(Xow_wiki wiki) {
|
||||
// Xof_orig_tbl orig_tbl = null;
|
||||
// wiki.File__orig_mgr().Init_by_wiki(wiki, Xof_fsdb_mode.new_v2_gui(), new Xof_orig_tbl[] {orig_tbl}, Xof_url_bldr.new_v2());
|
||||
// wiki.File__orig_mgr().Init_by_wiki(wiki, Xof_fsdb_mode.New__v2__gui(), new Xof_orig_tbl[] {orig_tbl}, Xof_url_bldr.new_v2());
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.poems; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
|
||||
public class Poem_nde implements Xox_xnde {
|
||||
private Xop_root_tkn xtn_root;
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.apps.cfgs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.xtns.lst.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*;
|
||||
@@ -347,7 +347,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
lst_pfunc_wkr.Init_include(ttl.Full_db(), cur_sect_bgn, cur_sect_end).Exec(page_bfr, ctx);
|
||||
prepend_mgr.End(ctx, full_bfr, page_bfr.Bfr(), page_bfr.Len(), Bool_.Y);
|
||||
full_bfr.Add_bfr_and_clear(page_bfr);
|
||||
full_bfr.Add(gplx.langs.htmls.Gfh_entity_.Space_bry); // $out.= " "; REF.MW:ProofreadPageRenderer.pn
|
||||
full_bfr.Add(gplx.langs.htmls.entitys.Gfh_entity_.Space_bry); // $out.= " "; REF.MW:ProofreadPageRenderer.pn
|
||||
}
|
||||
page_bfr.Mkr_rls();
|
||||
ctx.Tmpl_output_(null);
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scores; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.htmls.*; import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
|
||||
@@ -80,7 +80,7 @@ public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
|
||||
html_id_img = hcmd_id + "_img";
|
||||
html_id_a = hcmd_id + "_a";
|
||||
html_a_href = ""; html_img_src = "";
|
||||
html_img_alt = String_.new_u8(Bry_.Replace(code, Byte_ascii.Nl_bry, gplx.langs.htmls.Gfh_entity_.Nl_bry));
|
||||
html_img_alt = String_.new_u8(Bry_.Replace(code, Byte_ascii.Nl_bry, gplx.langs.htmls.entitys.Gfh_entity_.Nl_bry));
|
||||
String html_img_alt_tmp = "", html_img_src_tmp = "", html_a_href_tmp = "";
|
||||
html_img_src = png_file.To_http_file_str();
|
||||
html_a_href = aud_file.To_http_file_str();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 "< >"; 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 "< >"; for now, always use escaped
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
switch (fmt_tid) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user