r94579 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94578‎ | r94579 | r94580 >
Date:21:52, 15 August 2011
Author:wikinaut
Status:ok (Comments)
Tags:
Comment:
new version RSS 1.90: streamlined template use, extended documentation; replaced parsing of each single channel subelement (item) by one final parser call when rendering
Modified paths:
  • /trunk/extensions/RSS/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/RSS/RSS.i18n.php (modified) (history)
  • /trunk/extensions/RSS/RSS.php (modified) (history)
  • /trunk/extensions/RSS/RSSParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RSS/RELEASE-NOTES
@@ -1,24 +1,70 @@
2 -Extension page on mediawiki.org: http://www.mediawiki.org/wiki/Extension:RSS
 2+RELEASE NOTES of the MediaWiki extension RSS
 3+http://www.mediawiki.org/wiki/Extension:RSS
34
4 -== Change Log ==
5 -*original by mutante 25.03.2005
6 -*extended by Duesentrieb 30.04.2005
7 -*extended by Rdb78 07.07.2005
8 -*extended by Mafs 10.07.2005, 24.07.2005
9 -*extended by Niffler 28.02.2006
10 -*modified by Dzag 07.2006
11 -*modified by Alxndr 09.2006
 5+=== TO DO ===
 6+* bug 30377 add a new parameter to limit the number of characters when rendering
 7+ the channel item <description>
 8+* set an upper default limit for HttpRequest request size when fetching feeds
 9+ doing a HEAD request first to ask for the size but that value may not be
 10+ available. Check how much data is returned as its coming back
 11+ in which case you'd override the content fetch callback and count data as it
 12+ comes in or check the header, again, if it's provided, at the start of data
 13+ coming in. Then you could abort cleanly once it's gotten too much
 14+ (otherwise using the defaults - PHP will abort the entire program when your
 15+ memory usage gets too high)
 16+* bug 30028 "Error parsing XML for RSS" - improve and harden Extension:RSS when
 17+ parsing differently flavoured RSS feeds
 18+
 19+=== Version 1.90 2011-08-15 ===
 20+* removed parsing of each single channel subelement (item)
 21+* only the finally constructed feed is sent to the recursive parser:
 22+ in pre-1.9 versions, each channel subelement (item) was sent to the parser
 23+* [[MediaWiki:Rss-item]] default has channel subelement <description> added
 24+* Rss template default name has been changed:
 25+
 26+ until 1.8: [[Template:RSSPost]]
 27+ 1.9: [[MediaWiki:Rss-feed]], an existing [[Template:RSSPost]]
 28+ takes precedence to be compatible to pre-1.9 versions
 29+* introducing [[MediaWiki:Rss-feed]] with a meaningful default.
 30+ The channel subelements which make the feed are rendered in this
 31+ new standard layout:
 32+ * <title>
 33+ : <description>
 34+ : <author> <date>
 35+* There are several ways to customize the final layout of feed items:
 36+ 1. Admins can change the [[MediaWiki:Rss-feed]] default page
 37+ 2. Users can use the optional template= parameter to tell the extension
 38+ to render the feed with a different layout
 39+ <rss template=Pagename>...</rss> use layout as in [[Template:Pagename]]
 40+ 3. <rss template=Namespace:Pagename>...</rss> use [[Namespace:Pagename]]
 41+
 42+=== Version 1.8 2010-10-19 ===
 43+* removed dependencies on Snoopy in favor of MediaWiki's internal HttpRequest
 44+* removed MagpieRSS (perhaps to be replaced later with SimplePie)
 45+ because of concerns about MagpieRSS's security problems and
 46+ lack of maintenance.
 47+* Added ability to do more with the layout of RSS feeds.
 48+
 49+=== Version 1.7 2010-07-23 ===
 50+* cleaned up, included MagpieRSS library
 51+* put into the WMF subversion repository by Jeroen De Dauw
 52+ http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw
 53+* i18n file added by TranslateWiki.net people
 54+
 55+== Change Log of pre-1.7 versions 2010 and before ==
 56+(latest on top)
 57+*modified by [[User:K001|K001]] 15:15, 26 January 2010 (UTC): version 1.6, added support for date formats
 58+*modified by Peter Newman: 03:15, 7 October 2009 (UTC) Added htmlspecialchars escaping to the displayed strings
 59+*modified by [[User:Cmreigrut|Cmreigrut]] 19:05, 19 November 2008 (UTC): added date (if specified) to short output
 60+*modified by --[[User:Wikinaut|Wikinaut]] 11:17, 7 May 2008 (UTC) : changed method to disable chaching; Extension is now compatible to MediaWiki 1.12
