Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -126,7 +126,7 @@ |
127 | 127 | * @throws HttpError |
128 | 128 | */ |
129 | 129 | public function testCanonicalRedirect( $request, $title, $output ) { |
130 | | - global $wgUsePathInfo, $wgMobileDomain; |
| 130 | + global $wgUsePathInfo; |
131 | 131 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
132 | 132 | if ( empty( $xDevice ) ) { |
133 | 133 | return true; // Let the redirect happen |
— | — | @@ -161,15 +161,7 @@ |
162 | 162 | } |
163 | 163 | throw new HttpError( 500, $message ); |
164 | 164 | } else { |
165 | | - $parsedUrl = wfParseUrl( $targetUrl ); |
166 | | - if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === false ) { |
167 | | - $hostParts = explode( '.', $parsedUrl['host'] ); |
168 | | - $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2]; |
169 | | - } |
170 | | - $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : ''; |
171 | | - $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : ''; |
172 | | - $targetUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'] |
173 | | - . $queryDelimiter . $parsedUrl['query'] . $fragmentDelimiter . $parsedUrl['fragment']; |
| 165 | + $targetUrl = $this->getMobileUrl( $targetUrl ); |
174 | 166 | $output->setSquidMaxage( 1200 ); |
175 | 167 | $output->redirect( $targetUrl, '301' ); |
176 | 168 | } |
— | — | @@ -215,7 +207,7 @@ |
216 | 208 | } |
217 | 209 | |
218 | 210 | public function getMsg() { |
219 | | - global $wgUser, $wgContLang, $wgRequest, $wgServer, $wgMobileRedirectFormAction, $wgMobileDomain, $wgOut, $wgLanguageCode; |
| 211 | + global $wgUser, $wgContLang, $wgRequest, $wgServer, $wgMobileRedirectFormAction, $wgOut, $wgLanguageCode; |
220 | 212 | wfProfileIn( __METHOD__ ); |
221 | 213 | |
222 | 214 | self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' ); |
— | — | @@ -269,21 +261,7 @@ |
270 | 262 | unset( $tmp ); |
271 | 263 | $nt = Title::newFromText( $l ); |
272 | 264 | if ( $nt ) { |
273 | | - $parsedUrl = wfParseUrl( $nt->getFullURL() ); |
274 | | - if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === false ) { |
275 | | - $hostParts = explode( '.', $parsedUrl['host'] ); |
276 | | - $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2]; |
277 | | - } |
278 | | - $fragmentDelimiter = ( isset( $parsedUrl['fragment'] ) && $parsedUrl['fragment'] !== null ) ? '#' : ''; |
279 | | - $queryDelimiter = ( isset( $parsedUrl['query'] ) && $parsedUrl['query'] !== null ) ? '?' : ''; |
280 | | - |
281 | | - $languageUrl = $parsedUrl['scheme'] . $parsedUrl['delimiter'] . $parsedUrl['host'] . $parsedUrl['path']; |
282 | | - if ( isset( $parsedUrl['query'] ) ) { |
283 | | - $languageUrl .= $queryDelimiter . $parsedUrl['query']; |
284 | | - } |
285 | | - if ( isset( $parsedUrl['fragment'] ) ) { |
286 | | - $languageUrl .= $fragmentDelimiter . $parsedUrl['fragment']; |
287 | | - } |
| 265 | + $languageUrl = $this->getMobileUrl( $nt->getFullURL() ); |
288 | 266 | $languageUrls[] = array( |
289 | 267 | 'href' => $languageUrl, |
290 | 268 | 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' |
— | — | @@ -298,10 +276,9 @@ |
299 | 277 | |
300 | 278 | self::$languageUrls = $languageUrls; |
301 | 279 | |
302 | | - $nonMobileServerBaseURL = str_replace( $wgMobileDomain, '.', $wgServer ); |
303 | 280 | self::$mobileRedirectFormAction = ( $wgMobileRedirectFormAction !== false ) |
304 | 281 | ? $wgMobileRedirectFormAction |
305 | | - : "{$nonMobileServerBaseURL}/w/mobileRedirect.php"; |
| 282 | + : "{$wgServer}/w/mobileRedirect.php"; |
306 | 283 | |
307 | 284 | self::$mainPageUrl = Title::newMainPage()->getLocalUrl(); |
308 | 285 | self::$randomPageUrl = $this->getRelativeURL( SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl() ); |
— | — | @@ -310,58 +287,23 @@ |
311 | 288 | } |
312 | 289 | |
313 | 290 | /** |
314 | | - * @param $parsedUrl wfParseUrl Array |
315 | | - * @return string |
316 | | - */ |
317 | | - public function parsePageRedirect( $parsedUrl ) { |
318 | | - global $wgMobileDomain; |
319 | | - wfProfileIn( __METHOD__ ); |
320 | | - $redirect = ''; |
321 | | - $hostParts = explode( '.', $parsedUrl['host'] ); |
322 | | - $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2]; |
323 | | - $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : ''; |
324 | | - $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : ''; |
325 | | - $redirect = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path']; |
326 | | - if ( isset( $parsedUrl['query'] ) ) { |
327 | | - $redirect .= $queryDelimiter . $parsedUrl['query']; |
328 | | - } |
329 | | - if ( isset( $parsedUrl['fragment'] ) ) { |
330 | | - $redirect .= $fragmentDelimiter . $parsedUrl['fragment']; |
331 | | - } |
332 | | - wfProfileOut( __METHOD__ ); |
333 | | - return $redirect; |
334 | | - } |
335 | | - |
336 | | - /** |
337 | 291 | * @param $out OutputPage |
338 | 292 | * @param $redirect |
339 | 293 | * @param $code |
340 | 294 | * @return bool |
341 | 295 | */ |
342 | 296 | public function beforePageRedirect( $out, &$redirect, &$code ) { |
343 | | - global $wgMobileDomain; |
344 | 297 | wfProfileIn( __METHOD__ ); |
345 | 298 | if ( $out->getTitle()->isSpecial( 'Userlogin' ) ) { |
346 | 299 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
347 | 300 | if ( $xDevice ) { |
348 | | - $parsedUrl = wfParseUrl( $redirect ); |
349 | | - if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === false ) { |
350 | | - $hostParts = explode( '.', $parsedUrl['host'] ); |
351 | | - $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2]; |
352 | | - } |
353 | | - if ( $parsedUrl['scheme'] == 'http' ) { |
354 | | - $parsedUrl['scheme'] = 'https'; |
355 | | - } |
356 | | - |
357 | | - $redirect = $this->parsePageRedirect( $parsedUrl ); |
| 301 | + $forceHttps = true; |
| 302 | + $redirect = $this->getMobileUrl( $redirect, $forceHttps ); |
358 | 303 | } |
359 | 304 | } else if ( $out->getTitle()->isSpecial( 'Randompage' ) ) { |
360 | 305 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
361 | 306 | if ( $xDevice ) { |
362 | | - $parsedUrl = wfParseUrl( $redirect ); |
363 | | - if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === false ) { |
364 | | - $redirect = $this->parsePageRedirect( $parsedUrl ); |
365 | | - } |
| 307 | + $redirect = $this->getMobileUrl( $redirect ); |
366 | 308 | } |
367 | 309 | } |
368 | 310 | wfProfileOut( __METHOD__ ); |
— | — | @@ -1326,11 +1268,13 @@ |
1327 | 1269 | * @param $url string |
1328 | 1270 | * @return string |
1329 | 1271 | */ |
1330 | | - public function getMobileUrl( $url ) { |
1331 | | - global $wgMobileUrlTemplate; |
| 1272 | + public function getMobileUrl( $url, $forceHttps = false ) { |
1332 | 1273 | $parsedUrl = wfParseUrl( $url ); |
1333 | 1274 | $this->updateMobileUrlHost( $parsedUrl ); |
1334 | 1275 | $this->updateMobileUrlPath( $parsedUrl ); |
| 1276 | + if ( $forceHttps ) { |
| 1277 | + $parsedUrl[ 'scheme' ] = 'https'; |
| 1278 | + } |
1335 | 1279 | return wfAssembleUrl( $parsedUrl ); |
1336 | 1280 | } |
1337 | 1281 | |