r104529 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104528‎ | r104529 | r104530 >
Date:01:15, 29 November 2011
Author:preilly
Status:deferred
Tags:mobile 
Comment:
refactor beforePageDisplayHTML method to check for mobile view first
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -87,7 +87,7 @@
8888 }
8989
9090 class ExtMobileFrontend {
91 - const VERSION = '0.5.81';
 91+ const VERSION = '0.5.82';
9292
9393 /**
9494 * @var DOMDocument
@@ -432,156 +432,155 @@
433433 // echo $e->getMessage();
434434 }
435435
436 - // The title
437 - self::$title = $out->getTitle();
438 -
439 - if ( Title::newMainPage()->equals( self::$title ) ) {
440 - self::$isMainPage = true;
441 - }
442 -
443 - if ( self::$title == 'Special:UserLogin' ) {
444 - self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' );
445 - $returnToVal = $wgRequest->getVal( 'returnto' );
446 - $returnto = ( !empty ( $returnToVal ) ) ? '&returnto=' . wfUrlencode( $returnToVal ) : '';
447 - self::$wsLoginFormAction = self::$title->getLocalURL( 'action=submitlogin&type=login' . $returnto );
448 - }
449 -
450 - self::$htmlTitle = $out->getHTMLTitle();
451 -
452436 // Note: The WebRequest Class calls are made in this block because
453437 // since PHP 5.1.x, all objects have their destructors called
454438 // before the output buffer callback function executes.
455439 // Thus, globalized objects will not be available as expected in the function.
456440 // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104]
457 -
 441+
 442+ $xDevice = !empty( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : '';
 443+ self::$useFormat = $wgRequest->getText( 'useformat' );
458444 $mobileAction = $wgRequest->getText( 'mobileaction' );
459445 $action = $wgRequest->getText( 'action' );
460 - self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
461 - self::$enableImages = $wgRequest->getText( 'enableImages', 0 );
462 - self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' );
463446
464 - if ( self::$disableImages == 1 ) {
465 - $wgRequest->response()->setcookie( 'disableImages', 1 );
466 - $location = str_replace( '?disableImages=1', '', str_replace( '&disableImages=1', '', $wgRequest->getFullRequestURL() ) );
467 - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
468 - $location = $this->getRelativeURL( $location );
469 - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' );
470 - }
 447+ if ( self::$useFormat === 'mobile' ||
 448+ self::$useFormat === 'mobile-wap' ||
 449+ !empty( $xDevice ) ) {
 450+ if ( $action !== 'edit' &&
 451+ $mobileAction !== 'view_normal_site' ) {
471452
472 - if ( self::$disableImages == 0 ) {
473 - $disableImages = $wgRequest->getCookie( 'disableImages' );
474 - if ( $disableImages ) {
475 - self::$disableImages = $disableImages;
476 - }
477 - }
 453+ self::$title = $out->getTitle();
478454
479 - if ( self::$enableImages == 1 ) {
480 - $disableImages = $wgRequest->getCookie( 'disableImages' );
481 - if ( $disableImages ) {
482 - $wgRequest->response()->setcookie( 'disableImages', '' );
483 - }
484 - $location = str_replace( '?enableImages=1', '', str_replace( '&enableImages=1', '', $wgRequest->getFullRequestURL() ) );
485 - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
486 - $location = $this->getRelativeURL( $location );
487 - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=1' );
488 - }
 455+ if ( Title::newMainPage()->equals( self::$title ) ) {
 456+ self::$isMainPage = true;
 457+ }
489458
490 - self::$useFormat = $wgRequest->getText( 'useformat' );
491 - self::$format = $wgRequest->getText( 'format' );
492 - self::$requestedSegment = $wgRequest->getText( 'seg', 0 );
493 - self::$search = $wgRequest->getText( 'search' );
494 - self::$callback = $wgRequest->getText( 'callback' );
495 - self::$searchField = $wgRequest->getText( 'search', '' );
 459+ if ( self::$title == 'Special:UserLogin' ) {
 460+ self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' );
 461+ $returnToVal = $wgRequest->getVal( 'returnto' );
 462+ $returnto = ( !empty ( $returnToVal ) ) ? '&returnto=' . wfUrlencode( $returnToVal ) : '';
 463+ self::$wsLoginFormAction = self::$title->getLocalURL( 'action=submitlogin&type=login' . $returnto );
 464+ }
496465
497 - $xDevice = !empty( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : '';
 466+ self::$htmlTitle = $out->getHTMLTitle();
 467+ self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
 468+ self::$enableImages = $wgRequest->getText( 'enableImages', 0 );
 469+ self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' );
498470
499 - $acceptHeader = !empty( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : '';
500 - $device = new DeviceDetection();
 471+ if ( self::$disableImages == 1 ) {
 472+ $wgRequest->response()->setcookie( 'disableImages', 1 );
 473+ $location = str_replace( '?disableImages=1', '', str_replace( '&disableImages=1', '', $wgRequest->getFullRequestURL() ) );
 474+ $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
 475+ $location = $this->getRelativeURL( $location );
 476+ $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' );
 477+ }
501478
502 - if ( !empty( $xDevice ) ) {
503 - $formatName = $xDevice;
504 - } else {
505 - $formatName = $device->formatName( $userAgent, $acceptHeader );
506 - }
 479+ if ( self::$disableImages == 0 ) {
 480+ $disableImages = $wgRequest->getCookie( 'disableImages' );
 481+ if ( $disableImages ) {
 482+ self::$disableImages = $disableImages;
 483+ }
 484+ }
507485
508 - self::$device = $device->format( $formatName );
 486+ if ( self::$enableImages == 1 ) {
 487+ $disableImages = $wgRequest->getCookie( 'disableImages' );
 488+ if ( $disableImages ) {
 489+ $wgRequest->response()->setcookie( 'disableImages', '' );
 490+ }
 491+ $location = str_replace( '?enableImages=1', '', str_replace( '&enableImages=1', '', $wgRequest->getFullRequestURL() ) );
 492+ $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
 493+ $location = $this->getRelativeURL( $location );
 494+ $wgRequest->response()->header( 'Location: ' . $location . '&mfi=1' );
 495+ }
509496
510 - if ( self::$device['view_format'] === 'wml' ) {
511 - $this->contentFormat = 'WML';
512 - } elseif ( self::$device['view_format'] === 'html' ) {
513 - $this->contentFormat = 'XHTML';
514 - }
 497+ self::$format = $wgRequest->getText( 'format' );
 498+ self::$callback = $wgRequest->getText( 'callback' );
 499+ self::$requestedSegment = $wgRequest->getText( 'seg', 0 );
 500+ self::$search = $wgRequest->getText( 'search' );
 501+ self::$searchField = $wgRequest->getText( 'search', '' );
515502
516 - if ( self::$useFormat === 'mobile-wap' ) {
517 - $this->contentFormat = 'WML';
518 - }
 503+ $acceptHeader = !empty( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : '';
 504+ $device = new DeviceDetection();
519505
520 - if ( $mobileAction == 'leave_feedback' ) {
521 - echo $this->renderLeaveFeedbackXHTML();
522 - wfProfileOut( __METHOD__ );
523 - exit();
524 - }
 506+ if ( !empty( $xDevice ) ) {
 507+ $formatName = $xDevice;
 508+ } else {
 509+ $formatName = $device->formatName( $userAgent, $acceptHeader );
 510+ }
525511
526 - if ( $mobileAction == 'leave_feedback_post' ) {
 512+ self::$device = $device->format( $formatName );
527513
528 - $this->getMsg();
 514+ if ( self::$device['view_format'] === 'wml' ) {
 515+ $this->contentFormat = 'WML';
 516+ } elseif ( self::$device['view_format'] === 'html' ) {
 517+ $this->contentFormat = 'XHTML';
 518+ }
529519
530 - $subject = $wgRequest->getText( 'subject', '' );
531 - $message = $wgRequest->getText( 'message', '' );
532 - $token = $wgRequest->getText( 'edittoken', '' );
 520+ if ( self::$useFormat === 'mobile-wap' ) {
 521+ $this->contentFormat = 'WML';
 522+ }
533523
534 - $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] );
 524+ if ( $mobileAction == 'leave_feedback' ) {
 525+ echo $this->renderLeaveFeedbackXHTML();
 526+ wfProfileOut( __METHOD__ );
 527+ exit();
 528+ }
535529
536 - if ( $title->userCan( 'edit' ) &&
537 - !$wgUser->isBlockedFrom( $title ) &&
538 - $wgUser->matchEditToken( $token ) ) {
539 - $article = new Article( $title, 0 );
540 - $rawtext = $article->getRawText();
541 - $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> ";
542 - $article->doEdit( $rawtext, '' );
543 - }
 530+ if ( $mobileAction == 'leave_feedback_post' ) {
544531
545 - $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '&noticeid=1&useformat=mobile' );
546 - $location = $this->getRelativeURL( $location );
547 - $wgRequest->response()->header( 'Location: ' . $location );
548 - wfProfileOut( __METHOD__ );
549 - exit();
550 - }
 532+ $this->getMsg();
551533
552 - if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) {
553 - echo $this->renderDisableMobileSiteXHTML();
554 - wfProfileOut( __METHOD__ );
555 - exit();
556 - }
 534+ $subject = $wgRequest->getText( 'subject', '' );
 535+ $message = $wgRequest->getText( 'message', '' );
 536+ $token = $wgRequest->getText( 'edittoken', '' );
557537
558 - if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) {
559 - echo $this->renderOptInMobileSiteXHTML();
560 - wfProfileOut( __METHOD__ );
561 - exit();
562 - }
 538+ $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] );
563539
564 - if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) {
565 - echo $this->renderOptOutMobileSiteXHTML();
566 - wfProfileOut( __METHOD__ );
567 - exit();
568 - }
 540+ if ( $title->userCan( 'edit' ) &&
 541+ !$wgUser->isBlockedFrom( $title ) &&
 542+ $wgUser->matchEditToken( $token ) ) {
 543+ $article = new Article( $title, 0 );
 544+ $rawtext = $article->getRawText();
 545+ $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> ";
 546+ $article->doEdit( $rawtext, '' );
 547+ }
569548
570 - if ( $mobileAction == 'opt_in_cookie' ) {
571 - $this->setOptInOutCookie( '1' );
572 - $this->disableCaching();
573 - $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT );
574 - $wgRequest->response()->header( 'Location: ' . $location );
575 - }
 549+ $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '&noticeid=1&useformat=mobile' );
 550+ $location = $this->getRelativeURL( $location );
 551+ $wgRequest->response()->header( 'Location: ' . $location );
 552+ wfProfileOut( __METHOD__ );
 553+ exit();
 554+ }
576555
577 - if ( $mobileAction == 'opt_out_cookie' ) {
578 - $this->setOptInOutCookie( '' );
579 - }
 556+ if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) {
 557+ echo $this->renderDisableMobileSiteXHTML();
 558+ wfProfileOut( __METHOD__ );
 559+ exit();
 560+ }
580561
581 - if ( self::$useFormat === 'mobile' ||
582 - self::$useFormat === 'mobile-wap' ||
583 - !empty( $xDevice ) ) {
584 - if ( $action !== 'edit' &&
585 - $mobileAction !== 'view_normal_site' ) {
 562+ if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) {
 563+ echo $this->renderOptInMobileSiteXHTML();
 564+ wfProfileOut( __METHOD__ );
 565+ exit();
 566+ }
 567+
 568+ if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) {
 569+ echo $this->renderOptOutMobileSiteXHTML();
 570+ wfProfileOut( __METHOD__ );
 571+ exit();
 572+ }
 573+
 574+ if ( $mobileAction == 'opt_in_cookie' ) {
 575+ $this->setOptInOutCookie( '1' );
 576+ $this->disableCaching();
 577+ $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT );
 578+ $wgRequest->response()->header( 'Location: ' . $location );
 579+ }
 580+
 581+ if ( $mobileAction == 'opt_out_cookie' ) {
 582+ $this->setOptInOutCookie( '' );
 583+ }
 584+
586585 $this->getMsg();
587586 $this->disableCaching();
588587 $this->sendXDeviceVaryHeader();

Status & tagging log