Modul:Textinfo: Porovnání verzí

Z Wikizdrojů, volně dostupné knihovny
Smazaný obsah Přidaný obsah
- lokální monitoring nahrazený sdíleným
Shlomo (diskuse | příspěvky)
+OSN XXI
Řádek 264: Řádek 264:
["Dvacátýprvý"] = {
["Dvacátýprvý"] = {
1904,
1904,
{ "35-otto" }
{ "35-otto", "53-otto" }
},
},
["Dvacátýdruhý"] = {
["Dvacátýdruhý"] = {

Verze z 11. 9. 2017, 06:23

Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Textinfo

-- @brief
--  Backend for {{Textinfo}}.
-- 
-- @author
--  [[meta:User:Danny B.]]
local _module = {}
----------------------------------------


-- @brief
--  Creates the iterator for table sorted by its keys.
-- 
-- @param
--  tbl Table to be sorted
-- 
-- @return
--  Iterator Table sorted by keys
function kpairs( tbl )
	local keys = {}
	
	for key in pairs( tbl ) do
		table.insert( keys, key )
	end
	table.sort( keys, function ( a, b )
		if type( a ) == type( b ) then
			return a < b
		else
			return type( a ) < type( b )
		end
	end
	)
	
	local i = 0
	local iterator = function ()
		i = i + 1
		if keys[i] == nil then
			return nil
		else
			return keys[i], tbl[keys[i]]
		end
	end
	
	return iterator
end


_module.authorPrefix = "Autor:"
_module.refPattern = "\127'\"`UNIQ%-%-ref+%-%x%x%x%x%x%x%x%x%-QINU`\"'\127"


function _module._getLinkType( value )
	
	local output = "odkaz"
	local prefix = ""
	local _
	
	_, _, value = mw.ustring.find( value, "(%[%[.*%]%])" )
	
	if mw.ustring.sub( value, 3, mw.ustring.len( _module.authorPrefix ) + 2 ) == _module.authorPrefix then
		output = output .. " Autor"
		prefix = _module.authorPrefix
	end
	
	output = output .. _module._checkLink( value, prefix )
	
	return output
	
end


function _module._checkLink( value, prefix )
	
	local output = ""
	
	if mw.ustring.find( value, "|" ) ~= nil then
		output = output .. " s textem - "
		if mw.ustring.match( value, "%[%[" .. prefix .. "([^|]*)|%1%]%]" ) ~= nil then
			output = output .. "stejný"
		else
			output = output .. "různý"
		end
	end
	
	return output
	
end


function _module._replaceLink( value )
	
	return mw.ustring.gsub( value, "%[%[.*%]%]", "⌂" )
	
end


-- @brief
--  Monitors the "AUTOR", "AUTOR2" & "PŘELOŽIL" parameters.
-- 
-- @param
--  frame The current frame object
-- 
-- @return
--  Preprocessed wikitext
function _module.monitorAuthors( frame )
	
	if mw.title.getCurrentTitle().namespace ~= 0 then
		return
	end
	
	local output = ""
	local moduleArgs = frame.args
	
	local valueType = ""
	local variableName = mw.text.trim( moduleArgs[1] or "" )
	local value = mw.text.trim( moduleArgs[2] or "" )
	
	value = mw.ustring.gsub( value, "[<>\n]", { ["<"]="⧀", [">"]="⧁", ["\n"]="⏎" } )
	
	if value == "" then
		valueType = "(nevyplněno)"
	elseif value == "neuveden" then
		valueType = "neuveden"
	elseif value == "neznámý" then
		valueType = "neznámý"
	elseif mw.ustring.match( value, "%]%].*%[%[" ) ~= nil then
		local n = 1
		for _ in mw.ustring.gmatch( value, "%]%].-%[%[" ) do
			n = n + 1
		end
		valueType = "více odkazů/" .. n
	elseif mw.ustring.match( value, "^%[%[.*%]%]$" ) ~= nil then
		valueType = valueType .. _module._getLinkType( value )
	elseif mw.ustring.match( value, "^%[%[.*%]%]" .. _module.refPattern .. "$" ) ~= nil then
		valueType = _module._getLinkType( value ) .. " + ref"
	elseif mw.ustring.match( value, "^%[%[.*%]%].*" ) ~= nil then
		valueType = _module._getLinkType( value ) .. " + plaintext/" .. _module._replaceLink( value )
	elseif mw.ustring.match( value, ".*%[%[.*%]%]$" ) ~= nil then
		valueType = "plaintext + " .. _module._getLinkType( value ) .. "/" .. _module._replaceLink( value )
	elseif mw.ustring.match( value, ".*%[%[.*%]%]" .. _module.refPattern .. "$" ) ~= nil then
		valueType = "plaintext + " .. _module._getLinkType( value ) .. " + ref"
	elseif mw.ustring.match( value, ".*%[%[.*%]%].*" ) ~= nil then
		valueType = "plaintext + " .. _module._getLinkType( value ) .. " + plaintext/" .. _module._replaceLink( value )
	elseif mw.ustring.match( value, "^[^%[%]]*" .. _module.refPattern .. "$" ) ~= nil then
		valueType = "plaintext + ref"
	else
		local titleObject = mw.title.new( _module.authorPrefix .. value )
		-- expensive++
		if titleObject then
			if titleObject.exists then
				valueType = "plaintext autor"
				if titleObject.isRedirect then
					valueType = valueType .. " redirect"
				end
			else
				valueType = "plaintext/" .. value
			end
		else
			valueType = "nerozeznáno"
		end
	end
	
	output = string.format( "[[Kategorie:Monitoring:Textinfo/%s/=%s]]", variableName, valueType )
	
	output = frame:preprocess( output )
	
	return output
	
end


-- @brief
--  Monitors the "ZDROJ" parameter of Ottův slovník naučný.
-- 
-- @param
--  frame The current frame object
-- 
-- @return
--  Preprocessed wikitext
function _module.monitorSourceOsn( frame )
	
	if mw.ustring.match( mw.title.getCurrentTitle().text, "^Ottův slovník naučný" ) then
		
		local osnSources = {
			["První"] = {
				1888,
				{ "15-otto" }
			},
			["Druhý"] = {
				1889,
				{ "07-otto", "34-otto" }
			},
			["Třetí"] = {
				1890,
				{ "00-otto", "33-otto" }
			},
			["Čtvrtý"] = {
				1891,
				{ "25-otto" }
			},
			["Pátý"] = {
				1892,
				{ "22-otto", "55-otto" }
			},
			["Šestý"] = {
				1893,
				{ "19-otto", "51-otto" }
			},
			["Sedmý"] = {
				1893,
				{ "11-otto", "27-otto" }
			},
			["Osmý"] = {
				1894,
				{ "14-otto", "48-otto" }
			},
			["Devátý"] = {
				1895,
				{ "08-otto", "09-otto", "26-otto" }
			},
			["Desátý"] = {
				1896,
				{ "02-otto", "38-otto" }
			},
			["Jedenáctý"] = {
				1897,
				{ "04-otto", "10-otto", "23-otto" }
			},
			["Dvanáctý"] = {
				1897,
				{ "30-otto", "44-otto" }
			},
			["Třináctý"] = {
				1898,
				{ "17-otto" }
			},
			["Čtrnáctý"] = {
				1899,
				{ "00-stud", "42-otto" }
			},
			["Patnáctý"] = {
				1900,
				{ "28-otto" }
			},
			["Šestnáctý"] = {
				1900,
				{ "01-otto", "29-otto", "32-otto" }
			},
			["Sedmnáctý"] = {
				1901,
				{ "40-otto", "50-otto" }
			},
			["Osmnáctý"] = {
				1902,
				{ "01-stud", "31-otto", "56-otto" }
			},
			["Devatenáctý"] = {
				1902,
				{ "37-otto", "57-otto" }
			},
			["Dvacátý"] = {
				1903,
				{ "13-otto" }
			},
			["Dvacátýprvý"] = {
				1904,
				{ "35-otto", "53-otto" }
			},
			["Dvacátýdruhý"] = {
				1904,
				{ "16-otto", "36-otto" }
			},
			["Dvacátýtřetí"] = {
				1905,
				{ "47-otto" }
			},
			["Dvacátýčtvrtý"] = {
				1906,
				{ "21-otto", "24-otto", "39-otto" }
			},
			["Dvacátýpátý"] = {
				1906,
				{ "12-otto" }
			},
			["Dvacátýšestý"] = {
				1907,
				{ "41-otto" }
			},
			["Dvacátýsedmý"] = {
				1908,
				{ "20-otto", "43-otto" }
			}
		}
		
		local output = ""
		local moduleArgs = frame.args
		
		local value = mw.text.trim( moduleArgs[1] or "" )
		
		if mw.ustring.match( value, "https?://" ) ~= nil then
			
			if mw.ustring.match( value, "https?://.*https?://" ) ~= nil then
				
				output = "[[Kategorie:Monitoring:Textinfo/ZDROJ/=OSN-(více URL)]]"
				
			else
				
				local dil, rok, idNum, idStr = mw.ustring.match( value, "''Ottův slovník naučný.'' (.-) díl\..-(%d%d%d%d).-ottvslovnknauni(%d%d)(%l%l%l%l)goog#page/n%d-" )
				
				if dil then
					local mode = mw.ustring.match( value, "''Ottův slovník naučný.'' .- díl\..-%d%d%d%d.-ottvslovnknauni%d%d%l%l%l%lgoog#page/n%d-/mode/(%d)up" )
					if mode then
						output = string.format( "[[Kategorie:Monitoring:Textinfo/ZDROJ/=OSN-%s-%s-%s-%s-%s]]", dil, rok, idNum, idStr, mode )
					else
						output = string.format( "[[Kategorie:Monitoring:Textinfo/ZDROJ/=OSN-%s-%s-%s-%s]]", dil, rok, idNum, idStr )
					end
					if not osnSources[dil] then
						output = output .. "{{Chyba|text=OSN: Neznámý název dílu|kategorie=Opravit zdroj OSN hesla}}"
					else
						if tonumber( rok ) ~= osnSources[dil][1] then
							output = output .. "{{Chyba|text=OSN: Nekorespondující rok vydání k číslu dílu|kategorie=Opravit zdroj OSN hesla}}"
						end
						local validUrl = false
						for _, url in ipairs( osnSources[dil][2] ) do
							if idNum .. "-" .. idStr == url then
								validUrl = true
							end
						end
						if not validUrl then
							output = output .. "{{Chyba|text=OSN: Nekorespondující URL k číslu dílu|kategorie=Opravit zdroj OSN hesla}}"
						end
					end
				else
					output = "[[Kategorie:Monitoring:Textinfo/ZDROJ/=OSN-(nestandardní zápis)]]"
				end
				
			end
			
		else
			output = "[[Kategorie:Monitoring:Textinfo/ZDROJ/=OSN-(bez URL)]]"
		end
		
		output = frame:preprocess( output )
		
		return output
		
	end
	
end


-- @brief
--  Monitors the presence of tables in Ottův slovník naučný pages.
-- 
-- @param
--  frame The current frame object
-- 
-- @return
--  Preprocessed wikitext
function _module.monitorTablesOsn( frame )
	
	local titleObject = mw.title.getCurrentTitle()
	
	if mw.ustring.match( titleObject.text, "^Ottův slovník naučný" ) then
		
		local output = ""
		local n = 0
		
		for _ in mw.ustring.gmatch( titleObject:getContent(), "{|" ) do
			n = n + 1
		end
		
		if n > 0 then 
			output = string.format( "[[Kategorie:Monitoring:Heslo Ottova slovníku naučného obsahující wiki tabulku (%d×)]]", n )
		end
		
		n = 0
		
		for _ in mw.ustring.gmatch( titleObject:getContent(), "<table" ) do
			n = n + 1
		end
		
		if n > 0 then 
			output = string.format( "[[Kategorie:Monitoring:Heslo Ottova slovníku naučného obsahující HTML tabulku (%d×)]]", n )
		end
		
		output = frame:preprocess( output )
		
		return output
		
	end
	
end


----------------------------------------
return _module