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 and thus is used by the wiki users. 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


 * $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. 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:  http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml  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:  http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml  will refresh the cach 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, alligned to the right, of the width specified (in pixels)

Installing
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) Create a file called RSSReader.php in your new folder
 * 4) Copy and paste the RSSReader.php code into your new file
 * 5) Create a file called RSSReader.css in your new folder
 * 6) Copy and paste the RSSReader.css code into your new file
 * 7) Create a folder called cache in your RSSReader folder
 * 8) In LocalSettings.php, add the following line:
 * 9) Modify RSSReader.css to your liking to better fit your skin

RSSReader.php
"; } //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).

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.

Errors and Fixes
Here are some errors that have been encountered and how to fix them.

Warning: Cannot modify header information
This bug happens when there is extra whitespace at the end of a file (most commonly lastRSS.php). Make sure there are no trailing spaces or linebreaks after the closing php tag (?>).

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.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
 * 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