r103592 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103591‎ | r103592 | r103593 >
Date:15:04, 18 November 2011
Author:danwe
Status:deferred
Tags:
Comment:
Breaking changes and config var '$wgArrayExtensionCompatbilityMode' to deactivate them: #arrayreset now uses n parameters instead of ',' for multi array reset, #arraysearch returns '' instead of '-1' if unsuccessful.
Modified paths:
  • /trunk/extensions/ArrayExtension/ArrayExtension.php (modified) (history)
  • /trunk/extensions/ArrayExtension/RELEASE-NOTES (modified) (history)

Diff [purge]

Index: trunk/extensions/ArrayExtension/ArrayExtension.php
@@ -61,6 +61,14 @@
6262 unset( $dir );
6363
6464 /**
 65+ * Full compatbility to versions before 1.4
 66+ *
 67+ * @var boolean
 68+ */
 69+$wgArrayExtensionCompatbilityMode = true;
 70+
 71+
 72+/**
6573 * named arrays - an array has a list of values, and could be set to a SET
6674 */
6775 class ArrayExtension {
@@ -347,9 +355,13 @@
348356 }
349357 }
350358 }
351 -
 359+
 360+ global $wgArrayExtensionCompatbilityMode;
 361+
352362 // 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
354366 return $no;
355367 }
356368
@@ -420,20 +432,32 @@
421433 * {{#arrayreset:}}
422434 * {{#arrayreset:arrayid1,arrayid2,...arrayidn}}
423435 */
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 '';
435459 }
 460+
436461
437 -
438462 /**
439463 * convert an array to set
440464 * convert the array identified by arrayid into a set (all elements are unique)
@@ -812,14 +836,14 @@
813837
814838
815839 /**
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.
817841 *
818842 * @param string $arrayId
819843 * @return boolean whether the array existed and has been removed
820844 */
821 - public function removeArray( $arrayId = '' ) {
 845+ public function unsetArray( $arrayId ) {
822846 $arrayId = trim( $arrayId );
823 - if ( $this->arrayExists( $arrayId ) ) {
 847+ if( $this->arrayExists( $arrayId ) ) {
824848 unset( $this->mArrayExtension[ $arrayId ] );
825849 return true;
826850 }
@@ -876,7 +900,7 @@
877901
878902 $parser->setFunctionHook( 'arraysort', array( &$wgArrayExtension, 'arraysort' ) );
879903 $parser->setFunctionHook( 'arrayunique', array( &$wgArrayExtension, 'arrayunique' ) );
880 - $parser->setFunctionHook( 'arrayreset', array( &$wgArrayExtension, 'arrayreset' ) );
 904+ $parser->setFunctionHook( 'arrayreset', array( &$wgArrayExtension, 'arrayreset' ), SFH_OBJECT_ARGS );
881905
882906 $parser->setFunctionHook( 'arraymerge', array( &$wgArrayExtension, 'arraymerge' ) );
883907 $parser->setFunctionHook( 'arrayslice', array( &$wgArrayExtension, 'arrayslice' ) );
Index: trunk/extensions/ArrayExtension/RELEASE-NOTES
@@ -1,26 +1,35 @@
22 Changelog:
33 ==========
44 * (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.
713 - 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+
1015 @ToDo before release:
1116 - As in Variables 2.0, one store per Parser should be used.
1217 - ''#arraysearch'' should not expand both, 'yes' and 'no', just the one actual case.
 18+ - Further breaking changes fixing weird old behavior and functionality
1319
1420
1521 * January 24, 2011 version 1.3.2
1622 - New public class methods for creating and removing arrays. Good for use by other extensions.
1723 - VERSION constant added to ArrayExtension class
1824 * 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.
2027
2128 * 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)
2331 - 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
2534 - advanced check for regular expressions in '#arraysearch,' '#arraydefine' and '#arraysearcharray'
2635 Pivate function isValidRegEx() added
2736 - '#arraymerge' bug fixed: Php message in case of non existant seccond array
@@ -40,44 +49,55 @@
4150 - add "asc" as option of arraysort
4251
4352 * 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"
4760 * April 24, 2009 version 1.2
4861
4962 - 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
5165 * April 18, 2009 version 1.1.6
5266 - fixed a bug in arraymerge and arrayslice,
5367 * Mar 17, 2009 version 1.1.5
5468 - update '#arraysort,' add "reverse" option, http://us3.php.net/manual/en/function.array-reverse.php
5569 - update '#arrayreset,' add option to reset a selection of arrays
5670 * 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
5873 * Feb 23, 2009 version 1.1.3
5974 - fixed '#arraysearch,' "Warning: Missing argument 4..."
6075 * Feb 9, 2009 version 1.1.2
6176 - update '#arraysearch,' now support offset and preg regular expression
6277 * 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
6582 * Feb 5, 2009 version 1.1
6683 - 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
7088 - update '#arrayunique,' empty elements will be removed
7189 - update '#arraysort:' adding "random" option to make the array of values in random order
7290 - add '#arrayreset' to free all defined arrays for memory saving
7391 - 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
7594 - remove '#arraymember,' obsoleted by '#arraysearch'
7695 - remove '#arraypush,' obsoleted by '#arraydefine' and '#arraymerge'
7796 - remove '#arraypop,' obsoleted by '#arrayslice'
7897 - add safty check code to avoid unset parameters
7998
8099 * 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)
82102 * Jan 28, 2009 version 1.0.2
83103 - changed arraypop (add one parameter to support multiple pop)
84104 - added arrayindex (return an array element at index)

Status & tagging log