r98549 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98548‎ | r98549 | r98550 >
Date:18:55, 30 September 2011
Author:preilly
Status:resolved
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
@@ -84,7 +84,7 @@
8585 }
8686
8787 class ExtMobileFrontend {
88 - const VERSION = '0.5.74';
 88+ const VERSION = '0.5.76';
8989
9090 /**
9191 * @var DOMDocument
@@ -200,10 +200,52 @@
201201 );
202202
203203 public function testCanonicalRedirect( $request, $title, $output ) {
 204+ global $wgUsePathInfo, $wgMobileDomain;
204205 $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : '';
205206 if ( empty( $xDevice ) ) {
206207 return true; // Let the redirect happen
207208 } else {
 209+ if ( $title->getNamespace() == NS_SPECIAL ) {
 210+ list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
 211+ if ( $name ) {
 212+ $title = SpecialPage::getTitleFor( $name, $subpage );
 213+ }
 214+ }
 215+ $targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
 216+ // Redirect to canonical url, make it a 301 to allow caching
 217+ if ( $targetUrl == $request->getFullRequestURL() ) {
 218+ $message = "Redirect loop detected!\n\n" .
 219+ "This means the wiki got confused about what page was " .
 220+ "requested; this sometimes happens when moving a wiki " .
 221+ "to a new server or changing the server configuration.\n\n";
 222+
 223+ if ( $wgUsePathInfo ) {
 224+ $message .= "The wiki is trying to interpret the page " .
 225+ "title from the URL path portion (PATH_INFO), which " .
 226+ "sometimes fails depending on the web server. Try " .
 227+ "setting \"\$wgUsePathInfo = false;\" in your " .
 228+ "LocalSettings.php, or check that \$wgArticlePath " .
 229+ "is correct.";
 230+ } else {
 231+ $message .= "Your web server was detected as possibly not " .
 232+ "supporting URL path components (PATH_INFO) correctly; " .
 233+ "check your LocalSettings.php for a customized " .
 234+ "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " .
 235+ "to true.";
 236+ }
 237+ throw new HttpError( 500, $message );
 238+ } else {
 239+ $parsedUrl = wfParseUrl( $targetUrl );
 240+ if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === FALSE ) {
 241+ $hostParts = explode( '.', $parsedUrl['host'] );
 242+ $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2];
 243+ }
 244+ $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : '';
 245+ $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : '';
 246+ $targetUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'] . $queryDelimiter . $parsedUrl['query'] . $fragmentDelimiter . $parsedUrl['fragment'];
 247+ $output->setSquidMaxage( 1200 );
 248+ $output->redirect( $targetUrl, '301' );
 249+ }
208250 return false; // Prevent the redirect from occuring
209251 }
210252 }
@@ -484,8 +526,7 @@
485527 if ( self::$useFormat === 'mobile' ||
486528 self::$useFormat === 'mobile-wap' ||
487529 !empty( $xDevice ) ) {
488 - if ( $action !== 'edit' &&
489 - $mobileAction !== 'view_normal_site' ) {
 530+ if ( $action !== 'edit' ) {
490531 $this->getMsg();
491532 $this->disableCaching();
492533 $this->sendXDeviceVaryHeader();

Follow-up revisions

RevisionCommit summaryAuthorDate
r987271.17wmf1: Fix fatal in r98549, SpecialPageFactory doesn't exist in 1.17wmf1catrope22:10, 2 October 2011
r98799Fix fatal in r98549, SpecialPageFactory does not exist in 1.17wmf1preilly19:47, 3 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98462view_normal_site mobile action is no longer neededpreilly21:31, 29 September 2011
r98547fix for bug 30772 - mobile wikipedia commonly uses non-canonical urls that do...preilly18:49, 30 September 2011

Status & tagging log