Nicolas
Nicolas

Reputation: 6484

Auto refresh content in Mediawiki

I added a new tag (<news />) to my mediawiki to list the last modified pages.
Unfortunately the list is not updated unless I modify the page where the tag is.
I'm looking for a way to do it, and I think of AJAX. But I didn't manage to make AJAX refreshing my list.
Does anyone know a simple way to add an auto refresh feature on my Mediawiki ?
Here is my extension code :

$wgHooks['ParserFirstCallInit'][] = 'replaceTags';

function replaceTags( Parser $parser ) {
    $parser->setHook( 'news', 'newsRender' );
    return true;
}

function newsRender( $input, array $args, Parser $parser, PPFrame $frame ) {
    // Titre =News=
    $output = $parser->parse( "=News=", $parser->mTitle, $parser->mOptions, false, false )->getText();

    $nb = 5;

    $querySQL = "SELECT page_namespace, page_title, page_id, page_latest, rev_timestamp
                FROM page, revision
                WHERE page.page_latest = revision.rev_id 
                AND page_namespace = 0
                ORDER BY rev_timestamp
                DESC LIMIT 0,$nb";

    $dbr = wfGetDB( DB_SLAVE );
    $res = $dbr->query( $querySQL );

    $count = $dbr->numRows( $res );
    if( $count > 0 ) {  
        $output .= "<ul>";
        while( $row = $dbr->fetchObject( $res ) )
        {
            $pageTitle = $row->page_title;
            $nicerPageTitle = str_replace("_", " ", $pageTitle);
            $pageNamespace = $row->page_namespace;
            $title = Title::makeTitleSafe( $pageNamespace, $pageTitle );
            $url = $title->getFullURL();

            $date = $row->rev_timestamp;
            $date = wfTimestamp( TS_RFC2822, $date );

            $output .= "<li><a href=\"$url\">$nicerPageTitle</a> $date</li>";
        }
        $output .= "</ul>";
    } else {
        $output .= "A l'ouest rien de nouveau !!!";
    }

    return $output;
}

Upvotes: 1

Views: 1141

Answers (2)

Nicolas
Nicolas

Reputation: 6484

Thanks to nischayn22, I go into the cache problem in depth.
And I found that it's possible to deactivate it :

$parser->disableCache();

I tried it, and it works !!!

http://www.mediawiki.org/wiki/Extensions_FAQ#How_do_I_disable_caching_for_pages_using_my_extension.3F

Upvotes: 3

nischayn22
nischayn22

Reputation: 447

This probably happens because MediaWiki uses Cache for pages. What you could rather do is make a SpecialPage for the feature needed. AFAIK Special Pages are not cached (confirm this on irc #mediawiki). Also you might already find a similar implementation done by someone if you search the extensions that exist on Mediawiki.org .(Otherwise I would be happy to build one for you :)

Update: Extensions you could use Dynamic List(used in wikinews) and news . There could be more if you search mediawiki.org.

Upvotes: 2

Related Questions