Forward the edit-state when redirecting to renamed articles.

This improves usability with noscript
This commit is contained in:
Magnus Hovland Hoff 2018-09-24 23:01:01 +02:00
parent e92c9695be
commit a81a568ee2
2 changed files with 15 additions and 10 deletions

View file

@ -14,14 +14,18 @@ impl TemporaryRedirectResource {
Self { location } Self { location }
} }
pub fn from_slug<S: AsRef<str>>(slug: S) -> Self { pub fn from_slug<S: AsRef<str>>(slug: S, edit: bool) -> Self {
let base =
if slug.as_ref().is_empty() {
"."
} else {
slug.as_ref()
};
let tail = if edit { "?edit" } else { "" };
Self { Self {
location: location: format!("{}{}", base, tail)
if slug.as_ref().is_empty() {
"."
} else {
slug.as_ref()
}.to_owned()
} }
} }
} }

View file

@ -220,16 +220,17 @@ impl WikiLookup {
return Box::new(finished(None)); return Box::new(finished(None));
} }
let edit = query == Some("edit");
// Normalize all user-generated slugs: // Normalize all user-generated slugs:
let slugified_slug = slugify(&slug); let slugified_slug = slugify(&slug);
if slugified_slug != slug { if slugified_slug != slug {
return Box::new(finished(Some( return Box::new(finished(Some(
Box::new(TemporaryRedirectResource::from_slug(slugified_slug)) as BoxResource Box::new(TemporaryRedirectResource::from_slug(slugified_slug, edit)) as BoxResource
))); )));
} }
let state = self.state.clone(); let state = self.state.clone();
let edit = query == Some("edit");
let slug = slug.into_owned(); let slug = slug.into_owned();
use state::SlugLookup; use state::SlugLookup;
@ -240,7 +241,7 @@ impl WikiLookup {
SlugLookup::Hit { article_id, revision } => SlugLookup::Hit { article_id, revision } =>
Box::new(ArticleResource::new(state, article_id, revision, edit)) as BoxResource, Box::new(ArticleResource::new(state, article_id, revision, edit)) as BoxResource,
SlugLookup::Redirect(slug) => SlugLookup::Redirect(slug) =>
Box::new(TemporaryRedirectResource::from_slug(slug)) as BoxResource, Box::new(TemporaryRedirectResource::from_slug(slug, edit)) as BoxResource,
}))) })))
) )
} }