jenkins-bot has submitted this change and it was merged.

Change subject: Show stats for all languages
......................................................................


Show stats for all languages

Change-Id: I7f6e86cd6b17e6bd6f53abca4973a44e23b53cb6
---
M MainPage.i18n.php
M UserStats.php
M specials/SpecialTwnMainPage.php
3 files changed, 46 insertions(+), 15 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/MainPage.i18n.php b/MainPage.i18n.php
index 66bf048..66cdcea 100644
--- a/MainPage.i18n.php
+++ b/MainPage.i18n.php
@@ -40,7 +40,8 @@
        'twnmp-your-view-language-stats' => 'View language statistics',
        'twnmp-translations-per-month' => 'Translations/month',
        'twnmp-reviews-per-month' => 'Reviews/month',
-       'twnmp-translations-translator-ranking' => '{{GENDER:$1|Ranked}} $2 of 
$3 translators<br />in $4',
+       'twnmp-translations-translator-ranking' => '{{PLURAL:$3|1=You are the 
only one<br />for $4|{{GENDER:$1|Ranked}} $2 of $3<br />for $4}}',
+       'twnmp-translations-translator-ranking-source' => '{{PLURAL:$3|1=You 
are the only one|{{GENDER:$1|Ranked}} $2 of $3}}',
 
        'twnmp-bottom-help' => 'Help',
        'twnmp-bottom-special-pages' => 'Special pages',
@@ -133,7 +134,7 @@
 Means that the users performs that number of review actions every month.
 Translate it in a way that is natural to your language - you don't have to use 
the '/' character.
 {{Identical|Review}}",
-       'twnmp-translations-translator-ranking' => 'Shown in the "Translate" 
and "Proofread" boxes in the center of the main page.
+       'twnmp-translations-translator-ranking' => 'Shown in the "Translate" 
and "Proofread" boxes in the center of the main page. Refers to the ranking of 
the user among other translators or proofreaders to that language.
 
 Can be broken to two lines. <code><nowiki><br /></nowiki></code> is a line 
break. Break it in any way that is natural in your language.
 
@@ -142,6 +143,13 @@
 * $2 - the ranking of this user
 * $3 - the total number of translators into that language
 * $4 - the language name',
+       'twnmp-translations-translator-ranking-source' => 'Shown in the 
"Translate" and "Proofread" boxes in the center of the main page when it is 
shown in the source language of all message groups. Refers to the ranking of 
the users among other translators on the site.
+
+Parameters:
+* $1 - the username, which can be used for GENDER
+* $2 - the ranking of this user
+* $3 - the total number of translators',
+
        'twnmp-bottom-help' => 'A link that appears at the bottom of the main 
page.
 
 The link points to [[Translating:Index]].
diff --git a/UserStats.php b/UserStats.php
index b2cc9e6..41cd2f7 100644
--- a/UserStats.php
+++ b/UserStats.php
@@ -26,9 +26,12 @@
 
                $conds = array(
                        'rc_namespace' => $wgTranslateMessageNamespaces,
-                       'rc_title' . $dbr->buildLike( $dbr->anyString(), 
"/$language" ),
                        'rc_bot' => 0,
                );
+
+               if ( $language !== '' ) {
+                       $conds[] = 'rc_title' . $dbr->buildLike( 
$dbr->anyString(), "/$language" );
+               }
 
                $options = array(
                        'ORDER BY' => 'rc_id DESC',
@@ -56,10 +59,6 @@
                                $ret[$row->user_name]++;
                                $cutoff = $row->rc_id;
                        }
-
-                       if ( $res->numRows() < 1000 ) {
-                               break;
-                       }
                }
 
                arsort( $ret );
@@ -84,12 +83,15 @@
 
                $conds = array(
                        'log_namespace' => $wgTranslateMessageNamespaces,
-                       'log_title' . $dbr->buildLike( $dbr->anyString(), 
"/$language" ),
                        'log_type' => 'translationreview',
                        'log_action' => 'message',
                        'log_timestamp >= ' . $dbr->timestamp( $weekago ),
                );
 
+               if ( $language !== '' ) {
+                       $conds[] = 'log_title' . $dbr->buildLike( 
$dbr->anyString(), "/$language" );
+               }
+
                $options = array(
                        'GROUP BY' => 'user_name',
                );
