Jump to content

Module:Other uses: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Applied new mHatnote.disambiguate() helper instead of manual string concatenation
Updated from sandbox, plus a comment. Applies Module:Hatnote list to generate and format text
Line 1: Line 1:
local mHatnote = require('Module:Hatnote')
local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments --initialize lazily
local mArguments --initialize lazily
local mTableTools --initialize lazily
local mTableTools --initialize lazily
Line 27: Line 28:
args = {
args = {
options.defaultPage or
options.defaultPage or
mHatnote.disambiguate(options.title)
mHatnote.disambiguate(options.title, options.disambiguator)
}
}
end
end
--Generate and return hatnote
--should switch to using _forSee from [[Module:Hatnote list]] once that's out of alpha
local text = string.format(
local text = mHatlist.forSeeTableToString({{
use = options.otherText and "other " .. options.otherText or nil,
'For other %s, see %s.',
pages = args
(options.otherText or 'uses'),
}})
--should switch to using andList from [[Module:Hatnote list]] once that's out of alpha
mw.text.listToText(mHatnote.formatPages(unpack(args)))
)
return mHatnote._hatnote(text)
return mHatnote._hatnote(text)
end
end

Revision as of 20:10, 11 May 2016

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

-- Produces standard {{other uses}} implementation
function p.otheruses(frame)
	mArguments = require('Module:Arguments')
	mTableTools = require('Module:TableTools')
	local args = mTableTools.compressSparseArray(mArguments.getArgs(frame))
	local title = mw.title.getCurrentTitle().text
	return p._otheruses(args, {title=title})
end

-- Main generator
function p._otheruses(args, options)
	--Type-checks and defaults
	checkType('_otheruses', 1, args, 'table', true)
	args = args or {}
	checkType('_otheruses', 2, options, 'table')
	if not (options.defaultPage or options.title) then
		error('No default title data provided in "_otheruses" options table', 2)
	end
	if #args == 0 then
		args = {
			options.defaultPage or
			mHatnote.disambiguate(options.title, options.disambiguator)
		}
	end
	--Generate and return hatnote
	local text = mHatlist.forSeeTableToString({{
		use = options.otherText and "other " .. options.otherText or nil,
		pages = args
	}})
	return mHatnote._hatnote(text)
end

return p