X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FPreprocessor_Hash.php;h=c7f630d5dbe05970cf88c39ae1eb8054347c8ebe;hb=cc1191e5bdd5b4878ee29fc0b103e55420011e92;hp=145fbbc592502115f0ec8bd9366d4e06637497af;hpb=41a6af704ed186a115093d2e3e9eed4ab1d81233;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 145fbbc592..c7f630d5db 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -39,9 +39,8 @@ * * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class Preprocessor_Hash extends Preprocessor { - // @codingStandardsIgnoreEnd /** * @var Parser @@ -207,13 +206,6 @@ class Preprocessor_Hash extends Preprocessor { $search = $searchBase; if ( $stack->top === false ) { $currentClosing = ''; - } elseif ( - $stack->top->close === '}-' && - $stack->top->count > 2 - ) { - # adjust closing for -{{{...{{ - $currentClosing = '}'; - $search .= $currentClosing; } else { $currentClosing = $stack->top->close; $search .= $currentClosing; @@ -590,14 +582,27 @@ class Preprocessor_Hash extends Preprocessor { strspn( $text, $curChar[$curLen - 1], $i + 1 ) + 1 : strspn( $text, $curChar, $i ); + $savedPrefix = ''; + $lineStart = ( $i > 0 && $text[$i - 1] == "\n" ); + + if ( $curChar === "-{" && $count > $curLen ) { + // -{ => {{ transition because rightmost wins + $savedPrefix = '-'; + $i++; + $curChar = '{'; + $count--; + $rule = $this->rules[$curChar]; + } + # we need to add to stack only if opening brace count is enough for one of the rules if ( $count >= $rule['min'] ) { # Add it to the stack $piece = [ 'open' => $curChar, 'close' => $rule['end'], + 'savedPrefix' => $savedPrefix, 'count' => $count, - 'lineStart' => ( $i > 0 && $text[$i - 1] == "\n" ), + 'lineStart' => $lineStart, ]; $stack->push( $piece ); @@ -614,7 +619,7 @@ class Preprocessor_Hash extends Preprocessor { } } else { # Add literal brace(s) - self::addLiteral( $accum, str_repeat( $curChar, $count ) ); + self::addLiteral( $accum, $savedPrefix . str_repeat( $curChar, $count ) ); } $i += $count; } elseif ( $found == 'close' ) { @@ -631,10 +636,6 @@ class Preprocessor_Hash extends Preprocessor { # check for maximum matching characters (if there are 5 closing # characters, we will probably need only 3 - depending on the rules) $rule = $this->rules[$piece->open]; - if ( $piece->close === '}-' && $piece->count > 2 ) { - # tweak for -{..{{ }}..}- - $rule = $this->rules['{']; - } if ( $count > $rule['max'] ) { # The specified maximum exists in the callback array, unless the caller # has made an error @@ -673,7 +674,9 @@ class Preprocessor_Hash extends Preprocessor { # The invocation is at the start of the line if lineStart is set in # the stack, and all opening brackets are used up. - if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) { + if ( $maxCount == $matchingCount && + !empty( $piece->lineStart ) && + strlen( $piece->savedPrefix ) == 0 ) { $children[] = [ '@lineStart', [ 1 ] ]; } $titleNode = [ 'title', $titleAccum ]; @@ -712,14 +715,23 @@ class Preprocessor_Hash extends Preprocessor { if ( $piece->count >= $min ) { $stack->push( $piece ); $accum =& $stack->getAccum(); + } elseif ( $piece->count == 1 && $piece->open === '{' && $piece->savedPrefix === '-' ) { + $piece->savedPrefix = ''; + $piece->open = '-{'; + $piece->count = 2; + $piece->close = $this->rules[$piece->open]['end']; + $stack->push( $piece ); + $accum =& $stack->getAccum(); } else { $s = substr( $piece->open, 0, -1 ); $s .= str_repeat( substr( $piece->open, -1 ), $piece->count - strlen( $s ) ); - self::addLiteral( $accum, $s ); + self::addLiteral( $accum, $piece->savedPrefix . $s ); } + } elseif ( $piece->savedPrefix !== '' ) { + self::addLiteral( $accum, $piece->savedPrefix ); } $stackFlags = $stack->getFlags(); @@ -745,9 +757,6 @@ class Preprocessor_Hash extends Preprocessor { $accum[] = [ 'equals', [ '=' ] ]; $stack->getCurrentPart()->eqpos = count( $accum ) - 1; ++$i; - } elseif ( $found == 'dash' ) { - self::addLiteral( $accum, '-' ); - ++$i; } } @@ -789,12 +798,11 @@ class Preprocessor_Hash extends Preprocessor { * Stack class to help Preprocessor::preprocessToObj() * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPDStack_Hash extends PPDStack { - // @codingStandardsIgnoreEnd public function __construct() { - $this->elementClass = 'PPDStackElement_Hash'; + $this->elementClass = PPDStackElement_Hash::class; parent::__construct(); $this->rootAccum = []; } @@ -803,12 +811,11 @@ class PPDStack_Hash extends PPDStack { /** * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPDStackElement_Hash extends PPDStackElement { - // @codingStandardsIgnoreEnd public function __construct( $data = [] ) { - $this->partClass = 'PPDPart_Hash'; + $this->partClass = PPDPart_Hash::class; parent::__construct( $data ); } @@ -820,7 +827,7 @@ class PPDStackElement_Hash extends PPDStackElement { */ public function breakSyntax( $openingCount = false ) { if ( $this->open == "\n" ) { - $accum = $this->parts[0]->out; + $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out ); } else { if ( $openingCount === false ) { $openingCount = $this->count; @@ -830,7 +837,7 @@ class PPDStackElement_Hash extends PPDStackElement { substr( $this->open, -1 ), $openingCount - strlen( $s ) ); - $accum = [ $s ]; + $accum = [ $this->savedPrefix . $s ]; $lastIndex = 0; $first = true; foreach ( $this->parts as $part ) { @@ -857,9 +864,8 @@ class PPDStackElement_Hash extends PPDStackElement { /** * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPDPart_Hash extends PPDPart { - // @codingStandardsIgnoreEnd public function __construct( $out = '' ) { if ( $out !== '' ) { @@ -875,9 +881,8 @@ class PPDPart_Hash extends PPDPart { * An expansion frame, used as a context to expand the result of preprocessToObj() * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPFrame_Hash implements PPFrame { - // @codingStandardsIgnoreEnd /** * @var Parser @@ -1475,9 +1480,8 @@ class PPFrame_Hash implements PPFrame { * Expansion frame with template arguments * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPTemplateFrame_Hash extends PPFrame_Hash { - // @codingStandardsIgnoreEnd public $numberedArgs, $namedArgs, $parent; public $numberedExpansionCache, $namedExpansionCache; @@ -1658,9 +1662,8 @@ class PPTemplateFrame_Hash extends PPFrame_Hash { * Expansion frame with custom arguments * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPCustomFrame_Hash extends PPFrame_Hash { - // @codingStandardsIgnoreEnd public $args; @@ -1711,9 +1714,8 @@ class PPCustomFrame_Hash extends PPFrame_Hash { /** * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPNode_Hash_Tree implements PPNode { - // @codingStandardsIgnoreEnd public $name; @@ -1774,12 +1776,12 @@ class PPNode_Hash_Tree implements PPNode { $descriptor = $store[$index]; if ( is_string( $descriptor ) ) { - $class = 'PPNode_Hash_Text'; + $class = PPNode_Hash_Text::class; } elseif ( is_array( $descriptor ) ) { if ( $descriptor[self::NAME][0] === '@' ) { - $class = 'PPNode_Hash_Attr'; + $class = PPNode_Hash_Attr::class; } else { - $class = 'PPNode_Hash_Tree'; + $class = self::class; } } else { throw new MWException( __METHOD__.': invalid node descriptor' ); @@ -2059,9 +2061,8 @@ class PPNode_Hash_Tree implements PPNode { /** * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPNode_Hash_Text implements PPNode { - // @codingStandardsIgnoreEnd public $value; private $store, $index; @@ -2130,9 +2131,8 @@ class PPNode_Hash_Text implements PPNode { /** * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPNode_Hash_Array implements PPNode { - // @codingStandardsIgnoreEnd public $value; @@ -2188,9 +2188,8 @@ class PPNode_Hash_Array implements PPNode { /** * @ingroup Parser */ -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPNode_Hash_Attr implements PPNode { - // @codingStandardsIgnoreEnd public $name, $value; private $store, $index;