Confluence Space Meta Data User Macro

As an alternative / addition to the bundled Space Details macro for Confluence:

Space Details

here’s a simple user macro which displays extra details about a Confluence Space such as number of pages, number of blog posts, total size of attachments, etc. which you may find useful for a Community Management Dashboard:

Space Meta Data

NB: I couldn’t figure out how to round to 2 decimal places for the attachment size in Velocity without Velocity MathTool, if you know how to do that please drop me a line via the comments ;-)

To create the user macro:

1. Login to Confluence as a Confluence Administrator
2.  Select Browse -> Confluence Admin
3. Select User Macros -> Create a new user macro
4. Enter the information as provided below:

Edit Space Meta Macro

Template:

## Macro title: Space Meta Data
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 03/05/2012
## Installed by: <your name>

## Macro to display information such as number of pages, number of blog posts, attachment size, etc. about a Space. 

## @noparams

## Get space details
#set ( $spaceName = $space.getName() )
#set ( $spaceKey = $space.getKey() )
#set ( $spaceHome = $space.getHomePage() )
#set ( $spaceCreator = $space.getCreatorName() )
#set ( $spaceCreationDate = $space.getCreationDate() )
#set ( $spaceDescription = $space.getDescription() )
#set ( $pageCount = $spaceManager.findPageTotal($space) )
#set ( $blogCount = $spaceManager.getNumberOfBlogPosts($space) )

## Get all pages in the current Space
#set ( $allPagesInSpace = $pageManager.getPages($space, true) )

## Reset total attachment file size
#set ( $totalAttachmentFileSizeForSpace = 0 )

## Reset total number of attachments
#set ( $totalAttachmentCount = 0 )

## Loop through all pages in the current Space
#foreach ($page in $allPagesInSpace)
  ## reset the attachment count for each page
  #set ( $pageAttachmentCount = 0 )
  ## reset the attachment file size total for each page
  #set ( $totalFileSizePerPage = 0 )
  ## get the attachments for each page
  #set ( $allAttachments = $page.getAttachments() )
  ## Loop through each attachment
  #foreach ($attachment in $allAttachments)
    ## Increment the attachment count for the page
    #set ( $pageAttachmentCount = $pageAttachmentCount + 1 )
    ## Sum the size of the attachments on the page
    #set ( $totalFileSizePerPage = $totalFileSizePerPage + $attachment.getFileSize() )
  #end
  ## End looping through attachments
  ## Increment total attachment count for the current Space
  #set ( $totalAttachmentCount = $totalAttachmentCount + $pageAttachmentCount )
  ## Sum the total size of attachments for the current Space
  #set ( $totalAttachmentFileSizeForSpace = $totalAttachmentFileSizeForSpace + $totalFileSizePerPage )
#end
## End looping through pages

## Convert attachment size to MBs
#set ( $attachmentSizeMb = ($totalAttachmentFileSizeForSpace / 1024.00) / 1024.00 )

## Display Space Details
<table class="confluenceTable">
  <tbody>
    <tr>
      <th class="confluenceTh">Name</th>
      <td class="confluenceTd">$spaceName</td>
    </tr>
    <tr>
      <th class="confluenceTh">Key</th>
      <td class="confluenceTd">$spaceKey</td>
    </tr>
    <tr>
      <th class="confluenceTh">Description</th>
      <td class="confluenceTd">$spaceDescription.getBodyAsString()</td>
    </tr>
    <tr>
      <th class="confluenceTh">Home Page</th>
      <td class="confluenceTd">#contentLink2($spaceHome true false)</td>
    </tr>
    <tr>
      <th class="confluenceTh">Created By</th>
      <td class="confluenceTd">#usernameLink($spaceCreator) ($action.dateFormatter.formatDateTime($spaceCreationDate))</td>
    </tr>
    <tr>
      <th class="confluenceTh">Number of Pages</th>
      <td class="confluenceTd">$pageCount</td>
    </tr>
    <tr>
      <th class="confluenceTh">Number of Blog Posts</th>
      <td class="confluenceTd">$blogCount</td>
    </tr>
    <tr>
      <th class="confluenceTh">Number of Attachments</th>
      <td class="confluenceTd">$totalAttachmentCount (including all versions)</td>
    </tr>
    <tr>
      <th class="confluenceTh">Total Size of Attachments</th>
      <td class="confluenceTd">$attachmentSizeMb MB</td>
    </tr>
  </tbody>
