https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102088
Revision: 102088
Author: danwe
Date: 2011-11-05 07:10:04 +0000 (Sat, 05 Nov 2011)
Log Message:
-----------
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
trunk/extensions/RegexFun/RELEASE-NOTES
trunk/extensions/RegexFun/RegexFun.php
Modified: trunk/extensions/RegexFun/README
===================================================================
--- trunk/extensions/RegexFun/README 2011-11-05 05:15:01 UTC (rev 102087)
+++ trunk/extensions/RegexFun/README 2011-11-05 07:10:04 UTC (rev 102088)
@@ -11,7 +11,7 @@
Use of the 'e' modifier behind the expression will be
detected, the effect of using 'e' now is
adapted for mediawiki. With 'e' the replacement string will
be parsed after references are replaced.
- #regexall: Searches the whole string for as many matches as possible
and returns them separated by a separator.
- - #regex_var: Allows to access references of the last used 'regex' or
'regexsearch' function.
+ - #regex_var: Allows to access subexpression references of the last used
'regex' function.
- #regexquote: Runs php function 'preg_quote' on a string to use user-input
savelly in regex functions. In case the
first character is a character with special meaning in MW,
it will be replaced with its hexadecimal
notation e.g. '\x23' instead of '#'. This will prevent from
things going terribly wrong when using
Modified: trunk/extensions/RegexFun/RELEASE-NOTES
===================================================================
--- trunk/extensions/RegexFun/RELEASE-NOTES 2011-11-05 05:15:01 UTC (rev
102087)
+++ trunk/extensions/RegexFun/RELEASE-NOTES 2011-11-05 07:10:04 UTC (rev
102088)
@@ -1,5 +1,11 @@
Changelog:
==========
+ * (trunk) 2011 -- version 1.0.1
+ - Bug in '#regex_var' solved: default value now gets returned in case
'#regex' went wront or
+ not called before.
+ - '#regexall' last parameter, 'length' can be empty '' which is the
specified default now. It
+ simply means there is not limit and all items should be returned.
+
* November 4, 2011 -- Version 1.0 (initial public release).
Introduces the following parser functions defined within 'ExtRegexFun'
class:
- #regex
Modified: trunk/extensions/RegexFun/RegexFun.php
===================================================================
--- trunk/extensions/RegexFun/RegexFun.php 2011-11-05 05:15:01 UTC (rev
102087)
+++ trunk/extensions/RegexFun/RegexFun.php 2011-11-05 07:10:04 UTC (rev
102088)
@@ -6,7 +6,7 @@
*
* Info on mediawiki.org: http://www.mediawiki.org/wiki/Extension:Regex_Fun
*
- * @version: 1.0
+ * @version: 1.0.1
* @license: ISC license
* @author: Daniel Werner < [email protected] >
*
@@ -52,7 +52,7 @@
*
* @var string
*/
- const VERSION = '1.0';
+ const VERSION = '1.0.1';
/**
* Sets up parser functions
@@ -298,25 +298,29 @@
* @param $pattern String regular expression pattern - must use /, | or
% as delimiter
* @param $separator String to separate all the matches
* @param $offset Integer first match to print out. Negative values
possible: -1 means last match.
- * @param $limit Integer maximum matches for print out
+ * @param $length Integer maximum matches for print out
*
* @return String result of all matching text parts separated by a string
*/
- public static function regexall( &$parser , $subject = '' , $pattern = ''
, $separator = ', ' , $offset = 0 , $limit = null ) {
+ public static function regexall( &$parser , $subject = '' , $pattern = ''
, $separator = ', ' , $offset = 0 , $length = '' ) {
// validate and check for wrong input:
$continue = self::validateRegexCall( $parser, $subject,
$pattern, $specialFlags, false );
if( ! $continue ) {
return self::invalidRegexParsingOutput( $pattern );;
}
+
// adjust default values:
$offset = (int)$offset;
- if( $limit !== null ) {
- $limit = (int)$limit;
+
+ if( trim( $length ) === '' ) {
+ $length = null;
+ } else {
+ $length = (int)$length;
}
if( preg_match_all( $pattern, $subject, $matches,
PREG_SET_ORDER ) ) {
- $matches = array_slice( $matches, $offset, $limit );
+ $matches = array_slice( $matches, $offset, $length );
$output = ''; //$end = ($end or ($end >=
count($matches)) ? $end : count($matches) );
for( $count = 0; $count < count( $matches ); $count++ )
{
@@ -342,7 +346,7 @@
$lastMatches = self::getLastMatches( $parser );
if( $lastMatches === null ) { // last regex was invalid or none
executed yet
- return '';
+ return $defaultVal;
}
// if requested index is numerical:
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs