Index: trunk/extensions/RSS/RELEASE-NOTES |
— | — | @@ -2,8 +2,6 @@ |
3 | 3 | http://www.mediawiki.org/wiki/Extension:RSS |
4 | 4 | |
5 | 5 | === TO DO === |
6 | | -* bug 30377 add a new parameter to limit the number of characters when rendering |
7 | | - the channel item <description> |
8 | 6 | * set an upper default limit for HttpRequest request size when fetching feeds |
9 | 7 | doing a HEAD request first to ask for the size but that value may not be |
10 | 8 | available. Check how much data is returned as its coming back |
— | — | @@ -15,8 +13,11 @@ |
16 | 14 | * bug 30028 "Error parsing XML for RSS" - improve and harden Extension:RSS when |
17 | 15 | parsing differently flavoured RSS feeds |
18 | 16 | |
19 | | -=== Version 1.91 2012-02-13 === |
| 17 | +=== Version 1.92 2012-02-13 === |
20 | 18 | * added optional date= attribute and $wgRSSDateDefaultFormat parameter |
| 19 | +* added optional item-max-length= attribute and $wgRSSItemMaxLength parameter |
| 20 | + fixes bug 30377 add a new parameter to limit the number of characters when |
| 21 | + rendering the channel item <description> |
21 | 22 | |
22 | 23 | === Version 1.90 2011-08-15 === |
23 | 24 | * removed parsing of each single channel subelement (item) |
Index: trunk/extensions/RSS/RSSParser.php |
— | — | @@ -2,6 +2,8 @@ |
3 | 3 | |
4 | 4 | class RSSParser { |
5 | 5 | protected $maxheads = 32; |
| 6 | + protected $date = "Y-m-d H:i:s"; |
| 7 | + protected $ItemMaxLength = 200; |
6 | 8 | protected $reversed = false; |
7 | 9 | protected $highlight = array(); |
8 | 10 | protected $filter = array(); |
— | — | @@ -37,7 +39,7 @@ |
38 | 40 | * and return an object that can produce rendered output. |
39 | 41 | */ |
40 | 42 | function __construct( $url, $args ) { |
41 | | - global $wgRSSDateDefaultFormat; |
| 43 | + global $wgRSSDateDefaultFormat,$wgRSSItemMaxLength; |
42 | 44 | |
43 | 45 | $this->url = $url; |
44 | 46 | |
— | — | @@ -60,8 +62,6 @@ |
61 | 63 | case ( isset( $wgRSSDateDefaultFormat ) ): |
62 | 64 | $this->date = $wgRSSDateDefaultFormat; |
63 | 65 | break; |
64 | | - default: |
65 | | - $this->date = "Y-m-d H:i:s"; |
66 | 66 | } |
67 | 67 | |
68 | 68 | # Get highlight terms from argument array |
— | — | @@ -75,6 +75,16 @@ |
76 | 76 | $this->filter = self::explodeOnSpaces( $args['filter'] ); |
77 | 77 | } |
78 | 78 | |
| 79 | + # Get a maximal length for item texts |
| 80 | + switch ( true ) { |
| 81 | + case ( isset( $args['item-max-length'] ) ): |
| 82 | + $this->ItemMaxLength = $args['item-max-length']; |
| 83 | + break; |
| 84 | + case ( isset( $wgRSSItemMaxLength ) ): |
| 85 | + $this->ItemMaxLength = $wgRSSItemMaxLength; |
| 86 | + break; |
| 87 | + } |
| 88 | + |
79 | 89 | if ( isset( $args['filterout'] ) ) { |
80 | 90 | $this->filterOut = self::explodeOnSpaces( $args['filterout'] ); |
81 | 91 | } |
— | — | @@ -298,6 +308,7 @@ |
299 | 309 | // and that means bad RSS with stuff like |
300 | 310 | // <description><script>alert("hi")</script></description> will find its |
301 | 311 | // rogue <script> tags neutered. |
| 312 | + // use the overloaded multi byte wrapper functions in GlobalFunctions.php |
302 | 313 | |
303 | 314 | foreach ( array_keys( $item ) as $info ) { |
304 | 315 | switch ( $info ) { |
— | — | @@ -311,8 +322,12 @@ |
312 | 323 | $txt = date( $this->date, strtotime( $this->escapeTemplateParameter( $item[ $info ] ) ) ); |
313 | 324 | date_default_timezone_set( $tempTimezone ); |
314 | 325 | break; |
315 | | - default: |
316 | | - $txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) ); |
| 326 | + default: |
| 327 | + $str = $this->escapeTemplateParameter( $item[ $info ] ); |
| 328 | + if ( mb_strlen( $str ) > $this->ItemMaxLength ) { |
| 329 | + $str = mb_substr( $str, 0, $this->ItemMaxLength ) . " ..."; |
| 330 | + } |
| 331 | + $txt = $this->highlightTerms( $str ); |
317 | 332 | } |
318 | 333 | |
319 | 334 | $renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem ); |
Index: trunk/extensions/RSS/RSS.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | 'Rdb', 'Mafs', 'Alxndr', 'Thomas Gries', 'Chris Reigrut', |
28 | 28 | 'K001', 'Jack Phoenix', 'Jeroen De Dauw', 'Mark A. Hershberger' |
29 | 29 | ), |
30 | | - 'version' => '1.91 20120213', |
| 30 | + 'version' => '1.92 20120213', |
31 | 31 | 'url' => 'https://www.mediawiki.org/wiki/Extension:RSS', |
32 | 32 | 'descriptionmsg' => 'rss-desc', |
33 | 33 | ); |
— | — | @@ -68,3 +68,7 @@ |
69 | 69 | |
70 | 70 | // default date format of item publication dates see http://www.php.net/date |
71 | 71 | $wgRSSDateDefaultFormat = "(Y-m-d H:i:s)"; |
| 72 | + |
| 73 | +// limit the number of characters in the item description |
| 74 | +// or set to false for unlimited length. |
| 75 | +// $wgRSSItemMaxLength = 100; |