Merge "Remove unneeded uses of else{} in api/"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 20 Nov 2013 21:34:21 +0000 (21:34 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 20 Nov 2013 21:34:21 +0000 (21:34 +0000)
includes/api/ApiBase.php
includes/api/ApiComparePages.php
includes/api/ApiEditPage.php
includes/api/ApiFormatJson.php
includes/api/ApiMain.php
includes/api/ApiModuleManager.php
includes/api/ApiMove.php
includes/api/ApiParse.php
includes/api/ApiQueryRecentChanges.php
includes/api/ApiQueryUsers.php
includes/api/ApiUpload.php

index 47fb687..b6a7ca8 100644 (file)
@@ -177,9 +177,9 @@ abstract class ApiBase extends ContextSource {
        public function getModuleProfileName( $db = false ) {
                if ( $db ) {
                        return 'API:' . $this->mModuleName . '-DB';
-               } else {
-                       return 'API:' . $this->mModuleName;
                }
+
+               return 'API:' . $this->mModuleName;
        }
 
        /**
@@ -530,9 +530,9 @@ abstract class ApiBase extends ContextSource {
                        }
 
                        return $msg;
-               } else {
-                       return false;
                }
+
+               return false;
        }
 
        /**
@@ -1297,9 +1297,9 @@ abstract class ApiBase extends ContextSource {
        private function warnOrDie( $msg, $enforceLimits = false ) {
                if ( $enforceLimits ) {
                        $this->dieUsage( $msg, 'integeroutofrange' );
-               } else {
-                       $this->setWarning( $msg );
                }
+
+               $this->setWarning( $msg );
        }
 
        /**
@@ -1902,14 +1902,14 @@ abstract class ApiBase extends ContextSource {
                global $wgDebugAPI;
                if ( $wgDebugAPI !== true ) {
                        $this->dieUsageMsg( $error );
-               } else {
-                       if ( is_string( $error ) ) {
-                               $error = array( $error );
-                       }
-                       $parsed = $this->parseMsg( $error );
-                       $this->setWarning( '$wgDebugAPI: ' . $parsed['code']
-                               . ' - ' . $parsed['info'] );
                }
+
+               if ( is_string( $error ) ) {
+                       $error = array( $error );
+               }
+
+               $parsed = $this->parseMsg( $error );
+               $this->setWarning( '$wgDebugAPI: ' . $parsed['code'] . ' - ' . $parsed['info'] );
        }
 
        /**
index 1049b49..237e8c8 100644 (file)
@@ -70,10 +70,10 @@ class ApiComparePages extends ApiBase {
                                        'not exist or you do not have permission to view them.',
                                'baddiff'
                        );
-               } else {
-                       ApiResult::setContent( $vals, $difftext );
                }
 
+               ApiResult::setContent( $vals, $difftext );
+
                $this->getResult()->addValue( null, $this->getModuleName(), $vals );
        }
 
index 4e1c871..73eebca 100644 (file)
@@ -381,9 +381,9 @@ class ApiEditPage extends ApiBase {
                                $apiResult->addValue( null, $this->getModuleName(), $r );
 
                                return;
-                       } else {
-                               $this->dieUsageMsg( 'hookaborted' );
                        }
+
+                       $this->dieUsageMsg( 'hookaborted' );
                }
 
                // Do the actual save
index 15dc73b..be0b58b 100644 (file)
@@ -91,8 +91,8 @@ class ApiFormatJson extends ApiFormatBase {
        public function getDescription() {
                if ( $this->mIsRaw ) {
                        return 'Output data with the debugging elements in JSON format' . parent::getDescription();
-               } else {
-                       return 'Output data in JSON format' . parent::getDescription();
                }
+
+               return 'Output data in JSON format' . parent::getDescription();
        }
 }
index c3ada1f..a9aebe9 100644 (file)
@@ -741,12 +741,10 @@ class ApiMain extends ApiBase {
                if ( $salt !== false ) {
                        if ( !isset( $moduleParams['token'] ) ) {
                                $this->dieUsageMsg( array( 'missingparam', 'token' ) );
-                       } else {
-                               if ( !$this->getUser()
-                                       ->matchEditToken( $moduleParams['token'], $salt, $this->getContext()->getRequest() )
-                               ) {
-                                       $this->dieUsageMsg( 'sessionfailure' );
-                               }
+                       }
+
+                       if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt, $this->getContext()->getRequest() ) ) {
+                               $this->dieUsageMsg( 'sessionfailure' );
                        }
                }
 
@@ -773,11 +771,9 @@ class ApiMain extends ApiBase {
 
                                if ( $wgShowHostnames ) {
                                        $this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
-                               } else {
-                                       $this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
                                }
 
-                               return false;
+                               $this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
                        }
                }
 
index 407e089..c33e18c 100644 (file)
@@ -146,9 +146,9 @@ class ApiModuleManager extends ContextSource {
        public function isDefined( $moduleName, $group = null ) {
                if ( isset( $this->mModules[$moduleName] ) ) {
                        return $group === null || $this->mModules[$moduleName][0] === $group;
-               } else {
-                       return false;
                }
+
+               return false;
        }
 
        /**
@@ -159,9 +159,9 @@ class ApiModuleManager extends ContextSource {
        public function getModuleGroup( $moduleName ) {
                if ( isset( $this->mModules[$moduleName] ) ) {
                        return $this->mModules[$moduleName][0];
-               } else {
-                       return null;
                }
+
+               return null;
        }
 
        /**
index 5d5d1b7..20ac48a 100644 (file)
@@ -157,19 +157,19 @@ class ApiMove extends ApiBase {
                $success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect );
                if ( isset( $success[0] ) ) {
                        return array( 'error' => $this->parseMsg( $success ) );
-               } else {
-                       // At least some pages could be moved
-                       // Report each of them separately
-                       foreach ( $success as $oldTitle => $newTitle ) {
-                               $r = array( 'from' => $oldTitle );
-                               if ( is_array( $newTitle ) ) {
-                                       $r['error'] = $this->parseMsg( reset( $newTitle ) );
-                               } else {
-                                       // Success
-                                       $r['to'] = $newTitle;
-                               }
-                               $retval[] = $r;
+               }
+
+               // At least some pages could be moved
+               // Report each of them separately
+               foreach ( $success as $oldTitle => $newTitle ) {
+                       $r = array( 'from' => $oldTitle );
+                       if ( is_array( $newTitle ) ) {
+                               $r['error'] = $this->parseMsg( reset( $newTitle ) );
+                       } else {
+                               // Success
+                               $r['to'] = $newTitle;
                        }
+                       $retval[] = $r;
                }
 
                return $retval;
index 3ce5da2..ddc032d 100644 (file)
@@ -425,23 +425,24 @@ class ApiParse extends ApiBase {
                if ( $this->section !== false && $this->content !== null ) {
                        $this->content = $this->getSectionContent(
                                $this->content,
-                               !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getText() );
+                               !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getText()
+                       );
 
                        // Not cached (save or load)
                        return $this->content->getParserOutput( $page->getTitle(), null, $popts );
-               } else {
-                       // Try the parser cache first
-                       // getParserOutput will save to Parser cache if able
-                       $pout = $page->getParserOutput( $popts );
-                       if ( !$pout ) {
-                               $this->dieUsage( "There is no revision ID {$page->getLatest()}", 'missingrev' );
-                       }
-                       if ( $getWikitext ) {
-                               $this->content = $page->getContent( Revision::RAW );
-                       }
+               }
 
-                       return $pout;
+               // Try the parser cache first
+               // getParserOutput will save to Parser cache if able
+               $pout = $page->getParserOutput( $popts );
+               if ( !$pout ) {
+                       $this->dieUsage( "There is no revision ID {$page->getLatest()}", 'missingrev' );
+               }
+               if ( $getWikitext ) {
+                       $this->content = $page->getContent( Revision::RAW );
                }
+
+               return $pout;
        }
 
        private function getSectionContent( Content $content, $what ) {
index 50a3352..b44565e 100644 (file)
@@ -72,7 +72,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
         * @param  $pageid
         * @param  $title
         * @param $rc RecentChange (optional)
-        * @return bool|String
+        * @return bool|string
         */
        public static function getPatrolToken( $pageid, $title, $rc = null ) {
                global $wgUser;
@@ -85,23 +85,22 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        ) {
                                $validTokenUser = true;
                        }
-               } else {
-                       if ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
-                               $validTokenUser = true;
-                       }
+               } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
+                       $validTokenUser = true;
                }
 
                if ( $validTokenUser ) {
                        // The patrol token is always the same, let's exploit that
                        static $cachedPatrolToken = null;
+
                        if ( is_null( $cachedPatrolToken ) ) {
                                $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
                        }
 
                        return $cachedPatrolToken;
-               } else {
-                       return false;
                }
