| Index: branches/RL2/extensions/Gadgets/Gadgets.php |
| — | — | @@ -56,12 +56,7 @@ |
| 57 | 57 | * // TODO |
| 58 | 58 | * ); |
| 59 | 59 | */ |
| 60 | | -$wgGadgetRepositories = array( |
| 61 | | - array( |
| 62 | | - // Default local gadget repository. Doesn't need any parameters |
| 63 | | - 'class' => 'LocalGadgetRepo', |
| 64 | | - ) |
| 65 | | -); |
| | 60 | +$wgGadgetRepositories = array(); |
| 66 | 61 | |
| 67 | 62 | /** |
| 68 | 63 | * Whether or not to allow gadgets to be shared in the gadget manager. |
| Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
| — | — | @@ -261,18 +261,9 @@ |
| 262 | 262 | * @param $resourceLoader ResourceLoader |
| 263 | 263 | */ |
| 264 | 264 | public static function registerModules( &$resourceLoader ) { |
| 265 | | - global $wgGadgetRepositories; |
| 266 | | - // TODO: Factor this loop out somewhere and include LocalGadgetRepo more magically so we can use ::singleton() |
| 267 | | - foreach ( $wgGadgetRepositories as $params ) { |
| 268 | | - $repoClass = $params['class']; |
| 269 | | - unset( $params['class'] ); |
| 270 | | - $repo = new $repoClass( $params ); |
| 271 | | - |
| 272 | | - $gadgets = $repo->getGadgetIds(); |
| 273 | | - foreach ( $gadgets as $id ) { |
| 274 | | - $gadget = $repo->getGadget( $id ); |
| 275 | | - $resourceLoader->register( $gadget->getModuleName(), $gadget->getModule() ); |
| 276 | | - } |
| | 265 | + $gadgets = GadgetRepo::getAllGadgets(); |
| | 266 | + foreach ( $gadgets as $gadget ) { |
| | 267 | + $resourceLoader->register( $gadget->getModuleName(), $gadget->getModule() ); |
| 277 | 268 | } |
| 278 | 269 | return true; |
| 279 | 270 | } |
| — | — | @@ -282,21 +273,14 @@ |
| 283 | 274 | * @param $out OutputPage |
| 284 | 275 | */ |
| 285 | 276 | public static function beforePageDisplay( $out ) { |
| 286 | | - global $wgUser, $wgGadgetRepositories; |
| | 277 | + global $wgUser; |
| 287 | 278 | |
| 288 | 279 | wfProfileIn( __METHOD__ ); |
| 289 | 280 | |
| 290 | | - foreach ( $wgGadgetRepositories as $params ) { |
| 291 | | - $repoClass = $params['class']; |
| 292 | | - unset( $params['class'] ); |
| 293 | | - $repo = new $repoClass( $params ); |
| 294 | | - |
| 295 | | - $gadgets = $repo->getGadgetIds(); |
| 296 | | - foreach ( $gadgets as $id ) { |
| 297 | | - $gadget = $repo->getGadget( $id ); |
| 298 | | - if ( $gadget->isEnabledForUser( $wgUser ) && $gadget->isAllowed( $wgUser ) ) { |
| 299 | | - $out->addModules( $gadget->getModuleName() ); |
| 300 | | - } |
| | 281 | + $gadgets = GadgetRepo::getAllGadgets(); |
| | 282 | + foreach ( $gadgets as $gadget ) { |
| | 283 | + if ( $gadget->isEnabledForUser( $wgUser ) && $gadget->isAllowed( $wgUser ) ) { |
| | 284 | + $out->addModules( $gadget->getModuleName() ); |
| 301 | 285 | } |
| 302 | 286 | } |
| 303 | 287 | |
| Index: branches/RL2/extensions/Gadgets/backend/GadgetRepo.php |
| — | — | @@ -111,4 +111,35 @@ |
| 112 | 112 | } |
| 113 | 113 | return $msg->plain(); |
| 114 | 114 | } |
| | 115 | + |
| | 116 | + /** |
| | 117 | + * Get all gadget repositories. Returns the LocalGadgetRepo singleton and any |
| | 118 | + * repositories configured in $wgGadgetRepositories |
| | 119 | + * @return array of GadgetRepo objects |
| | 120 | + */ |
| | 121 | + public static function getAllRepos() { |
| | 122 | + global $wgGadgetRepositories; |
| | 123 | + $repos = array( LocalGadgetRepo::singleton() ); |
| | 124 | + foreach ( $wgGadgetRepositories as $params ) { |
| | 125 | + $repoClass = $params['class']; |
| | 126 | + unset( $params['class'] ); // Safe because foreach operates on a copy of the array |
| | 127 | + $repos[] = new $repoClass( $params ); |
| | 128 | + } |
| | 129 | + return $repos; |
| | 130 | + } |
| | 131 | + |
| | 132 | + /** |
| | 133 | + * Get all gadgets from all repositories. |
| | 134 | + * @return array of Gadget objects |
| | 135 | + */ |
| | 136 | + public static function getAllGadgets() { |
| | 137 | + $retval = array(); |
| | 138 | + $repos = GadgetRepo::getAllRepos(); |
| | 139 | + foreach ( $repos as $repo ) { |
| | 140 | + $gadgets = $repo->getGadgetIds(); |
| | 141 | + foreach ( $gadgets as $id ) { |
| | 142 | + $retval[] = $repo->getGadget( $id ); |
| | 143 | + } |
| | 144 | + } |
| | 145 | + } |
| 115 | 146 | } |