</table>

5. Click Save

You can then use the macro on a page by using:

{spacemeta}

Or select the macro from the Macro Browser via Insert -> Other Macros:

Insert Space Meta Data Macro

I Hope you find this useful. The source code is available on Bitbucket.

Related Links

Tips via Twitter for Confluence enterprise wiki

Got a Confluence tip? Tweet it now then see it in the Confluence docs.

Confluence Space Administrators – Remixed

A few weeks ago I blogged about how to write a Confluence user macro to list Space Administrators. The macro works, but is not ideal for implementations with a large user base as it loops through every user to find out if that user can administer the Space or not. This is a new version which loops through the permissions on the current Space and then lists the users and groups that can administer the Space – which should be a lot more performant than the previous version.

General instructions for creating the macro are the same as the previous post, but replace the Template with the following code:

## Macro title: Space Administrators
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 28/04/2012
## Installed by: <your name>

## Macro to list all users and groups with the permission to administer the current space.
## @noparams

<h1>Space Adminstrators</h1>
<p>The following users and groups have permission to administer the <strong>$space.getName()</strong> Space.</p>

<h2>Users</h2>

<table class="confluenceTable">
  <tr>
    <th class="confluenceTh">Space Administrators</th>
  </tr>

  #foreach ($permission in $space.getPermissions())
    #if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
      <tr>
        <td class="confluenceTd">#usernameLink($permission.getUserName())</td>
      </tr>
    #end
  #end
</table>

<h2>Groups</h2>

#foreach ($permission in $space.getPermissions())
  #if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
    #set ( $groupString = $permission.getGroup() )
    #set ( $groupObject = $userAccessor.getGroup($groupString) )
    #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )

    <h3>$groupString</h3>
    <table class="confluenceTable">
      <tr>
        <th class="confluenceTh">Space Administrators</th>
      </tr>

      #foreach ($member in $memberList)
        <tr>
          <td class="confluenceTd">#usernameLink($member)</td>
        </tr>
      #end
    </table>
  #end
#end

The macro loops through the permissions twice – once to pick up the users that have been given the administration permission directly, and a second time to pick up users that have inherited the permission by being a member of a group with the permission.

Using this macro will then give you the following:

Space Administrators

I hope you find it useful and if there are other ways of improving this macro please drop me a line via the comments.

Related Links

Tips via Twitter for Confluence enterprise wiki

Got a Confluence tip? Tweet it now then see it in the Confluence docs.

An Experiment with Dropbox and Google AdWords

The other weekend I ran an experiment with Google AdWords to see if I could max out my Dropbox referrals to get an extra 16GB of free storage using my free £75 AdWords voucher. This is the same hack that Vladik Rikhter blogged about back in September 2011; and with a ton of people doing the same following Vladik’s post I wanted to see if it still worked. Short answer: yes it does :-)

For those that don’t know what Dropbox is, it’s an online service for backing up, synching and sharing files and has clients for Web, Windows, OSX, Linux, iPhone, iPad, Android and Blackberry. The basic service gives you 2GB of storage for free (with paid plans offering more storage) and you can earn up to an extra 16GB of free storage through referrals (500MB per referral). If you want to sync files to have them available on multiple devices, or want to share files with other people it’s incredibly useful.

I just have the basic plan and had zero referrals before I started the AdWords campaign so needed 32 referrals to reach the 16GB maximum. I ran the campaign over the weekend of 14-15 April 2012, switching it off at around 6am on Monday 16 April 2012, and gained 59 referrals – more than enough for the extra 16GB of free storage.

The Figures

Ad Impressions: 21,141
Click Thru’s: 484
Click Thru Rate: 2.29%
Average Cost Per Click: £0.09
Total Ad Spend: £44.73

From the 484 click thru’s this generated the following numbers:

