r112308 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112307‎ | r112308 | r112309 >
Date:10:16, 24 February 2012
Author:wikinaut
Status:reverted
Tags:gerritmigration 
Comment:
v2.00 can parse ATOM feeds, at least some. This is a major improvement over pre-2.00 versions which only could read and parse RSS feeds but no ATOM feeds. Version 2.00 begins to keep care of namespaces in the XML. The parser still leaves room for further improvements. At least, E:RSS can now read E:WikiArticleFeeds generated RSS _and_ ATOM feeds.
Modified paths:
  • /trunk/extensions/RSS/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/RSS/RSS.php (modified) (history)
  • /trunk/extensions/RSS/RSSData.php (modified) (history)
  • /trunk/extensions/RSS/RSSParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RSS/RELEASE-NOTES
@@ -11,8 +11,13 @@
1212 (otherwise using the defaults - PHP will abort the entire program when your
1313 memory usage gets too high)
1414 * bug 30028 "Error parsing XML for RSS" - improve and harden Extension:RSS when
15 - parsing differently flavoured RSS feeds
 15+ parsing differently flavoured RSS feeds and ATOM feeds
1616
 17+=== Version 2.00 2012-02-24 ===
 18+* first version which can parse RSS and at least some ATOM feeds
 19+ partial solution of bug 30028 "Error parsing XML for RSS" - improve and harden
 20+ Extension:RSS when parsing differently flavoured RSS feeds and ATOM feeds
 21+
1722 === Version 1.94 2012-02-23 ===
1823 * changed white list definition and behaviour:
1924
Index: trunk/extensions/RSS/RSSData.php
@@ -15,8 +15,29 @@
1616 return;
1717 }
1818 $xpath = new DOMXPath( $xml );
19 - $items = $xpath->query( '/rss/channel/item' );
 19+
 20+ // register namespace as below, and apply a regex to the expression
 21+ // http://de3.php.net/manual/en/domxpath.query.php#103461
 22+ $namespaceURI = $xml->lookupnamespaceURI( NULL );
2023
 24+ if ( ( null !== $namespaceURI ) ) {
 25+ $defaultNS = "defaultNS";
 26+ $xpath->registerNamespace( $defaultNS, $namespaceURI );
 27+ $defaultNS = "defaultNS:";
 28+ } else {
 29+ $defaultNS = "";
 30+ }
 31+
 32+ $q = "/rss/channel/item";
 33+ $q = preg_replace( '#(::|/\s*|\A)(?![/@].+?|[a-z\-]+::)#', '$1' . $defaultNS . '$2', $q );
 34+ $items = $xpath->query( $q ); // is it an RSS feed ?
 35+
 36+ if ( $items->length === 0 ) {
 37+ $q = "/feed/entry";
 38+ $q = preg_replace( '#(::|/\s*|\A)(?![/@].+?|[a-z\-]+::)#', '$1' . $defaultNS . '$2', $q );
 39+ $items = $xpath->query( $q ); // is it an ATOM feed ?
 40+ }
 41+
2142 if( $items->length !== 0 ) {
2243 foreach ( $items as $item ) {
2344 $bit = array();
@@ -37,7 +58,7 @@
3859 $this->items[] = $bit;
3960 }
4061 } else {
41 - $this->error = 'No RSS items found.';
 62+ $this->error = 'No RSS//ATOM items found.';
4263 return;
4364 }
4465 }
@@ -52,10 +73,11 @@
5374 * @param $n String: name of the element we have
5475 * @return String Name to map it to
5576 */
56 - protected function rssTokenToName( $n ) {
57 - switch( $n ) {
 77+ protected function rssTokenToName( $name ) {
 78+ switch( $name ) {
5879 case 'dc:date':
5980 case 'pubDate':
 81+ case 'updated':
6082 return 'date';
6183 case 'dc:creator':
6284 return 'author';
@@ -73,9 +95,8 @@
7496 case 'comments':
7597 case 'category':
7698 return null;
77 -
7899 default:
79 - return $n;
 100+ return $name;
80101 }
81102 }
82103 }
\ No newline at end of file
Index: trunk/extensions/RSS/RSSParser.php
@@ -328,24 +328,32 @@
329329
330330 foreach ( array_keys( $item ) as $info ) {
331331 switch ( $info ) {
 332+ // ATOM <id> elements and RSS <link> elements are item link urls
 333+ case 'id':
 334+ $txt = $this->sanitizeUrl( $item['id'] );
 335+ $renderedItem = str_replace( '{{{link}}}', $txt, $renderedItem );
 336+ break;
332337 case 'link':
333 - $txt = $this->sanitizeUrl( $item[ $info ] );
 338+ if ( !isset( $item['id'] ) ) {
 339+ $txt = $this->sanitizeUrl( $item['link'] );
 340+ }
 341+ $renderedItem = str_replace( '{{{link}}}', $txt, $renderedItem );
334342 break;
335343 case 'date':
336344 $tempTimezone = date_default_timezone_get();
337345 date_default_timezone_set( 'UTC' );
338 - $txt = date( $this->date, strtotime( $this->escapeTemplateParameter( $item[ $info ] ) ) );
 346+ $txt = date( $this->date, strtotime( $this->escapeTemplateParameter( $item['date'] ) ) );
339347 date_default_timezone_set( $tempTimezone );
 348+ $renderedItem = str_replace( '{{{date}}}', $txt, $renderedItem );
340349 break;
341350 default:
342 - $str = $this->escapeTemplateParameter( $item[ $info ] );
 351+ $str = $this->escapeTemplateParameter( $item[$info] );
343352 if ( mb_strlen( $str ) > $this->ItemMaxLength ) {
344353 $str = mb_substr( $str, 0, $this->ItemMaxLength ) . " ...";
345354 }
346355 $txt = $this->highlightTerms( $str );
 356+ $renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem );
347357 }
348 -
349 - $renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem );
350358 }
351359
352360 // nullify all remaining info items in the template
Index: trunk/extensions/RSS/RSS.php
@@ -4,7 +4,7 @@
55 *
66 * @file
77 * @ingroup Extensions
8 - * @version 1.94
 8+ * @version 2.00
99 * @author mutante, Daniel Kinzler, Rdb, Mafs, Thomas Gries, Alxndr, Chris Reigrut, K001
1010 * @author Kellan Elliott-McCrea <kellan@protest.net> -- author of MagpieRSS
1111 * @author Jeroen De Dauw
@@ -14,7 +14,7 @@
1515 * @link http://www.mediawiki.org/wiki/Extension:RSS Documentation
1616 */
1717
18 -define( "EXTENSION_RSS_VERSION", "1.94 20120223" );
 18+define( "EXTENSION_RSS_VERSION", "2.00 20120224" );
1919
2020 if ( !defined( 'MEDIAWIKI' ) ) {
2121 die( "This is not a valid entry point.\n" );
@@ -49,6 +49,7 @@
5050 // Check cached content, if available, against remote.
5151 // $wgRSSCacheCompare should be set to false or a timeout
5252 // (less than $wgRSSCacheAge) after which a comparison will be made.
 53+// for debugging set $wgRSSCacheCompare = 1;
5354 $wgRSSCacheCompare = false;
5455
5556 // 5 second timeout

Follow-up revisions

RevisionCommit summaryAuthorDate
r114390Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251......catrope18:40, 21 March 2012

Status & tagging log