Cscott has uploaded a new change for review. https://gerrit.wikimedia.org/r/78972
Change subject: Make line breaks in <blockquote> behave like <div> (bug 6200). ...................................................................... Make line breaks in <blockquote> behave like <div> (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 <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 --- M RELEASE-NOTES-1.22 M includes/parser/Parser.php M tests/parser/parserTests.txt 3 files changed, 73 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/72/78972/1 diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index cfe553e..1255a1d 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -256,6 +256,7 @@ * (bug 49694) $wgSpamRegex is now also applied on the new section headline text adding a new topic on a page * (bug 41756) Improve treatment of multiple comments on a blank line. +* (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 diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 8fdf407..a7763c4 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -154,7 +154,7 @@ */ var $mStripState; - var $mIncludeCount, $mArgStack, $mLastSection, $mInPre; + var $mIncludeCount, $mArgStack, $mLastSection, $mInPre, $mInBlockQuote; /** * @var LinkHolderArray */ @@ -289,6 +289,7 @@ $this->mIncludeCount = array(); $this->mArgStack = false; $this->mInPre = false; + $this->mInBlockQuote = false; $this->mLinkHolders = new LinkHolderArray( $this ); $this->mLinkID = 0; $this->mRevisionObject = $this->mRevisionTimestamp = @@ -2450,10 +2451,10 @@ 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 @@ -2461,9 +2462,12 @@ if ( $preOpenMatch and !$preCloseMatch ) { $this->mInPre = true; } + if ( preg_match( '/<(\\/?)blockquote[\s>]/i', $t, $bqm ) ) { + $this->mInBlockQuote = !$bqm[1]; + } $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 !$this->mInBlockQuote ) { # pre if ( $this->mLastSection !== 'pre' ) { $paragraphStack = false; diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 0715ae6..e081bd2 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -1352,17 +1352,61 @@ !! 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 @@ -1856,6 +1900,12 @@ foo </blockquote> +<blockquote> +<pre> +foo +</pre> +</blockquote> + <table><tr><td> foo </td></tr></table> @@ -1877,7 +1927,13 @@ </pre> </center> <blockquote> - foo +<p> foo +</p> +</blockquote> +<blockquote> +<pre> +foo +</pre> </blockquote> <table><tr><td> <pre>foo @@ -13478,9 +13534,6 @@ </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 @@ -13493,7 +13546,8 @@ baz !! result <blockquote> -foo +<p>foo +</p> </blockquote> <p>bar </p> @@ -14173,8 +14227,6 @@ # 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 @@ -14187,8 +14239,6 @@ !! test Bug 6200: paragraphs inside blockquotes (extra line break on open) -!! options -disabled !! input <blockquote> Line one @@ -14204,8 +14254,6 @@ !! test Bug 6200: paragraphs inside blockquotes (extra line break on close) -!! options -disabled !! input <blockquote>Line one @@ -14221,8 +14269,6 @@ !! test Bug 6200: paragraphs inside blockquotes (extra line break on open and close) -!! options -disabled !! input <blockquote> Line one -- To view, visit https://gerrit.wikimedia.org/r/78972 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3696d4ab7b8ad6ebccf8483d6da1722353c1697d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Cscott <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
