MediawikiExtensions/RSS

Integrate RSS newsfeeds into wiki pages using magpie RSS parser in a custom Mediawiki extension:

(For example to interwiki syndicate RecentChanges pages.)

mutante 21:35, 25 Mar 2005 (CET)

Syntax
URL

Example
http://www.heise.de/newsticker/heise.rdf

http://slashdot.org/slashdot.rss

Result
http://slashdot.org/slashdot.rss

FFII News feed test
http://linuxfr.org/backend/news/rss20.rss

Linux ml
http://rss.gmane.org/messages/excerpts/gmane.linux.kernel

Source
setHook( "rss", "renderRss" ); }
 * 1) set hook (trigger) to rss, means will be made active tag

function renderRss( $input ) {
 * 1) the actual function (taking input)


 * 1) maybe its a good idea to escape string user input so they dont try to attach nasty things
 * 2) $input = mysql_escape_string($input);

$rss = fetch_rss($input);
 * 1) fetch the feed (magpie's job)

$link=$rss->channel['link']; $title=$rss->channel['title']; $cdesc=$rss->channel['description'];
 * 1) setting variables for table head


 * 1) putting the html table head into the output variable

$output=" ";

return $output;
 * 1) dump the output all at once

}

?>

Extended version by Duesentrieb
This is an extended version of the RSS-feed extension by mutante (http://meta.wikimedia.org/wiki/User:mutante/RSSFeed). It's main features are charset conversion, nicer formating and output of the full description text of the news items. It also introduces a syntax for controlling those features.

setHook( "rss", "renderRss" ); } function renderRss( $input ) { global $wgOutputEncoding; # $input = mysql_escape_string($input); if (!$input) return ""; #if -section is empty, return nothing #parse fields in rss-section $fields= explode("|",$input); $url= @$fields[0]; $args= array; for ($i=1; $i<sizeof($fields); $i++) { $f= $fields[$i]; if (strpos($f,"=")===False) $args[strtolower(trim($f))]= True; else { list($k,$v)= explode("=",$f,2); $args[strtolower(trim($k))]= trim($v); }   }    #get charset from argument-array $charset= @$args["charset"]; if (!$charset) $charset= $wgOutputEncoding; #get short-flag from argument-array #if short is set, no description text is printed $short= @$args["short"]; #fetch rss. may be cached locally. #Refer to the documentation of magpie for details. $rss = @fetch_rss($url); #check for errors. if ($rss->ERROR) { return " Failed to load RSS feed from $url: ".$rss->ERROR." "; #localize... }   if (!is_array($rss->items)) { return " Failed to load RSS feed from $url! "; #localize... }   #Bild title line $title= iconv($charset,$wgOutputEncoding,$rss->channel['title']); if ($rss->channel['link']) $title= "channel['link']."'>$title"; $output=" $title "; #Bild items if ($short) { #short item list $output.=""; foreach ($rss->items as $item) { $href = trim(iconv($charset,$wgOutputEncoding,$item['link'])); $title = trim(iconv($charset,$wgOutputEncoding,$item['title'])); $output.="$title"; }       $output.=""; }   else { #full item list $output.=""; foreach ($rss->items as $item) { $href = trim(iconv($charset,$wgOutputEncoding,$item['link'])); $title = trim(iconv($charset,$wgOutputEncoding,$item['title'])); #bild description text if desired if ($item["description"]) { $text= trim(iconv($charset,$wgOutputEncoding,$item['description'])); #avoid pre-tags $text= str_replace("\r"," ",$text); $text= str_replace("\n"," ",$text); $text= str_replace("\t"," ",$text); }               else $text = ""; $output.="$title"; if ($text) $output.="$text</dd>\n"; }       $output.="</dl>"; }   return $output; } ?>
 * 1) RSS-Feed Mediawiki extension
 * 1) original by mutante 25.03.2005
 * 2) extended by Duesentrieb 30.04.2005
 * 1) Requires:
 * 2)  * magpie rss parser <http://magpierss.sourceforge.net/>
 * 3)  * iconv <http://www.gnu.org/software/libiconv/>, see also <http://www.php.net/iconv>
 * 1) Installation:
 * 2)  * put this file (rss.php) into the extension directory of your mediawiki installation
 * 3)  * add the following to the end of LocalSettings.php: include("extensions/rss.php");
 * 4)  * make sure magpie can be found by PHP.
 * 1) Usage:
 * 2)  Use one section between -tags for each feed. The ress section may contain parameters
 * 3)  separated by a pipe ("|"), just like links and templates. Two parameters are supported:
 * 4)    * charset=...   the charset used by the feed. iconv is used to convert this.
 * 5)    * short         do not show the description text for each news item.
 * 1) Example:
 * 2)    http://slashdot.org/slashdot.rss|charset=UTF-8|short
 * 1) change this according to your magpie installation!
 * 1) install extension hook
 * 1) extension hook callback function
 * 1) parser hook callback function

from: http://meta.wikimedia.org/wiki/User:Duesentrieb/RSS