r106721 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106720‎ | r106721 | r106722 >
Date:23:27, 19 December 2011
Author:reedy
Status:resolved
Tags:
Comment:
Reducing indenting by one level as it was too much, and another by inverting an if statement and returning early
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -424,6 +424,12 @@
425425 return true;
426426 }
427427
 428+ /**
 429+ * @param $out OutputPage
 430+ * @param $redirect
 431+ * @param $code
 432+ * @return bool
 433+ */
428434 public function beforePageRedirect( $out, &$redirect, &$code ) {
429435 global $wgMobileDomain;
430436 wfProfileIn( __METHOD__ );
@@ -454,7 +460,7 @@
455461 }
456462
457463 /**
458 - * @param $out Outputpage
 464+ * @param $out OutputPage
459465 * @param $text String
460466 * @return bool
461467 */
@@ -502,160 +508,162 @@
503509
504510 if ( self::$useFormat === 'mobile' || self::$useFormat === 'mobile-wap' ||
505511 $xDevice ) {
506 - if ( $action !== 'edit' &&
507 - $mobileAction !== 'view_normal_site' ) {
 512+ if ( $action === 'edit' &&
 513+ $mobileAction === 'view_normal_site' ) {
 514+ wfProfileOut( __METHOD__ );
 515+ return true;
 516+ }
508517
509 - self::$title = $out->getTitle();
 518+ self::$title = $out->getTitle();
510519
511 - if ( Title::newMainPage()->equals( self::$title ) ) {
512 - self::$isMainPage = true;
513 - }
514 - if ( self::$title->getNamespace() == NS_FILE ) {
515 - self::$isFilePage = true;
516 - }
 520+ if ( Title::newMainPage()->equals( self::$title ) ) {
 521+ self::$isMainPage = true;
 522+ }
 523+ if ( self::$title->getNamespace() == NS_FILE ) {
 524+ self::$isFilePage = true;
 525+ }
517526
518 - self::$htmlTitle = $out->getHTMLTitle();
519 - self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
520 - self::$enableImages = $wgRequest->getText( 'enableImages', 0 );
521 - self::$displayNoticeId = $wgRequest->getText( 'noticeid', '' );
 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', '' );
522531
523 - if ( self::$disableImages == 1 ) {
524 - $wgRequest->response()->setcookie( 'disableImages', 1 );
525 - $location = str_replace( '?disableImages=1', '', str_replace( '&disableImages=1', '', $wgRequest->getFullRequestURL() ) );
526 - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
527 - $location = $this->getRelativeURL( $location );
528 - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=0' );
529 - }
 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+ }
530539
531 - if ( self::$disableImages == 0 ) {
532 - $disableImages = $wgRequest->getCookie( 'disableImages' );
533 - if ( $disableImages ) {
534 - self::$disableImages = $disableImages;
535 - }
536 - }
 540+ if ( self::$disableImages == 0 ) {
 541+ $disableImages = $wgRequest->getCookie( 'disableImages' );
 542+ if ( $disableImages ) {
 543+ self::$disableImages = $disableImages;
 544+ }
 545+ }
537546
538 - if ( self::$enableImages == 1 ) {
539 - $disableImages = $wgRequest->getCookie( 'disableImages' );
540 - if ( $disableImages ) {
541 - $wgRequest->response()->setcookie( 'disableImages', '' );
542 - }
543 - $location = str_replace( '?enableImages=1', '', str_replace( '&enableImages=1', '', $wgRequest->getFullRequestURL() ) );
544 - $location = str_replace( '&mfi=1', '', str_replace( '&mfi=0', '', $location ) );
545 - $location = $this->getRelativeURL( $location );
546 - $wgRequest->response()->header( 'Location: ' . $location . '&mfi=1' );
547 - }
 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' );
 556+ }
548557
549 - self::$format = $wgRequest->getText( 'format' );
550 - self::$callback = $wgRequest->getText( 'callback' );
551 - self::$requestedSegment = $wgRequest->getText( 'seg', 0 );
552 - self::$search = $wgRequest->getText( 'search' );
553 - self::$searchField = $wgRequest->getText( 'search', '' );
 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', '' );
