"Auto-Linking" Specific Key Word( Pattern)s in XWiki

I searched a bit for suggested solutions, but could not find any obvious solution so far:

We often mention JIRA and Bugzilla issues in our Wiki, like “ABC-1234” and “#1234”, respectively.

Both JIRA and Bugzilla automatically link other issues mentioned in some issue descriptions or comments.

It would be very convenient if our XWiki could also automagically create links to those JIRA and Bugzilla issues. A possible (and flexible) technical approach would probably to automatically create links based on some regular expression matching (and build the target URL using parts of the matching pattern).

What would be the best way to achieve something like this with XWiki?

You could use a rendering transformation for this for example or create the links at save time with a listener. For an example of such a transformation see https://extensions.xwiki.org/xwiki/bin/view/Extension/WikiWord%20Transformation

Thanks, will have a look.

Sorry for resurrecting this thread…

Could Xwiki also provide a way to apply such a transformation while saving a page, such that the transformation does not have to be applied every time the page is rendered? The WikiWord transformation explicitly warns about possible performance impacts for larger pages.

Obvious drawbacks of the “transform on save” solution would be that

  • the transformation has to be aware of the current page syntax and must know how to achieve it’s intended effect using appropriate syntax constructs
  • the transformation’s results are “hard coded” in the page after saving, so updating the transformation (e.g. with a fix / new features) will not help for already saved pages
  • the transformation has to be idempotent, i.e. make sure it doesn’t mess up the page in case an already transformed page is being edited again

Mh, maybe this approach wouldn’t be such a good idea after all, but I’d still be curious if it would be possible.

A similar but “distributed” approach to the WikiWord transformation way of transforming pages could be to employ JavaScript which post-processed each page in the browser after it’s rendered, similar to

https://www.xwiki.org/xwiki/bin/view/FAQ/How%20to%20open%20external%20links%20in%20a%20new%20tab%2Fwindow%20by%20default

The JavaScript could perform some regular expression search and replace on the final rendering results - however this might also be somewhat dangerous and I’m not sure about the performance implications if it’s ran from JavaScript in the browser. On the other hand, the post-processing could be postponed to take place after the page has already been loaded and rendered, so it might not delay page loading that much, and postprocessing is computed in a distributed fashion, so it does not place extra load on the server.

Opinions?

So yes this is possible. The way to do this is by writing an EventListener in java that listens to document creating (DocumentCreatingEvent) and document updating events (DocumentUpdatingEvent). Then in the onEvent method you’ll navigate the XDOM and perform modifications to it. Note: you don’t need (and shouldn’t) perform the save yourself, it’ll be done automatically if you listen to these events since they are sent before the doc is saved.

It’s quite simple and works efficiently.

See https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingEventListenerTutorial/

Thanks