MediawikiExtensions/RSS

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

(For example to interwiki syndicate RecentChanges pages like on the recent near changes.)

mutante 21:35, 25 Mar 2005 (CET)

Syntax
URL

Example
http://slashdot.org/slashdot.rss

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

del.icio.us UTF-8 test
http://del.icio.us/rss/krcla/%EC%84%A0%EA%B1%B0

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.


 * 6)  * iconv , see also 
 * 7) Installation:
 * 8)  * put this file (rss.php) into the extension directory of your mediawiki installation
 * 9)  * add the following to the end of LocalSettings.php: include("extensions/rss.php");
 * 10)  * make sure magpie can be found by PHP.
 * 11) Usage:
 * 12)  Use one section between -tags for each feed. The ress section may contain parameters
 * 13)  separated by a pipe ("|"), just like links and templates. Two parameters are supported:
 * 14)    * charset=...   the charset used by the feed. iconv is used to convert this.
 * 15)    * short         do not show the description text for each news item.
 * 16) Example:
 * 17)    http://slashdot.org/slashdot.rss|charset=UTF-8|short
 * 1)    * charset=...   the charset used by the feed. iconv is used to convert this.
 * 2)    * short         do not show the description text for each news item.
 * 3) Example:
 * 4)    http://slashdot.org/slashdot.rss|charset=UTF-8|short
 * 1)    http://slashdot.org/slashdot.rss|charset=UTF-8|short

require_once('magpierss-0.71.1/rss_fetch.inc');
 * 1) change this according to your magpie installation!

$wgExtensionFunctions[] = "wfRssExtension";
 * 1) install extension hook

function wfRssExtension { global $wgParser; #install parser hook for tags $wgParser->setHook( "rss", "renderRss" ); } function renderRss( $input ) { global $wgOutputEncoding;
 * 1) extension hook callback function
 * 1) parser hook callback function

# $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</dt>"; if ($text) $output.="<dd>$text</dd>\n"; }      $output.="</dl>"; }  return $output; }

?>

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