From: Aryeh Gregor Date: Mon, 18 Jan 2010 01:30:29 +0000 (+0000) Subject: Style fixes to Sanitizer and Parser X-Git-Tag: 1.31.0-rc.0~38218 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=cbbdaa51e1dd0ff2f1911fec4fde8e2ce18aeec9;p=lhc%2Fweb%2Fwiklou.git Style fixes to Sanitizer and Parser All parser tests pass, no functional change. --- diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 9bcc18b610..0487762205 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -410,37 +410,43 @@ class Sanitizer { $text = Sanitizer::removeHTMLcomments( $text ); $bits = explode( '<', $text ); $text = str_replace( '>', '>', array_shift( $bits ) ); - if(!$wgUseTidy) { + if ( !$wgUseTidy ) { $tagstack = $tablestack = array(); foreach ( $bits as $x ) { $regs = array(); + # $slash: Does the current element start with a '/'? + # $t: Current element name + # $params: String between element name and > + # $brace: Ending '>' or '/>' + # $rest: Everything until the next element of $bits if( preg_match( '!^(/?)(\\w+)([^>]*?)(/{0,1}>)([^<]*)$!', $x, $regs ) ) { list( /* $qbar */, $slash, $t, $params, $brace, $rest ) = $regs; } else { $slash = $t = $params = $brace = $rest = null; } - $badtag = 0 ; + $badtag = false; if ( isset( $htmlelements[$t = strtolower( $t )] ) ) { # Check our stack - if ( $slash ) { - # Closing a tag... - if( isset( $htmlsingleonly[$t] ) ) { - $badtag = 1; - } elseif ( ( $ot = @array_pop( $tagstack ) ) != $t ) { + if ( $slash && isset( $htmlsingleonly[$t] ) ) { + $badtag = true; + } elseif ( $slash ) { + # Closing a tag... is it the one we just opened? + $ot = @array_pop( $tagstack ); + if ( $ot != $t ) { if ( isset( $htmlsingleallowed[$ot] ) ) { # Pop all elements with an optional close tag # and see if we find a match below them $optstack = array(); - array_push ($optstack, $ot); - while ( ( ( $ot = @array_pop( $tagstack ) ) != $t ) && - isset( $htmlsingleallowed[$ot] ) ) - { - array_push ($optstack, $ot); + array_push( $optstack, $ot ); + $ot = @array_pop( $tagstack ); + while ( $ot != $t && isset( $htmlsingleallowed[$ot] ) ) { + array_push( $optstack, $ot ); + $ot = @array_pop( $tagstack ); } if ( $t != $ot ) { - # No match. Push the optinal elements back again - $badtag = 1; + # No match. Push the optional elements back again + $badtag = true; while ( $ot = @array_pop( $optstack ) ) { array_push( $tagstack, $ot ); } @@ -448,8 +454,8 @@ class Sanitizer { } else { @array_push( $tagstack, $ot ); #
  • can be nested in