From d4469dcc53ea505df5775292b313562c58715c17 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Mon, 25 Aug 2008 19:03:18 +0000 Subject: [PATCH] Add separate debug output from the normal wfDebug() output, similar to the parser debug report. Only displayed if A) $wgEnableHtmlDiff is on and B) $wgDebugComments is on. --- includes/DifferenceEngine.php | 5 ++++- includes/HTMLDiff.php | 38 ++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 4f5266583b..0f030581f6 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -337,7 +337,7 @@ CONTROL; function renderHtmlDiff() { - global $wgOut, $wgTitle, $wgParser; + global $wgOut, $wgTitle, $wgParser, $wgDebugComments; wfProfileIn( __METHOD__ ); $this->showDiffStyle(); @@ -392,6 +392,9 @@ CONTROL; $differ = new HTMLDiffer(new DelegatingContentHandler($wgOut)); $differ->htmlDiff($oldHtml, $newHtml); + if ( $wgDebugComments ) { + $wgOut->addHtml( "\n" ); + } wfProfileOut( __METHOD__ ); } diff --git a/includes/HTMLDiff.php b/includes/HTMLDiff.php index 13d7702d74..a5e94aacc5 100644 --- a/includes/HTMLDiff.php +++ b/includes/HTMLDiff.php @@ -398,10 +398,7 @@ class ImageNode extends TextNode { function __construct(TagNode $parent, /*array*/ $attrs) { if(!array_key_exists('src', $attrs)) { - //wfDebug('Image without a source:'); - //foreach ($attrs as $key => &$value) { - //wfDebug("$key = $value"); - //} + HTMLDiffer::diffDebug( "Image without a source\n" ); parent::__construct($parent, ''); }else{ parent::__construct($parent, '' . strtolower($attrs['src']) . ''); @@ -504,12 +501,12 @@ class DomTreeBuilder { */ public function endDocument() { $this->endWord(); - //wfDebug(count($this->textNodes) . ' text nodes in document.'); + HTMLDiffer::diffDebug( count($this->textNodes) . " text nodes in document.\n" ); } public function startElement($parser, $name, /*array*/ $attributes) { if (strcasecmp($name, 'body') != 0) { - //wfDebug("Starting $name node."); + HTMLDiffer::diffDebug( "Starting $name node.\n" ); $this->endWord(); $newNode = new TagNode($this->currentParent, $name, $attributes); @@ -528,7 +525,7 @@ class DomTreeBuilder { public function endElement($parser, $name) { if(strcasecmp($name, 'body') != 0) { - //wfDebug("Ending $name node."); + HTMLDiffer::diffDebug( "Ending $name node.\n"); if (0 == strcasecmp($name,'img')) { // Insert a dummy leaf for the image $img = new ImageNode($this->currentParent, $this->currentParent->attributes); @@ -710,7 +707,7 @@ class TextNodeDiffer { $junk1 = $junk2 = null; $deletedNodes = $root->getMinimalDeletedSet($this->deletedID, $junk1, $junk2); - //wfDebug("Minimal set of deleted nodes of size " . count($deletedNodes)); + HTMLDiffer::diffDebug( "Minimal set of deleted nodes of size " . count($deletedNodes) . "\n" ); // Set prevLeaf to the leaf after which the old HTML needs to be // inserted @@ -806,6 +803,7 @@ class TextNodeDiffer { class HTMLDiffer { private $output; + private static $debug = ''; function __construct($output) { $this->output = $output; @@ -824,13 +822,13 @@ class HTMLDiffer { // Set the function to handle blocks of character data xml_set_character_data_handler($xml_parser, array($domfrom, "characters")); - //wfDebug('Parsing '.strlen($from)." characters worth of HTML\n"); + HTMLDiffer::diffDebug( "Parsing " . strlen($from) . " characters worth of HTML\n" ); if (!xml_parse($xml_parser, ''.Sanitizer::hackDocType().'', false) || !xml_parse($xml_parser, $from, false) || !xml_parse($xml_parser, '', true)){ $error = xml_error_string(xml_get_error_code($xml_parser)); $line = xml_get_current_line_number($xml_parser); - wfDebug("XML error: $error at line $line\n"); + HTMLDiffer::diffDebug( "XML error: $error at line $line\n" ); } xml_parser_free($xml_parser); unset($from); @@ -845,13 +843,13 @@ class HTMLDiffer { // Set the function to handle blocks of character data xml_set_character_data_handler($xml_parser, array($domto, "characters")); - //wfDebug('Parsing '.strlen($to)." characters worth of HTML\n"); + HTMLDiffer::diffDebug( "Parsing " . strlen($to) . " characters worth of HTML\n" ); if (!xml_parse($xml_parser, ''.Sanitizer::hackDocType().'', false) || !xml_parse($xml_parser, $to, false) || !xml_parse($xml_parser, '', true)){ $error = xml_error_string(xml_get_error_code($xml_parser)); $line = xml_get_current_line_number($xml_parser); - wfDebug("XML error: $error at line $line\n"); + HTMLDiffer::diffDebug( "XML error: $error at line $line\n" ); } xml_parser_free($xml_parser); unset($to); @@ -938,6 +936,22 @@ class HTMLDiffer { return $d / (1.5 * count($numbers)); } + /** + * Add to debug output + * @param string $str Debug output + */ + public static function diffDebug( $str ) { + self :: $debug .= $str; + } + + /** + * Get debug output + * @return string + */ + public static function getDebugOutput() { + return self :: $debug; + } + } class TextOnlyComparator { -- 2.20.1