Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php |
— | — | @@ -101,4 +101,14 @@ |
102 | 102 | return $msg->plain(); |
103 | 103 | } |
104 | 104 | |
| 105 | + public function getGadgetsByCategory() { |
| 106 | + $retval = array(); |
| 107 | + $gadgetIDs = $this->getGadgetIds(); |
| 108 | + foreach ( $gadgetIDs as $id ) { |
| 109 | + $gadget = $this->getGadget( $id ); |
| 110 | + $retval[$gadget->getCategory()][] = $gadget; |
| 111 | + } |
| 112 | + return $retval; |
| 113 | + } |
| 114 | + |
105 | 115 | } |
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php |
— | — | @@ -44,15 +44,8 @@ |
45 | 45 | $data = array(); |
46 | 46 | $result = $this->getResult(); |
47 | 47 | $repo = new LocalGadgetRepo( array() ); |
48 | | - $gadgets = $repo->getGadgetIds(); |
49 | 48 | |
50 | | - // TODO: Put the grouping in the repo |
51 | | - $gadgetsByCategory = array(); |
52 | | - foreach ( $gadgets as $id ) { |
53 | | - $gadget = $repo->getGadget( $id ); |
54 | | - $gadgetsByCategory[$gadget->getCategory()][] = $gadget; |
55 | | - } |
56 | | - |
| 49 | + $gadgetsByCategory = $repo->getGadgetsByCategory(); |
57 | 50 | foreach ( $gadgetsByCategory as $category => $gadgets ) { |
58 | 51 | if ( !$this->neededNames || isset( $this->neededNames[$category] ) ) { |
59 | 52 | $row = array(); |
Index: branches/RL2/extensions/Gadgets/SpecialGadgetManager.php |
— | — | @@ -44,10 +44,10 @@ |
45 | 45 | global $wgGadgetEnableSharing; |
46 | 46 | |
47 | 47 | $repo = new LocalGadgetRepo( array() ); |
48 | | - $gadgetIds = $repo->getGadgetIds(); |
| 48 | + $gadgetsByCategory = $repo->getGadgetsByCategory(); |
49 | 49 | |
50 | 50 | // If there there are no gadgets at all, exit early. |
51 | | - if ( !count( $gadgetIds ) ) { |
| 51 | + if ( !count( $gadgetsByCategory ) ) { |
52 | 52 | $noGadgetsMsgHtml = Html::element( 'p', |
53 | 53 | array( |
54 | 54 | 'class' => 'mw-gadgetmanager-nogadgets' |
— | — | @@ -59,14 +59,7 @@ |
60 | 60 | // There is atleast one gadget, let's get started. |
61 | 61 | $this->getOutput()->addWikiMsg( 'gadgetmanager-pagetext' ); |
62 | 62 | $html = ''; |
63 | | - |
64 | | - // Sort gadgets by category |
65 | | - $gadgetsByCategory = array(); |
66 | | - foreach ( $gadgetIds as $gadgetId ) { |
67 | | - $gadget = $repo->getGadget( $gadgetId ); |
68 | | - $gadgetsByCategory[$gadget->getCategory()][$gadgetId] = $gadget; |
69 | | - } |
70 | | - |
| 63 | + |
71 | 64 | // Sort categories alphabetically |
72 | 65 | // @todo Sort causes the key "''" to be at the top, it should be on the bottom. |
73 | 66 | ksort( $gadgetsByCategory ); |