Find pages that use certain macros/plugins

Hi,

does anyone know a nice way to search Confluence for pages that use a given macro?

This would help to see which plugins are widely used or who is using certain plugins.

We could use this information to contact the plugin users directly or to see which plugins are no longer required and could be removed.

Regards,

Stephan

11 answers

1 accepted

This widget could not be displayed.

For people who don't have access to the database, here's how to do it in Confluence 4.0 and above:

http://ffeathers.wordpress.com/2011/11/04/how-to-search-confluence-for-usage-of-a-macro/

In a nutshell: In a nutshell: Enter the following in the Confluence search box, assuming that your macro name is “x”:

macroName: x*

The above works in out-of-the-box Confluence (no plugins required). If you install a plugin, you can also search for specific parameters and parameter values. See http://ffeathers.wordpress.com/2012/09/04/how-to-search-for-macros-and-macro-parameters-in-confluence-4/

I hope this helps!

Cheers, Sarah

I tried that, but I always get this response: "Did you mean: mucronate:sql*"

when searching for macroName:sql* (tried with or without a space after : )

Hallo Andre

Which version of Confluence are you using? The "macroName" search field is available in Confluence 4.0 and later.

In Confluence 3.5 and earlier, you can enter the curly brackets and the macro name surrounded by double quotation marks, like this:

“{sql”

More details in this post: http://ffeathers.wordpress.com/2011/11/04/how-to-search-confluence-for-usage-of-a-macro/

Cheers, Sarah

I believe it's cace sensative i.e. it has to be "macroName: SearchString*"

This worked perfectly for us! We had migrated to Confluence 5.0 (we were on OnDemand). The JIRA macro could not be converted correctly. This saved us a ton of time by locating the pages and making the updates manually -- we had started down the path of reviewing every page for the problem until we came across this. Thanks!!!!

yeah, this is great!

Great answer Sarah. What if I can't fined the exact macro name to use in the search? For example we're using the Customware Visibility plugin. But when i search for 'macroName:show-if' the result is 0, and i know that it's used. Any tips?

It does show "did you mean.." etc, but it still presents the results for what you asked for.

When I use that search, for either macroName:sql* or macroName:sql-query, I get exactly one result, even though I have dozens of pages using this macro. It only seems to find the outer macro, and almost all of my sql-query macros are wrapped in a run query.

This widget could not be displayed.

I was using the usage macro in the confluence 4.0. it installs and runs but, has always been slow and causes the server to hang up while running. What we have since done is borrowed and tweaked the sql it was running, and run it directly against the sql server. The code will check in pages and blogpost where the content is the current version and not deleted. I will return a contentid, page title, the space id, the creator, and when it was modified. We use the following code:

Select CONTENT.CONTENTID, Title, SpaceID, CREATOR, LASTMODDATE
from CONTENT, BODYCONTENT
WHERE 
PREVVER IS NULL 
AND (CONTENTTYPE = 'PAGE' OR CONTENTTYPE = 'BLOGPOST') 
AND CONTENT.CONTENTID = BODYCONTENT.CONTENTID 
AND CONTENT_STATUS = 'current'
AND (BODY like '%{macro%')

Opps that code works for un converted macros in confluence 4.

For converted macros replace the last line with

AND (BODY like '%<ac:macro ac:name="MACRO">%')

You can go straight to a page by using this link and replacing CONTENTID with the returned contentid from the sql results https://confluence-install/pages/viewpage.action?pageId=CONTENTID

Change "CONTENTID" to "CONTENT.CONTENTID"

works perfectly Jason - many thanks for the advice!

Select CONTENT.CONTENTID, CONTENT.Title, CONTENT.SpaceID, CREATOR, LASTMODDATE
from CONTENT, BODYCONTENT
WHERE
PREVVER IS NULL
AND (CONTENT.CONTENTTYPE = 'PAGE' OR CONTENT.CONTENTTYPE = 'BLOGPOST')
AND CONTENT.CONTENTID = BODYCONTENT.CONTENTID
AND CONTENT.CONTENT_STATUS = 'current'
AND (BODYCONTENT.BODY like '%{cache%')

I'm running confluence 4.2.x and this works for me:

Select CONTENT.CONTENTID, CONTENT.Title, CONTENT.SpaceID, CREATOR, LASTMODDATE
from CONTENT, BODYCONTENT
WHERE
PREVVER IS NULL
AND (CONTENT.CONTENTTYPE = 'PAGE' OR CONTENT.CONTENTTYPE = 'BLOGPOST')
AND CONTENT.CONTENTID = BODYCONTENT.CONTENTID
AND CONTENT.CONTENT_STATUS = 'current'
AND (BODYCONTENT.BODY like '%{cache%')

EDIT: Andre beat me to it :)

I tried running this (on mysql 5.0.95):

Select CONTENTID, Title, SpaceID, CREATOR, LASTMODDATE
from CONTENT, BODYCONTENT
WHERE
PREVVER IS NULL
AND (CONTENTTYPE = 'PAGE' OR CONTENTTYPE = 'BLOGPOST') 
AND CONTENT.CONTENTID = BODYCONTENT.CONTENTID 
AND CONTENT_STATUS = 'current'
AND (BODY like '%&lt;ac:macro ac:name="MACRO"&gt;%')

but then I get a 'ERROR 1052 (23000): Column 'CONTENTID' in field list is ambiguous' message from mysql.

FYI, this is on Confluence 4.3

Jason's SQL is the method to use when looking for a macro that is not working. For example, Graphviz recently became commercial and our existing pages using it now fail.

macroName:flowchart

does not work but the SQL method does. We needed it to answer the question: How many pages were using this plugin and should we buy it?

This widget could not be displayed.

On recent version of confluence (5.10+), it seems there is the usage of each macro, grouped by plugin, listed on this admin page:
https://%confluence%/admin/pluginusage.action 

The SQL queries were good, but they also returned some false positive (ex. if the macro name is used as a parameter of another macro, you will get a match on this page).

Gilles

cf. https://confluence.atlassian.com/confkb/how-to-get-a-list-of-the-most-popular-macros-used-in-confluence-353764197.html

best answer for current versions

This widget could not be displayed.

If you're using Confluence 3.5.x and earlier, you can try out Usage Stats Macro

Hanis,

thank you for the fast answer. I am about to upgrade from 3.5.x (right now). I have saved the list :)

Is there any way to do that with Confluence 4.x?

Regards,

Stephan

I'd also be interested in how to do this in confluence 4.x installation - a number of macros/plug-in I've used in the past have gone commercial and I'm being asked how widely they are being used in order to justify the purchase. Any 4.x suggestions woudl be most welcome.

This widget could not be displayed.

We wrote a little user macro for this requirement to create an overview page. Please use this macro only for Confluence version 3.5.x and older. Futhermore the performance of that macro iss very bad. Use is with care.

## @param macroname:title=Macro Name|type=string
 
#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)
   
## the pageManager gives you access to the pages
#set($pageManager =$containerContext.getComponent('pageManager')) 
 
## the spaceManager gives you access to the spaces
#set($spaceManager =$containerContext.getComponent('spaceManager')) 
#set($macroNameSplit = $parammacroname.split(",") ) 

#foreach( $space in $spaceManager.getAllSpaces() )   
 
    &lt;ul&gt;
    #foreach( $page in $pageManager.getPages( $space, true) )   
        #foreach( $macroName in $macroNameSplit )   
            #if( $page.content.contains("{$macroName" ) )
               &lt;li&gt;&lt;a href="$req.contextPath$page.urlPath"&gt;$space.key:$page.title  &amp;rarr; $macroName&lt;/a&gt;&lt;/li&gt;
            #end
        #end
    #end
    &lt;/ul&gt;
#end

This widget could not be displayed.

Using:

macroName: Table-of-Contents*

or any variation of this name/format doesn't find the TOC macro. It works perfectly well on single words, but not at all on multi-worded titles.

We're using 4.3.7. Cheers.

In the latest Confluence upgrades, you can no longer search macroName:JIRA Issues - it only locates those pages that have JIRA Issue

I submitted a support ticket and was told that this wasn't a bug as this was an unintended release of a feature. So, since it was not intended to be released, any issues are not bugs.

