r108702 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108701‎ | r108702 | r108703 >
Date:00:39, 12 January 2012
Author:preilly
Status:ok
Tags:mobile 
Comment:
fix for Bug 33441 - Random button directing to regular website
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -424,6 +424,29 @@
425425 wfProfileOut( __METHOD__ );
426426 return true;
427427 }
 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+ }
428451
429452 /**
430453 * @param $out OutputPage
@@ -445,15 +468,16 @@
446469 if ( $parsedUrl['scheme'] == 'http' ) {
447470 $parsedUrl['scheme'] = 'https';
448471 }
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 );
454481 }
455 - if ( isset( $parsedUrl['fragment'] ) ) {
456 - $redirect .= $fragmentDelimiter . $parsedUrl['fragment'];
457 - }
458482 }
459483 }
460484 wfProfileOut( __METHOD__ );

Sign-offs

UserFlagDate
Brion VIBBERinspected00:48, 12 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r1087031.18wmf1: MFT r108702preilly00:42, 12 January 2012

Status & tagging log