From: Gabriel Wicke Date: Wed, 2 Jun 2004 12:29:15 +0000 (+0000) Subject: nowiki handling X-Git-Tag: 1.5.0alpha1~3074 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=f982803ae9ad72a33ad2bae3bec09099851458a9;p=lhc%2Fweb%2Fwiklou.git nowiki handling * unstrip done for nowiki separately (unstripNoWiki()) * unstripNoWiki() called *after* doBlockLevels --- diff --git a/includes/Article.php b/includes/Article.php index 2658b9a5cc..c0bf678dfc 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -171,6 +171,7 @@ class Article { } # reinsert stripped tags $rv=$parser->unstrip($rv,$striparray); + $rv=$parser->unstripNoWiki($rv,$striparray); $rv=trim($rv); return $rv; @@ -717,6 +718,7 @@ class Article { $text=join("",$secs); # reinsert the stuff that we stripped out earlier $text=$parser->unstrip($text,$striparray); + $text=$parser->unstripNoWiki($text,$striparray); } } diff --git a/includes/Parser.php b/includes/Parser.php index 2bb28ede33..86199186fc 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -78,7 +78,6 @@ class Parser $this->mStripState = array(); $this->mArgStack = array(); $this->mInPre = false; - $this->mInNowiki = false; } # First pass--just handle sections, pass the rest off @@ -134,6 +133,7 @@ class Parser } # only once and last $text = $this->doBlockLevels( $text, $linestart ); + $text = $this->unstripNoWiki( $text, $this->mStripState ); if($wgUseTidy) { $text = $this->tidy($text); } @@ -214,12 +214,11 @@ class Parser $text = Parser::extractTags("nowiki", $text, $nowiki_content, $uniq_prefix); foreach( $nowiki_content as $marker => $content ){ - //if( $render ){ - //# use span to mark nowiki areas, note the trailing whitespace in span to avoid collisions with other spans - //$nowiki_content[$marker] = ''.wfEscapeHTMLTagsOnly( $content ).""; - //} else { + if( $render ){ + $nowiki_content[$marker] = wfEscapeHTMLTagsOnly( $content ); + } else { $nowiki_content[$marker] = "$content"; - //} + } } $text = Parser::extractTags("hiero", $text, $hiero_content, $uniq_prefix); @@ -289,18 +288,31 @@ class Parser return $text; } + # always call unstripNoWiki() after this one function unstrip( $text, &$state ) { # Must expand in reverse order, otherwise nested tags will be corrupted $contentDict = end( $state ); for ( $contentDict = end( $state ); $contentDict !== false; $contentDict = prev( $state ) ) { - for ( $content = end( $contentDict ); $content !== false; $content = prev( $contentDict ) ) { - $text = str_replace( key( $contentDict ), $content, $text ); + if( key($state) != 'nowiki') { + for ( $content = end( $contentDict ); $content !== false; $content = prev( $contentDict ) ) { + $text = str_replace( key( $contentDict ), $content, $text ); + } } } return $text; } + # always call this after unstrip() to preserve the order + function unstripNoWiki( $text, &$state ) + { + # Must expand in reverse order, otherwise nested tags will be corrupted + for ( $content = end($state['nowiki']); $content !== false; $content = prev( $state['nowiki'] ) ) { + $text = str_replace( key( $state['nowiki'] ), $content, $text ); + } + + return $text; + } # Add an item to the strip state # Returns the unique tag which must be inserted into the stripped text @@ -1010,9 +1022,6 @@ class Parser # happening here is handling of block-level elements p, pre, # and making lists from lines starting with * # : etc. # - - // Strip nowiki's again. - $text = $this->strip($text,$dblStripState); $textLines = explode( "\n", $text ); $lastPrefix = $output = $lastLine = ''; @@ -1025,22 +1034,12 @@ class Parser } foreach ( $textLines as $oLine ) { $lastPrefixLength = strlen( $lastPrefix ); - $preOpenMatch = preg_match("/
/", $oLine );
-			if($nowikiOpenMatch) $nowikiFullMatch = preg_match("/^(.*)mInPre) {
 				$this->mInPre = !empty($preOpenMatch);
 			}
