mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.6.5.1
This commit is contained in:
26
400_xowa/src_120_wiki/gplx/xowa/Bfmtr_eval_wiki.java
Normal file
26
400_xowa/src_120_wiki/gplx/xowa/Bfmtr_eval_wiki.java
Normal 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 Bfmtr_eval_wiki implements Bry_fmtr_eval_mgr {
|
||||
public Bfmtr_eval_wiki(Xow_wiki wiki) {this.wiki = wiki;} private Xow_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_utf8_(Object_.XtoStr_OrNullStr(rslt));
|
||||
}
|
||||
}
|
||||
33
400_xowa/src_120_wiki/gplx/xowa/Xow_dir_info.java
Normal file
33
400_xowa/src_120_wiki/gplx/xowa/Xow_dir_info.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_dir_info {
|
||||
public Xow_dir_info(boolean ns_root, byte id, String name) {this.ns_root = ns_root; this.id = id; this.name = name;}
|
||||
public byte Id() {return id;} private byte id;
|
||||
public String Name() {return name;} private String name;
|
||||
public boolean Ns_root() {return ns_root;} private boolean ns_root;
|
||||
public String Ext() {return ext_str;} private String ext_str = Xow_fsys_mgr.Wtr_xdat_str;
|
||||
public byte[] Ext_bry() {return ext_bry;} private byte[] ext_bry = Xow_fsys_mgr.Wtr_xdat_bry;
|
||||
public byte Ext_tid() {return ext_tid;}
|
||||
public Xow_dir_info Ext_tid_(byte v) {
|
||||
ext_tid = v;
|
||||
ext_bry = Xow_fsys_mgr.Wtr_ext(v);
|
||||
ext_str = String_.new_ascii_(ext_bry);
|
||||
return this;
|
||||
} byte ext_tid = gplx.ios.Io_stream_.Tid_file;
|
||||
}
|
||||
59
400_xowa/src_120_wiki/gplx/xowa/Xow_dir_info_.java
Normal file
59
400_xowa/src_120_wiki/gplx/xowa/Xow_dir_info_.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_dir_info_ {
|
||||
public static String Tid_name(byte tid) {
|
||||
switch (tid) {
|
||||
case Xow_dir_info_.Tid_page: return Xow_dir_info_.Name_page;
|
||||
case Xow_dir_info_.Tid_ttl: return Xow_dir_info_.Name_title;
|
||||
case Xow_dir_info_.Tid_id: return Xow_dir_info_.Name_id;
|
||||
case Xow_dir_info_.Tid_category: return Xow_dir_info_.Name_category;
|
||||
case Xow_dir_info_.Tid_category2_link: return Xow_dir_info_.Name_category2_link;
|
||||
case Xow_dir_info_.Tid_category2_main: return Xow_dir_info_.Name_category2_main;
|
||||
case Xow_dir_info_.Tid_search_ttl: return Xow_dir_info_.Name_search_ttl;
|
||||
default: throw Err_.unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static Xow_dir_info[] regy_() {
|
||||
Xow_dir_info[] rv = new Xow_dir_info[5];
|
||||
regy_itm_(rv, Bool_.Y, Tid_page);
|
||||
regy_itm_(rv, Bool_.Y, Tid_ttl);
|
||||
regy_itm_(rv, Bool_.N, Tid_id);
|
||||
regy_itm_(rv, Bool_.N, Tid_category);
|
||||
regy_itm_(rv, Bool_.N, Tid_search_ttl);
|
||||
return rv;
|
||||
}
|
||||
private static void regy_itm_(Xow_dir_info[] rv, boolean ns_root, byte id) {rv[id] = new Xow_dir_info(ns_root, id, Tid_name(id));}
|
||||
public static final String Ext_xdat = ".xdat", Ext_csv = ".csv", Ext_zip = ".zip"
|
||||
, Name_ns = "ns", Name_site = "site", Name_page = "page", Name_title = "title", Name_id = "id", Name_category = "category", Name_search_ttl = "search_title", Name_zip_suffix = "_zip"
|
||||
, Name_cfg = "cfg"
|
||||
, Name_reg_fil = "reg.csv", Name_category2 = "category2", Name_category2_link = "link", Name_category2_main = "main"
|
||||
;
|
||||
public static final byte[] Bry_xdat = Bry_.new_ascii_(Ext_xdat), Bry_csv = Bry_.new_ascii_(Ext_csv), Bry_zip = Bry_.new_ascii_(Ext_zip);
|
||||
public static final byte
|
||||
Tid_page = 0
|
||||
, Tid_ttl = 1
|
||||
, Tid_id = 2
|
||||
, Tid_category = 3
|
||||
, Tid_search_ttl = 4
|
||||
// , Tid_category2 = 5
|
||||
, Tid_category2_link = 5
|
||||
, Tid_category2_main = 6
|
||||
;
|
||||
public static final byte Regy_tid_max = 7;
|
||||
}
|
||||
119
400_xowa/src_120_wiki/gplx/xowa/Xow_fragment_mgr.java
Normal file
119
400_xowa/src_120_wiki/gplx/xowa/Xow_fragment_mgr.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
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 {
|
||||
private static final byte[] Date_format_default = Bry_.new_ascii_("dmy");
|
||||
private static final byte[] Num_format_digits = Bry_.new_ascii_("['', '']");
|
||||
public byte[] Html_js_table() {return html_js_table;} private byte[] html_js_table;
|
||||
public Xow_fragment_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
private Bry_fmtr html_js_table_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( " var xowa_global_values = {"
|
||||
, " 'collapsible-collapse' : '~{collapsible-collapse}',"
|
||||
, " 'collapsible-expand' : '~{collapsible-expand}',"
|
||||
, " 'sort-descending' : '~{sort-descending}',"
|
||||
, " 'sort-ascending' : '~{sort-ascending}',"
|
||||
, " 'wgContentLanguage' : '~{wgContentLanguage}',"
|
||||
, " 'wgSeparatorTransformTable' : ~{wgSeparatorTransformTable},"
|
||||
, " 'wgDigitTransformTable' : ~{wgDigitTransformTable},"
|
||||
, " 'wgDefaultDateFormat' : '~{wgDefaultDateFormat}',"
|
||||
, " 'wgMonthNames' : ~{wgMonthNames},"
|
||||
, " 'wgMonthNamesShort' : ~{wgMonthNamesShort},"
|
||||
, " };"
|
||||
), "collapsible-collapse", "collapsible-expand", "sort-descending", "sort-ascending", "wgContentLanguage", "wgSeparatorTransformTable", "wgDigitTransformTable", "wgDefaultDateFormat", "wgMonthNames", "wgMonthNamesShort");
|
||||
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_table_fmt_)) html_js_table_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_html_js_table)) return html_js_table;
|
||||
else 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_table_fmt_ = "html_js_table_fmt_", Invk_html_js_table = "html_js_table", Invk_html_js_edit_toolbar_fmt_ = "html_js_edit_toolbar_fmt_", Invk_html_js_edit_toolbar = "html_js_edit_toolbar";
|
||||
public void Evt_lang_changed(Xol_lang lang) {
|
||||
Bry_bfr bfr = lang.App().Utl_bry_bfr_mkr().Get_b512();
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
byte[] months_long = Html_js_table_months(bfr, msg_mgr, Xol_msg_itm_.Id_dte_month_name_january, Xol_msg_itm_.Id_dte_month_name_december);
|
||||
byte[] months_short = Html_js_table_months(bfr, msg_mgr, Xol_msg_itm_.Id_dte_month_abrv_jan, Xol_msg_itm_.Id_dte_month_abrv_dec);
|
||||
byte[] num_format_separators = Html_js_table_num_format_separators(bfr, lang.Num_mgr().Separators_mgr());
|
||||
html_js_table = html_js_table_fmtr.Bld_bry_many(bfr
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_collapsible_collapse)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_collapsible_expand)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_sort_descending)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_js_tables_sort_ascending)
|
||||
, lang.Key_bry()
|
||||
, num_format_separators
|
||||
, Num_format_digits
|
||||
, Date_format_default
|
||||
, months_long
|
||||
, months_short
|
||||
);
|
||||
msg_mgr = wiki.App().User().Msg_mgr();
|
||||
html_js_edit_toolbar = html_js_edit_toolbar_fmtr.Bld_bry_many(bfr
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_sample)
|
||||
, 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();
|
||||
}
|
||||
byte[] Html_js_table_months(Bry_bfr bfr, Xow_msg_mgr msg_mgr, int january_id, int december_id) {
|
||||
// ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Apos);
|
||||
for (int i = january_id; i <= december_id; i++) {
|
||||
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Apos);
|
||||
bfr.Add(msg_mgr.Val_by_id(i));
|
||||
bfr.Add_byte(Byte_ascii.Apos);
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Brack_end);
|
||||
return bfr.XtoAryAndClear();
|
||||
}
|
||||
private byte[] Html_js_table_num_format_separators(Bry_bfr bfr, Xol_transform_mgr separator_mgr) {
|
||||
byte[] dec_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__dec);
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn) .Add_byte(Byte_ascii.Apos).Add(dec_spr).Add_byte(Byte_ascii.Tab).Add_byte(Byte_ascii.Dot).Add_byte(Byte_ascii.Apos);
|
||||
byte[] grp_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__grp);
|
||||
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space) .Add_byte(Byte_ascii.Apos).Add(grp_spr).Add_byte(Byte_ascii.Tab).Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Apos);
|
||||
bfr.Add_byte(Byte_ascii.Brack_end);
|
||||
return bfr.XtoAryAndClear();
|
||||
}
|
||||
}
|
||||
93
400_xowa/src_120_wiki/gplx/xowa/Xow_fragment_mgr_tst.java
Normal file
93
400_xowa/src_120_wiki/gplx/xowa/Xow_fragment_mgr_tst.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
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_table_fmt() {
|
||||
fxt.Test_fragment(Xow_fragment_mgr.Invk_html_js_table, String_.Concat_lines_nl
|
||||
( " var xowa_global_values = {"
|
||||
, " 'collapsible-collapse' : 'Collapse',"
|
||||
, " 'collapsible-expand' : 'Expand',"
|
||||
, " 'sort-descending' : 'Sort descending',"
|
||||
, " 'sort-ascending' : 'Sort ascending',"
|
||||
, " 'wgContentLanguage' : 'en',"
|
||||
, " 'wgSeparatorTransformTable' : ['.\t.', ',\t,'],"
|
||||
, " 'wgDigitTransformTable' : ['', ''],"
|
||||
, " 'wgDefaultDateFormat' : 'dmy',"
|
||||
, " 'wgMonthNames' : ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
|
||||
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
|
||||
, " };"
|
||||
));
|
||||
}
|
||||
@Test public void Html_js_table_fmt_la() { // PURPOSE: la.gfs only specifies "," not "."; make sure both "." and "," show up, or else null ref error during import; DATE:2014-05-13
|
||||
Xol_lang la_lang = fxt.Make_lang("la");
|
||||
Xol_transform_mgr separators_mgr = la_lang.Num_mgr().Separators_mgr();
|
||||
separators_mgr.Clear();
|
||||
separators_mgr.Set(Xol_num_mgr.Separators_key__grp, Bry_.new_ascii_(" "));
|
||||
fxt.Test_fragment(la_lang, Xow_fragment_mgr.Invk_html_js_table, String_.Concat_lines_nl
|
||||
( " var xowa_global_values = {"
|
||||
, " 'collapsible-collapse' : 'Collapse',"
|
||||
, " 'collapsible-expand' : 'Expand',"
|
||||
, " 'sort-descending' : 'Sort descending',"
|
||||
, " 'sort-ascending' : 'Sort ascending',"
|
||||
, " 'wgContentLanguage' : 'la',"
|
||||
, " 'wgSeparatorTransformTable' : ['.\t.', ' \t,'],"
|
||||
, " 'wgDigitTransformTable' : ['', ''],"
|
||||
, " 'wgDefaultDateFormat' : 'dmy',"
|
||||
, " 'wgMonthNames' : ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
|
||||
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
|
||||
, " };"
|
||||
));
|
||||
}
|
||||
@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) {
|
||||
Xoa_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
} private Xow_wiki wiki;
|
||||
public Xol_lang Make_lang(String key) {return wiki.App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_(key));}
|
||||
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_utf8_(actl));
|
||||
}
|
||||
}
|
||||
115
400_xowa/src_120_wiki/gplx/xowa/Xow_fsys_mgr.java
Normal file
115
400_xowa/src_120_wiki/gplx/xowa/Xow_fsys_mgr.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_fsys_mgr {
|
||||
public Xow_fsys_mgr(Xow_wiki wiki, Io_url root_dir) {
|
||||
this.wiki = wiki; this.root_dir = root_dir;
|
||||
ns_dir = root_dir.GenSubDir(Xow_dir_info_.Name_ns);
|
||||
site_dir = root_dir.GenSubDir(Xow_dir_info_.Name_site);
|
||||
tmp_dir = root_dir.GenSubDir("tmp");
|
||||
} private Xow_wiki wiki;
|
||||
public Io_url Root_dir() {return root_dir;} Io_url root_dir;
|
||||
public Io_url Ns_dir() {return ns_dir;} Io_url ns_dir;
|
||||
public Io_url Site_dir() {return site_dir;} Io_url site_dir;
|
||||
public Io_url File_dir() {return wiki.App().Fsys_mgr().File_dir().GenSubDir_nest(wiki.Domain_str());}
|
||||
public Io_url Tmp_dir() {return tmp_dir;} public void Tmp_dir_(Io_url v) {tmp_dir = v;} Io_url tmp_dir;
|
||||
public Io_url Cfg_wiki_core_fil() {return root_dir.GenSubFil_nest(Const_url_cfg, "wiki_core.gfs");}
|
||||
public Io_url Cfg_wiki_stats_fil() {return root_dir.GenSubFil_nest(Const_url_cfg, "wiki_stats.gfs");}
|
||||
public Xow_dir_info[] Dir_regy() {return dir_regy;} private Xow_dir_info[] dir_regy = Xow_dir_info_.regy_();
|
||||
public Io_url Url_ns_dir(String ns_num, byte tid) {return ns_dir.GenSubDir_nest(ns_num, Xow_dir_info_.Tid_name(tid));}
|
||||
public Io_url Url_ns_reg(String ns_num, byte tid) {return ns_dir.GenSubFil_nest (ns_num , Xow_dir_info_.Tid_name(tid) , Xow_dir_info_.Name_reg_fil);}
|
||||
public Io_url Url_ns_fil(byte tid, int ns_id, int fil_idx) {
|
||||
Xow_dir_info dir_info = dir_regy[tid];
|
||||
String dir_name = dir_info.Name() + Xow_fsys_mgr.Wtr_dir(dir_info.Ext_tid());
|
||||
return Xow_fsys_mgr.Url_fil(ns_dir.GenSubDir_nest(Int_.XtoStr_PadBgn(ns_id, 3), dir_name), fil_idx, dir_regy[tid].Ext_bry());
|
||||
}
|
||||
public Io_url Url_site_fil(byte tid, int fil_idx) {return Xow_fsys_mgr.Url_fil(Url_site_dir(tid), fil_idx, Xow_dir_info_.Bry_xdat);}
|
||||
public Io_url Url_site_reg(byte tid) {return Url_site_dir(tid).GenSubFil(Xow_dir_info_.Name_reg_fil);}
|
||||
public Io_url Url_site_dir(byte tid) {
|
||||
switch (tid) {
|
||||
case Xow_dir_info_.Tid_category2_link: return site_dir.GenSubDir_nest(Xow_dir_info_.Name_category2, Xow_dir_info_.Name_category2_link);
|
||||
case Xow_dir_info_.Tid_category2_main: return site_dir.GenSubDir_nest(Xow_dir_info_.Name_category2, Xow_dir_info_.Name_category2_main);
|
||||
default: return site_dir.GenSubDir_nest(Xow_dir_info_.Tid_name(tid));
|
||||
}
|
||||
}
|
||||
public void Scan_dirs() {
|
||||
Scan_dirs_zip(this, Xow_dir_info_.Tid_page);
|
||||
Scan_dirs_ns(ns_dir, wiki.Ns_mgr());
|
||||
}
|
||||
private static void Scan_dirs_zip(Xow_fsys_mgr fsys_mgr, byte id) {
|
||||
Io_url[] dirs = Io_mgr._.QueryDir_args(fsys_mgr.Ns_dir().GenSubDir_nest("000")).FilPath_("*page*").DirOnly_().Recur_(false).ExecAsUrlAry();
|
||||
int len = dirs.length;
|
||||
byte tid = gplx.ios.Io_stream_.Tid_file; // needed for Xoa_xowa_exec_tst
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_url dir = dirs[i];
|
||||
String dir_name = dir.NameOnly();
|
||||
if (String_.Eq(dir_name, "page")) {tid = gplx.ios.Io_stream_.Tid_file; break;}
|
||||
else if (String_.Eq(dir_name, "page_zip")) tid = gplx.ios.Io_stream_.Tid_zip;
|
||||
else if (String_.Eq(dir_name, "page_gz")) tid = gplx.ios.Io_stream_.Tid_gzip;
|
||||
else if (String_.Eq(dir_name, "page_bz2")) tid = gplx.ios.Io_stream_.Tid_bzip2;
|
||||
// else throw Err_.unhandled(dir_name);
|
||||
}
|
||||
fsys_mgr.Dir_regy()[id].Ext_tid_(tid);
|
||||
}
|
||||
private static HashAdp Scan_dirs_ns(Io_url ns_dir, Xow_ns_mgr ns_mgr) {
|
||||
Io_url[] ns_dirs = Io_mgr._.QueryDir_args(ns_dir).Recur_(false).DirOnly_().ExecAsUrlAry();
|
||||
int len = ns_dirs.length;
|
||||
HashAdp rv = HashAdp_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
int ns_int = Int_.parse_or_(ns_dirs[i].NameOnly(), Int_.MinValue); if (ns_int == Int_.MinValue) continue;
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_int); if (ns == null) continue;
|
||||
ns.Exists_(true);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Io_url Url_fil(Io_url root_dir, int fil_idx, byte[] ext) {return Xos_url_gen.bld_fil_(root_dir, fil_idx, ext);}
|
||||
static final String Const_url_cfg = "cfg";
|
||||
public static Io_url Find_file_or_fail(Io_url dir, String file_name, String file_ext_0, String file_ext_1) {
|
||||
Io_url url = Find_file_or_null(dir, file_name, file_ext_0, file_ext_1);
|
||||
if (url == null) throw Err_mgr._.fmt_("", "", "could not find file: dir=~{0} name=~{1} ext_0=~{2} ext_1=~{3}", dir.Raw(), file_name, file_ext_0, file_ext_1);
|
||||
return url;
|
||||
}
|
||||
public static Io_url Find_file_or_null(Io_url dir, String file_name, String file_ext_0, String file_ext_1) {
|
||||
Io_url url = Xobd_rdr.Find_fil_by(dir, file_name + file_ext_0);
|
||||
if (url == null) {
|
||||
url = Xobd_rdr.Find_fil_by(dir, file_name + file_ext_1);
|
||||
if (url == null) return null;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
public static String Wtr_dir(byte v) {
|
||||
switch (v) {
|
||||
case gplx.ios.Io_stream_.Tid_file : return "";
|
||||
case gplx.ios.Io_stream_.Tid_zip : return "_zip";
|
||||
case gplx.ios.Io_stream_.Tid_gzip : return "_gz";
|
||||
case gplx.ios.Io_stream_.Tid_bzip2 : return "_bz2";
|
||||
default : throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
||||
public static byte[] Wtr_ext(byte v) {
|
||||
switch (v) {
|
||||
case gplx.ios.Io_stream_.Tid_file : return Wtr_xdat_bry;
|
||||
case gplx.ios.Io_stream_.Tid_zip : return Wtr_zip_bry;
|
||||
case gplx.ios.Io_stream_.Tid_gzip : return Wtr_gz_bry;
|
||||
case gplx.ios.Io_stream_.Tid_bzip2 : return Wtr_bz2_bry;
|
||||
default : throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
||||
public static final String Wtr_xdat_str = ".xdat", Wtr_zip_str = ".zip", Wtr_gz_str = ".gz", Wtr_bz2_str = ".bz2";
|
||||
public static final byte[] Wtr_xdat_bry = Bry_.new_ascii_(Wtr_xdat_str), Wtr_zip_bry = Bry_.new_ascii_(Wtr_zip_str), Wtr_gz_bry = Bry_.new_ascii_(Wtr_gz_str), Wtr_bz2_bry = Bry_.new_ascii_(Wtr_bz2_str);
|
||||
}
|
||||
38
400_xowa/src_120_wiki/gplx/xowa/Xow_fsys_mgr_tst.java
Normal file
38
400_xowa/src_120_wiki/gplx/xowa/Xow_fsys_mgr_tst.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xow_fsys_mgr_tst {
|
||||
Xow_fsys_mgr_fxt fxt = new Xow_fsys_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Zip_(Xow_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xow_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat");
|
||||
fxt.Zip_(Xow_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xow_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip");
|
||||
}
|
||||
}
|
||||
class Xow_fsys_mgr_fxt {
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
Xoa_app app; Xow_wiki wiki;
|
||||
public Xow_fsys_mgr_fxt Zip_(byte tid, boolean v) {wiki.Fsys_mgr().Dir_regy()[tid].Ext_tid_(v ? gplx.ios.Io_stream_.Tid_zip : gplx.ios.Io_stream_.Tid_file); return this;}
|
||||
public void Url_ns_fil(byte tid, int ns_id, int fil_idx, String expd) {
|
||||
Tfds.Eq(expd, wiki.Fsys_mgr().Url_ns_fil(tid, ns_id, fil_idx).Raw());
|
||||
}
|
||||
}
|
||||
26
400_xowa/src_120_wiki/gplx/xowa/Xow_gui_mgr.java
Normal file
26
400_xowa/src_120_wiki/gplx/xowa/Xow_gui_mgr.java
Normal 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";
|
||||
}
|
||||
36
400_xowa/src_120_wiki/gplx/xowa/Xow_html_util.java
Normal file
36
400_xowa/src_120_wiki/gplx/xowa/Xow_html_util.java
Normal 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(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_if_bool)) return If_bool(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
|
||||
else if (ctx.Match(k, Invk_if_yn)) return If_yn(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_if_bool = "if_bool", Invk_if_yn = "if_yn";
|
||||
String If_bool(String expr, String true_val, String false_val) {
|
||||
Object o = wiki.App().Gfs_mgr().Run_str(expr);
|
||||
try {return Bool_.cast_(o) ? true_val : false_val;}
|
||||
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
|
||||
}
|
||||
String If_yn(String expr, String true_val, String false_val) {
|
||||
String o = String_.as_(wiki.App().Gfs_mgr().Run_str(expr));
|
||||
try {return Yn.parse_(o) ? true_val : false_val;}
|
||||
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
|
||||
}
|
||||
}
|
||||
85
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_grp.java
Normal file
85
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_grp.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_lang_grp implements GfoInvkAble {
|
||||
public int Id() {return id;} private int id;
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public byte[] Name() {return name;} public Xow_lang_grp Name_(byte[] v) {name = v; return this;} private byte[] name;
|
||||
public int Sort_idx() {return sort_idx;} public Xow_lang_grp Sort_idx_(int v) {sort_idx = v; return this;} private int sort_idx = 0;
|
||||
public byte Sort_mode() {return sort_mode;} public Xow_lang_grp Sort_mode_(byte v) {sort_mode = v; return this;} private byte sort_mode = Sort_mode_page_name;
|
||||
public Xow_lang_itm[] Itms() {if (itms == null) itms = (Xow_lang_itm[])itm_list.XtoAry(Xow_lang_itm.class); return itms;} private Xow_lang_itm[] itms;
|
||||
public int Itms_len() {return this.Itms().length;}
|
||||
public Xow_lang_itm Itms_get(int i) {return this.Itms()[i];}
|
||||
public void Itms_add(Xow_lang_itm itm) {itms = null; itm_list.Add(itm);} ListAdp itm_list = ListAdp_.new_();
|
||||
public void Itms_active_len_add_one_() {++itms_active_len;}
|
||||
public int Itms_active_len() {return itms_active_len;} private int itms_active_len;
|
||||
public void Itms_reset() {
|
||||
Xow_lang_itm[] itms_ary = this.Itms();
|
||||
int itms_len = itms_ary.length;
|
||||
for (int i = 0; i < itms_len; i++)
|
||||
itms_ary[i].Atrs_set(null, false); // clear out pre-existing page names; needed b/c this struct is a singleton for entire wiki
|
||||
itms_active_len = 0;
|
||||
}
|
||||
public Bry_fmtr Html_all() {return html_all;} Bry_fmtr html_all; public Xow_lang_grp Html_all_(String s) {html_all = Bry_fmtr.new_(s, "all_name", "grps"); return this;}
|
||||
public byte[] Html_grp_bgn() {return html_grp_bgn;} private byte[] html_grp_bgn = Bry_.new_ascii_("\n <tr>");
|
||||
public byte[] Html_grp_end() {return html_grp_end;} private byte[] html_grp_end = Bry_.new_ascii_("\n </tr>");
|
||||
public Bry_fmtr Html_itm() {return html_itm;} Bry_fmtr html_itm; public Xow_lang_grp Html_itm_(String s) {html_itm = Bry_fmtr.new_(s, "lang_code", "lang_domain", "lang_name", "lang_href", "pagename_translation"); return this;}
|
||||
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) {
|
||||
Xow_lang_itm[] itms_ary = this.Itms();
|
||||
if (sort_mode == Xow_lang_grp.Sort_mode_page_name)
|
||||
Array_.Sort(itms_ary, Xow_lang_itm_sorter_page_name._);
|
||||
int itms_ary_len = itms_ary.length;
|
||||
for (int i = 0; i < itms_ary_len; i++)
|
||||
itms_ary[i].Html_bld(bfr, wiki);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_owner)) return lang_mgr;
|
||||
else if (ctx.Match(k, Invk_name_)) name = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_sort_idx_)) sort_idx = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_sort_mode_)) sort_mode = (byte)m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_html_all_)) Html_all_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_html_itm_)) Html_itm_(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_owner = "owner", Invk_name_ = "name_", Invk_sort_mode_ = "sort_mode_", Invk_sort_idx_ = "sort_idx_", Invk_html_all_ = "html_all_", Invk_html_itm_ = "html_itm_";
|
||||
public static final byte Sort_mode_lang_idx = 0, Sort_mode_lang_name = 1, Sort_mode_page_name = 2;
|
||||
public static Xow_lang_grp dflt_(Xow_lang_mgr lang_mgr, int id, byte[] key) {
|
||||
Xow_lang_grp rv = new Xow_lang_grp();
|
||||
rv.lang_mgr = lang_mgr; rv.id = id; rv.key = key; rv.name = key;
|
||||
rv.Html_all_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <h4>~{all_name}</h4>"
|
||||
, " <table style='width: 100%;'>~{grps}"
|
||||
, " </table>"
|
||||
));
|
||||
rv.Html_itm_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>~{lang_name}</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"~{lang_code}\" title=\"~{pagename_translation}\" href=\"~{lang_href}\">~{pagename_translation}</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
));
|
||||
return rv;
|
||||
} private Xow_lang_grp() {}
|
||||
Xow_lang_mgr lang_mgr;
|
||||
}
|
||||
class Xow_lang_itm_sorter_page_name implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {return Bry_.Compare(((Xow_lang_itm)lhsObj).Page_name(), ((Xow_lang_itm)rhsObj).Page_name());}
|
||||
public static final Xow_lang_itm_sorter_page_name _ = new Xow_lang_itm_sorter_page_name(); Xow_lang_itm_sorter_page_name() {}
|
||||
}
|
||||
class Xow_lang_grp_sorter_sort_idx implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {return Int_.Compare(((Xow_lang_grp)lhsObj).Sort_idx(), ((Xow_lang_grp)rhsObj).Sort_idx());}
|
||||
public static final Xow_lang_grp_sorter_sort_idx _ = new Xow_lang_grp_sorter_sort_idx(); Xow_lang_grp_sorter_sort_idx() {}
|
||||
}
|
||||
36
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_itm.java
Normal file
36
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_itm.java
Normal 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_lang_itm {
|
||||
public Xow_lang_itm(Xow_lang_grp html_grp, Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
|
||||
this.html_grp = html_grp; this.xwiki = xwiki; this.lang = lang;
|
||||
} private Xow_lang_grp html_grp; Xow_xwiki_itm xwiki; Xoac_lang_itm lang;
|
||||
public byte[] Lang_key() {return lang.Key_bry();}
|
||||
public byte[] Lang_domain() {return xwiki.Domain();}
|
||||
public byte[] Lang_name() {return lang.Local_name_bry();}
|
||||
public byte[] Page_name() {return page_name;} private byte[] page_name;
|
||||
public boolean Page_name_has() {return Bry_.Len_gt_0(page_name);}
|
||||
public boolean Empty_xwiki() {return empty_xwiki;} private boolean empty_xwiki;
|
||||
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki) {
|
||||
html_grp.Html_itm().Bld_bfr(bfr, lang.Key_bry(), xwiki.Domain(), lang.Local_name_bry(), page_name);
|
||||
}
|
||||
public void Atrs_set(byte[] page_name, boolean empty_xwiki) {
|
||||
this.page_name = page_name; this.empty_xwiki = empty_xwiki;
|
||||
html_grp.Itms_active_len_add_one_();
|
||||
}
|
||||
}
|
||||
156
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr.java
Normal file
156
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr.java
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_lang_mgr {
|
||||
Xow_lang_mgr() {
|
||||
int len = Xol_lang_itm_.Id__max;
|
||||
itms = new Xow_lang_itm[len];
|
||||
}
|
||||
public Bry_fmtr Html_div() {return html_div;} Bry_fmtr html_div = Bry_fmtr.new_(
|
||||
String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>~{langs_hdr}~{wikidata_link}</h5>~{grps}"
|
||||
, "</div>"
|
||||
), "grps", "langs_hdr", "wikidata_link");
|
||||
public Bry_fmtr Html_wikidata_link() {return html_wikidata_link;} Bry_fmtr html_wikidata_link = Bry_fmtr.new_(" (<a href=\"/site/www.wikidata.org/wiki/~{qid}\">wikidata</a>)", "qid");
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Itms_reg(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
|
||||
int lang_id = xwiki.Lang_id();
|
||||
Xoac_lang_grp ini_grp = lang.Grp();
|
||||
Xow_lang_grp grp = (Xow_lang_grp)hash.Fetch(ini_grp.Key_bry());
|
||||
if (grp == null) {
|
||||
grp = Grps_get_or_new(ini_grp.Key_bry());
|
||||
grp.Name_(ini_grp.Name_bry());
|
||||
grp.Sort_idx_(ini_grp.Sort_idx());
|
||||
}
|
||||
Xow_lang_itm itm = itms[lang_id];
|
||||
if (itm == null) {
|
||||
itm = new Xow_lang_itm(grp, xwiki, lang);
|
||||
itms[lang_id] = itm;
|
||||
}
|
||||
grp.Itms_add(itm);
|
||||
}
|
||||
public int Grps_len() {return hash.Count();}
|
||||
public Xow_lang_grp Grps_get_at(int i) {return (Xow_lang_grp)hash.FetchAt(i);}
|
||||
Xow_lang_grp Grps_get_or_new(byte[] key) {
|
||||
Xow_lang_grp rv = (Xow_lang_grp)hash.Fetch(key);
|
||||
if (rv == null) {
|
||||
int id = hash.Count();
|
||||
rv = Xow_lang_grp.dflt_(this, id, key);
|
||||
rv.Sort_idx_(id);
|
||||
hash.Add(key, rv);
|
||||
rv.Name_(key);
|
||||
}
|
||||
return rv;
|
||||
} private OrderedHash hash = OrderedHash_.new_bry_();
|
||||
public void Grps_sort() {hash.SortBy(Xow_lang_grp_sorter_sort_idx._);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Grps_get_or_new(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_sort)) Grps_sort();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_get = "get", Invk_sort = "sort";
|
||||
public void Html_bld(Bry_bfr bfr, Xow_wiki wiki, ListAdp ttl_list, byte[] qid) {
|
||||
int grp_len = hash.Count();
|
||||
for (int i = 0; i < grp_len; i++) {
|
||||
Xow_lang_grp grp = (Xow_lang_grp)hash.FetchAt(i);
|
||||
grp.Itms_reset();
|
||||
}
|
||||
int ttl_list_len = ttl_list.Count();
|
||||
for (int i = 0; i < ttl_list_len; i++) {
|
||||
Xoa_ttl ttl = (Xoa_ttl)ttl_list.FetchAt(i);
|
||||
Xow_xwiki_itm xwiki = ttl.Wik_itm();
|
||||
int lang_id = xwiki.Lang_id();
|
||||
Xow_lang_itm itm = itms[lang_id]; // NOTE: handles ttls like [[fr:]] and [[:fr;]] which have an empty Page_txt, but a valued Full_txt_raw
|
||||
byte[] ttl_bry = ttl.Page_txt_w_anchor();
|
||||
boolean empty_xwiki = false;
|
||||
if (Bry_.Len_eq_0(ttl_bry)) {
|
||||
ttl_bry = wiki.Ctx().Cur_page().Ttl().Page_txt();
|
||||
empty_xwiki = true;
|
||||
}
|
||||
itm.Atrs_set(ttl_bry, empty_xwiki);
|
||||
}
|
||||
html_bldr.Init(this, wiki, ttl_list, ttl_list_len, qid);
|
||||
html_bldr.XferAry(bfr, -1);
|
||||
} private Xow_lang_itm[] itms = null; Xow_lang_html html_bldr = new Xow_lang_html();
|
||||
public static Xow_lang_mgr dflt_() {
|
||||
return new Xow_lang_mgr();
|
||||
}
|
||||
}
|
||||
class Xow_lang_html implements Bry_fmtr_arg {
|
||||
int stage = 0;
|
||||
public Xow_lang_html Init(Xow_lang_mgr lang_mgr, Xow_wiki wiki, ListAdp ttl_list, int ttl_list_len, byte[] qid) {
|
||||
this.lang_mgr = lang_mgr; this.wiki = wiki; this.ttl_list = ttl_list; this.ttl_list_len = ttl_list_len; this.qid = qid;
|
||||
return this;
|
||||
} private Xow_lang_mgr lang_mgr; Xow_wiki wiki; ListAdp ttl_list; int ttl_list_len; byte[] qid;
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
switch (stage) {
|
||||
case 0: {
|
||||
stage = 1;
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b128().Mkr_rls();
|
||||
byte[] wikidata_link = Bry_.Len_eq_0(qid) ? Bry_.Empty : lang_mgr.Html_wikidata_link().Bld_bry_many(tmp_bfr, qid);
|
||||
lang_mgr.Html_div().Bld_bfr_many(bfr, this, wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_page_lang_header), wikidata_link);
|
||||
stage = 0;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
stage = 2;
|
||||
int grps_len = lang_mgr.Grps_len();
|
||||
for (int i = 0; i < grps_len; i++) {
|
||||
grp = lang_mgr.Grps_get_at(i);
|
||||
if (grp.Itms_active_len() == 0) continue; // skip grps with no items
|
||||
grp.Html_all().Bld_bfr_many(bfr, grp.Name(), this);
|
||||
}
|
||||
stage = 1;
|
||||
break;
|
||||
case 2:
|
||||
int itms_len = grp.Itms_len();
|
||||
int grp_counter = 0; boolean row_opened = false;
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
Xow_lang_itm itm = grp.Itms_get(i);
|
||||
if (!itm.Page_name_has()) continue;
|
||||
if (grp_counter == 0) {
|
||||
bfr.Add(grp.Html_grp_bgn());
|
||||
row_opened = true;
|
||||
}
|
||||
byte[] lang_key = itm.Lang_key();
|
||||
byte[] domain = itm.Lang_domain();
|
||||
byte[] page_name = itm.Page_name();
|
||||
byte[] local_name = itm.Lang_name();
|
||||
if (wiki.App().User().Wiki().Xwiki_mgr().Get_by_key(domain) == null)
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_http_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
|
||||
else
|
||||
tmp_bfr.Add(Xoh_href_parser.Href_site_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
|
||||
if (!itm.Empty_xwiki()) tmp_bfr.Add(page_name);
|
||||
grp.Html_itm().Bld_bfr_many(bfr, lang_key, domain, local_name, tmp_bfr.XtoAryAndClear(), page_name);
|
||||
++grp_counter;
|
||||
if (grp_counter == 3) {
|
||||
row_opened = false;
|
||||
bfr.Add(grp.Html_grp_end());
|
||||
grp_counter = 0;
|
||||
}
|
||||
}
|
||||
if (row_opened) {
|
||||
bfr.Add(grp.Html_grp_end());
|
||||
grp_counter = 0;
|
||||
}
|
||||
stage = 2;
|
||||
break;
|
||||
}
|
||||
} private Xow_lang_grp grp; Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
}
|
||||
65
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr_fxt.java
Normal file
65
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr_fxt.java
Normal 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.*;
|
||||
public class Xow_lang_mgr_fxt {
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
Init_langs(wiki);
|
||||
}
|
||||
public static void Init_langs(Xow_wiki wiki) {
|
||||
Xoa_app app = wiki.App();
|
||||
Xoa_lang_mgr lang_mgr = app.Lang_mgr();
|
||||
lang_mgr.Groups().Set_bulk(Bry_.new_ascii_(String_.Concat_lines_nl
|
||||
( "+||grp|wiki"
|
||||
, "+|wiki|grp|grp1"
|
||||
, "+|wiki|grp|grp2"
|
||||
, "+|grp1|itm|simple|Simple"
|
||||
, "+|grp2|itm|fr|French"
|
||||
, "+|grp1|itm|es|Spanish"
|
||||
, "+|grp2|itm|de|German"
|
||||
, "+|grp1|itm|it|Italian"
|
||||
, "+|grp1|itm|zh|Chinese"
|
||||
)));
|
||||
wiki.Xwiki_mgr().Add_bulk_langs(Bry_.new_ascii_("wiki"));
|
||||
String bulk = String_.Concat_lines_nl
|
||||
( "simple.wikipedia.org|simple.wikipedia.org"
|
||||
, "fr.wikipedia.org|fr.wikipedia.org"
|
||||
, "es.wikipedia.org|es.wikipedia.org"
|
||||
, "de.wikipedia.org|de.wikipedia.org"
|
||||
, "it.wikipedia.org|it.wikipedia.org"
|
||||
);
|
||||
wiki.App().User().Wiki().Xwiki_mgr().Add_bulk(Bry_.new_ascii_(bulk));
|
||||
}
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
Xoa_app app;
|
||||
public void tst(String raw, String expd) {
|
||||
Xop_ctx ctx = wiki.Ctx();
|
||||
ctx.Cur_page().Ttl_(Xoa_ttl.parse_(wiki, Bry_.new_ascii_("test_page")));
|
||||
byte[] raw_bry = Bry_.new_utf8_(raw);
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(raw_bry);
|
||||
wiki.Parser().Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), raw_bry);
|
||||
wiki.Html_mgr().Html_wtr().Write_all(bfr, ctx, raw_bry, root);
|
||||
|
||||
Bry_bfr html_bfr = Bry_bfr.new_();
|
||||
wiki.Xwiki_mgr().Lang_mgr().Html_bld(html_bfr, wiki, ctx.Cur_page().Xwiki_langs(), gplx.xowa.xtns.wdatas.Wdata_xwiki_link_wtr.Qid_null);
|
||||
Tfds.Eq_str_lines(expd, html_bfr.XtoStrAndClear());
|
||||
}
|
||||
}
|
||||
85
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr_tst.java
Normal file
85
400_xowa/src_120_wiki/gplx/xowa/Xow_lang_mgr_tst.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xow_lang_mgr_tst {
|
||||
Xow_lang_mgr_fxt fxt = new Xow_lang_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.tst("[[simple:Earth]] [[fr:Terre]] [[es:Tierra]] [[de:Erde]] [[it:Terre]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages</h5>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"simple\" title=\"Earth\" href=\"/site/simple.wikipedia.org/wiki/Earth\">Earth</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Spanish</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"es\" title=\"Tierra\" href=\"/site/es.wikipedia.org/wiki/Tierra\">Tierra</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Italian</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"it\" title=\"Terre\" href=\"/site/it.wikipedia.org/wiki/Terre\">Terre</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " <h4>grp2</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"fr\" title=\"Terre\" href=\"/site/fr.wikipedia.org/wiki/Terre\">Terre</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"de\" title=\"Erde\" href=\"/site/de.wikipedia.org/wiki/Erde\">Erde</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Empty() {
|
||||
fxt.tst("[[simple:]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages</h5>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"simple\" title=\"Test page\" href=\"/site/simple.wikipedia.org/wiki/\">Test page</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Unregistered() {
|
||||
// fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_utf8_("zh"), Bry_.new_utf8_("zh.wikipedia.org"), Bry_.new_utf8_("http://zh.wikipedia.org/~{0}"));
|
||||
fxt.tst("[[zh:Earth]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages</h5>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Chinese</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"zh\" title=\"Earth\" href=\"http://zh.wikipedia.org/wiki/Earth\">Earth</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Anchor() {// PURPOSE: A#b was not showing anchor "#b"; DATE:2013-10-23
|
||||
fxt.tst("[[simple:A#b]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5>In other languages</h5>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
, " <tr>"
|
||||
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><a hreflang=\"simple\" title=\"A#b\" href=\"/site/simple.wikipedia.org/wiki/A#b\">A#b</a></td><td style='width: 3%; padding-bottom: 5px;'></td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
31
400_xowa/src_120_wiki/gplx/xowa/Xow_mainpage_finder.java
Normal file
31
400_xowa/src_120_wiki/gplx/xowa/Xow_mainpage_finder.java
Normal 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 Xow_mainpage_finder {
|
||||
public static byte[] Find_or(Xow_wiki wiki, byte[] or) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
Xol_msg_itm msg_itm = Pf_msg_mgr.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), Msg_mainpage);
|
||||
byte[] rv = msg_itm.Src_is_missing()
|
||||
? or
|
||||
: Pf_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_ascii_("mainpage");
|
||||
}
|
||||
73
400_xowa/src_120_wiki/gplx/xowa/Xow_mainpage_finder_tst.java
Normal file
73
400_xowa/src_120_wiki/gplx/xowa/Xow_mainpage_finder_tst.java
Normal 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_ascii_(mainpage_val));
|
||||
}
|
||||
public void Init_mediawiki_page(String mainpage_val) {
|
||||
fxt.Init_page_create(String_.new_ascii_(Ttl_mainpage), mainpage_val);
|
||||
} private static final byte[] Ttl_mainpage = Bry_.new_ascii_("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_ascii_(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_ascii_(actl));
|
||||
}
|
||||
}
|
||||
110
400_xowa/src_120_wiki/gplx/xowa/Xow_msg_mgr.java
Normal file
110
400_xowa/src_120_wiki/gplx/xowa/Xow_msg_mgr.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Xow_msg_mgr implements GfoInvkAble {
|
||||
private Xow_wiki wiki; private Xol_lang lang; private Xol_msg_mgr msg_mgr;
|
||||
public Xow_msg_mgr(Xow_wiki wiki, Xol_lang lang) {
|
||||
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;}
|
||||
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 = wiki.Utl_bry_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 = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
itm = Pf_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_utf8_(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 = wiki.Utl_bry_bfr_mkr().Get_b512();
|
||||
if (itm == null)
|
||||
itm = Pf_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 = wiki.Utl_bry_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.XtoAryAndClear();
|
||||
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_ascii_("tooltip-"), CONST_prefix_accesskey = Bry_.new_ascii_("accesskey-"), CONST_atr_title = Bry_.new_ascii_(" title=\""), CONST_atr_accesskey = Bry_.new_ascii_(" 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";
|
||||
}
|
||||
105
400_xowa/src_120_wiki/gplx/xowa/Xow_ns.java
Normal file
105
400_xowa/src_120_wiki/gplx/xowa/Xow_ns.java
Normal 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.*;
|
||||
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_utf8_(v);
|
||||
}
|
||||
this.num_str = Int_.XtoStr_PadBgn(id, 3);
|
||||
this.num_bry = Bry_.new_ascii_(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 = OrderedHash_.new_();
|
||||
aliases.Add_if_new(alias, alias);
|
||||
} private OrderedHash 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.FetchAt(i);
|
||||
rv[i] = KeyVal_.int_(i + ListAdp_.Base1, alias);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists;
|
||||
public int Bldr_file_idx() {return bldr_file_idx;} public void Bldr_file_idx_(int v) {bldr_file_idx = v;} private int bldr_file_idx = Bldr_file_idx_heap;
|
||||
public static final int Bldr_file_idx_heap = -1;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_subpages_enabled_)) 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";
|
||||
}
|
||||
88
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_.java
Normal file
88
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
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_ {
|
||||
public static final int // EX.WP: 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_ascii_(Key_template);
|
||||
public static final byte[] Name_ui_main = Bry_.new_ascii_(Key_main);
|
||||
public static int Canonical_id(byte[] canonical_name) {
|
||||
if (canonical_hash == null) {
|
||||
Xow_ns[] ary = Canonical;
|
||||
int len = ary.length;
|
||||
canonical_hash = OrderedHash_.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.Fetch(canonical_name);
|
||||
return rv_obj == null ? Xow_ns_.Id_null : ((Int_obj_val)rv_obj).Val();
|
||||
} private static OrderedHash 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_ascii_(Key_main);
|
||||
public static final byte[] Ns_prefix_main = Bry_.new_ascii_("Main:");
|
||||
private static Xow_ns Canonical_new_(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Id_1st, Bry_.new_ascii_(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter;
|
||||
}
|
||||
26
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_case_.java
Normal file
26
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_case_.java
Normal 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_ns_case_ {
|
||||
public static final byte Id_all = 0, Id_1st = 1;
|
||||
public static byte parse_(String s) {
|
||||
if (String_.Eq(s, "first-letter")) return Id_1st;
|
||||
else if (String_.Eq(s, "case-sensitive")) return Id_all;
|
||||
else throw Err_mgr._.unhandled_(s);
|
||||
}
|
||||
}
|
||||
247
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_mgr.java
Normal file
247
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_mgr.java
Normal file
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
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.xtns.scribunto.*;
|
||||
public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
private OrderedHash id_hash = OrderedHash_.new_(); // hash for retrieval by id
|
||||
private Hash_adp_bry name_hash = Hash_adp_bry.ci_(); // hash for retrieval by name; note that ns names are case-insensitive "File:" == "fILe:"
|
||||
private Hash_adp_bry tmpl_hash = Hash_adp_bry.ci_(); // hash for retrieval by name; PERF for templates
|
||||
private OrderedHash aliases = OrderedHash_.new_(); // hash to store aliases; used to populate name_hash;
|
||||
public void 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;
|
||||
}
|
||||
public ByteTrieMgr_slim Category_trie() {return category_trie;} private ByteTrieMgr_slim 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 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.FetchAt(idx);}
|
||||
public Xow_ns Ids_get_or_null(int id) {return (Xow_ns)id_hash.Fetch(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.AddReplace(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.FetchAt(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_utf8_(kv.Key());
|
||||
Rebuild_hashes__add(name_hash, ns, alias_bry);
|
||||
if (ns.Id_tmpl()) {
|
||||
byte[] alias_name = Bry_.new_utf8_(kv.Key());
|
||||
alias_name = Bry_.Add(alias_name, Byte_ascii.Colon);
|
||||
tmpl_hash.AddReplace(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_ascii_("$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.AddReplace(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.AddReplace(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_utf8_(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 = ByteTrieMgr_slim.new_(ns.Case_match() == Xow_ns_case_.Id_all);
|
||||
category_trie.Add(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.AddReplace(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.SortBy(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.FetchAt(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.SortBy(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.FetchAt(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
|
||||
}
|
||||
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.NewLine);
|
||||
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_.X_to_int_or(flds[0], Int_.MinValue);
|
||||
this.Aliases_add(cur_id, String_.new_utf8_(flds[1]));
|
||||
}
|
||||
Ords_sort();
|
||||
}
|
||||
}
|
||||
50
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_mgr_.java
Normal file
50
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_mgr_.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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_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_() { // 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();
|
||||
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();
|
||||
}
|
||||
}
|
||||
60
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_mgr_tst.java
Normal file
60
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_mgr_tst.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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_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_ascii_("Templatex:Abc");
|
||||
Tfds.Eq(10, fxt.Ns_mgr().Tmpls_get_w_colon(name, 0, name.length));
|
||||
}
|
||||
}
|
||||
class Xow_ns_mgr_fxt {
|
||||
Xow_ns_mgr ns_mgr = new Xow_ns_mgr();
|
||||
public Xow_ns_mgr Ns_mgr() {return ns_mgr;}
|
||||
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_.XtoStr(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;
|
||||
}
|
||||
}
|
||||
63
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_tst.java
Normal file
63
400_xowa/src_120_wiki/gplx/xowa/Xow_ns_tst.java
Normal 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());
|
||||
}
|
||||
}
|
||||
58
400_xowa/src_120_wiki/gplx/xowa/Xow_script_mgr.java
Normal file
58
400_xowa/src_120_wiki/gplx/xowa/Xow_script_mgr.java
Normal 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(Xow_wiki wiki) {
|
||||
int len = hash.Count();
|
||||
Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_script_itm itm = (Xow_script_itm)hash.FetchAt(i);
|
||||
byte wiki_tid = wiki.Domain_tid();
|
||||
if (Byte_.In(wiki_tid, itm.Wiki_tids())) // wiki_tid matches itm
|
||||
itm.Fmtr().Bld_bfr_many(bfr, wiki.Domain_bry(), Xow_wiki_domain_.Key_by_tid(wiki_tid), wiki.Lang().Key_bry());
|
||||
}
|
||||
String gfs_script = String_.Replace(bfr.XtoStrAndClear(), Op_sys.Wnt.Nl_str(), Op_sys.Lnx.Nl_str());
|
||||
wiki.App().Gfs_mgr().Run_str(gfs_script);
|
||||
bfr.Mkr_rls();
|
||||
}
|
||||
public void Set(byte[] key, byte[] wiki_types_raw, byte[] script) {
|
||||
byte[][] wiki_tid_names = Bry_.Split(wiki_types_raw, Byte_ascii.Tilde);
|
||||
int len = wiki_tid_names.length;
|
||||
byte[] wiki_tids = new byte[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
wiki_tids[i] = Xow_wiki_domain_.Tid_by_key(wiki_tid_names[i]);
|
||||
|
||||
Xow_script_itm itm = new Xow_script_itm(key, wiki_tids, script);
|
||||
hash.AddReplace(itm.Key(), itm);
|
||||
}
|
||||
public OrderedHash hash = OrderedHash_.new_bry_();
|
||||
}
|
||||
class Xow_script_itm {
|
||||
public Xow_script_itm(byte[] key, byte[] wiki_tids, byte[] script) {
|
||||
this.key = key; this.wiki_tids = wiki_tids; this.fmtr = Bry_fmtr.new_bry_(script, "wiki_key", "wiki_type_name", "wiki_lang");
|
||||
}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public byte[] Wiki_tids() {return wiki_tids;} private byte[] wiki_tids;
|
||||
public Bry_fmtr Fmtr() {return fmtr;} Bry_fmtr fmtr;
|
||||
}
|
||||
29
400_xowa/src_120_wiki/gplx/xowa/Xow_sys_cfg.java
Normal file
29
400_xowa/src_120_wiki/gplx/xowa/Xow_sys_cfg.java
Normal 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(Xow_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_";
|
||||
}
|
||||
26
400_xowa/src_120_wiki/gplx/xowa/Xow_user.java
Normal file
26
400_xowa/src_120_wiki/gplx/xowa/Xow_user.java
Normal 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_ascii_("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_";
|
||||
}
|
||||
40
400_xowa/src_120_wiki/gplx/xowa/Xow_utl_mgr.java
Normal file
40
400_xowa/src_120_wiki/gplx/xowa/Xow_utl_mgr.java
Normal 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.*;
|
||||
public class Xow_utl_mgr {
|
||||
public Xow_utl_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_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._
|
||||
});
|
||||
}
|
||||
275
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java
Normal file
275
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java
Normal file
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
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.apps.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.html.*; import gplx.xowa.users.history.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.xowa.setup.maints.*; import gplx.xowa.wikis.caches.*;
|
||||
import gplx.xowa.bldrs.imports.*;
|
||||
public class Xow_wiki implements GfoInvkAble {
|
||||
private Xow_html_util util;
|
||||
public Xow_wiki(Xoa_app app, Io_url wiki_dir, Xow_ns_mgr ns_mgr, Xol_lang lang) {
|
||||
this.app = app; this.ns_mgr = ns_mgr; this.lang = lang;
|
||||
domain_str = wiki_dir.NameOnly(); domain_bry = Bry_.new_utf8_(domain_str);
|
||||
Xow_wiki_domain domain = Xow_wiki_domain_.parse_by_domain(domain_bry);
|
||||
domain_tid = domain.Tid();
|
||||
fsys_mgr = new Xow_fsys_mgr(this, wiki_dir);
|
||||
redirect_mgr = new Xop_redirect_mgr(this);
|
||||
data_mgr = new Xow_data_mgr(this);
|
||||
file_mgr = new Xow_file_mgr(this);
|
||||
utl_mgr = new Xow_utl_mgr(this);
|
||||
parser = Xop_parser.new_wiki_(this);
|
||||
cfg_parser = new Xowc_parser(this);
|
||||
ctx = Xop_ctx.new_(this);
|
||||
props.SiteName_(domain_tid).ServerName_(domain_bry);
|
||||
props.ContentLanguage_(lang.Key_bry());
|
||||
Pf_func_.Reg(lang.Func_regy(), lang);
|
||||
special_mgr = new Xows_mgr(this);
|
||||
stats = new Xow_wiki_stats(this);
|
||||
xwiki_mgr = new Xow_xwiki_mgr(this);
|
||||
xwiki_mgr.Add_full(domain_bry, domain_bry); // add full name to xwiki_mgr; needed for lookup in home ns; EX: [[en.wikipedia.org:Earth]]
|
||||
html_mgr = new Xow_html_mgr(this);
|
||||
sys_cfg = new Xow_sys_cfg(this);
|
||||
hive_mgr = new Xob_hive_mgr(this);
|
||||
util = new Xow_html_util(this);
|
||||
cfg_wiki_core = new Xow_cfg_wiki_core(this);
|
||||
import_cfg = new Xob_import_cfg(this);
|
||||
msg_mgr = new Xow_msg_mgr(this, lang);
|
||||
eval_mgr = new Bfmtr_eval_wiki(this);
|
||||
fragment_mgr = new Xow_fragment_mgr(this);
|
||||
xtn_mgr = new Xow_xtn_mgr().Ctor_by_wiki(this);
|
||||
if (domain_tid == Xow_wiki_domain_.Tid_home) {
|
||||
wdata_wiki_tid = Xow_wiki_domain_.Tid_wikipedia;
|
||||
wdata_wiki_lang = Xol_lang_.Key_en;
|
||||
}
|
||||
else {
|
||||
wdata_wiki_tid = domain_tid;
|
||||
wdata_wiki_lang = lang.Key_bry();
|
||||
}
|
||||
db_mgr = new gplx.xowa.dbs.Xodb_mgr_txt(this, data_mgr);
|
||||
domain_abrv = Xob_bz2_file.Build_alias(Xow_wiki_domain_.parse_by_domain(domain_bry));
|
||||
maint_mgr = new Xow_maint_mgr(this);
|
||||
cache_mgr = new Xow_cache_mgr(this);
|
||||
}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public byte[] Domain_bry() {return domain_bry;} private byte[] domain_bry;
|
||||
public String Domain_str() {return domain_str;} private String domain_str;
|
||||
public byte Domain_tid() {return domain_tid;} private byte domain_tid;
|
||||
public byte[] Domain_abrv() {return domain_abrv;} private byte[] domain_abrv;
|
||||
public Xol_lang Lang() {return lang;} private Xol_lang lang;
|
||||
public Xow_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xow_fsys_mgr fsys_mgr;
|
||||
public Xow_utl_mgr Utl_mgr() {return utl_mgr;} private Xow_utl_mgr utl_mgr;
|
||||
public Xow_ns_mgr Ns_mgr() {return ns_mgr;} public void Ns_mgr_(Xow_ns_mgr v) {ns_mgr = v;} private Xow_ns_mgr ns_mgr;
|
||||
public Xow_gui_mgr Gui_mgr() {return gui_mgr;} private Xow_gui_mgr gui_mgr = new Xow_gui_mgr();
|
||||
public Xow_user User() {return user;} private Xow_user user = new Xow_user();
|
||||
public Xow_data_mgr Data_mgr() {return data_mgr;} private Xow_data_mgr data_mgr;
|
||||
public Xodb_mgr Db_mgr() {return db_mgr;} private Xodb_mgr db_mgr;
|
||||
public Xodb_mgr_sql Db_mgr_as_sql() {return (Xodb_mgr_sql)db_mgr;}
|
||||
public Xows_mgr Special_mgr() {return special_mgr;} private Xows_mgr special_mgr;
|
||||
public Xow_html_mgr Html_mgr() {return html_mgr;} private Xow_html_mgr html_mgr;
|
||||
public Xow_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Xow_xtn_mgr xtn_mgr;
|
||||
public Xow_cache_mgr Cache_mgr() {return cache_mgr;} private Xow_cache_mgr cache_mgr;
|
||||
|
||||
public byte[] Commons_wiki_key() {return commons_wiki_key;} private byte[] commons_wiki_key = Xow_wiki_.Domain_commons_bry;
|
||||
public Xob_hive_mgr Hive_mgr() {return hive_mgr;} private Xob_hive_mgr hive_mgr;
|
||||
public Xow_msg_mgr Msg_mgr() {return msg_mgr;} private Xow_msg_mgr msg_mgr;
|
||||
public Xow_fragment_mgr Fragment_mgr() {return fragment_mgr;} private Xow_fragment_mgr fragment_mgr;
|
||||
public Bfmtr_eval_wiki Eval_mgr() {return eval_mgr;} private Bfmtr_eval_wiki eval_mgr;
|
||||
public Bry_bfr_mkr Utl_bry_bfr_mkr() {return app.Utl_bry_bfr_mkr();}
|
||||
public byte Wdata_wiki_tid() {return wdata_wiki_tid;} private byte wdata_wiki_tid;
|
||||
public byte[] Wdata_wiki_lang() {return wdata_wiki_lang;} private byte[] wdata_wiki_lang;
|
||||
public void Wdata_wiki_lang_(byte[] v) {this.wdata_wiki_lang = v;} // TEST:
|
||||
public boolean Init_needed() {return init_needed;} public Xow_wiki Init_needed_(boolean v) {init_needed = v; return this;} private boolean init_needed = true;
|
||||
|
||||
public Xop_parser Parser() {return parser;} private Xop_parser parser;
|
||||
public Xop_redirect_mgr Redirect_mgr() {return redirect_mgr;} private Xop_redirect_mgr redirect_mgr;
|
||||
public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx;
|
||||
public ListAdp Rls_list() {if (rls_list == null) rls_list = ListAdp_.new_(); return rls_list;} private ListAdp rls_list;
|
||||
public HashAdp If_exists_regy() {return if_exists_regy;} HashAdp if_exists_regy = HashAdp_.new_bry_();
|
||||
|
||||
public Xow_xwiki_mgr Xwiki_mgr() {return xwiki_mgr;} private Xow_xwiki_mgr xwiki_mgr;
|
||||
public Xow_file_mgr File_mgr() {return file_mgr;} private Xow_file_mgr file_mgr;
|
||||
public Xow_cfg_wiki_core Cfg_wiki_core() {return cfg_wiki_core;} private Xow_cfg_wiki_core cfg_wiki_core;
|
||||
public Xob_import_cfg Import_cfg() {return import_cfg;} private Xob_import_cfg import_cfg;
|
||||
|
||||
public Xow_wiki_stats Stats() {return stats;} private Xow_wiki_stats stats;
|
||||
public Xow_wiki_props Props() {return props;} private Xow_wiki_props props = new Xow_wiki_props();
|
||||
public Xou_history_cfg Cfg_history() {return cfg_history;} private Xou_history_cfg cfg_history = new Xou_history_cfg();
|
||||
public Xoh_cfg_gallery Cfg_gallery() {return cfg_gallery;} private Xoh_cfg_gallery cfg_gallery = new Xoh_cfg_gallery();
|
||||
public Xoh_file_page Cfg_file_page() {return cfg_file_page;} private Xoh_file_page cfg_file_page = new Xoh_file_page();
|
||||
public Xow_sys_cfg Sys_cfg() {return sys_cfg;} private Xow_sys_cfg sys_cfg;
|
||||
public Xowc_parser Cfg_parser() {return cfg_parser;} private Xowc_parser cfg_parser;
|
||||
public boolean Cfg_parser_lnki_xwiki_repos_enabled() {return cfg_parser_lnki_xwiki_repos_enabled;} public Xow_wiki Cfg_parser_lnki_xwiki_repos_enabled_(boolean v) {cfg_parser_lnki_xwiki_repos_enabled = v; return this;} private boolean cfg_parser_lnki_xwiki_repos_enabled;
|
||||
public Xoi_dump_mgr Import_mgr() {return import_mgr;} private Xoi_dump_mgr import_mgr = new Xoi_dump_mgr();
|
||||
public Xow_maint_mgr Maint_mgr() {return maint_mgr;} private Xow_maint_mgr maint_mgr;
|
||||
public void Clear_for_tests() { // NOTE: these are structures that cache items for PERF; need to be cleared out for multiple test runs
|
||||
file_mgr.Meta_mgr().Clear();
|
||||
db_mgr.Load_mgr().Clear();
|
||||
}
|
||||
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl) {return GetPageByTtl(url, ttl, lang, app.Gui_mgr().Browser_win().Active_tab());}
|
||||
public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return GetPageByTtl(url, ttl, lang, tab);}
|
||||
private Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab) {
|
||||
if (init_needed) Init_wiki(app.User());
|
||||
Xoa_page page = data_mgr.Get_page(url, ttl, false, false); // get page from data_mgr
|
||||
if (page.Missing()) { // page doesn't exist
|
||||
if (ttl.Ns().Id_file()) {
|
||||
Xow_wiki commons_wiki = app.Wiki_mgr().Get_by_key_or_null(commons_wiki_key);
|
||||
if (commons_wiki != null
|
||||
&& !Bry_.Eq(domain_bry, commons_wiki.Domain_bry())) // if file, check commons wiki; note that !Bry_.Eq is recursion guard
|
||||
return commons_wiki.GetPageByTtl(url, ttl, this.lang, tab);
|
||||
}
|
||||
else
|
||||
return page.Missing_();
|
||||
}
|
||||
if (page.Missing()) return page; // NOTE: commons can return null page
|
||||
page.Tab_(tab);
|
||||
page.Lang_(lang);
|
||||
gplx.xowa.xtns.scribunto.Scrib_core.Core_page_changed(page); // notify scribunto about page changed
|
||||
ParsePage(page, false); // NOTE: do not clear page b/c reused for search
|
||||
return page;
|
||||
}
|
||||
public void ParsePage_root(Xoa_page page, boolean clear) {
|
||||
ParsePage(page, clear);
|
||||
}
|
||||
public void ParsePage(Xoa_page page, boolean clear) {
|
||||
if (init_needed && !Env_.Mode_testing()) Init_wiki(app.User());
|
||||
ctx.Cur_page_(page);
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(page.Data_raw());
|
||||
if (clear) {page.Clear();}
|
||||
Xoa_ttl ttl = page.Ttl();
|
||||
if (Xow_page_tid.Identify(domain_tid, ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext) // only parse page if wikitext; skip .js, .css, Module; DATE:2013-11-10
|
||||
parser.Parse_text_to_wdom(root, ctx, app.Tkn_mkr(), page.Data_raw(), Xop_parser_.Doc_bgn_bos);
|
||||
page.Root_(root);
|
||||
root.Data_htm_(root.Root_src());
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_files)) return file_mgr;
|
||||
else if (ctx.Match(k, Invk_xwikis)) return xwiki_mgr;
|
||||
else if (ctx.Match(k, Invk_stats)) return stats;
|
||||
else if (ctx.Match(k, Invk_props)) return props;
|
||||
else if (ctx.Match(k, Invk_cfg_gallery_)) return cfg_gallery;
|
||||
else if (ctx.Match(k, Invk_commons_wiki_)) commons_wiki_key = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_lang)) return lang;
|
||||
else if (ctx.Match(k, Invk_lang_)) lang = app.Lang_mgr().Get_by_key_or_new(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_html)) return html_mgr;
|
||||
else if (ctx.Match(k, Invk_gui)) return gui_mgr;
|
||||
else if (ctx.Match(k, Invk_cfg_history)) return cfg_history;
|
||||
else if (ctx.Match(k, Invk_user)) return user;
|
||||
else if (ctx.Match(k, Invk_data_mgr)) return data_mgr;
|
||||
else if (ctx.Match(k, Invk_ns_mgr)) return ns_mgr;
|
||||
else if (ctx.Match(k, Invk_sys_cfg)) return sys_cfg;
|
||||
else if (ctx.Match(k, Invk_special)) return special_mgr;
|
||||
else if (ctx.Match(k, Invk_parser)) return cfg_parser;
|
||||
else if (ctx.Match(k, Invk_msgs)) return msg_mgr;
|
||||
else if (ctx.Match(k, Invk_util)) return util;
|
||||
else if (ctx.Match(k, Invk_app)) return app;
|
||||
else if (ctx.Match(k, Invk_data_storage_format_))db_mgr.Data_storage_format_(m.ReadByte("v"));
|
||||
else if (ctx.Match(k, Invk_db_mgr)) return db_mgr;
|
||||
else if (ctx.Match(k, Invk_db_mgr_to_sql_)) this.Db_mgr_create_as_sql();
|
||||
else if (ctx.Match(k, Invk_import_mgr)) return import_mgr;
|
||||
else if (ctx.Match(k, Invk_maint)) return maint_mgr;
|
||||
else if (ctx.Match(k, Invk_domain)) return domain_str;
|
||||
else if (ctx.Match(k, Invk_xtns)) return xtn_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_ZipDirs = "zip_dirs_", Invk_files = "files", Invk_xwikis = "xwikis", Invk_cfg_gallery_ = "cfg_gallery_", Invk_commons_wiki_ = "commons_wiki_", Invk_stats = "stats"
|
||||
, Invk_lang = "lang", Invk_lang_ = "lang_", Invk_html = "html", Invk_gui = "gui", Invk_cfg_history = "cfg_history", Invk_user = "user", Invk_data_mgr = "data_mgr", Invk_sys_cfg = "sys_cfg", Invk_ns_mgr = "ns_mgr"
|
||||
, Invk_special = "special"
|
||||
, Invk_props = "props", Invk_parser = "parser"
|
||||
, Invk_msgs = "msgs", Invk_app = "app", Invk_util = "util"
|
||||
, Invk_xtns = "xtns", Invk_data_storage_format_ = "data_storage_format_", Invk_import_mgr = "import"
|
||||
, Invk_db_mgr = "db_mgr", Invk_db_mgr_to_sql_ = "db_mgr_to_sql_"
|
||||
, Invk_domain = "domain", Invk_maint = "maint"
|
||||
;
|
||||
public Xodb_mgr_sql Db_mgr_create_as_sql() {Xodb_mgr_sql rv = new Xodb_mgr_sql(this); db_mgr = rv; return rv;}
|
||||
public Xow_wiki Init_assert() {if (init_needed) Init_wiki(app.User()); return this;}
|
||||
private boolean init_in_process = false;
|
||||
private void Init_wiki(Xou_user user) { // NOTE: (a) one-time initialization for all wikis; (b) not called by tests
|
||||
if (init_in_process) {
|
||||
app.Usr_dlg().Log_many("", "", "wiki.init: circular call canceled: ~{0}", domain_str);
|
||||
return; // NOTE: may be called multiple times due to "if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false;"; TODO: call this only once; DATE:2014-06-07
|
||||
}
|
||||
init_in_process = true;
|
||||
if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false; // NOTE: only mark inited if app fully launched; otherwise statements in xowa.gfs can fire and prematurely set home to inited; DATE:2013-03-24
|
||||
Gfo_log_bfr log_bfr = app.Log_bfr();
|
||||
log_bfr.Add("wiki.init.bgn: " + domain_str);
|
||||
app.Cfg_mgr().Init(this);
|
||||
file_mgr.Cfg_download().Enabled_(app.File_mgr().Download_mgr().Enabled()); // default download to app global; can be overriden below
|
||||
Io_url sqlite_url = Xodb_mgr_sql.Find_core_url(this);
|
||||
if (sqlite_url != null) {
|
||||
Xodb_mgr_sql db_mgr_sql = this.Db_mgr_create_as_sql();
|
||||
db_mgr_sql.Init_load(gplx.dbs.Db_connect_.sqlite_(sqlite_url));
|
||||
}
|
||||
db_mgr.Load_mgr().Load_init(this);
|
||||
app.Gfs_mgr().Run_url_for(this, fsys_mgr.Cfg_wiki_core_fil());
|
||||
gplx.xowa.utls.upgrades.Xoa_upgrade_mgr.Check(this);
|
||||
app.Gfs_mgr().Run_url_for(this, fsys_mgr.Cfg_wiki_stats_fil());
|
||||
app.Gfs_mgr().Run_url_for(this, user.Fsys_mgr().Wiki_root_dir().GenSubFil_nest("#cfg", "system", domain_str + ".gfs")); // run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
|
||||
fsys_mgr.Scan_dirs();
|
||||
if (lang.Init_by_load()) {
|
||||
if (domain_tid == Xow_wiki_domain_.Tid_wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; EX.WP: pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
|
||||
ns_mgr.Aliases_add(Xow_ns_.Id_project, Xow_ns_.Ns_name_wikipedia);
|
||||
}
|
||||
cfg_parser.Xtns().Itm_pages().Init(ns_mgr); // init ns_mgr for Page / Index ns just before rebuild; usually set by #cfg file
|
||||
Xow_ns_mgr_.rebuild_(lang, ns_mgr); // always rebuild; may be changed by user_wiki.gfs; different lang will change namespaces; EX: de.wikisource.org will have Seite for File and none of {{#lst}} will work
|
||||
fragment_mgr.Evt_lang_changed(lang);
|
||||
parser.Init_by_lang(lang);
|
||||
html_mgr.Init_by_lang(lang);
|
||||
lang.Vnt_mgr().Init_by_wiki(this);
|
||||
Bry_fmtr.Null.Eval_mgr().Enabled_(false);
|
||||
app.Wiki_mgr().Scripts().Exec(this);
|
||||
Bry_fmtr.Null.Eval_mgr().Enabled_(true);
|
||||
app.Wiki_mgr().Css_installer().Install_assert(this, user.Fsys_mgr().Wiki_html_dir(domain_str));
|
||||
html_mgr.Init_by_wiki(this);
|
||||
this.Copy_cfg(app.User().Wiki());
|
||||
File_repos_assert(app, this);
|
||||
xtn_mgr.Init_by_wiki(this);
|
||||
log_bfr.Add("wiki.init.end");
|
||||
app.Log_wtr().Log_msg_to_session_direct(log_bfr.Xto_str());
|
||||
init_in_process = false;
|
||||
}
|
||||
public void Rls() {
|
||||
if (rls_list == null) return;
|
||||
int len = rls_list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
RlsAble rls = (RlsAble)rls_list.FetchAt(i);
|
||||
rls.Rls();
|
||||
}
|
||||
}
|
||||
private void Copy_cfg(Xow_wiki wiki) {html_mgr.Copy_cfg(wiki.Html_mgr());}
|
||||
private static void File_repos_assert(Xoa_app app, Xow_wiki wiki) {
|
||||
byte[] wiki_key = wiki.Domain_bry();
|
||||
Xoa_repo_mgr repo_mgr = app.File_mgr().Repo_mgr();
|
||||
Xof_repo_itm repo_itm = repo_mgr.Get_by(wiki_key);
|
||||
if (repo_itm == null) {
|
||||
repo_itm = new Xof_repo_itm(repo_mgr, wiki_key).Wiki_key_(wiki_key);
|
||||
repo_mgr.Add(repo_itm);
|
||||
}
|
||||
Xow_repo_mgr pair_mgr = wiki.File_mgr().Repo_mgr();
|
||||
if (pair_mgr.Repos_len() == 0) {
|
||||
Xof_repo_itm repo_src = repo_mgr.Get_by(File_repo_xowa_null);
|
||||
if (repo_src == null) {
|
||||
repo_itm = new Xof_repo_itm(repo_mgr, File_repo_xowa_null).Wiki_key_(Xow_wiki_domain_.Key_home_bry);
|
||||
repo_mgr.Add(repo_itm);
|
||||
}
|
||||
pair_mgr.Add_repo(File_repo_xowa_null, wiki_key);
|
||||
}
|
||||
} static byte[] File_repo_xowa_null = Bry_.new_ascii_("xowa_repo_null");
|
||||
}
|
||||
28
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_.java
Normal file
28
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_.java
Normal 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 Xow_wiki_ {
|
||||
public static final String
|
||||
Domain_commons_str = "commons.wikimedia.org"
|
||||
, Domain_enwiki_str = "en.wikipedia.org"
|
||||
;
|
||||
public static final byte[]
|
||||
Domain_commons_bry = Bry_.new_ascii_(Domain_commons_str)
|
||||
, Domain_en_wiki_bry = Bry_.new_ascii_(Domain_enwiki_str)
|
||||
;
|
||||
}
|
||||
64
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_props.java
Normal file
64
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_props.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
public class Xow_wiki_props implements GfoInvkAble {
|
||||
public byte[] SiteName() {return siteName;} public Xow_wiki_props SiteName_(byte v) {siteName = Bry_.new_ascii_(String_.UpperFirst(String_.new_ascii_(Xow_wiki_domain_.Key_by_tid(v)))); return this;} private byte[] siteName = Bry_.Empty;
|
||||
public byte[] ServerName() {return serverName;} public Xow_wiki_props ServerName_(byte[] v) {serverName = v; server = Bry_.Add(bry_http, v); return this;} private byte[] serverName = Bry_.new_ascii_("localhost");
|
||||
public byte[] Server() {return server;} private byte[] server = Bry_.new_ascii_("http://localhost"); static final byte[] bry_http = Bry_.new_ascii_("http://");
|
||||
public byte[] ArticlePath() {return articlePath;} public Xow_wiki_props ArticlePath_(byte[] v) {articlePath = v; return this;} private byte[] articlePath = Xoh_href_parser.Href_wiki_bry;
|
||||
public byte[] ScriptPath() {return scriptPath;} public Xow_wiki_props ScriptPath_(byte[] v) {scriptPath = v; return this;} private byte[] scriptPath = Bry_.new_ascii_("/wiki");
|
||||
public byte[] StylePath() {return stylePath;} public Xow_wiki_props StylePath_(byte[] v) {stylePath = v; return this;} private byte[] stylePath = Bry_.new_ascii_("/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[] CurrentVersion() {return MediaWiki_version;}
|
||||
public byte[] Main_page() {return main_page;}
|
||||
public Xow_wiki_props Main_page_(byte[] v) {main_page = v; return this;} 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 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 void Main_page_update(Xow_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 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)
|
||||
siteName = Bry_.Mid(siteinfo_misc, 0, pipe_0);
|
||||
return this;
|
||||
} private byte[] siteinfo_misc = Bry_.Empty;
|
||||
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_"
|
||||
;
|
||||
public static final byte[] MediaWiki_version = Bry_.new_ascii_("1.21wmf11"); // approximate level of compatibility
|
||||
}
|
||||
44
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_stats.java
Normal file
44
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_stats.java
Normal 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(Xow_wiki wiki) {this.wiki = wiki;} private Xow_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;
|
||||
}
|
||||
}
|
||||
41
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_tst.java
Normal file
41
400_xowa/src_120_wiki/gplx/xowa/Xow_wiki_tst.java
Normal 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 GetPageByTtl() { // 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) {
|
||||
Xow_wiki wiki = fxt.Wiki();
|
||||
byte[] ttl_bry = Bry_.new_ascii_(ttl_str);
|
||||
Xoa_url url = new Xoa_url().Raw_(ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
Xoa_page actl = fxt.Wiki().GetPageByTtl(url, ttl);
|
||||
if (expd == null) Tfds.Eq_true(actl.Missing());
|
||||
else Tfds.Eq(expd, String_.new_utf8_(actl.Ttl().Raw()));
|
||||
}
|
||||
}
|
||||
30
400_xowa/src_120_wiki/gplx/xowa/Xow_xwiki_itm.java
Normal file
30
400_xowa/src_120_wiki/gplx/xowa/Xow_xwiki_itm.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xow_xwiki_itm implements gplx.CompareAble {
|
||||
public Xow_xwiki_itm(byte[] key, byte[] fmt, byte wiki_tid, int lang_id, byte[] domain) {this.key = key; this.fmt = fmt; this.wiki_tid = wiki_tid; this.lang_id = lang_id; this.domain = domain; this.key_str = String_.new_utf8_(key);}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public String Key_str() {return key_str;} private String key_str;
|
||||
public byte[] Fmt() {return fmt;} private byte[] fmt;
|
||||
public byte[] Domain() {return domain;} private byte[] domain;
|
||||
public byte Wiki_tid() {return wiki_tid;} private byte wiki_tid;
|
||||
public int Lang_id() {return lang_id;} private int lang_id;
|
||||
public boolean Type_is_lang(int cur_lang_id) {return lang_id != Xol_lang_itm_.Id__unknown && cur_lang_id != lang_id && Bry_.Len_gt_0(fmt);}
|
||||
public boolean Offline() {return offline;} public Xow_xwiki_itm Offline_(boolean v) {offline = v; return this;} private boolean offline;
|
||||
public int compareTo(Object obj) {Xow_xwiki_itm comp = (Xow_xwiki_itm)obj; return Bry_.Compare(key, comp.key);}
|
||||
}
|
||||
185
400_xowa/src_120_wiki/gplx/xowa/Xow_xwiki_mgr.java
Normal file
185
400_xowa/src_120_wiki/gplx/xowa/Xow_xwiki_mgr.java
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
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_xwiki_mgr implements GfoInvkAble {
|
||||
public Xow_xwiki_mgr(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki;
|
||||
public Xow_lang_mgr Lang_mgr() {return lang_mgr;} private Xow_lang_mgr lang_mgr = Xow_lang_mgr.dflt_();
|
||||
public int Len() {return list.Count();} private OrderedHash list = OrderedHash_.new_bry_(); Hash_adp_bry hash = Hash_adp_bry.ci_();
|
||||
public void Clear() {hash.Clear(); list.Clear();}
|
||||
public Xow_xwiki_itm Get_at(int i) {return (Xow_xwiki_itm)list.FetchAt(i);}
|
||||
public Xow_xwiki_itm Get_by_key(byte[] key) {return (Xow_xwiki_itm)hash.Get_by_bry(key);}
|
||||
public Xow_xwiki_itm Get_by_mid(byte[] src, int bgn, int end) {return (Xow_xwiki_itm)hash.Get_by_mid(src, bgn, end);}
|
||||
public void Add_full(String alias, String domain) {Add_full(Bry_.new_ascii_(alias), Bry_.new_ascii_(domain), null);}
|
||||
public void Add_full(byte[] alias, byte[] domain) {Add_full(alias, domain, null);}
|
||||
public void Add_full(byte[] alias, byte[] domain, byte[] fmt) {
|
||||
byte wiki_tid = Byte_.Zero;
|
||||
int lang_tid = -1;
|
||||
Xow_wiki_domain wiki_type = Xow_wiki_domain_.parse_by_domain(domain);
|
||||
wiki_tid = wiki_type.Tid();
|
||||
if (Bry_.Len_gt_0(wiki_type.Lang())) { // domain has lang (EX: "en.")
|
||||
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang());
|
||||
if (lang_itm == null) return; // unknown lang: do not add to wiki collection; EX: en1.wikipedia.org
|
||||
lang_tid = lang_itm.Id();
|
||||
}
|
||||
Xow_xwiki_itm itm = new Xow_xwiki_itm(alias, fmt, wiki_tid, lang_tid, domain);
|
||||
Add_itm(itm, null);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_count)) return list.Count();
|
||||
else if (ctx.Match(k, Invk_add_bulk)) Add_bulk(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_add_bulk_langs)) Add_bulk_langs(m);
|
||||
else if (ctx.Match(k, Invk_add_bulk_peers)) Add_bulk_peers(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_itms_print)) return Exec_itms_print(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_clear)) this.Clear();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_add_bulk = "add_bulk", Invk_add_bulk_langs = "add_bulk_langs", Invk_add_bulk_peers = "add_bulk_peers", Invk_itms_print = "itms_print", Invk_count = "count", Invk_clear = "clear";
|
||||
public void Sort_by_key() {
|
||||
list.Sort();
|
||||
}
|
||||
public void Add_bulk(byte[] raw) {
|
||||
byte[][] rows = Bry_.Split(raw, Byte_ascii.NewLine);
|
||||
int rows_len = rows.length;
|
||||
Hash_adp_bry lang_regy = Xol_lang_itm_.Regy();
|
||||
for (int i = 0; i < rows_len; i++) {
|
||||
byte[] row = rows[i]; if (Bry_.Len_eq_0(row)) continue; // ignore blank rows
|
||||
Xow_xwiki_itm itm = Add_bulk_row(lang_regy, row);
|
||||
Add_itm(itm, null);
|
||||
}
|
||||
}
|
||||
public Xow_xwiki_itm Add_bulk_row(Hash_adp_bry lang_regy, byte[] row) {
|
||||
byte[][] flds = Bry_.Split(row, Byte_ascii.Pipe); int flds_len = flds.length;
|
||||
byte[] alias = Bry_.Empty, wiki_type_bry = Bry_.Empty;
|
||||
for (int j = 0; j < flds_len; j++) {
|
||||
byte[] fld = flds[j];
|
||||
switch (j) {
|
||||
case 0: alias = fld; break;
|
||||
case 1: wiki_type_bry = fld; break;
|
||||
case 2: break; // reserved for 0,1 (0=custom; 1=wmf)
|
||||
default: throw Err_mgr._.unhandled_(j);
|
||||
}
|
||||
}
|
||||
Xow_wiki_domain wiki_type = Xow_wiki_domain_.parse_by_domain(wiki_type_bry);
|
||||
int lang_tid = Xol_lang_itm_.Id__unknown;
|
||||
if (Bry_.Len_gt_0(wiki_type.Lang())) {
|
||||
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang());
|
||||
if (lang_itm != null // lang exists
|
||||
&& Bry_.Eq(alias, lang_itm.Key())) // alias == lang.key; only assign langs to aliases that have lang key; EX: w|en.wikipedia.org; "w" alias should not be registered for "en"; DATE:2013-07-25
|
||||
lang_tid = lang_itm.Id();
|
||||
}
|
||||
return new Xow_xwiki_itm(alias, Bry_.Add(Xoh_href_parser.Href_http_bry, wiki_type_bry, Xoh_href_parser.Href_wiki_bry, Arg_0), wiki_type.Tid(), lang_tid, wiki_type_bry);
|
||||
} static final byte[] Arg_0 = Bry_.new_ascii_("~{0}");
|
||||
String Exec_itms_print(byte[] raw) {
|
||||
Bry_fmtr fmtr = Bry_fmtr.new_bry_(raw, "wiki_key");//, "wiki_type_url", "wiki_lang", "wiki_name", "wiki_logo_url");
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
|
||||
Hash_adp_bry seen = Hash_adp_bry.ci_();
|
||||
int wikis_len = list.Count();
|
||||
for (int i = 0; i < wikis_len; i++) {
|
||||
Xow_xwiki_itm itm = (Xow_xwiki_itm)list.FetchAt(i);
|
||||
byte[] key = itm.Key();
|
||||
if (Bry_.Eq(key, Xow_wiki_domain_.Key_home_bry)) continue; // skip home
|
||||
byte[] domain = itm.Domain();
|
||||
if (seen.Has(domain)) continue;
|
||||
seen.AddKeyVal(domain);
|
||||
fmtr.Bld_bfr_many(tmp_bfr, key);
|
||||
}
|
||||
return tmp_bfr.Mkr_rls().XtoStrAndClear();
|
||||
}
|
||||
public void Add_bulk_peers(byte[] raw) {
|
||||
byte[][] keys = Bry_.Split(raw, Byte_ascii.Tilde);
|
||||
int len = keys.length;
|
||||
OrderedHash peers = OrderedHash_.new_();
|
||||
Cfg_nde_root peer_root = wiki.App().Wiki_mgr().Groups();
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] key = keys[i];
|
||||
Cfg_nde_obj peer_grp = peer_root.Grps_get(key);
|
||||
if (peer_grp == null)
|
||||
throw Err_mgr._.fmt_(GRP_KEY, "invalid_peer", "unknown peer group: ~{0}", String_.new_utf8_(key));
|
||||
else
|
||||
Cfg_nde_obj_.Fill_recurse(peers, peer_grp);
|
||||
}
|
||||
|
||||
len = peers.Count();
|
||||
byte[] lang_key_bry = wiki.Lang().Key_bry();
|
||||
if (lang_key_bry == Xol_lang_itm_.Key__unknown) lang_key_bry = Xol_lang_.Key_en; // default non-lang wikis to english
|
||||
String lang_key_str = String_.new_utf8_(lang_key_bry);
|
||||
int lang_id = Xol_lang_itm_.Get_by_key(lang_key_bry).Id();
|
||||
byte wiki_tid = wiki.Domain_tid();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoac_wiki_itm wiki_itm = (Xoac_wiki_itm)peers.FetchAt(i);
|
||||
byte[] wiki_name_bry = wiki_itm.Key_bry();
|
||||
String wiki_name = String_.new_utf8_(wiki_name_bry);
|
||||
String domain_str = null;
|
||||
byte xwiki_tid_val = Xow_wiki_domain_.Tid_by_key(wiki_name_bry);
|
||||
switch (xwiki_tid_val) {
|
||||
case Xow_wiki_domain_.Tid_commons:
|
||||
case Xow_wiki_domain_.Tid_species:
|
||||
case Xow_wiki_domain_.Tid_meta:
|
||||
case Xow_wiki_domain_.Tid_incubator: domain_str = String_.Format("{0}.wikimedia.org", wiki_name); break; // EX: commons.wikimedia.org
|
||||
case Xow_wiki_domain_.Tid_wikidata: domain_str = String_.Format("www.wikidata.org", wiki_name); break; // EX: www.wikidata.org
|
||||
case Xow_wiki_domain_.Tid_mediawiki: domain_str = String_.Format("www.mediawiki.org", wiki_name); break;
|
||||
case Xow_wiki_domain_.Tid_wikimediafoundation: domain_str = String_.Format("wikimediafoundation.org", wiki_name); break;
|
||||
default: domain_str = String_.Format("{0}.{1}.org", lang_key_str, wiki_name); break; // EX: en.wiktionary.org
|
||||
}
|
||||
byte[] domain_bry = Bry_.new_utf8_(domain_str);
|
||||
Xow_wiki lang_wiki = wiki.App().Wiki_mgr().Get_by_key_or_null(domain_bry);
|
||||
boolean offline_exists = lang_wiki != null;
|
||||
String fmt = String_.Format("http://" + domain_str + "/wiki/~{0}");
|
||||
int aliases_len = wiki_itm.Aliases().length;
|
||||
for (int j = 0; j < aliases_len; j++) {
|
||||
byte[] alias = wiki_itm.Aliases()[j];
|
||||
if (wiki.Ns_mgr().Names_get_or_null(alias, 0, alias.length) != null) continue; // NOTE: do not add xwiki if alias matches namespace; EX: en.wiktionary.org has ns of "Wiktionary"; do not add alias of "wiktionary"; note that wikipedia does have an alias to wiktionary
|
||||
Xow_xwiki_itm xwiki = new Xow_xwiki_itm(alias, Bry_.new_utf8_(fmt), wiki_tid, lang_id, domain_bry).Offline_(offline_exists);
|
||||
Add_itm(xwiki, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Add_bulk_langs(GfoMsg m) {
|
||||
byte[] grp_key = m.ReadBry("grp_key");
|
||||
byte[] wiki_type_name = m.ReadBryOr("wiki_type_name", null);
|
||||
byte wiki_tid = wiki_type_name == null ? wiki.Domain_tid() : Xow_wiki_domain_.Tid_by_key(wiki_type_name);
|
||||
Add_bulk_langs(grp_key, wiki_tid);
|
||||
}
|
||||
public void Add_bulk_langs(byte[] grp_key) {Add_bulk_langs(grp_key, wiki.Domain_tid());}
|
||||
private void Add_bulk_langs(byte[] grp_key, byte wiki_tid) {
|
||||
OrderedHash langs = wiki.App().Lang_mgr().Xto_hash(grp_key);
|
||||
int len = langs.Count();
|
||||
byte[] wiki_tid_name = Xow_wiki_domain_.Key_by_tid(wiki_tid);
|
||||
String wiki_tid_name_str = String_.new_utf8_(wiki_tid_name);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoac_lang_itm lang = (Xoac_lang_itm)langs.FetchAt(i);
|
||||
String domain_str = String_.Format("{0}.{1}.org", String_.new_utf8_(lang.Key_bry()), wiki_tid_name_str); // EX: fr.wikipedia.org
|
||||
byte[] domain_bry = Bry_.new_utf8_(domain_str);
|
||||
Xow_wiki lang_wiki = wiki.App().Wiki_mgr().Get_by_key_or_null(domain_bry);
|
||||
boolean offline_exists = lang_wiki != null;
|
||||
String fmt = String_.Format("http://" + domain_str + "/wiki/~{0}");
|
||||
int lang_id = Xol_lang_itm_.Get_by_key(lang.Key_bry()).Id();
|
||||
Xow_xwiki_itm xwiki = new Xow_xwiki_itm(lang.Key_bry(), Bry_.new_utf8_(fmt), wiki_tid, lang_id, domain_bry).Offline_(offline_exists);
|
||||
Add_itm(xwiki, lang);
|
||||
}
|
||||
lang_mgr.Grps_sort();
|
||||
} private static final String GRP_KEY = "xowa.wiki.xwikis";
|
||||
private void Add_itm(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
|
||||
if ( !hash.Has(xwiki.Key()) // only register xwiki / lang pair once
|
||||
&& lang != null) // null lang should not be registered
|
||||
lang_mgr.Itms_reg(xwiki, lang);
|
||||
hash.AddReplace(xwiki.Key(), xwiki);
|
||||
list.AddReplace(xwiki.Key(), xwiki);
|
||||
}
|
||||
}
|
||||
124
400_xowa/src_120_wiki/gplx/xowa/Xow_xwiki_mgr_tst.java
Normal file
124
400_xowa/src_120_wiki/gplx/xowa/Xow_xwiki_mgr_tst.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
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.*; import gplx.xowa.langs.*;
|
||||
public class Xow_xwiki_mgr_tst {
|
||||
Xow_xwiki_mgr_fxt fxt = new Xow_xwiki_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Add_bulk_wiki_en() {fxt.Tst_add_bulk("w|en.wikipedia.org" , Xol_lang_itm_.Id__unknown , Xow_wiki_domain_.Tid_wikipedia , "w" , "http://en.wikipedia.org/wiki/~{0}", "en.wikipedia.org");}
|
||||
@Test public void Add_bulk_wiki_fr() {fxt.Tst_add_bulk("fr|fr.wikipedia.org" , Xol_lang_itm_.Id_fr , Xow_wiki_domain_.Tid_wikipedia , "fr" , "http://fr.wikipedia.org/wiki/~{0}", "fr.wikipedia.org");}
|
||||
@Test public void Add_bulk_wikt_en() {fxt.Tst_add_bulk("wikt|en.wiktionary.org" , Xol_lang_itm_.Id__unknown , Xow_wiki_domain_.Tid_wiktionary , "wikt" , "http://en.wiktionary.org/wiki/~{0}", "en.wiktionary.org");}
|
||||
@Test public void Add_bulk_commons() {fxt.Tst_add_bulk("commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_wiki_domain_.Tid_commons , "commons" , "http://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
|
||||
@Test public void Add_bulk_commons_cap() {fxt.Tst_add_bulk("Commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_wiki_domain_.Tid_commons , "Commons" , "http://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
|
||||
@Test public void Add_bulk_langs_wiki() {fxt.Langs_ini().Tst_add_bulk_langs("wiki", fxt.xwiki_("en", "en.wikipedia.org", "http://en.wikipedia.org/wiki/~{0}"), fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
|
||||
@Test public void Add_bulk_langs_grps() {fxt.Langs_ini().Tst_add_bulk_langs("europe_west~asia_east", fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
|
||||
@Test public void Add_bulk_langs_grp_itm() {fxt.Langs_ini().Tst_add_bulk_langs("europe_west~ja", fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
|
||||
@Test public void Add_bulk_langs_grp_commons() {
|
||||
fxt.Langs_ini();
|
||||
GfoInvkAble_.InvkCmd_msg(fxt.Wiki().Xwiki_mgr(), Xow_xwiki_mgr.Invk_add_bulk_langs, GfoMsg_.new_parse_(Xow_xwiki_mgr.Invk_add_bulk_langs).Add("grp_key", "europe_west").Add("wiki_type_name", "wikipedia"));
|
||||
fxt.Tst_itms(fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"));
|
||||
}
|
||||
@Test public void Add_bulk_peers() {fxt.Peers_ini().Tst_add_bulk_peers("peer", fxt.xwiki_null_("commons"), fxt.xwiki_null_("m"), fxt.xwiki_("wikt", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("wiktionary", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("s", "en.wikisource.org", "http://en.wikisource.org/wiki/~{0}"));}
|
||||
@Test public void Add_bulk_peers_skip_self() {fxt.Peers_ini().Tst_add_bulk_peers("peer", fxt.xwiki_null_("wikipedia"), fxt.xwiki_("w", "en.wikipedia.org", "http://en.wikipedia.org/wiki/~{0}"));} // PURPOSE: skip "wikipedia" as alias since "Wikipedia" is namespace; needed for titles of "Wikipedia:Main page" (which would otherwise try to go to page "Main Page" in the main names of xwiki "Wikipedia"
|
||||
@Test public void Add_bulk_core_wikidata() {fxt.Peers_ini().Tst_add_bulk_peers("core", fxt.xwiki_("d", "www.wikidata.org", "http://www.wikidata.org/wiki/~{0}"));}
|
||||
}
|
||||
class Xow_xwiki_mgr_fxt {
|
||||
Xow_xwiki_mgr xwiki_mgr; Xoa_lang_mgr lang_mgr; String_bldr sb = String_bldr_.new_(); Xoa_app app; Xow_wiki wiki;
|
||||
public void Clear() {
|
||||
if (xwiki_mgr == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
xwiki_mgr = wiki.Xwiki_mgr();
|
||||
lang_mgr = app.Lang_mgr();
|
||||
}
|
||||
xwiki_mgr.Clear();
|
||||
lang_mgr.Clear();
|
||||
}
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
public Xow_xwiki_itm xwiki_null_(String key) {return new Xow_xwiki_itm(Bry_.new_utf8_(key), Bry_.Empty, Xow_wiki_domain_.Tid_other, Xol_lang_itm_.Id__unknown, Bry_.Empty);}
|
||||
public Xow_xwiki_itm xwiki_(String key, String domain, String fmt) {return new Xow_xwiki_itm(Bry_.new_utf8_(key), Bry_.new_utf8_(fmt), Xow_wiki_domain_.Tid_other, Xol_lang_itm_.Id__unknown, Bry_.new_utf8_(domain));}
|
||||
public Xow_xwiki_mgr_fxt Tst_add_bulk(String raw, int lang_tid, byte wiki_tid, String alias, String fmt, String domain) {
|
||||
Xow_xwiki_itm itm = xwiki_mgr.Add_bulk_row(Xol_lang_itm_.Regy(), Bry_.new_ascii_(raw));
|
||||
Tfds.Eq(alias, String_.new_ascii_(itm.Key()));
|
||||
Tfds.Eq(fmt, String_.new_ascii_(itm.Fmt()));
|
||||
Tfds.Eq(wiki_tid, itm.Wiki_tid(), "wiki_tid");
|
||||
Tfds.Eq(lang_tid, itm.Lang_id(), "lang_id");
|
||||
return this;
|
||||
}
|
||||
public Xow_xwiki_mgr_fxt Langs_ini() {
|
||||
lang_mgr.Groups().Set_bulk(Bry_.new_utf8_(String_.Concat_lines_nl
|
||||
( "+||grp|wiki"
|
||||
, "+|wiki|grp|english"
|
||||
, "+|wiki|grp|europe_west"
|
||||
, "+|wiki|grp|asia_east"
|
||||
, "+|english|itm|en|English"
|
||||
, "+|europe_west|itm|fr|French"
|
||||
, "+|europe_west|itm|de|German"
|
||||
, "+|asia_east|itm|ja|Japanese"
|
||||
)));
|
||||
return this;
|
||||
}
|
||||
public Xow_xwiki_mgr_fxt Peers_ini() {
|
||||
app.Wiki_mgr().Groups().Set_bulk(Bry_.new_utf8_(String_.Concat_lines_nl
|
||||
( "+|core|itm|commons|commons"
|
||||
, "+|core|itm|meta|meta;m"
|
||||
, "+|core|itm|wikidata|d"
|
||||
, "+|peer|itm|wiktionary|wikt;wiktionary"
|
||||
, "+|peer|itm|wikisource|s"
|
||||
, "+|peer|itm|wikipedia|w;wikipedia"
|
||||
)));
|
||||
return this;
|
||||
}
|
||||
public Xow_xwiki_mgr_fxt Tst_add_bulk_langs(String langs, Xow_xwiki_itm... itms) {
|
||||
xwiki_mgr.Add_bulk_langs(Bry_.new_utf8_(langs));
|
||||
Tfds.Eq_str_lines(Xto_str(itms), Xto_str(Xto_ary(itms)));
|
||||
return this;
|
||||
}
|
||||
public Xow_xwiki_mgr_fxt Tst_add_bulk_peers(String exclude, Xow_xwiki_itm... itms) {
|
||||
xwiki_mgr.Add_bulk_peers(Bry_.new_utf8_(exclude));
|
||||
Tfds.Eq_str_lines(Xto_str(itms), Xto_str(Xto_ary(itms)));
|
||||
return this;
|
||||
}
|
||||
public Xow_xwiki_mgr_fxt Tst_itms(Xow_xwiki_itm... itms) {
|
||||
Tfds.Eq_str_lines(Xto_str(itms), Xto_str(Xto_ary(itms)));
|
||||
return this;
|
||||
}
|
||||
Xow_xwiki_itm[] Xto_ary(Xow_xwiki_itm[] itms) {
|
||||
int len = itms.length;
|
||||
ListAdp rv = ListAdp_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] alias = itms[i].Key();
|
||||
Xow_xwiki_itm itm = xwiki_mgr.Get_by_key(alias);
|
||||
if (itm == null) itm = xwiki_null_(String_.new_utf8_(alias)); // "null", ignore
|
||||
rv.Add(itm);
|
||||
}
|
||||
return (Xow_xwiki_itm[])rv.XtoAry(Xow_xwiki_itm.class);
|
||||
}
|
||||
String Xto_str(Xow_xwiki_itm[] itms) {
|
||||
int len = itms.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_xwiki_itm itm = itms[i];
|
||||
if (Bry_.Len_eq_0(itm.Domain())) // "null", ignore
|
||||
sb.Add(itm.Key()).Add_char_nl();
|
||||
else {
|
||||
sb.Add(itm.Key()).Add_char_pipe().Add(itm.Domain()).Add_char_pipe().Add(itm.Fmt()).Add_char_nl();
|
||||
}
|
||||
}
|
||||
return sb.XtoStrAndClear();
|
||||
}
|
||||
}
|
||||
32
400_xowa/src_120_wiki/gplx/xowa/Xowc_parser.java
Normal file
32
400_xowa/src_120_wiki/gplx/xowa/Xowc_parser.java
Normal 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.parsers.lnkis.cfgs.*;
|
||||
public class Xowc_parser implements GfoInvkAble {
|
||||
public Xowc_parser(Xow_wiki wiki) {
|
||||
lnki_cfg = new Xoc_lnki_cfg(wiki);
|
||||
}
|
||||
public boolean Flag_xtns_pages_init() {return flag_xtns_pages_init;} public Xowc_parser Flag_xtns_pages_init_(boolean v) {flag_xtns_pages_init = v; return this;} private boolean flag_xtns_pages_init = true;
|
||||
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 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 return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_xtns = "xtns", Invk_lnki = "lnki";
|
||||
}
|
||||
80
400_xowa/src_120_wiki/gplx/xowa/Xowc_xtn_pages.java
Normal file
80
400_xowa/src_120_wiki/gplx/xowa/Xowc_xtn_pages.java
Normal 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();
|
||||
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_ascii_(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_ascii_("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_ascii_("Page")
|
||||
, Default_ns_page_talk_name = Bry_.new_ascii_("Page_talk")
|
||||
, Default_ns_index_name = Bry_.new_ascii_("Index")
|
||||
, Default_ns_index_talk_name = Bry_.new_ascii_("Index_talk")
|
||||
;
|
||||
}
|
||||
65
400_xowa/src_120_wiki/gplx/xowa/Xowc_xtn_pages_tst.java
Normal file
65
400_xowa/src_120_wiki/gplx/xowa/Xowc_xtn_pages_tst.java
Normal 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_();
|
||||
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_ascii_(page_name), Bry_.new_ascii_(page_talk_name), Bry_.new_ascii_(index_name), Bry_.new_ascii_(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_ascii_(name));
|
||||
int actl_ns_id = ns == null ? Int_.MinValue : ns.Id();
|
||||
Tfds.Eq(expd_ns_id, actl_ns_id);
|
||||
}
|
||||
}
|
||||
28
400_xowa/src_120_wiki/gplx/xowa/Xowc_xtns.java
Normal file
28
400_xowa/src_120_wiki/gplx/xowa/Xowc_xtns.java
Normal 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_();
|
||||
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";
|
||||
}
|
||||
Reference in New Issue
Block a user