From 25ea9b8d959cddf9d61b9f8d59df7434c1ce4984 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Thu, 30 Jun 2011 01:06:17 +0000 Subject: [PATCH] Replace more multiple calls to $this->getResult() in methods with temporary variable --- includes/api/ApiImport.php | 5 +++-- includes/api/ApiMain.php | 18 ++++++++++-------- includes/api/ApiMove.php | 9 ++++++--- includes/api/ApiParse.php | 11 ++++++----- includes/api/ApiProtect.php | 5 +++-- includes/api/ApiPurge.php | 9 +++++---- includes/api/ApiQueryBacklinks.php | 15 +++++++++------ includes/api/ApiQueryBase.php | 7 ++++--- includes/api/ApiQueryCategoryMembers.php | 12 +++++++----- includes/api/ApiQueryRecentChanges.php | 6 ++++-- includes/api/ApiQuerySearch.php | 9 +++++---- includes/api/ApiQuerySiteinfo.php | 9 +++++---- 12 files changed, 67 insertions(+), 48 deletions(-) diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index 57c707b478..12cf08fe3e 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -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() { diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 62afcc5e41..eac29bea90 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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(); diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 85bd5ad17d..6fefc6a389 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -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 ); } /** diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index dfc2602b91..60758884ab 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -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(); diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index ccb7efe40f..021c687886 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -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() { diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 5757b0a367..bcb6f57628 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -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() { diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index bb59154888..e5de929830 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -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 ); diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 628611d445..18a1a1813d 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -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(); } /** diff --git a/includes/api/ApiQueryCategoryMembers.php b/includes/api/ApiQueryCategoryMembers.php index 5d40bac510..b4266b5c36 100644 --- a/includes/api/ApiQueryCategoryMembers.php +++ b/includes/api/ApiQueryCategoryMembers.php @@ -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' ); } } diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 2712bea89e..1cc0e3a4db 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -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 ); } diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index df3831295b..e5bf0d06d5 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -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 { diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index b25b83ce1c..6ace1641bb 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -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 ) { -- 2.20.1