Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/250282

Change subject: Move brace matching rules to Preprocessor class
......................................................................

Move brace matching rules to Preprocessor class

Instead of declaring the array of rules within both Preprocessor_DOM:: and
Preprocessor_Hash::preprocessToXml(), declare it as a private property of the
parent Preprocessor class.

Change-Id: I6193de66566c164fe85cdd6a88c04fa9c565f1a9
---
M includes/parser/Preprocessor.php
M includes/parser/Preprocessor_DOM.php
M includes/parser/Preprocessor_Hash.php
3 files changed, 29 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/82/250282/1

diff --git a/includes/parser/Preprocessor.php b/includes/parser/Preprocessor.php
index b1e49b2..df5d499 100644
--- a/includes/parser/Preprocessor.php
+++ b/includes/parser/Preprocessor.php
@@ -31,6 +31,27 @@
        const CACHE_VERSION = 1;
 
        /**
+        * @var array Brace matching rules.
+        */
+       protected $rules = array(
+               '{' => array(
+                       'end' => '}',
+                       'names' => array(
+                               2 => 'template',
+                               3 => 'tplarg',
+                       ),
+                       'min' => 2,
+                       'max' => 3,
+               ),
+               '[' => array(
+                       'end' => ']',
+                       'names' => array( 2 => null ),
+                       'min' => 2,
+                       'max' => 2,
+               )
+       );
+
+       /**
         * Store a document tree in the cache.
         *
         * @param string $text
diff --git a/includes/parser/Preprocessor_DOM.php 
b/includes/parser/Preprocessor_DOM.php
index b71b9d2..4ca3a87 100644
--- a/includes/parser/Preprocessor_DOM.php
+++ b/includes/parser/Preprocessor_DOM.php
@@ -193,24 +193,6 @@
         * @return string
         */
        public function preprocessToXml( $text, $flags = 0 ) {
-               $rules = array(
-                       '{' => array(
-                               'end' => '}',
-                               'names' => array(
-                                       2 => 'template',
-                                       3 => 'tplarg',
-                               ),
-                               'min' => 2,
-                               'max' => 3,
-                       ),
-                       '[' => array(
-                               'end' => ']',
-                               'names' => array( 2 => null ),
-                               'min' => 2,
-                               'max' => 2,
-                       )
-               );
-
                $forInclusion = $flags & Parser::PTD_FOR_INCLUSION;
 
                $xmlishElements = $this->parser->getStripList();
@@ -328,9 +310,9 @@
                                                }
                                        } elseif ( $curChar == $currentClosing 
) {
                                                $found = 'close';
-                                       } elseif ( isset( $rules[$curChar] ) ) {
+                                       } elseif ( isset( 
$this->rules[$curChar] ) ) {
                                                $found = 'open';
-                                               $rule = $rules[$curChar];
+                                               $rule = $this->rules[$curChar];
                                        } else {
                                                # Some versions of PHP have a 
strcspn which stops on null characters
                                                # Ignore and continue
@@ -627,7 +609,7 @@
 
                                # check for maximum matching characters (if 
there are 5 closing
                                # characters, we will probably need only 3 - 
depending on the rules)
-                               $rule = $rules[$piece->open];
+                               $rule = $this->rules[$piece->open];
                                if ( $count > $rule['max'] ) {
                                        # The specified maximum exists in the 
callback array, unless the caller
                                        # has made an error
@@ -696,7 +678,7 @@
                                        $piece->parts = array( new PPDPart );
                                        $piece->count -= $matchingCount;
                                        # do we still qualify for any callback 
with remaining count?
-                                       $min = $rules[$piece->open]['min'];
+                                       $min = 
$this->rules[$piece->open]['min'];
                                        if ( $piece->count >= $min ) {
                                                $stack->push( $piece );
                                                $accum =& $stack->getAccum();
diff --git a/includes/parser/Preprocessor_Hash.php 
b/includes/parser/Preprocessor_Hash.php
index 54824da..4f12414 100644
--- a/includes/parser/Preprocessor_Hash.php
+++ b/includes/parser/Preprocessor_Hash.php
@@ -118,24 +118,6 @@
                        return unserialize( $tree );
                }
 
-               $rules = array(
-                       '{' => array(
-                               'end' => '}',
-                               'names' => array(
-                                       2 => 'template',
-                                       3 => 'tplarg',
-                               ),
-                               'min' => 2,
-                               'max' => 3,
-                       ),
-                       '[' => array(
-                               'end' => ']',
-                               'names' => array( 2 => null ),
-                               'min' => 2,
-                               'max' => 2,
-                       )
-               );
-
                $forInclusion = $flags & Parser::PTD_FOR_INCLUSION;
 
                $xmlishElements = $this->parser->getStripList();
@@ -252,9 +234,9 @@
                                                }
                                        } elseif ( $curChar == $currentClosing 
) {
                                                $found = 'close';
-                                       } elseif ( isset( $rules[$curChar] ) ) {
+                                       } elseif ( isset( 
$this->rules[$curChar] ) ) {
                                                $found = 'open';
-                                               $rule = $rules[$curChar];
+                                               $rule = $this->rules[$curChar];
                                        } else {
                                                # Some versions of PHP have a 
strcspn which stops on null characters
                                                # Ignore and continue
@@ -557,7 +539,7 @@
 
                                # check for maximum matching characters (if 
there are 5 closing
                                # characters, we will probably need only 3 - 
depending on the rules)
-                               $rule = $rules[$piece->open];
+                               $rule = $this->rules[$piece->open];
                                if ( $count > $rule['max'] ) {
                                        # The specified maximum exists in the 
callback array, unless the caller
                                        # has made an error
@@ -668,7 +650,7 @@
                                        $piece->parts = array( new PPDPart_Hash 
);
                                        $piece->count -= $matchingCount;
                                        # do we still qualify for any callback 
with remaining count?
-                                       $min = $rules[$piece->open]['min'];
+                                       $min = 
$this->rules[$piece->open]['min'];
                                        if ( $piece->count >= $min ) {
                                                $stack->push( $piece );
                                                $accum =& $stack->getAccum();

-- 
To view, visit https://gerrit.wikimedia.org/r/250282
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6193de66566c164fe85cdd6a88c04fa9c565f1a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to