Hello!
Is there a way to see which macros are used on specific pages and across the wiki? We’d like to swap out some of the macros we’re using (some Pro ones that we used in the migration from Confluence) but aren’t sure how widespread their adoption is across our site.
I found this snippet: https://snippets.xwiki.org/xwiki/bin/view/Extension/List%20All%20Macros but it doesn’t indicate which pages use the macros.
Thanks!
Simpel
January 23, 2025, 8:06am
2
I do find macros with:
doccontentraw:{{macroname
See there is no space after the colon and I have to use those {{ too to find it. But I find pages with rendered text „macroname“ too.
1 Like
NorSch
January 23, 2025, 10:43am
3
With programming rights you can do database search like
{{groovy}}
import com.xpn.xwiki.store.*
def maximumHits=100
def hibStore = services.component.getInstance(XWikiStoreInterface.class, "hibernate")
def ctx = xcontext.context
hibStore.checkHibernate(ctx)
def bTransaction = hibStore.beginTransaction(false, ctx)
def session = hibStore.getSession(ctx)
def statement = session.connection().createStatement();
def s="select xwd_title,xwd_fullname, xwd_content from xwikidoc where xwd_fullname not RLIKE '^XWiki' and xwd_content RLIKE '{{.*?}}' limit ${maximumHits}"
def rset = statement.executeQuery(s);
ignoreList = ['toc','info','velocity','groovy']
println "|=title|=full Name|=Macro"
while (rset.next()) {
m=rset.getString(3) =~ /\{\{([A-Za-z0-9]+)/
macroList=[]
m.each { if (!macroList.contains(it[1]) && !ignoreList.contains(it[1])) macroList<< it[1] }
if(macroList != []) {
print "| ${rset.getString(1)}| ${rset.getString(2)} "
print "| ${macroList.sort().join(" ")}\n"
}
}
hibStore.endTransaction(ctx, true)
{{/groovy}}
May be, if more than 100 hits are wanted it will last a bit.
Note this is pure “textual” search.
Norbert
1 Like
vmassol
January 23, 2025, 12:26pm
4
vmassol
January 23, 2025, 12:30pm
5
The problem ofc is that you need to know the syntax of the pages to perform a good search. Luckily in all known syntaxes, the syntax is {{xxx/}}
so it should work fine.
Another approach would be to add or enable debug logs inside the MacroManager or MacroTransformation class to know which macros are used at runtime. You’d also get the knowledge of how often they’re used (if you need that knowledge). See also https://dev.xwiki.org/xwiki/bin/view/Community/Debugging#HUsingByteman
NorSch
January 23, 2025, 2:00pm
6
I have not managed to formulate a search with a ‘regular expression’ in Solr.
Theoretically, it should work in Solr 4, for example in the form
doccontentraw:/regularexpression/
A simple search
#set($hql = ‘select doc.fullName from XWikiDocument doc where doc.fullName like “XWiki” ’)
#set ($commentResults = $xwiki.search($hql,10,0))
as they appear in
https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/velocityHqlExamples/
fails, if you replace ‘like’ with ‘rlike’.
The error message reads:
‘unexpected token: rlike near line 1 ...’
Obviously the keyword ‘rlike’ is unknown.
For this reason, I have resorted to a database query from the “root”.