From: Brion Vibber Date: Sat, 24 Jul 2004 22:59:44 +0000 (+0000) Subject: $wgRawHtml option to enable ... container for RAW UNCHECKED X-Git-Tag: 1.5.0alpha1~2601 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=67833d481c7f21d6ff5b19aa450bf72825abeeaa;p=lhc%2Fweb%2Fwiklou.git $wgRawHtml option to enable ... container for RAW UNCHECKED UNPARSED html bits. Don't enable this except on trusted sites! --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 1b8d94457d..a9a29c3d02 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -418,6 +418,12 @@ $wgGoToEdit = false; # constructs. $wgUserHtml = true; +# Allow raw, unchecked HTML in ... sections. +# THIS IS VERY DANGEROUS on a publically editable site. +# Don't enable it unless you've restricted editing to trusted +# users only. +$wgRawHtml = false; + # $wgUseTidy: use tidy to make sure HTML output is sane. # This should only be enabled if $wgUserHtml is true. # tidy is a free tool that fixes broken HTML. diff --git a/includes/Parser.php b/includes/Parser.php index 98bf5fe928..c04124c6ab 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -201,6 +201,7 @@ class Parser # counting the sections in the wikisource function strip( $text, &$state, $stripcomments = false ) { $render = ($this->mOutputType == OT_HTML); + $html_content = array(); $nowiki_content = array(); $math_content = array(); $pre_content = array(); @@ -211,10 +212,23 @@ class Parser $uniq_prefix = UNIQ_PREFIX; #$text = str_replace( $uniq_prefix, wfHtmlEscapeFirst( $uniq_prefix ), $text ); - + # html + global $wgRawHtml; + if( $wgRawHtml ) { + $text = Parser::extractTags('html', $text, $html_content, $uniq_prefix); + foreach( $html_content as $marker => $content ) { + if ($render ) { + # Raw and unchecked for validity. + $html_content[$marker] = $content; + } else { + $html_content[$marker] = "$content"; + } + } + } + # nowiki $text = Parser::extractTags('nowiki', $text, $nowiki_content, $uniq_prefix); - foreach( $nowiki_content as $marker => $content ){ + foreach( $nowiki_content as $marker => $content ) { if( $render ){ $nowiki_content[$marker] = wfEscapeHTMLTagsOnly( $content ); } else { @@ -269,6 +283,7 @@ class Parser # 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; @@ -281,6 +296,7 @@ class Parser } } else { $state = array( + 'html' => $html_content, 'nowiki' => $nowiki_content, 'math' => $math_content, 'pre' => $pre_content, @@ -295,7 +311,7 @@ class Parser # Must expand in reverse order, otherwise nested tags will be corrupted $contentDict = end( $state ); for ( $contentDict = end( $state ); $contentDict !== false; $contentDict = prev( $state ) ) { - if( key($state) != 'nowiki') { + if( key($state) != 'nowiki' && key($state) != 'html') { for ( $content = end( $contentDict ); $content !== false; $content = prev( $contentDict ) ) { $text = str_replace( key( $contentDict ), $content, $text ); } @@ -310,6 +326,13 @@ class Parser for ( $content = end($state['nowiki']); $content !== false; $content = prev( $state['nowiki'] ) ) { $text = str_replace( key( $state['nowiki'] ), $content, $text ); } + + global $wgRawHtml; + if ($wgRawHtml) { + for ( $content = end($state['html']); $content !== false; $content = prev( $state['html'] ) ) { + $text = str_replace( key( $state['html'] ), $content, $text ); + } + } return $text; } @@ -322,6 +345,7 @@ class Parser $rnd = UNIQ_PREFIX . '-item' . Parser::getRandomString(); if ( !$state ) { $state = array( + 'html' => array(), 'nowiki' => array(), 'math' => array(), 'pre' => array()