r52983 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r52982 | r52983 (on ViewVC) | r52984 >
Date:15:17, 9 July 2009
Author:werdna
Status:reverted (Comments)
Tags:
Comment:* Allow leading-> as syntax for quoting.
Modified paths:

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
===================================================================
--- trunk/phase3/maintenance/parserTests.txt	(revision 52982)
+++ trunk/phase3/maintenance/parserTests.txt	(revision 52983)
@@ -6550,9 +6550,9 @@
 !! test
 Always escape literal '>' in output, not just after '<'
 !! input
-><>
+test ><>
 !! result
-<p>&gt;&lt;&gt;
+<p>test &gt;&lt;&gt;
 </p>
 !! end
 
@@ -7320,6 +7320,24 @@
 </p>
 !! end
 
+!! test
+Leading > blockquote syntax
+!! input
+> Hi
+> This
+> Is
+> A
+> Quote
+!! result
+<blockquote><p> Hi
+</p><p> This
+</p><p> Is
+</p><p> A
+</p><p> Quote
+</p></blockquote>
+
+!! end
+
 #
 #
 #
Index: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php	(revision 52982)
+++ trunk/phase3/includes/parser/Parser.php	(revision 52983)
@@ -1947,7 +1947,7 @@
 		elseif ( ';' === $char ) {
 			$result .= '<dl><dt>';
 			$this->mDTopen = true;
-		}
+		} elseif ( '>' === $char ) { $result .= "<blockquote><p>"; }
 		else { $result = '<!-- ERR 1 -->'; }
 
 		return $result;
@@ -1955,6 +1955,7 @@
 
 	/* private */ function nextItem( $char ) {
 		if ( '*' === $char || '#' === $char ) { return '</li><li>'; }
+		elseif ( '>' === $char ) { return "</p><p>"; }
 		elseif ( ':' === $char || ';' === $char ) {
 			$close = '</dd>';
 			if ( $this->mDTopen ) { $close = '</dt>'; }
@@ -1972,6 +1973,7 @@
 	/* private */ function closeList( $char ) {
 		if ( '*' === $char ) { $text = '</li></ul>'; }
 		elseif ( '#' === $char ) { $text = '</li></ol>'; }
+		elseif ( '>' === $char ) { $text = "</p></blockquote>"; }
 		elseif ( ':' === $char ) {
 			if ( $this->mDTopen ) {
 				$this->mDTopen = false;
@@ -2017,14 +2019,23 @@
 			// # = ol
 			// ; = dt
 			// : = dd
+			// > = blockquote
 
 			$lastPrefixLength = strlen( $lastPrefix );
 			$preCloseMatch = preg_match('/<\\/pre/i', $oLine );
 			$preOpenMatch = preg_match('/<pre/i', $oLine );
+			
+			// Need to decode &gt; --> > for blockquote syntax. Re-encode later.
+			// To avoid collision with real >s, we temporarily convert them to &gt;
+			// This is a weird choice of armouring, but it's totally resistant to any
+			//  collision.
+			$orig = $oLine;
+			$oLine = strtr( $oLine, array( '&gt;' => '>', '>' => '&gt;' ) );
+			
 			// If not in a <pre> element, scan for and figure out what prefixes are there.
 			if ( !$this->mInPre ) {
 				# Multiple prefixes may abut each other for nested lists.
-				$prefixLength = strspn( $oLine, '*#:;' );
+				$prefixLength = strspn( $oLine, '*#:;>' );
 				$prefix = substr( $oLine, 0, $prefixLength );
 
 				# eh?
@@ -2040,6 +2051,9 @@
 				$prefix = $prefix2 = '';
 				$t = $oLine;
 			}
+			
+			// Re-encode >s now
+			$t = strtr( $t, array( '&gt;' => '>', '>' => '&gt;' ) );
 
 			# List generation
 			if( $prefixLength && $lastPrefix === $prefix2 ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r52984Release notes updates for r52983werdna15:19, 9 July 2009
r55635Revert r52983 for now, could cause unexpected syntax interactions, we want to in...werdna17:16, 27 August 2009

Comments

#Comment by UV (Talk | contribs)   20:47, 9 July 2009

I would like to suggest to assign a class to the blockquote tag thus produced, so that quotes can be styled more easily (both per-site and per-user).

#Comment by Brion VIBBER (Talk | contribs)   18:55, 22 August 2009

This doesn't seem to work as expected with whitespace...

For instance this:

># we had a list
># with a couple items

has a functioning list while this:

> # we had a list
> # with a couple items

emits literal # characters.

#Comment by Werdna (Talk | contribs)   17:17, 27 August 2009

Reverted for now in r55635, to avoid annoying syntax interactions.

Status & tagging log

  • 17:17, 27 August 2009 Werdna (Talk | contribs) changed the status of r52983 [removed: fixme added: reverted]
  • 18:55, 22 August 2009 Brion VIBBER (Talk | contribs) changed the status of r52983 [removed: new added: fixme]
Views
Toolbox