MarkTraceur has uploaded a new change for review.

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


Change subject: Dynamically change user count on frontend
......................................................................

Dynamically change user count on frontend

Change-Id: I7c3757a031c991451a2f3910141f42ce02e629f1
---
M BetaFeatures.php
M SpecialBetaFeatures.php
M includes/HTMLBetaFeatureField.php
3 files changed, 56 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BetaFeatures 
refs/changes/25/74325/1

diff --git a/BetaFeatures.php b/BetaFeatures.php
index 27b6572..8aa5cc4 100644
--- a/BetaFeatures.php
+++ b/BetaFeatures.php
@@ -44,6 +44,12 @@
 );
 
 $wgResourceModules['ext.betaFeatures'] = array(
+       'scripts' => array(
+               'js/ext.BetaFeatures.js',
+       ),
+       'messages' => array(
+               'betafeatures-user-count',
+       ),
        'styles' => array(
                'css/betafeatures.css',
        ),
diff --git a/SpecialBetaFeatures.php b/SpecialBetaFeatures.php
index 47cd503..cdeb5bf 100644
--- a/SpecialBetaFeatures.php
+++ b/SpecialBetaFeatures.php
@@ -56,7 +56,7 @@
                        array( 'up_property', 'count(up_user) AS number' ),
                        "up_value = 1 AND up_property REGEXP '^beta-feature-'",
                        __METHOD__,
-                       array()
+                       array( 'GROUP BY' => 'up_property' )
                );
 
                $counts = array();
@@ -73,7 +73,7 @@
                $out = $this->getOutput();
                $lang = $this->getLang();
 
-               $out->addModuleStyles( 'ext.betaFeatures' );
+               $out->addModules( 'ext.betaFeatures' );
 
                $betaOpts = $this->getBetaOptions( $out );
                $formFields = array();
@@ -82,6 +82,8 @@
 
                $userCount = self::getUserCounts();
 
+               $commafiedCounts = array();
+
                foreach ( $betaOpts as $label => $opt ) {
                        $prefname = $label;
 
@@ -89,12 +91,14 @@
                                $prefname = 'beta-feature-' . $label;
                        }
 
+                       $enabled = !!$user->getOption( $prefname );
+
                        $formFields[$label] = array(
                                'label' => $this->msg( $opt['label-message'] 
)->escaped(),
                                'title' => $this->msg( $opt['title-message'] 
)->escaped(),
                                'class' => 'HTMLBetaFeatureField',
                                'id' => 'checkbox-for-' . $label,
-                               'default' => $user->getOption( $prefname ),
+                               'default' => $enabled,
                        );
 
                        if ( array_key_exists( 'screenshot', $opt ) ) {
@@ -110,13 +114,38 @@
                                $formFields[$label]['disabled'] = true;
                        }
 
-                       if ( array_key_exists( $prefname, $userCount ) ) {
+                       if ( $label !== 'enable-all-beta' ) {
+                               if ( !array_key_exists( $prefname, $userCount ) 
) {
+                                       $userCount[$prefname] = 0;
+                               }
+
+                               $countNum = $userCount[$prefname];
+                               $currentCount = $lang->commafy( $countNum );
+
                                $formFields[$label]['userCount'] = $this->msg(
                                        'betafeatures-user-count',
-                                       $userCount[$prefname],
-                                       $lang->commafy( $userCount[$prefname] ) 
)->escaped();
+                                       $countNum,
+                                       $currentCount )->escaped();
+                               $formFields[$label]['userCountNumber'] = 
$countNum;
+
+                               $commafied = array();
+                               $commafied[$countNum] = 
$formFields[$label]['userCount'];
+
+                               if ( $enabled ) {
+                                       $alteredNum = $countNum - 1;
+                               } else {
+                                       $alteredNum = $countNum + 1;
+                               }
+
+                               $commafied[$alteredNum] = $this->msg(
+                                       'betafeatures-user-count',
+                                       $alteredNum,
+                                       $lang->commafy( $alteredNum ) 
)->escaped();
+                               $commafiedCounts[$label] = $commafied;
                        }
                }
+
+               $out->addJsConfigVars( 'commafiedCounts', $commafiedCounts );
 
                $formFields['enable-all-beta']['default'] = $allEnabled;
 
@@ -131,12 +160,20 @@
        function processInput( $data ) {
                global $wgUser;
 
-               $opts = self::getBetaOptions( $this->getOutput() );
-
-               $wgUser->setOption( 'enable-all-beta', $data['enable-all-beta'] 
);
+               $setNonGlobal = !$data['enable-all-beta'];
 
                foreach ( $data as $name => $val ) {
-                       $wgUser->setOption( 'beta-feature-' . $name, $val );
+                       $lbl = $name;
+                       $set = false;
+
+                       if ( $name !== 'enable-all-beta' ) {
+                               $lbl = 'beta-feature-' . $name;
+                               $set = $setNonGlobal;
+                       } else {
+                               $set = true;
+                       }
+
+                       $wgUser->setOption( $lbl, !!$val );
                }
 
                $wgUser->saveSettings();
diff --git a/includes/HTMLBetaFeatureField.php 
b/includes/HTMLBetaFeatureField.php
index 4f5da86..d4b17e0 100644
--- a/includes/HTMLBetaFeatureField.php
+++ b/includes/HTMLBetaFeatureField.php
@@ -32,6 +32,7 @@
 
                $attrs = array(
                        'id' => $id,
+                       'class' => 'beta-feature-toggle',
                );
 
                $classes = array(
@@ -70,6 +71,8 @@
                                array( 'class' => 'beta-feature-user-count' ),
                                $this->mParams['userCount']
                        );
+
+                       $attrs['data-count'] = 
$this->mParams['userCountNumber'];
                }
 
                if ( $hasDesc ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c3757a031c991451a2f3910141f42ce02e629f1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BetaFeatures
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>

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

Reply via email to