mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.4.3.1'
This commit is contained in:
@@ -43,4 +43,9 @@ public class Xox_xnde_ {
|
||||
rv.Init(ctx.Page().Url_bry_safe(), src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Extract_body_or_null(byte[] src, Xop_xnde_tkn xnde) {
|
||||
int body_bgn = xnde.Tag_open_end();
|
||||
int body_end = xnde.Tag_close_bgn();
|
||||
return body_bgn != -1 && body_end > body_bgn ? Bry_.Mid(src, body_bgn, body_end) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Pfunc_ifexist_mgr {
|
||||
boolean rv = false;
|
||||
switch (ttl_ns.Id()) {
|
||||
case Xow_ns_.Tid__special: rv = true; break; // NOTE: some pages call for [[Special]]; always return true for now; DATE:2014-07-17
|
||||
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(exists_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(exists_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
default: rv = Find_ttl_in_db(exists_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
}
|
||||
exists_itm.Exists_(rv);
|
||||
|
||||
@@ -49,5 +49,5 @@ public class Pfunc_displaytitle extends Pf_func_base {
|
||||
byte[] rv = case_mgr.Case_build_lower(val); // lower-case
|
||||
return Bry_.Replace(rv, Byte_ascii.Space, Byte_ascii.Underline); // force underline; PAGE:de.w:Mod_qos DATE:2014-11-06
|
||||
}
|
||||
public static final Pfunc_displaytitle Instance = new Pfunc_displaytitle(); Pfunc_displaytitle() {}
|
||||
public static final Pfunc_displaytitle Instance = new Pfunc_displaytitle(); Pfunc_displaytitle() {}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
|
||||
Bry_bfr tmp_bfr = ctx.App().Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
switch (tid) {
|
||||
case Tid_local: tmp_bfr.Add(ctx.Wiki().Props().ArticlePath());break;
|
||||
case Tid_full: tmp_bfr.Add(Bry_relative_url).Add(ctx.Wiki().Props().ServerName()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
case Tid_full: tmp_bfr.Add(Bry_relative_url).Add(ctx.Wiki().Props().Server_name()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
case Tid_canonical: tmp_bfr.Add(ctx.Wiki().Props().Server()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
|
||||
@Override public int Id() {return id;} private int id;
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_urlfunc(id, tid, encode).Name_(name);}
|
||||
public static final byte Tid_local = 0, Tid_full = 1, Tid_canonical = 2;
|
||||
public static final byte[] Bry_relative_url = Bry_.new_a7("//");
|
||||
public static final byte[] Bry_relative_url = Bry_.new_a7("//");
|
||||
}
|
||||
/*
|
||||
NOTE: Both fullurle: and localurle: performed additional character escaping on the resulting link, but no example is known where that still has any additional effect.
|
||||
|
||||
@@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
public class Pfunc_urlfunc_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Localurl() {fxt.Test_parse_tmpl_str_test("{{localurl:a&b! c}}" , "{{test}}", "/wiki/A%26b!_c");}
|
||||
@Test public void Fullurl() {fxt.Test_parse_tmpl_str_test("{{fullurl:a&b! c}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Canonicalurl() {fxt.Test_parse_tmpl_str_test("{{canonicalurl:a&b! c}}" , "{{test}}", "http://en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Canonicalurl_case() {fxt.Test_parse_tmpl_str_test("{{CANONICALURL:a&b! c}}" , "{{test}}", "http://en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Localurle() {fxt.Test_parse_tmpl_str_test("{{localurle:a&b! c}}" , "{{test}}", "/wiki/A%26b!_c");}
|
||||
@Test public void Canonicalurl() {fxt.Test_parse_tmpl_str_test("{{canonicalurl:a&b! c}}" , "{{test}}", "https://en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Canonicalurl_case() {fxt.Test_parse_tmpl_str_test("{{CANONICALURL:a&b! c}}" , "{{test}}", "https://en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Localurle() {fxt.Test_parse_tmpl_str_test("{{localurle:a&b! c}}" , "{{test}}", "/wiki/A%26b!_c");}
|
||||
@Test public void Fullurle() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Canonicalurle() {fxt.Test_parse_tmpl_str_test("{{canonicalurle:a&b! c}}" , "{{test}}", "http://en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Canonicalurle() {fxt.Test_parse_tmpl_str_test("{{canonicalurle:a&b! c}}" , "{{test}}", "https://en.wikipedia.org/wiki/A%26b!_c");}
|
||||
@Test public void Fullurl_arg() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c|action=edit}}" , "{{test}}", "//en.wikipedia.org/wiki/A%26b!_c?action=edit");}
|
||||
@Test public void Random() {fxt.Test_parse_tmpl_str_test("{{fullurle:a&b! c|action=edit}}" , "{{test|a|b|c}}", "//en.wikipedia.org/wiki/A%26b!_c?action=edit");}
|
||||
@Test public void Xwiki() {
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Pfunc_wiki_props extends Pf_func_base {
|
||||
switch (id) {
|
||||
case Xol_kwd_grp_.Id_site_sitename: bfr.Add(props.Site_name()); break;
|
||||
case Xol_kwd_grp_.Id_site_server: bfr.Add(props.Server()); break;
|
||||
case Xol_kwd_grp_.Id_site_servername: bfr.Add(props.ServerName()); break;
|
||||
case Xol_kwd_grp_.Id_site_servername: bfr.Add(props.Server_name()); break;
|
||||
case Xol_kwd_grp_.Id_site_articlepath: bfr.Add(props.ArticlePath()); break;
|
||||
case Xol_kwd_grp_.Id_site_scriptpath: bfr.Add(props.ScriptPath()); break;
|
||||
case Xol_kwd_grp_.Id_site_stylepath: bfr.Add(props.StylePath()); break;
|
||||
@@ -38,5 +38,5 @@ public class Pfunc_wiki_props extends Pf_func_base {
|
||||
}
|
||||
}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_wiki_props(id).Name_(name);}
|
||||
public static final Pfunc_wiki_props Instance = new Pfunc_wiki_props(-1);
|
||||
public static final Pfunc_wiki_props Instance = new Pfunc_wiki_props(-1);
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ 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 org.junit.*;
|
||||
public class Pfunc_wiki_stats_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void setup() {fxt.Reset();}
|
||||
@Test public void SiteName() {fxt.Test_parse_tmpl_str_test("{{SITENAME}}" , "{{test}}", "Wikipedia");}
|
||||
@Test public void ServerName() {fxt.Test_parse_tmpl_str_test("{{SERVERNAME}}" , "{{test}}", "en.wikipedia.org");}
|
||||
@Test public void Server() {fxt.Test_parse_tmpl_str_test("{{SERVER}}" , "{{test}}", "http://en.wikipedia.org");}
|
||||
@Test public void Server() {fxt.Test_parse_tmpl_str_test("{{SERVER}}" , "{{test}}", "https://en.wikipedia.org");}
|
||||
@Test public void ArticlePath() {fxt.Test_parse_tmpl_str_test("{{ARTICLEPATH}}" , "{{test}}", "/wiki/");} // FUTURE: should be /wiki/$1
|
||||
@Test public void ScriptPath() {fxt.Test_parse_tmpl_str_test("{{SCRIPTPATH}}" , "{{test}}", "/wiki");}
|
||||
@Test public void StylePath() {fxt.Test_parse_tmpl_str_test("{{STYLEPATH}}" , "{{test}}", "/wiki/skins");}
|
||||
|
||||
@@ -87,13 +87,18 @@ class Luaj_value_ {
|
||||
if (o == null) return LuaValue.NIL;
|
||||
Class<?> c = Type_adp_.ClassOf_obj(o);
|
||||
if (Object_.Eq(c, Bool_.Cls_ref_type)) return LuaValue.valueOf((Boolean)o);
|
||||
else if (Object_.Eq(c, Byte_.Cls_ref_type)) return LuaValue.valueOf((Byte)o);
|
||||
else if (Object_.Eq(c, Int_.Cls_ref_type)) return LuaValue.valueOf((Integer)o);
|
||||
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, Double_.Cls_ref_type)) return LuaValue.valueOf((Double)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, Long_.Cls_ref_type)) return LuaValue.valueOf((Long)o);
|
||||
else if (Object_.Eq(c, Scrib_lua_proc.class)) return server.Get_closure_by_id(((Scrib_lua_proc)o).Id());
|
||||
else if (Object_.Eq(c, Float_.Cls_ref_type)) return LuaValue.valueOf((Float)o);
|
||||
else if (Object_.Eq(c, Char_.Cls_ref_type)) return LuaValue.valueOf((char)o);
|
||||
else if (Object_.Eq(c, Short_.Cls_ref_type)) return LuaValue.valueOf((Short)o);
|
||||
else return LuaValue.NIL;
|
||||
}
|
||||
private static LuaTable X_kv_ary_to_tbl(Luaj_server server, Keyval... ary) {
|
||||
@@ -145,7 +145,7 @@ public class Scrib_lib_site implements Scrib_lib {
|
||||
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[1] = Keyval_.new_("server" , Bry_.Add(gplx.core.net.Gfo_protocol_itm.Bry_relative, props.Server_name())); // NOTE: should generate "//en.wikipedia.org", not "de.wikipedia.org"; PAGE:de.w:Giro_d<5F>Italia_1996 DATE:2016-04-17
|
||||
rv[2] = Keyval_.new_("scriptPath" , props.ScriptPath());
|
||||
rv[3] = Keyval_.new_("stylePath" , props.StylePath());
|
||||
rv[4] = Keyval_.new_("currentVersion" , props.Current_version());
|
||||
|
||||
@@ -67,7 +67,7 @@ public class Scrib_lib_site_tst {
|
||||
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"
|
||||
, " server=//en.wikipedia.org"
|
||||
, " scriptPath=/wiki"
|
||||
, " stylePath=/wiki/skins"
|
||||
, " currentVersion=1.21wmf11"
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
, Invk_getUrl = "getUrl", Invk_getContent = "getContent", Invk_getFileInfo = "getFileInfo", Invk_getCurrentTitle = "getCurrentTitle"
|
||||
, Invk_protectionLevels = "protectionLevels", Invk_cascadingProtection = "cascadingProtection"
|
||||
;
|
||||
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);
|
||||
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);
|
||||
public boolean NewTitle(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
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.Pull_bry(0);
|
||||
@@ -95,12 +95,12 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
Pfunc_urlfunc.UrlString(core.Ctx(), url_func_tid, false, ttl_bry, bfr, qry_bry);
|
||||
return rslt.Init_obj(bfr.To_str_and_rls());
|
||||
}
|
||||
private static final Hash_adp_bry url_func_hash = Hash_adp_bry.ci_a7()
|
||||
private static final Hash_adp_bry url_func_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("fullUrl", Pfunc_urlfunc.Tid_full)
|
||||
.Add_str_byte("localUrl", Pfunc_urlfunc.Tid_local)
|
||||
.Add_str_byte("canonicalUrl", Pfunc_urlfunc.Tid_canonical);
|
||||
// private static final byte[] Proto_relative = Bry_.new_a7("relative");
|
||||
// private static final Hash_adp_bry proto_hash = Hash_adp_bry.ci_a7().Add_str_obj("http", Bry_.new_a7("http://")).Add_str_obj("https", Bry_.new_a7("https://")).Add_str_obj("relative", Bry_.new_a7("//")).Add_str_obj("canonical", Bry_.new_a7("1"));
|
||||
// private static final byte[] Proto_relative = Bry_.new_a7("relative");
|
||||
// private static final Hash_adp_bry proto_hash = Hash_adp_bry.ci_a7().Add_str_obj("http", Bry_.new_a7("http://")).Add_str_obj("https", Bry_.new_a7("https://")).Add_str_obj("relative", Bry_.new_a7("//")).Add_str_obj("canonical", Bry_.new_a7("1"));
|
||||
private byte[] Parse_ns(Xowe_wiki wiki, Object ns_obj) {
|
||||
if (Type_adp_.Eq_typeSafe(ns_obj, String.class))
|
||||
return Bry_.new_u8(String_.cast(ns_obj));
|
||||
@@ -171,7 +171,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
);
|
||||
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();
|
||||
@@ -179,13 +179,13 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl);
|
||||
byte[] rv = null;
|
||||
if (page_itm != null) {
|
||||
byte[] redirected_src = page_itm.Redirected_src_wtxt();
|
||||
byte[] redirected_src = page_itm.Wtxt__redirect();
|
||||
if (redirected_src != null) { // page is redirect; use its src, not its target's src; DATE:2014-07-11
|
||||
rv = redirected_src;
|
||||
core.Frame_parent().Rslt_is_redirect_(true); // flag frame as redirect, so that \n won't be prepended; EX:"#REDIRECT" x> "\n#REDIRECT"
|
||||
}
|
||||
else
|
||||
rv = page_itm.Wtxt();
|
||||
rv = page_itm.Wtxt__direct();
|
||||
}
|
||||
return rv == null ? rslt.Init_obj(null) : rslt.Init_obj(String_.new_u8(rv));
|
||||
}
|
||||
@@ -204,7 +204,7 @@ 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));
|
||||
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();
|
||||
@@ -226,6 +226,6 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
if (!ns_file_or_media)
|
||||
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();
|
||||
} private static final Xowd_page_itm tmp_db_page = Xowd_page_itm.new_tmp();
|
||||
public static final String Key_wikitexet = "wikitext";
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ public class Scrib_lib_title_tst {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl") , "//en.wikipedia.org/wiki/Main_Page");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "action=edit") , "//en.wikipedia.org/wiki/Main_Page?action=edit");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "localUrl") , "/wiki/Main_Page");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl") , "http://en.wikipedia.org/wiki/Main_Page");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl") , "https://en.wikipedia.org/wiki/Main_Page");
|
||||
// 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"))), "https://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"));
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Scrib_lib_uri_tst {
|
||||
@Test public void Url() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" ), "/wiki/A%26b!_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl , Object_.Ary("a&b! c" ), "//en.wikipedia.org/wiki/A%26b!_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_canonicalUrl , Object_.Ary("a&b! c" ), "http://en.wikipedia.org/wiki/A%26b!_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_canonicalUrl , Object_.Ary("a&b! c" ), "https://en.wikipedia.org/wiki/A%26b!_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" , "action=edit" ), "/wiki/A%26b!_c?action=edit");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("Media:A.png" ), "/wiki/File:A.png");
|
||||
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
|
||||
|
||||
@@ -55,7 +55,7 @@ class Xob_wbase_json_dump_db {
|
||||
this.page_modified_on = DateAdp_.Now();
|
||||
this.page_core_tbl = db_mgr.Tbl__page();
|
||||
page_tbl.Insert_bgn();
|
||||
qid_cmd.Wkr_bgn(bldr);
|
||||
qid_cmd.Page_wkr__bgn();
|
||||
pid_cmd.Pid_bgn();
|
||||
}
|
||||
private int page_id = 0, page_count_main = 0;
|
||||
|
||||
@@ -21,16 +21,16 @@ import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble {
|
||||
private Json_parser parser;
|
||||
public Xob_wdata_pid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
|
||||
public abstract String Wkr_key();
|
||||
public abstract String Page_wkr__key();
|
||||
public abstract void Pid_bgn();
|
||||
public abstract void Pid_add(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl);
|
||||
public abstract void Pid_end();
|
||||
public void Wkr_bgn(Xob_bldr bldr) {
|
||||
this.Init_dump(this.Wkr_key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
|
||||
public void Page_wkr__bgn() {
|
||||
this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
|
||||
parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
|
||||
this.Pid_bgn();
|
||||
}
|
||||
public void Wkr_run(Xowd_page_itm page) {
|
||||
public void Page_wkr__run(Xowd_page_itm page) {
|
||||
if (page.Ns_id() != Wdata_wiki_mgr.Ns_property) return;
|
||||
Json_doc jdoc = parser.Parse(page.Text());
|
||||
if (jdoc == null) {
|
||||
@@ -39,6 +39,7 @@ public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xo
|
||||
}
|
||||
Parse_jdoc(jdoc);
|
||||
}
|
||||
public void Page_wkr__run_cleanup() {}
|
||||
public void Parse_jdoc(Json_doc jdoc) {
|
||||
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
|
||||
byte[] qid = wdoc_parser.Parse_qid(jdoc);
|
||||
@@ -49,6 +50,6 @@ public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xo
|
||||
this.Pid_add(label.Lang(), label.Text(), qid);
|
||||
}
|
||||
}
|
||||
public void Wkr_end() {this.Pid_end();}
|
||||
public void Page_wkr__end() {this.Pid_end();}
|
||||
static final String GRP_KEY = "xowa.wdata.pid_wkr";
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_wdata_pid_sql extends Xob_wdata_pid_base {
|
||||
private Xowd_wbase_pid_tbl tbl;
|
||||
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;}
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;}
|
||||
@Override public void Pid_bgn() {
|
||||
Xowd_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
tbl = db_mgr.Db__wbase().Tbl__wbase_pid();
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xob_wdata_pid_txt extends Xob_wdata_pid_base {
|
||||
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_pid;}
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_pid;}
|
||||
@Override public void Pid_bgn() {
|
||||
pid_bldr = new Wdata_idx_bldr_pid(this, bldr, wiki, dump_fil_len);
|
||||
} Wdata_idx_bldr_pid pid_bldr;
|
||||
|
||||
@@ -21,24 +21,25 @@ import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.bldrs.wms.sites.*;
|
||||
public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xob_page_wkr, GfoInvkAble {
|
||||
private Json_parser parser; private Xob_wbase_ns_parser ns_parser; private final Xob_wbase_ns_parser_rslt ns_parser_rslt = new Xob_wbase_ns_parser_rslt();
|
||||
private Json_parser parser; private Xob_wbase_ns_parser ns_parser; private final Xob_wbase_ns_parser_rslt ns_parser_rslt = new Xob_wbase_ns_parser_rslt();
|
||||
public Xob_wdata_qid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
|
||||
public abstract String Wkr_key();
|
||||
public abstract String Page_wkr__key();
|
||||
public abstract void Qid_bgn();
|
||||
public abstract void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid);
|
||||
public abstract void Qid_end();
|
||||
public void Wkr_bgn(Xob_bldr bldr) {
|
||||
this.Init_dump(this.Wkr_key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
|
||||
public void Page_wkr__bgn() {
|
||||
this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
|
||||
this.parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
|
||||
this.ns_parser = new Xob_wbase_ns_parser(bldr.App().Fsys_mgr().Cfg_site_meta_fil());
|
||||
this.Qid_bgn();
|
||||
}
|
||||
public void Wkr_run(Xowd_page_itm page) {
|
||||
public void Page_wkr__run(Xowd_page_itm page) {
|
||||
if (page.Ns_id() != Xow_ns_.Tid__main) return; // qid pages are only in the Main Srch_rslt_cbk
|
||||
Json_doc jdoc = parser.Parse(page.Text());
|
||||
if (jdoc == null) {bldr.Usr_dlg().Warn_many("", "", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db())); return;}
|
||||
this.Parse_jdoc(jdoc);
|
||||
}
|
||||
public void Page_wkr__run_cleanup() {}
|
||||
public void Parse_jdoc(Json_doc jdoc) {
|
||||
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
|
||||
byte[] qid = wdoc_parser.Parse_qid(jdoc);
|
||||
@@ -56,7 +57,7 @@ public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xo
|
||||
this.Qid_add(sitelink.Site(), sitelink_ns, Xoa_ttl.Replace_spaces(sitelink_ttl), qid); // NOTE: always convert spaces to underscores; EX: "A B" -> "A_B" DATE:2015-04-21
|
||||
}
|
||||
}
|
||||
public void Wkr_end() {
|
||||
public void Page_wkr__end() {
|
||||
this.Qid_end();
|
||||
// wiki.Data__core_mgr().Db__wbase().Tbl__cfg().Insert_int("", "", 1);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_wdata_qid_sql extends Xob_wdata_qid_base {
|
||||
private Xowd_wbase_qid_tbl tbl;
|
||||
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_qid;}
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_qid;}
|
||||
@Override public void Qid_bgn() {
|
||||
Xowd_db_mgr db_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
|
||||
boolean db_is_all_or_few = db_mgr.Props().Layout_text().Tid_is_all_or_few();
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.xtns.wdatas.imports; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.xowa.bldrs.*;
|
||||
public class Xob_wdata_qid_txt extends Xob_wdata_qid_base {
|
||||
private Wdata_idx_bldr_qid qid_bldr;
|
||||
@Override public String Wkr_key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_qid;}
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_qid;}
|
||||
@Override public void Qid_bgn() {qid_bldr = new Wdata_idx_bldr_qid().Ctor(this, bldr, wiki, dump_fil_len);}
|
||||
@Override public void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid) {
|
||||
qid_bldr.Add(String_.new_u8(wiki_key), Int_.To_str_pad_bgn_zero(ns_id, 3), ttl, qid);
|
||||
|
||||
@@ -78,9 +78,9 @@ public class Random_selection_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
int options_len = options_ary.length;
|
||||
for (int i = 0; i < options_len; ++i) {
|
||||
Rndsel_option_itm option = options_ary[i];
|
||||
rnd -= option.Weight();
|
||||
rnd -= option.Weight;
|
||||
if (rnd <= 0) {
|
||||
option_bry = option.Text();
|
||||
option_bry = option.Text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class Random_selection_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
public static int Rnd_test = -1;
|
||||
}
|
||||
class Rndsel_option_itm {
|
||||
public Rndsel_option_itm(int weight, byte[] text) {this.weight = weight; this.text = text;}
|
||||
public int Weight() {return weight;} private final int weight;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public Rndsel_option_itm(int weight, byte[] text) {this.Weight = weight; this.Text = text;}
|
||||
public final int Weight;
|
||||
public final byte[] Text;
|
||||
}
|
||||
|
||||
51
400_xowa/src/gplx/xowa/xtns/wikias/Tabber_tab_itm.java
Normal file
51
400_xowa/src/gplx/xowa/xtns/wikias/Tabber_tab_itm.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.htmls.*;
|
||||
class Tabber_tab_itm {
|
||||
public Tabber_tab_itm(boolean active, byte[] name, byte[] text) {
|
||||
this.Active = active;
|
||||
this.Name = name;
|
||||
this.Text = text;
|
||||
}
|
||||
public final boolean Active;
|
||||
public final byte[] Name;
|
||||
public final byte[] Text;
|
||||
public static void Write(Bry_bfr bfr, byte[] id, Tabber_tab_itm[] ary) {
|
||||
bfr.Add_str_a7("<div id=\"tabber-");
|
||||
bfr.Add(id);
|
||||
bfr.Add_str_a7("\" class=\"tabber\">\n");
|
||||
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Tabber_tab_itm itm = ary[i];
|
||||
bfr.Add_str_a7("<div class=\"tabbertab\" title=\"");
|
||||
bfr.Add(Gfh_utl.Escape_html_as_bry(itm.Name));
|
||||
bfr.Add_str_a7("\"");
|
||||
if (itm.Active) {
|
||||
bfr.Add_str_a7(" data-active=\"true\"");
|
||||
}
|
||||
bfr.Add_str_a7(">\n");
|
||||
bfr.Add(Gfh_tag_.P_lhs);
|
||||
bfr.Add(itm.Text);
|
||||
bfr.Add(Gfh_tag_.P_rhs).Add_byte_nl();
|
||||
bfr.Add(Gfh_tag_.Div_rhs).Add_byte_nl();
|
||||
}
|
||||
bfr.Add(Gfh_tag_.Div_rhs);
|
||||
}
|
||||
}
|
||||
@@ -19,43 +19,45 @@ package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import gplx.xowa.htmls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Tabber_xnde implements Xox_xnde {
|
||||
private static final byte[] Spr__tab_itms = Bry_.new_a7("|-|");
|
||||
private byte[] html;
|
||||
private byte[] id;
|
||||
private Tabber_tab_itm[] tab_itms_ary;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
tmp_bfr.Add_str_a7("<div id=\"tabber-\" "); // TODO: add key which is md5 of inner src
|
||||
tmp_bfr.Add_str_a7("class=\"tabber\">\n");
|
||||
|
||||
// split on "|-|"; EX: "A|-|B" -> tab_1='A'; tab_2='B'
|
||||
byte[][] tab_itms = Bry_split_.Split(src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), Spr__tab_itms);
|
||||
List_adp tab_itms_list = List_adp_.new_();
|
||||
byte[] xnde_body = Xox_xnde_.Extract_body_or_null(src, xnde); if (xnde_body == null) return;
|
||||
this.id = Id_test == null ? gplx.core.security.HashAlgo_.Md5.Calc_hash_bry(xnde_body) : Id_test;
|
||||
byte[][] tab_itms = Bry_split_.Split(xnde_body, Spr__tab_itms);
|
||||
for (int i = 0; i < tab_itms.length; ++i) {
|
||||
byte[] tab_itm = tab_itms[i];
|
||||
tab_itm = Bry_.Trim(tab_itm);
|
||||
int tab_itm_len = tab_itm.length; if (tab_itm_len == 0) continue;
|
||||
|
||||
// split on "="; EX: A=B -> tab_name='A'; tab_body = 'B'
|
||||
byte[][] tab_parts = Bry_split_.Split(tab_itm, Byte_ascii.Eq);
|
||||
byte[] tab_head = tab_parts[0];
|
||||
byte[] tab_body = tab_parts.length == 1 ? Bry_.Empty : Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), tab_parts[1], false);
|
||||
|
||||
tmp_bfr.Add_str_a7("<div class=\"tabbertab\" title=\"");
|
||||
tmp_bfr.Add(Gfh_utl.Escape_html_as_bry(tab_head));
|
||||
tmp_bfr.Add_str_a7("\">\n");
|
||||
tmp_bfr.Add(Gfh_tag_.P_lhs);
|
||||
tmp_bfr.Add(tab_body);
|
||||
tmp_bfr.Add(Gfh_tag_.P_rhs).Add_byte_nl();
|
||||
tmp_bfr.Add(Gfh_tag_.Div_rhs).Add_byte_nl();
|
||||
byte[] tab_head = null, tab_body = null;
|
||||
int eq_pos = Bry_find_.Find_fwd(tab_itm, Byte_ascii.Eq);
|
||||
if (eq_pos == Bry_find_.Not_found) {
|
||||
tab_head = tab_itm;
|
||||
tab_body = Bry_.Empty;
|
||||
}
|
||||
else {
|
||||
tab_head = Bry_.Mid(tab_itm, 0, eq_pos);
|
||||
tab_body = Bry_.Mid(tab_itm, eq_pos + 1, tab_itm_len);
|
||||
tab_body = Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), tab_body, false);
|
||||
}
|
||||
tab_itms_list.Add(new Tabber_tab_itm(Bool_.N, tab_head, tab_body));
|
||||
}
|
||||
tmp_bfr.Add(Gfh_tag_.Div_rhs);
|
||||
html = tmp_bfr.To_bry_and_clear();
|
||||
tab_itms_ary = (Tabber_tab_itm[])tab_itms_list.To_ary_and_clear(Tabber_tab_itm.class);
|
||||
|
||||
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
if (html != null) bfr.Add(html);
|
||||
if (tab_itms_ary != null) Tabber_tab_itm.Write(bfr, id, tab_itms_ary);
|
||||
}
|
||||
|
||||
public static byte[] Id_test;
|
||||
private static final byte[] Spr__tab_itms = Bry_.new_a7("|-|");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import org.junit.*;
|
||||
public class Tabber_xnde_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Before public void init() {
|
||||
fxt.Reset();
|
||||
Tabber_xnde.Id_test = Bry_.new_a7("test");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabber>"
|
||||
@@ -28,7 +31,7 @@ public class Tabber_xnde_tst {
|
||||
, "tab2=''b''"
|
||||
, "</tabber>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-\" class=\"tabber\">"
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p><i>a</i></p>"
|
||||
, "</div>"
|
||||
@@ -38,17 +41,30 @@ public class Tabber_xnde_tst {
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Eq_missing() {
|
||||
@Test public void Eq__missing() {
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabber>"
|
||||
, "tab1"
|
||||
, "</tabber>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-\" class=\"tabber\">"
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p></p>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Eq__many() {
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabber>"
|
||||
, "tab1=A=B"
|
||||
, "</tabber>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p>A=B</p>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,136 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Tabview_xnde implements Xox_xnde {
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public class Tabview_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
private byte[] id;
|
||||
private Tabber_tab_itm[] tab_itms_ary;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
|
||||
switch (xatr_id) {
|
||||
case Xatr__id: id = xatr.Val_as_bry(); break;
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
ctx.Page().Html_data().Head_mgr().Itm__graph().Enabled_y_();
|
||||
Xox_xnde_.Parse_xatrs(wiki, this, xatrs_hash, src, xnde);
|
||||
|
||||
// get id
|
||||
id = Keep_alphanum(id);
|
||||
if (Bry_.Len_eq_0(id)) id = Int_.To_bry(global_id++);
|
||||
|
||||
// parse src
|
||||
byte[] tabs_src = Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
tabs_src = Bry_.Trim(tabs_src); // if(isset($tabs[0]) && $tabs[0] == "") {unset($tabs[0]);} if($tabs[count($tabs)] == "") {unset($tabs[count($tabs)]);}
|
||||
byte[][] tabs_ary = Bry_split_.Split_lines(tabs_src);
|
||||
List_adp tabs_list = List_adp_.new_();
|
||||
int tabs_len = tabs_ary.length;
|
||||
for (int i = 0; i < tabs_len; ++i) {
|
||||
Tabview_tab_itm itm = Tabview_tab_itm.Parse(wiki, ctx, tabs_ary[i]);
|
||||
if (itm != null)
|
||||
tabs_list.Add(itm);
|
||||
}
|
||||
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
|
||||
Tabview_tab_itm[] ary = (Tabview_tab_itm[])tabs_list.To_ary_and_clear(Tabview_tab_itm.class);
|
||||
tab_itms_ary = Tabview_tab_itm.To_tabber_ary(ary);
|
||||
|
||||
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
bfr.Add_mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
if (tab_itms_ary != null) Tabber_tab_itm.Write(bfr, id, tab_itms_ary);
|
||||
// write html
|
||||
//Bry_bfr bfr = Bry_bfr.new_();
|
||||
//bfr.Add_str_a7("<div id=\"flytabs_");
|
||||
//bfr.Add(id);
|
||||
//bfr.Add_str_a7("\">\n<ul>\n");
|
||||
//int ary_len = ary.length;
|
||||
//for (int i = 0; i < ary_len; ++i) {
|
||||
// Tabview_tab_itm itm = ary[i];
|
||||
// bfr.Add_str_a7("<li><a href=");
|
||||
// // href
|
||||
// bfr.Add_str_a7("><span>");
|
||||
// bfr.Add(itm.Tab_name);
|
||||
// bfr.Add_str_a7("</span></a></li>");
|
||||
//}
|
||||
//bfr.Add_str_a7("</ul>\n</div>\n");
|
||||
}
|
||||
|
||||
private int global_id = 0;
|
||||
public static final byte Xatr__id = 0;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7().Add_str_byte("id", Xatr__id);
|
||||
private static byte[] Keep_alphanum(byte[] src) {
|
||||
if (src == null) return null;
|
||||
int src_len = src.length; if (src_len == 0) return src;
|
||||
Bry_bfr bfr = null;
|
||||
for (int i = 0; i < src_len; ++i) {
|
||||
byte b = src[i];
|
||||
if ( Byte_ascii.Is_ltr(b)
|
||||
|| Byte_ascii.Is_num(b)) {
|
||||
if (bfr != null) bfr.Add_byte(b);
|
||||
}
|
||||
else { // not alphanum;
|
||||
if (bfr == null) { // 1st occurrence; create bfr and add initial to it
|
||||
bfr = Bry_bfr.new_();
|
||||
bfr.Add_mid(src, 0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return bfr == null ? src : bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
class Tabview_tab_itm {
|
||||
public Tabview_tab_itm(boolean active, boolean cache, byte[] tab_name, byte[] page_ttl_bry, byte[] page_body) {
|
||||
this.Active = active;
|
||||
this.Cache = cache;
|
||||
this.Tab_name = tab_name;
|
||||
this.Page_ttl_bry = page_ttl_bry;
|
||||
this.Page_body = page_body;
|
||||
}
|
||||
public final boolean Active;
|
||||
public final boolean Cache;
|
||||
public final byte[] Tab_name;
|
||||
public final byte[] Page_ttl_bry;
|
||||
public final byte[] Page_body;
|
||||
|
||||
public static Tabview_tab_itm Parse(Xowe_wiki wiki, Xop_ctx ctx, byte[] src) {
|
||||
byte[][] args_ary = Bry_split_.Split(src, Byte_ascii.Pipe);
|
||||
int args_len = args_ary.length;
|
||||
|
||||
boolean cache = false, active = false;
|
||||
byte[] tab_name = null, page_ttl_bry = null, page_body = null;
|
||||
for (int i = 0; i < args_len; ++i) {
|
||||
byte[] args_itm = args_ary[i];
|
||||
switch (i) {
|
||||
case 0:
|
||||
page_ttl_bry = args_itm;
|
||||
if (Bry_.Has_at_bgn(page_ttl_bry, Byte_ascii.Angle_bgn) || Bry_.Has_at_end(page_ttl_bry, Byte_ascii.Angle_end)) return null;
|
||||
Xoa_ttl page_ttl = wiki.Ttl_parse(page_ttl_bry);
|
||||
if (page_ttl == null) return null;
|
||||
gplx.xowa.wikis.caches.Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl);
|
||||
if (page_itm == null) return null;
|
||||
page_body = page_itm.Wtxt__redirect_or_direct();
|
||||
page_body = Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), page_body, false);
|
||||
break;
|
||||
case 1:
|
||||
tab_name = args_itm;
|
||||
if (Bry_.Has_at_bgn(tab_name, Byte_ascii.Angle_bgn) || Bry_.Has_at_end(tab_name, Byte_ascii.Angle_end)) return null;
|
||||
break;
|
||||
case 2:
|
||||
cache = Bry_.To_bool_or(args_itm, false);
|
||||
break;
|
||||
case 3:
|
||||
active = Bry_.To_bool_or(args_itm, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new Tabview_tab_itm(active, cache, tab_name, page_ttl_bry, page_body);
|
||||
}
|
||||
public static Tabber_tab_itm[] To_tabber_ary(Tabview_tab_itm[] ary) {
|
||||
int len = ary.length;
|
||||
Tabber_tab_itm[] rv = new Tabber_tab_itm[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Tabview_tab_itm src = ary[i];
|
||||
rv[i] = new Tabber_tab_itm(src.Active, src.Tab_name, src.Page_body);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
42
400_xowa/src/gplx/xowa/xtns/wikias/Tabview_xnde_tst.java
Normal file
42
400_xowa/src/gplx/xowa/xtns/wikias/Tabview_xnde_tst.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Tabview_xnde_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Basic() {
|
||||
fxt.Init_page_create("A", "''a''");
|
||||
fxt.Init_page_create("B", "''b''");
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabview id='test'>"
|
||||
, "A|tab1"
|
||||
, "B|tab2||true"
|
||||
, "</tabview>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p><i>a</i></p>"
|
||||
, "</div>"
|
||||
, "<div class=\"tabbertab\" title=\"tab2\" data-active=\"true\">"
|
||||
, "<p><i>b</i></p>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.htmls.*;
|
||||
class Xo_custom_html_pos_ {
|
||||
public static final byte Tid__head_end = 1, Tid__tail = 2;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("head_end", Tid__head_end)
|
||||
.Add_str_byte("tail", Tid__tail)
|
||||
;
|
||||
public static byte To_tid(byte[] bry) {
|
||||
byte tid = hash.Get_as_byte_or(bry, Byte_.Max_value_127);
|
||||
if (tid == Byte_.Max_value_127) throw Err_.new_wo_type("unknown pos", "pos", bry);
|
||||
return tid;
|
||||
}
|
||||
}
|
||||
class Xo_custom_html_type_ {
|
||||
public static final byte Tid__css_code = 1, Tid__js_code = 2;
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Gfh_tag_.Bry__style , Tid__css_code)
|
||||
.Add_bry_byte(Gfh_tag_.Bry__script , Tid__js_code)
|
||||
;
|
||||
public static byte[] To_bry(byte tid) {
|
||||
switch (tid) {
|
||||
case Tid__css_code: return Gfh_tag_.Bry__style;
|
||||
case Tid__js_code : return Gfh_tag_.Bry__script;
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
}
|
||||
}
|
||||
public static byte To_tid(byte[] bry) {
|
||||
byte tid = hash.Get_as_byte_or(bry, Byte_.Max_value_127); if (tid == Byte_.Max_value_127) throw Err_.new_wo_type("unknown type", "type", bry);
|
||||
return tid;
|
||||
}
|
||||
}
|
||||
@@ -16,18 +16,16 @@ 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.xowa_cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
private byte pos_val = Pos_head_end;
|
||||
public Xop_root_tkn Xtn_root() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_root should not be called");}
|
||||
public byte[] Xtn_html() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_html should not be called");}
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {
|
||||
if (xatr_id_obj == null) return;
|
||||
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
|
||||
switch (xatr_id.Val()) {
|
||||
case Xatr_pos_id: pos_val = Pos_val(xatr.Val_as_bry()); break;
|
||||
default: throw Err_.new_unhandled(xatr_id.Val());
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
private byte tag_pos = Xo_custom_html_pos_.Tid__head_end, tag_type = Xo_custom_html_type_.Tid__css_code;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
|
||||
switch (xatr_id) {
|
||||
case Xatr__pos: tag_pos = Xo_custom_html_pos_.To_tid(xatr.Val_as_bry()); break;
|
||||
case Xatr__type: tag_type = Xo_custom_html_type_.To_tid(xatr.Val_as_bry()); break;
|
||||
default: throw Err_.new_unhandled(xatr_id);
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
@@ -35,32 +33,27 @@ public class Xox_xowa_html_cmd implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "xowa_html command only allowed in xowa_home");
|
||||
return;
|
||||
}
|
||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
||||
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn();
|
||||
if (src[itm_bgn] == Byte_ascii.Nl) ++itm_bgn; // ignore 1st \n;
|
||||
// if (src[itm_end - 1] == Byte_ascii.Nl) --itm_end; // ignore last \n;
|
||||
byte[] raw = Bry_.Mid(src, itm_bgn, itm_end);
|
||||
if (pos_val == Pos_head_end)
|
||||
ctx.Page().Html_data().Custom_head_end_concat(raw);
|
||||
else
|
||||
ctx.Page().Html_data().Custom_html_end_concat(raw);
|
||||
|
||||
// parse xnde for tag_name, tag_body
|
||||
Xox_xnde_.Parse_xatrs(wiki, this, xatr_hash, src, xnde);
|
||||
byte[] name = Xo_custom_html_type_.To_bry(tag_type);
|
||||
int raw_bgn = xnde.Tag_open_end(), raw_end = xnde.Tag_close_bgn();
|
||||
raw_bgn = Bry_find_.Find_fwd_while_ws(src, raw_bgn, raw_end);
|
||||
raw_end = Bry_find_.Find_bwd__skip_ws(src, raw_end, raw_bgn);
|
||||
if (src[raw_bgn] == Byte_ascii.Nl) ++raw_bgn;
|
||||
if (src[raw_bgn] == Byte_ascii.Nl) ++raw_bgn;
|
||||
byte[] raw = Bry_.Mid(src, raw_bgn, raw_end);
|
||||
|
||||
// add to custom tags
|
||||
Xopg_html_data html_data = ctx.Page().Html_data();
|
||||
Xopg_tag_mgr tag_mgr = tag_pos == Xo_custom_html_pos_.Tid__tail ? html_data.Custom_tail_tags() : html_data.Custom_head_tags();
|
||||
tag_mgr.Add(new Xopg_tag_itm(name, raw));
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
|
||||
private static byte Pos_val(byte[] bry) {
|
||||
Object o = pos_val_hash.Get_by_bry(bry);
|
||||
if (o == null) throw Err_.new_wo_type("unknown pos", "pos", String_.new_u8(bry));
|
||||
return ((Byte_obj_val)o).Val();
|
||||
}
|
||||
private static final byte Pos_head_end = 1, Pos_html_end = 2;
|
||||
private static final byte[]
|
||||
Xatr_pos_key = Bry_.new_a7("pos")
|
||||
, Xatr_pos_val__head_end = Bry_.new_a7("head.end")
|
||||
, Xatr_pos_val__html_end = Bry_.new_a7("html.end")
|
||||
;
|
||||
private static final Hash_adp_bry pos_val_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Xatr_pos_val__head_end, Pos_head_end)
|
||||
.Add_bry_byte(Xatr_pos_val__html_end, Pos_html_end)
|
||||
;
|
||||
private static final byte Xatr_pos_id = 1;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7().Add_bry_byte(Xatr_pos_key, Xatr_pos_id);
|
||||
|
||||
public Xop_root_tkn Xtn_root() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_root should not be called");}
|
||||
public byte[] Xtn_html() {throw Err_.new_unimplemented_w_msg("xowa_html_cmd.xtn_html should not be called");}
|
||||
|
||||
private static final byte Xatr__pos = 1, Xatr__type = 2;
|
||||
private static final Hash_adp_bry xatr_hash = Hash_adp_bry.ci_a7().Add_str_byte("pos", Xatr__pos).Add_str_byte("type", Xatr__type);
|
||||
}
|
||||
|
||||
@@ -23,20 +23,20 @@ public class Xox_xowa_html_cmd_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xox_xowa_html_cmd_fxt fxt = new Xox_xowa_html_cmd_fxt();
|
||||
@Test public void Head_end() {
|
||||
fxt.Test_parse_w_skin
|
||||
( "<xowa_html pos='head.end'>test</xowa_html>"
|
||||
, "<html><head>test</head><body></body></html>"
|
||||
( "<xowa_html pos='head_end'>test</xowa_html>"
|
||||
, "<html><head><style>\ntest\n</style>\n</head><body></body></html>"
|
||||
);
|
||||
}
|
||||
@Test public void Html_end() {
|
||||
@Test public void Tail() {
|
||||
fxt.Test_parse_w_skin
|
||||
( "<xowa_html pos='html.end'>test</xowa_html>"
|
||||
, "<html><head></head><body></body>test</html>"
|
||||
( "<xowa_html pos='tail'>test</xowa_html>"
|
||||
, "<html><head></head><body></body><style>\ntest\n</style>\n</html>"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xox_xowa_html_cmd_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(16);
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
private Xowe_wiki wiki; private Xow_html_mgr html_mgr;
|
||||
public void Clear() {
|
||||
this.wiki = fxt.Wiki();
|
||||
|
||||
Reference in New Issue
Block a user