r88928 MediaWiki - Code Review archive

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

Diff [purge]

Index: trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
@@ -28,7 +28,7 @@
2929 * @param $text
3030 * @return Boolean
3131 */
32 - static function parse( &$parser, &$text ) {
 32+ static function parse ( &$parser, &$text ) {
3333
3434 wfProfileIn( __METHOD__ );
3535
@@ -38,7 +38,6 @@
3939 wfProfileOut( __METHOD__ );
4040
4141 return true;
42 -
4342 }
4443
4544 /**
@@ -46,19 +45,18 @@
4746 *
4847 * @return Array an array mapping terms (keys) to descriptions (values)
4948 */
50 - function getGlossaryArray( SemanticGlossaryMessageLog &$messages = null ) {
 49+ function getGlossaryArray ( SemanticGlossaryMessageLog &$messages = null ) {
5150
5251 global $smwgQDefaultNamespaces;
5352
5453 wfProfileIn( __METHOD__ );
5554
5655 $store = smwfGetStore(); // default store
57 -
5856 // Create query
59 - $desc = new SMWSomeProperty(new SMWDIProperty( '___glt' ), new SMWThingDescription());
60 - $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' ) ));
61 - $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' ) ));
62 - $desc -> addPrintRequest(new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' ) ));
 57+ $desc = new SMWSomeProperty( new SMWDIProperty( '___glt' ), new SMWThingDescription() );
 58+ $desc -> addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' ) ) );
 59+ $desc -> addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' ) ) );
 60+ $desc -> addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' ) ) );
6361
6462 $query = new SMWQuery( $desc, true, false );
6563 $query -> querymode = SMWQuery::MODE_INSTANCES;
@@ -93,14 +91,14 @@
9492
9593 if ( $messages ) {
9694 $messages -> addMessage(
97 - wfMsg('semanticglossary-termdefinedtwice', array($subject -> getPrefixedText())),
 95+ wfMsg( 'semanticglossary-termdefinedtwice', array( $subject -> getPrefixedText() ) ),
9896 SemanticGlossaryMessageLog::SG_WARNING );
9997 }
10098
10199 continue;
102100 }
103101
104 - $source = array( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getDBkey() );
 102+ $source = array( $subject -> getDBkey(), $subject -> getNamespace(), $subject -> getInterwiki(), $subject -> getDBkey() );
105103
106104 if ( array_key_exists( $term, $result ) ) {
107105 $result[ $term ] -> addDefinition( $definition, $link, $source );
@@ -123,7 +121,7 @@
124122 * @param $text
125123 * @return Boolean
126124 */
127 - protected function realParse( &$parser, &$text ) {
 125+ protected function realParse ( &$parser, &$text ) {
128126
129127 global $wgRequest, $sggSettings;
130128
@@ -144,12 +142,11 @@
145143 // var_export($text);
146144 //Parse HTML from page
147145 // $doc = new DOMDocument();
148 -//// @$doc -> loadHTML( '<html><meta http-equiv="content-type" content="charset=utf-8"/>' . $text . '</html>' );
 146+// @$doc -> loadHTML( '<html><meta http-equiv="content-type" content="charset=utf-8"/>' . $text . '</html>' );
149147 // $doc -> loadHTML( $text );
 148+ // FIXME: this works in PHP 5.3.3. What about 5.1?
 149+ $doc = @DOMDocument::loadHTML( $text );
150150
151 - // this works in PHP 5.3.3. What about 5.1?
152 - $doc = @DOMDocument::loadHTML($text);
153 -
154151 //Find all text in HTML.
155152 $xpath = new DOMXpath( $doc );
156153 $elements = $xpath -> query( "//*[not(ancestor-or-self::*[@class='noglossary'] or ancestor-or-self::a)][text()!=' ']/text()" );
@@ -167,7 +164,7 @@
168165
169166 //Split node text into words, putting offset and text into $offsets[0] array
170167 // preg_match_all( "/\b[^\b\s\.,;:]+/", $el -> nodeValue, $offsets, PREG_OFFSET_CAPTURE );
171 - preg_match_all( "/[^\s$sggSettings->punctuationCharacters]+/", $el -> nodeValue, $offsets, PREG_OFFSET_CAPTURE );
 168+ preg_match_all( "/[^\s{$sggSettings -> punctuationCharacters}]+/", $el -> nodeValue, $offsets, PREG_OFFSET_CAPTURE );
172169
173170 //Search and replace words in reverse order (from end of string backwards),
174171 //This way we don't mess up the offsets of the words as we iterate
@@ -209,7 +206,13 @@
210207
211208 if ( $changed ) {
212209 $body = $xpath -> query( '/html/body' );
213 - $text = $doc -> saveHTML();
 210+// $text = $doc -> saveXML( $body -> item( 0 ) );
 211+
 212+ $text = '';
 213+ foreach ( $body -> item( 0 ) -> childNodes as $child ) {
 214+ $text .= $doc -> saveXML( $child );
 215+ }
 216+
214217 $this -> loadModules( $parser );
215218 }
216219
@@ -218,7 +221,7 @@
219222 return true;
220223 }
221224
222 - protected function loadModules( &$parser ) {
 225+ protected function loadModules ( &$parser ) {
223226
224227 global $wgOut, $wgScriptPath;
225228

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

Status & tagging log