diff options
Diffstat (limited to 'extensions/ParserFunctions/ParserFunctions_body.php')
-rw-r--r-- | extensions/ParserFunctions/ParserFunctions_body.php | 102 |
1 files changed, 17 insertions, 85 deletions
diff --git a/extensions/ParserFunctions/ParserFunctions_body.php b/extensions/ParserFunctions/ParserFunctions_body.php index d3debf36..2651b06e 100644 --- a/extensions/ParserFunctions/ParserFunctions_body.php +++ b/extensions/ParserFunctions/ParserFunctions_body.php @@ -12,7 +12,6 @@ class ExtParserFunctions { */ public static function clearState( $parser ) { self::$mTimeChars = 0; - $parser->pf_markerRegex = null; return true; } @@ -31,38 +30,6 @@ class ExtParserFunctions { } /** - * Get the marker regex. Cached. - * @param $parser Parser - * @return - */ - public static function getMarkerRegex( $parser ) { - self::registerClearHook(); - if ( isset( $parser->pf_markerRegex ) ) { - return $parser->pf_markerRegex; - } - - wfProfileIn( __METHOD__ ); - - $prefix = preg_quote( $parser->uniqPrefix(), '/' ); - - $suffix = preg_quote( Parser::MARKER_SUFFIX, '/' ); - - $parser->pf_markerRegex = '/' . $prefix . '(?:(?!' . $suffix . ').)*' . $suffix . '/us'; - - wfProfileOut( __METHOD__ ); - return $parser->pf_markerRegex; - } - - /** - * @param $parser Parser - * @param $text string - * @return string - */ - private static function killMarkers ( $parser, $text ) { - return preg_replace( self::getMarkerRegex( $parser ), '' , $text ); - } - - /** * @return ExprParser */ public static function &getExprParser() { @@ -621,13 +588,8 @@ class ExtParserFunctions { * @return int */ public static function runLen ( $parser, $inStr = '' ) { - wfProfileIn( __METHOD__ ); - - $inStr = self::killMarkers( $parser, (string)$inStr ); - $len = mb_strlen( $inStr ); - - wfProfileOut( __METHOD__ ); - return $len; + $inStr = $parser->killMarkers( (string)$inStr ); + return mb_strlen( $inStr ); } /** @@ -644,23 +606,19 @@ class ExtParserFunctions { * @return int|string */ public static function runPos ( $parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { - wfProfileIn( __METHOD__ ); - - $inStr = self::killMarkers( $parser, (string)$inStr ); - $inNeedle = self::killMarkers( $parser, (string)$inNeedle ); + $inStr = $parser->killMarkers( (string)$inStr ); + $inNeedle = $parser->killMarkers( (string)$inNeedle ); if ( !self::checkLength( $inStr ) || !self::checkLength( $inNeedle ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } if ( $inNeedle == '' ) { $inNeedle = ' '; } - $pos = mb_strpos( $inStr, $inNeedle, $inOffset ); + $pos = mb_strpos( $inStr, $inNeedle, intval( $inOffset ) ); if ( $pos === false ) { $pos = ""; } - wfProfileOut( __METHOD__ ); return $pos; } @@ -677,14 +635,11 @@ class ExtParserFunctions { * @return int|string */ public static function runRPos ( $parser, $inStr = '', $inNeedle = '' ) { - wfProfileIn( __METHOD__ ); - - $inStr = self::killMarkers( $parser, (string)$inStr ); - $inNeedle = self::killMarkers( $parser, (string)$inNeedle ); + $inStr = $parser->killMarkers( (string)$inStr ); + $inNeedle = $parser->killMarkers( (string)$inNeedle ); if ( !self::checkLength( $inStr ) || !self::checkLength( $inNeedle ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } @@ -693,7 +648,6 @@ class ExtParserFunctions { $pos = mb_strrpos( $inStr, $inNeedle ); if ( $pos === false ) { $pos = -1; } - wfProfileOut( __METHOD__ ); return $pos; } @@ -716,12 +670,9 @@ class ExtParserFunctions { * @return string */ public static function runSub ( $parser, $inStr = '', $inStart = 0, $inLength = 0 ) { - wfProfileIn( __METHOD__ ); - - $inStr = self::killMarkers( $parser, (string)$inStr ); + $inStr = $parser->killMarkers( (string)$inStr ); if ( !self::checkLength( $inStr ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } @@ -731,7 +682,6 @@ class ExtParserFunctions { $result = mb_substr( $inStr, intval( $inStart ), intval( $inLength ) ); } - wfProfileOut( __METHOD__ ); return $result; } @@ -747,14 +697,11 @@ class ExtParserFunctions { * @return int|string */ public static function runCount ( $parser, $inStr = '', $inSubStr = '' ) { - wfProfileIn( __METHOD__ ); - - $inStr = self::killMarkers( $parser, (string)$inStr ); - $inSubStr = self::killMarkers( $parser, (string)$inSubStr ); + $inStr = $parser->killMarkers( (string)$inStr ); + $inSubStr = $parser->killMarkers( (string)$inSubStr ); if ( !self::checkLength( $inStr ) || !self::checkLength( $inSubStr ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } @@ -764,7 +711,6 @@ class ExtParserFunctions { $result = mb_substr_count( $inStr, $inSubStr ); - wfProfileOut( __METHOD__ ); return $result; } @@ -786,16 +732,14 @@ class ExtParserFunctions { public static function runReplace( $parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '', $inLimit = -1 ) { global $wgPFStringLengthLimit; - wfProfileIn( __METHOD__ ); - $inStr = self::killMarkers( $parser, (string)$inStr ); - $inReplaceFrom = self::killMarkers( $parser, (string)$inReplaceFrom ); - $inReplaceTo = self::killMarkers( $parser, (string)$inReplaceTo ); + $inStr = $parser->killMarkers( (string)$inStr ); + $inReplaceFrom = $parser->killMarkers( (string)$inReplaceFrom ); + $inReplaceTo = $parser->killMarkers( (string)$inReplaceTo ); if ( !self::checkLength( $inStr ) || !self::checkLength( $inReplaceFrom ) || !self::checkLength( $inReplaceTo ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } @@ -822,11 +766,9 @@ class ExtParserFunctions { $inReplaceTo, $inStr, $limit ); if ( !self::checkLength( $result ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } - wfProfileOut( __METHOD__ ); return $result; } @@ -848,10 +790,8 @@ class ExtParserFunctions { * @return string */ public static function runExplode ( $parser, $inStr = '', $inDiv = '', $inPos = 0, $inLim = null ) { - wfProfileIn( __METHOD__ ); - - $inStr = self::killMarkers( $parser, (string)$inStr ); - $inDiv = self::killMarkers( $parser, (string)$inDiv ); + $inStr = $parser->killMarkers( (string)$inStr ); + $inDiv = $parser->killMarkers( (string)$inDiv ); if ( $inDiv == '' ) { $inDiv = ' '; @@ -859,7 +799,6 @@ class ExtParserFunctions { if ( !self::checkLength( $inStr ) || !self::checkLength( $inDiv ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } @@ -875,7 +814,6 @@ class ExtParserFunctions { $result = ''; } - wfProfileOut( __METHOD__ ); return $result; } @@ -888,18 +826,12 @@ class ExtParserFunctions { * @return string */ public static function runUrlDecode( $parser, $inStr = '' ) { - wfProfileIn( __METHOD__ ); - - $inStr = self::killMarkers( $parser, (string)$inStr ); + $inStr = $parser->killMarkers( (string)$inStr ); if ( !self::checkLength( $inStr ) ) { - wfProfileOut( __METHOD__ ); return self::tooLongError(); } - $result = urldecode( $inStr ); - - wfProfileOut( __METHOD__ ); - return $result; + return urldecode( $inStr ); } /** |