2010-11-04 23:19:00 +00:00
|
|
|
<?php
|
2010-11-05 00:59:28 +00:00
|
|
|
|
2010-11-04 23:19:00 +00:00
|
|
|
class RSSHooks {
|
|
|
|
/**
|
|
|
|
* Tell the parser how to handle <rss> elements
|
2011-01-08 01:33:42 +00:00
|
|
|
* @param $parser Parser Object
|
2010-11-04 23:19:00 +00:00
|
|
|
*/
|
|
|
|
static function parserInit( $parser ) {
|
|
|
|
# Install parser hook for <rss> tags
|
|
|
|
$parser->setHook( 'rss', array( __CLASS__, 'renderRss' ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static function wrapping RSSParser to handle rendering of RSS elements
|
2010-11-05 00:59:28 +00:00
|
|
|
* @param $input String: text inside the tags.
|
|
|
|
* @param $args Array: value associative list of the element attributes and
|
|
|
|
* their values.
|
2011-01-08 01:33:42 +00:00
|
|
|
* @param $parser Parser
|
2012-01-28 17:05:20 +00:00
|
|
|
* @param $frame PPFrame parser context
|
2010-11-04 23:19:00 +00:00
|
|
|
*/
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
static function renderRss( $input, $args, $parser, $frame ) {
|
|
|
|
global $wgRSSCacheAge, $wgRSSCacheCompare, $wgRSSNamespaces, $wgRSSAllowedFeeds;
|
2011-05-06 16:21:43 +00:00
|
|
|
|
2011-05-06 16:40:14 +00:00
|
|
|
if ( is_array( $wgRSSNamespaces ) && count( $wgRSSNamespaces ) ) {
|
2011-05-06 16:21:43 +00:00
|
|
|
$ns = $parser->getTitle()->getNamespace();
|
2011-05-06 16:40:14 +00:00
|
|
|
$checkNS = array_flip( $wgRSSNamespaces );
|
2011-05-06 16:21:43 +00:00
|
|
|
|
|
|
|
if( !isset( $checkNS[$ns] ) ) {
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
return wfMsg( 'rss-ns-permission' );
|
2011-05-06 16:21:43 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-04 23:19:00 +00:00
|
|
|
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
if ( count( $wgRSSAllowedFeeds ) && !in_array( $input, $wgRSSAllowedFeeds ) ) {
|
|
|
|
return wfMsg( 'rss-url-permission' );
|
2012-02-23 21:12:54 +00:00
|
|
|
}
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
|
2010-11-13 19:11:28 +00:00
|
|
|
if ( !Http::isValidURI( $input ) ) {
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
return wfMsg( 'rss-invalid-url', htmlspecialchars( $input ) );
|
2010-11-04 23:19:00 +00:00
|
|
|
}
|
|
|
|
if ( $wgRSSCacheCompare ) {
|
|
|
|
$timeout = $wgRSSCacheCompare;
|
|
|
|
} else {
|
|
|
|
$timeout = $wgRSSCacheAge;
|
|
|
|
}
|
2010-11-16 22:06:59 +00:00
|
|
|
|
2010-11-15 23:47:12 +00:00
|
|
|
$parser->getOutput()->updateCacheExpiry( $timeout );
|
2010-11-04 23:19:00 +00:00
|
|
|
|
|
|
|
$rss = new RSSParser( $input, $args );
|
|
|
|
|
|
|
|
$status = $rss->fetch();
|
|
|
|
|
|
|
|
# Check for errors.
|
2010-11-05 00:59:28 +00:00
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
return wfMsg( 'rss-error', htmlspecialchars( $input ), $status->getWikiText() );
|
|
|
|
}
|
2010-11-04 23:19:00 +00:00
|
|
|
|
2010-11-05 00:59:28 +00:00
|
|
|
if ( !is_object( $rss->rss ) || !is_array( $rss->rss->items ) ) {
|
Revert r111347, r111348, r111350, r111351, r111515, r111816, r112243, r112251, r112308, r112314, r112315, r112465, r112467, r112709, r113297, r113508, r113510, r113524, r113546, r114168. Unreviewed revisions in the RSS extension and their dependencies.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 18:40:06 +00:00
|
|
|
return wfMsg( 'rss-empty', htmlspecialchars( $input ) );
|
2010-11-05 00:59:28 +00:00
|
|
|
}
|
2010-11-04 23:19:00 +00:00
|
|
|
|
|
|
|
return $rss->renderFeed( $parser, $frame );
|
|
|
|
}
|
|
|
|
}
|