1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Wiki: Support renamed folders (fix)

This commit is contained in:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,78 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.pages.skins.*;
import gplx.xowa.htmls.hrefs.*;
class Sites_xtn_skin_itm implements Xopg_xtn_skin_itm {
private List_adp itms = List_adp_.New();
private Sites_html_bldr html_bldr;
public Sites_xtn_skin_itm(Sites_html_bldr html_bldr) {this.html_bldr = html_bldr;}
public byte Tid() {return Xopg_xtn_skin_itm_tid.Tid_sidebar;}
public byte[] Key() {return KEY;} public static final byte[] KEY = Bry_.new_a7("RelatedSites");
public void Add(Sites_regy_itm itm) {itms.Add(itm);}
public void Write(Bry_bfr bfr, Xoae_page page) {
html_bldr.Bld_all(bfr, page, itms);
}
}
public class Sites_html_bldr implements gplx.core.brys.Bfr_arg {
private Sites_xtn_mgr xtn_mgr;
private Bry_bfr tmp_ttl = Bry_bfr_.Reset(255);
private List_adp list; private int list_len;
private Hash_adp_bry hash = Hash_adp_bry.cs();
public Sites_html_bldr(Sites_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
private Bry_fmtr url_fmtr = Bry_fmtr.keys_("title");
public void Bld_all(Bry_bfr bfr, Xoae_page page, List_adp list) {
this.list = list; this.list_len = list.Count();
hash.Clear();
fmtr_grp.Bld_bfr_many(bfr, xtn_mgr.Msg_related_sites(), this);
}
public void Bfr_arg__add(Bry_bfr bfr) {
Xowe_wiki wiki = xtn_mgr.Wiki();
Xoh_href_parser href_parser = wiki.Appe().Html__href_parser();
for (int i = 0; i < list_len; ++i) {
Sites_regy_itm itm = (Sites_regy_itm)list.Get_at(i);
byte[] xwiki_itm_name = itm.Xwiki_itm().Domain_name();
if (hash.Has(xwiki_itm_name)) continue;
hash.Add(xwiki_itm_name, xwiki_itm_name);
byte[] href = Xto_href(tmp_ttl, url_fmtr, href_parser, wiki, itm.Xwiki_itm(), itm.Ttl().Page_db());
fmtr_itm.Bld_bfr(bfr, itm.Cls(), href, xwiki_itm_name);
}
}
private static byte[] Xto_href(Bry_bfr tmp_bfr, Bry_fmtr url_fmtr, Xoh_href_parser href_parser, Xowe_wiki wiki, Xow_xwiki_itm xwiki_itm, byte[] ttl_page_db) {
gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(tmp_bfr, ttl_page_db);
byte[] rv = url_fmtr.Fmt_(xwiki_itm.Url_fmt()).Bld_bry_many(tmp_bfr, tmp_bfr.To_bry_and_clear());
if (xwiki_itm.Domain_tid() != Xow_domain_tid_.Tid__other)
rv = Bry_.Add(Xoh_href_.Bry__site, rv);
return rv;
}
private static final Bry_fmtr
fmtr_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div id='p-relatedsites' class='portal'>"
, " <h3>~{related_sites_hdr}</h3>"
, " <div class='body'>"
, " <ul>~{itms}"
, " </ul>"
, " </div>"
, "</div>"
), "related_sites_hdr", "itms")
, fmtr_itm = Bry_fmtr.new_
( "\n <li class='interwiki-~{key}'><a class='xowa-hover-off' href='~{href}'>~{name}</a></li>"
, "key", "href", "name")
;
}

View File