1261 *modified by Svanslyck 02.2008, replacing all « and » with "
1362 *<del>This has been updated to work better on newer (1.9) MediaWiki software, with the help of [[User:Duesentrieb]]. --[[User:CryptoQuick|CryptoQuick]] 14:26, 24 January 2007 (UTC)</del>
1463 **This appears not to be true; I have received numerous emails about it not working with 1.9+. I would love to help debug and fix the extension, but my host has not upgraded to PHP 5 and I'm thus stuck at MediaWiki 1.6.8, so that's as far as this is guaranteed to work properly. If anyone develops a fix, please post a link to it here! &#x2014;[[User:Alxndr|Alxndr]]&#x00a0;<sup>([[User talk:Alxndr|t]])</sup> 02:02, 16 June 2007 (UTC)
1564 ***I just found [http://nako.us/2007/03/16/mediawiki-19-fix-for-wfstrencode/ this fork] that purports to have a fix for the new loss of wfStrEncode(). I can't test it though so can anyone else verify that it works? &#x2014;[[User:Alxndr|Alxndr]]&#x00a0;<sup>([[User talk:Alxndr|t]])</sup> 02:18, 16 June 2007 (UTC)
16 -*modified by --[[User:Wikinaut|Wikinaut]] 11:17, 7 May 2008 (UTC) : changed method to disable chaching; Extension is now compatible to MediaWiki 1.12
17 -*modified by [[User:Cmreigrut|Cmreigrut]] 19:05, 19 November 2008 (UTC): added date (if specified) to short output
18 -*modified by Peter Newman: 03:15, 7 October 2009 (UTC) Added htmlspecialchars escaping to the displayed strings
19 -*modified by [[User:K001|K001]] 15:15, 26 January 2010 (UTC): version 1.6, added support for date formats
20 -
21 -=== Version 1.7 ===
22 -2010-7-23
23 -
24 -* Cleaned up, included MagpieRSS library and put onto the WMF subversion repository by Jeroen De Dauw - http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw
25 -* i18n file added by TranslateWiki.net people
\ No newline at end of file
 65+*modified by Alxndr 09.2006
 66+*modified by Dzag 07.2006
 67+*extended by Niffler 28.02.2006
 68+*extended by Mafs 10.07.2005, 24.07.2005
 69+*extended by Rdb78 07.07.2005
 70+*extended by Duesentrieb 30.04.2005
 71+*original by mutante 25.03.2005
Index: trunk/extensions/RSS/RSSParser.php
@@ -65,13 +65,42 @@
6666 $this->filterOut = self::explodeOnSpaces( $args['filterout'] );
6767 }
6868
 69+ // 'template' is the pagename of a user's itemTemplate including
 70+ // a further pagename for the feedTemplate
 71+ // In that way everything is handled via these two pages
 72+ // and no default pages or templates are used.
 73+
 74+ // 'templatename' is an optional pagename of a user's feedTemplate
 75+ // In that way it substitutes $1 (default: RSSPost) in MediaWiki:Rss-item
 76+
