r106724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106723‎ | r106724 | r106725 >
Date:23:35, 19 December 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Reduce more indenting
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -506,166 +506,168 @@
507507 $mobileAction = $wgRequest->getText( 'mobileaction' );
508508 $action = $wgRequest->getText( 'action' );
509509
510 - if ( self::$useFormat === 'mobile' || self::$useFormat === 'mobile-wap' ||
511 - $xDevice ) {
512 - if ( $action === 'edit' &&
513 - $mobileAction === 'view_normal_site' ) {
514 - wfProfileOut( __METHOD__ );
515 - return true;
516 - }
 510+ if ( self::$useFormat !== 'mobile' || self::$useFormat !== 'mobile-wap' ||
 511+ !$xDevice ) {
 512+ wfProfileOut( __METHOD__ );
 513+ return true;
 514+ }
 515+ if ( $action === 'edit' &&
 516+ $mobileAction === 'view_normal_site' ) {
 517+ wfProfileOut( __METHOD__ );
 518+ return true;
 519+ }
517520
518 - self::$title = $out->getTitle();
 521+ self::$title = $out->getTitle();
519522
520 - if ( Title::newMainPage()->equals( self::$title ) ) {
521 - self::$isMainPage = true;
522 - }
523 - if ( self::$title->getNamespace() == NS_FILE ) {
524 - self::$isFilePage = true;
525 - }
 523+ if ( Title::newMainPage()->equals( self::$title ) ) {
 524+ self::$isMainPage = true;
 525+ }
 526+ if ( self::$title->getNamespace() == NS_FILE ) {
 527+ self::$isFilePage = true;
 528+ }
526529
527 - self::$htmlTitle = $out->getHTMLTitle();
528 - self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
529 - self::$enableImages = $wgRequest->getText( 'enableImages', 0 );
530 - self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' );
 530+ self::$htmlTitle = $out->getHTMLTitle();
 531+ self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
 532+ self::$enableImages = $wgRequest->getText( 'enableImages', 0 );
 533+ self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' );
531534
532 - if ( self::$disableImages == 1 ) {
533 - $wgRequest->response()->setcookie( 'disableImages', 1 );
534 - $location = str_replace( '?disableImages=1', '', str_replace( '&disableImages=1', '', $wgRequest->getFullRequestURL() ) );
535 - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
536 - $location = $this->getRelativeURL( $location );
537 - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' );
538 - }
 535+ if ( self::$disableImages == 1 ) {
 536+ $wgRequest->response()->setcookie( 'disableImages', 1 );
 537+ $location = str_replace( '?disableImages=1', '', str_replace( '&disableImages=1', '', $wgRequest->getFullRequestURL() ) );
 538+ $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
 539+ $location = $this->getRelativeURL( $location );
 540+ $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' );
 541+ }
539542
540 - if ( self::$disableImages == 0 ) {
541 - $disableImages = $wgRequest->getCookie( 'disableImages' );
542 - if ( $disableImages ) {
543 - self::$disableImages = $disableImages;
544 - }
 543+ if ( self::$disableImages == 0 ) {
 544+ $disableImages = $wgRequest->getCookie( 'disableImages' );
 545+ if ( $disableImages ) {
 546+ self::$disableImages = $disableImages;
545547 }
 548+ }
546549
547 - if ( self::$enableImages == 1 ) {
548 - $disableImages = $wgRequest->getCookie( 'disableImages' );
549 - if ( $disableImages ) {
550 - $wgRequest->response()->setcookie( 'disableImages', '' );
551 - }
552 - $location = str_replace( '?enableImages=1', '', str_replace( '&enableImages=1', '', $wgRequest->getFullRequestURL() ) );
553 - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
554 - $location = $this->getRelativeURL( $location );
555 - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=1' );
 550+ if ( self::$enableImages == 1 ) {
 551+ $disableImages = $wgRequest->getCookie( 'disableImages' );
 552+ if ( $disableImages ) {
 553+ $wgRequest->response()->setcookie( 'disableImages', '' );
556554 }
 555+ $location = str_replace( '?enableImages=1', '', str_replace( '&enableImages=1', '', $wgRequest->getFullRequestURL() ) );
 556+ $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
 557+ $location = $this->getRelativeURL( $location );
 558+ $wgRequest->response()->header( 'Location: ' . $location . '&mfi=1' );
 559+ }
557560
558 - self::$format = $wgRequest->getText( 'format' );
559 - self::$callback = $wgRequest->getText( 'callback' );
560 - self::$requestedSegment = $wgRequest->getText( 'seg', 0 );
561 - self::$search = $wgRequest->getText( 'search' );
562 - self::$searchField = $wgRequest->getText( 'search', '' );
 561+ self::$format = $wgRequest->getText( 'format' );
 562+ self::$callback = $wgRequest->getText( 'callback' );
 563+ self::$requestedSegment = $wgRequest->getText( 'seg', 0 );
 564+ self::$search = $wgRequest->getText( 'search' );
 565+ self::$searchField = $wgRequest->getText( 'search', '' );
563566
564 - $acceptHeader = isset( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : '';
565 - $device = new DeviceDetection();
 567+ $acceptHeader = isset( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : '';
 568+ $device = new DeviceDetection();
566569
567 - if ( $xDevice ) {
568 - $formatName = $xDevice;
569 - } else {
570 - $formatName = $device->formatName( $userAgent, $acceptHeader );
571 - }
 570+ if ( $xDevice ) {
 571+ $formatName = $xDevice;
 572+ } else {
 573+ $formatName = $device->formatName( $userAgent, $acceptHeader );
 574+ }
572575
573 - self::$device = $device->format( $formatName );
 576+ self::$device = $device->format( $formatName );
574577
575 - if ( self::$device['view_format'] === 'wml' ) {
576 - $this->contentFormat = 'WML';
577 - } elseif ( self::$device['view_format'] === 'html' ) {
578 - $this->contentFormat = 'XHTML';
579 - }
 578+ if ( self::$device['view_format'] === 'wml' ) {
 579+ $this->contentFormat = 'WML';
 580+ } elseif ( self::$device['view_format'] === 'html' ) {
 581+ $this->contentFormat = 'XHTML';
 582+ }
580583
581 - if ( self::$useFormat === 'mobile-wap' ) {
582 - $this->contentFormat = 'WML';
583 - }
 584+ if ( self::$useFormat === 'mobile-wap' ) {
 585+ $this->contentFormat = 'WML';
 586+ }
584587
585 - if ( $mobileAction == 'leave_feedback' ) {
586 - echo $this->renderLeaveFeedbackXHTML();
587 - wfProfileOut( __METHOD__ );
588 - exit();
589 - }
 588+ if ( $mobileAction == 'leave_feedback' ) {
 589+ echo $this->renderLeaveFeedbackXHTML();
 590+ wfProfileOut( __METHOD__ );
 591+ exit();
 592+ }
590593
591 - if ( $mobileAction == 'leave_feedback_post' ) {
 594+ if ( $mobileAction == 'leave_feedback_post' ) {
592595
593 - $this->getMsg();
 596+ $this->getMsg();
594597
595 - $subject = $wgRequest->getText( 'subject', '' );
596 - $message = $wgRequest->getText( 'message', '' );
597 - $token = $wgRequest->getText( 'edittoken', '' );
 598+ $subject = $wgRequest->getText( 'subject', '' );
 599+ $message = $wgRequest->getText( 'message', '' );
 600+ $token = $wgRequest->getText( 'edittoken', '' );
598601
599 - $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] );
 602+ $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] );
600603
601 - if ( $title->userCan( 'edit' ) &&
602 - !$wgUser->isBlockedFrom( $title ) &&
603 - $wgUser->matchEditToken( $token ) ) {
604 - $article = new Article( $title, 0 );
605 - $rawtext = $article->getRawText();
606 - $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> ";
607 - $article->doEdit( $rawtext, '' );
608 - }
609 -
610 - $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '&noticeid=1&useformat=mobile' );
611 - $location = $this->getRelativeURL( $location );
612 - $wgRequest->response()->header( 'Location: ' . $location );
613 - wfProfileOut( __METHOD__ );
614 - exit();
 604+ if ( $title->userCan( 'edit' ) &&
 605+ !$wgUser->isBlockedFrom( $title ) &&
 606+ $wgUser->matchEditToken( $token ) ) {
 607+ $article = new Article( $title, 0 );
 608+ $rawtext = $article->getRawText();
 609+ $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> ";
 610+ $article->doEdit( $rawtext, '' );
615611 }
616612
617 - if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) {
618 - echo $this->renderDisableMobileSiteXHTML();
619 - wfProfileOut( __METHOD__ );
620 - exit();
621 - }
 613+ $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '&noticeid=1&useformat=mobile' );
 614+ $location = $this->getRelativeURL( $location );
 615+ $wgRequest->response()->header( 'Location: ' . $location );
 616+ wfProfileOut( __METHOD__ );
 617+ exit();
 618+ }
