From 00bad0cf9b0500f02b2d95a135c2348cba2fc62c Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 30 Nov 2011 12:43:10 +0000 Subject: [PATCH] (bug 32230) Expose wgRedirectedFrom (title of the page we were redirected from, if any) in JavaScript. Patch by MrBlueSky --- includes/Article.php | 3 +++ includes/OutputPage.php | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/includes/Article.php b/includes/Article.php index bb3ac3780f..5633e2aaf2 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -823,6 +823,9 @@ class Article extends Page { 'href' => $this->getTitle()->getLocalURL() ) ); + // Tell $wgOut the user arrived at this article through a redirect + $wgOut->setRedirectedFrom( $this->mRedirectedFrom ); + return true; } } elseif ( $rdfrom ) { diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 41bec576ec..feae2c1451 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -222,6 +222,14 @@ class OutputPage extends ContextSource { 'Cookie' => null ); + /** + * If the current page was reached through a redirect, $mRedirectedFrom contains the Title + * of the redirect. + * + * @var Title + */ + private $mRedirectedFrom = null; + /** * Constructor for OutputPage. This should not be called directly. * Instead a new RequestContext should be created and it will implicitly create @@ -776,6 +784,15 @@ class OutputPage extends ContextSource { return $this->mHTMLtitle; } + /** + * Set $mRedirectedFrom, the Title of the page which redirected us to the current page. + * + * param @t Title + */ + public function setRedirectedFrom( $t ) { + $this->mRedirectedFrom = $t; + } + /** * "Page title" means the contents of \. It is stored as a valid HTML fragment. * This function allows good tags like \ in the \ tag, but not bad tags like \. @@ -2781,6 +2798,9 @@ $templates if ( $title->isMainPage() ) { $vars['wgIsMainPage'] = true; } + if ( $this->mRedirectedFrom ) { + $vars['wgRedirectedFrom'] = $this->mRedirectedFrom->getPrefixedDBKey(); + } // Allow extensions to add their custom variables to the mw.config map. // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not -- 2.20.1