6977 if ( isset( $args['template'] ) ) {
70 - $titleObject = Title::newFromText( $args['template'], NS_TEMPLATE );
71 - $article = new Article( $titleObject, 0 );
72 - $this->itemTemplate = $article->fetchContent();
 78+ $itemTemplateTitleObject = Title::newFromText( $args['template'], NS_TEMPLATE );
 79+ $itemTemplateArticleObject = new Article( $itemTemplateTitleObject, 0 );
 80+ $this->itemTemplate = $itemTemplateArticleObject->fetchContent();
7381 } else {
74 - $templateName = isset( $args['templatename'] ) ? $args['templatename'] : 'RSSPost';
75 - $this->itemTemplate = wfMsgNoTrans( 'rss-item', $templateName );
 82+ if ( isset( $args['templatename'] ) ) {
 83+ $feedTemplatePagename = $args['templatename'];
 84+ } else {
 85+
 86+ // compatibility patch for rss extension
 87+
 88+ $feedTemplatePagename = 'RSSPost';
 89+ $feedTemplateTitleObject = Title::newFromText( $feedTemplatePagename, NS_TEMPLATE );
 90+
 91+ if ( !$feedTemplateTitleObject->exists() ) {
 92+ $feedTemplatePagename = Title::makeTitleSafe( NS_MEDIAWIKI, 'Rss-feed' );
 93+ }
 94+ }
 95+
 96+ // MediaWiki:Rss-item = {{ feedTemplatePagename | title = {{{title}}} | ... }}
 97+
 98+ // if the attribute parameter templatename= is not present
 99+ // then it defaults to
 100+ // {{ Template:RSSPost | title = {{{title}}} | ... }} - if Template:RSSPost exists from pre-1.9 versions
 101+ // {{ MediaWiki:Rss-feed | title = {{{title}}} | ... }} - otherwise
 102+
 103+ $this->itemTemplate = wfMsgNoTrans( 'rss-item', $feedTemplatePagename );
 104+
76105 }
77106 }
78107
@@ -213,8 +242,11 @@
214243 * @param $frame the frame param to pass to recursiveTagParse()
215244 */
216245 function renderFeed( $parser, $frame ) {
217 - $output = '';
218 - if ( isset( $this->itemTemplate ) ) {
 246+
 247+ $renderedFeed = '';
 248+
 249+ if ( isset( $this->itemTemplate ) && isset( $parser ) && isset( $frame ) ) {
 250+
219251 $headcnt = 0;
220252 if ( $this->reversed ) {
221253 $this->rss->items = array_reverse( $this->rss->items );
@@ -226,43 +258,48 @@
227259 }
228260
229261 if ( $this->canDisplay( $item ) ) {
230 - $output .= $this->renderItem( $item, $parser, $frame );
 262+ $renderedFeed .= $this->renderItem( $item ) . "\n";
231263 $headcnt++;
232264 }
233265 }
234 - }
235 - return $output;
 266+
 267+ $renderedFeed = $parser->recursiveTagParse( $renderedFeed, $frame );
 268+
 269+ }
 270+
 271+ return $renderedFeed;