622619
623 - if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) {
624 - echo $this->renderOptInMobileSiteXHTML();
625 - wfProfileOut( __METHOD__ );
626 - exit();
627 - }
 620+ if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) {
 621+ echo $this->renderDisableMobileSiteXHTML();
 622+ wfProfileOut( __METHOD__ );
 623+ exit();
 624+ }
628625
629 - if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) {
630 - echo $this->renderOptOutMobileSiteXHTML();
631 - wfProfileOut( __METHOD__ );
632 - exit();
633 - }
 626+ if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) {
 627+ echo $this->renderOptInMobileSiteXHTML();
 628+ wfProfileOut( __METHOD__ );
 629+ exit();
 630+ }
634631
635 - if ( $mobileAction == 'opt_in_cookie' ) {
636 - wfIncrStats( 'mobile.opt_in_cookie_set' );
637 - $this->setOptInOutCookie( '1' );
638 - $this->disableCaching();
639 - $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT );
640 - $wgRequest->response()->header( 'Location: ' . $location );
641 - }
 632+ if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) {
 633+ echo $this->renderOptOutMobileSiteXHTML();
 634+ wfProfileOut( __METHOD__ );
 635+ exit();
 636+ }
642637
643 - if ( $mobileAction == 'opt_out_cookie' ) {
644 - $this->setOptInOutCookie( '' );
645 - }
646 -
647 - $this->getMsg();
 638+ if ( $mobileAction == 'opt_in_cookie' ) {
 639+ wfIncrStats( 'mobile.opt_in_cookie_set' );
 640+ $this->setOptInOutCookie( '1' );
648641 $this->disableCaching();
649 - $this->sendXDeviceVaryHeader();
650 - $this->sendApplicationVersionVaryHeader();
651 - $this->checkUserStatus();
652 - $this->checkUserLoggedIn();
 642+ $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT );
 643+ $wgRequest->response()->header( 'Location: ' . $location );
 644+ }
