Summary: Display a compliant Creative Commons License description from a wiki page
Version: 2012-09-19
Prerequisites: v2.0+
Status: Stable
License: GPL2+
Categories: Markup
Users: (view? / edit)

Questions answered by this recipe

How can I display a compliant Creative Commons License description from a wiki page?


Display a compliant Creative Commons License description from a wiki page

The Creative Commons License text is more complex than a few simple links. It contains additional name space items in order for to track things. This recipe makes a simple markup to display the license.


Add the following to local/config.php:

/*  Copyright (c) 2012-2015, Tamara Temple <>. 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version. See pmwiki.php for full details
    and lack of warranty.
// nice markup for CC licenses
// Usage: (:cc-license [type=(by|by-nc|by-nc-sa)] [title=<name of work>] [work=<URL of work>] [author=<name of author>] [authorurl=<link to author's contact page>] [permissions=<link to more permissions page>]:)
// Defaults:
//   type: by-nc-sa
//   title: $WikiTitle
//   work: $ScriptDirUrl
//   author: Anonymous
//   authorurl: blank
//   permissions: $ScriptDirUrl?n=Site.Permissions
Markup('creativecommonslicenses', /* unique markup identifier */
       '<links',		  /* don't want pmwiki to reprocess urls in text */
       '/\\(:cc-license\\s*?(.*?):\\)/ei', /* regex for markup recognition */
function cc_license_markup($parameters='')
  global $WikiTitle, $ScriptUrl;

  /* defaults */
  $license_strings = array('by' => 'Attribution',
			   'by-nc' => 'Attribution NonCommercial',
			   'by-nc-sa' => 'Attribution NonCommercial ShareAlike');
  $defaults = array('type'=>'by-nc-sa',
  $LicenseFmt = "<a rel='license' href='\$CCL_URL'>
  <img alt='\$CCL_LogoAlt' style='border-width:0' src='\$CCL_LogoImg' />
  <span xmlns:dct='' href='' property='dct:title' rel='dct:type'><a href='\$CCL_Work'>\$CCL_Title</a></span> by <a xmlns:cc='' href='\$CCL_AuthorUrl' property='cc:attributionName' rel='cc:attributionURL'>\$CCL_Author</a> is licensed under a <a rel='license' href='\$CCL_URL'>Creative Commons \$CCL_string 3.0 Unported License</a>. Permissions beyond the scope of this license may be available at <a xmlns:cc='' href='\$CCL_Permissions' rel='cc:morePermissions'>Permissions</a>.";

  $args = array_merge($defaults, ParseArgs($parameters));
  $replacements = array();
  $replacements['$CCL_Title'] = $args['title'];
  $replacements['$CCL_Work'] = $args['work'];
  // NOTE: more precise replacement must preced less precise replacement
  $replacements['$CCL_AuthorUrl'] = $args['authorurl'];
  $replacements['$CCL_Author'] = $args['author'];
  $replacements['$CCL_Permissions'] = $args['permissions'];
  $replacements['$CCL_string'] = (isset($license_strings[$args['type']]) ? $license_strings[$args['type']] : 'Unknown');
  $replacements['$CCL_URL'] = "{$args['type']}/3.0/";
  $replacements['$CCL_LogoImg'] = "{$args['type']}/3.0/80x15.png";
  $replacements['$CCL_LogoAlt'] = "Creative Commons Licence";
  $return_text = str_replace(array_keys($replacements),array_values($replacements),$LicenseFmt);
  return Keep($return_text);


No configuration to speak of...


To use, put the following in your wiki text:

(:cc-license type=(by|by-nc|by-nc-sa) title=<name of work> work=<URL of work> author=<name of author> authorurl=<link to author's contact page> permissions=<link to more permissions page>:)


The following parameters have defaults:

Whatever $WikiTitle is set to
Whatever $ScriptUrl is set to
nothing (blank)
link to {$ScriptUrl}?n=Site.Permissions


To use most of the defaults

(:cc-license author="Tamara Temple" authorurl="":)


Change log / Release notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also



See discussion at CreativeCommonsLicenseDisplay-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.