236272 }
237273
238274 /**
239275 * Render each item, filtering it out if necessary, applying any highlighting.
240276 *
241 - * @param $item Array: an array produced by RSSData where keys are the
242 - * names of the RSS elements
243 - * @param $parser Parser the parser param to pass to recursiveTagParse()
244 - * @param $frame the frame param to pass to recursiveTagParse()
 277+ * @param $item Array: an array produced by RSSData where keys are the names of the RSS elements
245278 */
246 - protected function renderItem( $item, $parser, $frame ) {
247 - $output = "";
248 - if ( isset( $parser ) && isset( $frame ) ) {
249 - $rendered = $this->itemTemplate;
250 - // $info will only be an XML element name, so we're safe
251 - // using it. $item[$info] is handled by the XML parser --
252 - // and that means bad RSS with stuff like
253 - // <description><script>alert("hi")</script></description> will find its
254 - // rogue <script> tags neutered.
255 - foreach ( array_keys( $item ) as $info ) {
256 - if ( $info != 'link' ) {
257 - $txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) );
258 - } else {
259 - $txt = $this->sanitizeUrl( $item[ $info ] );
260 - }
261 - $rendered = str_replace( '{{{' . $info . '}}}', $txt, $rendered );
 279+ protected function renderItem( $item ) {
 280+
 281+ $renderedItem = $this->itemTemplate;
 282+
 283+ // $info will only be an XML element name, so we're safe using it.
 284+ // $item[$info] is handled by the XML parser --
 285+ // and that means bad RSS with stuff like
 286+ // <description><script>alert("hi")</script></description> will find its
 287+ // rogue <script> tags neutered.
 288+
 289+ foreach ( array_keys( $item ) as $info ) {
 290+ if ( $info != 'link' ) {
 291+ $txt = $this->highlightTerms( $this->escapeTemplateParameter( $item[ $info ] ) );
 292+ } else {
 293+ $txt = $this->sanitizeUrl( $item[ $info ] );
262294 }
 295+ $renderedItem = str_replace( '{{{' . $info . '}}}', $txt, $renderedItem );
 296+ }
263297
264 - $output = $parser->recursiveTagParse( $rendered, $frame );
265 - }
266 - return $output;
 298+ // nullify all remaining info items in the template
 299+ // without a corresponding info in the current feed item
 300+
 301+ $renderedItem = preg_replace( "!{{{[^}]+}}}!U", "", $renderedItem );
 302+
 303+ return $renderedItem;
267304 }
268305
269306 /**
Index: trunk/extensions/RSS/RSS.i18n.php
@@ -12,7 +12,7 @@
1313 * @author Łukasz Garczewski (TOR) <tor@wikia-inc.com>
1414 */
1515 $messages['en'] = array(
16 - 'rss-desc' => 'Displays an RSS feed on a wiki page',
 16+ 'rss-desc' => 'Displays RSS feeds on MediaWiki pages in a standard or in user-definable formats using template pages',
1717 'rss-error' => 'Failed to load RSS feed from $1: $2',
1818 'rss-empty' => 'Failed to load RSS feed from $1!',
1919 'rss-fetch-nourl' => 'Fetch called without a URL!',
@@ -20,9 +20,25 @@
2121 'rss-parse-error' => 'Error parsing XML for RSS',
2222 'rss-ns-permission' => 'RSS is not allowed in this namespace',
2323 'rss-url-permission' => 'This URL is not allowed to be included',
24 - 'rss-item' => '{{$1 | title = {{{title}}} | link = {{{link}}} | date = {{{date}}} | author = {{{author}}} }}',
 24+ 'rss-item' => '{{$1 | title = {{{title}}} | link = {{{link}}} | date = {{{date}}} | author = {{{author}}} | description = {{{description}}} }}',
 25+ 'rss-feed' => "<!-- the following are two alternative templates. The first is the basic default template for feeds -->; '''<span class='plainlinks'>[{{{link}}} {{{title}}}]</span>'''
 26+: {{{description}}}
 27+: {{{author}}} {{{date}}}<!-- don't use newline here --><!-- The second is an improved version which requires Extension:ParserFunctions --><!-- ; '''<span class='plainlinks'>[{{{link}}} {{{title}}}]</span>'''{{#if: {{{description|}}}|: {{{description}}}}}{{#if: {{{author|}}} | {{#if: {{{date|}}} |: &mdash; {{{author}}} {{{date}}}}} | {{#if: {{{author|}}}|: &mdash; {{{author}}}}} {{#if: {{{date|}}}|:{{{date}}}}}|}} -->",
2528 );
2629
 30+$messages['qqq'] = array(
 31+ 'rss-item' => "
 32+; $1
 33+: ''not to be localised''
 34+: The RSS extension substitutes this placeholder with the name of a template page. The content of this template page determines the final layout of the RSS feed on the rendered wiki page. The Extension:RSS currently uses 'MediaWiki:Rss-feed' as default for $1. This means that the content of [[MediaWiki:Rss-feed]] determines how RSS feed items are rendered.
 35+: It allows users to let RSS feeds rendered differently by using different (optional) 'template=<pagename>' parameters in the rss wiki tags.
 36+; title = {{{title}}} | link = {{{link}}} | ...
 37+: 'title' (left) is the variable name under which the content of an RSS feed field 'title' (right) is passed to the Template $1 where this is then used in the feed rendering.
 38+: This ''may'' be localised, but the content of the template $1 page (default [[MediaWiki:Rss-feed]] and potentially other RSS feed template pages on this wiki) needs then to be localised, too.
 39+: 'title' (right) is a name (property) of RSS feeds and is certainly not to be localised in any way.
 40+: ''I suggest not to localise anything.''",
 41+);
 42+
2743 /** Afrikaans (Afrikaans)
2844 * @author Naudefj
2945 */
Index: trunk/extensions/RSS/RSS.php
@@ -4,13 +4,13 @@
55 *
66 * @file
77 * @ingroup Extensions
8 - * @version 1.8
9 - * @author mutante, Daniel Kinzler, Rdb, Mafs, Alxndr, Chris Reigrut, K001
 8+ * @version 1.90
 9+ * @author mutante, Daniel Kinzler, Rdb, Mafs, Thomas Gries, Alxndr, Chris Reigrut, K001
1010 * @author Kellan Elliott-McCrea <kellan@protest.net> -- author of MagpieRSS
1111 * @author Jeroen De Dauw
1212 * @author Jack Phoenix <jack@countervandalism.net>
1313 * @copyright © Kellan Elliott-McCrea <kellan@protest.net>
14 - * @copyright © mutante, Daniel Kinzler, Rdb, Mafs, Alxndr, Chris Reigrut, K001
 14+ * @copyright © mutante, Daniel Kinzler, Rdb, Mafs, Thomas Gries, Alxndr, Chris Reigrut, K001
1515 * @link http://www.mediawiki.org/wiki/Extension:RSS Documentation
1616 */
1717
@@ -21,21 +21,11 @@
2222 // Extension credits that will show up on Special:Version
2323 $wgExtensionCredits['parserhook'][] = array(
2424 'name' => 'RSS feed',
25 - 'author' => array(
26 - 'Kellan Elliott-McCrea',
27 - 'mutante',
28 - 'Daniel Kinzler',
29 - 'Rdb',
30 - 'Mafs',
31 - 'Alxndr',
32 - 'Wikinaut',
33 - 'Chris Reigrut',
34 - 'K001',
35 - 'Jack Phoenix',
36 - 'Jeroen De Dauw',
37 - 'Mark A. Hershberger'
 25+ 'author' => array( 'Kellan Elliott-McCrea', 'mutante', 'Daniel Kinzler',
 26+ 'Rdb', 'Mafs', 'Alxndr', 'Thomas Gries', 'Chris Reigrut',
 27+ 'K001', 'Jack Phoenix', 'Jeroen De Dauw', 'Mark A. Hershberger'
3828 ),
39 - 'version' => '1.9',
 29+ 'version' => '1.90 20110815',
4030 'url' => 'http://www.mediawiki.org/wiki/Extension:RSS',
4131 'descriptionmsg' => 'rss-desc',
4232 );
@@ -49,16 +39,24 @@
5040
5141 $wgHooks['ParserFirstCallInit'][] = 'RSSHooks::parserInit';
5242
53 -$wgRSSCacheAge = 3600; // one hour
54 -$wgRSSCacheCompare = false; // Check cached content, if available, against remote.
55 - // $wgRSSCacheCompare should be set to false or a timeout
56 - // (less than $wgRSSCacheAge) after which a comparison will
57 - // be made.
58 -$wgRSSFetchTimeout = 5; // 5 second timeout
59 -$wgRSSNamespaces = null; // Ignore the RSS tag in all but the namespaces listed here.
60 - // null (the default) means the <rss> tag can be used
61 - // anywhere.
 43+ // one hour
 44+ $wgRSSCacheAge = 3600;
6245
 46+// Check cached content, if available, against remote.
 47+// $wgRSSCacheCompare should be set to false or a timeout
 48+// (less than $wgRSSCacheAge) after which a comparison will be made.
 49+$wgRSSCacheCompare = false;
 50+
 51+// 5 second timeout
 52+$wgRSSFetchTimeout = 5;
 53+
 54+// Ignore the RSS tag in all but the namespaces listed here.
 55+// null (the default) means the <rss> tag can be used anywhere.
 56+$wgRSSNamespaces = null;
 57+
 58+// URL whitelist of RSS Feeds:
 59+// if there are items in the array, and the used URL isn't in the array,
 60+// it will not be allowed (originally proposed in bug 27768)
6361 $wgRSSAllowedFeeds = array();
6462
6563 // Agent to use for fetching feeds

Sign-offs

UserFlagDate
MaxSeminspected11:56, 20 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r94603fix of a whitespace problem in the i18n system messagewikinaut06:59, 16 August 2011
r109650follow-up to r94579. Fixed white spaceswikinaut21:46, 20 January 2012

Comments

#Comment by Wikinaut (talk | contribs)   21:54, 15 August 2011

I did also layout changes, sorted items in the release notes "most recent on top" etc.

I have tried ("try harder!") to make code-reviewer happy; please bear with me, if some issues are not fully as you would like to have it.

#Comment by MaxSem (talk | contribs)   11:56, 20 January 2012

Looks OK except for some indentation problems: $feedTemplatePagename = 'RSSPost';, end of renderFeed().

#Comment by Wikinaut (talk | contribs)   21:47, 20 January 2012

white space problem fixed in r109650 .

#Comment by MaxSem (talk | contribs)   11:57, 20 January 2012

Are there parser tests, by the way?

#Comment by Reedy (talk | contribs)   19:53, 27 January 2012

Quick test of the extension seems alright

Status & tagging log