r88927 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88926‎ | r88927 | r88928 >
Date:20:27, 26 May 2011
Author:foxtrott
Status:deferred (Comments)
Tags:
Comment:
bugfix: injected illegal tags
Modified paths:
  • /trunk/extensions/Lingo/Lingo.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Lingo/Lingo.php
@@ -1,6 +1,7 @@
22 <?php
33
44 /**
 5+ * Provides hover-over tool tips on articles from words defined on the Terminology page.
56 * For more info see http://mediawiki.org/wiki/Extension:Lingo
67 *
78 * @defgroup Lingo
@@ -15,8 +16,6 @@
1617
1718 define( 'LINGO_VERSION', '0.1' );
1819
19 -
20 -
2120 $wgExtensionCredits[ 'parserhook' ][ ] = array(
2221 'path' => __FILE__,
2322 'name' => 'Lingo',
@@ -75,9 +74,10 @@
7675 $min = min( array_map( 'strlen', array_keys( $terms ) ) );
7776
7877 //Parse HTML from page
79 - $doc = new DOMDocument();
80 - $text = '<html><meta http-equiv="content-type" content="charset=utf-8"/>' . $text . "</html>";
81 - @$doc -> loadHTML( $text );
 78+// $doc = new DOMDocument();
 79+// $doc -> loadHTML( $text );
 80+ $doc = @DOMDocument::loadHTML( $text );
 81+
8282 //Find all text in HTML.
8383 $xpath = new DOMXpath( $doc );
8484 $elements = $xpath -> query( "//*[text()!=' ']/text()" );
@@ -126,7 +126,14 @@
127127 }
128128
129129 if ( $changed ) {
130 - $text = $doc -> saveHTML();
 130+
 131+ $body = $xpath -> query( '/html/body' );
 132+
 133+ $text = '';
 134+ foreach ( $body -> item( 0 ) -> childNodes as $child ) {
 135+ $text .= $doc -> saveXML( $child );
 136+ }
 137+
131138 }
132139
133140 return true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r88978followup r88927 & r88928: use wfSuppressWarnings; enable UTF8foxtrott17:06, 27 May 2011
r88979followup r88927 & r88928: use wfSuppressWarnings; enable UTF8foxtrott17:06, 27 May 2011

Comments

#Comment by Jack Phoenix (talk | contribs)   20:32, 26 May 2011
+	$doc = @DOMDocument::loadHTML( $text );

Don't use @, use wfSuppressWarnings() and wfRestoreWarnings() instead.

+		$body = $xpath -> query( '/html/body' );
+
+		$text = '';
+		foreach ( $body -> item( 0 ) -> childNodes as $child ) {
+			$text .= $doc -> saveXML( $child );
+		}

This is too spacey, and should be written like this instead:

		$body = $xpath->query( '/html/body' );

		$text = '';
		foreach ( $body->item( 0 )->childNodes as $child ) {
			$text .= $doc->saveXML( $child );
		}

Status & tagging log