List Orphaned Spaces

Last modified by Ecaterina Moraru (Valica) on 2021/03/18 11:28

cogLists all spaces that are ophaned in the wiki
TypeSnippet
Category
Developed by

Jerome

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

A "Orphaned Space" is a wiki space that is not linked from anywhere else but itself in a wiki. Such spaces are dangerous in terms of content accessibility because it means one cannot access its pages only clicking through links in the wiki. The only way they are accessible is by searching (wiki internal search engine or web engine) or by direct URL hit. The following snippet is a helper to "hunt" such spaces, in order to make wiki content more accessible, and make the wiki being better organized in general.

Code

To execute this snippet, you need both programming rights, and backlinks activated. Backlink are activated by default, but you can make sure they still are on your wiki checking the following is present in your xwiki.cfg file : xwiki.backlinks=1.

1 List of orphaned spaces

#foreach($space in $xwiki.spaces)
 #set($isLocked=true)
 #set($hql = "select lk.link from XWikiLink as lk, XWikiDocument as doc where doc.space='$space' and doc.id=lk.docId")
 #foreach($links in $xwiki.search($hql))
  #set($spaceLinks = $links.split(","))
  #foreach($link in $spaceLinks)
   #if($link.indexOf(".")>0 && $link.indexOf("$") < 0)
    #set($linkWeb = $link.substring(0, $link.indexOf(".")).replaceAll("\"",""))
     #if(!$linkWeb.equals($space)) #set($isLocked=false) #end
   #end
  #end
 #end
 #if($isLocked)
   #set($hql = "select doc.fullName, obj.className from XWikiDocument as doc, BaseObject as obj, LargeStringProperty as content where obj.name=doc.fullName and content.id.id=obj.id and (content.value like '%[$space.%]%' or content.value like '%[%>$space.%]%')")
   #set($objectLinks = $xwiki.search($hql))
   #if($objectLinks.size()>0)
* *$space* seems orphan, but is referenced from the following objects :
#foreach($object in $objectLinks)
** #foreach($elem in $object) #if($velocityCount==1) [$elem] #else ($elem) #end #end

#end

   #else
* *$space*
   #end
 #end
#end

Result

The proper execution of the snippet result in a list of spaces which are orphaned, possibly precising which spaces might be referenced from panels. For example, for the a fresh XWiki instance, you'll see the following :

  • Blog seems orphan, but might is from the following objects
    • Panels.BlogCategories (Panels.PanelClass)
    • Panels.QuickLinks (Panels.PanelClass)
  • Panels
  • Scheduler

Limitations of this snippet

This snippet is just a helper, and it has some limitations. For example, it does not take into consideration links that are available from the skin (in the velocity templates that constructs the UI around a document). They do not consider links that are displayed via ajax calls to velocity templates as well (like Lightboxes in the RMUI for example). Finally, they do not consider dynamic links either, i.e. links generated from code. The main purpose of the snippet is to help hunt orphaned spaces, but then it is ones responsibility to ensure the returned spaces are actually really orphaned, and if they are, maybe to take positive action to "un-orphan" them if desired emoticon_wink

     

Get Connected