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,90 +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.relatedArticles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.htmls.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Articles_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_relatedArticles;}
@Override public Pf_func New(int id, byte[] name) {return new Articles_func().Name_(name);}
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
byte[] argx = this.Eval_argx(ctx, src, caller, self);
Articles_xtn_skin_itm xtn_itm = (Articles_xtn_skin_itm)ctx.Page().Html_data().Xtn_skin_mgr().Get_or_null(Articles_xtn_skin_itm.KEY);
if (xtn_itm == null) {
xtn_itm = new Articles_xtn_skin_itm();
ctx.Page().Html_data().Xtn_skin_mgr().Add(xtn_itm);
}
Parse(xtn_itm, argx);
}
private void Parse(Articles_xtn_skin_itm xtn_itm, byte[] argx) {
int pos = Bry_find_.Find_fwd(argx, Const_dlm);
if (pos == Bry_find_.Not_found) // && missing; argx is both ttl and text
xtn_itm.Add(new Articles_itm(argx, argx));
else { // && exists; split by &&
byte[] ttl = Bry_.Trim(Bry_.Mid(argx, 0, pos));
byte[] text = Bry_.Trim(Bry_.Mid(argx, pos + Const_dlm.length));
xtn_itm.Add(new Articles_itm(ttl, text));
}
}
public static final Articles_func Instance = new Articles_func(); Articles_func() {}
private static final byte[] Const_dlm = new byte[] {Byte_ascii.Amp, Byte_ascii.Amp};
}
class Articles_itm {
public Articles_itm(byte[] ttl, byte[] text) {
this.ttl = ttl;
this.text = Xoa_ttl.Replace_unders(text); // placed in ctor, b/c called from two places above; DATE:2014-09-03
}
public byte[] Ttl() {return ttl;} private byte[] ttl;
public byte[] Text() {return text;} private byte[] text;
}
class Articles_itm_fmtr implements gplx.core.brys.Bfr_arg {
private Xowe_wiki wiki; private List_adp itms;
public void Init(Xowe_wiki wiki, List_adp itms) {this.wiki = wiki; this.itms = itms;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = itms.Count();
for (int i = 0; i < len; i++) {
Articles_itm itm = (Articles_itm)itms.Get_at(i);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, itm.Ttl()); if (ttl == null) continue;
fmtr.Bld_bfr(bfr, ttl.Full_db(), itm.Text());
}
}
private static final Bry_fmtr fmtr = Bry_fmtr.new_("\n <li class=\"interwiki-relart\"><a href=\"/wiki/~{ttl}\">~{text}</a></li>", "ttl", "text");
public static final Articles_itm_fmtr Instance = new Articles_itm_fmtr(); Articles_itm_fmtr() {}
}
class Articles_xtn_skin_itm implements Xopg_xtn_skin_itm {
private List_adp itms = List_adp_.New();
public byte Tid() {return Xopg_xtn_skin_itm_tid.Tid_sidebar;}
public byte[] Key() {return KEY;} public static final byte[] KEY = Bry_.new_a7("RelatedArticles");
public void Add(Articles_itm itm) {itms.Add(itm);}
public void Write(Bry_bfr bfr, Xoae_page page) {
Xowe_wiki wiki = page.Wikie();
itms_fmtr.Init(wiki, itms);
html_fmtr.Bld_bfr_many(bfr, wiki.Msg_mgr().Val_by_key_obj("relatedarticles-title"), itms_fmtr);
}
private static final Articles_itm_fmtr itms_fmtr = Articles_itm_fmtr.Instance;
private static final Bry_fmtr html_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
, " <h3>~{h3}</h3>"
, " <div class=\"body\">"
, " <ul>~{itms}"
, " </ul>"
, " </div>"
, "</div>"
), "h3", "itms");
}

View File

@@ -1,50 +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.relatedArticles; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.wikis.pages.skins.*;
public class Articles_func_tst {
@Before public void init() {fxt.Reset();} private Articles_func_fxt fxt = new Articles_func_fxt();
@Test public void Basic() {
fxt.Test_parse("{{#related:A1 && A 1}}{{#related:B1 && B_1}}{{#related:C_1}}", String_.Concat_lines_nl_skip_last // C1 handles no caption; PAGE:de.v:W<>rzburg; DATE:2014-08-06
( "<div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
, " <h3>Related articles</h3>"
, " <div class=\"body\">"
, " <ul>"
, " <li class=\"interwiki-relart\"><a href=\"/wiki/A1\">A 1</a></li>"
, " <li class=\"interwiki-relart\"><a href=\"/wiki/B1\">B 1</a></li>"
, " <li class=\"interwiki-relart\"><a href=\"/wiki/C_1\">C 1</a></li>"
, " </ul>"
, " </div>"
, "</div>"
));
}
}
class Articles_func_fxt {
private final Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Wiki().Lang().Msg_mgr().Itm_by_key_or_new("relatedarticles-title", "Related articles");
fxt.Reset();
}
public void Test_parse(String raw, String expd) {
fxt.Test_parse_page_all_str(raw, "");
Xopg_xtn_skin_fmtr_arg fmtr_arg = new Xopg_xtn_skin_fmtr_arg(fxt.Page(), Xopg_xtn_skin_itm_tid.Tid_sidebar);
Bry_bfr bfr = Bry_bfr_.New();
fmtr_arg.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}