r91147 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91146‎ | r91147 | r91148 >
Date:01:06, 30 June 2011
Author:reedy
Status:ok
Tags:
Comment:
Replace more multiple calls to $this->getResult() in methods with temporary variable
Modified paths:
  • /trunk/phase3/includes/api/ApiImport.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMove.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)
  • /trunk/phase3/includes/api/ApiProtect.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPurge.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategoryMembers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySearch.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryRecentChanges.php
@@ -269,6 +269,8 @@
270270
271271 $titles = array();
272272
 273+ $result = $this->getResult();
 274+
273275 /* Iterate through the rows, adding data extracted from them to our query result. */
274276 foreach ( $res as $row ) {
275277 if ( ++ $count > $params['limit'] ) {
@@ -285,7 +287,7 @@
286288 if ( !$vals ) {
287289 continue;
288290 }
289 - $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
 291+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
290292 if ( !$fit ) {
291293 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
292294 break;
@@ -297,7 +299,7 @@
298300
299301 if ( is_null( $resultPageSet ) ) {
300302 /* Format the result */
301 - $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
 303+ $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
302304 } else {
303305 $resultPageSet->populateFromTitles( $titles );
304306 }
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -347,6 +347,7 @@
348348 global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
349349
350350 $data = array();
 351+ $result = $this->getResult();
351352 foreach ( $wgGroupPermissions as $group => $permissions ) {
352353 $arr = array(
353354 'name' => $group,
@@ -375,16 +376,16 @@
376377 foreach ( $groupArr as $type => $rights ) {
377378 if ( isset( $rights[$group] ) ) {
378379 $arr[$type] = $rights[$group];
379 - $this->getResult()->setIndexedTagName( $arr[$type], 'group' );
 380+ $result->setIndexedTagName( $arr[$type], 'group' );
380381 }
381382 }
382383
383 - $this->getResult()->setIndexedTagName( $arr['rights'], 'permission' );
 384+ $result->setIndexedTagName( $arr['rights'], 'permission' );
384385 $data[] = $arr;
385386 }
386387
387 - $this->getResult()->setIndexedTagName( $data, 'group' );
388 - return $this->getResult()->addValue( 'query', $property, $data );
 388+ $result->setIndexedTagName( $data, 'group' );
 389+ return $result->addValue( 'query', $property, $data );
389390 }
390391
391392 protected function appendFileExtensions( $property ) {
Index: trunk/phase3/includes/api/ApiMove.php
@@ -107,15 +107,18 @@
108108 }
109109 }
110110
 111+ $result = $this->getResult();
 112+
111113 // Move subpages
112114 if ( $params['movesubpages'] ) {
113115 $r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
114116 $params['reason'], $params['noredirect'] );
115 - $this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' );
 117+ $result->setIndexedTagName( $r['subpages'], 'subpage' );
 118+
116119 if ( $params['movetalk'] ) {
117120 $r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
118121 $params['reason'], $params['noredirect'] );
119 - $this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' );
 122+ $result->setIndexedTagName( $r['subpages-talk'], 'subpage' );
120123 }
121124 }
122125
@@ -132,7 +135,7 @@
133136 $this->setWatch( $watch, $fromTitle, 'watchmoves' );
134137 $this->setWatch( $watch, $toTitle, 'watchmoves' );
135138
136 - $this->getResult()->addValue( null, $this->getModuleName(), $r );
 139+ $result->addValue( null, $this->getModuleName(), $r );
