From e0d4f1dc2210c0d0bef2f170a7634dbbb880233f Mon Sep 17 00:00:00 2001 From: Thomas Gries Date: Mon, 13 Feb 2012 01:39:24 +0000 Subject: [PATCH] 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. --- RELEASE-NOTES | 3 +++ RSS.php | 5 ++++- RSSData.php | 3 --- RSSParser.php | 31 +++++++++++++++++++++++++------ 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a2b1540..e4b3942 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -15,6 +15,9 @@ http://www.mediawiki.org/wiki/Extension:RSS * bug 30028 "Error parsing XML for RSS" - improve and harden Extension:RSS when parsing differently flavoured RSS feeds +=== Version 1.91 2012-02-13 === +* added optional date= attribute and $wgRSSDateDefaultFormat parameter + === Version 1.90 2011-08-15 === * removed parsing of each single channel subelement (item) * only the finally constructed feed is sent to the recursive parser: diff --git a/RSS.php b/RSS.php index 1fe406d..31e056c 100644 --- a/RSS.php +++ b/RSS.php @@ -26,7 +26,7 @@ $wgExtensionCredits['parserhook'][] = array( 'Rdb', 'Mafs', 'Alxndr', 'Thomas Gries', 'Chris Reigrut', 'K001', 'Jack Phoenix', 'Jeroen De Dauw', 'Mark A. Hershberger' ), - 'version' => '1.90 20110815', + 'version' => '1.91 20120213', 'url' => 'https://www.mediawiki.org/wiki/Extension:RSS', 'descriptionmsg' => 'rss-desc', ); @@ -65,3 +65,6 @@ $wgRSSUserAgent = 'MediaWikiRSS/0.02 (+http://www.mediawiki.org/wiki/Extension:R // Proxy server to use for fetching feeds $wgRSSProxy = false; + +// default date format of item publication dates see http://www.php.net/date +$wgRSSDateDefaultFormat = "(Y-m-d H:i:s)"; diff --git a/RSSData.php b/RSSData.php index de3fa20..c8f4a9f 100644 --- a/RSSData.php +++ b/RSSData.php @@ -55,11 +55,8 @@ class RSSData { protected function rssTokenToName( $n ) { switch( $n ) { case 'dc:date': - return 'date'; - # parse "2010-10-18T18:07:00Z" case 'pubDate': return 'date'; - # parse RFC date case 'dc:creator': return 'author'; case 'title': diff --git a/RSSParser.php b/RSSParser.php index 8c5eb7e..620ec82 100644 --- a/RSSParser.php +++ b/RSSParser.php @@ -37,6 +37,8 @@ class RSSParser { * and return an object that can produce rendered output. */ function __construct( $url, $args ) { + global $wgRSSDateDefaultFormat; + $this->url = $url; # Get max number of headlines from argument-array @@ -50,11 +52,18 @@ class RSSParser { } # Get date format from argument array - # FIXME: not used yet - if ( isset( $args['date'] ) ) { + # or use a default value + switch ( true ) { + case ( isset( $args['date'] ) ): $this->date = $args['date']; + break; + case ( isset( $wgRSSDateDefaultFormat ) ): + $this->date = $wgRSSDateDefaultFormat; + break; + default: + $this->date = "Y-m-d H:i:s"; } - + # Get highlight terms from argument array if ( isset( $args['highlight'] ) ) { # mapping to lowercase here so the regex can be case insensitive below. @@ -291,11 +300,21 @@ class RSSParser { // rogue