Extension:RSS Reader

This RSS Reader extension tries to provide a tool for including RSS feeds inside various articles across your wiki. It is best used on specialty pages made so that users can easily track the news, etc. This extension was made because all the other RSS extensions did not work or performed poorly on MediaWiki 1.10.

Usage
This extension is a parser extension which can be used by any wiki user. The function adds an   tag to use inside articles. Some modification of its behaviour is possible from LocalSettings.php as well.

LocalSettings.php
All the global variables used by the extension and modifiable by the user are listed here. If you modify these variables do so after the require_once statement:
 * $egCache
 * The boolean value that determines if caching should be done or not ; enabled by default, although distributions possibly need to disable this by default or change egCacheDir.


 * $egCacheDir
 * The path where parsed feeds are cached if egCache is enabled; it must obviously be writable to the www-data user.


 * $egCacheTime
 * The default amount of time (in seconds) between cachings of a feed. By default it is set to 3600 (1 hour). If a user does not specify a time argument or their argument is somehow corrupt, this value will be used.


 * $egCacheTimeMin
 * The minimum amount of time (in seconds) between cachings of a feed. By default it is set to 1800 (30 minutes). This is the most often a user can ask a feed to be refetched. Settings this time too low on busy servers might eat up a lot of server resources


 * $egCacheTimeMax
 * The maximum amount of time (in seconds) between cachings of a feed. By default it is set to 7200 (2 hours). This is the least often a user can ask a feed to be refetched.


 * $egNoFollow
 * Determines if all links created by the extension should have the  attribute. Default value is , if set to   then the   attribute will be added. Keep in mind, that some popular search engines (Yahoo! and Ask, for instance) will still follow, index and rank the links.


 * $egWidthMin
 * The minimum size (in pixels) of the width to which the size of a floating RSSbar can be set.


 * $egWidthMax
 * The maximum size (in pixels) of the width to which the size of a floating RSSbar can be set.

The tag
The custom tag is called  . For instance, if you put  http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml  then you will create a feed to BBC World news.


 * multiple feeds
 * You can add more than one feed in a single   tag to have them display in columns. Do so by adding "|" between the feed urls. Thus,  firsturl|secondurl|thirdurl  will create a reader with 3 columns, displaying items from all 3 feeds. Inside the   tag you can include optional settings, which are detailed below:


 * number
 * By default, the reader will display all the items in the feed. If you want to display upto a maximum of a certain number of items, then add number=n (where n is the max number) inside the rss tag: will display the last 10 stories from BBC World.

The max and min time allowed for the time argument is governed by $egCacheTimeMin and $egCacheTimeMax in LocalSettings.php. If the specified time falls outside this range, then it will revert to the default $egCacheTime value.
 * time
 * By default, the reader will take the value of $egCacheTime as the amount of time (in seconds) between each local caching of the RSS feed. If you want a certain feed to refresh its cache more or less frequently, then add time=t (where t is the refresh time in seconds) inside the rss tag: will refresh the cache of stories from BBC World every 7200 seconds (2 hours).


 * desc=off
 * Hides the description provided by the feed.


 * width
 * If set to a legal value (between $egWidthMin and $egWidthMax) it turns the RSS section into a floating div, aligned to the right, of the width specified (in pixels)


 * title=off
 * Hides the title (and description in ) of the feed.


 * text
 * By default, the reader will display the items as a bullet list of title links, but often the desired format is for each item to contain the description text. Add the "text" parameter to render the items in a div tag of class "rss", for example: See Home for an example of this format, the CSS rules used in this example are shown in the CSS section below.

Pre-Requisites
Ensure you have php_curl installed and configured.

Download the copy of the win32 PHP (not the installer one) from php.net (whichever php version that you want running on your webserver). Then from dll folder, copy these two files: libeay32.dll and ssleay32.dll to your Windows/System32 (whichever Windows you have).

Then from the extensions folder: get your php_curl.dll and place it under your PHP/extensions folder.

Change your php.ini where it specifies the extension folder for example: extension_dir = "./extensions/"

And uncomment your extension to php_curl.dll for example: extension=php_curl.dll

Install
If you want to install RSS Reader to use database-centric caching instead of file-centric caching, refer to alternative RSS parser below.
 * 1) Create a folder called RSSReader in your extensions directory
 * 2) Download the lastRSScode and save it in your newly created folder as lastRSS.php
 * 3) Patch lastRSS.php with this patch
 * 4) Create a file called RSSReader.php in your new folder
 * 5) Copy and paste the RSSReader.php code into your new file
 * 6) Create a file called RSSReader.css in your new folder
 * 7) Copy and paste the RSSReader.css code into your new file
 * 8) Create a folder called cache in your RSSReader folder and set write permission on it
 * 9) In LocalSettings.php, add the following line:
 * 10) Modify RSSReader.css to your liking to better fit your skin

