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

'v3.5.1.1'

This commit is contained in:
gnosygnu
2016-05-01 21:06:12 -04:00
parent 5ce4ea2a08
commit 96636f3161
131 changed files with 2287 additions and 928 deletions

View File

@@ -41,17 +41,17 @@ 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);
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 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_safe(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_safe(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));
}
@@ -153,7 +153,7 @@ class Scrib_lib_message_data {
return msg_val;
}
static final byte Key_tid_keys = 1, Key_tid_rawMessage = 2, Key_tid_lang = 3, Key_tid_useDB = 4, Key_tid_title = 5, Key_tid_params = 6;
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("keys", Key_tid_keys)
.Add_str_byte("rawMessage", Key_tid_rawMessage)
.Add_str_byte("lang", Key_tid_lang)
@@ -168,14 +168,14 @@ class Scrib_lib_message_data {
return ((Byte_obj_val)o).Val();
}
public static final byte Fmt_tid_parse = 1, Fmt_tid_text = 2, Fmt_tid_plain = 3, Fmt_tid_escaped = 4, Fmt_tid_parseAsBlock = 5;
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("parse", Fmt_tid_parse)
.Add_str_byte("text", Fmt_tid_text)
.Add_str_byte("plain", Fmt_tid_plain)
.Add_str_byte("escaped", Fmt_tid_escaped)
.Add_str_byte("parseAsBlock", Fmt_tid_parseAsBlock);
public static final byte Check_tid_exists = 1, Check_tid_isBlank = 2, Check_tid_isDisabled = 3;
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_a7()
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("exists", Check_tid_exists)
.Add_str_byte("isBlank", Check_tid_isBlank)
.Add_str_byte("isDisabled", Check_tid_isDisabled);

View File

@@ -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_safe(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
@@ -359,7 +359,7 @@ 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);
Keyval[] args_ary = args.Pull_kv_ary_safe(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);

View File