@@ -1,69 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Sites_html_bldr_tst {
@Before public void init() {fxt.Clear();} private Sites_html_bldr_fxt fxt = new Sites_html_bldr_fxt();
@Test public void Basic() {
fxt.Init_ttl("commons:A");
fxt.Init_ttl("dmoz:A");
fxt.Init_ttl("w:A"); // not in sites_regy_mgr; ignore
fxt.Init_ttl("commons:A"); // test dupe doesn't show up
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( "<div id='p-relatedsites' class='portal'>"
, " <h3>Related sites</h3>"
, " <div class='body'>"
, " <ul>"
, " <li class='interwiki-commons'><a class='xowa-hover-off' href='/site/commons.wikimedia.org/wiki/Category:A'>Wikimedia Commons</a></li>"
, " <li class='interwiki-dmoz'><a class='xowa-hover-off' href='http://www.dmoz.org/A'>DMOZ</a></li>"
, " </ul>"
, " </div>"
, "</div>"
));
}
}
class Sites_html_bldr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
private Sites_xtn_mgr xtn_mgr;
public void Clear() {
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xop_fxt.Init_msg(wiki, "relatedsites-title", "Related sites");
this.xtn_mgr = wiki.Xtn_mgr().Xtn_sites();
xtn_mgr.Enabled_y_();
xtn_mgr.Xtn_init_by_wiki(wiki);
wiki.Xwiki_mgr().Add_by_csv(Bry_.new_a7(String_.Concat_lines_nl_skip_last
( "0|w|en.wikipedia.org/wiki/~{0}|Wikipedia"
, "0|commons|commons.wikimedia.org/wiki/Category:~{0}|Wikimedia Commons"
, "0|dmoz|http://www.dmoz.org/~{0}|DMOZ"
)));
Init_regy_mgr("commons", "dmoz");
this.page = wiki.Parser_mgr().Ctx().Page();
}
private void Init_regy_mgr(String... ary) {xtn_mgr.Regy_mgr().Set_many(ary);}
public void Init_ttl(String lnki_ttl) {
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(lnki_ttl));
xtn_mgr.Regy_mgr().Match(page, ttl);
}
public void Test_bld(String expd) {
Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
Sites_xtn_skin_itm skin_itm = (Sites_xtn_skin_itm)page.Html_data().Xtn_skin_mgr().Get_or_null(Sites_xtn_skin_itm.KEY);
skin_itm.Write(tmp_bfr, page);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -1,28 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.xwikis.*;
public class Sites_regy_itm {
public Sites_regy_itm(Xow_xwiki_itm xwiki_itm, Xoa_ttl ttl) {
this.xwiki_itm = xwiki_itm; this.ttl = ttl;
this.cls = Bry_.Lcase__all(Bry_.Copy(xwiki_itm.Key_bry()));
}
public Xow_xwiki_itm Xwiki_itm() {return xwiki_itm;} private Xow_xwiki_itm xwiki_itm;
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
public byte[] Cls() {return cls;} private byte[] cls;
}

View File

@@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.pages.skins.*;
public class Sites_regy_mgr implements Gfo_invk {
private Hash_adp_bry hash = Hash_adp_bry.cs();
private Xow_xwiki_mgr xwiki_mgr;
public Sites_regy_mgr(Sites_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
public void Init_by_wiki(Xowe_wiki wiki) {this.xwiki_mgr = wiki.Xwiki_mgr();}
public Sites_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Sites_xtn_mgr xtn_mgr;
public void Set_many(String[] keys) {
int len = keys.length;
for (int i = 0; i < len; ++i) {
byte[] key = Bry_.new_u8(keys[i]);
hash.Add_if_dupe_use_nth(key, key);
}
}
public boolean Match(Xoae_page page, Xoa_ttl lnki_ttl) {
byte[] xwiki_key = lnki_ttl.Wik_txt();
Xow_xwiki_itm xwiki_itm = xwiki_mgr.Get_by_key(xwiki_key); if (xwiki_itm == null) return false;
if (!hash.Has(xwiki_itm.Key_bry())) return false;
Xopg_xtn_skin_mgr skin_mgr = page.Html_data().Xtn_skin_mgr();
Sites_xtn_skin_itm skin_itm = (Sites_xtn_skin_itm)skin_mgr.Get_or_null(Sites_xtn_skin_itm.KEY);
if (skin_itm == null) {
skin_itm = new Sites_xtn_skin_itm(xtn_mgr.Html_bldr());
skin_mgr.Add(skin_itm);
}
Sites_regy_itm sites_itm = new Sites_regy_itm(xwiki_itm, lnki_ttl);
skin_itm.Add(sites_itm);
return true;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set_many)) Set_many(m.ReadStrAry("v", "|"));
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_set_many = "set_many";
}

View File

@@ -1,44 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.htmls.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
public class Sites_xtn_mgr extends Xox_mgr_base {
public Sites_xtn_mgr() {
html_bldr = new Sites_html_bldr(this);
regy_mgr = new Sites_regy_mgr(this);
}
@Override public boolean Enabled_default() {return false;}
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("RelatedSites");
@Override public Xox_mgr Xtn_clone_new() {return new Sites_xtn_mgr();}
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {
this.wiki = wiki;
regy_mgr.Init_by_wiki(wiki);
if (!Enabled()) return;
Xox_mgr_base.Xtn_load_i18n(wiki, XTN_KEY);
msg_related_sites = wiki.Msg_mgr().Val_by_key_obj("relatedsites-title");
}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Sites_regy_mgr Regy_mgr() {return regy_mgr;} private Sites_regy_mgr regy_mgr;
public Sites_html_bldr Html_bldr() {return html_bldr;} private Sites_html_bldr html_bldr;
public byte[] Msg_related_sites() {return msg_related_sites;} private byte[] msg_related_sites;
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (String_.Eq(k, Invk_sites)) return regy_mgr;
else return super.Invk (ctx, ikey, k, m);
}
private static final String Invk_sites = "sites";
}