mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.strings.*;
|
||||
public class Xoac_wiki_cfg_bldr_cmd {
|
||||
public Xoac_wiki_cfg_bldr_cmd(String key, String text) {this.key = key; this.text = text;}
|
||||
public String Key() {return key;} private String key;
|
||||
public String Text() {return text;} private String text;
|
||||
public String Exec(String_bldr sb, String wiki, String src) {
|
||||
String sect_txt_bgn = sb.Add("// ").Add(key).Add(".bgn\n").To_str_and_clear();
|
||||
String sect_txt_end = sb.Add("// ").Add(key).Add(".end\n").To_str_and_clear();
|
||||
String sect_txt_all = sb.Add(sect_txt_bgn).Add(text + "\n").Add(sect_txt_end).To_str_and_clear(); // NOTE: always add \n; convenience for single line cmds
|
||||
return src + sect_txt_all;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
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.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xoac_wiki_cfg_bldr_fil implements GfoInvkAble {
|
||||
public Xoac_wiki_cfg_bldr_fil(String wiki) {this.wiki = wiki;}
|
||||
public String Wiki() {return wiki;} private String wiki;
|
||||
public int Itms_count() {return list.Count();}
|
||||
public Xoac_wiki_cfg_bldr_cmd Itms_get_at(int i) {return (Xoac_wiki_cfg_bldr_cmd)list.Get_at(i);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_new_cmd_)) {Itms_add(m.ReadStr("id"), m.ReadStr("text"));}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_new_cmd_ = "new_cmd_";
|
||||
public Xoac_wiki_cfg_bldr_cmd Itms_add(String key, String text) {
|
||||
Xoac_wiki_cfg_bldr_cmd rv = new Xoac_wiki_cfg_bldr_cmd(key, text);
|
||||
list.Add(rv);
|
||||
return rv;
|
||||
}
|
||||
List_adp list = List_adp_.new_();
|
||||
}
|
||||
@@ -17,7 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.xowa.wikis.xwikis.cfgs.*;
|
||||
public class Xob_wiki_cfg_bldr implements GfoInvkAble {
|
||||
public Xob_wiki_cfg_bldr(Xob_bldr bldr) {this.app = bldr.App();} private Xoae_app app;
|
||||
public void Exec() {
|
||||
@@ -30,14 +29,14 @@ public class Xob_wiki_cfg_bldr implements GfoInvkAble {
|
||||
private void Exec_fil(Xoac_wiki_cfg_bldr_fil fil) {
|
||||
String wiki_key = fil.Wiki();
|
||||
Io_url cfg_file = app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki_key + ".gfs");
|
||||
String cfg_text = Io_mgr.I.LoadFilStr_args(cfg_file).MissingIgnored_().Exec();
|
||||
String cfg_text = Io_mgr.Instance.LoadFilStr_args(cfg_file).MissingIgnored_().Exec();
|
||||
int len = fil.Itms_count();
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoac_wiki_cfg_bldr_cmd cmd = fil.Itms_get_at(i);
|
||||
cfg_text = cmd.Exec(sb, wiki_key, cfg_text);
|
||||
}
|
||||
Io_mgr.I.SaveFilStr(cfg_file, cfg_text);
|
||||
Io_mgr.Instance.SaveFilStr(cfg_file, cfg_text);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Itms_get_or_new(m.ReadStr("v"));
|
||||
@@ -53,5 +52,5 @@ public class Xob_wiki_cfg_bldr implements GfoInvkAble {
|
||||
hash.Add(wiki, rv);
|
||||
}
|
||||
return rv;
|
||||
} private Ordered_hash hash = Ordered_hash_.new_();
|
||||
} private Ordered_hash hash = Ordered_hash_.New();
|
||||
}
|
||||
|
||||
@@ -59,13 +59,13 @@ public class Xob_wiki_cfg_bldr_tst {
|
||||
}
|
||||
// @Test public void Lang_names_run() {
|
||||
// Io_url dir = Io_url_.new_dir_("/var/www/mediawiki/languages/messages/");
|
||||
// Io_url[] fils = Io_mgr.I.QueryDir_args(dir).ExecAsUrlAry();
|
||||
// Io_url[] fils = Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry();
|
||||
// int fils_len = fils.length;
|
||||
// String_bldr sb = String_bldr_.new_();
|
||||
// for (int i = 0; i < fils_len; i++) {
|
||||
// Io_url fil = fils[i];
|
||||
// String lang_code = String_.Lower(String_.Replace(fil.NameOnly(), "Messages", ""));
|
||||
// String txt = Io_mgr.I.LoadFilStr(fil);
|
||||
// String txt = Io_mgr.Instance.LoadFilStr(fil);
|
||||
// String[] lines = String_.Split(txt, '\n');
|
||||
// String line = lines[1];
|
||||
// line = String_.Replace(line, "/** ", "");
|
||||
@@ -89,11 +89,11 @@ public class Xob_wiki_cfg_bldr_tst {
|
||||
// String[] terms = String_.Split(line, '|');
|
||||
// sb.Add(lang_code).Add("|").Add(String_.Trim(terms[0])).Add("|").Add(String_.Trim(terms[1])).Add("\n");
|
||||
// }
|
||||
// Tfds.Write(sb.Xto_str_and_clear());
|
||||
// Tfds.Write(sb.To_str_and_clear());
|
||||
// }
|
||||
@Test public void Ns_aliases() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
Io_mgr.I.SaveFilStr("mem/en.wikipedia.org/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases", String_.Concat_lines_nl
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/en.wikipedia.org/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases", String_.Concat_lines_nl
|
||||
( "<api>"
|
||||
, "<query>"
|
||||
, "<namespacealiases>"
|
||||
@@ -127,7 +127,7 @@ public class Xob_wiki_cfg_bldr_tst {
|
||||
if (String_.Len_eq_0(wiki)) continue;
|
||||
try {
|
||||
String api = protocol + wiki + "/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases";
|
||||
String xml = String_.new_u8(Io_mgr.I.DownloadFil_args("", null).Trg_engine_key_(trg_engine_key).Exec_as_bry(api));
|
||||
String xml = String_.new_u8(Io_mgr.Instance.DownloadFil_args("", null).Trg_engine_key_(trg_engine_key).Exec_as_bry(api));
|
||||
if (xml == null) continue; // not found
|
||||
gplx.xmls.XmlDoc xdoc = gplx.xmls.XmlDoc_.parse(xml);
|
||||
gplx.xmls.XmlNde xnde = gplx.xmls.Xpath_.SelectFirst(xdoc.Root(), "query/namespacealiases");
|
||||
@@ -138,13 +138,13 @@ public class Xob_wiki_cfg_bldr_tst {
|
||||
if (!String_.Eq(ns_nde.Name(), "ns")) continue;
|
||||
int id = Int_.parse(ns_nde.Atrs().FetchValOr("id", "-1"));
|
||||
String name = String_.Replace(String_.Replace(ns_nde.Text_inner(), " ", "_"), "'", "''");
|
||||
sb.Add(Int_.Xto_str(id)).Add("|").Add(String_.Trim(name)).Add_char_nl();
|
||||
sb.Add(Int_.To_str(id)).Add("|").Add(String_.Trim(name)).Add_char_nl();
|
||||
}
|
||||
sb.Add("\");');\n");
|
||||
}
|
||||
catch(Exception e) {sb.Add("// fail: " + wiki + " " + Err_.Message_gplx_full(e)).Add_char_nl();}
|
||||
}
|
||||
return sb.Xto_str_and_clear();
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
class Xob_wiki_cfg_bldr_fxt {
|
||||
@@ -156,7 +156,7 @@ class Xob_wiki_cfg_bldr_fxt {
|
||||
wiki_cfg_bldr.Clear();
|
||||
hash.Clear();
|
||||
return this;
|
||||
} private Xoae_app app; Xob_wiki_cfg_bldr wiki_cfg_bldr; Ordered_hash hash = Ordered_hash_.new_();
|
||||
} private Xoae_app app; Xob_wiki_cfg_bldr wiki_cfg_bldr; Ordered_hash hash = Ordered_hash_.New();
|
||||
public Xob_wiki_cfg_bldr_fxt Init_cmd(String wiki, String key, String text) {
|
||||
wiki_cfg_bldr.Itms_get_or_new(wiki).Itms_add(key, text);
|
||||
return this;
|
||||
@@ -172,7 +172,7 @@ class Xob_wiki_cfg_bldr_fxt {
|
||||
KeyVal kv = (KeyVal)hash.Get_at(i);
|
||||
String wiki = kv.Key();
|
||||
String expd = (String)kv.Val();
|
||||
String actl = Io_mgr.I.LoadFilStr(app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki + ".gfs"));
|
||||
String actl = Io_mgr.Instance.LoadFilStr(app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki + ".gfs"));
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user