r92538 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92537‎ | r92538 | r92539 >
Date:15:52, 19 July 2011
Author:robin
Status:ok (Comments)
Tags:todo 
Comment:
Follow-up r92528:
* remove @static
* return database result directly (no need for while())
* getAllPrefixesDb() -> getAllPrefixesDB()
Modified paths:
  • /trunk/phase3/includes/interwiki/Interwiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/interwiki/Interwiki.php
@@ -204,7 +204,6 @@
205205 * @param $local If set, limits output to local/non-local interwikis
206206 * @return Array List of prefixes
207207 * @since 1.19
208 - * @static
209208 */
210209 protected static function getAllPrefixesCached( $local ) {
211210 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
@@ -269,34 +268,24 @@
270269 * @param $local If set, limits output to local/non-local interwikis
271270 * @return Array List of prefixes
272271 * @since 1.19
273 - * @static
274272 */
275 - protected static function getAllPrefixesDb( $local ) {
 273+ protected static function getAllPrefixesDB( $local ) {
276274 $db = wfGetDB( DB_SLAVE );
277275
278276 $where = array();
279277
280 - if ( isset($local) ) {
 278+ if ( isset( $local ) ) {
281279 if ( $local == 1 ) {
282280 $where['iw_local'] = 1;
283 - }
284 - elseif ( $local == 0 ) {
 281+ } elseif ( $local == 0 ) {
285282 $where['iw_local'] = 0;
286283 }
287284 }
288285
289 - $res = $db->select( 'interwiki',
 286+ return $db->select( 'interwiki',
290287 array( 'iw_prefix', 'iw_url', 'iw_api', 'iw_wikiid', 'iw_local', 'iw_trans' ),
291288 $where, __METHOD__, array( 'ORDER BY' => 'iw_prefix' )
292289 );
293 -
294 - $data = array();
295 - while( $row = $db->fetchRow($res) ) {
296 - $data[] = $row;
297 - }
298 - $db->freeResult( $res );
299 -
300 - return $data;
301290 }
302291
303292 /**
@@ -305,7 +294,6 @@
306295 * @param $local If set, limits output to local/non-local interwikis
307296 * @return Array List of prefixes
308297 * @since 1.19
309 - * @static
310298 */
311299 public static function getAllPrefixes( $local ) {
312300 global $wgInterwikiCache;
@@ -313,7 +301,7 @@
314302 if ( $wgInterwikiCache ) {
315303 return self::getAllPrefixesCached( $local );
316304 } else {
317 - return self::getAllPrefixesDb( $local );
 305+ return self::getAllPrefixesDB( $local );
318306 }
319307 }
320308

Follow-up revisions

RevisionCommit summaryAuthorDate
r92813Fixes for r92538 & r92528:...robin22:19, 21 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92528(bug 19838) API does not use interwiki cache....robin12:30, 19 July 2011

Comments

#Comment by Catrope (talk | contribs)   18:48, 20 July 2011
 	 * @return Array List of prefixes

This is now technically incorrect, you're returning either an array or a ResultWrapper. Use return iterator_to_array( $db->select( .... ) ); to return an array.

#Comment by SPQRobin (talk | contribs)   19:48, 20 July 2011

Then I get Fatal error: Cannot use object of type stdClass as array. It seems the best way is to revert this to the while loop.

#Comment by Catrope (talk | contribs)   21:11, 21 July 2011

Oh, bah, that's right, it'll still return objects. Yeah you can either go back to the while loop, or use something like foreach ( $res as $row ) { $retval[] = (array)$row; } return $retval;

#Comment by SPQRobin (talk | contribs)   22:21, 21 July 2011

Used foreach in r92813

Status & tagging log