Merge "Slight improvements to FormSpecialPage behavior."
[lhc/web/wiklou.git] / includes / Preferences.php
index 0d765fa..1b01750 100644 (file)
@@ -90,10 +90,14 @@ class Preferences {
                        }
                }
 
+               ## Make sure that form fields have their parent set. See bug 41337.
+               $dummyForm = new HTMLForm( array(), $context );
+
                ## Prod in defaults from the user
                foreach ( $defaultPreferences as $name => &$info ) {
                        $prefFromUser = self::getOptionFromUser( $name, $info, $user );
                        $field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation
+                       $field->mParent = $dummyForm;
                        $defaultOptions = User::getDefaultOptions();
                        $globalDefault = isset( $defaultOptions[$name] )
                                ? $defaultOptions[$name]
@@ -409,8 +413,8 @@ class Preferences {
 
                        $disableEmailPrefs = false;
 
-                       $emailauthenticationclass = 'mw-email-not-authenticated';
                        if ( $wgEmailAuthentication ) {
+                               $emailauthenticationclass = 'mw-email-not-authenticated';
                                if ( $user->getEmail() ) {
                                        if ( $user->getEmailAuthenticationTimestamp() ) {
                                                // date and time are separate parameters to facilitate localisation.
@@ -449,8 +453,8 @@ class Preferences {
                                        # Apply the same CSS class used on the input to the message:
                                        'cssclass' => $emailauthenticationclass,
                                );
+                               $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
                        }
-                       $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
 
                        if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
                                $defaultPreferences['disablemail'] = array(
@@ -1476,7 +1480,7 @@ class Preferences {
        }
 
        /**
-        * @deprecated in 1.19; will be removed in 1.20.
+        * @deprecated in 1.19
         * @param $user User
         * @return array
         */
@@ -1558,40 +1562,19 @@ class PreferencesForm extends HTMLForm {
        }
 
        /**
+        * Separate multi-option preferences into multiple preferences, since we
+        * have to store them separately
         * @param $data array
         * @return array
         */
        function filterDataForSubmit( $data ) {
-               // Support for separating multi-option preferences into multiple preferences
-               // Due to lack of array support.
                foreach ( $this->mFlatFields as $fieldname => $field ) {
-                       $info = $field->mParams;
-
-                       if ( $field instanceof HTMLMultiSelectField ) {
-                               $options = HTMLFormField::flattenOptions( $info['options'] );
-                               $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
-
-                               foreach ( $options as $opt ) {
-                                       $data["$prefix$opt"] = in_array( $opt, $data[$fieldname] );
-                               }
-
-                               unset( $data[$fieldname] );
-
-                       } elseif ( $field instanceof HTMLCheckMatrix ) {
-                               $columns = HTMLFormField::flattenOptions( $info['columns'] );
-                               $rows = HTMLFormField::flattenOptions( $info['rows'] );
+                       if ( $field instanceof HTMLNestedFilterable ) {
+                               $info = $field->mParams;
                                $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
-                               foreach ( $columns as $column ) {
-                                       foreach ( $rows as $row ) {
-                                               // Make sure option hasn't been removed
-                                               if ( !isset( $info['remove-options'] )
-                                                       || !in_array( "$column-$row", $info['remove-options'] ) )
-                                               {
-                                                       $data["$prefix-$column-$row"] = in_array( "$column-$row", $data[$fieldname] );
-                                               }
-                                       }
+                               foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
+                                       $data["$prefix-$key"] = $value;
                                }
-
                                unset( $data[$fieldname] );
                        }
                }