RSSReader.php
Create a folder called RSSReader. Inside this folder create the file: RSSReader.php tag that allows to display one or more RSS feeds on a page', 'url' => 'https://www.mediawiki.org/wiki/Extension:RSS_Reader' );

//path to follow for server scripts $egRSSReaderPath = $wgScriptPath."/extensions/RSSReader"; $egCacheTime     = 3600; //default cache time in seconds $egCacheTimeMin  = 1800; //minimum cache time in seconds $egCacheTimeMax  = 7200; //maximum cache time in seconds $egCache         = true; //boolean to determine if caching should be done $egCacheDir      = dirname( __FILE__ ).'/cache/'; //directory of cache //boolean to determine if links created should have rel="nofollow" $egNoFollow      = false; $egWidthMin      = 200;  //minimim width in pixels $egWidthMax      = 800;  //maximum width in pixels
 * 1) Global Variables ###

/** * select if cURLRSS or wikiRSS or lastRSS should be loaded * set rssType to the proper object type * each object of rssType must have the same interface */ if (file_exists(dirname(__FILE__)."/cURLRSS.php")){ require_once(dirname(__FILE__)."/cURLRSS.php"); //loads cURLRSS.php $rssType = new cURLRSS; //set rssType to cURLRSS } else if (file_exists(dirname( __FILE__ )."/wikiRSS.php")) { require_once(dirname( __FILE__ )."/wikiRSS.php"); //loads wikiRSS.php $rssType = new wikiRSS; //set rssType to wikiRSS } else if (file_exists(dirname( __FILE__ )."/lastRSS.php")) { require_once(dirname( __FILE__ )."/lastRSS.php"); //loads lastRSS.php $rssType = new lastRSS; //set rssType to lastRSS } else { trigger_error("RSSReader is not properly set-up:".   "need cURLRSS, wikiRSS or lastRSS"); }

function efRSSReader { global $wgParser; $wgParser->setHook( 'rss', 'efCreateRSSReader' ); }

function efCreateRSSReader($input, $argv, $parser){ global $wgOut, $egRSSReaderPath, $egCacheTime, $egCacheTimeMin, $egCacheDir, $wgRSSReaderExtVersion, $egCacheTimeMax, $egCache, $rssType, $egNoFollow, $egWidthMin, $egWidthMax;

// initialise args incase PHP set to strict foreach (array('number', 'width', 'title', 'time', 'desc') as $k) if (!isset($argv[$k])) $argv[$k] = false;

//disable cache so feed is fetched everytime page is visited $parser->disableCache; if (!$input){ //if no input do nothing } else { $fields = explode("|",$input); //get the urls between the tags

/*    * Check if a "number=n" argument has been provided * if it has and is an int, then set the $number field to the proper * value else set $number field to zero (which means "all available") */   if (!$argv["number"]){ //check if argument has been provided $number=0; //set default if no argument has been provided } else { //check if argument is an integer if ((int)$argv["number"]."" == $argv["number"]) { $number = $argv["number"]; //set $number field } else { $number=0; //if not an integer, then set default }   }

/*    * Check if a "width=n" argument has been provided * if it has and is an int, then set the $width field to the proper * value else set $width field to zero (which means "no width") */   if (!$argv["width"]){ //check if argument has been provided $width=0; //set default if no argument has been provided } else { //check if argument is an integer if ((int)$argv["width"]."" == $argv["width"]) { if (($argv["width"]>=$egWidthMin)&&($argv["width"]<=$egWidthMax)) { $width = $argv["width"]; //set $width field } else $width = 0; //if out of range, then set default } else { $width=0; //if not an integer, then set default }   }

/*    * Check if a "time=n" argument has been provided * if it has and is between $egCacheTimeMin and $egCacheTimeMax * then set $cacheTime to the value * else set $cacheTime to $egCacheTime (the default CacheTime) */   if (!$argv["time"]){ //check if argument has been provided //set default if no argument has been provided $cacheTime = $egCacheTime; } else { //check if argument is an integer if ((int)$argv["time"]."" == $argv["time"]) { //check if argument is in range if (($argv["time"]>=$egCacheTimeMin)         &&($argv["time"]<=$egCacheTimeMax)) { $cacheTime = $argv["time"]; //set $cacheTime field } else { //set default if argument is outside range $cacheTime = $egCacheTime; }     } else { $cacheTime=$egCacheTime; //set default if not an integer }   }

/* Check if a "desc=off" parameter has been provided and set desc */ $desc = true; //set the default if ($argv["desc"]){ //check if argument has been provided if ($argv["desc"]=="off") $desc = false; }

/* Check if "title=off" parameter was provided and set dispTitle */ $dispTitle = true; //set the default if ($argv["title"]){ //check if argument has been provided if ($argv["title"]=="off") $dispTitle = false; }

$wgOut->addLink(array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => "$egRSSReaderPath/RSSReader.css?$wgRSSReaderExtVersion", ));

if (!$width) { $output = ' "; } //close main "else"  return $output; }

Alternative RSS Parser
If you do not want to (or can't) use files for caching, then an alternative to lastRSS exists. The alternative, wikiRSS, is not recomended since benchmarks have shown it to be upto three times slower (not a super big deal since both are fast, but still a concern).

If you server does not, then you can not run lastRSS. An alternative exists, cURLRSS, this uses the cURL library (which you need to be configured already) instead of. This is the perfect solution for DreamHost users.

Possible Issues
The error checking in this extension has improved substantially since its first version, but the code is still far from foolproof. Therefore, it is possible to run into a number of issues or errors that you would have to fix yourself or report in the discussion section of this article. Some issues that you might run into are listed below.

Different Directory
If you do not install this code in $IP/extensions/RSSReader/ then there could be some issues. If the RSSReader.css file is not placed in $IP/extensions/RSSReader/ then you should add a new remote path name to LocalSettings.php. For reference, the default value is: Do not forget the $wgScriptPath at the start of the path.

RSSReader.php and lastRSS.php have fewer restrictions on them than RSSReader.css. The only thing you need to ensure is that the two files are in the same directory, and RSSReader.php is properly referenced in LocalSettings.php.

PHP support for allow_url_fopen
Both  and   require that your version of PHP include support for. You'll get an error like Error: It's not possible to get http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml if your PHP is missing this option. (Run  to get information about your PHP binary.) Some managed hosting services have this option turned off by default, for security reasons.

Warnings

 * This extension turns off parser caching for all the pages on which the   tag is present. This could result in server strain if rss tags are present on many high traffic pages.

Acknowledgement

 * lastRSS.php was not written by the author of this extension. lastRSS.php was written by Vojtech Semecky and licensed under GPL. If you want more information about lastRSS.php check its site

0.2.6

 * Update from Debian src:mediawiki-extensions 2.11 upload
 * Fixes a remotely exploitable user security hole wrt. HTML in feed titles and bodies (CVE-2012-6453)
 * Add $egCacheDir parameter, to allow people to point it to a writable directory to avoid having to disable $egCache when ./ is not writable to www-data (in Debian, we disable egCache by default; here on the Wiki page, it is enabled by default in the source code)
 * Fix installation path
 * Fix rendering path to CSS
 * Fix id="RSSMainBody" being used multiple times by making it into a CSS class that can be used for styling RSS output instead
 * Fix XHTML/1.0 Transitional validity of output
 * Fix a bunch of PHP warnings
 * Stop using  and sanitise RSS bodies correctly

0.2.5

 * Added a parameter called "text" which allows rendering of items in a div element of class "rss" which contains the item's description text (added by User:Nad).

0.2.4

 * Allowed user to hide title area
 * added new "title" attribute inside tag
 * Modified code formating a little
 * Added recognition of cURLRSS

0.2.3

 * Gave more flexible control of placement and size of the RSS feed
 * added new "width" attribute inside tag
 * added new global variables $egWidthMin and $egWidthMax to govern the allowed values for width
 * Improved the data in $wgExtensionCredits

0.2.2

 * Added $egNoFollow global variable to determine if rel="nofollow" should be added to all links
 * Added a "desc=off" option when placing RSSReader on page

0.2.1

 * Added recognition if wikiRSS or lastRSS is present
 * Added dynamic object loading (wikiRSS or lastRSS)
 * Added $egCache global variable to determine if caching should be done
 * Moved object initialization outside of fields for loop
 * Fixed an error in the error output to show the url
 * Improvement to comments and white space placing

0.2

 * Added license
 * Decoupled HTML and CSS (creating a seperate file for the CSS)
 * Gave more flexible control over time between cache
 * added new "time" attribute inside tag
 * Improved commenting in code
 * Improved error checking

Future Improvements

 * Expand on error checking
 * Provide more options for the user both inside the article and from LocalSettings.php
 * Provide more skinning options with CSS
 * Allow users to view an entry summary along with title
 * Add some fancy looking JavaScript
 * Allow parser functions along with tags
 * Allow users to pass a template to format the output

See other
Alternate extensions:
 * http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/rss/ broken
 * Extension:RSS
 * More: Category:RSS extensions