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

v2.10.3.1

This commit is contained in:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

View File

@@ -17,31 +17,70 @@ 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 gplx.core.btries.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.numbers.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Pfunc_pagesincategory extends Pf_func_base {
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bb) {
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self); if (Bry_.Len_eq_0(val_dat_ary)) {bb.Add_int_fixed(0, 1); return;}
val_dat_ary = Xoa_ttl.Replace_spaces(val_dat_ary);
@Override public int Id() {return Xol_kwd_grp_.Id_site_pagesincategory;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_pagesincategory().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) { // REF.MW: /includes/parser/CoreParserFunctions.php|pagesincategory
byte[] ctg_ttl_bry = Eval_argx(ctx, src, caller, self);
if (Bry_.Len_eq_0(ctg_ttl_bry)) {bfr.Add_int_digits(1, 0); return;} // no title; EX: "{{PAGESINCATEGORY:}}"
Xowe_wiki wiki = ctx.Wiki();
int ctg_len = wiki.Db_mgr().Load_mgr().Load_ctg_count(val_dat_ary);
if (ctg_len == 0) {bb.Add_int_fixed(0, 1); return;}
Xol_lang lang = wiki.Lang();
if (trie == null) trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_str_rawsuffix);
Xowd_db_mgr core_data_mgr = wiki.Data__core_mgr();
int ctg_id = core_data_mgr.Tbl__page().Select_id(Xow_ns_.Id_category, Xoa_ttl.Replace_spaces(ctg_ttl_bry));
if (ctg_id == Xowd_page_itm.Id_null) {bfr.Add_int_digits(1, 0); return;} // category doesn't exist; EX: "{{PAGESINCATEGORY:Unknown_category}}"
Xowd_category_itm ctg_itm = core_data_mgr.Db__cat_core().Tbl__cat_core().Select(ctg_id);
if (ctg_itm == null) {bfr.Add_int_digits(1, 0); return;} // category counts don't exist; shouldn't happen
Xol_lang_itm lang = wiki.Lang();
Btrie_slim_mgr num_format_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_str_rawsuffix);
Btrie_slim_mgr type_page_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_pagesincategory_pages);
Btrie_slim_mgr type_subc_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_pagesincategory_subcats);
Btrie_slim_mgr type_file_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_pagesincategory_files);
boolean fmt_num = true; byte[] type_bry = null;
int self_args_len = self.Args_len();
byte[] arg_1 = self_args_len < 1 ? null : Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0);
byte[] arg_2 = self_args_len < 2 ? null : Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1);
if (num_format_trie.Match_exact(arg_1) != null) { // is arg_1 raw?
fmt_num = false;
type_bry = arg_2;
}
else {
type_bry = arg_1;
fmt_num = num_format_trie.Match_exact(arg_2) == null;
}
int num = ctg_itm.Count_all();
if (type_bry != null) {
if (type_page_trie.Match_exact(type_bry) != null) num = ctg_itm.Count_pages();
else if (type_subc_trie.Match_exact(type_bry) != null) num = ctg_itm.Count_subcs();
else if (type_file_trie.Match_exact(type_bry) != null) num = ctg_itm.Count_files();
}
byte[] num_bry = Int_.To_bry(num);
byte[] rslt = fmt_num ? lang.Num_mgr().Format_num(num_bry) : lang.Num_mgr().Raw(num_bry);
bfr.Add(rslt);
}
public void Func_evaluate_old(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] ctg_ttl_bry = Eval_argx(ctx, src, caller, self); if (Bry_.Len_eq_0(ctg_ttl_bry)) {bfr.Add_int_digits(1, 0); return;} // no title; return 0; EX: "{{PAGESINCATEGORY:}}"
ctg_ttl_bry = Xoa_ttl.Replace_spaces(ctg_ttl_bry);
Xowe_wiki wiki = ctx.Wiki();
int ctg_len = wiki.Db_mgr().Load_mgr().Load_ctg_count(ctg_ttl_bry);
if (ctg_len == 0) {bfr.Add_int_digits(1, 0); return;}
Xol_lang_itm lang = wiki.Lang();
Btrie_slim_mgr num_format_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_str_rawsuffix);
// Btrie_slim_mgr type_page_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_pagesincategory_pages);
// Btrie_slim_mgr type_subc_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_pagesincategory_subcats);
// Btrie_slim_mgr type_file_trie = Xol_kwd_mgr.trie_(lang.Kwd_mgr(), Xol_kwd_grp_.Id_pagesincategory_files);
int self_args_len = self.Args_len();
boolean fmt_num = true;
if (self_args_len == 1) {
byte[] arg1 = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0);
if (arg1 != Bry_.Empty && trie.Match_exact(arg1, 0, arg1.length) != null)
if (arg1 != Bry_.Empty && num_format_trie.Match_exact(arg1, 0, arg1.length) != null)
fmt_num = false;
}
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128().Mkr_rls();
byte[] ctg_len_bry = tmp_bfr.Add_int_variable(ctg_len).Xto_bry_and_clear();
byte[] ctg_len_bry = tmp_bfr.Add_int_variable(ctg_len).To_bry_and_clear();
byte[] rslt = fmt_num ? lang.Num_mgr().Format_num(ctg_len_bry) : lang.Num_mgr().Raw(ctg_len_bry);
bb.Add(rslt);
} private Btrie_slim_mgr trie;
@Override public int Id() {return Xol_kwd_grp_.Id_site_pagesincategory;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_pagesincategory().Name_(name);}
public static final Pfunc_pagesincategory _ = new Pfunc_pagesincategory(); Pfunc_pagesincategory() {}
bfr.Add(rslt);
}
public static final Pfunc_pagesincategory Instance = new Pfunc_pagesincategory(); Pfunc_pagesincategory() {}
}

