Revised design of Special:Userlogin
[lhc/web/wiklou.git] / includes / Preferences.php
index 76e1760..8766ad3 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Form to edit user perferences.
+ * Form to edit user preferences.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -129,7 +129,7 @@ class Preferences {
        static function getOptionFromUser( $name, $info, $user ) {
                $val = $user->getOption( $name );
 
-               // Handling for array-type preferences
+               // Handling for multiselect preferences
                if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
                                ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
                        $options = HTMLFormField::flattenOptions( $info['options'] );
@@ -143,6 +143,23 @@ class Preferences {
                        }
                }
 
+               // Handling for checkmatrix preferences
+               if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
+                               ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
+                       $columns = HTMLFormField::flattenOptions( $info['columns'] );
+                       $rows = HTMLFormField::flattenOptions( $info['rows'] );
+                       $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name;
+                       $val = array();
+
+                       foreach ( $columns as $column ) {
+                               foreach ( $rows as $row ) {
+                                       if ( $user->getOption( "$prefix-$column-$row" ) ) {
+                                               $val[] = "$column-$row";
+                                       }
+                               }
+                       }
+               }
+
                return $val;
        }
 
@@ -185,7 +202,7 @@ class Preferences {
                                // Skip the default * group, seems useless here
                                continue;
                        }
-                       $groupName  = User::getGroupName( $ueg );
+                       $groupName = User::getGroupName( $ueg );
                        $userGroups[] = User::makeGroupLinkHTML( $ueg, $groupName );
 
                        $memberName = User::getGroupMember( $ueg, $userName );
@@ -380,7 +397,6 @@ class Preferences {
                                );
                        }
 
-
                        $defaultPreferences['emailaddress'] = array(
                                'type' => 'info',
                                'raw' => true,
@@ -530,18 +546,6 @@ class Preferences {
                                'section' => 'rendering/skin',
                        );
                }
-
-               $selectedSkin = $user->getOption( 'skin' );
-               if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
-                       $settings = array_flip( $context->getLanguage()->getQuickbarSettings() );
-
-                       $defaultPreferences['quickbar'] = array(
-                               'type' => 'radio',
-                               'options' => $settings,
-                               'section' => 'rendering/skin',
-                               'label-message' => 'qbsettings',
-                       );
-               }
        }
 
        /**
@@ -809,12 +813,18 @@ class Preferences {
                        'label-message' => 'tog-forceeditsummary',
                );
 
-
                $defaultPreferences['uselivepreview'] = array(
                        'type' => 'toggle',
                        'section' => 'editing/advancedediting',
                        'label-message' => 'tog-uselivepreview',
                );
+
+               $defaultPreferences['useeditwarning'] = array(
+                       'type' => 'toggle',
+                       'section' => 'editing/advancedediting',
+                       'label-message' => 'tog-useeditwarning',
+               );
+
        }
 
        /**
@@ -992,7 +1002,6 @@ class Preferences {
                        'min' => 0,
                );
 
-
                if ( $wgVectorUseSimpleSearch ) {
                        $defaultPreferences['vector-simplesearch'] = array(
                                'type' => 'toggle',
@@ -1230,7 +1239,7 @@ class Preferences {
         * @param $user User
         * @param $context IContextSource
         * @param $formClass string
-        * @param $remove Array: array of items to remove
+        * @param array $remove array of items to remove
         * @return HtmlForm
         */
        static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm', array $remove = array() ) {
@@ -1459,7 +1468,7 @@ class Preferences {
         *
         * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
         * @param $user User
-        * @param $newaddr string New email address
+        * @param string $newaddr New email address
         * @return Array (true on success or Status on failure, info string)
         */
        public static function trySetUserEmail( User $user, $newaddr ) {
@@ -1560,10 +1569,11 @@ class PreferencesForm extends HTMLForm {
         * @return array
         */
        function filterDataForSubmit( $data ) {
-               // Support for separating MultiSelect preferences into multiple preferences
+               // 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;
@@ -1572,6 +1582,23 @@ class PreferencesForm extends HTMLForm {
                                        $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'] );
+                               $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] );
                        }
                }