From: Roan Kattouw Date: Tue, 14 Jul 2009 21:25:33 +0000 (+0000) Subject: Add returntoquery= parameter to Special:Userlogin which adds a query string to the... X-Git-Tag: 1.31.0-rc.0~40953 X-Git-Url: http://git.cyclocoop.org/%27%20.%20url_absolue%28%24favicon%29%20.%20?a=commitdiff_plain;h=7a7cf1a2f9468e0ac27dcd078da4a53e10cbe017;p=lhc%2Fweb%2Fwiklou.git Add returntoquery= parameter to Special:Userlogin which adds a query string to the "Return to" link. Also using this parameter in the Log in and Log out links on top of the screen, so that people who click Log in from e.g. an edit page will be taken back to the edit page rather than to the page view. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 6c3fdb13f1..e0014a70da 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/OutputPage.php b/includes/OutputPage.php index f1647a61bc..a0d8790dde 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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( "

{$link}

\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 ); } /** diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index e25f0c8f10..82574cd48d 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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' ) ); } diff --git a/includes/Title.php b/includes/Title.php index b18b28a804..490ebfa2cb 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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() !== '' ) { diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index fa1bfdbcf1..def3ac9404 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -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; }