r85198 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85197‎ | r85198 | r85199 >
Date:16:02, 2 April 2011
Author:maxsem
Status:ok
Tags:
Comment:
Gadgets: refactored [options] parsing in preparation for adding moar
Modified paths:
  • /trunk/extensions/Gadgets/Gadgets_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Gadgets/Gadgets_body.php
@@ -209,17 +209,24 @@
210210 $gadget = new Gadget();
211211 $gadget->name = trim( str_replace(' ', '_', $m[1] ) );
212212 $gadget->definition = $definition;
213 - $params = trim( $m[2], ' []' );
214 - foreach ( preg_split( '/\s*\|\s*/', $params, -1, PREG_SPLIT_NO_EMPTY ) as $option ) {
215 - if ( $option == 'ResourceLoader' ) {
216 - $gadget->resourceLoaded = true;
217 - } elseif ( preg_match( '/dependencies\s*=/', $option ) ) {
218 - $option = preg_replace( '/dependencies\s*=\s*/', '', $option );
219 - $deps = preg_split( '/\s*,\s*/', $option, -1, PREG_SPLIT_NO_EMPTY );
220 - if ( $deps ) {
221 - $gadget->dependencies = $deps;
222 - }
 213+ $options = trim( $m[2], ' []' );
 214+ foreach ( preg_split( '/\s*\|\s*/', $options, -1, PREG_SPLIT_NO_EMPTY ) as $option ) {
 215+ $arr = preg_split( '/\s*=\s*/', $option, 2 );
 216+ $option = $arr[0];
 217+ if ( isset( $arr[1] ) ) {
 218+ $params = explode( ',', $arr[1] );
 219+ $params = array_map( 'trim', $params );
 220+ } else {
 221+ $params = array();
223222 }
 223+ switch ( $option ) {
 224+ case 'ResourceLoader':
 225+ $gadget->resourceLoaded = true;
 226+ break;
 227+ case 'dependencies':
 228+ $gadget->dependencies = $params;
 229+ break;
 230+ }
224231 }
225232 foreach ( preg_split( '/\s*\|\s*/', $m[3], -1, PREG_SPLIT_NO_EMPTY ) as $page ) {
226233 $page = "Gadget-$page";

Status & tagging log