I've just tried this again in 5.4.3 Download and it still works in the way I've described above.

So: macroName: Code-Block* - doesn't find the macro (though it does find other things).

However: macroName: code* - finds all pages using the Code Block macro.

Cheers.

More info on this.

When I started searching it was from the global search field. However, I've also tried this in specific spaces AND in sets of sub-pages that use the Page Tree Search macro.

This means you can run the search on a very specific set of pages. HTHs.

Cheers.

This widget could not be displayed.

Here's a macro that gets all macros used on all pages in a space. You can modify it to suit your needs (such as replacing the macroNames list with a single macro.

## Macro title: Macro Usage Report
## Developed by: Matthew J. Horn
## Date created: 11/12/13
## This macro takes no parameters
## @noparams

## Get a list of User Macros
#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($macroManager = $containerContext.getComponent('userMacroLibrary'))
#set($macroMetadataManager = $containerContext.getComponent('macroMetadataManager'))
#set($macroNames = $macroManager.getMacroNames())

## Get the ExcerptHelper (probably not supposed to be used for getting all macros, but it works)
#set($eHelper = $containerContext.getComponent('excerptHelper'))

## Get a list of pages in the space
#set ( $targetSpace = $spaceManager.getSpace("demo") )
#set ( $allPagesInSpace = $pageManager.getPages($targetSpace, true) )

## List all macro names
&lt;h3&gt;Macro names&lt;/h3&gt;
&lt;hr/&gt;
#foreach($name in $macroNames)
  $name, 
#end

## Iterate over each page and check if each of the macros in macroNames is used on that page
&lt;h3&gt;Macro Usage&lt;/h3&gt;
&lt;hr/&gt;
&lt;table&gt;
  &lt;tr&gt;&lt;th&gt;Macro&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;th&gt;Page (isValid) (parameters)&lt;/th&gt;&lt;/tr&gt;
  #foreach ($name in $macroNames) 
    &lt;tr&gt;
      &lt;td&gt;$macroMetadataManager.getMacroMetadataByName($name).getTitle().getKey() ($name)&lt;/td&gt;
      &lt;td&gt;$macroMetadataManager.getMacroMetadataByName($name).getDescription().getKey()&lt;/td&gt;
      &lt;td&gt;
      #foreach ($page in $allPagesInSpace)  ## $page is of type Page
        #if ($eHelper.getMacroDefinition($page, $name))
          &lt;a href="$page.getUrlPath()"&gt;$page.getTitle()&lt;/a&gt; ($eHelper.getMacroDefinition($page, $name).isValid()) ($eHelper.getMacroDefinition($page, $name).getParameters())&lt;br/&gt;          
        #end
      #end
      &lt;/td&gt;
    &lt;/tr&gt;
  #end
&lt;/table&gt;

Matthew

How do I use this please?

I added this Macro to user Macros and then created a page with this macro added in. I still do not get the list of Macros used on the space. Any ideas? I am using COnfluence 5.1.1

This is nice, but it should be clear, this only is for user macros.

This widget could not be displayed.

bingo!

Gavin's query works!

Thanks to all for the help!

This widget could not be displayed.

Hello,

Most of these searches seem to be for searching the entire confluence wiki for a macro. What I would like is when editing a page, I would like to jump to the next instance of the macro while I am editing the page. Kind of like CTRL+F but instead of searching for text, search for a macro.

I have tried inserting macroName: Note* into the "Find" field when pressing CTRL+F but it did not seem to work. Any suggestions?

This widget could not be displayed.

Well that's not very helpful is it?

This widget could not be displayed.

Hi,

Any idea when this will be supported again in a latest version of Confluence? Is there a feature request already on this? Thanks. Pat

Pat,

See my comments above, are they helpful?

Cheers.

Hi Mikc, Kind of helps. Here's our scenario we are looking for a resolution or workaround if you know of one. If someone leaves the company, we'd like to be able to find references to them as used in macros such as the user-profile macro, so we can clean things up on pages. We have a work instruction for doing that, but the work instruction steps don't work anymore: we used to be able to do that with wiki markup but not in the new HTML5 format of Confluence. Any ideas? Thanks, Pat

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

399 views 4 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you