1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-09-20 23:43:51 -04:00
parent 5fe27b5b3b
commit fa70c05354
1056 changed files with 8375 additions and 7095 deletions

View File

@@ -16,7 +16,8 @@ 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.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.php.*; import gplx.xowa.parsers.*;
import gplx.langs.phps.*; import gplx.xowa.parsers.*;
import gplx.xowa.apps.gfss.*;
public class Xol_msg_mgr_ {
// public static String Get_msg_val_gui_or_null(Xol_lang lang, byte[] pre, byte[] key, byte[] suf) {
// String rv = Get_msg_val_gui_or_null(lang, pre, key, suf);
@@ -58,13 +59,13 @@ public class Xol_msg_mgr_ {
if (has_tmpl) {
Xop_ctx sub_ctx = Xop_ctx.new_sub_(wiki); Xop_tkn_mkr tkn_mkr = sub_ctx.Tkn_mkr();
Xop_root_tkn sub_root = tkn_mkr.Root(msg_val);
msg_val = wiki.Parser().Parse_text_to_wtxt(sub_root, sub_ctx, tkn_mkr, msg_val);
msg_val = wiki.Parser_mgr().Main().Parse_text_to_wtxt(sub_root, sub_ctx, tkn_mkr, msg_val);
}
return msg_val;
}
public static Xol_msg_itm Get_msg_itm(Bry_bfr tmp_bfr, Xowe_wiki wiki, Xol_lang lang, byte[] msg_key) {
byte[] msg_key_sub_root = msg_key;
int slash_pos = Bry_finder.Find_bwd(msg_key, Byte_ascii.Slash);
int slash_pos = Bry_find_.Find_bwd(msg_key, Byte_ascii.Slash);
if (slash_pos != Bry_.NotFound) { // key is of format "key/lang"; EX: "January/en"
int msg_key_len = msg_key.length;
if (slash_pos != msg_key_len) { // get text after slash; EX: "en"
@@ -93,7 +94,7 @@ public class Xol_msg_mgr_ {
}
}
else { // page found; dump entire contents
msg_val = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, msg_page.Data_raw()); // note that MediaWiki msg's use php arg format ($1); xowa.gfs msgs are already converted
msg_val = Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, msg_page.Data_raw()); // note that MediaWiki msg's use php arg format ($1); xowa.gfs msgs are already converted
msg_in_wiki.Src_(Xol_msg_itm.Src_wiki);
}
Xol_msg_itm_.update_val_(msg_in_wiki, msg_val);

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Xow_mainpage_finder {
public static byte[] Find_or(Xowe_wiki wiki, byte[] or) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
Xol_msg_itm msg_itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), Msg_mainpage);
byte[] rv = msg_itm.Src_is_missing()
? or
: Xol_msg_mgr_.Get_msg_val(tmp_bfr, wiki, msg_itm, Bry_.Ary_empty)
;
tmp_bfr.Mkr_rls();
return rv;
}
public static final byte[] Msg_mainpage = Bry_.new_a7("mainpage");
}

View File

@@ -0,0 +1,73 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*;
public class Xow_mainpage_finder_tst {
@Before public void init() {fxt.Clear();} private Xow_mainpage_finder_fxt fxt = new Xow_mainpage_finder_fxt();
@Test public void Mediawiki() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Lang() {
fxt.Init_lang("Mainpage_by_lang");
fxt.Test_mainpage("Mainpage_by_lang");
}
@Test public void Siteinfo() {
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_siteinfo");
}
@Test public void Lang_and_siteinfo() {
fxt.Init_lang("Mainpage_by_lang");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_lang");
}
@Test public void Mediawiki_and_siteinfo() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Mediawiki_and_lang_and_siteinfo() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Init_lang("Mainpage_by_lang");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Mediawiki_tmpl() { // PURPOSE: de.wiktionary.org has "{{ns:project}}:Hauptseite"; DATE:2013-07-07
fxt.Init_mediawiki_page("{{ns:project}}:Hauptseite");
fxt.Test_mainpage("Wikipedia:Hauptseite");
}
}
class Xow_mainpage_finder_fxt {
public void Clear() {
fxt.Reset_for_msgs();
} private Xop_fxt fxt = new Xop_fxt();
public void Init_siteinfo(String mainpage_val) {
fxt.Wiki().Props().Main_page_(Bry_.new_a7(mainpage_val));
}
public void Init_mediawiki_page(String mainpage_val) {
fxt.Init_page_create(String_.new_a7(Ttl_mainpage), mainpage_val);
} private static final byte[] Ttl_mainpage = Bry_.new_a7("MediaWiki:Mainpage"); // TEST:
public void Init_lang(String mainpage_val) {
Xol_msg_itm msg_itm = fxt.Wiki().Lang().Msg_mgr().Itm_by_key_or_new(Xow_mainpage_finder.Msg_mainpage);
msg_itm.Atrs_set(Bry_.new_a7(mainpage_val), false, false);
}
public void Test_mainpage(String expd) {
byte[] actl = Xow_mainpage_finder.Find_or(fxt.Wiki(), fxt.Wiki().Props().Main_page());
Tfds.Eq(expd, String_.new_a7(actl));
}
}

