From 6ec6ce7da71ff54046111920e35749105d2e098d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 29 May 2006 23:02:21 +0000 Subject: [PATCH] * (bug 6133) Update strip state as we work. This mostly fixes extensions used in Cite.php tags when Tidy is on. --- RELEASE-NOTES | 3 +++ includes/Parser.php | 64 ++++++++++++++++----------------------------- 2 files changed, 26 insertions(+), 41 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e3cfb460e0..8112351d5d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -377,6 +377,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 4033) Respect $wgStyleDirectory when checking available skins * Remove hideous backslashes from MessagesBr.php * Fix APC object cache issues, add functionality to installer +* (bug 6133) Update strip state as we work. This mostly fixes extensions + used in Cite.php tags when Tidy is on. + == Compatibility == diff --git a/includes/Parser.php b/includes/Parser.php index 1469b803c5..948ffd6c48 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -439,9 +439,9 @@ class Parser foreach( $html_content as $marker => $content ) { if ($render ) { # Raw and unchecked for validity. - $html_content[$marker] = $content; + $state['html'][$marker] = $content; } else { - $html_content[$marker] = ''.$content.''; + $state['html'][$marker] = ''.$content.''; } } } @@ -450,9 +450,9 @@ class Parser $text = Parser::extractTags('nowiki', $text, $nowiki_content, $uniq_prefix); foreach( $nowiki_content as $marker => $content ) { if( $render ){ - $nowiki_content[$marker] = wfEscapeHTMLTagsOnly( $content ); + $state['nowiki'][$marker] = wfEscapeHTMLTagsOnly( $content ); } else { - $nowiki_content[$marker] = ''.$content.''; + $state['nowiki'][$marker] = ''.$content.''; } } @@ -461,9 +461,9 @@ class Parser $text = Parser::extractTags('math', $text, $math_content, $uniq_prefix); foreach( $math_content as $marker => $content ){ if( $render ) { - $math_content[$marker] = renderMath( $content ); + $state['math'][$marker] = renderMath( $content ); } else { - $math_content[$marker] = ''.$content.''; + $state['math'][$marker] = ''.$content.''; } } } @@ -472,9 +472,9 @@ class Parser $text = Parser::extractTags('pre', $text, $pre_content, $uniq_prefix); foreach( $pre_content as $marker => $content ){ if( $render ){ - $pre_content[$marker] = '
' . wfEscapeHTMLTagsOnly( $content ) . '
'; + $state['pre'][$marker] = '
' . wfEscapeHTMLTagsOnly( $content ) . '
'; } else { - $pre_content[$marker] = '
'.$content.'
'; + $state['pre'][$marker] = '
'.$content.'
'; } } @@ -483,9 +483,9 @@ class Parser foreach( $gallery_content as $marker => $content ) { require_once( 'ImageGallery.php' ); if ( $render ) { - $gallery_content[$marker] = $this->renderImageGallery( $content ); + $state['gallery'][$marker] = $this->renderImageGallery( $content ); } else { - $gallery_content[$marker] = ''.$content.''; + $state['gallery'][$marker] = ''.$content.''; } } @@ -504,13 +504,13 @@ class Parser $full_tag = $ext_tags[$tag][$marker]; $params = $ext_params[$tag][$marker]; if ( $render ) - $ext_content[$tag][$marker] = call_user_func_array( $callback, array( $content, $params, &$this ) ); + $state[$tag][$marker] = call_user_func_array( $callback, array( $content, $params, $this ) ); else { if ( is_null( $content ) ) { // Empty element tag - $ext_content[$tag][$marker] = $full_tag; + $state[$tag][$marker] = $full_tag; } else { - $ext_content[$tag][$marker] = "$full_tag$content"; + $state[$tag][$marker] = "$full_tag$content"; } } } @@ -524,32 +524,13 @@ class Parser $tempstate = array( 'comment' => $comment_content ); $text = $this->unstrip( $text, $tempstate ); $comment_content = array(); - } - - # Merge state with the pre-existing state, if there is one - if ( $state ) { - $state['html'] = $state['html'] + $html_content; - $state['nowiki'] = $state['nowiki'] + $nowiki_content; - $state['math'] = $state['math'] + $math_content; - $state['pre'] = $state['pre'] + $pre_content; - $state['gallery'] = $state['gallery'] + $gallery_content; - $state['comment'] = $state['comment'] + $comment_content; - - foreach( $ext_content as $tag => $array ) { - if ( array_key_exists( $tag, $state ) ) { - $state[$tag] = $state[$tag] + $array; - } - } } else { - $state = array( - 'html' => $html_content, - 'nowiki' => $nowiki_content, - 'math' => $math_content, - 'pre' => $pre_content, - 'gallery' => $gallery_content, - 'comment' => $comment_content, - ) + $ext_content; + if( !isset( $state['comment'] ) ) { + $state['comment'] = array(); + } + $state['comment'] += $comment_content; } + return $text; } @@ -587,12 +568,13 @@ class Parser } # Must expand in reverse order, otherwise nested tags will be corrupted - foreach( array_reverse( $state['nowiki'], true ) as $uniq => $content ) { - $text = str_replace( $uniq, $content, $text ); - } + if( isset( $state['nowiki'] ) ) + foreach( array_reverse( $state['nowiki'], true ) as $uniq => $content ) { + $text = str_replace( $uniq, $content, $text ); + } global $wgRawHtml; - if ($wgRawHtml) { + if ($wgRawHtml && isset( $state['html'] ) ) { foreach( array_reverse( $state['html'], true ) as $uniq => $content ) { $text = str_replace( $uniq, $content, $text ); } -- 2.20.1