653645
654 - if ( self::$title->isSpecial( 'Userlogin' ) && self::$isBetaGroupMember ) {
655 - self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' );
656 - $q = array( 'action' => 'submitlogin', 'type' => 'login' );
657 - $returnToVal = $wgRequest->getVal( 'returnto' );
 646+ if ( $mobileAction == 'opt_out_cookie' ) {
 647+ $this->setOptInOutCookie( '' );
 648+ }
658649
659 - if ( $returnToVal ) {
660 - $q['returnto'] = $returnToVal;
661 - }
 650+ $this->getMsg();
 651+ $this->disableCaching();
 652+ $this->sendXDeviceVaryHeader();
 653+ $this->sendApplicationVersionVaryHeader();
 654+ $this->checkUserStatus();
 655+ $this->checkUserLoggedIn();
662656
663 - self::$wsLoginFormAction = self::$title->getLocalURL( $q );
 657+ if ( self::$title->isSpecial( 'Userlogin' ) && self::$isBetaGroupMember ) {
 658+ self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' );
 659+ $q = array( 'action' => 'submitlogin', 'type' => 'login' );
 660+ $returnToVal = $wgRequest->getVal( 'returnto' );
 661+
 662+ if ( $returnToVal ) {
 663+ $q['returnto'] = $returnToVal;
664664 }
665665
666 - $this->setDefaultLogo();
667 - ob_start( array( $this, 'DOMParse' ) );
 666+ self::$wsLoginFormAction = self::$title->getLocalURL( $q );
668667 }
669668
 669+ $this->setDefaultLogo();
 670+ ob_start( array( $this, 'DOMParse' ) );
 671+
670672 wfProfileOut( __METHOD__ );
671673 return true;
672674 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r106891Fix boolean fail due to tiredness from r106721 and r106724reedy23:23, 20 December 2011

Comments

#Comment by Preilly (talk | contribs)   23:19, 20 December 2011

This logic is wrong:

if ( self::$useFormat === 'mobile' || self::$useFormat === 'mobile-wap' || - $xDevice ) {...

#Comment by Preilly (talk | contribs)   23:19, 20 December 2011

Sorry, I meant: if ( self::$useFormat !== 'mobile' || self::$useFormat !== 'mobile-wap' || !$xDevice ) {

Status & tagging log