Documentation icon دستاویز [تخلیق]
local mHatnote = require('Module:Hatnote')
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
--Two parameters, args and options, each tables:
--  * args: can be empty or nil, in which case the defaults kick in.
--    Otherwise assumed to be a table of unbracketed page strings, no table gaps
--  * options: must not be nil; it must have in a "defaultPage" or "title" option,
--    since this function doesn't use a frame object to do the defaulting itself.
--    Summary of options available:
--      * defaultPage: sets full default "other uses" target; overrides title and disambiguator
--      * title: sets title assumed that gets the suffix added
--      * disambiguator: sets default text appearing in parens, defaults to "disambiguation"
--      * otherText: allows setting more "other" options, defaults to "uses"
function p._otheruses(args, options)
	checkType('_otheruses', 1, args, 'table', true)
	if not args then args = {} end
	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
			(options.title .. '  (' .. (options.disambiguator or 'ضد ابہام') .. ')')
		}
	end
	local forOther = 'دیگر استعمالات ' .. (options.otherText or 'کے لیے') .. '، '
	local see = 'دیکھیے ' .. mw.text.listToText(mHatnote.formatPages(unpack(args))) .. "۔"
	local text = forOther .. see
	
	return mHatnote._hatnote(text)
end

return p