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:
@@ -42,7 +42,6 @@ public class Xob_cmd_keys {
|
||||
, Key_tdb_make_page = "tdb.text.page" // "core.make_page"
|
||||
, Key_tdb_make_id = "core.make_id"
|
||||
, Key_tdb_calc_stats = "core.calc_stats"
|
||||
, Key_tdb_core_term = "tdb.text.term" // "core.term"
|
||||
, Key_tdb_text_wdata_qid = "tdb.text.wdata.qid"
|
||||
, Key_tdb_text_wdata_pid = "tdb.text.wdata.pid"
|
||||
, Key_exec_sql = "import.sql.exec_sql"
|
||||
|
||||
@@ -58,7 +58,6 @@ public class Xob_cmd_mgr implements Gfo_invk {
|
||||
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_text_init)) return Add(new Xob_init_tdb(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_make_id)) return Xml_rdr_direct_add(wiki, new Xob_make_id_wkr(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_calc_stats)) return Add(new Xob_calc_stats_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_core_term)) return Add(new Xob_term_txt(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_text_wdata_qid)) return Xml_rdr_direct_add(wiki, new Xob_wdata_qid_txt().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_text_wdata_pid)) return Xml_rdr_direct_add(wiki, new Xob_wdata_pid_txt().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_diff_build)) return Add(new Xob_diff_build_cmd(bldr, wiki));
|
||||
|
||||
@@ -26,12 +26,26 @@ public abstract class Xob_term_base implements Xob_cmd, Gfo_invk {
|
||||
public void Cmd_run() {}
|
||||
public void Cmd_end() {
|
||||
Xoae_app app = wiki.Appe();
|
||||
app.Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_reset(); // NOTE: dirty wiki list so that next refresh will load itm
|
||||
app.Free_mem(false); // clear cache, else import will load new page with old items from cache; DATE:2013-11-21
|
||||
wiki.Props().Main_page_update(wiki);
|
||||
|
||||
// dirty wiki list so that next refresh will load wiki
|
||||
app.Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_reset();
|
||||
|
||||
// clear cache, else import will load new page with old items from cache; DATE:2013-11-21
|
||||
app.Free_mem(false);
|
||||
|
||||
// update main page
|
||||
byte[] new_main_page = gplx.xowa.langs.msgs.Xow_mainpage_finder.Find_or(wiki, wiki.Props().Siteinfo_mainpage()); // get new main_page from mainpage_finder
|
||||
wiki.Props().Main_page_update_(new_main_page);
|
||||
|
||||
// remove import marker
|
||||
app.Bldr().Import_marker().End(wiki);
|
||||
wiki.Init_needed_(true);// flag init_needed prior to show; dir_info will show page_txt instead of page_gz;
|
||||
wiki.Init_assert(); // force load; needed to pick up MediaWiki ns for MediaWiki:mainpage
|
||||
|
||||
// flag init_needed prior to show; dir_info will show page_txt instead of page_gz;
|
||||
wiki.Init_needed_(true);
|
||||
|
||||
// force load; needed to pick up MediaWiki ns for MediaWiki:mainpage
|
||||
wiki.Init_assert();
|
||||
|
||||
Cmd_end_hook();
|
||||
}
|
||||
public abstract void Cmd_end_hook();
|
||||
|
||||
@@ -89,7 +89,7 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xob_page_wkr, Gf
|
||||
Xow_db_file db_core = db_mgr.Db__core();
|
||||
db_core.Tbl__site_stats().Update(page_count_main, page_count_all, ns_mgr.Ns_file().Count()); // save page stats
|
||||
db_core.Tbl__ns().Insert(ns_mgr); // save ns
|
||||
db_mgr.Tbl__cfg().Insert_str(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__modified_latest, modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
db_mgr.Tbl__cfg().Insert_str(Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__modified_latest, modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
if (idx_mode.Tid_is_end()) page_core_tbl.Create_idx();
|
||||
if (redirect_id_enabled) {
|
||||
redirect_tbl.Conn().Txn_end();
|
||||
|
||||
@@ -17,23 +17,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.texts.sqls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import gplx.dbs.cfgs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
public class Xob_term_cmd extends Xob_term_base {
|
||||
public Xob_term_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Ctor(bldr, wiki); this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
@Override public String Cmd_key() {return KEY;} public static final String KEY = "text.term";
|
||||
@Override public void Cmd_end_hook() {
|
||||
// delete wiki's temp dir
|
||||
Io_mgr.Instance.DeleteDirDeep(wiki.Fsys_mgr().Tmp_dir());
|
||||
Db_cfg_tbl cfg_tbl = wiki.Data__core_mgr().Tbl__cfg();
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__bldr_version, wiki.Props().Bldr_version());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, wiki.Props().Main_page());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_misc", wiki.Props().Siteinfo_misc());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_mainpage", wiki.Props().Siteinfo_mainpage());
|
||||
|
||||
cfg_tbl.Insert_str(Xow_cfg_consts.Grp__empty, gplx.xowa.addons.wikis.directorys.dbs.Xowdir_wiki_cfg_.Key__domain , wiki.Domain_str());
|
||||
cfg_tbl.Insert_str(Xow_cfg_consts.Grp__empty, gplx.xowa.addons.wikis.directorys.dbs.Xowdir_wiki_cfg_.Key__name , wiki.Domain_str());
|
||||
// insert cfg defaults
|
||||
Xowd_cfg_tbl_.Insert__import(wiki);
|
||||
Xowd_cfg_tbl_.Insert__create(wiki);
|
||||
|
||||
// build fsdb
|
||||
gplx.fsdb.Fsdb_db_mgr__v2_bldr.Get_or_make(wiki, false);// always build file.user db; DATE:2015-05-12
|
||||
|
||||
// dansguardian
|
||||
if (wiki.App().Cfg().Get_bool_wiki_or(wiki, gplx.xowa.bldrs.filters.dansguardians.Dg_match_mgr.Cfg__enabled, false))
|
||||
new Xob_page_delete_cmd(wiki.Appe().Bldr(), wiki).Cmd_run();
|
||||
|
||||
wiki.Data__core_mgr().Rls();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +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.cmds.texts.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import gplx.xowa.bldrs.cmds.texts.*;
|
||||
public class Xob_term_txt extends Xob_term_base {
|
||||
public Xob_term_txt(Xob_bldr bldr, Xowe_wiki wiki) {this.Ctor(bldr, wiki); this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
@Override public String Cmd_key() {return Xob_cmd_keys.Key_tdb_core_term;}
|
||||
@Override public void Cmd_end_hook() {
|
||||
Io_mgr.Instance.SaveFilBry(wiki.Tdb_fsys_mgr().Cfg_wiki_core_fil(), wiki.Cfg_wiki_core().Build_gfs());
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class Xoa_css_extractor {
|
||||
if ( core_db_mgr == null
|
||||
|| core_db_mgr.Props() == null
|
||||
|| core_db_mgr.Props().Schema_is_1()
|
||||
|| !core_db_mgr.Tbl__cfg().Select_yn_or(Xow_cfg_consts.Grp__wiki_schema, Xow_db_file_schema_props.Key__tbl_css_core, Bool_.N)
|
||||
|| !core_db_mgr.Tbl__cfg().Select_yn_or(Xowd_cfg_key_.Grp__wiki_schema, Xow_db_file_schema_props.Key__tbl_css_core, Bool_.N)
|
||||
) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "css.db not found; wiki=~{0} css_dir=~{1}", wiki.Domain_str(), wiki_html_dir.Raw());
|
||||
return false;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Xob_info_file {
|
||||
, hash.Get_by(Cfg_key__orig_file_name ).To_str_or("")
|
||||
);
|
||||
}
|
||||
private static final String Cfg_grp = gplx.xowa.wikis.Xow_cfg_consts.Grp__bldr_db
|
||||
private static final String Cfg_grp = gplx.xowa.wikis.data.Xowd_cfg_key_.Grp__bldr_db
|
||||
, Cfg_key__id = "id" // EX: 1
|
||||
, Cfg_key__type = "type" // EX: core
|
||||
, Cfg_key__ns_ids = "ns_ids" // EX: 0
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Xob_info_session {
|
||||
, hash.Get_by(Cfg_key__guid).To_guid_or(Guid_adp_.Empty)
|
||||
);
|
||||
}
|
||||
public static final String Cfg_grp = gplx.xowa.wikis.Xow_cfg_consts.Grp__bldr_session
|
||||
public static final String Cfg_grp = gplx.xowa.wikis.data.Xowd_cfg_key_.Grp__bldr_session
|
||||
, Cfg_key__user = "user" // EX: anonymous
|
||||
, Cfg_key__version = "version" // EX: 2.3.1.4
|
||||
, Cfg_key__wiki_domain = "wiki_domain" // EX: en.wikipedia.org
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +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.setups.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
class Upgrader_v00_02_01 {
|
||||
public void Run(Xowe_wiki wiki) {
|
||||
Io_url cfg_dir = wiki.Fsys_mgr().Root_dir().GenSubDir("cfg");
|
||||
if (!Io_mgr.Instance.ExistsDir(cfg_dir)) return; // brand-new wiki; nothing to migrate
|
||||
Gfo_usr_dlg usr_dlg = wiki.Appe().Usr_dlg();
|
||||
usr_dlg.Note_many(GRP_KEY, "run.bgn", "migrate.bgn for ~{0}", wiki.Domain_str());
|
||||
Io_url siteinfo_url = cfg_dir.GenSubFil_nest("siteInfo.xml");
|
||||
usr_dlg.Note_many(GRP_KEY, "siteinfo.bgn", "siteinfo.bgn for ~{0}", siteinfo_url.Raw());
|
||||
String siteinfo_str = Io_mgr.Instance.LoadFilStr_args(siteinfo_url).MissingIgnored_(true).Exec(); if (String_.Len_eq_0(siteinfo_str)) throw Err_.new_wo_type("could not find siteinfo.xml", "url", siteinfo_url.Raw());
|
||||
usr_dlg.Note_many(GRP_KEY, "siteinfo.parse", "parsing siteinfo");
|
||||
gplx.xowa.bldrs.cmds.texts.xmls.Xob_siteinfo_parser_.Parse(Bry_.new_u8(siteinfo_str), wiki); // NOTE: this also resets the namespaces on the wiki; not necessary, but is benign
|
||||
usr_dlg.Note_many(GRP_KEY, "siteinfo.save", "saving siteinfo");
|
||||
byte[] wiki_core_bry = wiki.Cfg_wiki_core().Build_gfs();
|
||||
Io_mgr.Instance.SaveFilBry(wiki.Tdb_fsys_mgr().Cfg_wiki_core_fil(), wiki_core_bry);
|
||||
usr_dlg.Note_many(GRP_KEY, "siteinfo.end", "siteinfo.end for ~{0}", wiki.Domain_str());
|
||||
|
||||
Io_url old_wikistats_url = wiki.Fsys_mgr().Root_dir().GenSubFil_nest("cfg", "wiki.gfs");
|
||||
Io_url new_wikistats_url = wiki.Tdb_fsys_mgr().Cfg_wiki_stats_fil();
|
||||
if (Io_mgr.Instance.ExistsFil(new_wikistats_url)) // noop; should not happen, but perhaps results from merging directories;
|
||||
usr_dlg.Note_many(GRP_KEY, "wiki_stats.new_exists", "new wiki stats already exists for ~{0}", new_wikistats_url.Raw());
|
||||
else if (!Io_mgr.Instance.ExistsFil(old_wikistats_url)) // noop; should not happen;
|
||||
usr_dlg.Note_many(GRP_KEY, "wiki_stats.old_missing", "old wiki stats missing ~{0}", old_wikistats_url.Raw());
|
||||
else { // rename "wiki.gfs" to "wiki_stats.gfs"
|
||||
usr_dlg.Note_many(GRP_KEY, "wiki_stats.rename.bgn", "copying: src=~{0} trg=~{1}", old_wikistats_url.Raw(), new_wikistats_url.Raw());
|
||||
Io_mgr.Instance.CopyFil(old_wikistats_url, new_wikistats_url, false);
|
||||
}
|
||||
byte[] old_wikistats_bry = Io_mgr.Instance.LoadFilBry(new_wikistats_url);
|
||||
byte[] new_wikistats_bry = Bry_.Replace_between(old_wikistats_bry, Bry_.new_a7("props.main_page_('"), Bry_.new_a7("');\n"), Bry_.Empty);
|
||||
if (!Bry_.Eq(old_wikistats_bry, new_wikistats_bry)) {
|
||||
usr_dlg.Note_many(GRP_KEY, "wiki_stats.remove_mainpage", "removing mainpages");
|
||||
Io_mgr.Instance.SaveFilBry(new_wikistats_url, new_wikistats_bry);
|
||||
}
|
||||
usr_dlg.Note_many(GRP_KEY, "run.end", "migrate.end for ~{0}", wiki.Domain_str());
|
||||
usr_dlg.Note_many("", "", "");
|
||||
}
|
||||
static final String GRP_KEY = "xowa.wiki.upgrades.v00_02_01";
|
||||
}
|
||||
@@ -1,71 +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.setups.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*; import gplx.xowa.bldrs.installs.*;
|
||||
public class Upgrader_v00_02_01_tst {
|
||||
@Test public void Run() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
Io_url cfg_dir = wiki.Fsys_mgr().Root_dir().GenSubDir("cfg");
|
||||
Io_mgr.Instance.SaveFilStr(cfg_dir.GenSubFil("siteInfo.xml"), Str_siteinfo_xml);
|
||||
Io_mgr.Instance.SaveFilStr(cfg_dir.GenSubFil("wiki.gfs"), Str_wikistats_gfs);
|
||||
Upgrader_v00_02_01 mgr = new Upgrader_v00_02_01();
|
||||
mgr.Run(wiki);
|
||||
Tfds.Eq_str_lines(Xow_cfg_wiki_core_tst.Const_wiki_core_cfg, Io_mgr.Instance.LoadFilStr(wiki.Tdb_fsys_mgr().Cfg_wiki_core_fil()));
|
||||
Tfds.Eq_str_lines("/* assume content ... */", Io_mgr.Instance.LoadFilStr(wiki.Tdb_fsys_mgr().Cfg_wiki_stats_fil()));
|
||||
}
|
||||
public static String Str_siteinfo_xml = String_.Concat_lines_nl
|
||||
( "<siteinfo>"
|
||||
, " <sitename>Wikipedia</sitename>"
|
||||
, " <base>http://en.wikipedia.org/wiki/Main_Page</base>"
|
||||
, " <generator>MediaWiki 1.21wmf5</generator>"
|
||||
, " <case>first-letter</case>"
|
||||
, " <namespaces>"
|
||||
, " <namespace key=\"-2\" case=\"first-letter\">Media</namespace>"
|
||||
, " <namespace key=\"-1\" case=\"first-letter\">Special</namespace>"
|
||||
, " <namespace key=\"0\" case=\"first-letter\" />"
|
||||
, " <namespace key=\"1\" case=\"first-letter\">Talk</namespace>"
|
||||
, " <namespace key=\"2\" case=\"case-sensitive\">User test</namespace>" // NOTE: intentionally changing this to "0|User test" to differ from existing
|
||||
, " <namespace key=\"3\" case=\"first-letter\">User talk</namespace>"
|
||||
, " <namespace key=\"4\" case=\"first-letter\">Wikipedia</namespace>"
|
||||
, " <namespace key=\"5\" case=\"first-letter\">Wikipedia talk</namespace>"
|
||||
, " <namespace key=\"6\" case=\"first-letter\">File</namespace>"
|
||||
, " <namespace key=\"7\" case=\"first-letter\">File talk</namespace>"
|
||||
, " <namespace key=\"8\" case=\"first-letter\">MediaWiki</namespace>"
|
||||
, " <namespace key=\"9\" case=\"first-letter\">MediaWiki talk</namespace>"
|
||||
, " <namespace key=\"10\" case=\"first-letter\">Template</namespace>"
|
||||
, " <namespace key=\"11\" case=\"first-letter\">Template talk</namespace>"
|
||||
, " <namespace key=\"12\" case=\"first-letter\">Help</namespace>"
|
||||
, " <namespace key=\"13\" case=\"first-letter\">Help talk</namespace>"
|
||||
, " <namespace key=\"14\" case=\"first-letter\">Category</namespace>"
|
||||
, " <namespace key=\"15\" case=\"first-letter\">Category talk</namespace>"
|
||||
, " <namespace key=\"100\" case=\"first-letter\">Portal</namespace>"
|
||||
, " <namespace key=\"101\" case=\"first-letter\">Portal talk</namespace>"
|
||||
, " <namespace key=\"108\" case=\"first-letter\">Book</namespace>"
|
||||
, " <namespace key=\"109\" case=\"first-letter\">Book talk</namespace>"
|
||||
, " <namespace key=\"828\" case=\"first-letter\">Module</namespace>"
|
||||
, " <namespace key=\"829\" case=\"first-letter\">Module talk</namespace>"
|
||||
, " </namespaces>"
|
||||
, " </siteinfo>"
|
||||
);
|
||||
private static String Str_wikistats_gfs = String_.Concat_lines_nl
|
||||
( "/* assume content ... */"
|
||||
, "props.main_page_('Main Page');"
|
||||
, "props.main_page_('Main Page');" // sometimes doubled
|
||||
);
|
||||
}
|
||||
@@ -21,15 +21,6 @@ public class Xoa_upgrade_mgr {
|
||||
public static void Check(Xoae_app app) {
|
||||
Upgrade_history(app);
|
||||
}
|
||||
public static void Check(Xowe_wiki wiki) {
|
||||
if (wiki.Domain_tid() == Xow_domain_tid_.Tid__home) return; // home wiki never needs to be migrated
|
||||
try {
|
||||
if (Bry_.Eq(wiki.Props().Bldr_version(), Bry_.Empty)) { // version is ""; wiki must be created prior to v0.2.1; create wiki_core.gfs
|
||||
Upgrader_v00_02_01 mgr = new Upgrader_v00_02_01();
|
||||
mgr.Run(wiki);
|
||||
}
|
||||
} catch (Exception e) {wiki.Appe().Usr_dlg().Warn_many("", "", "unknown error during migrate; domain=~{0} err=~{1}", wiki.Domain_str(), Err_.Message_gplx_full(e));}
|
||||
}
|
||||
private static void Upgrade_history(Xoae_app app) {
|
||||
Io_url old_history_dir = app.Usere().Fsys_mgr().App_data_dir();
|
||||
Io_url new_history_dir = app.Usere().Fsys_mgr().App_data_dir().GenSubDir("history");
|
||||
|
||||
Reference in New Issue
Block a user