Change creator, author or contentAuthor

Version 4.1 by Eduard Moraru on 2021/03/17 16:18

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

Active Installs60
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

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}}

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki
Tags:
    

Get Connected