Refactor to avoid defining globals inside switches.
authorPlatonides <platonides@users.mediawiki.org>
Thu, 12 Aug 2010 14:25:07 +0000 (14:25 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Thu, 12 Aug 2010 14:25:07 +0000 (14:25 +0000)
includes/Autopromote.php
includes/api/ApiBase.php
includes/api/ApiEditPage.php
includes/api/ApiLogin.php
includes/api/ApiUpload.php
maintenance/dumpTextPass.php

index 2f96998..560ba7a 100644 (file)
@@ -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 {
index 1e3d5af..93d57d6 100644 (file)
@@ -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;
index 6e55b0a..8742f8b 100644 (file)
@@ -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:
index 3cd622b..c9b405b 100644 (file)
@@ -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;
index cf69ce0..9ba52ea 100644 (file)
@@ -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'],
index 9da20d9..3687694 100644 (file)
@@ -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;