×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    MediawikiExtensions/RSS: Difference between revisions

    Content added Content deleted
    imported>mutante
    imported>mutante
    Line 24: Line 24:
    # by mutante 25.03.2005
    # by mutante 25.03.2005


    # requiring magpie (see above)
    require_once('magpierss-0.71.1/rss_fetch.inc');
    require_once('magpierss-0.71.1/rss_fetch.inc');

    # give it a name
    $wgExtensionFunctions[] = "wfRssExtension";
    $wgExtensionFunctions[] = "wfRssExtension";


    # register with global parser (http://meta.wikimedia.org/wiki/Write_your_own_MediaWiki_extension)
    function wfRssExtension() {
    function wfRssExtension() {
    global $wgParser;
    global $wgParser;

    # set hook (trigger) to rss, means <rss> will be made active tag
    $wgParser->setHook( "rss", "renderRss" );
    $wgParser->setHook( "rss", "renderRss" );
    }
    }


    # the actual function (taking input)

    function renderRss( $input ) {
    function renderRss( $input ) {


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


    # fetch the feed (magpie's job)

    $rss = fetch_rss($input);
    $rss = fetch_rss($input);

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

    # putting the html table head into the output variable


    $output="<table><tr><th align='left' colspan='3'><i>RSS-feed included from:</th></tr>
    $output="<table><tr><th align='left' colspan='3'><i>RSS-feed included from:</th></tr>
    Line 47: Line 58:
    <th><i>'$cdesc'</i></th></tr><tr><th>Date</th>
    <th><i>'$cdesc'</i></th></tr><tr><th>Date</th>
    <th>Page</th><th>Description</th></tr>";
    <th>Page</th><th>Description</th></tr>";

    # now a loop to add table rows until none more are found


    foreach ($rss->items as $item) {
    foreach ($rss->items as $item) {

    # setting variables for table row

    $href = $item['link'];
    $href = $item['link'];
    $title = $item['title'];
    $title = $item['title'];
    $date = $rss->dc['date'];
    $date = $rss->dc['date'];
    $description = $item['description'];
    $description = $item['description'];

    # adding each single row (still in loop) (.= appends = would overwrite)

    $output.="<tr><td>date $date</td><td colspan='1'><a href='$href'>$title</a></td><td>$description</td></tr>";
    $output.="<tr><td>date $date</td><td colspan='1'><a href='$href'>$title</a></td><td>$description</td></tr>";
    }
    }

    # loop done ,adding final tag to close table properly
    $output.="</table>";
    $output.="</table>";


    # dump the output all at once
    return $output;
    return $output;



    Revision as of 18:28, 30 March 2005

    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

    <rss>URL</rss>

    Example

    <rss>http://slashdot.org/slashdot.rss</rss>

    Result

    <rss>http://slashdot.org/slashdot.rss</rss>

    Source

    <?php
    # RSS-Feed Mediawiki extension
    # using magpieRSS (http://magpierss.sourceforge.net/)
    # by mutante 25.03.2005
    
    # requiring magpie (see above)
    require_once('magpierss-0.71.1/rss_fetch.inc');
    
    # give it a name
    $wgExtensionFunctions[] = "wfRssExtension";
    
    # register with global parser (http://meta.wikimedia.org/wiki/Write_your_own_MediaWiki_extension)
    function wfRssExtension() {
    global $wgParser;
    
    # set hook (trigger) to rss, means <rss> will be made active tag
    $wgParser->setHook( "rss", "renderRss" );
    }
    
    # the actual function (taking input)
    function renderRss( $input ) {
    
    # maybe its a good idea to escape string user input so they dont try to attach nasty things
    # $input = mysql_escape_string($input);
    
    # fetch the feed (magpie's job)
    $rss = fetch_rss($input);
    
    # setting variables for table head
    $link=$rss->channel['link'];
    $title=$rss->channel['title'];
    $cdesc=$rss->channel['description'];
    
    # putting the html table head into the output variable
    
    $output="<table><tr><th align='left' colspan='3'><i>RSS-feed included from:</th></tr>
    <th colspan='2'><a href='$link'>$title</a></th>
    <th><i>'$cdesc'</i></th></tr><tr><th>Date</th>
    <th>Page</th><th>Description</th></tr>";
    
    # now a loop to add table rows until none more are found
    
    foreach ($rss->items as $item) {
    
    # setting variables for table row
    
    $href = $item['link'];
    $title = $item['title'];
    $date = $rss->dc['date'];
    $description = $item['description'];
    
    # adding each single row (still in loop) (.= appends = would overwrite)
    
    $output.="<tr><td>date $date</td><td colspan='1'><a href='$href'>$title</a></td><td>$description</td></tr>";
    }
    
    # loop done ,adding final tag to close table properly
    $output.="</table>";
    
    # dump the output all at once
    return $output;
    
    }
    
    ?>
    
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.