r102088 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102087‎ | r102088 | r102089 >
Date:07:10, 5 November 2011
Author:danwe
Status:deferred
Tags:
Comment:
Version 1.0.1 started. Bug in '#regex_var' solved. Default value now gets returned in any case it should be.
Modified paths:
  • /trunk/extensions/RegexFun/README (modified) (history)
  • /trunk/extensions/RegexFun/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/RegexFun/RegexFun.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RegexFun/RELEASE-NOTES
@@ -1,5 +1,11 @@
22 Changelog:
33 ==========
 4+ * (trunk) 2011 -- version 1.0.1
 5+ - Bug in '#regex_var' solved: default value now gets returned in case '#regex' went wront or
 6+ not called before.
 7+ - '#regexall' last parameter, 'length' can be empty '' which is the specified default now. It
 8+ simply means there is not limit and all items should be returned.
 9+
410 * November 4, 2011 -- Version 1.0 (initial public release).
511 Introduces the following parser functions defined within 'ExtRegexFun' class:
612 - #regex
Index: trunk/extensions/RegexFun/RegexFun.php
@@ -6,7 +6,7 @@
77 *
88 * Info on mediawiki.org: http://www.mediawiki.org/wiki/Extension:Regex_Fun
99 *
10 - * @version: 1.0
 10+ * @version: 1.0.1
1111 * @license: ISC license
1212 * @author: Daniel Werner < danweetz@web.de >
1313 *
@@ -52,7 +52,7 @@
5353 *
5454 * @var string
5555 */
56 - const VERSION = '1.0';
 56+ const VERSION = '1.0.1';
5757
5858 /**
5959 * Sets up parser functions
@@ -298,25 +298,29 @@
299299 * @param $pattern String regular expression pattern - must use /, | or % as delimiter
300300 * @param $separator String to separate all the matches
301301 * @param $offset Integer first match to print out. Negative values possible: -1 means last match.
302 - * @param $limit Integer maximum matches for print out
 302+ * @param $length Integer maximum matches for print out
303303 *
304304 * @return String result of all matching text parts separated by a string
305305 */
306 - public static function regexall( &$parser , $subject = '' , $pattern = '' , $separator = ', ' , $offset = 0 , $limit = null ) {
 306+ public static function regexall( &$parser , $subject = '' , $pattern = '' , $separator = ', ' , $offset = 0 , $length = '' ) {
307307 // validate and check for wrong input:
308308 $continue = self::validateRegexCall( $parser, $subject, $pattern, $specialFlags, false );
309309 if( ! $continue ) {
310310 return self::invalidRegexParsingOutput( $pattern );;
311311 }
 312+
312313 // adjust default values:
313314 $offset = (int)$offset;
314 - if( $limit !== null ) {
315 - $limit = (int)$limit;
 315+
 316+ if( trim( $length ) === '' ) {
 317+ $length = null;
 318+ } else {
 319+ $length = (int)$length;
316320 }
317321
318322 if( preg_match_all( $pattern, $subject, $matches, PREG_SET_ORDER ) ) {
319323
320 - $matches = array_slice( $matches, $offset, $limit );
 324+ $matches = array_slice( $matches, $offset, $length );
321325 $output = ''; //$end = ($end or ($end >= count($matches)) ? $end : count($matches) );
322326
323327 for( $count = 0; $count < count( $matches ); $count++ ) {
@@ -342,7 +346,7 @@
343347 $lastMatches = self::getLastMatches( $parser );
344348
345349 if( $lastMatches === null ) { // last regex was invalid or none executed yet
346 - return '';
 350+ return $defaultVal;
347351 }
348352
349353 // if requested index is numerical:
Index: trunk/extensions/RegexFun/README
@@ -11,7 +11,7 @@
1212 Use of the 'e' modifier behind the expression will be detected, the effect of using 'e' now is
1313 adapted for mediawiki. With 'e' the replacement string will be parsed after references are replaced.
1414 - #regexall: Searches the whole string for as many matches as possible and returns them separated by a separator.
15 - - #regex_var: Allows to access references of the last used 'regex' or 'regexsearch' function.
 15+ - #regex_var: Allows to access subexpression references of the last used 'regex' function.
1616 - #regexquote: Runs php function 'preg_quote' on a string to use user-input savelly in regex functions. In case the
1717 first character is a character with special meaning in MW, it will be replaced with its hexadecimal
1818 notation e.g. '\x23' instead of '#'. This will prevent from things going terribly wrong when using

Status & tagging log