@@ -18,10 +18,11 @@ 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.*;
public class Scrib_lib_mw__lib_tst {
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
@Before public void init() {
fxt.Clear_for_lib();
lib = fxt.Core().Lib_mw().Init();
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
}
@Test public void ParentFrameExists() {
fxt.Init_frame_parent("test");
fxt.Test_scrib_proc_bool(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, true);
@@ -79,6 +80,11 @@ public class Scrib_lib_mw__lib_tst {
@Test public void NewChildFrame() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_newChildFrame, Object_.Ary("current", "Page_0", Scrib_kv_utl_.flat_many_("key1", "val1")), "frame0");
}
@Test public void ExpandTemplate__null_arg() {
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
fxt.Parser_fxt().Data_create("Template:A", "b{{{1}}}c");
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", "A", Scrib_kv_utl_.flat_many_(2, "v2")), "bc"); // list: args is ary
}
@Test public void SetTTL() {
fxt.Test_scrib_proc_empty(lib, Scrib_lib_mw.Invk_setTTL, Object_.Ary(123));
Tfds.Eq(123, fxt.Core().Frame_current().Frame_lifetime());

View File

@@ -99,17 +99,23 @@ public class Scrib_lib_site implements Scrib_lib {
local = 0;
else if (filter != null)
throw Err_.new_wo_type("bad argument #1 to 'interwikiMap' (unknown filter '$filter')", "filter", filter);
// 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][];
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
if (local == 1 && !itm_is_local) continue;
if (local == 0 && itm_is_local) continue;
String prefix = itm.Key_str();
rv[i] = InterwikiMap_itm(itm, prefix, itm_is_local);
Hash_adp misc_cache = core.Wiki().Cache_mgr().Misc_cache();
String cache_key = "scribunto.interwikimap." + core.Wiki().Domain_str() + "." + filter;
Keyval[] rv = (Keyval[])misc_cache.Get_by(cache_key);
if (rv == null) {
Xow_xwiki_mgr xwiki_mgr = core.Wiki().Xwiki_mgr();
int xwiki_len = xwiki_mgr.Len();
List_adp list = List_adp_.new_();
for (int i = 0; i < xwiki_len; ++i) {
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
boolean itm_is_local = itm.Offline();
if (local == 1 && !itm_is_local) continue;
if (local == 0 && itm_is_local) continue;
String prefix = itm.Key_str();
list.Add(Keyval_.new_(prefix, InterwikiMap_itm(itm, prefix, itm_is_local)));
}
rv = (Keyval[])list.To_ary_and_clear(Keyval.class);
misc_cache.Add(cache_key, rv);
}
return rslt.Init_obj(rv);
}

View File

@@ -52,6 +52,19 @@ public class Scrib_lib_site_tst {
@Test public void PagesInNs() {
fxt.Test__proc__ints(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
}
@Test public void InterwikiMap() {
fxt.Test__proc__objs__nest(lib, Scrib_lib_site.Invk_interwikiMap, Object_.Ary("!local"), String_.Concat_lines_nl_skip_last
( "1="
, " en.wikipedia.org="
, " prefix=en.wikipedia.org"
, " url=en.wikipedia.org"
, " isProtocolRelative=false"
, " isLocal=false"
, " isTranscludable=false"
, " isCurrentWiki=false"
, " isExtraLanguageLink=false"
));
}
@Test public void Init_lib_site() {
Xowe_wiki wiki = fxt.Core().Wiki();
wiki.Stats().Load_by_db(1, 2, 3, 4, 5, 6, 7, 8);

View File

@@ -144,7 +144,7 @@ public class Scrib_lib_title implements Scrib_lib {
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[ 2] = Keyval_.new_("contentModel" , Key_wikitext); // $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);
}
@@ -227,5 +227,5 @@ public class Scrib_lib_title implements Scrib_lib {
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";
public static final String Key_wikitext = "wikitext";
}

View File

@@ -132,7 +132,7 @@ public class Scrib_lib_title_tst {
( "1="
, " isRedirect=" + Bool_.To_str_lower(redirect)
, " id=" + Int_.To_str(ttl_id)
, " contentModel=" + Scrib_lib_title.Key_wikitexet
, " contentModel=" + Scrib_lib_title.Key_wikitext
, " exists=" + Bool_.To_str_lower(exists)
);
}

View File

@@ -346,7 +346,10 @@ class Scrib_lib_ustring_gsub_mgr {
}
}
Keyval[] rslts = core.Interpreter().CallFunction(repl_func.Id(), luacbk_args);
tmp_bfr.Add_str_u8(Scrib_kv_utl_.Val_to_str(rslts, 0));
if (rslts.length > 0) { // ArrayIndex check
Object rslt_obj = rslts[0].Val(); // 0th idx has result
tmp_bfr.Add_str_u8(Object_.Xto_str_strict_or_empty(rslt_obj)); // NOTE: always convert to String; rslt_obj can be int; PAGE:en.d:seven DATE:2016-04-27
}
break;
}
default: throw Err_.new_unhandled(repl_tid);

View File

@@ -56,6 +56,11 @@ public class Scrib_lib_ustring__gsub__tst {
Exec_gsub("ab", ".", -1, proc_root.To_scrib_lua_proc(), "ab;2"); // fails if "ab;4"
Tfds.Eq_str("0;1;2;0;1;2;", bfr.To_str_and_clear()); // fails if "0;1;1;1"
}
@Test public void Replace__proc__number() { // PURPOSE:handle replace-as-number in gproc; PAGE:en.d:seven; DATE:2016-04-27
Mock_proc__number proc = new Mock_proc__number(0);
fxt.Init__cbk(proc);
Exec_gsub("ab", ".", -1, proc.To_scrib_lua_proc(), "12;2"); // fails if "ab;4"
}
@Test public void Regx__int() { // PURPOSE: do not fail if integer is passed in for @regx; PAGE:en.d:λύω DATE:2014-09-02
Exec_gsub("abcd", 1 , -1, "A" , "abcd;0");
}
@@ -102,3 +107,10 @@ class Mock_proc__recursive extends Mock_proc_fxt { private final Mock_scrib_f
return args;
}
}
class Mock_proc__number extends Mock_proc_fxt { private int counter = 0;
public Mock_proc__number(int id) {super(id, "number");}
@Override public Keyval[] Exec_by_scrib(Keyval[] args) {
args[0].Val_(++counter); // set replace-val to int
return args;
}
}