r76841 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76840‎ | r76841 | r76842 >
Date:22:06, 16 November 2010
Author:mah
Status:ok (Comments)
Tags:brion 
Comment:
* Remove the call to disableCache(), that, upon double-checking, does undermine the caching that updateCacheExpiry() is trying to set up in the very next line.
* Fix renderItem so that it isn't overly complex and just subsitutes the parsed contents of RSS elements (e.g. {{{description}}} is substituted with the contents of the <description> tag).
Modified paths:
  • /trunk/extensions/RSS/RSSHooks.php (modified) (history)
  • /trunk/extensions/RSS/RSSParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RSS/RSSHooks.php
@@ -29,7 +29,7 @@
3030 } else {
3131 $timeout = $wgRSSCacheAge;
3232 }
33 - $parser->disableCache();
 33+
3434 $parser->getOutput()->updateCacheExpiry( $timeout );
3535
3636 $rss = new RSSParser( $input, $args );
Index: trunk/extensions/RSS/RSSParser.php
@@ -254,33 +254,26 @@
255255 * @param $frame the frame param to pass to recursiveTagParse()
256256 */
257257 protected function renderItem( $item, $parser, $frame ) {
258 - $parts = explode( '|', $this->itemTemplate );
259 -
260 - $output = '';
261 - if ( count( $parts ) > 1 && isset( $parser ) && isset( $frame ) ) {
 258+ $output = "";
 259+ if ( isset( $parser ) && isset( $frame ) ) {
262260 $rendered = array();
263261 foreach ( $this->displayFields as $field ) {
264262 if ( isset($item[$field] ) ) {
265 - $item[$field] = $this->highlightTerms( wfEscapeWikiText( $item[$field] ) );
 263+ $item[$field] = $this->highlightTerms( $item[$field] );
266264 }
267265 }
268266
269 - foreach ( $parts as $part ) {
270 - $bits = explode( '=', $part );
271 - $left = null;
272 -
273 - if ( count( $bits ) == 2 ) {
274 - $left = trim( $bits[0] );
275 - }
276 -
277 - if ( isset( $item[$left] ) ) {
278 - $leftValue = str_replace( '{{{' . $left . '}}}', $item[$left], $bits[1] );
279 - $rendered[] = "$left = $leftValue";
280 - } else {
281 - $rendered[] = $part;
282 - }
 267+ $rendered = $this->itemTemplate;
 268+ // $info will only be an XML element name, so we're safe
 269+ // using it. $item[$info] is handled by the XML parser --
 270+ // and that means bad RSS with stuff like
 271+ // <description><script>alert("hi")</script></description> will find its
 272+ // rogue <script> tags neutered.
 273+ foreach ( array_keys( $item ) as $info ) {
 274+ $rendered = str_replace( '{{{' . $info . '}}}', wfEscapeWikiText( $item[$info] ),
 275+ $rendered );
283276 }
284 - $output .= $parser->recursiveTagParse( implode( ' | ', $rendered ), $frame );
 277+ $output .= $parser->recursiveTagParse( $rendered, $frame );
285278 }
286279 return $output;
287280 }
@@ -421,7 +414,7 @@
422415 $styleStart = "<span style='font-weight: bold; background: none repeat scroll 0%% 0%% rgb(%s); color: %s;'>";
423416 $styleEnd = '</span>';
424417
425 - # bg colors cribbed from Google's highlighting of search teerms
 418+ # bg colors cribbed from Google's highlighting of search terms
426419 $bgcolor = array( '255, 255, 102', '160, 255, 255', '153, 255, 153',
427420 '255, 153, 153', '255, 102, 255', '136, 0, 0', '0, 170, 0', '136, 104, 0',
428421 '0, 70, 153', '153, 0, 153' );

Comments

#Comment by Brion VIBBER (talk | contribs)   03:24, 8 February 2011

Seems ok to me.

Status & tagging log