Nemo bis has uploaded a new change for review.

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

Change subject: [WIP] Add custom query to characterEditStats.php when 
$wgRCMaxAge is too low
......................................................................

[WIP] Add custom query to characterEditStats.php when $wgRCMaxAge is too low

As suggested about I93ec9443ac6859856c016d2780855bbf8e06ef3a

Bug: T64833
Change-Id: Ib830b6b888eb4fc048c4a3a74c30e82096a372c2
---
M scripts/characterEditStats.php
1 file changed, 38 insertions(+), 4 deletions(-)


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

diff --git a/scripts/characterEditStats.php b/scripts/characterEditStats.php
index 418fe4d..e41e213 100644
--- a/scripts/characterEditStats.php
+++ b/scripts/characterEditStats.php
@@ -52,7 +52,7 @@
        }
 
        public function execute() {
-               global $wgTranslateFuzzyBotName, $wgSitename;
+               global $wgTranslateFuzzyBotName, $wgSitename, $wgRCMaxAge;
 
                $days = (int)$this->getOption( 'days', 30 );
                $hours = $days * 24;
@@ -74,9 +74,43 @@
 
                // 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 );
+               if ( $hours * 3600 <= $wgRCMaxAge ) {
+                       // Fetch some extract fields that normally 
TranslateUtils::translationChanges won't
+                       $extraFields = array( 'rc_old_len', 'rc_new_len' );
+                       $rows = TranslateUtils::translationChanges( $hours, 
$bots, $namespaces, $extraFields );
+               } else {
+                       // Fetch some extract fields that normally 
TranslateUtils::translationChanges won't
+                       $extraFields = array( 'rev_len AS rc_new_len', 
'rc_new_len' );
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $recentchanges = $dbr->tableName( 'revision' );
+                       $hours = (int)$hours;
+                       $cutoff_unixtime = time() - ( $hours * 3600 );
+                       $cutoff = $dbr->timestamp( $cutoff_unixtime );
+
+                       $namespaces = $dbr->makeList( 
$wgTranslateMessageNamespaces );
+                       if ( $ns ) {
+                               $namespaces = $dbr->makeList( $ns );
+                       }
+
+                       $fields = array_merge(
+                               array( 'page_title AS rc_title', 'rev_timestamp 
AS rc_timestamp', 'rev_user_text AS rc_user_text', 'rev_namespace AS 
rc_namespace' ),
+                               $extraFields
+                       );
+                       $fields = implode( ',', $fields );
+                       // @todo Raw SQL
+                       $sql = "SELECT $fields, substring_index(page_title, 
'/', -1) as lang FROM $recentchanges " .
+                               "JOIN page ON rev_page = page_id" .
+                               "AND rev_namespace in ($namespaces) " .
+                               "AND rev_parent_id = 0" .
+                               "HAVING rc_timestamp >= '{$cutoff}' " .
+                               ( $bots ? '' : 'AND rc_bot = 0 ' ) .
+                               "AND rc_namespace in ($namespaces) " .
+                               'ORDER BY lang ASC, rc_timestamp DESC';
+
+                       $res = $dbr->query( $sql, __METHOD__ );
+                       $rows = iterator_to_array( $res );
+               }
+
                // Get counts for edits per language code after filtering out 
edits by FuzzyBot
                $codes = array();
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib830b6b888eb4fc048c4a3a74c30e82096a372c2
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