mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RSS
synced 2024-11-23 23:34:07 +00:00
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.
This commit is contained in:
parent
559d041d5e
commit
e0d4f1dc22
Notes:
Thomas Gries
2012-02-13 01:39:24 +00:00
|
@ -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:
|
||||
|
|
5
RSS.php
5
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)";
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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 <script> tags neutered.
|
||||
|
||||
foreach ( array_keys( $item ) as $info ) {
|
||||
if ( $info != 'link' ) {
|
||||
$txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) );
|
||||
} else {
|
||||
switch ( $info ) {
|
||||
case 'link':
|
||||
$txt = $this->sanitizeUrl( $item[ $info ] );
|
||||
break;
|
||||
case 'date':
|
||||
// PHP > 5.3.0 users can better use date_create_from_format method to reformat a date string
|
||||
$tempTimezone = date_default_timezone_get();
|
||||
date_default_timezone_set( 'UTC' );
|
||||
$txt = date( $this->date, strtotime( $item[ $info ] ) );
|
||||
date_default_timezone_set( $tempTimezone );
|
||||
break;
|
||||
default:
|
||||
$txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) );
|
||||
}
|
||||
|
||||
$renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue