r81673 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81672‎ | r81673 | r81674 >
Date:01:03, 8 February 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Stylized
Modified paths:
  • /trunk/extensions/ArrayExtension/ArrayExtension.i18n.php (modified) (history)
  • /trunk/extensions/ArrayExtension/ArrayExtension.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArrayExtension/ArrayExtension.i18n.php
@@ -1,5 +1,5 @@
22 <?php
3 -
 3+
44 /**
55 * Get translated magic words, if available
66 *
@@ -8,7 +8,7 @@
99 */
1010 function efArrayExtensionWords( $lang ) {
1111 $words = array();
12 -
 12+
1313 /**
1414 * English
1515 */
@@ -19,7 +19,7 @@
2020 'arraysize' => array( 0, 'arraysize' ),
2121 'arrayindex' => array( 0, 'arrayindex' ),
2222 'arraysearch' => array( 0, 'arraysearch' ),
23 -
 23+
2424 'arrayunique' => array( 0, 'arrayunique' ),
2525 'arraysort' => array( 0, 'arraysort' ),
2626 'arrayreset' => array( 0, 'arrayreset' ),
@@ -32,7 +32,7 @@
3333 'arraydiff' => array( 0, 'arraydiff' ),
3434 'arraysearcharray' => array( 0, 'arraysearcharray' ),
3535 );
36 -
 36+
3737 # English is used as a fallback, and the English synonyms are
3838 # used if a translation has not been provided for a given word
3939 return ( $lang == 'en' || !isset( $words[$lang] ) )
Index: trunk/extensions/ArrayExtension/ArrayExtension.php
@@ -13,40 +13,40 @@
1414
1515 - add experimental table (2 dimension array) data structure
1616 * table = header, row+ (1,1....)
17 - * sort_table_by_header (header)
18 - * sort_table_by_col (col)
 17+ * sort_table_by_header (header)
 18+ * sort_table_by_col (col)
1919 * print_table (format) e.g. csv, ul, ol,
20 - * add_table_row (array)
 20+ * add_table_row (array)
2121 * get_table_row (row) to an array
22 - * add_table_col(array)
 22+ * add_table_col(array)
2323 * get_table_col (col) to an array
2424 * get_table_header () to an array
2525 * get_total_row
2626 * get_total_col
2727
2828 */
29 -
 29+
3030 if ( ! defined( 'MEDIAWIKI' ) ) {
3131 die( 'This file is a MediaWiki extension, it is not a valid entry point' );
3232 }
3333
3434 $wgExtensionFunctions[] = 'efSetupArrayExtension';
35 -
 35+
3636 $wgExtensionCredits['parserhook'][] = array(
3737 'name' => 'ArrayExtension',
3838 'url' => 'http://www.mediawiki.org/wiki/Extension:ArrayExtension',
39 - 'author' => array ('Li Ding', 'Jie Bao', 'Daniel Werner'),
 39+ 'author' => array ( 'Li Ding', 'Jie Bao', 'Daniel Werner' ),
4040 'description' => 'Store and compute named arrays',
4141 'version' => ArrayExtension::VERSION,
4242
4343 );
44 -
 44+
4545 $wgHooks['LanguageGetMagic'][] = 'efArrayExtensionLanguageGetMagic';
4646
4747
4848 /**
4949 * named arrays - an array has a list of values, and could be set to a SET
50 - */
 50+ */
5151 class ArrayExtension {
5252
5353 const VERSION = '1.3.2';
@@ -57,18 +57,18 @@
5858 global $wgHooks;
5959 $wgHooks['ParserClearState'][] = &$this;
6060 }
61 -
 61+
6262 function onParserClearState( &$parser ) {
63 - $this->mArrayExtension = array(); //remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates
 63+ $this->mArrayExtension = array(); // remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates
6464 return true;
6565 }
66 -
67 - ///////////////////////////////////////////////////////////
 66+
 67+ ////////////////////////////////////////////////////////// /
6868 // PART 1. constructor
69 - ///////////////////////////////////////////////////////////
70 -
 69+ ////////////////////////////////////////////////////////// /
 70+
