Replace more multiple calls to $this->getResult() in methods with temporary variable
authorSam Reed <reedy@users.mediawiki.org>
Thu, 30 Jun 2011 01:06:17 +0000 (01:06 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Thu, 30 Jun 2011 01:06:17 +0000 (01:06 +0000)
12 files changed:
includes/api/ApiImport.php
includes/api/ApiMain.php
includes/api/ApiMove.php
includes/api/ApiParse.php
includes/api/ApiProtect.php
includes/api/ApiPurge.php
includes/api/ApiQueryBacklinks.php
includes/api/ApiQueryBase.php
includes/api/ApiQueryCategoryMembers.php
includes/api/ApiQueryRecentChanges.php
includes/api/ApiQuerySearch.php
includes/api/ApiQuerySiteinfo.php

index 57c707b..12cf08f 100644 (file)
@@ -88,8 +88,9 @@ class ApiImport extends ApiBase {
                }
 
                $resultData = $reporter->getData();
-               $this->getResult()->setIndexedTagName( $resultData, 'page' );
-               $this->getResult()->addValue( null, $this->getModuleName(), $resultData );
+               $result = $this->getResult();
+               $result->setIndexedTagName( $resultData, 'page' );
+               $result->addValue( null, $this->getModuleName(), $resultData );
        }
 
        public function mustBePosted() {
index 62afcc5..eac29be 100644 (file)
@@ -473,6 +473,7 @@ class ApiMain extends ApiBase {
         * @return string
         */
        protected function substituteResultWithError( $e ) {
+               $result = $this->getResult();
                // Printer may not be initialized if the extractRequestParams() fails for the main module
                if ( !isset ( $this->mPrinter ) ) {
                        // The printer has not been created yet. Try to manually get formatter value.
@@ -483,7 +484,7 @@ class ApiMain extends ApiBase {
 
                        $this->mPrinter = $this->createPrinterByName( $value );
                        if ( $this->mPrinter->getNeedsRawData() ) {
-                               $this->getResult()->setRawMode();
+                               $result->setRawMode();
                        }
                }
 
@@ -512,16 +513,16 @@ class ApiMain extends ApiBase {
                        ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' );
                }
 
-               $this->getResult()->reset();
-               $this->getResult()->disableSizeCheck();
+               $result->reset();
+               $result->disableSizeCheck();
                // Re-add the id
                $requestid = $this->getParameter( 'requestid' );
                if ( !is_null( $requestid ) ) {
-                       $this->getResult()->addValue( null, 'requestid', $requestid );
+                       $result->addValue( null, 'requestid', $requestid );
                }
                // servedby is especially useful when debugging errors
-               $this->getResult()->addValue( null, 'servedby', wfHostName() );
-               $this->getResult()->addValue( null, 'error', $errMessage );
+               $result->addValue( null, 'servedby', wfHostName() );
+               $result->addValue( null, 'error', $errMessage );
 
                return $errMessage['code'];
        }
@@ -532,13 +533,14 @@ class ApiMain extends ApiBase {
         */
        protected function setupExecuteAction() {
                // First add the id to the top element
+               $result = $this->getResult();
                $requestid = $this->getParameter( 'requestid' );
                if ( !is_null( $requestid ) ) {
-                       $this->getResult()->addValue( null, 'requestid', $requestid );
+                       $result->addValue( null, 'requestid', $requestid );
                }
                $servedby = $this->getParameter( 'servedby' );
                if ( $servedby ) {
-                       $this->getResult()->addValue( null, 'servedby', wfHostName() );
+                       $result->addValue( null, 'servedby', wfHostName() );
                }
 
                $params = $this->extractRequestParams();
index 85bd5ad..6fefc6a 100644 (file)
@@ -107,15 +107,18 @@ class ApiMove extends ApiBase {
                        }
                }
 
+               $result = $this->getResult();
+
                // Move subpages
                if ( $params['movesubpages'] ) {
                        $r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
                                        $params['reason'], $params['noredirect'] );
-                       $this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' );
+                       $result->setIndexedTagName( $r['subpages'], 'subpage' );
+
                        if ( $params['movetalk'] ) {
                                $r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
                                        $params['reason'], $params['noredirect'] );
-                               $this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' );
+                               $result->setIndexedTagName( $r['subpages-talk'], 'subpage' );
                        }
                }
 
@@ -132,7 +135,7 @@ class ApiMove extends ApiBase {
                $this->setWatch( $watch, $fromTitle, 'watchmoves' );
                $this->setWatch( $watch, $toTitle, 'watchmoves' );
 
-               $this->getResult()->addValue( null, $this->getModuleName(), $r );
+               $result->addValue( null, $this->getModuleName(), $r );
        }
 
        /**
index dfc2602..6075888 100644 (file)
@@ -77,6 +77,9 @@ class ApiParse extends ApiBase {
 
                $redirValues = null;
 
+               // Return result
+               $result = $this->getResult();
+
                if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
                        if ( !is_null( $oldid ) ) {
                                // Don't use the parser cache
@@ -178,19 +181,17 @@ class ApiParse extends ApiBase {
                        if ( $params['onlypst'] ) {
                                // Build a result and bail out
                                $result_array['text'] = array();
-                               $this->getResult()->setContent( $result_array['text'], $this->pstText );
+                               $result->setContent( $result_array['text'], $this->pstText );
                                if ( isset( $prop['wikitext'] ) ) {
                                        $result_array['wikitext'] = array();
-                                       $this->getResult()->setContent( $result_array['wikitext'], $this->text );
+                                       $result->setContent( $result_array['wikitext'], $this->text );
                                }
-                               $this->getResult()->addValue( null, $this->getModuleName(), $result_array );
+                               $result->addValue( null, $this->getModuleName(), $result_array );
                                return;
                        }
                        $p_result = $wgParser->parse( $params['pst'] ? $this->pstText : $this->text, $titleObj, $popts );
                }
 
-               // Return result
-               $result = $this->getResult();
                $result_array = array();
 
                $result_array['title'] = $titleObj->getPrefixedText();
index ccb7efe..021c687 100644 (file)
@@ -130,8 +130,9 @@ class ApiProtect extends ApiBase {
                        $res['cascade'] = '';
                }
                $res['protections'] = $resultProtections;
-               $this->getResult()->setIndexedTagName( $res['protections'], 'protection' );
-               $this->getResult()->addValue( null, $this->getModuleName(), $res );
+               $result = $this->getResult();
+               $result->setIndexedTagName( $res['protections'], 'protection' );
+               $result->addValue( null, $this->getModuleName(), $res );
        }
 
        public function mustBePosted() {
index 5757b0a..bcb6f57 100644 (file)
@@ -72,7 +72,7 @@ class ApiPurge extends ApiBase {
                        $article = Article::newFromTitle( $title, $context );
                        $article->doPurge(); // Directly purge and skip the UI part of purge().
                        $r['purged'] = '';
-                       
+
                        if( $forceLinkUpdate ) {
                                if ( !$wgUser->pingLimiter() ) {
                                        global $wgParser, $wgEnableParserCache;
@@ -94,11 +94,12 @@ class ApiPurge extends ApiBase {
                                        $forceLinkUpdate = false;
                                }
                        }
-                       
+
                        $result[] = $r;
                }
-               $this->getResult()->setIndexedTagName( $result, 'page' );
-               $this->getResult()->addValue( null, $this->getModuleName(), $result );
+               $apiResult = $this->getResult();
+               $apiResult->setIndexedTagName( $result, 'page' );
+               $apiResult->addValue( null, $this->getModuleName(), $result );
        }
 
        public function isWriteMode() {
index bb59154..e5de929 100644 (file)
@@ -231,9 +231,12 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                $this->redirect = isset( $this->params['redirect'] ) && $this->params['redirect'];
                $userMax = ( $this->redirect ? ApiBase::LIMIT_BIG1 / 2 : ApiBase::LIMIT_BIG1 );
                $botMax  = ( $this->redirect ? ApiBase::LIMIT_BIG2 / 2 : ApiBase::LIMIT_BIG2 );
+
+               $result = $this->getResult();
+
                if ( $this->params['limit'] == 'max' ) {
                        $this->params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
-                       $this->getResult()->setParsedLimit( $this->getModuleName(), $this->params['limit'] );
+                       $result->setParsedLimit( $this->getModuleName(), $this->params['limit'] );
                }
 
                $this->processContinue();
@@ -290,13 +293,13 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                }
                if ( is_null( $resultPageSet ) ) {
                        // Try to add the result data in one go and pray that it fits
-                       $fit = $this->getResult()->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) );
+                       $fit = $result->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) );
                        if ( !$fit ) {
                                // It didn't fit. Add elements one by one until the
                                // result is full.
                                foreach ( $this->resultArr as $pageID => $arr ) {
                                        // Add the basic entry without redirlinks first
-                                       $fit = $this->getResult()->addValue(
+                                       $fit = $result->addValue(
                                                array( 'query', $this->getModuleName() ),
                                                null, array_diff_key( $arr, array( 'redirlinks' => '' ) ) );
                                        if ( !$fit ) {
@@ -307,7 +310,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                                        $hasRedirs = false;
                                        $redirLinks = isset( $arr['redirlinks'] ) ? $arr['redirlinks'] : array();
                                        foreach ( (array)$redirLinks as $key => $redir ) {
-                                               $fit = $this->getResult()->addValue(
+                                               $fit = $result->addValue(
                                                        array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
                                                        $key, $redir );
                                                if ( !$fit ) {
@@ -317,7 +320,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                                                $hasRedirs = true;
                                        }
                                        if ( $hasRedirs ) {
-                                               $this->getResult()->setIndexedTagName_internal(
+                                               $result->setIndexedTagName_internal(
                                                        array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
                                                        $this->bl_code );
                                        }
@@ -327,7 +330,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                                }
                        }
 
-                       $this->getResult()->setIndexedTagName_internal(
+                       $result->setIndexedTagName_internal(
                                array( 'query', $this->getModuleName() ),
                                $this->bl_code
                        );
index 628611d..18a1a18 100644 (file)
@@ -352,9 +352,10 @@ abstract class ApiQueryBase extends ApiBase {
        protected function setContinueEnumParameter( $paramName, $paramValue ) {
                $paramName = $this->encodeParamName( $paramName );
                $msg = array( $paramName => $paramValue );
-               $this->getResult()->disableSizeCheck();
-               $this->getResult()->addValue( 'query-continue', $this->getModuleName(), $msg );
-               $this->getResult()->enableSizeCheck();
+               $result = $this->getResult();
+               $result->disableSizeCheck();
+               $result->addValue( 'query-continue', $this->getModuleName(), $msg );
+               $result->enableSizeCheck();
        }
 
        /**
index 5d40bac..b4266b5 100644 (file)
@@ -129,11 +129,11 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                                'by the previous query', '_badcontinue'
                                        );
                                }
-                               
+
                                // Remove the types to skip from $queryTypes
                                $contTypeIndex = array_search( $cont[0], $queryTypes );
                                $queryTypes = array_slice( $queryTypes, $contTypeIndex );
-                               
+
                                // Add a WHERE clause for sortkey and from
                                // pack( "H*", $foo ) is used to convert hex back to binary
                                $escSortkey = $this->getDB()->addQuotes( pack( "H*", $cont[1] ) );
@@ -143,7 +143,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                $contWhere = "cl_sortkey $op $escSortkey OR " .
                                        "(cl_sortkey = $escSortkey AND " .
                                        "cl_from $op= $from)";
-                               
+
                        } else {
                                // The below produces ORDER BY cl_sortkey, cl_from, possibly with DESC added to each of them
                                $this->addWhereRange( 'cl_sortkey',
@@ -189,6 +189,8 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                        $res = $this->select( __METHOD__ );
                        $rows = iterator_to_array( $res );
                }
+
+               $result = $this->getResult();
                $count = 0;
                foreach ( $rows as $row ) {
                        if ( ++ $count > $limit ) {
@@ -234,7 +236,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                if ( $fld_timestamp ) {
                                        $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
                                }
-                               $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ),
+                               $fit = $result->addValue( array( 'query', $this->getModuleName() ),
                                                null, $vals );
                                if ( !$fit ) {
                                        if ( $params['sort'] == 'timestamp' ) {
@@ -253,7 +255,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                }
 
                if ( is_null( $resultPageSet ) ) {
-                       $this->getResult()->setIndexedTagName_internal(
+                       $result->setIndexedTagName_internal(
                                         array( 'query', $this->getModuleName() ), 'cm' );
                }
        }
index 2712bea..1cc0e3a 100644 (file)
@@ -269,6 +269,8 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
                $titles = array();
 
+               $result = $this->getResult();
+
                /* Iterate through the rows, adding data extracted from them to our query result. */
                foreach ( $res as $row ) {
                        if ( ++ $count > $params['limit'] ) {
@@ -285,7 +287,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                if ( !$vals ) {
                                        continue;
                                }
-                               $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
+                               $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                                if ( !$fit ) {
                                        $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
                                        break;
@@ -297,7 +299,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
                if ( is_null( $resultPageSet ) ) {
                        /* Format the result */
-                       $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
+                       $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
                } else {
                        $resultPageSet->populateFromTitles( $titles );
                }
index df38312..e5bf0d0 100644 (file)
@@ -97,16 +97,17 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        $this->dieUsage( "{$what} search is disabled", "search-{$what}-disabled" );
                }
 
+               $result = $this->getResult();
                // Add search meta data to result
                if ( isset( $searchInfo['totalhits'] ) ) {
                        $totalhits = $matches->getTotalHits();
                        if ( $totalhits !== null ) {
-                               $this->getResult()->addValue( array( 'query', 'searchinfo' ),
+                               $result->addValue( array( 'query', 'searchinfo' ),
                                                'totalhits', $totalhits );
                        }
                }
                if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) {
-                       $this->getResult()->addValue( array( 'query', 'searchinfo' ),
+                       $result->addValue( array( 'query', 'searchinfo' ),
                                                'suggestion', $matches->getSuggestionQuery() );
                }
 
@@ -171,7 +172,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                }
 
                                // Add item to results and see whether it fits
-                               $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ),
+                               $fit = $result->addValue( array( 'query', $this->getModuleName() ),
                                                null, $vals );
                                if ( !$fit ) {
                                        $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 );
@@ -185,7 +186,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                }
 
                if ( is_null( $resultPageSet ) ) {
-                       $this->getResult()->setIndexedTagName_internal( array(
+                       $result->setIndexedTagName_internal( array(
                                                'query', $this->getModuleName()
                                        ), 'p' );
                } else {
index b25b83c..6ace164 100644 (file)
@@ -347,6 +347,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
 
                $data = array();
+               $result = $this->getResult();
                foreach ( $wgGroupPermissions as $group => $permissions ) {
                        $arr = array(
                                'name' => $group,
@@ -375,16 +376,16 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        foreach ( $groupArr as $type => $rights ) {
                                if ( isset( $rights[$group] ) ) {
                                        $arr[$type] = $rights[$group];
-                                       $this->getResult()->setIndexedTagName( $arr[$type], 'group' );
+                                       $result->setIndexedTagName( $arr[$type], 'group' );
                                }
                        }
 
-                       $this->getResult()->setIndexedTagName( $arr['rights'], 'permission' );
+                       $result->setIndexedTagName( $arr['rights'], 'permission' );
                        $data[] = $arr;
                }
 
-               $this->getResult()->setIndexedTagName( $data, 'group' );
-               return $this->getResult()->addValue( 'query', $property, $data );
+               $result->setIndexedTagName( $data, 'group' );
+               return $result->addValue( 'query', $property, $data );
        }
 
        protected function appendFileExtensions( $property ) {