How to automatically show an outdated warning message after “n” days in MediaWiki

mediawiki

We are using a MediaWiki 1.23.3 at work, and most of our pages need to be updated with fresh new data very often.

I'm wondering if there is a way to automatically show a text/template in the header of every page after "n" days from the last update, to alert the user that data in the page can be outdated and should be checked.

Any ideas?

Best Answer

An ArticleViewHeader hook maybe?

$wgHooks['ArticleViewHeader'][] = function ( &$article, &$outputDone, &$pcache ) {
    $lastUpdate = new DateTime( $article->getTimestamp() );
    $cutoff = new DateTime( "-$n days" );
    if (  $lastUpdate < $cutoff ) {
        $article->getContext()->getOutput()->addHTML(
            Html::element( 'div', [ 'class' => 'outdated-warning' ],
                "boo I'm old" );
        );
    }
};