Index: branches/preferences-work/extensions/Gadgets/Gadgets.php |
— | — | @@ -123,20 +123,14 @@ |
124 | 124 | |
125 | 125 | function wfGadgetsGetPreferences( $user, &$preferences ) { |
126 | 126 | $gadgets = wfLoadGadgetsStructured(); |
127 | | - |
128 | 127 | if (!$gadgets) return true; |
129 | 128 | |
130 | 129 | wfLoadExtensionMessages( 'Gadgets' ); |
131 | 130 | |
132 | 131 | $options = array_fill_keys( array_keys($gadgets), array() ); |
133 | | - |
134 | | - $selectedGadgets = array(); |
135 | | - |
136 | 132 | foreach( $gadgets as $section => $thisSection ) { |
137 | 133 | foreach( $thisSection as $gname => $code ) { |
138 | 134 | $options[$section][wfMsgExt( "gadget-$gname", 'parseinline' )] = $gname; |
139 | | - if ( $user->getOption( "gadget-$gname") ) |
140 | | - $selectedGadgets[] = $gname; |
141 | 135 | } |
142 | 136 | } |
143 | 137 | |
— | — | @@ -158,7 +152,6 @@ |
159 | 153 | 'section' => 'gadgets', |
160 | 154 | 'label' => ' ', |
161 | 155 | 'prefix' => 'gadget-', |
162 | | - 'default' => $selectedGadgets, |
163 | 156 | ); |
164 | 157 | |
165 | 158 | return true; |
Index: branches/preferences-work/phase3/includes/Preferences.php |
— | — | @@ -684,7 +684,6 @@ |
685 | 685 | |
686 | 686 | // Searchable namespaces back-compat with old format |
687 | 687 | $searchableNamespaces = SearchEngine::searchableNamespaces(); |
688 | | - $searchDefault = self::loadOldSearchNs( $user ); |
689 | 688 | |
690 | 689 | $nsOptions = array(); |
691 | 690 | foreach( $wgContLang->getNamespaces() as $ns => $name ) { |
— | — | @@ -702,7 +701,6 @@ |
703 | 702 | 'label-message' => 'defaultns', |
704 | 703 | 'options' => $nsOptions, |
705 | 704 | 'section' => 'searchoptions', |
706 | | - 'default' => $searchDefault, |
707 | 705 | 'prefix' => 'searchNs', |
708 | 706 | ); |
709 | 707 | |
— | — | @@ -735,7 +733,7 @@ |
736 | 734 | ## Prod in defaults from the user |
737 | 735 | global $wgDefaultUserOptions; |
738 | 736 | foreach( $defaultPreferences as $name => &$info ) { |
739 | | - $prefFromUser = $user->getOption( $name ); |
| 737 | + $prefFromUser = self::getOptionFromUser( $name, $info, $user ); |
740 | 738 | $field = HTMLForm::loadInputFromParameters( $info ); // For validation |
741 | 739 | $globalDefault = isset($wgDefaultUserOptions[$name]) |
742 | 740 | ? $wgDefaultUserOptions[$name] |
— | — | @@ -745,7 +743,7 @@ |
746 | 744 | if ( isset($info['default']) ) { |
747 | 745 | // Already set, no problem |
748 | 746 | continue; |
749 | | - } elseif ( isset( $user->mOptions[$name] ) && // Make sure we're not just pulling nothing |
| 747 | + } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing |
750 | 748 | $field->validate( $prefFromUser, $user->mOptions ) ) { |
751 | 749 | $info['default'] = $prefFromUser; |
752 | 750 | } elseif( $field->validate( $globalDefault, $user->mOptions ) ) { |
— | — | @@ -758,6 +756,28 @@ |
759 | 757 | return $defaultPreferences; |
760 | 758 | } |
761 | 759 | |
| 760 | + // Pull option from a user account. Handles stuff like array-type preferences. |
| 761 | + static function getOptionFromUser( $name, $info, $user ) { |
| 762 | + $val = $user->getOption( $name ); |
| 763 | + |
| 764 | + // Handling for array-type preferences |
| 765 | + if ( ( isset($info['type']) && $info['type'] == 'multiselect' ) || |
| 766 | + ( isset($info['class']) && $info['class'] == 'HTMLMultiSelectField' ) ) { |
| 767 | + |
| 768 | + $options = HTMLFormField::flattenOptions($info['options']); |
| 769 | + $prefix = isset($info['prefix']) ? $info['prefix'] : $name; |
| 770 | + $val = array(); |
| 771 | + |
| 772 | + foreach( $options as $label => $value ) { |
| 773 | + if ($user->getOption( "$prefix$value" ) ) { |
| 774 | + $val[] = $value; |
| 775 | + } |
| 776 | + } |
| 777 | + } |
| 778 | + |
| 779 | + return $val; |
| 780 | + } |
| 781 | + |
762 | 782 | static function generateSkinOptions( $user ) { |
763 | 783 | global $wgDefaultSkin; |
764 | 784 | $ret = array(); |
Index: branches/preferences-work/phase3/includes/User.php |
— | — | @@ -1869,7 +1869,7 @@ |
1870 | 1870 | * @see getBoolOption() |
1871 | 1871 | * @see getIntOption() |
1872 | 1872 | */ |
1873 | | - function getOption( $oname, $defaultOverride = '' ) { |
| 1873 | + function getOption( $oname, $defaultOverride = null ) { |
1874 | 1874 | $this->loadOptions(); |
1875 | 1875 | |
1876 | 1876 | if ( is_null( $this->mOptions ) ) { |