Index: trunk/extensions/ArrayExtension/ArrayExtension.php |
— | — | @@ -61,6 +61,14 @@ |
62 | 62 | unset( $dir ); |
63 | 63 | |
64 | 64 | /** |
| 65 | + * Full compatbility to versions before 1.4 |
| 66 | + * |
| 67 | + * @var boolean |
| 68 | + */ |
| 69 | +$wgArrayExtensionCompatbilityMode = true; |
| 70 | + |
| 71 | + |
| 72 | +/** |
65 | 73 | * named arrays - an array has a list of values, and could be set to a SET |
66 | 74 | */ |
67 | 75 | class ArrayExtension { |
— | — | @@ -347,9 +355,13 @@ |
348 | 356 | } |
349 | 357 | } |
350 | 358 | } |
351 | | - |
| 359 | + |
| 360 | + global $wgArrayExtensionCompatbilityMode; |
| 361 | + |
352 | 362 | // no match! (Expand only when needed!) |
353 | | - $no = isset( $args[4] ) ? trim( $frame->expand( $args[4] ) ) : '-1'; |
| 363 | + $no = isset( $args[4] ) |
| 364 | + ? trim( $frame->expand( $args[4] ) ) |
| 365 | + : $wgArrayExtensionCompatbilityMode ? '-1' : ''; // COMPATBILITY-MODE |
354 | 366 | return $no; |
355 | 367 | } |
356 | 368 | |
— | — | @@ -420,20 +432,32 @@ |
421 | 433 | * {{#arrayreset:}} |
422 | 434 | * {{#arrayreset:arrayid1,arrayid2,...arrayidn}} |
423 | 435 | */ |
424 | | - function arrayreset( &$parser, $arrayids ) { |
425 | | - if ( !$this->is_non_empty( $arrayids ) ) { |
426 | | - // reset all |
427 | | - $this->mArrayExtension = array(); |
428 | | - } else { |
429 | | - $arykeys = explode( ',', $arrayids ); |
430 | | - foreach ( $arykeys as $arrayid ) { |
431 | | - $this->removeArray( $arrayids ); |
432 | | - } |
433 | | - } |
434 | | - return ''; |
| 436 | + function arrayreset( &$parser, PPFrame $frame, $args) { |
| 437 | + global $wgArrayExtensionCompatbilityMode; |
| 438 | + |
| 439 | + if( $wgArrayExtensionCompatbilityMode && count( $args ) == 1 ) { |
| 440 | + /* |
| 441 | + * COMPATBILITY-MODE: before arrays were separated by ';' which is an bad idea since |
| 442 | + * the ',' is an allowed character in array names! |
| 443 | + */ |
| 444 | + $args = preg_split( '/\s*,\s*/', $args[0] ); |
| 445 | + } |
| 446 | + |
| 447 | + // reset all hash tables if no specific tables are given: |
| 448 | + if( ! isset( $args[0] ) || ( $args[0] === '' && count( $args ) == 1 ) ) { |
| 449 | + $this->mArrayExtension = array(); |
| 450 | + } |
| 451 | + else { |
| 452 | + // reset specific hash tables: |
| 453 | + foreach( $args as $arg ) { |
| 454 | + $arrayId = trim( $frame->expand( $arg ) ); |
| 455 | + $this->unsetArray( $arrayId ); |
| 456 | + } |
| 457 | + } |
| 458 | + return ''; |
435 | 459 | } |
| 460 | + |
436 | 461 | |
437 | | - |
438 | 462 | /** |
439 | 463 | * convert an array to set |
440 | 464 | * convert the array identified by arrayid into a set (all elements are unique) |
— | — | @@ -812,14 +836,14 @@ |
813 | 837 | |
814 | 838 | |
815 | 839 | /** |
816 | | - * Removes an existing array. If array doesn't exist this will return false, otherwise true. |
| 840 | + * Removes an existing array. If array didn't exist this will return false, otherwise true. |
817 | 841 | * |
818 | 842 | * @param string $arrayId |
819 | 843 | * @return boolean whether the array existed and has been removed |
820 | 844 | */ |
821 | | - public function removeArray( $arrayId = '' ) { |
| 845 | + public function unsetArray( $arrayId ) { |
822 | 846 | $arrayId = trim( $arrayId ); |
823 | | - if ( $this->arrayExists( $arrayId ) ) { |
| 847 | + if( $this->arrayExists( $arrayId ) ) { |
824 | 848 | unset( $this->mArrayExtension[ $arrayId ] ); |
825 | 849 | return true; |
826 | 850 | } |
— | — | @@ -876,7 +900,7 @@ |
877 | 901 | |
878 | 902 | $parser->setFunctionHook( 'arraysort', array( &$wgArrayExtension, 'arraysort' ) ); |
879 | 903 | $parser->setFunctionHook( 'arrayunique', array( &$wgArrayExtension, 'arrayunique' ) ); |
880 | | - $parser->setFunctionHook( 'arrayreset', array( &$wgArrayExtension, 'arrayreset' ) ); |
| 904 | + $parser->setFunctionHook( 'arrayreset', array( &$wgArrayExtension, 'arrayreset' ), SFH_OBJECT_ARGS ); |
881 | 905 | |
882 | 906 | $parser->setFunctionHook( 'arraymerge', array( &$wgArrayExtension, 'arraymerge' ) ); |
883 | 907 | $parser->setFunctionHook( 'arrayslice', array( &$wgArrayExtension, 'arrayslice' ) ); |
Index: trunk/extensions/ArrayExtension/RELEASE-NOTES |
— | — | @@ -1,26 +1,35 @@ |
2 | 2 | Changelog: |
3 | 3 | ========== |
4 | 4 | * (trunk) version 1.4 |
5 | | - - arrayprint will handle <includeonly>/<noinclude> correct in case its used in a template. |
6 | | - - Internationalization in several languages added. |
| 5 | + - Configuration variable '$wgArrayExtensionCompatbilityMode' to deactivate the following |
| 6 | + breaking changes: |
| 7 | + + '#arrayreset' now uses n parameters instead of ',' as separator for n arrays to reset |
| 8 | + + '#arraysearch' returns an empty string '' instead of '-1' in case nothing was found. |
| 9 | + - '#arraysearch' will only expand 'yes' or 'no' if given, but never both. |
| 10 | + - negative indexes for '#arraysearch' and '#arrayindex' possible. |
| 11 | + - arrayprint will handle <includeonly>/<noinclude> correct in case it's used in a template. |
| 12 | + - Internationalization in several languages added. |
7 | 13 | - moved into mediawiki.org svn repository. |
8 | | - - '#arraysearch' will only update expand 'yes' or 'no' if given, but never both. |
9 | | - - negative indexes for '#arraysearch' and '#arrayindex' possible. |
| 14 | + |
10 | 15 | @ToDo before release: |
11 | 16 | - As in Variables 2.0, one store per Parser should be used. |
12 | 17 | - ''#arraysearch'' should not expand both, 'yes' and 'no', just the one actual case. |
| 18 | + - Further breaking changes fixing weird old behavior and functionality |
13 | 19 | |
14 | 20 | |
15 | 21 | * January 24, 2011 version 1.3.2 |
16 | 22 | - New public class methods for creating and removing arrays. Good for use by other extensions. |
17 | 23 | - VERSION constant added to ArrayExtension class |
18 | 24 | * July 20, 2010 version 1.3.1 |
19 | | - - Removed critical bug. Some kind of "Superglobal" Arrays on page imports and job queue jobs. Values were passed from one page to another page. |
| 25 | + - Removed critical bug. Some kind of "Superglobal" Arrays on page imports and job queue jobs. |
| 26 | + Values were passed from one page to another page. |
20 | 27 | |
21 | 28 | * July 5, 2010 version 1.3 |
22 | | - - update arrayunion and arraydiff, fixed heavy bug (gaps between array indexes doing some serious trouble in other arrayfunctions like arraysearch) |
| 29 | + - update arrayunion and arraydiff, fixed heavy bug (gaps between array indexes doing some serious |
| 30 | + trouble in other arrayfunctions like arraysearch) |
23 | 31 | - array function ''#arraysearcharray'' added |
24 | | - - '#arraysearch' code cleanup, search parameter is optional now, searching for empty elements is possible now |
| 32 | + - '#arraysearch' code cleanup, search parameter is optional now, searching for empty elements is |
| 33 | + possible now |
25 | 34 | - advanced check for regular expressions in '#arraysearch,' '#arraydefine' and '#arraysearcharray' |
26 | 35 | Pivate function isValidRegEx() added |
27 | 36 | - '#arraymerge' bug fixed: Php message in case of non existant seccond array |
— | — | @@ -40,44 +49,55 @@ |
41 | 50 | - add "asc" as option of arraysort |
42 | 51 | |
43 | 52 | * May 03, 2009 version 1.2.1 |
44 | | - - update arraydefine by adding options: "unique"; sort=( "desc", "asce", "random", "reverse"), and print=( "list" ). Options are diliminated by comma, e.g. "unique, sort=desc,print=list". |
45 | | - - fixed bug in arrayslice (offset can be greater than array size): if offset is no less than array size, empty array will be returned, if offset if no greater than negative array size, a new array with all elements will be returned |
46 | | - - update arrayindex by adding print option when (i) the array is not defined; (ii) the index is not valid in the specified array: e.g. "default=bad array" |
| 53 | + - update arraydefine by adding options: "unique"; sort=( "desc", "asce", "random", "reverse"), and |
| 54 | + print=( "list" ). Options are diliminated by comma, e.g. "unique, sort=desc,print=list". |
| 55 | + - fixed bug in arrayslice (offset can be greater than array size): if offset is no less than array |
| 56 | + size, empty array will be returned, if offset if no greater than negative array size, a new array |
| 57 | + with all elements will be returned |
| 58 | + - update arrayindex by adding print option when (i) the array is not defined; (ii) the index is not |
| 59 | + valid in the specified array: e.g. "default=bad array" |
47 | 60 | * April 24, 2009 version 1.2 |
48 | 61 | |
49 | 62 | - fixed a bug in arrayslice, (offset=0) |
50 | | - - clean up code, added two private functions, validate_array_index, validate_array_offset, validate_array_by_arrayid; rename some parameters key=> new_key, differentiate offset and index |
| 63 | + - clean up code, added two private functions, validate_array_index, validate_array_offset, |
| 64 | + validate_array_by_arrayid; rename some parameters key=> new_key, differentiate offset and index |
51 | 65 | * April 18, 2009 version 1.1.6 |
52 | 66 | - fixed a bug in arraymerge and arrayslice, |
53 | 67 | * Mar 17, 2009 version 1.1.5 |
54 | 68 | - update '#arraysort,' add "reverse" option, http://us3.php.net/manual/en/function.array-reverse.php |
55 | 69 | - update '#arrayreset,' add option to reset a selection of arrays |
56 | 70 | * Feb 23, 2009 version 1.1.4 |
57 | | - - fixed '#arraysearch,' better recognize perl patterns identified by starting with "/", http://www.perl.com/doc/manual/html/pod/perlre.html |
| 71 | + - fixed '#arraysearch,' better recognize perl patterns identified by starting with "/", |
| 72 | + http://www.perl.com/doc/manual/html/pod/perlre.html |
58 | 73 | * Feb 23, 2009 version 1.1.3 |
59 | 74 | - fixed '#arraysearch,' "Warning: Missing argument 4..." |
60 | 75 | * Feb 9, 2009 version 1.1.2 |
61 | 76 | - update '#arraysearch,' now support offset and preg regular expression |
62 | 77 | * Feb 8, 2009 version 1.1.1 |
63 | | - - update '#arrayprint,' now wiki links, parser functions and templates properly parsed. This enables foreach loop call. |
64 | | - - update '#arraysearch,' now allows customized output upon found/non-found by specifying additional parameters |
| 78 | + - update '#arrayprint,' now wiki links, parser functions and templates properly parsed. This enables |
| 79 | + foreach loop call. |
| 80 | + - update '#arraysearch,' now allows customized output upon found/non-found by specifying additional |
| 81 | + parameters |
65 | 82 | * Feb 5, 2009 version 1.1 |
66 | 83 | - update '#arraydefine:' replacing 'explode' by 'preg_split', |
67 | | - and we now allow delimitors to be (i) a string; or (ii) a perl regular expressnion pattern, sourrounded by '/', e.g. '/..blah.../' |
68 | | - - update '#arrayprint,' change parameters from "prefix","suffix" to a "template", |
69 | | - and users can replace a substring in the template with array value, similar to arraymap in semantic forms |
| 84 | + and we now allow delimitors to be (i) a string; or (ii) a perl regular expressnion pattern, |
| 85 | + sourrounded by '/', e.g. '/..blah.../' |
| 86 | + - update '#arrayprint,' change parameters from "prefix","suffix" to a "template", and users can |
| 87 | + replace a substring in the template with array value, similar to arraymap in semantic forms |
70 | 88 | - update '#arrayunique,' empty elements will be removed |
71 | 89 | - update '#arraysort:' adding "random" option to make the array of values in random order |
72 | 90 | - add '#arrayreset' to free all defined arrays for memory saving |
73 | 91 | - add '#arrayslice' to return an array bounded by start_index and length. |
74 | | - - add '#arraysearch.' now we can return the index of the first occurence of an element, return -1 if not found |
| 92 | + - add '#arraysearch.' now we can return the index of the first occurence of an element, return -1 if |
| 93 | + not found |
75 | 94 | - remove '#arraymember,' obsoleted by '#arraysearch' |
76 | 95 | - remove '#arraypush,' obsoleted by '#arraydefine' and '#arraymerge' |
77 | 96 | - remove '#arraypop,' obsoleted by '#arrayslice' |
78 | 97 | - add safty check code to avoid unset parameters |
79 | 98 | |
80 | 99 | * Feb 1, 2009 version 1.0.3 |
81 | | - - fixed bug on arrayunique, php array_unique only make values unique, but the array index was not updated. (arraydefine is also affected) |
| 100 | + - fixed bug on arrayunique, php array_unique only make values unique, but the array index was not |
| 101 | + updated. (arraydefine is also affected) |
82 | 102 | * Jan 28, 2009 version 1.0.2 |
83 | 103 | - changed arraypop (add one parameter to support multiple pop) |
84 | 104 | - added arrayindex (return an array element at index) |