From 368aa5dc6765e387061aa69413c8f29afa512292 Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Wed, 2 Apr 2014 23:52:52 -0400 Subject: [PATCH] Make RECOVER_ORIG preserve extension tags Add PPFrame::NO_TAGS, set by PPFrame::RECOVER_ORIG, to preserve extension tags rather than expanding them. Bug: 22683 Change-Id: I427333a20d32eb711a7b5d5ac8b780ef89c752a1 --- RELEASE-NOTES-1.24 | 2 ++ includes/parser/Preprocessor.php | 3 ++- includes/parser/Preprocessor_DOM.php | 30 ++++++++++++++++++++------- includes/parser/Preprocessor_Hash.php | 18 +++++++++++++++- tests/parser/parserTests.txt | 16 ++++++++------ 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 72edd7665d..12e870e1c6 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -99,6 +99,8 @@ production. * (bug 52587) Maintenance script deleteBatch.php no longer follows redirects in the file namespace and delete the file on the target page. It will still however delete the redirect page. +* (bug 22683) {{msgnw:}} and other uses of PPFrame::RECOVER_ORIG will correctly + recover the original code of extension tags. === Web API changes in 1.24 === * action=parse API now supports prop=modules, which provides the list of diff --git a/includes/parser/Preprocessor.php b/includes/parser/Preprocessor.php index dd5fc4fc47..335bd61ed5 100644 --- a/includes/parser/Preprocessor.php +++ b/includes/parser/Preprocessor.php @@ -77,8 +77,9 @@ interface PPFrame { const STRIP_COMMENTS = 4; const NO_IGNORE = 8; const RECOVER_COMMENTS = 16; + const NO_TAGS = 32; - const RECOVER_ORIG = 27; // = 1|2|8|16 no constant expression support in PHP yet + const RECOVER_ORIG = 59; // = 1|2|8|16|32 no constant expression support in PHP yet /** This constant exists when $indexOffset is supported in newChild() */ const SUPPORTS_INDEX_OFFSET = 1; diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 90af670d76..f5fc3ec669 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -1234,13 +1234,29 @@ class PPFrame_DOM implements PPFrame { $attrs = $xpath->query( 'attr', $contextNode ); $inners = $xpath->query( 'inner', $contextNode ); $closes = $xpath->query( 'close', $contextNode ); - $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, - ); - $out .= $this->parser->extensionSubstitution( $params, $this ); + if ( $flags & PPFrame::NO_TAGS ) { + $s = '<' . $this->expand( $names->item( 0 ), $flags ); + if ( $attrs->length > 0 ) { + $s .= $this->expand( $attrs->item( 0 ), $flags ); + } + if ( $inners->length > 0 ) { + $s .= '>' . $this->expand( $inners->item( 0 ), $flags ); + if ( $closes->length > 0 ) { + $s .= $this->expand( $closes->item( 0 ), $flags ); + } + } else { + $s .= '/>'; + } + $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, + ); + $out .= $this->parser->extensionSubstitution( $params, $this ); + } } elseif ( $contextNode->nodeName == 'h' ) { # Heading $s = $this->expand( $contextNode->childNodes, $flags ); diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index bc2b68658f..bf2bf614c3 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -1138,7 +1138,23 @@ class PPFrame_Hash implements PPFrame { } elseif ( $contextNode->name == 'ext' ) { # Extension tag $bits = $contextNode->splitExt() + array( 'attr' => null, 'inner' => null, 'close' => null ); - $out .= $this->parser->extensionSubstitution( $bits, $this ); + if ( $flags & PPFrame::NO_TAGS ) { + $s = '<' . $bits['name']->firstChild->value; + if ( $bits['attr'] ) { + $s .= $bits['attr']->firstChild->value; + } + if ( $bits['inner'] ) { + $s .= '>' . $bits['inner']->firstChild->value; + if ( $bits['close'] ) { + $s .= $bits['close']->firstChild->value; + } + } else { + $s .= '/>'; + } + $out .= $s; + } else { + $out .= $this->parser->extensionSubstitution( $bits, $this ); + } } elseif ( $contextNode->name == 'h' ) { # Heading if ( $this->parser->ot['html'] ) { diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 7276349a43..c447a44c53 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -8325,20 +8325,24 @@ Template:MSGNW test * interpreted but rather passed unmodified {{test}} + +File:Foobar.jpg + !! endarticle # hmm, fix this or just deprecate msgnw and document its behavior? !! test msgnw keyword -!! options -disabled !! wikitext {{msgnw:MSGNW test}} !! html -

''None'' of '''this''' should be -* interpreted - but rather passed unmodified -{{test}} +

''None'' of '''this''' should be +* interpreted + but rather passed unmodified +{{test}} +<gallery> +File:Foobar.jpg +</gallery>

!! end -- 2.20.1