r111347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111346‎ | r111347 | r111348 >
Date:01:39, 13 February 2012
Author:wikinaut
Status:reverted
Tags:gerritmigration 
Comment:
adding the long-wanted date format attribute. implemented a date format equalising function, so that dates of RSS feeds are rendered in a common format.
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
@@ -15,6 +15,9 @@
1616 * bug 30028 "Error parsing XML for RSS" - improve and harden Extension:RSS when
1717 parsing differently flavoured RSS feeds
1818
 19+=== Version 1.91 2012-02-13 ===
 20+* added optional date= attribute and $wgRSSDateDefaultFormat parameter
 21+
1922 === Version 1.90 2011-08-15 ===
2023 * removed parsing of each single channel subelement (item)
2124 * only the finally constructed feed is sent to the recursive parser:
Index: trunk/extensions/RSS/RSSData.php
@@ -55,11 +55,8 @@
5656 protected function rssTokenToName( $n ) {
5757 switch( $n ) {
5858 case 'dc:date':
59 - return 'date';
60 - # parse "2010-10-18T18:07:00Z"
6159 case 'pubDate':
6260 return 'date';
63 - # parse RFC date
6461 case 'dc:creator':
6562 return 'author';
6663 case 'title':
Index: trunk/extensions/RSS/RSSParser.php
@@ -37,6 +37,8 @@
3838 * and return an object that can produce rendered output.
3939 */
4040 function __construct( $url, $args ) {
 41+ global $wgRSSDateDefaultFormat;
 42+
4143 $this->url = $url;
4244
4345 # Get max number of headlines from argument-array
@@ -50,11 +52,18 @@
5153 }
5254
5355 # Get date format from argument array
54 - # FIXME: not used yet
55 - if ( isset( $args['date'] ) ) {
 56+ # or use a default value
 57+ switch ( true ) {
 58+ case ( isset( $args['date'] ) ):
5659 $this->date = $args['date'];
 60+ break;
 61+ case ( isset( $wgRSSDateDefaultFormat ) ):
 62+ $this->date = $wgRSSDateDefaultFormat;
 63+ break;
 64+ default:
 65+ $this->date = "Y-m-d H:i:s";
5766 }
58 -
 67+
5968 # Get highlight terms from argument array
6069 if ( isset( $args['highlight'] ) ) {
6170 # mapping to lowercase here so the regex can be case insensitive below.
@@ -291,11 +300,21 @@
292301 // rogue <script> tags neutered.
293302
294303 foreach ( array_keys( $item ) as $info ) {
295 - if ( $info != 'link' ) {
 304+ switch ( $info ) {
 305+ case 'link':
 306+ $txt = $this->sanitizeUrl( $item[ $info ] );
 307+ break;
 308+ case 'date':
 309+ // PHP > 5.3.0 users can better use date_create_from_format method to reformat a date string
 310+ $tempTimezone = date_default_timezone_get();
 311+ date_default_timezone_set( 'UTC' );
 312+ $txt = date( $this->date, strtotime( $item[ $info ] ) );
 313+ date_default_timezone_set( $tempTimezone );
 314+ break;
 315+ default:
296316 $txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) );
297 - } else {
298 - $txt = $this->sanitizeUrl( $item[ $info ] );
299317 }
 318+
300319 $renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem );
301320 }
302321
Index: trunk/extensions/RSS/RSS.php
@@ -26,7 +26,7 @@
2727 'Rdb', 'Mafs', 'Alxndr', 'Thomas Gries', 'Chris Reigrut',
2828 'K001', 'Jack Phoenix', 'Jeroen De Dauw', 'Mark A. Hershberger'
2929 ),
30 - 'version' => '1.90 20110815',
 30+ 'version' => '1.91 20120213',
3131 'url' => 'https://www.mediawiki.org/wiki/Extension:RSS',
3232 'descriptionmsg' => 'rss-desc',
3333 );
@@ -65,3 +65,6 @@
6666
6767 // Proxy server to use for fetching feeds
6868 $wgRSSProxy = false;
 69+
 70+// default date format of item publication dates see http://www.php.net/date
 71+$wgRSSDateDefaultFormat = "(Y-m-d H:i:s)";

Follow-up revisions

RevisionCommit summaryAuthorDate
r111348follow-up r111347 : adding escapeTemplateParameter around the user supplied o...wikinaut01:49, 13 February 2012
r114390Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251......catrope18:40, 21 March 2012

Status & tagging log