How do I find the backlinks to a given page?
Last modified byon 2017/03/28
|Question||How do I find the backlinks to a given page?|
Note: the feature is now available, see:
You can use the Velocity code below to get the backlinks of the current page. Note: the code here requires access to the privileged API, but you can also change it so that is uses only the simple XWiki API (use xwiki.searchDocumentNames, instead of calling directly the Hibernate store).
\#set (\$sql = "select xlink.fullName from XWikiLink as xlink where xlink.link='\$cdoc.fullName' order by xlink.fullName") \#set (\$results = \$xwiki.xWiki.getHibernateStore().search(\$sql,50,0,\$context.context)) \#if (\$results.size() > 0) \#foreach (\$result in \$results) \#set (\$backlink = \$xwiki.getDocument(\$result)) * [\$backlink.name>\$result] \#end \#end
Notes entered before the feature has been made available: There is no easy solution yet.. So for the moment the response would be "it is not possible". The rest of the answer is more for developers on how to handle this: This is a little complex.. Doing it without saving the links of a page in a separate structure in the database, this can be an important query because you need to query the whole database searching for links using regular expression. Now the regular expression is complex because there are multiple cases which can transform the link to a link to a specific page. For example if you have the page , then the following texts will create a link to this page: