It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Find pages that use certain macros/plugins

Stephan Haslinger May 31, 2012

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

25 votes
Answer accepted

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

Andre van der Elst Sep 13, 2012

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

Gavin Fowler Sep 24, 2012

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

Karie Kelly Feb 04, 2013

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!!!!

Brian K Sep 18, 2014

yeah, this is great!

Jorge Sep 28, 2014

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?

Laura Witty Feb 02, 2016

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

Derek Broughton Nov 27, 2017

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.

Bernd Schneider Nov 06, 2018

Hm. For me it seems to work sometimes, sometimes not. I can also find macroName: excerpt-include*. But searching for the "Page properties" macro doesn't work. Can the blank in the macro name be the problem?

I tried:

macroName: page*
macroName: page properties
macroName: "Page properties"
...

I found pages, but that seems to be not connected to what I search.

11 votes
Jason Hensler Sep 12, 2012

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

Jason Hensler Sep 12, 2012

Change "CONTENTID" to "CONTENT.CONTENTID"

Gavin Fowler Sep 12, 2012

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%')

Gavin Fowler Sep 12, 2012

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 :)

Andre van der Elst Sep 12, 2012

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.

Andre van der Elst Sep 12, 2012

FYI, this is on Confluence 4.3

John Price Aug 18, 2013

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?

6 votes
G Beraudo Feb 03, 2017

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

Lorenzo Babbage Oct 12, 2017

Very helpful!

Andrei Dec 15, 2017

best answer for current versions

Ed Kershenbaum Feb 07, 2019

Thanks!  Works great in Cloud Confluence as well!

https://YourNameGoesHere.atlassian.net/wiki/admin/pluginusage.action

Nilesh Raut Wednesday

Thanks! This is helpful.

2 votes
Hanis Suhailah May 31, 2012

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

Stephan Haslinger May 31, 2012

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

Gavin Fowler Sep 12, 2012

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.

2 votes

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

1 vote
mick davidson Aug 06, 2013

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.

Karie Kelly Aug 06, 2013

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.

mick davidson Jul 08, 2014

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.

mick davidson Jul 08, 2014

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.

1 vote
Matthew J. Horn Nov 11, 2013

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;

Nari Man Jul 01, 2014

Matthew

How do I use this please?

Nari Man Jul 01, 2014

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

David Hergert Feb 16, 2016

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

0 votes
Andre van der Elst Sep 12, 2012

bingo!

Gavin's query works!

Thanks to all for the help!

0 votes
Daniel Zimmerman May 27, 2013

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?

0 votes
mick davidson Aug 06, 2013

Well that's not very helpful is it?

0 votes
Pat Pigatti May 15, 2014

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

mick davidson Jul 08, 2014

Pat,

See my comments above, are they helpful?

Cheers.

Pat Pigatti Oct 06, 2014

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

859 views 0 19
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you