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

Change subject: Implement sandboxed user logic for main page
......................................................................


Implement sandboxed user logic for main page

Change-Id: Id9cd5a6e1aa6ac3f3dda690865f0c4536f350421
---
M MainPage.i18n.php
M resources/css/ext.translate.mainpage.css
M specials/SpecialTwnMainPage.php
3 files changed, 104 insertions(+), 16 deletions(-)

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

Objections:
  Santhosh: There's a problem with this change, please improve



diff --git a/MainPage.i18n.php b/MainPage.i18n.php
index 40d8d89..b787358 100644
--- a/MainPage.i18n.php
+++ b/MainPage.i18n.php
@@ -33,17 +33,23 @@
        'twnmp-translate-link' => 'Translate',
        'twnmp-proofread-link' => 'Review',
        'twnmp-translate-button' => 'Translate',
+       'twnmp-view-button' => 'View translations',
        'twnmp-proofread-button' => 'Review',
 
        'twnmp-your-translations-stats' => 'Your translation statistics',
        'twnmp-your-translations-stats-all-languages' => 'For all languages',
        'twnmp-your-view-language-stats' => 'View language statistics',
        'twnmp-translations-per-month' => 'Translations/month',
+       'twnmp-translations-in-sandbox' => 'Translations',
        'twnmp-reviews-per-month' => 'Reviews/month',
        '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-add-project' => 'Add your open source project for translation',
+
+       'twnmp-sandboxed' => 'You need to provide more translations to get full 
translation rights.',
+       'twnmp-sandboxed-limit' => 'You reached the translation limit. Our team 
will verify and upgrade your account soon.',
+
        'twnmp-bottom-help' => 'Help',
        'twnmp-bottom-support' => 'Support desk',
        'twnmp-bottom-languages-supported' => 'Supported languages',
@@ -129,6 +135,7 @@
        'twnmp-translate-button' => "A label for the button that appears near 
the user's translation statistics.
 Pressing the button brings the user to the translation editor. Parallel to 
{{msg-mw|twnmp-proofread-button}}.
 {{Identical|Translate}}",
+       'twnmp-view-button' => 'A label for the button that appears near the 
user\'s translation statistics when the maximum number of translations in 
sandbox has already been done.',
        'twnmp-proofread-button' => "A label for the button that appears near 
the user's translation statistics.
 Pressing the button brings the user to the translation editor in review mode. 
Parallel to {{msg-mw|twnmp-translate-button}}.
 {{Identical|Review}}",
@@ -143,6 +150,7 @@
 Appears in the user's statistics box near a number.
 Means that the users performs that number of translations every month.
 Translate it in a way that is natural to your language - you don't have to use 
the '/' character.",
+       'twnmp-translations-in-sandbox' => 'Similar to 
{{msg-mw|twnmp-translations-per-month}} but for sandboxed users',
        'twnmp-reviews-per-month' => "Appears in the user's statistics box near 
a number.
 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.
@@ -173,6 +181,10 @@
        'twnmp-add-project' => 'Used as link text for the link pointing to 
[[Special:MyLanguage/Translating:New project|Translating:New project]].
 
 See example: [[Special:MainPage]]',
+
+       'twnmp-sandboxed' => 'A text shown to sandboxed users in their personal 
area on the main page instead of proofrading statistics.',
+       'twnmp-sandboxed-limit' => 'A text shown to sandboxed users in their 
personal area on the main page instead of proofreading statistics.',
+
        'twnmp-bottom-help' => 'A link that appears at the bottom of the main 
page.
 
 The link points to [[Translating:Index]].
diff --git a/resources/css/ext.translate.mainpage.css 
b/resources/css/ext.translate.mainpage.css
index 7493e90..246c6f8 100644
--- a/resources/css/ext.translate.mainpage.css
+++ b/resources/css/ext.translate.mainpage.css
@@ -213,10 +213,6 @@
        min-height: 75px;
 }
 
-.user-stats-title h2 {
-       border-bottom: none;
-}
-
 .twn-mainpage-alllang-stats {
        padding: 0 10px;
 }
@@ -254,10 +250,25 @@
        font-size: 15px;
 }
 
