mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Source: Restore broken commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.files.xfers.*;
|
||||
public class Xoa_available_wikis_mgr implements Gfo_invk {
|
||||
private Bry_fmtr itms_as_html_fmtr = Bry_fmtr.new_("\n <li><a href=\"/site/~{domain}/\"~{itm_cls}>~{domain}</a></li>", "domain", "itm_cls");
|
||||
public Xoa_available_wikis_mgr(Xoae_app app) {this.app = app;} private Xoae_app app;
|
||||
public String Itms_as_html() {
|
||||
if (itms_as_html == null) {
|
||||
String itm_cls = app.Usere().Wiki().Html_mgr().Head_mgr().Popup_mgr().Enabled() ? " class='xowa-hover-off'" : ""; // always add popup-disabled class in sidebar, even if popups aren't enabled; not worth effort to check cfg for get "current wiki"; DATE:2016-12-13
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
Xow_xwiki_mgr xwiki_mgr = app.Usere().Wiki().Xwiki_mgr();
|
||||
xwiki_mgr.Sort_by_key();
|
||||
int len = xwiki_mgr.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_xwiki_itm itm = xwiki_mgr.Get_at(i);
|
||||
if (itm.Domain_tid() == Xow_domain_tid_.Tid__home) continue;// don't show home wiki
|
||||
if (!itm.Offline()) continue; // only show items marked Offline (added by Available_from_fsys); DATE:2014-09-21
|
||||
itms_as_html_fmtr.Bld_bfr_many(tmp_bfr, itm.Domain_bry(), itm_cls);
|
||||
}
|
||||
itms_as_html = tmp_bfr.To_str();
|
||||
}
|
||||
return itms_as_html;
|
||||
} private String itms_as_html;
|
||||
public void Itms_reset() {itms_as_html = null;}
|
||||
public boolean Visible() {return visible;} private boolean visible = true;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_itms_as_html)) return this.Itms_as_html();
|
||||
else if (ctx.Match(k, Invk_itms_refresh)) Itms_reset();
|
||||
else if (ctx.Match(k, Invk_visible)) return Yn.To_str(visible);
|
||||
else if (ctx.Match(k, Invk_visible_)) visible = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_visible_toggle)) {visible = !visible; app.Gui_mgr().Browser_win().Active_html_box().Html_js_eval_proc_as_str("xowa-portal-wikis-visible-toggle", Bool_.To_str_lower(visible));}
|
||||
else if (ctx.Match(k, Invk_itms_as_html_fmtr_)) itms_as_html_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_visible = "visible", Invk_visible_ = "visible_", Invk_visible_toggle = "visible_toggle", Invk_itms_as_html = "itms_as_html", Invk_itms_as_html_fmtr_ = "itms_as_html_fmtr_", Invk_itms_refresh = "itms_refresh";
|
||||
}
|
||||
26
400_xowa/src/gplx/xowa/htmls/portal/Xoa_portal_mgr.java
Normal file
26
400_xowa/src/gplx/xowa/htmls/portal/Xoa_portal_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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoa_portal_mgr implements Gfo_invk {
|
||||
public Xoa_portal_mgr(Xoae_app app) {wikis = new Xoa_available_wikis_mgr(app);}
|
||||
public Xoa_available_wikis_mgr Wikis() {return wikis;} private Xoa_available_wikis_mgr wikis;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_wikis)) return wikis;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_wikis = "wikis";
|
||||
}
|
||||
132
400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls.java
Normal file
132
400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls.java
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_page_body_cls { // REF.MW:Skin.php|getPageClasses
|
||||
public static byte[] Calc(Bry_bfr tmp_bfr, Xoa_ttl ttl, int page_tid) {
|
||||
tmp_bfr.Add(Bry_id_prefix).Add_int_variable(ttl.Ns().Id()); // ns-0; note that special is ns--1 DATE:2014-09-24
|
||||
Add_type(tmp_bfr, ttl); // ns-special || ns-talk || ns-subject
|
||||
tmp_bfr.Add_byte_space().Add(Bry_page_prefix).Add(Escape_cls(ttl.Full_db())); // page-Page_title
|
||||
if (page_tid == Xow_page_tid.Tid_json) {
|
||||
switch (ttl.Ns().Id()) {
|
||||
case Xow_ns_.Tid__main:
|
||||
tmp_bfr.Add_byte_space().Add(Bry_wb_entitypage);
|
||||
tmp_bfr.Add_byte_space().Add(Bry_wb_itempage);
|
||||
tmp_bfr.Add_byte_space().Add(Bry_wb_itempage).Add_byte(Byte_ascii.Dash).Add(ttl.Page_db());
|
||||
break;
|
||||
case Wdata_wiki_mgr.Ns_property:
|
||||
tmp_bfr.Add_byte_space().Add(Bry_wb_entitypage);
|
||||
tmp_bfr.Add_byte_space().Add(Bry_wb_propertypage);
|
||||
tmp_bfr.Add_byte_space().Add(Bry_wb_propertypage).Add_byte(Byte_ascii.Dash).Add(ttl.Page_db());
|
||||
break;
|
||||
default:
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unexpected ns for page_body_cls; ttl=~{0}", String_.new_u8(ttl.Raw()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
private static void Add_type(Bry_bfr tmp_bfr, Xoa_ttl ttl) {
|
||||
tmp_bfr.Add_byte_space();
|
||||
if (ttl.Ns().Id_is_special()) {
|
||||
tmp_bfr.Add(Bry_type_special); // MW_TODO: add " mw-special-$canonicalName"
|
||||
}
|
||||
else if (ttl.Ns().Id_is_talk())
|
||||
tmp_bfr.Add(Bry_type_talk);
|
||||
else
|
||||
tmp_bfr.Add(Bry_type_subject);
|
||||
}
|
||||
public static byte[] Escape_cls(byte[] src) { // REF.MW:Sanitizer.php|escapeClass; return rtrim( preg_replace(array( '/(^[0-9\\-])|[\\x00-\\x20!"#$%&\'()*+,.\\/:;<=>?@[\\]^`{|}~]|\\xC2\\xA0/', '/_+/' ), '_', $class ), '_' );
|
||||
Bry_bfr trg_bfr = null;
|
||||
int src_len = src.length; int bgn = -1;
|
||||
for (int i = 0; i < src_len; ++i) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Space:
|
||||
case Byte_ascii.Bang: case Byte_ascii.Quote: case Byte_ascii.Hash: case Byte_ascii.Dollar: case Byte_ascii.Percent:
|
||||
case Byte_ascii.Amp: case Byte_ascii.Apos: case Byte_ascii.Paren_bgn: case Byte_ascii.Paren_end: case Byte_ascii.Star:
|
||||
case Byte_ascii.Plus: case Byte_ascii.Comma: case Byte_ascii.Dot: case Byte_ascii.Backslash: case Byte_ascii.Slash:
|
||||
case Byte_ascii.Colon: case Byte_ascii.Semic: case Byte_ascii.Gt: case Byte_ascii.Eq: case Byte_ascii.Lt:
|
||||
case Byte_ascii.Question: case Byte_ascii.At: case Byte_ascii.Brack_bgn: case Byte_ascii.Brack_end:
|
||||
case Byte_ascii.Pow: case Byte_ascii.Tick:
|
||||
case Byte_ascii.Curly_bgn: case Byte_ascii.Pipe: case Byte_ascii.Curly_end: case Byte_ascii.Tilde:
|
||||
if (trg_bfr == null)
|
||||
src[i] = Byte_ascii.Underline;
|
||||
else {
|
||||
if (bgn != -1) {
|
||||
trg_bfr.Add_mid(src, bgn, i);
|
||||
bgn = -1;
|
||||
}
|
||||
trg_bfr.Add_byte(Byte_ascii.Underline);
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Underline:
|
||||
if (trg_bfr == null) {
|
||||
trg_bfr = Bry_bfr_.New_w_size(src_len);
|
||||
trg_bfr.Add_mid(src, 0, i);
|
||||
}
|
||||
if (bgn != -1) {
|
||||
trg_bfr.Add_mid(src, bgn, i);
|
||||
bgn = -1;
|
||||
}
|
||||
int repeat = 0;
|
||||
for (int j = i + 1; j < src_len; ++j) {
|
||||
if (src[j] == Byte_ascii.Underline)
|
||||
++repeat;
|
||||
else
|
||||
break;
|
||||
}
|
||||
trg_bfr.Add_byte(Byte_ascii.Underline);
|
||||
i += repeat;
|
||||
break;
|
||||
case -62:
|
||||
int next = i + 1;
|
||||
if (next < src_len && src[next] == -96) {
|
||||
if (trg_bfr == null) {
|
||||
trg_bfr = Bry_bfr_.New_w_size(src_len);
|
||||
trg_bfr.Add_mid(src, 0, i);
|
||||
}
|
||||
trg_bfr.Add_byte(Byte_ascii.Underline);
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (trg_bfr != null && bgn == -1)
|
||||
bgn = i;
|
||||
break;
|
||||
default:
|
||||
if (trg_bfr != null && bgn == -1)
|
||||
bgn = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bgn != -1) trg_bfr.Add_mid(src, bgn, src_len);
|
||||
return trg_bfr == null ? src : trg_bfr.To_bry_and_clear();
|
||||
}
|
||||
private static final byte[]
|
||||
Bry_id_prefix = Bry_.new_a7("ns-")
|
||||
, Bry_type_special = Bry_.new_a7("ns-special")
|
||||
, Bry_type_talk = Bry_.new_a7("ns-talk")
|
||||
, Bry_type_subject = Bry_.new_a7("ns-subject")
|
||||
, Bry_page_prefix = Bry_.new_a7("page-")
|
||||
, Bry_wb_entitypage = Bry_.new_a7("wb-entitypage")
|
||||
, Bry_wb_itempage = Bry_.new_a7("wb-itempage")
|
||||
, Bry_wb_propertypage = Bry_.new_a7("wb-propertypage")
|
||||
;
|
||||
public static int Page_tid_wikitext = 0, Page_tid_wikidata_qid = 1, Page_tid_wikidata_pid = 2;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Xoh_page_body_cls_tst {
|
||||
@Before public void init() {} private Xoh_page_body_cls_fxt fxt = new Xoh_page_body_cls_fxt();
|
||||
@Test public void Escape_cls() {
|
||||
fxt.Test_escape_cls("0123456789", "0123456789"); // noop: num
|
||||
fxt.Test_escape_cls("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // noop: ucase
|
||||
fxt.Test_escape_cls("abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"); // noop: lcase
|
||||
fxt.Test_escape_cls("!\"#$%&'()*+,.\\/:;<=>?@[]^`{|}~", "______________________________"); // underline: syms
|
||||
fxt.Test_escape_cls("a.bcd..ef.", "a_bcd__ef_"); // letters + syms
|
||||
fxt.Test_escape_cls("a__b___c" , "a_b_c"); // multiple underlines
|
||||
fxt.Test_escape_cls("a b", "a_b"); // nbsp
|
||||
}
|
||||
@Test public void Calc() {
|
||||
fxt.Test_calc(Xow_page_tid.Tid_wikitext , "A" , "ns-0 ns-subject page-A");
|
||||
fxt.Test_calc(Xow_page_tid.Tid_wikitext , "Talk:A" , "ns-1 ns-talk page-Talk_A");
|
||||
fxt.Test_calc(Xow_page_tid.Tid_wikitext , "Wikipedia:Página principal" , "ns-4 ns-subject page-Wikipedia_Página_principal");
|
||||
fxt.Test_calc(Xow_page_tid.Tid_json , "Q2" , "ns-0 ns-subject page-Q2 wb-entitypage wb-itempage wb-itempage-Q2");
|
||||
fxt.Test_calc(Xow_page_tid.Tid_json , "Property:P1" , "ns-120 ns-subject page-Property_P1 wb-entitypage wb-propertypage wb-propertypage-P1");
|
||||
}
|
||||
}
|
||||
class Xoh_page_body_cls_fxt {
|
||||
private Bry_bfr tmp_bfr; private Xoae_app app; private Xowe_wiki wiki;
|
||||
public void Test_escape_cls(String raw, String expd) {
|
||||
Tfds.Eq(expd, String_.new_u8(Xoh_page_body_cls.Escape_cls(Bry_.new_u8(raw))));
|
||||
}
|
||||
public void Test_calc(byte page_tid, String ttl_str, String expd) {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
tmp_bfr = Bry_bfr_.Reset(255);
|
||||
wiki.Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, Wdata_wiki_mgr.Ns_property_name);
|
||||
}
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
|
||||
Tfds.Eq(expd, String_.new_u8(Xoh_page_body_cls.Calc(tmp_bfr, ttl, page_tid)));
|
||||
}
|
||||
}
|
||||
73
400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl.java
Normal file
73
400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl.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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_rtl_utl {
|
||||
private static final int[] tmp_ary = new int[32]; // support no more than 16 items
|
||||
private static Bry_bfr bfr = Bry_bfr_.Reset(32);
|
||||
public static byte[] Reverse_li(byte[] src) {
|
||||
int src_len = src.length;
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int ul_bgn = Bry_find_.Find_fwd(src, Ul_bgn, pos, src_len);
|
||||
if (ul_bgn == Bry_find_.Not_found) break; // no more <ul
|
||||
int ul_end = Bry_find_.Find_fwd(src, Ul_end, ul_bgn + Ul_bgn.length, src_len);
|
||||
if (ul_end == Bry_find_.Not_found) break; // no more </ul>
|
||||
bfr.Add_mid(src, pos, ul_bgn); // add pos -> <ul
|
||||
ul_end += Ul_end.length;
|
||||
Reverse_li_src(bfr, src, ul_bgn, ul_end, tmp_ary);
|
||||
pos = ul_end;
|
||||
}
|
||||
bfr.Add_mid(src, pos, src_len); // add rest of String
|
||||
return bfr.To_bry_and_clear(); // exit
|
||||
}
|
||||
private static void Reverse_li_src(Bry_bfr bfr, byte[] src, int ul_bgn, int ul_end, int[] tmp_ary) {
|
||||
int pos = ul_bgn;
|
||||
int tmp_idx = 0;
|
||||
while (true) {
|
||||
int li_bgn = Bry_find_.Find_fwd(src, Li_bgn, pos, ul_end);
|
||||
if (li_bgn == Bry_find_.Not_found) break; // no more <li
|
||||
int li_end = Bry_find_.Find_fwd(src, Li_end, pos, ul_end);
|
||||
if (li_end == Bry_find_.Not_found) break; // no more </li>
|
||||
tmp_ary[tmp_idx++] = li_bgn;
|
||||
tmp_ary[tmp_idx++] = li_end + Li_end.length;
|
||||
pos = li_end + Li_end.length;
|
||||
}
|
||||
int ul_bgn_rhs = Bry_find_.Find_fwd(src, Byte_ascii.Gt, ul_bgn);
|
||||
if (tmp_idx < 3 // 0 or 1 li; add everything between ul
|
||||
|| ul_bgn_rhs == Bry_find_.Not_found
|
||||
) {
|
||||
bfr.Add_mid(src, ul_bgn, ul_end);
|
||||
return;
|
||||
}
|
||||
int li_n_end = tmp_ary[tmp_idx - 1];
|
||||
++ul_bgn_rhs;
|
||||
bfr.Add_mid(src, ul_bgn, ul_bgn_rhs); // add from "<ul" -> to 1st ">"
|
||||
for (int i = tmp_idx - 1; i > -1; i -= 2) {
|
||||
int li_end = tmp_ary[i];
|
||||
int prv_pos = i < 2 ? ul_bgn_rhs : tmp_ary[i - 2];
|
||||
bfr.Add_mid(src, prv_pos, li_end); // add from "<li" -> to "</li>"
|
||||
}
|
||||
bfr.Add_mid(src, li_n_end, ul_end); // add from nth "</li>" -> "</ul>"
|
||||
}
|
||||
private static final byte[]
|
||||
Ul_bgn = Bry_.new_a7("<ul")
|
||||
, Ul_end = Bry_.new_a7("</ul>")
|
||||
, Li_bgn = Bry_.new_a7("<li")
|
||||
, Li_end = Bry_.new_a7("</li>")
|
||||
;
|
||||
}
|
||||
64
400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl_tst.java
Normal file
64
400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl_tst.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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_rtl_utl_tst {
|
||||
@Before public void init() {fxt.Init();} private Xoh_rtl_utl_fxt fxt = new Xoh_rtl_utl_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_reverse_li("<ul><li>a</li><li>b</li></ul>", "<ul><li>b</li><li>a</li></ul>");
|
||||
}
|
||||
@Test public void Zero() {
|
||||
fxt.Test_reverse_li("a", "a");
|
||||
}
|
||||
@Test public void One() {
|
||||
fxt.Test_reverse_li("<ul><li>a</li></ul>", "<ul><li>a</li></ul>");
|
||||
}
|
||||
@Test public void Example() {
|
||||
fxt.Test_reverse_li(String_.Concat_lines_nl_skip_last
|
||||
( "<div>"
|
||||
, " <ul>"
|
||||
, " <li>a"
|
||||
, " </li>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, " <li>c"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, "</div>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div>"
|
||||
, " <ul>"
|
||||
, " <li>c"
|
||||
, " </li>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, " <li>a"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoh_rtl_utl_fxt {
|
||||
public void Init() {
|
||||
}
|
||||
public void Test_reverse_li(String raw, String expd) {
|
||||
byte[] actl = Xoh_rtl_utl.Reverse_li(Bry_.new_u8(raw));
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
66
400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr.java
Normal file
66
400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_subpages_bldr implements gplx.core.brys.Bfr_arg {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255), ttl_bfr = Bry_bfr_.Reset(255);
|
||||
private byte[][] segs;
|
||||
public byte[] Bld(Xow_ns_mgr ns_mgr, Xoa_ttl ttl) {
|
||||
Xow_ns ns = ttl.Ns();
|
||||
if (! ( ns.Subpages_enabled() // ns has subpages
|
||||
&& ttl.Leaf_bgn() != Bry_find_.Not_found // ttl has leaf text; EX: Help:A/B
|
||||
&& ns.Id() != ns_mgr.Ns_page_id() // ns is not [[Page:]]; PAGE:en.s:Notes_on_Osteology_of_Baptanodon._With_a_Description_of_a_New_Species DATE:2014-09-06
|
||||
)
|
||||
) return Bry_.Empty; // doesn't match above; return empty;
|
||||
byte[] raw = ttl.Raw();
|
||||
this.segs = Bry_split_.Split(raw, Byte_ascii.Slash);
|
||||
fmtr_grp.Bld_bfr(tmp_bfr, this);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int segs_len = segs.length - 1; // last seg is current page; do not print
|
||||
for (int i = 0; i < segs_len; ++i) {
|
||||
byte[] dlm = null;
|
||||
if (i == 0)
|
||||
dlm = Dlm_1st;
|
||||
else {
|
||||
dlm = Dlm_nth;
|
||||
ttl_bfr.Add_byte_slash();
|
||||
}
|
||||
byte[] seg = segs[i];
|
||||
ttl_bfr.Add(seg);
|
||||
byte[] seg_ttl = ttl_bfr.To_bry();
|
||||
byte[] seg_ttl_enc = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(ttl_bfr.To_bry());
|
||||
byte[] href = Bry_.Add(Xoh_href_.Bry__wiki, seg_ttl_enc); // EX: /wiki/Help:A
|
||||
fmtr_itm.Bld_bfr(bfr, dlm, href, seg_ttl, seg);
|
||||
}
|
||||
ttl_bfr.Clear();
|
||||
}
|
||||
private static final byte[] Dlm_1st = Bry_.new_a7("< "), Dlm_nth = Bry_.new_a7("‎ | ");
|
||||
private static final Bry_fmtr
|
||||
fmtr_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<span class=\"subpages\">~{itms}"
|
||||
, "</span>"
|
||||
), "itms")
|
||||
, fmtr_itm = Bry_fmtr.new_
|
||||
( "\n ~{dlm}<a href=\"~{href}\" title=\"~{title}\">~{caption}</a>"
|
||||
, "dlm", "href", "title", "caption")
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_subpages_bldr_tst {
|
||||
@Before public void init() {fxt.Init();} private Xoh_subpages_bldr_fxt fxt = new Xoh_subpages_bldr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_bld("Help:A/B/C", String_.Concat_lines_nl_skip_last
|
||||
( "<span class=\"subpages\">"
|
||||
, " < <a href=\"/wiki/Help:A\" title=\"Help:A\">Help:A</a>"
|
||||
, " ‎ | <a href=\"/wiki/Help:A/B\" title=\"Help:A/B\">B</a>"
|
||||
, "</span>"
|
||||
));
|
||||
}
|
||||
@Test public void Skip_page() {
|
||||
fxt.Wiki().Ns_mgr().Add_new(104, "Page");
|
||||
fxt.Wiki().Ns_mgr().Ns_page_id_(104);
|
||||
fxt.Test_bld("Page:A/B/C", "");
|
||||
}
|
||||
}
|
||||
class Xoh_subpages_bldr_fxt {
|
||||
private Xoae_app app;
|
||||
private Xoh_subpages_bldr subpages_bldr = new Xoh_subpages_bldr();
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public void Init() {
|
||||
this.app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__help).Subpages_enabled_(true);
|
||||
}
|
||||
public void Test_bld(String ttl_str, String expd) {
|
||||
byte[] actl = subpages_bldr.Bld(wiki.Ns_mgr(), Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str)));
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
178
400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr.java
Normal file
178
400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr.java
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.addons.htmls.sidebars.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.apps.apis.xowa.html.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.htmls.portal.vnts.*;
|
||||
public class Xow_portal_mgr implements Gfo_invk {
|
||||
private Xowe_wiki wiki; private boolean lang_is_rtl; private Xoapi_toggle_itm toggle_itm;
|
||||
private final Vnt_mnu_grp_fmtr vnt_menu_fmtr = new Vnt_mnu_grp_fmtr();
|
||||
private final Gfo_url_encoder fsys_lnx_encoder = Gfo_url_encoder_.New__fsys_lnx().Make();
|
||||
private boolean sidebar_enabled;
|
||||
public Xow_portal_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
this.sidebar_mgr = new Xoh_sidebar_mgr(wiki);
|
||||
this.missing_ns_cls = Bry_.Eq(wiki.Domain_bry(), Xow_domain_tid_.Bry__home) ? Missing_ns_cls_hide : null; // if home wiki, set missing_ns to application default; if any other wiki, set to null; will be overriden during init
|
||||
}
|
||||
public byte[] Missing_ns_cls() {return missing_ns_cls;} public Xow_portal_mgr Missing_ns_cls_(byte[] v) {missing_ns_cls = v; return this;} private byte[] missing_ns_cls; // NOTE: must be null due to Init check above
|
||||
public Xoh_sidebar_mgr Sidebar_mgr() {return sidebar_mgr;} private Xoh_sidebar_mgr sidebar_mgr;
|
||||
public Bry_fmtr Div_home_fmtr() {return div_home_fmtr;} private Bry_fmtr div_home_fmtr = Bry_fmtr.new_("");
|
||||
public Xow_portal_mgr Init_assert() {if (init_needed) Init(); return this;}
|
||||
public byte[] Div_jump_to() {return div_jump_to;} private byte[] div_jump_to = Bry_.Empty;
|
||||
public void Init_by_lang(Xol_lang_itm lang) {
|
||||
lang_is_rtl = !lang.Dir_ltr();
|
||||
}
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
wiki.App().Cfg().Bind_many_wiki(this, wiki, Cfg__missing_class, Cfg__sidebar_enabled__desktop, Cfg__sidebar_enabled__server);
|
||||
}
|
||||
private void Sidebar_enabled_(boolean is_desktop, boolean val) {
|
||||
// set sidebar_enabled if (a) is_gui and is_desktop; or (b) is_server and !is_desktop
|
||||
if (wiki.App().Mode().Tid_is_gui()) {
|
||||
if (is_desktop)
|
||||
this.sidebar_enabled = val;
|
||||
}
|
||||
else {
|
||||
if (!is_desktop)
|
||||
this.sidebar_enabled = val;
|
||||
}
|
||||
}
|
||||
public void Init() {
|
||||
init_needed = false;
|
||||
if (missing_ns_cls == null) {// if missing_ns_cls not set for wiki, use the home wiki's
|
||||
Missing_ns_cls_(wiki.Appe().Usere().Wiki().Html_mgr().Portal_mgr().Missing_ns_cls());
|
||||
}
|
||||
Bry_fmtr_eval_mgr eval_mgr = wiki.Eval_mgr();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
Init_fmtr(tmp_bfr, eval_mgr, div_view_fmtr);
|
||||
Init_fmtr(tmp_bfr, eval_mgr, div_ns_fmtr);
|
||||
byte[] wiki_user_name = wiki.User().Name();
|
||||
div_personal_bry = Init_fmtr(tmp_bfr, eval_mgr, div_personal_fmtr, Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user).Name_db_w_colon(), wiki_user_name), wiki_user_name, Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Tid__user), Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user_talk).Name_db_w_colon(), wiki_user_name), Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Tid__user_talk));
|
||||
byte[] main_page_href_bry = tmp_bfr.Add(Xoh_href_.Bry__site).Add(wiki.Domain_bry()).Add(Xoh_href_.Bry__wiki).To_bry_and_clear(); // NOTE: build /site/en.wikipedia.org/wiki/ href; no Main_Page, as that will be inserted by Xoh_href_parser
|
||||
div_logo_bry = Init_fmtr(tmp_bfr, eval_mgr, div_logo_fmtr, main_page_href_bry, fsys_lnx_encoder.Encode_to_file_protocol(wiki.Appe().Usere().Fsys_mgr().Wiki_root_dir().GenSubFil_nest(wiki.Domain_str(), "html", "logo.png")));
|
||||
div_home_bry = Init_fmtr(tmp_bfr, eval_mgr, div_home_fmtr);
|
||||
div_wikis_fmtr.Eval_mgr_(eval_mgr);
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
div_jump_to = Div_jump_to_fmtr.Bld_bry_many(tmp_bfr, msg_mgr.Val_by_key_obj("jumpto"), msg_mgr.Val_by_key_obj("jumptonavigation"), msg_mgr.Val_by_key_obj("comma-separator"), msg_mgr.Val_by_key_obj("jumptosearch"));
|
||||
tmp_bfr.Mkr_rls();
|
||||
sidebar_mgr.Init_by_wiki();
|
||||
} private boolean init_needed = true;
|
||||
private byte[] Init_fmtr(Bry_bfr tmp_bfr, Bry_fmtr_eval_mgr eval_mgr, Bry_fmtr fmtr, Object... fmt_args) {
|
||||
fmtr.Eval_mgr_(eval_mgr);
|
||||
fmtr.Bld_bfr_many(tmp_bfr, fmt_args);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public byte[] Div_personal_bry() {return div_personal_bry;} private byte[] div_personal_bry = Bry_.Empty;
|
||||
public byte[] Div_ns_bry(Bry_bfr_mkr bfr_mkr, Xoa_ttl ttl, Xow_ns_mgr ns_mgr) {
|
||||
Xow_ns ns = ttl.Ns();
|
||||
byte[] subj_cls = Ns_cls_by_ord(ns_mgr, ns.Ord_subj_id()), talk_cls = Ns_cls_by_ord(ns_mgr, ns.Ord_talk_id());
|
||||
if (ns.Id_is_talk())
|
||||
talk_cls = Xow_portal_mgr.Cls_selected_y;
|
||||
else
|
||||
subj_cls = Xow_portal_mgr.Cls_selected_y;
|
||||
Bfr_arg vnt_menu = null;
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr(); // VNT; DATE:2015-03-03
|
||||
if (vnt_mgr.Enabled()) {
|
||||
vnt_menu_fmtr.Init(vnt_mgr.Regy(), wiki.Domain_bry(), ttl.Full_db(), vnt_mgr.Cur_itm().Key());
|
||||
vnt_menu = wiki.Lang().Vnt_mgr().Enabled() ? vnt_menu_fmtr : null;
|
||||
}
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
div_ns_fmtr.Bld_bfr_many(tmp_bfr, Bry_.Add(Xoh_href_.Bry__wiki, ttl.Subj_txt()), subj_cls, Bry_.Add(Xoh_href_.Bry__wiki, ttl.Talk_txt()), talk_cls, vnt_menu);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private byte[] Ns_cls_by_ord(Xow_ns_mgr ns_mgr, int ns_ord) {
|
||||
Xow_ns ns = ns_mgr.Ords_get_at(ns_ord);
|
||||
return ns == null || ns.Exists() ? Bry_.Empty : missing_ns_cls;
|
||||
}
|
||||
private byte[] Ns_cls_by_id(Xow_ns_mgr ns_mgr, int ns_id) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id);
|
||||
return ns == null || ns.Exists() ? Bry_.Empty : missing_ns_cls;
|
||||
}
|
||||
public byte[] Div_view_bry(Bry_bfr_mkr bfr_mkr, byte output_tid, byte[] search_text) {
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
byte[] read_cls = Bry_.Empty, edit_cls = Bry_.Empty, html_cls = Bry_.Empty;
|
||||
switch (output_tid) {
|
||||
case Xopg_page_.Tid_read: read_cls = Cls_selected_y; break;
|
||||
case Xopg_page_.Tid_edit: edit_cls = Cls_selected_y; break;
|
||||
case Xopg_page_.Tid_html: html_cls = Cls_selected_y; break;
|
||||
}
|
||||
div_view_fmtr.Bld_bfr_many(tmp_bfr, read_cls, edit_cls, html_cls, search_text);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
} public static final byte[] Cls_selected_y = Bry_.new_a7("selected"), Cls_new = Bry_.new_a7("new"), Cls_display_none = Bry_.new_a7("xowa_display_none");
|
||||
public byte[] Div_logo_bry() {return div_logo_bry;} private byte[] div_logo_bry = Bry_.Empty;
|
||||
public byte[] Div_home_bry() {return sidebar_enabled ? div_home_bry : Bry_.Empty;} private byte[] div_home_bry = Bry_.Empty;
|
||||
public byte[] Div_sync_bry(Bry_bfr tmp_bfr, boolean manual_enabled, Xow_wiki wiki, Xoa_page page) {
|
||||
// only show update_html if wmf; DATE:2016-08-31
|
||||
if ( wiki.Domain_itm().Domain_type().Src() == Xow_domain_tid.Src__wmf
|
||||
&& manual_enabled) {
|
||||
div_sync_fmtr.Bld_bfr_many(tmp_bfr, page.Ttl().Full_url());
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
return Bry_.Empty;
|
||||
}
|
||||
public byte[] Div_wikis_bry(Bry_bfr_mkr bfr_mkr) {
|
||||
if (toggle_itm == null) // TEST:lazy-new b/c Init_by_wiki
|
||||
toggle_itm = wiki.Appe().Api_root().Html().Page().Toggle_mgr().Get_or_new("offline-wikis").Init(Bry_.new_a7("Wikis"));
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
div_wikis_fmtr.Bld_bfr_many(tmp_bfr, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr());
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private final Bry_fmtr
|
||||
div_personal_fmtr = Bry_fmtr.new_("~{portal_personal_subj_href};~{portal_personal_subj_text};~{portal_personal_talk_cls};~{portal_personal_talk_href};~{portal_personal_talk_cls};", "portal_personal_subj_href", "portal_personal_subj_text", "portal_personal_subj_cls", "portal_personal_talk_href", "portal_personal_talk_cls")
|
||||
, div_ns_fmtr = Bry_fmtr.new_("~{portal_ns_subj_href};~{portal_ns_subj_cls};~{portal_ns_talk_href};~{portal_ns_talk_cls};~{portal_div_vnts}", "portal_ns_subj_href", "portal_ns_subj_cls", "portal_ns_talk_href", "portal_ns_talk_cls", "portal_div_vnts")
|
||||
, div_view_fmtr = Bry_fmtr.new_("", "portal_view_read_cls", "portal_view_edit_cls", "portal_view_html_cls", "search_text")
|
||||
, div_logo_fmtr = Bry_fmtr.new_("", "portal_nav_main_href", "portal_logo_url")
|
||||
, div_sync_fmtr = Bry_fmtr.new_("", "page_url")
|
||||
, div_wikis_fmtr = Bry_fmtr.new_("", "toggle_btn", "toggle_hdr")
|
||||
;
|
||||
private byte[] Reverse_li(byte[] bry) {
|
||||
return lang_is_rtl ? Xoh_rtl_utl.Reverse_li(bry) : bry;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_div_personal_)) div_personal_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_div_ns_)) div_ns_fmtr.Fmt_(Reverse_li(m.ReadBry("v")));
|
||||
else if (ctx.Match(k, Invk_div_view_)) div_view_fmtr.Fmt_(Reverse_li(m.ReadBry("v")));
|
||||
else if (ctx.Match(k, Invk_div_logo_)) div_logo_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_div_home_)) div_home_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_div_sync_)) div_sync_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_div_wikis_)) div_wikis_fmtr.Fmt_(m.ReadBry("v"));
|
||||
|
||||
else if (ctx.Match(k, Cfg__missing_class)) missing_ns_cls = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Cfg__sidebar_enabled__desktop)) Sidebar_enabled_(Bool_.Y, m.ReadYn("v"));
|
||||
else if (ctx.Match(k, Cfg__sidebar_enabled__server)) Sidebar_enabled_(Bool_.N, m.ReadYn("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_div_personal_ = "div_personal_", Invk_div_view_ = "div_view_", Invk_div_ns_ = "div_ns_", Invk_div_home_ = "div_home_"
|
||||
, Invk_div_sync_ = "div_sync_", Invk_div_wikis_ = "div_wikis_";
|
||||
public static final String Invk_div_logo_ = "div_logo_";
|
||||
private static final byte[] Missing_ns_cls_hide = Bry_.new_a7("xowa_display_none");
|
||||
private static final Bry_fmtr Div_jump_to_fmtr = Bry_fmtr.new_
|
||||
( "\n <div id=\"jump-to-nav\" class=\"mw-jump\">~{jumpto}<a href=\"#mw-navigation\">~{jumptonavigation}</a>~{comma-separator}<a href=\"#p-search\">~{jumptosearch}</a></div>"
|
||||
, "jumpto", "jumptonavigation", "comma-separator", "jumptosearch");
|
||||
|
||||
private static final String
|
||||
Cfg__missing_class = "xowa.html.portal.missing_class"
|
||||
, Cfg__sidebar_enabled__desktop = "xowa.html.portal.sidebar_enabled_desktop"
|
||||
, Cfg__sidebar_enabled__server = "xowa.html.portal.sidebar_enabled_server"
|
||||
;
|
||||
}
|
||||
52
400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr_tst.java
Normal file
52
400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr_tst.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Xow_portal_mgr_tst {
|
||||
@Before public void init() {fxt.Init();} private Xowh_portal_mgr_fxt fxt = new Xowh_portal_mgr_fxt();
|
||||
@Test public void Div_ns_bry() {
|
||||
fxt.Test_div_ns_bry("A" , "/wiki/A;selected;/wiki/Talk:A;xowa_display_none;");
|
||||
fxt.Test_div_ns_bry("Talk:A" , "/wiki/A;;/wiki/Talk:A;selected;");
|
||||
}
|
||||
@Test public void Div_personal_bry() {
|
||||
fxt.Test_div_personal_bry("/wiki/User:anonymous;anonymous;xowa_display_none;/wiki/User_talk:anonymous;xowa_display_none;");
|
||||
}
|
||||
@Test public void Missing_ns_cls() {
|
||||
fxt.Test_missing_ns_cls("xowa_display_none");
|
||||
}
|
||||
}
|
||||
class Xowh_portal_mgr_fxt {
|
||||
public void Init() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
wiki.Ns_mgr().Ns_main().Exists_(true); // needed for ns
|
||||
wiki.Html_mgr().Portal_mgr().Init_assert(); // needed for personal
|
||||
wiki.Html_mgr().Portal_mgr().Missing_ns_cls_(Bry_.new_a7("xowa_display_none"));
|
||||
}
|
||||
} private Xoae_app app; Xowe_wiki wiki;
|
||||
public void Test_div_ns_bry(String ttl, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(wiki.Html_mgr().Portal_mgr().Div_ns_bry(wiki.Utl__bfr_mkr(), Xoa_ttl.Parse(wiki, Bry_.new_a7(ttl)), wiki.Ns_mgr())));
|
||||
}
|
||||
public void Test_div_personal_bry(String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(wiki.Html_mgr().Portal_mgr().Div_personal_bry()));
|
||||
}
|
||||
public void Test_missing_ns_cls(String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(wiki.Html_mgr().Portal_mgr().Missing_ns_cls()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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.htmls.portal.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.portal.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
public class Vnt_mnu_grp_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private final Xolg_vnt_itm_fmtr itm_fmtr = new Xolg_vnt_itm_fmtr();
|
||||
private Xol_vnt_regy mgr; private byte[] page_vnt;
|
||||
public void Init(Xol_vnt_regy mgr, byte[] wiki_domain, byte[] page_href, byte[] page_vnt) {
|
||||
this.mgr = mgr; this.page_vnt = page_vnt;
|
||||
itm_fmtr.Init(mgr, wiki_domain, page_href, page_vnt);
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Xol_vnt_itm mnu_itm = mgr.Get_by(page_vnt);
|
||||
fmtr.Bld_bfr_many(bfr, mnu_itm == null ? Bry_.Empty : mnu_itm.Name(), itm_fmtr);
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div id='p-variants' role='navigation' class='vectorMenu' aria-labelledby='p-variants-label'>"
|
||||
, " <h3 id='p-variants-label'><span>~{grp_text}</span><a href='#'></a></h3>"
|
||||
, " <div class='menu'>"
|
||||
, " <ul>~{itms}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
), "grp_text", "itms"
|
||||
);
|
||||
}
|
||||
class Xolg_vnt_itm_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private Xol_vnt_regy mgr; private byte[] wiki_domain, page_href, page_vnt;
|
||||
public void Init(Xol_vnt_regy mgr, byte[] wiki_domain, byte[] page_href, byte[] page_vnt) {this.mgr = mgr; this.wiki_domain = wiki_domain; this.page_href = page_href; this.page_vnt = page_vnt;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int len = mgr.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xol_vnt_itm itm = mgr.Get_at(i); if (!itm.Visible()) continue;
|
||||
boolean itm_is_selected = Bry_.Eq(itm.Key(), page_vnt);
|
||||
byte[] itm_cls_selected = itm_is_selected ? Itm_cls_selected_y : Bry_.Empty;
|
||||
fmtr.Bld_bfr_many(bfr, i, itm_cls_selected, wiki_domain, itm.Key(), itm.Name(), page_href);
|
||||
}
|
||||
}
|
||||
private static final byte[] Itm_cls_selected_y = Bry_.new_a7(" class='selected'");
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last // NOTE: using "/site/zh.w/zh-hans/A" instead of "/zh-hans/A" b/c it is easier for href_parser; if /site/ ever needs to truly mean "not-this-site", then change this to "/lang/"; DATE:2015-07-30
|
||||
( ""
|
||||
, " <li id='ca-varlang-~{itm_idx}'~{itm_cls_selected}><a href='/site/~{wiki_domain}/~{itm_lang}/~{itm_href}' lang='~{itm_lang}' hreflang='~{itm_lang}' class='xowa-hover-off'>~{itm_text}</a></li>"
|
||||
), "itm_idx", "itm_cls_selected", "wiki_domain", "itm_lang", "itm_text", "itm_href"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.htmls.portal.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.portal.*;
|
||||
import org.junit.*; import gplx.xowa.langs.vnts.*;
|
||||
public class Vnt_mnu_grp_fmtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Vnt_mnu_grp_fmtr_fxt fxt = new Vnt_mnu_grp_fmtr_fxt();
|
||||
@Test public void Basic() {
|
||||
// fxt.Test_to_str("Earth", "zh-hk", String_.Concat_lines_nl_skip_last
|
||||
// ( ""
|
||||
// , " <div id='p-variants' role='navigation' class='vectorMenu' aria-labelledby='p-variants-label'>"
|
||||
// , " <h3 id='p-variants-label'><span>Choose lang</span><a href='#'></a></h3>"
|
||||
// , " <div class='menu'>"
|
||||
// , " <ul>"
|
||||
// , " <li id='ca-varlang-0'><a href='/wiki/Earth?xowa_vnt=zh-hans' lang='zh-hans' hreflang='zh-hans'>Simplified</a></li>"
|
||||
// , " <li id='ca-varlang-1'><a href='/wiki/Earth?xowa_vnt=zh-hant' lang='zh-hant' hreflang='zh-hant'>Traditional</a></li>"
|
||||
// , " <li id='ca-varlang-2'><a href='/wiki/Earth?xowa_vnt=zh-cn' lang='zh-cn' hreflang='zh-cn'>China</a></li>"
|
||||
// , " <li id='ca-varlang-3' class='selected'><a href='/wiki/Earth?xowa_vnt=zh-hk' lang='zh-hk' hreflang='zh-hk'>Hong Kong</a></li>"
|
||||
// , " <li id='ca-varlang-4'><a href='/wiki/Earth?xowa_vnt=zh-mo' lang='zh-mo' hreflang='zh-mo'>Macau</a></li>"
|
||||
// , " <li id='ca-varlang-5'><a href='/wiki/Earth?xowa_vnt=zh-sg' lang='zh-sg' hreflang='zh-sg'>Singapore</a></li>"
|
||||
// , " <li id='ca-varlang-6'><a href='/wiki/Earth?xowa_vnt=zh-tw' lang='zh-tw' hreflang='zh-tw'>Taiwan</a></li>"
|
||||
// , " </ul>"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// ));
|
||||
}
|
||||
}
|
||||
class Vnt_mnu_grp_fmtr_fxt {
|
||||
private final Xol_vnt_regy mgr = new Xol_vnt_regy();
|
||||
public void Clear() {
|
||||
this.Init_grp("Choose lang", "zh-hans", "Simplified", "zh-hant", "Traditional", "zh-cn", "China", "zh-hk", "Hong Kong", "zh-mo", "Macau", "zh-sg", "Singapore", "zh-tw", "Taiwan");
|
||||
}
|
||||
public void Init_grp(String text, String... langs) {
|
||||
mgr.Clear();
|
||||
int len = langs.length;
|
||||
String lang_code = "";
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String lang = langs[i];
|
||||
if (i % 2 == 0)
|
||||
lang_code = lang;
|
||||
else {
|
||||
mgr.Add(Bry_.new_u8(lang_code), Bry_.new_u8(lang));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Test_to_str(String page_href, String selected_vnt, String expd) {
|
||||
Vnt_mnu_grp_fmtr vnt_grp_fmtr = new Vnt_mnu_grp_fmtr();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
vnt_grp_fmtr.Init(mgr, Bry_.new_u8(page_href), Bry_.new_a7("zh.wikipedia.org"), Bry_.new_u8(selected_vnt));
|
||||
vnt_grp_fmtr.Bfr_arg__add(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user