Revert r113650 and reapply r113619 and r113649 with one modification: User::createNew...
[lhc/web/wiklou.git] / includes / Preferences.php
index 8fb00e2..c021b26 100644 (file)
@@ -84,9 +84,9 @@ class Preferences {
                                // Already set, no problem
                                continue;
                        } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
-                                       $field->validate( $prefFromUser, $user->mOptions ) === true ) {
+                                       $field->validate( $prefFromUser, $user->getOptions() ) === true ) {
                                $info['default'] = $prefFromUser;
-                       } elseif ( $field->validate( $globalDefault, $user->mOptions ) === true ) {
+                       } elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
                                $info['default'] = $globalDefault;
                        } else {
                                throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
@@ -252,7 +252,7 @@ class Preferences {
                }
 
                // Language
-               $languages = Language::getLanguageNames( false );
+               $languages = Language::fetchLanguageNames( null, 'mw' );
                if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
                        $languages[$wgLanguageCode] = $wgLanguageCode;
                }
@@ -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(
@@ -638,11 +646,6 @@ class Preferences {
                );
 
                if ( $wgAllowUserCssPrefs ) {
-                       $defaultPreferences['highlightbroken'] = array(
-                               'type' => 'toggle',
-                               'section' => 'rendering/advancedrendering',
-                               'label' => $context->msg( 'tog-highlightbroken' )->text(), // Raw HTML
-                       );
                        $defaultPreferences['showtoc'] = array(
                                'type' => 'toggle',
                                'section' => 'rendering/advancedrendering',
@@ -1218,6 +1221,10 @@ class Preferences {
                        $removeKeys = array_flip( $remove );
                        $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
                }
+
+               /**
+                * @var $htmlForm PreferencesForm
+                */
                $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
 
                $htmlForm->setModifiedUser( $user );
@@ -1337,7 +1344,7 @@ class Preferences {
 
        /**
         * @param $formData
-        * @param $form HTMLForm
+        * @param $form PreferencesForm
         * @param $entryPoint string
         * @return bool|Status|string
         */
@@ -1396,6 +1403,7 @@ class Preferences {
 
        /**
         * @param $formData
+        * @param $form PreferencesForm
         * @return Status
         */
        public static function tryUISubmit( $formData, $form ) {
@@ -1458,10 +1466,13 @@ class Preferences {
        }
 
        /**
+        * @deprecated in 1.19; will be removed in 1.20.
         * @param $user User
         * @return array
         */
        public static function loadOldSearchNs( $user ) {
+               wfDeprecated( __METHOD__, '1.19' );
+
                $searchableNamespaces = SearchEngine::searchableNamespaces();
                // Back compat with old format
                $arr = array();
@@ -1483,10 +1494,16 @@ class PreferencesForm extends HTMLForm {
 
        private $modifiedUser;
 
+       /**
+        * @param $user User
+        */
        public function setModifiedUser( $user ) {
                $this->modifiedUser = $user;
        }
 
+       /**
+        * @return User
+        */
        public function getModifiedUser() {
                if ( $this->modifiedUser === null ) {
                        return $this->getUser();
@@ -1553,8 +1570,10 @@ class PreferencesForm extends HTMLForm {
 
                return $data;
        }
+
        /**
         * Get the whole body of the form.
+        * @return string
         */
        function getBody() {
                return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' );
@@ -1563,6 +1582,8 @@ class PreferencesForm extends HTMLForm {
        /**
         * Get the <legend> for a given section key. Normally this is the
         * prefs-$key message but we'll allow extensions to override it.
+        * @param $key string
+        * @return string
         */
        function getLegend( $key ) {
                $legend = parent::getLegend( $key );