Module:About-distinguish

"This page is about … It is not to be confused with …"

{{About-distinguish}} is a template for noting other uses when there could be confusion with another topic.

  • {{about-distinguish|USE1|PAGE1}}Lua error at line 68: attempt to index field 'wikibase' (a nil value).
  • {{about-distinguish|USE1|PAGE1|PAGE2}}Lua error at line 68: attempt to index field 'wikibase' (a nil value).
  • {{about-distinguish|USE1|PAGE1{{!}}DISPLAY-TEXT|PAGE2#SECTION|PAGE3}}Lua error at line 68: attempt to index field 'wikibase' (a nil value).

For cases requiring custom text, use {{about-distinguish2}} instead:

  • {{about-distinguish-text|USE1|TEXT}}Lua error at line 68: attempt to index field 'wikibase' (a nil value).

If the page's Wikidata item has the property of being an instance of "human", then the template will try to replace "It" in "It is not to be confused with" with a more appropriate pronoun, based on the value of the "sex or gender" property of the item.

<templatedata> { "params": { "1": { "label": "USE (what this page is about)", "description": "This is shown for the thing saying 'This page is about ...'", "type": "string", "required": true }, "2": { "label": "PAGE1", "description": "First page to be shown in the 'Not to be confused with PAGE1' text. Enter the page name (and section)", "example": "PAGE1", "type": "wiki-page-name", "required": true }, "3": { "label": "PAGE2", "description": "Another thing that the subject of this page is not to be confused with", "type": "wiki-page-name" }, "4": { "label": "PAGE3", "description": "Yet another thing that the subject of this page is not to be confused with", "type": "wiki-page-name" } }, "description": "template for noting other uses when there could be confusion with another topic. For a version with custom text instead of links to other pages, see Template:about-distinguish-text", "format": "inline" } </templatedata>


local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments --initialize lazily
local mTableTools = require('Module:TableTools')
local checkType = require('libraryUtil').checkType
local p = {}

function p.aboutDistinguish (frame)
	mArguments = require('Module:Arguments')
	local args = mArguments.getArgs(frame)
	return p._aboutDistinguish(args)
end

function p.aboutDistinguishText (frame)
	mArguments = require('Module:Arguments')
	local args = mArguments.getArgs(frame)
	return p._aboutDistinguish(args, {formatted = false})
end

function p._aboutDistinguish(args, options)
	-- Type checks and defaults
	checkType('_aboutDistinguish', 1, args, 'table')
	if not args[1] then
		return mHatnote.makeWikitextError(
			'no about topic supplied',
			'Template:About-distinguish',
			args.category
		)
	end
	if not args[2] then
		return mHatnote.makeWikitextError(
			'no page to be distinguished supplied',
			'Template:About-distinguish',
			args.category
		)
	end
	checkType('_aboutDistinguish', 2, options, 'table', true)
	options = options or {}
	local defaultOptions = {
		defaultPageType = 'page',
		namespace = mw.title.getCurrentTitle().namespace,
		pageTypesByNamespace = {
			[0] = 'article',
			[14] = 'category'
		},
		sectionString = 'section',
		formatted = true
	}
	for k, v in pairs(defaultOptions) do
		if options[k] == nil then options[k] = v end
	end

	-- Set pieces of initial "about" string
	local pageType = (args.section and options.sectionString) or
		options.pageTypesByNamespace[options.namespace] or
		options.defaultPageType
	args = mTableTools.compressSparseArray(args)
	local about = table.remove(args, 1)

	--Get pronoun from Wikidata. Really basic, but it should work.
	local pronouns = {
		['female'] = 'She is',
		['transgender female'] = "She is",
		['male'] = 'He is',
		['transgender male'] = 'He is',
		['default'] = 'They are'
	}
	local wde = mw.wikibase.getEntity()
	local p31 = (wde and wde:formatPropertyValues('P31').value) == 'human'
	local p21 = wde and wde:formatPropertyValues('P21').value
	local pronoun = p31 and (pronouns[p21] or pronouns['default']) or 'It is'

	--Assemble everything together and return
	local text = string.format(
		'This %s is about %s. %s not to be confused with %s.',
		pageType,
		about,
		pronoun,
		mHatlist.orList(args, options.formatted)
	)
	return mHatnote._hatnote(text)
end

return p