Update RSS to add the ability to restrict per-namespace.

This commit is contained in:
Mark A. Hershberger 2011-05-06 16:21:43 +00:00
parent 721dc2c237
commit 518d4b7a17
3 changed files with 19 additions and 6 deletions

View file

@ -18,6 +18,7 @@ $messages['en'] = array(
'rss-fetch-nourl' => 'Fetch called without a URL!',
'rss-invalid-url' => 'Not a valid URL: $1',
'rss-parse-error' => 'Error parsing XML for RSS',
'rss-ns-permission' => 'RSS is not allowed in this namespace',
'rss-item' => '{{RSSPost | title = {{{title}}} | link = {{{link}}} | date = {{{date}}} | author = {{{author}}} }}',
);

13
RSS.php
View file

@ -51,13 +51,16 @@ $wgHooks['ParserFirstCallInit'][] = 'RSSHooks::parserInit';
$wgRSSCacheAge = 3600; // one hour
$wgRSSCacheCompare = false; // Check cached content, if available, against remote.
// $wgRSSCacheCompare should be set to false or a timeout
// (less than $wgRSSCacheAge) after which a comparison will
// be made.
$wgRSSFetchTimeout = 5; // 5 second timeout
// $wgRSSCacheCompare should be set to false or a timeout
// (less than $wgRSSCacheAge) after which a comparison will
// be made.
$wgRSSFetchTimeout = 5; // 5 second timeout
$wgRSSNamespaces = null; // Ignore the RSS tag in all but the namespaces listed here.
// null (the default) means the <rss> tag can be used
// anywhere.
// Agent to use for fetching feeds
$wgRSSUserAgent = 'MediaWikiRSS/0.01 (+http://www.mediawiki.org/wiki/Extension:RSS) / MediaWiki RSS extension';
$wgRSSUserAgent = 'MediaWikiRSS/0.02 (+http://www.mediawiki.org/wiki/Extension:RSS) / MediaWiki RSS extension';
// Proxy server to use for fetching feeds
$wgRSSProxy = false;

View file

@ -20,7 +20,16 @@ class RSSHooks {
* @param $frame Frame parser context
*/
static function renderRss( $input, $args, $parser, $frame ) {
global $wgRSSCacheAge, $wgRSSCacheCompare;
global $wgRSSCacheAge, $wgRSSCacheCompare, $wgRSSNamespaces;
if ( $wgRSSNamespaces !== null && is_array($wgRSSNamespaces) ) {
$ns = $parser->getTitle()->getNamespace();
$checkNS = array_flip($wgRSSNamespaces);
if( !isset( $checkNS[$ns] ) ) {
return wfMsg( 'rss-ns-permission' );
}
}
if ( !Http::isValidURI( $input ) ) {
return wfMsg( 'rss-invalid-url', htmlspecialchars( $input ) );