View File

@@ -0,0 +1,65 @@
/*
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.pfuncs.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
public class Pfunc_pagesincategory_tst {
private final Pfunc_pagesincategory_tstr tstr = new Pfunc_pagesincategory_tstr();
@Before public void setup() {tstr.Init(); tstr.Init_category_counts("A", 1000, 2000, 3000);}
@Test public void Type__none() {tstr.Test_parse("{{PAGESINCATEGORY:A}}" , "6,000");}
@Test public void Type__none__fmt() {tstr.Test_parse("{{PAGESINCATEGORY:A|R}}" , "6000");}
@Test public void Type__page__1st() {tstr.Test_parse("{{PAGESINCATEGORY:A|pages}}" , "1,000");}
@Test public void Type__subc__1st() {tstr.Test_parse("{{PAGESINCATEGORY:A|subcats}}" , "2,000");}
@Test public void Type__file__1st() {tstr.Test_parse("{{PAGESINCATEGORY:A|files}}" , "3,000");}
@Test public void Type__page__2nd() {tstr.Test_parse("{{PAGESINCATEGORY:A|R|pages}}" , "1000");}
@Test public void Type__subc__2nd() {tstr.Test_parse("{{PAGESINCATEGORY:A|R|subcats}}" , "2000");}
@Test public void Type__file__2nd() {tstr.Test_parse("{{PAGESINCATEGORY:A|R|files}}" , "3000");}
@Test public void Zero__no_title() {tstr.Test_parse("{{PAGESINCATEGORY:}}" , "0");}
@Test public void Zero__missing_title() {tstr.Test_parse("{{PAGESINCATEGORY:Missing}}" , "0");}
@Test public void Wrong_args() {tstr.Test_parse("{{PAGESINCATEGORY:A|invalid|x}}" , "6,000");} // defaults to all,fmt
}
class Pfunc_pagesincategory_tstr {
private final Xop_fxt parser_tstr;
private final Xoae_app app; private final Xowe_wiki wiki;
private final Xowd_db_mgr core_data_mgr;
private final Xowd_page_tbl page_tbl; private final Xowd_cat_core_tbl cat_core_tbl;
public Pfunc_pagesincategory_tstr() {
Xoa_test_.Inet__init();
this.app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
Xoa_test_.Db__init__mem(wiki);
this.parser_tstr = new Xop_fxt(app, wiki);
this.core_data_mgr = wiki.Data__core_mgr();
this.page_tbl = core_data_mgr.Tbl__page();
this.cat_core_tbl = core_data_mgr.Db__cat_core().Tbl__cat_core();
}
public void Init() {
parser_tstr.Reset();
}
public void Init_category_counts(String category_title, int pages, int subcs, int files) {
int page_id = 1;
page_tbl.Insert_bgn();
page_tbl.Insert_cmd_by_batch(page_id, Xow_ns_.Id_category, Bry_.new_u8(category_title), Bool_.N, DateAdp_.Now(), 1, 1, 1, 1);
page_tbl.Insert_end();
cat_core_tbl.Insert_bgn();
cat_core_tbl.Insert_cmd_by_batch(page_id, pages, subcs, files, Byte_.Zero, 1);
cat_core_tbl.Insert_end();
}
public void Test_parse(String raw, String expd) {
parser_tstr.Test_html_full_str(raw, expd);
}
}

View File

@@ -16,7 +16,7 @@ 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.pfuncs.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.wikis.metas.*;
public class Pfunc_wiki_props extends Pf_func_base {
@@ -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 _ = new Pfunc_wiki_props(-1);
public static final Pfunc_wiki_props Instance = new Pfunc_wiki_props(-1);
}

View File

@@ -32,7 +32,7 @@ public class Pfunc_wiki_props_tst {
@Test public void NumArticles_raw() {Init_numArticles(1234); fxt.Test_parse_tmpl_str_test("{{NUMBEROFARTICLES:R}}" , "{{test}}", "1234"); Init_numArticles(2);}
@Test public void NumArticles_fmt() {Init_numArticles(1234); fxt.Test_parse_tmpl_str_test("{{NUMBEROFARTICLES}}" , "{{test}}", "1,234"); Init_numArticles(2);}
@Test public void NumArticles_fmt_i18n() { // PURPOSE: use lang's num_mgr; PAGE:ru.u:Main_Page; DATE:2014-07-03
fxt.Lang_by_id_(Xol_lang_itm_.Id_ru);
fxt.Lang_by_id_(Xol_lang_stub_.Id_ru);
Init_numArticles(1234); fxt.Test_parse_tmpl_str_test("{{NUMBEROFARTICLES}}" , "{{test}}", "1234"); Init_numArticles(2);
}
private Pfunc_wiki_props_tst Init_numArticles(int v) {fxt.Wiki().Stats().NumArticles_(v); return this;}

View File

@@ -16,7 +16,7 @@ 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.pfuncs.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.wikis.metas.*;
public class Pfunc_wiki_stats extends Pf_func_base {
@@ -48,5 +48,5 @@ public class Pfunc_wiki_stats extends Pf_func_base {
public Pfunc_wiki_stats(int id) {this.id = id;}
@Override public int Id() {return id;} private int id;
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_wiki_stats(id).Name_(name);}
public static final Pfunc_wiki_stats _ = new Pfunc_wiki_stats(-1);
public static final Pfunc_wiki_stats Instance = new Pfunc_wiki_stats(-1);
}