Modul:Viz

Dobrý den, přišli jste sem a hledáte význam slova Modul:Viz. V DICTIOUS najdete nejen všechny slovníkové významy slova Modul:Viz, ale dozvíte se také o jeho etymologii, charakteristice a o tom, jak se říká Modul:Viz v jednotném a množném čísle. Vše, co potřebujete vědět o slově Modul:Viz, najdete zde. Definice slova Modul:Viz vám pomůže být přesnější a správnější při mluvení nebo psaní textů. Znalost definiceModul:Viz, stejně jako definice dalších slov, obohacuje vaši slovní zásobu a poskytuje vám více a lepších jazykových zdrojů.

Modul Viz je užíván šablonou: Šablona:Viz. V šabloně je bližší nápověda; na diskuzní stránce šablony je odpovídající diskuze. K modulu bylo hlasování: Wikislovník:Hlasování/Zavedení modulových seznamů pro šablonu Viz.


local p = {}

local replacementTable = mw.loadData( 'Modul:Viz/Replacements' )

local function getArgNums(pargs, prefix)
    -- Returns an ordered table containing the numbers (>0) of the arguments
    -- that exist for the specified prefix. Includes 0 if prefix without number
    -- is used as argument. For example, if the prefix was 'seznam', and
    -- 'seznam1', 'seznam', and 'seznam5' exist, it would return {0, 1, 5}.
    local nums = { }
    if pargs then table.insert(nums, 0) end
    for k, v in pairs(pargs) do
        local num = tostring(k):match('^' .. prefix .. '(%d*)$')
        if num then table.insert(nums, tonumber(num)) end
    end
    table.sort(nums)
    return nums
end

local function canonicalizeTitle(title)
	local replacementRegEx = ""
	local regexBuilder = {}
	local idx = 0
	for key, _ in pairs( replacementTable ) do
		idx = idx + 1
		regexBuilder = (key == '-' or key == '%' or key == '^') and ('%' .. key) or key
	end
	replacementRegEx = ""
	return mw.ustring.gsub( mw.ustring.lower( title ), replacementRegEx, replacementTable )
end

local function normalizeChar(s)
	-- např. "Č(…)" → c , "fi(…)" → "fi"
	return mw.ustring.lower(mw.ustring.toNFKD(mw.ustring.sub(mw.ustring.toNFD(s), 1, 1)))
end

function p.viz(frame)
	pargs = frame:getParent().args
	local title = mw.title.getCurrentTitle()
	local items = {}
	local result = ""
	local listnums = getArgNums(pargs, 'seznam')
	if not (pargs or listnums) then		-- no params, guess the list name
		table.insert( listnums, 0 )
		result = result .. "]"
	end

	for k, num in ipairs( listnums ) do 		--include lists
		local adr = "Module:Viz/"
		if num == 0 then						--unnumberd guessed list
			if pargs then				--unnumberd
				adr = adr .. pargs
			else								--guess
				adr = adr .. canonicalizeTitle( title.text )
			end
		else
			adr = adr .. pargs
		end

		local exists, list = pcall(require, adr)	--read items from existing list
		if exists then
			for i, item in ipairs( list ) do		--and add them
				if item ~= title.fullText and item ~= "" then		--if not empty or identical with the page
					s = "]"
					for j, link in ipairs( items ) do	--or already included
						if s == link then
							s = nil
							result = result .. "]"
						end
					end
					table.insert(items, s)
				end
			end
			result = result .. "]"
		else
			result = result .. "]"
		end
 	end

	for i, arg in ipairs(pargs) do		--include single items
		if arg ~= title.fullText then
			s = "]"
			for j, link in ipairs( items ) do
				if s == link then
					s = nil
					result = result .. "]"
				end
			end
			table.insert(items, s)
		else
			result = result .. "]"
		end
	end

	if #items == 0 then
		result = result .. "]"
	else
		result = result .. "''Možná hledáte'' " .. mw.text.listToText( items, ", ", " ''nebo'' ")
		if result:sub(-3,-3) ~= "." then result = result .. "." end
	end
	return result
end
 
return p