View File

@@ -0,0 +1,113 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.html.sidebar.*;
public class Xow_msg_mgr implements GfoInvkAble {
private final Xowe_wiki wiki; private Xol_lang lang; private final Xol_msg_mgr msg_mgr;
public Xow_msg_mgr(Xowe_wiki wiki, Xol_lang lang) {
this.wiki = wiki;
this.lang = lang;
this.msg_mgr = new Xol_msg_mgr(wiki, false);
}
public void Clear() {msg_mgr.Clear();}
public void Lang_(Xol_lang v) {
this.lang = v;
this.Clear();
}
public byte[] Val_by_id_args(int id, Object... args) {return Val_by_id_priv(id, args);}
public byte[] Val_by_id(int id) {return Val_by_id_priv(id, null);}
private byte[] Val_by_id_priv(int id, Object[] args) {
Xol_msg_itm itm = msg_mgr.Itm_by_id_or_null(id);
if (itm == null)
itm = lang.Msg_mgr().Itm_by_id_or_null(id);
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
byte[] rv = Val_by_itm(tmp_bfr, itm, args);
tmp_bfr.Mkr_rls();
return rv;
}
public Xol_msg_itm Get_or_make(byte[] key) {return msg_mgr.Itm_by_key_or_new(key);}
public Xol_msg_itm Get_or_null(byte[] key) {return msg_mgr.Itm_by_key_or_null(key);}
public Xol_msg_itm Find_or_null(byte[] key) {
Xol_msg_itm itm = msg_mgr.Itm_by_key_or_null(key);
if (itm == null) {
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, lang, key);
if (itm.Src_is_missing()) itm = null;
tmp_bfr.Mkr_rls();
}
return itm;
}
public byte[] Val_by_key_args(byte[] key, Object... args) {return Val_by_key(key, args);}
public byte[] Val_by_key_obj(String key) {return Val_by_key(Bry_.new_u8(key), null);}
public byte[] Val_by_key_obj(byte[] key) {return Val_by_key(key, null);}
private byte[] Val_by_key(byte[] key, Object[] args) {
Xol_msg_itm itm = msg_mgr.Itm_by_key_or_null(key);
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
if (itm == null)
itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, lang, key);
if (itm.Src_is_missing()) {
tmp_bfr.Mkr_rls();
return Bry_.Empty;
}
byte[] rv = Val_by_itm(tmp_bfr, itm, args);
tmp_bfr.Mkr_rls();
return rv;
}
public byte[] Val_by_itm(Bry_bfr tmp_bfr, Xol_msg_itm itm, Object[] args) {
byte[] rv = itm.Val();
if (args != null) rv = itm.Fmt_tmp(tmp_bfr, rv, args);
if (itm.Has_tmpl_txt()) rv = wiki.Parser_mgr().Main().Parse_text_to_wtxt(rv);
return rv;
}
public byte[] Val_html_accesskey_and_title(byte[] id) {
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
byte[] rv = Val_html_accesskey_and_title(id, bfr, null);
bfr.Mkr_rls();
return rv;
}
public byte[] Val_html_accesskey_and_title(byte[] id, Bry_bfr bfr, Xowh_sidebar_itm itm) {
byte[] tooltip_key = Bry_.Add(CONST_prefix_tooltip, id);
byte[] tooltip_val = Val_by_key_obj(tooltip_key);
boolean tooltip_found = Bry_.Len_gt_0(tooltip_val);
byte[] accesskey_key = Bry_.Empty, accesskey_val = Bry_.Empty;
boolean accesskey_found = false;
if (tooltip_found) {
accesskey_key = Bry_.Add(CONST_prefix_accesskey, id);
accesskey_val = Val_by_key_obj(accesskey_key);
accesskey_found = Bry_.Len_gt_0(accesskey_val);
}
if (accesskey_found)
bfr.Add(CONST_atr_accesskey).Add(accesskey_val).Add_byte(Byte_ascii.Quote);
bfr.Add(CONST_atr_title).Add(tooltip_found ? tooltip_val : Bry_.Empty); // NOTE: if tooltip not found, make blank; don't bother showing tooltip_key
if (accesskey_found)
bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Brack_bgn).Add(accesskey_val).Add_byte(Byte_ascii.Brack_end);
bfr.Add_byte(Byte_ascii.Quote);
byte[] rv = bfr.Xto_bry_and_clear();
if (itm == null)
return rv;
else {
itm.Accesskey_(accesskey_val).Title_(tooltip_val).Atr_accesskey_and_title_(rv);
return null;
}
} static final byte[] CONST_prefix_tooltip = Bry_.new_a7("tooltip-"), CONST_prefix_accesskey = Bry_.new_a7("accesskey-"), CONST_atr_title = Bry_.new_a7(" title=\""), CONST_atr_accesskey = Bry_.new_a7(" accesskey=\"");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return this.Val_by_key_obj(m.ReadBry("v"));
else if (ctx.Match(k, Invk_get_html_accesskey_and_title)) return this.Val_html_accesskey_and_title(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get", Invk_get_html_accesskey_and_title = "get_html_accesskey_and_title";
}