Extensions Wiki » Extensions » Changes By User

Changes By User

Last modified by Vincent Massol on 2013/03/11 09:38
cogShows a list of all the documents a user has ever contributed to
TypeSnippet
Developed by

Thomas Drevon

LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Originally written for an xwiki instance for use in a school class while the students were working in groups on different projects. The teacher wanted to keep an eye on what each individual student was actually contributing, so this report shows a list of all the documents a user has ever contributed to, and lets you view the diff between revisions, just like in "history" mode.

This code snippet goes into XWiki.XWikiUserSheet, preferably somewhere near the bottom.

NOTE: This code examines ALL revisions of ALL documents on your wiki and is thus extremely inefficient! It will not scale at all on a wiki with many documents.

If you find a way to make the code more efficient, please let me know and I'll update this page :-)

Code

<h2 class="heading-1-1-1">Recent changes by $doc.name</h2>

#set( $query = "where 1=1 order by doc.date desc")
#set( $formatDate = "yyyy MMMM dd, HH:mm")
#set( $allDocs = $xwiki.searchDocuments($query))
#set( $itemsEdited = $xwiki.getHashMap())

#foreach ($item in $allDocs)
  #set($aDoc = $xwiki.getDocument($item))
  #foreach ($version in $aDoc.getRecentRevisions())
    #set( $counter = $counter +1)
      #set($revDoc = $xwiki.getDocument($aDoc, $version))
      #if($doc.name == $xwiki.getDocument($revDoc.author).name)
        #set( $dummy = $itemsEdited.put($item, "ok"))
      #end
  #end
#end

#foreach ($item in $itemsEdited.keySet())
  <h3>$item</h3>
  #set($editedDoc = $xwiki.getDocument($item))
  <form action="$editedDoc.getURL("view", "viewer=changes&amp;$docvariant")" method="post">
    <div id="history">
    <div class="centered">
    <table class="xwikidatatable" summary="$msg.get(document) ${doc.displayTitle} &mdash; $msg.get("history")">
      <tr>
        <th>$msg.get("from")</th>
        <th>$msg.get("to")</th>
        <th>$msg.get("version")</th>
        <th>$msg.get("reveditor")</th>
        <th>$msg.get("date")</th>
        #if($xwiki.hasEditComment())
          <th>$msg.get("comment")</th>
        #end
        #if($hasedit || $hasadmin)
          <th></th>
        #end
      </tr>

      #if ($editedDoc.realLanguage!="")
        #set($lang = "&amp;language=${editedDoc.realLanguage}")
      #else
        #set($lang = "")
      #end
      #foreach ($version in $editedDoc.getRecentRevisions())
        #set($origdoc = "")
        #set($newdoc = "")
        #set($nextversion = $version)
        #set($newdoc = $xwiki.getDocument($editedDoc, $nextversion))
        <tr class="row#if($velocityCount % 2 == 1) even #else odd #end">
          <td><input type="radio" name="rev1" value="$nextversion" /></td>
          <td><input type="radio" name="rev2" value="$nextversion" /></td>
          <td><a href="$editedDoc.getURL("viewrev","rev=$nextversion")">$nextversion</a></td>
          #if($newdoc=="")
            <td>&ndash;</td>
            <td>&ndash;</td>
          #else
            <td>$xwiki.getLocalUserName($newdoc.author)</td>
            <td>$xwiki.formatDate($newdoc.date, "dd/MM/yyyy hh:mm")</td>
          #end
          #if($xwiki.hasEditComment())
            <td>$!{newdoc.comment}</td>
          #end
          #if($hasedit || $hasadmin)
            <td></td>
          #end
        </tr>
      #end
    </table>
    <div class="buttons"><div class="buttonwrapper"><input type="submit" accesskey="c" value="$msg.get("compare")" class="button"/></div></div>
    </div>
  </div>

</form>
<br />

#end

Result

changes_by_user.png

Tags:
Created by thomasd on 2007/06/05 10:57

Download XWiki