7171 /**
72 - * Define an array by a list of 'values' deliminated by 'delimiter',
 72+ * Define an array by a list of 'values' deliminated by 'delimiter',
7373 * the delimiter should be perl regular expression pattern
7474 * usage:
7575 * {{#arraydefine:arrayid|values|delimiter|options}}
@@ -76,61 +76,61 @@
7777 * http://us2.php.net/manual/en/book.pcre.php
7878 * see also: http://us2.php.net/manual/en/function.preg-split.php
7979 */
80 - function arraydefine( &$parser, $arrayid, $value='', $delimiter = '/\s*,\s*/', $options = '', $delimiter2= ', ', $search='@@@@', $subject='@@@@', $frame=null) {
81 - if (!isset($arrayid))
 80+ function arraydefine( &$parser, $arrayid, $value = '', $delimiter = '/\s*,\s*/', $options = '', $delimiter2 = ', ', $search = '@@@@', $subject = '@@@@', $frame = null ) {
 81+ if ( !isset( $arrayid ) )
8282 return '';
8383
84 - //normalize
85 - $value = trim($value);
86 - $delimiter = trim($delimiter);
87 -
88 - if (!$this->is_non_empty ($value) ){
 84+ // normalize
 85+ $value = trim( $value );
 86+ $delimiter = trim( $delimiter );
 87+
 88+ if ( !$this->is_non_empty ( $value ) ) {
8989 $this->mArrayExtension[$arrayid] = array();
90 - }else if (!$this->is_non_empty($delimiter)){
 90+ } else if ( !$this->is_non_empty( $delimiter ) ) {
9191 $this->mArrayExtension[$arrayid] = array( $value );
92 - }else{
 92+ } else {
9393 if ( !$this->isValidRegEx( $delimiter ) )
94 - $delimiter = '/\s*' . preg_quote( $delimiter, '/' ) . '\s*/'; //Anpassung von Daniel Werner (preg_quote)
95 -
96 - $this->mArrayExtension[$arrayid] = preg_split($delimiter, $value);
97 -
 94+ $delimiter = '/\s*' . preg_quote( $delimiter, '/' ) . '\s*/'; // Anpassung von Daniel Werner (preg_quote)
 95+
 96+ $this->mArrayExtension[$arrayid] = preg_split( $delimiter, $value );
 97+
9898 // validate if the array has been successfully created
99 - $ret = $this->validate_array_by_arrayid($arrayid);
100 - if ($ret !== true){
 99+ $ret = $this->validate_array_by_arrayid( $arrayid );
 100+ if ( $ret !== true ) {
101101 return '';
102102 }
103 -
 103+
104104 // now parse the options, and do posterior process on the created array
105 - $ary_option = $this->parse_options($options);
106 -
 105+ $ary_option = $this->parse_options( $options );
 106+
107107 // make it unique if option is set
108 - if (FALSE !== array_key_exists('unique', $ary_option)){
109 - $this->arrayunique($parser, $arrayid);
 108+ if ( FALSE !== array_key_exists( 'unique', $ary_option ) ) {
 109+ $this->arrayunique( $parser, $arrayid );
110110 }
111 -
 111+
112112 // sort array if the option is set
113 - $this->arraysort($parser, $arrayid, $this->get_array_value($ary_option,"sort"));
 113+ $this->arraysort( $parser, $arrayid, $this->get_array_value( $ary_option, "sort" ) );
114114
115115 // print the array upon request
116 - if (strcmp("list", $this->get_array_value($ary_option,"print"))===0){
117 - return $this->arrayprint($parser, $arrayid);
118 - }else if (strcmp("full", $this->get_array_value($ary_option,"print"))===0){
119 - return $this->arrayprint($parser, $arrayid, $delimiter2, $search, $subject, $frame);
 116+ if ( strcmp( "list", $this->get_array_value( $ary_option, "print" ) ) === 0 ) {
 117+ return $this->arrayprint( $parser, $arrayid );
 118+ } else if ( strcmp( "full", $this->get_array_value( $ary_option, "print" ) ) === 0 ) {
 119+ return $this->arrayprint( $parser, $arrayid, $delimiter2, $search, $subject, $frame );
120120 }
121121 }
122 -
 122+
123123 return '';
124124 }
125125
126126
127 - ///////////////////////////////////////////////////////////
 127+ ////////////////////////////////////////////////////////// /
128128 // PART 2. print
129 - ///////////////////////////////////////////////////////////
 129+ ////////////////////////////////////////////////////////// /
130130
131131
132132 /**
133133 * print an array.
134 - * foreach element of the array, print 'subject' where all occurrences of 'search' is replaced with the element,
 134+ * foreach element of the array, print 'subject' where all occurrences of 'search' is replaced with the element,
135135 * and each element print-out is deliminated by 'delimiter'
136136 * The subject can embed parser functions; wiki links; and templates.
137137 * usage:
@@ -142,34 +142,34 @@
143143 * {{#arrayprint:b|<br/>|@@@|{{#set:prop=@@@}} }} -- embed parser function
144144 * {{#arrayprint:b|<br/>|@@@|{{f.tag{{f.print.vbar}}prop{{f.print.vbar}}@@@}} }} -- embed template function
145145 * {{#arrayprint:b|<br/>|@@@|[[name::@@@]]}} -- make SMW links
146 - */
147 - function arrayprint( &$parser, $arrayid , $delimiter = ', ', $search='@@@@', $subject='@@@@', $frame=null) {
148 - $ret = $this->validate_array_by_arrayid($arrayid);
149 - if ($ret !== true){
 146+ */
 147+ function arrayprint( &$parser, $arrayid , $delimiter = ', ', $search = '@@@@', $subject = '@@@@', $frame = null ) {
 148+ $ret = $this->validate_array_by_arrayid( $arrayid );
 149+ if ( $ret !== true ) {
150150 return $ret;
151151 }
152 -
153 - $values=$this->mArrayExtension[$arrayid];
154 - $rendered_values= array();
155 - foreach($values as $v){
156 - $temp_result_value = str_replace($search, $v, $subject);
157 - if (isset($frame)){
158 - $temp_result_value = $parser->preprocessToDom($temp_result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0);
159 - $temp_result_value = trim($frame->expand($temp_result_value));
160 - }
 152+
 153+ $values = $this->mArrayExtension[$arrayid];
 154+ $rendered_values = array();
 155+ foreach ( $values as $v ) {
 156+ $temp_result_value = str_replace( $search, $v, $subject );
 157+ if ( isset( $frame ) ) {
 158+ $temp_result_value = $parser->preprocessToDom( $temp_result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 );
 159+ $temp_result_value = trim( $frame->expand( $temp_result_value ) );
 160+ }
161161 $rendered_values[] = $temp_result_value ;
162162 }
163 - return array(implode( $delimiter, $rendered_values) , 'noparse' => false, 'isHTML' => false);
 163+ return array( implode( $delimiter, $rendered_values ) , 'noparse' => false, 'isHTML' => false );
164164 }
165 -
 165+
166166 function arrayprintObj( &$parser, $frame, $args ) {
167167 // Set variables
168 - $arrayid = isset($args[0]) ? trim($frame->expand($args[0])) : '';
169 - $delimiter = isset($args[1]) ? trim($frame->expand($args[1])) : ', ';
170 - $search = isset($args[2]) ? trim($frame->expand($args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES)) : '@@@@';
171 - $subject = isset($args[3]) ? trim($frame->expand($args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES)) : '@@@@';
 168+ $arrayid = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
 169+ $delimiter = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ', ';
 170+ $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@';
 171+ $subject = isset( $args[3] ) ? trim( $frame->expand( $args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@';
172172
173 - return $this->arrayprint($parser, $arrayid, $delimiter, $search, $subject, $frame);
 173+ return $this->arrayprint( $parser, $arrayid, $delimiter, $search, $subject, $frame );
174174 }
175175
176176
@@ -178,23 +178,23 @@
179179 * usage:
180180 * {{#arrayindex:arrayid|index}}
181181 */
182 - function arrayindex( &$parser, $arrayid , $index , $options='') {
 182+ function arrayindex( &$parser, $arrayid , $index , $options = '' ) {
183183 // now parse the options, and do posterior process on the created array
184 - $ary_option = $this->parse_options($options);
 184+ $ary_option = $this->parse_options( $options );
185185
186 - $ret = $this->validate_array_by_arrayid($arrayid);
187 - if ($ret !== true){
188 - return $this->get_array_value($ary_option,"default");
 186+ $ret = $this->validate_array_by_arrayid( $arrayid );
 187+ if ( $ret !== true ) {
 188+ return $this->get_array_value( $ary_option, "default" );
189189 }
190190
191 - $ret = $this->validate_array_index($index, $this->mArrayExtension[$arrayid]);
192 - if ($ret !== true){
193 - return $this->get_array_value($ary_option,"default");
 191+ $ret = $this->validate_array_index( $index, $this->mArrayExtension[$arrayid] );
 192+ if ( $ret !== true ) {
 193+ return $this->get_array_value( $ary_option, "default" );
194194 }
195195
196196 return $this->mArrayExtension[$arrayid][$index];
197197 }
198 -
 198+
199199 /**
200200 * return size of array.
201201 * Print the size (number of elements) in the specified array
@@ -203,19 +203,19 @@
204204 *
205205 * See: http://www.php.net/manual/en/function.count.php
206206 */
207 - function arraysize( &$parser, $arrayid) {
208 - $ret = $this->validate_array_by_arrayid($arrayid);
209 - if ($ret !== true){
 207+ function arraysize( &$parser, $arrayid ) {
 208+ $ret = $this->validate_array_by_arrayid( $arrayid );
 209+ if ( $ret !== true ) {
210210 return '';
211211 }
212 -
213 - return count ($this->mArrayExtension[$arrayid]);
 212+
 213+ return count ( $this->mArrayExtension[$arrayid] );
214214 }
215215
216216
217217
218218
219 -
 219+
220220 /**
221221 * locate the index of the first occurence of an element starting from the 'index'
222222 * - print "-1" (not found) or index (found) to show the index of the first occurence of 'value' in the array identified by arrayid
@@ -227,34 +227,34 @@
228228 * See: http://www.php.net/manual/en/function.array-search.php
229229 * note it is extended to support regular expression match and index
230230 */
231 - function arraysearch( &$parser, $arrayid, $needle = '/^\s*$/', $index = 0, $yes = null, $no = '-1') {
232 - $ret = $this->validate_array_by_arrayid($arrayid);
233 - if ($ret !== true)
 231+ function arraysearch( &$parser, $arrayid, $needle = '/^\s*$/', $index = 0, $yes = null, $no = '-1' ) {
 232+ $ret = $this->validate_array_by_arrayid( $arrayid );
 233+ if ( $ret !== true )
234234 return $no;
235 -
236 - $ret = $this->validate_array_index($index, $this->mArrayExtension[$arrayid]);
 235+
 236+ $ret = $this->validate_array_index( $index, $this->mArrayExtension[$arrayid] );
237237 if ( !$ret )
238238 return $no;
239 -
 239+
240240 if ( !$this->isValidRegEx( $needle ) )
241241 $needle = '/^\s*' . preg_quote( $needle, '/' ) . '\s*$/';
242 -
243 - //search for a match inside the array:
244 - for ($i=$index; $i < count($this->mArrayExtension[$arrayid]); $i++){
 242+
 243+ // search for a match inside the array:
 244+ for ( $i = $index; $i < count( $this->mArrayExtension[$arrayid] ); $i++ ) {
245245 $value = $this->mArrayExtension[$arrayid][$i];
246246
247 - if (preg_match($needle, $value)){
248 - if (isset($yes))
 247+ if ( preg_match( $needle, $value ) ) {
 248+ if ( isset( $yes ) )
249249 return $yes;
250250 else
251251 return $i;
252252 }
253253 }
254 -
255 - //no match:
 254+
 255+ // no match:
256256 return $no;
257257 }
258 -
 258+
259259 /**
260260 * search an array and create a new array with all the results. Transforming the new entries before storing them is possible too.
261261 * usage:
@@ -264,78 +264,78 @@
265265 * "$n" where "n" stands for a number to access a variable from the regex result.
266266 */
267267 function arraysearcharray( &$parser, $arrayid_new, $arrayid, $needle = '/^(\s*)$/', $index = 0, $limit = -1, $transform = '' ) {
268 - $ret = $this->validate_array_by_arrayid($arrayid);
269 - if( !$ret )
 268+ $ret = $this->validate_array_by_arrayid( $arrayid );
 269+ if ( !$ret )
270270 return '';
271 -
272 - if( !isset($arrayid_new) )
 271+
 272+ if ( !isset( $arrayid_new ) )
273273 return '';
274 -
275 - if( !is_numeric($index) )
 274+
 275+ if ( !is_numeric( $index ) )
276276 $index = 0;
277 -
278 - if( !is_numeric($limit) )
 277+
 278+ if ( !is_numeric( $limit ) )
279279 $limit = -1;
280 -
281 - //calculate start index for negative start indexes:
282 - if( $index < 0 ) {
 280+
 281+ // calculate start index for negative start indexes:
 282+ if ( $index < 0 ) {
283283 $index = count( $this->mArrayExtension[$arrayid] ) + $index;
284 - if( $index < 0 ) $index = 0;
 284+ if ( $index < 0 ) $index = 0;
285285 }
286 -
 286+
287287 $newArr = array();
288288 $newArrSize = 0;
289 -
 289+
290290 if ( !$this->isValidRegEx( $needle ) )
291291 $needle = '/^\s*(' . preg_quote( $needle, '/' ) . ')\s*$/';
292 -
293 - //search the array for all matches and put them in the new array
294 - for ($i = $index; $i < count($this->mArrayExtension[$arrayid]); $i++)
295 - {
 292+
 293+ // search the array for all matches and put them in the new array
 294+ for ( $i = $index; $i < count( $this->mArrayExtension[$arrayid] ); $i++ )
 295+ {
296296 $value = $this->mArrayExtension[$arrayid][$i];
297 -
298 - if( preg_match($needle, $value) ) {
299 - if( $transform != '' ) {
 297+
 298+ if ( preg_match( $needle, $value ) ) {
 299+ if ( $transform != '' ) {
300300 $value = preg_replace( $needle, $transform, $value );
301301 }
302302 $newArr[] = $value;
303303 $newArrSize++;
304 - //stop if limit is reached
305 - if( $newArrSize == $limit )
 304+ // stop if limit is reached
 305+ if ( $newArrSize == $limit )
306306 break;
307307 }
308308 }
309 -
 309+
310310 $this->mArrayExtension[$arrayid_new] = $newArr;
311311 return '';
312312 }
313 -
314313
315314
316 - ///////////////////////////////////////////////////////////
317 - // PART 3. alter an array
318 - ///////////////////////////////////////////////////////////
319 -
 315+
 316+ ////////////////////////////////////////////////////////// /
 317+ // PART 3. alter an array
 318+ ////////////////////////////////////////////////////////// /
 319+
320320 /**
321321 * reset some or all defined arrayes
322322 * usage:
323323 * {{#arrayreset:}}
324324 * {{#arrayreset:arrayid1,arrayid2,...arrayidn}}
325325 */
326 - function arrayreset( &$parser, $arrayids) {
327 - if (!$this->is_non_empty($arrayids)){
328 - //reset all
 326+ function arrayreset( &$parser, $arrayids ) {
 327+ if ( !$this->is_non_empty( $arrayids ) ) {
 328+ // reset all
329329 $this->mArrayExtension = array();
330 - }else{
331 - $arykeys = explode(',', $arrayids);
332 - foreach ($arykeys as $arrayid){
 330+ } else {
 331+ $arykeys = explode( ',', $arrayids );
 332+ foreach ( $arykeys as $arrayid ) {
333333 $this->removeArray( $arrayids );
334334 }
335335 }
336336 return '';
337 - }
338 -
339 -
 337+ }
 338+
 339+
340340 /**
341341 * convert an array to set
342342 * convert the array identified by arrayid into a set (all elements are unique)
@@ -345,20 +345,20 @@
346346 * see: http://www.php.net/manual/en/function.array-unique.php
347347 */
348348 function arrayunique( &$parser, $arrayid ) {
349 - $ret = $this->validate_array_by_arrayid($arrayid);
350 - if ($ret !== true){
 349+ $ret = $this->validate_array_by_arrayid( $arrayid );
 350+ if ( $ret !== true ) {
351351 return '';
352352 }
353353
354 - $this->mArrayExtension[$arrayid]= array_unique ($this->mArrayExtension[$arrayid]);
355 - $values= array();
356 - foreach ($this->mArrayExtension[$arrayid] as $v){
357 - //if (!isset($v))
358 - if (strlen($v)>0)
359 - $values[]=$v;
 354+ $this->mArrayExtension[$arrayid] = array_unique ( $this->mArrayExtension[$arrayid] );
 355+ $values = array();
 356+ foreach ( $this->mArrayExtension[$arrayid] as $v ) {
 357+ // if (!isset($v))
 358+ if ( strlen( $v ) > 0 )
 359+ $values[] = $v;
360360 }
361361 $this->mArrayExtension[$arrayid] = $values;
362 - }
 362+ }
363363
364364
365365 /**
@@ -370,75 +370,75 @@
371371 * - reverse: Return an array with elements in reverse order
372372 * usage:
373373 * {{#arraysort:arrayid|order}}
374 - *
 374+ *
375375 * see: http://www.php.net/manual/en/function.sort.php
376376 * http://www.php.net/manual/en/function.rsort.php
377377 * http://www.php.net/manual/en/function.shuffle.php
378378 * http://us3.php.net/manual/en/function.array-reverse.php
379 - */
380 - function arraysort( &$parser, $arrayid , $sort = 'none') {
381 - $ret = $this->validate_array_by_arrayid($arrayid);
382 - if ($ret !== true){
 379+ */
 380+ function arraysort( &$parser, $arrayid , $sort = 'none' ) {
 381+ $ret = $this->validate_array_by_arrayid( $arrayid );
 382+ if ( $ret !== true ) {
383383 return '';
384384 }
385385
386386
387 - switch ($sort){
388 - case 'asc':
389 - case 'asce':
390 - case 'ascending': sort($this->mArrayExtension[$arrayid]); break;
 387+ switch ( $sort ) {
 388+ case 'asc':
 389+ case 'asce':
 390+ case 'ascending': sort( $this->mArrayExtension[$arrayid] ); break;
391391
392392
393 - case 'desc':
394 - case 'descending': rsort($this->mArrayExtension[$arrayid]); break;
395 -
396 - case 'random': shuffle($this->mArrayExtension[$arrayid]); break;
 393+ case 'desc':
 394+ case 'descending': rsort( $this->mArrayExtension[$arrayid] ); break;
397395
 396+ case 'random': shuffle( $this->mArrayExtension[$arrayid] ); break;
398397
399 - case 'reverse': $this->mArrayExtension[$arrayid]= array_reverse($this->mArrayExtension[$arrayid]); break;
400 - };
401 - }
402 -
403 -
404 - ///////////////////////////////////////////////////////////
405 - // PART 4. create an array
406 - ///////////////////////////////////////////////////////////
407 -
 398+
 399+ case 'reverse': $this->mArrayExtension[$arrayid] = array_reverse( $this->mArrayExtension[$arrayid] ); break;
 400+ } ;
 401+ }
 402+
 403+
 404+ ////////////////////////////////////////////////////////// /
 405+ // PART 4. create an array
 406+ ////////////////////////////////////////////////////////// /
 407+
408408 /**
409 - * merge two arrays, keep duplicated values
 409+ * merge two arrays, keep duplicated values
410410 * usage:
411411 * {{#arraymerge:arrayid_new|arrayid1|arrayid2}}
412 - *
 412+ *
413413 * merge values two arrayes identified by arrayid1 and arrayid2 into a new array identified by arrayid_new.
414414 * this merge differs from array_merge of php because it merges values.
415 - */
416 - function arraymerge( &$parser, $arrayid_new, $arrayid1, $arrayid2='' ) {
417 - if (!isset($arrayid_new) )
 415+ */
 416+ function arraymerge( &$parser, $arrayid_new, $arrayid1, $arrayid2 = '' ) {
 417+ if ( !isset( $arrayid_new ) )
418418 return '';
419419
420 - $ret = $this->validate_array_by_arrayid($arrayid1);
421 - if ($ret !== true){
 420+ $ret = $this->validate_array_by_arrayid( $arrayid1 );
 421+ if ( $ret !== true ) {
422422 return '';
423423 }
424 -
 424+
425425 $temp_array = array();
426 - foreach ($this->mArrayExtension[$arrayid1] as $entry){
427 - array_push ($temp_array, $entry);
 426+ foreach ( $this->mArrayExtension[$arrayid1] as $entry ) {
 427+ array_push ( $temp_array, $entry );
428428 }
429429
430 - if ( isset($arrayid2) && strlen($arrayid2)>0){
431 - $ret = $this->validate_array_by_arrayid($arrayid2);
432 - if ( $ret === true ){
433 - foreach ($this->mArrayExtension[$arrayid2] as $entry){
434 - array_push ($temp_array, $entry);
 430+ if ( isset( $arrayid2 ) && strlen( $arrayid2 ) > 0 ) {
 431+ $ret = $this->validate_array_by_arrayid( $arrayid2 );
 432+ if ( $ret === true ) {
 433+ foreach ( $this->mArrayExtension[$arrayid2] as $entry ) {
 434+ array_push ( $temp_array, $entry );
435435 }
436436 }
437437 }
438 -
 438+
439439 $this->mArrayExtension[$arrayid_new] = $temp_array;
440440 return '';
441441 }
442 -
 442+
443443 /**
444444 * extract a slice from an array
445445 * usage:
@@ -446,32 +446,32 @@
447447 *
448448 * extract a slice from an array
449449 * see: http://www.php.net/manual/en/function.array-slice.php
450 - */
451 - function arrayslice( &$parser, $arrayid_new , $arrayid , $offset, $length='') {
452 - if (!isset($arrayid_new) )
 450+ */
 451+ function arrayslice( &$parser, $arrayid_new , $arrayid , $offset, $length = '' ) {
 452+ if ( !isset( $arrayid_new ) )
453453 return '';
454454
455 - $ret = $this->validate_array_by_arrayid($arrayid);
456 - if ($ret !== true){
 455+ $ret = $this->validate_array_by_arrayid( $arrayid );
 456+ if ( $ret !== true ) {
457457 return '';
458458 }
459459
460 - //$ret = $this->validate_array_offset($offset, $this->mArrayExtension[$arrayid]);
461 - //if ($ret !== true){
 460+ // $ret = $this->validate_array_offset($offset, $this->mArrayExtension[$arrayid]);
 461+ // if ($ret !== true){
462462 // return '';
463 - //}
464 -
 463+ // }
 464+
465465 $temp_array = array();
466 - if (is_numeric($offset)){
467 - if ($this->is_non_empty($length) && is_numeric($length)){
468 - $temp = array_slice($this->mArrayExtension[$arrayid], $offset, $length);
469 - }else{
470 - $temp = array_slice($this->mArrayExtension[$arrayid], $offset);
 466+ if ( is_numeric( $offset ) ) {
 467+ if ( $this->is_non_empty( $length ) && is_numeric( $length ) ) {
 468+ $temp = array_slice( $this->mArrayExtension[$arrayid], $offset, $length );
 469+ } else {
 470+ $temp = array_slice( $this->mArrayExtension[$arrayid], $offset );
471471 }
472 -
473 - if (!empty($temp) && is_array($temp))
474 - $temp_array = array_values($temp);
475 - }
 472+
 473+ if ( !empty( $temp ) && is_array( $temp ) )
 474+ $temp_array = array_values( $temp );
 475+ }
476476 $this->mArrayExtension[$arrayid_new] = $temp_array;
477477 return '';
478478 }
@@ -480,225 +480,225 @@
481481 * set operation, {red, white} = {red, white} union {red}
482482 * usage:
483483 * {{#arrayunion:arrayid_new|arrayid1|arrayid2}}
484 -
 484+
485485 * similar to arraymerge, this union works on values.
486 - */
 486+ */
487487 function arrayunion( &$parser, $arrayid_new , $arrayid1 , $arrayid2 ) {
488 - if (!isset($arrayid_new) )
 488+ if ( !isset( $arrayid_new ) )
489489 return '';
490490
491491
492 - $ret = $this->validate_array_by_arrayid($arrayid1);
493 - if ($ret !== true){
 492+ $ret = $this->validate_array_by_arrayid( $arrayid1 );
 493+ if ( $ret !== true ) {
494494 return '';
495495 }
496496
497 - $ret = $this->validate_array_by_arrayid($arrayid2);
498 - if ($ret !== true){
 497+ $ret = $this->validate_array_by_arrayid( $arrayid2 );
 498+ if ( $ret !== true ) {
499499 return '';
500500 }
501 -
502 - $this->arraymerge($parser, $arrayid_new, $arrayid1, $arrayid2);
503 - $this->mArrayExtension[$arrayid_new] = array_unique ($this->mArrayExtension[$arrayid_new]);
504 -
 501+
 502+ $this->arraymerge( $parser, $arrayid_new, $arrayid1, $arrayid2 );
 503+ $this->mArrayExtension[$arrayid_new] = array_unique ( $this->mArrayExtension[$arrayid_new] );
 504+
505505 return '';
506506 }
507507
508 - //////////////////////////////////////////////////
 508+ ///////////////////////////////////////////////// /
509509 // SET OPERATIONS: a set does not have duplicated element
510 -
 510+
511511 /**
512512 * set operation, {red} = {red, white} intersect {red,black}
513513 * usage:
514514 * {{#arrayintersect:arrayid_new|arrayid1|arrayid2}}
515515 * See: http://www.php.net/manual/en/function.array-intersect.php
516 - */
 516+ */
517517 function arrayintersect( &$parser, $arrayid_new , $arrayid1 , $arrayid2 ) {
518 - if (!isset($arrayid_new) )
 518+ if ( !isset( $arrayid_new ) )
519519 return '';
520520
521 - $ret = $this->validate_array_by_arrayid($arrayid1);
522 - if ($ret !== true){
 521+ $ret = $this->validate_array_by_arrayid( $arrayid1 );
 522+ if ( $ret !== true ) {
523523 return '';
524524 }
525 -
526 - $ret = $this->validate_array_by_arrayid($arrayid2);
527 - if ($ret !== true){
 525+
 526+ $ret = $this->validate_array_by_arrayid( $arrayid2 );
 527+ if ( $ret !== true ) {
528528 return '';
529529 }
530 -
531 - //keys will be preserved...
532 - $newArray = array_intersect( array_unique($this->mArrayExtension[$arrayid1]), array_unique($this->mArrayExtension[$arrayid2]) );
533 -
534 - //...so we have to reorganize the key order
535 - $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys($newArray);
536 -
 530+
 531+ // keys will be preserved...
 532+ $newArray = array_intersect( array_unique( $this->mArrayExtension[$arrayid1] ), array_unique( $this->mArrayExtension[$arrayid2] ) );
 533+
 534+ // ...so we have to reorganize the key order
 535+ $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys( $newArray );
 536+
537537 return '';
538538 }
539 -
 539+
540540 /**
541541 *
542542 * usage:
543543 * {{#arraydiff:arrayid_new|arrayid1|arrayid2}}
544 -
 544+
545545 * set operation, {white} = {red, white} - {red}
546546 * see: http://www.php.net/manual/en/function.array-diff.php
547547 */
548548 function arraydiff( &$parser, $arrayid_new , $arrayid1 , $arrayid2 ) {
549 - if (!isset($arrayid_new) )
 549+ if ( !isset( $arrayid_new ) )
550550 return '';
551551
552 - $ret = $this->validate_array_by_arrayid($arrayid1);
553 - if ($ret !== true){
 552+ $ret = $this->validate_array_by_arrayid( $arrayid1 );
 553+ if ( $ret !== true ) {
554554 return '';
555555 }
556556
557 - $ret = $this->validate_array_by_arrayid($arrayid2);
558 - if ($ret !== true){
 557+ $ret = $this->validate_array_by_arrayid( $arrayid2 );
 558+ if ( $ret !== true ) {
559559 return '';
560560 }
561561
562 - //keys will be preserved...
563 - $newArray = array_diff( array_unique($this->mArrayExtension[$arrayid1]),array_unique($this->mArrayExtension[$arrayid2]));
 562+ // keys will be preserved...
 563+ $newArray = array_diff( array_unique( $this->mArrayExtension[$arrayid1] ), array_unique( $this->mArrayExtension[$arrayid2] ) );
564564
565 - //...so we have to reorganize the key order
566 - $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys($newArray);
567 -
 565+ // ...so we have to reorganize the key order
 566+ $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys( $newArray );
 567+
568568 return '';
569 - }
 569+ }
570570
571571
572572
573 - //////////////////////////////////////////////////
 573+ ///////////////////////////////////////////////// /
574574 // private functions
575 - //////////////////////////////////////////////////
576 -
577 - function is_non_empty($var){
578 - return isset($var) && strlen($var)>0;
 575+ ///////////////////////////////////////////////// /
 576+
 577+ function is_non_empty( $var ) {
 578+ return isset( $var ) && strlen( $var ) > 0;
579579 }
580 -
 580+
581581 // private functions for validating the index of an array
582 - function validate_array_index($index, $array){
583 - if (!isset($index))
 582+ function validate_array_index( $index, $array ) {
 583+ if ( !isset( $index ) )
584584 return false;
585585
586 - if (!is_numeric($index))
 586+ if ( !is_numeric( $index ) )
587587 return false;
588588
589 - if (!isset($array) || !is_array($array))
 589+ if ( !isset( $array ) || !is_array( $array ) )
590590 return false;
591 -
592 - if (!array_key_exists($index, $array)) /*($index<0 || $index>=count($array))*/
 591+
 592+ if ( !array_key_exists( $index, $array ) ) /*($index<0 || $index>=count($array))*/
593593 return false;
594 -
 594+
595595 return true;
596 - }
 596+ }
597597
598598 // private functions for validating the index of an array
599 - function validate_array_offset($offset, $array){
600 - if (!isset($offset))
 599+ function validate_array_offset( $offset, $array ) {
 600+ if ( !isset( $offset ) )
601601 return false;
602602
603603
604 - if (!is_numeric($offset))
 604+ if ( !is_numeric( $offset ) )
605605 return false;
606606
607607
608 - if (!isset($array) || !is_array($array))
 608+ if ( !isset( $array ) || !is_array( $array ) )
609609 return false;
610 -
611 - if ( $offset>=count($array))
 610+
 611+ if ( $offset >= count( $array ) )
612612 return false;
613 -
 613+
614614 return true;
615615 }
616 -
617 - //private function for validating array by name
618 - function validate_array_by_arrayid($array_name){
619 - if (!isset($array_name))
 616+
 617+ // private function for validating array by name
 618+ function validate_array_by_arrayid( $array_name ) {
 619+ if ( !isset( $array_name ) )
620620 return '';
621 -
622 - if (!isset($this->mArrayExtension))
 621+
 622+ if ( !isset( $this->mArrayExtension ) )
623623 return "undefined array: $array_name";
624 -
625 - if (!array_key_exists($array_name,$this->mArrayExtension) || !is_array($this->mArrayExtension[$array_name]))
 624+
 625+ if ( !array_key_exists( $array_name, $this->mArrayExtension ) || !is_array( $this->mArrayExtension[$array_name] ) )
626626 return "undefined array: $array_name";
627 -
 627+
628628 return true;
629629 }
630630
631 - function get_array_value($array, $field){
632 - if (is_array($array) && FALSE !== array_key_exists($field, $array))
 631+ function get_array_value( $array, $field ) {
 632+ if ( is_array( $array ) && FALSE !== array_key_exists( $field, $array ) )
633633 return $array[$field];
634634 else
635635 return '';
636636 }
637637
638 - function parse_options($options){
639 - if (isset($options)){
 638+ function parse_options( $options ) {
 639+ if ( isset( $options ) ) {
640640 // now parse the options, and do posterior process on the created array
641 - $ary_option = preg_split ('/\s*[,]\s*/', strtolower($options));
 641+ $ary_option = preg_split ( '/\s*[,]\s*/', strtolower( $options ) );
642642 }
643 -
 643+
644644 $ret = array();
645 - if (isset($ary_option) && is_array($ary_option) && sizeof($ary_option)>0){
646 - foreach ($ary_option as $option){
647 - $ary_pair = explode('=', $option,2);
648 - if (sizeof($ary_pair)==1){
 645+ if ( isset( $ary_option ) && is_array( $ary_option ) && sizeof( $ary_option ) > 0 ) {
 646+ foreach ( $ary_option as $option ) {
 647+ $ary_pair = explode( '=', $option, 2 );
 648+ if ( sizeof( $ary_pair ) == 1 ) {
649649 $ret[$ary_pair[0]] = true;
650 - }else{
 650+ } else {
651651 $ret[$ary_pair[0]] = $ary_pair[1];
652652 }
653653 }
654 - }
 654+ }
655655 return $ret;
656656 }
657 -
658 - /* ============================ */
 657+
659658 /* ============================ */
 659+ /* ============================ */
660660 /* === === */
661661 /* === HELPER FUNCTIONS === */
662662 /* === === */
663 - /* ============================ */
664663 /* ============================ */
 664+ /* ============================ */
665665
666 - function getArrayValue( $arrayId='', $key='' ) {
 666+ function getArrayValue( $arrayId = '', $key = '' ) {
667667 $arrayId = trim( $arrayId );
668 - if( $this->arrayExists( $arrayId ) && array_key_exists( $key, $this->mArrayExtension[ $arrayId ] ) )
 668+ if ( $this->arrayExists( $arrayId ) && array_key_exists( $key, $this->mArrayExtension[ $arrayId ] ) )
669669 return $this->mArrayExtension[ $arrayId ][ $key ];
670670 else
671671 return '';
672672 }
673 -
674 - //return an array identified by $arrayId. If it doesn't exist this will return null.
675 - function getArray( $arrayId='' ) {
676 - if( $this->arrayExists( $arrayId ) )
 673+
 674+ // return an array identified by $arrayId. If it doesn't exist this will return null.
 675+ function getArray( $arrayId = '' ) {
 676+ if ( $this->arrayExists( $arrayId ) )
677677 return $this->mArrayExtension[ $arrayId ];
678678 else
679679 return null;
680680 }
681 -
682 - function arrayExists( $arrayId='' ) {
683 - if( array_key_exists( trim( $arrayId ), $this->mArrayExtension ) )
684681
 682+ function arrayExists( $arrayId = '' ) {
 683+ if ( array_key_exists( trim( $arrayId ), $this->mArrayExtension ) )
685684
686685
 686+
687687 return true;
688688 else
689689 return false;
690690 }
691 -
692 - //add a new array or overwrite existing one. Values delivered as real array.
693 - function createArray( $arrayId='', $arr=array() ) {
 691+
 692+ // add a new array or overwrite existing one. Values delivered as real array.
 693+ function createArray( $arrayId = '', $arr = array() ) {
694694 $arr = $this->reorganizeArrayKeys( $arr );
695695 $this->mArrayExtension[ trim( $arrayId ) ] = $arr;
696696 }
697697
698 -
699 - //remove an existing array. If array doesn't exist this will return false, otherwise true.
700 - function removeArray( $arrayId='' ) {
 698+
 699+ // remove an existing array. If array doesn't exist this will return false, otherwise true.
 700+ function removeArray( $arrayId = '' ) {
701701 $arrayId = trim( $arrayId );
702 - if( $this->arrayExists( $arrayId ) ) {
 702+ if ( $this->arrayExists( $arrayId ) ) {
703703 unset( $this->mArrayExtension[ $arrayId ] );
704704 return true;
705705 } else {
@@ -707,30 +707,30 @@
708708
709709
710710 }
711 -
712 - //Rebuild the array and reorganize all keys. This means all gaps between array items will be closed.
713 - function reorganizeArrayKeys( $arr = array() ) {
714 - $newArray = array();
715 - foreach ($arr as $val){
 711+
 712+ // Rebuild the array and reorganize all keys. This means all gaps between array items will be closed.
 713+ function reorganizeArrayKeys( $arr = array() ) {
 714+ $newArray = array();
 715+ foreach ( $arr as $val ) {
716716 $newArray[] = trim( $val );
717 - }
 717+ }
718718 return $newArray;
719719 }
720 -
721 - //Decide for the given $pattern if its a valid regular expression or not
722 - function isValidRegEx( $pattern ) {
 720+
 721+ // Decide for the given $pattern if its a valid regular expression or not
 722+ function isValidRegEx( $pattern ) {
723723 return preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern );
724724 }
725725 }
726 -
 726+
727727 function efSetupArrayExtension() {
728728 global $wgParser, $wgArrayExtension;
729729
730 - $wgArrayExtension = new ArrayExtension;
 730+ $wgArrayExtension = new ArrayExtension;
731731 $wgParser->setFunctionHook( 'arraydefine', array( &$wgArrayExtension, 'arraydefine' ) );
732732
733 - if( defined( get_class( $wgParser) . '::SFH_OBJECT_ARGS' ) ) {
734 - $wgParser->setFunctionHook('arrayprint', array( &$wgArrayExtension, 'arrayprintObj' ), SFH_OBJECT_ARGS);
 733+ if ( defined( get_class( $wgParser ) . '::SFH_OBJECT_ARGS' ) ) {
 734+ $wgParser->setFunctionHook( 'arrayprint', array( &$wgArrayExtension, 'arrayprintObj' ), SFH_OBJECT_ARGS );
735735 } else {
736736 $wgParser->setFunctionHook( 'arrayprint', array( &$wgArrayExtension, 'arrayprint' ) );
737737 }
@@ -751,10 +751,10 @@
752752 $wgParser->setFunctionHook( 'arraydiff', array( &$wgArrayExtension, 'arraydiff' ) );
753753 $wgParser->setFunctionHook( 'arraysearcharray', array( &$wgArrayExtension, 'arraysearcharray' ) );
754754 }
755 -
 755+
756756 function efArrayExtensionLanguageGetMagic( &$magicWords, $langCode ) {
757757 require_once( dirname( __FILE__ ) . '/ArrayExtension.i18n.php' );
758 - foreach( efArrayExtensionWords( $langCode ) as $word => $trans )
 758+ foreach ( efArrayExtensionWords( $langCode ) as $word => $trans )
759759 $magicWords[$word] = $trans;
760760 return true;
761761 }
\ No newline at end of file

Status & tagging log