r105130 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105129‎ | r105130 | r105131 >
Date:22:19, 4 December 2011
Author:danwe
Status:deferred
Tags:
Comment:
startet version 2.0rc2. Improved '#arraysearcharray' support for 'Regex Fun' extension.
Modified paths:
  • /trunk/extensions/Arrays/Arrays.php (modified) (history)
  • /trunk/extensions/Arrays/Arrays_Settings.php (modified) (history)
  • /trunk/extensions/Arrays/RELEASE-NOTES (modified) (history)

Diff [purge]

Index: trunk/extensions/Arrays/RELEASE-NOTES
@@ -1,16 +1,20 @@
22 Changelog:
33 ==========
44
 5+ * (trunk) -- Version 2.0rc2
 6+ - '#arraysearcharray' with 'e' using 'Regex Fun' no longer requires an escaped transform (parameter 6)
 7+ input. It works just like the '#regex' parser functions replacement parameter.
 8+
59 * December 4, 2011 -- Version 2.0rc
6 - This release is built upon 1.4 alpha. See changes of 1.4 alpha as well.
7 - 'ArrayExtension' is now simply called 'Arrays'. Therefore you have to adjust your LocalSettings.php.
 10+ This release is built upon 1.4 alpha. See changes of 1.4 alpha as well.
 11+ 'ArrayExtension' is now simply called 'Arrays'. Therefore you have to adjust your LocalSettings.php.
812 - Compatibility mode variable '$egArraysCompatibilityMode' ('$egArrayExtensionCompatbilityMode' in
913 Version 1.4 alpha) is set to false by default. See Version 1.4 alpha for further information.
1014 - Additional changes to the compatibility mode behavior in version 2.0 include:
1115 + '#arrayindex' will return its default also in case of existing index but empty value. This
12 - makes the function consistent with Variables '#var' and hash tables '#hashvalue'.
13 - + '#arraymerge', '#arrayunion', '#arraydiff' and '#arrayintersect' with only one array for
14 - the operation will make a copy of that array instead of creating no array at all.
 16+ makes the function consistent with Variables '#var' and HashTables '#hashvalue'.
 17+ + '#arrayunion', '#arraydiff' and '#arrayintersect' with only one array for the operation will make
 18+ a copy of that array instead of creating no array at all (just like '#arraymerge' behaved already).
1519 + Default separator for '#arrayprint' now is the languages default separator instead of ', '.
1620 + '#arrayprint' will no longer expand the given wiki markup twice. Instead, it will escape special
1721 characters of array values before they will be inserted into the markup. This way it won't be
Index: trunk/extensions/Arrays/Arrays.php
@@ -11,7 +11,7 @@
1212 * @ingroup Arrays
1313 *
1414 * @licence MIT License
15 - * @version: 2.0rc
 15+ * @version: 2.0rc2
1616 *
1717 * @author Li Ding < lidingpku@gmail.com >
1818 * @author Jie Bao
@@ -53,7 +53,7 @@
5454 *
5555 * @since 2.0 (before in 'Arrays' class since 1.3.2)
5656 */
57 - const VERSION = '2.0rc';
 57+ const VERSION = '2.0rc2';
5858
5959 /**
6060 * Store for arrays.
@@ -105,7 +105,7 @@
106106 self::initFunction( $parser, 'arrayindex', SFH_OBJECT_ARGS );
107107 self::initFunction( $parser, 'arraysize' );
108108 self::initFunction( $parser, 'arraysearch', SFH_OBJECT_ARGS );
109 - self::initFunction( $parser, 'arraysearcharray' );
 109+ self::initFunction( $parser, 'arraysearcharray', SFH_OBJECT_ARGS );
110110 self::initFunction( $parser, 'arrayslice' );
111111 self::initFunction( $parser, 'arrayreset', SFH_OBJECT_ARGS );
112112 self::initFunction( $parser, 'arrayunique' );
@@ -445,7 +445,7 @@
446446 * note it is extended to support regular expression match and index
447447 */
448448 static function pfObj_arraysearch( Parser &$parser, PPFrame $frame, $args ) {
449 -
 449+ // Get Parameters
450450 $arrayId = trim( $frame->expand( $args[0] ) );
451451 $index = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : 0;
452452
@@ -505,17 +505,13 @@
506506 * "needle" can be a regular expression or a string search value. If "needle" is a regular expression, "transform" can contain
507507 * "$n" where "n" stands for a number to access a variable from the regex result.
508508 */
509 - static function pf_arraysearcharray(
510 - Parser &$parser,
511 - $arrayId_new,
512 - $arrayId = null,
513 - $needle = '/^(\s*)$/',
514 - $index = 0,
515 - $limit = '',
516 - $transform = ''
517 - ) {
 509+ static function pfObj_arraysearcharray( Parser &$parser, PPFrame $frame, $args ) {
518510 $store = self::get( $parser );
519 -
 511+
 512+ // get first two parameters
 513+ $arrayId = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : null;
 514+ $arrayId_new = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
 515+
520516 if( $arrayId === null ) {
521517 global $egArraysCompatibilityMode;
522518 if( ! $egArraysCompatibilityMode ) { // COMPATIBILITY-MODE
@@ -523,6 +519,13 @@
524520 }
525521 return '';
526522 }
 523+
 524+ // Get Parameters the other parameters
 525+ $needle = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '/^(\s*)$/';
 526+ $index = isset( $args[3] ) ? trim( $frame->expand( $args[3] ) ) : 0;
 527+ $limit = isset( $args[4] ) ? trim( $frame->expand( $args[4] ) ) : '';
 528+ $rawTransform = isset( $args[5] ) ? $args[5] : null;
 529+
527530 // also takes care of negative index by calculating start index:
528531 $validIndex = $store->validate_array_index( $arrayId, $index, false );
529532
@@ -556,10 +559,14 @@
557560
558561 if( preg_match( $needle, $value ) ) {
559562 // Found something!
560 - if( $transform !== '' ) {
 563+ if( $rawTransform !== null ) {
561564 // Transform the found string. Can we use 'Regex Fun' ?
562565 if( $regexFunSupport ) {
563566 // do the transformation with Regex Fun to support 'e' flag:
 567+ $transform = trim( $frame->expand(
 568+ $rawTransform,
 569+ PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES // leave expanding of templates to 'Regex Fun'
 570+ ) );
564571 $value = ExtRegexFun::doPregReplace(
565572 $needle,
566573 $transform,
@@ -571,6 +578,7 @@
572579 }
573580 else {
574581 // regular preg_replace:
 582+ $transform = trim( $frame->expand( $rawTransform ) );
575583 $value = preg_replace( $needle, $transform, $value );
576584 }
577585 }
Index: trunk/extensions/Arrays/Arrays_Settings.php
@@ -17,7 +17,6 @@
1818 */
1919
2020 /**
21 - * Full compatbility to versions before 1.4.
2221 * Set to false by default since version 2.0.
2322 *
2423 * @since 2.0 (as '$egArrayExtensionCompatbilityMode' in 1.4 alpha)

Status & tagging log