(bug 34302) Add CSS classes to email fields in user preferences
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 7 Mar 2012 09:56:24 +0000 (09:56 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 7 Mar 2012 09:56:24 +0000 (09:56 +0000)
Patch by Nischay Nahata whom I have mentored earlier this week.

CREDITS
RELEASE-NOTES-1.20
includes/Preferences.php
resources/Resources.php
resources/mediawiki.special/mediawiki.special.changeemail.css
resources/mediawiki.special/mediawiki.special.preferences.css [new file with mode: 0644]
tests/phpunit/includes/PreferencesTest.php

diff --git a/CREDITS b/CREDITS
index 338732e..8baea59 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -159,6 +159,7 @@ following names for their contribution to the product.
 * Nx.devnull
 * Nikola Kovacs
 * Nikolaos S. Karastathis
+* Nischay Nahata
 * Olaf Lenz
 * Olivier Finlay Beaton
 * Paul Copperman
index 1b00309..41cf78f 100644 (file)
@@ -21,6 +21,7 @@ production.
   contentSub, ... The same div often also contains the class mw-content-ltr/rtl.
 * (bug 27619) Remove preference option to display broken links as link?
 * (bug 34896) Update jQuery JSON plugin to v2.3 (2011-09-17)
+* (bug 34302) Add CSS classes to email fields in user preferences
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
index a003c9f..c021b26 100644 (file)
@@ -354,16 +354,19 @@ class Preferences {
                                $emailAddress .= $emailAddress == '' ? $link : " ($link)";
                        }
 
+
                        $defaultPreferences['emailaddress'] = array(
                                'type' => 'info',
                                'raw' => true,
                                'default' => $emailAddress,
                                'label-message' => 'youremail',
                                'section' => 'personal/email',
+                               # 'cssclass' chosen below
                        );
 
                        $disableEmailPrefs = false;
 
+                       $emailauthenticationclass = 'mw-email-not-authenticated';
                        if ( $wgEmailAuthentication ) {
                                if ( $user->getEmail() ) {
                                        if ( $user->getEmailAuthenticationTimestamp() ) {
@@ -378,6 +381,7 @@ class Preferences {
                                                $emailauthenticated = $context->msg( 'emailauthenticated',
                                                        $time, $d, $t )->parse() . '<br />';
                                                $disableEmailPrefs = false;
+                                               $emailauthenticationclass = 'mw-email-authenticated';
                                        } else {
                                                $disableEmailPrefs = true;
                                                $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
@@ -385,10 +389,12 @@ class Preferences {
                                                                SpecialPage::getTitleFor( 'Confirmemail' ),
                                                                $context->msg( 'emailconfirmlink' )->escaped()
                                                        ) . '<br />';
+                                               $emailauthenticationclass="mw-email-not-authenticated";
                                        }
                                } else {
                                        $disableEmailPrefs = true;
                                        $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
+                                       $emailauthenticationclass = 'mw-email-none';
                                }
 
                                $defaultPreferences['emailauthentication'] = array(
@@ -397,9 +403,11 @@ class Preferences {
                                        'section' => 'personal/email',
                                        'label-message' => 'prefs-emailconfirm-label',
                                        'default' => $emailauthenticated,
+                                       # Apply the same CSS class used on the input to the message:
+                                       'cssclass' => $emailauthenticationclass,
                                );
-
                        }
+                       $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
 
                        if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
                                $defaultPreferences['disablemail'] = array(
index 6529405..4e4c90a 100644 (file)
@@ -786,6 +786,7 @@ return array(
        ),
        'mediawiki.special.preferences' => array(
                'scripts' => 'resources/mediawiki.special/mediawiki.special.preferences.js',
+               'styles'  => 'resources/mediawiki.special/mediawiki.special.preferences.css',
        ),
        'mediawiki.special.recentchanges' => array(
                'scripts' => 'resources/mediawiki.special/mediawiki.special.recentchanges.js',
index 3d53e8d..9461fbd 100644 (file)
@@ -5,6 +5,8 @@
        border-bottom-right-radius: 0.8em;
        border-top-right-radius: 0.8em;
 }
+
+/** colors also used in mediawiki.special.preferences.css */
 #mw-emailaddress-validity.valid {
        border: 1px solid #80FF80;
        background-color: #C0FFC0;
diff --git a/resources/mediawiki.special/mediawiki.special.preferences.css b/resources/mediawiki.special/mediawiki.special.preferences.css
new file mode 100644 (file)
index 0000000..161efde
--- /dev/null
@@ -0,0 +1,11 @@
+/** Reuses colors from mediawiki.special.changeemail.css */
+.mw-email-not-authenticated .mw-input,
+.mw-email-none .mw-input{
+       border: 1px solid #FF8080;
+       background-color: #FFC0C0;
+       color: black;
+}
+/** Authenticated email field has its own class too. Unstyled by default */
+/*
+.mw-email-authenticated .mw-input { }
+*/
index ad2a143..89d9e0c 100644 (file)
@@ -31,9 +31,10 @@ class PreferencesTest extends MediaWikiTestCase {
         */
        function testEmailFieldsWhenUserHasNoEmail() {
                $prefs = $this->prefsFor( 'noemail' );
-               $this->assertArrayNotHasKey( 'class',
+               $this->assertArrayHasKey( 'cssclass',
                        $prefs['emailaddress']
                );
+               $this->assertEquals( 'mw-email-none', $prefs['emailaddress']['cssclass'] );
        }
        /**
         * Placeholder to verify bug 34302
@@ -41,9 +42,10 @@ class PreferencesTest extends MediaWikiTestCase {
         */
        function testEmailFieldsWhenUserEmailNotAuthenticated() {
                $prefs = $this->prefsFor( 'notauth' );
-               $this->assertArrayNotHasKey( 'class',
+               $this->assertArrayHasKey( 'cssclass',
                        $prefs['emailaddress']
                );
+               $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailaddress']['cssclass'] );
        }
        /**
         * Placeholder to verify bug 34302
@@ -51,9 +53,10 @@ class PreferencesTest extends MediaWikiTestCase {
         */
        function testEmailFieldsWhenUserEmailIsAuthenticated() {
                $prefs = $this->prefsFor( 'auth' );
-               $this->assertArrayNotHasKey( 'class',
+               $this->assertArrayHasKey( 'cssclass',
                        $prefs['emailaddress']
                );
+               $this->assertEquals( 'mw-email-authenticated', $prefs['emailaddress']['cssclass'] );
        }