Warn users when viewing outdated articles

Hi there!

I’m new to xWiki and slightly overwhelmed, so please bear with me.

I’d like to show a warning banner on the top of any article, if it has been accessed by the user via an URL like /wiki/MyArticle?rev=3.1 if this is not the latest revision/version of the article. I’ll be grateful for any hints pointing me in the right direction. I already g$%gled and looked for matching extensions, but to no avail.

Yes, I found this topic, but it refers to an articles last updated date being older than x, not its revision/version.

Regards

Hi @metawiki!

In Velocity, you can get the value from the URL with $request.rev, the current document version with $doc.version and there is also $doc.revisions that will give a list of revisions and you can grab the latest from there, to compare to the one from URL.

Hope it helps,
Alex

1 Like

Thanks @acotiuga, that’s good starting points for my deep-dive into velocity :grimacing:
Will post my solution when I find one :slight_smile: have a nice sunday!

1 Like

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