diff --git a/specials/SpecialTwnMainPage.php b/specials/SpecialTwnMainPage.php
index 571d3b6..fab2ed8 100644
--- a/specials/SpecialTwnMainPage.php
+++ b/specials/SpecialTwnMainPage.php
@@ -376,7 +376,7 @@
        public function twnStats() {
                $stale = 60 * 60 * 6;
                $expired = 60 * 60 * 24;
-               $cacher = new CachedStat( 'atwnstats', $stale, $expired,
+               $cacher = new CachedStat( 'twnstats', $stale, $expired,
                        array( 'SpecialTwnMainPage::getTwnStats' ), 'allow 
miss' );
                $stats = $cacher->get();
 
@@ -538,13 +538,26 @@
        }
 
        public function userStats() {
+               $groupsSourceLanguage = MessageGroups::haveSingleSourceLanguage(
+                       MessageGroups::getAllGroups()
+               );
                $languageCode = $this->getLanguage()->getCode();
-               $languageName = TranslateUtils::getLanguageName( $languageCode, 
$languageCode );
+
+               if ( $groupsSourceLanguage === $languageCode ) {
+                       # Do stats for all languages, denoted by empty string
+                       $languageForStats = '';
+               } else {
+                       $languageForStats = $languageCode;
+               }
 
                $stale = 60 * 5;
                $expired = 60 * 60 * 12;
-               $cacher = new CachedStat( "userstats-$languageCode", $stale, 
$expired,
-                       array( 'SpecialTwnMainPage::getUserStats', 
$languageCode, 30 ),
+               $cacher = new CachedStat( "userstats-$languageForStats", 
$stale, $expired,
+                       array(
+                               'SpecialTwnMainPage::getUserStats',
+                               $languageForStats,
+                               30
+                       ),
                        'allow miss'
                );
                $statsArray = $cacher->get();
@@ -568,13 +581,16 @@
                        $this->msg( 'twnmp-your-translations-stats' )->text()
                );
 
-               $groupsSourceLanguage = 
MessageGroups::haveSingleSourceLanguage( MessageGroups::getAllGroups() );
+               $languageName = TranslateUtils::getLanguageName( $languageCode, 
$languageCode );
                if ( $groupsSourceLanguage === $languageCode ) {
                        $translationStatsSubtitle = $this->msg(
                                'twnmp-your-translations-stats-all-languages'
                        )->text();
+
+                       $translationStatsRankingMsg = 
'twnmp-translations-translator-ranking-source';
                } else {
                        $translationStatsSubtitle = $languageName;
+                       $translationStatsRankingMsg = 
'twnmp-translations-translator-ranking';
                }
 
                $out .= Html::element( 'div', array(), 
$translationStatsSubtitle );
@@ -601,11 +617,14 @@
                                        $this->msg( 
'twnmp-translations-per-month' )->text()
                                );
 
-                               $msg = $this->msg( 
'twnmp-translations-translator-ranking' )
+                               // TODO: When refactoring, $languageName should 
not be used
+                               // when using the message for the source page
+                               $msg = $this->msg( $translationStatsRankingMsg )
                                        ->params( $myuser, $i, $translators, 
$languageName )
                                        ->plain();
                                $wrap = new RawMessage( "<div 
class='rank-description'>$msg</div>" );
                                $out .= $wrap->parse();
+
                                break;
                        }
                        $i++;
@@ -639,7 +658,9 @@
                                        $this->msg( 'twnmp-reviews-per-month' 
)->text()
                                );
 
-                               $msg = $this->msg( 
'twnmp-translations-translator-ranking' )
+                               // TODO: When refactoring, $languageName should 
not be used
+                               // when using the message for the source page
+                               $msg = $this->msg( $translationStatsRankingMsg )
                                        ->params( $myuser, $i, $translators, 
$languageName )
                                        ->plain();
                                $wrap = new RawMessage( "<div 
class='rank-description'>$msg</div>" );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7f6e86cd6b17e6bd6f53abca4973a44e23b53cb6
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/TwnMainPage
Gerrit-Branch: master
Gerrit-Owner: Amire80 <amir.ahar...@mail.huji.ac.il>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to