From ca209473d1e94196a8f9d454bb6f6ab40841f9c8 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sun, 17 Nov 2013 20:54:11 +0100 Subject: [PATCH] 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 --- includes/api/ApiBase.php | 26 +++++++++++++------------- includes/api/ApiComparePages.php | 4 ++-- includes/api/ApiEditPage.php | 4 ++-- includes/api/ApiFormatJson.php | 4 ++-- includes/api/ApiMain.php | 14 +++++--------- includes/api/ApiModuleManager.php | 8 ++++---- includes/api/ApiMove.php | 24 ++++++++++++------------ includes/api/ApiParse.php | 25 +++++++++++++------------ includes/api/ApiQueryRecentChanges.php | 13 ++++++------- includes/api/ApiQueryUsers.php | 6 +----- includes/api/ApiUpload.php | 11 +++++------ 11 files changed, 65 insertions(+), 74 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 47fb687723..b6a7ca8de6 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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'] ); } /** diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php index 1049b49c35..237e8c8758 100644 --- a/includes/api/ApiComparePages.php +++ b/includes/api/ApiComparePages.php @@ -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 ); } diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 4e1c871142..73eebcad08 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -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 diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 15dc73b02c..be0b58b63b 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -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(); } } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 9ecae8d0a8..85f24b6eb5 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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' ); } } diff --git a/includes/api/ApiModuleManager.php b/includes/api/ApiModuleManager.php index 407e089ca3..c33e18c9a4 100644 --- a/includes/api/ApiModuleManager.php +++ b/includes/api/ApiModuleManager.php @@ -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; } /** diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 5d5d1b7a98..20ac48a8a2 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -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; diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 3ce5da200b..ddc032d779 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -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 ) { diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 50a335233d..b44565e431 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -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; } /** diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index f22140a0df..cd4a8fcf0f 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -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() { diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 01e0f6e04a..1a642b9cda 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -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'; } -- 2.20.1