How to prevent internal wiki links as url

Hi.

It’s perfect that wiki links will be updated, if the page it links to changes it’s name / destination.

But what most users do is copying wiki urls from the browsers address bar instead of using the wiki intern links. Now I’m dreaming of a solution that will repair those urls pointing to the wiki itself to intern links.

Is someone out there with such a script? Otherwise I would try to create an event “on save”. But I would need a lot of time to fulfill this. Any hints or snippets?

Regards, Simpel

A litte bit brute force:
If you want to do this be a job - just find the documents by modifying the following search example

{{velocity}}
#set ($queryStatement = 'doccontentraw:">>https://bug"')
#set ($query = $services.query.createQuery($queryStatement, 'solr'))
#set ($discard = $query.bindValue('sort', "score desc"))
#set ($discard = $query.bindValue('fq', 'type:DOCUMENT'))
#set ($searchResponse = $query.execute()[0])
#foreach ($searchResult in $searchResponse.results)
  * [[${searchResult.wiki}:${searchResult.fullname}>>${searchResult.wiki}:${searchResult.fullname}]]
#end
{{/velocity}}

(replace “bug” with your server name)

and continue with a set of “replaceAll” and regular expressions

1 Like

Let me see if I understand your question. I have a page called “TestPage1” under my SandBox. The browsers url bar looks like: https://xwiki.example.com/xwiki/bin/view/Sandbox/TestPage1

Now you rename the page to 1PageTest

The new url would now be different, it would now be
https://xwiki.example.com/xwiki/bin/view/Sandbox/1PageTest

Anyone using the old url is going to either get
a) a broken link or
b) a html redirect to redirect from the old url to the new url

The second option happens happens if you’ve ticked the “CREATE AN AUTOMATIC REDIRECT” checkbox on the page rename page.

If people copy and use the old url - other than redirecting them to the new page automatically, there is nothing you can do to reach out and change their saved url.

Please correct me if I have not properly understood your question.

We have the same problem/wish. I tried writing an on save listener that finds absolute urls to the wiki and replaces them with internal links, but I could not find a safe way to get the name of the article from the url, because special characters can cause errors here.
I think you need to call the api to get the internal link/name, but I just could not figure out how to.

The “create an automatic redirect”-checkbox would be a solution, if the users would tick it - they just don’t.

As helena said users won’t tick the checkbox.

What I want to achieve is:
Someone just copy&paste

https://xwiki.example.com/xwiki/bin/view/Sandbox/TestPage1

in the editor and saves.

A script / event listener etc. “repairs” it to

[[Sandbox.TestPage1]]

The part in the beginning of the url shows me that this url is part of my wiki. So how can I look now into database for the internal wiki link? Just replacing Sandbox/TestPage1 with Sandbox.TestPage1 won’t work as helena already said due to special characters.

I’m back to this topic. Is there any chance to get the internal wiki link of a given external wiki link by script? Best driven by an event listener.

Many users don’t understand the advantages of internal wiki links. They see the comfort of copying the address bar and do it.

I know how to write the event listener but I don’t see a possibility to replace the external url with an internal wiki link.

Regards, Simpel

Have you tried the URL Normalizer extension?

https://extensions.xwiki.org/xwiki/bin/view/Extension/WikiLinkURLNormalizer/

1 Like

As I read it I think it is exactly what I was looking for.

I will test it as soon as possible.

Thanks, Simpel

Works like charm except for urls with anchors and subwikis as described in section limitations. To be clear it works inside a subwiki but couldn’t handle urls to other subwikis (including the „main“ subwiki).

Thanks for guiding me, Simpel

hmm I don’t see any limitation mentioned about links between subwikis in the doc. Thus I think that’s supposed to work. I also don’t see an existing issue about it: Issue Navigator - XWiki.org JIRA

Could you raise a new jira issue with explanations how to reproduce?

Thanks

Done: URLNORMALZ-24: main wiki links are not normalized inside a subwiki