Make line breaks in <blockquote> behave like <div> (bug 6200).
authorC. Scott Ananian <cscott@cscott.net>
Tue, 6 Aug 2013 19:22:18 +0000 (15:22 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Thu, 12 Sep 2013 15:09:23 +0000 (08:09 -0700)
This is an old, old bug: the earliest filed dup is bug 1857, on 2005-04-10.
See bug 51086 for a modern discussion, and bug 52763 for some non-obvious
consequences: indented text inside a blockquote must not trigger
creation of a <pre> block (unlike <div>).

This patch should bring the PHP parser and Parsoid closer together.

This also fixes (or works around) bug 15491, which is really a bug in tidy.
But because <blockquote> content is typically wrapped with <p> tags now,
we don't trigger the tidy bug (see
https://bugzilla.wikimedia.org/show_bug.cgi?id=15491#c7 for details).

Credit to Aryeh Gregor (https://bugzilla.wikimedia.org/show_bug.cgi?id=6200#c8)
and Vitaliy Filippov (https://bugzilla.wikimedia.org/show_bug.cgi?id=6200#c37)
for almost-correct patches for this bug, which saved me a bunch of effort.
Thanks to Subramanya Sastry for pointing out bug 52763 and preventing a
bunch of broken articles on enwiki.

Bug: 6200
Bug: 15491
Bug: 52763
Change-Id: I3696d4ab7b8ad6ebccf8483d6da1722353c1697d

RELEASE-NOTES-1.22
includes/parser/Parser.php
tests/parser/parserTests.txt

index e503e30..295a95f 100644 (file)
@@ -291,6 +291,7 @@ production.
 * (bug 51742) Add data-sort-value for better sorting of hitcounts Special:Tags
 * (bug 26811) On DB error pages, server hostnames are now hidden when both
   $wgShowHostnames and $wgShowSQLErrors are false.
+* (bug 6200) line breaks in <blockquote> are handled like they are in <div>
 
 === API changes in 1.22 ===
 * (bug 25553) The JSON output formatter now leaves forward slashes unescaped
index fd69bfc..3376734 100644 (file)
@@ -2362,6 +2362,7 @@ class Parser {
                $this->mDTopen = $inBlockElem = false;
                $prefixLength = 0;
                $paragraphStack = false;
+               $inBlockquote = false;
 
                foreach ( $textLines as $oLine ) {
                        # Fix up $linestart
@@ -2455,10 +2456,10 @@ class Parser {
                                wfProfileIn( __METHOD__ . "-paragraph" );
                                # No prefix (not in list)--go to paragraph mode
                                # XXX: use a stack for nestable elements like span, table and div
-                               $openmatch = preg_match( '/(?:<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<dl|<li|<\\/tr|<\\/td|<\\/th)/iS', $t );
+                               $openmatch = preg_match( '/(?:<table|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<dl|<li|<\\/tr|<\\/td|<\\/th)/iS', $t );
                                $closematch = preg_match(
-                                       '/(?:<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|' .
-                                       '<td|<th|<\\/?div|<hr|<\\/pre|<\\/p|' . $this->mUniqPrefix . '-pre|<\\/li|<\\/ul|<\\/ol|<\\/dl|<\\/?center)/iS', $t );
+                                       '/(?:<\\/table|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|' .
+                                       '<td|<th|<\\/?blockquote|<\\/?div|<hr|<\\/pre|<\\/p|' . $this->mUniqPrefix . '-pre|<\\/li|<\\/ul|<\\/ol|<\\/dl|<\\/?center)/iS', $t );
                                if ( $openmatch or $closematch ) {
                                        $paragraphStack = false;
                                        # TODO bug 5718: paragraph closed
@@ -2466,9 +2467,14 @@ class Parser {
                                        if ( $preOpenMatch and !$preCloseMatch ) {
                                                $this->mInPre = true;
                                        }
+                                       $bqOffset = 0;
+                                       while ( preg_match( '/<(\\/?)blockquote[\s>]/i', $t, $bqMatch, PREG_OFFSET_CAPTURE, $bqOffset ) ) {
+                                               $inBlockquote = !$bqMatch[1][0]; // is this a close tag?
+                                               $bqOffset = $bqMatch[0][1] + strlen( $bqMatch[0][0] );
+                                       }
                                        $inBlockElem = !$closematch;
                                } elseif ( !$inBlockElem && !$this->mInPre ) {
-                                       if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' || trim( $t ) != '' ) ) {
+                                       if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' || trim( $t ) != '' ) and !$inBlockquote ) {
                                                # pre
                                                if ( $this->mLastSection !== 'pre' ) {
                                                        $paragraphStack = false;
index 146f867..f841afb 100644 (file)
@@ -1239,8 +1239,9 @@ b
 </p><p>b
 </p>
 !! end
+
 !! test
-Block tag on one line
+Block tag on one line (<div>)
 !! input
 a <div>foo</div>
 
@@ -1252,7 +1253,19 @@ a <div>foo</div>
 !! end
 
 !! test
-Block tag on both lines
+Block tag on one line (<blockquote>)
+!! input
+a <blockquote>foo</blockquote>
+
+b
+!! result
+a <blockquote>foo</blockquote>
+<p>b
+</p>
+!! end
+
+!! test
+Block tag on both lines (<div>)
 !! input
 a <div>foo</div>
 
@@ -1263,6 +1276,18 @@ b <div>foo</div>
 
 !! end
 
+!! test
+Block tag on both lines (<blockquote>)
+!! input
+a <blockquote>foo</blockquote>
+
+b <blockquote>foo</blockquote>
+!! result
+a <blockquote>foo</blockquote>
+b <blockquote>foo</blockquote>
+
+!! end
+
 !! test
 Multiple lines without block tags
 !! input
@@ -1389,17 +1414,61 @@ Regression with preformatted in <center>
 
 !! end
 
-# Expected output in the following test is not really expected (there should be
-# <pre> in the output) -- it's only testing for well-formedness.
 !! test
-Bug 6200: Preformatted in <blockquote>
+Bug 52763: Preformatted in <blockquote>
 !! input
 <blockquote>
  Blah
 </blockquote>
 !! result
 <blockquote>
- Blah
+<p> Blah
+</p>
+</blockquote>
+
+!! end
+
+!! test
+Bug 51086: Double newlines in blockquotes should be turned into paragraphs
+!! input
+<blockquote>
+Foo
+
+Bar
+</blockquote>
+!! result
+<blockquote>
+<p>Foo
+</p><p>Bar
+</p>
+</blockquote>
+
+!! end
+
+!! test
+Bug 15491: <ins>/<del> in blockquote
+!! input
+<blockquote>
+Foo <del>bar</del> <ins>baz</ins> quux
+</blockquote>
+!! result
+<blockquote>
+<p>Foo <del>bar</del> <ins>baz</ins> quux
+</p>
+</blockquote>
+
+!! end
+
+# Note that the p-wrapping is newline sensitive, which could be
+# considered a bug: tidy will wrap only the 'Foo' in the example
+# below in a <p> tag. (see comment 23-25 of bug #6200)
+!! test
+Bug 15491: <ins>/<del> in blockquote (2)
+!! input
+<blockquote>Foo <del>bar</del> <ins>baz</ins> quux
+</blockquote>
+!! result
+<blockquote>Foo <del>bar</del> <ins>baz</ins> quux
 </blockquote>
 
 !! end
 !!input
  <p> foo </p>
  <div> foo </div>
+ <blockquote> foo </blockquote>
  <span> foo </span>
 !!result
  <p> foo </p>
  <div> foo </div>
+ <blockquote> foo </blockquote>
 <pre><span> foo </span>
 </pre>
 !!end
@@ -1909,6 +1980,12 @@ c
  foo
 </blockquote>
 
+<blockquote>
+<pre>
+foo
+</pre>
+</blockquote>
+
 <table><tr><td>
  foo
 </td></tr></table>
@@ -1930,7 +2007,13 @@ c
 </pre>
 </center>
 <blockquote>
- foo
+<p> foo
+</p>
+</blockquote>
+<blockquote>
+<pre>
+foo
+</pre>
 </blockquote>
 <table><tr><td>
 <pre>foo
@@ -7288,8 +7371,10 @@ Templates: 1. Simple use
 Templates: 2. Inside a block tag
 !!input
 <div>{{echo|Foo}}</div>
+<blockquote>{{echo|Foo}}</blockquote>
 !!result
 <div>Foo</div>
+<blockquote>Foo</blockquote>
 
 !!end
 
@@ -13610,9 +13695,6 @@ __NOEDITSECTION__
 </p>
 !! end
 
-# Expected output in the following test is not necessarily expected (there
-# should probably be <p> tags inside the <blockquote> in the output) -- it's
-# only testing for well-formedness.
 !! test
 Bug 6200: blockquotes and paragraph formatting
 !! input
@@ -13625,7 +13707,8 @@ bar
  baz
 !! result
 <blockquote>
-foo
+<p>foo
+</p>
 </blockquote>
 <p>bar
 </p>
@@ -14305,8 +14388,6 @@ B</strong>
 # Bug 6200: <blockquote> should behave like <div> with respect to line breaks
 !! test
 Bug 6200: paragraphs inside blockquotes (no extra line breaks)
-!! options
-disabled
 !! input
 <blockquote>Line one
 
@@ -14319,8 +14400,6 @@ Line two</blockquote>
 
 !! test
 Bug 6200: paragraphs inside blockquotes (extra line break on open)
-!! options
-disabled
 !! input
 <blockquote>
 Line one
@@ -14336,8 +14415,6 @@ Line two</blockquote>
 
 !! test
 Bug 6200: paragraphs inside blockquotes (extra line break on close)
-!! options
-disabled
 !! input
 <blockquote>Line one
 
@@ -14353,8 +14430,6 @@ Line two
 
 !! test
 Bug 6200: paragraphs inside blockquotes (extra line break on open and close)
-!! options
-disabled
 !! input
 <blockquote>
 Line one