Index: trunk/extensions/Arrays/RELEASE-NOTES |
— | — | @@ -15,6 +15,8 @@ |
16 | 16 | + '#arraymerge', '#arrayunion', '#arraydiff' and '#arrayintersect' with only one array for |
17 | 17 | the operation will make a copy of that array instead of creating no array at all. |
18 | 18 | + See 1.4 alpha for previous changes |
| 19 | + - If 'Regex Fun' extension is installed, '#arraysearcharray' can use Regex Funs 'e' flag feature |
| 20 | + for transforming the result and at the same time parsing them after each back-reference inclusion. |
19 | 21 | |
20 | 22 | |
21 | 23 | * November 20, 2001 -- Version 1.4 alpha (r103716) |
Index: trunk/extensions/Arrays/Arrays.php |
— | — | @@ -125,7 +125,6 @@ |
126 | 126 | */ |
127 | 127 | public static function getDir() { |
128 | 128 | static $dir = null; |
129 | | - |
130 | 129 | if( $dir === null ) { |
131 | 130 | $dir = dirname( __FILE__ ); |
132 | 131 | } |
— | — | @@ -287,6 +286,7 @@ |
288 | 287 | } |
289 | 288 | |
290 | 289 | $rendered_values = array(); |
| 290 | + |
291 | 291 | foreach( $array as $val ) { |
292 | 292 | // replace place holder with current value: |
293 | 293 | $rawResult = str_replace( $search, $val, $subject ); |
— | — | @@ -503,8 +503,9 @@ |
504 | 504 | } |
505 | 505 | |
506 | 506 | $newArr = array(); |
507 | | - |
508 | | - if( ! self::isValidRegEx( $needle ) ) { |
| 507 | + |
| 508 | + $regexFunSupport = self::hasRegexFunSupport(); |
| 509 | + if( ! self::isValidRegEx( $needle, $regexFunSupport ) ) { |
509 | 510 | $needle = '/^\s*(' . preg_quote( $needle, '/' ) . ')\s*$/'; |
510 | 511 | } |
511 | 512 | |
— | — | @@ -515,8 +516,24 @@ |
516 | 517 | $value = $array[ $i ]; |
517 | 518 | |
518 | 519 | if( preg_match( $needle, $value ) ) { |
| 520 | + // Found something! |
519 | 521 | if( $transform !== '' ) { |
520 | | - $value = preg_replace( $needle, $transform, $value ); |
| 522 | + // Transform the found string. Can we use 'Regex Fun' ? |
| 523 | + if( $regexFunSupport ) { |
| 524 | + // do the transformation with Regex Fun to support 'e' flag: |
| 525 | + $value = ExtRegexFun::doPregReplace( |
| 526 | + $needle, |
| 527 | + $transform, |
| 528 | + $value, |
| 529 | + -1, |
| 530 | + $parser, |
| 531 | + array( ExtRegexFun::FLAG_REPLACEMENT_PARSE ) |
| 532 | + ); |
| 533 | + } |
| 534 | + else { |
| 535 | + // regular preg_replace: |
| 536 | + $value = preg_replace( $needle, $transform, $value ); |
| 537 | + } |
521 | 538 | } |
522 | 539 | $newArr[] = trim( $value ); |
523 | 540 | |
— | — | @@ -598,6 +615,7 @@ |
599 | 616 | |
600 | 617 | // reset all hash tables if no specific tables are given: |
601 | 618 | if( ! isset( $args[0] ) || ( $args[0] === '' && count( $args ) == 1 ) ) { |
| 619 | + // reset ALL arrays! |
602 | 620 | $store->mArrays = array(); |
603 | 621 | } |
604 | 622 | else { |
— | — | @@ -672,7 +690,8 @@ |
673 | 691 | break; |
674 | 692 | |
675 | 693 | case 'reverse': |
676 | | - $store->mArrays[ $arrayId ] = array_reverse( $store->mArrays[ $arrayId ] ); |
| 694 | + $reverse = array_reverse( $store->getArray( $arrayId ) ); |
| 695 | + $store->setArray( $arrayId, $reverse ); |
677 | 696 | break; |
678 | 697 | } ; |
679 | 698 | } |
— | — | @@ -1123,10 +1142,17 @@ |
1124 | 1143 | * Arrays parser functions or not. |
1125 | 1144 | * |
1126 | 1145 | * @param string $pattern regular expression including delimiters and optional flags |
| 1146 | + * @param bool $forRegexFun whether the regular expression is inteded to be used with 'Regex Fun' |
| 1147 | + * if supported by the wikis infrastructure. In case 'Regex Fun' is not available, |
| 1148 | + * the default validation will be used. |
1127 | 1149 | * |
1128 | 1150 | * @return boolean |
1129 | 1151 | */ |
1130 | | - static function isValidRegEx( $pattern ) { |
| 1152 | + static function isValidRegEx( $pattern, $forRegexFun = false ) { |
| 1153 | + if( $forRegexFun && self::hasRegexFunSupport() ) { |
| 1154 | + return ExtRegexFun::validateRegex( $pattern ); |
| 1155 | + } |
| 1156 | + |
1131 | 1157 | if( ! preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ) ) { |
1132 | 1158 | return false; |
1133 | 1159 | } |
— | — | @@ -1135,4 +1161,19 @@ |
1136 | 1162 | wfRestoreWarnings(); |
1137 | 1163 | return $isValid; |
1138 | 1164 | } |
| 1165 | + |
| 1166 | + /** |
| 1167 | + * Whether 'Regex Fun' extension is available in this wiki to take over preg_replace handling |
| 1168 | + * for '#arraysearcharray' function. |
| 1169 | + */ |
| 1170 | + static function hasRegexFunSupport() { |
| 1171 | + static $support = null; |
| 1172 | + if( $support === null ) { |
| 1173 | + $support = ( |
| 1174 | + defined( 'ExtRegexFun::VERSION' ) |
| 1175 | + && version_compare( ExtRegexFun::VERSION, '1.0.1', '>=' ) |
| 1176 | + ); |
| 1177 | + } |
| 1178 | + return $support; |
| 1179 | + } |
1139 | 1180 | } |