r79266 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79265‎ | r79266 | r79267 >
Date:17:06, 30 December 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Styleli[zs]e the API up to date (Been a while since)
Modified paths:
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFeedWatchlist.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllmessages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllpages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryPageProps.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRsd.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryRecentChanges.php
@@ -84,7 +84,7 @@
8585 if ( is_null( $cachedPatrolToken ) ) {
8686 $cachedPatrolToken = $wgUser->editToken( 'patrol' );
8787 }
88 -
 88+
8989 return $cachedPatrolToken;
9090 }
9191
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -324,44 +324,44 @@
325325
326326 protected function appendUserGroups( $property, $numberInGroup ) {
327327 global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
328 -
 328+
329329 $data = array();
330330 foreach ( $wgGroupPermissions as $group => $permissions ) {
331331 $arr = array(
332332 'name' => $group,
333333 'rights' => array_keys( $permissions, true ),
334334 );
335 -
 335+
336336 if ( $numberInGroup ) {
337337 global $wgAutopromote;
338 -
 338+
339339 if ( $group == 'user' ) {
340340 $arr['number'] = SiteStats::users();
341 -
 341+
342342 // '*' and autopromote groups have no size
343343 } elseif ( $group !== '*' && !isset( $wgAutopromote[$group] ) ) {
344344 $arr['number'] = SiteStats::numberInGroup( $group );
345345 }
346346 }
347 -
 347+
348348 $groupArr = array(
349349 'add' => $wgAddGroups,
350350 'remove' => $wgRemoveGroups,
351351 'add-self' => $wgGroupsAddToSelf,
352352 'remove-self' => $wgGroupsRemoveFromSelf
353353 );
354 -
355 - foreach( $groupArr as $type => $rights ) {
356 - if( isset( $rights[$group] ) ) {
 354+
 355+ foreach ( $groupArr as $type => $rights ) {
 356+ if ( isset( $rights[$group] ) ) {
357357 $arr[$type] = $rights[$group];
358358 $this->getResult()->setIndexedTagName( $arr[$type], 'group' );
359359 }
360360 }
361 -
 361+
362362 $this->getResult()->setIndexedTagName( $arr['rights'], 'permission' );
363363 $data[] = $arr;
364364 }
365 -
 365+
366366 $this->getResult()->setIndexedTagName( $data, 'group' );
367367 return $this->getResult()->addValue( 'query', $property, $data );
368368 }
Index: trunk/phase3/includes/api/ApiParse.php
@@ -93,7 +93,7 @@
9494
9595 $wgTitle = $titleObj;
9696
97 - //If for some reason the "oldid" is actually the current revision, it may be cached
 97+ // If for some reason the "oldid" is actually the current revision, it may be cached
9898 if ( $titleObj->getLatestRevID() === $oldid ) {
9999 $p_result = false;
100100 $pcache = ParserCache::singleton();
Index: trunk/phase3/includes/api/ApiQueryAllpages.php
@@ -75,7 +75,7 @@
7676 $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
7777 $to = ( is_null( $params['to'] ) ? null : $this->titlePartToKey( $params['to'] ) );
7878 $this->addWhereRange( 'page_title', $dir, $from, $to );
79 -
 79+
8080 if ( isset( $params['prefix'] ) ) {
8181 $this->addWhere( 'page_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
8282 }
Index: trunk/phase3/includes/api/ApiQueryPageProps.php
@@ -44,54 +44,54 @@
4545
4646 public function execute() {
4747 $this->params = $this->extractRequestParams();
48 -
 48+
4949 # Only operate on existing pages
5050 $pages = $this->getPageSet()->getGoodTitles();
5151 if ( !count( $pages ) ) {
5252 # Nothing to do
5353 return;
5454 }
55 -
 55+
5656 $this->addTables( 'page_props' );
5757 $this->addFields( array( 'pp_page', 'pp_propname', 'pp_value' ) );
5858 $this->addWhereFld( 'pp_page', array_keys( $pages ) );
59 -
 59+
6060 if ( $this->params['continue'] ) {
6161 $this->addWhere( 'pp_page >=' . intval( $this->params['continue'] ) );
6262 }
63 -
 63+
6464 # Force a sort order to ensure that properties are grouped by page
6565 $this->addOption( 'ORDER BY', 'pp_page' );
66 -
 66+
6767 $res = $this->select( __METHOD__ );
6868 $currentPage = 0; # Id of the page currently processed
6969 $props = array();
7070 $result = $this->getResult();
71 -
 71+
7272 foreach ( $res as $row ) {
7373 if ( $currentPage != $row->pp_page ) {
74 - # Different page than previous row, so add the properties to
 74+ # Different page than previous row, so add the properties to
7575 # the result and save the new page id
76 -
 76+
7777 if ( $currentPage ) {
7878 if ( !$this->addPageProps( $result, $currentPage, $props ) ) {
7979 # addPageProps() indicated that the result did not fit
8080 # so stop adding data. Reset props so that it doesn't
8181 # get added again after loop exit
82 -
 82+
8383 $props = array();
8484 break;
8585 }
86 -
 86+
8787 $props = array();
8888 }
89 -
 89+
9090 $currentPage = $row->pp_page;
9191 }
92 -
 92+
9393 $props[$row->pp_propname] = $row->pp_value;
9494 }
95 -
 95+
9696 if ( count( $props ) ) {
9797 # Add any remaining properties to the results
9898 $this->addPageProps( $result, $currentPage, $props );
@@ -99,7 +99,7 @@
100100 }
101101
102102 /**
103 - * Add page properties to an ApiResult, adding a continue
 103+ * Add page properties to an ApiResult, adding a continue
104104 * parameter if it doesn't fit.
105105 *
106106 * @param $result ApiResult
@@ -109,7 +109,7 @@
110110 */
111111 private function addPageProps( $result, $page, $props ) {
112112 $fit = $result->addValue( array( 'query', 'pages' ), $page, $props );
113 -
 113+
114114 if ( !$fit ) {
115115 $this->setContinueEnumParameter( 'continue', $page );
116116 }
@@ -120,7 +120,7 @@
121121 return 'public';
122122 }
123123
124 - public function getAllowedParams() {
 124+ public function getAllowedParams() {
125125 return array( 'continue' => null );
126126 }
127127
Index: trunk/phase3/includes/api/ApiQueryBacklinks.php
@@ -248,9 +248,9 @@
249249 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
250250 // We need to keep the parent page of this redir in
251251 if ( $this->hasNS ) {
252 - $parentID = $this->pageMap[$row->{$this->bl_ns}][$row->{$this->bl_title}];
 252+ $parentID = $this->pageMap[$row-> { $this->bl_ns } ][$row-> { $this->bl_title } ];
253253 } else {
254 - $parentID = $this->pageMap[NS_IMAGE][$row->{$this->bl_title}];
 254+ $parentID = $this->pageMap[NS_IMAGE][$row-> { $this->bl_title } ];
255255 }
256256 $this->continueStr = $this->getContinueRedirStr( $parentID, $row->page_id );
257257 break;
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -57,32 +57,32 @@
5858 if ( !$titleObj || $titleObj->isExternal() ) {
5959 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
6060 }
61 -
62 - if( $params['redirect'] ) {
63 - if( $titleObj->isRedirect() ) {
 61+
 62+ if ( $params['redirect'] ) {
 63+ if ( $titleObj->isRedirect() ) {
6464 $oldTitle = $titleObj;
65 -
 65+
6666 $titles = Title::newFromRedirectArray( Revision::newFromTitle( $oldTitle )->getText( Revision::FOR_THIS_USER ) );
67 - //array_shift( $titles );
68 -
 67+ // array_shift( $titles );
 68+
6969 $this->getResult()->addValue( null, 'foo', $titles );
70 -
71 -
 70+
 71+
7272 $redirValues = array();
7373 foreach ( $titles as $id => $newTitle ) {
74 -
75 - if( !isset( $titles[ $id - 1 ] ) ) {
 74+
 75+ if ( !isset( $titles[ $id - 1 ] ) ) {
7676 $titles[ $id - 1 ] = $oldTitle;
7777 }
78 -
 78+
7979 $redirValues[] = array(
8080 'from' => $titles[ $id - 1 ]->getPrefixedText(),
8181 'to' => $newTitle->getPrefixedText()
8282 );
83 -
 83+
8484 $titleObj = $newTitle;
8585 }
86 -
 86+
8787 $this->getResult()->setIndexedTagName( $redirValues, 'r' );
8888 $this->getResult()->addValue( null, 'redirects', $redirValues );
8989
Index: trunk/phase3/includes/api/ApiQueryAllmessages.php
@@ -83,8 +83,8 @@
8484 if ( $skip && $message === $params['from'] ) {
8585 $skip = false;
8686 }
87 -
88 - if( $useto && $message > $params['to'] ) {
 87+
 88+ if ( $useto && $message > $params['to'] ) {
8989 break;
9090 }
9191
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -285,7 +285,7 @@
286286 if ( $this->fld_userid ) {
287287 $vals['userid'] = $row->user_id;
288288 }
289 -
 289+
290290 if ( !$row->log_user ) {
291291 $vals['anon'] = '';
292292 }
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -45,7 +45,7 @@
4646 private $mPropModuleNames, $mListModuleNames, $mMetaModuleNames;
4747
4848 /**
49 - * @var ApiPageSet
 49+ * @var ApiPageSet
5050 */
5151 private $mPageSet;
5252
@@ -471,7 +471,7 @@
472472 private function doExport( $pageSet, $result ) {
473473 $exportTitles = array();
474474 $titles = $pageSet->getGoodTitles();
475 - if( count( $titles ) ) {
 475+ if ( count( $titles ) ) {
476476 foreach ( $titles as $title ) {
477477 if ( $title->userCanRead() ) {
478478 $exportTitles[] = $title;
Index: trunk/phase3/includes/api/ApiRsd.php
@@ -169,7 +169,7 @@
170170 parent::__construct( $main, $format );
171171 $this->setRootElement( 'rsd' );
172172 }
173 -
 173+
174174 public function getMimeType() {
175175 return 'application/rsd+xml';
176176 }
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php
@@ -236,7 +236,7 @@
237237 }
238238
239239 if ( $this->fld_userid ) {
240 - $vals['user'] = $row->rc_user;
 240+ $vals['user'] = $row->rc_user;
241241 }
242242
243243 if ( !$row->rc_user ) {
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -169,7 +169,7 @@
170170 $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
171171 }
172172
173 -
 173+
174174 if ( !is_null( $this->token ) || $pageCount > 0 ) {
175175 $this->addFields( Revision::selectPageFields() );
176176 }
@@ -224,7 +224,7 @@
225225 }
226226 }
227227
228 - //Bug 24166 - API error when using rvprop=tags
 228+ // Bug 24166 - API error when using rvprop=tags
229229 $this->addTables( 'revision' );
230230
231231
@@ -480,10 +480,10 @@
481481 }
482482 if ( $this->parseContent ) {
483483 global $wgEnableParserCache;
484 -
 484+
485485 $popts = new ParserOptions();
486486 $popts->setTidy( true );
487 -
 487+
488488 $articleObj = new Article( $title );
489489
490490 $p_result = false;
@@ -498,7 +498,7 @@
499499 $pcache->save( $p_result, $articleObj, $popts );
500500 }
501501 }
502 -
 502+
503503 $text = $p_result->getText();
504504 }
505505 ApiResult::setContent( $vals, $text );
Index: trunk/phase3/includes/api/ApiBase.php
@@ -373,7 +373,7 @@
374374 $isArray = is_array( $paramSettings[self::PARAM_TYPE] );
375375
376376 if ( !$isArray
377 - || $isArray && count( $paramSettings[self::PARAM_TYPE] ) > self::LIMIT_SML1) {
 377+ || $isArray && count( $paramSettings[self::PARAM_TYPE] ) > self::LIMIT_SML1 ) {
378378 $desc .= $paramPrefix . "Maximum number of values " .
379379 self::LIMIT_SML1 . " (" . self::LIMIT_SML2 . " for bots)";
380380 }
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -86,25 +86,25 @@
8787
8888 // Prepare the API result
8989 $result = array();
90 -
 90+
9191 $warnings = $this->getApiWarnings();
92 - if ( $warnings ) {
 92+ if ( $warnings ) {
9393 $result['result'] = 'Warning';
9494 $result['warnings'] = $warnings;
9595 // in case the warnings can be fixed with some further user action, let's stash this upload
9696 // and return a key they can use to restart it
97 - try {
 97+ try {
9898 $result['sessionkey'] = $this->performStash();
99 - } catch ( MWException $e ) {
 99+ } catch ( MWException $e ) {
100100 $result['warnings']['stashfailed'] = $e->getMessage();
101101 }
102 - } elseif ( $this->mParams['stash'] ) {
 102+ } elseif ( $this->mParams['stash'] ) {
103103 // Some uploads can request they be stashed, so as not to publish them immediately.
104104 // In this case, a failure to stash ought to be fatal
105105 try {
106 - $result['result'] = 'Success';
 106+ $result['result'] = 'Success';
107107 $result['sessionkey'] = $this->performStash();
108 - } catch ( MWException $e ) {
 108+ } catch ( MWException $e ) {
109109 $this->dieUsage( $e->getMessage(), 'stashfailed' );
110110 }
111111 } else {
@@ -113,12 +113,12 @@
114114 $result = $this->performUpload();
115115 }
116116
117 - if ( $result['result'] === 'Success' ) {
 117+ if ( $result['result'] === 'Success' ) {
118118 $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() );
119119 }
120120
121121 $this->getResult()->addValue( null, $this->getModuleName(), $result );
122 -
 122+
123123 // Cleanup any temporary mess
124124 $this->mUpload->cleanupTempFile();
125125 }
@@ -133,7 +133,7 @@
134134 try {
135135 $sessionKey = $this->mUpload->stashSessionFile()->getSessionKey();
136136 } catch ( MWException $e ) {
137 - throw new MWException( 'Stashing temporary file failed: ' . get_class($e) . ' ' . $e->getMessage() );
 137+ throw new MWException( 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage() );
138138 }
139139 return $sessionKey;
140140 }
@@ -141,9 +141,9 @@
142142
143143 /**
144144 * Select an upload module and set it to mUpload. Dies on failure. If the
145 - * request was a status request and not a true upload, returns false;
 145+ * request was a status request and not a true upload, returns false;
146146 * otherwise true
147 - *
 147+ *
148148 * @return bool
149149 */
150150 protected function selectUploadModule() {
@@ -158,7 +158,7 @@
159159 // Status request for an async upload
160160 $sessionData = UploadFromUrlJob::getSessionData( $this->mParams['statuskey'] );
161161 if ( !isset( $sessionData['result'] ) ) {
162 - $this->dieUsage( 'No result in session data', 'missingresult');
 162+ $this->dieUsage( 'No result in session data', 'missingresult' );
163163 }
164164 if ( $sessionData['result'] == 'Warning' ) {
165165 $sessionData['warnings'] = $this->transformWarnings( $sessionData['warnings'] );
@@ -166,16 +166,16 @@
167167 }
168168 $this->getResult()->addValue( null, $this->getModuleName(), $sessionData );
169169 return false;
170 -
171 - }
172170
 171+ }
173172
 173+
174174 // The following modules all require the filename parameter to be set
175175 if ( is_null( $this->mParams['filename'] ) ) {
176176 $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
177177 }
178 -
179178
 179+
180180 if ( $this->mParams['sessionkey'] ) {
181181 // Upload stashed in a previous request
182182 $sessionData = $request->getSessionData( UploadBase::getSessionKeyName() );
@@ -207,7 +207,7 @@
208208 $this->dieUsage( 'Using leavemessage without ignorewarnings is not supported',
209209 'missing-ignorewarnings' );
210210 }
211 -
 211+
212212 if ( $this->mParams['leavemessage'] ) {
213213 $async = 'async-leavemessage';
214214 } else {
@@ -219,7 +219,7 @@
220220 $this->mParams['url'], $async );
221221
222222 }
223 -
 223+
224224 return true;
225225 }
226226
Index: trunk/phase3/includes/api/ApiFeedWatchlist.php
@@ -189,7 +189,7 @@
190190 'allrev' => 'Include multiple revisions of the same page within given timeframe',
191191 'wlowner' => "The user whose watchlist you want (must be accompanied by {$this->getModulePrefix()}token if it's not you)",
192192 'wltoken' => 'Security token that requested user set in their preferences',
193 - 'linktodiffs'=> 'Link to change differences instead of article pages'
 193+ 'linktodiffs' => 'Link to change differences instead of article pages'
194194 );
195195 }
196196

Comments

#Comment by Bryan (talk | contribs)   12:58, 10 March 2011
-						$parentID = $this->pageMap[$row->{$this->bl_ns}][$row->{$this->bl_title}];
+						$parentID = $this->pageMap[$row-> { $this->bl_ns } ][$row-> { $this->bl_title } ];
#Comment by Reedy (talk | contribs)   13:09, 10 March 2011

Hmm. Minor bug in stylize. Might be worth poking

Status & tagging log