I was looking for a MediaWiki extension that could read RSS feeds and output them onto the page. The trouble was, the extensions I found either didn’t work, or were very uncustomisable. For example, for one that actually worked, adding this to the wiki page:
<feed>http://jonnylamb.com/feed/</feed>
forced this output on me:
<h3><a href="http://jonnylamb.com/2007/03/22/minimo-bongo/">Minimo Bongo</a></h3> <small>22 March 2007, by jonnylamb</small> <h3><a href="http://jonnylamb.com/2007/03/22/durham-visit/">Durham Visit</a></h3> <small>22 March 2007, by jonnylamb</small> <h3><a href="http://jonnylamb.com/2007/03/22/musically-active/">Musically Active</a></h3> <small>22 March 2007, by jonnylamb</small> <h3><a href="http://jonnylamb.com/2007/03/05/age/">++age</a></h3> <small>5 March 2007, by jonnylamb</small>
This is not ideal. Instead of looking further for a better extension, I wrote one. It is called SimpleFeed and it lives on the Extension:SimpleFeed page on mediawiki.org.
It is simple for two reasons:
Here is a quick tour on how to use it:
Once it is installed, one can choose the syntax each item is outputted in. For example:
<feed url="http://jonnylamb.com/feed/">
== [{PERMALINK} {TITLE}] ==
{DATE} by {AUTHOR}
{DESCRIPTION}
</feed>
For each item from the feed, the curly-bracketed words get replaced with their corresponding values. Note the use of wiki-markup as this is then parsed by the MediaWiki parser, producing something like this:
<a name="Minimo_Bongo"></a><h2> <span class="mw-headline"> <a href="http://jonnylamb.com/2007/03/22/minimo-bongo/" class="external text" title="http://jonnylamb.com/2007/03/22/minimo-bongo/" rel="nofollow">Minimo Bongo</a> </span></h2> <p>22 March 2007 by jonnylamb </p> <p>I shoved [...]
So of course there’s a whole load of MediaWiki stuff added which makes it integrate into the wiki much better, and the killer feature is the customisation possible!
There’s more information on its mediawiki.org page: http://www.mediawiki.org/wiki/Extension:SimpleFeed.
April 3rd, 2007 at 7:54 pm
Hi,
Nice work. Unfortunately I have some trouble using this with sections to generate a table of contents. For example:
== First Feed ==
=== [{PERMALINK} {TITLE}] ===
== Second Feed ==
=== [{PERMALINK} {TITLE}] ===
does not result in:
* 1 First Section
o 1.1 [{LINK} {TITLE}]
* 2 Second Section
o 2.1 [{LINK} {TITLE}]
but instead it generates 2 different TOCs.
It also seems to break __NOEDITSECTION__.
I’m not sure what’s going on here. Any ideas?
Justin
April 4th, 2007 at 3:43 am
Figured it out and hacked SimpleFeed to use a tag so the feeds get sent to the MediaWiki parser as 1 blob.
function parseFeeds($input, $args, &$parser)
{
$output = “__NOEDITSECTION__”;
$x = 0;
preg_match_all(’%(.*?)((.*?))%s’, $input, $result);
foreach($result[2] as $feed) {
$output .= $result[1][$x];
$feed = simplexml_load_string($feed);
foreach($feed->attributes() as $a => $b){
$feed_args[$a] = (string)$b;
}
$feed_input = $result[3][$x];
$output .= parseFeed($feed_input, $feed_args, $parser);
$x++;
}
$parserObject = $parser->parse($output, $parser->mTitle, $parser->mOptions, false, false);
return $parserObject->getText();
}
Add the function to SimpleFeed.php, hook it instead of parseFeed(), have parseFeed() return $output and use like this:
==Jonny’s Blog==
===[{LINK} {TITLE}]===
{DESCRIPTION}
==Someone’s Blog==
===[{LINK} {TITLE}]===
{DESCRIPTION}
Justin
PS. Please improve my code, I’m not very good at this.
April 4th, 2007 at 3:46 am
Hm.. That’s not right. See here for the code.
April 4th, 2007 at 3:46 am
http://pastebin.ca/423355
sigh
April 9th, 2007 at 2:46 am
Justin, I’m liking what you’re thinking! I tried what you had suggested and found the two TOCs- how amusing! However, I’m finding it a little hard to get the code you provided working here.
I think this actually needs a hook so that wiki-text is put into the main document, then parsed only once. This way, the TOCs would be fine. I will look into that, but for now, what would be great is if you provided a diff. If you can’t then putting the contents of _your_ SimpleFeed.php onto pastebin would be alright.
Thank you for your input,
Regards,
July 24th, 2007 at 10:36 am
I have a little problem with SimpleFeed.
I tried to use the tag inside a template but unfortunately the mediawiki doesn’t put in the parameters before the simpleed functions are called. Can you help me with this problem. I tried to do it myself but don’t know that much mediawiki code yet.
Thanks Lutz
February 6th, 2008 at 11:48 pm
So I was wondering would it be hard to make it render anchor tags to square brackets in the description…
March 30th, 2008 at 3:58 am
Hi Jonny. I’m not sure this falls within the scope of your code but I’m trying to implement Extension:SimpleFeed on a WAMP-on-a-stick server. I get an error on loading a page with a tag:
Warning: gzinflate() [function.gzinflate]: data error in W:\www\wi\extensions\simplepie.inc on line 7743
Do you have any suggestions?
Thanks
Euan Schelfhout
April 1st, 2008 at 11:58 am
Euan:
Sorry but the problem you describe looks a problem with SimplePie as opposed to SimpleFeed. The warning also looks very general and I’m not sure what exactly the problem is at all.. Sorry!
April 8th, 2008 at 6:30 pm
Hi Johnny,
I just discovered you SimpleFeed Wiki extension - excellent work!
I’m wondering how I can use Simplepie Addons, as seen on Ryan’s documentation page. http://simplepie.org/wiki/addons/start
Any ideas?
Btw - do you have a Amazon whishlist or something like that?
Cheers
Chris
April 11th, 2008 at 2:58 pm
Hi Christian,
Thanks for your comments on SimpleFeed. You may be interested to know that I’ve done some trivial updates on it and put it in its on Git repository and I’ve updated the Extension:SimpleFeed page on mediawiki.org.
Git repository:
http://git.jonnylamb.com/?p=simplefeed.git;a=summary
I’ve not come across SimplePie addons before, but just looking at it now, I don’t think it applies to SimpleFeed as SimpleFeed is a plugin to MediaWiki, not SimplePie. Please correct me if I’m wrong though.
Although I shouldn’t advocate getting me anything from my Amazin wishlist, I can’t help putting down the URL!
http://www.amazon.co.uk/gp/registry/3N663QT72D2OC
Many thanks,
June 26th, 2008 at 4:45 am
Hey Jonny,
A quick note regarding what looks like 2 bugs for the $simplepie_cache_folder variable. On line 35, it should be a “.” instead of a “+”. And in function parseFeed, you need to have a “global $simplepie_cache_folder;”
Thanks!
June 26th, 2008 at 9:55 am
Hi Dave,
Thank you for noticing and bringing to my attention these bugs. I’ve clearly been using python more than PHP recently! I’ve fixed these bugs in the Git repository:
http://git.jonnylamb.com/?p=simplefeed.git;a=summary
Many thanks,
July 18th, 2008 at 6:50 pm
I’m loving the extension. I’m interested in displaying the feed items side by side. I threw a around the”’[{PERMALINK} {TITLE}]”’{DESCRIPTION}, but it ain’t working right. It’s showing the ’s in the right places, but it’s not converting to a table. Any ideas on how to do this or a better way at getting the items side by side in my wiki?
July 18th, 2008 at 6:51 pm
doh, I was talking about tds — the blog stripped them out