From 4893afd833335ed6758186e93114407f7eac5681 Mon Sep 17 00:00:00 2001 From: Tyler Romeo Date: Fri, 10 Aug 2012 14:59:08 -0400 Subject: [PATCH] (bug 31040) Fixed $wgSecureLogin effect on returnto. 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 --- includes/Skin.php | 18 ++++++++++++++---- includes/SkinTemplate.php | 38 +++++++++++++------------------------- includes/Title.php | 6 ++++-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index 22cc0c997c..3db4cf9440 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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 ); + } } /** diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 3f07dd613a..4af77d3198 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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; } diff --git a/includes/Title.php b/includes/Title.php index 642f8dd7e5..b01c00b75b 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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(); -- 2.20.1