Merge "Slight improvements to FormSpecialPage behavior."
[lhc/web/wiklou.git] / includes / Preferences.php
index 44c87f0..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]
@@ -310,23 +314,23 @@ class Preferences {
                        'label-message' => 'yourlanguage',
                );
 
-               /* see if there are multiple language variants to choose from*/
-               $variantArray = array();
+               // see if there are multiple language variants to choose from
                if ( !$wgDisableLangConversion ) {
                        $variants = $wgContLang->getVariants();
 
-                       foreach ( $variants as $v ) {
-                               $v = str_replace( '_', '-', strtolower( $v ) );
-                               $variantArray[$v] = $wgContLang->getVariantname( $v, false );
-                       }
+                       if ( count( $variants ) > 1 ) {
+                               $variantArray = array();
+                               foreach ( $variants as $v ) {
+                                       $v = str_replace( '_', '-', strtolower( $v ) );
+                                       $variantArray[$v] = $wgContLang->getVariantname( $v, false );
+                               }
 
-                       $options = array();
-                       foreach ( $variantArray as $code => $name ) {
-                               $display = wfBCP47( $code ) . ' - ' . $name;
-                               $options[$display] = $code;
-                       }
+                               $options = array();
+                               foreach ( $variantArray as $code => $name ) {
+                                       $display = wfBCP47( $code ) . ' - ' . $name;
+                                       $options[$display] = $code;
+                               }
 
-                       if ( count( $variantArray ) > 1 ) {
                                $defaultPreferences['variant'] = array(
                                        'label-message' => 'yourvariant',
                                        'type' => 'select',
@@ -334,16 +338,16 @@ class Preferences {
                                        'section' => 'personal/i18n',
                                        'help-message' => 'prefs-help-variant',
                                );
-                       }
-               }
 
-               if ( count( $variantArray ) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion ) {
-                       $defaultPreferences['noconvertlink'] =
-                               array(
-                               'type' => 'toggle',
-                               'section' => 'personal/i18n',
-                               'label-message' => 'tog-noconvertlink',
-                       );
+                               if ( !$wgDisableTitleConversion ) {
+                                       $defaultPreferences['noconvertlink'] =
+                                               array(
+                                               'type' => 'toggle',
+                                               'section' => 'personal/i18n',
+                                               'label-message' => 'tog-noconvertlink',
+                                       );
+                               }
+                       }
                }
 
                // show a preview of the old signature first
@@ -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(
@@ -674,7 +678,7 @@ class Preferences {
                        'section' => 'rendering/advancedrendering',
                        'options' => $stubThresholdOptions,
                        'size' => 20,
-                       'label' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
+                       'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
                );
 
                if ( $wgAllowUserCssPrefs ) {
@@ -1093,7 +1097,7 @@ class Preferences {
                        }
 
                        # Create preview link
-                       $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
+                       $mplink = htmlspecialchars( $mptitle->getLocalURL( array( 'useskin' => $skinkey ) ) );
                        $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
 
                        # Create links to user CSS/JS pages
@@ -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'] );
+                       if ( $field instanceof HTMLNestedFilterable ) {
+                               $info = $field->mParams;
                                $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
-
-                               foreach ( $options as $opt ) {
-                                       $data["$prefix$opt"] = in_array( $opt, $data[$fieldname] );
+                               foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
+                                       $data["$prefix-$key"] = $value;
                                }
-
-                               unset( $data[$fieldname] );
-
-                       } elseif ( $field instanceof HTMLCheckMatrix ) {
-                               $columns = HTMLFormField::flattenOptions( $info['columns'] );
-                               $rows = HTMLFormField::flattenOptions( $info['rows'] );
-                               $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] );
-                                               }
-                                       }
-                               }
-
                                unset( $data[$fieldname] );
                        }
                }