Redirect: Allow redirects to Special pages

pull/620/head
gnosygnu 8 years ago
parent 982cd2b848
commit 4c3ea9890d

@ -32,6 +32,9 @@ public class Xow_page_mgr implements Gfo_invk {
} }
private void Load_by_ns(Xoae_page rv, Xoa_url url, Xoa_ttl ttl, boolean called_from_msg) { private void Load_by_ns(Xoae_page rv, Xoa_url url, Xoa_ttl ttl, boolean called_from_msg) {
rv.Url_(url); // NOTE: must update page.Url(); should combine with Xoae_page.New() rv.Url_(url); // NOTE: must update page.Url(); should combine with Xoae_page.New()
// WORKAROUND: loop twice in order to allow redirects from regular page to special
for (int i = 0; i < 2; i++) {
Xow_ns ns = ttl.Ns(); Xow_ns ns = ttl.Ns();
switch (ns.Id()) { switch (ns.Id()) {
case Xow_ns_.Tid__special: // Special pages are built (not loaded from db) case Xow_ns_.Tid__special: // Special pages are built (not loaded from db)
@ -57,15 +60,21 @@ public class Xow_page_mgr implements Gfo_invk {
} }
break; break;
} }
Load_from_db(rv, ns, ttl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no)); Xoa_ttl redirect_ttl = Load_from_db(rv, ns, ttl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no));
if (redirect_ttl != null && redirect_ttl.Ns().Id_is_special()) {
ttl = redirect_ttl;
rv.Redirect_trail().Clear();
rv.Db().Page().Exists_y_();
}
} }
public void Load_from_db(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean redirect_force) { }
public Xoa_ttl Load_from_db(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean redirect_force) {
int redirects = 0; int redirects = 0;
Xowd_page_itm page_row = Xowd_page_itm.new_tmp(); Xowd_page_itm page_row = Xowd_page_itm.new_tmp();
while (true) { // loop until (a) no more redirects or (b) page not found while (true) { // loop until (a) no more redirects or (b) page not found
// load from page table // load from page table
boolean exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(page_row, ns, ttl.Page_db()); boolean exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(page_row, ns, ttl.Page_db());
if (!exists) {rv.Db().Page().Exists_n_(); return;} if (!exists) {rv.Db().Page().Exists_n_(); return ttl;}
if (wiki.App().Mode().Tid_is_gui()) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03 if (wiki.App().Mode().Tid_is_gui()) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03
wiki.Appe().Usr_dlg().Prog_many("", "", "loading page for ~{0}", ttl.Raw()); wiki.Appe().Usr_dlg().Prog_many("", "", "loading page for ~{0}", ttl.Raw());
@ -76,20 +85,20 @@ public class Xow_page_mgr implements Gfo_invk {
wiki.Db_mgr().Load_mgr().Load_page(page_row, ns); wiki.Db_mgr().Load_mgr().Load_page(page_row, ns);
byte[] wtxt = page_row.Text(); byte[] wtxt = page_row.Text();
rv.Db().Text().Text_bry_(wtxt); rv.Db().Text().Text_bry_(wtxt);
if (redirect_force) return; // redirect_force passed; return page now, even if page is a redirect elsewhere; NOTE: only applies to WTXT, not HTML if (redirect_force) return ttl; // redirect_force passed; return page now, even if page is a redirect elsewhere; NOTE: only applies to WTXT, not HTML
// handle redirects for html_dbs // handle redirects for html_dbs
if ( page_row.Redirect_id() > 0 // redirect exists if ( page_row.Redirect_id() > 0 // redirect exists
&& Bry_.Len_eq_0(wtxt)) { // wikitext is not found && Bry_.Len_eq_0(wtxt)) { // wikitext is not found
Redirect_to_html_page(rv, wiki, page_row); Redirect_to_html_page(rv, wiki, page_row);
return; return ttl;
} }
// handle redirects // handle redirects
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(wtxt); Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(wtxt);
if ( redirect_ttl == null // not a redirect if ( redirect_ttl == null // not a redirect
|| redirects++ > 4) // too many redirects; something went wrong || redirects++ > 4) // too many redirects; something went wrong
return; return redirect_ttl;
// redirect; do some bookkeeping and reset ns / ttl // redirect; do some bookkeeping and reset ns / ttl
// NOTE: this adds the target ttl to redirect_mgr (#REDIRECT [[A]]); note that special redirects will add source ttl; DATE:2016-07-31 // NOTE: this adds the target ttl to redirect_mgr (#REDIRECT [[A]]); note that special redirects will add source ttl; DATE:2016-07-31

Loading…
Cancel
Save