Index: trunk/phase3/includes/WikiMap.php |
— | — | @@ -20,11 +20,13 @@ |
21 | 21 | if( $major === null ) { |
22 | 22 | return null; |
23 | 23 | } |
24 | | - $server = $wgConf->get( 'wgCanonicalServer', $wikiID, $major, |
| 24 | + $canonicalServer = $wgConf->get( 'wgCanonicalServer', $wikiID, $major, |
25 | 25 | array( 'lang' => $minor, 'site' => $major ) ); |
| 26 | + $server = $wgConf->get( 'wgServer', $wikiID, $major, |
| 27 | + array( 'lang' => $minor, 'site' => $major ) ); |
26 | 28 | $path = $wgConf->get( 'wgArticlePath', $wikiID, $major, |
27 | 29 | array( 'lang' => $minor, 'site' => $major ) ); |
28 | | - return new WikiReference( $major, $minor, $server, $path ); |
| 30 | + return new WikiReference( $major, $minor, $canonicalServer, $path, $server ); |
29 | 31 | } |
30 | 32 | |
31 | 33 | /** |
— | — | @@ -100,21 +102,23 @@ |
101 | 103 | class WikiReference { |
102 | 104 | private $mMinor; ///< 'en', 'meta', 'mediawiki', etc |
103 | 105 | 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' |
106 | 109 | |
107 | | - public function __construct( $major, $minor, $server, $path ) { |
| 110 | + public function __construct( $major, $minor, $canonicalServer, $path, $server = null ) { |
108 | 111 | $this->mMajor = $major; |
109 | 112 | $this->mMinor = $minor; |
110 | | - $this->mServer = $server; |
| 113 | + $this->mCanonicalServer = $canonicalServer; |
111 | 114 | $this->mPath = $path; |
| 115 | + $this->mServer = $server === null ? $canonicalServer : $server; |
112 | 116 | } |
113 | 117 | |
114 | 118 | public function getHostname() { |
115 | 119 | $prefixes = array( 'http://', 'https://' ); |
116 | 120 | 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 ) ); |
119 | 123 | } |
120 | 124 | } |
121 | 125 | throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" ); |
— | — | @@ -149,12 +153,32 @@ |
150 | 154 | } |
151 | 155 | |
152 | 156 | /** |
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 |
154 | 158 | * |
155 | 159 | * @param $page String: page name (must be normalised before calling this function!) |
156 | 160 | * @return String: Url |
157 | 161 | */ |
| 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 | + */ |
158 | 171 | 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 ) { |
159 | 183 | return |
160 | 184 | $this->mServer . |
161 | 185 | $this->getLocalUrl( $page ); |
Index: trunk/extensions/CentralAuth/CentralAuthHooks.php |
— | — | @@ -168,7 +168,8 @@ |
169 | 169 | $wgMemc->set( CentralAuthUser::memcKey( 'login-token', $loginToken ), $data, 600 ); |
170 | 170 | |
171 | 171 | $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" ); |
173 | 174 | |
174 | 175 | $inject_html .= Xml::element( 'img', |
175 | 176 | array( |