Add returntoquery= parameter to Special:Userlogin which adds a query string to the...
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 14 Jul 2009 21:25:33 +0000 (21:25 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 14 Jul 2009 21:25:33 +0000 (21:25 +0000)
RELEASE-NOTES
includes/OutputPage.php
includes/SkinTemplate.php
includes/Title.php
includes/specials/SpecialUserlogin.php

index 6c3fdb1..e0014a7 100644 (file)
@@ -251,6 +251,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 19693) User name is now escaped in "Contributions for ..." link on
   Special:BlockIP
 * (bug 19571) Override buildConcat for SQLite.
+* Log in and log out links no longer return to page view when clicked from
+  history view, edit page, or something similar
 
 == API changes in 1.16 ==
 
index f1647a6..a0d8790 100644 (file)
@@ -1467,11 +1467,13 @@ class OutputPage {
         * Add a "return to" link pointing to a specified title
         *
         * @param Title $title Title to link
+        * @param string $query Query string
         */
-       public function addReturnTo( $title ) {
+       public function addReturnTo( $title, $query ) {
                global $wgUser;
                $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
-               $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link( $title ) );
+               $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link(
+                       $title, null, array(), $query ) );
                $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
        }
 
@@ -1482,12 +1484,16 @@ class OutputPage {
         * @param null $unused No longer used
         * @param Title $returnto Title to return to
         */
-       public function returnToMain( $unused = null, $returnto = NULL ) {
+       public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
                global $wgRequest;
 
-               if ( $returnto == NULL ) {
+               if ( $returnto == null ) {
                        $returnto = $wgRequest->getText( 'returnto' );
                }
+               
+               if ( $returntoquery == null ) {
+                       $returntoquery = $wgRequest->getText( 'returntoquery' );
+               }
 
                if ( '' === $returnto ) {
                        $returnto = Title::newMainPage();
@@ -1502,7 +1508,7 @@ class OutputPage {
                        $titleObj = Title::newMainPage();
                }
 
-               $this->addReturnTo( $titleObj );
+               $this->addReturnTo( $titleObj, $returntoquery );
        }
 
        /**
index e25f0c8..82574cd 100644 (file)
@@ -164,6 +164,9 @@ class SkinTemplate extends Skin {
                wfProfileIn( __METHOD__ . '-stuff' );
                $this->thispage = $this->mTitle->getPrefixedDBkey();
                $this->thisurl = $this->mTitle->getPrefixedURL();
+               $query = $wgRequest->data;
+               unset( $query['title'] );
+               $this->thisquery = wfArrayToCGI( $query );
                $this->loggedin = $wgUser->isLoggedIn();
                $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
                $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
@@ -562,7 +565,7 @@ class SkinTemplate extends Skin {
                        $personal_urls['logout'] = array(
                                'text' => wfMsg( 'userlogout' ),
                                'href' => self::makeSpecialUrl( 'Userlogout',
-                                       $title->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
+                                       $title->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}&returntoquery={$this->thisquery}"
                                ),
                                'active' => false
                        );
@@ -589,13 +592,13 @@ class SkinTemplate extends Skin {
                                );
                                $personal_urls['anonlogin'] = array(
                                        'text' => wfMsg( $loginlink ),
-                                       'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
+                                       'href' => self::makeSpecialUrl( 'Userlogin', "returnto={$this->thisurl}&returntoquery={$this->thisquery}" ),
                                        'active' => $title->isSpecial( 'Userlogin' )
                                );
                        } else {
                                $personal_urls['login'] = array(
                                        'text' => wfMsg( $loginlink ),
-                                       'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
+                                       'href' => self::makeSpecialUrl( 'Userlogin', "returnto={$this->thisurl}&returntoquery={$this->thisquery}" ),
                                        'active' => $title->isSpecial( 'Userlogin' )
                                );
                        }
index b18b28a..490ebfa 100644 (file)
@@ -862,11 +862,6 @@ class Title {
         */
        public function getLinkUrl( $query = array(), $variant = false ) {
                wfProfileIn( __METHOD__ );
-               if( !is_array( $query ) ) {
-                       wfProfileOut( __METHOD__ );
-                       throw new MWException( 'Title::getLinkUrl passed a non-array for '.
-                       '$query' );
-               }
                if( $this->isExternal() ) {
                        $ret = $this->getFullURL( $query );
                } elseif( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) {
index fa1bfdb..def3ac9 100644 (file)
@@ -37,7 +37,8 @@ class LoginForm {
 
        var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
        var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
-       var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage, $mSkipCookieCheck;
+       var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
+       var $mSkipCookieCheck, $mReturnToQuery;
 
        /**
         * Constructor
@@ -53,6 +54,7 @@ class LoginForm {
                $this->mRetype = $request->getText( 'wpRetype' );
                $this->mDomain = $request->getText( 'wpDomain' );
                $this->mReturnTo = $request->getVal( 'returnto' );
+               $this->mReturnToQuery = $request->getVal( 'returntoquery' );
                $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
                $this->mPosted = $request->wasPosted();
                $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
@@ -68,6 +70,7 @@ class LoginForm {
 
                if ( $wgRedirectOnLogin ) {
                        $this->mReturnTo = $wgRedirectOnLogin;
+                       $this->mReturnToQuery = '';
                }
 
                if( $wgEnableEmail ) {
@@ -89,6 +92,7 @@ class LoginForm {
                # When switching accounts, it sucks to get automatically logged out
                if( $this->mReturnTo == $wgLang->specialPage( 'Userlogout' ) ) {
                        $this->mReturnTo = '';
+                       $this->mReturnToQuery = '';
                }
        }
 
@@ -719,8 +723,7 @@ class LoginForm {
                        if ( !$titleObj instanceof Title ) {
                                $titleObj = Title::newMainPage();
                        }
-
-                       $wgOut->redirect( $titleObj->getFullURL() );
+                       $wgOut->redirect( $titleObj->getFullURL( $this->mReturnToQuery ) );
                }
        }
 
@@ -753,7 +756,7 @@ class LoginForm {
                $wgOut->addHTML( $injected_html );
 
                if ( !empty( $this->mReturnTo ) ) {
-                       $wgOut->returnToMain( null, $this->mReturnTo );
+                       $wgOut->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery );
                } else {
                        $wgOut->returnToMain( null );
                }
@@ -852,6 +855,9 @@ class LoginForm {
 
                if ( !empty( $this->mReturnTo ) ) {
                        $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
+                       if ( !empty( $this->mReturnToQuery ) )
+                               $returnto .= '&returntoquery=' .
+                                       wfUrlencode( $this->mReturnToQuery );
                        $q .= $returnto;
                        $linkq .= $returnto;
                }