Avoid mention notification when editing pages with velocity script

Hallo Community,

sometimes we need to do some technical refactoring on our wiki pages, maybe for editing macro parameters or editing links or something.

In this cases we don’t want to leave tracks on the pages.

So we save the pages by:

        #set ($mydocinternal = $document.getDocument())
        $mydocinternal.setAuthorReference($modifier)
        #set ($discard = $mydocinternal.setMetaDataDirty(false))
        #set ($discard = $mydocinternal.setContentDirty(false))
        $xwiki.getXWiki().saveDocument($mydocinternal, "", true, $xcontext.getContext())

This works fine, no history or version is created an the last page editor stays.

But if there are mention macros on this pages, every “mention-user” get notified on saving the page.

How can i avoid this notfications?

Thanks for helping.

Ideally you shouldn’t do what you do since it’s bypassing the history feature of XWiki which is there to track all changes, whatever they are, for accountability and more.

This is why we developed the concept of minor changes. See https://www.xwiki.org/xwiki/bin/view/documentation/xs/user/base/page/view-page/view-history/major-minor-versions/MinorEdits/

Mentions are sent only when a new mention macro is added. Thus if you make a change to a page which contains an existing mention, the mention notification won’t be sent.

The only debate to be had is whether notifications should be visible when you add a mention to a page and save the page as a minor edit. It could be consistent with our notifications to not show them by default (with an option to receive them for minor edits too,). However, it would also remove some use case, like the ability to mention someone to check a refactoring on the page.

Thanks for your Answer.

In my case, the mentions are exsiting mentions on the page.
I do not change anything in context of the mention macros.

I change the content by the following velocity call:

$document.setContent($document.getContent().replace($macro, $newMacro))

can this be the problem?

I’ve tested the following in a page:

{{velocity}}
#if ($request.confirm == '1')
  #set ($document = $xwiki.getDocument('Main.WebHome'))
  $document.setContent($document.getContent().replace("workspaces", "xxxworkspaces"))
  #set ($mydocinternal = $document.getDocument())
  #set ($discard = $mydocinternal.setAuthorReference('XWiki.Admin'))
  #set ($discard = $mydocinternal.setMetaDataDirty(false))
  #set ($discard = $mydocinternal.setContentDirty(false))
  $xwiki.getXWiki().saveDocument($mydocinternal, "xxx", true, $xcontext.getContext())
#end
{{/velocity}}

Before executing it, I had put a mention on Main.WebHome and verified that the user received the notification.

After executing this script, the user didn’t receive a mention notification again.

Okay, thanks for this hint.

XWiki seams to do some correction in the mention in some cases.
I can not reproduce this behavior, but today i receive a notification for a page with a existing mention and the history looks like this:

Yes, when using the WYSIWYG editor, the content is parsed, transformed as HTML, then you make modifications to the HTML in the WYSIWYG editor and when saving, the content is parsed as HTML, and converted again in the original document syntax.

Thus, if the original content was using some syntax “shortcuts” and not the canonical form, it’s transformed into the canonical form.

The reference parameter is supposed to be a reference so that’s probably why it got fixed (seer https://extensions.xwiki.org/xwiki/bin/view/Extension/Mentions%20Application/#HParametersdefinition ).

Okay, so the only way to avoid this notification is to global disable mail server, right?

As I said, you’ll only get a notification the first time a mention macro is used (or maybe when it’s parameters are changed, to be checked). So when editing existing docs you won’t receive new mentions if you don’t change the mention macros.