mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Template_styles: Add support for template styles
This commit is contained in:
@@ -47,6 +47,7 @@ public class Xow_xtn_mgr implements Gfo_invk {
|
||||
Add(app, new gplx.xowa.xtns.pfuncs.scribunto.Pfunc_xtn_mgr());
|
||||
Add(app, new gplx.xowa.xtns.flaggedRevs.Flagged_revs_xtn_mgr());
|
||||
Add(app, new gplx.xowa.xtns.jsonConfigs.scribunto.Jscfg_xtn_mgr());
|
||||
Add(app, new gplx.xowa.xtns.cldrs.Cldr_name_xtn_mgr());
|
||||
return this;
|
||||
}
|
||||
public Xow_xtn_mgr Ctor_by_wiki(Xowe_wiki wiki) {
|
||||
|
||||
@@ -20,8 +20,8 @@ public class Cldr_name_loader {
|
||||
private final Io_url cldr_dir;
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
|
||||
public Cldr_name_loader(Io_url xowa_xtn_dir) {
|
||||
cldr_dir = xowa_xtn_dir.GenSubDir_nest("cldr", "CldrNames");
|
||||
public Cldr_name_loader(Io_url root_dir) {
|
||||
cldr_dir = root_dir.GenSubDir_nest("bin", "any", "xowa", "xtns", "cldr", "CldrNames");
|
||||
}
|
||||
|
||||
public Cldr_name_file Load(String lang_key) {
|
||||
|
||||
24
400_xowa/src/gplx/xowa/xtns/cldrs/Cldr_name_xtn_mgr.java
Normal file
24
400_xowa/src/gplx/xowa/xtns/cldrs/Cldr_name_xtn_mgr.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.cldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Cldr_name_xtn_mgr extends Xox_mgr_base {
|
||||
// private Cldr_name_loader loader;
|
||||
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("CldrNames");
|
||||
@Override public Xox_mgr Xtn_clone_new() {return new Cldr_name_xtn_mgr();}
|
||||
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {
|
||||
// loader = new Cldr_name_loader(wiki.App().Fsys_mgr().Bin_xtns_dir());
|
||||
}
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/xtns/cldrs/Language_name.java
Normal file
31
400_xowa/src/gplx/xowa/xtns/cldrs/Language_name.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.cldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Language_name implements gplx.core.brys.Bry_bfr_able {
|
||||
public Language_name(byte[] code, byte[] name, byte[] note) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.note = note;
|
||||
}
|
||||
public byte[] Code() {return code;} private final byte[] code;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public byte[] Note() {return note;} private final byte[] note;
|
||||
public void To_bfr(Bry_bfr bfr) {
|
||||
bfr.Add(code).Add_byte_pipe();
|
||||
bfr.Add(name).Add_byte_pipe();
|
||||
bfr.Add(note);
|
||||
}
|
||||
}
|
||||
57
400_xowa/src/gplx/xowa/xtns/cldrs/Language_name_loader.java
Normal file
57
400_xowa/src/gplx/xowa/xtns/cldrs/Language_name_loader.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.cldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Language_name_loader {
|
||||
private final Json_parser parser = new Json_parser();
|
||||
private final Io_url names_url;
|
||||
|
||||
public Language_name_loader(Io_url root_dir) {
|
||||
names_url = root_dir.GenSubFil_nest("bin", "any", "xowa", "cfg", "lang", "data", "names.json");
|
||||
}
|
||||
public Ordered_hash Load_as_hash() {
|
||||
byte[] json = Io_mgr.Instance.LoadFilBry(names_url);
|
||||
if (json == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "no names file exists");
|
||||
return Ordered_hash_.New();
|
||||
}
|
||||
Language_name[] ary = Load(json);
|
||||
|
||||
// convert
|
||||
Ordered_hash rv = Ordered_hash_.New();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Language_name itm = ary[i];
|
||||
rv.Add(itm.Code(), Keyval_.new_(String_.new_u8(itm.Code()), itm.Name()));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Language_name[] Load(byte[] json) {
|
||||
List_adp list = List_adp_.New();
|
||||
|
||||
Json_doc jdoc = parser.Parse(json);
|
||||
Json_ary root = jdoc.Root_ary();
|
||||
int len = root.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Json_nde node = root.Get_as_nde(i);
|
||||
byte[] code = node.Get_as_bry("code");
|
||||
byte[] name = node.Get_as_bry("name");
|
||||
Language_name itm = new Language_name(code, name, null);
|
||||
list.Add(itm);
|
||||
}
|
||||
return (Language_name[])list.To_ary_and_clear(Language_name.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.cldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.langs.phps.*;
|
||||
import gplx.langs.jsons.*;
|
||||
|
||||
// REF.MW: /languages/data/Names.php
|
||||
class Language_names_converter {
|
||||
private final Php_parser parser = new Php_parser();
|
||||
private final Php_evaluator eval = new Php_evaluator(new gplx.core.log_msgs.Gfo_msg_log("test")).Comments_for_kv_();
|
||||
private final Php_text_itm_parser text_itm_parser = new Php_text_itm_parser().Quote_is_single_(true);
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
private final Byte_obj_ref tmp_result = Byte_obj_ref.zero_();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
|
||||
public Language_name[] Parse_fil(Io_url url) {
|
||||
byte[] src = Io_mgr.Instance.LoadFilBry(url);
|
||||
int bgn = Bry_find_.Find_fwd(src, Bry_.new_a7("$names"));
|
||||
int end = Bry_find_.Find_bwd(src, Bry_.new_a7("];"), src.length);
|
||||
return Parse(Bry_.Mid(src, bgn, end));
|
||||
}
|
||||
public Language_name[] Parse(byte[] src) {
|
||||
parser.Parse_tkns(src, eval);
|
||||
Php_line[] lines = (Php_line[])eval.List().To_ary(Php_line.class);
|
||||
|
||||
List_adp rv = List_adp_.New();
|
||||
int lines_len = lines.length;
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
Php_line line = lines[i];
|
||||
Php_line_assign assign_line = (Php_line_assign)line;
|
||||
|
||||
byte[][][] ary = Parse_ary_kvs(src, assign_line);
|
||||
for (byte[][] itm : ary) {
|
||||
rv.Add(new Language_name(itm[0], itm[1], itm[2]));
|
||||
}
|
||||
}
|
||||
eval.Clear();
|
||||
return (Language_name[])rv.To_ary_and_clear(Language_name.class);
|
||||
}
|
||||
private byte[][][] Parse_ary_kvs(byte[] src, Php_line_assign assign) {
|
||||
List_adp list = List_adp_.New();
|
||||
Php_itm_ary ary = (Php_itm_ary)assign.Val();
|
||||
int ary_len = ary.Subs_len();
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Php_itm_kv kv = (Php_itm_kv)ary.Subs_get(i);
|
||||
byte[] key = kv.Key().Val_obj_bry();
|
||||
byte[] val = text_itm_parser.Parse_as_bry(tmp_list, kv.Val().Val_obj_bry(), tmp_result, tmp_bfr);
|
||||
|
||||
int comments_len = kv.Comments__len();
|
||||
for (int j = 0; j < comments_len; j++) {
|
||||
if (j != 0) tmp_bfr.Add_byte_space();
|
||||
Php_tkn_comment tkn = kv.Comments__get_at__or_null(j);
|
||||
tkn.To_bfr(tmp_bfr, src, true);
|
||||
}
|
||||
byte[] comm = tmp_bfr.To_bry_and_clear();
|
||||
list.Add(new byte[][] {key, val, comm});
|
||||
}
|
||||
return (byte[][][])list.To_ary_and_clear(byte[][].class);
|
||||
}
|
||||
public String To_json(Language_name[] ary) {
|
||||
Json_doc_wtr doc_wtr = new Json_doc_wtr();
|
||||
doc_wtr.Ary_bgn();
|
||||
int len = ary.length;
|
||||
byte[] key_code = Bry_.new_a7("code");
|
||||
byte[] key_name = Bry_.new_a7("name");
|
||||
byte[] key_note = Bry_.new_a7("note");
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) doc_wtr.Comma();
|
||||
doc_wtr.Nde_bgn();
|
||||
Language_name itm = ary[i];
|
||||
doc_wtr.Kv(Bool_.N, key_code, itm.Code());
|
||||
doc_wtr.Kv(Bool_.Y, key_name, itm.Name());
|
||||
doc_wtr.Kv(Bool_.Y, key_note, itm.Note());
|
||||
doc_wtr.Nde_end();
|
||||
}
|
||||
doc_wtr.Ary_end();
|
||||
return doc_wtr.Bld_as_str();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.cldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.langs.phps.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Language_names_converter_tst {
|
||||
private final Language_names_converter_fxt fxt = new Language_names_converter_fxt();
|
||||
@Test public void Parse_fil() {
|
||||
fxt.Exec__Parse(String_.Concat_lines_nl
|
||||
( "/*ignore_bgn*/ $names = ["
|
||||
, " 'aa' => 'Afar', # comment_a "
|
||||
, " 'mic' => 'Mikmaq', # comment_m "
|
||||
, " 'zza' => 'Zaza', # comment_z "
|
||||
, "]; /*ignore_end*/"
|
||||
)
|
||||
, new Language_name[]
|
||||
{ fxt.Make__language_name("aa", "Afar", "comment_a")
|
||||
, fxt.Make__language_name("mic", "Mikmaq", "comment_m")
|
||||
, fxt.Make__language_name("zza", "Zaza", "comment_z")
|
||||
}, Json_doc.Make_str_by_apos
|
||||
( "["
|
||||
, " {"
|
||||
, " 'code':'aa'"
|
||||
, " , 'name':'Afar'"
|
||||
, " , 'note':'comment_a'"
|
||||
, " }"
|
||||
, ","
|
||||
, " {"
|
||||
, " 'code':'mic'"
|
||||
, " , 'name':'Mikmaq'"
|
||||
, " , 'note':'comment_m'"
|
||||
, " }"
|
||||
, ","
|
||||
, " {"
|
||||
, " 'code':'zza'"
|
||||
, " , 'name':'Zaza'"
|
||||
, " , 'note':'comment_z'"
|
||||
, " }"
|
||||
, "]"
|
||||
));
|
||||
}
|
||||
@Test public void Convert() {
|
||||
Language_names_converter converter = new Language_names_converter();
|
||||
Language_name[] names = converter.Parse_fil(Io_url_.new_dir_("C:\\000\\100_bin\\200_server\\200_http\\100_apache\\100_v2.4\\htdocs\\mediawiki\\v1.29.1\\languages\\data\\Names.php"));
|
||||
String json = converter.To_json(names);
|
||||
Io_mgr.Instance.SaveFilStr(Io_url_.new_fil_("C:\\xowa\\bin\\any\\xowa\\cfg\\lang\\data\\names.json"), json);
|
||||
}
|
||||
}
|
||||
class Language_names_converter_fxt {
|
||||
private final Language_names_converter converter = new Language_names_converter();
|
||||
public Language_name Make__language_name(String code, String name, String note) {return new Language_name(Bry_.new_u8(code), Bry_.new_u8(name), Bry_.new_u8(note));}
|
||||
public void Exec__Parse(String src, Language_name[] expd_names, String expd_json) {
|
||||
Language_name[] actl = converter.Parse(Bry_.new_u8(src));
|
||||
Gftest.Eq__ary(expd_names, actl);
|
||||
Gftest.Eq__ary__lines(expd_json, converter.To_json(actl));
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.xowa.xtns.jsonConfigs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.jsonConfigs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.names.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Jscfg_scrib_lib_tst {
|
||||
private final Jscfg_scrib_lib_fxt fxt = new Jscfg_scrib_lib_fxt();
|
||||
@@ -150,7 +150,7 @@ class Jscfg_scrib_lib_fxt {
|
||||
fxt.Parser_fxt().Init_page_create(commons_wiki, page, text);
|
||||
}
|
||||
public Xol_lang_itm Init__lang(String key, String fallbacks) {
|
||||
Xol_lang_itm lang = new Xol_lang_itm(fxt.Core().App().Lang_mgr(), Bry_.new_u8(key));
|
||||
Xol_lang_itm lang = Xol_lang_itm.New(fxt.Core().App().Lang_mgr(), Bry_.new_u8(key));
|
||||
lang.Fallback_bry_(Bry_.new_a7(fallbacks));
|
||||
return lang;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.pfuncs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*;
|
||||
import gplx.core.intls.*; import gplx.xowa.langs.numbers.*;
|
||||
import gplx.core.intls.*; import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.names.*;
|
||||
public class Pf_formatnum_es_tst {
|
||||
private Xop_fxt fxt;
|
||||
@Before public void init() {
|
||||
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();
|
||||
Xol_lang_itm lang = Xol_lang_itm.New(app.Lang_mgr(), Bry_.new_a7("es")).Init_by_load_assert();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "es.wikipedia.org", lang);
|
||||
fxt = new Xop_fxt(app, wiki);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.pfuncs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.intls.*; import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
|
||||
import gplx.core.intls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.names.*;
|
||||
public class Pf_formatnum_fa_tst {
|
||||
private Xop_fxt fxt;
|
||||
@Before public void init() {
|
||||
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();
|
||||
Xol_lang_itm lang = Xol_lang_itm.New(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.Make__wiki__edit(app, "fa.wikipedia.org", lang);
|
||||
fxt = new Xop_fxt(app, wiki);
|
||||
@@ -31,7 +32,7 @@ public class Pf_formatnum_fa_tst {
|
||||
@Test public void English() { // PURPOSE: make sure regular numbers are still read; DATE:2015-07-18
|
||||
fxt.Test_parse_tmpl_str_test("{{formatnum:150|R}}" , "{{test}}", "150");
|
||||
}
|
||||
public static final String Persian_numbers_gfs = String_.Concat_lines_nl
|
||||
public static final String Persian_numbers_gfs = String_.Concat_lines_nl
|
||||
( "numbers {"
|
||||
, " digits {"
|
||||
, " clear;"
|
||||
|
||||
@@ -28,7 +28,8 @@ class Pfunc_tag_kvp_wtr {
|
||||
if (key_bgn != -1)
|
||||
tmp.Add_byte(Byte_ascii.Eq);
|
||||
tmp.Add_byte(Byte_ascii.Quote);
|
||||
gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Encode(tmp, kvp_bry, val_bgn, val_end);// PURPOSE: escape html in atrs; PAGE:fr.v:France; DATE:2017-06-01
|
||||
// gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Encode(tmp, kvp_bry, val_bgn, val_end);// PURPOSE: escape html in atrs; PAGE:fr.w:France; DATE:2017-06-01
|
||||
gplx.langs.htmls.Gfh_utl.Escape_html_to_bfr(tmp, kvp_bry, val_bgn, val_end, true, true, true, true, true);
|
||||
tmp.Add_byte(Byte_ascii.Quote);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Pfunc_tag_tst {
|
||||
@Test public void Ws_all() {fxt.Test_html_full_str("{{#tag:pre|a| id = b }}" , "<pre id=\"b\">a</pre>");}
|
||||
@Test public void Ws_quoted() {fxt.Test_html_full_str("{{#tag:pre|a| id = ' b ' }}" , "<pre id=\"_b_\">a</pre>");}
|
||||
@Test public void Err_bad_key() {fxt.Test_html_full_str("{{#tag:pre|a|id=val|b}}" , "<pre id=\"val\">a</pre>");} // PURPOSE: b was failing b/c id was larger and key_end set to 4 (whereas b was len=1)
|
||||
@Test public void Html_is_escaped() {fxt.Test_html_full_str("{{#tag:pre|a|id='<br/>'}}" , "<pre id=\".3Cbr.2F.3E\">a</pre>");} // PURPOSE: escape html in atrs; PAGE:fr.v:France; DATE:2017-06-01
|
||||
@Test public void Html_is_escaped() {fxt.Test_html_full_str("{{#tag:pre|a|id='<br/>'}}" , "<pre id=\".3Cbr.2F.3E\">a</pre>");} // PURPOSE: escape html in atrs; PAGE:fr.w:France; DATE:2017-06-01
|
||||
// @Test public void Missing_val() {fxt.ini_Msg(Mwl_tag_rsc.Instance.Invalid).Test_parse_tmpl_str_test("{{#tag:pre|a|id=}}" , "{{test}}" , "");} // see {{Reflist|colwidth=30em}} -> <ref group=a>a</ref>{{#tag:references||group=}} -> ""
|
||||
// @Test public void Err() {
|
||||
// fxt.Test_parse_tmpl_str_test("{{#tag:ref|George Robertson announced in January 2003 that he would be stepping down in December.<ref> {{cite news|title =NATO Secretary General to Leave His Post in December After 4 Years |first = Craig | last = Smith | work = The New York Times | date = January 23, 2003| url = http://www.nytimes.com/2003/01/23/world/nato-secretary-general-to-leave-his-post-in-december-after-4-years.html?scp=2&sq=lord+robertson&st=nyt|accessdate = 2009-03-29}}</ref> Jaap de Hoop Scheffer was selected as his successor, but could not assume the office until January 2004 because of his commitment in the Dutch Parliament.<ref> {{cite news|title = Jaap de Hoop Scheffer | work = Newsmakers | issue = 1 | publisher = Thomson Gale | date = January 1, 2005}}</ref> Robertson was asked to extend his term until Scheffer was ready, but declined, so Minuto-Rizzo, the Deputy Secretary General, took over in the interim.<ref name =\"ncsd\" /> |group=N|}}"
|
||||
|
||||
@@ -130,6 +130,11 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
return rslt.Init_obj(valid);
|
||||
}
|
||||
public boolean FetchLanguageName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String lang_code = args.Pull_str(0);
|
||||
byte[] inLanguage = args.Pull_bry(1);
|
||||
String rv = core.App().Lang_mgr().Name_mgr().fetchLanguageName(lang_code, inLanguage, null);
|
||||
return rslt.Init_obj(rv);
|
||||
/*
|
||||
byte[] lang_code = args.Pull_bry(0);
|
||||
// byte[] trans_code = args.Get_bry_or_null(1); // TODO_OLD: FetchLanguageName("en", "fr") -> Anglais; WHEN: needs global database of languages; cldr
|
||||
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_null(lang_code);
|
||||
@@ -137,6 +142,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
? "" // unknown -> return ""; PAGE:en.w:United_States_Strategic_Bombing_Survey; DATE:2018-07-01
|
||||
: String_.new_u8(lang_itm.Canonical_name()); // known -> return canonical name
|
||||
return rslt.Init_obj(rv);
|
||||
*/
|
||||
}
|
||||
public boolean FetchLanguageNames(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
// byte[] lang_code = args.Cast_bry_or_null(0);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.template_styles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.wikis.caches.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.parsers.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Template_styles_nde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
private byte[] css_ttl_bry;
|
||||
private byte[] css_src;
|
||||
private Xoa_ttl css_ttl;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
|
||||
switch (xatr_id) {
|
||||
case Xatr__src: css_ttl_bry = 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);
|
||||
Xox_xnde_.Parse_xatrs(wiki, this, xatrs_hash, src, xnde);
|
||||
|
||||
// get css_ttl
|
||||
css_ttl = wiki.Ttl_parse(css_ttl_bry);
|
||||
if (css_ttl == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "Template_styles_nde.invalid_ttl: wiki=~{0} page=~{1} css_ttl=~{2}", wiki.Domain_bry(), ctx.Page().Url_bry_safe(), css_ttl_bry);
|
||||
return;
|
||||
}
|
||||
|
||||
// assume "Template:" if no explicit ns and no ":"
|
||||
if (!css_ttl.ForceLiteralLink() // no initial ":"
|
||||
&& css_ttl.Ns().Id_is_main()) {
|
||||
css_ttl = wiki.Ttl_parse(Bry_.Add(Xow_ns_.Bry__template_w_colon, css_ttl_bry));
|
||||
}
|
||||
|
||||
// get page
|
||||
Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm_2(css_ttl);
|
||||
css_src = page_itm == null ? null : page_itm.Wtxt__direct();
|
||||
if (css_src == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "Template_styles_nde.page_not_found: wiki=~{0} page=~{1} css_ttl=~{2}", wiki.Domain_bry(), ctx.Page().Url_bry_safe(), css_ttl_bry);
|
||||
}
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
|
||||
if (css_ttl == null) {
|
||||
bfr.Add_str_a7(formatTagError("Invalid title for TemplateStyles src attribute."));
|
||||
}
|
||||
else if (css_src == null) {
|
||||
bfr.Add_str_a7(formatTagError("Page " + String_.new_u8(css_ttl_bry) + " has no content."));
|
||||
}
|
||||
else {
|
||||
bfr.Add_str_a7("<style>");
|
||||
bfr.Add(css_src);
|
||||
bfr.Add_str_a7("</style>");
|
||||
}
|
||||
}
|
||||
private static String formatTagError(String msg) {
|
||||
// $parser->addTrackingCategory( 'templatestyles-page-error-category' );
|
||||
return "<strong class=\"error\">"
|
||||
// + call_user_func_array( 'wfMessage', $msg )->inContentLanguage()->parse()
|
||||
+ msg
|
||||
+ "</strong>";
|
||||
}
|
||||
public static final byte Xatr__src = 0;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7().Add_str_byte("src", Xatr__src);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.template_styles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Template_styles_nde_tst {
|
||||
private final Template_styles_nde_fxt fxt = new Template_styles_nde_fxt();
|
||||
@Before public void init() {
|
||||
fxt.Reset();
|
||||
}
|
||||
private static final String Css_red = ".red{color:red;}";
|
||||
private static final String Style_red = "<style>" + Css_red + "</style>";
|
||||
@Test public void Implicit_template() { // PURPOSE: default to template
|
||||
fxt.Init__page("Template:Test.css", Css_red);
|
||||
fxt.Test__parse
|
||||
( "<templatestyles src='Test.css'/>"
|
||||
, Style_red
|
||||
);
|
||||
}
|
||||
@Test public void Force_main() { // PURPOSE: ":" forces main
|
||||
fxt.Init__page("Test.css", Css_red);
|
||||
fxt.Test__parse
|
||||
( "<templatestyles src=':Test.css'/>"
|
||||
, Style_red
|
||||
);
|
||||
}
|
||||
@Test public void Explicit() { // PURPOSE: explicit ns
|
||||
fxt.Init__page("Module:Test.css", Css_red);
|
||||
fxt.Test__parse
|
||||
( "<templatestyles src='Module:Test.css'/>"
|
||||
, Style_red
|
||||
);
|
||||
}
|
||||
@Test public void Error__invalid_title() {
|
||||
fxt.Test__parse
|
||||
( "<templatestyles src='A|b.css'/>"
|
||||
, "<strong class=\"error\">Invalid title for TemplateStyles src attribute.</strong>"
|
||||
);
|
||||
}
|
||||
@Test public void Error__missing_page() {
|
||||
fxt.Test__parse
|
||||
( "<templatestyles src='Missing.css'/>"
|
||||
, "<strong class=\"error\">Page Missing.css has no content.</strong>"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Template_styles_nde_fxt {
|
||||
private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
public void Reset() {
|
||||
parser_fxt.Reset();
|
||||
parser_fxt.Wiki().Xtn_mgr().Init_by_wiki(parser_fxt.Wiki());
|
||||
}
|
||||
public void Init__page(String page, String text) {
|
||||
parser_fxt.Init_page_create(page, text);
|
||||
}
|
||||
public void Test__parse(String src, String expd) {
|
||||
parser_fxt.Test__parse__tmpl_to_html(src, expd);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user