Szerkesztő:Pepo41/Homokozó/Modul:MCitlib

A Wikipédiából, a szabad enciklopédiából

-- Version 2020.05.31 require('Modul:No globals') local ds = require('Modul:Dátumszűrés') local nyksz = require('Modul:Homokozó/Pepo41/Nyelvkódszűrő')

local args = {} local used_args = {} local config = {} local lang = mw.getContentLanguage()

-- hibakeresésre szolgáló globális változó, ami tartalmazza az analízisre -- szolgáló üzeneteket, az alábbi --pop() függvény gyűjtögeti a tartalmát local ou = local oumax = 20 -- a tesztüzenetek számának maximuma local oumarad = oumax


local function pop(...) -- idézőjeles rész és bővítmények az ou számára

                          -- memóriatúllépést okozhat, csak teszteléshez

local list = {...} oumarad = oumarad - 1 -- előre csökkentjük, így mindig a maradék lehetséges --pop hívások számát mutatja if oumarad == 0 then return end -- hogy ne legyen memóriatúllépés for _, var in pairs(list) do ou = ou .. tostring(var) .. '\n ' mw.log(ou) end

end


local function isRoman(v) if type(v) ~= 'string' then -- római számok stringek return false end return ( v:match( '^[IVXLCDM]+$' ) ~= nil ) end

local hibavan = false local hiba_jelzes = {} local kategorizalas_van = false

local function error(kategorizalas_kell, about) -- Enclose errorMsg with -- Precondition: -- about -- string hibavan = true if kategorizalas_kell then kategorizalas_van = true end local r = about if type( about ) == 'string' then if #about == 0 then r = 'Lua-hiba' end else r = tostring( about ) end table.insert(hiba_jelzes, '' .. r .. '') end

local function getArgMain(names, le, suffix) for _, v in ipairs(names) do if suffix then v = v .. tostring(suffix) end used_args[v] = true if args[v] and args[v] ~= then if le and type(args[v]) == 'string' then -- lecsípjük az utolsó pontot vagy vesszőt return args[v]:gsub('[%.,]$', ) else return args[v] end end end return nil end

local function getArg(le, ...) -- itt eredetileg a frame nem paraméter -- Retrieve template argument -- Precondition: -- le: true értékkel jelzi, hogy levágható a paraméter végéről a felesleges vessző és pont -- ...: paraméternevek, az első megadott és nem üreset adja vissza

return getArgMain({...}, le) end

local function getArgMore(le, max, ...) local ret = {} local val = getArg(le, ...) if val then table.insert(ret, val) end for i = 2, max do val = getArgMain({...}, le, i) if val then table.insert(ret, val) end end return ret end

local function checkArgs() for n, v in pairs(args) do if not used_args[n] then local msg = 'CitLib: Nem használt paraméter: ' .. n mw.log(msg) mw.addWarning(msg) kategorizalas_van = true end end end

local function getConf(conf) local v = config[conf] return (v ~= and v) or nil end

local function urlencode(str) -- URL kódolása return (str :gsub('%s', '%%20') :gsub('"', '%%22') :gsub("'", '%%27') :gsub('<', '%%3c') :gsub('>', '%%3e') :gsub('%[', '%%5b') :gsub('%]', '%%5d') :gsub('{', '%%7b') :gsub('|', '%%7c') :gsub('}', '%%7d') ) end

-- Gets the display text for a wikilink like B or B gives B local function removewikilink( str ) return (str:gsub( '%[%[([^%[%]]*)%]%]', function (l) return l:gsub( '^[^|]*|(.*)$', '%1' ):gsub('^%s*(.-)%s*$', '%1'); end)) end


