mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.4.1'
This commit is contained in:
@@ -164,7 +164,7 @@ public class Xow_page_mgr implements Gfo_invk {
|
||||
Xoa_ttl trg_ttl = Xoa_ttl.Parse(wiki, page_bry);
|
||||
Xoa_url trg_url = Xoa_url.New(wiki.Domain_bry(), page_bry);
|
||||
page.Ttl_(trg_ttl).Url_(trg_url);
|
||||
page.Redirect().Itms__add__special(trg_url, trg_ttl);
|
||||
page.Redirect().Itms__add__article(trg_url, trg_ttl, null);
|
||||
wiki.Data_mgr().Load_from_db(page, trg_ttl.Ns(), trg_ttl, trg_url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,36 @@ 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.wikis.pages.redirects; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xopg_redirect_data {
|
||||
import gplx.xowa.specials.*;
|
||||
public class Xopg_redirect_mgr {
|
||||
private final List_adp itms = List_adp_.New();
|
||||
public int Itms__len() {return itms.Len();}
|
||||
public byte[] Itms__get_at_0th_or_null() {return itms.Len() == 0 ? null : this.Itms__get_at(0).Wikitext();}
|
||||
public Xopg_redirect_itm Itms__get_at_nth_or_null() {return itms.Len() == 0 ? null : (Xopg_redirect_itm)itms.Get_at(itms.Len() - 1);}
|
||||
public Xopg_redirect_itm Itms__get_at(int i) {return (Xopg_redirect_itm)itms.Get_at(i);}
|
||||
public void Itms__add__article(Xoa_url url, Xoa_ttl ttl, byte[] wikitext) {Itms__add(url, ttl, wikitext);}
|
||||
public void Itms__add__special(Xoa_url url, Xoa_ttl ttl) {Itms__add(url, ttl, null);}
|
||||
public void Itms__add__special(Xow_wiki wiki, Xow_special_meta meta, Keyval... url_args) {
|
||||
// build url and include args if available
|
||||
byte[] url_bry = meta.Ttl_bry();
|
||||
int url_args_len = url_args.length;
|
||||
if (url_args_len > 0) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
bfr.Add(url_bry);
|
||||
for (int i = 0; i < url_args_len; ++i) {
|
||||
Keyval url_arg = url_args[i];
|
||||
bfr.Add_byte(i == 0 ? Byte_ascii.Question : Byte_ascii.Amp);
|
||||
bfr.Add_str_u8(url_arg.Key());
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
bfr.Add_obj(url_arg.Val());
|
||||
}
|
||||
url_bry = bfr.To_bry_and_clear();
|
||||
}
|
||||
|
||||
// create objects and add to list
|
||||
Xoa_url url = wiki.Utl__url_parser().Parse(url_bry);
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(meta.Ttl_bry());
|
||||
this.Itms__add(url, ttl, null);
|
||||
}
|
||||
private void Itms__add(Xoa_url url, Xoa_ttl ttl, byte[] wikitext) {
|
||||
Xopg_redirect_itm itm = new Xopg_redirect_itm(url, ttl, wikitext);
|
||||
itms.Add(itm);
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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.wikis.pages.redirects; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.pages.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.specials.*;
|
||||
public class Xopg_redirect_mgr__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xopg_redirect_mgr__fxt fxt = new Xopg_redirect_mgr__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__Itms__add__special(fxt.Make_meta("XowaTest"), Keyval_.Ary_empty, fxt.Make__itm("en.wikipedia.org/wiki/Special:XowaTest", "Special:XowaTest", null));
|
||||
}
|
||||
@Test public void Args() {
|
||||
fxt.Test__Itms__add__special
|
||||
( fxt.Make_meta("XowaTest"), Keyval_.Ary(Keyval_.new_("k1", "v1"), Keyval_.new_("k2", "v2"), Keyval_.new_("k3", "v3"))
|
||||
, fxt.Make__itm("en.wikipedia.org/wiki/Special:XowaTest?k1=v1&k2=v2&k3=v3", "Special:XowaTest", null)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xopg_redirect_mgr__fxt {
|
||||
private Xow_wiki wiki;
|
||||
private final Xopg_redirect_mgr mgr = new Xopg_redirect_mgr();
|
||||
public void Clear() {
|
||||
mgr.Clear();
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
public Xow_special_meta Make_meta(String key) {return Xow_special_meta.New_xo(key, "test display name");}
|
||||
public Xopg_redirect_itm Make__itm(String url_str, String ttl_str, String wikitext) {
|
||||
Xoa_url url = wiki.Utl__url_parser().Parse(Bry_.new_u8(url_str));
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(Bry_.new_u8(ttl_str));
|
||||
return new Xopg_redirect_itm(url, ttl, Bry_.new_u8_safe(wikitext));
|
||||
}
|
||||
public void Test__Itms__add__special(Xow_special_meta meta, Keyval[] url_args, Xopg_redirect_itm expd) {
|
||||
mgr.Itms__add__special(wiki, meta, url_args);
|
||||
Xopg_redirect_itm actl = mgr.Itms__get_at(0);
|
||||
Gftest.Eq__bry(expd.Ttl().Raw(), actl.Ttl().Raw(), "ttl");
|
||||
Gftest.Eq__str(expd.Url().To_str(), actl.Url().To_str(), "url");
|
||||
Gftest.Eq__bry(expd.Wikitext(), actl.Wikitext(), "wikitext");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user