Total Joined Dropbox: 83
Total Installed Dropbox: 59
Total Ineligible: 1
Abandonment Rate: 28.91% (24 not installed / 83 joined)
Conversion Rate: 12.19% (59 installs / 484 click thru’s)
Cost Per Conversion: £0.79 (£44.73 ad spend / 59 installs)

NB: you only get the referral bonus if someone installs Dropbox after joining.

It’s the first time I’d used AdWords and the stats geek in me found the numbers really interesting. From running this short experiment you can see how online advertising costs could soon mount up and why targeted advertising to help increase that magic “conversion rate” is so appealing.

Related Links

List Blog Posts Confluence User Macro

Following on from my previous post on Creating a Blog Summary Page in Confluence here is a simple user macro which will list all of the blog posts in the current Confluence Space which were posted in the current month and the previous month, grouped by month.

List Blog Posts

To create the user macro:

1. Login to Confluence as a Confluence Administrator
2.  Select Browse -> Confluence Admin
3. Select User Macros -> Create a new user macro
4. Enter the information as provided below:

Edit Blog Post Macro

Template:

## Macro title: List Blog Posts
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option (No macro body)
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 13/04/2012
## Installed by: <your name>

## Macro to display blog posts for the current and previous months
## @noparams

#set ( $allBlogsInSpace = $pageManager.getBlogPosts($space, true) )

## get a calendar object for the current date
#set ( $currentDate = $action.dateFormatter.getCalendar() )

## Define an array of Month names
#set ( $monthArray = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] )

## set the current month
#set ( $currentMonthNum = $currentDate.get(2) )
#set ( $currentMonth = $monthArray.get($currentMonthNum) )

## Display posts for the current month
<h5>$currentMonth</h5>
#foreach($blog in $allBlogsInSpace)
  #if ($blog.getPostingMonth() == $currentMonth)
    #contentLink2($blog, true, false) $blog.getPostingDayOfMonth() $blog.getPostingMonth() $blog.getPostingYear()<br />
  #end
#end

## set the previous month
#set ( $previousMonthNum = $currentDate.get(2) - 1 )
#set ($previousMonth = $monthArray.get($previousMonthNum) )

## Display posts for the previous month
<h5>$previousMonth</h5>
#foreach($blog in $allBlogsInSpace)
  #if ($blog.getPostingMonth() == $previousMonth)
    #contentLink2($blog, true, false) $blog.getPostingDayOfMonth() $blog.getPostingMonth() $blog.getPostingYear()<br />
  #end
#end

5. Click Save

You can then use the macro on a page by using:

{listblogposts}

Or select the macro from the Macro Browser via Insert -> Other Macros:

List Blog Post Macro Browser

Adding this macro to my Blog Summary Page it now looks like:

Blog Summary Page

Hope you find this useful. The source code is available on Bitbucket.

Related Links

Tips via Twitter for Confluence enterprise wiki

Got a Confluence tip? Tweet it now then see it in the Confluence docs.

Confluence 4.2 is Here

Confluence NinjaAtlassian continue to iterate faster than a ninja in slippers with the release of Confluence 4.2 today; a mere 4 months since the release of Confluence 4.1 and just 7 months after Confluence 4.0 was unleashed on the world.

There have already been a few teaser blog posts detailing some of the new functionality in 4.2:

but here’s a look at what else is new.

Page Layouts

If you’re familiar with Confluence you’re probably familiar with the fun and games you could get into nesting {section} and {column} macros to try and bring some order to your pages – see one of my previous blog posts for an example. With Confluence 4.2 that pain is taken away with the introduction of predefined page layouts.

Page Layouts

Likes and Quick Comments

Confluence 4.2 also introduces Facebook style “Likes” to help encourage user engagement and identify popular content. Engagement is also encouraged via the new comment functionality which invites users to comment by displaying their profile picture and launching the comment dialogue with a single click.

Likes and Quick Comments

Popular Content and Personalised Email Summaries

Your users are flagging the content that they like and Confluence 4.2 makes it easy for them to stay in the loop with what’s hot with popular content on the Dashboard and personalised email summaries.

Popular Content Dashboard

Popular Content Email Summary

If you like what you’ve seen so far head on over to the official announcement to get the full details, or why not jump right in and download Confluence 4.2 today.

Related Links

S7RUCAW2VRKH