137140 }
138141
139142 /**
Index: trunk/phase3/includes/api/ApiParse.php
@@ -77,6 +77,9 @@
7878
7979 $redirValues = null;
8080
 81+ // Return result
 82+ $result = $this->getResult();
 83+
8184 if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
8285 if ( !is_null( $oldid ) ) {
8386 // Don't use the parser cache
@@ -178,19 +181,17 @@
179182 if ( $params['onlypst'] ) {
180183 // Build a result and bail out
181184 $result_array['text'] = array();
182 - $this->getResult()->setContent( $result_array['text'], $this->pstText );
 185+ $result->setContent( $result_array['text'], $this->pstText );
183186 if ( isset( $prop['wikitext'] ) ) {
184187 $result_array['wikitext'] = array();
185 - $this->getResult()->setContent( $result_array['wikitext'], $this->text );
 188+ $result->setContent( $result_array['wikitext'], $this->text );
186189 }
187 - $this->getResult()->addValue( null, $this->getModuleName(), $result_array );
 190+ $result->addValue( null, $this->getModuleName(), $result_array );
188191 return;
189192 }
190193 $p_result = $wgParser->parse( $params['pst'] ? $this->pstText : $this->text, $titleObj, $popts );
191194 }
192195
193 - // Return result
194 - $result = $this->getResult();
195196 $result_array = array();
196197
197198 $result_array['title'] = $titleObj->getPrefixedText();
Index: trunk/phase3/includes/api/ApiProtect.php
@@ -130,8 +130,9 @@
131131 $res['cascade'] = '';
132132 }
133133 $res['protections'] = $resultProtections;
134 - $this->getResult()->setIndexedTagName( $res['protections'], 'protection' );
135 - $this->getResult()->addValue( null, $this->getModuleName(), $res );
 134+ $result = $this->getResult();
 135+ $result->setIndexedTagName( $res['protections'], 'protection' );
 136+ $result->addValue( null, $this->getModuleName(), $res );
136137 }
137138
138139 public function mustBePosted() {
Index: trunk/phase3/includes/api/ApiPurge.php
@@ -72,7 +72,7 @@
7373 $article = Article::newFromTitle( $title, $context );
7474 $article->doPurge(); // Directly purge and skip the UI part of purge().
7575 $r['purged'] = '';
76 -
 76+
7777 if( $forceLinkUpdate ) {
7878 if ( !$wgUser->pingLimiter() ) {
7979 global $wgParser, $wgEnableParserCache;
@@ -94,11 +94,12 @@
9595 $forceLinkUpdate = false;
9696 }
9797 }
98 -
 98+
9999 $result[] = $r;
100100 }
101 - $this->getResult()->setIndexedTagName( $result, 'page' );
102 - $this->getResult()->addValue( null, $this->getModuleName(), $result );
 101+ $apiResult = $this->getResult();
 102+ $apiResult->setIndexedTagName( $result, 'page' );
 103+ $apiResult->addValue( null, $this->getModuleName(), $result );
103104 }
104105
105106 public function isWriteMode() {
Index: trunk/phase3/includes/api/ApiQueryBacklinks.php
@@ -231,9 +231,12 @@
232232 $this->redirect = isset( $this->params['redirect'] ) && $this->params['redirect'];
233233 $userMax = ( $this->redirect ? ApiBase::LIMIT_BIG1 / 2 : ApiBase::LIMIT_BIG1 );
234234 $botMax = ( $this->redirect ? ApiBase::LIMIT_BIG2 / 2 : ApiBase::LIMIT_BIG2 );
 235+
 236+ $result = $this->getResult();
 237+
235238 if ( $this->params['limit'] == 'max' ) {
236239 $this->params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
237 - $this->getResult()->setParsedLimit( $this->getModuleName(), $this->params['limit'] );
 240+ $result->setParsedLimit( $this->getModuleName(), $this->params['limit'] );
238241 }
239242
240243 $this->processContinue();
@@ -290,13 +293,13 @@
291294 }
292295 if ( is_null( $resultPageSet ) ) {
293296 // Try to add the result data in one go and pray that it fits
294 - $fit = $this->getResult()->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) );
 297+ $fit = $result->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) );
295298 if ( !$fit ) {
296299 // It didn't fit. Add elements one by one until the
297300 // result is full.
298301 foreach ( $this->resultArr as $pageID => $arr ) {
299302 // Add the basic entry without redirlinks first
300 - $fit = $this->getResult()->addValue(
 303+ $fit = $result->addValue(
301304 array( 'query', $this->getModuleName() ),
302305 null, array_diff_key( $arr, array( 'redirlinks' => '' ) ) );
303306 if ( !$fit ) {
@@ -307,7 +310,7 @@
308311 $hasRedirs = false;
309312 $redirLinks = isset( $arr['redirlinks'] ) ? $arr['redirlinks'] : array();
310313 foreach ( (array)$redirLinks as $key => $redir ) {
311 - $fit = $this->getResult()->addValue(
 314+ $fit = $result->addValue(
312315 array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
313316 $key, $redir );
314317 if ( !$fit ) {
@@ -317,7 +320,7 @@
318321 $hasRedirs = true;
319322 }
320323 if ( $hasRedirs ) {
321 - $this->getResult()->setIndexedTagName_internal(
 324+ $result->setIndexedTagName_internal(
322325 array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
323326 $this->bl_code );
324327 }
@@ -327,7 +330,7 @@
328331 }
329332 }
330333
331 - $this->getResult()->setIndexedTagName_internal(
 334+ $result->setIndexedTagName_internal(
332335 array( 'query', $this->getModuleName() ),
333336 $this->bl_code
334337 );
Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -352,9 +352,10 @@
353353 protected function setContinueEnumParameter( $paramName, $paramValue ) {
354354 $paramName = $this->encodeParamName( $paramName );
355355 $msg = array( $paramName => $paramValue );
356 - $this->getResult()->disableSizeCheck();
357 - $this->getResult()->addValue( 'query-continue', $this->getModuleName(), $msg );
358 - $this->getResult()->enableSizeCheck();
 356+ $result = $this->getResult();
 357+ $result->disableSizeCheck();
 358+ $result->addValue( 'query-continue', $this->getModuleName(), $msg );
 359+ $result->enableSizeCheck();
359360 }
360361
361362 /**
Index: trunk/phase3/includes/api/ApiImport.php
@@ -88,8 +88,9 @@
8989 }
9090
9191 $resultData = $reporter->getData();
92 - $this->getResult()->setIndexedTagName( $resultData, 'page' );
93 - $this->getResult()->addValue( null, $this->getModuleName(), $resultData );
 92+ $result = $this->getResult();
 93+ $result->setIndexedTagName( $resultData, 'page' );
 94+ $result->addValue( null, $this->getModuleName(), $resultData );
9495 }
9596
9697 public function mustBePosted() {
Index: trunk/phase3/includes/api/ApiQueryCategoryMembers.php
@@ -129,11 +129,11 @@
130130 'by the previous query', '_badcontinue'
131131 );
132132 }
133 -
 133+
134134 // Remove the types to skip from $queryTypes
135135 $contTypeIndex = array_search( $cont[0], $queryTypes );
136136 $queryTypes = array_slice( $queryTypes, $contTypeIndex );
137 -
 137+
138138 // Add a WHERE clause for sortkey and from
139139 // pack( "H*", $foo ) is used to convert hex back to binary
140140 $escSortkey = $this->getDB()->addQuotes( pack( "H*", $cont[1] ) );
@@ -143,7 +143,7 @@
144144 $contWhere = "cl_sortkey $op $escSortkey OR " .
145145 "(cl_sortkey = $escSortkey AND " .
146146 "cl_from $op= $from)";
147 -
 147+
148148 } else {
149149 // The below produces ORDER BY cl_sortkey, cl_from, possibly with DESC added to each of them
150150 $this->addWhereRange( 'cl_sortkey',
@@ -189,6 +189,8 @@
190190 $res = $this->select( __METHOD__ );
191191 $rows = iterator_to_array( $res );
192192 }
 193+
 194+ $result = $this->getResult();
193195 $count = 0;
194196 foreach ( $rows as $row ) {
195197 if ( ++ $count > $limit ) {
@@ -234,7 +236,7 @@
235237 if ( $fld_timestamp ) {
236238 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
237239 }
238 - $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ),
 240+ $fit = $result->addValue( array( 'query', $this->getModuleName() ),
239241 null, $vals );
240242 if ( !$fit ) {
241243 if ( $params['sort'] == 'timestamp' ) {
@@ -253,7 +255,7 @@
254256 }
255257
256258 if ( is_null( $resultPageSet ) ) {
257 - $this->getResult()->setIndexedTagName_internal(
 259+ $result->setIndexedTagName_internal(
258260 array( 'query', $this->getModuleName() ), 'cm' );
259261 }
260262 }
Index: trunk/phase3/includes/api/ApiQuerySearch.php
@@ -97,16 +97,17 @@
9898 $this->dieUsage( "{$what} search is disabled", "search-{$what}-disabled" );
9999 }
100100
 101+ $result = $this->getResult();
101102 // Add search meta data to result
102103 if ( isset( $searchInfo['totalhits'] ) ) {
103104 $totalhits = $matches->getTotalHits();
104105 if ( $totalhits !== null ) {
105 - $this->getResult()->addValue( array( 'query', 'searchinfo' ),
 106+ $result->addValue( array( 'query', 'searchinfo' ),
106107 'totalhits', $totalhits );
107108 }
108109 }
109110 if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) {
110 - $this->getResult()->addValue( array( 'query', 'searchinfo' ),
 111+ $result->addValue( array( 'query', 'searchinfo' ),
111112 'suggestion', $matches->getSuggestionQuery() );
112113 }
113114
@@ -171,7 +172,7 @@
172173 }
173174
174175 // Add item to results and see whether it fits
175 - $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ),
 176+ $fit = $result->addValue( array( 'query', $this->getModuleName() ),
176177 null, $vals );
177178 if ( !$fit ) {
178179 $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 );
@@ -185,7 +186,7 @@
186187 }
187188
188189 if ( is_null( $resultPageSet ) ) {
189 - $this->getResult()->setIndexedTagName_internal( array(
 190+ $result->setIndexedTagName_internal( array(
190191 'query', $this->getModuleName()
191192 ), 'p' );
192193 } else {
Index: trunk/phase3/includes/api/ApiMain.php
@@ -473,6 +473,7 @@
474474 * @return string
475475 */
476476 protected function substituteResultWithError( $e ) {
 477+ $result = $this->getResult();
477478 // Printer may not be initialized if the extractRequestParams() fails for the main module
478479 if ( !isset ( $this->mPrinter ) ) {
479480 // The printer has not been created yet. Try to manually get formatter value.
@@ -483,7 +484,7 @@
484485
485486 $this->mPrinter = $this->createPrinterByName( $value );
486487 if ( $this->mPrinter->getNeedsRawData() ) {
487 - $this->getResult()->setRawMode();
 488+ $result->setRawMode();
488489 }
489490 }
490491
@@ -512,16 +513,16 @@
513514 ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' );
514515 }
515516
516 - $this->getResult()->reset();
517 - $this->getResult()->disableSizeCheck();
 517+ $result->reset();
 518+ $result->disableSizeCheck();
