r104282 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104281‎ | r104282 | r104283 >
Date:17:23, 26 November 2011
Author:reedy
Status:deferred
Tags:
Comment:
Fixed mixed spaces and tabs

Trim trailing whitespace
Modified paths:
  • /trunk/extensions/Arrays/Arrays.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Arrays/Arrays.php
@@ -15,7 +15,7 @@
1616 * @author Li Ding < lidingpku@gmail.com >
1717 * @author Jie Bao
1818 * @author Daniel Werner < danweetz@web.de > (since version 1.3)
19 - *
 19+ *
2020 * @ToDo:
2121 * use $egArrayExtensionCompatbilityMode to finally get rid of unlogic behavior of certain functions
2222 * who create a new array from the data of one or more old arrays. In case only the new array name is
@@ -46,9 +46,9 @@
4747 * Full compatbility to versions before 1.4.
4848 * Set to true by default since version 2.0.
4949 * Regretable, this one has a speclling error...
50 - *
 50+ *
5151 * @since 1.4 alpha
52 - *
 52+ *
5353 * @var boolean
5454 */
5555 $egArrayExtensionCompatbilityMode = false;
@@ -57,32 +57,32 @@
5858 /**
5959 * Extension class with all the array functionality, also serves as store for arrays per
6060 * Parser object and offers public accessors for interaction with the 'Arrays' extension.
61 - *
 61+ *
6262 * @since 2.0 ('ArrayExtension' before and one global instance, also non-static parser functions)
6363 */
6464 class ExtArrays {
6565
6666 /**
6767 * Version of the 'Arrays' extension.
68 - *
 68+ *
6969 * @since 2.0 (before in 'Arrays' class since 1.3.2)
7070 */
7171 const VERSION = '2.0 alpha';
7272
7373 /**
7474 * Store for arrays.
75 - *
 75+ *
7676 * @var array
7777 * @private
7878 */
79 - var $mArrays = array();
 79+ var $mArrays = array();
8080
8181 /**
8282 * Sets up parser functions
83 - *
 83+ *
8484 * @since 2.0
8585 */
86 - public static function init( Parser &$parser ) {
 86+ public static function init( Parser &$parser ) {
8787 /*
8888 * store for arrays per Parser object. This will solve several bugs related to
8989 * 'ParserClearState' hook clearing all variables early in combination with certain
@@ -94,8 +94,8 @@
9595 self::initFunction( $parser, 'arraydefine' );
9696 self::initFunction( $parser, 'arrayprint', SFH_OBJECT_ARGS );
9797 self::initFunction( $parser, 'arrayindex', SFH_OBJECT_ARGS );
98 - self::initFunction( $parser, 'arraysize' );
99 - self::initFunction( $parser, 'arraysearch', SFH_OBJECT_ARGS );
 98+ self::initFunction( $parser, 'arraysize' );
 99+ self::initFunction( $parser, 'arraysearch', SFH_OBJECT_ARGS );
100100 self::initFunction( $parser, 'arraysearcharray' );
101101 self::initFunction( $parser, 'arrayslice' );
102102 self::initFunction( $parser, 'arrayreset', SFH_OBJECT_ARGS );
@@ -105,22 +105,22 @@
106106 self::initFunction( $parser, 'arrayunion', SFH_OBJECT_ARGS );
107107 self::initFunction( $parser, 'arraydiff', SFH_OBJECT_ARGS );
108108 self::initFunction( $parser, 'arrayintersect', SFH_OBJECT_ARGS );
109 -
 109+
110110 return true;
111111 }
112 - private static function initFunction( Parser &$parser, $name, $flags = 0 ) {
 112+ private static function initFunction( Parser &$parser, $name, $flags = 0 ) {
113113 // all parser functions with prefix:
114 - $prefix = ( $flags & SFH_OBJECT_ARGS ) ? 'pfObj_' : 'pf_';
 114+ $prefix = ( $flags & SFH_OBJECT_ARGS ) ? 'pfObj_' : 'pf_';
115115 $functionCallback = array( __CLASS__, $prefix . $name );
116 -
117 - $parser->setFunctionHook( $name, $functionCallback, $flags );
118 - }
119 -
 116+
 117+ $parser->setFunctionHook( $name, $functionCallback, $flags );
 118+ }
 119+
120120 /**
121121 * Returns the extensions base installation directory.
122122 *
123123 * @since 2.0
124 - *
 124+ *
125125 * @return boolean
126126 */
127127 public static function getDir() {
@@ -130,8 +130,8 @@
131131 }
132132 return $dir;
133133 }
134 -
135 -
 134+
 135+
136136 ####################
137137 # Parser Functions #
138138 ####################
@@ -149,31 +149,31 @@
150150 * http://us2.php.net/manual/en/book.pcre.php
151151 * see also: http://us2.php.net/manual/en/function.preg-split.php
152152 */
153 - static function pf_arraydefine(
 153+ static function pf_arraydefine(
154154 Parser &$parser,
155155 $arrayId,
156156 $value = null,
157157 $delimiter = '/\s*,\s*/',
158158 $options = ''
159159 ) {
160 - if ( !isset( $arrayId ) ) {
161 - return '';
162 - }
163 -
 160+ if ( !isset( $arrayId ) ) {
 161+ return '';
 162+ }
 163+
164164 $out = '';
165165 $array = array();
166166 $trimDone = false; // whether or not we can be sure that all array elements are trimmed
167 -
168 - // normalize
169 - $delimiter = trim( $delimiter );
170167
171 - if( $value === null ) {
 168+ // normalize
 169+ $delimiter = trim( $delimiter );
 170+
 171+ if( $value === null ) {
172172 // no element set, not even an empty one
173 - $array = array();
174 - }
 173+ $array = array();
 174+ }
175175 else {
176176 $value = trim( $value ); // just in case...
177 -
 177+
178178 // fill array with user input:
179179 if( $delimiter === '' ) {
180180 // whole input one element, also takes care of special case empty '' value and 'unique' option set
@@ -188,21 +188,21 @@
189189 }
190190 $array = preg_split( $delimiter, $value );
191191 }
192 -
 192+
193193 // trim all values before unique if still necessary, otherwise unique might not work correctly
194194 if( ! $trimDone ) {
195195 $array = self::sanitizeArray( $array );
196196 }
197197
198 - // now parse the options, and do posterior process on the created array
199 - $arrayOptions = self::parse_options( $options );
200 -
201 - // make it unique if option is set
202 - if( array_key_exists( 'unique', $arrayOptions ) ) {
 198+ // now parse the options, and do posterior process on the created array
 199+ $arrayOptions = self::parse_options( $options );
 200+
 201+ // make it unique if option is set
 202+ if( array_key_exists( 'unique', $arrayOptions ) ) {
203203 // unique like the parser function would do it
204204 $array = self::array_unique( $array );
205 - }
206 -
 205+ }
 206+
207207 /**
208208 * @ToDo:
209209 * The 'empty' option was introduced in r81676 but actually breaks old functionality since it will remove
@@ -213,19 +213,19 @@
214214 */
215215 /*
216216 // remove all empty '' elements if option is NOT set
217 - if( ! array_key_exists( 'empty', $arrayOptions ) ) {
 217+ if( ! array_key_exists( 'empty', $arrayOptions ) ) {
218218 $values = array(); // temp array so we won't have gaps (don't use unset!)
219 - foreach ( $array as $key => $value ) {
220 - if( $value !== '' ) {
221 - $values[] = $elem;
222 - }
223 - }
 219+ foreach ( $array as $key => $value ) {
 220+ if( $value !== '' ) {
 221+ $values[] = $elem;
 222+ }
 223+ }
224224 $array = $values;
225225 unset( $values );
226 - }
 226+ }
227227 */
228228
229 - // sort array if the option is set
 229+ // sort array if the option is set
230230 if( array_key_exists( 'sort', $arrayOptions ) ) {
231231 $array = self::arraySort( $array, self::array_value( $arrayOptions, 'sort' ) );
232232 }
@@ -238,11 +238,11 @@
239239 break;
240240 }
241241 }
242 -
 242+
243243 self::get( $parser )->setArray( $arrayId, $array );
244244
245245 return $out;
246 - }
 246+ }
