1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 14:30:51 +00:00

Embeddable: Handle redirects

This commit is contained in:
gnosygnu 2017-05-29 14:43:13 -04:00
parent f129344506
commit d521299987
3 changed files with 25 additions and 5 deletions

View File

@ -30,8 +30,8 @@ public class Xoa_app_ {
}
}
public static final String Name = "xowa";
public static final int Version_id = 526;
public static final String Version = "4.5.4.1705";
public static final int Version_id = 527;
public static final String Version = "4.5.5.1705";
public static String Build_date = "2012-12-30 00:00:00";
public static String Build_date_fmt = "yyyy-MM-dd HH:mm:ss";
public static String Op_sys_str;

View File

@ -25,7 +25,7 @@ public class Xop_mediawiki_wkr {
}
public void Loader_(Xop_mediawiki_loader loader) {
if (loader != null)
wiki.Cache_mgr().Load_wkr_(new Xow_page_cache_wkr__embeddable(loader));
wiki.Cache_mgr().Load_wkr_(new Xow_page_cache_wkr__embeddable(wiki, loader));
}
public void Free_memory() {
wiki.Cache_mgr().Tmpl_result_cache().Clear();

View File

@ -14,12 +14,32 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.parsers.mediawikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.parsers.*;
import gplx.xowa.parsers.utils.*;
class Xow_page_cache_wkr__embeddable implements gplx.xowa.wikis.caches.Xow_page_cache_wkr {
private final Xop_mediawiki_loader cbk;
public Xow_page_cache_wkr__embeddable(Xop_mediawiki_loader cbk) {
private final Xop_redirect_mgr redirect_mgr;
public Xow_page_cache_wkr__embeddable(Xowe_wiki wiki, Xop_mediawiki_loader cbk) {
this.cbk = cbk;
this.redirect_mgr = new Xop_redirect_mgr(wiki);
}
public byte[] Get_page_or_null(byte[] full_db) {
return Bry_.new_u8(cbk.LoadWikitext(String_.new_u8(full_db)));
byte[] wikitext = null;
// loop to handle redirects
int loops = 0;
while (loops++ < 5) {
wikitext = Bry_.new_u8(cbk.LoadWikitext(String_.new_u8(full_db)));
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(wikitext);
// not a redirect; exit loop
if (redirect_ttl == null) {
break;
}
// redirect
else {
full_db = redirect_ttl.Full_db();
continue;
}
}
return wikitext;
}
}