+
+               return false;
        }
 
        /**
index f22140a..cd4a8fc 100644 (file)
@@ -271,11 +271,7 @@ class ApiQueryUsers extends ApiQueryBase {
        }
 
        public function getCacheMode( $params ) {
-               if ( isset( $params['token'] ) ) {
-                       return 'private';
-               } else {
-                       return 'anon-public-user-private';
-               }
+               return isset( $params['token'] ) ? 'private' : 'anon-public-user-private';
        }
 
        public function getAllowedParams() {
index 01e0f6e..1a642b9 100644 (file)
@@ -458,9 +458,9 @@ class ApiUpload extends ApiBase {
                if ( $permission !== true ) {
                        if ( !$user->isLoggedIn() ) {
                                $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
-                       } else {
-                               $this->dieUsageMsg( 'badaccess-groups' );
                        }
+
+                       $this->dieUsageMsg( 'badaccess-groups' );
                }
        }
 
@@ -661,11 +661,10 @@ class ApiUpload extends ApiBase {
                                                'result' => 'Queued',
                                                'statuskey' => $error[0][1],
                                        );
-                               } else {
-                                       $this->getResult()->setIndexedTagName( $error, 'error' );
-
-                                       $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
                                }
+
+                               $this->getResult()->setIndexedTagName( $error, 'error' );
+                               $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
                        }
                        $result['result'] = 'Success';
                }