Warn users when viewing outdated articles

Hey folks,

oof, getting back on this issue i managed eventually and thought I’d share the code with anyone interested.

Unfortunately, I found out about !$doc.isMostRecent() only after I stumbled upon @vmassol’s Rollback a Document snippet here.

I have a bit longer solution than that now, this advantage is that this snippet here also tells what the latest document revision / version number is, so that I can link to it, show its revision date etc.

#set ($criteria = $xwiki.criteriaService.revisionCriteriaFactory.createRevisionCriteria())
#set ($range = $xwiki.criteriaService.rangeFactory.createTailRange(1))
$criteria.setRange($range)
$criteria.setIncludeMinorVersions(true)
#set ($mostRecentVersion = $doc.getRevisions($criteria).get(0))
#if($doc.version != $mostRecentVersion)
    (% class="box warningmessage" %)
    (((
    Hey Buddy, you're not looking at the most recent version! ($doc.version instead of $mostRecentVersion)
    )))
#end

In addition, I found this hint here on the forum on where to include this snippet in the skin, so that it shows on every page.

Thanks for coming to my TED talk.

1 Like