Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -718,11 +718,11 @@ |
719 | 719 | $attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' ); |
720 | 720 | |
721 | 721 | $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 ); |
727 | 727 | } else if ( count ( $td_history ) == 0 ) { |
728 | 728 | // Don't do any of the following |
729 | 729 | $out .= $outLine."\n"; |
— | — | @@ -751,9 +751,9 @@ |
752 | 752 | |
753 | 753 | // Whats after the tag is now only attributes |
754 | 754 | $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 ); |
758 | 758 | |
759 | 759 | $line = ''; |
760 | 760 | $last_tag = array_pop ( $last_tag_history ); |
Index: trunk/phase3/includes/Sanitizer.php |
— | — | @@ -410,37 +410,43 @@ |
411 | 411 | $text = Sanitizer::removeHTMLcomments( $text ); |
412 | 412 | $bits = explode( '<', $text ); |
413 | 413 | $text = str_replace( '>', '>', array_shift( $bits ) ); |
414 | | - if(!$wgUseTidy) { |
| 414 | + if ( !$wgUseTidy ) { |
415 | 415 | $tagstack = $tablestack = array(); |
416 | 416 | foreach ( $bits as $x ) { |
417 | 417 | $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 |
418 | 423 | if( preg_match( '!^(/?)(\\w+)([^>]*?)(/{0,1}>)([^<]*)$!', $x, $regs ) ) { |
419 | 424 | list( /* $qbar */, $slash, $t, $params, $brace, $rest ) = $regs; |
420 | 425 | } else { |
421 | 426 | $slash = $t = $params = $brace = $rest = null; |
422 | 427 | } |
423 | 428 | |
424 | | - $badtag = 0 ; |
| 429 | + $badtag = false; |
425 | 430 | if ( isset( $htmlelements[$t = strtolower( $t )] ) ) { |
426 | 431 | # 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 ) { |
432 | 438 | if ( isset( $htmlsingleallowed[$ot] ) ) { |
433 | 439 | # Pop all elements with an optional close tag |
434 | 440 | # and see if we find a match below them |
435 | 441 | $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 ); |
441 | 447 | } |
442 | 448 | 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; |
445 | 451 | while ( $ot = @array_pop( $optstack ) ) { |
446 | 452 | array_push( $tagstack, $ot ); |
447 | 453 | } |
— | — | @@ -448,8 +454,8 @@ |
449 | 455 | } else { |
450 | 456 | @array_push( $tagstack, $ot ); |
451 | 457 | # <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; |
454 | 460 | } |
455 | 461 | } |
456 | 462 | } else { |
— | — | @@ -461,23 +467,23 @@ |
462 | 468 | } else { |
463 | 469 | # Keep track for later |
464 | 470 | 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; |
470 | 476 | # Is it a self closed htmlpair ? (bug 5487) |
471 | | - } else if( $brace == '/>' && |
| 477 | + } elseif ( $brace == '/>' && |
472 | 478 | isset( $htmlpairs[$t] ) ) { |
473 | | - $badtag = 1; |
474 | | - } elseif( isset( $htmlsingleonly[$t] ) ) { |
| 479 | + $badtag = true; |
| 480 | + } elseif ( isset( $htmlsingleonly[$t] ) ) { |
475 | 481 | # Hack to force empty tag for uncloseable elements |
476 | 482 | $brace = '/>'; |
477 | | - } else if( isset( $htmlsingle[$t] ) ) { |
| 483 | + } elseif ( isset( $htmlsingle[$t] ) ) { |
478 | 484 | # Hack to not close $htmlsingle tags |
479 | 485 | $brace = null; |
480 | | - } else if( isset( $tabletags[$t] ) |
481 | | - && in_array($t ,$tagstack) ) { |
| 486 | + } elseif ( isset( $tabletags[$t] ) |
| 487 | + && in_array( $t, $tagstack ) ) { |
482 | 488 | // New table tag but forgot to close the previous one |
483 | 489 | $text .= "</$t>"; |
484 | 490 | } else { |
— | — | @@ -497,7 +503,7 @@ |
498 | 504 | # Strip non-approved attributes from the tag |
499 | 505 | $newparams = Sanitizer::fixTagAttributes( $params, $t ); |
500 | 506 | } |
501 | | - if ( ! $badtag ) { |
| 507 | + if ( !$badtag ) { |
502 | 508 | $rest = str_replace( '>', '>', $rest ); |
503 | 509 | $close = ( $brace == '/>' && !$slash ) ? ' /' : ''; |
504 | 510 | $text .= "<$slash$t$newparams$close>$rest"; |