r53270 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53269‎ | r53270 | r53271 >
Date:21:25, 14 July 2009
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -1467,11 +1467,13 @@
14681468 * Add a "return to" link pointing to a specified title
14691469 *
14701470 * @param Title $title Title to link
 1471+ * @param string $query Query string
14711472 */
1472 - public function addReturnTo( $title ) {
 1473+ public function addReturnTo( $title, $query ) {
14731474 global $wgUser;
14741475 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
1475 - $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link( $title ) );
 1476+ $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link(
 1477+ $title, null, array(), $query ) );
14761478 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
14771479 }
14781480
@@ -1482,12 +1484,16 @@
14831485 * @param null $unused No longer used
14841486 * @param Title $returnto Title to return to
14851487 */
1486 - public function returnToMain( $unused = null, $returnto = NULL ) {
 1488+ public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
14871489 global $wgRequest;
14881490
1489 - if ( $returnto == NULL ) {
 1491+ if ( $returnto == null ) {
14901492 $returnto = $wgRequest->getText( 'returnto' );
14911493 }
 1494+
 1495+ if ( $returntoquery == null ) {
 1496+ $returntoquery = $wgRequest->getText( 'returntoquery' );
 1497+ }
14921498
14931499 if ( '' === $returnto ) {
14941500 $returnto = Title::newMainPage();
@@ -1502,7 +1508,7 @@
15031509 $titleObj = Title::newMainPage();
15041510 }
15051511
1506 - $this->addReturnTo( $titleObj );
 1512+ $this->addReturnTo( $titleObj, $returntoquery );
15071513 }
15081514
15091515 /**
Index: trunk/phase3/includes/Title.php
@@ -862,11 +862,6 @@
863863 */
864864 public function getLinkUrl( $query = array(), $variant = false ) {
865865 wfProfileIn( __METHOD__ );
866 - if( !is_array( $query ) ) {
867 - wfProfileOut( __METHOD__ );
868 - throw new MWException( 'Title::getLinkUrl passed a non-array for '.
869 - '$query' );
870 - }
871866 if( $this->isExternal() ) {
872867 $ret = $this->getFullURL( $query );
873868 } elseif( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) {
Index: trunk/phase3/includes/SkinTemplate.php
@@ -164,6 +164,9 @@
165165 wfProfileIn( __METHOD__ . '-stuff' );
166166 $this->thispage = $this->mTitle->getPrefixedDBkey();
167167 $this->thisurl = $this->mTitle->getPrefixedURL();
 168+ $query = $wgRequest->data;
 169+ unset( $query['title'] );
 170+ $this->thisquery = wfArrayToCGI( $query );
168171 $this->loggedin = $wgUser->isLoggedIn();
169172 $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
170173 $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
@@ -562,7 +565,7 @@
563566 $personal_urls['logout'] = array(
564567 'text' => wfMsg( 'userlogout' ),
565568 'href' => self::makeSpecialUrl( 'Userlogout',
566 - $title->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
 569+ $title->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}&returntoquery={$this->thisquery}"
567570 ),
568571 'active' => false
569572 );
@@ -589,13 +592,13 @@
590593 );
591594 $personal_urls['anonlogin'] = array(
592595 'text' => wfMsg( $loginlink ),
593 - 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
 596+ 'href' => self::makeSpecialUrl( 'Userlogin', "returnto={$this->thisurl}&returntoquery={$this->thisquery}" ),
594597 'active' => $title->isSpecial( 'Userlogin' )
595598 );
596599 } else {
597600 $personal_urls['login'] = array(
598601 'text' => wfMsg( $loginlink ),
599 - 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
 602+ 'href' => self::makeSpecialUrl( 'Userlogin', "returnto={$this->thisurl}&returntoquery={$this->thisquery}" ),
600603 'active' => $title->isSpecial( 'Userlogin' )
601604 );
602605 }
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -37,7 +37,8 @@
3838
3939 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
4040 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
41 - var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage, $mSkipCookieCheck;
 41+ var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
 42+ var $mSkipCookieCheck, $mReturnToQuery;
