(bug 32230) Expose wgRedirectedFrom (title of the page we were redirected from, if...
authorRoan Kattouw <catrope@users.mediawiki.org>
Wed, 30 Nov 2011 12:43:10 +0000 (12:43 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Wed, 30 Nov 2011 12:43:10 +0000 (12:43 +0000)
includes/Article.php
includes/OutputPage.php

index bb3ac37..5633e2a 100644 (file)
@@ -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 ) {
index 41bec57..feae2c1 100644 (file)
@@ -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 \<h1\>. It is stored as a valid HTML fragment.
         * This function allows good tags like \<sup\> in the \<h1\> tag, but not bad tags like \<script\>.
@@ -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