Umherirrender has uploaded a new change for review. https://gerrit.wikimedia.org/r/149382
Change subject: Rename Preprocessor_DOM/Preprocessor_Hash to PreprocessorDOM/PreprocessorHash ...................................................................... Rename Preprocessor_DOM/Preprocessor_Hash to PreprocessorDOM/PreprocessorHash phpcs says: Class name "Preprocessor_DOM" is not in camel caps format Added all effected classes to release notes Preprocessor_DOM and Preprocessor_Hash now extends PreprocessorDOM/PreprocessorHash for backward compatibility, because LocalSettings.php can contains the class due to $wgParserConf['preprocessorClass'] Change-Id: I1a77f4894953f05afd4ff0751657ac0c91f5f233 --- M RELEASE-NOTES-1.24 M includes/AutoLoader.php M includes/DefaultSettings.php M includes/parser/Parser.php R includes/parser/PreprocessorDOM.php R includes/parser/PreprocessorHash.php M maintenance/preprocessDump.php M tests/phpunit/includes/parser/PreprocessorTest.php 8 files changed, 211 insertions(+), 166 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/82/149382/1 diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 2e9aaaf..0b92987 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -282,6 +282,23 @@ * CSSJanus_Tokenizer to CSSJanusTokenizer * MediaWiki_I18N to MediaWikiI18N * Parser_DiffTest to ParserDiffTest +* PPCustomFrame_DOM to PPCustomFrameDOM +* PPCustomFrame_Hash to PPCustomFrameHash +* PPDAccum_Hash to PPDAccumHash +* PPDPart_Hash to PPDPartHash +* PPDStack_Hash to PPDStackHash +* PPDStackElement_Hash to PPDStackElementHash +* PPFrame_DOM to PPFrameDOM +* PPFrame_Hash to PPFrameHash +* PPNode_DOM to PPNodeDOM +* PPNode_Hash_Array to PPNodeHashArray +* PPNode_Hash_Attr to PPNodeHashAttr +* PPNode_Hash_Text to PPNodeHashText +* PPNode_Hash_Tree to PPNodeHashTree +* PPTemplateFrame_DOM to PPTemplateFrameDOM +* PPTemplateFrame_Hash to PPTemplateFrameHash +* Preprocessor_Hash to PreprocessorHash +* Preprocessor_DOM to PreprocessorDOM * RevDel_ArchiveItem to RevDelArchiveItem * RevDel_ArchiveList to RevDelArchiveList * RevDel_ArchivedFileItem to RevDelArchivedFileItem diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index f35b380..5ddb4bb 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -799,34 +799,36 @@ 'LinkHolderArray' => 'includes/parser/LinkHolderArray.php', 'MWTidy' => 'includes/parser/MWTidy.php', 'MWTidyWrapper' => 'includes/parser/MWTidy.php', - 'PPCustomFrame_DOM' => 'includes/parser/Preprocessor_DOM.php', - 'PPCustomFrame_Hash' => 'includes/parser/Preprocessor_Hash.php', - 'PPDAccum_Hash' => 'includes/parser/Preprocessor_Hash.php', - 'PPDPart' => 'includes/parser/Preprocessor_DOM.php', - 'PPDPart_Hash' => 'includes/parser/Preprocessor_Hash.php', - 'PPDStack' => 'includes/parser/Preprocessor_DOM.php', - 'PPDStackElement' => 'includes/parser/Preprocessor_DOM.php', - 'PPDStackElement_Hash' => 'includes/parser/Preprocessor_Hash.php', - 'PPDStack_Hash' => 'includes/parser/Preprocessor_Hash.php', + 'PPCustomFrameDOM' => 'includes/parser/PreprocessorDOM.php', + 'PPCustomFrameHash' => 'includes/parser/PreprocessorHash.php', + 'PPDAccumHash' => 'includes/parser/PreprocessorHash.php', + 'PPDPart' => 'includes/parser/PreprocessorDOM.php', + 'PPDPartHash' => 'includes/parser/PreprocessorHash.php', + 'PPDStack' => 'includes/parser/PreprocessorDOM.php', + 'PPDStackElement' => 'includes/parser/PreprocessorDOM.php', + 'PPDStackElementHash' => 'includes/parser/PreprocessorHash.php', + 'PPDStackHash' => 'includes/parser/PreprocessorHash.php', 'PPFrame' => 'includes/parser/Preprocessor.php', - 'PPFrame_DOM' => 'includes/parser/Preprocessor_DOM.php', - 'PPFrame_Hash' => 'includes/parser/Preprocessor_Hash.php', + 'PPFrameDOM' => 'includes/parser/PreprocessorDOM.php', + 'PPFrameHash' => 'includes/parser/PreprocessorHash.php', 'PPNode' => 'includes/parser/Preprocessor.php', - 'PPNode_DOM' => 'includes/parser/Preprocessor_DOM.php', - 'PPNode_Hash_Array' => 'includes/parser/Preprocessor_Hash.php', - 'PPNode_Hash_Attr' => 'includes/parser/Preprocessor_Hash.php', - 'PPNode_Hash_Text' => 'includes/parser/Preprocessor_Hash.php', - 'PPNode_Hash_Tree' => 'includes/parser/Preprocessor_Hash.php', - 'PPTemplateFrame_DOM' => 'includes/parser/Preprocessor_DOM.php', - 'PPTemplateFrame_Hash' => 'includes/parser/Preprocessor_Hash.php', + 'PPNodeDOM' => 'includes/parser/PreprocessorDOM.php', + 'PPNodeHashArray' => 'includes/parser/PreprocessorHash.php', + 'PPNodeHashAttr' => 'includes/parser/PreprocessorHash.php', + 'PPNodeHashText' => 'includes/parser/PreprocessorHash.php', + 'PPNodeHashTree' => 'includes/parser/PreprocessorHash.php', + 'PPTemplateFrameDOM' => 'includes/parser/PreprocessorDOM.php', + 'PPTemplateFrameHash' => 'includes/parser/PreprocessorHash.php', 'Parser' => 'includes/parser/Parser.php', 'ParserCache' => 'includes/parser/ParserCache.php', 'ParserOptions' => 'includes/parser/ParserOptions.php', 'ParserOutput' => 'includes/parser/ParserOutput.php', 'ParserDiffTest' => 'includes/parser/ParserDiffTest.php', 'Preprocessor' => 'includes/parser/Preprocessor.php', - 'Preprocessor_DOM' => 'includes/parser/Preprocessor_DOM.php', - 'Preprocessor_Hash' => 'includes/parser/Preprocessor_Hash.php', + 'PreprocessorDOM' => 'includes/parser/PreprocessorDOM.php', + 'Preprocessor_DOM' => 'includes/parser/PreprocessorDOM.php', + 'PreprocessorHash' => 'includes/parser/PreprocessorHash.php', + 'Preprocessor_Hash' => 'includes/parser/PreprocessorHash.php', 'StripState' => 'includes/parser/StripState.php', # includes/profiler diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3ef59b3..b75e154 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3723,13 +3723,13 @@ * class The class name * * preprocessorClass The preprocessor class. Two classes are currently available: - * Preprocessor_Hash, which uses plain PHP arrays for temporary - * storage, and Preprocessor_DOM, which uses the DOM module for - * temporary storage. Preprocessor_DOM generally uses less memory; + * PreprocessorHash, which uses plain PHP arrays for temporary + * storage, and PreprocessorDOM, which uses the DOM module for + * temporary storage. PreprocessorDOM generally uses less memory; * the speed of the two is roughly the same. * - * If this parameter is not given, it uses Preprocessor_DOM if the - * DOM module is available, otherwise it uses Preprocessor_Hash. + * If this parameter is not given, it uses PreprocessorDOM if the + * DOM module is available, otherwise it uses PreprocessorHash. * * The entire associative array will be passed through to the constructor as * the first parameter. Note that only Setup.php can use this variable -- @@ -3740,7 +3740,7 @@ */ $wgParserConf = array( 'class' => 'Parser', - #'preprocessorClass' => 'Preprocessor_Hash', + #'preprocessorClass' => 'PreprocessorHash', ); /** @@ -3757,7 +3757,7 @@ /** * A complexity limit on template expansion: the maximum number of elements * generated by Preprocessor::preprocessToObj(). This allows you to limit the - * amount of memory used by the Preprocessor_DOM node cache: testing indicates + * amount of memory used by the PreprocessorDOM node cache: testing indicates * that each element uses about 160 bytes of memory on a 64-bit processor, so * this default corresponds to about 155 MB. * diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index bc4fcce..4b0cc36 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -227,16 +227,16 @@ if ( isset( $conf['preprocessorClass'] ) ) { $this->mPreprocessorClass = $conf['preprocessorClass']; } elseif ( defined( 'HPHP_VERSION' ) ) { - # Preprocessor_Hash is much faster than Preprocessor_DOM under HipHop - $this->mPreprocessorClass = 'Preprocessor_Hash'; + # PreprocessorHash is much faster than PreprocessorDOM under HipHop + $this->mPreprocessorClass = 'PreprocessorHash'; } elseif ( extension_loaded( 'domxml' ) ) { # PECL extension that conflicts with the core DOM extension (bug 13770) wfDebug( "Warning: you have the obsolete domxml extension for PHP. Please remove it!\n" ); - $this->mPreprocessorClass = 'Preprocessor_Hash'; + $this->mPreprocessorClass = 'PreprocessorHash'; } elseif ( extension_loaded( 'dom' ) ) { - $this->mPreprocessorClass = 'Preprocessor_DOM'; + $this->mPreprocessorClass = 'PreprocessorDOM'; } else { - $this->mPreprocessorClass = 'Preprocessor_Hash'; + $this->mPreprocessorClass = 'PreprocessorHash'; } wfDebug( __CLASS__ . ": using preprocessor: {$this->mPreprocessorClass}\n" ); } diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/PreprocessorDOM.php similarity index 95% rename from includes/parser/Preprocessor_DOM.php rename to includes/parser/PreprocessorDOM.php index f5fc3ec..d9c6905 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/PreprocessorDOM.php @@ -24,7 +24,7 @@ /** * @ingroup Parser */ -class Preprocessor_DOM implements Preprocessor { +class PreprocessorDOM implements Preprocessor { /** * @var Parser @@ -49,23 +49,23 @@ } /** - * @return PPFrame_DOM + * @return PPFrameDOM */ function newFrame() { - return new PPFrame_DOM( $this ); + return new PPFrameDOM( $this ); } /** * @param array $args - * @return PPCustomFrame_DOM + * @return PPCustomFrameDOM */ function newCustomFrame( $args ) { - return new PPCustomFrame_DOM( $this, $args ); + return new PPCustomFrameDOM( $this, $args ); } /** * @param array $values - * @return PPNode_DOM + * @return PPNodeDOM */ function newPartNodeArray( $values ) { //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais) @@ -102,7 +102,7 @@ } $root = $dom->documentElement; - $node = new PPNode_DOM( $root->childNodes ); + $node = new PPNodeDOM( $root->childNodes ); return $node; } @@ -144,7 +144,7 @@ * dependency requirements. * * @throws MWException - * @return PPNode_DOM + * @return PPNodeDOM */ function preprocessToObj( $text, $flags = 0 ) { wfProfileIn( __METHOD__ ); @@ -203,7 +203,7 @@ $result = $dom->loadXML( $xml, 1 << 19 ); } if ( $result ) { - $obj = new PPNode_DOM( $dom->documentElement ); + $obj = new PPNodeDOM( $dom->documentElement ); } wfProfileOut( __METHOD__ . '-loadXML' ); @@ -769,6 +769,19 @@ } /** + * @ingroup Parser + * @deprecated since 1.24 Use PreprocessorDOM instead + */ +// @codingStandardsIgnoreStart Exclude backward class name from CodeSniffer checks +class Preprocessor_DOM extends PreprocessorDOM { + function __construct( $parser ) { + wfDeprecated( __CLASS__, '1.24' ); + parent::__construct( $parser ); + } +} +// @codingStandardsIgnoreEnd + +/** * Stack class to help Preprocessor::preprocessToObj() * @ingroup Parser */ @@ -953,7 +966,7 @@ * An expansion frame, used as a context to expand the result of preprocessToObj() * @ingroup Parser */ -class PPFrame_DOM implements PPFrame { +class PPFrameDOM implements PPFrame { /** * @var Preprocessor @@ -1012,7 +1025,7 @@ * @param bool|array $args * @param Title|bool $title * @param int $indexOffset - * @return PPTemplateFrame_DOM + * @return PPTemplateFrameDOM */ function newChild( $args = false, $title = false, $indexOffset = 0 ) { $namedArgs = array(); @@ -1049,13 +1062,13 @@ } } } - return new PPTemplateFrame_DOM( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title ); + return new PPTemplateFrameDOM( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title ); } /** * @throws MWException * @param string|int $key - * @param string|PPNode_DOM|DOMDocument $root + * @param string|PPNodeDOM|DOMDocument $root * @param int $flags * @return string */ @@ -1066,7 +1079,7 @@ /** * @throws MWException - * @param string|PPNode_DOM|DOMDocument $root + * @param string|PPNodeDOM|DOMDocument $root * @param int $flags * @return string */ @@ -1097,7 +1110,7 @@ $this->parser->mHighestExpansionDepth = $expansionDepth; } - if ( $root instanceof PPNode_DOM ) { + if ( $root instanceof PPNodeDOM ) { $root = $root->node; } if ( $root instanceof DOMDocument ) { @@ -1114,7 +1127,7 @@ $out =& $outStack[$level]; $index =& $indexStack[$level]; - if ( $iteratorNode instanceof PPNode_DOM ) { + if ( $iteratorNode instanceof PPNodeDOM ) { $iteratorNode = $iteratorNode->node; } @@ -1143,7 +1156,7 @@ $iteratorStack[$level] = false; } - if ( $contextNode instanceof PPNode_DOM ) { + if ( $contextNode instanceof PPNodeDOM ) { $contextNode = $contextNode->node; } @@ -1169,8 +1182,8 @@ } else { $lineStart = $contextNode->getAttribute( 'lineStart' ); $params = array( - 'title' => new PPNode_DOM( $title ), - 'parts' => new PPNode_DOM( $parts ), + 'title' => new PPNodeDOM( $title ), + 'parts' => new PPNodeDOM( $parts ), 'lineStart' => $lineStart ); $ret = $this->parser->braceSubstitution( $params, $this ); if ( isset( $ret['object'] ) ) { @@ -1189,8 +1202,8 @@ $newIterator = $this->virtualBracketedImplode( '{{{', '|', '}}}', $title, $parts ); } else { $params = array( - 'title' => new PPNode_DOM( $title ), - 'parts' => new PPNode_DOM( $parts ) ); + 'title' => new PPNodeDOM( $title ), + 'parts' => new PPNodeDOM( $parts ) ); $ret = $this->parser->argSubstitution( $params, $this ); if ( isset( $ret['object'] ) ) { $newIterator = $ret['object']; @@ -1250,10 +1263,10 @@ $out .= $s; } else { $params = array( - 'name' => new PPNode_DOM( $names->item( 0 ) ), - 'attr' => $attrs->length > 0 ? new PPNode_DOM( $attrs->item( 0 ) ) : null, - 'inner' => $inners->length > 0 ? new PPNode_DOM( $inners->item( 0 ) ) : null, - 'close' => $closes->length > 0 ? new PPNode_DOM( $closes->item( 0 ) ) : null, + 'name' => new PPNodeDOM( $names->item( 0 ) ), + 'attr' => $attrs->length > 0 ? new PPNodeDOM( $attrs->item( 0 ) ) : null, + 'inner' => $inners->length > 0 ? new PPNodeDOM( $inners->item( 0 ) ) : null, + 'close' => $closes->length > 0 ? new PPNodeDOM( $closes->item( 0 ) ) : null, ); $out .= $this->parser->extensionSubstitution( $params, $this ); } @@ -1285,7 +1298,7 @@ } if ( $newIterator !== false ) { - if ( $newIterator instanceof PPNode_DOM ) { + if ( $newIterator instanceof PPNodeDOM ) { $newIterator = $newIterator->node; } $outStack[] = ''; @@ -1319,7 +1332,7 @@ $first = true; $s = ''; foreach ( $args as $root ) { - if ( $root instanceof PPNode_DOM ) { + if ( $root instanceof PPNodeDOM ) { $root = $root->node; } if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) { @@ -1350,7 +1363,7 @@ $first = true; $s = ''; foreach ( $args as $root ) { - if ( $root instanceof PPNode_DOM ) { + if ( $root instanceof PPNodeDOM ) { $root = $root->node; } if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) { @@ -1381,7 +1394,7 @@ $first = true; foreach ( $args as $root ) { - if ( $root instanceof PPNode_DOM ) { + if ( $root instanceof PPNodeDOM ) { $root = $root->node; } if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) { @@ -1412,7 +1425,7 @@ $first = true; foreach ( $args as $root ) { - if ( $root instanceof PPNode_DOM ) { + if ( $root instanceof PPNodeDOM ) { $root = $root->node; } if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) { @@ -1548,18 +1561,18 @@ * Expansion frame with template arguments * @ingroup Parser */ -class PPTemplateFrame_DOM extends PPFrame_DOM { +class PPTemplateFrameDOM extends PPFrameDOM { var $numberedArgs, $namedArgs; /** - * @var PPFrame_DOM + * @var PPFrameDOM */ var $parent; var $numberedExpansionCache, $namedExpansionCache; /** * @param Preprocessor $preprocessor - * @param bool|PPFrame_DOM $parent + * @param bool|PPFrameDOM $parent * @param array $numberedArgs * @param array $namedArgs * @param bool|Title $title @@ -1604,7 +1617,7 @@ /** * @throws MWException * @param string|int $key - * @param string|PPNode_DOM|DOMDocument $root + * @param string|PPNodeDOM|DOMDocument $root * @param int $flags * @return string */ @@ -1712,7 +1725,7 @@ * Expansion frame with custom arguments * @ingroup Parser */ -class PPCustomFrame_DOM extends PPFrame_DOM { +class PPCustomFrameDOM extends PPFrameDOM { var $args; function __construct( $preprocessor, $args ) { @@ -1758,7 +1771,7 @@ /** * @ingroup Parser */ -class PPNode_DOM implements PPNode { +class PPNodeDOM implements PPNode { /** * @var DOMElement @@ -1793,21 +1806,21 @@ } /** - * @return bool|PPNode_DOM + * @return bool|PPNodeDOM */ function getChildren() { return $this->node->childNodes ? new self( $this->node->childNodes ) : false; } /** - * @return bool|PPNode_DOM + * @return bool|PPNodeDOM */ function getFirstChild() { return $this->node->firstChild ? new self( $this->node->firstChild ) : false; } /** - * @return bool|PPNode_DOM + * @return bool|PPNodeDOM */ function getNextSibling() { return $this->node->nextSibling ? new self( $this->node->nextSibling ) : false; @@ -1816,7 +1829,7 @@ /** * @param string $type * - * @return bool|PPNode_DOM + * @return bool|PPNodeDOM */ function getChildrenOfType( $type ) { return new self( $this->getXPath()->query( $type, $this->node ) ); @@ -1835,7 +1848,7 @@ /** * @param int $i - * @return bool|PPNode_DOM + * @return bool|PPNodeDOM */ function item( $i ) { $item = $this->node->item( $i ); diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/PreprocessorHash.php similarity index 91% rename from includes/parser/Preprocessor_Hash.php rename to includes/parser/PreprocessorHash.php index 26daca1..8bf02c6 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/PreprocessorHash.php @@ -27,7 +27,7 @@ * * "<h>" nodes that aren't at the top are replaced with <possible-h> * @ingroup Parser */ -class Preprocessor_Hash implements Preprocessor { +class PreprocessorHash implements Preprocessor { /** * @var Parser */ @@ -40,48 +40,48 @@ } /** - * @return PPFrame_Hash + * @return PPFrameHash */ function newFrame() { - return new PPFrame_Hash( $this ); + return new PPFrameHash( $this ); } /** * @param array $args - * @return PPCustomFrame_Hash + * @return PPCustomFrameHash */ function newCustomFrame( $args ) { - return new PPCustomFrame_Hash( $this, $args ); + return new PPCustomFrameHash( $this, $args ); } /** * @param array $values - * @return PPNode_Hash_Array + * @return PPNodeHashArray */ function newPartNodeArray( $values ) { $list = array(); foreach ( $values as $k => $val ) { - $partNode = new PPNode_Hash_Tree( 'part' ); - $nameNode = new PPNode_Hash_Tree( 'name' ); + $partNode = new PPNodeHashTree( 'part' ); + $nameNode = new PPNodeHashTree( 'name' ); if ( is_int( $k ) ) { - $nameNode->addChild( new PPNode_Hash_Attr( 'index', $k ) ); + $nameNode->addChild( new PPNodeHashAttr( 'index', $k ) ); $partNode->addChild( $nameNode ); } else { - $nameNode->addChild( new PPNode_Hash_Text( $k ) ); + $nameNode->addChild( new PPNodeHashText( $k ) ); $partNode->addChild( $nameNode ); - $partNode->addChild( new PPNode_Hash_Text( '=' ) ); + $partNode->addChild( new PPNodeHashText( '=' ) ); } - $valueNode = new PPNode_Hash_Tree( 'value' ); - $valueNode->addChild( new PPNode_Hash_Text( $val ) ); + $valueNode = new PPNodeHashTree( 'value' ); + $valueNode->addChild( new PPNodeHashText( $val ) ); $partNode->addChild( $valueNode ); $list[] = $partNode; } - $node = new PPNode_Hash_Array( $list ); + $node = new PPNodeHashArray( $list ); return $node; } @@ -106,7 +106,7 @@ * dependency requirements. * * @throws MWException - * @return PPNode_Hash_Tree + * @return PPNodeHashTree */ function preprocessToObj( $text, $flags = 0 ) { wfProfileIn( __METHOD__ ); @@ -178,7 +178,7 @@ // Use "A" modifier (anchored) instead of "^", because ^ doesn't work with an offset $elementsRegex = "~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA"; - $stack = new PPDStack_Hash; + $stack = new PPDStackHash; $searchBase = "[{<\n"; // For fast reverse searches @@ -347,7 +347,7 @@ // Sanity check first though $wsLength = $i - $wsStart; if ( $wsLength > 0 - && $accum->lastNode instanceof PPNode_Hash_Text + && $accum->lastNode instanceof PPNodeHashText && strspn( $accum->lastNode->value, " \t", -$wsLength ) === $wsLength ) { $accum->lastNode->value = substr( $accum->lastNode->value, 0, -$wsLength ); @@ -445,14 +445,14 @@ $attr = substr( $text, $attrStart, $attrEnd - $attrStart ); } - $extNode = new PPNode_Hash_Tree( 'ext' ); - $extNode->addChild( PPNode_Hash_Tree::newWithText( 'name', $name ) ); - $extNode->addChild( PPNode_Hash_Tree::newWithText( 'attr', $attr ) ); + $extNode = new PPNodeHashTree( 'ext' ); + $extNode->addChild( PPNodeHashTree::newWithText( 'name', $name ) ); + $extNode->addChild( PPNodeHashTree::newWithText( 'attr', $attr ) ); if ( $inner !== null ) { - $extNode->addChild( PPNode_Hash_Tree::newWithText( 'inner', $inner ) ); + $extNode->addChild( PPNodeHashTree::newWithText( 'inner', $inner ) ); } if ( $close !== null ) { - $extNode->addChild( PPNode_Hash_Tree::newWithText( 'close', $close ) ); + $extNode->addChild( PPNodeHashTree::newWithText( 'close', $close ) ); } $accum->addNode( $extNode ); } elseif ( $found == 'line-start' ) { @@ -475,7 +475,7 @@ $piece = array( 'open' => "\n", 'close' => "\n", - 'parts' => array( new PPDPart_Hash( str_repeat( '=', $count ) ) ), + 'parts' => array( new PPDPartHash( str_repeat( '=', $count ) ) ), 'startPos' => $i, 'count' => $count ); $stack->push( $piece ); @@ -517,9 +517,9 @@ } if ( $count > 0 ) { // Normal match, output <h> - $element = new PPNode_Hash_Tree( 'possible-h' ); - $element->addChild( new PPNode_Hash_Attr( 'level', $count ) ); - $element->addChild( new PPNode_Hash_Attr( 'i', $headingIndex++ ) ); + $element = new PPNodeHashTree( 'possible-h' ); + $element->addChild( new PPNodeHashAttr( 'level', $count ) ); + $element->addChild( new PPNodeHashAttr( 'i', $headingIndex++ ) ); $element->lastChild->nextSibling = $accum->firstNode; $element->lastChild = $accum->lastNode; } else { @@ -610,14 +610,14 @@ $titleAccum = $parts[0]->out; unset( $parts[0] ); - $element = new PPNode_Hash_Tree( $name ); + $element = new PPNodeHashTree( $name ); # 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 ) ) { - $element->addChild( new PPNode_Hash_Attr( 'lineStart', 1 ) ); + $element->addChild( new PPNodeHashAttr( 'lineStart', 1 ) ); } - $titleNode = new PPNode_Hash_Tree( 'title' ); + $titleNode = new PPNodeHashTree( 'title' ); $titleNode->firstChild = $titleAccum->firstNode; $titleNode->lastChild = $titleAccum->lastNode; $element->addChild( $titleNode ); @@ -651,7 +651,7 @@ $equalsNode = $node; // Construct name node - $nameNode = new PPNode_Hash_Tree( 'name' ); + $nameNode = new PPNodeHashTree( 'name' ); if ( $lastNode !== false ) { $lastNode->nextSibling = false; $nameNode->firstChild = $part->out->firstNode; @@ -659,21 +659,21 @@ } // Construct value node - $valueNode = new PPNode_Hash_Tree( 'value' ); + $valueNode = new PPNodeHashTree( 'value' ); if ( $equalsNode->nextSibling !== false ) { $valueNode->firstChild = $equalsNode->nextSibling; $valueNode->lastChild = $part->out->lastNode; } - $partNode = new PPNode_Hash_Tree( 'part' ); + $partNode = new PPNodeHashTree( 'part' ); $partNode->addChild( $nameNode ); $partNode->addChild( $equalsNode->firstChild ); $partNode->addChild( $valueNode ); $element->addChild( $partNode ); } else { - $partNode = new PPNode_Hash_Tree( 'part' ); - $nameNode = new PPNode_Hash_Tree( 'name' ); - $nameNode->addChild( new PPNode_Hash_Attr( 'index', $argIndex++ ) ); - $valueNode = new PPNode_Hash_Tree( 'value' ); + $partNode = new PPNodeHashTree( 'part' ); + $nameNode = new PPNodeHashTree( 'name' ); + $nameNode->addChild( new PPNodeHashAttr( 'index', $argIndex++ ) ); + $valueNode = new PPNodeHashTree( 'value' ); $valueNode->firstChild = $part->out->firstNode; $valueNode->lastChild = $part->out->lastNode; $partNode->addChild( $nameNode ); @@ -692,7 +692,7 @@ # Re-add the old stack element if it still has unmatched opening characters remaining if ( $matchingCount < $piece->count ) { - $piece->parts = array( new PPDPart_Hash ); + $piece->parts = array( new PPDPartHash ); $piece->count -= $matchingCount; # do we still qualify for any callback with remaining count? $min = $rules[$piece->open]['min']; @@ -737,7 +737,7 @@ } } - $rootNode = new PPNode_Hash_Tree( 'root' ); + $rootNode = new PPNodeHashTree( 'root' ); $rootNode->firstChild = $stack->rootAccum->firstNode; $rootNode->lastChild = $stack->rootAccum->lastNode; @@ -756,23 +756,36 @@ } /** + * @ingroup Parser + * @deprecated since 1.24 Use PreprocessorHash instead + */ +// @codingStandardsIgnoreStart Exclude backward class name from CodeSniffer checks +class Preprocessor_Hash extends PreprocessorHash { + function __construct( $parser ) { + wfDeprecated( __CLASS__, '1.24' ); + parent::__construct( $parser ); + } +} +// @codingStandardsIgnoreEnd + +/** * Stack class to help Preprocessor::preprocessToObj() * @ingroup Parser */ -class PPDStack_Hash extends PPDStack { +class PPDStackHash extends PPDStack { function __construct() { - $this->elementClass = 'PPDStackElement_Hash'; + $this->elementClass = 'PPDStackElementHash'; parent::__construct(); - $this->rootAccum = new PPDAccum_Hash; + $this->rootAccum = new PPDAccumHash; } } /** * @ingroup Parser */ -class PPDStackElement_Hash extends PPDStackElement { +class PPDStackElementHash extends PPDStackElement { function __construct( $data = array() ) { - $this->partClass = 'PPDPart_Hash'; + $this->partClass = 'PPDPartHash'; parent::__construct( $data ); } @@ -780,7 +793,7 @@ * Get the accumulator that would result if the close is not found. * * @param int|bool $openingCount - * @return PPDAccum_Hash + * @return PPDAccumHash */ function breakSyntax( $openingCount = false ) { if ( $this->open == "\n" ) { @@ -789,7 +802,7 @@ if ( $openingCount === false ) { $openingCount = $this->count; } - $accum = new PPDAccum_Hash; + $accum = new PPDAccumHash; $accum->addLiteral( str_repeat( $this->open, $openingCount ) ); $first = true; foreach ( $this->parts as $part ) { @@ -808,9 +821,9 @@ /** * @ingroup Parser */ -class PPDPart_Hash extends PPDPart { +class PPDPartHash extends PPDPart { function __construct( $out = '' ) { - $accum = new PPDAccum_Hash; + $accum = new PPDAccumHash; if ( $out !== '' ) { $accum->addLiteral( $out ); } @@ -821,7 +834,7 @@ /** * @ingroup Parser */ -class PPDAccum_Hash { +class PPDAccumHash { var $firstNode, $lastNode; function __construct() { @@ -834,11 +847,11 @@ */ function addLiteral( $s ) { if ( $this->lastNode === false ) { - $this->firstNode = $this->lastNode = new PPNode_Hash_Text( $s ); - } elseif ( $this->lastNode instanceof PPNode_Hash_Text ) { + $this->firstNode = $this->lastNode = new PPNodeHashText( $s ); + } elseif ( $this->lastNode instanceof PPNodeHashText ) { $this->lastNode->value .= $s; } else { - $this->lastNode->nextSibling = new PPNode_Hash_Text( $s ); + $this->lastNode->nextSibling = new PPNodeHashText( $s ); $this->lastNode = $this->lastNode->nextSibling; } } @@ -862,15 +875,15 @@ * @param string $value */ function addNodeWithText( $name, $value ) { - $node = PPNode_Hash_Tree::newWithText( $name, $value ); + $node = PPNodeHashTree::newWithText( $name, $value ); $this->addNode( $node ); } /** - * Append a PPDAccum_Hash + * Append a PPDAccumHash * Takes over ownership of the nodes in the source argument. These nodes may * subsequently be modified, especially nextSibling. - * @param PPDAccum_Hash $accum + * @param PPDAccumHash $accum */ function addAccum( $accum ) { if ( $accum->lastNode === false ) { @@ -889,7 +902,7 @@ * An expansion frame, used as a context to expand the result of preprocessToObj() * @ingroup Parser */ -class PPFrame_Hash implements PPFrame { +class PPFrameHash implements PPFrame { /** * @var Parser @@ -945,11 +958,11 @@ * Create a new child frame * $args is optionally a multi-root PPNode or array containing the template arguments * - * @param array|bool|PPNode_Hash_Array $args + * @param array|bool|PPNodeHashArray $args * @param Title|bool $title * @param int $indexOffset * @throws MWException - * @return PPTemplateFrame_Hash + * @return PPTemplateFrameHash */ function newChild( $args = false, $title = false, $indexOffset = 0 ) { $namedArgs = array(); @@ -958,10 +971,10 @@ $title = $this->title; } if ( $args !== false ) { - if ( $args instanceof PPNode_Hash_Array ) { + if ( $args instanceof PPNodeHashArray ) { $args = $args->value; } elseif ( !is_array( $args ) ) { - throw new MWException( __METHOD__ . ': $args must be array or PPNode_Hash_Array' ); + throw new MWException( __METHOD__ . ': $args must be array or PPNodeHashArray' ); } foreach ( $args as $arg ) { $bits = $arg->splitArg(); @@ -978,13 +991,13 @@ } } } - return new PPTemplateFrame_Hash( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title ); + return new PPTemplateFrameHash( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title ); } /** * @throws MWException * @param string|int $key - * @param string|PPNode_Hash|DOMDocument $root + * @param string|PPNode|DOMDocument $root * @param int $flags * @return string */ @@ -1043,7 +1056,7 @@ $contextNode = $iteratorNode[$index]; $index++; } - } elseif ( $iteratorNode instanceof PPNode_Hash_Array ) { + } elseif ( $iteratorNode instanceof PPNodeHashArray ) { if ( $index >= $iteratorNode->getLength() ) { // All done with this iterator $iteratorStack[$level] = false; @@ -1065,13 +1078,13 @@ // nothing to do } elseif ( is_string( $contextNode ) ) { $out .= $contextNode; - } elseif ( is_array( $contextNode ) || $contextNode instanceof PPNode_Hash_Array ) { + } elseif ( is_array( $contextNode ) || $contextNode instanceof PPNodeHashArray ) { $newIterator = $contextNode; - } elseif ( $contextNode instanceof PPNode_Hash_Attr ) { + } elseif ( $contextNode instanceof PPNodeHashAttr ) { // No output - } elseif ( $contextNode instanceof PPNode_Hash_Text ) { + } elseif ( $contextNode instanceof PPNodeHashText ) { $out .= $contextNode->value; - } elseif ( $contextNode instanceof PPNode_Hash_Tree ) { + } elseif ( $contextNode instanceof PPNodeHashTree ) { if ( $contextNode->name == 'template' ) { # Double-brace expansion $bits = $contextNode->splitTemplate(); @@ -1215,7 +1228,7 @@ $first = true; $s = ''; foreach ( $args as $root ) { - if ( $root instanceof PPNode_Hash_Array ) { + if ( $root instanceof PPNodeHashArray ) { $root = $root->value; } if ( !is_array( $root ) ) { @@ -1245,7 +1258,7 @@ $first = true; $s = ''; foreach ( $args as $root ) { - if ( $root instanceof PPNode_Hash_Array ) { + if ( $root instanceof PPNodeHashArray ) { $root = $root->value; } if ( !is_array( $root ) ) { @@ -1268,7 +1281,7 @@ * with implode() * * @param string $sep - * @return PPNode_Hash_Array + * @return PPNodeHashArray */ function virtualImplode( $sep /*, ... */ ) { $args = array_slice( func_get_args(), 1 ); @@ -1276,7 +1289,7 @@ $first = true; foreach ( $args as $root ) { - if ( $root instanceof PPNode_Hash_Array ) { + if ( $root instanceof PPNodeHashArray ) { $root = $root->value; } if ( !is_array( $root ) ) { @@ -1291,7 +1304,7 @@ $out[] = $node; } } - return new PPNode_Hash_Array( $out ); + return new PPNodeHashArray( $out ); } /** @@ -1300,7 +1313,7 @@ * @param string $start * @param string $sep * @param string $end - * @return PPNode_Hash_Array + * @return PPNodeHashArray */ function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) { $args = array_slice( func_get_args(), 3 ); @@ -1308,7 +1321,7 @@ $first = true; foreach ( $args as $root ) { - if ( $root instanceof PPNode_Hash_Array ) { + if ( $root instanceof PPNodeHashArray ) { $root = $root->value; } if ( !is_array( $root ) ) { @@ -1324,7 +1337,7 @@ } } $out[] = $end; - return new PPNode_Hash_Array( $out ); + return new PPNodeHashArray( $out ); } function __toString() { @@ -1453,7 +1466,7 @@ * Expansion frame with template arguments * @ingroup Parser */ -class PPTemplateFrame_Hash extends PPFrame_Hash { +class PPTemplateFrameHash extends PPFrameHash { var $numberedArgs, $namedArgs, $parent; var $numberedExpansionCache, $namedExpansionCache; @@ -1504,7 +1517,7 @@ /** * @throws MWException * @param string|int $key - * @param string|PPNode_Hash|DOMDocument $root + * @param string|PPNode|DOMDocument $root * @param int $flags * @return string */ @@ -1633,7 +1646,7 @@ * Expansion frame with custom arguments * @ingroup Parser */ -class PPCustomFrame_Hash extends PPFrame_Hash { +class PPCustomFrameHash extends PPFrameHash { var $args; function __construct( $preprocessor, $args ) { @@ -1683,7 +1696,7 @@ /** * @ingroup Parser */ -class PPNode_Hash_Tree implements PPNode { +class PPNodeHashTree implements PPNode { var $name, $firstChild, $lastChild, $nextSibling; function __construct( $name ) { @@ -1695,7 +1708,7 @@ $inner = ''; $attribs = ''; for ( $node = $this->firstChild; $node; $node = $node->nextSibling ) { - if ( $node instanceof PPNode_Hash_Attr ) { + if ( $node instanceof PPNodeHashAttr ) { $attribs .= ' ' . $node->name . '="' . htmlspecialchars( $node->value ) . '"'; } else { $inner .= $node->__toString(); @@ -1711,11 +1724,11 @@ /** * @param string $name * @param string $text - * @return PPNode_Hash_Tree + * @return PPNodeHashTree */ static function newWithText( $name, $text ) { $obj = new self( $name ); - $obj->addChild( new PPNode_Hash_Text( $text ) ); + $obj->addChild( new PPNodeHashText( $text ) ); return $obj; } @@ -1729,14 +1742,14 @@ } /** - * @return PPNode_Hash_Array + * @return PPNodeHashArray */ function getChildren() { $children = array(); for ( $child = $this->firstChild; $child; $child = $child->nextSibling ) { $children[] = $child; } - return new PPNode_Hash_Array( $children ); + return new PPNodeHashArray( $children ); } function getFirstChild() { @@ -1796,7 +1809,7 @@ } if ( $child->name === 'name' ) { $bits['name'] = $child; - if ( $child->firstChild instanceof PPNode_Hash_Attr + if ( $child->firstChild instanceof PPNodeHashAttr && $child->firstChild->name === 'index' ) { $bits['index'] = $child->firstChild->value; @@ -1897,7 +1910,7 @@ if ( !isset( $bits['title'] ) ) { throw new MWException( 'Invalid node passed to ' . __METHOD__ ); } - $bits['parts'] = new PPNode_Hash_Array( $parts ); + $bits['parts'] = new PPNodeHashArray( $parts ); return $bits; } } @@ -1905,7 +1918,7 @@ /** * @ingroup Parser */ -class PPNode_Hash_Text implements PPNode { +class PPNodeHashText implements PPNode { var $value, $nextSibling; function __construct( $value ) { @@ -1963,7 +1976,7 @@ /** * @ingroup Parser */ -class PPNode_Hash_Array implements PPNode { +class PPNodeHashArray implements PPNode { var $value, $nextSibling; function __construct( $value ) { @@ -2018,7 +2031,7 @@ /** * @ingroup Parser */ -class PPNode_Hash_Attr implements PPNode { +class PPNodeHashAttr implements PPNode { var $name, $value, $nextSibling; function __construct( $name, $value ) { diff --git a/maintenance/preprocessDump.php b/maintenance/preprocessDump.php index 17d97b0..e76b44a 100644 --- a/maintenance/preprocessDump.php +++ b/maintenance/preprocessDump.php @@ -67,7 +67,7 @@ } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) { $name = $wgParserConf['preprocessorClass']; } else { - $name = 'Preprocessor_DOM'; + $name = 'PreprocessorDOM'; } $wgParser->firstCallInit(); diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php index 345fd0a..b9c2986 100644 --- a/tests/phpunit/includes/parser/PreprocessorTest.php +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -18,7 +18,7 @@ $this->mOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang ); $name = isset( $wgParserConf['preprocessorClass'] ) ? $wgParserConf['preprocessorClass'] - : 'Preprocessor_DOM'; + : 'PreprocessorDOM'; $this->mPreprocessor = new $name( $this ); } @@ -151,7 +151,7 @@ /** * @dataProvider provideCases - * @covers Preprocessor_DOM::preprocessToXml + * @covers PreprocessorDOM::preprocessToXml */ public function testPreprocessorOutput( $wikiText, $expectedXml ) { $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) ); @@ -174,7 +174,7 @@ /** * @dataProvider provideFiles - * @covers Preprocessor_DOM::preprocessToXml + * @covers PreprocessorDOM::preprocessToXml */ public function testPreprocessorOutputFiles( $filename ) { $folder = __DIR__ . "/../../../parser/preprocess"; @@ -239,7 +239,7 @@ /** * @dataProvider provideHeadings - * @covers Preprocessor_DOM::preprocessToXml + * @covers PreprocessorDOM::preprocessToXml */ public function testHeadings( $wikiText, $expectedXml ) { $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) ); -- To view, visit https://gerrit.wikimedia.org/r/149382 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1a77f4894953f05afd4ff0751657ac0c91f5f233 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits