r14196 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14195‎ | r14196 | r14197 >
Date:10:23, 13 May 2006
Author:hashar
Status:old
Tags:
Comment:
Sanitizer debugging statements.
Modified paths:
  • /branches/hashar/includes/DefaultSettings.php (modified) (history)
  • /branches/hashar/includes/Sanitizer.php (modified) (history)

Diff [purge]

Index: branches/hashar/includes/Sanitizer.php
@@ -328,7 +328,7 @@
329329 * @return string
330330 */
331331 function removeHTMLtags( $text, $processCallback = null, $args = array() ) {
332 - global $wgUseTidy, $wgUserHtml;
 332+ global $wgUseTidy, $wgUserHtml, $wgDebugSanitizer;
333333 $fname = 'Parser::removeHTMLtags';
334334 wfProfileIn( $fname );
335335
@@ -375,8 +375,10 @@
376376 $bits = explode( '<', $text );
377377 $text = array_shift( $bits );
378378 if(!$wgUseTidy) {
 379+ if($wgDebugSanitizer) { wfDebug("\nSanitizer: BEGIN removeHTMLtags without tidy\n\n"); }
379380 $tagstack = array(); $tablestack = array();
380381 foreach ( $bits as $x ) {
 382+ if($wgDebugSanitizer) { wfDebug("Sanitizer: NEW BIT: '$x'\n"); }
381383 $prev = error_reporting( E_ALL & ~( E_NOTICE | E_WARNING ) );
382384 preg_match( '/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/',
383385 $x, $regs );
@@ -387,13 +389,17 @@
388390 if ( in_array( $t = strtolower( $t ), $htmlelements ) ) {
389391 # Check our stack
390392 if ( $slash ) {
 393+ if($wgDebugSanitizer) { wfDebug("Sanitizer: slash: $t\n"); }
391394 # Closing a tag...
392395 if( in_array( $t, $htmlsingleonly ) ) {
 396+ if($wgDebugSanitizer) { wfDebug("Sanitizer: htmlsingleonly: $t\n"); }
393397 $badtag = 1;
394398 } elseif ( ( $ot = @array_pop( $tagstack ) ) != $t ) {
 399+ if($wgDebugSanitizer) { wfDebug("Sanitizer: diff: $t != $ot\n"); }
395400 @array_push( $tagstack, $ot );
396401 # <li> can be nested in <ul> or <ol>, skip those cases:
397402 if(!(in_array($ot, $htmllist) && in_array($t, $listtags) )) {
 403+ if($wgDebugSanitizer) { wfDebug("Sanitizer: $t FUN => badtag\n"); }
398404 $badtag = 1;
399405 }
400406 } else {
@@ -403,21 +409,27 @@
404410 $newparams = '';
405411 }
406412 } else {
 413+ if($wgDebugSanitizer) { wfDebug("Sanitizer: $t NO slash\n"); }
407414 # Keep track for later
408415 if ( in_array( $t, $tabletags ) &&
409416 ! in_array( 'table', $tagstack ) ) {
 417+ if($wgDebugSanitizer) { wfDebug("Sanitizer: $t out of table? => badtag\n"); }
410418 $badtag = 1;
411419 } else if ( in_array( $t, $tagstack ) &&
412420 ! in_array ( $t , $htmlnest ) ) {
 421+ if($wgDebugSanitizer) { wfDebug("Sanitizer: $t not a nest => badtag\n"); }
413422 $badtag = 1 ;
414423 # Is it a self closed htmlpair ? (bug 5487)
415424 } else if( $brace == '/>' &&
416425 in_array($t, $htmlpairs) ) {
 426+ if($wgDebugSanitizer) { wfDebug("Sanitizer: $t not a self closed pair => badtag\n"); }
417427 $badtag = 1;
418428 } elseif( in_array( $t, $htmlsingleonly ) ) {
 429+ if($wgDebugSanitizer) { wfDebug("Sanitizer: $t htmlsingleonly close forced\n"); }
419430 # Hack to force empty tag for uncloseable elements
420431 $brace = '/>';
421432 } else if( in_array( $t, $htmlsingle ) ) {
 433+ if($wgDebugSanitizer) { wfDebug("Sanitizer: $t htmlsingle noclose forced\n"); }
422434 # Hack to not close $htmlsingle tags
423435 $brace = NULL;
424436 } else {
@@ -440,16 +452,28 @@
441453 if ( ! $badtag ) {
442454 $rest = str_replace( '>', '&gt;', $rest );
443455 $close = ( $brace == '/>' ) ? ' /' : '';
444 - $text .= "<$slash$t$newparams$close>$rest";
 456+ $toadd = "<$slash$t$newparams$close>$rest";
 457+ if($wgDebugSanitizer) { wfDebug("Sanitizer: RESULT: '$toadd'\n"); }
 458+ $text .= $toadd;
445459 continue;
446460 }
447461 }
 462+ if($wgDebugSanitizer) { wfDebug("Sanitizer: RESULT: escaping '$x'\n"); }
448463 $text .= '&lt;' . str_replace( '>', '&gt;', $x);
449464 }
450 - # Close off any remaining tags
451 - while ( is_array( $tagstack ) && ($t = array_pop( $tagstack )) ) {
452 - $text .= "</$t>\n";
453 - if ( $t == 'table' ) { $tagstack = array_pop( $tablestack ); }
 465+
 466+ if( is_array( $tagstack ) ) {
 467+ if($wgDebugSanitizer) { wfDebug("Sanitizer: start closing remaining tags:\n");}
 468+ # Close off any remaining tags
 469+ while ( is_array( $tagstack ) && ($t = array_pop( $tagstack )) ) {
 470+ if($wgDebugSanitizer) { wfDebug("Sanitizer: closing $t\n");}
 471+ $text .= "</$t>\n";
 472+ if ( $t == 'table' ) { $tagstack = array_pop( $tablestack ); }
 473+ }
 474+ if($wgDebugSanitizer) {
 475+ wfDebug("Sanitizer: closed all remainingtags.\n");
 476+ wfDebug("\nSanitizer: END OF removeHTMLtags without tidy\n");
 477+ }
454478 }
455479 } else {
456480 # this might be possible using tidy itself
Index: branches/hashar/includes/DefaultSettings.php
@@ -703,6 +703,7 @@
704704 $wgDebugRedirects = false;
705705 $wgDebugRawPage = false; # Avoid overlapping debug entries by leaving out CSS
706706
 707+$wgDebugSanitizer = false;
707708 $wgDebugComments = false;
708709 $wgReadOnly = null;
709710 $wgLogQueries = false;

Status & tagging log