From: Antoine Musso Date: Wed, 7 Mar 2012 09:56:24 +0000 (+0000) Subject: (bug 34302) Add CSS classes to email fields in user preferences X-Git-Tag: 1.31.0-rc.0~24351 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/wiki/supprimer.php?a=commitdiff_plain;h=160a4719579cfd45a3f652c64c8cc0709f21d075;p=lhc%2Fweb%2Fwiklou.git (bug 34302) Add CSS classes to email fields in user preferences Patch by Nischay Nahata whom I have mentored earlier this week. --- diff --git a/CREDITS b/CREDITS index 338732ea55..8baea59394 100644 --- 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 diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 1b0030996a..41cf78fe7b 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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. diff --git a/includes/Preferences.php b/includes/Preferences.php index a003c9f824..c021b268c9 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -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() . '
'; $disableEmailPrefs = false; + $emailauthenticationclass = 'mw-email-authenticated'; } else { $disableEmailPrefs = true; $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '
' . @@ -385,10 +389,12 @@ class Preferences { SpecialPage::getTitleFor( 'Confirmemail' ), $context->msg( 'emailconfirmlink' )->escaped() ) . '
'; + $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( diff --git a/resources/Resources.php b/resources/Resources.php index 6529405f98..4e4c90ac37 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -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', diff --git a/resources/mediawiki.special/mediawiki.special.changeemail.css b/resources/mediawiki.special/mediawiki.special.changeemail.css index 3d53e8dbde..9461fbdcef 100644 --- a/resources/mediawiki.special/mediawiki.special.changeemail.css +++ b/resources/mediawiki.special/mediawiki.special.changeemail.css @@ -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 index 0000000000..161efde30d --- /dev/null +++ b/resources/mediawiki.special/mediawiki.special.preferences.css @@ -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 { } +*/ diff --git a/tests/phpunit/includes/PreferencesTest.php b/tests/phpunit/includes/PreferencesTest.php index ad2a143900..89d9e0c263 100644 --- a/tests/phpunit/includes/PreferencesTest.php +++ b/tests/phpunit/includes/PreferencesTest.php @@ -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'] ); }