r87546 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87545‎ | r87546 | r87547 >
Date:16:21, 6 May 2011
Author:mah
Status:resolved (Comments)
Tags:
Comment:
Update RSS to add the ability to restrict per-namespace.
Modified paths:
  • /trunk/extensions/RSS/RSS.i18n.php (modified) (history)
  • /trunk/extensions/RSS/RSS.php (modified) (history)
  • /trunk/extensions/RSS/RSSHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RSS/RSSHooks.php
@@ -20,8 +20,17 @@
2121 * @param $frame Frame parser context
2222 */
2323 static function renderRss( $input, $args, $parser, $frame ) {
24 - global $wgRSSCacheAge, $wgRSSCacheCompare;
 24+ global $wgRSSCacheAge, $wgRSSCacheCompare, $wgRSSNamespaces;
2525
 26+ if ( $wgRSSNamespaces !== null && is_array($wgRSSNamespaces) ) {
 27+ $ns = $parser->getTitle()->getNamespace();
 28+ $checkNS = array_flip($wgRSSNamespaces);
 29+
 30+ if( !isset( $checkNS[$ns] ) ) {
 31+ return wfMsg( 'rss-ns-permission' );
 32+ }
 33+ }
 34+
2635 if ( !Http::isValidURI( $input ) ) {
2736 return wfMsg( 'rss-invalid-url', htmlspecialchars( $input ) );
2837 }
Index: trunk/extensions/RSS/RSS.i18n.php
@@ -18,6 +18,7 @@
1919 'rss-fetch-nourl' => 'Fetch called without a URL!',
2020 'rss-invalid-url' => 'Not a valid URL: $1',
2121 'rss-parse-error' => 'Error parsing XML for RSS',
 22+ 'rss-ns-permission' => 'RSS is not allowed in this namespace',
2223 'rss-item' => '{{RSSPost | title = {{{title}}} | link = {{{link}}} | date = {{{date}}} | author = {{{author}}} }}',
2324 );
2425
Index: trunk/extensions/RSS/RSS.php
@@ -51,13 +51,16 @@
5252
5353 $wgRSSCacheAge = 3600; // one hour
5454 $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
 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.
5962
6063 // Agent to use for fetching feeds
61 -$wgRSSUserAgent = 'MediaWikiRSS/0.01 (+http://www.mediawiki.org/wiki/Extension:RSS) / MediaWiki RSS extension';
 64+$wgRSSUserAgent = 'MediaWikiRSS/0.02 (+http://www.mediawiki.org/wiki/Extension:RSS) / MediaWiki RSS extension';
6265
6366 // Proxy server to use for fetching feeds
6467 $wgRSSProxy = false;

Comments

#Comment by 😂 (talk | contribs)   17:46, 6 May 2011

Rather than array_flip()ing and isset()ing, why not just use in_array()?

#Comment by MarkAHershberger (talk | contribs)   18:59, 6 May 2011

because "in_array() is slow" and I wanted to avoid it. I didn't test how slow it was compared to what I did, though.

#Comment by 😂 (talk | contribs)   19:13, 6 May 2011

You're thinking array_key_exists(). In any case, this isn't working as we discussed on IRC :)

#Comment by Catrope (talk | contribs)   14:10, 20 August 2011
+		if ( $wgRSSNamespaces !== null && is_array($wgRSSNamespaces) ) {

This is redundant, is_array(null) is false.

Did any follow-up come out of that IRC discussion? Provisionally marking fixme for the array_flip() weirdness and Chad's claim that it "isn't working".

Status & tagging log