mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Wiki.Dom: Refactor Wiki.Props
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.parsers.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.metas.*;
|
||||
public class Xow_cfg_wiki_core {
|
||||
public Xow_cfg_wiki_core(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public void Save() {
|
||||
}
|
||||
public byte[] Build_gfs() {
|
||||
Xoa_gfs_bldr wtr = new Xoa_gfs_bldr();
|
||||
Xow_wiki_props props = wiki.Props();
|
||||
wtr.Add_proc_init_many(Xowe_wiki.Invk_props).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_bldr_version_).Add_parens_str(props.Bldr_version()).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_main_page_).Add_parens_str(props.Main_page()).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_siteinfo_misc_).Add_parens_str(props.Siteinfo_misc()).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_wiki_props.Invk_siteinfo_mainpage_).Add_parens_str(props.Siteinfo_mainpage()).Add_nl();
|
||||
wtr.Add_term_nl();
|
||||
wtr.Add_proc_init_many(Xowe_wiki.Invk_ns_mgr).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_ns_mgr.Invk_clear).Add_nl();
|
||||
wtr.Add_proc_cont_one(Xow_ns_mgr.Invk_load).Add_paren_bgn().Add_nl();
|
||||
wtr.Add_quote_xtn_bgn();
|
||||
Xol_csv_parser csv_parser = Xol_csv_parser.Instance;
|
||||
int nms_len = wiki.Ns_mgr().Count();
|
||||
for (int i = 0; i < nms_len; i++) {
|
||||
Xow_ns ns = wiki.Ns_mgr().Ords_get_at(i);
|
||||
wtr.Bfr().Add_int_variable(ns.Id()).Add_byte_pipe().Add_int_fixed(ns.Case_match(), 1).Add_byte_pipe();
|
||||
csv_parser.Save(wtr.Bfr(), ns.Name_ui());
|
||||
wtr.Add_nl();
|
||||
}
|
||||
wtr.Add_quote_xtn_end();
|
||||
wtr.Add_paren_end().Add_term_nl();
|
||||
return wtr.Xto_bry();
|
||||
}
|
||||
public void Load(String raw) {
|
||||
wiki.Appe().Gfs_mgr().Run_str_for(wiki, raw);
|
||||
}
|
||||
public static void Load_ns_(Xow_ns_mgr ns_mgr, byte[] src) {// 10|1|Template
|
||||
int len = src.length; int pos = 0, fld_bgn = 0, fld_idx = 0, row_bgn = 0;
|
||||
int cur_id = Int_.Min_value; byte cur_case_match = Byte_.Max_value_127; byte[] cur_name = Bry_.Empty;
|
||||
Xol_csv_parser csv_parser = Xol_csv_parser.Instance;
|
||||
while (true) {
|
||||
boolean last = pos == len;
|
||||
byte b = last ? Byte_ascii.Nl : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Pipe:
|
||||
switch (fld_idx) {
|
||||
case 0: cur_id = Bry_.To_int_or(src, fld_bgn, pos, Int_.Min_value); if (cur_id == Int_.Min_value) throw Err_.new_wo_type("failed to load id", "id", String_.new_u8(src, fld_bgn, pos)); break;
|
||||
case 1: cur_case_match = Bry_.To_int_as_byte(src, fld_bgn, pos, Byte_.Max_value_127); if (cur_id == Byte_.Max_value_127) throw Err_.new_wo_type("failed to load match", "id", String_.new_u8(src, fld_bgn, pos)); break;
|
||||
default: throw Err_.new_unhandled(fld_idx);
|
||||
}
|
||||
fld_bgn = pos + 1;
|
||||
++fld_idx;
|
||||
break;
|
||||
case Byte_ascii.Nl:
|
||||
if (pos > row_bgn) { // guard against blank lines
|
||||
cur_name = csv_parser.Load(src, fld_bgn, pos);
|
||||
ns_mgr.Add_new(cur_id, cur_name, cur_case_match, false);
|
||||
}
|
||||
cur_id = Int_.Min_value; cur_case_match = Byte_.Max_value_127;
|
||||
fld_bgn = pos + 1;
|
||||
fld_idx = 0;
|
||||
row_bgn = fld_bgn;
|
||||
break;
|
||||
}
|
||||
if (last) break;
|
||||
++pos;
|
||||
}
|
||||
ns_mgr.Init_w_defaults();
|
||||
}
|
||||
static final String Url_wiki_core_gfs = "wiki_core.gfs";
|
||||
static final String GRP_KEY = "xowa.wiki.cfg.wiki_core";
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xow_cfg_wiki_core_tst {
|
||||
Xow_cfg_wiki_core_fxt fxt = new Xow_cfg_wiki_core_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Save() {
|
||||
fxt.Save_tst(Xoa_app_.Version, "Main_Page", "Wikipedia|MediaWiki 1.21wmf5|first-letter|", 0, "User test", Const_wiki_core_cfg);
|
||||
}
|
||||
@Test public void Load_and_save() {
|
||||
fxt.Load_and_save_tst(Const_wiki_core_cfg);
|
||||
}
|
||||
@Test public void Load() {
|
||||
fxt.Load_tst(String_.Concat_lines_nl
|
||||
( "ns_mgr.clear.load("
|
||||
, "<:['"
|
||||
, "0|0|" // DEFECT: test that 0 sets case_match to case-sensitive; empty name was causing it to "default" to 1; DATE:2013-01-30
|
||||
, "" // test to make sure blank line doesn't fail
|
||||
, "4|1|Wikipedia" // test to make sure that values are updated after blank line
|
||||
, ""
|
||||
, "']:>"
|
||||
, ");"
|
||||
)
|
||||
, fxt.ns_(Xow_ns_.Tid__main , true, "")
|
||||
, fxt.ns_(Xow_ns_.Tid__project , false, "Wikipedia")
|
||||
);
|
||||
}
|
||||
public static final String Const_wiki_core_cfg = String_.Concat_lines_nl
|
||||
( "props"
|
||||
, ".bldr_version_('" + Xoa_app_.Version + "')"
|
||||
, ".main_page_('Main_Page')"
|
||||
, ".siteinfo_misc_('Wikipedia|MediaWiki 1.21wmf5|first-letter|')"
|
||||
, ".siteinfo_mainpage_('')"
|
||||
, ";"
|
||||
, "ns_mgr"
|
||||
, ".clear"
|
||||
, ".load("
|
||||
, "<:['"
|
||||
, "-2|1|Media"
|
||||
, "-1|1|Special"
|
||||
, "0|1|"
|
||||
, "1|1|Talk"
|
||||
, "2|0|User test" // NOTE: intentionally changing this to "0|User test" to differ from existing
|
||||
, "3|1|User talk"
|
||||
, "4|1|Wikipedia"
|
||||
, "5|1|Wikipedia talk"
|
||||
, "6|1|File"
|
||||
, "7|1|File talk"
|
||||
, "8|1|MediaWiki"
|
||||
, "9|1|MediaWiki talk"
|
||||
, "10|1|Template"
|
||||
, "11|1|Template talk"
|
||||
, "12|1|Help"
|
||||
, "13|1|Help talk"
|
||||
, "14|1|Category"
|
||||
, "15|1|Category talk"
|
||||
, "100|1|Portal"
|
||||
, "101|1|Portal talk"
|
||||
, "108|1|Book"
|
||||
, "109|1|Book talk"
|
||||
, "828|1|Module"
|
||||
, "829|1|Module talk"
|
||||
, "']:>"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
class Xow_cfg_wiki_core_fxt {
|
||||
Xoae_app app; Xowe_wiki wiki;
|
||||
public Xowe_wiki Wiki() {return wiki;}
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
public void Save_tst(String bldr_version, String main_page, String siteinfo_misc, int ns_user_case_match, String ns_user_name, String expd) {
|
||||
wiki.Props().Bldr_version_(Bry_.new_a7(bldr_version)).Main_page_(Bry_.new_a7(main_page)).Siteinfo_misc_(Bry_.new_a7(siteinfo_misc));
|
||||
Xow_ns ns_user = wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user);
|
||||
ns_user.Case_match_((byte)ns_user_case_match); ns_user.Name_bry_(Bry_.new_a7(ns_user_name));
|
||||
Tfds.Eq_str_lines(expd, String_.new_a7(wiki.Cfg_wiki_core().Build_gfs()));
|
||||
}
|
||||
public void Load_and_save_tst(String raw) {
|
||||
wiki.Cfg_wiki_core().Load(raw);
|
||||
Tfds.Eq_str_lines(raw, String_.new_a7(wiki.Cfg_wiki_core().Build_gfs()));
|
||||
}
|
||||
public Xow_ns ns_(int id, boolean case_match, String name) {return new Xow_ns(id, case_match ? Xow_ns_case_.Tid__all : Xow_ns_case_.Tid__1st, Bry_.new_u8(name), false);}
|
||||
public void Load_tst(String raw, Xow_ns... expd_ary) {
|
||||
wiki.Cfg_wiki_core().Load(raw);
|
||||
int expd_len = expd_ary.length;
|
||||
for (int i = 0; i < expd_len; i++) {
|
||||
Xow_ns expd = expd_ary[i];
|
||||
Xow_ns actl = wiki.Ns_mgr().Ids_get_or_null(expd.Id());
|
||||
Tfds.Eq(expd.Case_match(), actl.Case_match(), Int_.To_str(expd.Id()));
|
||||
Tfds.Eq(expd.Name_db_str(), actl.Name_db_str(), Int_.To_str(expd.Id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user