From: C. Scott Ananian Date: Tue, 6 Aug 2013 19:22:18 +0000 (-0400) Subject: Make line breaks in
behave like
(bug 6200). X-Git-Tag: 1.31.0-rc.0~18772^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=336d7465239431106c4a0222e8671585733b7842;p=lhc%2Fweb%2Fwiklou.git Make line breaks in
behave like
(bug 6200). 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
 block (unlike 
). 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
content is typically wrapped with

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 --- diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index e503e30195..295a95fd8b 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -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

are handled like they are in
=== API changes in 1.22 === * (bug 25553) The JSON output formatter now leaves forward slashes unescaped diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index fd69bfc3dc..3376734a8d 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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( '/(?:mUniqPrefix . '-pre|<\\/li|<\\/ul|<\\/ol|<\\/dl|<\\/?center)/iS', $t ); + '/(?:<\\/table|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|' . + '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; diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 146f86718e..f841afb6f8 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -1239,8 +1239,9 @@ b

b

!! end + !! test -Block tag on one line +Block tag on one line (
) !! input a
foo
@@ -1252,7 +1253,19 @@ a
foo
!! end !! test -Block tag on both lines +Block tag on one line (
) +!! input +a
foo
+ +b +!! result +a
foo
+

b +

+!! end + +!! test +Block tag on both lines (
) !! input a
foo
@@ -1263,6 +1276,18 @@ b
foo
!! end +!! test +Block tag on both lines (
) +!! input +a
foo
+ +b
foo
+!! result +a
foo
+b
foo
+ +!! end + !! test Multiple lines without block tags !! input @@ -1389,17 +1414,61 @@ Regression with preformatted in
!! end -# Expected output in the following test is not really expected (there should be -#
 in the output) -- it's only testing for well-formedness.
 !! test
-Bug 6200: Preformatted in 
+Bug 52763: Preformatted in
!! input
Blah
!! result
- Blah +

Blah +

+
+ +!! end + +!! test +Bug 51086: Double newlines in blockquotes should be turned into paragraphs +!! input +
+Foo + +Bar +
+!! result +
+

Foo +

Bar +

+
+ +!! end + +!! test +Bug 15491: / in blockquote +!! input +
+Foo bar baz quux +
+!! result +
+

Foo bar baz quux +

+
+ +!! 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

tag. (see comment 23-25 of bug #6200) +!! test +Bug 15491: / in blockquote (2) +!! input +

Foo bar baz quux +
+!! result +
Foo bar baz quux
!! end @@ -1882,10 +1951,12 @@ c !!input

foo

foo
+
foo
foo !!result

foo

foo
+
foo
 foo 
 
!!end @@ -1909,6 +1980,12 @@ c foo
+
+
+foo
+
+
+
foo
@@ -1930,7 +2007,13 @@ c
- foo +

foo +

+
+
+
+foo
+
foo
@@ -7288,8 +7371,10 @@ Templates: 1. Simple use
 Templates: 2. Inside a block tag
 !!input
 
{{echo|Foo}}
+
{{echo|Foo}}
!!result
Foo
+
Foo
!!end @@ -13610,9 +13695,6 @@ __NOEDITSECTION__

!! end -# Expected output in the following test is not necessarily expected (there -# should probably be

tags inside the

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
-foo +

foo +

bar

@@ -14305,8 +14388,6 @@ B # Bug 6200:
should behave like
with respect to line breaks !! test Bug 6200: paragraphs inside blockquotes (no extra line breaks) -!! options -disabled !! input
Line one @@ -14319,8 +14400,6 @@ Line two
!! test Bug 6200: paragraphs inside blockquotes (extra line break on open) -!! options -disabled !! input
Line one @@ -14336,8 +14415,6 @@ Line two
!! test Bug 6200: paragraphs inside blockquotes (extra line break on close) -!! options -disabled !! input
Line one @@ -14353,8 +14430,6 @@ Line two !! test Bug 6200: paragraphs inside blockquotes (extra line break on open and close) -!! options -disabled !! input
Line one