How to implement "Approved Revisions"?

Last modified by Vincent Massol on 2014/05/24

MediaWiki supports a notion of Approved Revision.

There are several ways in XWiki to have a similar mechanism:

Creating a Display Revision Application

  • Create an XClass, say Revision.RevisionClass and add a String field named revision which will contain which revision to display for a given page.
  • Add an XObject ClassSheetBinding to Revision.RevisionClass and fill the value with Revision.RevisionSheet. This sheet will contain the script to display a given revision.
  • Create the Revision.RevisionSheet page with the following content:
    {{velocity}}
    #if ($doc.fullName != 'Revision.RevisionSheet')
      #set($revisionClass = $doc.getObject("Revision.RevisionClass"))
      #if($revisionClass)
        #set ($rev = $doc.getValue("revision"))
        #if ("$!rev" != '')
          #set ($revDoc = $xwiki.getDocument($doc, $rev))
          #if ($revDoc)
            $revDoc.content
          #else
            {{error}}Invalid revision [$rev] specified, showing latest content{{/error}}

            $doc.content
          #end
        #else
          $doc.content
        #end
      #else
        $doc.content
      #end
    #end
    {{/velocity}}

You're done. Now let's try it!

  • Create a page, say Main.Test with the content "Original Content"
  • Edit the page again to change the content to "New Content"
  • Add an XObject of type Revision.RevisionClass and set the revision field to 1.1 (this is the version we want to display)
  • Save!

You'll see "Original Content" displayed emoticon_smile

Get Connected