From 50e2405a030a8055a56851b956f06a3ec0a0a461 Mon Sep 17 00:00:00 2001 From: Platonides Date: Thu, 12 Aug 2010 14:25:07 +0000 Subject: [PATCH] Refactor to avoid defining globals inside switches. --- includes/Autopromote.php | 2 +- includes/api/ApiBase.php | 2 +- includes/api/ApiEditPage.php | 3 ++- includes/api/ApiLogin.php | 5 +---- includes/api/ApiUpload.php | 3 ++- maintenance/dumpTextPass.php | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/includes/Autopromote.php b/includes/Autopromote.php index 2f96998087..560ba7a705 100644 --- a/includes/Autopromote.php +++ b/includes/Autopromote.php @@ -104,6 +104,7 @@ class Autopromote { * @return bool Whether the condition is true for the user */ private static function checkCondition( $cond, User $user ) { + global $wgEmailAuthentication; if ( count( $cond ) < 1 ) { return false; } @@ -111,7 +112,6 @@ class Autopromote { switch( $cond[0] ) { case APCOND_EMAILCONFIRMED: if ( User::isValidEmailAddr( $user->getEmail() ) ) { - global $wgEmailAuthentication; if ( $wgEmailAuthentication ) { return (bool)$user->getEmailAuthenticationTimestamp(); } else { diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 1e3d5af2f7..93d57d64d9 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -550,6 +550,7 @@ abstract class ApiBase { * @returns mixed */ protected function getWatchlistValue ( $watchlist, $titleObj, $userOption = null ) { + global $wgUser; switch ( $watchlist ) { case 'watch': return true; @@ -558,7 +559,6 @@ abstract class ApiBase { return false; case 'preferences': - global $wgUser; # If the user is already watching, don't bother checking if ( $titleObj->userIsWatching() ) { return null; diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 6e55b0a078..8742f8b4d1 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -252,6 +252,8 @@ class ApiEditPage extends ApiBase { $retval = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] ); $wgRequest = $oldRequest; + global $wgMaxArticleSize; + switch( $retval ) { case EditPage::AS_HOOK_ERROR: case EditPage::AS_HOOK_ERROR_EXPECTED: @@ -274,7 +276,6 @@ class ApiEditPage extends ApiBase { case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED: case EditPage::AS_CONTENT_TOO_BIG: - global $wgMaxArticleSize; $this->dieUsageMsg( array( 'contenttoobig', $wgMaxArticleSize ) ); case EditPage::AS_READ_ONLY_PAGE_ANON: diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 3cd622bac6..c9b405bd62 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -70,12 +70,10 @@ class ApiLogin extends ApiBase { $loginForm = new LoginForm( $req ); - global $wgCookiePrefix; + global $wgCookiePrefix, $wgUser, $wgPasswordAttemptThrottle;; switch ( $authRes = $loginForm->authenticateUserData() ) { case LoginForm::SUCCESS: - global $wgUser; - $wgUser->setOption( 'rememberpassword', 1 ); $wgUser->setCookies(); @@ -134,7 +132,6 @@ class ApiLogin extends ApiBase { break; case LoginForm::THROTTLED: - global $wgPasswordAttemptThrottle; $result['result'] = 'Throttled'; $result['wait'] = intval( $wgPasswordAttemptThrottle['seconds'] ); break; diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index cf69ce0ffc..9ba52eaa9b 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -167,6 +167,8 @@ class ApiUpload extends ApiBase { * Performs file verification, dies on error. */ protected function verifyUpload( ) { + global $wgFileExtensions; + $verification = $this->mUpload->verifyUpload( ); if ( $verification['status'] === UploadBase::OK ) { return; @@ -184,7 +186,6 @@ class ApiUpload extends ApiBase { $this->dieUsage( 'The file is missing an extension', 'filetype-missing' ); break; case UploadBase::FILETYPE_BADTYPE: - global $wgFileExtensions; $this->dieUsage( 'This type of file is banned', 'filetype-banned', 0, array( 'filetype' => $verification['finalExt'], diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 9da20d9698..3687694557 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -80,11 +80,11 @@ class TextPassDumper extends BackupDumper { } function processOption( $opt, $val, $param ) { + global $IP; $url = $this->processFileOpt( $val, $param ); switch( $opt ) { case 'prefetch': - global $IP; require_once "$IP/maintenance/backupPrefetch.inc"; $this->prefetch = new BaseDump( $url ); break; -- 2.20.1