1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/*
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 gplx.core.btries.*; import gplx.xowa.langs.numbers.*;
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);
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);
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)
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[] 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() {}
}

View File

@@ -0,0 +1,39 @@
/*
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.*;
public class Pfunc_wiki_props extends Pf_func_base {
public Pfunc_wiki_props(int id) {this.id = id;}
@Override public int Id() {return id;} private int id;
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
Xow_wiki_props props = ctx.Wiki().Props();
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_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;
case Xol_kwd_grp_.Id_site_directionmark: bfr.Add(props.DirectionMark()); break;
case Xol_kwd_grp_.Id_site_currentversion: bfr.Add(props.Current_version()); break;
case Xol_kwd_grp_.Id_site_contentlanguage: bfr.Add(ctx.Cur_page().Lang().Key_bry()); break;
default: throw Exc_.new_unhandled(id);
}
}
@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);
}

View File

@@ -0,0 +1,39 @@
/*
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.langs.*;
public class Pfunc_wiki_props_tst {
private Xop_fxt fxt = new Xop_fxt();
@Before public void setup() {fxt.Reset(); fxt.Wiki().Stats().NumPages_(1).NumArticles_(2).NumFiles_(3).NumEdits_(4).NumViews_(5).NumUsers_(6).NumUsersActive_(7).NumAdmins_(8);}
@Test public void NumPages() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFPAGES}}" , "{{test}}", "1");}
@Test public void NumArticles() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFARTICLES}}" , "{{test}}", "2");}
@Test public void NumFiles() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFFILES}}" , "{{test}}", "3");}
@Test public void NumEdits() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFEDITS}}" , "{{test}}", "4");}
@Test public void NumViews() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFVIEWS}}" , "{{test}}", "5");}
@Test public void NumUsers() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFUSERS}}" , "{{test}}", "6");}
@Test public void NumUsersActive() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFACTIVEUSERS}}" , "{{test}}", "7");}
@Test public void NumAdmins() {fxt.Test_parse_tmpl_str_test("{{NUMBEROFADMINS}}" , "{{test}}", "8");}
@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);
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

@@ -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.pfuncs.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_wiki_stats extends Pf_func_base {
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr rslt_bfr) {
byte[] argx = Eval_argx(ctx, src, caller, self);
boolean raw = false;
if (argx.length == 1) {
byte argx_0 = argx[0];
switch (argx_0) {case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_r: raw = true; break;}
}
Xow_wiki_stats stats = ctx.Wiki().Stats();
int v = 0;
switch (id) {
case Xol_kwd_grp_.Id_num_pages: v = stats.NumPages(); break;
case Xol_kwd_grp_.Id_num_articles: v = stats.NumArticles(); break;
case Xol_kwd_grp_.Id_num_files: v = stats.NumFiles(); break;
case Xol_kwd_grp_.Id_num_edits: v = stats.NumEdits(); break;
case Xol_kwd_grp_.Id_num_views: v = stats.NumViews(); break;
case Xol_kwd_grp_.Id_num_users: v = stats.NumUsers(); break;
case Xol_kwd_grp_.Id_num_users_active: v = stats.NumUsersActive(); break;
case Xol_kwd_grp_.Id_num_admins: v = stats.NumAdmins(); break;
default: throw Exc_.new_unhandled(id);
}
if (raw)
rslt_bfr.Add_int_variable(v);
else
rslt_bfr.Add(ctx.Cur_page().Lang().Num_mgr().Format_num(v));
}
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);
}

View File

@@ -0,0 +1,32 @@
/*
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.*;
public class Pfunc_wiki_stats_tst {
private 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 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");}
@Test public void ContentLanguage() {fxt.Test_parse_tmpl_str_test("{{CONTENTLANG}}" , "{{test}}", "en");}
@Test public void DirectionMark() {fxt.Test_parse_tmpl_str_test("{{DIRECTIONMARK}}" , "{{test}}", "");}
@Test public void CurrentVersion() {fxt.Test_parse_tmpl_str_test("{{CURRENTVERSION}}" , "{{test}}", "1.21wmf11");}
}