Index: branches/wmf/1.18wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -424,6 +424,29 @@ |
425 | 425 | wfProfileOut( __METHOD__ ); |
426 | 426 | return true; |
427 | 427 | } |
| 428 | + |
| 429 | + /** |
| 430 | + * @param $parsedUrl wfParseUrl Array |
| 431 | + * @return string |
| 432 | + */ |
| 433 | + public function parsePageRedirect( $parsedUrl ) { |
| 434 | + global $wgMobileDomain; |
| 435 | + wfProfileIn( __METHOD__ ); |
| 436 | + $redirect = ''; |
| 437 | + $hostParts = explode( '.', $parsedUrl['host'] ); |
| 438 | + $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2]; |
| 439 | + $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : ''; |
| 440 | + $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : ''; |
| 441 | + $redirect = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path']; |
| 442 | + if ( isset( $parsedUrl['query'] ) ) { |
| 443 | + $redirect .= $queryDelimiter . $parsedUrl['query']; |
| 444 | + } |
| 445 | + if ( isset( $parsedUrl['fragment'] ) ) { |
| 446 | + $redirect .= $fragmentDelimiter . $parsedUrl['fragment']; |
| 447 | + } |
| 448 | + wfProfileOut( __METHOD__ ); |
| 449 | + return $redirect; |
| 450 | + } |
428 | 451 | |
429 | 452 | /** |
430 | 453 | * @param $out OutputPage |
— | — | @@ -445,15 +468,16 @@ |
446 | 469 | if ( $parsedUrl['scheme'] == 'http' ) { |
447 | 470 | $parsedUrl['scheme'] = 'https'; |
448 | 471 | } |
449 | | - $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : ''; |
450 | | - $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : ''; |
451 | | - $redirect = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path']; |
452 | | - if ( isset( $parsedUrl['query'] ) ) { |
453 | | - $redirect .= $queryDelimiter . $parsedUrl['query']; |
| 472 | + |
| 473 | + $redirect = $this->parsePageRedirect( $parsedUrl ); |
| 474 | + } |
| 475 | + } else if ($out->getTitle()->isSpecial( 'Randompage' ) ) { |
| 476 | + $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
| 477 | + if ( $xDevice ) { |
| 478 | + $parsedUrl = wfParseUrl( $redirect ); |
| 479 | + if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === false ) { |
| 480 | + $redirect = $this->parsePageRedirect( $parsedUrl ); |
454 | 481 | } |
455 | | - if ( isset( $parsedUrl['fragment'] ) ) { |
456 | | - $redirect .= $fragmentDelimiter . $parsedUrl['fragment']; |
457 | | - } |
458 | 482 | } |
459 | 483 | } |
460 | 484 | wfProfileOut( __METHOD__ ); |