Simplify factory methods of RecentChange.
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 29 Jun 2012 09:51:55 +0000 (11:51 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 6 Jul 2012 06:29:10 +0000 (06:29 +0000)
* Make RecentChange::newFromId() use RecentChange::newFromConds()
* We have DatabaseBase::selectRow() for the purpose of selecting
  a single row.

Change-Id: Ie818205437ecea6a4860b74f49b2940c91132a66

includes/RecentChange.php

index cd8a1b5..3327826 100644 (file)
@@ -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;