1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/*
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 Bfmtr_eval_wiki implements Bry_fmtr_eval_mgr {
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);
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
}
public void Eval_mgr_(Bry_fmtr... fmtrs) {
int fmtrs_len = fmtrs.length;
for (int i = 0; i < fmtrs_len; i++)
fmtrs[i].Eval_mgr_(this);
}
}

View File

@@ -0,0 +1,65 @@
/*
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.numbers.*;
public class Xow_fragment_mgr implements GfoInvkAble {
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 = {"
, " 'bold_tip' : '~{bold_tip}',"
, " 'bold_sample' : '~{bold_sample}',"
, " 'italic_tip' : '~{italic_tip}',"
, " 'italic_sample' : '~{italic_sample}',"
, " 'link_tip' : '~{link_tip}',"
, " 'link_sample' : '~{link_sample}',"
, " 'headline_tip' : '~{headline_tip}',"
, " 'headline_sample' : '~{headline_sample}',"
, " 'ulist_tip' : '~{ulist_tip}',"
, " 'ulist_sample' : '~{ulist_sample}',"
, " 'olist_tip' : '~{olist_tip}',"
, " 'olist_sample' : '~{olist_sample}'"
, " };"
), "bold_tip", "bold_sample", "italic_tip", "italic_sample", "link_tip", "link_sample", "headline_tip", "headline_sample", "ulist_tip", "ulist_sample", "olist_tip", "olist_sample");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_html_js_edit_toolbar_fmt_)) html_js_edit_toolbar_fmtr.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_html_js_edit_toolbar)) return html_js_edit_toolbar;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
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 = Xoa_app_.Utl__bfr_mkr().Get_b512();
Xow_msg_mgr msg_mgr = wiki.Appe().Usere().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)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_italic_tip)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_italic_sample)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_link_tip)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_link_sample)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_headline_tip)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_headline_sample)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_ulist_tip)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_ulist_sample)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_olist_tip)
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_olist_sample)
);
bfr.Mkr_rls();
}
}

View File

@@ -0,0 +1,57 @@
/*
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.*;
import gplx.xowa.langs.numbers.*;
public class Xow_fragment_mgr_tst {
Xow_fragment_mgr_fxt fxt = new Xow_fragment_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Html_js_edit_toolbar_fmt() {
fxt.Test_fragment(Xow_fragment_mgr.Invk_html_js_edit_toolbar, String_.Concat_lines_nl
( " var xowa_edit_i18n = {"
, " 'bold_tip' : 'Bold text',"
, " 'bold_sample' : 'Bold text',"
, " 'italic_tip' : 'Italic text',"
, " 'italic_sample' : 'Italic text',"
, " 'link_tip' : 'Internal link',"
, " 'link_sample' : 'Link title',"
, " 'headline_tip' : 'Level 2 headline',"
, " 'headline_sample' : 'Headline text',"
, " 'ulist_tip' : 'Bulleted list',"
, " 'ulist_sample' : 'Bulleted list item',"
, " 'olist_tip' : 'Numbered list',"
, " 'olist_sample' : 'Numbered list item'"
, " };"
));
}
}
class Xow_fragment_mgr_fxt {
public void Clear() {
if (wiki == null) {
Xoae_app app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
}
} private Xowe_wiki wiki;
public Xol_lang Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_key_or_new(Bry_.new_a7(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);
byte[] actl = (byte[])GfoInvkAble_.InvkCmd(wiki.Fragment_mgr(), key);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.cfgs.gui.*;
public class Xow_gui_mgr implements GfoInvkAble {
public Xocfg_html Cfg_browser() {return cfg_browser;} private Xocfg_html cfg_browser = new Xocfg_html();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_cfg_browser)) return cfg_browser;
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_cfg_browser = "cfg_browser";
}

View File

@@ -0,0 +1,36 @@
/*
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_html_util implements GfoInvkAble {
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.Appe().Gfs_mgr().Run_str(expr);
try {return Bool_.cast_(o) ? true_val : false_val;}
catch (Exception e) {Exc_.Noop(e); return "expr failed: " + expr;}
}
String If_yn(String expr, String true_val, String false_val) {
String o = String_.as_(wiki.Appe().Gfs_mgr().Run_str(expr));
try {return Yn.parse_(o) ? true_val : false_val;}
catch (Exception e) {Exc_.Noop(e); return "expr failed: " + expr;}
}
}

View File

@@ -0,0 +1,32 @@
/*
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.msgs.*;
public class Xow_mainpage_finder {
public static byte[] Find_or(Xowe_wiki wiki, byte[] or) {
Bry_bfr tmp_bfr = wiki.Utl__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()
? or
: Xol_msg_mgr_.Get_msg_val(tmp_bfr, wiki, msg_itm, Bry_.Ary_empty)
;
tmp_bfr.Mkr_rls();
return rv;
}
public static final byte[] Msg_mainpage = Bry_.new_a7("mainpage");
}

View File

@@ -0,0 +1,73 @@
/*
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_mainpage_finder_tst {
@Before public void init() {fxt.Clear();} private Xow_mainpage_finder_fxt fxt = new Xow_mainpage_finder_fxt();
@Test public void Mediawiki() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Lang() {
fxt.Init_lang("Mainpage_by_lang");
fxt.Test_mainpage("Mainpage_by_lang");
}
@Test public void Siteinfo() {
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_siteinfo");
}
@Test public void Lang_and_siteinfo() {
fxt.Init_lang("Mainpage_by_lang");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_lang");
}
@Test public void Mediawiki_and_siteinfo() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Mediawiki_and_lang_and_siteinfo() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Init_lang("Mainpage_by_lang");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Mediawiki_tmpl() { // PURPOSE: de.wiktionary.org has "{{ns:project}}:Hauptseite"; DATE:2013-07-07
fxt.Init_mediawiki_page("{{ns:project}}:Hauptseite");
fxt.Test_mainpage("Wikipedia:Hauptseite");
}
}
class Xow_mainpage_finder_fxt {
public void Clear() {
fxt.Reset_for_msgs();
} private Xop_fxt fxt = new Xop_fxt();
public void Init_siteinfo(String mainpage_val) {
fxt.Wiki().Props().Main_page_(Bry_.new_a7(mainpage_val));
}
public void Init_mediawiki_page(String mainpage_val) {
fxt.Init_page_create(String_.new_a7(Ttl_mainpage), mainpage_val);
} private static final byte[] Ttl_mainpage = Bry_.new_a7("MediaWiki:Mainpage"); // TEST:
public void Init_lang(String mainpage_val) {
Xol_msg_itm msg_itm = fxt.Wiki().Lang().Msg_mgr().Itm_by_key_or_new(Xow_mainpage_finder.Msg_mainpage);
msg_itm.Atrs_set(Bry_.new_a7(mainpage_val), false, false);
}
public void Test_mainpage(String expd) {
byte[] actl = Xow_mainpage_finder.Find_or(fxt.Wiki(), fxt.Wiki().Props().Main_page());
Tfds.Eq(expd, String_.new_a7(actl));
}
}

View File

@@ -0,0 +1,113 @@
/*
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.html.sidebar.*; import gplx.xowa.langs.msgs.*;
public class Xow_msg_mgr implements GfoInvkAble {
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);
}
public void Clear() {msg_mgr.Clear();}
public void Lang_(Xol_lang v) {
this.lang = v;
this.Clear();
}
public byte[] Val_by_id_args(int id, Object... args) {return Val_by_id_priv(id, args);}
public byte[] Val_by_id(int id) {return Val_by_id_priv(id, null);}
private byte[] Val_by_id_priv(int id, Object[] args) {
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 = Xoa_app_.Utl__bfr_mkr().Get_b512();
byte[] rv = Val_by_itm(tmp_bfr, itm, args);
tmp_bfr.Mkr_rls();
return rv;
}
public Xol_msg_itm Get_or_make(byte[] key) {return msg_mgr.Itm_by_key_or_new(key);}
public Xol_msg_itm Get_or_null(byte[] key) {return msg_mgr.Itm_by_key_or_null(key);}
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 = Xoa_app_.Utl__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();
}
return itm;
}
public byte[] Val_by_key_args(byte[] key, Object... args) {return Val_by_key(key, args);}
public byte[] Val_by_key_obj(String key) {return Val_by_key(Bry_.new_u8(key), null);}
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 = Xoa_app_.Utl__bfr_mkr().Get_b512();
if (itm == null)
itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, lang, key);
if (itm.Src_is_missing()) {
tmp_bfr.Mkr_rls();
return Bry_.Empty;
}
byte[] rv = Val_by_itm(tmp_bfr, itm, args);
tmp_bfr.Mkr_rls();
return rv;
}
public byte[] Val_by_itm(Bry_bfr tmp_bfr, Xol_msg_itm itm, Object[] args) {
byte[] rv = itm.Val();
if (args != null) rv = itm.Fmt_tmp(tmp_bfr, rv, args);
if (itm.Has_tmpl_txt()) rv = wiki.Parser().Parse_text_to_wtxt(rv);
return rv;
}
public byte[] Val_html_accesskey_and_title(byte[] id) {
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
byte[] rv = Val_html_accesskey_and_title(id, bfr, null);
bfr.Mkr_rls();
return rv;
}
public byte[] Val_html_accesskey_and_title(byte[] id, Bry_bfr bfr, Xowh_sidebar_itm itm) {
byte[] tooltip_key = Bry_.Add(CONST_prefix_tooltip, id);
byte[] tooltip_val = Val_by_key_obj(tooltip_key);
boolean tooltip_found = Bry_.Len_gt_0(tooltip_val);
byte[] accesskey_key = Bry_.Empty, accesskey_val = Bry_.Empty;
boolean accesskey_found = false;
if (tooltip_found) {
accesskey_key = Bry_.Add(CONST_prefix_accesskey, id);
accesskey_val = Val_by_key_obj(accesskey_key);
accesskey_found = Bry_.Len_gt_0(accesskey_val);
}
if (accesskey_found)
bfr.Add(CONST_atr_accesskey).Add(accesskey_val).Add_byte(Byte_ascii.Quote);
bfr.Add(CONST_atr_title).Add(tooltip_found ? tooltip_val : Bry_.Empty); // NOTE: if tooltip not found, make blank; don't bother showing tooltip_key
if (accesskey_found)
bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Brack_bgn).Add(accesskey_val).Add_byte(Byte_ascii.Brack_end);
bfr.Add_byte(Byte_ascii.Quote);
byte[] rv = bfr.Xto_bry_and_clear();
if (itm == null)
return rv;
else {
itm.Accesskey_(accesskey_val).Title_(tooltip_val).Atr_accesskey_and_title_(rv);
return null;
}
} static final byte[] CONST_prefix_tooltip = Bry_.new_a7("tooltip-"), CONST_prefix_accesskey = Bry_.new_a7("accesskey-"), CONST_atr_title = Bry_.new_a7(" title=\""), CONST_atr_accesskey = Bry_.new_a7(" accesskey=\"");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return this.Val_by_key_obj(m.ReadBry("v"));
else if (ctx.Match(k, Invk_get_html_accesskey_and_title)) return this.Val_html_accesskey_and_title(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get", Invk_get_html_accesskey_and_title = "get_html_accesskey_and_title";
}

View File

@@ -0,0 +1,105 @@
/*
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.bldrs.cmds.*;
public class Xow_ns implements GfoInvkAble {
public Xow_ns(int id, byte case_match, byte[] name, boolean is_alias) {
this.id = id; this.case_match = case_match; this.is_alias = is_alias;
Name_bry_(name);
}
public void Name_bry_(byte[] v) {
if (id == Xow_ns_.Id_main) { // NOTE: Main will never prefix titles; EX: "Test" vs "Category:Test"
this.name_str = "";
this.name_bry = Bry_.Empty;
this.name_db_w_colon = Bry_.Empty;
}
else {
this.name_bry = v;
this.name_db_w_colon = Bry_.Add(v, Byte_ascii.Colon);
this.name_str = String_.new_u8(v);
}
this.num_str = Int_.Xto_str_pad_bgn_zero(id, 3);
this.num_bry = Bry_.new_a7(num_str);
this.name_enc = Xoa_url_encoder._.Encode(name_bry);
this.name_txt = Bry_.Replace(name_enc, Byte_ascii.Underline, Byte_ascii.Space);
this.name_txt_w_colon = Bry_.Replace(name_db_w_colon, Byte_ascii.Underline, Byte_ascii.Space);
}
public byte[] Name_bry() {return name_bry;} private byte[] name_bry;
public String Name_str() {return name_str;} private String name_str;
public byte[] Name_txt() {return name_txt;} private byte[] name_txt;
public byte[] Name_enc() {return name_enc;} private byte[] name_enc;
public byte[] Name_db_w_colon() {return name_db_w_colon;} private byte[] name_db_w_colon;
public byte[] Name_txt_w_colon() {return name_txt_w_colon;} private byte[] name_txt_w_colon; // PERF: for Xoa_ttl
public byte[] Name_ui() {return id == Xow_ns_.Id_main ? Xow_ns_.Name_ui_main : name_txt;}
public String Num_str() {return num_str;} private String num_str;
public byte[] Num_bry() {return num_bry;} private byte[] num_bry;
public int Id() {return id;} private int id;
public int Id_subj_id() {if (id < 0) return id; return Id_talk() ? id - 1 : id;} // id< 0: special/media return themself; REF.MW: Namespace.php|getSubject
public int Id_talk_id() {if (id < 0) return id; return Id_talk() ? id : id + 1;} // REF.MW: Namespace.php|getTalk
public int Id_alt_id() {if (id < 0) return id; return Id_talk() ? Id_subj_id() : Id_talk_id();} // REF.MW: Namespace.php|getTalk
public boolean Id_subj() {return !Id_talk();} // REF.MW: Namespace.php|isMain
public boolean Id_talk() {return id > Xow_ns_.Id_main && id % 2 == 1;} // REF.MW: Namespace.php|isTalk
public boolean Id_file() {return id == Xow_ns_.Id_file;}
public boolean Id_file_or_media() {return id == Xow_ns_.Id_file || id == Xow_ns_.Id_media;}
public boolean Id_tmpl() {return id == Xow_ns_.Id_template;}
public boolean Id_ctg() {return id == Xow_ns_.Id_category;}
public boolean Id_main() {return id == Xow_ns_.Id_main;}
public boolean Id_media() {return id == Xow_ns_.Id_media;}
public boolean Id_special() {return id == Xow_ns_.Id_special;}
public boolean Id_module() {return id == gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module;}
public int Ord() {return ord;} public void Ord_(int v) {this.ord = v;} private int ord;
public int Ord_subj_id() {if (id < 0) return ord; return Id_talk() ? ord - 1 : ord;} // id< 0: special/media returns self
public int Ord_talk_id() {if (id < 0) return ord; return Id_talk() ? ord : ord + 1;}
public byte Case_match() {return case_match;} public void Case_match_(byte v) {case_match = v;} private byte case_match;
public boolean Subpages_enabled() {return subpages_enabled;} private boolean subpages_enabled = false;// CHANGED: id > Xow_ns_.Id_special; only Special, Media does not have subpages; DATE:2013-10-07
public Xow_ns Subpages_enabled_(boolean v) {subpages_enabled = v; return this;}
public boolean Is_gender_aware() {return id == Xow_ns_.Id_user || id == Xow_ns_.Id_user_talk;} // ASSUME: only User, User_talk are gender aware
public boolean Is_capitalized() {return false;} // ASSUME: always false (?)
public boolean Is_content() {return id == Xow_ns_.Id_main;} // ASSUME: only Main
public boolean Is_includable() {return true;} // ASSUME: always true (be transcluded?)
public boolean Is_movable() {return id > Xow_ns_.Id_special;} // ASSUME: only Special, Media cannot move (be renamed?)
public boolean Is_meta() {return id < Xow_ns_.Id_main;} // ASSUME: only Special, Media
public boolean Is_alias() {return is_alias;} private boolean is_alias;
public int Count() {return count;} public Xow_ns Count_(int v) {count = v; return this;} private int count;
public byte[] Gen_ttl(byte[] page) {return id == Xow_ns_.Id_main ? page : Bry_.Add(name_db_w_colon, page);}
public void Aliases_add(String alias) {
if (String_.Eq(alias, name_str)) return;
if (aliases == null) aliases = Ordered_hash_.new_();
aliases.Add_if_dupe_use_1st(alias, alias);
} private Ordered_hash aliases;
public KeyVal[] Aliases_as_scrib_ary() { // NOTE: intended for Scrib_lib_site; DATE:2014-02-15
if (aliases == null) return KeyVal_.Ary_empty;
int len = aliases.Count();
KeyVal[] rv = new KeyVal[len];
for (int i = 0; i < len; i++) {
String alias = (String)aliases.Get_at(i);
rv[i] = KeyVal_.int_(i + List_adp_.Base1, alias);
}
return rv;
}
public boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists;
public Xob_ns_file_itm Bldr_data() {return bldr_data;} public void Bldr_data_(Xob_ns_file_itm v) {bldr_data = v;} private Xob_ns_file_itm bldr_data;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_subpages_enabled_)) this.subpages_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_id)) return id;
else if (ctx.Match(k, Invk_name_txt)) return name_txt;
else if (ctx.Match(k, Invk_name_ui)) return Name_ui();
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_subpages_enabled_ = "subpages_enabled_", Invk_id = "id", Invk_name_txt = "name_txt", Invk_name_ui = "name_ui";
}

View File

@@ -0,0 +1,89 @@
/*
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.*;
public class Xow_ns_ {
public static final int // PAGE:en.w:http://www.mediawiki.org/wiki/Help:Namespaces
Id_media = -2
, Id_special = -1
, Id_main = 0 , Id_talk = 1
, Id_user = 2 , Id_user_talk = 3
, Id_project = 4 , Id_project_talk = 5
, Id_file = 6 , Id_file_talk = 7
, Id_mediawiki = 8 , Id_mediaWiki_talk = 9
, Id_template = 10 , Id_template_talk = 11
, Id_help = 12 , Id_help_talk = 13
, Id_category = 14 , Id_category_talk = 15
, Id_portal = 100 , Id_portal_talk = 101
, Id_null = Int_.MinValue
;
public static final String
Key_media = "Media"
, Key_special = "Special"
, Key_main = "(Main)" , Key_talk = "Talk"
, Key_user = "User" , Key_user_talk = "User talk"
, Key_project = "Project" , Key_project_talk = "Project talk"
, Key_file = "File" , Key_file_talk = "File talk"
, Key_mediaWiki = "MediaWiki" , Key_mediaWiki_talk = "MediaWiki talk"
, Key_template = "Template" , Key_template_talk = "Template talk"
, Key_help = "Help" , Key_help_talk = "Help talk"
, Key_category = "Category" , Key_category_talk = "Category talk"
, Key_portal = "Portal" , Key_portal_talk = "Portal talk"
, Key_module = "Module" , Key_module_talk = "Module talk"
, Key_null = "null"
;
public static final byte[] Bry_template = Bry_.new_a7(Key_template);
public static final byte[] Name_ui_main = Bry_.new_a7(Key_main);
public static int Canonical_id(byte[] canonical_name) {
if (canonical_hash == null) {
Xow_ns[] ary = Canonical;
int len = ary.length;
canonical_hash = Ordered_hash_.new_bry_();
for (int i = 0; i < len; i++) {
Xow_ns ns = ary[i];
canonical_hash.Add(ns.Name_bry(), Int_obj_val.new_(ns.Id()));
}
}
Object rv_obj = canonical_hash.Get_by(canonical_name);
return rv_obj == null ? Xow_ns_.Id_null : ((Int_obj_val)rv_obj).Val();
} private static Ordered_hash canonical_hash;
public static int Canonical_idx_media = 0;
public static final Xow_ns[] Canonical = new Xow_ns[] // REF.MW: Namespace.php|$wgCanonicalNamespaceNames
{ Canonical_new_(Id_media, Key_media)
, Canonical_new_(Id_special, Key_special)
, Canonical_new_(Id_talk, Key_talk)
, Canonical_new_(Id_user, Key_user)
, Canonical_new_(Id_user_talk, Key_user_talk)
, Canonical_new_(Id_project, Key_project)
, Canonical_new_(Id_project_talk, Key_project_talk)
, Canonical_new_(Id_file, Key_file)
, Canonical_new_(Id_file_talk, Key_file_talk)
, Canonical_new_(Id_mediawiki, Key_mediaWiki)
, Canonical_new_(Id_mediaWiki_talk, Key_mediaWiki_talk)
, Canonical_new_(Id_template, Key_template)
, Canonical_new_(Id_template_talk, Key_template_talk)
, Canonical_new_(Id_help, Key_help)
, Canonical_new_(Id_help_talk, Key_help_talk)
, Canonical_new_(Id_category, Key_category)
, Canonical_new_(Id_category_talk, Key_category_talk)
};
public static final String Ns_name_wikipedia = "Wikipedia";
public static final byte[] Ns_name_main_bry = Bry_.new_a7(Key_main);
public static final byte[] Ns_prefix_main = Bry_.new_a7("Main:");
private static Xow_ns Canonical_new_(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Id_1st, Bry_.new_a7(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter;
}

View File

@@ -0,0 +1,34 @@
/*
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_ns_case_ {
public static final byte Id_all = 0, Id_1st = 1;
public static final String Key_all = "case-sensitive", Key_1st = "first-letter";
public static byte parse_(String s) {
if (String_.Eq(s, Key_1st)) return Id_1st;
else if (String_.Eq(s, Key_all)) return Id_all;
else throw Exc_.new_unhandled(s);
}
public static String To_str(byte uid) {
switch (uid) {
case Id_all: return Key_all;
case Id_1st: return Key_1st;
default: throw Exc_.new_unhandled(uid);
}
}
}

View File

@@ -0,0 +1,262 @@
/*
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.core.btries.*; import gplx.xowa.langs.cases.*;
import gplx.xowa.xtns.scribunto.*;
public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
private Ordered_hash id_hash = Ordered_hash_.new_(); // hash for retrieval by id
private Hash_adp_bry name_hash; // hash for retrieval by name; note that ns names are case-insensitive "File:" == "fILe:"
private Hash_adp_bry tmpl_hash; // hash for retrieval by name; PERF for templates
private Ordered_hash aliases = Ordered_hash_.new_(); // hash to store aliases; used to populate name_hash;
public Xow_ns_mgr(Xol_case_mgr case_mgr) {
name_hash = Hash_adp_bry.ci_utf8_(case_mgr);
tmpl_hash = Hash_adp_bry.ci_utf8_(case_mgr);
}
public Xow_ns_mgr Clear() {
name_hash.Clear();
id_hash.Clear();
tmpl_hash.Clear();
for (int i = 0; i < ords_len; i++)
ords[i] = null;
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;
public Xow_ns Ns_template() {return ns_template;} private Xow_ns ns_template;
public Xow_ns Ns_file() {return ns_file;} private Xow_ns ns_file;
public Xow_ns Ns_category() {return ns_category;} private Xow_ns ns_category;
public Xow_ns Ns_portal() {return ns_portal;} private Xow_ns ns_portal;
public Xow_ns Ns_project() {return ns_project;} private Xow_ns ns_project;
public Xow_ns Ns_module() {return ns_module;} private Xow_ns ns_module;
public Xow_ns Ns_mediawiki() {return ns_mediawiki;} private Xow_ns ns_mediawiki;
public int Ns_page_id() {return ns_page_id;} public void Ns_page_id_(int v) {ns_page_id = v;} private int ns_page_id = Int_.MinValue;
public int Count() {return ns_count;} private int ns_count = 0;
public Xow_ns[] Ords_ary() {return ords;} private Xow_ns[] ords = new Xow_ns[Xow_ns_mgr_.Ordinal_max];
public int Ords_len() {return ords_len;} private int ords_len;
public Xow_ns Ords_get_at(int ord) {return ords[ord];}
public int Ids_len() {return id_hash.Count();}
public Xow_ns Ids_get_at(int idx) {return (Xow_ns)id_hash.Get_at(idx);}
public Xow_ns Ids_get_or_null(int id) {return (Xow_ns)id_hash.Get_by(ns_hash_lkp.Val_(id));} private Int_obj_ref ns_hash_lkp = Int_obj_ref.zero_();
private Xow_ns Ids_get_or_empty(int id) {
Xow_ns rv = Ids_get_or_null(id);
return rv == null ? Ns__empty : rv;
} private static final Xow_ns Ns__empty = new Xow_ns(Int_.MaxValue, Byte_.Zero, Bry_.Empty, false);
public Xow_ns Names_get_or_null(byte[] name_bry) {return this.Names_get_or_null(name_bry, 0, name_bry.length);}
public Xow_ns Names_get_or_null(byte[] src, int bgn, int end) {
Object rv = name_hash.Get_by_mid(src, bgn, end);
return rv == null ? null : ((Xow_ns_mgr_name_itm)rv).Ns();
}
public Xow_ns Names_get_or_main(byte[] name_bry) {
Xow_ns rv = this.Names_get_or_null(name_bry, 0, name_bry.length);
return rv == null ? this.Ns_main() : rv;
}
public Object Names_get_w_colon(byte[] src, int bgn, int end) { // NOTE: get ns for a name with a ":"; EX: "Template:A" should return "Template" ns
int colon_pos = Bry_finder.Find_fwd(src, Byte_ascii.Colon, bgn, end);
if (colon_pos == Bry_.NotFound) return null; // name does not have ":"; return;
Object rv = name_hash.Get_by_mid(src, bgn, colon_pos);
return rv == null ? null : ((Xow_ns_mgr_name_itm)rv).Ns();
}
public int Tmpls_get_w_colon(byte[] src, int bgn, int end) { // NOTE: get length of template name with a ":"; EX: "Template:A" returns 10; PERF
int colon_pos = Bry_finder.Find_fwd(src, Byte_ascii.Colon, bgn, end);
if (colon_pos == Bry_.NotFound) return Bry_.NotFound;
Object o = tmpl_hash.Get_by_mid(src, bgn, colon_pos + 1); // +1 to include colon_pos
return o == null ? Bry_.NotFound : ((byte[])o).length;
}
public void Aliases_clear() {aliases.Clear();}
public Xow_ns_mgr Aliases_add(int ns_id, String name) {
KeyVal kv = KeyVal_.new_(name, Int_obj_val.new_(ns_id));
aliases.Add_if_dupe_use_nth(name, kv);
return this;
}
public Xow_ns_mgr Init() {
this.Ords_sort();
this.Rebuild_hashes();
return this;
}
public void Init_w_defaults() {
this.Add_defaults();
this.Init();
}
private void Rebuild_hashes() {
name_hash.Clear(); tmpl_hash.Clear();
for (int i = 0; i < ords_len; i++) {
Xow_ns ns = ords[i];
if (ns == null) continue; // TEST: allow gaps in ns numbers; see Talk_skip test and related
if (ns.Id() == Xow_ns_.Id_project_talk) Fix_project_talk(ns); // NOTE: handle $1 talk as per Language.php!fixVariableInNamespace; placement is important as it must go before key registration but after ord sort
Rebuild_hashes__add(name_hash, ns, ns.Name_bry());
if (ns.Id_tmpl()) tmpl_hash.Add(ns.Name_db_w_colon(), ns.Name_db_w_colon());
}
int aliases_len = aliases.Count();
for (int i = 0; i < aliases_len; i++) {
KeyVal kv = (KeyVal)aliases.Get_at(i);
int ns_id = ((Int_obj_val)kv.Val()).Val();
Xow_ns ns = Ids_get_or_null(ns_id); if (ns == null) continue; // happens when alias exists, but not ns; EX: test has Image alias, but not File alias; should not happen "live" but don't want to fail
ns.Aliases_add(kv.Key()); // register alias with official ns; EX: "Image" will be placed in "File"'s .Aliases
byte[] alias_bry = Bry_.new_u8(kv.Key());
Rebuild_hashes__add(name_hash, ns, alias_bry);
if (ns.Id_tmpl()) {
byte[] alias_name = Bry_.new_u8(kv.Key());
alias_name = Bry_.Add(alias_name, Byte_ascii.Colon);
tmpl_hash.Add_if_dupe_use_nth(alias_name, alias_name);
}
}
}
private void Fix_project_talk(Xow_ns ns) {
byte[] ns_name = ns.Name_bry();
if (Bry_finder.Find_fwd(ns.Name_bry(), Project_talk_fmt_arg)== Bry_.NotFound) return; // no $1 found; exit
Xow_ns project_ns = ords[ns.Ord_subj_id()];
if (project_ns == null) return; // should warn or throw error; for now just exit
ns.Name_bry_(Bry_.Replace(ns_name, Project_talk_fmt_arg, project_ns.Name_bry()));
} private static final byte[] Project_talk_fmt_arg = Bry_.new_a7("$1");
private void Rebuild_hashes__add(Hash_adp_bry hash, Xow_ns ns, byte[] key) {
Xow_ns_mgr_name_itm ns_itm = new Xow_ns_mgr_name_itm(key, ns);
hash.Add_if_dupe_use_nth(key, ns_itm);
if (Bry_finder.Find_fwd(key, Byte_ascii.Underline) != Bry_.NotFound) // ns has _; add another entry for space; EX: Help_talk -> Help talk
hash.Add_if_dupe_use_nth(Bry_.Replace(key, Byte_ascii.Underline, Byte_ascii.Space), ns_itm);
}
public Xow_ns_mgr Add_defaults() { // NOTE: needs to happen after File ns is added; i.e.: cannot be put in Xow_ns_mgr() {} ctor
Aliases_add(Xow_ns_.Id_file , "Image"); // REF.MW: Setup.php; add "Image", "Image talk" for backward compatibility; note that MW hardcodes Image ns as well
Aliases_add(Xow_ns_.Id_file_talk, "Image_talk");
Aliases_add(Xow_ns_.Id_project , "Project"); // always add "Project" ns (EX: Wikipedia is name for en.wikipedia.org; not sure if MW hardcodes, but it is in messages
Aliases_add(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module, "Module"); // always add "Module" ns; de.wikipedia.org has "Modul" defined in siteinfo.xml, but also uses Module
return this;
}
public Xow_ns_mgr Add_new(int nsId, String name) {return Add_new(nsId, Bry_.new_u8(name), Xow_ns_case_.Id_1st, false);} // for tst_ constructor
public Xow_ns_mgr Add_new(int ns_id, byte[] name, byte caseMatchId, boolean alias) {
Bry_.Replace_all_direct(name, Byte_ascii.Space, Byte_ascii.Underline); // standardize on _; EX: User talk -> User_talk; DATE:2013-04-21
Xow_ns ns = new Xow_ns(ns_id, caseMatchId, name, alias);
switch (ns_id) {
case Xow_ns_.Id_main: ns_main = ns; break;
case Xow_ns_.Id_template: ns_template = ns; break;
case Xow_ns_.Id_portal: ns_portal = ns; break;
case Xow_ns_.Id_project: ns_project = ns; break;
case Xow_ns_.Id_mediawiki: ns_mediawiki = ns; break;
case Scrib_xtn_mgr.Ns_id_module: ns_module = ns; break;
case Xow_ns_.Id_file: if (ns_file == null) ns_file = ns; break; // NOTE: if needed, else Image will become the official ns_file
case Xow_ns_.Id_category:
ns_category = ns;
if (category_trie == null)
category_trie = Btrie_slim_mgr.new_(ns.Case_match() == Xow_ns_case_.Id_all);
category_trie.Add_obj(ns.Name_bry(), this);
break;
}
++ns_count;
if (!id_hash.Has(ns_hash_lkp.Val_(ns_id))) // NOTE: do not add if already exists; avoids alias
id_hash.Add(Int_obj_ref.new_(ns.Id()), ns);
name_hash.Add_if_dupe_use_nth(ns.Name_bry(), new Xow_ns_mgr_name_itm(ns.Name_bry(), ns));
return this;
}
public int compare(Object lhsObj, Object rhsObj) {
Xow_ns lhs = (Xow_ns)lhsObj;
Xow_ns rhs = (Xow_ns)rhsObj;
return Int_.Compare(lhs.Id(), rhs.Id());
}
private void Ords_sort() {
int ords_cur = 0;
int ns_len = id_hash.Count();
id_hash.Sort_by(this);
// assert that all items are grouped in pairs of subj, talk; note that subj is even and talk is odd
int nxt_ns_id = Int_.MinValue;
int prv_ns_id = Int_.MinValue;
for (int i = 0; i < ns_len; i++) {
Xow_ns ns = (Xow_ns)id_hash.Get_at(i);
int ns_id = ns.Id();
if (ns_id < 0 // ignore negative ns (which don't have subj/talk pairing)
|| ns.Is_alias() // ignore alias
) continue;
if (nxt_ns_id != Int_.MinValue) { // nxt_ns_id is set
if (nxt_ns_id != ns_id) // prv was subj, but cur does not match expected talk_id; create talk for prv subj
Ords_sort_add(nxt_ns_id);
nxt_ns_id = Int_.MinValue; // always reset value
}
if (ns_id % 2 == 0) // subj
nxt_ns_id = ns_id + 1; // anticipate nxt_ns_id
else { // talk
if (prv_ns_id != ns_id - 1) // prv was not subj for cur; create subj for current talk
Ords_sort_add(ns_id - 1);
}
prv_ns_id = ns_id;
}
if (nxt_ns_id != Int_.MinValue) // handle trailing ns_id; EX: 0, 1, 2; need to make 3
Ords_sort_add(nxt_ns_id);
// sort again b/c new ns may have been added
id_hash.Sort_by(this);
ns_len = id_hash.Count();
// assign ords; assert that subj has even ordinal index
ords_len = 0;
for (int i = 0; i < ns_len; i++) {
Xow_ns ns = (Xow_ns)id_hash.Get_at(i);
int ns_id = ns.Id();
if (ns.Is_alias()) continue; // ignore alias
if (ns_id < 0) {}
else {
if (ns_id % 2 == 0) { // subj
if (ords_cur % 2 != 0) { // current ordinal is not even; skip
++ords_len;
++ords_cur;
}
}
}
ns.Ord_(ords_cur);
ords[ords_cur++] = ns;
++ords_len;
}
}
private void Ords_sort_add(int ns_id) {
this.Add_new(ns_id, Bry_.XbyInt(ns_id), Xow_ns_case_.Id_1st, false); // NOTE: name and case_match are mostly useless defaults; note that in theory this proc should not be called (all siteInfos should be well-formed) but just in case, create items now so that Get_by_ord() does not fail
}
public byte[] Bld_ttl_w_ns(Bry_bfr bfr, boolean text_form, boolean literalize, int ns_id, byte[] ttl) {
if (ns_id == Xow_ns_.Id_main) return ttl;
Xow_ns ns = Ids_get_or_null(ns_id); if (ns == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "ns_mgr:uknown ns_id; ns_id=~{0} ttl=~{1}", ns_id, ttl); return ttl;}
if (literalize) bfr.Add_byte(Byte_ascii.Colon); // NOTE: add : to literalize ns; EX: [[Category:A]] will get thrown into category list; [[:Category:A]] will print
bfr.Add(text_form ? ns.Name_txt_w_colon() : ns.Name_db_w_colon());
bfr.Add(ttl);
return bfr.Xto_bry_and_clear();
}
class Xow_ns_mgr_name_itm {
public Xow_ns_mgr_name_itm(byte[] name, Xow_ns ns) {this.name = name; this.name_len = name.length; this.ns = ns;}
public byte[] Name() {return name;} private byte[] name;
public int Name_len() {return name_len;} private int name_len;
public Xow_ns Ns() {return ns;} private Xow_ns ns;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_load)) Xow_cfg_wiki_core.Load_ns_(this, m.ReadBry("v"));
else if (ctx.Match(k, Invk_clear)) this.Clear();
else if (ctx.Match(k, Invk_add_alias_bulk)) Exec_add_alias_bulk(m.ReadBry("v"));
else if (ctx.Match(k, Invk_get_by_id_or_new)) return this.Ids_get_or_empty(m.ReadInt("v")); // NOTE: called by #cfg files for setting Subpages_enabled; if ns doesn't exist, returning empty is fine; DATE:2014-02-15
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_add_alias_bulk = "add_alias_bulk", Invk_get_by_id_or_new = "get_by_id_or_new";
public static final String Invk_load = "load", Invk_clear = "clear";
private void Exec_add_alias_bulk(byte[] raw) {
byte[][] lines = Bry_.Split(raw, Byte_ascii.Nl);
int lines_len = lines.length;
for (int i = 0; i < lines_len; i++) {
byte[] line = lines[i];
if (line.length == 0) continue;
byte[][] flds = Bry_.Split(line, Byte_ascii.Pipe);
int cur_id = Bry_.Xto_int_or(flds[0], Int_.MinValue);
this.Aliases_add(cur_id, String_.new_u8(flds[1]));
}
Ords_sort();
}
}

View File

@@ -0,0 +1,51 @@
/*
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.cases.*;
public class Xow_ns_mgr_ {
public static final int Ordinal_max = 255; // ASSUME: no more than 255 ns in a wiki; choosing 255 to align with byte (no particular reason why it needs to be a byte, but better than 500, 1000, etc)
public static Xow_ns_mgr default_(Xol_case_mgr case_mgr) { // NOTE: same as en.wikipedia.org's ns circa 2012-01 (currently omitting ns:446,447,710,711)
Xow_ns_mgr rv = new Xow_ns_mgr(case_mgr);
rv = rv.Add_new(-2, "Media").Add_new(-1, "Special").Add_new(0, "").Add_new(1, "Talk").Add_new(2, "User").Add_new(3, "User_talk").Add_new(4, "Wikipedia").Add_new(5, "Wikipedia_talk")
.Add_new(6, "File").Add_new(7, "File_talk").Add_new(8, "MediaWiki").Add_new(9, "MediaWiki_talk").Add_new(10, "Template").Add_new(11, "Template_talk")
.Add_new(12, "Help").Add_new(13, "Help_talk").Add_new(14, "Category").Add_new(15, "Category_talk").Add_new(100, "Portal").Add_new(101, "Portal_talk").Add_new(108, "Book").Add_new(109, "Book_talk")
.Add_new(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_module).Add_new(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module_talk, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_module_talk)
.Add_defaults()
;
rv.Init();
return rv;
}
public static void rebuild_(Xol_lang lang, Xow_ns_mgr ns_mgr) {
Xol_ns_grp ns_names = lang.Ns_names();
int ns_names_len = ns_names.Len();
for (int i = 0; i < ns_names_len; i++) {
Xow_ns ns_name = ns_names.Get_at(i);
int ns_id = ns_name.Id();
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id);
ns.Name_bry_(ns_name.Name_bry());
}
ns_names = lang.Ns_aliases();
ns_names_len = ns_names.Len();
for (int i = 0; i < ns_names_len; i++) {
Xow_ns ns_name = ns_names.Get_at(i);
int ns_id = ns_name.Id();
ns_mgr.Aliases_add(ns_id, ns_name.Name_str());
}
ns_mgr.Init();
}
}

View File

@@ -0,0 +1,79 @@
/*
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.*;
import gplx.xowa.langs.cases.*;
public class Xow_ns_mgr_tst {
@Before public void init() {fxt.Clear();} private Xow_ns_mgr_fxt fxt = new Xow_ns_mgr_fxt();
@Test public void Basic() {fxt.ini_ns_(-2, 0, 1).run_Ords_sort().tst_Ords(-2, -100, 0, 1);}
@Test public void Talk_skip() {fxt.ini_ns_(-2, 0, 2, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
@Test public void Subj_skip() {fxt.ini_ns_(-2, 1, 2, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
@Test public void Out_of_order() {fxt.ini_ns_(3, 1, 2, -2).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
@Test public void Skip_odd() {fxt.ini_ns_(-2, 1, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
@Test public void Skip_even() {fxt.ini_ns_(-2, 2, 4).run_Ords_sort().tst_Ords(-2, -100, 2, 3, 4, 5);}
@Test public void Ns_alias() {
fxt.Ns_mgr().Aliases_clear();
fxt.Ns_mgr().Add_new(Xow_ns_.Id_template, "Template");
fxt.Ns_mgr().Aliases_add(Xow_ns_.Id_template, "Templatex");
fxt.Ns_mgr().Init();
byte[] name = Bry_.new_a7("Templatex:Abc");
Tfds.Eq(10, fxt.Ns_mgr().Tmpls_get_w_colon(name, 0, name.length));
}
@Test public void Utf8() {// PURPOSE: handle different casings for ns_names; PAGE:ru.w:Портрет_итальянского_Ренессанса DATE:2014-07-04
Xow_ns_mgr ns_mgr = new Xow_ns_mgr(Xol_case_mgr_.Utf8());
ns_mgr.Add_new(1234, "Test");
ns_mgr.Add_new(1235, "файл");
fxt.Ns_mgr_(ns_mgr);
fxt.Test_ns_name(1234, "Test", "test", "TEST", "tesT");
fxt.Test_ns_name(1235, "файл", "Файл");
}
}
class Xow_ns_mgr_fxt {
private Xow_ns_mgr ns_mgr = new Xow_ns_mgr(Xol_case_mgr_.Ascii());
public Xow_ns_mgr Ns_mgr() {return ns_mgr;}
public void Ns_mgr_(Xow_ns_mgr v) {this.ns_mgr = v;}
public void Clear() {ns_mgr.Clear();}
public Xow_ns_mgr_fxt ini_ns_(int... ids) {
int ids_len = ids.length;
for (int i = 0; i < ids_len; i++) {
int id = ids[i];
ns_mgr.Add_new(id, Int_.Xto_str(id));
}
return this;
}
public Xow_ns_mgr_fxt run_Ords_sort() {ns_mgr.Init(); return this;}
public Xow_ns_mgr_fxt tst_Ords(int... expd) {
int actl_len = ns_mgr.Ords_len();
int[] actl = new int[actl_len];
for (int i = 0; i < actl_len; i++) {
Xow_ns ns_itm = ns_mgr.Ords_ary()[i];
actl[i] = ns_itm == null ? -100 : ns_itm.Id();
}
Tfds.Eq_ary(expd, actl);
return this;
}
public void Test_ns_name(int expd_id, String... ns_names) {
int ns_names_len = ns_names.length;
for (int i = 0; i < ns_names_len; ++i) {
String ns_name = ns_names[i];
Xow_ns actl_ns = ns_mgr.Names_get_or_null(Bry_.new_u8(ns_name));
int actl_id = actl_ns == null ? Int_.MinValue : actl_ns.Id();
Tfds.Eq(expd_id, actl_id, ns_name);
}
}
}

View File

@@ -0,0 +1,63 @@
/*
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_ns_tst {
@Before public void init() {fxt.Clear();} private Xow_ns_fxt fxt = new Xow_ns_fxt();
@Test public void Category() {
fxt .Expd_id_subjId_(Xow_ns_.Id_category)
.Expd_id_talkId_(Xow_ns_.Id_category_talk)
.Expd_id_subj_(Bool_.Y)
.Expd_id_talk_(Bool_.N)
.Test(Xow_ns_.Id_category)
;
}
@Test public void Category_talk() {
fxt .Expd_id_subjId_(Xow_ns_.Id_category)
.Expd_id_talkId_(Xow_ns_.Id_category_talk)
.Expd_id_subj_(Bool_.N)
.Expd_id_talk_(Bool_.Y)
.Test(Xow_ns_.Id_category_talk)
;
}
@Test public void Special() {
fxt .Expd_id_subjId_(Xow_ns_.Id_special)
.Expd_id_talkId_(Xow_ns_.Id_special)
.Expd_id_subj_(Bool_.Y)
.Expd_id_talk_(Bool_.N)
.Test(Xow_ns_.Id_special)
;
}
}
class Xow_ns_fxt {
public void Clear() {
expd_id_subjId = expd_id_talkId = Int_.MaxValue;
expd_id_subj = expd_id_talk = false;
}
public Xow_ns_fxt Expd_id_subjId_(int v) {expd_id_subjId = v; return this;} private int expd_id_subjId;
public Xow_ns_fxt Expd_id_talkId_(int v) {expd_id_talkId = v; return this;} private int expd_id_talkId;
public Xow_ns_fxt Expd_id_subj_(boolean v) {expd_id_subj = v; return this;} private boolean expd_id_subj;
public Xow_ns_fxt Expd_id_talk_(boolean v) {expd_id_talk = v; return this;} private boolean expd_id_talk;
public void Test(int nsId) {
Xow_ns actl = new Xow_ns(nsId, Xow_ns_case_.Id_1st, Bry_.Empty, false);
Tfds.Eq(expd_id_subjId, actl.Id_subj_id());
Tfds.Eq(expd_id_talkId, actl.Id_talk_id());
Tfds.Eq(expd_id_subj, actl.Id_subj());
Tfds.Eq(expd_id_talk, actl.Id_talk());
}
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.wikis.*;
public class Xow_script_mgr implements GfoInvkAble {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) Set(m.ReadBry("key"), m.ReadBry("wiki_type"), m.ReadBry("script"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_set = "set";
public void Exec(Xowe_wiki wiki) {
int len = hash.Count();
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
for (int i = 0; i < len; i++) {
Xow_script_itm itm = (Xow_script_itm)hash.Get_at(i);
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_type_.Get_type_as_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.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;
int[] wiki_tids = new int[len];
for (int i = 0; i < len; i++)
wiki_tids[i] = Xow_domain_type_.Get_type_as_tid(wiki_tid_names[i]);
Xow_script_itm itm = new Xow_script_itm(key, wiki_tids, script);
hash.Add_if_dupe_use_nth(itm.Key(), itm);
}
public Ordered_hash hash = Ordered_hash_.new_bry_();
}
class Xow_script_itm {
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 int[] Wiki_tids() {return wiki_tids;} private int[] wiki_tids;
public Bry_fmtr Fmtr() {return fmtr;} Bry_fmtr fmtr;
}

View File

@@ -0,0 +1,29 @@
/*
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_sys_cfg implements GfoInvkAble {
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) {
if (ctx.Match(k, Invk_xowa_cmd_enabled_)) xowa_cmd_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_xowa_cmd_enabled_)) xowa_proto_enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_xowa_cmd_enabled_ = "xowa_cmd_enabled_";
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
public class Xow_user implements GfoInvkAble {
public byte[] Name() {return name;} private byte[] name = Bry_.new_a7("anonymous");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_name_)) name = m.ReadBry("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_name_ = "name_";
}

View File

@@ -0,0 +1,40 @@
/*
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.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(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);
anchor_encode_parser.Init_by_wiki(wiki);
anchor_encode_parser.Init_by_lang(wiki.Lang());
}
return anchor_encode_parser;
} private Xop_parser anchor_encode_parser;
private static final Xop_lxr_mgr Anchor_encode_lxr_mgr
= new Xop_lxr_mgr(new Xop_lxr[]
{ Xop_pipe_lxr._, new Xop_eq_lxr(false), Xop_space_lxr._, Xop_tab_lxr._, Xop_nl_lxr._
, Xop_curly_bgn_lxr._, Xop_curly_end_lxr._
, Xop_amp_lxr._, Xop_colon_lxr._
, Xop_apos_lxr._
, Xop_lnki_lxr_bgn._, Xop_lnki_lxr_end._
, Xop_lnke_lxr._, Xop_lnke_end_lxr._
, Xop_xnde_lxr._
});
}

View File

@@ -0,0 +1,49 @@
/*
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.wikis.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.fsdb.meta.*; import gplx.fsdb.*;
import gplx.xowa.html.*; import gplx.xowa.html.wtrs.*; import gplx.xowa.html.hzips.*; import gplx.xowa.html.hdumps.*; import gplx.xowa.html.xouis.tbls.*;
public interface Xow_wiki extends Xow_ttl_parser {
boolean Type_is_edit();
Xoa_app App();
Xol_lang Lang();
byte[] Domain_bry(); // EX: en.wikipedia.org
String Domain_str();
int Domain_tid(); // Xow_domain_type_.Tid_wikipedia
byte[] Domain_abrv(); // enwiki
Xow_domain Domain_itm();
Xow_fsys_mgr Fsys_mgr();
Xowd_db_mgr Data__core_mgr();
Xof_fsdb_mode File__fsdb_mode();
Fsdb_db_mgr File__fsdb_core();
Xow_repo_mgr File__repo_mgr();
Xof_orig_mgr File__orig_mgr();
Xof_bin_mgr File__bin_mgr();
Fsm_mnt_mgr File__mnt_mgr();
boolean Html__hdump_enabled();
Xow_hzip_mgr Html__hzip_mgr();
Xohd_hdump_rdr Html__hdump_rdr();
Xoh_page_wtr_mgr_base Html__page_wtr_mgr();
Xoui_tbl_mgr Html__xoui_tbl_mgr();
boolean Html__css_installing(); void Html__css_installing_(boolean v);
Xow_xwiki_mgr Xwiki_mgr();
Xow_wiki_props Props();
void Init_by_wiki();
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.wikis.*;
import gplx.xowa.html.hrefs.*;
public class Xow_wiki_props implements GfoInvkAble {
public byte[] Main_page() {return main_page;} private byte[] main_page = Xoa_page_.Main_page_bry; // HACK: default to Main_Page b/c some code tries to do Xoa_ttl.parse_() which will not work with ""; DATE:2014-02-16
public Xow_wiki_props Main_page_(byte[] v) {main_page = v; return this;}
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
}
public byte[] Site_name() {return site_name;} private byte[] site_name = 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_a7("localhost");
public byte[] Server() {return server;} private byte[] server = Bry_.new_a7("http://localhost"); static final byte[] bry_http = Bry_.new_a7("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;
public byte[] ScriptPath() {return scriptPath;} public Xow_wiki_props ScriptPath_(byte[] v) {scriptPath = v; return this;} private byte[] scriptPath = Bry_.new_a7("/wiki");
public byte[] StylePath() {return stylePath;} public Xow_wiki_props StylePath_(byte[] v) {stylePath = v; return this;} private byte[] stylePath = Bry_.new_a7("/wiki/skins");
public byte[] ContentLanguage() {return contentLanguage;} public Xow_wiki_props ContentLanguage_(byte[] v) {contentLanguage = v; return this;} private byte[] contentLanguage = Bry_.Empty;
public byte[] DirectionMark() {return directionMark;} public Xow_wiki_props DirectionMark_(byte[] v) {directionMark = v; return this;} private byte[] directionMark = Bry_.Empty;
public byte[] Current_version() {return Current_version_const;}
public byte[] Bldr_version() {return bldr_version;} public Xow_wiki_props Bldr_version_(byte[] v) {bldr_version = v; return this;} private byte[] bldr_version = Bry_.Empty;
public int Css_version() {return css_version;} public Xow_wiki_props Css_version_(int v) {css_version = v; return this;} private int css_version = 1;
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 Xow_wiki_props SiteName_(int v) {site_name = Bry_.new_a7(String_.UpperFirst(String_.new_a7(Xow_domain_type_.Get_type_as_bry(v)))); return this;}
public Xow_wiki_props Siteinfo_misc_(byte[] v) {
siteinfo_misc = v;
int pipe_0 = Bry_finder.Find_fwd(v, Byte_ascii.Pipe);
if (pipe_0 != Bry_.NotFound)
site_name = Bry_.Mid(siteinfo_misc, 0, pipe_0);
return this;
} private byte[] siteinfo_misc = Bry_.Empty;
public void Init_by_load(gplx.dbs.cfgs.Db_cfg_tbl cfg_tbl) {
this.main_page = cfg_tbl.Select_bry_or(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, null);
if (main_page == null) {
Xoa_app_.Usr_dlg().Warn_many("", "", "mw_props.load; main_page not found; conn=~{0}", cfg_tbl.Conn().Conn_info().Xto_api());
this.main_page = Xoa_page_.Main_page_bry;
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_main_page_)) main_page = m.ReadBry("v");
else if (ctx.Match(k, Invk_bldr_version_)) bldr_version = m.ReadBry("v");
else if (ctx.Match(k, Invk_siteinfo_misc_)) Siteinfo_misc_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_siteinfo_mainpage_)) siteinfo_mainpage = m.ReadBry("v");
else if (ctx.Match(k, Invk_css_version_)) css_version = m.ReadInt("v");
else if (ctx.Match(k, Invk_modified_latest_)) modified_latest = m.ReadDate("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_main_page_ = "main_page_"
, Invk_bldr_version = "bldr_version", Invk_bldr_version_ = "bldr_version_", Invk_siteinfo_misc_ = "siteinfo_misc_", Invk_siteinfo_mainpage_ = "siteinfo_mainpage_"
, Invk_css_version_ = "css_version_"
, Invk_modified_latest_ = "modified_latest_"
;
private static final byte[] Current_version_const = Bry_.new_a7("1.21wmf11"); // approximate level of compatibility
}

View File

@@ -0,0 +1,44 @@
/*
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_stats implements GfoInvkAble {
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;
public int NumEdits() {return num_edits;} public Xow_wiki_stats NumEdits_(int v) {num_edits = v; return this;} private int num_edits;
public int NumViews() {return num_views;} public Xow_wiki_stats NumViews_(int v) {num_views = v; return this;} private int num_views;
public int NumUsers() {return num_users;} public Xow_wiki_stats NumUsers_(int v) {num_users = v; return this;} private int num_users;
public int NumUsersActive() {return num_users_active;} public Xow_wiki_stats NumUsersActive_(int v) {num_users_active = v; return this;} private int num_users_active;
public int NumAdmins() {return num_admins;} public Xow_wiki_stats NumAdmins_(int v) {num_admins = v; return this;} private int num_admins;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_number_of_pages_)) num_pages = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_articles_)) num_articles = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_files_)) num_files = m.ReadInt("v");
else if (ctx.Match(k, Invk_number_of_articles_in_ns_)) return Number_of_articles_in_ns_(m);
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Invk_number_of_pages_ = "number_of_pages_", Invk_number_of_articles_ = "number_of_articles_", Invk_number_of_files_ = "number_of_files_", Invk_number_of_articles_in_ns_ = "number_of_articles_in_ns_";
Object Number_of_articles_in_ns_(GfoMsg m) {
int ns_id = m.ReadInt("ns_id");
int count = m.ReadInt("count");
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
if (ns != null) ns.Count_(count);
return this;
}
}

View File

@@ -0,0 +1,41 @@
/*
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_wiki_tst {
@Before public void init() {fxt.Clear();} private Xow_wiki_fxt fxt = new Xow_wiki_fxt();
@Test public void Load_page_by_ttl() { // PURPOSE.fix: unknown page causes null reference error in scribunto; DATE:2013-08-27
gplx.xowa.xtns.scribunto.Scrib_core.Core_new_(fxt.Fxt().App(), fxt.Fxt().Ctx());
fxt.Test_getPageByTtl("Does_not_exist", null);
}
}
class Xow_wiki_fxt {
public void Clear() {
fxt = new Xop_fxt();
}
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt;
public void Test_getPageByTtl(String ttl_str, String expd) {
Xowe_wiki wiki = fxt.Wiki();
byte[] ttl_bry = Bry_.new_a7(ttl_str);
Xoa_url url = Xoa_url.blank_().Raw_(ttl_bry);
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
Xoae_page actl = fxt.Wiki().Load_page_by_ttl(url, ttl);
if (expd == null) Tfds.Eq_true(actl.Missing());
else Tfds.Eq(expd, String_.new_u8(actl.Ttl().Raw()));
}
}

View File

@@ -0,0 +1,36 @@
/*
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.parsers.lnkis.cfgs.*;
public class Xowc_parser implements GfoInvkAble {
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;
public Xowc_xtns Xtns() {return xtns;} private Xowc_xtns xtns = new Xowc_xtns();
public boolean Display_title_restrict() {return display_title_restrict;} public void Display_title_restrict_(boolean v) {display_title_restrict = v;} private boolean display_title_restrict = true;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_xtns)) return xtns;
else if (ctx.Match(k, Invk_lnki)) return lnki_cfg;
else if (ctx.Match(k, Invk_display_title_restrict)) return display_title_restrict;
else if (ctx.Match(k, Invk_display_title_restrict_)) display_title_restrict = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_xtns = "xtns", Invk_lnki = "lnki", Invk_display_title_restrict = "display_title_restrict", Invk_display_title_restrict_ = "display_title_restrict_";
}

View File

@@ -0,0 +1,80 @@
/*
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 Xowc_xtn_pages implements GfoInvkAble {
public boolean Init_needed() {return init_needed;} private boolean init_needed = true;
public int Ns_page_id() {return ns_page_id;} private int ns_page_id = Int_.MinValue;
public int Ns_page_talk_id() {return ns_page_talk_id;} private int ns_page_talk_id = Int_.MinValue;
public int Ns_index_id() {return ns_index_id;} private int ns_index_id = Int_.MinValue;
public int Ns_index_talk_id() {return ns_index_talk_id;} private int ns_index_talk_id = Int_.MinValue;
public void Ns_names_(byte[] page_name, byte[] page_talk_name, byte[] index_name, byte[] index_talk_name) {
this.page_name = page_name; this.page_talk_name = page_talk_name; this.index_name = index_name; this.index_talk_name = index_talk_name;
}
private byte[]
page_name = Default_ns_page_name
, page_talk_name = Default_ns_page_talk_name
, index_name = Default_ns_index_name
, index_talk_name = Default_ns_index_talk_name;
public void Reset() {
ns_page_id = ns_page_talk_id = ns_index_id = ns_index_talk_id = Int_.MinValue;
init_needed = true;
}
public void Init(Xow_ns_mgr ns_mgr) {
init_needed = false;
int len = ns_mgr.Ords_len();
for (int i = 0; i < len; i++) { // Page / Index ns_ids are variable per wiki; iterate over ns, and set ns_id
Xow_ns ns = ns_mgr.Ords_get_at(i); if (ns == null) continue;
byte[] ns_name = ns.Name_enc();
if (Bry_.Eq(ns_name, page_name)) {ns_page_id = ns.Id(); ns_mgr.Ns_page_id_(ns_page_id);}
else if (Bry_.Eq(ns_name, page_talk_name)) ns_page_talk_id = ns.Id();
else if (Bry_.Eq(ns_name, index_name)) ns_index_id = ns.Id();
else if (Bry_.Eq(ns_name, index_talk_name)) ns_index_talk_id = ns.Id();
}
int aliases_added = 0;
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_page_id , Default_ns_page_name);
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_page_talk_id , Default_ns_page_talk_name);
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_index_id , Default_ns_index_name);
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_index_talk_id , Default_ns_index_talk_name);
if (aliases_added > 0) // NOTE: will probably only be 0 for English Wikisource
ns_mgr.Init_w_defaults();
}
private int Set_canonical(Xow_ns_mgr ns_mgr, int aliases_added, int id, byte[] name) {
Xow_ns ns = ns_mgr.Ids_get_or_null(id);
if ( ns == null // ns doesn't exist; should throw error;
|| !Bry_.Eq(ns.Name_bry(), name) // ns exists, but name doesn't match canonical
) {
ns_mgr.Aliases_add(id, String_.new_a7(name));
++aliases_added;
}
return aliases_added;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_ns_names_)) Ns_names_(m.ReadBry("page"), m.ReadBry("page_talk"), m.ReadBry("index"), m.ReadBry("index_talk"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_ns_names_ = "ns_names_";
public static final byte[] Xtn_key = Bry_.new_a7("pages");
public static final int Ns_index_id_default = 102, Ns_page_id_default = 104;
private static final byte[]
Default_ns_page_name = Bry_.new_a7("Page")
, Default_ns_page_talk_name = Bry_.new_a7("Page_talk")
, Default_ns_index_name = Bry_.new_a7("Index")
, Default_ns_index_talk_name = Bry_.new_a7("Index_talk")
;
}

View File

@@ -0,0 +1,65 @@
/*
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.*; import gplx.xowa.wikis.*;
public class Xowc_xtn_pages_tst {
@Before public void init() {fxt.Clear();} private Xowc_xtn_pages_fxt fxt = new Xowc_xtn_pages_fxt();
@Test public void Init() {
fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by <siteinfo>
fxt.Init_names("Foreign_page", "Foreign_page_talk", "Foreign_index", "Foreign_index_talk"); // ns set by .gfs files in /user/wiki/#cfg
fxt.Exec_init();
fxt.Test_ns_ids(200, 201, 202, 203);
fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk");
}
}
class Xowc_xtn_pages_fxt {
private Xow_ns_mgr ns_mgr;
private Xowc_xtn_pages cfg_pages;
public void Clear() {
ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.Ascii());
cfg_pages = new Xowc_xtn_pages();
}
public Xowc_xtn_pages_fxt Init_ns(int id, String name) {
ns_mgr.Add_new(id, name);
return this;
}
public void Init_names(String page_name, String page_talk_name, String index_name, String index_talk_name) {
cfg_pages.Ns_names_(Bry_.new_a7(page_name), Bry_.new_a7(page_talk_name), Bry_.new_a7(index_name), Bry_.new_a7(index_talk_name));
}
public void Exec_init() {
ns_mgr.Init_w_defaults(); // init ns_msg
cfg_pages.Init(ns_mgr); // init cfg
}
public void Test_ns_ids(int page_id, int page_talk_id, int index_id, int index_talk_id) {
Tfds.Eq(page_id , cfg_pages.Ns_page_id());
Tfds.Eq(page_talk_id , cfg_pages.Ns_page_talk_id());
Tfds.Eq(index_id , cfg_pages.Ns_index_id());
Tfds.Eq(index_talk_id , cfg_pages.Ns_index_talk_id());
}
public void Test_ns_canonical(String page_name, String page_talk_name, String index_name, String index_talk_name) {
Test_ns_canonical_itm(page_name , cfg_pages.Ns_page_id());
Test_ns_canonical_itm(page_talk_name , cfg_pages.Ns_page_talk_id());
Test_ns_canonical_itm(index_name , cfg_pages.Ns_index_id());
Test_ns_canonical_itm(index_talk_name , cfg_pages.Ns_index_talk_id());
}
private void Test_ns_canonical_itm(String name, int expd_ns_id) {
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_a7(name));
int actl_ns_id = ns == null ? Int_.MinValue : ns.Id();
Tfds.Eq(expd_ns_id, actl_ns_id);
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
public class Xowc_xtns implements GfoInvkAble {
private Hash_adp_bry hash = Hash_adp_bry.ci_ascii_();
public Xowc_xtns() {hash.Add(Xowc_xtn_pages.Xtn_key, itm_pages);}
public Xowc_xtn_pages Itm_pages() {return itm_pages;} private Xowc_xtn_pages itm_pages = new Xowc_xtn_pages();
public Object Get_by_key(byte[] key) {return hash.Get_by_bry(key);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return (GfoInvkAble)hash.Get_by_bry(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get";
}

View File

@@ -0,0 +1,336 @@
/*
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.fsdb.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.fsdb.meta.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.html.wtrs.*; import gplx.xowa.html.hzips.*; import gplx.xowa.html.hdumps.*; import gplx.xowa.html.css.*; import gplx.xowa.html.ns_files.*; import gplx.xowa.html.xouis.tbls.*;
import gplx.xowa.setup.maints.*; import gplx.xowa.wikis.caches.*;
import gplx.xowa.bldrs.xmls.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.tdbs.*;
public class Xowe_wiki implements Xow_wiki, GfoInvkAble {
public Xowe_wiki(Xoae_app app, Xol_lang lang, Xow_ns_mgr ns_mgr, Xow_domain domain_itm, Io_url wiki_dir) {
this.app = app; this.lang = lang; this.ns_mgr = ns_mgr;
this.domain_itm = domain_itm; this.domain_str = domain_itm.Domain_str(); this.domain_bry = domain_itm.Domain_bry(); this.domain_tid = domain_itm.Domain_tid(); this.domain_abrv = Xow_wiki_alias.Build_alias(domain_itm);
fsys_mgr = new Xow_fsys_mgr(wiki_dir, app.Fsys_mgr().File_dir().GenSubDir(domain_str));
xwiki_mgr = new Xow_xwiki_mgr(this, app.Utl__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]]
this.html_mgr = new Xow_html_mgr(this);
this.html_mgr__hdump_rdr = new Xohd_hdump_rdr(app, this);
this.html_mgr__hdump_wtr = new Xohd_hdump_wtr(app, this);
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);
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_type_.Tid_home) {
wdata_wiki_tid = Xow_domain_type_.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);
maint_mgr = new Xow_maint_mgr(this);
cache_mgr = new Xow_cache_mgr(this);
}
public Xow_ns_mgr Ns_mgr() {return ns_mgr;} private final Xow_ns_mgr ns_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 boolean Type_is_edit() {return Bool_.Y;}
public Xoa_app App() {return app;}
public Xol_lang Lang() {return lang;} private final Xol_lang lang;
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 Xow_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xow_fsys_mgr fsys_mgr;
public Xowd_db_mgr Data__core_mgr() {return db_mgr.Tid() == Xodb_mgr_txt.Tid_txt ? null : this.Db_mgr_as_sql().Core_data_mgr();} // TEST:
public Xof_fsdb_mode File__fsdb_mode() {return file_mgr.Fsdb_mode();}
public Fsdb_db_mgr File__fsdb_core() {return file_mgr.Db_core();}
public Xow_repo_mgr File__repo_mgr() {return file_mgr.Repo_mgr();}
public Xof_orig_mgr File__orig_mgr() {return file_mgr.Orig_mgr();}
public Xof_bin_mgr File__bin_mgr() {return file_mgr.Fsdb_mgr().Bin_mgr();}
public Fsm_mnt_mgr File__mnt_mgr() {return file_mgr.Fsdb_mgr().Mnt_mgr();}
public boolean Html__hdump_enabled() {return html_mgr__hdump_enabled;} private boolean html_mgr__hdump_enabled = Bool_.N;
public Xow_hzip_mgr Html__hzip_mgr() {return html_mgr.Hzip_mgr();}
public Xohd_hdump_rdr Html__hdump_rdr() {return html_mgr__hdump_rdr;} private final Xohd_hdump_rdr html_mgr__hdump_rdr;
public Xoh_page_wtr_mgr_base Html__page_wtr_mgr() {return html_mgr.Page_wtr_mgr();}
public Xoui_tbl_mgr Html__xoui_tbl_mgr() {return html__xoui_tbl_mgr;} private final Xoui_tbl_mgr html__xoui_tbl_mgr = new Xoui_tbl_mgr();
public boolean Html__css_installing() {return html__css_installing;} public void Html__css_installing_(boolean v) {html__css_installing = v;} private boolean html__css_installing;
public Xow_xwiki_mgr Xwiki_mgr() {return xwiki_mgr;} private final Xow_xwiki_mgr xwiki_mgr;
public Xow_wiki_props Props() {return props;} private final Xow_wiki_props props = new Xow_wiki_props();
public Xohd_hdump_wtr Html__hdump_wtr() {return html_mgr__hdump_wtr;} private final Xohd_hdump_wtr html_mgr__hdump_wtr;
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 Xow_page_mgr Page_mgr() {return page_mgr;} private Xow_page_mgr page_mgr = new Xow_page_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__bfr_mkr() {return app.Utl__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__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.To_bry_and_rls();
}
private Xow_html_util util;
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 List_adp Rls_list() {if (rls_list == null) rls_list = List_adp_.new_(); return rls_list;} private List_adp 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 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_wtr Cfg_file_page() {return cfg_file_page;} private Xoh_file_page_wtr cfg_file_page = new Xoh_file_page_wtr();
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 Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl) {return Load_page_by_ttl(url, ttl, lang, app.Gui_mgr().Browser_win().Active_tab(), true);}
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return Load_page_by_ttl(url, ttl, lang, tab, true);}
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab, boolean parse_page) {
if (init_needed) Init_wiki(app.Usere());
Xoae_page page = Xoae_page.new_(this, ttl); page.Tab_data().Tab_(tab);
data_mgr.Get_page(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) { // commons exists
if (!Bry_.Eq(domain_bry, commons_wiki.Domain_bry())) { // !Bry_.Eq is recursion guard
Xoae_page rv = commons_wiki.Load_page_by_ttl(url, ttl, this.lang, tab, true);
if (rv.Exists()) {
rv.Commons_mgr().Source_wiki_(this);
return rv;
}
else {
page.Missing_(false);
page.Commons_mgr().Xowa_mockup_(true);
return page;
}
}
}
}
else
return page.Missing_();
}
if (page.Missing()) return page; // NOTE: commons can return null page
page.Tab_data().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.Usere());
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 Xodb_mgr_sql Db_mgr_create_as_sql() {Xodb_mgr_sql rv = new Xodb_mgr_sql(this); db_mgr = rv; return rv;}
public void Init_by_wiki() {Init_assert();}
public Xowe_wiki Init_assert() {if (init_needed) Init_wiki(app.Usere()); return this;}
private boolean init_in_process = false;
public void Init_db_mgr() {
Io_url core_db_url = gplx.xowa.wikis.Xow_fsys_mgr.Find_core_fil(this);
if (core_db_url == null) {
tdb_fsys_mgr.Scan_dirs();
}
else {
Xodb_mgr_sql db_mgr_sql = this.Db_mgr_create_as_sql();
db_mgr_sql.Core_data_mgr().Init_by_load(core_db_url);
file_mgr.Init_file_mgr_by_load(this);
}
}
private void Init_wiki(Xoue_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
app.Gfs_mgr().Run_url_for(this, tdb_fsys_mgr.Cfg_wiki_stats_fil());
Init_db_mgr();
if (!app.Bldr().Import_marker().Chk(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);
// init ns_mgr
if (lang.Init_by_load()) {
if (domain_tid == Xow_domain_type_.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);
}
app.Gfs_mgr().Run_url_for(this, app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(domain_str + ".gfs")); // NOTE: must be run after lang.Init_by_load b/c lang will reload ns_mgr; DATE:2015-04-17run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
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
// push lang changes
fragment_mgr.Evt_lang_changed(lang);
parser.Init_by_lang(lang);
html_mgr.Init_by_lang(lang);
lang.Vnt_mgr().Init_by_wiki(this);
// other init
Bry_fmtr.Null.Eval_mgr().Enabled_(false); app.Wiki_mgr().Scripts().Exec(this); Bry_fmtr.Null.Eval_mgr().Enabled_(true);
app.Html__css_installer().Install(this, Xowd_css_core_mgr.Key_default);
Html__hdump_enabled_(html_mgr__hdump_enabled);
html_mgr.Init_by_wiki(this);
this.Copy_cfg(app.Usere().Wiki());
Xow_repo_mgr_.Assert_repos(app, this);
xtn_mgr.Init_by_wiki(this);
log_bfr.Add("wiki.init.end");
app.Log_wtr().Log_to_session_direct(log_bfr.Xto_str());
init_in_process = false;
}
private void Html__hdump_enabled_(boolean v) {
this.html_mgr__hdump_enabled = v;
if (html_mgr__hdump_enabled) {
Xowd_html_tbl.Assert_col__page_html_db_id(Db_mgr_as_sql().Core_data_mgr()); // NOTE: must go above html_mgr.Init_by_wiki b/c Page_load will be done via messages
html_mgr__hdump_rdr.Init_by_db(this.Data__core_mgr());
html_mgr__hdump_wtr.Init_by_db(this.Data__core_mgr());
}
}
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.Get_at(i);
rls.Rls();
}
}
private void Copy_cfg(Xowe_wiki wiki) {html_mgr.Copy_cfg(wiki.Html_mgr());}
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 Exc_.new_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_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_)) this.html_mgr__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_import_mgr = "import"
, Invk_db_mgr_to_sql_ = "db_mgr_to_sql_"
, Invk_domain = "domain", Invk_maint = "maint", Invk_hdump_enabled_ = "hdump_enabled_"
;
public static final String // SERIALIZED
Invk_db_mgr = "db_mgr" // SERIALIZED:000.sqlite3|xowa_cfg
;
public static final String Invk_lang_ = "lang_";
private static int Xwiki_tid(int tid) {
switch (tid) {
case Xow_domain_type_.Tid_commons:
case Xow_domain_type_.Tid_species:
case Xow_domain_type_.Tid_incubator:
case Xow_domain_type_.Tid_mediawiki:
case Xow_domain_type_.Tid_wmfblog:
case Xow_domain_type_.Tid_home: return Xow_domain_type_.Tid_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;
}
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.xowa.apis.xowa.bldrs.imports.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
public class Xowe_wiki_bldr {
public static void Create(Xowe_wiki wiki, long src_fil_len, String src_fil_name) {
wiki.Db_mgr_create_as_sql(); // create db_mgr as sql
Xoapi_import import_api = wiki.Appe().Api_root().Bldr().Wiki().Import();
Xowd_core_db_props db_mgr_props = import_api.New_props(wiki.Domain_str(), src_fil_len);
Xob_info_session info_session = Xob_info_session.new_(import_api.User_name(), wiki.Domain_str(), src_fil_name);
wiki.Db_mgr_as_sql().Core_data_mgr().Init_by_make(db_mgr_props, info_session); // make core_db
}
}