There's a wonderful thread over here (How can i find pages on which a macro is used, programmatically?) that discusses analysis of Confluence instance and explains how to find all pages that use macros installed on the instance.
This involves using adminstration console in Confluence in order to enumerate all macros registered in the instance.
However, it doesn't deep further into details on listing all pages that use specific macros in a specific Confluence. For example, I don't have administrative access to Confluence administration facilities, and control over my space is all I have.
I would like to run a kind of editorial analysis against the space in order to find out on what pages in the space specific macros are used.
I managed to mofidy the original code provided by @Davin Studer to work for a specific space name and for a single macro name. But I can't figure out how to modify the script to work on a collecton of macros.
Since I don't have administrative access to adminstration facilities, the admin console, whatsoever, I am using the modified code by pasting it inside the Markdown plugin that I insert on a Confluence page.
Here's the modified script:
<script type="text/javascript">
//The script only works on fields with a single value...
var macroObjects = {
'name': ['info'],
'title' : ['Info']
}
///////////////////////////////////////////////////////
// Can't manage to work it with multiple macro names
///////////////////////////////////////////////////////
/* var macroObjects = [
{
'name': ['info'],
'title' : ['Info']
},
{
'name': ['ui-text-box'],
'title': ['UI Text Box']
}
]; */
var queue = {
macros: [macroObjects],
current: 0,
start: function () {
this.macros.sort(compare);
this.current = 0;
this.next();
},
next: function () {
if (this.current >= this.macros.length) {
AJS.$('#queryStatus span').removeClass('aui-lozenge-current');
AJS.$('#queryStatus span').addClass('aui-lozenge-success');
AJS.$('#queryStatus span').text('Report Complete');
AJS.tablessortable.setTableSortable(AJS.$('#macroUsageReport table'));
return null;
}
else {
this.current += 1;
lookupMacro(this.macros[this.current - 1]);
}
}
};
function lookupMacro(macro) {
var html = '';
var searchURL = '';
AJS.$('#queryStatus span').text('Getting counts for macro: ' + macro.title);
searchURL = '/wiki/rest/searchv3/1.0/search?where=my_space_name&spaceSearch=true&queryString=macroName:' + encodeURIComponent(macro.name);
AJS.$.ajax( {
type: 'GET',
url: searchURL,
dataType: "json",
success: function(data) {
if(data.total > 0) {
html = '<tr>';
html += ' <td class="confluenceTd">' + macro.title + '</td>';
html += ' <td class="confluenceTd">' + macro.name + '</td>';
html += ' <td class="confluenceTd">' + data.total + '</td>';
html += ' <td class="confluenceTd"><a href="/wiki/dosearchsite.action?where=my_space_name&spaceSearch=true&queryString=macroName:' + encodeURIComponent(macro.name) + '" target="_blank">Show all pages</a></td>';
html += '</tr>';
}
AJS.$('#macroUsageReport table tbody').append(html);
queue.next();
},
error: function (x, y, z) {
AJS.$('#queryStatus span').removeClass('aui-lozenge-current');
AJS.$('#queryStatus span').addClass('aui-lozenge-error');
AJS.$('#queryStatus span').text('Error getting counts for macro:' + macro.title);
}
} );
}
function compare(a, b) {
if (a.title < b.title) {
return -1;
}
if (a.title > b.title) {
return 1;
}
return 0;
}
AJS.toInit(function() {
queue.start();
} );
</script>
<div id="queryStatus">
<span class="status-macro aui-lozenge aui-lozenge-current">
</span>
</div>
<div id="macroUsageReport">
<table class="confluenceTable">
<thead>
<tr>
<th>Macro title</th>
<th>Macro name</th>
<th>Found times</th>
<th>Source page</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
The above script only works for a single macro at a time.
If I define the set of macros that I'd like to scan my space for as
var macroObjects = {
'name': ['info'],
'title' : ['Info']
}The script returns a page with stats for the macro known as info but doesn't work if I define a dictionary with two macros: info and ui-text-box.
var macroObjects = [
{
'name': ['info'],
'title' : ['Info']
},
{
'name': ['ui-text-box'],
'title': ['UI Text Box']
}
];
I am not a developer, just wanting to clean up my space so that it uses only a single type of the admonotion blocks.
I'd apreciate if someone could help me to make this code run for a set of macro names.
Thank you in advance.