(bug 31040) Fixed $wgSecureLogin effect on returnto.
authorTyler Romeo <tylerromeo@gmail.com>
Fri, 10 Aug 2012 18:59:08 +0000 (14:59 -0400)
committerTyler Anthony Romeo <tylerromeo@gmail.com>
Mon, 13 Aug 2012 12:53:43 +0000 (08:53 -0400)
Added parameter to Title::getFullURL to allow specification
of a protocol rather than assuming PROTO_RELATIVE. Also
added an accompanying parameter to Skin::makeSpecialUrl
to make a link for a specific protocol.

Cleaned up the creation of personal URLs in SkinTemplate.php
so that when $wgSecureLogin is enabled, the returnto
query is not lost in the process.

Note: This will only work if $wgServer is set to a
protocol relative URL.

Change-Id: Iba48eb3620fb3a721220364185f7abfd902412d0
Signed-off-by: Tyler Romeo <tylerromeo@gmail.com>
includes/Skin.php
includes/SkinTemplate.php
includes/Title.php

index 22cc0c9..3db4cf9 100644 (file)
@@ -1067,13 +1067,23 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param $name string
-        * @param $urlaction string
+        * Make a URL for a Special Page using the given query and protocol.
+        *
+        * If $proto is set to null, make a local URL. Otherwise, make a full
+        * URL with the protocol specified.
+        *
+        * @param $name string Name of the Special page
+        * @param $urlaction string Query to append
+        * @param $proto Protocol to use or null for a local URL
         * @return String
         */
-       static function makeSpecialUrl( $name, $urlaction = '' ) {
+       static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
                $title = SpecialPage::getSafeTitleFor( $name );
-               return $title->getLocalURL( $urlaction );
+               if( is_null( $proto ) ) {
+                       return $title->getLocalURL( $urlaction );
+               } else {
+                       return $title->getFullURL( $urlaction, false, $proto );
+               }
        }
 
        /**
index 3f07dd6..4af77d3 100644 (file)
@@ -625,35 +625,23 @@ class SkinTemplate extends Skin {
                        $is_signup = $request->getText( 'type' ) == 'signup';
 
                        # anonlogin & login are the same
+                       global $wgSecureLogin;
+                       $proto = $wgSecureLogin ? PROTO_HTTPS : null;
+
                        $login_url = array(
                                'text' => $this->msg( $loginlink )->text(),
-                               'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
-                               'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup )
+                               'href' => self::makeSpecialUrl( 'Userlogin', $returnto, $proto ),
+                               'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
+                               'class' => $wgSecureLogin ? 'link-https' : ''
+                       );
+                       $createaccount_url = array(
+                               'text' => $this->msg( 'createaccount' )->text(),
+                               'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ),
+                               'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
+                               'class' => $wgSecureLogin ? 'link-https' : ''
                        );
-                       if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
-                               $createaccount_url = array(
-                                       'text' => $this->msg( 'createaccount' )->text(),
-                                       'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
-                                       'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
-                               );
-                       }
-                       global $wgServer, $wgSecureLogin;
-                       if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
-                               $title = SpecialPage::getTitleFor( 'Userlogin' );
-                               $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
-                               $login_url['href']  = $https_url;
-                               # @todo FIXME: Class depends on skin
-                               $login_url['class'] = 'link-https';
-                               if ( isset( $createaccount_url ) ) {
-                                       $https_url = preg_replace( '/^http:/', 'https:',
-                                               $title->getFullURL( 'type=signup' ) );
-                                       $createaccount_url['href']  = $https_url;
-                                       # @todo FIXME: Class depends on skin
-                                       $createaccount_url['class'] = 'link-https';
-                               }
-                       }
 
-                       if ( isset( $createaccount_url ) ) {
+                       if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
                                $personal_urls['createaccount'] = $createaccount_url;
                        }
 
index 642f8dd..b01c00b 100644 (file)
@@ -1270,9 +1270,11 @@ class Title {
         * See getLocalURL for the arguments.
         *
         * @see self::getLocalURL
+        * @see wfExpandUrl
+        * @param $proto Protocol type to use in URL
         * @return String the URL
         */
-       public function getFullURL( $query = '', $query2 = false ) {
+       public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
                $query = self::fixUrlQueryArgs( $query, $query2 );
 
                # Hand off all the decisions on urls to getLocalURL
@@ -1281,7 +1283,7 @@ class Title {
                # Expand the url to make it a full url. Note that getLocalURL has the
                # potential to output full urls for a variety of reasons, so we use
                # wfExpandUrl instead of simply prepending $wgServer
-               $url = wfExpandUrl( $url, PROTO_RELATIVE );
+               $url = wfExpandUrl( $url, $proto );
 
                # Finally, add the fragment.
                $url .= $this->getFragmentForURL();