Pastakhov has uploaded a new change for review. https://gerrit.wikimedia.org/r/67965
Change subject: Add PCRE Functions (version 0.4.3) ...................................................................... Add PCRE Functions (version 0.4.3) Change-Id: I29ca62d575b86e91a4aeba29f40316a9da2bfb07 --- M Foxway.php M Settings.php A includes/functions/Fpcre.php 3 files changed, 92 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Foxway refs/changes/65/67965/1 diff --git a/Foxway.php b/Foxway.php index de30ac2..5809ac9 100644 --- a/Foxway.php +++ b/Foxway.php @@ -15,7 +15,7 @@ die( 'This file is an extension to MediaWiki and thus not a valid entry point.' ); } -define( 'Foxway_VERSION' , '0.4.2' ); +define( 'Foxway_VERSION' , '0.4.3' ); // Register this extension on Special:Version $wgExtensionCredits['parserhook'][] = array( @@ -64,6 +64,7 @@ $wgAutoloadClasses['Foxway\\BaseFunction'] = $dir . '/includes/functions/BaseFunction.php'; $wgAutoloadClasses['Foxway\\FArray'] = $dir . '/includes/functions/FArray.php'; +$wgAutoloadClasses['Foxway\\Fpcre'] = $dir . '/includes/functions/Fpcre.php'; $wgAutoloadClasses['Foxway\\FString'] = $dir . '/includes/functions/FString.php'; $wgAutoloadClasses['Foxway\\FVariable'] = $dir . '/includes/functions/FVariable.php'; @@ -120,4 +121,8 @@ 'sscanf' => 2147483644, // 0b1111111111111111111111111111100 'str_ireplace' => 8, // 0b1000 'str_replace' => 8, // 0b1000 + 'preg_filter' => 16, // 0b10000 + 'preg_match_all' => 4, // 0b100 + 'preg_match' => 4, // 0b100 + 'preg_replace' => 16, // 0b10000 ); diff --git a/Settings.php b/Settings.php index be813f8..cf7751b 100644 --- a/Settings.php +++ b/Settings.php @@ -213,6 +213,17 @@ 'vsprintf', 'wordwrap', ), + 'Fpcre' => array( // PCRE Functions @see http://php.net/manual/en/ref.pcre.php + 'preg_filter', + 'preg_grep', + 'preg_last_error', + 'preg_match_all', + 'preg_match_all', + 'preg_match', + 'preg_quote', + //'preg_replace', @todo remove PREG_REPLACE_EVAL modifier + 'preg_split', + ), ); $wgFoxwayAllowedPHPConstants = array( @@ -321,4 +332,19 @@ 'YESSTR', 'NOSTR', 'CODESET', + // @see http://www.php.net/manual/en/pcre.constants.php + 'PREG_PATTERN_ORDER', + 'PREG_SET_ORDER', + 'PREG_OFFSET_CAPTURE', + 'PREG_SPLIT_NO_EMPTY', + 'PREG_SPLIT_DELIM_CAPTURE', + 'PREG_SPLIT_OFFSET_CAPTURE', + 'PREG_NO_ERROR', + 'PREG_INTERNAL_ERROR', + 'PREG_BACKTRACK_LIMIT_ERROR', + 'PREG_RECURSION_LIMIT_ERROR', + 'PREG_BAD_UTF8_ERROR', + 'PREG_BAD_UTF8_OFFSET_ERROR', + 'PCRE_VERSION', + 'PREG_GREP_INVERT', ); \ No newline at end of file diff --git a/includes/functions/Fpcre.php b/includes/functions/Fpcre.php new file mode 100644 index 0000000..0f4aaf0 --- /dev/null +++ b/includes/functions/Fpcre.php @@ -0,0 +1,60 @@ +<?php +namespace Foxway; +/** + * Fpcre class implements PCRE Functions for Foxway extension. + * + * @file Fpcre.php + * @ingroup Foxway + * @author Pavel Astakhov <pastak...@yandex.ru> + * @licence GNU General Public Licence 2.0 or later + */ +class Fpcre extends BaseFunction { + protected static $listFunction = array( + 'f_preg_filter' => array('preg_filter', 3, 5), + 'f_preg_grep' => array('preg_grep', 2, 3), + //'f_preg_last_error' @see self::f_preg_last_error + 'f_preg_match_all' => array('preg_match_all', 3, 5), // @todo PHP 5.4.0: The matches parameter became optional. => array('preg_match_all', 2, 5) + 'f_preg_match' => array('preg_match', 2, 5), + 'f_preg_quote' => array('preg_quote', 1, 2), + // @todo preg_replace_callback + //'f_preg_replace' => array('preg_replace', 3, 5), @todo remove PREG_REPLACE_EVAL modifier + 'f_preg_split' => array('preg_split', 2, 4), + ); + + public static function __callStatic($name, $arguments) { + global $wgFoxwayPassByReference; + + if( isset(self::$listFunction[$name]) ) { + $funcData = &self::$listFunction[$name]; + $refarg = &$arguments[0]; + if( isset($wgFoxwayPassByReference[$funcData[0]]) ) { + foreach ($refarg as $key => &$value) { + if( $value instanceof RValue ) { + $refarg[$key] = &$value->getReference(); + } + } + } + $c = count($refarg); + if( $c >= $funcData[1] && $c <= $funcData[2] ) { + return new RValue( call_user_func_array($funcData[0], $refarg) ); + }else{ + return self::wrongParameterCount($name, __LINE__); + } + } else { + return self::callUnknownMethod($name, __LINE__); + } + } + + /** + * Returns the error code of the last PCRE regex execution + * @param array $arguments + * @return \Foxway\RValue + */ + public static function f_preg_last_error($arguments) { + if( count($arguments) != 0 ) { + return self::wrongParameterCount( __FUNCTION__, __LINE__ ); + } + return new RValue( preg_last_error() ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/67965 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I29ca62d575b86e91a4aeba29f40316a9da2bfb07 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Foxway Gerrit-Branch: master Gerrit-Owner: Pastakhov <pastak...@yandex.ru> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits