r96884 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96883‎ | r96884 | r96885 >
Date:19:00, 12 September 2011
Author:catrope
Status:ok
Tags:
Comment:
RL2: Factor code for grouping gadgets by category out to GadgetRepo::getGadgetsByCategory()
Modified paths:
  • /branches/RL2/extensions/Gadgets/SpecialGadgetManager.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/GadgetRepo.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php
@@ -101,4 +101,14 @@
102102 return $msg->plain();
103103 }
104104
 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+
105115 }
Index: branches/RL2/extensions/Gadgets/api/ApiQueryGadgetCategories.php
@@ -44,15 +44,8 @@
4545 $data = array();
4646 $result = $this->getResult();
4747 $repo = new LocalGadgetRepo( array() );
48 - $gadgets = $repo->getGadgetIds();
4948
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();
5750 foreach ( $gadgetsByCategory as $category => $gadgets ) {
5851 if ( !$this->neededNames || isset( $this->neededNames[$category] ) ) {
5952 $row = array();
Index: branches/RL2/extensions/Gadgets/SpecialGadgetManager.php
@@ -44,10 +44,10 @@
4545 global $wgGadgetEnableSharing;
4646
4747 $repo = new LocalGadgetRepo( array() );
48 - $gadgetIds = $repo->getGadgetIds();
 48+ $gadgetsByCategory = $repo->getGadgetsByCategory();
4949
5050 // If there there are no gadgets at all, exit early.
51 - if ( !count( $gadgetIds ) ) {
 51+ if ( !count( $gadgetsByCategory ) ) {
5252 $noGadgetsMsgHtml = Html::element( 'p',
5353 array(
5454 'class' => 'mw-gadgetmanager-nogadgets'
@@ -59,14 +59,7 @@
6060 // There is atleast one gadget, let's get started.
6161 $this->getOutput()->addWikiMsg( 'gadgetmanager-pagetext' );
6262 $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+
7164 // Sort categories alphabetically
7265 // @todo Sort causes the key "''" to be at the top, it should be on the bottom.
7366 ksort( $gadgetsByCategory );

Status & tagging log