-.row.langstats-link-row {
+.langstats-link,
+.sandbox-message {
+       padding: 10px 15px;
+}
+
+.ranking {
        padding: 10px;
 }
 
+.sandbox-message {
+       color: #333333;
+       background-color: #fbf9ce;
+       font-size: 14px;
+}
+
+.langstats-link {
+       border-top: 1px solid #DDDDDD;
+}
+
 a.langstats-link {
        font-size: 16px;
        padding: 10px;
diff --git a/specials/SpecialTwnMainPage.php b/specials/SpecialTwnMainPage.php
index e4ac4d1..cfb0e83 100644
--- a/specials/SpecialTwnMainPage.php
+++ b/specials/SpecialTwnMainPage.php
@@ -474,7 +474,7 @@
 
        public function userWidget() {
                if ( $this->getUser()->isLoggedIn() ) {
-                       return $this->userStats();
+                       return $this->loggedInWidget();
                } else {
                        return $this->loginForm();
                }
@@ -585,10 +585,44 @@
                return "\n$out\n";
        }
 
-       public function userStats() {
+       public function loggedInWidget() {
+               $languageCode = $this->getLanguage()->getCode();
+               $languageName = TranslateUtils::getLanguageName( $languageCode, 
$languageCode );
+
+               $subtitle = '';
+
+               $link = Html::element( 'a', array(
+                       'href' => SpecialPage::getTitleFor( 'LanguageStats' 
)->getLocalUrl(),
+               ), $this->msg( 'twnmp-your-view-language-stats' )->text() );
+
+               if ( TranslateSandbox::isSandboxed( $this->getUser() ) ) {
+                       $rows = $this->getSandboxRows();
+               } else {
+                       $subtitle = htmlspecialchars( $languageName );
+                       $rows = $this->getTranslationStatsRows();
+               }
+
+               return <<<HTML
+
+<div class="five columns main-widget stats-widget">
+       <div class="row user-stats-title">
+               <h2>
+                       {$this->msg( 'twnmp-your-translations-stats' 
)->escaped()}
+               </h2>
+               <div class="subtitle">$subtitle</div>
+       </div>
+       $rows
+       <div class="row langstats-link">$link</div>
+</div>
+
+HTML;
+       }
+
+       public function getTranslationStatsRows() {
                $groupsSourceLanguage = MessageGroups::haveSingleSourceLanguage(
                        MessageGroups::getAllGroups()
                );
+
                $languageCode = $this->getLanguage()->getCode();
 
                if ( $groupsSourceLanguage === $languageCode ) {
@@ -654,7 +688,7 @@
 
                $myuser = $this->getUser()->getName();
 
-               $out .= Html::openElement( 'form', array(
+               $out = Html::openElement( 'form', array(
                        'class' => 'row ranking',
                        'action' => SpecialPage::getTitleFor( 'Translate' 
)->getLocalUrl(),
                ) );
@@ -700,6 +734,7 @@
                $out .= Html::closeElement( 'div' );
                $out .= Html::closeElement( 'form' );
 
+               // Proofreading row
                $out .= Html::openElement( 'form', array(
                        'class' => 'row ranking',
                        'action' => SpecialPage::getTitleFor( 'Translate' 
)->getLocalUrl(),
@@ -746,14 +781,44 @@
                $out .= Html::closeElement( 'div' );
                $out .= Html::closeElement( 'form' );
 
-               $out .= Html::openElement( 'div', array( 'class' => 'row 
langstats-link-row' ) );
-               $out .= Html::element( 'a', array(
-                       'class' => 'twelve columns langstats-link',
-                       'href' => SpecialPage::getTitleFor( 'LanguageStats' 
)->getLocalUrl(),
-               ), $this->msg( 'twnmp-your-view-language-stats' )->text() );
-               $out .= Html::closeElement( 'div' );
-               $out .= Html::closeElement( 'div' );
-
                return $out;
        }
+
+       public function getSandboxRows() {
+               global $wgTranslateSandboxLimit;
+
+               $store = new TranslationStashStorage( wfGetDB( DB_SLAVE ) );
+               $count = count( $store->getTranslations( $this->getUser() ) );
+
+               if ( $count < $wgTranslateSandboxLimit ) {
+                       $button = $this->msg( 'twnmp-translate-button' 
)->escaped();
+                       $message = $this->msg( 'twnmp-sandboxed' )->escaped();
+               } else {
+                       $button = $this->msg( 'twnmp-view-button' )->escaped();
+                       $message = $this->msg( 'twnmp-sandboxed-limit' 
)->escaped();
+               }
+
+               $count = $this->getLanguage()->formatNum( $count );
+               $count = htmlspecialchars( $count );
+
+               $action = SpecialPage::getTitleFor( 'TranslationStash' 
)->getLocalUrl();
+               $action = htmlspecialchars( $action );
+
+               return <<<HTML
+
+<form class="row ranking" action="$action">
+       <div class="eight columns">
+               <div class="count">$count</div>
+               <div class="count-description">
+                       {$this->msg( 'twnmp-translations-in-sandbox' 
)->escaped()}
+               </div>
+       </div>
+       <div class="four columns">
+               <button type="submit" class="button green">$button</button>
+       </div>
+</form>
+<div class="row sandbox-message">$message</div>
+
+HTML;
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id9cd5a6e1aa6ac3f3dda690865f0c4536f350421
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/TwnMainPage
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: KartikMistry <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Pginer <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to