local OCinSoutput = setmetatable( {}, { __newindex = function(self, key, value) if value ~= nil and value ~= then rawset( self, #self+1, table.concat{ key, '=', mw.uri.encode( removewikilink( value ) ) } ); --> OCinSoutput[1],[2],[3]... dagad -- az egész konstrukció a rawset és a __newindex segítségével növeli e táblát a key value párokkal -- --pop('mit tesz a concat:', self[#self]); --> rft_val_fmt=info:ofi/fmt:kev:mtx:book end end } )


local function _citlib() local alkategoriak = {}

local cap, capaut, aut, tit, subtit, vol, ass, edi, red, red2, loc, loc2 local ann, pag, ser, sernr, isbn, misc, url, accd, aurl, archd, lan local alkategoriak_kellenek = getConf('alkategóriák kellenek') ----pop('Kellenek az alkategóriák??', alkategoriak_kellenek) -- igen, vagy nem a lehetséges válasz if alkategoriak_kellenek then if alkategoriak_kellenek == 'igen' then ----pop('Kellenek az alkategóriák', alkategoriak_kellenek) alkategoriak_kellenek = true else alkategoriak_kellenek = false end end

local sablon_kimenetek_kellenek = getConf('sablon kimenetek kellenek') -- kívánságra kikapcsolható ----pop('Sablon kimenetek kellenek?', sablon_kimenetek_kellenek) -- igen, vagy nem a lehetséges válasz if sablon_kimenetek_kellenek then if sablon_kimenetek_kellenek == 'igen' then ----pop('Kellenek az alkategóriák', alkategoriak_kellenek) sablon_kimenetek_kellenek = true else sablon_kimenetek_kellenek = false end else -- ha a getConf nil értékkel tért vissza sablon_kimenetek_kellenek = true end

cap = getArg(true, 'cap', 'fejezetcím') capaut = getArgMore(true, 3, 'capaut', 'fejezetszerző') aut = getArgMore(true, 3, 'szerző', 'aut') tit = getArg(true, 'cím', 'tit') subtit = getArg(true, 'alcím', 'subtit') vol = getArg(true, 'vol', 'kötet') ass = getArgMore(true, 3, 'ass', 'közreműködők') isbn = getArg(true, 'isbn') edi = getArg(true, 'edi', 'kiadás') loc = getArg(true, 'loc', 'hely') loc2 = getArg(true, 'loc2', 'hely2') red = getArg(true, 'red', 'kiadó') red2 = getArg(true, 'red2', 'kiadó2') ann = getArg(true, 'év', 'ann') --if ann then ann = string.gsub(ann, '[%[%]]', )end Pasztilla közlése szerint pag = getArg(true, 'oldal', 'pag') ser = getArg(true, 'ser', 'sorozat') sernr = getArg(true, 'sernr', 'sorozatszám') misc = getArg(true, 'egyéb', 'misc') url = getArg(false, 'url') accd = getArg(true, 'elér', 'accd') if accd then accd = string.gsub(accd, '[%[%]]', ) end aurl = getArg(true, 'archívurl', 'aurl') archd = getArg(true, 'archívdátum', 'archd') if archd then archd = string.gsub(archd, '[%[%]]', ) end lan = getArg(true, 'nyelvkód', 'lan')

-- fejezetszerzők összeállítása capautban if #capaut > 0 then capaut = table.concat(capaut, ' – ') .. ':' else capaut = nil end

-- fejezetcím local CoinS_cap if cap then CoinS_cap = cap end

-- szerzők összeállítása if #aut > 0 then for _, v in ipairs(aut) do OCinSoutput['rft.au'] = v end aut = table.concat(aut, ' – ') .. ':' else aut = nil end

--cím és alcím local CoinS_tit = nil if tit then tit = mw.text.trim(lang:ucfirst(tit)) else tit = '(cím?)' error(true, 'nincs elsődleges cím') table.insert(alkategoriak, 'Hibásan használt CitLib – cím nélkül') end ----pop('megkérdőjelezte a címet', tit) if subtit then subtit = lang:ucfirst(subtit) -- ha a cím végén kettőspont van, leszedjük, hogy ne legyen kettő egymás után tit = tit:gsub(':$', ) .. ': ' .. subtit end CoinS_tit = tit:gsub('%.$', ) if not tit:match('[%.%?!,\166]$') then tit = tit .. '.' end

tit = "" .. tit .. "" ----pop('cím in italic', tit)

if vol then CoinS_tit = CoinS_tit .. vol end

-- asszisztencia if #ass > 0 then ass = lang:ucfirst(table.concat(ass, '–')) .. '.' else ass = nil end

-- edi local CoinS_edi = nil if edi then CoinS_edi = edi edi = edi .. '.' end

local kiadas = local CoinS_loc, CoinS_red if loc then if loc2 then if red then if red2 then --loc,loc2,red,red2 kiadas = loc .. ': ' .. red .. '; ' .. loc2 .. ': ' .. red2 .. '.' CoinS_loc = loc ; CoinS_red = red else --loc,loc2,red,not red2 kiadas = loc .. '; ' .. loc2 .. ': ' .. red .. '.' end else if red2 then --loc,loc2,not red, red2 kiadas = loc .. ': (kiadó nélkül); ' .. loc2 .. ': ' .. red2 .. '.' CoinS_loc = loc2 ; CoinS_red = red2 else --loc,loc2,not red, not red2 kiadas = loc .. '; ' .. loc2 .. ': ' .. '(kiadó nélkül)' .. '.' end end else if red then if red2 then --loc,not loc2, red, red2 kiadas = loc .. ': ' .. red .. '; ' .. '(hely nélkül)' .. ': ' .. red2 .. '.' CoinS_loc = loc ; CoinS_red = red else --loc,not loc2, red, not red2 kiadas = loc .. ': ' .. red .. '.' CoinS_loc = loc ; CoinS_red = red end else if red2 then --loc,not loc2, not red, red2 kiadas = loc .. ': ' .. '(kiadó nélkül)' .. '; ' .. '(hely nélkül)' .. ': ' .. red2 .. '.' else --loc,not loc2, not red, not red2 kiadas = loc .. ': ' .. '(kiadó nélkül)' .. '.' end end end else if loc2 then if red then if red2 then --not loc,loc2, red,red2 kiadas = '(hely nélkül)' .. ': ' .. red .. '; ' .. loc2 .. ': ' .. red2 .. '.' CoinS_loc = loc2 ; CoinS_red = red2 else --not loc,loc2,red, not red2 kiadas = '(hely nélkül)' .. ': ' .. red .. '; ' .. loc2 .. ': ' .. '(kiadó nélkül)' .. '.' end else if red2 then --not loc,loc2, not red,red2 kiadas = loc2 .. ': ' .. red2 .. '.' CoinS_loc = loc2 ; CoinS_red = red2 else --not loc,loc2, not red,not red2 kiadas = loc2 .. ': ' .. '(kiadó nélkül).' end end else if red then if red2 then --not loc, not loc2, red,red2 kiadas = '(hely nélkül)' .. ': ' .. red .. ';' .. red2 .. '.' else --not loc, not loc2, red, not red2 kiadas = '(hely nélkül)' .. ': ' .. red .. '.' end else if red2 then --not loc, not loc2, not red,red2 kiadas = '(hely nélkül)' .. ': ' .. red2 .. '.' else --not loc, not loc2, not red, not red2

end end end end

-- év local CoinS_ann = nil if ann then local count = 0 -- kiskötőjelből nagy ann = ann:gsub('[%-]', '–') -- az évben csak számjegyek és nagykötőjel, valamint szögletes zárójelek maradhatnak ann, count = ann:gsub('[^%–%[%]%!0123456789]', ) if count > 0 then error(false, 'tiltott karakter az év paraméterben') table.insert(alkategoriak, 'Hibásan használt CitLib – tiltott karakter az év paraméterben') end ----pop('ev a gsubolása után', ann) CoinS_ann = ann end

-- oldal adatok local CoinS_pag = nil if pag then pag = (pag :gsub('-', '–') -- kiskötőjelből nagykötőjel :gsub('—', '–') -- hetvenkvirtesből nagykötőjel :gsub('%.', ) -- pontból üreset :gsub(',', '.,')) -- végül vesszőből pontot követő vesszőt CoinS_pag = pag pag = ' ' .. pag .. '. o.' end

-- sorozat kezelése local sernum_van_de_ser_nincs = false local CoinS_ser = nil local CoinS_sernr = nil if ser then CoinS_ser = ser ser = '= ' .. ser .. ', ' end if sernr ~= nil and ser == nil then sernr = '(sorozatszám?)' error(true, 'sorozatszám sorozat nélkül') table.insert(alkategoriak, 'Hibásan használt CitLib – sorozatszám sorozat nélkül') else if sernr then local proba_sernr = sernr:gsub('[^%dIVXLCDM]', ) if tonumber(proba_sernr) then CoinS_sernr = sernr sernr = sernr .. '.' elseif not isRoman(proba_sernr) then error(true, 'helytelen sorozatszám') table.insert(alkategoriak, 'Hibásan használt CitLib – helytelen sorozatszám') end end end

-- ISBN kezelése local CoinS_isbn = nil if isbn then ----pop('van isbn paraméter', isbn) local helyes, hiba_str, isbn_table helyes, isbn, hiba_str, isbn_table = require('Modul:CheckISBN').isISBN(isbn, true)

-- isbn = string.gsub(isbn_str, 'ISBN ([%dXx]+)', 'ISBN %1') CoinS_isbn = table.concat(isbn_table, ', ') table.insert(hiba_jelzes, hiba_str)

if helyes then ----pop('helyesek a paraméterek') else hibavan = true table.insert(alkategoriak, 'Hibásan használt CitLib – helytelen ISBN kód') end end

-- URL kezelése local CoinS_url= nil if url then CoinS_url = url -- SZÜKSÉGES CSERÉK:cím=Keyboards and Covert Channels" --newline [ ] | Ezek kellenek, mert az URL ráhúzásakor bezavarnak --space [ ] | ----pop('tud-e az url-ről?', url) url = urlencode(url) ----pop('ráhúzás előtti cím', tit) if cap then cap = string.gsub(cap, '\n', ' ') cap = string.gsub(cap, '%[', '[') cap = string.gsub(cap, '%]', ']') cap = string.gsub(cap, '%|', '|') cap = '[' .. url .. ' ' .. cap .. ']' elseif tit then tit = string.gsub(tit, '\n', ' ') tit = string.gsub(tit, '%[', '[') tit = string.gsub(tit, '%]', ']') tit = string.gsub(tit, '%|', '|') tit = '[' .. url .. ' ' .. tit .. ']' ----pop('ráhúzza?', tit) end end if cap then cap = cap .. '. In ' end

   -- nyelv kezelése
   local tagok={}
   local i,j,szel

if lan then

   local   nyelvek,hibak,nyomok = nil
   nyelvek,hibak,nyomok = nyksz.nyelvszuro(lan)
   pop("kapott hibalista=", nyomok)
      if hibak then
         pop("nyelvkód-hibák a nyelvszűrésen belül=", hibak)
         local uzenet = hibak ..'hibás nyelvkód'
         error(true, uzenet)	
         table.insert(alkategoriak, 'Hibásan használt CitLib – nyelvkódhiba')
      end 
      if nyelvek then
         pop("kapott nyelvlista=", nyelvek)
         lan = nyelvek
      end          
      if nyomok then
         pop("nyomkövetés a nyelvszűrésen belül=", nyomok)
      end   
      if #tit == 0 then

error(true, 'nyelv cím nélkül') table.insert(alkategoriak, 'Hibásan használt CitLib – nyelv cím nélkül')

      end         

end --if lan


-- archívdátum -- archívurl

if archd then -- ha van dátum local outarchd, dou dou = select(2, ds.datumszuro(archd)) if dou then outarchd = ds.honapnevesdate(dou) if aurl then aurl = urlencode(aurl) archd = '[' .. aurl .. ' arch]' else error(true, 'archívdátum van, de archívurl nélkül') table.insert(alkategoriak, 'Hibásan használt CitLib – archívdátum archívurl nélkül') end else error(true, 'hibás archívdátum') table.insert(alkategoriak, 'Hibásan használt CitLib – hibás archívdátum') end end

-- elérés dátuma if accd then -- ha van elérés local nyom, dou = ds.datumszuro(accd) -- --pop('a dátumszűrés eredménye', nyom) if dou then accd = 'Hozzáférés: ' .. ds.honapnevesdate(dou) else error(true, 'hibás elérési dátum') table.insert(alkategoriak, 'Hibásan használt CitLib – hibás elérési dátum') end end

-- CoinS local empty_span = ' ' local this_page = mw.title.getCurrentTitle() local ctx_ver = 'Z39.88-2004' local coins = nil OCinSoutput['rft.atitle'] = CoinS_cap OCinSoutput.rft_val_fmt = 'info:ofi/fmt:kev:mtx:book' OCinSoutput['rft.genre'] = 'book' --OCinSoutput['rft.au'] = CoinS_aut OCinSoutput['rft.btitle'] = CoinS_tit OCinSoutput['rft.place'] = CoinS_loc OCinSoutput['rft.date'] = CoinS_ann OCinSoutput['rft.series'] = CoinS_ser OCinSoutput['rft.issue'] = CoinS_sernr OCinSoutput['rft.pages'] = CoinS_pag OCinSoutput['rft.edition'] = CoinS_edi OCinSoutput['rft.pub'] = CoinS_red OCinSoutput['rft.isbn'] = CoinS_isbn OCinSoutput.rft_id = CoinS_url OCinSoutput.rfr_id = table.concat{ 'info:sid/', mw.site.server:match( '[^/]*$' ), ':', this_page.prefixedText } OCinSoutput = setmetatable( OCinSoutput, nil );

-- sort with version string always first, and combine. table.sort( OCinSoutput ) table.insert( OCinSoutput, 1, 'ctx_ver=' .. ctx_ver ) -- such as "Z39.88-2004" coins = table.concat(OCinSoutput, '&') coins = '' .. empty_span .. '';

-- output összeállítása local s = if sablon_kimenetek_kellenek then if capaut then s = s .. capaut .. ' ' end if cap then s = s .. cap .. ' ' end if aut then s = s .. aut .. ' ' end if tit then s = s .. tit .. ' ' end if vol then s = s .. vol .. ' ' end if lan then s = s .. lan .. ' ' end if ass then s = s .. ass .. ' ' end if edi then s = s .. edi .. ' ' end if kiadas then s = s .. kiadas .. ' ' end if ann then s = s .. ann .. '. ' end if pag then s = s .. pag .. ' ' end if ser then s = s .. ser .. ' ' end if sernr then s = s .. sernr .. ' ' end if isbn then s = s .. isbn .. ' ' end if archd then s = s .. archd .. ' ' end if accd then s = s .. accd .. ' ' end if misc then s = s .. misc .. ' ' end if coins then s = s .. coins .. ' ' end if ou then s = s .. ou end --ez csak nyomkövetésnél kell, de akkor nagyon end

checkArgs()

if hibavan then s = s .. table.concat(hiba_jelzes, ', ') end

if kategorizalas_van then s = s .. end if alkategoriak_kellenek and #alkategoriak > 0 then s = s .. ' ' end

return mw.text.trim(s) end

local function _run(a, c) args = a config = c or {} return _citlib() end

local function run(frame) args = frame:getParent().args -- a sablon hívásakor megadott paraméterek config = frame.args -- az #invoke utasításban átadott paraméterek return _citlib() end

local p = { run = run, _run = _run }

return p