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,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