mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RSS
synced 2024-11-27 17:10:25 +00:00
fix for bug30377 : add a new parameter to limit the number of characters when rendering the channel item <description>
This commit is contained in:
parent
46e1da3b14
commit
f54d6b047b
Notes:
Thomas Gries
2012-02-13 07:23:56 +00:00
|
@ -2,8 +2,6 @@ RELEASE NOTES of the MediaWiki extension RSS
|
|||
http://www.mediawiki.org/wiki/Extension:RSS
|
||||
|
||||
=== 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
|
||||
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
|
||||
|
@ -15,8 +13,11 @@ 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 ===
|
||||
=== Version 1.92 2012-02-13 ===
|
||||
* 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 ===
|
||||
* removed parsing of each single channel subelement (item)
|
||||
|
|
6
RSS.php
6
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.91 20120213',
|
||||
'version' => '1.92 20120213',
|
||||
'url' => 'https://www.mediawiki.org/wiki/Extension:RSS',
|
||||
'descriptionmsg' => 'rss-desc',
|
||||
);
|
||||
|
@ -68,3 +68,7 @@ $wgRSSProxy = false;
|
|||
|
||||
// default date format of item publication dates see http://www.php.net/date
|
||||
$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;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
class RSSParser {
|
||||
protected $maxheads = 32;
|
||||
protected $date = "Y-m-d H:i:s";
|
||||
protected $ItemMaxLength = 200;
|
||||
protected $reversed = false;
|
||||
protected $highlight = array();
|
||||
protected $filter = array();
|
||||
|
@ -37,7 +39,7 @@ class RSSParser {
|
|||
* and return an object that can produce rendered output.
|
||||
*/
|
||||
function __construct( $url, $args ) {
|
||||
global $wgRSSDateDefaultFormat;
|
||||
global $wgRSSDateDefaultFormat,$wgRSSItemMaxLength;
|
||||
|
||||
$this->url = $url;
|
||||
|
||||
|
@ -60,8 +62,6 @@ class RSSParser {
|
|||
case ( isset( $wgRSSDateDefaultFormat ) ):
|
||||
$this->date = $wgRSSDateDefaultFormat;
|
||||
break;
|
||||
default:
|
||||
$this->date = "Y-m-d H:i:s";
|
||||
}
|
||||
|
||||
# Get highlight terms from argument array
|
||||
|
@ -75,6 +75,16 @@ class RSSParser {
|
|||
$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'] ) ) {
|
||||
$this->filterOut = self::explodeOnSpaces( $args['filterout'] );
|
||||
}
|
||||
|
@ -298,6 +308,7 @@ class RSSParser {
|
|||
// and that means bad RSS with stuff like
|
||||
// <description><script>alert("hi")</script></description> will find its
|
||||
// rogue <script> tags neutered.
|
||||
// use the overloaded multi byte wrapper functions in GlobalFunctions.php
|
||||
|
||||
foreach ( array_keys( $item ) as $info ) {
|
||||
switch ( $info ) {
|
||||
|
@ -311,8 +322,12 @@ class RSSParser {
|
|||
$txt = date( $this->date, strtotime( $this->escapeTemplateParameter( $item[ $info ] ) ) );
|
||||
date_default_timezone_set( $tempTimezone );
|
||||
break;
|
||||
default:
|
||||
$txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) );
|
||||
default:
|
||||
$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 );
|
||||
|
|
Loading…
Reference in a new issue