247247
248248
249249 ///////////////////////////////////////////////////////////
@@ -265,21 +265,21 @@
266266 * {{#arrayprint:b|<br/>|@@@|{{f.tag{{f.print.vbar}}prop{{f.print.vbar}}@@@}} }} -- embed template function
267267 * {{#arrayprint:b|<br/>|@@@|[[name::@@@]]}} -- make SMW links
268268 */
269 - static function pfObj_arrayprint( Parser &$parser, $frame, $args ) {
270 - // Get Parameters
271 - $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
272 - $delimiter = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ', ';
 269+ static function pfObj_arrayprint( Parser &$parser, $frame, $args ) {
 270+ // Get Parameters
 271+ $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
 272+ $delimiter = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ', ';
273273 /*
274274 * PPFrame::NO_ARGS and PPFrame::NO_TEMPLATES for expansion make a lot of sense here since the patterns getting replaced
275275 * in $subject before $subject is being parsed. So any template or argument influence in the patterns wouldn't make any
276276 * sense in any sane scenario.
277277 */
278 - $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@';
279 - $subject = isset( $args[3] ) ? trim( $frame->expand( $args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@';
280 -
 278+ $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@';
 279+ $subject = isset( $args[3] ) ? trim( $frame->expand( $args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@';
 280+
281281 // get array, null if non-existant:
282282 $array = self::get( $parser )->getArray( $arrayId );
283 -
 283+
284284 if( $array === null ) {
285285 // array we want to print doesn't exist!
286286 global $egArrayExtensionCompatbilityMode;
@@ -292,11 +292,11 @@
293293 }
294294
295295 $rendered_values = array();
296 -
 296+
297297 foreach( $array as $val ) {
298298 // replace place holder with current value:
299299 $rawResult = str_replace( $search, $val, $subject );
300 -
 300+
301301 /*
302302 * $subjectd still is un-expanded (this allows to use some parser functions like
303303 * {{FULLPAGENAME:@@@@}} directly without getting parsed before @@@@ is replaced.
@@ -307,8 +307,8 @@
308308
309309 $rendered_values[] = $rawResult;
310310 }
311 -
312 - $output = implode( $delimiter, $rendered_values );
 311+
 312+ $output = implode( $delimiter, $rendered_values );
313313 $noparse = false;
314314
315315 /*
@@ -319,10 +319,10 @@
320320
321321 $output = $parser->preprocessToDom( $output, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 );
322322 $output = trim( $frame->expand( $output ) );
323 -
 323+
324324 return $output;
325 - }
326 -
 325+ }
 326+
327327 /**
328328 * print the value of an array (identified by arrayid) by the index, invalid index results in the default value being printed. note the index is 0-based.
329329 * usage:
@@ -330,26 +330,26 @@
331331 */
332332 static function pfObj_arrayindex( Parser &$parser, PPFrame $frame, $args ) {
333333 global $egArrayExtensionCompatbilityMode;
334 -
 334+
335335 // Get Parameters
336 - $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
 336+ $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
337337 $rawOptions = isset( $args[2] ) ? $args[2] : '';
338 -
 338+
339339 if( ! isset( $args[1] ) ) {
340340 return '';
341341 }
342342 $index = trim( $frame->expand( $args[1] ) );
343 -
 343+
344344 // get value or null if it doesn't exist. Takes care of negative index as well
345345 $val = self::get( $parser )->getArrayValue( $arrayId, $index );
346 -
347 - if( $val === null || ( $val === '' && !$egArrayExtensionCompatbilityMode ) ) {
348 - // index doesn't exist, return default (parameter 3)!
 346+
 347+ if( $val === null || ( $val === '' && !$egArrayExtensionCompatbilityMode ) ) {
 348+ // index doesn't exist, return default (parameter 3)!
349349 // without compatibility, also return default in case of empty string ''
350 -
 350+
351351 // only expand default when needed
352352 $defaultOrOptions = trim( $frame->expand( $rawOptions ) );
353 -
 353+
354354 if( $egArrayExtensionCompatbilityMode ) {
355355 // COMPATIBILITY-MODE
356356 // now parse the options, and do posterior process on the created array
@@ -358,13 +358,13 @@
359359 } else {
360360 $default = $defaultOrOptions;
361361 }
362 -
 362+
363363 return $default;
364 - }
365 -
 364+ }
 365+
366366 return $val;
367 - }
368 -
 367+ }
 368+
369369 /**
370370 * returns the size of an array.
371371 * Print the size (number of elements) in the specified array and '' if array doesn't exist
@@ -373,17 +373,17 @@
374374 *
375375 * See: http://www.php.net/manual/en/function.count.php
376376 */
377 - static function pf_arraysize( Parser &$parser, $arrayId ) {
 377+ static function pf_arraysize( Parser &$parser, $arrayId ) {
378378 $store = self::get( $parser );
379 -
380 - if( ! $store->arrayExists( $arrayId ) ) {
381 - return '';
382 - }
383 -
384 - return count( $store->getArray( $arrayId ) );
385 - }
386379
387 -
 380+ if( ! $store->arrayExists( $arrayId ) ) {
 381+ return '';
 382+ }
 383+
 384+ return count( $store->getArray( $arrayId ) );
 385+ }
 386+
 387+
388388 /**
389389 * locate the index of the first occurence of an element starting from the 'index'
390390 * - print "-1" (not found) or index (found) to show the index of the first occurence of 'value' in the array identified by arrayid
@@ -396,25 +396,25 @@
397397 * note it is extended to support regular expression match and index
398398 */
399399 static function pfObj_arraysearch( Parser &$parser, PPFrame $frame, $args ) {
400 -
 400+
401401 $arrayId = trim( $frame->expand( $args[0] ) );
402402 $index = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : 0;
403 -
 403+
404404 $store = self::get( $parser );
405 -
406 - if( $store->arrayExists( $arrayId )
407 - && $store->validate_array_index( $arrayId, $index, false )
 405+
 406+ if( $store->arrayExists( $arrayId )
 407+ && $store->validate_array_index( $arrayId, $index, false )
408408 ) {
409409 $array = $store->getArray( $arrayId );
410 -
 410+
411411 // validate/build search regex:
412412 if( isset( $args[1] ) ) {
413 -
 413+
414414 $needle = trim( $frame->expand( $args[1] ) );
415 -
 415+
416416 if ( ! self::isValidRegEx( $needle ) ) {
417417 $needle = '/^\s*' . preg_quote( trim( $needle ), '/' ) . '\s*$/';
418 - }
 418+ }
419419 }
420420 else {
421421 $needle = '/^\s*$/';
@@ -428,7 +428,7 @@
429429 if ( preg_match( $needle, $value ) ) {
430430 // found!
431431 if ( isset( $args[3] ) ) {
432 - // Expand only when needed!
 432+ // Expand only when needed!
433433 return trim( $frame->expand( $args[3] ) );
434434 }
435435 else {
@@ -438,15 +438,15 @@
439439 }
440440 }
441441 }
442 -
 442+
443443 global $egArrayExtensionCompatbilityMode;
444 -
 444+
445445 // no match! (Expand only when needed!)
446446 $no = isset( $args[4] )
447 - ? trim( $frame->expand( $args[4] ) )
448 - : $egArrayExtensionCompatbilityMode ? '-1' : ''; // COMPATIBILITY-MODE
449 - return $no;
450 - }
 447+ ? trim( $frame->expand( $args[4] ) )
 448+ : $egArrayExtensionCompatbilityMode ? '-1' : ''; // COMPATIBILITY-MODE
 449+ return $no;
 450+ }
451451
452452 /**
453453 * search an array and create a new array with all the results. Transforming the new entries before storing them is possible too.
@@ -466,47 +466,47 @@
467467 $transform = ''
468468 ) {
469469 $store = self::get( $parser );
470 -
 470+
471471 if( $arrayId === null ) {
472472 global $egArrayExtensionCompatbilityMode;
473473 if( ! $egArrayExtensionCompatbilityMode ) { // COMPATIBILITY-MODE
474474 $store->setArray( $arrayId_new );
475475 }
476476 return '';
477 - }
 477+ }
478478 // also takes care of negative index by calculating start index:
479479 $validIndex = $store->validate_array_index( $arrayId, $index, false );
480 -
 480+
481481 // make sure at least empty array exists but don't overwrite data
482482 // we still need in case new array ID same as target array ID
483483 $array = $store->getArray( $arrayId );
484484 $store->setArray( $arrayId_new );
485 -
486 - if( $array === null || !$validIndex ) {
 485+
 486+ if( $array === null || !$validIndex ) {
487487 return '';
488488 }
489 -
 489+
490490 // non-numeric limit will be set to 0, except limit was omitted ('')
491491 $limit = $limit === '' ? -1 : (int)$limit;
492492 if( $limit === 0 ) {
493493 return '';
494494 }
495 -
496 - $newArr = array();
497 -
 495+
 496+ $newArr = array();
 497+
498498 $regexFunSupport = self::hasRegexFunSupport();
499 - if( ! self::isValidRegEx( $needle, $regexFunSupport ) ) {
 499+ if( ! self::isValidRegEx( $needle, $regexFunSupport ) ) {
500500 $needle = '/^\s*(' . preg_quote( $needle, '/' ) . ')\s*$/';
501501 }
502502
503503 // search the array for all matches and put them in the new array
504504 $total = count( $array );
505 - for( $i = $index; $i < $total; $i++ ) {
506 -
 505+ for( $i = $index; $i < $total; $i++ ) {
 506+
507507 $value = $array[ $i ];
508508
509509 if( preg_match( $needle, $value ) ) {
510 - // Found something!
 510+ // Found something!
511511 if( $transform !== '' ) {
512512 // Transform the found string. Can we use 'Regex Fun' ?
513513 if( $regexFunSupport ) {
@@ -526,19 +526,19 @@
527527 }
528528 }
529529 $newArr[] = trim( $value );
530 -
 530+
531531 // stop if limit is reached, limit -1 means no limit
532532 if( --$limit === 0 ) {
533533 break;
534534 }
535535 }
536 - }
537 -
 536+ }
 537+
538538 // set new array:
539539 $store->setArray( $arrayId_new, $newArr );
540540 return '';
541541 }
542 -
 542+
543543 /**
544544 * extract a slice from an array
545545 * usage:
@@ -561,7 +561,7 @@
562562
563563 // make sure at least an empty array exists if we return early
564564 $store->setArray( $arrayId_new );
565 -
 565+
566566 if( $array === null
567567 || ! is_numeric( $offset ) // don't ignore invalid offset
568568 ) {
@@ -571,15 +571,15 @@
572572 if( ! is_numeric( $length ) ) {
573573 $length = null; // ignore invalid input, slice till end
574574 }
575 -
576 - // array_slice will re-organize keys
 575+
 576+ // array_slice will re-organize keys
577577 $newArray = array_slice( $array, $offset, $length );
578578 $store->setArray( $arrayId_new, $newArray );
579 -
 579+
580580 return '';
581581 }
582 -
583 -
 582+
 583+
584584 ///////////////////////////////////////////////////////////
585585 // PART 3. Array Alteration
586586 ///////////////////////////////////////////////////////////
@@ -592,7 +592,7 @@
593593 */
594594 static function pfObj_arrayreset( Parser &$parser, PPFrame $frame, $args) {
595595 global $egArrayExtensionCompatbilityMode;
596 -
 596+
597597 if( $egArrayExtensionCompatbilityMode && count( $args ) == 1 ) {
598598 /*
599599 * COMPATIBILITY-MODE: before arrays were separated by ';' which is an bad idea since
@@ -600,9 +600,9 @@
601601 */
602602 $args = preg_split( '/\s*,\s*/', trim( $frame->expand( $args[0] ) ) );
603603 }
604 -
 604+
605605 $store = self::get( $parser );
606 -
 606+
607607 // reset all hash tables if no specific tables are given:
608608 if( ! isset( $args[0] ) || ( $args[0] === '' && count( $args ) == 1 ) ) {
609609 // reset ALL arrays!
@@ -612,13 +612,13 @@
613613 // reset specific hash tables:
614614 foreach( $args as $arg ) {
615615 $arrayId = trim( $frame->expand( $arg ) );
616 - $store->unsetArray( $arrayId );
 616+ $store->unsetArray( $arrayId );
617617 }
618618 }
619619 return '';
620 - }
621 -
 620+ }
622621
 622+
623623 /**
624624 * convert an array to a set
625625 * convert the array identified by arrayid into a set (all elements are unique)
@@ -628,16 +628,16 @@
629629 *
630630 * see: http://www.php.net/manual/en/function.array-unique.php
631631 */
632 - static function pf_arrayunique( Parser &$parser, $arrayId ) {
 632+ static function pf_arrayunique( Parser &$parser, $arrayId ) {
633633 $store = self::get( $parser );
634 -
635 - if( $store->arrayExists( $arrayId ) ) {
 634+
 635+ if( $store->arrayExists( $arrayId ) ) {
636636 $array = $store->getArray( $arrayId );
637637 $array = self::array_unique( $array );
638638 $store->setArray( $arrayId, $array );
639 - }
640 - return '';
641 - }
 639+ }
 640+ return '';
 641+ }
642642
643643
644644 /**
@@ -653,32 +653,32 @@
654654 * see: http://www.php.net/manual/en/function.sort.php
655655 * http://www.php.net/manual/en/function.rsort.php
656656 * http://www.php.net/manual/en/function.shuffle.php
657 - * http://us3.php.net/manual/en/function.array-reverse.php
 657+ * http://us3.php.net/manual/en/function.array-reverse.php
658658 */
659 - static function pf_arraysort( Parser &$parser, $arrayId , $sort = 'none' ) {
 659+ static function pf_arraysort( Parser &$parser, $arrayId , $sort = 'none' ) {
660660 $store = self::get( $parser );
661 -
 661+
662662 $array = $store->getArray( $arrayId );
663 -
664 - if( $array === null ) {
665 - return '';
666 - }
667 -
 663+
 664+ if( $array === null ) {
 665+ return '';
 666+ }
 667+
668668 // sort array and store it
669669 $array = self::arraySort( $array, $sort );
670670 $store->setArray( $arrayId, $array );
671671 return '';
672 - }
 672+ }
673673
674674
675675 ///////////////////////////////////////////////////////////
676676 // PART 4. Array Interaction
677677 ///////////////////////////////////////////////////////////
678 -
 678+
679679 /**
680680 * Merge values two arrayes identified by arrayid1 and arrayid2 into a new array identified by arrayid_new.
681681 * This merge differs from array_merge of php because it merges values.
682 - *
 682+ *
683683 * Usage:
684684 * {{#arraymerge:arrayid_new |array1 |array2 |... |array n}}
685685 * See: http://www.php.net/manual/en/function.array-merge.php
@@ -691,12 +691,12 @@
692692 // keys will not be re-organized
693693 return array_merge( $array1, $array2 );
694694 }
695 -
696 - /**
 695+
 696+ /**
697697 * Usage:
698698 * {{#arrayunion:arrayid_new|arrayid1|arrayid2}}
699 - *
700 - * Set operation, {red, white} = {red, white} union {red}
 699+ *
 700+ * Set operation, {red, white} = {red, white} union {red}
701701 * Similar to arraymerge but with unique values. This union works on values.
702702 */
703703 static function pfObj_arrayunion( &$parser, $frame, $args) {
@@ -707,11 +707,11 @@
708708 // keys will not be re-organized
709709 return array_unique( array_merge( $array1, $array2 ) );
710710 }
711 -
 711+
712712 /**
713713 * Usage:
714714 * {{#arrayintersect:arrayid_new |array1 |array2 |... |array n}}
715 - *
 715+ *
716716 * Set operation, {red} = {red, white} intersect {red,black}
717717 * See: http://www.php.net/manual/en/function.array-intersect.php
718718 */
@@ -740,22 +740,22 @@
741741 // keys will be preserved!
742742 return array_diff( $array1, $array2 );
743743 }
744 -
745 -
 744+
 745+
746746 ##################
747747 # Private helper #
748748 ##################
749 -
 749+
750750 /**
751751 * Base function for operations with multiple arrays given thru n parameters
752752 * $operationFunc expects a function name prefix (suffix 'multi_') with two parameters
753753 * $array1 and $array2 which will perform an action between $array1 and $array2 which
754754 * will result into a new $array1. There can be 1 to n $hash2 in the whole process.
755 - *
 755+ *
756756 * Note: This function is similar to that of Extension:HashTables.
757 - *
 757+ *
758758 * @since 2.0
759 - *
 759+ *
760760 * @param $frame PPFrame
761761 * @param $args array
762762 * @param $operationFunc string name of the function calling this. There must be a counterpart
@@ -769,7 +769,7 @@
770770 $operationRan = false;
771771 $finalArrayId = trim( $frame->expand( $args[0] ) );
772772 $operationFunc = 'multi_' . preg_replace( '/^pfObj_/', '', $operationFunc );
773 -
 773+
774774 // For all arrays given in parameters 2 to n (ignore 1 because this is the name of the new array)
775775 for( $i = 1; $i < count( $args ); $i++ ) {
776776 // just make sure we don't fall into gaps of given arguments:
@@ -777,10 +777,10 @@
778778 continue;
779779 }
780780 $argArrayId = trim( $frame->expand( $args[ $i ] ) );
781 -
 781+
782782 // ignore all tables which do not exist
783783 if( $this->arrayExists( $argArrayId ) ) {
784 - $argArray = $this->getArray( $argArrayId );
 784+ $argArray = $this->getArray( $argArrayId );
785785 if( $lastArray === null ) {
786786 // first valid array, process together with second...
787787 $lastArray = $argArray;
@@ -792,14 +792,14 @@
793793 }
794794 }
795795 }
796 -
 796+
797797 // in case no array was given at all:
798798 if( $lastArray === null ) {
799799 $lastArray = array();
800800 }
801 -
 801+
802802 global $egArrayExtensionCompatbilityMode;
803 -
 803+
804804 if( ! $operationRan && $egArrayExtensionCompatbilityMode
805805 && $operationFunc !== 'multi_arraymerge' // only exception was 'arraymerge'
806806 ) {
@@ -810,33 +810,33 @@
811811 */
812812 return '';
813813 }
814 -
 814+
815815 // if the operation didn't run because there was only one or no array:
816816 if( ! $operationRan && $runFuncOnSingleArray ) {
817817 $lastArray = $this->{ $operationFunc }( $lastArray );
818818 }
819 -
 819+
820820 // re-organize all keys since some 'multi_' functions will preserve keys!
821821 $lastArray = array_merge( $lastArray );
822 -
 822+
823823 $this->setArray( $finalArrayId, $lastArray );
824 - }
 824+ }
825825
826 - /**
 826+ /**
827827 * Validates an index for an array and returns true in case the index is a valid index within
828828 * the array. This also changes the index value, which is given by reference, in case it is
829829 * set to a negative value. In case $strictIndex is set to false, further transforming of
830830 * $index might be done - in the same cases normally the function would return false.
831 - *
 831+ *
832832 * @param string $arrayId
833833 * @param mixed &$index
834834 * @param bool $strictIndex Whether non-numeric indexes and negative indexes which would
835835 * end up out of range, below 0, should be set to 0 automatically.
836 - *
 836+ *
837837 * @return boolean
838838 */
839 - protected function validate_array_index( $arrayId, &$index, $strictIndex = false ) {
840 - if( ! is_numeric( $index ) ) {
 839+ protected function validate_array_index( $arrayId, &$index, $strictIndex = false ) {
 840+ if( ! is_numeric( $index ) ) {
841841 if( $strictIndex ) {
842842 return false;
843843 } else {
@@ -844,13 +844,13 @@
845845 }
846846 }
847847 $index = (int)$index;
848 -
 848+
849849 if( ! array_key_exists( $arrayId, $this->mArrays ) ) {
850850 return false;
851851 }
852 -
 852+
853853 $array = $this->mArrays[ $arrayId ];
854 -
 854+
855855 // calculate start index for negative start indexes:
856856 if( $index < 0 ) {
857857 $index = count( $array ) + $index;
@@ -858,22 +858,22 @@
859859 $index = 0;
860860 }
861861 }
862 -
863 - if( ! isset( $array ) ) {
 862+
 863+ if( ! isset( $array ) ) {
864864 return false;
865865 }
866 - if( ! array_key_exists( $index, $array ) ) {
 866+ if( ! array_key_exists( $index, $array ) ) {
867867 return false;
868868 }
869 - return true;
870 - }
871 -
 869+ return true;
 870+ }
 871+
872872 /**
873873 * private function for validating array by name
874874 * @ToDo: get rid of this!
875875 * @deprecated
876876 */
877 - protected function validate_array_by_arrayId( $arrayId ) {
 877+ protected function validate_array_by_arrayId( $arrayId ) {
878878 if( ! isset( $arrayId ) ) {
879879 return '';
880880 }
@@ -890,27 +890,27 @@
891891 }
892892
893893 return true;
894 - }
895 -
 894+ }
 895+
896896 /**
897897 * Convenience function to get a value from an array. Returns '' in case the
898898 * value doesn't exist or no array was given
899 - *
 899+ *
900900 * @return string
901901 */
902 - protected static function array_value( $array, $field ) {
903 - if ( is_array( $array ) && array_key_exists( $field, $array ) ) {
 902+ protected static function array_value( $array, $field ) {
 903+ if ( is_array( $array ) && array_key_exists( $field, $array ) ) {
904904 return $array[ $field ];
905905 }
906906 return '';
907 - }
908 -
 907+ }
 908+
909909 /**
910910 * Parses a string of options separated by ','. Options can be just certain key-words or
911911 * key-value pairs separated by '='. Options are case-insensitive and spacing between
912912 * separators will be ignored.
913913 */
914 - protected static function parse_options( $options ) {
 914+ protected static function parse_options( $options ) {
915915 if( ! isset( $options ) ) {
916916 return array();
917917 }
@@ -918,25 +918,25 @@
919919 // now parse the options, and do posterior process on the created array
920920 $options = preg_split( '/\s*,\s*/', strtolower( $options ) );
921921
922 - $ret = array();
 922+ $ret = array();
923923 foreach( $options as $option ) {
924924 $optPair = preg_split( '/\s*\=\s*/', $option, 2 );
925 - if( sizeof( $optPair ) == 1 ) {
 925+ if( sizeof( $optPair ) == 1 ) {
926926 $ret[ $optPair[0] ] = true;
927927 } else {
928928 $ret[ $optPair[0] ] = $optPair[1];
929929 }
930930 }
931931 return $ret;
932 - }
933 -
 932+ }
 933+
934934 /**
935935 * same as self::arrayUnique() but without sanitazation, only for internal use.
936936 */
937937 protected static function array_unique( array $array ) {
938938 // delete duplicate values
939939 $array = array_unique( $array );
940 -
 940+
941941 $values = array();
942942 foreach( $array as $key => $val ) {
943943 // don't put emty elements into the array
@@ -944,7 +944,7 @@
945945 $values[] = $val;
946946 }
947947 }
948 -
 948+
949949 return $values;
950950 }
951951
@@ -952,7 +952,7 @@
953953 ##############
954954 # Used Hooks #
955955 ##############
956 -
 956+
957957 static function onParserClearState( Parser &$parser ) {
958958 // remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates
959959 $parser->mExtArrays = new self();
@@ -968,43 +968,43 @@
969969 # other extensions doing interactive stuff
970970 # with the Array extension.
971971 #
972 -
 972+
973973 /**
974974 * Convenience function to return the 'Arrays' extensions array store connected
975975 * to a certain Parser object. Each parser has its own store which will be reset after
976976 * a parsing process [Parser::parse()] has finished.
977 - *
 977+ *
978978 * @since 2.0
979 - *
 979+ *
980980 * @param Parser &$parser
981 - *
 981+ *
982982 * @return ExtArrays by reference so we still have the right object after 'ParserClearState'
983983 */
984984 public static function &get( Parser &$parser ) {
985985 return $parser->mExtArrays;
986986 }
987 -
 987+
988988 /**
989989 * Returns an array identified by $arrayId. If it doesn't exist, null will be returned.
990 - *
 990+ *
991991 * @since 2.0
992 - *
 992+ *
993993 * @param string $arrayId
994 - *
 994+ *
995995 * @return array|null
996996 */
997 - function getArray( $arrayId ) {
 997+ function getArray( $arrayId ) {
998998 $arrayId = trim( $arrayId );
999999 if( $this->arrayExists( $arrayId ) ) {
10001000 return $this->mArrays[ $arrayId ];
10011001 }
10021002 return null;
1003 - }
1004 -
 1003+ }
 1004+
10051005 /**
10061006 * This will add a new array or overwrite an existing one. Values should be delliverd as array
10071007 * values in form of a string. The array will be sanitized internally.
1008 - *
 1008+ *
10091009 * @param string $arrayId
10101010 * @param array $array
10111011 */
@@ -1012,64 +1012,64 @@
10131013 $array = self::sanitizeArray( $array );
10141014 $this->mArrays[ trim( $arrayId ) ] = $array;
10151015 }
1016 -
 1016+
10171017 /**
10181018 * Same as the public function createArray() but without sanitizing the array automatically.
10191019 * This is save and faster for internal usage, just be sure your array doesn't have un-trimmed
10201020 * values or non-numeric or negative array keys and no gaps between keys.
1021 - *
 1021+ *
10221022 * @param type $arrayId
1023 - * @param type $array
 1023+ * @param type $array
10241024 */
10251025 protected function setArray( $arrayId, $array = array() ) {
10261026 $this->mArrays[ trim( $arrayId ) ] = $array;
10271027 }
1028 -
 1028+
10291029 /**
10301030 * Returns whether a certain array is defined within the page scope.
1031 - *
 1031+ *
10321032 * @param string $arrayId
1033 - *
 1033+ *
10341034 * @return boolean
10351035 */
10361036 function arrayExists( $arrayId ) {
10371037 return array_key_exists( trim( $arrayId ), $this->mArrays );
10381038 }
1039 -
 1039+
10401040 /**
10411041 * Returns a value within an array. If key or array do not exist, this will return null
10421042 * or another predefined default. $index can also be a negative value, in this case the
10431043 * value that far from the end of the array will be returned.
1044 - *
 1044+ *
10451045 * @since 2.0
1046 - *
 1046+ *
10471047 * @param string $arrayId
10481048 * @param string $index
10491049 * @param mixed $default value to return in case the value doesn't exist. null by default.
1050 - *
 1050+ *
10511051 * @return string|null
10521052 */
1053 - function getArrayValue( $arrayId, $index, $default = null ) {
1054 - $arrayId = trim( $arrayId );
 1053+ function getArrayValue( $arrayId, $index, $default = null ) {
 1054+ $arrayId = trim( $arrayId );
10551055 if( $this->arrayExists( $arrayId )
10561056 && $this->validate_array_index( $arrayId, $index, true )
1057 - && array_key_exists( $index, $this->mArrays[ $arrayId ] )
 1057+ && array_key_exists( $index, $this->mArrays[ $arrayId ] )
10581058 ) {
10591059 return $this->mArrays[ $arrayId ][ $index ];
10601060 }
10611061 else {
10621062 return $default;
10631063 }
1064 - }
 1064+ }
10651065
10661066
10671067 /**
10681068 * Removes an existing array. If array didn't exist this will return false, otherwise true.
1069 - *
 1069+ *
10701070 * @since 2.0
1071 - *
 1071+ *
10721072 * @param string $arrayId
1073 - *
 1073+ *
10741074 * @return boolean whether the array existed and has been removed
10751075 */
10761076 public function unsetArray( $arrayId ) {
@@ -1084,9 +1084,9 @@
10851085 /**
10861086 * Rebuild the array and reorganize all keys, trim all values.
10871087 * All gaps between array items will be closed.
1088 - *
 1088+ *
10891089 * @since 2.0
1090 - *
 1090+ *
10911091 * @param array $arr array to be reorganized
10921092 * @return array
10931093 */
@@ -1097,36 +1097,36 @@
10981098 }
10991099 return $newArray;
11001100 }
1101 -
 1101+
11021102 /**
11031103 * Removes duplicate values and all empty elements from an array just like the
11041104 * '#arrayunique' parser function would do it. The array will be sanitized internally.
1105 - *
 1105+ *
11061106 * @since 2.0
1107 - *
 1107+ *
11081108 * @param array $array
1109 - *
 1109+ *
11101110 * @return array
11111111 */
11121112 public static function arrayUnique( array $array ) {
11131113 $arr = $this->sanitizeArray( $arr );
11141114 $array = self::array_unique( $array );
11151115 }
1116 -
 1116+
11171117 /**
11181118 * Sorts an array just like parser function '#arraysort' would do it and allows the
11191119 * same sort modes.
1120 - *
 1120+ *
11211121 * @since 2.0
1122 - *
 1122+ *
11231123 * @param array $array
11241124 * @param string $sortMode
1125 - *
 1125+ *
11261126 * @return array
11271127 */
11281128 public static function arraySort( array $array, $sortMode ) {
11291129 // do the requested sorting of the given array:
1130 - switch( $sortMode ) {
 1130+ switch( $sortMode ) {
11311131 case 'asc':
11321132 case 'asce':
11331133 case 'ascending':
@@ -1153,19 +1153,19 @@
11541154 /**
11551155 * Decides for the given $pattern whether its a valid regular expression acceptable for
11561156 * Arrays parser functions or not.
1157 - *
 1157+ *
11581158 * @param string $pattern regular expression including delimiters and optional flags
11591159 * @param bool $forRegexFun whether the regular expression is inteded to be used with 'Regex Fun'
11601160 * if supported by the wikis infrastructure. In case 'Regex Fun' is not available,
11611161 * the default validation will be used.
1162 - *
 1162+ *
11631163 * @return boolean
11641164 */
11651165 static function isValidRegEx( $pattern, $forRegexFun = false ) {
11661166 if( $forRegexFun && self::hasRegexFunSupport() ) {
11671167 return ExtRegexFun::validateRegex( $pattern );
11681168 }
1169 -
 1169+
11701170 if( ! preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ) ) {
11711171 return false;
11721172 }
@@ -1174,7 +1174,7 @@
11751175 wfRestoreWarnings();
11761176 return $isValid;
11771177 }
1178 -
 1178+
11791179 /**
11801180 * Whether 'Regex Fun' extension is available in this wiki to take over preg_replace handling
11811181 * for '#arraysearcharray' function.

Status & tagging log