| Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
| — | — | @@ -36,31 +36,35 @@ |
| 37 | 37 | * @param $preferences Array: Preference descriptions |
| 38 | 38 | */ |
| 39 | 39 | public static function getPreferences( $user, &$preferences ) { |
| 40 | | - // TODO convert |
| 41 | | - return true; |
| 42 | | - $gadgets = Gadget::loadStructuredList(); |
| 43 | | - if (!$gadgets) return true; |
| | 40 | + // TODO: Part of this is duplicated from registerModules(), factor out into the repo |
| | 41 | + $repo = new LocalGadgetRepo( array() ); |
| 44 | 42 | |
| 45 | | - $options = array(); |
| 46 | | - $default = array(); |
| 47 | | - foreach( $gadgets as $section => $thisSection ) { |
| 48 | | - $available = array(); |
| 49 | | - foreach( $thisSection as $gadget ) { |
| 50 | | - if ( $gadget->isAllowed( $user ) ) { |
| 51 | | - $gname = $gadget->getName(); |
| 52 | | - $available[$gadget->getDescription()] = $gname; |
| 53 | | - if ( $gadget->isEnabled( $user ) ) { |
| 54 | | - $default[] = $gname; |
| 55 | | - } |
| 56 | | - } |
| | 43 | + $gadgets = $repo->getGadgetNames(); |
| | 44 | + $sections = array(); // array( section => array( desc => name ) ) |
| | 45 | + $default = array(); // array of Gadget names |
| | 46 | + foreach ( $gadgets as $name ) { |
| | 47 | + $gadget = $repo->getGadget( $name ); |
| | 48 | + if ( !$gadget->isAllowed( $user ) || $gadget->isHidden() ) { |
| | 49 | + continue; |
| 57 | 50 | } |
| | 51 | + $section = $gadget->getSection(); |
| | 52 | + |
| | 53 | + // Add the Gadget to the right section |
| | 54 | + $description = wfMessage( $gadget->getDescriptionMsg() )->parse(); |
| | 55 | + $sections[$section][$description] = $name; |
| | 56 | + // Add the Gadget to the default list if enabled |
| | 57 | + if ( $gadget->isEnabledForUser( $user ) ) { |
| | 58 | + $default[] = $name; |
| | 59 | + } |
| | 60 | + } |
| | 61 | + |
| | 62 | + $options = array(); // array( desc1 => name1, section1 => array( desc2 => name2 ) ) |
| | 63 | + foreach ( $sections as $section => $gadgets ) { |
| 58 | 64 | if ( $section !== '' ) { |
| 59 | | - $section = wfMsgExt( "gadget-section-$section", 'parseinline' ); |
| 60 | | - if ( count ( $available ) ) { |
| 61 | | - $options[$section] = $available; |
| 62 | | - } |
| | 65 | + $sectionMsg = wfMsgExt( "gadget-section-$section", 'parseinline' ); |
| | 66 | + $options[$sectionMsg] = $gadgets; |
| 63 | 67 | } else { |
| 64 | | - $options = array_merge( $options, $available ); |
| | 68 | + $options += $gadgets; |
| 65 | 69 | } |
| 66 | 70 | } |
| 67 | 71 | |
| — | — | @@ -75,7 +79,6 @@ |
| 76 | 80 | 'raw' => 1, |
| 77 | 81 | 'rawrow' => 1, |
| 78 | 82 | ); |
| 79 | | - |
| 80 | 83 | $preferences['gadgets'] = |
| 81 | 84 | array( |
| 82 | 85 | 'type' => 'multiselect', |
| — | — | @@ -85,7 +88,6 @@ |
| 86 | 89 | 'prefix' => 'gadget-', |
| 87 | 90 | 'default' => $default, |
| 88 | 91 | ); |
| 89 | | - |
| 90 | 92 | return true; |
| 91 | 93 | } |
| 92 | 94 | |