4243
4344 /**
4445 * Constructor
@@ -53,6 +54,7 @@
5455 $this->mRetype = $request->getText( 'wpRetype' );
5556 $this->mDomain = $request->getText( 'wpDomain' );
5657 $this->mReturnTo = $request->getVal( 'returnto' );
 58+ $this->mReturnToQuery = $request->getVal( 'returntoquery' );
5759 $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
5860 $this->mPosted = $request->wasPosted();
5961 $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
@@ -68,6 +70,7 @@
6971
7072 if ( $wgRedirectOnLogin ) {
7173 $this->mReturnTo = $wgRedirectOnLogin;
 74+ $this->mReturnToQuery = '';
7275 }
7376
7477 if( $wgEnableEmail ) {
@@ -89,6 +92,7 @@
9093 # When switching accounts, it sucks to get automatically logged out
9194 if( $this->mReturnTo == $wgLang->specialPage( 'Userlogout' ) ) {
9295 $this->mReturnTo = '';
 96+ $this->mReturnToQuery = '';
9397 }
9498 }
9599
@@ -719,8 +723,7 @@
720724 if ( !$titleObj instanceof Title ) {
721725 $titleObj = Title::newMainPage();
722726 }
723 -
724 - $wgOut->redirect( $titleObj->getFullURL() );
 727+ $wgOut->redirect( $titleObj->getFullURL( $this->mReturnToQuery ) );
725728 }
726729 }
727730
@@ -753,7 +756,7 @@
754757 $wgOut->addHTML( $injected_html );
755758
756759 if ( !empty( $this->mReturnTo ) ) {
757 - $wgOut->returnToMain( null, $this->mReturnTo );
 760+ $wgOut->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery );
758761 } else {
759762 $wgOut->returnToMain( null );
760763 }
@@ -852,6 +855,9 @@
853856
854857 if ( !empty( $this->mReturnTo ) ) {
855858 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
 859+ if ( !empty( $this->mReturnToQuery ) )
 860+ $returnto .= '&returntoquery=' .
 861+ wfUrlencode( $this->mReturnToQuery );
856862 $q .= $returnto;
857863 $linkq .= $returnto;
858864 }
Index: trunk/phase3/RELEASE-NOTES
@@ -251,6 +251,8 @@
252252 * (bug 19693) User name is now escaped in "Contributions for ..." link on
253253 Special:BlockIP
254254 * (bug 19571) Override buildConcat for SQLite.
 255+* Log in and log out links no longer return to page view when clicked from
 256+ history view, edit page, or something similar
255257
256258 == API changes in 1.16 ==
257259

Follow-up revisions

RevisionCommit summaryAuthorDate
r53293Couple of issues in r53270: use accessor method and keep the function signatu...nikerabbit06:43, 15 July 2009
r53305Fix encoding issue in r53270catrope10:22, 15 July 2009
r53777Fix r53270: drop &returntoquery parameter if empty, and prevent Special:Userl...catrope10:34, 26 July 2009
r54535Merge trunk fixes to support returnto query params, needed for OptIn smoothness...brion18:15, 6 August 2009

Comments

#Comment by OverlordQ (talk | contribs)   02:11, 15 July 2009

Causes file deletion to throw an error, see bug #19727

#Comment by Nikerabbit (talk | contribs)   06:42, 15 July 2009

This doesn't seem to work properly, only the first param is remembered if there is many.

#Comment by Catrope (talk | contribs)   10:23, 15 July 2009

Fixed in r53305

#Comment by Umherirrender (talk | contribs)   18:31, 23 July 2009

This produce very long url. It is possible to exclude a parameter, when he is empty?

#Comment by Catrope (talk | contribs)   10:34, 26 July 2009

Long URL and loop fixed in r53777

#Comment by Trevor Parscal (WMF) (talk | contribs)   16:26, 6 August 2009

Does this fix bug #13? I think it does...

Status & tagging log