fix some spacing
[lhc/web/wiklou.git] / includes / Preferences.php
index 76e1760..cb91153 100644 (file)
@@ -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,
@@ -809,7 +825,6 @@ class Preferences {
                        'label-message' => 'tog-forceeditsummary',
                );
 
-
                $defaultPreferences['uselivepreview'] = array(
                        'type' => 'toggle',
                        'section' => 'editing/advancedediting',
@@ -992,7 +1007,6 @@ class Preferences {
                        'min' => 0,
                );
 
-
                if ( $wgVectorUseSimpleSearch ) {
                        $defaultPreferences['vector-simplesearch'] = array(
                                'type' => 'toggle',
@@ -1560,10 +1574,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 +1587,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] );
                        }
                }