Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×This question is in reference to Atlassian Documentation: Links
In some cases, editors are selecting the wrong space when entering a link. When we publish documents, links to other spaces are removed. We need to be able to run a report in Conlfuence that will find all links that go to this other space before we publish the document.
Found this question on accident. Even though it is already over 2 years old, I'd still like to post an answer. I wrote a user macro to identify outgoing links in our documentation spaces. It works a treat for me, but having just re-scanned the code (also 2 years old) I noticed that it is not really optimized for large spaces. It is also partially commented in German... ;-)
This was also written for Confluence 5 or so. It could definitely be improved upon, but it works as is in 6.14.3. At least for me.
## Macro title: Outgoing Links
## Macro has a body: N
## Body processing: rendered
## Output: HTML
##
## Developed by: Jens Iwanenko
## Date created: 2016-08-15
## Installed by: Jens Iwanenko
## This macro lists all outgoing links of a Space or a Pagetree.
## @param Method:title=Methode|type=enum|enumValues=Teilbaum,Space|default=Teilbaum|desc=Wählen, ob die Ausgehenden Links eines Space oder eines Teilbaums gesammelt werden sollen (Default: Teilbaum).
## @param Space:title=Space|type=spacekey|desc=Den Space-Key eingeben, zu dem die ausgehenden Links gesammelt werden sollen. Wird ignoriert, wenn die Methode "Teilbaum" ist (Default: aktueller Space).
## @param Parent:title=Seite|type=confluence-content|desc=Den Seitennamen des Teilbaum-Parents eingeben, zu dem die ausgehenden Links gesammelt werden sollen. Wird ignoriert, wenn die Methode "Space" ist (Default: aktuelle Seite).
#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager=$getInstanceMethod.invoke(null,null))
#set($containerContext=$containerManager.containerContext)
#set($spaceManager=$containerContext.getComponent('spaceManager'))
#set($pageManager=$containerContext.getComponent('pageManager'))
#set($spaceKey = $content.getSpaceKey())
#set($parentPageTitle = $content.getPageTitle())
#set($outgoingLinks = [])
#set($containingPages = [])
## Teilbaum Start
#if($paramMethod == "Teilbaum")
#if($paramParent)
#if ($paramParent.contains(':'))
#set ( $strArray = [] )
#foreach($str in $paramParent.split(':'))
#set($dummy = $strArray.add($str)) ## Assign returnval to avoid printing 'true'.
#end
#set($spaceKey = $strArray.get(0).trim())
#set($parentPageTitle = $strArray.get(1).trim())
#else
#set($parentPageTitle = $paramPage.trim())
#end
#end
#set($parentPage = $pageManager.getPage($spaceKey, $parentPageTitle))
#end
## Teilbaum Ende
## Space Start
#if($paramMethod == "Space")
#if($paramSpace)
#set($spaceKey = $paramSpace)
#end
#set($space = $spaceManager.getSpace($spaceKey))
#set($parentPage = $space.getHomePage())
#end
## Space Ende
## Allgemein Start
#foreach($ogLink in $parentPage.getOutgoingLinks())
#if($ogLink.getDestinationSpaceKey() != $spaceKey)
#set($dummy = $outgoingLinks.add($ogLink))
#set($dummy = $containingPages.add($parentPage))
#end
#end
#set($subPages = $parentPage.getDescendants())
#foreach($subPage in $subPages)
#foreach($ogLink in $subPage.getOutgoingLinks())
#if($ogLink.getDestinationSpaceKey() != $spaceKey)
#if(!$ogLink.isUrlLink())
#set($dummy = $outgoingLinks.add($ogLink))
#set($dummy = $containingPages.add($subPage))
#end
#end
#end
#end
## Allgemein Ende
## HTML Start
<div class="enc-outgoing-links">
<div>
#if($outgoingLinks.size() == 1)
$outgoingLinks.size() ausgehender Link
#else
$outgoingLinks.size() ausgehende Links
#end
#if($paramMethod == "Space")
im Space <a href="$parentPage.getUrlPath()">$spaceKey</a>.
#end
#if($paramMethod == "Teilbaum")
im Teilbaum von <a href="$parentPage.getUrlPath()">$parentPage.getTitle()</a> ($spaceKey).
#end
</div>
<table class="aui aui-table-sortable">
<thead>
<tr>
<th>Seite</th>
<th>Zielseite</th>
<th>Zielspace</th>
</tr>
</thead>
<tbody>
#set($iterator = 0)
#foreach($ogLink in $outgoingLinks)
<tr>
<td><a href="$containingPages.get($iterator).getUrlPath()">$containingPages.get($iterator).getTitle()</a></td>
<td><a href="$pageManager.getPage($ogLink.getDestinationSpaceKey(),$ogLink.getDestinationPageTitle()).getUrlPath()">$ogLink.getDestinationPageTitle()</a></td>
<td>$ogLink.getDestinationSpaceKey()</td>
</tr>
#set($iterator = $iterator +1)
#end
</tbody>
</table>
</div>
## HTML Ende
We export the space to Word. The links should not go to this other space: they are incorrect links, so I want to find all of the links that go to that space and change them or remove them. Once the pages are exported to Word, all the links to that other space are removed, so we can't easily find them in the Word document. It just looks like text so it doesn't stand out in any way.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure what you mean by "publish the document"- paper? PDF? web page? Confluence page?
Why do you want to remove the links the author has put in - is it because they "might" be wrong?
But why/how are they are entering wrong links?
If linking from on page to another (even in different Space) in Confluence,
Or any other linking:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.