Nemo bis has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/213308

Change subject: characterEditStats.php: allow using the revision table
......................................................................

characterEditStats.php: allow using the revision table

When --days > $wgRCMaxAge, the RC table doesn't suffice: alter
TranslateUtils and the messaging so that the revision table is used.

The diff size would require a join with the rev_parent so we avoid
supporting it for the meanwhile in this patch. The option is not used
by operations/puppet/files/misc/scripts/characterEditStatsTranslate.

Change-Id: I93ec9443ac6859856c016d2780855bbf8e06ef3a
---
M TranslateUtils.php
M scripts/characterEditStats.php
2 files changed, 49 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/08/213308/1

diff --git a/TranslateUtils.php b/TranslateUtils.php
index 09243a3..ba48f9f 100644
--- a/TranslateUtils.php
+++ b/TranslateUtils.php
@@ -98,7 +98,8 @@
        }
 
        /**
-        * Fetches recent changes for titles in given namespaces
+        * Fetches recent changes for titles in given namespaces.
+        * Also uses the revision table if the time period is longer than max 
age.
         *
         * @param int $hours Number of hours.
         * @param bool $bots Should bot edits be included.
@@ -107,12 +108,19 @@
         * @return array List of recent changes.
         */
        public static function translationChanges(
-               $hours = 24, $bots = false, $ns = null, $extraFields = array()
+               $hours = 24, $bots = false, $ns = null, $extraFields = array(), 
$translationSize = false
        ) {
-               global $wgTranslateMessageNamespaces;
+               global $wgTranslateMessageNamespaces, $wgRCMaxAge;
 
                $dbr = wfGetDB( DB_SLAVE );
-               $recentchanges = $dbr->tableName( 'recentchanges' );
+               if ( $hours * 3600 <= $wgRCMaxAge ) {
+                       $recentchanges = $dbr->tableName( 'recentchanges' );
+                       $t = rc;
+               } else {
+                       $recentchanges = $dbr->tableName( 'revision' );
+                       $t = rev;
+               }
+               
                $hours = intval( $hours );
                $cutoff_unixtime = time() - ( $hours * 3600 );
                $cutoff = $dbr->timestamp( $cutoff_unixtime );
@@ -122,17 +130,25 @@
                        $namespaces = $dbr->makeList( $ns );
                }
 
+               if ( $translationSize ) {
+                       if ( $t === 'rc' ) {
+                               $extraFields[] = 'rc_new_len AS 
translationSize';
+                       } else {
+                               $extraFields[] = 'rev_len AS translationSize';
+                       }
+               }
+
                $fields = array_merge(
-                       array( 'rc_title', 'rc_timestamp', 'rc_user_text', 
'rc_namespace' ),
+                       array( $t . '_title', $t . '_timestamp', $t . 
'_user_text', $t . '_namespace' ),
                        $extraFields
                );
                $fields = implode( ',', $fields );
                // @todo Raw SQL
                $sql = "SELECT $fields, substring_index(rc_title, '/', -1) as 
lang FROM $recentchanges " .
-                       "WHERE rc_timestamp >= '{$cutoff}' " .
-                       ( $bots ? '' : 'AND rc_bot = 0 ' ) .
-                       "AND rc_namespace in ($namespaces) " .
-                       "ORDER BY lang ASC, rc_timestamp DESC";
+                       "WHERE ' . $t . '_timestamp >= '{$cutoff}' " .
+                       ( $bots && $t === 'rc' ? '' : 'AND ' . $t . '_bot = 0 ' 
) .
+                       "AND ' . $t . '_namespace in ($namespaces) " .
+                       "ORDER BY lang ASC, ' . $t . '_timestamp DESC";
 
                $res = $dbr->query( $sql, __METHOD__ );
                $rows = iterator_to_array( $res );
diff --git a/scripts/characterEditStats.php b/scripts/characterEditStats.php
index 782d008..ee33909 100644
--- a/scripts/characterEditStats.php
+++ b/scripts/characterEditStats.php
@@ -74,19 +74,37 @@
 
                // Select set of edits to report on
 
-               // Fetch some extrac fields that normally 
TranslateUtils::translationChanges wont
-               $extraFields = array( 'rc_old_len', 'rc_new_len' );
-               $rows = TranslateUtils::translationChanges( $hours, $bots, 
$namespaces, $extraFields );
+               global $wgRCMaxAge;
+               if ( $this->hasOption( 'diff' ) ) {
+                       if ( $days * 3600 * 24 > $wgRCMaxAge ) {
+                               $this->output( 'NOTE: The selected timestamp is 
higher than $wgRCMaxAge: '
+                                       . "to calculate the diff size, only the 
last $wgRCMaxAge seconds will "
+                                       . 'be considered.'
+                               )
+                               $days = $wgRCMaxAge / 24 / 3600;
+                       }
+                       
+                       // Fetch some extra fields that normally 
TranslateUtils::translationChanges won't
+                       $extraFields = array( 'rc_old_len', 'rc_new_len' );
+               }
+               if ( $days * 3600 * 24 > $wgRCMaxAge ) {
+                       $t = 'rev';
+               } else {
+                       $t = 'rc';
+               }
+
+               $rows = TranslateUtils::translationChanges( $hours, $bots, 
$namespaces,
+                       $extraFields, $translationSize = true );
                // Get counts for edits per language code after filtering out 
edits by FuzzyBot
                $codes = array();
 
                foreach ( $rows as $_ ) {
                        // Filter out edits by $wgTranslateFuzzyBotName
-                       if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) {
+                       if ( $_->{$t}_user_text === $wgTranslateFuzzyBotName ) {
                                continue;
                        }
 
-                       $handle = new MessageHandle( Title::newFromText( 
$_->rc_title ) );
+                       $handle = new MessageHandle( Title::newFromText( 
$_->{$t}_title ) );
                        $code = $handle->getCode();
 
                        if ( !isset( $codes[$code] ) ) {
@@ -96,7 +114,7 @@
                        if ( $this->hasOption( 'diff' ) ) {
                                $diff = abs( $_->rc_new_len - $_->rc_old_len );
                        } else {
-                               $diff = $_->rc_new_len;
+                               $diff = $_->translationSize;
                        }
                        $codes[$code] += $diff;
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/213308
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I93ec9443ac6859856c016d2780855bbf8e06ef3a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nemo bis <federicol...@tiscali.it>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to