Make RECOVER_ORIG preserve extension tags
authorJackmcbarn <jackmcbarn@gmail.com>
Thu, 3 Apr 2014 03:52:52 +0000 (23:52 -0400)
committerAnomie <bjorsch@wikimedia.org>
Thu, 19 Jun 2014 18:12:14 +0000 (18:12 +0000)
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
includes/parser/Preprocessor.php
includes/parser/Preprocessor_DOM.php
includes/parser/Preprocessor_Hash.php
tests/parser/parserTests.txt

index 72edd76..12e870e 100644 (file)
@@ -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
index dd5fc4f..335bd61 100644 (file)
@@ -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;
index 90af670..f5fc3ec 100644 (file)
@@ -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 );
index bc2b686..bf2bf61 100644 (file)
@@ -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'] ) {
index 7276349..c447a44 100644 (file)
@@ -8325,20 +8325,24 @@ Template:MSGNW test
 * interpreted
  but rather passed unmodified
 {{test}}
+<gallery>
+File:Foobar.jpg
+</gallery>
 !! endarticle
 
 # hmm, fix this or just deprecate msgnw and document its behavior?
 !! test
 msgnw keyword
-!! options
-disabled
 !! wikitext
 {{msgnw:MSGNW test}}
 !! html
-<p>''None'' of '''this''' should be 
-* interpreted
- but rather passed unmodified
-{{test}}
+<p>&#39;&#39;None&#39;&#39; of &#39;&#39;&#39;this&#39;&#39;&#39; should be 
+&#42; interpreted
+&#32;but rather passed unmodified
+&#123;&#123;test&#125;&#125;
+&#60;gallery&#62;
+File:Foobar.jpg
+&#60;/gallery&#62;
 </p>
 !! end