mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.2.4.1
This commit is contained in:
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Bfmtr_eval_wiki implements Bry_fmtr_eval_mgr {
|
||||
public Bfmtr_eval_wiki(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public Bfmtr_eval_wiki(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public byte[] Eval(byte[] cmd) {
|
||||
Object rslt = GfsCore._.Exec_bry(cmd, wiki);
|
||||
|
||||
@@ -1,33 +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; import gplx.*;
|
||||
public class Xow_dir_info {
|
||||
public Xow_dir_info(boolean ns_root, byte id, String name) {this.ns_root = ns_root; this.id = id; this.name = name;}
|
||||
public byte Id() {return id;} private byte id;
|
||||
public String Name() {return name;} private String name;
|
||||
public boolean Ns_root() {return ns_root;} private boolean ns_root;
|
||||
public String Ext() {return ext_str;} private String ext_str = Xow_fsys_mgr.Wtr_xdat_str;
|
||||
public byte[] Ext_bry() {return ext_bry;} private byte[] ext_bry = Xow_fsys_mgr.Wtr_xdat_bry;
|
||||
public byte Ext_tid() {return ext_tid;}
|
||||
public Xow_dir_info Ext_tid_(byte v) {
|
||||
ext_tid = v;
|
||||
ext_bry = Xow_fsys_mgr.Wtr_ext(v);
|
||||
ext_str = String_.new_ascii_(ext_bry);
|
||||
return this;
|
||||
} byte ext_tid = gplx.ios.Io_stream_.Tid_file;
|
||||
}
|
||||
@@ -1,59 +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; import gplx.*;
|
||||
public class Xow_dir_info_ {
|
||||
public static String Tid_name(byte tid) {
|
||||
switch (tid) {
|
||||
case Xow_dir_info_.Tid_page: return Xow_dir_info_.Name_page;
|
||||
case Xow_dir_info_.Tid_ttl: return Xow_dir_info_.Name_title;
|
||||
case Xow_dir_info_.Tid_id: return Xow_dir_info_.Name_id;
|
||||
case Xow_dir_info_.Tid_category: return Xow_dir_info_.Name_category;
|
||||
case Xow_dir_info_.Tid_category2_link: return Xow_dir_info_.Name_category2_link;
|
||||
case Xow_dir_info_.Tid_category2_main: return Xow_dir_info_.Name_category2_main;
|
||||
case Xow_dir_info_.Tid_search_ttl: return Xow_dir_info_.Name_search_ttl;
|
||||
default: throw Err_.unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static Xow_dir_info[] regy_() {
|
||||
Xow_dir_info[] rv = new Xow_dir_info[5];
|
||||
regy_itm_(rv, Bool_.Y, Tid_page);
|
||||
regy_itm_(rv, Bool_.Y, Tid_ttl);
|
||||
regy_itm_(rv, Bool_.N, Tid_id);
|
||||
regy_itm_(rv, Bool_.N, Tid_category);
|
||||
regy_itm_(rv, Bool_.N, Tid_search_ttl);
|
||||
return rv;
|
||||
}
|
||||
private static void regy_itm_(Xow_dir_info[] rv, boolean ns_root, byte id) {rv[id] = new Xow_dir_info(ns_root, id, Tid_name(id));}
|
||||
public static final String Ext_xdat = ".xdat", Ext_csv = ".csv", Ext_zip = ".zip"
|
||||
, Name_ns = "ns", Name_site = "site", Name_page = "page", Name_title = "title", Name_id = "id", Name_category = "category", Name_search_ttl = "search_title", Name_zip_suffix = "_zip"
|
||||
, Name_cfg = "cfg"
|
||||
, Name_reg_fil = "reg.csv", Name_category2 = "category2", Name_category2_link = "link", Name_category2_main = "main"
|
||||
;
|
||||
public static final byte[] Bry_xdat = Bry_.new_ascii_(Ext_xdat), Bry_csv = Bry_.new_ascii_(Ext_csv), Bry_zip = Bry_.new_ascii_(Ext_zip);
|
||||
public static final byte
|
||||
Tid_page = 0
|
||||
, Tid_ttl = 1
|
||||
, Tid_id = 2
|
||||
, Tid_category = 3
|
||||
, Tid_search_ttl = 4
|
||||
// , Tid_category2 = 5
|
||||
, Tid_category2_link = 5
|
||||
, Tid_category2_main = 6
|
||||
;
|
||||
public static final byte Regy_tid_max = 7;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.langs.numbers.*;
|
||||
public class Xow_fragment_mgr implements GfoInvkAble {
|
||||
public Xow_fragment_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public Xow_fragment_mgr(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public byte[] Html_js_edit_toolbar() {return html_js_edit_toolbar;} private byte[] html_js_edit_toolbar;
|
||||
private Bry_fmtr html_js_edit_toolbar_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( " var xowa_edit_i18n = {"
|
||||
@@ -44,8 +44,8 @@ public class Xow_fragment_mgr implements GfoInvkAble {
|
||||
}
|
||||
public static final String Invk_html_js_edit_toolbar_fmt_ = "html_js_edit_toolbar_fmt_", Invk_html_js_edit_toolbar = "html_js_edit_toolbar";
|
||||
public void Evt_lang_changed(Xol_lang lang) {
|
||||
Bry_bfr bfr = lang.App().Utl_bry_bfr_mkr().Get_b512();
|
||||
Xow_msg_mgr msg_mgr = wiki.App().User().Msg_mgr();
|
||||
Bry_bfr bfr = Xoa_app_.Utl_bry_bfr_mkr().Get_b512();
|
||||
Xow_msg_mgr msg_mgr = wiki.Appe().User().Msg_mgr();
|
||||
html_js_edit_toolbar = html_js_edit_toolbar_fmtr.Bld_bry_many(bfr
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_sample)
|
||||
|
||||
@@ -43,11 +43,11 @@ public class Xow_fragment_mgr_tst {
|
||||
class Xow_fragment_mgr_fxt {
|
||||
public void Clear() {
|
||||
if (wiki == null) {
|
||||
Xoa_app app = Xoa_app_fxt.app_();
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
} private Xow_wiki wiki;
|
||||
public Xol_lang Make_lang(String key) {return wiki.App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_(key));}
|
||||
} private Xowe_wiki wiki;
|
||||
public Xol_lang Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_(key));}
|
||||
public void Test_fragment(String key, String expd) {Test_fragment(wiki.Lang(), key, expd);}
|
||||
public void Test_fragment(Xol_lang lang, String key, String expd) {
|
||||
wiki.Fragment_mgr().Evt_lang_changed(lang);
|
||||
|
||||
@@ -1,118 +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; import gplx.*;
|
||||
public class Xow_fsys_mgr {
|
||||
public Xow_fsys_mgr(Xow_wiki wiki, Io_url root_dir) {
|
||||
this.wiki = wiki; this.root_dir = root_dir;
|
||||
ns_dir = root_dir.GenSubDir(Xow_dir_info_.Name_ns);
|
||||
site_dir = root_dir.GenSubDir(Xow_dir_info_.Name_site);
|
||||
tmp_dir = root_dir.GenSubDir("tmp");
|
||||
file_dir = wiki.App().Fsys_mgr().File_dir().GenSubDir_nest(wiki.Domain_str());
|
||||
file_dir_bry_len = file_dir.To_http_file_bry().length;
|
||||
} private Xow_wiki wiki;
|
||||
public Io_url Root_dir() {return root_dir;} private Io_url root_dir;
|
||||
public Io_url Ns_dir() {return ns_dir;} private Io_url ns_dir;
|
||||
public Io_url Site_dir() {return site_dir;} private Io_url site_dir;
|
||||
public Io_url File_dir() {return file_dir;} private Io_url file_dir;
|
||||
public int File_dir_bry_len() {return file_dir_bry_len;} private int file_dir_bry_len;
|
||||
public Io_url Tmp_dir() {return tmp_dir;} public void Tmp_dir_(Io_url v) {tmp_dir = v;} Io_url tmp_dir;
|
||||
public Io_url Cfg_wiki_core_fil() {return root_dir.GenSubFil_nest(Const_url_cfg, "wiki_core.gfs");}
|
||||
public Io_url Cfg_wiki_stats_fil() {return root_dir.GenSubFil_nest(Const_url_cfg, "wiki_stats.gfs");}
|
||||
public Xow_dir_info[] Dir_regy() {return dir_regy;} private Xow_dir_info[] dir_regy = Xow_dir_info_.regy_();
|
||||
public Io_url Url_ns_dir(String ns_num, byte tid) {return ns_dir.GenSubDir_nest(ns_num, Xow_dir_info_.Tid_name(tid));}
|
||||
public Io_url Url_ns_reg(String ns_num, byte tid) {return ns_dir.GenSubFil_nest (ns_num , Xow_dir_info_.Tid_name(tid) , Xow_dir_info_.Name_reg_fil);}
|
||||
public Io_url Url_ns_fil(byte tid, int ns_id, int fil_idx) {
|
||||
Xow_dir_info dir_info = dir_regy[tid];
|
||||
String dir_name = dir_info.Name() + Xow_fsys_mgr.Wtr_dir(dir_info.Ext_tid());
|
||||
return Xow_fsys_mgr.Url_fil(ns_dir.GenSubDir_nest(Int_.Xto_str_pad_bgn(ns_id, 3), dir_name), fil_idx, dir_regy[tid].Ext_bry());
|
||||
}
|
||||
public Io_url Url_site_fil(byte tid, int fil_idx) {return Xow_fsys_mgr.Url_fil(Url_site_dir(tid), fil_idx, Xow_dir_info_.Bry_xdat);}
|
||||
public Io_url Url_site_reg(byte tid) {return Url_site_dir(tid).GenSubFil(Xow_dir_info_.Name_reg_fil);}
|
||||
public Io_url Url_site_dir(byte tid) {
|
||||
switch (tid) {
|
||||
case Xow_dir_info_.Tid_category2_link: return site_dir.GenSubDir_nest(Xow_dir_info_.Name_category2, Xow_dir_info_.Name_category2_link);
|
||||
case Xow_dir_info_.Tid_category2_main: return site_dir.GenSubDir_nest(Xow_dir_info_.Name_category2, Xow_dir_info_.Name_category2_main);
|
||||
default: return site_dir.GenSubDir_nest(Xow_dir_info_.Tid_name(tid));
|
||||
}
|
||||
}
|
||||
public void Scan_dirs() {
|
||||
Scan_dirs_zip(this, Xow_dir_info_.Tid_page);
|
||||
Scan_dirs_ns(ns_dir, wiki.Ns_mgr());
|
||||
}
|
||||
private static void Scan_dirs_zip(Xow_fsys_mgr fsys_mgr, byte id) {
|
||||
Io_url[] dirs = Io_mgr._.QueryDir_args(fsys_mgr.Ns_dir().GenSubDir_nest("000")).FilPath_("*page*").DirOnly_().Recur_(false).ExecAsUrlAry();
|
||||
int len = dirs.length;
|
||||
byte tid = gplx.ios.Io_stream_.Tid_file; // needed for Xoa_xowa_exec_tst
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_url dir = dirs[i];
|
||||
String dir_name = dir.NameOnly();
|
||||
if (String_.Eq(dir_name, "page")) {tid = gplx.ios.Io_stream_.Tid_file; break;}
|
||||
else if (String_.Eq(dir_name, "page_zip")) tid = gplx.ios.Io_stream_.Tid_zip;
|
||||
else if (String_.Eq(dir_name, "page_gz")) tid = gplx.ios.Io_stream_.Tid_gzip;
|
||||
else if (String_.Eq(dir_name, "page_bz2")) tid = gplx.ios.Io_stream_.Tid_bzip2;
|
||||
// else throw Err_.unhandled(dir_name);
|
||||
}
|
||||
fsys_mgr.Dir_regy()[id].Ext_tid_(tid);
|
||||
}
|
||||
private static HashAdp Scan_dirs_ns(Io_url ns_dir, Xow_ns_mgr ns_mgr) {
|
||||
Io_url[] ns_dirs = Io_mgr._.QueryDir_args(ns_dir).Recur_(false).DirOnly_().ExecAsUrlAry();
|
||||
int len = ns_dirs.length;
|
||||
HashAdp rv = HashAdp_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
int ns_int = Int_.parse_or_(ns_dirs[i].NameOnly(), Int_.MinValue); if (ns_int == Int_.MinValue) continue;
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_int); if (ns == null) continue;
|
||||
ns.Exists_(true);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Io_url Url_fil(Io_url root_dir, int fil_idx, byte[] ext) {return Xos_url_gen.bld_fil_(root_dir, fil_idx, ext);}
|
||||
static final String Const_url_cfg = "cfg";
|
||||
public static Io_url Find_file_or_fail(Io_url dir, String file_name, String file_ext_0, String file_ext_1) {
|
||||
Io_url url = Find_file_or_null(dir, file_name, file_ext_0, file_ext_1);
|
||||
if (url == null) throw Err_mgr._.fmt_("", "", "could not find file: dir=~{0} name=~{1} ext_0=~{2} ext_1=~{3}", dir.Raw(), file_name, file_ext_0, file_ext_1);
|
||||
return url;
|
||||
}
|
||||
public static Io_url Find_file_or_null(Io_url dir, String file_name, String file_ext_0, String file_ext_1) {
|
||||
Io_url url = Xobd_rdr.Find_fil_by(dir, file_name + file_ext_0);
|
||||
if (url == null) {
|
||||
url = Xobd_rdr.Find_fil_by(dir, file_name + file_ext_1);
|
||||
if (url == null) return null;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
public static String Wtr_dir(byte v) {
|
||||
switch (v) {
|
||||
case gplx.ios.Io_stream_.Tid_file : return "";
|
||||
case gplx.ios.Io_stream_.Tid_zip : return "_zip";
|
||||
case gplx.ios.Io_stream_.Tid_gzip : return "_gz";
|
||||
case gplx.ios.Io_stream_.Tid_bzip2 : return "_bz2";
|
||||
default : throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
||||
public static byte[] Wtr_ext(byte v) {
|
||||
switch (v) {
|
||||
case gplx.ios.Io_stream_.Tid_file : return Wtr_xdat_bry;
|
||||
case gplx.ios.Io_stream_.Tid_zip : return Wtr_zip_bry;
|
||||
case gplx.ios.Io_stream_.Tid_gzip : return Wtr_gz_bry;
|
||||
case gplx.ios.Io_stream_.Tid_bzip2 : return Wtr_bz2_bry;
|
||||
default : throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
||||
public static final String Wtr_xdat_str = ".xdat", Wtr_zip_str = ".zip", Wtr_gz_str = ".gz", Wtr_bz2_str = ".bz2";
|
||||
public static final byte[] Wtr_xdat_bry = Bry_.new_ascii_(Wtr_xdat_str), Wtr_zip_bry = Bry_.new_ascii_(Wtr_zip_str), Wtr_gz_bry = Bry_.new_ascii_(Wtr_gz_str), Wtr_bz2_bry = Bry_.new_ascii_(Wtr_bz2_str);
|
||||
}
|
||||
@@ -1,38 +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; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xow_fsys_mgr_tst {
|
||||
Xow_fsys_mgr_fxt fxt = new Xow_fsys_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Zip_(Xow_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xow_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat");
|
||||
fxt.Zip_(Xow_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xow_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip");
|
||||
}
|
||||
}
|
||||
class Xow_fsys_mgr_fxt {
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
Xoa_app app; Xow_wiki wiki;
|
||||
public Xow_fsys_mgr_fxt Zip_(byte tid, boolean v) {wiki.Fsys_mgr().Dir_regy()[tid].Ext_tid_(v ? gplx.ios.Io_stream_.Tid_zip : gplx.ios.Io_stream_.Tid_file); return this;}
|
||||
public void Url_ns_fil(byte tid, int ns_id, int fil_idx, String expd) {
|
||||
Tfds.Eq(expd, wiki.Fsys_mgr().Url_ns_fil(tid, ns_id, fil_idx).Raw());
|
||||
}
|
||||
}
|
||||
@@ -17,19 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_html_util implements GfoInvkAble {
|
||||
public Xow_html_util(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public Xow_html_util(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_if_bool)) return If_bool(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
|
||||
else if (ctx.Match(k, Invk_if_yn)) return If_yn(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_if_bool = "if_bool", Invk_if_yn = "if_yn";
|
||||
String If_bool(String expr, String true_val, String false_val) {
|
||||
Object o = wiki.App().Gfs_mgr().Run_str(expr);
|
||||
Object o = wiki.Appe().Gfs_mgr().Run_str(expr);
|
||||
try {return Bool_.cast_(o) ? true_val : false_val;}
|
||||
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
|
||||
}
|
||||
String If_yn(String expr, String true_val, String false_val) {
|
||||
String o = String_.as_(wiki.App().Gfs_mgr().Run_str(expr));
|
||||
String o = String_.as_(wiki.Appe().Gfs_mgr().Run_str(expr));
|
||||
try {return Yn.parse_(o) ? true_val : false_val;}
|
||||
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
|
||||
}
|
||||
|
||||
@@ -1,85 +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; import gplx.*;
|
||||
public class Xow_lang_grp implements GfoInvkAble {
|
||||
public int Id() {return id;} private int id;
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public byte[] Name() {return name;} public Xow_lang_grp Name_(byte[] v) {name = v; return this;} private byte[] name;
|
||||
public int Sort_idx() {return sort_idx;} public Xow_lang_grp Sort_idx_(int v) {sort_idx = v; return this;} private int sort_idx = 0;
|
||||
public byte Sort_mode() {return sort_mode;} public Xow_lang_grp Sort_mode_(byte v) {sort_mode = v; return this;} private byte sort_mode = Sort_mode_page_name;
|
||||
public Xow_lang_itm[] Itms() {if (itms == null) itms = (Xow_lang_itm[])itm_list.Xto_ary(Xow_lang_itm.class); return itms;} private Xow_lang_itm[] itms;
|
||||
public int Itms_len() {return this.Itms().length;}
|
||||
public Xow_lang_itm Itms_get(int i) {return this.Itms()[i];}
|
||||
public void Itms_add(Xow_lang_itm itm) {itms = null; itm_list.Add(itm);} ListAdp itm_list = ListAdp_.new_();
|
||||
public void Itms_active_len_add_one_() {++itms_active_len;}
|
||||
public int Itms_active_len() {return itms_active_len;} private int itms_active_len;
|
||||
public void Itms_reset() {
|
||||
Xow_lang_itm[] itms_ary = this.Itms();
|
||||
int itms_len = itms_ary.length;
|
||||
for (int i = 0; i < itms_len; i++)
|
||||
itms_ary[i].Atrs_set(null, false, null); // clear out pre-existing page names; needed b/c this struct is a singleton for entire wiki
|
||||
itms_active_len = 0;
|
||||
}
|
||||
public Bry_fmtr Html_all() {return html_all;} Bry_fmtr html_all; public Xow_lang_grp Html_all_(String s) {html_all = Bry_fmtr.new_(s, "all_name", "grps"); return this;}
|
||||
public byte[] Html_grp_bgn() {return html_grp_bgn;} private byte[] html_grp_bgn = Bry_.new_ascii_("\n <tr>");
|
||||
public byte[] Html_grp_end() {return html_grp_end;} private byte[] html_grp_end = Bry_.new_ascii_("\n </tr>");
|
||||
public Bry_fmtr Html_itm() {return html_itm;} Bry_fmtr html_itm; public Xow_lang_grp Html_itm_(String s) {html_itm = Bry_fmtr.new_(s, "lang_code", "lang_domain", "lang_name", "lang_href", "pagename_translation", "page_badge"); return this;}
|
||||
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) {
|
||||
Xow_lang_itm[] itms_ary = this.Itms();
|
||||
if (sort_mode == Xow_lang_grp.Sort_mode_page_name)
|
||||
Array_.Sort(itms_ary, Xow_lang_itm_sorter_page_name._);
|
||||
int itms_ary_len = itms_ary.length;
|
||||
for (int i = 0; i < itms_ary_len; i++)
|
||||
itms_ary[i].Html_bld(bfr, wiki);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return lang_mgr;
|
||||
else if (ctx.Match(k, Invk_name_)) name = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_sort_idx_)) sort_idx = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_sort_mode_)) sort_mode = (byte)m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_html_all_)) Html_all_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_html_itm_)) Html_itm_(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_owner = "owner", Invk_name_ = "name_", Invk_sort_mode_ = "sort_mode_", Invk_sort_idx_ = "sort_idx_", Invk_html_all_ = "html_all_", Invk_html_itm_ = "html_itm_";
|
||||
public static final byte Sort_mode_lang_idx = 0, Sort_mode_lang_name = 1, Sort_mode_page_name = 2;
|
||||
public static Xow_lang_grp dflt_(Xow_lang_mgr lang_mgr, int id, byte[] key) {
|
||||
Xow_lang_grp rv = new Xow_lang_grp();
|
||||
rv.lang_mgr = lang_mgr; rv.id = id; rv.key = key; rv.name = key;
|
||||
rv.Html_all_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <h4>~{all_name}</h4>"
|
||||
, " <table style='width: 100%;'>~{grps}"
|
||||
, " </table>"
|
||||
));
|
||||
rv.Html_itm_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>~{lang_name}</td><td style='width: 20%; padding-bottom: 5px;'><li~{page_badge}><a hreflang=\"~{lang_code}\" title=\"~{pagename_translation}\" href=\"~{lang_href}\">~{pagename_translation}</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
));
|
||||
return rv;
|
||||
} private Xow_lang_grp() {}
|
||||
Xow_lang_mgr lang_mgr;
|
||||
}
|
||||
class Xow_lang_itm_sorter_page_name implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {return Bry_.Compare(((Xow_lang_itm)lhsObj).Page_name(), ((Xow_lang_itm)rhsObj).Page_name());}
|
||||
public static final Xow_lang_itm_sorter_page_name _ = new Xow_lang_itm_sorter_page_name(); Xow_lang_itm_sorter_page_name() {}
|
||||
}
|
||||
class Xow_lang_grp_sorter_sort_idx implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {return Int_.Compare(((Xow_lang_grp)lhsObj).Sort_idx(), ((Xow_lang_grp)rhsObj).Sort_idx());}
|
||||
public static final Xow_lang_grp_sorter_sort_idx _ = new Xow_lang_grp_sorter_sort_idx(); Xow_lang_grp_sorter_sort_idx() {}
|
||||
}
|
||||
@@ -1,38 +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; import gplx.*;
|
||||
import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xow_lang_itm {
|
||||
public Xow_lang_itm(Xow_lang_grp html_grp, Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
|
||||
this.html_grp = html_grp; this.xwiki = xwiki; this.lang = lang;
|
||||
} private Xow_lang_grp html_grp; Xow_xwiki_itm xwiki; Xoac_lang_itm lang;
|
||||
public byte[] Lang_key() {return lang.Key_bry();}
|
||||
public byte[] Lang_domain() {return xwiki.Domain();}
|
||||
public byte[] Lang_name() {return lang.Local_name_bry();}
|
||||
public byte[] Page_name() {return page_name;} private byte[] page_name;
|
||||
public boolean Page_name_has() {return Bry_.Len_gt_0(page_name);}
|
||||
public boolean Empty_xwiki() {return empty_xwiki;} private boolean empty_xwiki;
|
||||
public byte[][] Page_badges() {return page_badges;} private byte[][] page_badges;
|
||||
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) {
|
||||
html_grp.Html_itm().Bld_bfr(bfr, lang.Key_bry(), xwiki.Domain(), lang.Local_name_bry(), page_name);
|
||||
}
|
||||
public void Atrs_set(byte[] page_name, boolean empty_xwiki, byte[][] page_badges) {
|
||||
this.page_name = page_name; this.empty_xwiki = empty_xwiki; this.page_badges = page_badges;
|
||||
html_grp.Itms_active_len_add_one_();
|
||||
}
|
||||
}
|
||||
@@ -1,193 +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; import gplx.*;
|
||||
import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.xtns.wdatas.core.*;
|
||||
public class Xow_lang_mgr {
|
||||
Xow_lang_mgr() {
|
||||
int len = Xol_lang_itm_.Id__max;
|
||||
itms = new Xow_lang_itm[len];
|
||||
}
|
||||
public Bry_fmtr Html_div() {return html_div;} Bry_fmtr html_div = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>~{langs_hdr}~{wikidata_link}~{toggle_btn}</h5>"
|
||||
, " <div~{toggle_hdr}>~{grps}"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
), "langs_hdr", "wikidata_link", "toggle_btn", "toggle_hdr", "grps");
|
||||
public Bry_fmtr Html_wikidata_link() {return html_wikidata_link;} Bry_fmtr html_wikidata_link = Bry_fmtr.new_(" (<a href=\"/site/www.wikidata.org/wiki/~{qid}\">wikidata</a>)", "qid");
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Itms_reg(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
|
||||
int lang_id = xwiki.Lang_id();
|
||||
Xoac_lang_grp ini_grp = lang.Grp();
|
||||
Xow_lang_grp grp = (Xow_lang_grp)hash.Fetch(ini_grp.Key_bry());
|
||||
if (grp == null) {
|
||||
grp = Grps_get_or_new(ini_grp.Key_bry());
|
||||
grp.Name_(ini_grp.Name_bry());
|
||||
grp.Sort_idx_(ini_grp.Sort_idx());
|
||||
}
|
||||
Xow_lang_itm itm = itms[lang_id];
|
||||
if (itm == null) {
|
||||
itm = new Xow_lang_itm(grp, xwiki, lang);
|
||||
itms[lang_id] = itm;
|
||||
}
|
||||
grp.Itms_add(itm);
|
||||
}
|
||||
public int Grps_len() {return hash.Count();}
|
||||
public Xow_lang_grp Grps_get_at(int i) {return (Xow_lang_grp)hash.FetchAt(i);}
|
||||
Xow_lang_grp Grps_get_or_new(byte[] key) {
|
||||
Xow_lang_grp rv = (Xow_lang_grp)hash.Fetch(key);
|
||||
if (rv == null) {
|
||||
int id = hash.Count();
|
||||
rv = Xow_lang_grp.dflt_(this, id, key);
|
||||
rv.Sort_idx_(id);
|
||||
hash.Add(key, rv);
|
||||
rv.Name_(key);
|
||||
}
|
||||
return rv;
|
||||
} private OrderedHash hash = OrderedHash_.new_bry_();
|
||||
public void Grps_sort() {hash.SortBy(Xow_lang_grp_sorter_sort_idx._);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Grps_get_or_new(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_sort)) Grps_sort();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_get = "get", Invk_sort = "sort";
|
||||
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki, ListAdp slink_list, byte[] qid) {
|
||||
int grp_len = hash.Count();
|
||||
for (int i = 0; i < grp_len; i++) {
|
||||
Xow_lang_grp grp = (Xow_lang_grp)hash.FetchAt(i);
|
||||
grp.Itms_reset();
|
||||
}
|
||||
int slink_len = slink_list.Count();
|
||||
for (int i = 0; i < slink_len; i++) {
|
||||
Wdata_sitelink_itm slink = (Wdata_sitelink_itm)slink_list.FetchAt(i);
|
||||
Xoa_ttl ttl = slink.Page_ttl();
|
||||
Xow_xwiki_itm xwiki = ttl.Wik_itm();
|
||||
int lang_id = xwiki.Lang_id();
|
||||
Xow_lang_itm itm = itms[lang_id]; // NOTE: handles ttls like [[fr:]] and [[:fr;]] which have an empty Page_txt, but a valued Full_txt_raw
|
||||
byte[] ttl_bry = ttl.Page_txt_w_anchor();
|
||||
boolean empty_xwiki = false;
|
||||
if (Bry_.Len_eq_0(ttl_bry)) {
|
||||
ttl_bry = wiki.Ctx().Cur_page().Ttl().Page_txt();
|
||||
empty_xwiki = true;
|
||||
}
|
||||
itm.Atrs_set(ttl_bry, empty_xwiki, slink.Badges());
|
||||
}
|
||||
html_bldr.Init(this, wiki, slink_list, slink_len, qid);
|
||||
html_bldr.XferAry(bfr, -1);
|
||||
} private Xow_lang_itm[] itms = null; Xow_lang_html html_bldr = new Xow_lang_html();
|
||||
public static Xow_lang_mgr dflt_() {
|
||||
return new Xow_lang_mgr();
|
||||
}
|
||||
}
|
||||
class Xow_lang_html implements Bry_fmtr_arg {
|
||||
private Xow_lang_mgr lang_mgr; Xow_wiki wiki; ListAdp ttl_list; private byte[] qid;
|
||||
private Xoapi_toggle_itm toggle_itm;
|
||||
private int stage = 0;
|
||||
public Xow_lang_html Init(Xow_lang_mgr lang_mgr, Xow_wiki wiki, ListAdp ttl_list, int ttl_list_len, byte[] qid) {
|
||||
this.lang_mgr = lang_mgr; this.wiki = wiki; this.ttl_list = ttl_list; this.qid = qid;
|
||||
toggle_itm = wiki.App().Api_root().Html().Page().Toggle_mgr().Get_or_new("wikidata-langs");
|
||||
return this;
|
||||
}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
switch (stage) {
|
||||
case 0: {
|
||||
stage = 1;
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b128().Mkr_rls();
|
||||
byte[] msg_lang = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_page_lang_header);
|
||||
byte[] wikidata_link = Bry_.Len_eq_0(qid) ? Bry_.Empty : lang_mgr.Html_wikidata_link().Bld_bry_many(tmp_bfr, qid);
|
||||
toggle_itm.Init(wiki);
|
||||
lang_mgr.Html_div().Bld_bfr_many(bfr, msg_lang, wikidata_link, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), this);
|
||||
stage = 0;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
stage = 2;
|
||||
int grps_len = lang_mgr.Grps_len();
|
||||
for (int i = 0; i < grps_len; i++) {
|
||||
grp = lang_mgr.Grps_get_at(i);
|
||||
if (grp.Itms_active_len() == 0) continue; // skip grps with no items
|
||||
grp.Html_all().Bld_bfr_many(bfr, grp.Name(), this);
|
||||
}
|
||||
stage = 1;
|
||||
break;
|
||||
case 2:
|
||||
int itms_len = grp.Itms_len();
|
||||
int grp_counter = 0; boolean row_opened = false;
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
Xow_lang_itm itm = grp.Itms_get(i);
|
||||
if (!itm.Page_name_has()) continue;
|
||||
if (grp_counter == 0) {
|
||||
bfr.Add(grp.Html_grp_bgn());
|
||||
row_opened = true;
|
||||
}
|
||||
byte[] lang_key = itm.Lang_key();
|
||||
byte[] domain = itm.Lang_domain();
|
||||
byte[] page_name = itm.Page_name();
|
||||
byte[] local_name = itm.Lang_name();
|
||||
byte[] badge_cls = Badge_cls(tmp_bfr, itm.Page_badges());
|
||||
if (wiki.App().User().Wiki().Xwiki_mgr().Get_by_key(domain) == null)
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_http_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
|
||||
else
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_site_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
|
||||
if (!itm.Empty_xwiki()) tmp_bfr.Add(page_name);
|
||||
grp.Html_itm().Bld_bfr_many(bfr, lang_key, domain, local_name, tmp_bfr.Xto_bry_and_clear(), page_name, badge_cls);
|
||||
++grp_counter;
|
||||
if (grp_counter == 3) {
|
||||
row_opened = false;
|
||||
bfr.Add(grp.Html_grp_end());
|
||||
grp_counter = 0;
|
||||
}
|
||||
}
|
||||
if (row_opened) {
|
||||
bfr.Add(grp.Html_grp_end());
|
||||
grp_counter = 0;
|
||||
}
|
||||
stage = 2;
|
||||
break;
|
||||
}
|
||||
} private Xow_lang_grp grp; Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private static byte[] Badge_cls(Bry_bfr bfr, byte[][] badges) {
|
||||
if (badges == null) badges = Bry_.Ary_empty;
|
||||
int badges_len = badges.length;
|
||||
bfr.Add(Cls_bgn);
|
||||
if (badges_len == 0)
|
||||
bfr.Add(Badge_none_cls);
|
||||
else {
|
||||
for (int i = 0; i < badges_len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_comma();
|
||||
byte[] badge = badges[i];
|
||||
byte[] badge_cls = (byte[])badges_hash.Get_by_bry(badge);
|
||||
if (badge_cls == null) Gfo_usr_dlg_._.Warn_many("", "", "unknown badge: badge~{0}", String_.new_utf8_(badge));
|
||||
else bfr.Add(badge_cls);
|
||||
}
|
||||
}
|
||||
bfr.Add_byte_apos();
|
||||
return bfr.Xto_bry_and_clear();
|
||||
}
|
||||
private static final byte[]
|
||||
Badge_none_cls = Bry_.new_ascii_("badge-none")
|
||||
, Cls_bgn = Bry_.new_ascii_(" class='")
|
||||
;
|
||||
private static Hash_adp_bry badges_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_obj("Q17437798", Bry_.new_ascii_("badge-goodarticle"))
|
||||
.Add_str_obj("Q17437796", Bry_.new_ascii_("badge-featuredarticle"))
|
||||
.Add_str_obj("Q17559452", Bry_.new_ascii_("badge-recommendedarticle"))
|
||||
.Add_str_obj("Q17506997", Bry_.new_ascii_("badge-featuredlist"))
|
||||
;
|
||||
}
|
||||
@@ -1,65 +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; import gplx.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_lang_mgr_fxt {
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
Init_langs(wiki);
|
||||
}
|
||||
public static void Init_langs(Xow_wiki wiki) {
|
||||
Xoa_app app = wiki.App();
|
||||
Xoa_lang_mgr lang_mgr = app.Lang_mgr();
|
||||
lang_mgr.Groups().Set_bulk(Bry_.new_ascii_(String_.Concat_lines_nl
|
||||
( "+||grp|wiki"
|
||||
, "+|wiki|grp|grp1"
|
||||
, "+|wiki|grp|grp2"
|
||||
, "+|grp1|itm|simple|Simple"
|
||||
, "+|grp2|itm|fr|French"
|
||||
, "+|grp1|itm|es|Spanish"
|
||||
, "+|grp2|itm|de|German"
|
||||
, "+|grp1|itm|it|Italian"
|
||||
, "+|grp1|itm|zh|Chinese"
|
||||
)));
|
||||
wiki.Xwiki_mgr().Add_bulk_langs(Bry_.new_ascii_("wiki"));
|
||||
String bulk = String_.Concat_lines_nl
|
||||
( "simple.wikipedia.org|simple.wikipedia.org"
|
||||
, "fr.wikipedia.org|fr.wikipedia.org"
|
||||
, "es.wikipedia.org|es.wikipedia.org"
|
||||
, "de.wikipedia.org|de.wikipedia.org"
|
||||
, "it.wikipedia.org|it.wikipedia.org"
|
||||
);
|
||||
wiki.App().User().Wiki().Xwiki_mgr().Add_bulk(Bry_.new_ascii_(bulk));
|
||||
}
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
Xoa_app app;
|
||||
public void tst(String raw, String expd) {
|
||||
Xop_ctx ctx = wiki.Ctx();
|
||||
ctx.Cur_page().Ttl_(Xoa_ttl.parse_(wiki, Bry_.new_ascii_("test_page")));
|
||||
byte[] raw_bry = Bry_.new_utf8_(raw);
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(raw_bry);
|
||||
wiki.Parser().Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), raw_bry);
|
||||
wiki.Html_mgr().Html_wtr().Write_all(bfr, ctx, raw_bry, root);
|
||||
|
||||
Bry_bfr html_bfr = Bry_bfr.new_();
|
||||
wiki.Xwiki_mgr().Lang_mgr().Html_bld(html_bfr, wiki, ctx.Cur_page().Slink_list(), gplx.xowa.xtns.wdatas.Wdata_xwiki_link_wtr.Qid_null);
|
||||
Tfds.Eq_str_lines(expd, html_bfr.Xto_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -1,93 +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; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xow_lang_mgr_tst {
|
||||
private Xow_lang_mgr_fxt fxt = new Xow_lang_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.tst("[[simple:Earth]] [[fr:Terre]] [[es:Tierra]] [[de:Erde]] [[it:Terre]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages<a href='javascript:xowa_toggle_visible(\"wikidata-langs\");'><img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
|
||||
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"Earth\" href=\"/site/simple.wikipedia.org/wiki/Earth\">Earth</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Spanish</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"es\" title=\"Tierra\" href=\"/site/es.wikipedia.org/wiki/Tierra\">Tierra</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Italian</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"it\" title=\"Terre\" href=\"/site/it.wikipedia.org/wiki/Terre\">Terre</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " <h4>grp2</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"fr\" title=\"Terre\" href=\"/site/fr.wikipedia.org/wiki/Terre\">Terre</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"de\" title=\"Erde\" href=\"/site/de.wikipedia.org/wiki/Erde\">Erde</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Empty() {
|
||||
fxt.tst("[[simple:]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages<a href='javascript:xowa_toggle_visible(\"wikidata-langs\");'><img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
|
||||
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"Test page\" href=\"/site/simple.wikipedia.org/wiki/\">Test page</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Unregistered() {
|
||||
// fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_utf8_("zh"), Bry_.new_utf8_("zh.wikipedia.org"), Bry_.new_utf8_("http://zh.wikipedia.org/~{0}"));
|
||||
fxt.tst("[[zh:Earth]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages<a href='javascript:xowa_toggle_visible(\"wikidata-langs\");'><img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
|
||||
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Chinese</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"zh\" title=\"Earth\" href=\"http://zh.wikipedia.org/wiki/Earth\">Earth</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Anchor() {// PURPOSE: A#b was not showing anchor "#b"; DATE:2013-10-23
|
||||
fxt.tst("[[simple:A#b]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages<a href='javascript:xowa_toggle_visible(\"wikidata-langs\");'><img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
|
||||
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"A#b\" href=\"/site/simple.wikipedia.org/wiki/A#b\">A#b</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.langs.msgs.*;
|
||||
public class Xow_mainpage_finder {
|
||||
public static byte[] Find_or(Xow_wiki wiki, byte[] or) {
|
||||
public static byte[] Find_or(Xowe_wiki wiki, byte[] or) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
Xol_msg_itm msg_itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), Msg_mainpage);
|
||||
byte[] rv = msg_itm.Src_is_missing()
|
||||
|
||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.html.sidebar.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xow_msg_mgr implements GfoInvkAble {
|
||||
private Xow_wiki wiki; private Xol_lang lang; private Xol_msg_mgr msg_mgr;
|
||||
public Xow_msg_mgr(Xow_wiki wiki, Xol_lang lang) {
|
||||
private final Xowe_wiki wiki; private Xol_lang lang; private final Xol_msg_mgr msg_mgr;
|
||||
public Xow_msg_mgr(Xowe_wiki wiki, Xol_lang lang) {
|
||||
this.wiki = wiki;
|
||||
this.lang = lang;
|
||||
this.msg_mgr = new Xol_msg_mgr(wiki, false);
|
||||
@@ -35,7 +35,7 @@ public class Xow_msg_mgr implements GfoInvkAble {
|
||||
Xol_msg_itm itm = msg_mgr.Itm_by_id_or_null(id);
|
||||
if (itm == null)
|
||||
itm = lang.Msg_mgr().Itm_by_id_or_null(id);
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl_bry_bfr_mkr().Get_b512();
|
||||
byte[] rv = Val_by_itm(tmp_bfr, itm, args);
|
||||
tmp_bfr.Mkr_rls();
|
||||
return rv;
|
||||
@@ -45,7 +45,7 @@ public class Xow_msg_mgr implements GfoInvkAble {
|
||||
public Xol_msg_itm Find_or_null(byte[] key) {
|
||||
Xol_msg_itm itm = msg_mgr.Itm_by_key_or_null(key);
|
||||
if (itm == null) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl_bry_bfr_mkr().Get_b512();
|
||||
itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, lang, key);
|
||||
if (itm.Src_is_missing()) itm = null;
|
||||
tmp_bfr.Mkr_rls();
|
||||
@@ -57,7 +57,7 @@ public class Xow_msg_mgr implements GfoInvkAble {
|
||||
public byte[] Val_by_key_obj(byte[] key) {return Val_by_key(key, null);}
|
||||
private byte[] Val_by_key(byte[] key, Object[] args) {
|
||||
Xol_msg_itm itm = msg_mgr.Itm_by_key_or_null(key);
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl_bry_bfr_mkr().Get_b512();
|
||||
if (itm == null)
|
||||
itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, lang, key);
|
||||
if (itm.Src_is_missing()) {
|
||||
@@ -75,7 +75,7 @@ public class Xow_msg_mgr implements GfoInvkAble {
|
||||
return rv;
|
||||
}
|
||||
public byte[] Val_html_accesskey_and_title(byte[] id) {
|
||||
Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
Bry_bfr bfr = Xoa_app_.Utl_bry_bfr_mkr().Get_b512();
|
||||
byte[] rv = Val_html_accesskey_and_title(id, bfr, null);
|
||||
bfr.Mkr_rls();
|
||||
return rv;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
name_hash = Hash_adp_bry.ci_utf8_(case_mgr);
|
||||
tmpl_hash = Hash_adp_bry.ci_utf8_(case_mgr);
|
||||
}
|
||||
public void Clear() {
|
||||
public Xow_ns_mgr Clear() {
|
||||
name_hash.Clear();
|
||||
id_hash.Clear();
|
||||
tmpl_hash.Clear();
|
||||
@@ -36,6 +36,7 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
ords_len = 0;
|
||||
ns_count = 0;
|
||||
ns_file = null;
|
||||
return this;
|
||||
}
|
||||
public Btrie_slim_mgr Category_trie() {return category_trie;} private Btrie_slim_mgr category_trie;
|
||||
public Xow_ns Ns_main() {return ns_main;} private Xow_ns ns_main;
|
||||
|
||||
@@ -23,25 +23,25 @@ public class Xow_script_mgr implements GfoInvkAble {
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_set = "set";
|
||||
public void Exec(Xow_wiki wiki) {
|
||||
public void Exec(Xowe_wiki wiki) {
|
||||
int len = hash.Count();
|
||||
Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_script_itm itm = (Xow_script_itm)hash.FetchAt(i);
|
||||
byte wiki_tid = wiki.Domain_tid();
|
||||
if (Byte_.In(wiki_tid, itm.Wiki_tids())) // wiki_tid matches itm
|
||||
itm.Fmtr().Bld_bfr_many(bfr, wiki.Domain_bry(), Xow_wiki_domain_.Key_by_tid(wiki_tid), wiki.Lang().Key_bry());
|
||||
int wiki_tid = wiki.Domain_tid();
|
||||
if (Int_.In(wiki_tid, itm.Wiki_tids())) // wiki_tid matches itm
|
||||
itm.Fmtr().Bld_bfr_many(bfr, wiki.Domain_bry(), Xow_domain_.Tid__get_bry(wiki_tid), wiki.Lang().Key_bry());
|
||||
}
|
||||
String gfs_script = String_.Replace(bfr.Xto_str_and_clear(), Op_sys.Wnt.Nl_str(), Op_sys.Lnx.Nl_str());
|
||||
wiki.App().Gfs_mgr().Run_str(gfs_script);
|
||||
wiki.Appe().Gfs_mgr().Run_str(gfs_script);
|
||||
bfr.Mkr_rls();
|
||||
}
|
||||
public void Set(byte[] key, byte[] wiki_types_raw, byte[] script) {
|
||||
byte[][] wiki_tid_names = Bry_.Split(wiki_types_raw, Byte_ascii.Tilde);
|
||||
int len = wiki_tid_names.length;
|
||||
byte[] wiki_tids = new byte[len];
|
||||
int[] wiki_tids = new int[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
wiki_tids[i] = Xow_wiki_domain_.Tid_by_key(wiki_tid_names[i]);
|
||||
wiki_tids[i] = Xow_domain_.Tid__get_int(wiki_tid_names[i]);
|
||||
|
||||
Xow_script_itm itm = new Xow_script_itm(key, wiki_tids, script);
|
||||
hash.AddReplace(itm.Key(), itm);
|
||||
@@ -49,10 +49,10 @@ public class Xow_script_mgr implements GfoInvkAble {
|
||||
public OrderedHash hash = OrderedHash_.new_bry_();
|
||||
}
|
||||
class Xow_script_itm {
|
||||
public Xow_script_itm(byte[] key, byte[] wiki_tids, byte[] script) {
|
||||
public Xow_script_itm(byte[] key, int[] wiki_tids, byte[] script) {
|
||||
this.key = key; this.wiki_tids = wiki_tids; this.fmtr = Bry_fmtr.new_bry_(script, "wiki_key", "wiki_type_name", "wiki_lang");
|
||||
}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public byte[] Wiki_tids() {return wiki_tids;} private byte[] wiki_tids;
|
||||
public int[] Wiki_tids() {return wiki_tids;} private int[] wiki_tids;
|
||||
public Bry_fmtr Fmtr() {return fmtr;} Bry_fmtr fmtr;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_sys_cfg implements GfoInvkAble {
|
||||
public Xow_sys_cfg(Xow_wiki wiki) {}
|
||||
public Xow_sys_cfg(Xowe_wiki wiki) {}
|
||||
public boolean Xowa_cmd_enabled() {return xowa_cmd_enabled;} public Xow_sys_cfg Xowa_cmd_enabled_(boolean v) {xowa_cmd_enabled = v; return this;} private boolean xowa_cmd_enabled;
|
||||
public boolean Xowa_proto_enabled() {return xowa_proto_enabled;} public Xow_sys_cfg Xowa_proto_enabled_(boolean v) {xowa_proto_enabled = v; return this;} private boolean xowa_proto_enabled;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.paras.*;
|
||||
public class Xow_utl_mgr {
|
||||
public Xow_utl_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public Xow_utl_mgr(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public Xop_parser Anchor_encode_parser() {
|
||||
if (anchor_encode_parser == null) {
|
||||
anchor_encode_parser = new Xop_parser(wiki, wiki.Parser().Tmpl_lxr_mgr(), Anchor_encode_lxr_mgr);
|
||||
|
||||
@@ -16,274 +16,17 @@ 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; import gplx.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.html.*; import gplx.xowa.users.history.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*; import gplx.xowa.apps.ttls.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.setup.maints.*; import gplx.xowa.wikis.caches.*;
|
||||
import gplx.xowa.bldrs.imports.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
public class Xow_wiki implements GfoInvkAble, Xoa_ttl_parser {
|
||||
private Xow_html_util util; private boolean hdump_enabled;
|
||||
public Xow_wiki(Xoa_app app, Io_url wiki_dir, Xow_ns_mgr ns_mgr, Xol_lang lang) {
|
||||
this.app = app; this.ns_mgr = ns_mgr; this.lang = lang;
|
||||
domain_str = wiki_dir.NameOnly(); domain_bry = Bry_.new_utf8_(domain_str);
|
||||
domain_itm = Xow_wiki_domain_.parse_by_domain(domain_bry);
|
||||
domain_tid = domain_itm.Wiki_tid();
|
||||
xwiki_domain_tid = Xow_wiki_domain_.Xwiki_tid(domain_tid);
|
||||
fsys_mgr = new Xow_fsys_mgr(this, wiki_dir);
|
||||
redirect_mgr = new Xop_redirect_mgr(this);
|
||||
data_mgr = new Xow_data_mgr(this);
|
||||
file_mgr = new Xow_file_mgr(this);
|
||||
utl_mgr = new Xow_utl_mgr(this);
|
||||
parser = Xop_parser.new_wiki_(this);
|
||||
cfg_parser = new Xowc_parser(this);
|
||||
ctx = Xop_ctx.new_(this);
|
||||
props.SiteName_(domain_tid).ServerName_(domain_bry);
|
||||
props.ContentLanguage_(lang.Key_bry());
|
||||
Pf_func_.Reg(lang.Func_regy(), lang);
|
||||
special_mgr = new Xows_mgr(this, lang);
|
||||
stats = new Xow_wiki_stats(this);
|
||||
xwiki_mgr = new Xow_xwiki_mgr(this, app.Url_parser().Url_parser(), domain_tid);
|
||||
xwiki_mgr.Add_full(domain_bry, domain_bry); // add full name to xwiki_mgr; needed for lookup in home ns; EX: [[en.wikipedia.org:Earth]]
|
||||
html_mgr = new Xow_html_mgr(this);
|
||||
sys_cfg = new Xow_sys_cfg(this);
|
||||
hive_mgr = new Xob_hive_mgr(this);
|
||||
util = new Xow_html_util(this);
|
||||
cfg_wiki_core = new Xow_cfg_wiki_core(this);
|
||||
import_cfg = new Xob_import_cfg(this);
|
||||
msg_mgr = new Xow_msg_mgr(this, lang);
|
||||
eval_mgr = new Bfmtr_eval_wiki(this);
|
||||
fragment_mgr = new Xow_fragment_mgr(this);
|
||||
xtn_mgr = new Xow_xtn_mgr().Ctor_by_wiki(this);
|
||||
if (domain_tid == Xow_wiki_domain_.Tid_home) {
|
||||
wdata_wiki_tid = Xow_wiki_domain_.Tid_wikipedia;
|
||||
wdata_wiki_lang = Xol_lang_.Key_en;
|
||||
}
|
||||
else {
|
||||
wdata_wiki_tid = domain_tid;
|
||||
wdata_wiki_lang = domain_itm.Lang_orig_key(); // NOTE: must use orig_key for nowiki; "no" not "nb" DATE:2014-10-07
|
||||
}
|
||||
Wdata_wiki_abrv_();
|
||||
db_mgr = new gplx.xowa.dbs.Xodb_mgr_txt(this, data_mgr);
|
||||
domain_abrv = Xow_wiki_alias.Build_alias(Xow_wiki_domain_.parse_by_domain(domain_bry));
|
||||
maint_mgr = new Xow_maint_mgr(this);
|
||||
cache_mgr = new Xow_cache_mgr(this);
|
||||
}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public byte[] Domain_bry() {return domain_bry;} private byte[] domain_bry;
|
||||
public String Domain_str() {return domain_str;} private String domain_str;
|
||||
public byte Domain_tid() {return domain_tid;} private byte domain_tid;
|
||||
public byte[] Domain_abrv() {return domain_abrv;} private byte[] domain_abrv;
|
||||
public Xow_wiki_domain Domain_itm() {return domain_itm;} private Xow_wiki_domain domain_itm;
|
||||
public byte Xwiki_domain_tid() {return xwiki_domain_tid;} private byte xwiki_domain_tid;
|
||||
public Xol_lang Lang() {return lang;} private Xol_lang lang;
|
||||
public Xow_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xow_fsys_mgr fsys_mgr;
|
||||
public Xow_utl_mgr Utl_mgr() {return utl_mgr;} private Xow_utl_mgr utl_mgr;
|
||||
public Xow_ns_mgr Ns_mgr() {return ns_mgr;} public void Ns_mgr_(Xow_ns_mgr v) {ns_mgr = v;} private Xow_ns_mgr ns_mgr;
|
||||
public Xow_gui_mgr Gui_mgr() {return gui_mgr;} private Xow_gui_mgr gui_mgr = new Xow_gui_mgr();
|
||||
public Xow_user User() {return user;} private Xow_user user = new Xow_user();
|
||||
public Xow_data_mgr Data_mgr() {return data_mgr;} private Xow_data_mgr data_mgr;
|
||||
public Xodb_mgr Db_mgr() {return db_mgr;} private Xodb_mgr db_mgr;
|
||||
public Xodb_mgr_sql Db_mgr_as_sql() {return (Xodb_mgr_sql)db_mgr;}
|
||||
public Xows_mgr Special_mgr() {return special_mgr;} private Xows_mgr special_mgr;
|
||||
public Xow_html_mgr Html_mgr() {return html_mgr;} private Xow_html_mgr html_mgr;
|
||||
public Xow_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Xow_xtn_mgr xtn_mgr;
|
||||
public Xow_cache_mgr Cache_mgr() {return cache_mgr;} private Xow_cache_mgr cache_mgr;
|
||||
|
||||
public byte[] Commons_wiki_key() {return commons_wiki_key;} private byte[] commons_wiki_key = Xow_wiki_.Domain_commons_bry;
|
||||
public Xob_hive_mgr Hive_mgr() {return hive_mgr;} private Xob_hive_mgr hive_mgr;
|
||||
public Xow_msg_mgr Msg_mgr() {return msg_mgr;} private Xow_msg_mgr msg_mgr;
|
||||
public Xow_fragment_mgr Fragment_mgr() {return fragment_mgr;} private Xow_fragment_mgr fragment_mgr;
|
||||
public Bfmtr_eval_wiki Eval_mgr() {return eval_mgr;} private Bfmtr_eval_wiki eval_mgr;
|
||||
public Bry_bfr_mkr Utl_bry_bfr_mkr() {return app.Utl_bry_bfr_mkr();}
|
||||
// public byte Wdata_wiki_tid() {return wdata_wiki_tid;}
|
||||
public byte[] Wdata_wiki_lang() {return wdata_wiki_lang;} private byte[] wdata_wiki_lang;
|
||||
public void Wdata_wiki_lang_(byte[] v) {this.wdata_wiki_lang = v; Wdata_wiki_abrv_();} // TEST:
|
||||
public byte[] Wdata_wiki_abrv() {return wdata_wiki_abrv;} private byte[] wdata_wiki_abrv; private byte wdata_wiki_tid;
|
||||
private void Wdata_wiki_abrv_() {
|
||||
Bry_bfr bfr = app.Utl_bry_bfr_mkr().Get_b128();
|
||||
Xow_wiki_alias.Build_alias_by_lang_tid(bfr, wdata_wiki_lang, Byte_obj_ref.new_(wdata_wiki_tid));
|
||||
wdata_wiki_abrv = bfr.Mkr_rls().Xto_bry_and_clear();
|
||||
}
|
||||
public Xoa_ttl Ttl_parse(byte[] ttl) {return Xoa_ttl.parse_(this, ttl);}
|
||||
public Xoa_ttl Ttl_parse(int ns_id, byte[] ttl) {return Xoa_ttl.parse_(this, ns_id, ttl);}
|
||||
|
||||
public boolean Init_needed() {return init_needed;} public Xow_wiki Init_needed_(boolean v) {init_needed = v; return this;} private boolean init_needed = true;
|
||||
|
||||
public Xop_parser Parser() {return parser;} private Xop_parser parser;
|
||||
public Xop_redirect_mgr Redirect_mgr() {return redirect_mgr;} private Xop_redirect_mgr redirect_mgr;
|
||||
public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx;
|
||||
public ListAdp Rls_list() {if (rls_list == null) rls_list = ListAdp_.new_(); return rls_list;} private ListAdp rls_list;
|
||||
|
||||
public Xow_xwiki_mgr Xwiki_mgr() {return xwiki_mgr;} private Xow_xwiki_mgr xwiki_mgr;
|
||||
public Xow_file_mgr File_mgr() {return file_mgr;} private Xow_file_mgr file_mgr;
|
||||
public Xow_cfg_wiki_core Cfg_wiki_core() {return cfg_wiki_core;} private Xow_cfg_wiki_core cfg_wiki_core;
|
||||
public Xob_import_cfg Import_cfg() {return import_cfg;} private Xob_import_cfg import_cfg;
|
||||
|
||||
public Xow_wiki_stats Stats() {return stats;} private Xow_wiki_stats stats;
|
||||
public Xow_wiki_props Props() {return props;} private Xow_wiki_props props = new Xow_wiki_props();
|
||||
public Xou_history_cfg Cfg_history() {return cfg_history;} private Xou_history_cfg cfg_history = new Xou_history_cfg();
|
||||
public Xoh_cfg_gallery Cfg_gallery() {return cfg_gallery;} private Xoh_cfg_gallery cfg_gallery = new Xoh_cfg_gallery();
|
||||
public Xoh_file_page Cfg_file_page() {return cfg_file_page;} private Xoh_file_page cfg_file_page = new Xoh_file_page();
|
||||
public Xow_sys_cfg Sys_cfg() {return sys_cfg;} private Xow_sys_cfg sys_cfg;
|
||||
public Xowc_parser Cfg_parser() {return cfg_parser;} private Xowc_parser cfg_parser;
|
||||
public boolean Cfg_parser_lnki_xwiki_repos_enabled() {return cfg_parser_lnki_xwiki_repos_enabled;} public Xow_wiki Cfg_parser_lnki_xwiki_repos_enabled_(boolean v) {cfg_parser_lnki_xwiki_repos_enabled = v; return this;} private boolean cfg_parser_lnki_xwiki_repos_enabled;
|
||||
public Xoi_dump_mgr Import_mgr() {return import_mgr;} private Xoi_dump_mgr import_mgr = new Xoi_dump_mgr();
|
||||
public Xow_maint_mgr Maint_mgr() {return maint_mgr;} private Xow_maint_mgr maint_mgr;
|
||||
public void Clear_for_tests() { // NOTE: these are structures that cache items for PERF; need to be cleared out for multiple test runs
|
||||
file_mgr.Meta_mgr().Clear();
|
||||
db_mgr.Load_mgr().Clear();
|
||||
}
|
||||
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl) {return GetPageByTtl(url, ttl, lang, app.Gui_mgr().Browser_win().Active_tab(), true);}
|
||||
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return GetPageByTtl(url, ttl, lang, tab, true);}
|
||||
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab, boolean parse_page) {
|
||||
if (init_needed) Init_wiki(app.User());
|
||||
Xoa_page page = data_mgr.Get_page(url, ttl, false, false); // get page from data_mgr
|
||||
if (page.Missing()) { // page doesn't exist
|
||||
if (ttl.Ns().Id_file()) {
|
||||
Xow_wiki commons_wiki = app.Wiki_mgr().Get_by_key_or_null(commons_wiki_key);
|
||||
if (commons_wiki != null
|
||||
&& !Bry_.Eq(domain_bry, commons_wiki.Domain_bry())) // if file, check commons wiki; note that !Bry_.Eq is recursion guard
|
||||
return commons_wiki.GetPageByTtl(url, ttl, this.lang, tab, true);
|
||||
}
|
||||
else
|
||||
return page.Missing_();
|
||||
}
|
||||
if (page.Missing()) return page; // NOTE: commons can return null page
|
||||
page.Tab_(tab);
|
||||
page.Lang_(lang);
|
||||
if (parse_page)
|
||||
ParsePage(page, false); // NOTE: do not clear page b/c reused for search
|
||||
return page;
|
||||
}
|
||||
public void ParsePage_root(Xoa_page page, boolean clear) {ParsePage(page, clear);}
|
||||
public void ParsePage(Xoa_page page, boolean clear) {
|
||||
if (init_needed && !Env_.Mode_testing()) Init_wiki(app.User());
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(page); // notify scribunto about page changed
|
||||
ctx.Cur_page_(page);
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw());
|
||||
if (clear) {page.Clear();}
|
||||
Xoa_ttl ttl = page.Ttl();
|
||||
if (Xow_page_tid.Identify(domain_tid, ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10
|
||||
parser.Parse_text_to_wdom(root, ctx, app.Tkn_mkr(), page.Data_raw(), Xop_parser_.Doc_bgn_bos);
|
||||
page.Root_(root);
|
||||
root.Data_htm_(root.Root_src());
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_files)) return file_mgr;
|
||||
else if (ctx.Match(k, Invk_xwikis)) return xwiki_mgr;
|
||||
else if (ctx.Match(k, Invk_stats)) return stats;
|
||||
else if (ctx.Match(k, Invk_props)) return props;
|
||||
else if (ctx.Match(k, Invk_cfg_gallery_)) return cfg_gallery;
|
||||
else if (ctx.Match(k, Invk_commons_wiki_)) commons_wiki_key = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_lang)) return lang;
|
||||
else if (ctx.Match(k, Invk_lang_)) lang = app.Lang_mgr().Get_by_key_or_new(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_html)) return html_mgr;
|
||||
else if (ctx.Match(k, Invk_gui)) return gui_mgr;
|
||||
else if (ctx.Match(k, Invk_cfg_history)) return cfg_history;
|
||||
else if (ctx.Match(k, Invk_user)) return user;
|
||||
else if (ctx.Match(k, Invk_data_mgr)) return data_mgr;
|
||||
else if (ctx.Match(k, Invk_ns_mgr)) return ns_mgr;
|
||||
else if (ctx.Match(k, Invk_sys_cfg)) return sys_cfg;
|
||||
else if (ctx.Match(k, Invk_special)) return special_mgr;
|
||||
else if (ctx.Match(k, Invk_parser)) return cfg_parser;
|
||||
else if (ctx.Match(k, Invk_msgs)) return msg_mgr;
|
||||
else if (ctx.Match(k, Invk_util)) return util;
|
||||
else if (ctx.Match(k, Invk_app)) return app;
|
||||
else if (ctx.Match(k, Invk_data_storage_format_))db_mgr.Data_storage_format_(m.ReadByte("v"));
|
||||
else if (ctx.Match(k, Invk_db_mgr)) return db_mgr;
|
||||
else if (ctx.Match(k, Invk_db_mgr_to_sql_)) this.Db_mgr_create_as_sql();
|
||||
else if (ctx.Match(k, Invk_import_mgr)) return import_mgr;
|
||||
else if (ctx.Match(k, Invk_maint)) return maint_mgr;
|
||||
else if (ctx.Match(k, Invk_domain)) return domain_str;
|
||||
else if (ctx.Match(k, Invk_xtns)) return xtn_mgr;
|
||||
else if (ctx.Match(k, Invk_hdump_enabled_)) hdump_enabled = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_ZipDirs = "zip_dirs_", Invk_files = "files", Invk_xwikis = "xwikis", Invk_cfg_gallery_ = "cfg_gallery_", Invk_commons_wiki_ = "commons_wiki_", Invk_stats = "stats"
|
||||
, Invk_lang = "lang", Invk_lang_ = "lang_", Invk_html = "html", Invk_gui = "gui", Invk_cfg_history = "cfg_history", Invk_user = "user", Invk_data_mgr = "data_mgr", Invk_sys_cfg = "sys_cfg", Invk_ns_mgr = "ns_mgr"
|
||||
, Invk_special = "special"
|
||||
, Invk_props = "props", Invk_parser = "parser"
|
||||
, Invk_msgs = "msgs", Invk_app = "app", Invk_util = "util"
|
||||
, Invk_xtns = "xtns", Invk_data_storage_format_ = "data_storage_format_", Invk_import_mgr = "import"
|
||||
, Invk_db_mgr = "db_mgr", Invk_db_mgr_to_sql_ = "db_mgr_to_sql_"
|
||||
, Invk_domain = "domain", Invk_maint = "maint", Invk_hdump_enabled_ = "hdump_enabled_"
|
||||
;
|
||||
public Xodb_mgr_sql Db_mgr_create_as_sql() {Xodb_mgr_sql rv = new Xodb_mgr_sql(this); db_mgr = rv; return rv;}
|
||||
public Xow_wiki Init_assert() {if (init_needed) Init_wiki(app.User()); return this;}
|
||||
private boolean init_in_process = false;
|
||||
private void Init_wiki(Xou_user user) { // NOTE: (a) one-time initialization for all wikis; (b) not called by tests
|
||||
if (init_in_process) {
|
||||
app.Usr_dlg().Log_many("", "", "wiki.init: circular call canceled: ~{0}", domain_str);
|
||||
return; // NOTE: may be called multiple times due to "if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false;"; TODO: call this only once; DATE:2014-06-07
|
||||
}
|
||||
init_in_process = true;
|
||||
if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false; // NOTE: only mark inited if app fully launched; otherwise statements in xowa.gfs can fire and prematurely set home to inited; DATE:2013-03-24
|
||||
Gfo_log_bfr log_bfr = app.Log_bfr();
|
||||
log_bfr.Add("wiki.init.bgn: " + domain_str);
|
||||
app.Cfg_mgr().Init(this);
|
||||
file_mgr.Cfg_download().Enabled_(app.File_mgr().Download_mgr().Enabled()); // default download to app global; can be overriden below
|
||||
Io_url sqlite_url = Xodb_mgr_sql.Find_core_url(this);
|
||||
if (sqlite_url != null) {
|
||||
Xodb_mgr_sql db_mgr_sql = this.Db_mgr_create_as_sql();
|
||||
db_mgr_sql.Init_load(gplx.dbs.Db_url_.sqlite_(sqlite_url));
|
||||
db_mgr_sql.Html_db_enabled_(hdump_enabled);
|
||||
}
|
||||
if (!Xob_import_marker.Check(this)) {app.Wiki_mgr().Del(domain_bry); init_needed = false; return;} // NOTE: must call after Db_mgr_create_as_sql(); also, must delete wiki from mgr; DATE:2014-08-24
|
||||
db_mgr.Load_mgr().Load_init(this);
|
||||
app.Gfs_mgr().Run_url_for(this, fsys_mgr.Cfg_wiki_core_fil());
|
||||
gplx.xowa.utls.upgrades.Xoa_upgrade_mgr.Check(this);
|
||||
app.Gfs_mgr().Run_url_for(this, fsys_mgr.Cfg_wiki_stats_fil());
|
||||
app.Gfs_mgr().Run_url_for(this, app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(domain_str + ".gfs")); // run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
|
||||
fsys_mgr.Scan_dirs();
|
||||
if (lang.Init_by_load()) {
|
||||
if (domain_tid == Xow_wiki_domain_.Tid_wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; PAGE:en.w:pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
|
||||
ns_mgr.Aliases_add(Xow_ns_.Id_project, Xow_ns_.Ns_name_wikipedia);
|
||||
}
|
||||
cfg_parser.Xtns().Itm_pages().Init(ns_mgr); // init ns_mgr for Page / Index ns just before rebuild; usually set by #cfg file
|
||||
Xow_ns_mgr_.rebuild_(lang, ns_mgr); // always rebuild; may be changed by user_wiki.gfs; different lang will change namespaces; EX: de.wikisource.org will have Seite for File and none of {{#lst}} will work
|
||||
fragment_mgr.Evt_lang_changed(lang);
|
||||
parser.Init_by_lang(lang);
|
||||
html_mgr.Init_by_lang(lang);
|
||||
lang.Vnt_mgr().Init_by_wiki(this);
|
||||
Bry_fmtr.Null.Eval_mgr().Enabled_(false);
|
||||
app.Wiki_mgr().Scripts().Exec(this);
|
||||
Bry_fmtr.Null.Eval_mgr().Enabled_(true);
|
||||
app.Wiki_mgr().Css_installer().Install_assert(this, user.Fsys_mgr().Wiki_html_dir(domain_str));
|
||||
html_mgr.Init_by_wiki(this);
|
||||
this.Copy_cfg(app.User().Wiki());
|
||||
File_repos_assert(app, this);
|
||||
xtn_mgr.Init_by_wiki(this);
|
||||
log_bfr.Add("wiki.init.end");
|
||||
app.Log_wtr().Log_msg_to_session_direct(log_bfr.Xto_str());
|
||||
init_in_process = false;
|
||||
}
|
||||
public void Rls() {
|
||||
if (rls_list == null) return;
|
||||
int len = rls_list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
RlsAble rls = (RlsAble)rls_list.FetchAt(i);
|
||||
rls.Rls();
|
||||
}
|
||||
}
|
||||
private void Copy_cfg(Xow_wiki wiki) {html_mgr.Copy_cfg(wiki.Html_mgr());}
|
||||
private static void File_repos_assert(Xoa_app app, Xow_wiki wiki) {
|
||||
byte[] wiki_key = wiki.Domain_bry();
|
||||
Xoa_repo_mgr repo_mgr = app.File_mgr().Repo_mgr();
|
||||
Xof_repo_itm repo_itm = repo_mgr.Get_by(wiki_key);
|
||||
if (repo_itm == null) {
|
||||
repo_itm = new Xof_repo_itm(repo_mgr, wiki_key).Wiki_key_(wiki_key);
|
||||
repo_mgr.Add(repo_itm);
|
||||
}
|
||||
Xow_repo_mgr pair_mgr = wiki.File_mgr().Repo_mgr();
|
||||
if (pair_mgr.Repos_len() == 0) {
|
||||
Xof_repo_itm repo_src = repo_mgr.Get_by(File_repo_xowa_null);
|
||||
if (repo_src == null) {
|
||||
repo_itm = new Xof_repo_itm(repo_mgr, File_repo_xowa_null).Wiki_key_(Xow_wiki_domain_.Key_home_bry);
|
||||
repo_mgr.Add(repo_itm);
|
||||
}
|
||||
pair_mgr.Add_repo(File_repo_xowa_null, wiki_key);
|
||||
}
|
||||
} static byte[] File_repo_xowa_null = Bry_.new_ascii_("xowa_repo_null");
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.repos.*;
|
||||
public interface Xow_wiki extends Xow_ttl_parser {
|
||||
byte[] Domain_bry(); // EX: en.wikipedia.org
|
||||
String Domain_str();
|
||||
int Domain_tid(); // Xow_domain_.Tid_int_wikipedia
|
||||
byte[] Domain_abrv(); // enwiki
|
||||
Xow_domain Domain_itm();
|
||||
Xow_fsys_mgr Fsys_mgr();
|
||||
Xoa_app App();
|
||||
Xol_lang Lang();
|
||||
Xow_repo_mgr File_mgr__repo_mgr();
|
||||
boolean File_mgr__version_is_1();
|
||||
}
|
||||
|
||||
@@ -1,28 +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; import gplx.*;
|
||||
public class Xow_wiki_ {
|
||||
public static final String
|
||||
Domain_commons_str = "commons.wikimedia.org"
|
||||
, Domain_enwiki_str = "en.wikipedia.org"
|
||||
;
|
||||
public static final byte[]
|
||||
Domain_commons_bry = Bry_.new_ascii_(Domain_commons_str)
|
||||
, Domain_en_wiki_bry = Bry_.new_ascii_(Domain_enwiki_str)
|
||||
;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
public class Xow_wiki_props implements GfoInvkAble {
|
||||
public byte[] SiteName() {return siteName;} public Xow_wiki_props SiteName_(byte v) {siteName = Bry_.new_ascii_(String_.UpperFirst(String_.new_ascii_(Xow_wiki_domain_.Key_by_tid(v)))); return this;} private byte[] siteName = Bry_.Empty;
|
||||
public byte[] SiteName() {return siteName;} public Xow_wiki_props SiteName_(int v) {siteName = Bry_.new_ascii_(String_.UpperFirst(String_.new_ascii_(Xow_domain_.Tid__get_bry(v)))); return this;} private byte[] siteName = Bry_.Empty;
|
||||
public byte[] ServerName() {return serverName;} public Xow_wiki_props ServerName_(byte[] v) {serverName = v; server = Bry_.Add(bry_http, v); return this;} private byte[] serverName = Bry_.new_ascii_("localhost");
|
||||
public byte[] Server() {return server;} private byte[] server = Bry_.new_ascii_("http://localhost"); static final byte[] bry_http = Bry_.new_ascii_("http://");
|
||||
public byte[] ArticlePath() {return articlePath;} public Xow_wiki_props ArticlePath_(byte[] v) {articlePath = v; return this;} private byte[] articlePath = Xoh_href_parser.Href_wiki_bry;
|
||||
@@ -34,7 +34,7 @@ public class Xow_wiki_props implements GfoInvkAble {
|
||||
public byte[] Siteinfo_misc() {return siteinfo_misc;}
|
||||
public byte[] Siteinfo_mainpage() {return siteinfo_mainpage;} private byte[] siteinfo_mainpage = Bry_.Empty;
|
||||
public DateAdp Modified_latest() {return modified_latest;} private DateAdp modified_latest;
|
||||
public void Main_page_update(Xow_wiki wiki) {
|
||||
public void Main_page_update(Xowe_wiki wiki) {
|
||||
siteinfo_mainpage = main_page; // note that main_page came from <siteinfo>; store old value for record's sake
|
||||
main_page = Xow_mainpage_finder.Find_or(wiki, siteinfo_mainpage); // get new main_page from mainpage_finder
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_wiki_stats implements GfoInvkAble {
|
||||
public Xow_wiki_stats(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public Xow_wiki_stats(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public int NumPages() {return num_pages;} public Xow_wiki_stats NumPages_(int v) {num_pages = v; return this;} private int num_pages; // in entire wiki: 28,433,596
|
||||
public int NumArticles() {return num_articles;} public Xow_wiki_stats NumArticles_(int v) {num_articles = v; return this;} private int num_articles; // in main ns: 4,074,996
|
||||
public int NumFiles() {return num_files;} public Xow_wiki_stats NumFiles_(int v) {num_files = v; return this;} private int num_files;
|
||||
|
||||
@@ -30,11 +30,11 @@ class Xow_wiki_fxt {
|
||||
}
|
||||
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt;
|
||||
public void Test_getPageByTtl(String ttl_str, String expd) {
|
||||
Xow_wiki wiki = fxt.Wiki();
|
||||
Xowe_wiki wiki = fxt.Wiki();
|
||||
byte[] ttl_bry = Bry_.new_ascii_(ttl_str);
|
||||
Xoa_url url = Xoa_url.blank_().Raw_(ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
Xoa_page actl = fxt.Wiki().GetPageByTtl(url, ttl);
|
||||
Xoae_page actl = fxt.Wiki().GetPageByTtl(url, ttl);
|
||||
if (expd == null) Tfds.Eq_true(actl.Missing());
|
||||
else Tfds.Eq(expd, String_.new_utf8_(actl.Ttl().Raw()));
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.parsers.lnkis.cfgs.*;
|
||||
public class Xowc_parser implements GfoInvkAble {
|
||||
public Xowc_parser(Xow_wiki wiki) {
|
||||
public Xowc_parser(Xowe_wiki wiki) {
|
||||
lnki_cfg = new Xoc_lnki_cfg(wiki);
|
||||
}
|
||||
public Xoc_lnki_cfg Lnki_cfg() {return lnki_cfg;} private Xoc_lnki_cfg lnki_cfg;
|
||||
|
||||
312
400_xowa/src_120_wiki/gplx/xowa/Xowe_wiki.java
Normal file
312
400_xowa/src_120_wiki/gplx/xowa/Xowe_wiki.java
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.files.exts.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.html.*; import gplx.xowa.users.history.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.*; import gplx.xowa.dbs.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.setup.maints.*; import gplx.xowa.wikis.caches.*;
|
||||
import gplx.xowa.bldrs.imports.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.tdbs.*;
|
||||
public class Xowe_wiki implements Xow_wiki, GfoInvkAble {
|
||||
private Xow_html_util util; private boolean hdump_enabled;
|
||||
public Xowe_wiki(Xoae_app app, Io_url wiki_dir, Xow_ns_mgr ns_mgr, Xol_lang lang) {
|
||||
this.app = app; this.ns_mgr = ns_mgr; this.lang = lang;
|
||||
domain_str = wiki_dir.NameOnly(); domain_bry = Bry_.new_utf8_(domain_str);
|
||||
domain_itm = Xow_domain_.parse(domain_bry);
|
||||
domain_tid = domain_itm.Domain_tid();
|
||||
domain_abrv = Xow_wiki_alias.Build_alias(Xow_domain_.parse(domain_bry));
|
||||
fsys_mgr = new Xow_fsys_mgr(wiki_dir, app.Fsys_mgr().File_dir().GenSubDir(domain_str));
|
||||
xwiki_mgr = new Xow_xwiki_mgr(this, app.Url_parser().Url_parser());
|
||||
xwiki_mgr.Add_full(domain_bry, domain_bry); // add full name to xwiki_mgr; needed for lookup in home ns; EX: [[en.wikipedia.org:Earth]]
|
||||
|
||||
tdb_fsys_mgr = new Xotdb_fsys_mgr(wiki_dir, ns_mgr);
|
||||
xwiki_domain_tid = Xwiki_tid(domain_tid);
|
||||
redirect_mgr = new Xop_redirect_mgr(this);
|
||||
data_mgr = new Xow_data_mgr(this);
|
||||
file_mgr = new Xow_file_mgr(this);
|
||||
utl_mgr = new Xow_utl_mgr(this);
|
||||
parser = Xop_parser.new_wiki_(this);
|
||||
cfg_parser = new Xowc_parser(this);
|
||||
ctx = Xop_ctx.new_(this);
|
||||
props.SiteName_(domain_tid).ServerName_(domain_bry);
|
||||
props.ContentLanguage_(lang.Key_bry());
|
||||
Pf_func_.Reg(lang.Func_regy(), lang);
|
||||
special_mgr = new Xows_mgr(this, lang);
|
||||
stats = new Xow_wiki_stats(this);
|
||||
html_mgr = new Xow_html_mgr(this);
|
||||
sys_cfg = new Xow_sys_cfg(this);
|
||||
hive_mgr = new Xob_hive_mgr(this);
|
||||
util = new Xow_html_util(this);
|
||||
cfg_wiki_core = new Xow_cfg_wiki_core(this);
|
||||
import_cfg = new Xob_import_cfg(this);
|
||||
msg_mgr = new Xow_msg_mgr(this, lang);
|
||||
eval_mgr = new Bfmtr_eval_wiki(this);
|
||||
fragment_mgr = new Xow_fragment_mgr(this);
|
||||
xtn_mgr = new Xow_xtn_mgr().Ctor_by_wiki(this);
|
||||
if (domain_tid == Xow_domain_.Tid_int_home) {
|
||||
wdata_wiki_tid = Xow_domain_.Tid_int_wikipedia;
|
||||
wdata_wiki_lang = Xol_lang_.Key_en;
|
||||
}
|
||||
else {
|
||||
wdata_wiki_tid = domain_tid;
|
||||
wdata_wiki_lang = domain_itm.Lang_orig_key(); // NOTE: must use orig_key for nowiki; "no" not "nb" DATE:2014-10-07
|
||||
}
|
||||
Wdata_wiki_abrv_();
|
||||
db_mgr = new gplx.xowa.dbs.Xodb_mgr_txt(this, data_mgr);
|
||||
maint_mgr = new Xow_maint_mgr(this);
|
||||
cache_mgr = new Xow_cache_mgr(this);
|
||||
}
|
||||
public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry;
|
||||
public String Domain_str() {return domain_str;} private final String domain_str;
|
||||
public int Domain_tid() {return domain_tid;} private final int domain_tid;
|
||||
public byte[] Domain_abrv() {return domain_abrv;} private final byte[] domain_abrv;
|
||||
public Xow_domain Domain_itm() {return domain_itm;} private final Xow_domain domain_itm;
|
||||
public Xol_lang Lang() {return lang;} private final Xol_lang lang;
|
||||
public Xow_ns_mgr Ns_mgr() {return ns_mgr;} private final Xow_ns_mgr ns_mgr;
|
||||
public Xow_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xow_fsys_mgr fsys_mgr;
|
||||
public Xoa_ttl Ttl_parse(byte[] ttl) {return Xoa_ttl.parse_(this, ttl);}
|
||||
public Xoa_ttl Ttl_parse(int ns_id, byte[] ttl) {return Xoa_ttl.parse_(this, ns_id, ttl);}
|
||||
public Xow_repo_mgr File_mgr__repo_mgr() {return file_mgr.Repo_mgr();}
|
||||
public boolean File_mgr__version_is_1() {return true;}
|
||||
public Xoa_app App() {return app;}
|
||||
|
||||
public Xow_xwiki_mgr Xwiki_mgr() {return xwiki_mgr;} private final Xow_xwiki_mgr xwiki_mgr;
|
||||
public int Xwiki_domain_tid() {return xwiki_domain_tid;} private int xwiki_domain_tid;
|
||||
public Xoae_app Appe() {return app;} private Xoae_app app;
|
||||
public Xow_utl_mgr Utl_mgr() {return utl_mgr;} private Xow_utl_mgr utl_mgr;
|
||||
public Xow_gui_mgr Gui_mgr() {return gui_mgr;} private Xow_gui_mgr gui_mgr = new Xow_gui_mgr();
|
||||
public Xow_user User() {return user;} private Xow_user user = new Xow_user();
|
||||
public Xow_data_mgr Data_mgr() {return data_mgr;} private Xow_data_mgr data_mgr;
|
||||
public Xodb_mgr Db_mgr() {return db_mgr;} private Xodb_mgr db_mgr;
|
||||
public Xodb_mgr_sql Db_mgr_as_sql() {return (Xodb_mgr_sql)db_mgr;}
|
||||
public Xows_mgr Special_mgr() {return special_mgr;} private Xows_mgr special_mgr;
|
||||
public Xow_html_mgr Html_mgr() {return html_mgr;} private Xow_html_mgr html_mgr;
|
||||
public Xow_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Xow_xtn_mgr xtn_mgr;
|
||||
public Xow_cache_mgr Cache_mgr() {return cache_mgr;} private Xow_cache_mgr cache_mgr;
|
||||
|
||||
public byte[] Commons_wiki_key() {return commons_wiki_key;} private byte[] commons_wiki_key = Xow_domain_.Domain_bry_commons;
|
||||
public Xob_hive_mgr Hive_mgr() {return hive_mgr;} private Xob_hive_mgr hive_mgr;
|
||||
public Xow_msg_mgr Msg_mgr() {return msg_mgr;} private Xow_msg_mgr msg_mgr;
|
||||
public Xow_fragment_mgr Fragment_mgr() {return fragment_mgr;} private Xow_fragment_mgr fragment_mgr;
|
||||
public Bfmtr_eval_wiki Eval_mgr() {return eval_mgr;} private Bfmtr_eval_wiki eval_mgr;
|
||||
public Bry_bfr_mkr Utl_bry_bfr_mkr() {return app.Utl_bry_bfr_mkr();}
|
||||
public byte[] Wdata_wiki_lang() {return wdata_wiki_lang;} private byte[] wdata_wiki_lang;
|
||||
public void Wdata_wiki_lang_(byte[] v) {this.wdata_wiki_lang = v; Wdata_wiki_abrv_();} // TEST:
|
||||
public byte[] Wdata_wiki_abrv() {return wdata_wiki_abrv;} private byte[] wdata_wiki_abrv; private int wdata_wiki_tid;
|
||||
private void Wdata_wiki_abrv_() {
|
||||
Bry_bfr bfr = app.Utl_bry_bfr_mkr().Get_b128();
|
||||
Xow_wiki_alias.Build_alias_by_lang_tid(bfr, wdata_wiki_lang, Int_obj_ref.new_(wdata_wiki_tid));
|
||||
wdata_wiki_abrv = bfr.Mkr_rls().Xto_bry_and_clear();
|
||||
}
|
||||
|
||||
public boolean Init_needed() {return init_needed;} public Xowe_wiki Init_needed_(boolean v) {init_needed = v; return this;} private boolean init_needed = true;
|
||||
|
||||
public Xop_parser Parser() {return parser;} private Xop_parser parser;
|
||||
public Xop_redirect_mgr Redirect_mgr() {return redirect_mgr;} private Xop_redirect_mgr redirect_mgr;
|
||||
public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx;
|
||||
public ListAdp Rls_list() {if (rls_list == null) rls_list = ListAdp_.new_(); return rls_list;} private ListAdp rls_list;
|
||||
|
||||
public Xow_file_mgr File_mgr() {return file_mgr;} private Xow_file_mgr file_mgr;
|
||||
public Xow_cfg_wiki_core Cfg_wiki_core() {return cfg_wiki_core;} private Xow_cfg_wiki_core cfg_wiki_core;
|
||||
public Xob_import_cfg Import_cfg() {return import_cfg;} private Xob_import_cfg import_cfg;
|
||||
|
||||
public Xotdb_fsys_mgr Tdb_fsys_mgr() {return tdb_fsys_mgr;} private final Xotdb_fsys_mgr tdb_fsys_mgr;
|
||||
|
||||
public Xow_wiki_stats Stats() {return stats;} private Xow_wiki_stats stats;
|
||||
public Xow_wiki_props Props() {return props;} private Xow_wiki_props props = new Xow_wiki_props();
|
||||
public Xou_history_cfg Cfg_history() {return cfg_history;} private Xou_history_cfg cfg_history = new Xou_history_cfg();
|
||||
public Xoh_cfg_gallery Cfg_gallery() {return cfg_gallery;} private Xoh_cfg_gallery cfg_gallery = new Xoh_cfg_gallery();
|
||||
public Xoh_file_page Cfg_file_page() {return cfg_file_page;} private Xoh_file_page cfg_file_page = new Xoh_file_page();
|
||||
public Xow_sys_cfg Sys_cfg() {return sys_cfg;} private Xow_sys_cfg sys_cfg;
|
||||
public Xowc_parser Cfg_parser() {return cfg_parser;} private Xowc_parser cfg_parser;
|
||||
public boolean Cfg_parser_lnki_xwiki_repos_enabled() {return cfg_parser_lnki_xwiki_repos_enabled;} public Xowe_wiki Cfg_parser_lnki_xwiki_repos_enabled_(boolean v) {cfg_parser_lnki_xwiki_repos_enabled = v; return this;} private boolean cfg_parser_lnki_xwiki_repos_enabled;
|
||||
public Xoi_dump_mgr Import_mgr() {return import_mgr;} private Xoi_dump_mgr import_mgr = new Xoi_dump_mgr();
|
||||
public Xow_maint_mgr Maint_mgr() {return maint_mgr;} private Xow_maint_mgr maint_mgr;
|
||||
public void Clear_for_tests() { // NOTE: these are structures that cache items for PERF; need to be cleared out for multiple test runs
|
||||
file_mgr.Meta_mgr().Clear();
|
||||
db_mgr.Load_mgr().Clear();
|
||||
}
|
||||
public Xoae_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl) {return GetPageByTtl(url, ttl, lang, app.Gui_mgr().Browser_win().Active_tab(), true);}
|
||||
public Xoae_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return GetPageByTtl(url, ttl, lang, tab, true);}
|
||||
public Xoae_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab, boolean parse_page) {
|
||||
if (init_needed) Init_wiki(app.User());
|
||||
Xoae_page page = data_mgr.Get_page(url, ttl, false, false); // get page from data_mgr
|
||||
if (page.Missing()) { // page doesn't exist
|
||||
if (ttl.Ns().Id_file()) {
|
||||
Xowe_wiki commons_wiki = app.Wiki_mgr().Get_by_key_or_null(commons_wiki_key);
|
||||
if (commons_wiki != null
|
||||
&& !Bry_.Eq(domain_bry, commons_wiki.Domain_bry())) // if file, check commons wiki; note that !Bry_.Eq is recursion guard
|
||||
return commons_wiki.GetPageByTtl(url, ttl, this.lang, tab, true);
|
||||
}
|
||||
else
|
||||
return page.Missing_();
|
||||
}
|
||||
if (page.Missing()) return page; // NOTE: commons can return null page
|
||||
page.Tab_(tab);
|
||||
page.Lang_(lang);
|
||||
if (parse_page)
|
||||
ParsePage(page, false); // NOTE: do not clear page b/c reused for search
|
||||
return page;
|
||||
}
|
||||
public void ParsePage_root(Xoae_page page, boolean clear) {ParsePage(page, clear);}
|
||||
public void ParsePage(Xoae_page page, boolean clear) {
|
||||
if (init_needed && !Env_.Mode_testing()) Init_wiki(app.User());
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(page); // notify scribunto about page changed
|
||||
ctx.Cur_page_(page);
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw());
|
||||
if (clear) {page.Clear();}
|
||||
Xoa_ttl ttl = page.Ttl();
|
||||
if (Xow_page_tid.Identify(domain_tid, ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10
|
||||
parser.Parse_text_to_wdom(root, ctx, app.Tkn_mkr(), page.Data_raw(), Xop_parser_.Doc_bgn_bos);
|
||||
page.Root_(root);
|
||||
root.Data_htm_(root.Root_src());
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_files)) return file_mgr;
|
||||
else if (ctx.Match(k, Invk_xwikis)) return xwiki_mgr;
|
||||
else if (ctx.Match(k, Invk_stats)) return stats;
|
||||
else if (ctx.Match(k, Invk_props)) return props;
|
||||
else if (ctx.Match(k, Invk_cfg_gallery_)) return cfg_gallery;
|
||||
else if (ctx.Match(k, Invk_commons_wiki_)) commons_wiki_key = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_lang)) return lang;
|
||||
else if (ctx.Match(k, Invk_lang_)) throw Err_.deprecated("wiki.lang_");
|
||||
else if (ctx.Match(k, Invk_html)) return html_mgr;
|
||||
else if (ctx.Match(k, Invk_gui)) return gui_mgr;
|
||||
else if (ctx.Match(k, Invk_cfg_history)) return cfg_history;
|
||||
else if (ctx.Match(k, Invk_user)) return user;
|
||||
else if (ctx.Match(k, Invk_data_mgr)) return data_mgr;
|
||||
else if (ctx.Match(k, Invk_ns_mgr)) return ns_mgr;
|
||||
else if (ctx.Match(k, Invk_sys_cfg)) return sys_cfg;
|
||||
else if (ctx.Match(k, Invk_special)) return special_mgr;
|
||||
else if (ctx.Match(k, Invk_parser)) return cfg_parser;
|
||||
else if (ctx.Match(k, Invk_msgs)) return msg_mgr;
|
||||
else if (ctx.Match(k, Invk_util)) return util;
|
||||
else if (ctx.Match(k, Invk_app)) return app;
|
||||
else if (ctx.Match(k, Invk_data_storage_format_))db_mgr.Data_storage_format_(m.ReadByte("v"));
|
||||
else if (ctx.Match(k, Invk_db_mgr)) return db_mgr;
|
||||
else if (ctx.Match(k, Invk_db_mgr_to_sql_)) this.Db_mgr_create_as_sql();
|
||||
else if (ctx.Match(k, Invk_import_mgr)) return import_mgr;
|
||||
else if (ctx.Match(k, Invk_maint)) return maint_mgr;
|
||||
else if (ctx.Match(k, Invk_domain)) return domain_str;
|
||||
else if (ctx.Match(k, Invk_xtns)) return xtn_mgr;
|
||||
else if (ctx.Match(k, Invk_hdump_enabled_)) hdump_enabled = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_ZipDirs = "zip_dirs_", Invk_files = "files", Invk_xwikis = "xwikis", Invk_cfg_gallery_ = "cfg_gallery_", Invk_commons_wiki_ = "commons_wiki_", Invk_stats = "stats"
|
||||
, Invk_lang = "lang", Invk_html = "html", Invk_gui = "gui", Invk_cfg_history = "cfg_history", Invk_user = "user", Invk_data_mgr = "data_mgr", Invk_sys_cfg = "sys_cfg", Invk_ns_mgr = "ns_mgr"
|
||||
, Invk_special = "special"
|
||||
, Invk_props = "props", Invk_parser = "parser"
|
||||
, Invk_msgs = "msgs", Invk_app = "app", Invk_util = "util"
|
||||
, Invk_xtns = "xtns", Invk_data_storage_format_ = "data_storage_format_", Invk_import_mgr = "import"
|
||||
, Invk_db_mgr = "db_mgr", Invk_db_mgr_to_sql_ = "db_mgr_to_sql_"
|
||||
, Invk_domain = "domain", Invk_maint = "maint", Invk_hdump_enabled_ = "hdump_enabled_"
|
||||
;
|
||||
public static final String Invk_lang_ = "lang_";
|
||||
public Xodb_mgr_sql Db_mgr_create_as_sql() {Xodb_mgr_sql rv = new Xodb_mgr_sql(this); db_mgr = rv; return rv;}
|
||||
public Xowe_wiki Init_assert() {if (init_needed) Init_wiki(app.User()); return this;}
|
||||
private boolean init_in_process = false;
|
||||
private void Init_wiki(Xou_user user) { // NOTE: (a) one-time initialization for all wikis; (b) not called by tests
|
||||
if (init_in_process) {
|
||||
app.Usr_dlg().Log_many("", "", "wiki.init: circular call canceled: ~{0}", domain_str);
|
||||
return; // NOTE: may be called multiple times due to "if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false;"; TODO: call this only once; DATE:2014-06-07
|
||||
}
|
||||
init_in_process = true;
|
||||
if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false; // NOTE: only mark inited if app fully launched; otherwise statements in xowa.gfs can fire and prematurely set home to inited; DATE:2013-03-24
|
||||
Gfo_log_bfr log_bfr = app.Log_bfr();
|
||||
log_bfr.Add("wiki.init.bgn: " + domain_str);
|
||||
app.Cfg_mgr().Init(this);
|
||||
file_mgr.Cfg_download().Enabled_(app.File_mgr().Wmf_mgr().Enabled()); // default download to app global; can be overriden below
|
||||
Io_url sqlite_url = Xodb_mgr_sql.Find_core_url(this);
|
||||
if (sqlite_url != null) {
|
||||
Xodb_mgr_sql db_mgr_sql = this.Db_mgr_create_as_sql();
|
||||
db_mgr_sql.Init_load(gplx.dbs.Db_url_.sqlite_(sqlite_url));
|
||||
db_mgr_sql.Html_db_enabled_(hdump_enabled);
|
||||
}
|
||||
if (!Xob_import_marker.Check(this)) {app.Wiki_mgr().Del(domain_bry); init_needed = false; return;} // NOTE: must call after Db_mgr_create_as_sql(); also, must delete wiki from mgr; DATE:2014-08-24
|
||||
db_mgr.Load_mgr().Load_init(this);
|
||||
app.Gfs_mgr().Run_url_for(this, tdb_fsys_mgr.Cfg_wiki_core_fil());
|
||||
gplx.xowa.utls.upgrades.Xoa_upgrade_mgr.Check(this);
|
||||
app.Gfs_mgr().Run_url_for(this, tdb_fsys_mgr.Cfg_wiki_stats_fil());
|
||||
app.Gfs_mgr().Run_url_for(this, app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(domain_str + ".gfs")); // run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
|
||||
tdb_fsys_mgr.Scan_dirs();
|
||||
if (lang.Init_by_load()) {
|
||||
if (domain_tid == Xow_domain_.Tid_int_wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; PAGE:en.w:pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
|
||||
ns_mgr.Aliases_add(Xow_ns_.Id_project, Xow_ns_.Ns_name_wikipedia);
|
||||
}
|
||||
cfg_parser.Xtns().Itm_pages().Init(ns_mgr); // init ns_mgr for Page / Index ns just before rebuild; usually set by #cfg file
|
||||
Xow_ns_mgr_.rebuild_(lang, ns_mgr); // always rebuild; may be changed by user_wiki.gfs; different lang will change namespaces; EX: de.wikisource.org will have Seite for File and none of {{#lst}} will work
|
||||
fragment_mgr.Evt_lang_changed(lang);
|
||||
parser.Init_by_lang(lang);
|
||||
html_mgr.Init_by_lang(lang);
|
||||
lang.Vnt_mgr().Init_by_wiki(this);
|
||||
Bry_fmtr.Null.Eval_mgr().Enabled_(false);
|
||||
app.Wiki_mgr().Scripts().Exec(this);
|
||||
Bry_fmtr.Null.Eval_mgr().Enabled_(true);
|
||||
app.Wiki_mgr().Css_installer().Install_assert(this, user.Fsys_mgr().Wiki_html_dir(domain_str));
|
||||
html_mgr.Init_by_wiki(this);
|
||||
this.Copy_cfg(app.User().Wiki());
|
||||
File_repos_assert(app, this);
|
||||
xtn_mgr.Init_by_wiki(this);
|
||||
log_bfr.Add("wiki.init.end");
|
||||
app.Log_wtr().Log_msg_to_session_direct(log_bfr.Xto_str());
|
||||
init_in_process = false;
|
||||
}
|
||||
public void Rls() {
|
||||
if (rls_list == null) return;
|
||||
int len = rls_list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
RlsAble rls = (RlsAble)rls_list.FetchAt(i);
|
||||
rls.Rls();
|
||||
}
|
||||
}
|
||||
private void Copy_cfg(Xowe_wiki wiki) {html_mgr.Copy_cfg(wiki.Html_mgr());}
|
||||
private static void File_repos_assert(Xoae_app app, Xowe_wiki wiki) {
|
||||
byte[] wiki_key = wiki.Domain_bry();
|
||||
Xoa_repo_mgr repo_mgr = app.File_mgr().Repo_mgr();
|
||||
Xof_repo_itm repo_itm = repo_mgr.Get_by(wiki_key);
|
||||
Xoa_fsys_mgr app_fsys_mgr = app.Fsys_mgr();
|
||||
Xof_rule_mgr ext_rule_mgr = app.File_mgr().Ext_rules();
|
||||
if (repo_itm == null) {
|
||||
repo_itm = new Xof_repo_itm(wiki_key, app_fsys_mgr, ext_rule_mgr).Wiki_key_(wiki_key);
|
||||
repo_mgr.Add(repo_itm);
|
||||
}
|
||||
Xowe_repo_mgr pair_mgr = wiki.File_mgr().Repo_mgr();
|
||||
if (pair_mgr.Repos_len() == 0) {
|
||||
Xof_repo_itm repo_src = repo_mgr.Get_by(File_repo_xowa_null);
|
||||
if (repo_src == null) {
|
||||
repo_itm = new Xof_repo_itm(File_repo_xowa_null, app_fsys_mgr, ext_rule_mgr).Wiki_key_(Xow_domain_.Tid_bry_home);
|
||||
repo_mgr.Add(repo_itm);
|
||||
}
|
||||
pair_mgr.Add_repo(File_repo_xowa_null, wiki_key);
|
||||
}
|
||||
} static byte[] File_repo_xowa_null = Bry_.new_ascii_("xowa_repo_null");
|
||||
private static int Xwiki_tid(int tid) {
|
||||
switch (tid) {
|
||||
case Xow_domain_.Tid_int_commons:
|
||||
case Xow_domain_.Tid_int_species:
|
||||
case Xow_domain_.Tid_int_incubator:
|
||||
case Xow_domain_.Tid_int_mediawiki:
|
||||
case Xow_domain_.Tid_int_wikimediafoundation:
|
||||
case Xow_domain_.Tid_int_home: return Xow_domain_.Tid_int_wikipedia; // set xwiki_tid to wikipedia; allows [[da:Page]] to point to da.wikipedia.org; PAGE:species:Puccinia; DATE:2014-09-14
|
||||
default: return tid;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user