Siebrand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/95887


Change subject: Remove unneeded uses of else{} in api/
......................................................................

Remove unneeded uses of else{} in api/

Fixed a little documentation issue, removed a line of unreachable code
and fixed up two formatting issues in the process.

Change-Id: If29391ee1a0daf19973437f36c3216b8716debd0
---
M includes/api/ApiBase.php
M includes/api/ApiComparePages.php
M includes/api/ApiEditPage.php
M includes/api/ApiFormatJson.php
M includes/api/ApiMain.php
M includes/api/ApiModuleManager.php
M includes/api/ApiMove.php
M includes/api/ApiParse.php
M includes/api/ApiQueryRecentChanges.php
M includes/api/ApiQueryUsers.php
M includes/api/ApiUpload.php
11 files changed, 64 insertions(+), 66 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/87/95887/1

diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index f776e6d..247d3e8 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -163,9 +163,9 @@
        public function getModuleProfileName( $db = false ) {
                if ( $db ) {
                        return 'API:' . $this->mModuleName . '-DB';
-               } else {
-                       return 'API:' . $this->mModuleName;
                }
+
+               return 'API:' . $this->mModuleName;
        }
 
        /**
@@ -502,9 +502,9 @@
                        }
 
                        return $msg;
-               } else {
-                       return false;
                }
+
+               return false;
        }
 
        /**
@@ -1196,9 +1196,9 @@
        private function warnOrDie( $msg, $enforceLimits = false ) {
                if ( $enforceLimits ) {
                        $this->dieUsage( $msg, 'integeroutofrange' );
-               } else {
-                       $this->setWarning( $msg );
                }
+
+               $this->setWarning( $msg );
        }
 
        /**
@@ -1465,14 +1465,14 @@
                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'] );
        }
 
        /**
diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php
index cbad164..3ea230c 100644
--- a/includes/api/ApiComparePages.php
+++ b/includes/api/ApiComparePages.php
@@ -67,10 +67,10 @@
                if ( $difftext === false ) {
                        $this->dieUsage( 'The diff cannot be retrieved. ' .
                                'Maybe one or both revisions do 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 );
        }
 
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index fd024e1..3c34c60 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -365,9 +365,9 @@
                                $apiResult->addValue( null, 
$this->getModuleName(), $r );
 
                                return;
-                       } else {
-                               $this->dieUsageMsg( 'hookaborted' );
                        }
+
+                       $this->dieUsageMsg( 'hookaborted' );
                }
 
                // Do the actual save
diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php
index 7a88176..a9da38f 100644
--- a/includes/api/ApiFormatJson.php
+++ b/includes/api/ApiFormatJson.php
@@ -89,8 +89,8 @@
        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();
        }
 }
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index c301e9e..7047b55 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -726,10 +726,10 @@
                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' );
                        }
                }
 
@@ -756,11 +756,9 @@
 
                                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' );
                        }
                }
 
diff --git a/includes/api/ApiModuleManager.php 
b/includes/api/ApiModuleManager.php
index 407e089..c33e18c 100644
--- a/includes/api/ApiModuleManager.php
+++ b/includes/api/ApiModuleManager.php
@@ -146,9 +146,9 @@
        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 @@
        public function getModuleGroup( $moduleName ) {
                if ( isset( $this->mModules[$moduleName] ) ) {
                        return $this->mModules[$moduleName][0];
-               } else {
-                       return null;
                }
+
+               return null;
        }
 
        /**
diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php
index c2d0959..00489e0 100644
--- a/includes/api/ApiMove.php
+++ b/includes/api/ApiMove.php
@@ -153,19 +153,19 @@
                $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;
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 3ce5da2..ddc032d 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -425,23 +425,24 @@
                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 ) {
diff --git a/includes/api/ApiQueryRecentChanges.php 
b/includes/api/ApiQueryRecentChanges.php
index 7848853..81b8e59 100644
--- a/includes/api/ApiQueryRecentChanges.php
+++ b/includes/api/ApiQueryRecentChanges.php
@@ -72,7 +72,7 @@
         * @param  $pageid
         * @param  $title
         * @param $rc RecentChange (optional)
-        * @return bool|String
+        * @return bool|string
         */
        public static function getPatrolToken( $pageid, $title, $rc = null ) {
                global $wgUser;
@@ -99,9 +99,9 @@
                        }
 
                        return $cachedPatrolToken;
-               } else {
-                       return false;
                }
+
+               return false;
        }
 
        /**
diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php
index f22140a..102a60b 100644
--- a/includes/api/ApiQueryUsers.php
+++ b/includes/api/ApiQueryUsers.php
@@ -273,9 +273,9 @@
        public function getCacheMode( $params ) {
                if ( isset( $params['token'] ) ) {
                        return 'private';
-               } else {
-                       return 'anon-public-user-private';
                }
+
+               return 'anon-public-user-private';
        }
 
        public function getAllowedParams() {
diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php
index 01e0f6e..1a642b9 100644
--- a/includes/api/ApiUpload.php
+++ b/includes/api/ApiUpload.php
@@ -458,9 +458,9 @@
                if ( $permission !== true ) {
                        if ( !$user->isLoggedIn() ) {
                                $this->dieUsageMsg( array( 'mustbeloggedin', 
'upload' ) );
-                       } else {
-                               $this->dieUsageMsg( 'badaccess-groups' );
                        }
+
+                       $this->dieUsageMsg( 'badaccess-groups' );
                }
        }
 
@@ -661,11 +661,10 @@
                                                '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';
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/95887
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If29391ee1a0daf19973437f36c3216b8716debd0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to