518519 // Re-add the id
519520 $requestid = $this->getParameter( 'requestid' );
520521 if ( !is_null( $requestid ) ) {
521 - $this->getResult()->addValue( null, 'requestid', $requestid );
 522+ $result->addValue( null, 'requestid', $requestid );
522523 }
523524 // servedby is especially useful when debugging errors
524 - $this->getResult()->addValue( null, 'servedby', wfHostName() );
525 - $this->getResult()->addValue( null, 'error', $errMessage );
 525+ $result->addValue( null, 'servedby', wfHostName() );
 526+ $result->addValue( null, 'error', $errMessage );
526527
527528 return $errMessage['code'];
528529 }
@@ -532,13 +533,14 @@
533534 */
534535 protected function setupExecuteAction() {
535536 // First add the id to the top element
 537+ $result = $this->getResult();
536538 $requestid = $this->getParameter( 'requestid' );
537539 if ( !is_null( $requestid ) ) {
538 - $this->getResult()->addValue( null, 'requestid', $requestid );
 540+ $result->addValue( null, 'requestid', $requestid );
539541 }
540542 $servedby = $this->getParameter( 'servedby' );
541543 if ( $servedby ) {
542 - $this->getResult()->addValue( null, 'servedby', wfHostName() );
 544+ $result->addValue( null, 'servedby', wfHostName() );
543545 }
544546
545547 $params = $this->extractRequestParams();

Status & tagging log