fix for bug30377 : add a new parameter to limit the number of characters when rendering the channel item <description>

This commit is contained in:
Thomas Gries 2012-02-13 07:23:56 +00:00
parent 46e1da3b14
commit f54d6b047b
Notes: Thomas Gries 2012-02-13 07:23:56 +00:00
3 changed files with 29 additions and 9 deletions

View file

@ -2,8 +2,6 @@ RELEASE NOTES of the MediaWiki extension RSS
http://www.mediawiki.org/wiki/Extension:RSS http://www.mediawiki.org/wiki/Extension:RSS
=== TO DO === === TO DO ===
* bug 30377 add a new parameter to limit the number of characters when rendering
the channel item <description>
* set an upper default limit for HttpRequest request size when fetching feeds * set an upper default limit for HttpRequest request size when fetching feeds
doing a HEAD request first to ask for the size but that value may not be doing a HEAD request first to ask for the size but that value may not be
available. Check how much data is returned as its coming back available. Check how much data is returned as its coming back
@ -15,8 +13,11 @@ http://www.mediawiki.org/wiki/Extension:RSS
* bug 30028 "Error parsing XML for RSS" - improve and harden Extension:RSS when * bug 30028 "Error parsing XML for RSS" - improve and harden Extension:RSS when
parsing differently flavoured RSS feeds parsing differently flavoured RSS feeds
=== Version 1.91 2012-02-13 === === Version 1.92 2012-02-13 ===
* added optional date= attribute and $wgRSSDateDefaultFormat parameter * added optional date= attribute and $wgRSSDateDefaultFormat parameter
* added optional item-max-length= attribute and $wgRSSItemMaxLength parameter
fixes bug 30377 add a new parameter to limit the number of characters when
rendering the channel item <description>
=== Version 1.90 2011-08-15 === === Version 1.90 2011-08-15 ===
* removed parsing of each single channel subelement (item) * removed parsing of each single channel subelement (item)

View file

@ -26,7 +26,7 @@ $wgExtensionCredits['parserhook'][] = array(
'Rdb', 'Mafs', 'Alxndr', 'Thomas Gries', 'Chris Reigrut', 'Rdb', 'Mafs', 'Alxndr', 'Thomas Gries', 'Chris Reigrut',
'K001', 'Jack Phoenix', 'Jeroen De Dauw', 'Mark A. Hershberger' 'K001', 'Jack Phoenix', 'Jeroen De Dauw', 'Mark A. Hershberger'
), ),
'version' => '1.91 20120213', 'version' => '1.92 20120213',
'url' => 'https://www.mediawiki.org/wiki/Extension:RSS', 'url' => 'https://www.mediawiki.org/wiki/Extension:RSS',
'descriptionmsg' => 'rss-desc', 'descriptionmsg' => 'rss-desc',
); );
@ -68,3 +68,7 @@ $wgRSSProxy = false;
// default date format of item publication dates see http://www.php.net/date // default date format of item publication dates see http://www.php.net/date
$wgRSSDateDefaultFormat = "(Y-m-d H:i:s)"; $wgRSSDateDefaultFormat = "(Y-m-d H:i:s)";
// limit the number of characters in the item description
// or set to false for unlimited length.
// $wgRSSItemMaxLength = 100;

View file

@ -2,6 +2,8 @@
class RSSParser { class RSSParser {
protected $maxheads = 32; protected $maxheads = 32;
protected $date = "Y-m-d H:i:s";
protected $ItemMaxLength = 200;
protected $reversed = false; protected $reversed = false;
protected $highlight = array(); protected $highlight = array();
protected $filter = array(); protected $filter = array();
@ -37,7 +39,7 @@ class RSSParser {
* and return an object that can produce rendered output. * and return an object that can produce rendered output.
*/ */
function __construct( $url, $args ) { function __construct( $url, $args ) {
global $wgRSSDateDefaultFormat; global $wgRSSDateDefaultFormat,$wgRSSItemMaxLength;
$this->url = $url; $this->url = $url;
@ -60,8 +62,6 @@ class RSSParser {
case ( isset( $wgRSSDateDefaultFormat ) ): case ( isset( $wgRSSDateDefaultFormat ) ):
$this->date = $wgRSSDateDefaultFormat; $this->date = $wgRSSDateDefaultFormat;
break; break;
default:
$this->date = "Y-m-d H:i:s";
} }
# Get highlight terms from argument array # Get highlight terms from argument array
@ -75,6 +75,16 @@ class RSSParser {
$this->filter = self::explodeOnSpaces( $args['filter'] ); $this->filter = self::explodeOnSpaces( $args['filter'] );
} }
# Get a maximal length for item texts
switch ( true ) {
case ( isset( $args['item-max-length'] ) ):
$this->ItemMaxLength = $args['item-max-length'];
break;
case ( isset( $wgRSSItemMaxLength ) ):
$this->ItemMaxLength = $wgRSSItemMaxLength;
break;
}
if ( isset( $args['filterout'] ) ) { if ( isset( $args['filterout'] ) ) {
$this->filterOut = self::explodeOnSpaces( $args['filterout'] ); $this->filterOut = self::explodeOnSpaces( $args['filterout'] );
} }
@ -298,6 +308,7 @@ class RSSParser {
// and that means bad RSS with stuff like // and that means bad RSS with stuff like
// <description><script>alert("hi")</script></description> will find its // <description><script>alert("hi")</script></description> will find its
// rogue <script> tags neutered. // rogue <script> tags neutered.
// use the overloaded multi byte wrapper functions in GlobalFunctions.php
foreach ( array_keys( $item ) as $info ) { foreach ( array_keys( $item ) as $info ) {
switch ( $info ) { switch ( $info ) {
@ -311,8 +322,12 @@ class RSSParser {
$txt = date( $this->date, strtotime( $this->escapeTemplateParameter( $item[ $info ] ) ) ); $txt = date( $this->date, strtotime( $this->escapeTemplateParameter( $item[ $info ] ) ) );
date_default_timezone_set( $tempTimezone ); date_default_timezone_set( $tempTimezone );
break; break;
default: default:
$txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) ); $str = $this->escapeTemplateParameter( $item[ $info ] );
if ( mb_strlen( $str ) > $this->ItemMaxLength ) {
$str = mb_substr( $str, 0, $this->ItemMaxLength ) . " ...";
}
$txt = $this->highlightTerms( $str );
} }
$renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem ); $renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem );