r61192 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61191‎ | r61192 | r61193 >
Date:01:30, 18 January 2010
Author:simetrical
Status:ok
Tags:
Comment:
Style fixes to Sanitizer and Parser

All parser tests pass, no functional change.
Modified paths:
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -718,11 +718,11 @@
719719 $attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' );
720720
721721 $outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>";
722 - array_push ( $td_history , false );
723 - array_push ( $last_tag_history , '' );
724 - array_push ( $tr_history , false );
725 - array_push ( $tr_attributes , '' );
726 - array_push ( $has_opened_tr , false );
 722+ array_push( $td_history , false );
 723+ array_push( $last_tag_history , '' );
 724+ array_push( $tr_history , false );
 725+ array_push( $tr_attributes , '' );
 726+ array_push( $has_opened_tr , false );
727727 } else if ( count ( $td_history ) == 0 ) {
728728 // Don't do any of the following
729729 $out .= $outLine."\n";
@@ -751,9 +751,9 @@
752752
753753 // Whats after the tag is now only attributes
754754 $attributes = $this->mStripState->unstripBoth( $line );
755 - $attributes = Sanitizer::fixTagAttributes ( $attributes , 'tr' );
756 - array_pop ( $tr_attributes );
757 - array_push ( $tr_attributes , $attributes );
 755+ $attributes = Sanitizer::fixTagAttributes( $attributes, 'tr' );
 756+ array_pop( $tr_attributes );
 757+ array_push( $tr_attributes, $attributes );
758758
759759 $line = '';
760760 $last_tag = array_pop ( $last_tag_history );
Index: trunk/phase3/includes/Sanitizer.php
@@ -410,37 +410,43 @@
411411 $text = Sanitizer::removeHTMLcomments( $text );
412412 $bits = explode( '<', $text );
413413 $text = str_replace( '>', '&gt;', array_shift( $bits ) );
414 - if(!$wgUseTidy) {
 414+ if ( !$wgUseTidy ) {
415415 $tagstack = $tablestack = array();
416416 foreach ( $bits as $x ) {
417417 $regs = array();
 418+ # $slash: Does the current element start with a '/'?
 419+ # $t: Current element name
 420+ # $params: String between element name and >
 421+ # $brace: Ending '>' or '/>'
 422+ # $rest: Everything until the next element of $bits
418423 if( preg_match( '!^(/?)(\\w+)([^>]*?)(/{0,1}>)([^<]*)$!', $x, $regs ) ) {
419424 list( /* $qbar */, $slash, $t, $params, $brace, $rest ) = $regs;
420425 } else {
421426 $slash = $t = $params = $brace = $rest = null;
422427 }
423428
424 - $badtag = 0 ;
 429+ $badtag = false;
425430 if ( isset( $htmlelements[$t = strtolower( $t )] ) ) {
426431 # Check our stack
427 - if ( $slash ) {
428 - # Closing a tag...
429 - if( isset( $htmlsingleonly[$t] ) ) {
430 - $badtag = 1;
431 - } elseif ( ( $ot = @array_pop( $tagstack ) ) != $t ) {
 432+ if ( $slash && isset( $htmlsingleonly[$t] ) ) {
 433+ $badtag = true;
 434+ } elseif ( $slash ) {
 435+ # Closing a tag... is it the one we just opened?
 436+ $ot = @array_pop( $tagstack );
 437+ if ( $ot != $t ) {
432438 if ( isset( $htmlsingleallowed[$ot] ) ) {
433439 # Pop all elements with an optional close tag
434440 # and see if we find a match below them
435441 $optstack = array();
436 - array_push ($optstack, $ot);
437 - while ( ( ( $ot = @array_pop( $tagstack ) ) != $t ) &&
438 - isset( $htmlsingleallowed[$ot] ) )
439 - {
440 - array_push ($optstack, $ot);
 442+ array_push( $optstack, $ot );
 443+ $ot = @array_pop( $tagstack );
 444+ while ( $ot != $t && isset( $htmlsingleallowed[$ot] ) ) {
 445+ array_push( $optstack, $ot );
 446+ $ot = @array_pop( $tagstack );
441447 }
442448 if ( $t != $ot ) {
443 - # No match. Push the optinal elements back again
444 - $badtag = 1;
 449+ # No match. Push the optional elements back again
 450+ $badtag = true;
445451 while ( $ot = @array_pop( $optstack ) ) {
446452 array_push( $tagstack, $ot );
447453 }
@@ -448,8 +454,8 @@
449455 } else {
450456 @array_push( $tagstack, $ot );
451457 # <li> can be nested in <ul> or <ol>, skip those cases:
452 - if(!(isset( $htmllist[$ot] ) && isset( $listtags[$t] ) )) {
453 - $badtag = 1;
 458+ if ( !isset( $htmllist[$ot] ) || !isset( $listtags[$t] ) ) {
 459+ $badtag = true;
454460 }
455461 }
456462 } else {
@@ -461,23 +467,23 @@
462468 } else {
463469 # Keep track for later
464470 if ( isset( $tabletags[$t] ) &&
465 - ! in_array( 'table', $tagstack ) ) {
466 - $badtag = 1;
467 - } else if ( in_array( $t, $tagstack ) &&
468 - ! isset( $htmlnest [$t ] ) ) {
469 - $badtag = 1 ;
 471+ !in_array( 'table', $tagstack ) ) {
 472+ $badtag = true;
 473+ } elseif ( in_array( $t, $tagstack ) &&
 474+ !isset( $htmlnest [$t ] ) ) {
 475+ $badtag = true;
470476 # Is it a self closed htmlpair ? (bug 5487)
471 - } else if( $brace == '/>' &&
 477+ } elseif ( $brace == '/>' &&
472478 isset( $htmlpairs[$t] ) ) {
473 - $badtag = 1;
474 - } elseif( isset( $htmlsingleonly[$t] ) ) {
 479+ $badtag = true;
 480+ } elseif ( isset( $htmlsingleonly[$t] ) ) {
475481 # Hack to force empty tag for uncloseable elements
476482 $brace = '/>';
477 - } else if( isset( $htmlsingle[$t] ) ) {
 483+ } elseif ( isset( $htmlsingle[$t] ) ) {
478484 # Hack to not close $htmlsingle tags
479485 $brace = null;
480 - } else if( isset( $tabletags[$t] )
481 - && in_array($t ,$tagstack) ) {
 486+ } elseif ( isset( $tabletags[$t] )
 487+ && in_array( $t, $tagstack ) ) {
482488 // New table tag but forgot to close the previous one
483489 $text .= "</$t>";
484490 } else {
@@ -497,7 +503,7 @@
498504 # Strip non-approved attributes from the tag
499505 $newparams = Sanitizer::fixTagAttributes( $params, $t );
500506 }
501 - if ( ! $badtag ) {
 507+ if ( !$badtag ) {
502508 $rest = str_replace( '>', '&gt;', $rest );
503509 $close = ( $brace == '/>' && !$slash ) ? ' /' : '';
504510 $text .= "<$slash$t$newparams$close>$rest";

Status & tagging log