mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
ParserFunctions: Add ParserFunction for PageLanguage [#595]
This commit is contained in:
parent
c67970b5b9
commit
bc976ac300
@ -275,5 +275,6 @@ kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_categorytree, "#categorytree");
|
||||
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_assessment, "#assessment");
|
||||
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_statements, "#statements");
|
||||
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_translation, "#translation");
|
||||
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_pagelanguage, "PAGELANGUAGE");
|
||||
}
|
||||
}
|
||||
|
@ -237,8 +237,9 @@ public static final int
|
||||
, Id_ttl_root_url = 217
|
||||
, Id_statements = 218
|
||||
, Id_translation = 219
|
||||
, Id_pagelanguage = 220
|
||||
;
|
||||
public static final int Id__max = 220;
|
||||
public static final int Id__max = 221;
|
||||
|
||||
private static byte[] ary_itm_(int id) {
|
||||
switch (id) {
|
||||
@ -462,6 +463,7 @@ case Xol_kwd_grp_.Id_categorytree: return Bry_.new_u8("categorytree");
|
||||
case Xol_kwd_grp_.Id_assessment: return Bry_.new_u8("assessment");
|
||||
case Xol_kwd_grp_.Id_statements: return Bry_.new_u8("statements");
|
||||
case Xol_kwd_grp_.Id_translation: return Bry_.new_u8("translation");
|
||||
case Xol_kwd_grp_.Id_pagelanguage: return Bry_.new_u8("pagelanguage");
|
||||
default: throw Err_.new_unhandled(id);
|
||||
}
|
||||
}
|
||||
|
@ -258,6 +258,7 @@ public class Pf_func_ {
|
||||
, Xol_kwd_grp_.Id_assessment
|
||||
, Xol_kwd_grp_.Id_statements
|
||||
, Xol_kwd_grp_.Id_translation
|
||||
, Xol_kwd_grp_.Id_pagelanguage
|
||||
};
|
||||
public static Xot_defn Get_prototype(int id) {
|
||||
switch (id) {
|
||||
@ -350,6 +351,7 @@ public class Pf_func_ {
|
||||
case Xol_kwd_grp_.Id_page_defaultsort: return Pfunc_defaultsort.Instance;
|
||||
case Xol_kwd_grp_.Id_noeditsection: return Pfunc_noeditsection.Instance;
|
||||
case Xol_kwd_grp_.Id_site_pagesincategory: return Pfunc_pagesincategory.Instance;
|
||||
case Xol_kwd_grp_.Id_pagelanguage: return Pfunc_pagelanguage.Instance;
|
||||
|
||||
case Xol_kwd_grp_.Id_url_ns: return new Pfunc_ns(false);
|
||||
case Xol_kwd_grp_.Id_url_nse: return new Pfunc_ns(true);
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
public class Pfunc_pagelanguage extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_pagelanguage;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_pagelanguage().Name_(name);}
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
bfr.Add(ctx.Page().Lang().Key_bry());
|
||||
// byte[] argx = Eval_argx(ctx, src, caller, self);
|
||||
// Xopg_db_protection rev_data = ctx.Page().Db().Protection();
|
||||
// switch (id) {
|
||||
// case Xol_kwd_grp_.Id_page_id:
|
||||
// case Xol_kwd_grp_.Id_rev_id: bfr.Add_int_variable(ctx.Page().Db().Page().Id()); break; // NOTE: making rev_id and page_id interchangeable; XOWA does not store rev_id
|
||||
// case Xol_kwd_grp_.Id_rev_user: bfr.Add(rev_data.User()); break;
|
||||
// case Xol_kwd_grp_.Id_rev_protectionlevel: bfr.Add(rev_data.Protection_level()); break;
|
||||
// case Xol_kwd_grp_.Id_rev_protectionexpiry: bfr.Add(rev_data.Protection_expiry()); break;
|
||||
// case Xol_kwd_grp_.Id_rev_revisionsize: // default revsize to pagesize; MW has additional logic for subst which should not apply to XO; https://gerrit.wikimedia.org/r/#/c/82650/
|
||||
// bfr.Add_int_variable(ctx.Page().Db().Text().Text_bry().length);
|
||||
// break;
|
||||
// case Xol_kwd_grp_.Id_rev_pagesize:
|
||||
// if (argx.length > 0) {
|
||||
// Xoa_ttl argx_ttl = Xoa_ttl.Parse(ctx.Wiki(), argx);
|
||||
// if (argx_ttl == null) { // invalid ttl; EX: {{PAGESIZE:{{{bad}}}}}
|
||||
// bfr.Add_byte(Byte_ascii.Num_0);
|
||||
// return;
|
||||
// }
|
||||
// Xoae_page argx_page = ctx.Wiki().Data_mgr().Load_page_by_ttl(argx_ttl);
|
||||
// if (argx_page.Db().Page().Exists()) {
|
||||
// bfr.Add_int_variable(argx_page.Db().Text().Text_bry().length);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// bfr.Add_byte(Byte_ascii.Num_0);
|
||||
// break;
|
||||
// default: throw Err_.new_unhandled(id);
|
||||
// }
|
||||
}
|
||||
public static final Pfunc_pagelanguage Instance = new Pfunc_pagelanguage();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Pfunc_pagelanguage__tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse__tmpl_to_html("{{PAGELANGUAGE}}", "en");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user