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

'v3.3.4.1'

This commit is contained in:
gnosygnu
2016-03-27 23:44:59 -04:00
parent de67253a9c
commit baaef32df2
903 changed files with 13339 additions and 8695 deletions

View File

@@ -90,14 +90,14 @@ public class Xow_xtn_mgr implements GfoInvkAble {
byte[] xtn_key = mgr.Xtn_key();
Object o = xtn_tid_trie.Match_exact(xtn_key, 0, xtn_key.length); if (o == null) return;
switch (((Byte_obj_val)o).Val()) {
case Tid_cite: xtn_cite = (Cite_xtn_mgr)mgr; break;
case Tid_sites: xtn_sites = (Sites_xtn_mgr)mgr; break;
case Tid_insider: xtn_insider = (Insider_xtn_mgr)mgr; break;
case Tid_indicator: xtn_indicator= (Indicator_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;
case Tid_pgbnr: xtn_pgbnr = (Pgbnr_xtn_mgr)mgr; break;
case Tid_cite: xtn_cite = (Cite_xtn_mgr)mgr; break;
case Tid_sites: xtn_sites = (Sites_xtn_mgr)mgr; break;
case Tid_insider: xtn_insider = (Insider_xtn_mgr)mgr; break;
case Tid_indicator: xtn_indicator = (Indicator_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;
case Tid_pgbnr: xtn_pgbnr = (Pgbnr_xtn_mgr)mgr; break;
}
}
private static final byte Tid_cite = 0, Tid_sites = 1, Tid_insider = 2, Tid_imap = 3, Tid_proofread = 4, Tid_wikibase = 5, Tid_indicator = 6, Tid_pgbnr = 7;

View File

@@ -33,7 +33,7 @@ public class References_nde implements Xox_xnde, Mwh_atr_itm_owner {
if (ctx.Tid_is_popup()) return;
Ref_itm_mgr ref_mgr = ctx.Page().Ref_mgr();
if (ref_mgr.References__recursing()) return; // skip nested <references> else refs will be lost; EX:"<references><references/></references>"; PAGE:en.w:Hwair; DATE:2014-06-27
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag_div); // xnde generates <block_node>; <references> -> <ol>; close any blocks; PAGE:fr.w:Heidi_(roman); DATE:2014-02-17
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag__div); // xnde generates <block_node>; <references> -> <ol>; close any blocks; PAGE:fr.w:Heidi_(roman); DATE:2014-02-17
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair) { // "<references>", "</references>"; parse anything in between but only to pick up <ref> tags; discard everything else; DATE:2014-06-27
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn();

View File

@@ -28,7 +28,7 @@ class Cldr_lang_tbl implements Rls_able {
this.fld_lang_name = flds.Add_str("lang_name", 2048);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_cldr_code, fld_lang_code)));}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_cldr_code, fld_lang_code)));}
public void Insert_bgn() {conn.Txn_bgn("cldr_lang__inser"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(byte[] cldr_code, byte[] lang_code, byte[] lang_name) {
@@ -44,4 +44,4 @@ class Cldr_lang_tbl implements Rls_able {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
}
}

View File

@@ -24,7 +24,7 @@ public class Dpl_xnde implements Xox_xnde {
private Dpl_itm itm = new Dpl_itm(); private List_adp pages = List_adp_.new_();
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {} // NOTE: <dynamicPageList> has no attributes
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
itm.Parse(wiki, ctx, ctx.Page().Ttl().Full_txt(), src, xnde);
itm.Parse(wiki, ctx, ctx.Page().Ttl().Full_txt_w_ttl_case(), src, xnde);
Dpl_page_finder.Find_pages(pages, wiki, itm);
if (itm.Sort_ascending() != Bool_.__byte)
pages.Sort_by(new Dpl_page_sorter(itm));
@@ -53,14 +53,14 @@ public class Dpl_xnde implements Xox_xnde {
for (int i = itms_bgn; i < itms_len; i++) {
Xowd_page_itm page = (Xowd_page_itm)pages.Get_at(i);
Xoa_ttl ttl = Xoa_ttl.parse(wiki, page.Ns_id(), page.Ttl_page_db());
byte[] ttl_page_txt = show_ns ? ttl.Full_txt() : ttl.Page_txt();
byte[] ttl_page_txt = show_ns ? ttl.Full_txt_w_ttl_case() : ttl.Page_txt();
if (ttl_page_txt == null) continue; // NOTE: apparently DynamicPageList allows null pages; DATE:2013-07-22
switch (html_mode.Tid()) {
case Dpl_html_data.Tid_list_ul:
case Dpl_html_data.Tid_list_ol:
bfr.Add(Xoh_consts.Space_2).Add(html_mode.Itm_bgn()).Add(Gfh_bldr_.Bry__a_lhs_w_href);
bfr.Add_str_a7("/wiki/").Add(Gfo_url_encoder_.Href.Encode(ttl.Full_db())).Add_byte_quote(); // NOTE: Full_db to encode spaces as underscores; PAGE:en.q:Wikiquote:Speedy_deletions DATE:2016-01-19
Gfh_atr_.Add(bfr, Gfh_atr_.Bry__title, Xoh_html_wtr_escaper.Escape(amp_mgr, tmp_bfr, ttl.Full_txt())); // NOTE: Full_txt b/c title always includes ns, even if show_ns is off; PAGE:en.b:Wikibooks:WikiProject DATE:2016-01-20
Gfh_atr_.Add(bfr, Gfh_atr_.Bry__title, Xoh_html_wtr_escaper.Escape(amp_mgr, tmp_bfr, ttl.Full_txt_w_ttl_case())); // NOTE: Full_txt b/c title always includes ns, even if show_ns is off; PAGE:en.b:Wikibooks:WikiProject DATE:2016-01-20
if (itm.No_follow()) bfr.Add(Bry_nofollow);
bfr.Add_byte(Byte_ascii.Gt);
Xoh_html_wtr_escaper.Escape(amp_mgr, bfr, ttl_page_txt, 0, ttl_page_txt.length, false, false);

View File

@@ -51,11 +51,11 @@ public class Flagged_revs_lib implements Scrib_lib {
// if ( !FlaggedRevs::inReviewNamespace( $title ) ) return rslt.Init_null();
return rslt.Init_obj(getDefaultVisibilitySettings());
}
private static KeyVal[] getDefaultVisibilitySettings() {
KeyVal[] rv = new KeyVal[3];
rv[0] = KeyVal_.new_("over"+"ride", 0); // FlaggedRevs::isStableShownByDefault() ? 1 : 0,
rv[1] = KeyVal_.new_("autoreview", "");
rv[2] = KeyVal_.new_("expiry", "infinity");
private static Keyval[] getDefaultVisibilitySettings() {
Keyval[] rv = new Keyval[3];
rv[0] = Keyval_.new_("over"+"ride", 0); // FlaggedRevs::isStableShownByDefault() ? 1 : 0,
rv[1] = Keyval_.new_("autoreview", "");
rv[2] = Keyval_.new_("expiry", "infinity");
return rv;
}
}

View File

@@ -69,8 +69,8 @@ class Gallery_itm_parser_fxt {
private Xoae_app app; private Xowe_wiki wiki;
private Gallery_itm_parser parser;
public Gallery_itm_parser_fxt Init() {
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
parser = new Gallery_itm_parser();
parser.Init_by_wiki(wiki);
return this;
@@ -97,7 +97,7 @@ class Gallery_itm_parser_fxt {
Gallery_itm itm = (Gallery_itm)list.Get_at(i);
String[] ary = new String[5];
rv[i] = ary;
ary[0] = String_.new_u8(itm.Ttl().Full_txt());
ary[0] = String_.new_u8(itm.Ttl().Full_txt_w_ttl_case());
ary[2] = Xto_str_ary_itm(src, itm.Alt_bgn(), itm.Alt_end());
ary[3] = Xto_str_ary_itm(src, itm.Link_bgn(), itm.Link_end());
ary[4] = Xto_str_ary_itm(src, itm.Page_bgn(), itm.Page_end());

View File

@@ -84,7 +84,6 @@ public abstract class Gallery_mgr_base {
Gallery_itm itm = (Gallery_itm)xnde.Itms_get_at(i);
Xoa_ttl ttl = itm.Ttl(); if (Bry_.Len_eq_0(ttl.Page_db())) return; // if file ttl is invalid, do not write; EX:File:#A.png; DATE:2016-01-12
byte[] itm_caption = itm.Caption_bry(); if (itm_caption == null) itm_caption = Bry_.Empty;
Xop_lnki_tkn lnki = itm.Lnki_tkn();
int lnki_w_orig = lnki.W(), lnki_h_orig = lnki.H(); // store orig lnki_w / lnki_w
this.Get_thumb_size(lnki, itm.Ext()); // packed=expand by 1.5;
@@ -138,7 +137,6 @@ public abstract class Gallery_mgr_base {
tmp_bfr.Add(itm_divs_end_bry);
itm_html = tmp_bfr.To_bry_and_clear();
}
byte[] show_filenames_link = Bry_.Empty;
if (xnde.Show_filename()) {
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_plain_by_bry
@@ -192,7 +190,7 @@ public abstract class Gallery_mgr_base {
int len = xatr_list.Count();
for (int i = 0; i < len; i++) {
Mwh_atr_itm xatr = (Mwh_atr_itm)xatr_list.Get_at(i);
if (!whitelist_mgr.Chk(Xop_xnde_tag_.Tid_ul, src, xatr)) continue;
if (!whitelist_mgr.Chk(Xop_xnde_tag_.Tid__ul, src, xatr)) continue;
byte[] key = xatr.Key_bry();
byte[] val = xatr.Val_as_bry();
Gfh_wtr.Write_atr_bry(bfr, key, val);

View File

@@ -22,7 +22,7 @@ public class Gallery_xnde_tst {
@Before public void init() {fxt.Reset(); fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki());}
@Test public void Lnki_no_caption() {
fxt.Test_parse_page_wiki("<gallery>File:A.png</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
)
@@ -30,7 +30,7 @@ public class Gallery_xnde_tst {
}
@Test public void Lnki_1() {
fxt.Test_parse_page_wiki("<gallery>File:A.png|b</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
)
@@ -38,7 +38,7 @@ public class Gallery_xnde_tst {
}
@Test public void Lnki_3() {
fxt.Test_parse_page_wiki("<gallery>File:A.png|a\nFile:B.png|b\nFile:C.png|c</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
, new_chkr_gallery_itm().Expd_lnki_("File:B.png")
@@ -48,7 +48,7 @@ public class Gallery_xnde_tst {
}
@Test public void Ignore_newLines() {
fxt.Test_parse_page_wiki("<gallery>\n\n\nFile:A.png|a\n\n\nFile:B.png|b\n\n\n</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
, new_chkr_gallery_itm().Expd_lnki_("File:B.png")
@@ -57,7 +57,7 @@ public class Gallery_xnde_tst {
}
@Test public void Only_first_pipe() {
fxt.Test_parse_page_wiki("<gallery>File:A.png|File:B.png|cc</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
)
@@ -65,7 +65,7 @@ public class Gallery_xnde_tst {
}
@Test public void Invalid_lnki() {
fxt.Test_parse_page_wiki("<gallery>A.png|cc</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png") // NOTE: MW converts "A.png" to "File:A.png"
)
@@ -73,7 +73,7 @@ public class Gallery_xnde_tst {
}
@Test public void File_only_trailing_nl() {
fxt.Test_parse_page_wiki("<gallery>File:A.png\n</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_(null)
)
@@ -82,7 +82,7 @@ public class Gallery_xnde_tst {
@Test public void Invalid_curly() {
raw_src = "a\n";
fxt.Init_log_(Xop_ttl_log.Invalid_char).Test_parse_page_wiki("<gallery>File:A.png|" + raw_src + "}}</gallery>" // NOTE: }} is ignored since it is not a valid title
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_("a")
)
@@ -91,7 +91,7 @@ public class Gallery_xnde_tst {
@Test public void Caption() {
raw_src = "a<br/>c";
fxt.Test_parse_page_wiki("<gallery>File:A.png|" + raw_src + "</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_(raw_src)
)
@@ -103,7 +103,7 @@ public class Gallery_xnde_tst {
( "<gallery perrow=3>"
, "File:A.jpg|" + raw_src
, "</gallery>"
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.jpg").Expd_caption_(raw_src)
)
@@ -115,7 +115,7 @@ public class Gallery_xnde_tst {
( "<gallery>"
, "File:A.jpg|" + raw_src
, "</gallery>"
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.jpg").Expd_caption_("<center>a</center>")
)
@@ -127,7 +127,7 @@ public class Gallery_xnde_tst {
( "<gallery>"
, "<!-- deleted A.jpg|" + raw_src
, "</gallery>"
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_()
)
);
@@ -135,7 +135,7 @@ public class Gallery_xnde_tst {
@Test public void Misc_atr() { // make sure misc attribute doesn't fail
raw_src = "b";
fxt.Test_parse_page_wiki("<gallery id=a>File:A.png|" + raw_src + "</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid_gallery).Xnde_xtn_
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_(raw_src)
)

View File

@@ -39,8 +39,8 @@ public class Imap_parser_tst {
class Imap_fxt_base {
protected Xoae_app app; protected Xowe_wiki wiki;
@gplx.Virtual public void Reset() {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
wiki.Parser_mgr().Ctx().Para().Enabled_n_();
}
public Imap_itm_shape itm_rect_(String link, double... pts_ary) {return itm_shape_(Imap_itm_.Tid_shape_rect, link, pts_ary);}

View File

@@ -45,8 +45,8 @@ class Indicator_html_bldr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
private Indicator_xtn_mgr xtn_mgr;
public void Clear() {
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
this.xtn_mgr = wiki.Xtn_mgr().Xtn_indicator();
xtn_mgr.Enabled_y_();
xtn_mgr.Xtn_init_by_wiki(wiki);

View File

@@ -39,8 +39,8 @@ class Insider_html_bldr_fxt {
private Insider_xtn_mgr xtn_mgr;
private Insider_xtn_skin_itm skin_itm;
public void Clear() {
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xop_fxt.Init_msg(wiki, "insider-title", "Docent");
Xop_fxt.Init_msg(wiki, "insider-about", "About Docents");
Xop_fxt.Init_msg(wiki, "insider-about-page", "Docent_page");

View File

@@ -256,13 +256,13 @@ class Listing_xatrs {
public static Xop_xnde_tag Tag_by_tid(int tid) {
Xop_xnde_tag rv = null;
switch (tid) {
case Xop_xnde_tag_.Tid_listing_buy: rv = Xop_xnde_tag_.Tag_listing_buy; break;
case Xop_xnde_tag_.Tid_listing_do: rv = Xop_xnde_tag_.Tag_listing_do; break;
case Xop_xnde_tag_.Tid_listing_drink: rv = Xop_xnde_tag_.Tag_listing_drink; break;
case Xop_xnde_tag_.Tid_listing_eat: rv = Xop_xnde_tag_.Tag_listing_eat; break;
case Xop_xnde_tag_.Tid_listing_listing: rv = Xop_xnde_tag_.Tag_listing_listing; break;
case Xop_xnde_tag_.Tid_listing_see: rv = Xop_xnde_tag_.Tag_listing_see; break;
case Xop_xnde_tag_.Tid_listing_sleep: rv = Xop_xnde_tag_.Tag_listing_sleep; break;
case Xop_xnde_tag_.Tid__listing_buy: rv = Xop_xnde_tag_.Tag__listing_buy; break;
case Xop_xnde_tag_.Tid__listing_do: rv = Xop_xnde_tag_.Tag__listing_do; break;
case Xop_xnde_tag_.Tid__listing_drink: rv = Xop_xnde_tag_.Tag__listing_drink; break;
case Xop_xnde_tag_.Tid__listing_eat: rv = Xop_xnde_tag_.Tag__listing_eat; break;
case Xop_xnde_tag_.Tid__listing_listing: rv = Xop_xnde_tag_.Tag__listing_listing; break;
case Xop_xnde_tag_.Tid__listing_see: rv = Xop_xnde_tag_.Tag__listing_see; break;
case Xop_xnde_tag_.Tid__listing_sleep: rv = Xop_xnde_tag_.Tag__listing_sleep; break;
default: throw Err_.new_unhandled(tid);
}
return rv;

View File

@@ -102,6 +102,6 @@ public class Xof_math_mgr implements GfoInvkAble {
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_", Invk_renderer = "renderer", Invk_renderer_ = "renderer_", Invk_renderer_list = "renderer_list";
private static KeyVal[] Options_renderer_list = KeyVal_.Ary(KeyVal_.new_("mathjax", "MathJax"), KeyVal_.new_("latex", "LaTeX"));
private static Keyval[] Options_renderer_list = Keyval_.Ary(Keyval_.new_("mathjax", "MathJax"), Keyval_.new_("latex", "LaTeX"));
private static final String GRP_KEY = "xowa.math.mgr";
}

View File

@@ -0,0 +1,53 @@
/*
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.new_window_links; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.langs.kwds.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
import gplx.core.net.*;
public class New_window_link_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_new_window_link;}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public Pf_func New(int id, byte[] name) {return new New_window_link_func().Name_(name);}
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
byte[] title = Eval_argx(ctx, src, caller, self);
int self_args_len = self.Args_len();
byte[] caption = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, null);
Gfo_url url = url_parser.Parse(title);
if (url.Protocol_tid() == Gfo_protocol_itm.Tid_unknown) {
bfr.Add_str_a7("[[");
bfr.Add(title);
if (caption != null) {
bfr.Add_byte_pipe();
bfr.Add(caption);
}
// bfr.Add_str_a7("|target=_blank");
bfr.Add_str_a7("]]");
}
else {
if (caption == null)
bfr.Add(title);
else {
bfr.Add_str_a7("[");
bfr.Add(title);
bfr.Add_byte_space();
bfr.Add(caption);
bfr.Add_str_a7("]");
}
}
}
private static final Gfo_url_parser url_parser = new Gfo_url_parser();
}

View File

@@ -0,0 +1,26 @@
/*
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.new_window_links; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.pages.skins.*;
public class New_window_link_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Lnki__none() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:A}}" , "<a href='/wiki/A'>A</a>");}
@Test public void Lnki__caption() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:A|B}}" , "<a href='/wiki/A'>B</a>");}
@Test public void Lnke__none() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:https://a.org}}" , "<a href='https://a.org' rel='nofollow' class='external free'>https://a.org</a>");}
@Test public void Lnke__caption() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:https://a.org|A}}" , "<a href='https://a.org' rel='nofollow' class='external text'>A</a>");}
}

View File

@@ -37,8 +37,8 @@ public class Pgbnr_func_tst {
class Pgbnr_func_fxt {
private final Xop_fxt fxt;
public Pgbnr_func_fxt() {
Xoae_app app = Xoa_app_fxt.app_();
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, "en.wikivoyage.org");
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "en.wikivoyage.org");
fxt = new Xop_fxt(app, wiki);
}
public void Test__parse__eq(String raw, String expd) {

View File

@@ -20,7 +20,7 @@ import gplx.core.brys.*; import gplx.langs.mustaches.*; import gplx.xowa.parsers
import gplx.xowa.langs.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*;
import gplx.xowa.htmls.core.htmls.*;
public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_a7("pagebanner");
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_a7("pagebanner");
@Override public Xox_mgr Clone_new() {return new Pgbnr_xtn_mgr();}
public Pgbnr_cfg Cfg() {return cfg;} private Pgbnr_cfg cfg;
public Mustache_tkn_itm Template_root() {return template_root;} private Mustache_tkn_itm template_root;
@@ -34,7 +34,7 @@ public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
switch (wiki.Domain_tid()) {
case Xow_domain_tid_.Int__home:
enabled = true;
ns_ary = Int_.Ary(Xow_ns_.Tid__help);
ns_ary = Int_.Ary(Xow_ns_.Tid__main);
break;
case Xow_domain_tid_.Int__wikivoyage:
switch (wiki.Lang().Lang_id()) {
@@ -83,7 +83,7 @@ public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
if (itm == null) return;
Pgbnr_func.Add_banner(bfr, pctx, hctx, src);
}
private static final byte[] Template_dflt = Bry_.New_u8_nl_apos
private static final byte[] Template_dflt = Bry_.New_u8_nl_apos
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
, " <div class='wpb-topbanner'>"
, " {{#isHeadingOverrideEnabled}}<h1 class='wpb-name'>{{title}}</h1>{{/isHeadingOverrideEnabled}}"

View File

@@ -89,6 +89,7 @@ public class Pf_func_ {
, Xol_kwd_grp_.Id_strx_replace
, Xol_kwd_grp_.Id_strx_explode
, Xol_kwd_grp_.Id_strx_urldecode
, Xol_kwd_grp_.Id_new_window_link
);
Ary_nonwmf = (int[])list.To_ary_and_clear(int.class);
}
@@ -390,6 +391,7 @@ public class Pf_func_ {
case Xol_kwd_grp_.Id_lstx: return gplx.xowa.xtns.lst.Lst_pfunc_lstx.Instance;
case Xol_kwd_grp_.Id_invoke: return new gplx.xowa.xtns.scribunto.Scrib_invoke_func();
case Xol_kwd_grp_.Id_pagebanner: return new gplx.xowa.xtns.pagebanners.Pgbnr_func();
case Xol_kwd_grp_.Id_new_window_link: return new gplx.xowa.xtns.new_window_links.New_window_link_func();
case Xol_kwd_grp_.Id_property: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_property();
case Xol_kwd_grp_.Id_noexternallanglinks: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_noExternalLangLinks();

View File

@@ -27,11 +27,11 @@ class Pfunc_i18n_fxt {
public Xop_fxt Fxt() {return fxt;}
public Pfunc_i18n_fxt lang_(String v) {lang_key = v; return this;} private String lang_key;
public Pfunc_i18n_fxt Ini() {
if (app == null) app = Xoa_app_fxt.app_();
if (app == null) app = Xoa_app_fxt.Make__app__edit();
app.Lang_mgr().Clear(); // else lang values retained from last run
app.Free_mem(false); // else tmpl_result_cache will get reused from last run for {{test}}
lang = app.Lang_mgr().Get_by_or_new(Bry_.new_a7(lang_key));
wiki = Xoa_app_fxt.wiki_(app, lang_key + ".wikipedia.org", lang);
wiki = Xoa_app_fxt.Make__wiki__edit(app, lang_key + ".wikipedia.org", lang);
fxt = new Xop_fxt(app, wiki);
return this;
} private Xoae_app app; private Xop_fxt fxt; Xol_lang_itm lang; Xowe_wiki wiki;

View File

@@ -21,9 +21,9 @@ import gplx.core.intls.*; import gplx.xowa.langs.numbers.*;
public class Pf_formatnum_es_tst {
private Xop_fxt fxt;
@Before public void init() {
Xoae_app app = Xoa_app_fxt.app_();
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("es")).Init_by_load_assert();
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, "es.wikipedia.org", lang);
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "es.wikipedia.org", lang);
fxt = new Xop_fxt(app, wiki);
}
@Test public void Basic() {

View File

@@ -21,10 +21,10 @@ import gplx.core.intls.*; import gplx.xowa.langs.*; import gplx.xowa.langs.numbe
public class Pf_formatnum_fa_tst {
private Xop_fxt fxt;
@Before public void init() {
Xoae_app app = Xoa_app_fxt.app_();
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("fa")).Init_by_load_assert();
app.Gfs_mgr().Run_str_for(lang, Persian_numbers_gfs);
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, "fa.wikipedia.org", lang);
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "fa.wikipedia.org", lang);
fxt = new Xop_fxt(app, wiki);
}
@Test public void Basic() {

View File

@@ -31,7 +31,7 @@ public class Pfunc_tag extends Pf_func_base {
try {
int tag_idx = ++tag__next_id;
Xop_xnde_tag tag = (Xop_xnde_tag)ctx.Xnde_tag_regy().Get_trie(ctx.Xnde_names_tid()).Match_exact(tag_name, 0, tag_name.length);
boolean tag_is_ref = tag != null && tag.Id() == Xop_xnde_tag_.Tid_ref;
boolean tag_is_ref = tag != null && tag.Id() == Xop_xnde_tag_.Tid__ref;
if (tag_is_ref) // <ref>; add <xtag_bgn> to handle nested refs; PAGE:en.w:Battle_of_Midway; DATE:2014-06-27
tmp.Add(Xtag_bgn_lhs).Add_int_pad_bgn(Byte_ascii.Num_0, 10, tag_idx).Add(Xtag_rhs);
tmp.Add_byte(Byte_ascii.Lt).Add(tag_name);

View File

@@ -49,7 +49,6 @@ class Pft_fmt_itm_hebrew_ {
public static boolean Calc_hebrew_date(int[] rv, int year, int month, int day) { // REF.MW:Language.php|tsToHebrew
// Calculate Hebrew year
int hebrewYear = year + 3760;
// Month number when September = 1, August = 12
month += 4;
if (month > 12) {
@@ -58,7 +57,6 @@ class Pft_fmt_itm_hebrew_ {
year++;
hebrewYear++;
}
// Calculate day of year from 1 September
int dayOfYear = day;
for (int i = 1; i < month; i++) {
@@ -75,10 +73,8 @@ class Pft_fmt_itm_hebrew_ {
dayOfYear += 31;
}
}
// Calculate the start of the Hebrew year
int start = Calc_hebrew_year_num_start(hebrewYear);
// Calculate next year's start
int nextStart = 0;
if (dayOfYear <= start) {
@@ -100,10 +96,8 @@ class Pft_fmt_itm_hebrew_ {
// Next year's start
nextStart = Calc_hebrew_year_num_start(hebrewYear + 1);
}
// Calculate Hebrew day of year
int hebrewDayOfYear = dayOfYear - start;
// Difference between year's days
int diff = nextStart - start;
// Add 12 (or 13 for leap years) days to ignore the difference between
@@ -114,7 +108,6 @@ class Pft_fmt_itm_hebrew_ {
} else {
diff += 12;
}
// Check the year pattern, and is leap year
// 0 means an incomplete year, 1 means a regular year, 2 means a complete year
// This is mod 30, to work on both leap years (which add 30 days of Adar I)
@@ -122,14 +115,12 @@ class Pft_fmt_itm_hebrew_ {
int yearPattern = diff % 30;
// Check if leap year
boolean isLeap = diff >= 30;
// Calculate day in the month from number of day in the Hebrew year
// Don't check Adar - if the day is not in Adar, we will stop before;
// if it is in Adar, we will use it to check if it is Adar I or Adar II
int hebrewDay = hebrewDayOfYear;
int hebrewMonth = 1;
int days = 0;
while (hebrewMonth <= 12) {
// Calculate days in this month
if (isLeap && hebrewMonth == 6) {
@@ -205,7 +196,6 @@ class Pft_fmt_itm_hebrew_ {
, Rslt_day_num = 2
, Rslt_month_days_count = 3
;
private static final byte[][][] Numeral_tbls = new byte[][][]
{ new byte[][] {Bry_.Empty, Bry_.new_u8("א"), Bry_.new_u8("ב"), Bry_.new_u8("ג"), Bry_.new_u8("ד"), Bry_.new_u8("ה") , Bry_.new_u8("ו") , Bry_.new_u8("ז") , Bry_.new_u8("ח") , Bry_.new_u8("ט") , Bry_.new_u8("י")}
, new byte[][] {Bry_.Empty, Bry_.new_u8("י"), Bry_.new_u8("כ"), Bry_.new_u8("ל"), Bry_.new_u8("מ"), Bry_.new_u8("נ") , Bry_.new_u8("ס") , Bry_.new_u8("ע") , Bry_.new_u8("פ") , Bry_.new_u8("צ") , Bry_.new_u8("ק")}

View File

@@ -28,7 +28,6 @@ class Pft_fmt_itm_hijiri {
int hiji_d = greg_d;
int hiji_m = greg_m;
int hiji_y = greg_y;
int tmp_jd = 0;
if (
(hiji_y > 1582) || ((hiji_y == 1582) && (hiji_m > 10)) ||
@@ -43,7 +42,6 @@ class Pft_fmt_itm_hijiri {
tmp_jd = 367 * hiji_y - (int)((7 * (hiji_y + 5001 + (int)((hiji_m - 9) / 7))) / 4) +
(int)((275 * hiji_m) / 9) + hiji_d + 1729777;
}
int tmp_l = tmp_jd -1948440 + 10632;
int tmp_n = (int)((tmp_l - 1) / 10631);
tmp_l = tmp_l - 10631 * tmp_n + 354;
@@ -52,7 +50,6 @@ class Pft_fmt_itm_hijiri {
hiji_m = (int)((24 * tmp_l) / 709);
hiji_d = tmp_l - (int)((709 * hiji_m) / 24);
hiji_y = 30 * tmp_n + tmp_j - 30;
rv[0] = hiji_y;
rv[1] = hiji_m;
rv[2] = hiji_d;

View File

@@ -31,7 +31,7 @@ public class Pfunc_filepath_tst {
Xoae_app app = fxt.App();
en_wiki = fxt.Wiki();
// Init_orig_mgr(en_wiki);
commons_wiki = Xoa_app_fxt.wiki_(app, Xow_domain_itm_.Str__commons);
commons_wiki = Xoa_app_fxt.Make__wiki__edit(app, Xow_domain_itm_.Str__commons);
mock_wkr.Clear_commons(); // assume all files are in repo 0
en_wiki.File_mgr().Repo_mgr().Page_finder_(mock_wkr);
commons_wiki.Db_mgr().Load_mgr().Clear();

View File

@@ -21,7 +21,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Pfunc_rel2abs extends Pf_func_base {
@Override public boolean Func_require_colon_arg() {return true;}
private static final byte[] Ary_dot_slash = Bry_.new_a7("./"), Ary_dot_dot = Bry_.new_a7(".."), Ary_dot_dot_slash = Bry_.new_a7("../");
private static final byte[] Ary_dot_slash = Bry_.new_a7("./"), Ary_dot_dot = Bry_.new_a7(".."), Ary_dot_dot_slash = Bry_.new_a7("../");
private static void qry_bgns_with_init() {
qry_bgns_with = Btrie_fast_mgr.cs();
qry_bgns_with.Add(Byte_ascii.Slash, Int_obj_ref.new_(Id_slash));
@@ -33,7 +33,7 @@ public class Pfunc_rel2abs extends Pf_func_base {
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {// REF.MW:ParserFunctions_body.php
byte[] qry = Eval_argx(ctx, src, caller, self);
byte[] orig = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self.Args_len(), 0);
if (orig.length == 0) orig = ctx.Page().Ttl().Full_txt();
if (orig.length == 0) orig = ctx.Page().Ttl().Full_txt_w_ttl_case();
bfr.Add(Rel2abs(ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls(), qry, orig));
}
public static boolean Rel2abs_ttl(byte[] ttl, int bgn, int end) {
@@ -57,7 +57,7 @@ public class Pfunc_rel2abs extends Pf_func_base {
}
return rv;
}
private static final Int_obj_ref ignore_rel2abs_tid = Int_obj_ref.zero_();
private static final Int_obj_ref ignore_rel2abs_tid = Int_obj_ref.zero_();
public static byte[] Rel2abs(Bry_bfr tmp_bfr, byte[] qry, byte[] src) {return Rel2abs(tmp_bfr, qry, src, ignore_rel2abs_tid);}
public static byte[] Rel2abs(Bry_bfr tmp_bfr, byte[] qry, byte[] src, Int_obj_ref rel2abs_tid) {
if (qry_bgns_with == null) qry_bgns_with_init();
@@ -65,7 +65,6 @@ public class Pfunc_rel2abs extends Pf_func_base {
// qry_len = RTrim(qry, Byte_ascii.Slash, qry_bgn, qry_len); // not needed, but test anyway
if (qry_len == 0) return src;// no qry; return src; EX:{{#rel2abs:|a/b}} -> a/b
byte[] tmp = src;
int tmp_adj = 0, i = 0, prv_slash_end = 0, tmp_len = src_len, seg_pos = 0;
boolean tmp_is_1st = true;
@@ -182,4 +181,4 @@ B -> [A, B] add
C -> [A, C] add
. -> [A, C] noop
D -> [A, C, D] add
*/
*/

View File

@@ -38,7 +38,7 @@ public class Pfunc_rel2abs_tst {
@Test public void Err_owner() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:..}}" , "{{test}}" , "");} // PURPOSE.fix: should not fail
@Test public void Err_owner_2() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/../../b|a}}" , "{{test}}" , "");} // PURPOSE.fix: should not fail
@Test public void Ns_should_be_included_for_cur_page() {// PURPOSE.fix: current title was not returning ns; EX: de.wikipedia.org/wiki/Hilfe:Vorlagenprogrammierung#Funktion_rel2abs
fxt.Page_ttl_("Help:A"); // set page to title with namespace
fxt.Page_ttl_("Help:A"); // set page to title with Srch_rslt_cbk
fxt.Test_parse_tmpl_str_test("{{#rel2abs:.}}" , "{{test}}" , "Help:A");
}
@Test public void Owner_lvl0() {// PURPOSE.fix: old rel2abs was producing "/c"; EX: de.wikipedia.org/wiki/Hilfe:Vorlagenprogrammierung#Funktion_rel2abs

View File

@@ -27,8 +27,7 @@ public class Pfunc_titleparts extends Pf_func_base {
byte[] argx = Eval_argx(ctx, src, caller, self); if (argx == null) return; // no argx; return empty
Xoa_ttl argx_as_ttl = Xoa_ttl.new_(ctx.Wiki(), ctx.App().Msg_log_null(), argx, 0, argx.length); // transform to title in order to upper first, replace _, etc..
if (argx_as_ttl == null) {bfr.Add(argx); return;} // NOTE: argx_as_ttl will be null if invalid, such as [[a|b]]; PAGE:en.w:owl and {{taxobox/showtaxon|Dinosauria}}
else argx = argx_as_ttl.Full_txt();
else argx = argx_as_ttl.Full_txt_w_ttl_case();
// get parts_len
byte[] parts_len_ary = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 0);
int parts_len = parts_len_ary == Bry_.Empty ? Int_.Min_value : Bry_.To_int_or(parts_len_ary, Int_.Max_value);
@@ -37,7 +36,6 @@ public class Pfunc_titleparts extends Pf_func_base {
bfr.Add(argx);
return;
}
// get parts_bgn
byte[] parts_bgn_arg = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 1);
int parts_bgn = parts_bgn_arg == Bry_.Empty ? 0 : Bry_.To_int_or(parts_bgn_arg, Int_.Min_value);
@@ -55,12 +53,10 @@ public class Pfunc_titleparts extends Pf_func_base {
if (src[i] == Byte_ascii.Slash) dlms_ary[dlms_ary_len++] = i;
}
dlms_ary[dlms_ary_len] = src_len; // put src_len into last dlms_ary; makes dlms_ary[] logic easier
// calc bgn_idx; must occur before adjust parts_len
int bgn_idx = parts_bgn > -1 ? parts_bgn : parts_bgn + dlms_ary_len; // negative parts_bgn means calc from end of dlms_ary_len; EX a/b/c|1|-1 means start from 2
if ( bgn_idx < 0 // bgn_idx can be negative when parts_len is negative and greater than array; EX: {{#titleparts:a/b|-1|-2}} results in dlms_ary_len of 1 and parts_bgn of -2 which will be parts_bgn of -1
|| bgn_idx > dlms_ary_len) return Bry_.Empty; // if bgn > len, return ""; EX: {{#titleparts:a/b|1|3}} should return ""
// adjust parts_len for negative/null
if (parts_len == Int_.Min_value) parts_len = dlms_ary_len; // no parts_len; default to dlms_ary_len
else if (parts_len < 0) { // neg parts_len; shorten parts now and default to rest of String; EX: a/b/c|-1 -> makes String a/b/c and get 2 parts
@@ -69,7 +65,6 @@ public class Pfunc_titleparts extends Pf_func_base {
if (parts_len < 1) return Bry_.Empty; // NOTE: if zerod'd b/c of neg length, return empty; contrast with line below; EX: a/b/c|-4
}
if (parts_len == 0) return src; // if no dlms, return orig
// calc idxs for extraction
int bgn_pos = dlms_ary[bgn_idx] + 1; // +1 to start after slash
int end_idx = bgn_idx + parts_len;

View File

@@ -27,7 +27,7 @@ public class Pfunc_ttl extends Pf_func_base {
switch (id) {
case Xol_kwd_grp_.Id_ttl_page_txt: bfr.Add(ttl.Page_txt()); break;
case Xol_kwd_grp_.Id_ttl_page_url: bfr.Add(ttl.Page_url()); break;
case Xol_kwd_grp_.Id_ttl_full_txt: bfr.Add(ttl.Full_txt()); break;
case Xol_kwd_grp_.Id_ttl_full_txt: bfr.Add(ttl.Full_txt_w_ttl_case()); break;
case Xol_kwd_grp_.Id_ttl_full_url: bfr.Add(ttl.Full_url()); break;
case Xol_kwd_grp_.Id_ttl_leaf_txt: bfr.Add(ttl.Leaf_txt()); break;
case Xol_kwd_grp_.Id_ttl_leaf_url: bfr.Add(ttl.Leaf_url()); break;
@@ -49,5 +49,5 @@ public class Pfunc_ttl extends Pf_func_base {
public Pfunc_ttl(int id) {this.id = id;}
@Override public int Id() {return id;} private int id;
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_ttl(id).Name_(name);}
public static final Pfunc_ttl Instance = new Pfunc_ttl(-1);
public static final Pfunc_ttl Instance = new Pfunc_ttl(-1);
}

View File

@@ -39,9 +39,9 @@ class Pfunc_pagesincategory_tstr {
private final Xowd_page_tbl page_tbl; private final Xowd_cat_core_tbl cat_core_tbl;
public Pfunc_pagesincategory_tstr() {
Xoa_test_.Inet__init();
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
Xoa_test_.Db__init__mem(wiki);
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xoa_test_.Init__db__edit(wiki);
this.parser_tstr = new Xop_fxt(app, wiki);
this.core_data_mgr = wiki.Data__core_mgr();
this.page_tbl = core_data_mgr.Tbl__page();

View File

@@ -19,7 +19,7 @@ package gplx.xowa.xtns.pfuncs.wikis; import gplx.*; import gplx.xowa.*; import g
import org.junit.*; import gplx.xowa.langs.*;
public class Pfunc_wiki_props_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void setup() {fxt.Reset(); fxt.Wiki().Stats().NumPages_(1).NumArticles_(2).NumFiles_(3).NumEdits_(4).NumViews_(5).NumUsers_(6).NumUsersActive_(7).NumAdmins_(8);}
@Before public void setup() {fxt.Reset(); fxt.Wiki().Stats().Load_by_db(1, 2, 3, 4, 5, 6, 7, 8);}
@Test public void NumPages() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFPAGES}}" , "{{test}}", "1");}
@Test public void NumArticles() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFARTICLES}}" , "{{test}}", "2");}
@Test public void NumFiles() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFFILES}}" , "{{test}}", "3");}
@@ -35,5 +35,5 @@ public class Pfunc_wiki_props_tst {
fxt.Lang_by_id_(Xol_lang_stub_.Id_ru);
Init_numArticles(1234); fxt.Test_parse_tmpl_str_test("{{NUMBEROFARTICLES}}" , "{{test}}", "1234"); Init_numArticles(2);
}
private Pfunc_wiki_props_tst Init_numArticles(int v) {fxt.Wiki().Stats().NumArticles_(v); return this;}
private Pfunc_wiki_props_tst Init_numArticles(int v) {fxt.Wiki().Stats().Load_by_db(1, v, 3, 4, 5, 6, 7, 8); return this;}
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.pfuncs.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.wikis.metas.*;
import gplx.xowa.wikis.data.site_stats.*;
public class Pfunc_wiki_stats extends Pf_func_base {
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
byte[] argx = Eval_argx(ctx, src, caller, self);
@@ -27,23 +27,23 @@ public class Pfunc_wiki_stats extends Pf_func_base {
byte argx_0 = argx[0];
switch (argx_0) {case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_r: raw = true; break;}
}
Xow_wiki_stats stats = ctx.Wiki().Stats();
int v = 0;
Xow_site_stats_mgr stats = ctx.Wiki().Stats();
long v = 0;
switch (id) {
case Xol_kwd_grp_.Id_num_pages: v = stats.NumPages(); break;
case Xol_kwd_grp_.Id_num_articles: v = stats.NumArticles(); break;
case Xol_kwd_grp_.Id_num_files: v = stats.NumFiles(); break;
case Xol_kwd_grp_.Id_num_edits: v = stats.NumEdits(); break;
case Xol_kwd_grp_.Id_num_views: v = stats.NumViews(); break;
case Xol_kwd_grp_.Id_num_users: v = stats.NumUsers(); break;
case Xol_kwd_grp_.Id_num_users_active: v = stats.NumUsersActive(); break;
case Xol_kwd_grp_.Id_num_admins: v = stats.NumAdmins(); break;
case Xol_kwd_grp_.Id_num_pages: v = stats.Num_pages(); break;
case Xol_kwd_grp_.Id_num_articles: v = stats.Num_articles(); break;
case Xol_kwd_grp_.Id_num_files: v = stats.Num_files(); break;
case Xol_kwd_grp_.Id_num_edits: v = stats.Num_edits(); break;
case Xol_kwd_grp_.Id_num_views: v = stats.Num_views(); break;
case Xol_kwd_grp_.Id_num_users: v = stats.Num_users(); break;
case Xol_kwd_grp_.Id_num_users_active: v = stats.Num_active(); break;
case Xol_kwd_grp_.Id_num_admins: v = stats.Num_admins(); break;
default: throw Err_.new_unhandled(id);
}
if (raw)
bfr.Add_int_variable(v);
bfr.Add_long_variable(v);
else
bfr.Add(ctx.Page().Lang().Num_mgr().Format_num(v));
bfr.Add(ctx.Page().Lang().Num_mgr().Format_num_by_long(v));
}
public Pfunc_wiki_stats(int id) {this.id = id;}
@Override public int Id() {return id;} private int id;

View File

@@ -73,7 +73,7 @@ class Pp_index_parser {
}
case Xop_tkn_itm_.Tid_xnde: {
Xop_xnde_tkn xnde = (Xop_xnde_tkn)sub;
if (xnde.Tag().Id() == Xop_xnde_tag_.Tid_pagelist)
if (xnde.Tag().Id() == Xop_xnde_tag_.Tid__pagelist)
rv.Pagelist_xndes().Add(xnde);
break;
}

View File

@@ -41,8 +41,8 @@ class Sites_html_bldr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
private Sites_xtn_mgr xtn_mgr;
public void Clear() {
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xop_fxt.Init_msg(wiki, "relatedsites-title", "Related sites");
this.xtn_mgr = wiki.Xtn_mgr().Xtn_sites();
xtn_mgr.Enabled_y_();

View File

@@ -107,10 +107,15 @@ public class Scrib_core {
lib_uri.Notify_page_changed();
lib_title.Notify_page_changed();
lib_wikibase.Notify_page_changed();
expensive_function_count = 0;
}
public byte[] Cur_wiki() {return cur_wiki;} private byte[] cur_wiki = Bry_.Empty;
public byte[] Cur_lang() {return cur_lang;} private byte[] cur_lang = Bry_.Empty;
public Scrib_lua_mod RegisterInterface(Scrib_lib lib, Io_url url, KeyVal... args) {
public void Increment_expensive_function_count() {
++expensive_function_count;
if (expensive_function_count > 255) {}
} private int expensive_function_count;
public Scrib_lua_mod RegisterInterface(Scrib_lib lib, Io_url url, Keyval... args) {
this.RegisterLibrary(lib.Procs());
Scrib_lua_mod rv = this.LoadLibraryFromFile(url.NameAndExt(), Io_mgr.Instance.LoadFilStr(url));
Scrib_lua_proc setupInterface_func = rv.Fncs_get_by_key("setupInterface");
@@ -120,24 +125,24 @@ public class Scrib_core {
}
public void RegisterLibrary(Scrib_proc_mgr lib_proc_mgr) {
int len = lib_proc_mgr.Len();
KeyVal[] functions_ary = new KeyVal[len];
Keyval[] functions_ary = new Keyval[len];
for (int i = 0; i < len; i++) {
Scrib_proc lib_proc = lib_proc_mgr.Get_at(i);
String lib_proc_key = lib_proc.Proc_key();
this.proc_mgr.Set(lib_proc_key, lib_proc);
functions_ary[i] = KeyVal_.new_(lib_proc.Proc_name(), lib_proc_key);
functions_ary[i] = Keyval_.new_(lib_proc.Proc_name(), lib_proc_key);
}
engine.RegisterLibrary(functions_ary);
}
@gplx.Internal protected Scrib_lua_mod LoadLibraryFromFile(String name, String text) {
int lib_id = engine.LoadString("@" + name, text).Id(); // NOTE: 'Prepending an "@" to the chunk name makes Lua think it is a filename'
KeyVal[] values = engine.CallFunction(lib_id, KeyVal_.Ary_empty);
Keyval[] values = engine.CallFunction(lib_id, Keyval_.Ary_empty);
Scrib_lua_mod rv = new Scrib_lua_mod(this, name);
if (values.length > 0) { // NOTE: values.length == 0 for "package.lua" (no fnc_ids returned);
KeyVal[] fncs = Scrib_kv_utl_.Val_to_KeyVal_ary(values, 0);
Keyval[] fncs = Scrib_kv_utl_.Val_to_KeyVal_ary(values, 0);
int len = fncs.length;
for (int i = 0; i < len; i++) {
KeyVal itm = fncs[i];
Keyval itm = fncs[i];
Scrib_lua_proc fnc = Scrib_lua_proc.cast_or_null_(itm.Val());
if (fnc != null) rv.Fncs_add(fnc); // NOTE: some lua funcs will return INF; EX: stringLengthLimit
}
@@ -164,8 +169,8 @@ public class Scrib_core {
parent_frame.Frame_tid_(Scrib_frame_.Tid_parent); current_frame.Frame_tid_(Scrib_frame_.Tid_current);
try {
Scrib_lua_mod mod = Mods_get_or_new(mod_name, mod_text);
KeyVal[] func_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_u8(fnc_name));
KeyVal[] func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeModule"), func_args); // call init_chunk to get proc dynamically; DATE:2014-07-12
Keyval[] func_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_u8(fnc_name));
Keyval[] func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeModule"), func_args); // call init_chunk to get proc dynamically; DATE:2014-07-12
if (func_rslt == null || func_rslt.length < 2) throw Err_.new_wo_type("lua.error:function did not return a value", "fnc_name", String_.new_u8(fnc_name)); // must return at least 2 items for func_rslt[1] below; DATE:2014-09-22
Scrib_lua_proc proc = (Scrib_lua_proc)func_rslt[1].Val(); // note that init_chunk should have: [0]:true/false result; [1]:proc
func_args = Scrib_kv_utl_.base1_many_(proc);
@@ -176,7 +181,7 @@ public class Scrib_core {
// gplx.xowa.parsers.xndes.Xop_xnde_tkn.Hack_ctx = ctx;
// bfr.Add(rslt_bry);
if (!Env_.Mode_testing())
engine.CleanupChunks(KeyVal_.Ary(KeyVal_.int_(proc.Id(), ""))); // cleanup chunk immediately; needed for heavy pages like en.d:water; DATE:2014-08-07
engine.CleanupChunks(Keyval_.Ary(Keyval_.int_(proc.Id(), ""))); // cleanup chunk immediately; needed for heavy pages like en.d:water; DATE:2014-08-07
}
finally {
lib_mw.Invoke_end();

View File

@@ -26,8 +26,8 @@ public class Scrib_core_fxt {
}
public Scrib_core_fxt Clear() {
if (core == null) {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
core = Scrib_core.Core_new_(app, wiki.Parser_mgr().Ctx());
server = new Process_server_mock();
core.Interpreter().Server_(server);
@@ -41,9 +41,9 @@ public class Scrib_core_fxt {
} private Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public Scrib_core Core() {return core;} private Scrib_core core;
public Process_server_mock Server() {return server;} Process_server_mock server;
public KeyVal kv_(Object key, Object val) {return KeyVal_.obj_(key, val);}
public KeyVal[] kv_ary_(KeyVal... v) {return v;}
public KeyVal kv_func_(String key, int id) {return KeyVal_.new_(key, new Scrib_lua_proc(key, id));}
public Keyval kv_(Object key, Object val) {return Keyval_.obj_(key, val);}
public Keyval[] kv_ary_(Keyval... v) {return v;}
public Keyval kv_func_(String key, int id) {return Keyval_.new_(key, new Scrib_lua_proc(key, id));}
public Scrib_core_fxt Init_lib_fil(String name, String text) {
Io_url url = core.Fsys_mgr().Script_dir().GenSubFil(name);
Io_mgr.Instance.SaveFilStr(url, text);
@@ -70,10 +70,10 @@ public class Scrib_core_fxt {
Tfds.Eq(expd_id, actl_id);
return this;
}
public Scrib_core_fxt Test_CallFunction(int prc_id, Object[] args, KeyVal... expd) {
KeyVal[] actl = core.Interpreter().CallFunction(prc_id, Scrib_kv_utl_.base1_many_(args));
public Scrib_core_fxt Test_CallFunction(int prc_id, Object[] args, Keyval... expd) {
Keyval[] actl = core.Interpreter().CallFunction(prc_id, Scrib_kv_utl_.base1_many_(args));
Test_server_logs();
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
return this;
}
public Scrib_core_fxt Test_RegisterLibrary(String[] proc_names, String[] expd_keys) {
@@ -87,15 +87,15 @@ public class Scrib_core_fxt {
Tfds.Eq_ary_str(expd_keys, actl_keys);
return this;
}
public Scrib_core_fxt Test_LoadLibraryFromFile(String name, String text, KeyVal... expd) {
public Scrib_core_fxt Test_LoadLibraryFromFile(String name, String text, Keyval... expd) {
Scrib_lua_mod actl_lib = core.LoadLibraryFromFile(name, text);
int actl_len = actl_lib.Fncs_len();
KeyVal[] actl = new KeyVal[actl_len];
Keyval[] actl = new Keyval[actl_len];
for (int i = 0; i < actl_len; i++) {
Scrib_lua_proc itm = actl_lib.Fncs_get_at(i);
actl[i] = KeyVal_.new_(itm.Key(), itm.Id());
actl[i] = Keyval_.new_(itm.Key(), itm.Id());
}
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
return this;
}
public Scrib_core_fxt Test_Module_GetInitChunk(String name, String text, int expd_id) {
@@ -105,14 +105,14 @@ public class Scrib_core_fxt {
Tfds.Eq(expd_id, actl_id);
return this;
}
public Scrib_core_fxt Test_ExecuteModule(int mod_id, KeyVal... expd) {
KeyVal[] values = core.Interpreter().ExecuteModule(mod_id);
KeyVal[] actl = (KeyVal[])values[0].Val();
public Scrib_core_fxt Test_ExecuteModule(int mod_id, Keyval... expd) {
Keyval[] values = core.Interpreter().ExecuteModule(mod_id);
Keyval[] actl = (Keyval[])values[0].Val();
Test_server_logs();
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
return this;
}
public Scrib_core_fxt Test_GetExpandedArgument(KeyVal[] args, String arg, String expd) {// NOTE: test is rigidly defined; (a) always same 3 arguments in frame; (b) expd={"val_1", "val_2", "val_3", ""}
public Scrib_core_fxt Test_GetExpandedArgument(Keyval[] args, String arg, String expd) {// NOTE: test is rigidly defined; (a) always same 3 arguments in frame; (b) expd={"val_1", "val_2", "val_3", ""}
this.Expd_server_rcvd_add("0000003D00000079{[\"op\"]=\"call\",[\"id\"]=8,[\"nargs\"]=1,[\"args\"]={[1]=chunks[9]}}")
.Init_server_prep_add("a:4:{s:2:\"id\";s:32:\"mw_interface-getExpandedArgument\";s:2:\"op\";s:4:\"call\";s:5:\"nargs\";i:2;s:4:\"args\";a:2:{i:1;s:7:\"current\";i:2;s:" + String_.Len(arg) + ":\"" + arg + "\";}}");
if (String_.Eq(expd, ""))
@@ -125,13 +125,13 @@ public class Scrib_core_fxt {
Test_server_logs();
return this;
}
public Scrib_core_fxt Test_GetAllExpandedArguments(KeyVal... args) {
public Scrib_core_fxt Test_GetAllExpandedArguments(Keyval... args) {
core.Frame_current_(Xot_invk_mock.new_(Frame_ttl_test, args));
core.Interpreter().ExecuteModule(9);
Test_server_logs();
return this;
}
public Scrib_core_fxt Test_Invoke(String mod_name, String mod_code, String prc_name, KeyVal... args) {
public Scrib_core_fxt Test_Invoke(String mod_name, String mod_code, String prc_name, Keyval... args) {
core.Invoke(wiki, core.Ctx(), Bry_.Empty, Xot_invk_mock.Null, Xot_invk_mock.new_(Frame_ttl_test, args), tmp_bfr, Bry_.new_u8(mod_name), Bry_.new_u8(mod_code), Bry_.new_u8(prc_name));
Test_server_logs();
return this;

View File

@@ -47,4 +47,4 @@ class Scrib_err_filter_mgr_fxt {
public void Test_print(String expd) {
Tfds.Eq_str_lines(expd, err_mgr.Print());
}
}
}

View File

@@ -28,7 +28,7 @@ public class Scrib_frame_ {
public static Xot_invk Get_frame(Scrib_core core, String frame_id) {
if (String_.Eq(frame_id, "current")) return core.Frame_current();
else if (String_.Eq(frame_id, "parent")) return core.Frame_parent();
else if (String_.Eq(frame_id, "empty")) return Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, null, KeyVal_.Ary_empty); // not sure if it should return null title; DATE:2014-07-12
else if (String_.Eq(frame_id, "empty")) return Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, null, Keyval_.Ary_empty); // not sure if it should return null title; DATE:2014-07-12
else {
return (Xot_invk)core.Frame_created_list().Get_by(frame_id); // NOTE: can return null; some calls expect nil; EX:mw.lua and "currentFrame = newFrame( 'empty' )"; DATE:2014-07-12
}

View File

@@ -52,7 +52,7 @@ public class Scrib_invoke_func_fxt {
public Scrib_invoke_func_fxt Init_server_print_key_y_() {server.Print_key_(true); return this;}
public Scrib_invoke_func_fxt Init_server_print_key_n_() {server.Print_key_(false); return this;}
public Scrib_invoke_func_fxt Init_lua_rcvd_raw(String raw) {server.Prep_add(raw); return this;}
public Scrib_invoke_func_fxt Init_lua_rcvd(String cbk_name, KeyVal... ary) {
public Scrib_invoke_func_fxt Init_lua_rcvd(String cbk_name, Keyval... ary) {
server.Prep_add(rsp_bldr.Bld_mw_cbk(cbk_name, ary));
return this;
}
@@ -69,8 +69,8 @@ public class Scrib_invoke_func_fxt {
this.Init_lua_rcvd_rv();
return this;
}
public Scrib_invoke_func_fxt Init_lua_rcvd_expandTemplate(String frame, String tmpl_ttl, KeyVal... ary) {
ary = new KeyVal[] {KeyVal_.int_(1, "current"), KeyVal_.int_(2, tmpl_ttl), KeyVal_.int_(3, ary)};
public Scrib_invoke_func_fxt Init_lua_rcvd_expandTemplate(String frame, String tmpl_ttl, Keyval... ary) {
ary = new Keyval[] {Keyval_.int_(1, "current"), Keyval_.int_(2, tmpl_ttl), Keyval_.int_(3, ary)};
server.Prep_add(rsp_bldr.Bld_mw_cbk("expandTemplate", ary));
this.Init_lua_rcvd_rv();
return this;
@@ -92,11 +92,11 @@ public class Scrib_invoke_func_fxt {
Tfds.Eq_str(expd, tmp_bfr.To_str_and_clear(), "error");
}
public void Test_lib_proc(Scrib_lib lib, String func_name, Object[] args, String expd) {Test_lib_proc_kv(lib, func_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_lib_proc_kv(Scrib_lib lib, String func_name, KeyVal[] args, String expd) {
public void Test_lib_proc_kv(Scrib_lib lib, String func_name, Keyval[] args, String expd) {
Test_lib_proc_internal(lib, func_name, args);
this.Test_invoke(expd);
}
private void Test_lib_proc_internal(Scrib_lib lib, String func_name, KeyVal[] args) {
private void Test_lib_proc_internal(Scrib_lib lib, String func_name, Keyval[] args) {
Init_lua_module();
this.Init_cbk(Scrib_core.Key_mw_interface, lib, func_name);
this.Init_lua_rcvd(func_name, args);
@@ -105,16 +105,16 @@ public class Scrib_invoke_func_fxt {
public void Test_log_rcvd(int i, String expd) {
Tfds.Eq(expd, (String)server.Log_rcvd().Get_at(i));
}
public void Init_frame_parent(String ttl, KeyVal... ary) {
public void Init_frame_parent(String ttl, Keyval... ary) {
core.Frame_parent_(Xot_invk_mock.test_(Bry_.new_u8(ttl), ary));
}
public void Init_frame_current(KeyVal... ary) {
public void Init_frame_current(Keyval... ary) {
core.Frame_current_(Xot_invk_mock.test_(Bry_.new_a7("Module:Mod_0"), ary));
}
public void Clear_for_lib() {Clear_for_lib("en.wikipedia.org", "en");}
public void Clear_for_lib(String domain, String lang) {
Xoae_app app = Xoa_app_fxt.app_();
fxt = new Xop_fxt(app, Xoa_app_fxt.wiki_(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)))); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib
Xoae_app app = Xoa_app_fxt.Make__app__edit();
fxt = new Xop_fxt(app, Xoa_app_fxt.Make__wiki__edit(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)))); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib
core_fxt = new Scrib_core_fxt(fxt);
core = core_fxt.Core();
Xot_invk parent_frame = new Xot_invk_temp(true); parent_frame.Frame_tid_(Scrib_frame_.Tid_null);
@@ -123,35 +123,35 @@ public class Scrib_invoke_func_fxt {
core.When_page_changed(fxt.Page());
}
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_str(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(Object_.Xto_str_strict_or_null_mark(expd), Object_.Xto_str_strict_or_null_mark(actl[0].Val()));
}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps__flat(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
KeyVal[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {
Keyval[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(expd, Kv_ary_to_kv_vals_str(actl_ary));
}
public void Test_scrib_proc_kv_objs(Scrib_lib lib, String proc_name, KeyVal[] args, Object... expd_ary) {
KeyVal[] actl_kvs = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_kv_objs(Scrib_lib lib, String proc_name, Keyval[] args, Object... expd_ary) {
Keyval[] actl_kvs = Test__lib_proc__core(lib, proc_name, args);
Object[] actl_ary = KeyVal_to_obj_ary(actl_kvs);
Tfds.Eq_ary(expd_ary, actl_ary);
}
private static Object[] KeyVal_to_obj_ary(KeyVal[] kv_ary) {
private static Object[] KeyVal_to_obj_ary(Keyval[] kv_ary) {
int len = kv_ary.length;
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i) {
KeyVal kv = kv_ary[i];
Keyval kv = kv_ary[i];
rv[i] = kv.Val();
}
return rv;
}
private String Kv_ary_to_kv_vals_str(KeyVal[] ary) {
private String Kv_ary_to_kv_vals_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
KeyVal kv = ary[i];
Keyval kv = ary[i];
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(kv.Val()));
}
return bfr.To_str_and_clear();
@@ -159,30 +159,30 @@ public class Scrib_invoke_func_fxt {
public void Test_scrib_proc_bool(Scrib_lib lib, String proc_name, Object[] args, boolean expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_int(Scrib_lib lib, String proc_name, Object[] args, int expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, Object[] args, Object expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, KeyVal[] args, Object expd) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, Keyval[] args, Object expd) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(expd, actl[0].Val());
}
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, Object[] args) {Test_scrib_proc_empty(lib, proc_name, Scrib_kv_utl_.base1_many_(args));}
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, KeyVal[] args) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, args);
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, Keyval[] args) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, args);
Tfds.Eq(0, actl.length);
}
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_str_ary(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
KeyVal[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
String actl = KeyVal_.Ary__to_str__nest(actl_ary);
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {
Keyval[] actl_ary = Test__lib_proc__core(lib, proc_name, args);
String actl = Keyval_.Ary__to_str__nest(actl_ary);
Tfds.Eq_str_lines(expd, actl);
}
public KeyVal[] Test_scrib_proc_rv_as_kv_ary(Scrib_lib lib, String proc_name, Object[] args) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return (KeyVal[])actl[0].Val();
public Keyval[] Test_scrib_proc_rv_as_kv_ary(Scrib_lib lib, String proc_name, Object[] args) {
Keyval[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return (Keyval[])actl[0].Val();
}
public Object Test_scrib_proc_rv_as_obj(Scrib_lib lib, String proc_name, Object[] args) {
KeyVal[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
Keyval[] actl = Test__lib_proc__core(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
return actl[0].Val();
}
private KeyVal[] Test__lib_proc__core(Scrib_lib lib, String proc_name, KeyVal[] args) {
private Keyval[] Test__lib_proc__core(Scrib_lib lib, String proc_name, Keyval[] args) {
Scrib_proc proc = lib.Procs().Get_by_key(proc_name);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(new Scrib_proc_args(args), proc_rslt);
@@ -193,7 +193,7 @@ public class Scrib_invoke_func_fxt {
}
class Scrib_lua_rsp_bldr {
Bry_bfr bfr = Bry_bfr.reset_(255);
public String Bld_mw_cbk(String cbk_name, KeyVal... ary) {
public String Bld_mw_cbk(String cbk_name, Keyval... ary) {
cbk_name = "mw_interface-" + cbk_name;
bfr.Add_str_a7("a:4:{s:2:\"id\";");
Bld_str(bfr, cbk_name);
@@ -208,7 +208,7 @@ class Scrib_lua_rsp_bldr {
else if (Object_.Eq(v_type, String_.Cls_ref_type)) Bld_str(bfr, String_.cast(v));
else if (Object_.Eq(v_type, Bool_.Cls_ref_type)) Bld_bool(bfr, Bool_.cast(v));
else if (Object_.Eq(v_type, Double_.Cls_ref_type)) Bld_double(bfr, Double_.cast(v));
else if (Object_.Eq(v_type, KeyVal[].class)) Bld_kv_ary(bfr, (KeyVal[])v);
else if (Object_.Eq(v_type, Keyval[].class)) Bld_kv_ary(bfr, (Keyval[])v);
else if (Object_.Eq(v_type, Scrib_lua_proc.class)) Bld_fnc(bfr, (Scrib_lua_proc)v);
else throw Err_.new_unhandled(Type_adp_.NameOf_obj(v));
}
@@ -217,11 +217,11 @@ class Scrib_lua_rsp_bldr {
private void Bld_double(Bry_bfr bfr, double v) {bfr.Add_str_a7("d:").Add_double(v).Add_byte(Byte_ascii.Semic);}
private void Bld_str(Bry_bfr bfr, String v) {bfr.Add_str_a7("s:").Add_int_variable(Bry_.new_u8(v).length).Add_str_a7(":\"").Add_str_a7(v).Add_str_a7("\";");} // NOTE: must use Bry_.new_u8(v).length to calculate full bry len
private void Bld_fnc(Bry_bfr bfr, Scrib_lua_proc v) {bfr.Add_str_a7("O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:").Add_int_variable(v.Id()).Add_byte(Byte_ascii.Semic).Add_byte(Byte_ascii.Curly_end);}
private void Bld_kv_ary(Bry_bfr bfr, KeyVal[] ary) {
private void Bld_kv_ary(Bry_bfr bfr, Keyval[] ary) {
int len = ary.length;
bfr.Add_str_a7("a:").Add_int_variable(len).Add_str_a7(":{");
for (int i = 0; i < len; i++) {
KeyVal kv = ary[i];
Keyval kv = ary[i];
Bld_obj(bfr, kv.Key_as_obj());
Bld_obj(bfr, kv.Val());
}

View File

@@ -17,48 +17,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Scrib_kv_utl_ {
public static KeyVal[] base1_obj_(Object v) {return new KeyVal[] {KeyVal_.int_(0 + Scrib_core.Base_1, v)};}
public static KeyVal[] base1_many_(Object... vals) {
public static Keyval[] base1_obj_(Object v) {return new Keyval[] {Keyval_.int_(0 + Scrib_core.Base_1, v)};}
public static Keyval[] base1_many_(Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++)
rv[i] = KeyVal_.int_(i + Scrib_core.Base_1, vals[i]);
rv[i] = Keyval_.int_(i + Scrib_core.Base_1, vals[i]);
return rv;
}
public static KeyVal[] base1_many_ary_(Object... vals) {
public static Keyval[] base1_many_ary_(Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++)
rv[i] = KeyVal_.int_(i + Scrib_core.Base_1, vals[i]);
rv[i] = Keyval_.int_(i + Scrib_core.Base_1, vals[i]);
return rv;
}
public static KeyVal[] base1_list_(List_adp list) {
public static Keyval[] base1_list_(List_adp list) {
int len = list.Count();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++)
rv[i] = KeyVal_.int_(i + Scrib_core.Base_1, list.Get_at(i));
rv[i] = Keyval_.int_(i + Scrib_core.Base_1, list.Get_at(i));
list.Clear();
return rv;
}
public static KeyVal[] flat_many_(Object... vals) {
public static Keyval[] flat_many_(Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len / 2];
Keyval[] rv = new Keyval[len / 2];
for (int i = 0; i < len; i += 2)
rv[i / 2] = KeyVal_.obj_(vals[i], vals[i + 1]);
rv[i / 2] = Keyval_.obj_(vals[i], vals[i + 1]);
return rv;
}
public static String Val_to_str(KeyVal[] ary, int idx) {
public static String Val_to_str(Keyval[] ary, int idx) {
if (ary == null) throw Err_.new_wo_type("ary is null");
int ary_len = ary.length;
if (ary_len == 0 && idx == 0) return ""; // NOTE: Modules can throw exceptions in which return value is nothing; do not fail; return ""; EX: -logy; DATE:2013-10-14
if (idx >= ary_len) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_to_str(ary));
if (idx >= ary_len) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", Keyval_.Ary_to_str(ary));
Object o = ary[idx].Val();
try {return (String)o;}
catch (Exception e) {throw Err_.new_cast(e, String.class, o);}
}
public static KeyVal[] Val_to_KeyVal_ary(KeyVal[] ary, int idx) {
if (ary == null) throw Err_.new_wo_type("ary is null"); if (idx >= ary.length) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_to_str(ary));
try {return (KeyVal[])ary[idx].Val();}
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as KeyVal[] failed", "ary", KeyVal_.Ary_to_str(ary));}
public static Keyval[] Val_to_KeyVal_ary(Keyval[] ary, int idx) {
if (ary == null) throw Err_.new_wo_type("ary is null"); if (idx >= ary.length) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", Keyval_.Ary_to_str(ary));
try {return (Keyval[])ary[idx].Val();}
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as Keyval[] failed", "ary", Keyval_.Ary_to_str(ary));}
}
}

View File

@@ -43,12 +43,12 @@ public class Scrib_lua_mod {
public void Execute() {
hash.Clear(); // NOTE: questionable. should probably be removed, as it forces all modules to be "loadString"'d again; DATE:2013-10-16
this.LoadString(name); // assert lua_id;
KeyVal[] rslt = core.Interpreter().ExecuteModule(lua_id);
Keyval[] rslt = core.Interpreter().ExecuteModule(lua_id);
if (rslt.length == 0) throw Err_.new_wo_type("module missing", "name", name, "lua_id", lua_id);
KeyVal[] prcs_ary = (KeyVal[])rslt[0].Val();
Keyval[] prcs_ary = (Keyval[])rslt[0].Val();
int prcs_len = prcs_ary.length;
for (int i = 0; i < prcs_len; i++) {
KeyVal prc_kv = prcs_ary[i];
Keyval prc_kv = prcs_ary[i];
String prc_key = prc_kv.Key();
Object prc_val = prc_kv.Val();
Scrib_lua_proc fnc = null;

View File

@@ -17,14 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Scrib_proc_args {
private KeyVal[] ary; private int ary_len;
public Scrib_proc_args(KeyVal[] v) {Init(v);}
private Keyval[] ary; private int ary_len;
public Scrib_proc_args(Keyval[] v) {Init(v);}
public int Len() {return ary_len;}
public KeyVal[] Ary() {return ary;}
public Keyval[] Ary() {return ary;}
public boolean Pull_bool(int i) {return Bool_.cast(Get_or_fail(i));}
public String Pull_str(int i) {return String_.cast(Get_or_fail(i));}
public byte[] Pull_bry(int i) {return Bry_.new_u8(String_.cast(Get_or_fail(i)));}
public KeyVal[] Pull_kv_ary(int i) {return (KeyVal[])Get_or_fail(i);}
public Keyval[] Pull_kv_ary(int i) {return (Keyval[])Get_or_fail(i);}
public int Pull_int(int i) {Object rv = Get_or_fail(i);
try {return Int_.coerce_(rv);} // coerce to handle "1" and 1; will still fail if "abc" is passed
catch (Exception e) {
@@ -45,6 +45,7 @@ public class Scrib_proc_args {
}
}
public Object Pull_obj(int i) {return Get_or_fail(i);}
public String Cast_str_or(int i, String or) {Object rv = Get_or_null(i); return rv == null ? or : String_.cast (rv);}
public String Cast_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : String_.cast (rv);}
public byte[] Cast_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(String_.cast (rv));} // NOTE: cast is deliberate; Scrib call checkType whi
public byte[] Cast_bry_or_empty(int i) {Object rv = Get_or_null(i); return rv == null ? Bry_.Empty : Bry_.new_u8(String_.cast (rv));}
@@ -55,16 +56,16 @@ public class Scrib_proc_args {
public int Cast_int_or(int i, int or) {Object rv = Get_or_null(i); return rv == null ? or : Int_.coerce_(rv);} // coerce to handle "1" and 1;
public String Xstr_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Object_.Xto_str_loose_or(rv, null);} // NOTE: Modules can throw exceptions in which return value is nothing; do not fail; return ""; EX: -logy; DATE:2013-10-14
public byte[] Xstr_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(Object_.Xto_str_loose_or(rv, null));}
public KeyVal[] Cast_kv_ary_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : (KeyVal[])rv;}
public Keyval[] Cast_kv_ary_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : (Keyval[])rv;}
public byte[][] Cast_params_as_bry_ary_or_rest_of_ary(int params_idx) { // PAGE:ru.w:Ленин,_Владимир_Ильич; DATE:2014-07-01 MW:LanguageLibrary.php|ConvertPlural: if (is_array($args[0])) $args = $args[0]; $forms = array_values(array_map('strval', $args));
if (params_idx < 0 || params_idx >= ary_len) return Bry_.Ary_empty;
Object o = ary[params_idx].Val();
if (Type_adp_.Eq_typeSafe(o, KeyVal[].class)) {
KeyVal[] tbl = (KeyVal[])o;
if (Type_adp_.Eq_typeSafe(o, Keyval[].class)) {
Keyval[] tbl = (Keyval[])o;
int rv_len = tbl.length;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; i++) {
KeyVal itm = tbl[i];
Keyval itm = tbl[i];
rv[i] = Bry_.new_u8(String_.cast(itm.Val()));
}
return rv;
@@ -73,7 +74,7 @@ public class Scrib_proc_args {
int rv_len = ary_len - params_idx;
byte[][] rv = new byte[rv_len][];
for (int i = 0; i < rv_len; i++) {
KeyVal itm = ary[i + params_idx];
Keyval itm = ary[i + params_idx];
rv[i] = Bry_.new_u8(String_.cast(itm.Val()));
}
return rv;
@@ -85,12 +86,12 @@ public class Scrib_proc_args {
Class<?> qry_args_cls = Type_adp_.ClassOf_obj(qry_args_obj);
if (qry_args_cls == String.class)
return Bry_.new_u8((String)qry_args_obj);
else if (qry_args_cls == KeyVal[].class) {
else if (qry_args_cls == Keyval[].class) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
KeyVal[] kvs = (KeyVal[])qry_args_obj;
Keyval[] kvs = (Keyval[])qry_args_obj;
int len = kvs.length;
for (int i = 0; i < len; i++) {
KeyVal kv = kvs[i];
Keyval kv = kvs[i];
if (i != 0) bfr.Add_byte(Byte_ascii.Amp);
bfr.Add_str_u8(kv.Key());
bfr.Add_byte(Byte_ascii.Eq);
@@ -103,16 +104,16 @@ public class Scrib_proc_args {
return Bry_.Empty;
}
}
private void Init(KeyVal[] v) {
private void Init(Keyval[] v) {
int v_len = v.length;
if (v_len == 0) {
ary = KeyVal_.Ary_empty;
ary = Keyval_.Ary_empty;
ary_len = 0;
return;
}
int v_max = -1;
for (int i = 0; i < v_len; i++) {
KeyVal kv = v[i];
Keyval kv = v[i];
int idx = Int_.cast(kv.Key_as_obj());
if (v_max < idx) v_max = idx;
}
@@ -121,9 +122,9 @@ public class Scrib_proc_args {
this.ary = v;
}
else { // keys are not in sequential order, or there are gaps; EX: [1:a,3:c]
ary = new KeyVal[ary_len];
ary = new Keyval[ary_len];
for (int i = 0; i < v_len; i++) {
KeyVal kv = v[i];
Keyval kv = v[i];
int idx = Int_.cast(kv.Key_as_obj());
ary[idx - List_adp_.Base1] = kv;
}
@@ -131,12 +132,12 @@ public class Scrib_proc_args {
}
private Object Get_or_null(int i) {
if (i < 0 || i >= ary_len) return null;
KeyVal kv = ary[i];
Keyval kv = ary[i];
return kv == null ? null : kv.Val();
}
private Object Get_or_fail(int i) {
if (i < 0 || i >= ary_len) throw Err_.new_wo_type("bad argument: nil", "idx", i, "len", ary_len);
KeyVal kv = ary[i];
Keyval kv = ary[i];
Object rv = kv == null ? null : kv.Val();
if (rv == null) throw Err_.new_wo_type("scrib arg is null", "idx", i, "len", ary_len);
return rv;

View File

@@ -17,46 +17,46 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Scrib_proc_rslt {
private KeyVal[] ary;
public KeyVal[] Ary() {return ary;}
private Keyval[] ary;
public Keyval[] Ary() {return ary;}
public String Fail_msg() {return fail_msg;} private String fail_msg;
public boolean Init_fail(String v) {fail_msg = v; return false;}
public boolean Init_null() {Init_obj(null); return true;} // return array(null);
public boolean Init_str_empty() {Init_obj(""); return true;}
public boolean Init_ary_empty() {ary = KeyVal_.Ary_empty; return true;}
public boolean Init_ary_empty() {ary = Keyval_.Ary_empty; return true;}
public boolean Init_obj(Object val) {
ary = new KeyVal[] {KeyVal_.int_(Scrib_core.Base_1, val)};
ary = new Keyval[] {Keyval_.int_(Scrib_core.Base_1, val)};
return true;
}
public boolean Init_many_objs(Object... vals) {
int len = vals.length;
ary = new KeyVal[len];
ary = new Keyval[len];
for (int i = 0; i < len; i++)
ary[i] = KeyVal_.int_(i + Scrib_core.Base_1, vals[i]);
ary[i] = Keyval_.int_(i + Scrib_core.Base_1, vals[i]);
return true;
}
public boolean Init_many_kvs(KeyVal... kvs) {
public boolean Init_many_kvs(Keyval... kvs) {
ary = kvs;
return true;
}
public boolean Init_many_list(List_adp list) {
int len = list.Count();
ary = new KeyVal[len];
ary = new Keyval[len];
for (int i = 0; i < len; i++)
ary[i] = KeyVal_.int_(i + Scrib_core.Base_1, list.Get_at(i));
ary[i] = Keyval_.int_(i + Scrib_core.Base_1, list.Get_at(i));
list.Clear();
return true;
}
public boolean Init_many_empty() {
ary = KeyVal_.Ary_empty;
ary = Keyval_.Ary_empty;
return true;
}
public boolean Init_bry_ary(byte[][] v) { // NOTE:fallbacks should return "table {fallback_1, fallback_2}"; PAGE:wd:Main_Page DATE:2015-04-21
int len = v.length;
KeyVal[] itms = new KeyVal[len];
Keyval[] itms = new Keyval[len];
for (int i = 0; i < len; i++)
itms[i] = KeyVal_.int_(i + Scrib_core.Base_1, String_.new_u8(v[i]));
this.ary = new KeyVal[] {KeyVal_.int_(Scrib_core.Base_1, itms)};
itms[i] = Keyval_.int_(i + Scrib_core.Base_1, String_.new_u8(v[i]));
this.ary = new Keyval[] {Keyval_.int_(Scrib_core.Base_1, itms)};
return true;
}
}

View File

@@ -20,8 +20,8 @@ public interface Scrib_engine {
boolean Dbg_print(); void Dbg_print_(boolean v);
Scrib_server Server(); void Server_(Scrib_server v);
Scrib_lua_proc LoadString(String name, String text);
KeyVal[] CallFunction(int id, KeyVal[] args);
void RegisterLibrary(KeyVal[] functions_ary);
KeyVal[] ExecuteModule(int mod_id);
void CleanupChunks(KeyVal[] ids);
Keyval[] CallFunction(int id, Keyval[] args);
void RegisterLibrary(Keyval[] functions_ary);
Keyval[] ExecuteModule(int mod_id);
void CleanupChunks(Keyval[] ids);
}

View File

@@ -30,5 +30,5 @@ public class Scrib_engine_type {
else throw Err_.new_unimplemented();
}
public static final byte Type_lua = 0, Type_luaj = 1;
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_("luaj"), KeyVal_.new_("lua"));
public static Keyval[] Options__list = Keyval_.Ary(Keyval_.new_("luaj"), Keyval_.new_("lua"));
}

View File

@@ -26,8 +26,8 @@ public class Luaj_engine implements Scrib_engine {
this.core = core;
server = new Luaj_server(core, debug_enabled);
proc_mgr = core.Proc_mgr();
Luaj_server_func_recv._.Engine_(this);
Luaj_server_func_dbg._.Core_(core);
Luaj_server_func_recv.Instance.Engine_(this);
Luaj_server_func_dbg.Instance.Core_(core);
}
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {server = (Luaj_server)v;}
public boolean Dbg_print() {return dbg_print;} public void Dbg_print_(boolean v) {dbg_print = v;} private boolean dbg_print;
@@ -41,14 +41,14 @@ public class Luaj_engine implements Scrib_engine {
LuaInteger proc_id = (LuaInteger)values_tbl.rawget(1);
return new Scrib_lua_proc(name, proc_id.v);
}
public void RegisterLibrary(KeyVal[] functions) {
public void RegisterLibrary(Keyval[] functions) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_registerLibrary);
msg.set("name", "mw_interface");
msg.set("functions", Luaj_value_.X_obj_to_val(server, functions));
server.Dispatch(msg);
}
public KeyVal[] CallFunction(int id, KeyVal[] args) {
public Keyval[] CallFunction(int id, Keyval[] args) {
int args_len = args.length;
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_callFunction);
@@ -57,16 +57,16 @@ public class Luaj_engine implements Scrib_engine {
msg.set("args", Luaj_value_.X_obj_to_val(server, args));
return this.Dispatch_as_kv_ary(msg);
}
public KeyVal[] ExecuteModule(int mod_id) {
public Keyval[] ExecuteModule(int mod_id) {
return this.CallFunction(core.Lib_mw().Mod().Fncs_get_id("executeModule"), Scrib_kv_utl_.base1_obj_(new Scrib_lua_proc("", mod_id)));
}
public void CleanupChunks(KeyVal[] ids) {
public void CleanupChunks(Keyval[] ids) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", "cleanupChunks");
msg.set("ids", Luaj_value_.X_obj_to_val(server, ids));
this.Dispatch_as_kv_ary(msg);
}
public KeyVal[] Dispatch_as_kv_ary(LuaTable msg) {
public Keyval[] Dispatch_as_kv_ary(LuaTable msg) {
while (true) {
LuaTable rsp = server.Dispatch(msg);
String op = Luaj_value_.Get_val_as_str(rsp, "op");
@@ -77,29 +77,29 @@ public class Luaj_engine implements Scrib_engine {
else if (String_.Eq(op, "error")) {
String err = Luaj_value_.Get_val_as_str(rsp, "value");
core.Handle_error(err, "");
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
else
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
}
public LuaTable Server_recv_call(LuaTable rsp) {
String proc_id = Luaj_value_.Get_val_as_str(rsp, "id");
KeyVal[] args = Luaj_value_.Get_val_as_kv_ary(server, rsp, "args");
Keyval[] args = Luaj_value_.Get_val_as_kv_ary(server, rsp, "args");
Scrib_proc proc = proc_mgr.Get_by_key(proc_id); if (proc == null) throw Scrib_xtn_mgr.err_("could not find proc with id of {0}", proc_id);
Scrib_proc_args proc_args = new Scrib_proc_args(args);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(proc_args, proc_rslt);
String fail_msg = proc_rslt.Fail_msg();
if (fail_msg == null) {
KeyVal[] cbk_rslts = proc_rslt.Ary();
Keyval[] cbk_rslts = proc_rslt.Ary();
return ReturnMessage(cbk_rslts);
}
else {
return ReturnFail(fail_msg);
}
}
private LuaTable ReturnMessage(KeyVal[] values) {
private LuaTable ReturnMessage(Keyval[] values) {
LuaTable msg = LuaValue.tableOf();
msg.set("op", Val_returnMessage);
msg.set("nvalues", LuaValue.valueOf(values.length));

View File

@@ -21,14 +21,13 @@ import org.luaj.vm2.*; import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.jse.*;
import gplx.xowa.xtns.scribunto.engines.process.*;
public class Luaj_server implements Scrib_server {
private LuaTable server;
public Luaj_server(Scrib_core core, boolean debug_enabled) {
}
public Luaj_server(Scrib_core core, boolean debug_enabled) {}
public static Globals Globals_singleton;
public void Init(String... init_args) {
Globals_singleton = JsePlatform.standardGlobals();
Globals_singleton.load(new DebugLib());
Globals_singleton.load(new MWClient());
Globals_singleton.set("dbg", Luaj_server_func_dbg._);
Globals_singleton.set("dbg", Luaj_server_func_dbg.Instance);
String root_str = init_args[2];
if (Op_sys.Cur().Tid_is_wnt())
root_str = String_.Replace(root_str, Op_sys.Wnt.Fsys_dir_spr_str(), Op_sys.Lnx.Fsys_dir_spr_str());
@@ -75,7 +74,7 @@ public class Luaj_server implements Scrib_server {
*/
public LuaValue call(LuaValue libname) {
LuaValue library = tableOf();
library.set("client_recv", Luaj_server_func_recv._);
library.set("client_recv", Luaj_server_func_recv.Instance);
LuaValue env = gplx.xowa.xtns.scribunto.engines.luaj.Luaj_server.Globals_singleton;
env.set( "MWClient", library );
return library;

View File

@@ -36,5 +36,5 @@ public class Luaj_server_func_dbg extends VarArgFunction {
core.Page().Html_data().Xtn_scribunto_dbg_(bfr.To_bry_and_clear());
return NONE;
}
public static Luaj_server_func_dbg _ = new Luaj_server_func_dbg();
public static Luaj_server_func_dbg Instance = new Luaj_server_func_dbg();
}

View File

@@ -28,5 +28,5 @@ public class Luaj_server_func_recv extends OneArgFunction {
if (!String_.Eq(op, "call")) throw Err_.new_wo_type("luaj_recvr only processes op calls");
return engine.Server_recv_call(tbl);
}
public static Luaj_server_func_recv _ = new Luaj_server_func_recv();
public static Luaj_server_func_recv Instance = new Luaj_server_func_recv();
}

View File

@@ -24,11 +24,11 @@ class Luaj_value_ {
public static LuaTable Get_val_as_lua_table(LuaTable owner, String key) {
return (LuaTable)owner.get(key);
}
public static KeyVal[] Get_val_as_kv_ary(Luaj_server server, LuaTable owner, String key) {
public static Keyval[] Get_val_as_kv_ary(Luaj_server server, LuaTable owner, String key) {
LuaTable table = (LuaTable)owner.get(key);
return Luaj_value_.X_tbl_to_kv_ary(server, table);
}
public static KeyVal[] X_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
public static Keyval[] X_tbl_to_kv_ary(Luaj_server server, LuaTable tbl) {
List_adp temp = List_adp_.new_();
LuaValue cur = LuaValue.NIL;
int len = 0;
@@ -38,23 +38,23 @@ class Luaj_value_ {
LuaValue itm_val = itm.arg(2); // val is itm 2
Object itm_val_obj = X_val_to_obj(server, itm_val);
LuaValue itm_key = itm.arg(1);
KeyVal kv = null;
Keyval kv = null;
if (itm_val.type() == LuaValue.TFUNCTION) { // function is converted to Scrib_lua_proc
String func_key = itm_key.tojstring();
int func_id = Int_.cast(itm_val_obj);
Scrib_lua_proc lua_func = new Scrib_lua_proc(func_key, func_id);
if (itm_key.type() == LuaValue.TSTRING) // most functions are named
kv = KeyVal_.new_(func_key, lua_func);
kv = Keyval_.new_(func_key, lua_func);
else // some are not; particularly "anonymous" functions in Module for gsub_function; these will have a kv of int,int; note that key must be int; if string, lua will not be able to match it back to int later
kv = KeyVal_.int_(((LuaInteger)itm_key).v, lua_func);
kv = Keyval_.int_(((LuaInteger)itm_key).v, lua_func);
}
else {
switch (itm_key.type()) {
case LuaValue.TNUMBER:
kv = KeyVal_.int_(((LuaNumber)itm_key).toint(), itm_val_obj);
kv = Keyval_.int_(((LuaNumber)itm_key).toint(), itm_val_obj);
break;
case LuaValue.TSTRING:
kv = KeyVal_.new_(((LuaString)itm_key).tojstring(), itm_val_obj);
kv = Keyval_.new_(((LuaString)itm_key).tojstring(), itm_val_obj);
break;
default:
throw Err_.new_unhandled(itm_key.type());
@@ -64,8 +64,8 @@ class Luaj_value_ {
cur = itm_key;
++len;
}
if (len == 0) return KeyVal_.Ary_empty;
return (KeyVal[])temp.To_ary(KeyVal.class);
if (len == 0) return Keyval_.Ary_empty;
return (Keyval[])temp.To_ary(Keyval.class);
}
private static Object X_val_to_obj(Luaj_server server, LuaValue v) {
switch (v.type()) {
@@ -91,16 +91,16 @@ class Luaj_value_ {
else if (Object_.Eq(c, Double_.Cls_ref_type)) return LuaValue.valueOf((Double)o);
else if (Object_.Eq(c, String_.Cls_ref_type)) return LuaValue.valueOf((String)o);
else if (Object_.Eq(c, byte[].class)) return LuaValue.valueOf(String_.new_u8((byte[])o));
else if (Object_.Eq(c, KeyVal.class)) return X_kv_ary_to_tbl(server, (KeyVal)o);
else if (Object_.Eq(c, KeyVal[].class)) return X_kv_ary_to_tbl(server, (KeyVal[])o);
else if (Object_.Eq(c, Keyval.class)) return X_kv_ary_to_tbl(server, (Keyval)o);
else if (Object_.Eq(c, Keyval[].class)) return X_kv_ary_to_tbl(server, (Keyval[])o);
else if (Object_.Eq(c, Scrib_lua_proc.class)) return server.Get_closure_by_id(((Scrib_lua_proc)o).Id());
else return LuaValue.NIL;
}
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, KeyVal... ary) {
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, Keyval... ary) {
LuaTable rv = LuaValue.tableOf();
int len = ary.length;
for (int i = 0; i < len; i++) {
KeyVal itm = ary[i];
Keyval itm = ary[i];
LuaValue itm_val = X_obj_to_val(server, itm.Val());
switch (itm.Key_tid()) {
case Type_adp_.Tid__int:

View File

@@ -22,7 +22,7 @@ public abstract class Mock_proc_fxt {
public int Id() {return id;} private final int id;
public String Key() {return key;} private final String key;
public Scrib_lua_proc To_scrib_lua_proc() {return new Scrib_lua_proc(key, id);}
public abstract KeyVal[] Exec_by_scrib(KeyVal[] args);
public abstract Keyval[] Exec_by_scrib(Keyval[] args);
}
class Mock_engine implements Scrib_engine {
private final Hash_adp hash = Hash_adp_.new_();
@@ -30,13 +30,13 @@ class Mock_engine implements Scrib_engine {
public boolean Dbg_print() {return false;} public void Dbg_print_(boolean v) {}
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {} private final Mock_server server = new Mock_server();
public Scrib_lua_proc LoadString(String name, String text) {return null;}
public KeyVal[] CallFunction(int id, KeyVal[] args) {
public Keyval[] CallFunction(int id, Keyval[] args) {
Mock_proc_fxt proc = (Mock_proc_fxt)hash.Get_by_or_fail(tmp_hash_id.Val_(id));
return proc.Exec_by_scrib(args);
}
public void RegisterLibrary(KeyVal[] functions_ary) {}
public KeyVal[] ExecuteModule(int mod_id) {return null;}
public void CleanupChunks(KeyVal[] ids) {}
public void RegisterLibrary(Keyval[] functions_ary) {}
public Keyval[] ExecuteModule(int mod_id) {return null;}
public void CleanupChunks(Keyval[] ids) {}
public void Clear() {}
public void RegisterLibraryForTest(Mock_proc_fxt proc) {
hash.Add(Int_obj_ref.new_(proc.Id()), proc);

View File

@@ -21,11 +21,11 @@ public class Mock_scrib_fxt {
private final Mock_engine engine = new Mock_engine();
private final Mock_server server = new Mock_server();
private Xop_fxt parser_fxt;
public Scrib_core Core() {return core;} private Scrib_core core;
public Scrib_core Core() {return core;} private Scrib_core core;
public void Clear() {Clear("en.wikipedia.org", "en");}
public void Clear(String domain, String lang) {
Xoae_app app = Xoa_app_fxt.app_();
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)));
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)));
parser_fxt = new Xop_fxt(app, wiki); // NOTE: always new(); don't try to cache; causes errors in Language_lib
core = Scrib_core.Core_new_(app, wiki.Parser_mgr().Ctx());
core.Engine_(engine); engine.Clear();
@@ -39,47 +39,49 @@ public class Mock_scrib_fxt {
for (Mock_proc_fxt proc : ary)
engine.RegisterLibraryForTest(proc);
}
public void Test__proc__objs__flat(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.Y, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__objs__nest(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.N, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.Y, args);}
public void Test__proc__kvps__nest(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.N, args);}
private static void Test__proc__kvps(Scrib_lib lib, String proc_name, String expd, boolean flat, KeyVal[] args) {
KeyVal[] actl_ary = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
public void Init__page(String ttl, String txt) {parser_fxt.Init_page_create(ttl, txt);}
public void Test__proc__ints (Scrib_lib lib, String proc_name, Object[] args, int expd) {Test__proc__kvps(lib, proc_name, Bool_.Y, Int_.To_str(expd), Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__objs__flat(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.Y, expd, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__objs__nest(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.N, expd, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.Y, expd, args);}
public void Test__proc__kvps__nest(Scrib_lib lib, String proc_name, Keyval[] args, String expd) {Test__proc__kvps(lib, proc_name, Bool_.N, expd, args);}
private static void Test__proc__kvps(Scrib_lib lib, String proc_name, boolean flat, String expd, Keyval[] args) {
Keyval[] actl_ary = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
if (flat)
Tfds.Eq(expd, Mock_scrib_fxt_.Kvp_vals_to_str(actl_ary));
else
Tfds.Eq_str_lines(expd, KeyVal_.Ary__to_str__nest(actl_ary));
Tfds.Eq_str_lines(expd, Keyval_.Ary__to_str__nest(actl_ary));
}
public void Test__proc__objs__empty(Scrib_lib lib, String proc_name, Object[] args) {Test__proc__kvps__empty(lib, proc_name, Scrib_kv_utl_.base1_many_(args));}
public void Test__proc__kvps__empty(Scrib_lib lib, String proc_name, KeyVal[] args) {
public void Test__proc__kvps__empty(Scrib_lib lib, String proc_name, Keyval[] args) {
Tfds.Eq(0, Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args).length);
}
public void Test__proc__kvps__vals(Scrib_lib lib, String proc_name, KeyVal[] args, Object... expd_ary) {
KeyVal[] actl_kvs = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
public void Test__proc__kvps__vals(Scrib_lib lib, String proc_name, Keyval[] args, Object... expd_ary) {
Keyval[] actl_kvs = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
Object[] actl_ary = Mock_scrib_fxt_.Kvp_vals_to_objs(actl_kvs);
Tfds.Eq_ary(expd_ary, actl_ary);
}
}
class Mock_scrib_fxt_ {
public static KeyVal[] Test__lib_proc__core(Scrib_lib lib, String proc_name, KeyVal[] args) {
public static Keyval[] Test__lib_proc__core(Scrib_lib lib, String proc_name, Keyval[] args) {
Scrib_proc proc = lib.Procs().Get_by_key(proc_name);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(new Scrib_proc_args(args), proc_rslt);
return proc_rslt.Ary();
}
public static Object[] Kvp_vals_to_objs(KeyVal[] kvps) {
public static Object[] Kvp_vals_to_objs(Keyval[] kvps) {
int len = kvps.length;
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i)
rv[i] = kvps[i].Val();
return rv;
}
public static String Kvp_vals_to_str(KeyVal[] ary) {
public static String Kvp_vals_to_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
KeyVal kv = ary[i];
Keyval kv = ary[i];
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(kv.Val()));
}
return bfr.To_str_and_clear();

View File

@@ -31,22 +31,22 @@ public class Process_engine implements Scrib_engine {
public boolean Dbg_print() {return dbg_print;} public void Dbg_print_(boolean v) {dbg_print = v;} private boolean dbg_print;
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {server = v;} Scrib_server server;
public Scrib_lua_proc LoadString(String name, String text) {
KeyVal[] rslt = this.Dispatch("op", "loadString", "text", text, "chunkName", name);
Keyval[] rslt = this.Dispatch("op", "loadString", "text", text, "chunkName", name);
return new Scrib_lua_proc(name, Int_.cast(rslt[0].Val()));
}
public KeyVal[] CallFunction(int id, KeyVal[] args) {
public Keyval[] CallFunction(int id, Keyval[] args) {
return this.Dispatch("op", "call", "id", id, "nargs", args.length, "args", args);
}
public void RegisterLibrary(KeyVal[] functions_ary) {
public void RegisterLibrary(Keyval[] functions_ary) {
this.Dispatch("op", "registerLibrary", "name", Scrib_core.Key_mw_interface, "functions", functions_ary);
}
public void CleanupChunks(KeyVal[] ids) {
public void CleanupChunks(Keyval[] ids) {
this.Dispatch("op", "cleanupChunks", "ids", ids);
}
public KeyVal[] ExecuteModule(int mod_id) {
public Keyval[] ExecuteModule(int mod_id) {
return this.CallFunction(core.Lib_mw().Mod().Fncs_get_id("executeModule"), Scrib_kv_utl_.base1_obj_(new Scrib_lua_proc("", mod_id)));
}
private KeyVal[] Dispatch(Object... ary) {
private Keyval[] Dispatch(Object... ary) {
Bry_bfr bfr = app.Utl__bfr_mkr().Get_k004().Clear();
while (true) {
Dispatch_bld_send(bfr, ary);
@@ -61,18 +61,18 @@ public class Process_engine implements Scrib_engine {
}
else if (String_.Eq(op, "error")) {
core.Handle_error(rsp.Rslt_ary()[0].Val_to_str_or_empty(), "");
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
else if (String_.Eq(op, "call")) {
String id = rsp.Call_id();
KeyVal[] args = rsp.Call_args();
Keyval[] args = rsp.Call_args();
Scrib_proc proc = proc_mgr.Get_by_key(id); if (proc == null) throw Scrib_xtn_mgr.err_("could not find proc with id of {0}", id);
Scrib_proc_args proc_args = new Scrib_proc_args(args);
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
proc.Proc_exec(proc_args, proc_rslt);
String fail_msg = proc_rslt.Fail_msg();
if (fail_msg == null) {
KeyVal[] cbk_rslts = proc_rslt.Ary();
Keyval[] cbk_rslts = proc_rslt.Ary();
ary = Object_.Ary("op", "return", "nvalues", cbk_rslts.length, "values", cbk_rslts);
}
else {
@@ -82,7 +82,7 @@ public class Process_engine implements Scrib_engine {
else {
bfr.Mkr_rls();
// app.Usr_dlg().Warn_many("", "", "invalid dispatch: op=~{0} page=~{1}", op, String_.new_u8(core.Ctx().Page().Page_ttl().Page_db()));
return KeyVal_.Ary_empty;
return Keyval_.Ary_empty;
}
}
} private static final byte[] Dispatch_hdr = Bry_.new_a7("0000000000000000"); // itm_len + itm_chk in 8-len HexDec

View File

@@ -27,26 +27,26 @@ public class Process_recv_msg {
} private Hash_adp arg_keys = Hash_adp_.new_(); private static final byte Arg_op = 0, Arg_values = 1, Arg_id = 2, Arg_args = 3;
public String Op() {return op;} private String op;
public String Call_id() {return call_id;} private String call_id;
public KeyVal[] Rslt_ary() {return rslt_ary;} private KeyVal[] rslt_ary;
public KeyVal[] Values() {return values;} private KeyVal[] values;
public KeyVal[] Call_args() {return call_args;} private KeyVal[] call_args;
public Keyval[] Rslt_ary() {return rslt_ary;} private Keyval[] rslt_ary;
public Keyval[] Values() {return values;} private Keyval[] values;
public Keyval[] Call_args() {return call_args;} private Keyval[] call_args;
public String Extract(byte[] rsp) {
try {
op = call_id = null;
rslt_ary = values = call_args = null;
KeyVal[] root_ary = parser.Parse_as_kvs(rsp);
rslt_ary = (KeyVal[])root_ary[0].Val();
Keyval[] root_ary = parser.Parse_as_kvs(rsp);
rslt_ary = (Keyval[])root_ary[0].Val();
int len = rslt_ary.length;
for (int i = 0; i < len; i++) {
KeyVal kv = rslt_ary[i];
Keyval kv = rslt_ary[i];
String kv_key = kv.Key();
Byte_obj_val bv = (Byte_obj_val)arg_keys.Get_by(kv_key);
if (bv != null) {
switch (bv.Val()) {
case Arg_op: op = kv.Val_to_str_or_empty(); break;
case Arg_values: values = (KeyVal[])kv.Val(); break;
case Arg_values: values = (Keyval[])kv.Val(); break;
case Arg_id: call_id = kv.Val_to_str_or_empty(); break;
case Arg_args: call_args = (KeyVal[])kv.Val(); break;
case Arg_args: call_args = (Keyval[])kv.Val(); break;
}
}
}

View File

@@ -54,19 +54,19 @@ public class Process_send_wtr {
bfr.Add_byte(Byte_ascii.Brack_end);
return true;
} static final byte[] Prc_bgn = Bry_.new_a7("chunks[");
private boolean Encode_ary(Bry_bfr bfr, KeyVal[] ary) {
private boolean Encode_ary(Bry_bfr bfr, Keyval[] ary) {
int len = ary.length;
bfr.Add_byte(Byte_ascii.Curly_bgn);
for (int i = 0; i < len; i++) {
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
KeyVal itm = ary[i];
Keyval itm = ary[i];
Encode_key(bfr, itm.Key_as_obj());
Encode_obj(bfr, itm.Val());
}
bfr.Add_byte(Byte_ascii.Curly_end);
return true;
}
private boolean Encode_kv(Bry_bfr bfr, KeyVal kv) {
private boolean Encode_kv(Bry_bfr bfr, Keyval kv) {
bfr.Add_byte(Byte_ascii.Curly_bgn);
Encode_key(bfr, kv.Key_as_obj());
Encode_obj(bfr, kv.Val());
@@ -88,8 +88,8 @@ public class Process_send_wtr {
else if (Object_.Eq(c, String.class)) {if (!Encode_str(bfr, (String)o)) return false;}
else if (Object_.Eq(c, byte[].class)) {if (!Encode_str(bfr, (byte[])o)) return false;} // NOTE: not in Scribunto; added here for PERF of not re-creating a String Object
else if (Object_.Eq(c, Scrib_lua_proc.class)) {if (!Encode_prc(bfr, (Scrib_lua_proc)o)) return false;}
else if (Object_.Eq(c, KeyVal.class)) {if (!Encode_kv(bfr, (KeyVal)o)) return false;}
else if (Object_.Eq(c, KeyVal[].class)) {if (!Encode_ary(bfr, (KeyVal[])o)) return false;}
else if (Object_.Eq(c, Keyval.class)) {if (!Encode_kv(bfr, (Keyval)o)) return false;}
else if (Object_.Eq(c, Keyval[].class)) {if (!Encode_ary(bfr, (Keyval[])o)) return false;}
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: {0}", Type_adp_.NameOf_obj(o));}
return true;
}

View File

@@ -36,7 +36,7 @@ class Scrib_lua_srl_fxt {
srl = new Process_send_wtr(usr_dlg);
}
} Process_send_wtr srl; Gfo_usr_dlg usr_dlg;
public KeyVal[] ary_(KeyVal... ary) {return ary;}
public KeyVal itm_(String key, Object val) {return KeyVal_.new_(key, val);}
public Keyval[] ary_(Keyval... ary) {return ary;}
public Keyval itm_(String key, Object val) {return Keyval_.new_(key, val);}
public void Test_encode(Object o, String expd) {Tfds.Eq(expd, srl.Encode(o));}
}

View File

@@ -55,34 +55,34 @@ class Process_server_mock_rcvd_val implements Process_server_mock_rcvd {
public Process_server_mock_rcvd_val(boolean print_key) {this.print_key = print_key;} private boolean print_key;
public String Bld(Object[] cmd_objs) {
Bry_bfr tmp_bfr = Bry_bfr.new_();
Bld_recursive(tmp_bfr, 0, (KeyVal[])cmd_objs[5]);
Bld_recursive(tmp_bfr, 0, (Keyval[])cmd_objs[5]);
byte[] values_str = tmp_bfr.To_bry_and_clear();
tmp_bfr.Add(Bry_rv_bgn).Add_int_variable(values_str.length).Add(Bry_rv_mid).Add(values_str).Add(Bry_rv_end);
return tmp_bfr.To_str_and_clear();
}
private void Bld_recursive(Bry_bfr bfr, int depth, KeyVal[] ary) {
private void Bld_recursive(Bry_bfr bfr, int depth, Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
KeyVal kv = ary[i];
Keyval kv = ary[i];
Object kv_val = kv.Val();
if (kv_val == null) {
bfr.Add(gplx.langs.jsons.Json_itm_.Bry__null);
continue;
}
Class<?> kv_val_type = kv_val.getClass();
boolean kv_val_is_array = Type_adp_.Eq(kv_val_type, KeyVal[].class);
boolean kv_val_is_array = Type_adp_.Eq(kv_val_type, Keyval[].class);
if (print_key && !kv_val_is_array)
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
if (Type_adp_.Eq(kv_val_type, Bool_.Cls_ref_type))
bfr.Add(Bool_.cast(kv_val) ? gplx.langs.jsons.Json_itm_.Bry__true : gplx.langs.jsons.Json_itm_.Bry__false);
else if (kv_val_is_array) {
KeyVal[] sub = (KeyVal[])kv_val;
Keyval[] sub = (Keyval[])kv_val;
if (sub.length == 0) {bfr.Add_byte(Byte_ascii.Curly_bgn).Add_byte(Byte_ascii.Curly_end);}
else {
bfr.Add_byte_nl();
bfr.Add_byte_repeat(Byte_ascii.Space, (depth + 1) * 2);
Bld_recursive(bfr, depth + 1, (KeyVal[])kv_val);
Bld_recursive(bfr, depth + 1, (Keyval[])kv_val);
}
}
else

View File

@@ -18,32 +18,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.langs.jsons.*;
class Kv_ary_utl {
public static KeyVal[] new_(boolean base_1, Object... vals) {
public static Keyval[] new_(boolean base_1, Object... vals) {
int len = vals.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; ++i)
rv[i] = KeyVal_.int_(i + (base_1 ? 1 : 0), vals[i]);
rv[i] = Keyval_.int_(i + (base_1 ? 1 : 0), vals[i]);
return rv;
}
public static KeyVal[] new_kvs(KeyVal... vals) {return vals;}
public static String Ary_to_str(Json_wtr wtr, KeyVal[] ary) {
public static Keyval[] new_kvs(Keyval... vals) {return vals;}
public static String Ary_to_str(Json_wtr wtr, Keyval[] ary) {
wtr.Doc_nde_bgn();
Ary_to_str(wtr, 0, ary);
return wtr.Doc_nde_end().To_str_and_clear();
}
private static void Ary_to_str(Json_wtr wtr, int indent, KeyVal[] ary) {
private static void Ary_to_str(Json_wtr wtr, int indent, Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Ary_to_str__itm(wtr, indent, ary[i]);
}
}
private static void Ary_to_str__itm(Json_wtr wtr, int indent, KeyVal itm) {
private static void Ary_to_str__itm(Json_wtr wtr, int indent, Keyval itm) {
Object val = itm.Val();
Class<?> val_type = val.getClass();
int type_tid = Type_adp_.To_tid_type(val_type);
if (type_tid == Type_adp_.Tid__obj) {
if (Type_adp_.Eq(val_type, KeyVal[].class))
Ary_to_str__nde(wtr, indent, itm.Key(), (KeyVal[])itm.Val());
if (Type_adp_.Eq(val_type, Keyval[].class))
Ary_to_str__nde(wtr, indent, itm.Key(), (Keyval[])itm.Val());
else if (Type_adp_.Is_array(val_type))
Ary_to_str__ary(wtr, indent, itm.Key(), Array_.cast(val));
else
@@ -57,7 +57,7 @@ class Kv_ary_utl {
Ary_to_str__ary_itms(wtr, indent + 1, array);
wtr.Ary_end();
}
private static void Ary_to_str__nde(Json_wtr wtr, int indent, String key, KeyVal[] kv) {
private static void Ary_to_str__nde(Json_wtr wtr, int indent, String key, Keyval[] kv) {
wtr.Nde_bgn(key);
Ary_to_str(wtr, indent + 1, kv);
wtr.Nde_end();
@@ -69,8 +69,8 @@ class Kv_ary_utl {
Class<?> itm_type = itm.getClass();
int itm_type_tid = Type_adp_.To_tid_type(itm_type);
if (itm_type_tid == Type_adp_.Tid__obj) {
if (Type_adp_.Eq(itm_type, KeyVal.class))
Ary_to_str__itm(wtr, indent + 1, (KeyVal)itm);
if (Type_adp_.Eq(itm_type, Keyval.class))
Ary_to_str__itm(wtr, indent + 1, (Keyval)itm);
else if (Type_adp_.Is_array(itm_type))
Ary_to_str__ary_itms(wtr, indent + 1, Array_.cast(itm));
else

View File

@@ -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.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
class Scrib_err {
public static Err Make__err__arg(String proc, int arg_idx, String actl, String expd) {
String rv = String_.Format("bad argument #{0} to {1} ({2} expected, got {3})", arg_idx, proc, expd, actl); // "bad argument #$argIdx to '$name' ($expectType expected, got $type)"
return Err_.new_("scribunto", rv);
}
}

View File

@@ -78,7 +78,7 @@ public class Scrib_lib_language implements Scrib_lib {
, Invk_formatNum, Invk_formatDate, Invk_formatDuration, Invk_getDurationIntervals, Invk_parseFormattedNumber
, Invk_convertPlural, Invk_convertGrammar, Invk_gender, Invk_isRTL
);
public void Notify_lang_changed() {if (notify_lang_changed_fnc != null) core.Interpreter().CallFunction(notify_lang_changed_fnc.Id(), KeyVal_.Ary_empty);}
public void Notify_lang_changed() {if (notify_lang_changed_fnc != null) core.Interpreter().CallFunction(notify_lang_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean GetContLangCode(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(core.Ctx().Lang().Key_str());}
public boolean IsSupportedLanguage(Scrib_proc_args args, Scrib_proc_rslt rslt) {return IsKnownLanguageTag(args, rslt);}// NOTE: checks if "MessagesXX.php" exists; note that xowa has all "MessagesXX.php"; for now, assume same functionality as IsKnownLanguageTag (worst case is that a small wiki depends on a lang not being there; will need to put in a "wiki.Langs()" then)
public boolean IsKnownLanguageTag(Scrib_proc_args args, Scrib_proc_rslt rslt) { // NOTE: checks if in languages/Names.php
@@ -166,9 +166,9 @@ public class Scrib_lib_language implements Scrib_lib {
byte[] num = args.Xstr_bry_or_null(1);
boolean skip_commafy = false;
if (num != null) { // MW: if num present, check options table for noCommafy arg;
KeyVal[] kv_ary = args.Cast_kv_ary_or_null(2);
Keyval[] kv_ary = args.Cast_kv_ary_or_null(2);
if (kv_ary != null) {
Object skip_commafy_obj = KeyVal_.Ary_get_by_key_or_null(kv_ary, "noCommafy");
Object skip_commafy_obj = Keyval_.Ary_get_by_key_or_null(kv_ary, "noCommafy");
if (skip_commafy_obj != null)
skip_commafy = Bool_.cast(skip_commafy_obj);
}
@@ -212,7 +212,7 @@ public class Scrib_lib_language implements Scrib_lib {
public boolean FormatDuration(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xol_lang_itm lang = lang_(args);
long seconds = args.Pull_long(1);
KeyVal[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Keyval[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Xol_duration_itm[] intervals = Xol_duration_itm_.Xto_itm_ary(intervals_kv_ary);
byte[] rv = lang.Duration_mgr().Format_durations(core.Ctx(), seconds, intervals);
return rslt.Init_obj(rv);
@@ -220,7 +220,7 @@ public class Scrib_lib_language implements Scrib_lib {
public boolean GetDurationIntervals(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xol_lang_itm lang = lang_(args);
long seconds = args.Pull_long(1);
KeyVal[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Keyval[] intervals_kv_ary = args.Cast_kv_ary_or_null(2);
Xol_duration_itm[] intervals = Xol_duration_itm_.Xto_itm_ary(intervals_kv_ary);
Xol_interval_itm[] rv = lang.Duration_mgr().Get_duration_intervals(seconds, intervals);
return rslt.Init_obj(Xol_interval_itm.Xto_kv_ary(rv));

View File

@@ -68,8 +68,8 @@ public class Scrib_lib_language_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("de", 1234), "1.234"); // german spr
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", 1234), "1,234"); // english spr
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234"), "1,234"); // String passed (not int)
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", true))) , "1234"); // noCommafy.y
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", false))) , "1,234"); // noCommafy.n
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", Keyval_.Ary(Keyval_.new_("noCommafy", true))) , "1234"); // noCommafy.y
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", Keyval_.Ary(Keyval_.new_("noCommafy", false))) , "1,234"); // noCommafy.n
}
@Test public void FormatDate() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "2013-03-17", false), "2013-03-17");
@@ -84,7 +84,7 @@ public class Scrib_lib_language_tst {
@Test public void FormatDate_date_omitted() { // PURPOSE: some calls skip the date; retrieve arg_4 by int; EX: pl.w:L._Frank_Baum
Tfds.Now_enabled_y_();
Tfds.Now_set(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, KeyVal_.Ary(KeyVal_.int_(1, "en"), KeyVal_.int_(2, "Y-m-d"), KeyVal_.int_(4, false)), "2013-12-19");
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Keyval_.Ary(Keyval_.int_(1, "en"), Keyval_.int_(2, "Y-m-d"), Keyval_.int_(4, false)), "2013-12-19");
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", ""), "2013-12-19");// PURPOSE: '' should return today, not fail; EX: th.w:สถานีรถไฟตรัง
Tfds.Now_enabled_n_();
}
@@ -135,11 +135,11 @@ public class Scrib_lib_language_tst {
, " seconds=3"
));
}
public static KeyVal[] Kv_ary_(String... ary) {
public static Keyval[] Kv_ary_(String... ary) {
int ary_len = ary.length;
KeyVal[] rv = new KeyVal[ary_len];
Keyval[] rv = new Keyval[ary_len];
for (int i = 0; i < ary_len; i++) {
rv[i] = KeyVal_.int_(i, ary[i]);
rv[i] = Keyval_.int_(i, ary[i]);
}
return rv;
}

View File

@@ -42,20 +42,20 @@ public class Scrib_lib_message implements Scrib_lib {
private static final int Proc_plain = 0, Proc_check = 1, Proc_init_message_for_lang = 2;
public static final String Invk_plain = "plain", Invk_check = "check", Invk_init_message_for_lang = "init_message_for_lang";
private static final String[] Proc_names = String_.Ary(Invk_plain, Invk_check, Invk_init_message_for_lang);
public void Notify_lang_changed() {if (notify_lang_changed_fnc != null) core.Interpreter().CallFunction(notify_lang_changed_fnc.Id(), KeyVal_.Ary_empty);}
public void Notify_lang_changed() {if (notify_lang_changed_fnc != null) core.Interpreter().CallFunction(notify_lang_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean Plain(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte fmt_tid = Scrib_lib_message_data.Fmt_tid_plain;
KeyVal[] data_kvary = args.Pull_kv_ary(0);
Keyval[] data_kvary = args.Pull_kv_ary(0);
Scrib_lib_message_data msg_data = new Scrib_lib_message_data().Parse(data_kvary);
return rslt.Init_obj(String_.new_u8(msg_data.Make_msg(core.Cur_lang(), core.Wiki(), core.Ctx(), true, fmt_tid)));
}
public boolean Check(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte chk_tid = Scrib_lib_message_data.parse_chk_(args.Pull_bry(0));
KeyVal[] data_kvary = args.Pull_kv_ary(1);
Keyval[] data_kvary = args.Pull_kv_ary(1);
Scrib_lib_message_data msg_data = new Scrib_lib_message_data().Parse(data_kvary);
return rslt.Init_obj(msg_data.Chk_msg(core.Cur_lang(), core.Wiki(), core.Ctx(), false, chk_tid));
}
public boolean Init_message_for_lang(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(KeyVal_.new_("lang", core.Wiki().Lang().Key_str()));}
public boolean Init_message_for_lang(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(Keyval_.new_("lang", core.Wiki().Lang().Key_str()));}
}
class Scrib_lib_message_data {
public boolean Use_db() {return use_db;} private boolean use_db;
@@ -65,16 +65,16 @@ class Scrib_lib_message_data {
public byte[] Raw_msg_key() {return raw_msg_key;} private byte[] raw_msg_key;
public Object[] Args() {return args;} Object[] args;
public Xoa_ttl Ttl() {return ttl;} public Scrib_lib_message_data Ttl_(Xoa_ttl v) {ttl = v; return this;} Xoa_ttl ttl;
public Scrib_lib_message_data Parse(KeyVal[] ary) {
public Scrib_lib_message_data Parse(Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
KeyVal kv = ary[i];
Keyval kv = ary[i];
byte[] kv_key = Bry_.new_a7(kv.Key());
Object key_obj = key_hash.Get_by(kv_key); if (key_obj == null) throw Err_.new_wo_type("msg_key is invalid", "key", kv_key);
byte key_tid = ((Byte_obj_val)key_obj).Val();
switch (key_tid) {
case Key_tid_keys:
KeyVal[] keys_ary = (KeyVal[])kv.Val();
Keyval[] keys_ary = (Keyval[])kv.Val();
msg_key = keys_ary[0].Val_to_bry();
break;
case Key_tid_rawMessage: raw_msg_key = kv.Val_to_bry(); break;
@@ -82,7 +82,7 @@ class Scrib_lib_message_data {
case Key_tid_useDB: use_db = Bool_.cast(kv.Val()); break;
case Key_tid_title: title_bry = kv.Val_to_bry(); break;
case Key_tid_params:
KeyVal[] args_ary = (KeyVal[])kv.Val();
Keyval[] args_ary = (Keyval[])kv.Val();
int args_ary_len = args_ary.length;
args = new String[args_ary_len];
for (int j = 0; j < args_ary_len; j++)

View File

@@ -33,11 +33,11 @@ public class Scrib_lib_message_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary_lang("sun", "fr")) , "dim");
}
@Test public void Plain_rawMessage() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "$1", "params", KeyVal_.Ary(KeyVal_.int_(1, "abc")))), "abc");
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "$1", "params", Keyval_.Ary(Keyval_.int_(1, "abc")))), "abc");
}
@Test public void Plain_rawMessage_empty() {// PURPOSE:rawMessage would throw null ref if rawMessage called template that returns empty value; PAGE:it.w:L'Internazionale DATE:2015-02-25
fxt.Parser_fxt().Init_page_create("Template:Msg", "");
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "{{Msg}}", "params", KeyVal_.Ary(KeyVal_.int_(1, "abc")))), "");
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "{{Msg}}", "params", Keyval_.Ary(Keyval_.int_(1, "abc")))), "");
}
@Test public void Check() {
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("exists" , keys_ary("sun")) , true);
@@ -58,19 +58,19 @@ public class Scrib_lib_message_tst {
private void Init_msg(Xol_lang_itm lang, String key, String val) {
lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_a7(key)).Atrs_set(Bry_.new_a7(val), false, false);
}
KeyVal[] keys_ary(String msg_key) {return keys_ary(msg_key, null, null);}
KeyVal[] keys_ary_arg(String msg_key, String arg) {return keys_ary(msg_key, null, arg);}
KeyVal[] keys_ary_lang(String msg_key, String lang) {return keys_ary(msg_key, lang, null);}
KeyVal[] keys_ary(String msg_key, String lang, String arg) {
Keyval[] keys_ary(String msg_key) {return keys_ary(msg_key, null, null);}
Keyval[] keys_ary_arg(String msg_key, String arg) {return keys_ary(msg_key, null, arg);}
Keyval[] keys_ary_lang(String msg_key, String lang) {return keys_ary(msg_key, lang, null);}
Keyval[] keys_ary(String msg_key, String lang, String arg) {
boolean arg_exists = arg != null;
boolean lang_exists = lang != null;
int idx = 0;
KeyVal[] rv = new KeyVal[1 + (arg_exists ? 1 : 0) + (lang_exists ? 1 : 0)];
rv[0] = KeyVal_.new_("keys", KeyVal_.Ary(KeyVal_.int_(1, msg_key)));
Keyval[] rv = new Keyval[1 + (arg_exists ? 1 : 0) + (lang_exists ? 1 : 0)];
rv[0] = Keyval_.new_("keys", Keyval_.Ary(Keyval_.int_(1, msg_key)));
if (arg_exists)
rv[++idx] = KeyVal_.new_("params", KeyVal_.Ary(KeyVal_.int_(1, arg)));
rv[++idx] = Keyval_.new_("params", Keyval_.Ary(Keyval_.int_(1, arg)));
if (lang_exists)
rv[++idx] = KeyVal_.new_("lang", lang);
rv[++idx] = Keyval_.new_("lang", lang);
return rv;
}
}

View File

@@ -29,7 +29,7 @@ public class Scrib_lib_mw implements Scrib_lib {
Init();
core.RegisterInterface(this, script_dir.GenSubFil("mwInit.lua")); // DATE:2014-07-12
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.lua")
, KeyVal_.new_("allowEnvFuncs", allow_env_funcs));
, Keyval_.new_("allowEnvFuncs", allow_env_funcs));
return mod;
}
public void Invoke_bgn(Xowe_wiki wiki, Xop_ctx ctx, byte[] new_src) {
@@ -81,7 +81,7 @@ public class Scrib_lib_mw implements Scrib_lib {
, Invk_getFrameTitle = "getFrameTitle", Invk_setTTL = "setTTL"
, Invk_parentFrameExists = "parentFrameExists"
;
private static final String[] Proc_names = String_.Ary
private static final String[] Proc_names = String_.Ary
( Invk_loadPackage, Invk_loadPHPLibrary
, Invk_frameExists, Invk_newChildFrame
, Invk_getExpandedArgument, Invk_getAllExpandedArguments
@@ -164,7 +164,7 @@ public class Scrib_lib_mw implements Scrib_lib {
Xot_invk parent_frame = Scrib_frame_.Get_parent(core, frame_tid);
int frame_arg_adj = Scrib_frame_.Get_arg_adj(frame_tid);
int args_len = frame.Args_len() - frame_arg_adj;
if (args_len < 1) return rslt.Init_obj(KeyVal_.Ary_empty); // occurs when "frame:getParent().args" but no parent frame
if (args_len < 1) return rslt.Init_obj(Keyval_.Ary_empty); // occurs when "frame:getParent().args" but no parent frame
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b128(); // NOTE: do not make modular level variable, else random failures; DATE:2013-10-14
List_adp rv = List_adp_.new_();
int arg_idx = 0;
@@ -202,11 +202,11 @@ public class Scrib_lib_mw implements Scrib_lib {
nde.Val_tkn().Tmpl_evaluate(ctx, src, parent_frame, tmp_bfr);
// ctx.Scribunto = Bool_.N;
String val = key_missing ? tmp_bfr.To_str_and_clear() : tmp_bfr.To_str_and_clear_and_trim(); // NOTE: must trim if key_exists; DUPE:TRIM_IF_KEY
KeyVal kv = key_is_str ? KeyVal_.new_(key_as_str, val) : KeyVal_.int_(key_as_int, val);
Keyval kv = key_is_str ? Keyval_.new_(key_as_str, val) : Keyval_.int_(key_as_int, val);
rv.Add(kv);
}
tmp_bfr.Mkr_rls();
return rslt.Init_obj((KeyVal[])rv.To_ary(KeyVal.class));
return rslt.Init_obj((Keyval[])rv.To_ary(Keyval.class));
}
public boolean FrameExists(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String frame_id = args.Pull_str(0);
@@ -227,7 +227,7 @@ public class Scrib_lib_mw implements Scrib_lib {
Xop_ctx tmp_ctx = Xop_ctx.new_sub_(cur_wiki);
int args_adj = Scrib_frame_.Get_arg_adj(frame_tid);
int args_len = frame.Args_len() - args_adj;
KeyVal[] kv_args = new KeyVal[args_len];
Keyval[] kv_args = new Keyval[args_len];
Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b512();
for (int i = 0; i < args_len; i++) {
Arg_nde_tkn arg = frame.Args_get_by_idx(i + args_adj);
@@ -236,7 +236,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (String_.Eq(key, "")) key = Int_.To_str(i);
arg.Val_tkn().Tmpl_evaluate(ctx, src, parent_frame, tmp_bfr); // NOTE: must evaluate against parent_frame; evaluating against current frame may cause stack-overflow; DATE:2013-04-04
String val = tmp_bfr.To_str_and_clear();
kv_args[i] = KeyVal_.new_(key, val);
kv_args[i] = Keyval_.new_(key, val);
}
Xot_invk_mock mock_frame = Xot_invk_mock.new_(Bry_.new_u8(frame_id), kv_args); // use frame_id for Frame_ttl; in lieu of a better candidate; DATE:2014-09-21
tmp_ctx.Parse_tid_(Xop_parser_.Parse_tid_page_tmpl); // default xnde names to template; needed for test, but should be in place; DATE:2014-06-27
@@ -252,7 +252,7 @@ public class Scrib_lib_mw implements Scrib_lib {
int fnc_name_len = fnc_name.length;
Bry_obj_ref argx_ref = Bry_obj_ref.New_empty();
Bry_obj_ref fnc_name_ref = Bry_obj_ref.New(fnc_name);
KeyVal[] parser_func_args = CallParserFunction_parse_args(cur_wiki.Appe().Utl_num_parser(), argx_ref, fnc_name_ref, args.Ary());
Keyval[] parser_func_args = CallParserFunction_parse_args(cur_wiki.Appe().Utl_num_parser(), argx_ref, fnc_name_ref, args.Ary());
Xot_invk_mock frame = Xot_invk_mock.new_(parent_frame.Defn_tid(), 0, fnc_name, parser_func_args); // pass something as frame_ttl; choosng fnc_name; DATE:2014-09-21
Xol_func_itm finder = cur_wiki.Lang().Func_regy().Find_defn(fnc_name, 0, fnc_name_len);
Xot_defn defn = finder.Func();
@@ -264,17 +264,17 @@ public class Scrib_lib_mw implements Scrib_lib {
bfr.Mkr_rls();
return rslt.Init_obj(bfr.To_str_and_clear());
}
private KeyVal[] CallParserFunction_parse_args(Number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, KeyVal[] args) {
private Keyval[] CallParserFunction_parse_args(Number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, Keyval[] args) {
List_adp rv = List_adp_.new_();
// flatten args
int args_len = args.length;
for (int i = 2; i < args_len; i++) {
KeyVal arg = args[i];
Keyval arg = args[i];
if (Is_kv_ary(arg)) {
KeyVal[] arg_kv_ary = (KeyVal[])arg.Val();
Keyval[] arg_kv_ary = (Keyval[])arg.Val();
int arg_kv_ary_len = arg_kv_ary.length;
for (int j = 0; j < arg_kv_ary_len; j++) {
KeyVal sub_arg = arg_kv_ary[j];
Keyval sub_arg = arg_kv_ary[j];
rv.Add(sub_arg);
}
}
@@ -287,7 +287,7 @@ public class Scrib_lib_mw implements Scrib_lib {
int fnc_name_len = fnc_name.length;
int fnc_name_colon_pos = Bry_find_.Find_fwd(fnc_name, Byte_ascii.Colon, 0, fnc_name_len);
if (fnc_name_colon_pos == Bry_find_.Not_found) {
KeyVal arg_argx = (KeyVal)rv.Get_at(0);
Keyval arg_argx = (Keyval)rv.Get_at(0);
argx_ref.Val_(arg_argx.Val_to_bry());
rv.Del_at(0);
}
@@ -296,9 +296,9 @@ public class Scrib_lib_mw implements Scrib_lib {
fnc_name = Bry_.Mid(fnc_name, 0, fnc_name_colon_pos);
fnc_name_ref.Val_(fnc_name);
}
return (KeyVal[])rv.To_ary(KeyVal.class);
return (Keyval[])rv.To_ary(Keyval.class);
}
private static boolean Is_kv_ary(KeyVal kv) {return Type_adp_.Eq_typeSafe(kv.Val(), KeyVal[].class);}
private static boolean Is_kv_ary(Keyval kv) {return Type_adp_.Eq_typeSafe(kv.Val(), Keyval[].class);}
public boolean ExpandTemplate(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String ttl_str = args.Pull_str(1);
byte[] ttl_bry = Bry_.new_u8(ttl_str);
@@ -306,7 +306,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (ttl == null) return rslt.Init_ary_empty(); // invalid ttl;
if (!ttl.ForceLiteralLink() && ttl.Ns().Id_is_main()) // title is not literal and is not prefixed with Template; parse again as template; EX: ":A" and "Template:A" are fine; "A" is parsed again as "Template:A"
ttl = Xoa_ttl.parse(cur_wiki, Bry_.Add(cur_wiki.Ns_mgr().Ns_template().Name_db_w_colon(), ttl_bry)); // parse again, but add "Template:"
KeyVal[] args_ary = args.Pull_kv_ary(2);
Keyval[] args_ary = args.Pull_kv_ary(2);
// BLOCK.bgn:Xot_invk_tkn.Transclude; cannot reuse b/c Transclude needs invk_tkn, and invk_tkn is manufactured late; DATE:2014-01-02
byte[] sub_src = null;
if (ttl.Ns().Id_is_tmpl()) { // ttl is template; check tmpl_regy first before going to data_mgr
@@ -316,7 +316,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (sub_src == null) // ttl is not in template cache, or is a ttl in non-Template ns; load title
sub_src = core.Wiki().Cache_mgr().Page_cache().Get_or_load_as_src(ttl);
if (sub_src != null) {
Xot_invk_mock sub_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt(), args_ary); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-09-21
Xot_invk_mock sub_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt_w_ttl_case(), args_ary); // NOTE: (1) must have ns (Full); (2) must be txt (space, not underscore); EX:Template:Location map+; DATE:2014-09-21
Xot_defn_tmpl transclude_tmpl = ctx.Wiki().Parser_mgr().Main().Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), ttl.Ns(), ttl.Page_db(), sub_src);
Bry_bfr sub_bfr = cur_wiki.Utl__bfr_mkr().Get_k004();
transclude_tmpl.Tmpl_evaluate(ctx, sub_frame, sub_bfr);
@@ -330,7 +330,7 @@ public class Scrib_lib_mw implements Scrib_lib {
// BLOCK.end:Xot_invk_tkn.Transclude
}
public boolean IncrementExpensiveFunctionCount(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(KeyVal_.Ary_empty);} // NOTE: for now, always return null (XOWA does not care about expensive parser functions)
public boolean IncrementExpensiveFunctionCount(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(Keyval_.Ary_empty);} // NOTE: for now, always return null (XOWA does not care about expensive parser functions)
public boolean IsSubsting(Scrib_proc_args args, Scrib_proc_rslt rslt) {
boolean is_substing = false;
Xot_invk current_frame = core.Frame_current();
@@ -359,8 +359,8 @@ public class Scrib_lib_mw implements Scrib_lib {
ttl = Xoa_ttl.parse(cur_wiki, Bry_.new_u8((String)ttl_obj));
if (ttl == null) throw Err_.new_wo_type("newChild: invalid title", "title", (String)ttl_obj);
}
KeyVal[] args_ary = args.Pull_kv_ary(2);
Xot_invk_mock new_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt(), args_ary); // NOTE: use spaces, not unders; REF.MW:$frame->getTitle()->getPrefixedText(); DATE:2014-08-14
Keyval[] args_ary = args.Pull_kv_ary(2);
Xot_invk_mock new_frame = Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, ttl.Full_txt_w_ttl_case(), args_ary); // NOTE: use spaces, not unders; REF.MW:$frame->getTitle()->getPrefixedText(); DATE:2014-08-14
String new_frame_id = "frame" + Int_.To_str(frame_list_len);
frame_list.Add(new_frame_id, new_frame);
return rslt.Init_obj(new_frame_id);
@@ -379,8 +379,8 @@ public class Scrib_lib_mw implements Scrib_lib {
}
class Scrib_lib_mw_callParserFunction_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
KeyVal lhs = (KeyVal)lhsObj;
KeyVal rhs = (KeyVal)rhsObj;
Keyval lhs = (Keyval)lhsObj;
Keyval rhs = (Keyval)rhsObj;
Object lhs_key = lhs.Key_as_obj();
Object rhs_key = rhs.Key_as_obj();
boolean lhs_is_int = Int_.TypeMatch(lhs_key.getClass());
@@ -392,5 +392,5 @@ class Scrib_lib_mw_callParserFunction_sorter implements gplx.core.lists.Comparer
else // both are strings
return String_.Compare(String_.cast(lhs_key), String_.cast(rhs_key));
}
public static final Scrib_lib_mw_callParserFunction_sorter Instance = new Scrib_lib_mw_callParserFunction_sorter(); Scrib_lib_mw_callParserFunction_sorter() {}
public static final Scrib_lib_mw_callParserFunction_sorter Instance = new Scrib_lib_mw_callParserFunction_sorter(); Scrib_lib_mw_callParserFunction_sorter() {}
}

View File

@@ -30,15 +30,15 @@ public class Scrib_lib_mw__lib_tst {
fxt.Test_scrib_proc_bool(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, false);
}
@Test public void GetAllExpandedArguments() {
fxt.Init_frame_current(KeyVal_.new_("k1", "v1"));
fxt.Init_frame_current(Keyval_.new_("k1", "v1"));
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "1=\n k1=v1");
}
@Test public void GetAllExpandedArguments_parent() {
fxt.Init_frame_parent("test", KeyVal_.new_("1", "a1"), KeyVal_.new_("2", "a2"));
fxt.Init_frame_parent("test", Keyval_.new_("1", "a1"), Keyval_.new_("2", "a2"));
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("parent"), "1=\n 1=a1\n 2=a2");
}
@Test public void GetExpandedArgument() {
fxt.Init_frame_current(KeyVal_.int_(1, "val_1"), KeyVal_.new_("key_2", "val_2"), KeyVal_.int_(3, "val_3"));
fxt.Init_frame_current(Keyval_.int_(1, "val_1"), Keyval_.new_("key_2", "val_2"), Keyval_.int_(3, "val_3"));
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , "val_1"); // get 1st by idx
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "2") , "val_3"); // get 2nd by idx (which is "3", not "key_2)
fxt.Test_scrib_proc_empty (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "3")); // get 3rd by idx (which is n/a, not "val_3")
@@ -46,17 +46,17 @@ public class Scrib_lib_mw__lib_tst {
fxt.Test_scrib_proc_empty (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_3")); // key_3 n/a
}
@Test public void GetExpandedArgument_parent() {
fxt.Init_frame_parent ("test", KeyVal_.new_("1", "a1"), KeyVal_.new_("2", "a2"));
fxt.Init_frame_current(KeyVal_.new_("2", "b2"));
fxt.Init_frame_parent ("test", Keyval_.new_("1", "a1"), Keyval_.new_("2", "a2"));
fxt.Init_frame_current(Keyval_.new_("2", "b2"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "1"), "a1");
}
@Test public void GetExpandedArgument_numeric_key() { // PURPOSE.FIX: frame.args[1] was ignoring "1=val_1" b/c it was looking for 1st unnamed arg (and 1 is the name for "1=val_1")
fxt.Init_frame_current(KeyVal_.new_("1", "val_1"));
fxt.Init_frame_current(Keyval_.new_("1", "val_1"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1"), "val_1"); // get 1st by idx, even though idx is String
}
@Test public void GetExpandedArgument_numeric_key_2() { // PURPOSE.FIX: same as above, but for parent context; DATE:2013-09-23
fxt.Init_frame_parent ("test", KeyVal_.new_("2", "a1"));
fxt.Init_frame_current(KeyVal_.new_("2", "a2"));
fxt.Init_frame_parent ("test", Keyval_.new_("2", "a1"));
fxt.Init_frame_current(Keyval_.new_("2", "a2"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2"), "a1"); // get 1st by idx, even though idx is String
}
@Test public void GetExpandedArgument_out_of_bounds() {
@@ -86,4 +86,4 @@ public class Scrib_lib_mw__lib_tst {
@Test public void LoadPHPLibrary() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_loadPHPLibrary, Object_.Ary("mock_library") , Scrib_invoke_func_fxt.Null_rslt);
}
}
}

View File

@@ -17,10 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.addons.ctgs.*;
import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.xwikis.*;
public class Scrib_lib_site implements Scrib_lib {
public Scrib_lib_site(Scrib_core core) {this.core = core;} private Scrib_core core;
public Scrib_lib_site(Scrib_core core) {this.core = core;} private final 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_lua_mod Register(Scrib_core core, Io_url script_dir) {
@@ -29,7 +29,7 @@ public class Scrib_lib_site implements Scrib_lib {
notify_wiki_changed_fnc = mod.Fncs_get_by_key("notify_wiki_changed");
return mod;
} private Scrib_lua_proc notify_wiki_changed_fnc;
public Scrib_proc_mgr Procs() {return procs;} private Scrib_proc_mgr procs = new Scrib_proc_mgr();
public Scrib_proc_mgr Procs() {return procs;} private final Scrib_proc_mgr procs = new Scrib_proc_mgr();
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
switch (key) {
case Proc_getNsIndex: return GetNsIndex(args, rslt);
@@ -51,9 +51,34 @@ public class Scrib_lib_site implements Scrib_lib {
}
public boolean PagesInCategory(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte[] ctg_name = args.Pull_bry(0);
// byte[] ctg_type = Scrib_kv_utl_.Val_to_bry(values, 1); // TODO.7: get by categoy type; WHEN: categories
int ctg_count = core.Wiki().Db_mgr().Load_mgr().Load_ctg_count(ctg_name);
return rslt.Init_obj(ctg_count);
String ctg_type = args.Cast_str_or(1, "all");
Xoa_ttl ctg_ttl = core.Wiki().Ttl_parse(Xow_ns_.Tid__category, ctg_name);
if (ctg_ttl == null) return rslt.Init_obj(0);
Xoax_ctg_addon ctg_mgr = Xoax_ctg_addon.Get(core.Wiki());
Xoctg_ctg_itm ctg_itm = ctg_mgr.Itms__get_or_null(ctg_name);
if (ctg_itm == null) {
core.Increment_expensive_function_count();
ctg_itm = ctg_mgr.Itms__load(ctg_name);
}
if (String_.Eq(ctg_type, "*")) {
Keyval[] rv = new Keyval[4];
rv[0] = Keyval_.new_("all", ctg_itm.All);
rv[1] = Keyval_.new_("pages", ctg_itm.Pages);
rv[2] = Keyval_.new_("subcats", ctg_itm.Subcs);
rv[3] = Keyval_.new_("files", ctg_itm.Files);
return rslt.Init_obj(rv);
}
else {
int rv_count = 0;
switch (ctg_type) {
case "all": rv_count = ctg_itm.All; break;
case "pages": rv_count = ctg_itm.Pages; break;
case "subcats": rv_count = ctg_itm.Subcs; break;
case "files": rv_count = ctg_itm.Files; break;
default: throw Scrib_err.Make__err__arg(Invk_pagesInCategory, 2, ctg_type, "one of '*', 'all', 'pages', 'subcats', or 'files'");
}
return rslt.Init_obj(rv_count);
}
}
public boolean PagesInNs(Scrib_proc_args args, Scrib_proc_rslt rslt) {
int ns_id = args.Pull_int(0);
@@ -77,7 +102,7 @@ public class Scrib_lib_site implements Scrib_lib {
// TODO: cache interwikimap results
Xow_xwiki_mgr xwiki_mgr = core.Wiki().Xwiki_mgr();
int xwiki_len = xwiki_mgr.Len();
KeyVal[][] rv = new KeyVal[xwiki_len][];
Keyval[][] rv = new Keyval[xwiki_len][];
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
@@ -88,96 +113,96 @@ public class Scrib_lib_site implements Scrib_lib {
}
return rslt.Init_obj(rv);
}
private KeyVal[] InterwikiMap_itm(Xow_xwiki_itm itm, String prefix, boolean itm_is_local) {
private Keyval[] InterwikiMap_itm(Xow_xwiki_itm itm, String prefix, boolean itm_is_local) {
boolean is_extralanguage_link = false;
int rv_len = 7;
if (is_extralanguage_link) rv_len += 2;
String url = String_.new_u8(itm.Domain_bry());
boolean url_is_relative = String_.Has_at_bgn(url, "//");
KeyVal[] rv = new KeyVal[rv_len];
rv[ 0] = KeyVal_.new_("prefix" , prefix);
rv[ 1] = KeyVal_.new_("url" , url); // wfExpandUrl( $row['iw_url'], PROTO_RELATIVE ),
rv[ 2] = KeyVal_.new_("isProtocolRelative" , url_is_relative); // substr( $row['iw_url'], 0, 2 ) === '//',
rv[ 3] = KeyVal_.new_("isLocal" , itm_is_local); // isset( $row['iw_local'] ) && $row['iw_local'] == '1',
rv[ 4] = KeyVal_.new_("isTranscludable" , Bool_.N); // isset( $row['iw_trans'] ) && $row['iw_trans'] == '1',
rv[ 5] = KeyVal_.new_("isCurrentWiki" , Bool_.N); // in_array( $prefix, $wgLocalInterwikis ),
rv[ 6] = KeyVal_.new_("isExtraLanguageLink" , is_extralanguage_link); // in_array( $prefix, $wgExtraInterlanguageLinkPrefixes ),
Keyval[] rv = new Keyval[rv_len];
rv[ 0] = Keyval_.new_("prefix" , prefix);
rv[ 1] = Keyval_.new_("url" , url); // wfExpandUrl( $row['iw_url'], PROTO_RELATIVE ),
rv[ 2] = Keyval_.new_("isProtocolRelative" , url_is_relative); // substr( $row['iw_url'], 0, 2 ) === '//',
rv[ 3] = Keyval_.new_("isLocal" , itm_is_local); // isset( $row['iw_local'] ) && $row['iw_local'] == '1',
rv[ 4] = Keyval_.new_("isTranscludable" , Bool_.N); // isset( $row['iw_trans'] ) && $row['iw_trans'] == '1',
rv[ 5] = Keyval_.new_("isCurrentWiki" , Bool_.N); // in_array( $prefix, $wgLocalInterwikis ),
rv[ 6] = Keyval_.new_("isExtraLanguageLink" , is_extralanguage_link); // in_array( $prefix, $wgExtraInterlanguageLinkPrefixes ),
if (is_extralanguage_link) {
rv[7] = KeyVal_.new_("displayText" , "displayText_TODO"); // $displayText = wfMessage( "interlanguage-link-$prefix" ); if ( !$displayText->isDisabled() ) ...
rv[7] = KeyVal_.new_("tooltip" , "tooltip_TODO"); // $tooltip = wfMessage( "interlanguage-link-sitename-$prefix" );
rv[7] = Keyval_.new_("displayText" , "displayText_TODO"); // $displayText = wfMessage( "interlanguage-link-$prefix" ); if ( !$displayText->isDisabled() ) ...
rv[7] = Keyval_.new_("tooltip" , "tooltip_TODO"); // $tooltip = wfMessage( "interlanguage-link-sitename-$prefix" );
}
return rv;
}
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), KeyVal_.Ary_empty);}
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_site_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xowe_wiki wiki = core.Wiki();
KeyVal[] rv = new KeyVal[7];
Keyval[] rv = new Keyval[7];
Bld_info(rv);
rv[5] = KeyVal_.new_("name" + "spaces", Bld_ns_ary(wiki));
rv[6] = KeyVal_.new_("stats", Bld_stats(wiki));
rv[5] = Keyval_.new_("name" + "spaces", Bld_ns_ary(wiki));
rv[6] = Keyval_.new_("stats", Bld_stats(wiki));
return rslt.Init_obj(rv);
}
private void Bld_info(KeyVal[] rv) {
private void Bld_info(Keyval[] rv) {
Xow_wiki_props props = core.Wiki().Props();
rv[0] = KeyVal_.new_("siteName" , props.Site_name());
rv[1] = KeyVal_.new_("server" , props.Server());
rv[2] = KeyVal_.new_("scriptPath" , props.ScriptPath());
rv[3] = KeyVal_.new_("stylePath" , props.StylePath());
rv[4] = KeyVal_.new_("currentVersion" , props.Current_version());
rv[0] = Keyval_.new_("siteName" , props.Site_name());
rv[1] = Keyval_.new_("server" , props.Server());
rv[2] = Keyval_.new_("scriptPath" , props.ScriptPath());
rv[3] = Keyval_.new_("stylePath" , props.StylePath());
rv[4] = Keyval_.new_("currentVersion" , props.Current_version());
}
private KeyVal[] Bld_ns_ary(Xowe_wiki wiki) {
private Keyval[] Bld_ns_ary(Xowe_wiki wiki) {
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
int len = ns_mgr.Ids_len();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
int rv_idx = 0;
for (int i = 0; i < len; i++) {
Xow_ns ns = ns_mgr.Ids_get_at(i);
if (ns == null) continue;
int ns_id = ns.Id();
rv[rv_idx++] = KeyVal_.int_(ns_id, Bld_ns(wiki, ns, ns_id));
rv[rv_idx++] = Keyval_.int_(ns_id, Bld_ns(wiki, ns, ns_id));
}
return rv;
}
private KeyVal[] Bld_ns(Xowe_wiki wiki, Xow_ns ns, int ns_id) {
private Keyval[] Bld_ns(Xowe_wiki wiki, Xow_ns ns, int ns_id) {
int len = 16;
if (ns_id < Xow_ns_.Tid__main) len = 14;
else if (ns_id == Xow_ns_.Tid__main) len = 17;
KeyVal[] rv = new KeyVal[len];
rv[ 0] = KeyVal_.new_("id" , ns_id);
rv[ 1] = KeyVal_.new_("name" , ns.Name_ui());
rv[ 2] = KeyVal_.new_("canonicalName" , ns.Name_db_str()); // strtr( $canonical, "_", " " ),
rv[ 3] = KeyVal_.new_("hasSubpages" , ns.Subpages_enabled()); // MWNs::hasSubpages( $ns ),
rv[ 4] = KeyVal_.new_("hasGenderDistinction" , ns.Is_gender_aware()); // MWNs::hasGenderDistinction( $ns ),
rv[ 5] = KeyVal_.new_("isCapitalized" , ns.Is_capitalized()); // MWNs::isCapitalized( $ns ),
rv[ 6] = KeyVal_.new_("isContent" , ns.Is_content()); // MWNs::isContent( $ns ),
rv[ 7] = KeyVal_.new_("isIncludable" , ns.Is_includable()); // !MWNs::isNonincludable( $ns ),
rv[ 8] = KeyVal_.new_("isMovable" , ns.Is_movable()); // MWNs::isMovable( $ns ),
rv[ 9] = KeyVal_.new_("isSubject" , ns.Id_is_subj());
rv[10] = KeyVal_.new_("isTalk" , ns.Id_is_talk());
rv[11] = KeyVal_.new_("defaultContentModel" , null); // MWNs::getNsContentModel( $ns ), ASSUME: always null?
rv[12] = KeyVal_.new_("aliases" , ns.Aliases_as_scrib_ary()); // DATE:2014-02-15
Keyval[] rv = new Keyval[len];
rv[ 0] = Keyval_.new_("id" , ns_id);
rv[ 1] = Keyval_.new_("name" , ns.Name_ui());
rv[ 2] = Keyval_.new_("canonicalName" , ns.Name_db_str()); // strtr( $canonical, "_", " " ),
rv[ 3] = Keyval_.new_("hasSubpages" , ns.Subpages_enabled()); // MWNs::hasSubpages( $ns ),
rv[ 4] = Keyval_.new_("hasGenderDistinction" , ns.Is_gender_aware()); // MWNs::hasGenderDistinction( $ns ),
rv[ 5] = Keyval_.new_("isCapitalized" , ns.Is_capitalized()); // MWNs::isCapitalized( $ns ),
rv[ 6] = Keyval_.new_("isContent" , ns.Is_content()); // MWNs::isContent( $ns ),
rv[ 7] = Keyval_.new_("isIncludable" , ns.Is_includable()); // !MWNs::isNonincludable( $ns ),
rv[ 8] = Keyval_.new_("isMovable" , ns.Is_movable()); // MWNs::isMovable( $ns ),
rv[ 9] = Keyval_.new_("isSubject" , ns.Id_is_subj());
rv[10] = Keyval_.new_("isTalk" , ns.Id_is_talk());
rv[11] = Keyval_.new_("defaultContentModel" , null); // MWNs::getNsContentModel( $ns ), ASSUME: always null?
rv[12] = Keyval_.new_("aliases" , ns.Aliases_as_scrib_ary()); // DATE:2014-02-15
if (ns_id < 0)
rv[13] = KeyVal_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
rv[13] = Keyval_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
else {
rv[13] = KeyVal_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
rv[14] = KeyVal_.new_("talk" , ns.Id_talk_id()); // MWNs::getTalk( $ns );
rv[15] = KeyVal_.new_("associated" , ns.Id_alt_id()); // MWNs::getAssociated( $ns );
rv[13] = Keyval_.new_("subject" , ns_id); // MWNs::getSubject( $ns );
rv[14] = Keyval_.new_("talk" , ns.Id_talk_id()); // MWNs::getTalk( $ns );
rv[15] = Keyval_.new_("associated" , ns.Id_alt_id()); // MWNs::getAssociated( $ns );
if (ns_id == Xow_ns_.Tid__main)
rv[16] = KeyVal_.new_("displayName" , wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ns_blankns)); // MWNs::getAssociated( $ns );
rv[16] = Keyval_.new_("displayName" , wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ns_blankns)); // MWNs::getAssociated( $ns );
}
return rv;
}
private KeyVal[] Bld_stats(Xowe_wiki wiki) {
Xow_wiki_stats stats = wiki.Stats();
KeyVal[] rv = new KeyVal[8];
rv[0] = KeyVal_.new_("pages", stats.NumPages()); // SiteStats::pages(),
rv[1] = KeyVal_.new_("articles", stats.NumArticles()); // SiteStats::articles(),
rv[2] = KeyVal_.new_("files", stats.NumFiles()); // SiteStats::images(),
rv[3] = KeyVal_.new_("edits", stats.NumEdits()); // SiteStats::edits(),
rv[4] = KeyVal_.new_("views", stats.NumViews()); // $wgDisableCounters ? null : (int)SiteStats::views(),
rv[5] = KeyVal_.new_("users", stats.NumUsers()); // SiteStats::users(),
rv[6] = KeyVal_.new_("activeUsers", stats.NumUsersActive());// SiteStats::activeUsers(),
rv[7] = KeyVal_.new_("admins", stats.NumAdmins()); // SiteStats::activeUsers(),
private Keyval[] Bld_stats(Xowe_wiki wiki) {
Xow_site_stats_mgr stats = wiki.Stats();
Keyval[] rv = new Keyval[8];
rv[0] = Keyval_.new_("pages" , stats.Num_pages()); // SiteStats::pages(),
rv[1] = Keyval_.new_("articles" , stats.Num_articles()); // SiteStats::articles(),
rv[2] = Keyval_.new_("files" , stats.Num_files()); // SiteStats::images(),
rv[3] = Keyval_.new_("edits" , stats.Num_edits()); // SiteStats::edits(),
rv[4] = Keyval_.new_("views" , stats.Num_views()); // $wgDisableCounters ? null : (int)SiteStats::views(),
rv[5] = Keyval_.new_("users" , stats.Num_users()); // SiteStats::users(),
rv[6] = Keyval_.new_("activeUsers" , stats.Num_active()); // SiteStats::activeUsers(),
rv[7] = Keyval_.new_("admins" , stats.Num_admins()); // SiteStats::activeUsers(),
return rv;
}
}

View File

@@ -16,30 +16,45 @@ 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.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import org.junit.*; import gplx.xowa.wikis.nss.*;
import org.junit.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
public class Scrib_lib_site_tst {
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
@Before public void init() {
fxt.Clear_for_lib();
fxt.Clear();
lib = fxt.Core().Lib_site().Init();
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
@Test public void GetNsIndex() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Help"), 12);
}
@Test public void GetNsIndex_invalid() {
fxt.Test_scrib_proc_empty(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Helpx")); // unknown ns; return empty String
@Test public void GetNsIndex__valid() {
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Help"), 12);
}
@Test public void GetNsIndex__invalid() {
fxt.Test__proc__objs__empty(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Helpx")); // unknown ns; return empty String
}
@Test public void UsersInGroup() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_usersInGroup, Object_.Ary("sysop"), 0); // SELECT * FROM user_groups;
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_usersInGroup, Object_.Ary("sysop"), 0); // SELECT * FROM user_groups;
}
@Test public void PagesInCategory() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A"), 0);
@Test public void PagesInCategory__invalid() {
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A|"), 0);
}
@Test public void PagesInCategory__exists() {
gplx.xowa.addons.ctgs.Xoax_ctg_addon.Get(fxt.Core().Wiki()).Itms__add(Bry_.new_a7("A"), 3, 2, 1);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "pages") , 3);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "subcats") , 2);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "files") , 1);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "all") , 6);
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A", "*") , String_.Concat_lines_nl_skip_last
( "1="
, " all=6"
, " pages=3"
, " subcats=2"
, " files=1"
));
}
@Test public void PagesInNs() {
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
}
@Test public void Init_lib_site() {
Xowe_wiki wiki = fxt.Parser_fxt().Wiki();
fxt.Parser_fxt().Wiki().Stats().NumPages_(1).NumArticles_(2).NumFiles_(3).NumEdits_(4).NumViews_(5).NumUsers_(6).NumUsersActive_(7).NumAdmins_(8);
Xowe_wiki wiki = fxt.Core().Wiki();
wiki.Stats().Load_by_db(1, 2, 3, 4, 5, 6, 7, 8);
wiki.Ns_mgr()
.Clear()
.Add_new(Xow_ns_.Tid__module , Xow_ns_.Key__module)
@@ -49,7 +64,7 @@ public class Scrib_lib_site_tst {
.Add_new(Xow_ns_.Tid__talk , Xow_ns_.Key__talk)
.Init_w_defaults()
;
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl_skip_last
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl_skip_last
( "1="
, " siteName=Wikipedia"
, " server=http://en.wikipedia.org"

View File

@@ -53,31 +53,13 @@ public class Scrib_lib_text implements Scrib_lib {
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_;
// 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;
// Object itm_as_ary = null;
// if (Type_adp_.Eq(itm_type, typeof(KeyVal[]))) 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);
// if (itm_as_kvy != null && !Bitmask_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))
// itm_as_kvy = json_util.Reindex_arrays(itm_as_kvy, true);
// 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 if (itm_as_ary != null)
// 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);
// }
} private static Keyval[] Gfh_entity_;
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;
Keyval[] itm_as_kvy = null;
Object itm_as_ary = null;
if (Type_adp_.Eq(itm_type, KeyVal[].class)) itm_as_kvy = (KeyVal[])itm;
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) {
@@ -114,7 +96,7 @@ public class Scrib_lib_text implements Scrib_lib {
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();
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());
@@ -124,14 +106,14 @@ public class Scrib_lib_text implements Scrib_lib {
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 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) {
Xow_msg_mgr msg_mgr = core.Wiki().Msg_mgr();
KeyVal[] rv = new KeyVal[4];
rv[0] = KeyVal_.new_("comma", Init_lib_text_get_msg(msg_mgr, "comma-separator"));
rv[1] = KeyVal_.new_("and", Init_lib_text_get_msg(msg_mgr, "and") + Init_lib_text_get_msg(msg_mgr, "word-separator"));
rv[2] = KeyVal_.new_("ellipsis", Init_lib_text_get_msg(msg_mgr, "ellipsis"));
rv[3] = KeyVal_.new_("nowiki_protocols", KeyVal_.Ary_empty); // NOTE: code implemented, but waiting for it to be used; DATE:2014-03-20
Keyval[] rv = new Keyval[4];
rv[0] = Keyval_.new_("comma", Init_lib_text_get_msg(msg_mgr, "comma-separator"));
rv[1] = Keyval_.new_("and", Init_lib_text_get_msg(msg_mgr, "and") + Init_lib_text_get_msg(msg_mgr, "word-separator"));
rv[2] = Keyval_.new_("ellipsis", Init_lib_text_get_msg(msg_mgr, "ellipsis"));
rv[3] = Keyval_.new_("nowiki_protocols", Keyval_.Ary_empty); // NOTE: code implemented, but waiting for it to be used; DATE:2014-03-20
return rslt.Init_obj(rv);
}
private String Init_lib_text_get_msg(Xow_msg_mgr msg_mgr, String msg_key) {

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.core.net.*;
class Scrib_lib_text_ {
public static KeyVal[] Init_nowiki_protocols(Xowe_wiki wiki) {
public static Keyval[] Init_nowiki_protocols(Xowe_wiki wiki) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
Ordered_hash protocols = Gfo_protocol_itm.Regy;
int len = protocols.Count();
@@ -26,14 +26,14 @@ class Scrib_lib_text_ {
for (int i = 0; i < len; i++) {
Gfo_protocol_itm itm = (Gfo_protocol_itm)protocols.Get_at(i);
if (itm.Text_ends_w_colon()) { // To convert the protocol into a case-insensitive Lua pattern, we need to replace letters with a character class like [Xx] and insert a '%' before various punctuation.
KeyVal kv = Init_nowiki_protocols_itm(bfr, itm);
Keyval kv = Init_nowiki_protocols_itm(bfr, itm);
rv.Add(kv);
}
}
bfr.Mkr_rls();
return (KeyVal[])rv.To_ary(KeyVal.class);
return (Keyval[])rv.To_ary(Keyval.class);
}
private static KeyVal Init_nowiki_protocols_itm(Bry_bfr bfr, Gfo_protocol_itm itm) {
private static Keyval Init_nowiki_protocols_itm(Bry_bfr bfr, Gfo_protocol_itm itm) {
byte[] key = itm.Key_wo_colon_bry();
int end = key.length - 1; // -1 to ignore final colon
for (int i = 0; i < end; i++) {
@@ -62,6 +62,6 @@ class Scrib_lib_text_ {
}
}
bfr.Add(Colon_encoded);
return KeyVal_.new_(itm.Key_wo_colon_str(), bfr.To_str_and_clear());
return Keyval_.new_(itm.Key_wo_colon_str(), bfr.To_str_and_clear());
} private static final byte[] Colon_encoded = Bry_.new_a7("&#58;");
}

View File

@@ -19,7 +19,7 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
import gplx.langs.jsons.*;
class Scrib_lib_text__json_util {
private final Json_wtr wtr = new Json_wtr();
public void Reindex_arrays(Scrib_lib_text__reindex_data rv, KeyVal[] kv_ary, boolean is_encoding) {
public void Reindex_arrays(Scrib_lib_text__reindex_data rv, Keyval[] kv_ary, boolean is_encoding) {
int next = 0;
if (is_encoding) {
Array_.Sort(kv_ary, KeyVal__sorter__key_is_numeric.Instance);
@@ -28,10 +28,10 @@ class Scrib_lib_text__json_util {
boolean is_sequence = true;
int len = kv_ary.length;
for (int i = 0; i < len; ++i) {
KeyVal kv = kv_ary[i];
Keyval kv = kv_ary[i];
Object kv_val = kv.Val();
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), KeyVal[].class)) {
Reindex_arrays(rv, (KeyVal[])kv_val, is_encoding);
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), Keyval[].class)) {
Reindex_arrays(rv, (Keyval[])kv_val, is_encoding);
if (!rv.Rv_is_kvy())
kv.Val_(rv.Rv_as_ary());
}
@@ -62,23 +62,23 @@ class Scrib_lib_text__json_util {
}
rv.Init(Bool_.Y, kv_ary, null);
}
private static Object[] To_array_values(KeyVal[] ary) {
private static Object[] To_array_values(Keyval[] ary) {
int len = ary.length;
Object[] rv = new Object[len];
for (int i = 0; i < len; ++i) {
KeyVal itm = ary[i];
Keyval itm = ary[i];
rv[i] = itm.Val();
}
return rv;
}
private static void Convert_to_base1(KeyVal[] ary) {
private static void Convert_to_base1(Keyval[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
KeyVal itm = ary[i];
Keyval itm = ary[i];
itm.Key_(i + 1);
}
}
public KeyVal[] Decode_rslt_as_nde() {return decode_rslt_as_nde;} private KeyVal[] decode_rslt_as_nde;
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 byte Decode(Json_parser parser, byte[] src, int flag) {
synchronized (wtr) {
@@ -90,13 +90,13 @@ class Scrib_lib_text__json_util {
else {
Json_nde root = (Json_nde)jdoc.Root_grp();
int len = root.Len();
this.decode_rslt_as_nde = new KeyVal[len];
this.decode_rslt_as_nde = new Keyval[len];
for (int i = 0; i < len; ++i) {
Json_kv json_kv = root.Get_at_as_kv(i);
String kv_str = json_kv.Key_as_str();
Object kv_val = Decode_obj(json_kv.Val());
int kv_int = Int_.parse_or(kv_str, Int_.Min_value);
decode_rslt_as_nde[i] = kv_int == Int_.Min_value ? KeyVal_.new_(kv_str, kv_val) : KeyVal_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
decode_rslt_as_nde[i] = kv_int == Int_.Min_value ? Keyval_.new_(kv_str, kv_val) : Keyval_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
}
return Bool_.Y_byte;
}
@@ -119,19 +119,19 @@ class Scrib_lib_text__json_util {
}
return rv;
}
private KeyVal[] Decode_nde(Json_nde nde) {
private Keyval[] Decode_nde(Json_nde nde) {
int len = nde.Len();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; ++i) {
Json_kv itm = nde.Get_at_as_kv(i);
String kv_str = itm.Key_as_str();
int kv_int = Int_.parse_or(kv_str, Int_.Min_value);
Object kv_val = Decode_obj(itm.Val());
rv[i] = kv_int == Int_.Min_value ? KeyVal_.new_(kv_str, kv_val) : KeyVal_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
rv[i] = kv_int == Int_.Min_value ? Keyval_.new_(kv_str, kv_val) : Keyval_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
}
return rv;
}
public byte[] Encode_as_nde(KeyVal[] itm, int flag, int skip) {
public byte[] Encode_as_nde(Keyval[] itm, int flag, int skip) {
synchronized (wtr ) {
wtr.Clear().Doc_nde_bgn();
Encode_kv_ary(itm);
@@ -145,19 +145,19 @@ class Scrib_lib_text__json_util {
return wtr.Doc_ary_end().To_bry_and_clear();
}
}
private void Encode_kv_ary(KeyVal[] kv_ary) {
private void Encode_kv_ary(Keyval[] kv_ary) {
int len = kv_ary.length;
for (int i = 0; i < len; ++i) {
KeyVal kv = kv_ary[i];
Keyval kv = kv_ary[i];
Encode_kv(kv);
}
}
private void Encode_kv(KeyVal kv) {
private void Encode_kv(Keyval kv) {
Object kv_val = kv.Val();
Class<?> type = Type_adp_.ClassOf_obj(kv_val);
if (Type_adp_.Eq(type, KeyVal[].class)) {
if (Type_adp_.Eq(type, Keyval[].class)) {
wtr.Nde_bgn(kv.Key());
Encode_kv_ary((KeyVal[])kv_val);
Encode_kv_ary((Keyval[])kv_val);
wtr.Nde_end();
}
else if (Type_adp_.Is_array(type)) { // encode as array
@@ -194,8 +194,8 @@ class Scrib_lib_text__json_util {
}
class KeyVal__sorter__key_is_numeric implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
KeyVal lhs_itm = (KeyVal)lhsObj;
KeyVal rhs_itm = (KeyVal)rhsObj;
Keyval lhs_itm = (Keyval)lhsObj;
Keyval rhs_itm = (Keyval)rhsObj;
int lhs_int = Int_.parse_or(lhs_itm.Key(), Int_.Min_value);
int rhs_int = Int_.parse_or(rhs_itm.Key(), Int_.Min_value);
return CompareAble_.Compare(lhs_int, rhs_int);
@@ -204,9 +204,9 @@ class KeyVal__sorter__key_is_numeric implements gplx.core.lists.ComparerAble {
}
class Scrib_lib_text__reindex_data {
public boolean Rv_is_kvy() {return rv_is_kvy;} private boolean rv_is_kvy;
public KeyVal[] Rv_as_kvy() {return rv_as_kvy;} private KeyVal[] rv_as_kvy;
public Keyval[] Rv_as_kvy() {return rv_as_kvy;} private Keyval[] rv_as_kvy;
public Object Rv_as_ary() {return rv_as_ary;} private Object rv_as_ary;
public void Init(boolean rv_is_kvy, KeyVal[] rv_as_kvy, Object rv_as_ary) {
public void Init(boolean rv_is_kvy, Keyval[] rv_as_kvy, Object rv_as_ary) {
this.rv_is_kvy = rv_is_kvy;
this.rv_as_kvy = rv_as_kvy;
this.rv_as_ary = rv_as_ary;

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.core.primitives.*;
class Scrib_lib_text_html_entities {
public static KeyVal[] new_() {
KeyVal[] rv = new KeyVal[1510];
public static Keyval[] new_() {
Keyval[] rv = new Keyval[1510];
Int_obj_ref idx = Int_obj_ref.zero_();
new_itm_(rv, idx, Bry_.New_by_ints(9), "&Tab;");
new_itm_(rv, idx, Bry_.New_by_ints(10), "&NewLine;");
@@ -1533,7 +1533,7 @@ new_itm_(rv, idx, Bry_.New_by_ints(240, 157, 149, 170), "&yopf;");
new_itm_(rv, idx, Bry_.New_by_ints(240, 157, 149, 171), "&zopf;");
return rv;
}
private static void new_itm_(KeyVal[] ary, Int_obj_ref idx, byte[] key, String val) {
ary[idx.Val_add_post()] = KeyVal_.new_(String_.new_u8(key), val);
private static void new_itm_(Keyval[] ary, Int_obj_ref idx, byte[] key, String val) {
ary[idx.Val_add_post()] = Keyval_.new_(String_.new_u8(key), val);
}
}

View File

@@ -31,7 +31,7 @@ public class Scrib_lib_text_json_tst {
( "{"
, "}"
)
, KeyVal_.Ary_empty
, Keyval_.Ary_empty
);
}
@Test public void Nde__key_obj__primitives() { // NOTE: based on MW
@@ -50,12 +50,12 @@ public class Scrib_lib_text_json_tst {
, " }"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("int", 1)
, KeyVal_.new_("String", "abc")
, KeyVal_.new_("true", true)
, KeyVal_.new_("array", new int[] {1, 2, 3})
, KeyVal_.new_("node", KeyVal_.Ary(KeyVal_.new_("key", "val")))
, Keyval_.Ary
( Keyval_.new_("int", 1)
, Keyval_.new_("String", "abc")
, Keyval_.new_("true", true)
, Keyval_.new_("array", new int[] {1, 2, 3})
, Keyval_.new_("node", Keyval_.Ary(Keyval_.new_("key", "val")))
));
}
@Test public void Nde__obj_in_obj() {
@@ -69,10 +69,10 @@ public class Scrib_lib_text_json_tst {
, " ]"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x", new Object[]
{ 1, 2, KeyVal_.Ary
( KeyVal_.new_("y", "x")
, Keyval_.Ary
( Keyval_.new_("x", new Object[]
{ 1, 2, Keyval_.Ary
( Keyval_.new_("y", "x")
)
}
)
@@ -93,10 +93,10 @@ public class Scrib_lib_text_json_tst {
, " ]"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x"
, new Object[] {1, 2, KeyVal_.Ary
( KeyVal_.new_("y"
, Keyval_.Ary
( Keyval_.new_("x"
, new Object[] {1, 2, Keyval_.Ary
( Keyval_.new_("y"
, new Object[] {3, 4}
))}))
);
@@ -109,10 +109,10 @@ public class Scrib_lib_text_json_tst {
, ", '2':2"
, "}"
)
, KeyVal_.Ary
( KeyVal_.new_("x", "x")
, KeyVal_.new_("1", 1)
, KeyVal_.new_("2", 2)
, Keyval_.Ary
( Keyval_.new_("x", "x")
, Keyval_.new_("1", 1)
, Keyval_.new_("2", 2)
));
}
@Test public void Nde__key_int__auto() {// NOTE: based on MW
@@ -193,13 +193,13 @@ public class Scrib_lib_text_json_tst {
@Test public void Nde__smoke() {
json_fxt.Test_json_encode(fxt, lib
, Scrib_lib_text__json_util.Flag__none
, KeyVal_.Ary
( KeyVal_.new_("axes", KeyVal_.Ary
( KeyVal_.int_(1, KeyVal_.Ary
( KeyVal_.new_("type", "x")
, Keyval_.Ary
( Keyval_.new_("axes", Keyval_.Ary
( Keyval_.int_(1, Keyval_.Ary
( Keyval_.new_("type", "x")
))
, KeyVal_.int_(2, KeyVal_.Ary
( KeyVal_.new_("type", "y")
, Keyval_.int_(2, Keyval_.Ary
( Keyval_.new_("type", "y")
))
))
)
@@ -216,7 +216,7 @@ public class Scrib_lib_text_json_tst {
);
}
@Test public void Decode__key__int() {
KeyVal[] kv_ary = (KeyVal[])json_fxt.Test_json_decode(fxt, lib
Keyval[] kv_ary = (Keyval[])json_fxt.Test_json_decode(fxt, lib
, Scrib_lib_text__json_util.Flag__none
, Json_doc.Make_str_by_apos
( "{ '1':"
@@ -225,15 +225,15 @@ public class Scrib_lib_text_json_tst {
, ", '2':'b'"
, "}"
)
, KeyVal_.Ary
( KeyVal_.int_(1, KeyVal_.Ary
( KeyVal_.int_(11, "aa")
, Keyval_.Ary
( Keyval_.int_(1, Keyval_.Ary
( Keyval_.int_(11, "aa")
))
, KeyVal_.int_(2, "b")
, Keyval_.int_(2, "b")
)
);
Tfds.Eq(kv_ary[0].Key_as_obj(), 1);
Tfds.Eq(((KeyVal[])kv_ary[0].Val())[0].Key_as_obj(), 11);
Tfds.Eq(((Keyval[])kv_ary[0].Val())[0].Key_as_obj(), 11);
}
}
class Scrib_lib_json_fxt {
@@ -253,7 +253,7 @@ class Scrib_lib_json_fxt {
private String To_str(Object o) {
if (o == null) return "<< NULL >>";
Class<?> type = o.getClass();
if (Type_adp_.Eq(type, KeyVal[].class)) return Kv_ary_utl.Ary_to_str(wtr, (KeyVal[])o);
if (Type_adp_.Eq(type, Keyval[].class)) return Kv_ary_utl.Ary_to_str(wtr, (Keyval[])o);
else if (Type_adp_.Is_array(type)) return Array_.To_str_nested_obj(o);
else return Object_.Xto_str_strict_or_null(o);
}

View File

@@ -28,7 +28,7 @@ public class Scrib_lib_text_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_text.Invk_unstrip, Object_.Ary("a"), "a");
}
@Test public void GetEntityTable() {
KeyVal[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
Keyval[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
Tfds.Eq(1510, actl.length); // large result; only test # of entries
}
}

View File

@@ -28,8 +28,8 @@ public class Scrib_lib_title implements Scrib_lib {
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
Init();
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.title.lua")
, KeyVal_.new_("thisTitle", "") // NOTE: pass blank; will be updated by GetCurrentTitle
, KeyVal_.new_("NS_MEDIA", Xow_ns_.Tid__media) // NOTE: MW passes down NS_MEDIA; this should be -2 on all wikis...
, Keyval_.new_("thisTitle", "") // NOTE: pass blank; will be updated by GetCurrentTitle
, Keyval_.new_("NS_MEDIA", Xow_ns_.Tid__media) // NOTE: MW passes down NS_MEDIA; this should be -2 on all wikis...
);
notify_page_changed_fnc = mod.Fncs_get_by_key("notify_page_changed");
return mod;
@@ -73,7 +73,7 @@ public class Scrib_lib_title implements Scrib_lib {
if (ttl == null) return rslt.Init_obj(null); // invalid title; exit; matches MW logic
return rslt.Init_obj(GetInexpensiveTitleData(ttl));
}
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), KeyVal_.Ary_empty);}
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);}
public boolean GetUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xowe_wiki wiki = core.Wiki();
byte[] ttl_bry = args.Pull_bry(0);
@@ -141,11 +141,11 @@ public class Scrib_lib_title implements Scrib_lib {
ttl_redirect = tmp_db_page.Redirected();
ttl_id = tmp_db_page.Id();
}
KeyVal[] rv = new KeyVal[4];
rv[ 0] = KeyVal_.new_("isRedirect" , ttl_redirect); // title.isRedirect
rv[ 1] = KeyVal_.new_("id" , ttl_id); // $title->getArticleID(),
rv[ 2] = KeyVal_.new_("contentModel" , Key_wikitexet); // $title->getContentModel(); see Defines.php and CONTENT_MODEL_
rv[ 3] = KeyVal_.new_("exists" , ttl_exists); // $ret['id'] > 0; TODO: if Special: check regy of implemented pages
Keyval[] rv = new Keyval[4];
rv[ 0] = Keyval_.new_("isRedirect" , ttl_redirect); // title.isRedirect
rv[ 1] = Keyval_.new_("id" , ttl_id); // $title->getArticleID(),
rv[ 2] = Keyval_.new_("contentModel" , Key_wikitexet); // $title->getContentModel(); see Defines.php and CONTENT_MODEL_
rv[ 3] = Keyval_.new_("exists" , ttl_exists); // $ret['id'] > 0; TODO: if Special: check regy of implemented pages
return rslt.Init_obj(rv);
}
public boolean GetFileInfo(Scrib_proc_args args, Scrib_proc_rslt rslt) {
@@ -158,20 +158,20 @@ public class Scrib_lib_title implements Scrib_lib {
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
// 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
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: get pages info
Keyval[] rv = Keyval_.Ary
( Keyval_.new_("exists" , true)
, Keyval_.new_("width" , itm.W())
, Keyval_.new_("height" , itm.H())
, Keyval_.new_("pages" , null) // TODO: 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));
public boolean GetContent(Scrib_proc_args args, Scrib_proc_rslt rslt) {
byte[] ttl_bry = args.Pull_bry(0);
Xowe_wiki wiki = core.Wiki();
@@ -204,8 +204,8 @@ public class Scrib_lib_title implements Scrib_lib {
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
return rslt.Init_obj(CascadingProtection_rv);
}
public static final KeyVal[] CascadingProtection_rv = KeyVal_.Ary(KeyVal_.new_("sources", Bool_.N), KeyVal_.new_("restrictions", KeyVal_.Ary_empty));
private KeyVal[] GetInexpensiveTitleData(Xoa_ttl ttl) {
public static final Keyval[] CascadingProtection_rv = Keyval_.Ary(Keyval_.new_("sources", Bool_.N), Keyval_.new_("restrictions", Keyval_.Ary_empty));
private Keyval[] GetInexpensiveTitleData(Xoa_ttl ttl) {
Xow_ns ns = ttl.Ns();
boolean ns_file_or_media = ns.Id_is_file_or_media(), ns_special = ns.Id_is_special();
int rv_len = 7, rv_idx = 7;
@@ -213,18 +213,18 @@ public class Scrib_lib_title implements Scrib_lib {
if (!ns_file_or_media) ++rv_len;
Xow_xwiki_itm xwiki_itm = ttl.Wik_itm();
String xwiki_str = xwiki_itm == null ? "" : xwiki_itm.Key_str();
KeyVal[] rv = new KeyVal[rv_len];
rv[ 0] = KeyVal_.new_("isLocal" , true); // title.isLocal; NOTE: always true; passing "http:" also returns true; not sure how to handle "Interwiki::fetch( $this->mInterwiki )->isLocal()"
rv[ 1] = KeyVal_.new_("interwiki" , xwiki_str); // $title->getInterwiki(),
rv[ 2] = KeyVal_.new_("namespace" , ns.Id()); // $ns,
rv[ 3] = KeyVal_.new_("nsText" , Xow_ns_canonical_.To_canonical_or_local_as_str(ns)); // $title->getNsText(), NOTE: needed b/c some modules expect English "Template"; PAGE:sh.w:Koprno DATE:2015-11-08
rv[ 4] = KeyVal_.new_("text" , ttl.Page_txt()); // $title->getText(),
rv[ 5] = KeyVal_.new_("fragment" , ttl.Anch_txt()); // $title->getFragment(),
rv[ 6] = KeyVal_.new_("thePartialUrl" , ttl.Page_db()); // $title->getPartialUrl(),
Keyval[] rv = new Keyval[rv_len];
rv[ 0] = Keyval_.new_("isLocal" , true); // title.isLocal; NOTE: always true; passing "http:" also returns true; not sure how to handle "Interwiki::fetch( $this->mInterwiki )->isLocal()"
rv[ 1] = Keyval_.new_("interwiki" , xwiki_str); // $title->getInterwiki(),
rv[ 2] = Keyval_.new_("namespace" , ns.Id()); // $ns,
rv[ 3] = Keyval_.new_("nsText" , Xow_ns_canonical_.To_canonical_or_local_as_str(ns)); // $title->getNsText(), NOTE: needed b/c some modules expect English "Template"; PAGE:sh.w:Koprno DATE:2015-11-08
rv[ 4] = Keyval_.new_("text" , ttl.Page_txt()); // $title->getText(),
rv[ 5] = Keyval_.new_("fragment" , ttl.Anch_txt()); // $title->getFragment(),
rv[ 6] = Keyval_.new_("thePartialUrl" , ttl.Page_db()); // $title->getPartialUrl(),
if (ns_special)
rv[rv_idx++] = KeyVal_.new_("exists" , false); // TODO: lookup specials
rv[rv_idx++] = Keyval_.new_("exists" , false); // TODO: lookup specials
if (!ns_file_or_media)
rv[rv_idx++] = KeyVal_.new_("file" , false); // REF.MW: if ( $ns !== NS_FILE && $ns !== NS_MEDIA ) $ret['file'] = false;
rv[rv_idx++] = Keyval_.new_("file" , false); // REF.MW: if ( $ns !== NS_FILE && $ns !== NS_MEDIA ) $ret['file'] = false;
return rv;
} private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
public static final String Key_wikitexet = "wikitext";

View File

@@ -44,7 +44,7 @@ public class Scrib_lib_title_tst {
// fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "", "http") , "http://en.wikipedia.org/wiki/Main_Page"); // TODO
}
@Test public void GetUrl__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; fr.w:Wikip<69>dia:Image_du_jour/Date; DATE:2013-12-24
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", KeyVal_.Ary(KeyVal_.new_("action", "edit"), KeyVal_.new_("preload", "b"))), "http://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", Keyval_.Ary(Keyval_.new_("action", "edit"), Keyval_.new_("preload", "b"))), "http://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
}
@Test public void MakeTitle() {
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Module", "A") , ttl_fast(828, "Module", "A"));
@@ -110,14 +110,6 @@ public class Scrib_lib_title_tst {
byte[] ttl_bry = Bry_.new_u8(ttl_str);
wiki.File__orig_mgr().Insert(Xof_repo_itm_.Repo_remote, ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty);
}
// private static void Init_page_regy(Xowe_wiki wiki, String ttl, int id, boolean is_redirect) {
// String url_str = "test/en.wikipedia.org/wiki_page_regy";
// Dbmeta_tbl_itm meta = new Xowd_page_tbl().new_meta();
// Db_conn_pool.Instance.Set_mem(url_str, meta);
// Db_conn_info url = Db_conn_info_.mem_(url_str);
// Xowd_page_tbl tbl = new Xowd_page_tbl(Bool_.N, url);
// tbl.Insert(id, ns_id, Bry_.new_u8(ttl), is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id);
// }
private static String ttl_fast(int ns_id, String ns_str, String ttl) {return ttl_fast(ns_id, ns_str, ttl, "", "", ttl);}
private static String ttl_fast(int ns_id, String ns_str, String ttl, String anchor) {return ttl_fast(ns_id, ns_str, ttl, anchor, "", ttl);}
private static String ttl_fast(int ns_id, String ns_str, String ttl, String anchor, String xwiki) {return ttl_fast(ns_id, ns_str, ttl, anchor, xwiki, ttl);}

View File

@@ -29,7 +29,7 @@ public class Scrib_lib_uri implements Scrib_lib {
notify_page_changed_fnc = mod.Fncs_get_by_key("notify_page_changed");
return mod;
} private Scrib_lua_proc notify_page_changed_fnc;
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), KeyVal_.Ary_empty);}
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);}
public Scrib_proc_mgr Procs() {return procs;} private Scrib_proc_mgr procs = new Scrib_proc_mgr();
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
switch (key) {

View File

@@ -31,7 +31,7 @@ public class Scrib_lib_uri_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("[bad]" ), Scrib_invoke_func_fxt.Null_rslt); // handle invalid titles; EX:it.w:Billy_the_Kid; DATE:2014-01-20
}
@Test public void Url__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; it.w:Astronomie; DATE:2014-01-18
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", KeyVal_.Ary(KeyVal_.new_("action", "edit"))), "//en.wikipedia.org/wiki/A?action=edit");
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", Keyval_.Ary(Keyval_.new_("action", "edit"))), "//en.wikipedia.org/wiki/A?action=edit");
}
@Test public void AnchorEncode() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_anchorEncode , Object_.Ary("[irc://a b c]" ), "b_c");

View File

@@ -29,8 +29,8 @@ public class Scrib_lib_ustring implements Scrib_lib {
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
Init();
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.ustring.lua")
, KeyVal_.new_("stringLengthLimit", string_len_max)
, KeyVal_.new_("patternLengthLimit", pattern_len_max)
, Keyval_.new_("stringLengthLimit", string_len_max)
, Keyval_.new_("patternLengthLimit", pattern_len_max)
);
return mod;
}
@@ -145,18 +145,18 @@ public class Scrib_lib_ustring implements Scrib_lib {
public boolean Gmatch_callback(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String text = args.Xstr_str_or_null(0); // NOTE: UstringLibrary.php!ustringGmatchCallback calls preg_match directly; $s can be any type, and php casts automatically;
String regx = args.Pull_str(1);
KeyVal[] capt = args.Cast_kv_ary_or_null(2);
Keyval[] capt = args.Cast_kv_ary_or_null(2);
int pos = args.Pull_int(3);
Regx_adp regx_adp = Scrib_lib_ustring.RegxAdp_new_(core.Ctx(), regx);
Regx_match[] regx_rslts = regx_adp.Match_all(text, pos);
int len = regx_rslts.length;
if (len == 0) return rslt.Init_many_objs(pos, KeyVal_.Ary_empty);
if (len == 0) return rslt.Init_many_objs(pos, Keyval_.Ary_empty);
Regx_match match = regx_rslts[0]; // NOTE: take only 1st result
List_adp tmp_list = List_adp_.new_();
AddCapturesFromMatch(tmp_list, match, text, capt, true); // NOTE: was incorrectly set as false; DATE:2014-04-23
return rslt.Init_many_objs(match.Find_end(), Scrib_kv_utl_.base1_list_(tmp_list));
}
private void AddCapturesFromMatch(List_adp tmp_list, Regx_match rslt, String text, KeyVal[] capts, boolean op_is_match) {// NOTE: this matches behavior in UstringLibrary.php!addCapturesFromMatch
private void AddCapturesFromMatch(List_adp tmp_list, Regx_match rslt, String text, Keyval[] capts, boolean op_is_match) {// NOTE: this matches behavior in UstringLibrary.php!addCapturesFromMatch
Regx_group[] grps = rslt.Groups();
int grps_len = grps.length;
int capts_len = capts == null ? 0 : capts.length;
@@ -215,16 +215,16 @@ class Scrib_lib_ustring_gsub_mgr {
tmp_repl_tid = Repl_tid_string;
tmp_repl_bry = Bry_.new_u8(Int_.To_str(Int_.cast(repl_obj)));
}
else if (Object_.Eq(repl_type, KeyVal[].class)) {
else if (Object_.Eq(repl_type, Keyval[].class)) {
tmp_repl_tid = Repl_tid_table;
KeyVal[] repl_tbl = (KeyVal[])repl_obj;
Keyval[] repl_tbl = (Keyval[])repl_obj;
if (repl_hash == null)
repl_hash = Hash_adp_.new_();
else
repl_hash.Clear();
int repl_tbl_len = repl_tbl.length;
for (int i = 0; i < repl_tbl_len; i++) {
KeyVal repl_itm = repl_tbl[i];
Keyval repl_itm = repl_tbl[i];
String repl_itm_val = repl_itm.Val_to_str_or_empty();
repl_hash.Add(repl_itm.Key(), Bry_.new_u8(repl_itm_val));
}
@@ -326,7 +326,7 @@ class Scrib_lib_ustring_gsub_mgr {
break;
}
case Repl_tid_luacbk: {
KeyVal[] luacbk_args = null;
Keyval[] luacbk_args = null;
Regx_group[] grps = match.Groups();
int grps_len = grps.length;
if (grps_len == 0) { // no match; use original String
@@ -334,14 +334,14 @@ class Scrib_lib_ustring_gsub_mgr {
luacbk_args = Scrib_kv_utl_.base1_obj_(find_str);
}
else { // match; build ary of matches; (see UStringLibrary.php)
luacbk_args = new KeyVal[grps_len];
luacbk_args = new Keyval[grps_len];
for (int i = 0; i < grps_len; i++) {
Regx_group grp = grps[i];
String find_str = String_.Mid(text, grp.Bgn(), grp.End());
luacbk_args[i] = KeyVal_.int_(i + Scrib_core.Base_1, find_str);
luacbk_args[i] = Keyval_.int_(i + Scrib_core.Base_1, find_str);
}
}
KeyVal[] rslts = core.Interpreter().CallFunction(repl_func.Id(), luacbk_args);
Keyval[] rslts = core.Interpreter().CallFunction(repl_func.Id(), luacbk_args);
tmp_bfr.Add_str_u8(Scrib_kv_utl_.Val_to_str(rslts, 0));
break;
}

View File

@@ -33,7 +33,7 @@ public class Scrib_lib_ustring__gmatch__tst {
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 8) , "1=8\n2=");
}
@Test public void Callback__nomatch() {// PURPOSE.fix: was originally returning "" instead of original String; EX:vi.d:trở_thành; DATE:2014-04-23
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a", "a" , KeyVal_.Ary_empty, 0) , "1=1\n2=\n 1=a");
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a", "a" , Keyval_.Ary_empty, 0) , "1=1\n2=\n 1=a");
}
@Test public void Callback__anypos() {// PURPOSE.fix: was not handling $capt argument; EX:vi.d:trở_thành; DATE:2014-04-23
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a bcd e", "()(b)" , Scrib_kv_utl_.base1_many_(true, false), 0), String_.Concat_lines_nl_skip_last

View File

@@ -92,7 +92,7 @@ class Mock_proc__recursive extends Mock_proc_fxt { private final Mock_scrib_fxt
this.fxt = fxt; this.lib = lib; this.inner = inner;
this.bfr = bfr;
}
@Override public KeyVal[] Exec_by_scrib(KeyVal[] args) {
@Override public Keyval[] Exec_by_scrib(Keyval[] args) {
bfr.Add_int_variable(this.Id()).Add_byte_semic();
if (inner != null)
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_("a", ".", inner.To_scrib_lua_proc(), -1), "a;1");

View File

@@ -38,7 +38,7 @@ public class Scrib_lib_ustring__match__tst {
Exec_match("" , "a?" , 1, ""); // no results with ? should return "" not nil; PAGE:en.d:民; DATE:2015-01-30
}
@Test public void Args_out_of_order() {
fxt.Test__proc__kvps__empty(lib, Scrib_lib_ustring.Invk_match, KeyVal_.Ary(KeyVal_.int_(2, "[a]")));
fxt.Test__proc__kvps__empty(lib, Scrib_lib_ustring.Invk_match, Keyval_.Ary(Keyval_.int_(2, "[a]")));
}
// @Test public void Match_viwiktionary() {
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);

View File

@@ -47,8 +47,8 @@ public class Scrib_lib_wikibase implements Scrib_lib {
}
private static final int Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_renderSnak = 3, Proc_renderSnaks = 4, Proc_getEntityId = 5, Proc_getUserLang = 6, Proc_getDescription = 7, Proc_resolvePropertyId = 8, Proc_getSiteLinkPageName = 9, Proc_incrementExpensiveFunctionCount = 10;
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount";
private static final String[] Proc_names = String_.Ary(Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount);
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), KeyVal_.Ary_empty);}
private static final String[] Proc_names = String_.Ary(Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount);
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) {
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
@@ -66,7 +66,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
byte[] ttl_bry = args.Pull_bry(0);
Xowe_wiki wiki = core.Wiki();
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
byte[] rv = wiki.Appe().Wiki_mgr().Wdata_mgr().Qids_get(wiki, ttl); if (rv == null) rv = Bry_.Empty;
byte[] rv = wiki.Appe().Wiki_mgr().Wdata_mgr().Qid_mgr.Get_or_null(wiki, ttl); if (rv == null) rv = Bry_.Empty;
return rslt.Init_obj(rv);
}
public boolean GetUserLang(Scrib_proc_args args, Scrib_proc_rslt rslt) {
@@ -88,13 +88,13 @@ public class Scrib_lib_wikibase implements Scrib_lib {
Xow_domain_itm domain_itm = core.Wiki().Domain_itm();
return rslt.Init_obj(wdoc.Slink_list__get_or_fallback(domain_itm.Abrv_wm()));
}
public boolean IncrementExpensiveFunctionCount(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(KeyVal_.Ary_empty);} // NOTE: for now, always return null (XOWA does not care about expensive parser functions)
public boolean IncrementExpensiveFunctionCount(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(Keyval_.Ary_empty);} // NOTE: for now, always return null (XOWA does not care about expensive parser functions)
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 Wdata_doc Get_wdoc(byte[] ttl_bry) {
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Pages_get_by_ttl_name(ttl_bry);
if (wdoc == null) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), ttl_bry);
private Wdata_doc Get_wdoc(byte[] xid_bry) {
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Doc_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
if (wdoc == null) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), xid_bry);
return wdoc;
}
}

View File

@@ -37,7 +37,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
}
private static final int Proc_getGlobalSiteId = 0, Proc_formatPropertyValues = 1;
public static final String Invk_getGlobalSiteId = "getGlobalSiteId", Invk_formatPropertyValues = "formatPropertyValues";
private static final String[] Proc_names = String_.Ary(Invk_getGlobalSiteId, Invk_formatPropertyValues);
private static final String[] Proc_names = String_.Ary(Invk_getGlobalSiteId, Invk_formatPropertyValues);
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
}
@@ -47,13 +47,13 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
Xoae_app app = core.App(); Xowe_wiki wiki = core.Wiki();
Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr();
byte[] lang = wiki.Wdata_wiki_lang();
Wdata_doc wdoc = wdata_mgr.Pages_get(qid); if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), qid); return rslt.Init_str_empty();} // NOTE: return empty String, not nil; PAGE:fr.s:Henri_Bergson; DATE:2014-08-13
int pid_int = wdata_mgr.Pids__parse_as_int_or_null(pid); // parse as num; EX: p123 -> 123; PAGE:hr.w:Hepatitis DATE:2015-11-08
if (pid_int == Wdata_wiki_mgr.Pid_null) pid_int = wdata_mgr.Pids__get_by_name(lang, pid); // parse as name; EX: name > 123
Wdata_doc wdoc = wdata_mgr.Doc_mgr.Get_by_bry_or_null(qid); if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), qid); return rslt.Init_str_empty();} // NOTE: return empty String, not nil; PAGE:fr.s:Henri_Bergson; DATE:2014-08-13
int pid_int = Wbase_pid_mgr.To_int_or_null(pid); // parse as num; EX: p123 -> 123; PAGE:hr.w:Hepatitis DATE:2015-11-08
if (pid_int == Wdata_wiki_mgr.Pid_null) pid_int = wdata_mgr.Pid_mgr.Get_or_null(lang, pid); // parse as name; EX: name > 123
if (pid_int == Wdata_wiki_mgr.Pid_null) return rslt.Init_str_empty();
Wdata_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty();
Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512();
wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang);
return rslt.Init_obj(bfr.To_bry_and_rls());
}
}
}

View File

@@ -28,7 +28,7 @@ public class Scrib_lib_wikibase_entity_tst {
}
@Test public void FormatPropertyValues() {
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_str(3, "P3_val")).Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_str(3, "P3_val")).Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3") , "P3_val"); // lookup by id
wdata_fxt.Init_pids_add("en", "P3_val", 3);
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3_val") , "P3_val"); // lookup by name

View File

@@ -18,111 +18,111 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
class Scrib_lib_wikibase_srl {
public static KeyVal[] Srl(Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
public static Keyval[] Srl(Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
int base_adj = legacy_style ? 0 : 1;
List_adp rv = List_adp_.new_();
if (header_enabled) {
rv.Add(KeyVal_.new_("id", wdoc.Qid()));
rv.Add(KeyVal_.new_("type", Wdata_dict_value_entity_tid.Str_item));
rv.Add(KeyVal_.new_("schemaVersion", base_adj + 1)); // NOTE: needed by mw.wikibase.lua
rv.Add(Keyval_.new_("id", wdoc.Qid()));
rv.Add(Keyval_.new_("type", Wdata_dict_value_entity_tid.Str_item));
rv.Add(Keyval_.new_("schemaVersion", base_adj + 1)); // NOTE: needed by mw.wikibase.lua
}
Srl_root(rv, Wdata_doc_parser_v2.Str_labels , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Label_list()));
Srl_root(rv, Wdata_doc_parser_v2.Str_descriptions , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Descr_list()));
Srl_root(rv, Wdata_doc_parser_v2.Str_sitelinks , Srl_sitelinks (Wdata_dict_sitelink.Str_site , Wdata_dict_sitelink.Str_title, wdoc.Slink_list(), base_adj));
Srl_root(rv, Wdata_doc_parser_v2.Str_aliases , Srl_aliases (base_adj, wdoc.Alias_list()));
Srl_root(rv, Wdata_doc_parser_v2.Str_claims , Srl_claims (base_adj, legacy_style, wdoc.Claim_list()));
return (KeyVal[])rv.To_ary(KeyVal.class);
return (Keyval[])rv.To_ary(Keyval.class);
}
private static void Srl_root(List_adp rv, String label, KeyVal[] ary) {
private static void Srl_root(List_adp rv, String label, Keyval[] ary) {
if (ary == null) return; // don't add node if empty; EX: labels:{} should not add "labels" kv
rv.Add(KeyVal_.new_(label, ary));
rv.Add(Keyval_.new_(label, ary));
}
private static KeyVal[] Srl_langtexts(String lang_label, String text_label, Ordered_hash list) {
private static Keyval[] Srl_langtexts(String lang_label, String text_label, Ordered_hash list) {
int len = list.Count(); if (len == 0) return null;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_langtext_itm itm = (Wdata_langtext_itm)list.Get_at(i);
String lang = String_.new_u8(itm.Lang());
String text = String_.new_u8(itm.Text());
rv[i] = KeyVal_.new_(lang, KeyVal_.Ary(KeyVal_.new_(lang_label, lang), KeyVal_.new_(text_label, text)));
rv[i] = Keyval_.new_(lang, Keyval_.Ary(Keyval_.new_(lang_label, lang), Keyval_.new_(text_label, text)));
}
return rv;
}
private static KeyVal[] Srl_sitelinks(String key_label, String val_label, Ordered_hash list, int base_adj) {
private static Keyval[] Srl_sitelinks(String key_label, String val_label, Ordered_hash list, int base_adj) {
int len = list.Count(); if (len == 0) return null;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.Get_at(i);
String site = String_.new_u8(itm.Site());
String name = String_.new_u8(itm.Name());
rv[i] = KeyVal_.new_(site, KeyVal_.Ary(KeyVal_.new_(key_label, site), KeyVal_.new_(val_label, name), Srl_sitelinks_badges(itm.Badges(), base_adj)));
rv[i] = Keyval_.new_(site, Keyval_.Ary(Keyval_.new_(key_label, site), Keyval_.new_(val_label, name), Srl_sitelinks_badges(itm.Badges(), base_adj)));
}
return rv;
}
private static KeyVal Srl_sitelinks_badges(byte[][] badges, int base_adj) { // DATE:2014-11-13
private static Keyval Srl_sitelinks_badges(byte[][] badges, int base_adj) { // DATE:2014-11-13
if (badges == null) badges = Bry_.Ary_empty; // null badges -> badges:[]
int len = badges.length;
KeyVal[] kvs = len == 0 ? KeyVal_.Ary_empty : new KeyVal[len];
Keyval[] kvs = len == 0 ? Keyval_.Ary_empty : new Keyval[len];
for (int i = 0; i < len; i++) {
byte[] badge = badges[i];
kvs[i] = KeyVal_.int_(i + base_adj, String_.new_u8(badge));
kvs[i] = Keyval_.int_(i + base_adj, String_.new_u8(badge));
}
return KeyVal_.new_("badges", kvs);
return Keyval_.new_("badges", kvs);
}
private static KeyVal[] Srl_aliases(int base_adj, Ordered_hash list) {
private static Keyval[] Srl_aliases(int base_adj, Ordered_hash list) {
int len = list.Count(); if (len == 0) return null;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_alias_itm itm = (Wdata_alias_itm)list.Get_at(i);
String lang = String_.new_u8(itm.Lang());
rv[i] = KeyVal_.new_(lang, Srl_aliases_langs(base_adj, lang, itm.Vals()));
rv[i] = Keyval_.new_(lang, Srl_aliases_langs(base_adj, lang, itm.Vals()));
}
return rv;
}
private static KeyVal[] Srl_aliases_langs(int base_adj, String lang, byte[][] ary) {
private static Keyval[] Srl_aliases_langs(int base_adj, String lang, byte[][] ary) {
int len = ary.length;
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
byte[] itm = ary[i];
rv[i] = KeyVal_.int_(i + base_adj, KeyVal_.Ary(KeyVal_.new_(Wdata_dict_langtext.Str_language, lang), KeyVal_.new_(Wdata_dict_langtext.Str_value, String_.new_u8(itm)))); // NOTE: using same base_adj logic as claims
rv[i] = Keyval_.int_(i + base_adj, Keyval_.Ary(Keyval_.new_(Wdata_dict_langtext.Str_language, lang), Keyval_.new_(Wdata_dict_langtext.Str_value, String_.new_u8(itm)))); // NOTE: using same base_adj logic as claims
}
return rv;
}
private static KeyVal[] Srl_claims(int base_adj, boolean legacy_style, Ordered_hash claim_grps) {
private static Keyval[] Srl_claims(int base_adj, boolean legacy_style, Ordered_hash claim_grps) {
int len = claim_grps.Count(); if (len == 0) return null;
int rv_len = legacy_style ? len * 2 : len; // NOTE: legacyStyle returns 2 sets of properties: official "P" and legacy "p"; DATE:2014-05-11
KeyVal[] rv = new KeyVal[rv_len];
Keyval[] rv = new Keyval[rv_len];
for (int i = 0; i < len; i++) {
Wdata_claim_grp grp = (Wdata_claim_grp)claim_grps.Get_at(i);
String pid_str = Int_.To_str(grp.Id());
KeyVal[] grp_val = Srl_claims_prop_grp("P" + pid_str, grp, base_adj);
rv[i] = KeyVal_.new_("P" + pid_str, grp_val);
Keyval[] grp_val = Srl_claims_prop_grp("P" + pid_str, grp, base_adj);
rv[i] = Keyval_.new_("P" + pid_str, grp_val);
if (legacy_style)
rv[i + len] = KeyVal_.new_("p" + pid_str, grp_val); // SEE:WikibaseLuaBindings.php; This is a B/C hack to allow existing lua code to use hardcoded IDs in both lower (legacy) and upper case.; DATE:2014-05-11
rv[i + len] = Keyval_.new_("p" + pid_str, grp_val); // SEE:WikibaseLuaBindings.php; This is a B/C hack to allow existing lua code to use hardcoded IDs in both lower (legacy) and upper case.; DATE:2014-05-11
}
return rv;
}
private static KeyVal[] Srl_claims_prop_grp(String pid, Wdata_claim_grp grp, int base_adj) {
private static Keyval[] Srl_claims_prop_grp(String pid, Wdata_claim_grp grp, int base_adj) {
int len = grp.Len();
KeyVal[] rv = new KeyVal[len];
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
Wdata_claim_itm_core itm = grp.Get_at(i);
rv[i] = KeyVal_.int_(i + base_adj, Srl_claims_prop_itm(pid, itm, base_adj)); // NOTE: must be super 0 or super 1; DATE:2014-05-09
rv[i] = Keyval_.int_(i + base_adj, Srl_claims_prop_itm(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(String pid, Wdata_claim_itm_core itm, int base_adj) {
private static Keyval[] Srl_claims_prop_itm(String pid, Wdata_claim_itm_core itm, int base_adj) {
List_adp list = List_adp_.new_();
list.Add(KeyVal_.new_("id", pid));
list.Add(KeyVal_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm)));
list.Add(KeyVal_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid())));
list.Add(KeyVal_.new_("type", itm.Prop_type()));
list.Add(Keyval_.new_("id", pid));
list.Add(Keyval_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm)));
list.Add(Keyval_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid())));
list.Add(Keyval_.new_("type", itm.Prop_type()));
Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(itm.Qualifiers(), base_adj));
return (KeyVal[])list.To_ary_and_clear(KeyVal.class);
return (Keyval[])list.To_ary_and_clear(Keyval.class);
}
private static KeyVal[] Srl_qualifiers(Wdata_claim_grp_list list, int base_adj) {
private static Keyval[] Srl_qualifiers(Wdata_claim_grp_list list, int base_adj) {
if (list == null) return null;
int list_len = list.Len(); if (list_len == 0) return KeyVal_.Ary_empty;
int list_len = list.Len(); if (list_len == 0) return Keyval_.Ary_empty;
List_adp rv = List_adp_.new_();
List_adp pid_list = List_adp_.new_();
for (int i = 0; i < list_len; ++i) {
@@ -132,25 +132,25 @@ class Scrib_lib_wikibase_srl {
String itm_pid = grp.Id_str();
for (int j = 0; j < grp_len; ++j) {
Wdata_claim_itm_core itm = grp.Get_at(j);
pid_list.Add(KeyVal_.int_(j + base_adj, Srl_claims_prop_itm_core(itm_pid, itm))); // NOTE: was originally "+ 1"; changed to base_adj; PAGE:ru.w:Tor ru.w:Кактусовые DATE:2014-10-25
pid_list.Add(Keyval_.int_(j + base_adj, Srl_claims_prop_itm_core(itm_pid, itm))); // NOTE: was originally "+ 1"; changed to base_adj; PAGE:ru.w:Tor ru.w:Кактусовые DATE:2014-10-25
}
rv.Add(KeyVal_.new_(itm_pid, (KeyVal[])pid_list.To_ary_and_clear(KeyVal.class)));
rv.Add(Keyval_.new_(itm_pid, (Keyval[])pid_list.To_ary_and_clear(Keyval.class)));
}
return (KeyVal[])rv.To_ary_and_clear(KeyVal.class);
return (Keyval[])rv.To_ary_and_clear(Keyval.class);
}
private static KeyVal[] Srl_claims_prop_itm_core(String pid, Wdata_claim_itm_core itm) {
private static Keyval[] Srl_claims_prop_itm_core(String pid, Wdata_claim_itm_core itm) {
boolean snak_is_valued = itm.Snak_tid() == Wdata_dict_snak_tid.Tid_value; // PURPOSE: was != Wdata_dict_snak_tid.Tid_novalue; PAGE:it.s:Autore:Anonimo DATE:2015-12-06
int snak_is_valued_adj = snak_is_valued ? 1 : 0;
KeyVal[] rv = new KeyVal[3 + snak_is_valued_adj];
Keyval[] rv = new Keyval[3 + snak_is_valued_adj];
if (snak_is_valued) // NOTE: novalue must not return slot (no datavalue node in json); PAGE:ru.w:Лимонов,_Эдуард_Вениаминович; DATE:2015-02-16; ALSO: sv.w:Joseph_Jaquet; DATE:2015-07-31
rv[0] = KeyVal_.new_("datavalue", Srl_claims_prop_itm_core_val(itm));
rv[0 + snak_is_valued_adj] = KeyVal_.new_("property", pid);
rv[1 + snak_is_valued_adj] = KeyVal_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid()));
rv[2 + snak_is_valued_adj] = KeyVal_.new_("datatype", Wdata_dict_val_tid.To_str__srl(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
rv[0] = Keyval_.new_("datavalue", Srl_claims_prop_itm_core_val(itm));
rv[0 + snak_is_valued_adj] = Keyval_.new_("property", pid);
rv[1 + snak_is_valued_adj] = Keyval_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid()));
rv[2 + snak_is_valued_adj] = Keyval_.new_("datatype", Wdata_dict_val_tid.To_str__srl(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
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) {
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: return Datavalue_somevalue;
case Wdata_dict_snak_tid.Tid_novalue: return Datavalue_novalue; // TODO: throw exc
@@ -160,6 +160,6 @@ class Scrib_lib_wikibase_srl {
}
}
public static final String Key_type = "type", Key_value = "value";
private static final KeyVal[] Datavalue_somevalue = KeyVal_.Ary_empty; // changed to not return value-node; PAGE:it.s:Autore:Anonimo DATE:2015-12-06 // new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
private static final KeyVal[] Datavalue_novalue = KeyVal_.Ary_empty;
private static final Keyval[] Datavalue_somevalue = Keyval_.Ary_empty; // changed to not return value-node; PAGE:it.s:Autore:Anonimo DATE:2015-12-06 // new Keyval[] {Keyval_.new_(Key_type, ""), Keyval_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
private static final Keyval[] Datavalue_novalue = Keyval_.Ary_empty;
}

View File

@@ -391,36 +391,36 @@ class Scrib_lib_wikibase_srl_fxt {
public Scrib_lib_wikibase_srl_fxt Init_prop(Wdata_claim_itm_core prop) {wdoc_bldr.Add_claims(prop); return this;}
public Scrib_lib_wikibase_srl_fxt Test(String... expd) {return Test(false, expd);}
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, String... expd) {
KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(wdoc_bldr.Xto_wdoc(), header_enabled, base0);
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(wdoc_bldr.Xto_wdoc(), header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
public Scrib_lib_wikibase_srl_fxt Test(Wdata_doc wdoc, String... expd) {return Test(false, wdoc, expd);}
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, Wdata_doc wdoc, String... expd) {
KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(wdoc, header_enabled, base0);
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(wdoc, header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
private String Xto_str(KeyVal[] ary) {
private String Xto_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr.new_();
Xto_str(bfr, ary, 0);
return bfr.To_str_and_clear();
}
private void Xto_str(Bry_bfr bfr, KeyVal[] ary, int depth) {
private void Xto_str(Bry_bfr bfr, Keyval[] ary, int depth) {
int len = ary.length;
for (int i = 0; i < len; i++) {
KeyVal kv = ary[i];
Keyval kv = ary[i];
Xto_str(bfr, kv, depth);
}
}
private void Xto_str(Bry_bfr bfr, KeyVal kv, int depth) {
private void Xto_str(Bry_bfr bfr, Keyval kv, int depth) {
bfr.Add_byte_repeat(Byte_ascii.Space, depth * 2);
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
Object kv_val = kv.Val();
if (kv_val == null) {bfr.Add_str_a7("null").Add_byte_nl(); return;}
Class<?> kv_val_cls = kv_val.getClass();
if (Type_adp_.Eq(kv_val_cls, KeyVal[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (KeyVal[])kv_val, depth + 1);}
else if (Type_adp_.Eq(kv_val_cls, KeyVal[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (KeyVal)kv_val, depth + 1);}
if (Type_adp_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval[])kv_val, depth + 1);}
else if (Type_adp_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval)kv_val, depth + 1);}
else bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(Object_.Xto_str_strict_or_empty(kv_val)).Add_byte(Byte_ascii.Apos).Add_byte_nl();
}
}

View File

@@ -18,78 +18,78 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.scribunto.libs; 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 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_u8(itm.Val_str()));
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_u8(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));
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) {
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, claim_entity.Entity_tid_str());
rv[1] = KeyVal_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.To_str(claim_entity.Entity_id()));
Keyval[] rv = new Keyval[2];
rv[0] = Keyval_.new_(Wdata_dict_value_entity.Str_entity_type, claim_entity.Entity_tid_str());
rv[1] = Keyval_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.To_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_val_tid.Str_monolingualtext);
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm));
rv = new Keyval[2];
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_monolingualtext);
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_u8(itm.Text()));
rv[1] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_u8(itm.Lang()));
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_u8(itm.Text()));
rv[1] = Keyval_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_u8(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));
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 , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
rv[1] = KeyVal_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_u8(itm.Unit()));
rv[2] = KeyVal_.new_(Wdata_dict_value_quantity.Str_upperbound , itm.Ubound_as_num().To_str());
rv[3] = KeyVal_.new_(Wdata_dict_value_quantity.Str_lowerbound , itm.Lbound_as_num().To_str());
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 , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
rv[1] = Keyval_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_u8(itm.Unit()));
rv[2] = Keyval_.new_(Wdata_dict_value_quantity.Str_upperbound , itm.Ubound_as_num().To_str());
rv[3] = Keyval_.new_(Wdata_dict_value_quantity.Str_lowerbound , itm.Lbound_as_num().To_str());
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));
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_a7(itm.Time()));
rv[1] = KeyVal_.new_(Wdata_dict_value_time.Str_precision , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
rv[2] = KeyVal_.new_(Wdata_dict_value_time.Str_before , itm.Before_int());
rv[3] = KeyVal_.new_(Wdata_dict_value_time.Str_after , itm.After_int());
rv[4] = KeyVal_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
rv[5] = KeyVal_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str);
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_a7(itm.Time()));
rv[1] = Keyval_.new_(Wdata_dict_value_time.Str_precision , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
rv[2] = Keyval_.new_(Wdata_dict_value_time.Str_before , itm.Before_int());
rv[3] = Keyval_.new_(Wdata_dict_value_time.Str_after , itm.After_int());
rv[4] = Keyval_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
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));
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_a7(itm.Lat())));
rv[1] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse(String_.new_a7(itm.Lng())));
rv[2] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_altitude , String_.new_u8(itm.Alt()));
rv[3] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_globe , String_.new_u8(itm.Glb()));
rv[4] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_precision , itm.Prc_as_num().To_double());
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_a7(itm.Lat())));
rv[1] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse(String_.new_a7(itm.Lng())));
rv[2] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_altitude , String_.new_u8(itm.Alt()));
rv[3] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_globe , String_.new_u8(itm.Glb()));
rv[4] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_precision , itm.Prc_as_num().To_double());
return rv;
}
public void Visit_system(Wdata_claim_itm_system itm) {
rv = KeyVal_.Ary_empty;
rv = Keyval_.Ary_empty;
}
}

View File

@@ -19,8 +19,8 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
import org.junit.*;
import gplx.xowa.xtns.wdatas.*;
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();
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();
@Before public void init() {
fxt.Clear_for_lib("en.wikipedia.org", "zh-hans");
lib = fxt.Core().Lib_wikibase().Init();
@@ -36,31 +36,31 @@ public class Scrib_lib_wikibase_tst {
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("missing_page" ), "");
}
@Test public void GetLabel__cur() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hans", "s").Add_label("zh-hant", "t").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hans", "s").Add_label("zh-hant", "t").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "s"); // do not get fallback
}
@Test public void GetLabel__fallback_1() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hant", "t").Add_label("zh-hk", "h").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hant", "t").Add_label("zh-hk", "h").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "t"); // get 1st fallback
}
@Test public void GetLabel__fallback_2() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hk", "hk").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hk", "hk").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "hk"); // get 2nd fallback
}
@Test public void GetLabel__fallback_en() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "en").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "en").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "en"); // get en
}
@Test public void GetDescr() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_description("zh-hans", "s").Add_description("zh-hant", "t").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_description("zh-hans", "s").Add_description("zh-hant", "t").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getDescription, Object_.Ary("q2"), "s");
}
@Test public void GetSlink() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_sitelink("enwiki", "a").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_sitelink("enwiki", "a").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getSiteLinkPageName, Object_.Ary("q2"), "a");
}
@Test public void GetEntity() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl_skip_last
( "1="
, " id=q2"
@@ -73,7 +73,7 @@ public class Scrib_lib_wikibase_tst {
));
}
@Test public void GetEntity_property() { // PURPOSE: getEntity should be able to convert "p2" to "Property:P2"; EX:es.w:Arnold_Gesell; DATE:2014-02-18
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("en", "b").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("en", "b").Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("p2", false), String_.Concat_lines_nl_skip_last
( "1="
, " id=Property:p2" // only difference from above
@@ -86,7 +86,7 @@ public class Scrib_lib_wikibase_tst {
));
}
@Test public void ResolvePropertyId() {
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("zh-hans", "prop_a").Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("zh-hans", "prop_a").Xto_wdoc());
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_resolvePropertyId, Object_.Ary("p2"), "prop_a");
}
}

View File

@@ -23,7 +23,7 @@ public class Scrib_regx_converter {
public Scrib_regx_converter() {Init();}
public String Regx() {return regx;} private String regx;
public List_adp Capt_list() {return capt_list;}
public KeyVal[] Capt_ary() {return capt_list.Count() == 0 ? null : (KeyVal[])capt_list.To_ary(KeyVal.class);}
public Keyval[] Capt_ary() {return capt_list.Count() == 0 ? null : (Keyval[])capt_list.To_ary(Keyval.class);}
private Bry_fmtr fmtr_balanced; private Bry_bfr bfr_balanced;
public String Parse(byte[] src, byte[] anchor) {
int len = src.length;
@@ -48,7 +48,7 @@ public class Scrib_regx_converter {
if (i + 1 >= len) throw Err_.new_wo_type("Unmatched open-paren at pattern character " + Int_.To_str(i));
boolean capt_itm = src[i + 1] == Byte_ascii.Paren_end; // current is "()"
++grps_len;
capt_list.Add(KeyVal_.int_(grps_len, capt_itm));
capt_list.Add(Keyval_.int_(grps_len, capt_itm));
bfr.Add_byte(Byte_ascii.Paren_bgn);
grps_open.Add(grps_len);
grps_parens.Add(i + 1);
@@ -99,7 +99,6 @@ public class Scrib_regx_converter {
case Byte_ascii.Ltr_f: { // EX: lua frontier pattern; "%f[%a]"; DATE:2015-07-21
++i;
if (i + 1 >= len || src[i] != Byte_ascii.Brack_bgn) throw Err_.new_("scribunto", "missing '[' after %f in pattern at pattern character $ii");
// %f always followed by bracketed term; convert lua bracketed term to regex
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
i = bracketedCharSetToRegex(tmp_bfr, src, i, len);

View File

@@ -66,4 +66,4 @@ class Scrib_regx_converter_fxt {
String actl = Regx_adp_.Replace(text, regex_str, replace);
Tfds.Eq(expd, actl);
}
}
}

View File

@@ -74,8 +74,8 @@ public class Xop_languages_xnde implements Xox_xnde {
fmtr_mgr_itms.Init(langs, ctx.Wiki(), root_ttl, ctx.Page().Lang().Key_bry());
fmtr_all.Bld_bfr_many(bfr, "Other languages", fmtr_mgr_itms);
}
private static final Xop_languages_fmtr fmtr_mgr_itms = new Xop_languages_fmtr();
public static final Bry_fmtr fmtr_all = Bry_fmtr.new_(String_.Concat_lines_nl
private static final Xop_languages_fmtr fmtr_mgr_itms = new Xop_languages_fmtr();
public static final Bry_fmtr fmtr_all = Bry_fmtr.new_(String_.Concat_lines_nl
( "<table>"
, " <tbody>"
, " <tr valign=\"top\">"
@@ -120,7 +120,7 @@ class Xop_languages_fmtr implements gplx.core.brys.Bfr_arg {
byte[] lang_ttl_bry = lang_is_en ? root_ttl_bry : Bry_.Add_w_dlm(Xoa_ttl.Subpage_spr, root_ttl_bry, lang_key);
Xoa_ttl lang_ttl = Xoa_ttl.parse(wiki, ns_id, lang_ttl_bry);
byte[] lang_href = href_wtr.Build_to_bry(wiki, lang_ttl);
byte[] lang_title = Xoh_html_wtr.Ttl_to_title(lang_ttl.Full_txt());
byte[] lang_title = Xoh_html_wtr.Ttl_to_title(lang_ttl.Full_txt_w_ttl_case());
Bry_fmtr fmtr = null;
if (Bry_.Eq(lang_key, Xol_lang_itm_.Key_en)) fmtr = Xop_languages_xnde.fmtr_itm_english;
else if (Bry_.Eq(lang_key, cur_lang)) fmtr = Xop_languages_xnde.fmtr_itm_selected;

View File

@@ -0,0 +1,60 @@
/*
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.*;
public class Wbase_doc_mgr {
private final Xoae_app app;
private final Wdata_wiki_mgr wbase_mgr;
private final Wbase_qid_mgr qid_mgr;
private final gplx.xowa.apps.caches.Wdata_doc_cache hash;
public Wbase_doc_mgr(Xoae_app app, Wdata_wiki_mgr wbase_mgr, Wbase_qid_mgr qid_mgr) {
this.app = app; this.wbase_mgr = wbase_mgr; this.qid_mgr = qid_mgr;
this.hash = app.Cache_mgr().Doc_cache();
}
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
public void Clear() {hash.Clear();}
public void Add(byte[] full_db, Wdata_doc page) {hash.Add(full_db, page);} // TEST:
public Wdata_doc Get_by_ttl_or_null(Xowe_wiki wiki, Xoa_ttl ttl) {
byte[] qid_bry = qid_mgr.Get_or_null(wiki, ttl); // EX: "enwiki","Earth" -> "Q2"
return qid_bry == null ? null : this.Get_by_bry_or_null(qid_bry);
}
public Wdata_doc Get_by_xid_or_null(byte[] xid) {return Get_by_bry_or_null(Prepend_property_if_needed(xid));}// scribunto passes either p1 or q1; convert p1 to "Property:P1"
public Wdata_doc Get_by_bry_or_null(byte[] full_db) { // must be format like "Q2" or "Property:P1"
Wdata_doc rv = hash.Get_or_null(full_db);
if (rv == null) {
byte[] page_src = Load_or_null(full_db); if (page_src == null) return null; // page not found
rv = new Wdata_doc(full_db, wbase_mgr, wbase_mgr.Jdoc_parser().Parse(page_src));
Add(full_db, rv);
}
return rv;
}
private byte[] Load_or_null(byte[] full_db) {
if (!enabled) return null;
Xoa_ttl page_ttl = Xoa_ttl.parse(wbase_mgr.Wdata_wiki(), full_db); if (page_ttl == null) {app.Usr_dlg().Warn_many("", "", "invalid qid for ttl: qid=~{0}", full_db); return null;}
Xoae_page page_itm = wbase_mgr.Wdata_wiki().Data_mgr().Get_page(page_ttl, false);
return page_itm.Missing() ? null : page_itm.Data_raw();
}
private 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
&& Byte_ascii.Is_num(bry[1])
? Bry_.Add(Wdata_wiki_mgr.Ns_property_name_bry, Byte_ascii.Colon_bry, bry) // if ttl starts with "p#", prepend "Property:" to get "Property:P#"; NOTE: do not ucase P b/c it breaks a test; DATE:2014-02-18
: bry;
}
}

View File

@@ -0,0 +1,46 @@
/*
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.*;
public class Wbase_pid_mgr { // EX: "en|road_map" -> 15 ("Property:P15")
private final Wdata_wiki_mgr wbase_mgr;
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Wbase_pid_mgr(Wdata_wiki_mgr wbase_mgr) {this.wbase_mgr = wbase_mgr;}
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
public void Clear() {hash.Clear();}
public void Add(byte[] pid_key, int pid_id) {hash.Add_bry_int(pid_key, pid_id);}
public int Get_or_null(byte[] lang_key, byte[] pid_name) {
if (!enabled) return Wdata_wiki_mgr.Pid_null;
byte[] pid_key = Bry_.Add(lang_key, Byte_ascii.Pipe_bry, pid_name); // EX: "en|road_map"
int rv = hash.Get_as_int_or(pid_key, -1);
if (rv == -1) {
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_pid(lang_key, pid_name); if (rv == Wdata_wiki_mgr.Pid_null) return rv;
Add(pid_key, rv);
}
return rv;
}
public static int To_int_or_null(byte[] pid_ttl) { // EX: "p123" -> "123"
int len = pid_ttl.length; if (len == 0) return Wdata_wiki_mgr.Pid_null;
byte ltr_p = pid_ttl[0]; // make sure 1st char is "P" or "p"
switch (ltr_p) {
case Byte_ascii.Ltr_P:
case Byte_ascii.Ltr_p: break;
default: return Wdata_wiki_mgr.Pid_null;
}
return Bry_.To_int_or(pid_ttl, 1, len, Wdata_wiki_mgr.Pid_null);
}
}

View File

@@ -0,0 +1,47 @@
/*
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.wikis.domains.*;
public class Wbase_qid_mgr {// EX: "enwiki|0|Earth" -> "Q2"
private final Wdata_wiki_mgr wbase_mgr;
private final Hash_adp_bry hash = Hash_adp_bry.cs();
private final gplx.core.primitives.Int_obj_ref tmp_wiki_tid = gplx.core.primitives.Int_obj_ref.zero_();
public Wbase_qid_mgr(Wdata_wiki_mgr wbase_mgr) {
this.wbase_mgr = wbase_mgr;
}
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
public void Clear() {hash.Clear();}
public void Add(Bry_bfr bfr, byte[] lang_key, int wiki_tid, byte[] ns_num, byte[] ttl, byte[] qid) { // TEST:
Xow_abrv_wm_.To_abrv(bfr, lang_key, tmp_wiki_tid.Val_(wiki_tid));
byte[] qids_key = bfr.Add_byte(Byte_ascii.Pipe).Add(ns_num).Add_byte(Byte_ascii.Pipe).Add(ttl).To_bry();
hash.Add(qids_key, qid);
}
public byte[] Get_or_null(Xowe_wiki wiki, Xoa_ttl ttl) {return Get_or_null(wiki.Wdata_wiki_abrv(), ttl);}
public byte[] Get_or_null(byte[] wiki_abrv, Xoa_ttl ttl) {
if (!enabled) return null;
if (Bry_.Len_eq_0(wiki_abrv)) return null; // "other" wikis will never call wikidata
byte[] key = Bry_.Add(wiki_abrv, Byte_ascii.Pipe_bry, ttl.Ns().Num_bry(), Byte_ascii.Pipe_bry, ttl.Page_db()); // EX: "enwiki|014|Earth"
byte[] rv = (byte[])hash.Get_by(key);
if (rv == null) { // not in cache; load from db
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_qid(wiki_abrv, ttl.Ns().Num_bry(), ttl.Page_db());
byte[] val_for_hash = rv == null ? Bry_.Empty : rv; // JAVA: hashtable does not accept null as value; use Bry_.Empty
hash.Add(key, val_for_hash); // NOTE: if not in db, will insert Bry_.Empty; DATE:2014-07-23
}
return Bry_.Len_eq_0(rv) ? null : rv; // JAVA: convert Bry_.Empty to null which is what callers expect
}
}

View File

@@ -36,7 +36,7 @@ public class Wdata_doc_wtr {
wtr.Key(true, key);
wtr.Nde_bgn();
for (int i = 0; i < len; i++) {
KeyVal kv = (KeyVal)list.Get_at(i);
Keyval kv = (Keyval)list.Get_at(i);
wtr.Kv(i != 0, Bry_.new_u8(kv.Key()), Bry_.new_u8(kv.Val_to_str_or_empty()));
}
wtr.Nde_end();
@@ -49,7 +49,7 @@ public class Wdata_doc_wtr {
wtr.Nde_bgn();
for (int i = 0; i < len; i++) {
if (i != 0) wtr.Comma();
KeyVal kv = (KeyVal)list.Get_at(i);
Keyval kv = (Keyval)list.Get_at(i);
wtr.Key(false, Bry_.new_u8(kv.Key())); // write key; EX: enwiki:
wtr.Nde_bgn(); // bgn nde; EX: {
wtr.Kv(false, Wdata_doc_parser_v1.Bry_name, Bry_.new_u8(kv.Val_to_str_or_empty())); // write name; EX: name=Earth

View File

@@ -21,7 +21,7 @@ import gplx.xowa.langs.*;
import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.hwtrs.*;
class Wdata_prop_val_visitor implements Wdata_claim_visitor {
private Wdata_wiki_mgr wdata_mgr; private Xoae_app app; private Bry_bfr bfr; private byte[] lang_key;
private final Bry_bfr tmp_time_bfr = Bry_bfr.reset_(255); private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_();
private final Bry_bfr tmp_time_bfr = Bry_bfr.reset_(255); private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_();
private Wdata_hwtr_msgs msgs;
public Wdata_prop_val_visitor(Xoae_app app, Wdata_wiki_mgr wdata_mgr) {this.app = app; this.wdata_mgr = wdata_mgr;}
public void Init(Bry_bfr bfr, Wdata_hwtr_msgs msgs, byte[] lang_key) {this.bfr = bfr; ; this.msgs = msgs; this.lang_key = lang_key;}
@@ -31,7 +31,7 @@ class Wdata_prop_val_visitor implements Wdata_claim_visitor {
}
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(itm.Page_ttl_db());
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(itm.Page_ttl_db());
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_itm_.Key_en)) // NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19
@@ -55,6 +55,6 @@ class Wdata_prop_val_visitor implements Wdata_claim_visitor {
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_u8("±");
private static final byte[] Ignore_comma = new byte[]{Byte_ascii.Comma};
private static final byte[] Bry_quantity_margin_of_error = Bry_.new_u8("±");
}

View File

@@ -24,21 +24,30 @@ import gplx.xowa.wikis.domains.*; import gplx.xowa.htmls.*; import gplx.xowa.par
import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.xtns.wdatas.pfuncs.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.hwtrs.*;
import gplx.xowa.parsers.*;
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 final Hash_adp_bry qids_cache = Hash_adp_bry.cs(), pids_cache = Hash_adp_bry.cs();
private Int_obj_ref wiki_tid_ref = Int_obj_ref.zero_();
private final Xoae_app app;
private final Wdata_prop_val_visitor prop_val_visitor;
private final Wdata_doc_parser wdoc_parser_v1 = new Wdata_doc_parser_v1(), wdoc_parser_v2 = new Wdata_doc_parser_v2();
private Wdata_hwtr_mgr hwtr_mgr;
public Wdata_wiki_mgr(Xoae_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 Xoae_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;
this.Qid_mgr = new Wbase_qid_mgr(this);
this.Pid_mgr = new Wbase_pid_mgr(this);
this.Doc_mgr = new Wbase_doc_mgr(app, this, this.Qid_mgr);
this.prop_val_visitor = new Wdata_prop_val_visitor(app, this);
this.Enabled_(true);
}
public GfoEvMgr EvMgr() {return evMgr;} private final GfoEvMgr evMgr;
public final Wbase_qid_mgr Qid_mgr;
public final Wbase_pid_mgr Pid_mgr;
public final Wbase_doc_mgr Doc_mgr;
public boolean Enabled() {return enabled;} private boolean enabled;
public void Enabled_(boolean v) {
this.enabled = v;
Qid_mgr.Enabled_(v);
Pid_mgr.Enabled_(v);
Doc_mgr.Enabled_(v);
}
public byte[] Domain() {return domain;} public void Domain_(byte[] v) {domain = v;} private byte[] domain = Bry_.new_a7("www.wikidata.org");
public Xowe_wiki Wdata_wiki() {if (wdata_wiki == null) wdata_wiki = app.Wiki_mgr().Get_by_or_make(domain).Init_assert(); return wdata_wiki;} private Xowe_wiki wdata_wiki;
public Json_parser Jdoc_parser() {return jdoc_parser;} private Json_parser jdoc_parser = new Json_parser();
@@ -50,107 +59,20 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
? wdoc_parser_v2 : wdoc_parser_v1; // if "type", must be v2
}
public Xop_log_property_wkr Property_wkr() {return property_wkr;} private Xop_log_property_wkr property_wkr;
public Int_obj_ref Tmp_prop_ref() {return tmp_prop_ref;} Int_obj_ref tmp_prop_ref = Int_obj_ref.zero_();
public void Clear() {
qids_cache.Clear();
pids_cache.Clear();
doc_cache.Clear();
}
public void Qids_add(Bry_bfr bfr, byte[] lang_key, int wiki_tid, byte[] ns_num, byte[] ttl, byte[] qid) {
Xow_abrv_wm_.To_abrv(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).To_bry();
qids_cache.Add(qids_key, qid);
}
public byte[] Qids_get(Xowe_wiki wiki, Xoa_ttl ttl) {return Qids_get(wiki.Wdata_wiki_abrv(), ttl);}
private byte[] Qids_get(byte[] wiki_abrv, Xoa_ttl ttl) {
if (!enabled) return null;
if (Bry_.Len_eq_0(wiki_abrv)) return null; // "other" wikis will never call wikidata
byte[] cache_key = Bry_.Add(wiki_abrv, Byte_ascii.Pipe_bry, ttl.Ns().Num_bry(), Byte_ascii.Pipe_bry, ttl.Page_db()); // EX:enwiki|014|Earth
byte[] rv = (byte[])qids_cache.Get_by(cache_key);
if (rv == null) { // not in cache; load from db
rv = this.Wdata_wiki().Db_mgr().Load_mgr().Load_qid(wiki_abrv, ttl.Ns().Num_bry(), ttl.Page_db());
byte[] add_val = rv == null ? Bry_.Empty : rv; // JAVA: hashtable does not accept null as value; use Bry_.Empty
qids_cache.Add(cache_key, add_val); // NOTE: if not in db, will insert a null value for cache_key; DATE:2014-07-23
}
return Bry_.Len_eq_0(rv) ? null : rv; // JAVA: convert Bry_.Empty to null
}
public Int_obj_val Pids_add(byte[] pids_key, int pid_id) {Int_obj_val rv = Int_obj_val.new_(pid_id); pids_cache.Add(pids_key, rv); return rv;}
public int Pids__parse_as_int_or_null(byte[] pid_ttl) { // EX: "p123" -> "123"
int len = pid_ttl.length; if (len == 0) return Wdata_wiki_mgr.Pid_null;
byte ltr_p = pid_ttl[0]; // make sure 1st char is "P" or "p"
switch (ltr_p) {
case Byte_ascii.Ltr_P:
case Byte_ascii.Ltr_p: break;
default: return Wdata_wiki_mgr.Pid_null;
}
return Bry_.To_int_or(pid_ttl, 1, len, Wdata_wiki_mgr.Pid_null);
}
public int Pids__get_by_name(byte[] lang_key, byte[] pid_name) {
if (!enabled) return Pid_null;
byte[] pids_key = Bry_.Add(lang_key, Byte_ascii.Pipe_bry, pid_name); // EX: "en|name"
Int_obj_val rv = (Int_obj_val)pids_cache.Get_by(pids_key);
if (rv == null) {
int pid_id = this.Wdata_wiki().Db_mgr().Load_mgr().Load_pid(lang_key, pid_name); if (pid_id == Pid_null) return Pid_null;
rv = Pids_add(pids_key, pid_id);
}
return rv.Val();
}
public void Pages_add(byte[] qid, Wdata_doc page) {
doc_cache.Add(qid, page);
}
public Wdata_doc Pages_get(Xowe_wiki wiki, Xoa_ttl ttl, Wdata_pf_property_data data) {
if (data.Q() != null) return Pages_get(data.Q());
else if (data.Of() != null) {
Xoa_ttl of_ttl = Xoa_ttl.parse(wiki, data.Of()); if (of_ttl == null) return null;
byte[] qid = Qids_get(wiki, of_ttl); if (qid == null) return null; // NOTE: for now, use wiki.Lang_key(), not page.Lang()
return Pages_get(qid);
}
else return Pages_get(wiki, ttl);
}
public Wdata_doc Pages_get(Xowe_wiki wiki, Xoa_ttl ttl) {byte[] qid_bry = Qids_get(wiki, ttl); return qid_bry == null? null : Pages_get(qid_bry);}
public Wdata_doc Pages_get_by_ttl_name(byte[] ttl_bry) {
if (Byte_ascii.Case_lower(ttl_bry[0]) == Byte_ascii.Ltr_p) // if ttl starts with "p", change title to "Property:" ns; DATE:2014-02-18
ttl_bry = Bry_.Add_w_dlm(Byte_ascii.Colon, Wdata_wiki_mgr.Ns_property_name_bry, ttl_bry);
return Pages_get(ttl_bry);
}
public Wdata_doc Pages_get(byte[] qid_bry) {
qid_bry = Get_low_qid(qid_bry);
Wdata_doc rv = doc_cache.Get_or_null(qid_bry);
if (rv == null) {
Json_doc jdoc = Get_json(qid_bry); if (jdoc == null) return null; // page not found
rv = new Wdata_doc(qid_bry, this, jdoc);
doc_cache.Add(qid_bry, rv);
}
return rv;
}
public static byte[] Get_low_qid(byte[] bry) { // HACK: wdata currently does not differentiate between "Vandalism" and "Wikipedia:Vandalism", combining both into "Vandalism:q4664011|q6160"; get lowest qid
int bry_len = bry.length;
int pipe_pos = Bry_find_.Find_fwd(bry, Byte_ascii.Pipe, 0, bry_len);
if (pipe_pos == Bry_find_.Not_found) return bry;
byte[][] qids = Bry_split_.Split(bry, Byte_ascii.Pipe);
int qids_len = qids.length;
int qid_min = Int_.Max_value;
int qid_idx = 0;
for (int i = 0; i < qids_len; i++) {
byte[] qid = qids[i];
int qid_len = qid.length;
int qid_val = Bry_.To_int_or(qid, 1, qid_len, Int_.Max_value);
if (qid_val < qid_min) {
qid_min = qid_val;
qid_idx = i;
}
}
return qids[qid_idx];
Qid_mgr.Clear();
Pid_mgr.Clear();
Doc_mgr.Clear();
}
public byte[] Get_claim_or(Xow_domain_itm domain, Xoa_ttl page_ttl, int pid, byte[] or) {
byte[] qid = this.Qids_get(domain.Abrv_wm(), page_ttl); if (qid == null) return or;
Wdata_doc wdoc = this.Pages_get(qid); if (wdoc == null) return or;
byte[] qid = this.Qid_mgr.Get_or_null(domain.Abrv_wm(), page_ttl); if (qid == null) return or;
Wdata_doc wdoc = Doc_mgr.Get_by_bry_or_null(qid); if (wdoc == null) return or;
Wdata_claim_grp claim_grp = wdoc.Claim_list_get(pid); if (claim_grp == null || claim_grp.Len() == 0) return or;
Wdata_claim_itm_core claim_itm = claim_grp.Get_at(0);
prop_val_visitor.Init(tmp_bfr, hwtr_mgr.Msgs(), domain.Lang_orig_key());
claim_itm.Welcome(prop_val_visitor);
return tmp_bfr.To_bry_and_clear();
} private final Bry_bfr tmp_bfr = Bry_bfr.new_(32);
} private final Bry_bfr tmp_bfr = Bry_bfr.new_(32);
public void Resolve_to_bfr(Bry_bfr bfr, Wdata_claim_grp prop_grp, byte[] lang_key) {
Hwtr_mgr_assert();
int len = prop_grp.Len();
@@ -173,15 +95,14 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
}
}
}
public static final byte[] Bry_q = Bry_.new_a7("q");
public byte[] Popup_text(Xoae_page page) {
Hwtr_mgr_assert();
Wdata_doc wdoc = this.Pages_get_by_ttl_name(page.Ttl().Page_db());
Wdata_doc wdoc = Doc_mgr.Get_by_bry_or_null(page.Ttl().Full_db());
return hwtr_mgr.Popup(wdoc);
}
public void Write_json_as_html(Bry_bfr bfr, byte[] ttl_bry, byte[] data_raw) {
public void Write_json_as_html(Bry_bfr bfr, byte[] page_full_db, byte[] data_raw) {
Hwtr_mgr_assert();
Wdata_doc wdoc = this.Pages_get_by_ttl_name(ttl_bry);
Wdata_doc wdoc = Doc_mgr.Get_by_bry_or_null(page_full_db);
hwtr_mgr.Init_by_wdoc(wdoc);
bfr.Add(hwtr_mgr.Write(wdoc));
}
@@ -208,13 +129,6 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
json.Root_nde().Print_as_json(bfr, 0);
bfr.Add(Xoh_consts.Span_end);
}
private Json_doc Get_json(byte[] qid_bry) {
if (!enabled) return null;
Xoa_ttl qid_ttl = Xoa_ttl.parse(this.Wdata_wiki(), qid_bry); if (qid_ttl == null) {app.Usr_dlg().Warn_many("", "", "invalid qid for ttl: qid=~{0}", String_.new_u8(qid_bry)); return null;}
Xoae_page qid_page = this.Wdata_wiki().Data_mgr().Get_page(qid_ttl, false); if (qid_page.Missing()) return null;
byte[] src = qid_page.Data_raw();
return jdoc_parser.Parse(src);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.To_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
@@ -232,14 +146,15 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
}
public static final int Ns_property = 120;
public static final String Ns_property_name = "Property";
public static final byte[] Ns_property_name_bry = Bry_.new_a7(Ns_property_name);
public static final byte[]
public static final byte[] Ns_property_name_bry = Bry_.new_a7(Ns_property_name);
public static final byte[] Bry_q = Bry_.new_a7("q");
public static final byte[]
Ttl_prefix_qid_bry_db = Bry_.new_a7("q") // NOTE: for historical reasons this is standardized as lowercase q not Q; DATE:2015-06-12
, Ttl_prefix_qid_bry_gui = Bry_.new_a7("Q") // NOTE: use uppercase Q for writing html; DATE:2015-06-12
, Ttl_prefix_pid_bry = Bry_.new_a7("Property:P")
;
public static final int Pid_null = -1;
public static final byte[] Html_json_id = Bry_.new_a7("xowa-wikidata-json");
public static final byte[] Html_json_id = Bry_.new_a7("xowa-wikidata-json");
public static boolean Wiki_page_is_json(int wiki_tid, int ns_id) {
switch (wiki_tid) {
case Xow_domain_tid_.Int__wikidata:

View File

@@ -22,7 +22,7 @@ import gplx.xowa.wikis.nss.*;
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
public class Wdata_wiki_mgr_fxt {
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr();
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr();
public Xowe_wiki Wiki() {return parser_fxt.Wiki();}
public Wdata_wiki_mgr_fxt Init() {return Init(new Xop_fxt(), true);}
public Wdata_wiki_mgr_fxt Init(Xop_fxt parser_fxt, boolean reset) {
@@ -81,10 +81,10 @@ public class Wdata_wiki_mgr_fxt {
}
public void Init_qids_add(String lang_key, int wiki_tid, String ttl, String qid) {
Bry_bfr tmp_bfr = app.Utl__bfr_mkr().Get_b512();
wdata_mgr.Qids_add(tmp_bfr, Bry_.new_a7(lang_key), wiki_tid, Bry_.new_a7("000"), Bry_.new_a7(ttl), Bry_.new_a7(qid));
wdata_mgr.Qid_mgr.Add(tmp_bfr, Bry_.new_a7(lang_key), wiki_tid, Bry_.new_a7("000"), Bry_.new_a7(ttl), Bry_.new_a7(qid));
tmp_bfr.Mkr_rls();
}
public void Init_pids_add(String lang_key, String pid_name, int pid) {wdata_mgr.Pids_add(Bry_.new_u8(lang_key + "|" + pid_name), pid);}
public void Init_pids_add(String lang_key, String pid_name, int pid) {wdata_mgr.Pid_mgr.Add(Bry_.new_u8(lang_key + "|" + pid_name), pid);}
public void Init_links_add(String wiki, String ttl, String qid) {Init_links_add(wiki, "000", ttl, qid);}
public void Init_links_add(String wiki, String ns_num, String ttl, String qid) {
byte[] ttl_bry = Bry_.new_u8(ttl);
@@ -114,17 +114,14 @@ public class Wdata_wiki_mgr_fxt {
external_lang_links.Langs_add(Bry_.new_a7(lang));
}
}
public void Test_get_low_qid(String qid, String expd) {
Tfds.Eq(expd, String_.new_a7(Wdata_wiki_mgr.Get_low_qid(Bry_.new_a7(qid))));
}
public void Test_link(String ttl_str, String expd) {Test_link(Xoa_ttl.parse(wiki, Xow_ns_.Tid__main, Bry_.new_u8(ttl_str)), expd);}
public void Test_link(Xoa_ttl ttl, String expd) {
byte[] qid_ttl = wdata_mgr.Qids_get(wiki, ttl);
byte[] qid_ttl = wdata_mgr.Qid_mgr.Get_or_null(wiki, ttl);
Tfds.Eq(expd, String_.new_u8(qid_ttl));
}
public void Test_parse_pid_null(String val) {Test_parse_pid(val, Wdata_wiki_mgr.Pid_null);}
public void Test_parse_pid(String val, int expd) {Tfds.Eq(expd, Wdata_pf_property.Parse_pid(num_parser, Bry_.new_a7(val)));} private Number_parser num_parser = new Number_parser();
public void Init_pages_add(Wdata_doc page) {wdata_mgr.Pages_add(page.Qid(), page);}
public void Init__docs__add(Wdata_doc page) {wdata_mgr.Doc_mgr.Add(page.Qid(), page);}
public void Test_parse(String raw, String expd) {
parser_fxt.Test_parse_page_tmpl_str(raw, expd);
}

View File

@@ -54,9 +54,4 @@ public class Wdata_wiki_mgr_tst {
, "</span>"
));
}
@Test public void Get_low_qid() {
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt();
fxt.Test_get_low_qid("q1" , "q1"); // return self
fxt.Test_get_low_qid("q2|q1", "q1"); // return lowest
}
}

View File

@@ -36,7 +36,7 @@ public class Wdata_xwiki_link_wtr implements gplx.core.brys.Bfr_arg {
return Qid_null;
}
Wdata_wiki_mgr wdata_mgr = wiki.Appe().Wiki_mgr().Wdata_mgr();
Wdata_doc doc = wdata_mgr.Pages_get(wiki, ttl); if (doc == null) return Qid_null; // no links
Wdata_doc doc = wdata_mgr.Doc_mgr.Get_by_ttl_or_null(wiki, ttl); if (doc == null) return Qid_null; // no links
boolean external_links_mgr_enabled = external_links_mgr.Enabled();
Ordered_hash links = doc.Slink_list();
Bry_bfr tmp_bfr = wiki.Appe().Utl__bfr_mkr().Get_k004();
@@ -70,12 +70,12 @@ public class Wdata_xwiki_link_wtr implements gplx.core.brys.Bfr_arg {
return doc.Qid();
} catch (Exception e) {Err_.Noop(e); return Qid_null;}
}
public static final byte[] Qid_null = Bry_.Empty; // NOTE: return Empty, not null else Bry_fmtr will fail
public static final byte[] Qid_null = Bry_.Empty; // NOTE: return Empty, not null else Bry_fmtr will fail
}
class Xoa_ttl_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Xoa_ttl lhs = (Xoa_ttl)lhsObj, rhs = (Xoa_ttl)rhsObj;
return Bry_.Compare(lhs.Raw(), rhs.Raw());
}
public static final Xoa_ttl_sorter Instance = new Xoa_ttl_sorter(); Xoa_ttl_sorter() {}
public static final Xoa_ttl_sorter Instance = new Xoa_ttl_sorter(); Xoa_ttl_sorter() {}
}

Some files were not shown because too many files have changed in this diff Show More