Change creator, author or contentAuthor

Version 1.4 by Eduard Moraru on 2016/05/04 15:50

user_goChange the creator, last author or content author fields for a specified existing document with a specified user.
TypeXAR
CategoryOther
Developed by

Eduard Moraru

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Changes the creator, last author or content author fields for a specified existing document with a specified user.

This is useful, for example, when the creator of a document is important and, even if you have created a document, you want to give credits to someone else.

Another important usecase of this is when you want to assign Script Rights or Programming Rights to a page (by setting the contentAuthor). This is similar to the Change Content Author extension in this sense, however it is more flexible and it only targets a single, specified document.

Requires Programming Rights to function.

Note: If you install this with Extension Manager or manual import, the page also contains rights set to allow only the XWiki.XWikiAdminGroup to view, edit and delete the page, to avoid misuse. Of course, you can change the rights as you wish.

change creator, author or contentAuthor.png

Source

Below is the source to copy/paste in a new document in your XWiki instance, in case you can/will not use Extension Manager or direct XAR import to install it.

{{velocity}}
#set ($documentReferenceString = "$!request.documentReference")
#set ($userReferenceString = "$!request.userReference")
#if ($documentReferenceString != '' && $userReferenceString != '')
  #set ($documentReference = $services.model.resolveDocument($documentReferenceString))
  #set ($document = $xwiki.getDocument($documentReference))
  #if ($document.isNew())
    {{error}}The document [$document] does not exist, so we can't change its creator.{{/error}}
  #else
    #set ($userReference = $services.model.resolveDocument($userReferenceString))
    #set ($internalDocument = $document.document)
    #if ($request.creator == 'true')
      #set ($discard = $internalDocument.setCreatorReference($userReference))
    #end
    #if ($request.author == 'true')
      #set ($discard = $internalDocument.setAuthorReference($userReference))
    #end
    #if ($request.contentAuthor == 'true')
      #set ($discard = $internalDocument.setContentAuthorReference($userReference))
    #end
    #set ($discard = $xwiki.xWiki.saveDocument($internalDocument, "Changed creator, author or contentAuthor document fields to $userReference", $xcontext.context))
    {{success}}Changed creator, author or contentAuthor fields for document [[$documentReference]] to [[$userReference]]{{/success}}
  #end
#else
 Change the creator, last author or content author fields for an existing document with a given user.

  {{html}}
   <form action='' class='xform'>
     <dl>
       <dt><label for='documentReference'>Document to change</label></dd>
       <dd><input type='text' name='documentReference' class='suggestDocuments withTip' value='Document reference'/></dd>

       <dt><label for='userReference'>User to set</label></dd>
       <dd><input type='text' name='userReference' class='suggestUsers withTip' value='User reference'/></dd>

       <dt>Fields to change:</dt>
      
       <dd>
         <label for='creator'>
           <input type='checkbox' name='creator' value='true' checked='checked'/>
           Creator
         </label>
       <dd>
       </dd>
         <label for='author>
           <input type='checkbox' name='author' value='true' checked='checked'/>
           Author
         </label>
       <dd>
       </dd>
         <label for='contentAuthor>
           <input type='checkbox' name='contentAuthor' value='true' checked='checked'/>
           Content Author
         </label>
       </dd>

       <dt>
         <input type='submit' value='Change'/>
       </dt>
     </dl>
   </form>
  {{/html}}
#end
{{/velocity}}
Tags:
    

Get Connected