From b9f62f92377aa16d6a69b258217473c6afbad3df Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 29 Jun 2012 11:51:55 +0200 Subject: [PATCH] Simplify factory methods of RecentChange. * Make RecentChange::newFromId() use RecentChange::newFromConds() * We have DatabaseBase::selectRow() for the purpose of selecting a single row. Change-Id: Ie818205437ecea6a4860b74f49b2940c91132a66 --- includes/RecentChange.php | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/includes/RecentChange.php b/includes/RecentChange.php index cd8a1b5ba8..3327826739 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -19,7 +19,7 @@ * * @file */ - + /** * Utility class for creating new RC entries * @@ -108,13 +108,7 @@ class RecentChange { * @return RecentChange */ public static function newFromId( $rcid ) { - $dbr = wfGetDB( DB_SLAVE ); - $row = $dbr->selectRow( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ ); - if( $row !== false ) { - return self::newFromRow( $row ); - } else { - return null; - } + return self::newFromConds( array( 'rc_id' => $rcid ), __METHOD__ ); } /** @@ -126,18 +120,12 @@ class RecentChange { */ public static function newFromConds( $conds, $fname = __METHOD__ ) { $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( - 'recentchanges', - '*', - $conds, - $fname - ); - if( $res instanceof ResultWrapper && $res->numRows() > 0 ) { - $row = $res->fetchObject(); - $res->free(); + $row = $dbr->selectRow( 'recentchanges', '*', $conds, $fname ); + if ( $row !== false ) { return self::newFromRow( $row ); + } else { + return null; } - return null; } # Accessors @@ -781,7 +769,7 @@ class RecentChange { } } else { $ip = $wgRequest->getIP(); - if( !$ip ) + if( !$ip ) $ip = ''; } return $ip; -- 2.20.1