mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Scribunto: Apply namespace argument only if in main namespace [#473]
This commit is contained in:
parent
b74ca77786
commit
05e8c11338
@ -60,21 +60,30 @@ public class Scrib_lib_title implements Scrib_lib {
|
|||||||
;
|
;
|
||||||
private static final String[] Proc_names = String_.Ary(Invk_newTitle, Invk_makeTitle, Invk_getExpensiveData, Invk_getUrl, Invk_getContent, Invk_getFileInfo, Invk_getCurrentTitle, Invk_protectionLevels, Invk_cascadingProtection, Invk_redirectTarget);
|
private static final String[] Proc_names = String_.Ary(Invk_newTitle, Invk_makeTitle, Invk_getExpensiveData, Invk_getUrl, Invk_getContent, Invk_getFileInfo, Invk_getCurrentTitle, Invk_protectionLevels, Invk_cascadingProtection, Invk_redirectTarget);
|
||||||
public boolean NewTitle(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean NewTitle(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
// validate args
|
||||||
if (args.Len() == 0) return rslt.Init_obj(null); // invalid title, return null; EX:{{#invoke:Message box|fmbox}} DATE:2015-03-04
|
if (args.Len() == 0) return rslt.Init_obj(null); // invalid title, return null; EX:{{#invoke:Message box|fmbox}} DATE:2015-03-04
|
||||||
byte[] ttl_bry = args.Xstr_bry_or_null(0); // NOTE: Pull_bry fails if caller passes int; PAGE:de.w:Wikipedia:Lua/Modul/Pinging/Test/recipients; DATE:2016-04-21
|
byte[] ttl_bry = args.Xstr_bry_or_null(0); // NOTE: Pull_bry fails if caller passes int; PAGE:de.w:Wikipedia:Lua/Modul/Pinging/Test/recipients; DATE:2016-04-21
|
||||||
Object ns_obj = args.Cast_obj_or_null(1);
|
Object ns_obj = args.Cast_obj_or_null(1);
|
||||||
Xowe_wiki wiki = core.Wiki();
|
|
||||||
byte[] ns_bry = null;
|
byte[] ns_bry = null;
|
||||||
|
Xowe_wiki wiki = core.Wiki();
|
||||||
if (ns_obj != null) {
|
if (ns_obj != null) {
|
||||||
ns_bry = Parse_ns(wiki, ns_obj); if (ns_bry == null) throw Err_.new_wo_type("unknown ns", "ns", Object_.Xto_str_strict_or_empty(ns_obj));
|
ns_bry = Parse_ns(wiki, ns_obj); if (ns_bry == null) throw Err_.new_wo_type("unknown ns", "ns", Object_.Xto_str_strict_or_empty(ns_obj));
|
||||||
}
|
}
|
||||||
if (ns_bry != null) {
|
|
||||||
|
// parse ttl
|
||||||
|
Xoa_ttl ttl = wiki.Ttl_parse(ttl_bry);
|
||||||
|
|
||||||
|
// apply ns only if main ns; also, ns in title takes precedence over argument; ISSUE#:473 DATE:2019-05-22
|
||||||
|
if ( ttl != null
|
||||||
|
&& ttl.Ns().Id_is_main()
|
||||||
|
&& ns_bry != null) {
|
||||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||||
ttl_bry = bfr.Add(ns_bry).Add_byte(Byte_ascii.Colon).Add(ttl_bry).To_bry_and_rls();
|
ttl_bry = bfr.Add(ns_bry).Add_byte(Byte_ascii.Colon).Add(ttl.Full_db_w_anch()).To_bry_and_rls();
|
||||||
|
ttl = wiki.Ttl_parse(ttl_bry);
|
||||||
}
|
}
|
||||||
Xoa_ttl ttl = Xoa_ttl.Parse(core.Wiki(), ttl_bry);
|
return ttl == null
|
||||||
if (ttl == null) return rslt.Init_obj(null); // invalid title; exit; matches MW logic
|
? rslt.Init_obj(null) // invalid title; exit; matches MW logic
|
||||||
return rslt.Init_obj(GetInexpensiveTitleData(ttl));
|
: 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) {
|
public boolean GetUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
|
@ -31,6 +31,10 @@ public class Scrib_lib_title_tst {
|
|||||||
@Test public void NewTitle_int() {
|
@Test public void NewTitle_int() {
|
||||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary(1234) , ttl_fast(0 , "", "1234", "", "", "1234"));
|
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary(1234) , ttl_fast(0 , "", "1234", "", "", "1234"));
|
||||||
}
|
}
|
||||||
|
@Test public void NewTitle_ns() {// ns in title takes precedence over argument; ISSUE#:473 DATE:2019-05-22
|
||||||
|
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("Template:A", "Template"), ttl_fast(10 , "Template", "A"));
|
||||||
|
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("Help:A" , "Template"), ttl_fast(12 , "Help", "A"));
|
||||||
|
}
|
||||||
@Test public void NewTitle__foreign() {// PURPOSE: must be local language's version; Russian "Шаблон" not English "Template"; PAGE:ru.w:Королевство_Нидерландов DATE:2016-11-23
|
@Test public void NewTitle__foreign() {// PURPOSE: must be local language's version; Russian "Шаблон" not English "Template"; PAGE:ru.w:Королевство_Нидерландов DATE:2016-11-23
|
||||||
fxt.Core().Wiki().Ns_mgr().Ns_template().Name_bry_(Bry_.new_a7("Template_in_nonenglish_name"));
|
fxt.Core().Wiki().Ns_mgr().Ns_template().Name_bry_(Bry_.new_a7("Template_in_nonenglish_name"));
|
||||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("A", "Template") , ttl_fast(10 , "Template_in_nonenglish_name", "A")); // "Template_in_nonenglish_name" not "Template"
|
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("A", "Template") , ttl_fast(10 , "Template_in_nonenglish_name", "A")); // "Template_in_nonenglish_name" not "Template"
|
||||||
|
Loading…
Reference in New Issue
Block a user