Module:CCLicense
This module processes Creative Commons parameter flags, constructs permissions and restrictions summaries, generates 32px icon strings, and passes metadata and attribution details to Template:License card.
Files are categorized based on the exact license names.
Usage
This module should not be directly used on content pages or files. Use Template:CCLicense or a specific wrapper template (such as
This file is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.
You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
) instead.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
zero / cc0 |
Boolean | false | Generates CC0 Universal Public Domain rights and metadata output. |
by |
Boolean | true (except CC0) | Adds Attribution requirement text (sets metadata attrreq="true").
|
nc |
Boolean | false | Adds NonCommercial restriction text (sets metadata nonfree="true").
|
sa |
Boolean | false | Adds ShareAlike condition text. |
nd |
Boolean | false | Adds NoDerivatives restriction text (removes "to remix" permission, sets metadata nonfree="true", and overrides ShareAlike).
|
version |
String | 4.0 | License version string. |
jurisdiction |
String | Ported country code (e.g., de, us).
| |
attr / attribution / author |
String | Custom attribution entity name passed as attr.
|
Emitted License Card Arguments
title: Formatted license link line (e.g.,This file is licensed under the [...] license.).description: Itemized breakdown of free uses and conditions.icons: Sequence of 32px formatted file links for CC badges.shortname/longname: Machine-readable strings for standard MediaWiki metadata viewers.attr: Passed through when present.
Testing
Run the unit test suite on Module:CCLicense/testcases using:
{{#invoke:CCLicense/testcases|run}}
local p = {}
local yesno = require('Module:Yesno')
function p.main(frame)
local args = frame:getParent().args
if not args.version and not args.by and not args.zero and not args.cc0 and not args.sa and not args.nc and not args.nd then
args = frame.args
end
-- Extract flags
local is_zero = yesno(args.zero or args.cc0, false)
-- Attribution defaults to true for all standard CC licenses unless explicitly disabled or CC0
local by = yesno(args.by, not is_zero)
local nc = yesno(args.nc, false)
local sa = yesno(args.sa, false)
local nd = yesno(args.nd, false)
local version = args.version or "4.0"
local jurisdiction = (args.jurisdiction or args.port or ""):lower():match("^%s*(.-)%s*$")
local attribution = (args.attr or args.attribution or args.author or ""):match("^%s*(.-)%s*$")
-- Strict Namespace Check: Categories apply strictly to NS 6 (File) non-doc pages
local title_obj = mw.title.getCurrentTitle()
local is_file_ns = (title_obj and title_obj.namespace == 6)
local is_doc = (title_obj and title_obj.isSubpage and title_obj.subpageText:lower() == "doc")
local should_cat = is_file_ns and not is_doc
-- Build license code, title, and icons with dark mode support (32px)
local code_parts = {}
local name_parts = {}
local icons = {'[[File:Cc.logo.circle.svg|32px|class=skin-invert-image|link=]]'}
if is_zero then
code_parts = {"zero"}
name_parts = {"CC0 1.0 Universal Public Domain Dedication"}
table.insert(icons, '[[File:Cc-zero_white.svg|32px|link=]]')
else
if by then
table.insert(code_parts, "by")
table.insert(name_parts, "Attribution")
table.insert(icons, '[[File:Cc-by_new_white.svg|32px|link=]]')
end
if nc then
table.insert(code_parts, "nc")
table.insert(name_parts, "NonCommercial")
table.insert(icons, '[[File:Cc-nc_white.svg|32px|link=]]')
end
if nd then
table.insert(code_parts, "nd")
table.insert(name_parts, "NoDerivatives")
table.insert(icons, '[[File:Cc-nd_white.svg|32px|link=]]')
elseif sa then
table.insert(code_parts, "sa")
table.insert(name_parts, "ShareAlike")
table.insert(icons, '[[File:Cc-sa_white.svg|32px|link=]]')
end
end
local code = table.concat(code_parts, "-"):lower()
local code_upper = table.concat(code_parts, "-"):upper()
-- Generate License URL
local url = ""
if is_zero then
url = "https://creativecommons.org/publicdomain/zero/1.0/"
else
local jur_path = (jurisdiction ~= "" and jurisdiction ~= "international" and jurisdiction ~= "unported")
and ("/" .. jurisdiction) or ""
url = string.format("https://creativecommons.org/licenses/%s/%s%s/", code, version, jur_path)
end
-- Construct Readable Names
local full_name = ""
local short_name = ""
if is_zero then
full_name = "CC0 1.0 Universal"
short_name = "CC0 1.0"
else
local jur_text = (jurisdiction ~= "" and jurisdiction ~= "unported")
and (" " .. jurisdiction:gsub("^%l", string.upper))
or (version == "4.0" and " International" or " Unported")
full_name = "Creative Commons " .. table.concat(name_parts, "-") .. " " .. version .. jur_text
short_name = "CC " .. code_upper .. " " .. version
if jurisdiction ~= "" and jurisdiction ~= "international" and jurisdiction ~= "unported" then
short_name = short_name .. " " .. jurisdiction:upper()
end
end
-- Title Parameter for License_card
local title_text = ""
if is_zero then
title_text = string.format("This work has been dedicated to the public domain under the [%s %s] Public Domain Dedication.", url, full_name)
else
title_text = string.format("This file is licensed under the [%s %s] license.", url, full_name)
end
-- Construct Detailed Description (Permissions and Restrictions)
local desc_parts = {}
if is_zero then
table.insert(desc_parts, "You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.")
else
table.insert(desc_parts, "You are free:")
local freedoms = {"* '''to share''' – to copy, distribute and transmit the work"}
if not nd then
table.insert(freedoms, "* '''to remix''' – to adapt the work")
end
table.insert(desc_parts, table.concat(freedoms, "\n"))
table.insert(desc_parts, "Under the following conditions:")
local conditions = {}
if by then
local attr_condition = "* '''attribution''' – You must give appropriate credit"
if attribution ~= "" then
attr_condition = attr_condition .. " to ''" .. attribution .. "''"
end
attr_condition = attr_condition .. ", provide a link to the license, and indicate if changes were made."
table.insert(conditions, attr_condition)
end
if nc then
table.insert(conditions, "* '''noncommercial''' – You may not use the material for commercial purposes.")
end
if sa and not nd then
table.insert(conditions, "* '''share alike''' – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.")
end
if nd then
table.insert(conditions, "* '''no derivatives''' – If you remix, transform, or build upon the material, you may not distribute the modified material.")
end
table.insert(desc_parts, table.concat(conditions, "\n"))
end
local description_text = table.concat(desc_parts, "\n")
-- Build Category Output using full_name
local category_markup = ""
if should_cat then
category_markup = string.format("\n[[Category:%s files]]", full_name)
end
-- Delegate rendering to Template:License_card
return frame:expandTemplate{
title = 'License card',
args = {
title = title_text,
description = description_text .. category_markup,
icons = table.concat(icons, " "),
shortname = short_name,
longname = full_name,
link = url,
linkreq = is_zero and "false" or "true",
attrreq = by and "true" or "false",
nonfree = (nc or nd) and "true" or "false",
attr = attribution ~= "" and attribution or nil
}
}
end
return p