-			if (!$this->mInNowiki) {
-				$this->mInNowiki = !empty($nowikiOpenMatch);
-			}
-			if ( 
-				!$this->mInPre && (!$this->mInNowiki || 
-				($nowikiOpenMatch && strlen($nowikiOpenMatches[1]) > 0) ) 
-			) 
-			{
+			if ( !$this->mInPre ) {
 				# Multiple prefixes may abut each other for nested lists.
 				$prefixLength = strspn( $oLine, "*#:;" );
 				$pref = substr( $oLine, 0, $prefixLength );
@@ -1120,11 +1119,8 @@ class Parser
 					} else {
 						$inBlockElem = true;
 					}
-				} else if ( 
-					!$inBlockElem && !$this->mInPre && 
-					(!$this->mInNowiki || ($nowikiOpenMatch && trim($nowikiOpenMatches[1]) == ''  ) ) ) 
-					{
-					if ( " " == $t{0} and trim($t) != '' and (!$this->mInNowiki || $nowikiOpenMatch && strlen($nowikiOpenMatches[1]) > 0 ) ) {
+				} else if ( !$inBlockElem && !$this->mInPre ) {
+					if ( " " == $t{0} and trim($t) != '' ) {
 						// pre
 						if ($this->mLastSection != 'pre') {
 							$paragraphStack = false;
@@ -1160,7 +1156,6 @@ class Parser
 					}
 				}
 			}
-			if($nowikiCloseMatch) $this->mInNowiki = false;
 			if ($paragraphStack === false) {
 				$output .= $t."\n";
 			}
@@ -1173,7 +1168,6 @@ class Parser
 			$output .= "mLastSection . ">";
 			$this->mLastSection = "";
 		}
-		$output = $this->unstrip( $output, $dblStripState );
 
 		wfProfileOut( $fname );
 		return $output;
@@ -1731,6 +1725,7 @@ class Parser
 			# The canonized header is a version of the header text safe to use for links
 			# Avoid insertion of weird stuff like  by expanding the relevant sections
 			$canonized_headline = $this->unstrip( $headline, $this->mStripState );
+			$canonized_headline = $this->unstripNoWiki( $headline, $this->mStripState );
 
 			# strip out HTML
 			$canonized_headline = preg_replace( "/<.*?" . ">/","",$canonized_headline );
@@ -1910,6 +1905,7 @@ class Parser
 		$text = $this->strip( $text, $stripState, false );
 		$text = $this->pstPass2( $text, $user );
 		$text = $this->unstrip( $text, $stripState );
+		$text = $this->unstripNoWiki( $text, $stripState );
 		return $text;
 	}
 
diff --git a/maintenance/archives/moveCustomMessages.inc b/maintenance/archives/moveCustomMessages.inc
index 398bbf381a..436011316d 100644
--- a/maintenance/archives/moveCustomMessages.inc
+++ b/maintenance/archives/moveCustomMessages.inc
@@ -106,6 +106,7 @@ function moveCustomMessages( $phase ) {
 					# [[MediaWiki:]] -> [[Template:]]
 					$text = preg_replace_callback( $linkRegex, "wfReplaceMediaWiki", $text );
 					$text = $parser->unstrip( $text, $stripState );
+					$text = $parser->unstripNoWiki( $text, $stripState );
 					if ( $text != $row->cur_text ) {
 						wfUpdateArray( 'cur', array( 'cur_text' => $text ), array( 'cur_id' => $id ) );
 						print "$pdbk\n";
@@ -133,4 +134,4 @@ function wfReplaceMediaWiki( $m ) {
 	return $text;
 }
 
-?>
\ No newline at end of file
+?>