(bug 37301) add sizediff to list=usercontribs
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 16 Jun 2012 07:47:11 +0000 (09:47 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Sat, 16 Jun 2012 07:47:11 +0000 (09:47 +0200)
Moving function getParentLength from SpecialContributions to Revision
and use it in the list module. The size of the parent is selected by a
batch, like the special page.

Change-Id: I6e388e75cd765f2a918b0c192477d87347e96bcd

includes/Revision.php
includes/api/ApiQueryUserContributions.php
includes/specials/SpecialContributions.php

index 6b8aabc..14bd587 100644 (file)
@@ -395,6 +395,29 @@ class Revision {
                return array( 'user_name' );
        }
 
+       /**
+        * Do a batched query to get the parent revision lengths
+        * @param $db DatabaseBase
+        * @param $revIds Array
+        * @return array
+        */
+       public static function getParentLengths( $db, array $revIds ) {
+               $revLens = array();
+               if ( !$revIds ) {
+                       return $revLens; // empty
+               }
+               wfProfileIn( __METHOD__ );
+               $res = $db->select( 'revision',
+                       array( 'rev_id', 'rev_len' ),
+                       array( 'rev_id' => $revIds ),
+                       __METHOD__ );
+               foreach ( $res as $row ) {
+                       $revLens[$row->rev_id] = $row->rev_len;
+               }
+               wfProfileOut( __METHOD__ );
+               return $revLens;
+       }
+
        /**
         * Constructor
         *
index 097d3e1..45a6da4 100644 (file)
@@ -35,10 +35,10 @@ class ApiQueryContributions extends ApiQueryBase {
                parent::__construct( $query, $moduleName, 'uc' );
        }
 
-       private $params, $prefixMode, $userprefix, $multiUserMode, $usernames;
+       private $params, $prefixMode, $userprefix, $multiUserMode, $usernames, $parentLens;
        private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
                        $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
-                       $fld_patrolled = false, $fld_tags = false, $fld_size = false;
+                       $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
 
        public function execute() {
                // Parse some parameters
@@ -50,6 +50,7 @@ class ApiQueryContributions extends ApiQueryBase {
                $this->fld_comment = isset( $prop['comment'] );
                $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
                $this->fld_size = isset( $prop['size'] );
+               $this->fld_sizediff = isset( $prop['sizediff'] );
                $this->fld_flags = isset( $prop['flags'] );
                $this->fld_timestamp = isset( $prop['timestamp'] );
                $this->fld_patrolled = isset( $prop['patrolled'] );
@@ -82,6 +83,17 @@ class ApiQueryContributions extends ApiQueryBase {
                // Do the actual query.
                $res = $this->select( __METHOD__ );
 
+               if( $this->fld_sizediff ) {
+                       $revIds = array();
+                       foreach ( $res as $row ) {
+                               if( $row->rev_parent_id ) {
+                                       $revIds[] = $row->rev_parent_id;
+                               }
+                       }
+                       $this->parentLens = Revision::getParentLengths( $this->getDB(), $revIds );
+                       $res->rewind(); // reset
+               }
+
                // Initialise some variables
                $count = 0;
                $limit = $this->params['limit'];
@@ -245,7 +257,8 @@ class ApiQueryContributions extends ApiQueryBase {
                // $this->addFieldsIf( 'rev_text_id', $this->fld_ids ); // Should this field be exposed?
                $this->addFieldsIf( 'rev_comment', $this->fld_comment || $this->fld_parsedcomment );
                $this->addFieldsIf( 'rev_len', $this->fld_size );
-               $this->addFieldsIf( array( 'rev_minor_edit', 'rev_parent_id' ), $this->fld_flags );
+               $this->addFieldsIf( 'rev_minor_edit', $this->fld_flags );
+               $this->addFieldsIf( 'rev_parent_id', $this->fld_flags || $this->fld_sizediff );
                $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
 
                if ( $this->fld_tags ) {
@@ -333,6 +346,11 @@ class ApiQueryContributions extends ApiQueryBase {
                        $vals['size'] = intval( $row->rev_len );
                }
 
+               if ( $this->fld_sizediff && !is_null( $row->rev_len ) && !is_null( $row->rev_parent_id ) ) {
+                       $parentLen = isset( $this->parentLens[$row->rev_parent_id] ) ? $this->parentLens[$row->rev_parent_id] : 0;
+                       $vals['sizediff'] = intval( $row->rev_len - $parentLen );
+               }
+
                if ( $this->fld_tags ) {
                        if ( $row->ts_tags ) {
                                $tags = explode( ',', $row->ts_tags );
@@ -398,6 +416,7 @@ class ApiQueryContributions extends ApiQueryBase {
                                        'comment',
                                        'parsedcomment',
                                        'size',
+                                       'sizediff',
                                        'flags',
                                        'patrolled',
                                        'tags'
@@ -436,7 +455,8 @@ class ApiQueryContributions extends ApiQueryBase {
                                ' timestamp      - Adds the timestamp of the edit',
                                ' comment        - Adds the comment of the edit',
                                ' parsedcomment  - Adds the parsed comment of the edit',
-                               ' size           - Adds the size of the page',
+                               ' size           - Adds the new size of the edit',
+                               ' sizediff       - Adds the size delta of the edit against its parent',
                                ' flags          - Adds flags of the edit',
                                ' patrolled      - Tags patrolled edits',
                                ' tags           - Lists tags for the edit',
index 62b34ad..ac8555e 100644 (file)
@@ -706,7 +706,7 @@ class ContribsPager extends ReverseChronologicalPager {
                                $revIds[] = $row->rev_parent_id;
                        }
                }
-               $this->mParentLens = $this->getParentLengths( $revIds );
+               $this->mParentLens = Revision::getParentLengths( $this->getDatabase(), $revIds );
                $this->mResult->rewind(); // reset
 
                # Do a link batch query
@@ -724,28 +724,6 @@ class ContribsPager extends ReverseChronologicalPager {
                $this->mResult->seek( 0 );
        }
 
-       /**
-        * Do a batched query to get the parent revision lengths
-        * @param $revIds array
-        * @return array
-        */
-       private function getParentLengths( array $revIds ) {
-               $revLens = array();
-               if ( !$revIds ) {
-                       return $revLens; // empty
-               }
-               wfProfileIn( __METHOD__ );
-               $res = $this->getDatabase()->select( 'revision',
-                       array( 'rev_id', 'rev_len' ),
-                       array( 'rev_id' => $revIds ),
-                       __METHOD__ );
-               foreach ( $res as $row ) {
-                       $revLens[$row->rev_id] = $row->rev_len;
-               }
-               wfProfileOut( __METHOD__ );
-               return $revLens;
-       }
-
        /**
         * @return string
         */