r95747 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95746‎ | r95747 | r95748 >
Date:09:49, 30 August 2011
Author:catrope
Status:ok
Tags:
Comment:
RL2: Convert preferences code to use the new backend
Modified paths:
  • /branches/RL2/extensions/Gadgets/GadgetHooks.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/GadgetHooks.php
@@ -36,31 +36,35 @@
3737 * @param $preferences Array: Preference descriptions
3838 */
3939 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() );
4442
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;
5750 }
 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 ) {
5864 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;
6367 } else {
64 - $options = array_merge( $options, $available );
 68+ $options += $gadgets;
6569 }
6670 }
6771
@@ -75,7 +79,6 @@
7680 'raw' => 1,
7781 'rawrow' => 1,
7882 );
79 -
8083 $preferences['gadgets'] =
8184 array(
8285 'type' => 'multiselect',
@@ -85,7 +88,6 @@
8689 'prefix' => 'gadget-',
8790 'default' => $default,
8891 );
89 -
9092 return true;
9193 }
9294

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95740RL2: Convert the BeforePageDisplay hook code to the new backendcatrope08:38, 30 August 2011

Status & tagging log