r98745 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98744‎ | r98745 | r98746 >
Date:10:27, 3 October 2011
Author:catrope
Status:ok
Tags:
Comment:
(bug 31320) CentralAuth uses http URLs for autologin images when logging in over https.

Renamed WikiReference::getUrl() to getCanonicalUrl() (but kept the old name as a back compat alias), and added getFullUrl() which returns a URL built using $wgServer rather than $wgCanonicalServer, which means it'll be protocol-relative if the wiki is configured for that.
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthHooks.php (modified) (history)
  • /trunk/phase3/includes/WikiMap.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WikiMap.php
@@ -20,11 +20,13 @@
2121 if( $major === null ) {
2222 return null;
2323 }
24 - $server = $wgConf->get( 'wgCanonicalServer', $wikiID, $major,
 24+ $canonicalServer = $wgConf->get( 'wgCanonicalServer', $wikiID, $major,
2525 array( 'lang' => $minor, 'site' => $major ) );
 26+ $server = $wgConf->get( 'wgServer', $wikiID, $major,
 27+ array( 'lang' => $minor, 'site' => $major ) );
2628 $path = $wgConf->get( 'wgArticlePath', $wikiID, $major,
2729 array( 'lang' => $minor, 'site' => $major ) );
28 - return new WikiReference( $major, $minor, $server, $path );
 30+ return new WikiReference( $major, $minor, $canonicalServer, $path, $server );
2931 }
3032
3133 /**
@@ -100,21 +102,23 @@
101103 class WikiReference {
102104 private $mMinor; ///< 'en', 'meta', 'mediawiki', etc
103105 private $mMajor; ///< 'wiki', 'wiktionary', etc
104 - private $mServer; ///< server override, 'www.mediawiki.org'
105 - private $mPath; ///< path override, '/wiki/$1'
 106+ private $mCanonicalServer; ///< canonical server URL, e.g. 'http://www.mediawiki.org'
 107+ private $mServer; ///< server URL, may be protocol-relative, e.g. '//www.mediawiki.org'
 108+ private $mPath; ///< path, '/wiki/$1'
106109
107 - public function __construct( $major, $minor, $server, $path ) {
 110+ public function __construct( $major, $minor, $canonicalServer, $path, $server = null ) {
108111 $this->mMajor = $major;
109112 $this->mMinor = $minor;
110 - $this->mServer = $server;
 113+ $this->mCanonicalServer = $canonicalServer;
111114 $this->mPath = $path;
 115+ $this->mServer = $server === null ? $canonicalServer : $server;
112116 }
113117
114118 public function getHostname() {
115119 $prefixes = array( 'http://', 'https://' );
116120 foreach ( $prefixes as $prefix ) {
117 - if ( substr( $this->mServer, 0, strlen( $prefix ) ) ) {
118 - return substr( $this->mServer, strlen( $prefix ) );
 121+ if ( substr( $this->mCanonicalServer, 0, strlen( $prefix ) ) ) {
 122+ return substr( $this->mCanonicalServer, strlen( $prefix ) );
119123 }
120124 }
121125 throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" );
@@ -149,12 +153,32 @@
150154 }
151155
152156 /**
153 - * Get a URL to a page on this foreign wiki
 157+ * Get a canonical (i.e. based on $wgCanonicalServer) URL to a page on this foreign wiki
154158 *
155159 * @param $page String: page name (must be normalised before calling this function!)
156160 * @return String: Url
157161 */
 162+ public function getCanonicalUrl( $page ) {
 163+ return
 164+ $this->mCanonicalServer .
 165+ $this->getLocalUrl( $page );
 166+ }
 167+
 168+ /**
 169+ * Alias for getCanonicalUrl(), for backwards compatibility.
 170+ */
158171 public function getUrl( $page ) {
 172+ return $this->getCanonicalUrl( $page );
 173+ }
 174+
 175+ /**
 176+ * Get a URL based on $wgServer, like Title::getFullUrl() would produce
 177+ * when called locally on the wiki.
 178+ *
 179+ * @param $page String: page name (must be normalized before calling this function!)
 180+ * @return String: URL
 181+ */
 182+ public function getFullUrl( $page ) {
159183 return
160184 $this->mServer .
161185 $this->getLocalUrl( $page );
Index: trunk/extensions/CentralAuth/CentralAuthHooks.php
@@ -168,7 +168,8 @@
169169 $wgMemc->set( CentralAuthUser::memcKey( 'login-token', $loginToken ), $data, 600 );
170170
171171 $wiki = WikiMap::getWiki( $wiki );
172 - $url = wfAppendQuery( $wiki->getUrl( 'Special:AutoLogin' ), "token=$loginToken" );
 172+ // Use WikiReference::getFullUrl(), returns a protocol-relative URL if needed
 173+ $url = wfAppendQuery( $wiki->getFullUrl( 'Special:AutoLogin' ), "token=$loginToken" );
173174
174175 $inject_html .= Xml::element( 'img',
175176 array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r987461.18wmf1: MFT r98744, r98745catrope10:42, 3 October 2011
r987471.17wmf1: MFT r98744, r98745catrope10:42, 3 October 2011
r98748Followup r98745: also use protocol-relative URLs for logout linkscatrope10:55, 3 October 2011
r104337Change getUrl to getFullUrl (due to r98745), so it uses protocol-relative URLsrobin15:04, 27 November 2011

Status & tagging log