mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Source: Restore broken commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.addons; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
public class Xoi_addon_mgr implements Gfo_invk {
|
||||
Xoi_firefox_installer Firefox() {return firefox;} private Xoi_firefox_installer firefox = new Xoi_firefox_installer();
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
firefox.Init_by_app(app);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_firefox)) return firefox;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_firefox = "firefox";
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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.addons; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import gplx.core.ios.zips.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.apps.fsys.*;
|
||||
public class Xoi_firefox_installer implements Gfo_invk {
|
||||
private Io_url src_xpi, trg_xpi;
|
||||
private Io_url trg_xpi_package;
|
||||
private Process_adp program = new Process_adp();
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
src_xpi = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("firefox", "xowa_viewer", "default", "xowa_viewer@piotrex.xpi");
|
||||
trg_xpi = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("firefox", "xowa_viewer", "install", "xowa_viewer@piotrex.xpi");
|
||||
trg_xpi_package = trg_xpi.OwnerDir().GenSubDir("package");
|
||||
Xoa_fsys_eval cmd_eval = app.Url_cmd_eval();
|
||||
Process_adp.ini_(this, app.Usr_dlg(), program, cmd_eval, Process_adp.Run_mode_async, 0, "firefox", "\"~{url}\"", "url");
|
||||
}
|
||||
public void Install_via_process() {
|
||||
Generate();
|
||||
program.Run(trg_xpi.Raw());
|
||||
}
|
||||
public void Generate() {
|
||||
Io_mgr.Instance.CopyFil(src_xpi, trg_xpi, true);
|
||||
Io_zip_mgr_base.Instance.Unzip_to_dir(trg_xpi, trg_xpi_package);
|
||||
Pref_gen();
|
||||
Io_zip_mgr_base.Instance.Zip_dir(trg_xpi_package, trg_xpi);
|
||||
}
|
||||
private void Pref_gen() {
|
||||
Io_url prefs_fil = trg_xpi_package.GenSubFil_nest("defaults", "preferences", "prefs.js");
|
||||
String prefs_str = Io_mgr.Instance.LoadFilStr(prefs_fil);
|
||||
prefs_str = Pref_update(prefs_str, "extensions.xowa_viewer.xowa_app", Env_.AppUrl().Raw());
|
||||
Io_mgr.Instance.SaveFilStr(prefs_fil, prefs_str);
|
||||
}
|
||||
public static String Pref_update(String src, String key, String val) {
|
||||
String find = String_.Format("pref(\"{0}\"", key); // EX: 'pref("key"'
|
||||
int bgn = String_.FindFwd(src, find); // look for 'pref...'
|
||||
if (bgn == String_.Find_none) return src; // key not found; return;
|
||||
int end = String_.FindFwd(src, "\n", bgn + String_.Len(find)); // look for '\n'; note that this will trim any comments; EX: pref("key", "val"); // comment will be lost
|
||||
if (end == String_.Find_none) return src; // nl not found; return;
|
||||
String repl = String_.Format("{0}, \"{1}\");", find, val); // EX: 'pref("key", "val");'
|
||||
return String_.Mid(src, 0, bgn)
|
||||
+ repl
|
||||
+ String_.Mid(src, end);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_install)) Install_via_process();
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_install = "install";
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.addons; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*;
|
||||
public class Xoi_firefox_installer_tst {
|
||||
private Xoi_firefox_pref_fxt fxt = new Xoi_firefox_pref_fxt();
|
||||
@Test public void Pref_update() {
|
||||
fxt.Test_pref_update(String_.Concat_lines_nl
|
||||
( "pref(\"key_0\", \"val_0\"); // comment_0"
|
||||
, "pref(\"key_1\", \"val_1\"); // comment_1"
|
||||
, "pref(\"key_2\", \"val_2\"); // comment_2"
|
||||
)
|
||||
, "key_1", "val_1_updated"
|
||||
, String_.Concat_lines_nl
|
||||
( "pref(\"key_0\", \"val_0\"); // comment_0"
|
||||
, "pref(\"key_1\", \"val_1_updated\");"
|
||||
, "pref(\"key_2\", \"val_2\"); // comment_2"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xoi_firefox_pref_fxt {
|
||||
public void Test_pref_update(String src, String key, String val, String expd) {
|
||||
String actl = Xoi_firefox_installer.Pref_update(src, key, val);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_dump_itm.java
Normal file
37
400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_dump_itm.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
public class Wmf_dump_itm implements gplx.CompareAble {
|
||||
public byte[] Wiki_abrv() {return wiki_abrv;} public void Wiki_abrv_(byte[] v) {this.wiki_abrv = v;} private byte[] wiki_abrv; // EX: enwiki
|
||||
public DateAdp Dump_date() {return dump_date;} public void Dump_date_(DateAdp v) {this.dump_date = v;} private DateAdp dump_date; // EX: 20140304
|
||||
public DateAdp Status_time() {return status_time;} public void Status_time_(DateAdp v) {this.status_time = v;} private DateAdp status_time; // EX: 2014-03-15 23:22:06
|
||||
public byte[] Status_msg() {return status_msg;} // EX: Dump in progress / Dump complete
|
||||
public void Status_msg_(byte[] v) {
|
||||
this.status_msg = v;
|
||||
if (Bry_.Eq(status_msg, Status_msg_dump_complete))
|
||||
status_tid = Status_tid_complete;
|
||||
else if (Bry_.Eq(status_msg, Status_msg_dump_in_progress))
|
||||
status_tid = Status_tid_working;
|
||||
else
|
||||
status_tid = Status_tid_error;
|
||||
} private byte[] status_msg;
|
||||
public byte Status_tid() {return status_tid;} private byte status_tid;
|
||||
public int compareTo(Object obj) {Wmf_dump_itm comp = (Wmf_dump_itm)obj; return Bry_.Compare(wiki_abrv, comp.wiki_abrv);}
|
||||
private static byte[] Status_msg_dump_complete = Bry_.new_a7("Dump complete"), Status_msg_dump_in_progress = Bry_.new_a7("Dump in progress");
|
||||
public static final byte Status_tid_complete = 0, Status_tid_working = 1, Status_tid_error = 2;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
public class Wmf_dump_list_parser {
|
||||
public Wmf_dump_itm[] Parse(byte[] src) {
|
||||
Ordered_hash itms = Ordered_hash_.New_bry();
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int a_pos = Bry_find_.Find_fwd(src, Find_anchor, pos); if (a_pos == Bry_find_.Not_found) break; // no more anchors found
|
||||
pos = a_pos + Find_anchor.length;
|
||||
try {
|
||||
Wmf_dump_itm itm = new Wmf_dump_itm();
|
||||
if (!Parse_href(itm, src, a_pos)) continue; // anchor not parseable; not a link to a wmf dump
|
||||
if (itms.Has(itm.Wiki_abrv())) continue; // ignore dupes
|
||||
itms.Add(itm.Wiki_abrv(), itm);
|
||||
itm.Status_time_(Parse_status_time(src, a_pos));
|
||||
itm.Status_msg_(Parse_status_msg(src, a_pos));
|
||||
} catch (Exception e) {Err_.Noop(e);}
|
||||
}
|
||||
return (Wmf_dump_itm[])itms.To_ary(Wmf_dump_itm.class);
|
||||
}
|
||||
private boolean Parse_href(Wmf_dump_itm itm, byte[] src, int a_pos) { // EX: http://dumps.wikimedia.org/enwiki/20130807
|
||||
int href_pos = Bry_find_.Find_fwd(src, Find_href, a_pos); if (href_pos == Bry_find_.Not_found) return false; // no <li>; something bad happened
|
||||
int href_bgn_pos = Bry_find_.Find_fwd(src, Byte_ascii.Quote, href_pos + Find_href.length);
|
||||
int href_end_pos = Bry_find_.Find_fwd(src, Byte_ascii.Quote, href_bgn_pos + 1); if (href_end_pos == Bry_find_.Not_found) return false;
|
||||
byte[] href_bry = Bry_.Mid(src, href_bgn_pos + 1, href_end_pos);
|
||||
int date_end = href_bry.length;
|
||||
int date_bgn = Bry_find_.Find_bwd(href_bry, Byte_ascii.Slash); if (date_bgn == Bry_find_.Not_found) return false;
|
||||
byte[] date_bry = Bry_.Mid(href_bry, date_bgn + 1, date_end); if (date_bry.length == 0) return false; // anchors like "/other_static_dumps" should be skipped
|
||||
if (Bry_.Has(date_bry, Bry_.new_u8("legal.html"))) return false;
|
||||
if (Bry_.Has(date_bry, Bry_.new_u8("Privacy_policy"))) return false;
|
||||
DateAdp date = DateAdp_.parse_fmt(String_.new_a7(date_bry), "yyyyMMdd");
|
||||
itm.Dump_date_(date);
|
||||
int abrv_end = date_bgn;
|
||||
int abrv_bgn = Bry_find_.Find_bwd(href_bry, Byte_ascii.Slash, abrv_end); if (abrv_bgn == Bry_find_.Not_found) abrv_bgn = -1; // "enwiki/20130708"
|
||||
byte[] abrv_bry = Bry_.Mid(href_bry, abrv_bgn + 1, abrv_end);
|
||||
itm.Wiki_abrv_(Bry_.Replace(abrv_bry, Byte_ascii.Underline, Byte_ascii.Dash));
|
||||
return true;
|
||||
}
|
||||
private DateAdp Parse_status_time(byte[] src, int a_pos) {
|
||||
int li_pos = Bry_find_.Find_bwd(src, Find_li, a_pos); if (li_pos == Bry_find_.Not_found) return null;
|
||||
int bgn = Bry_find_.Find_fwd(src, Byte_ascii.Gt, li_pos + Find_li.length); if (bgn == Bry_find_.Not_found) return null;
|
||||
byte[] rv_bry = Bry_.Mid(src, bgn + 1, a_pos);
|
||||
return DateAdp_.parse_fmt(String_.Trim(String_.new_a7(rv_bry)), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
private byte[] Parse_status_msg(byte[] src, int a_pos) {
|
||||
int span_pos = Bry_find_.Find_fwd(src, Find_span_bgn, a_pos); if (span_pos == Bry_find_.Not_found) return null;
|
||||
int bgn = Bry_find_.Find_fwd(src, Byte_ascii.Gt, span_pos + Find_span_bgn.length); if (bgn == Bry_find_.Not_found) return null;
|
||||
int end = Bry_find_.Find_fwd(src, Find_span_end, bgn); if (end == Bry_find_.Not_found) return null;
|
||||
return Bry_.Mid(src, bgn + 1, end);
|
||||
}
|
||||
private static byte[]
|
||||
Find_anchor = Bry_.new_a7("<a")
|
||||
, Find_href = Bry_.new_a7(" href=")
|
||||
, Find_li = Bry_.new_a7("<li")
|
||||
, Find_span_bgn = Bry_.new_a7("<span")
|
||||
, Find_span_end = Bry_.new_a7("</span>")
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Wmf_dump_list_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Wmf_dump_list_parser_fxt fxt = new Wmf_dump_list_parser_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse
|
||||
( "<li>2013-07-17 00:32:33 <a href=\"http://dumps.wikimedia.org/enwiki/20130708\">enwiki</a>: <span class=\"done\">Dump complete</span></li>"
|
||||
, fxt.itm("enwiki", "20130708", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-07-17 00:32:33")
|
||||
);
|
||||
fxt.Test_parse(String_.Concat_lines_nl
|
||||
( "<li>2013-07-24 02:02:13 <a href=\"http://dumps.wikimedia.org/kawiki/20130724\">kawiki</a>: <span class=\"in-progress\">Dump in progress</span></li>"
|
||||
, "<ul><li class=\"in-progress\"><span class=\"updates\">2013-07-24 00:54:55</span> <span class=\"status\">in-progress</span> <span class=\"title\">All pages with complete page edit history (.bz2)</span><div class=\"progress\">2013-07-24 02:02:13: kawiki (ID 18587) 22046 pages (5.5|11140.9/sec all|curr), 869000 revs (215.2|505.3/sec all|curr), 99.9%|99.9% prefetched (all|curr), ETA 2013-07-24 04:09:41 [max 2514872]</div>"
|
||||
, "<ul><li class=\"file\">kawiki-20130724-pages-meta-history.xml.bz2 245.2 MB (written) </li></ul></li></ul>"
|
||||
)
|
||||
, fxt.itm("kawiki", "20130724", Wmf_dump_itm.Status_tid_working, "Dump in progress", "2013-07-24 02:02:13")
|
||||
);
|
||||
fxt.Test_parse
|
||||
( "<li>2013-07-17 00:32:33 <a href=\"http://dumps.wikimedia.org/enwiki/20130708\">enwiki</a>: <span class=\"done\">Error</span></li>"
|
||||
, fxt.itm("enwiki", "20130708", Wmf_dump_itm.Status_tid_error, "Error", "2013-07-17 00:32:33")
|
||||
);
|
||||
fxt.Test_parse
|
||||
( "<li>2013-11-28 06:08:56 <a href=\"zh_classicalwiki/20131128\">zh_classicalwiki</a>: <span class='done'>Dump complete</span></li>"
|
||||
, fxt.itm("zh-classicalwiki", "20131128", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-11-28 06:08:56")
|
||||
);
|
||||
}
|
||||
// @Test public void Update() { // MAINT:QUARTERLY:2016-10-13; must run home/wiki/Dashboard/Wiki_maintenance and click "update dump status"
|
||||
// Hash_adp_bry excluded_domains = Hash_adp_bry.cs().Add_many_str
|
||||
// ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org"
|
||||
// , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org"
|
||||
// , "strategy.wikipedia.org", "ten.wikipedia.org", "test2.wikipedia.org", "test.wikipedia.org"
|
||||
// , "usability.wikipedia.org", "vote.wikipedia.org"
|
||||
// , "bd.wikimedia.org", "dk.wikimedia.org", "mx.wikimedia.org", "nyc.wikimedia.org", "nz.wikimedia.org", "pa-us.wikimedia.org", "rs.wikimedia.org", "ua.wikimedia.org"
|
||||
// );
|
||||
// Wmf_dump_itm[] itms = new Wmf_dump_list_parser().Parse(Io_mgr.Instance.LoadFilBry("C:\\xowa\\bin\\any\\xowa\\xtns\\xowa\\maintenance\\backup-index.html"));
|
||||
// Array_.Sort(itms);
|
||||
// Bry_bfr sql_bfr = Bry_bfr_.New();
|
||||
// Bry_bfr bld_bfr = Bry_bfr_.New();
|
||||
// int itms_len = itms.length;
|
||||
// int counter = 1;
|
||||
// for (int i = 0; i < itms_len; i++) {
|
||||
// Wmf_dump_itm itm = itms[i];
|
||||
// byte[] abrv = itm.Wiki_abrv();
|
||||
// if (Bry_.Eq(abrv, Bry_.new_a7("testwikidatawiki"))) continue;
|
||||
// byte[] domain_bry = Xow_abrv_wm_.Parse_to_domain_bry(abrv);
|
||||
// if (domain_bry == null) continue; // not a standard WMF wiki; ignore
|
||||
// if (Bry_find_.Find_fwd(domain_bry, Bry_.new_a7("wikimania")) != Bry_find_.Not_found) continue;
|
||||
// if (excluded_domains.Has(domain_bry)) continue;
|
||||
// Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
// byte[] tid_name = Xto_display_name(Xow_domain_tid_.Get_type_as_bry(domain_itm.Domain_type_id()));
|
||||
// sql_bfr
|
||||
// .Add_byte(Byte_ascii.Paren_bgn)
|
||||
// .Add_int_variable(counter++)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_int_variable(1)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add(domain_itm.Lang_orig_key())
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add(tid_name)
|
||||
// .Add_byte(Byte_ascii.Apos)
|
||||
// .Add_byte(Byte_ascii.Paren_end)
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_str_u8("--" + String_.new_u8(abrv))
|
||||
// .Add_byte_nl()
|
||||
// ;
|
||||
// bld_bfr
|
||||
// .Add_byte(Byte_ascii.Comma)
|
||||
// .Add_byte(Byte_ascii.Space)
|
||||
// .Add_byte(Byte_ascii.Quote)
|
||||
// .Add(domain_bry)
|
||||
// .Add_byte(Byte_ascii.Quote)
|
||||
// .Add_byte_nl()
|
||||
// ;
|
||||
// }
|
||||
// Io_url temp = Io_url_.new_fil_("C:\\xowa\\user\\import_update.txt");
|
||||
// Io_mgr.Instance.SaveFilBfr(temp, sql_bfr);
|
||||
//// Io_mgr.Instance.AppendFilBfr(temp, bld_bfr);
|
||||
// }
|
||||
// private static byte[] Xto_display_name(byte[] v) {
|
||||
// if (Bry_.Eq(v, Xow_domain_tid_.Bry__wmforg)) return Bry_.new_a7("Wikimedia Foundation");
|
||||
// else if (Bry_.Eq(v, Xow_domain_tid_.Bry__species)) return Bry_.new_a7("Wikispecies");
|
||||
// else if (Bry_.Eq(v, Xow_domain_tid_.Bry__mediawiki)) return Bry_.new_a7("MediaWiki");
|
||||
// else return Bry_.Add(Byte_ascii.Case_upper(v[0]), Bry_.Mid(v, 1, v.length));
|
||||
// }
|
||||
}
|
||||
class Wmf_dump_list_parser_fxt {
|
||||
public void Clear() {}
|
||||
private Wmf_dump_list_parser parser = new Wmf_dump_list_parser();
|
||||
public String itm(String wiki_abrv, String dump_date, byte status_done, String status_msg, String status_time) {
|
||||
return String_.Concat_with_str("\n", wiki_abrv, dump_date
|
||||
, Byte_.To_str(status_done)
|
||||
, status_msg
|
||||
, status_time
|
||||
);
|
||||
}
|
||||
public void Test_parse(String raw, String... expd) {
|
||||
Wmf_dump_itm[] actl = parser.Parse(Bry_.new_a7(raw));
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl(expd), String_.Concat_lines_nl(Xto_str(actl)));
|
||||
}
|
||||
public String[] Xto_str(Wmf_dump_itm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = Xto_str(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static String Xto_str(Wmf_dump_itm itm) {
|
||||
DateAdp status_time = itm.Status_time();
|
||||
String status_time_str = status_time == null ? "" : status_time.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time);
|
||||
return String_.Concat_with_str("\n", String_.new_a7(itm.Wiki_abrv()), itm.Dump_date().XtoStr_fmt("yyyyMMdd")
|
||||
, Byte_.To_str(itm.Status_tid())
|
||||
, String_.new_a7(itm.Status_msg())
|
||||
, status_time_str
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
public class Wmf_latest_itm {
|
||||
public Wmf_latest_itm(byte[] name, DateAdp date, long size) {
|
||||
this.name = name; this.date = date; this.size = size;
|
||||
}
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public DateAdp Date() {return date;} private final DateAdp date;
|
||||
public long Size() {return size;} private final long size;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import gplx.core.btries.*; import gplx.core.ios.*;
|
||||
public class Wmf_latest_parser {
|
||||
private Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
public int Count() {return hash.Count();}
|
||||
public Wmf_latest_itm Get_at(int i) {return (Wmf_latest_itm)hash.Get_at(i);}
|
||||
public Wmf_latest_itm Get_by(byte[] k) {return (Wmf_latest_itm)hash.Get_by(k);}
|
||||
public Wmf_latest_itm[] To_ary() {return (Wmf_latest_itm[])hash.To_ary(Wmf_latest_itm.class);}
|
||||
public void Parse(byte[] src) {
|
||||
hash.Clear();
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
byte[] name_bgn_bry = Bry_.new_a7("\n<a href=\"");
|
||||
byte[] date_bgn_bry = Bry_.new_a7("</a>");
|
||||
byte[] date_end_bry = Bry_.new_a7(" ");
|
||||
// byte[] size_bgn_bry = Bry_.new_a7("</td><td class=\"s\">");
|
||||
Btrie_slim_mgr date_trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry("Jan", "01").Add_bry("Feb", "02").Add_bry("Mar", "03").Add_bry("Apr", "04").Add_bry("May", "05").Add_bry("Jun", "06")
|
||||
.Add_bry("Jul", "07").Add_bry("Aug", "08").Add_bry("Sep", "09").Add_bry("Oct", "10").Add_bry("Nov", "11").Add_bry("Dec", "12")
|
||||
;
|
||||
// Btrie_slim_mgr size_trie = Btrie_slim_mgr.cs()
|
||||
// .Add_bry("B", " B").Add_bry("K", " KB").Add_bry("M", " MB").Add_bry("G", " GB");
|
||||
byte[] date_or = Bry_.new_a7("1970-01-01 00:00:00");
|
||||
// byte[] size_or = Bry_.new_a7("0 B");
|
||||
int size_end = 0; int src_len = src.length;
|
||||
while (true) {
|
||||
int name_bgn = Bry_find_.Move_fwd(src, name_bgn_bry, size_end, src_len); if (name_bgn == Bry_find_.Not_found) break;
|
||||
int name_end = Bry_find_.Find_fwd(src, Byte_ascii.Quote, name_bgn, src_len);
|
||||
byte[] name = Bry_.Mid(src, name_bgn, name_end);
|
||||
int date_bgn = Bry_find_.Move_fwd(src, date_bgn_bry, name_end, src_len); if (date_bgn == Bry_find_.Not_found) {Gfo_usr_dlg_.Instance.Warn_many("", "", "date_bgn not found"); break;}
|
||||
date_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, date_bgn, src_len); if (date_bgn == Bry_find_.Not_found) {Gfo_usr_dlg_.Instance.Warn_many("", "", "date_bgn not found"); break;}
|
||||
int date_end = Bry_find_.Find_fwd(src, date_end_bry, date_bgn, src_len);
|
||||
byte[] date_bry = Bry_.Mid(src, date_bgn, date_end);
|
||||
DateAdp date = DateAdp_.parse_fmt(String_.new_a7(Replace_or(tmp_bfr, date_trie, trv, date_bry, 3, date_or)), "dd-MM-yyyy HH:mm");
|
||||
int size_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, date_end, src_len); if (size_bgn == Bry_find_.Not_found) {Gfo_usr_dlg_.Instance.Warn_many("", "", "size_bgn not found"); break;}
|
||||
size_end = Bry_find_.Find_fwd(src, Byte_ascii.Cr, size_bgn, src_len);
|
||||
byte[] size_bry = Bry_.Mid(src, size_bgn, size_end);
|
||||
long size = Long_.parse_or(String_.new_u8(size_bry), -1);
|
||||
Wmf_latest_itm itm = new Wmf_latest_itm(name, date, size);
|
||||
hash.Add(name, itm);
|
||||
}
|
||||
}
|
||||
private static byte[] Replace_or(Bry_bfr tmp_bfr, Btrie_slim_mgr trie, Btrie_rv trv, byte[] src, int pos, byte[] or) {
|
||||
int src_len = src.length;
|
||||
Object o = trie.Match_at(trv, src, pos, src_len); if (o == null) return or;
|
||||
tmp_bfr.Add_mid(src, 0, pos);
|
||||
tmp_bfr.Add((byte[])o);
|
||||
tmp_bfr.Add_mid(src, trv.Pos(), src_len);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import org.junit.*; import gplx.core.ios.*;
|
||||
public class Wmf_latest_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Wmf_latest_parser_fxt fxt = new Wmf_latest_parser_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse
|
||||
( "\n<a href=\"enwiki-latest-pages-articles.xml.bz2\">enwiki-latest-pages-articles.xml.bz2</a> 15-Jan-2015 05:43 11575640561\r\n"
|
||||
, fxt.itm("enwiki-latest-pages-articles.xml.bz2", "2015-01-15 05:43", "10.781 GB")
|
||||
);
|
||||
}
|
||||
// @Test public void Smoke() {
|
||||
// Wmf_latest_parser parser = new Wmf_latest_parser();
|
||||
// parser.Parse(Io_mgr.Instance.LoadFilBry("C:\\wmf_latest.html"));
|
||||
// Tfds.Dbg(String_.Concat_lines_nl(Wmf_latest_parser_fxt.Xto_str_ary(parser.To_ary())));
|
||||
// }
|
||||
}
|
||||
class Wmf_latest_parser_fxt {
|
||||
public void Clear() {}
|
||||
private Wmf_latest_parser parser = new Wmf_latest_parser();
|
||||
public Wmf_latest_itm itm(String name, String date, String size) {return new Wmf_latest_itm(Bry_.new_a7(name), DateAdp_.parse_iso8561(date), Io_size_.parse_or(size, 0));}
|
||||
public void Test_parse(String raw, Wmf_latest_itm... expd) {
|
||||
parser.Parse(Bry_.new_a7(raw));
|
||||
Wmf_latest_itm[] actl = parser.To_ary();
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl(Xto_str_ary(expd)), String_.Concat_lines_nl(Xto_str_ary(actl)));
|
||||
}
|
||||
public static String[] Xto_str_ary(Wmf_latest_itm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = Xto_str(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static String Xto_str(Wmf_latest_itm itm) {
|
||||
return String_.Concat_with_str("\n", String_.new_a7(itm.Name()), itm.Date().XtoStr_fmt_iso_8561(), Io_size_.To_str(itm.Size()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.files.downloads.*;
|
||||
public class Xoa_maint_mgr implements Gfo_invk {
|
||||
public Xoa_maint_mgr(Xoae_app app) {
|
||||
this.app = app;
|
||||
wmf_dump_status_url = Wmf_dump_status_url(app);
|
||||
wiki_mgr = new Xoa_maint_wikis_mgr(app);
|
||||
} private Xoae_app app; private Io_url wmf_dump_status_url;
|
||||
public Xoa_maint_wikis_mgr Wiki_mgr() {return wiki_mgr;} private Xoa_maint_wikis_mgr wiki_mgr;
|
||||
public boolean Wmf_dump_status_loaded() {return wmf_dump_status_loaded;} private boolean wmf_dump_status_loaded;
|
||||
public void Wmf_dump_status_loaded_assert() {
|
||||
if (!wmf_dump_status_loaded) {
|
||||
Wmf_status_parse();
|
||||
wmf_dump_status_loaded = true;
|
||||
}
|
||||
}
|
||||
public void Wmf_status_update() {
|
||||
Wmf_status_download();
|
||||
Wmf_status_parse();
|
||||
}
|
||||
public boolean Wmf_status_download() {
|
||||
String[] server_urls = gplx.xowa.bldrs.installs.Xoi_dump_mgr.Server_urls(app);
|
||||
int len = server_urls.length;
|
||||
Xof_download_wkr download_wkr = app.Wmf_mgr().Download_wkr();
|
||||
for (int i = 0; i < len; i++) {
|
||||
String server_url = server_urls[i] + "backup-index.html";
|
||||
byte rslt = download_wkr.Download(true, server_url, wmf_dump_status_url, "downloading wmf status");
|
||||
if (rslt == IoEngine_xrg_downloadFil.Rslt_pass) return true;
|
||||
}
|
||||
app.Usr_dlg().Prog_many("", "", "could not download latest status");
|
||||
return false;
|
||||
}
|
||||
public boolean Wmf_status_parse() {
|
||||
Wmf_dump_list_parser parser = new Wmf_dump_list_parser();
|
||||
Hash_adp_bry itms_hash = Hash_adp_bry.cs();
|
||||
Wmf_dump_itm[] itms = parser.Parse(Io_mgr.Instance.LoadFilBry(wmf_dump_status_url));
|
||||
int len = itms.length;
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "maint.html count; count=~{0}", len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wmf_dump_itm itm = itms[i];
|
||||
byte[] wiki_abrv = itm.Wiki_abrv();
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "maint.html itm; itm=~{0}", wiki_abrv);
|
||||
byte[] wiki_domain = Xow_abrv_wm_.Parse_to_domain_bry(wiki_abrv);
|
||||
if (wiki_domain == null) continue; // invalid wiki-name; ex: nycwikimedia
|
||||
itms_hash.Add(wiki_domain, itm);
|
||||
}
|
||||
len = app.Wiki_mgr().Count();
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "maint.wiki_count; count=~{0}", len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_at_or_null(i);
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "maint.wiki_itm; wiki=~{0}", wiki.Domain_str());
|
||||
Wmf_dump_itm itm = (Wmf_dump_itm)itms_hash.Get_by_bry(wiki.Domain_bry()); if (itm == null) continue;
|
||||
wiki.Maint_mgr().Wmf_dump_date_(itm.Dump_date()).Wmf_dump_done_(itm.Status_tid() == Wmf_dump_itm.Status_tid_complete).Wmf_dump_status_(itm.Status_msg());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_wmf_status_update)) Wmf_status_update();
|
||||
else if (ctx.Match(k, Invk_wikis)) return wiki_mgr;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_wmf_status_update = "wmf_status_update", Invk_wikis = "wikis";
|
||||
public static Io_url Wmf_dump_status_url(Xoae_app app) {return app.Fsys_mgr().Bin_xowa_dir().GenSubDir_nest("xtns", "xowa", "maintenance", "backup-index.html");}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
public class Xoa_maint_wikis_mgr implements Gfo_invk {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
public Xoa_maint_wikis_mgr(Xoae_app app) {this.app = app;} private Xoae_app app;
|
||||
public int Len() {return hash.Count();}
|
||||
public Xowe_wiki Get_at(int i) {
|
||||
if (init) Init();
|
||||
byte[] domain = (byte[])hash.Get_at(i);
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(domain);
|
||||
wiki.Init_assert();
|
||||
return wiki;
|
||||
}
|
||||
public void Add(byte[] domain) {hash.Add_if_dupe_use_nth(domain, domain);} // NOTE: must be Add_if_dupe_use_nth to replace existing wikis
|
||||
public void Init() {
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] domain = (byte[])hash.Get_at(i);
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(domain);
|
||||
wiki.Init_assert();
|
||||
}
|
||||
init = false;
|
||||
}
|
||||
private boolean init = true;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_len)) return this.Len();
|
||||
else if (ctx.Match(k, Invk_get_at)) return this.Get_at(m.ReadInt("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
// return this;
|
||||
} private static final String Invk_len = "len", Invk_get_at = "get_at";
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*;
|
||||
public class Xow_maint_mgr implements Gfo_invk {
|
||||
public Xow_maint_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
maint_mgr = wiki.Appe().Setup_mgr().Maint_mgr();
|
||||
} private Xowe_wiki wiki; private Xoa_maint_mgr maint_mgr;
|
||||
public DateAdp Wmf_dump_date() {
|
||||
maint_mgr.Wmf_dump_status_loaded_assert();
|
||||
return wmf_dump_date;
|
||||
} public Xow_maint_mgr Wmf_dump_date_(DateAdp v) {this.wmf_dump_date = v; return this;} private DateAdp wmf_dump_date;
|
||||
public boolean Wmf_dump_done() {return wmf_dump_done;} public Xow_maint_mgr Wmf_dump_done_(boolean v) {this.wmf_dump_done = v; return this;} private boolean wmf_dump_done;
|
||||
public byte[] Wmf_dump_status() {return wmf_dump_status;} public Xow_maint_mgr Wmf_dump_status_(byte[] v) {this.wmf_dump_status = v; return this;} private byte[] wmf_dump_status;
|
||||
public DateAdp Wiki_dump_date() {
|
||||
if (wiki_dump_date == null)
|
||||
wiki_dump_date = wiki.Db_mgr().Dump_date_query();
|
||||
return wiki_dump_date;
|
||||
} private DateAdp wiki_dump_date;
|
||||
public boolean Wiki_update_needed() {
|
||||
if (this.Wiki_dump_date() == null) return false; // will be null if a custom wiki (i.e.: not on http://dumps.wikimedia.org/backup-index.html)
|
||||
if (this.Wmf_dump_date() == null) return false; // also null if custom wiki
|
||||
return this.Wmf_dump_date().Diff(this.Wiki_dump_date()).Total_days().To_double() > 1;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_wmf_dump_date)) return DateAdp_.Xto_str_fmt_or(Wmf_dump_date(), "yyyy-MM-dd", "");
|
||||
else if (ctx.Match(k, Invk_wmf_dump_date_)) Wmf_dump_date_(m.ReadDate("v"));
|
||||
else if (ctx.Match(k, Invk_wmf_dump_done)) return Yn.To_str(wmf_dump_done);
|
||||
else if (ctx.Match(k, Invk_wmf_dump_done_)) wmf_dump_done = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_wmf_dump_status)) return String_.new_u8(wmf_dump_status);
|
||||
else if (ctx.Match(k, Invk_wmf_dump_status_)) wmf_dump_status = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_wiki_dump_date)) return DateAdp_.Xto_str_fmt_or(Wiki_dump_date(), "yyyy-MM-dd", "");
|
||||
else if (ctx.Match(k, Invk_wiki_dump_date_)) wiki_dump_date = m.ReadDate("v");
|
||||
else if (ctx.Match(k, Invk_wiki_update_needed)) return Yn.To_str(Wiki_update_needed());
|
||||
else if (ctx.Match(k, Invk_wiki_dump_date_)) wiki_dump_date = m.ReadDate("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_wmf_dump_date = "wmf_dump_date", Invk_wmf_dump_date_ = "wmf_dump_date_", Invk_wmf_dump_done = "wmf_dump_done", Invk_wmf_dump_done_ = "wmf_dump_done_"
|
||||
, Invk_wmf_dump_status = "wmf_dump_status", Invk_wmf_dump_status_ = "wmf_dump_status_", Invk_wiki_dump_date = "wiki_dump_date", Invk_wiki_dump_date_ = "wiki_dump_date_"
|
||||
, Invk_wiki_update_needed = "wiki_update_needed"
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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";
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.wikis.domains.*;
|
||||
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");
|
||||
if (Io_mgr.Instance.ExistsDir(new_history_dir)) return; // new_history_dir exists;
|
||||
app.Usr_dlg().Log_many("", "", "moving history files");
|
||||
Io_url[] old_history_fils = Io_mgr.Instance.QueryDir_args(old_history_dir).Recur_(false).ExecAsUrlAry();
|
||||
int len = old_history_fils.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_url old_history_fil = old_history_fils[i];
|
||||
Io_mgr.Instance.CopyFil(old_history_fil, new_history_dir.GenSubFil(old_history_fil.NameAndExt()), false);
|
||||
}
|
||||
app.Usr_dlg().Log_many("", "", "moved history files: ~{0}", len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Xoa_upgrade_mgr_tst {
|
||||
@Test public void Run() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
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");
|
||||
Io_mgr.Instance.SaveFilStr(old_history_dir.GenSubFil("page_history.csv"), "test");
|
||||
Xoa_upgrade_mgr.Check(app);
|
||||
Tfds.Eq("test", Io_mgr.Instance.LoadFilStr(old_history_dir.GenSubFil("page_history.csv"))); // old file still exists
|
||||
Tfds.Eq("test", Io_mgr.Instance.LoadFilStr(new_history_dir.GenSubFil("page_history.csv"))); // new file exists
|
||||
Io_mgr.Instance.SaveFilStr(new_history_dir.GenSubFil("page_history.csv"), "test1"); // dirty file
|
||||
Xoa_upgrade_mgr.Check(app); // rerun
|
||||
Tfds.Eq("test1", Io_mgr.Instance.LoadFilStr(new_history_dir.GenSubFil("page_history.csv"))); // dirty file remains (not replaced by old file)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user