554563
555 - $acceptHeader = isset( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : '';
556 - $device = new DeviceDetection();
 564+ $acceptHeader = isset( $_SERVER["HTTP_ACCEPT"] ) ? $_SERVER["HTTP_ACCEPT"] : '';
 565+ $device = new DeviceDetection();
557566
558 - if ( $xDevice ) {
559 - $formatName = $xDevice;
560 - } else {
561 - $formatName = $device->formatName( $userAgent, $acceptHeader );
562 - }
 567+ if ( $xDevice ) {
 568+ $formatName = $xDevice;
 569+ } else {
 570+ $formatName = $device->formatName( $userAgent, $acceptHeader );
 571+ }
563572
564 - self::$device = $device->format( $formatName );
 573+ self::$device = $device->format( $formatName );
565574
566 - if ( self::$device['view_format'] === 'wml' ) {
567 - $this->contentFormat = 'WML';
568 - } elseif ( self::$device['view_format'] === 'html' ) {
569 - $this->contentFormat = 'XHTML';
570 - }
 575+ if ( self::$device['view_format'] === 'wml' ) {
 576+ $this->contentFormat = 'WML';
 577+ } elseif ( self::$device['view_format'] === 'html' ) {
 578+ $this->contentFormat = 'XHTML';
 579+ }
571580
572 - if ( self::$useFormat === 'mobile-wap' ) {
573 - $this->contentFormat = 'WML';
574 - }
 581+ if ( self::$useFormat === 'mobile-wap' ) {
 582+ $this->contentFormat = 'WML';
 583+ }
575584
576 - if ( $mobileAction == 'leave_feedback' ) {
577 - echo $this->renderLeaveFeedbackXHTML();
578 - wfProfileOut( __METHOD__ );
579 - exit();
580 - }
 585+ if ( $mobileAction == 'leave_feedback' ) {
 586+ echo $this->renderLeaveFeedbackXHTML();
 587+ wfProfileOut( __METHOD__ );
 588+ exit();
 589+ }
581590
582 - if ( $mobileAction == 'leave_feedback_post' ) {
 591+ if ( $mobileAction == 'leave_feedback_post' ) {
583592
584 - $this->getMsg();
 593+ $this->getMsg();
585594
586 - $subject = $wgRequest->getText( 'subject', '' );
587 - $message = $wgRequest->getText( 'message', '' );
588 - $token = $wgRequest->getText( 'edittoken', '' );
 595+ $subject = $wgRequest->getText( 'subject', '' );
 596+ $message = $wgRequest->getText( 'message', '' );
 597+ $token = $wgRequest->getText( 'edittoken', '' );
589598
590 - $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] );
 599+ $title = Title::newFromText( self::$messages['mobile-frontend-feedback-page'] );
591600
592 - if ( $title->userCan( 'edit' ) &&
593 - !$wgUser->isBlockedFrom( $title ) &&
594 - $wgUser->matchEditToken( $token ) ) {
595 - $article = new Article( $title, 0 );
596 - $rawtext = $article->getRawText();
597 - $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> ";
598 - $article->doEdit( $rawtext, '' );
599 - }
 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+ }
600609
601 - $location = str_replace( '&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '&noticeid=1&useformat=mobile' );
602 - $location = $this->getRelativeURL( $location );
603 - $wgRequest->response()->header( 'Location: ' . $location );
604 - wfProfileOut( __METHOD__ );
605 - exit();
606 - }
 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();
 615+ }
607616
608 - if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) {
609 - echo $this->renderDisableMobileSiteXHTML();
610 - wfProfileOut( __METHOD__ );
611 - exit();
612 - }
 617+ if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) {
 618+ echo $this->renderDisableMobileSiteXHTML();
 619+ wfProfileOut( __METHOD__ );
 620+ exit();
 621+ }
613622
614 - if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) {
615 - echo $this->renderOptInMobileSiteXHTML();
616 - wfProfileOut( __METHOD__ );
617 - exit();
618 - }
 623+ if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) {
 624+ echo $this->renderOptInMobileSiteXHTML();
 625+ wfProfileOut( __METHOD__ );
 626+ exit();
 627+ }
619628
620 - if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) {
621 - echo $this->renderOptOutMobileSiteXHTML();
622 - wfProfileOut( __METHOD__ );
623 - exit();
624 - }
 629+ if ( $mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML' ) {
 630+ echo $this->renderOptOutMobileSiteXHTML();
 631+ wfProfileOut( __METHOD__ );
 632+ exit();
 633+ }
625634
626 - if ( $mobileAction == 'opt_in_cookie' ) {
627 - wfIncrStats( 'mobile.opt_in_cookie_set' );
628 - $this->setOptInOutCookie( '1' );
629 - $this->disableCaching();
630 - $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT );
631 - $wgRequest->response()->header( 'Location: ' . $location );
632 - }
 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+ }
633642
634 - if ( $mobileAction == 'opt_out_cookie' ) {
635 - $this->setOptInOutCookie( '' );
636 - }
 643+ if ( $mobileAction == 'opt_out_cookie' ) {
 644+ $this->setOptInOutCookie( '' );
 645+ }
637646
638 - $this->getMsg();
639 - $this->disableCaching();
640 - $this->sendXDeviceVaryHeader();
641 - $this->sendApplicationVersionVaryHeader();
642 - $this->checkUserStatus();
643 - $this->checkUserLoggedIn();
 647+ $this->getMsg();
 648+ $this->disableCaching();
 649+ $this->sendXDeviceVaryHeader();
 650+ $this->sendApplicationVersionVaryHeader();
 651+ $this->checkUserStatus();
 652+ $this->checkUserLoggedIn();
644653
645 - if ( self::$title->isSpecial( 'Userlogin' ) && self::$isBetaGroupMember ) {
646 - self::$wsLoginToken = $wgRequest->getSessionData( 'wsLoginToken' );
647 - $q = array( 'action' => 'submitlogin', 'type' => 'login' );
648 - $returnToVal = $wgRequest->getVal( 'returnto' );
 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' );
649658
650 - if ( $returnToVal ) {
651 - $q['returnto'] = $returnToVal;
652 - }
 659+ if ( $returnToVal ) {
 660+ $q['returnto'] = $returnToVal;
 661+ }
653662
654 - self::$wsLoginFormAction = self::$title->getLocalURL( $q );
655 - }
 663+ self::$wsLoginFormAction = self::$title->getLocalURL( $q );
 664+ }
656665
657 - $this->setDefaultLogo();
658 - ob_start( array( $this, 'DOMParse' ) );
659 - }
 666+ $this->setDefaultLogo();
 667+ ob_start( array( $this, 'DOMParse' ) );
660668 }
661669
662670 wfProfileOut( __METHOD__ );

Follow-up revisions

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

Status & tagging log