|
|
| (116 גרסאות ביניים של 10 משתמשים אינן מוצגות) |
| שורה 1: |
שורה 1: |
| function equaldata(d, dd)
| | -- This function is used for תבנית:הערה parameters control |
| if d[1] ~= dd[1] then
| |
| templatedatacheck = templatedatacheck .. "<br/>מספר פרמטרים שונה ללא שם בתבנית " .. templatename .. " ב-templatedata<br/>"
| |
| end
| |
| equaltable(d[2], dd[2])
| |
| equaltable(d[3], dd[3], true)
| |
| end
| |
| function equaltable(d, dd, must)
| |
| local found
| |
| for c, cc in pairs(d) do
| |
| found = false
| |
| for e, ee in pairs(dd) do
| |
| if cc == ee then
| |
| found = true
| |
| end
| |
| end
| |
| if not found then
| |
| templatedatacheck = templatedatacheck .. "<br/>לא נמצא פרמטר " .. cc .. " בתבנית " .. templatename .. " ב-templatedata"
| |
| if must then
| |
| templatedatacheck = templatedatacheck .. "בפרמטריפ חובה"
| |
| end
| |
| templatedatacheck = templatedatacheck .. "<br/>"
| |
| end
| |
| end
| |
| end
| |
| function printtable(d)
| |
| local ans = ""
| |
| for c, cc in pairs(d) do
| |
| ans = ans .. cc .. " "
| |
| end
| |
| return ans
| |
| end
| |
| -- This is the main module function | |
| function main(frame) | |
| if mw.title.getCurrentTitle()["namespace"] ~= 0
| |
| then return "" end
| |
| ans = "" -- answer to be printed
| |
| namespace = "תבנית:" -- template namespace
| |
| pframe = frame:getParent() -- Article frame
| |
| errors = 0 -- errors counter
| |
| templatedatacheck = ''
| |
| local template = pframe:getTitle() -- template full name
| |
| templatename = template -- template name to remove namespace
| |
| local havesug = "" -- not enough suggestions error message
| |
| needsug = false -- is there a need to add suggestions
| |
| if find1(templatename, namespace) == 1 --remove namespace from template name
| |
| then templatename = mw.ustring.sub(templatename, len1(namespace) + 1) end
| |
|
| |
| local data, copydata
| |
| local subpageName = 'יחידה:פרמטרים/' .. templatename
| |
| local tdReader = require( 'Module:ReadTd' )
| |
| if mw.title.makeTitle( 0, subpageName ).exists then
| |
| data = mw.loadData(subpageName) -- read template variables data
| |
| copydata = tdReader.compat( templatename )
| |
| equaldata(data, copydata)
| |
| if templatedatacheck ~= '' then
| |
| templatedatacheck = templatedatacheck .. "[[קטגוריה:שגיאה במידע מובנה על תבנית]]"
| |
| end
| |
| else
| |
| data = tdReader.compat( templatename )
| |
| end
| |
| if not data then error( 'Template ' .. tempaltename .. " can't be verified, no subpage and no templatedata" ) end
| |
|
| |
| | |
| local numbered = 0 -- real nonnamed parameters counter
| |
| local parnum = 0 -- template data parameters counter
| |
| local sugnum = 0 -- template data suggestions counter
| |
| local mustnum = data[1] -- template data maximum unnamed parameters number
| |
| parameters = data[2] -- template data parameters list
| |
| must = data[3] -- template data must parameters list
| |
| suggestions = data[4] -- template data suggestions table
| |
| for c, cc in pairs(suggestions) do -- count suggestions
| |
| sugnum = sugnum + 1 end
| |
| if sugnum == 0 then -- noone
| |
| havesug = "אין הצעות בהגדרת התבנית"
| |
| else for c, cc in pairs(parameters) do -- count parameters
| |
| parnum = parnum + 1 end
| |
| if sugnum < parnum / 2 then -- not enough suggestions
| |
| havesug = "אין מספיק הצעות בהגדרת התבנית" end end
| |
| for tt, t in pairs(must) do -- check all must parameters indeed here
| |
| checkmust(t) end
| |
| for k, v in pairs(pframe.args) do -- for each real parameter
| |
| if type(k) == "string" -- if named
| |
| then checknamed(k) -- check it
| |
| elseif not isempty(v) -- if unnamed and not empty
| |
| then numbered = k end end -- remember last such parameter number
| |
| if mustnum < numbered -- too many unnamed parameters
| |
| then out("צריך מקסימום " .. mustnum .. " פרמטרים ללא שם, ישנם " .. numbered .. ', והם:')
| |
| errors = errors + 1 -- an error
| |
| for k, v in pairs(pframe.args) do -- print all unnamed parameters
| |
| if type(k) ~= "string" then
| |
| if not isempty(v)
| |
| then out("''" .. k .. "'': " .. '<span style="color:green">"</span>' .. v
| |
| .. '<span style="color:green">"</span>')
| |
| else out("''" .. k .. "'' ריק") end end end end
| |
| if templatedatacheck ~= '' then
| |
| templatedatacheck = '<div class="error parameters"><small>' .. templatedatacheck .. '</small></div>'
| |
| end
| |
| if ans == "" -- no problems
| |
| then return ans .. templatedatacheck end
| |
| if needsug -- need to print not enough parameters message
| |
| then ans = havesug .. "<br/>" .. ans end
| |
| if errors > 1 -- plural
| |
| then errors = "ו"
| |
| else errors = "" end
| |
| return '<div class="error parameters"><small>' .. " '''שגיא" .. errors .. "ת פרמטרים ב[["
| |
| .. template .. "]]:<br/>" .. ans .. "'''</td></tr></table></small></div>" -- answer
| |
| .. "[[קטגוריה:שגיאות פרמטריות]][[קטגוריה:שגיאות פרמטריות בתבנית " .. templatename .. "]]" .. templatedatacheck
| |
| end
| |
| | |
| -- This function checks each template data must parameter
| |
| function checkmust(must)
| |
| for g, h in pairs(pframe.args) do -- for each real parameters
| |
| if must == g .. "" -- found
| |
| then if isempty(h) -- but empty
| |
| then out("פרמטר חובה ריק: ''" .. g .. "''")
| |
| errors = errors + 1 end
| |
| return end end
| |
| out("פרמטר חובה חסר: ''" .. must .. "''") -- not found
| |
| errors = errors + 1
| |
| end
| |
| | |
| -- This function checks each named real parameter
| |
| function checknamed(k)
| |
| local answer = "פרמטר לא ידוע: ''" .. k .. "''" -- answer if will be needed
| |
| for p1, p in pairs(parameters) do -- for each template data parameter
| |
| if p == k -- match
| |
| then return end end
| |
| errors = errors + 1
| |
| if suggestions[k] == nil or suggestions[k] == "" -- is there a suggestion
| |
| then needsug = true -- if no, need more suggestions
| |
| else answer = answer .. ', <span style = "color:green">מומלץ ' .. "''" .. suggestions[k] .. "''</span>" end
| |
| out(answer) -- output
| |
| end
| |
| | |
| -- This procedure checks is the argument is nothing then whitespace
| |
| function isempty(v)
| |
| for i = 1, len1(v) do -- each character
| |
| if mw.ustring.byte(v, i, i) > 32 -- real text
| |
| then return false end end
| |
| return true -- indeed empty
| |
| end
| |
| | |
| -- This function add a line to the output
| |
| function out(new)
| |
| ans = ans .. new .. "</br>"
| |
| end
| |
| | |
| -- This functions finds substring in string
| |
| function find1(str, what, where)
| |
| return mw.ustring.find(str, what, where, true) or 0
| |
| end
| |
| | |
| -- This function calculates string length
| |
| function len1(s)
| |
| if s == nil -- no string
| |
| then return 0 end
| |
| return mw.ustring.len(s)
| |
| end
| |
| | |
| function sub1(str, from, to)
| |
| return mw.ustring.sub(str, from, to)
| |
| end
| |
| | |
| function equal(frame) | | function equal(frame) |
| local pframe = frame:getParent() | | local pframe = frame:getParent() |
| type = sub1(pframe:getTitle(), 7) | | type = mw.ustring.sub(pframe:getTitle(), 7) |
| oldargs = pframe.args | | oldargs = pframe.args |
| local newargs = {} | | local newargs = {} |
| שורה 172: |
שורה 9: |
| for p, pp in pairs(oldargs) do | | for p, pp in pairs(oldargs) do |
| stop = false | | stop = false |
| if tostring(p) == tostring(kinds[1]) and newargs[p] == nil | | if tostring(p) == tostring(kinds[1]) and newargs[p] == nil then |
| then newargs[p] = pp | | newargs[p] = pp |
| stop = true
| | stop = true |
| elseif tostring(p) == tostring(kinds[1]) | | elseif tostring(p) == tostring(kinds[1]) then |
| then equalerror("תוכן כפול: " .. newargs[p] .. " וגם " .. pp) | | equalerror("תוכן כפול: " .. newargs[p] .. " וגם " .. pp) |
| stop = true
| | stop = true |
| else for z, zz in ipairs(kinds) do | | else |
| if tostring(p) == tostring(zz) | | for z, zz in ipairs(kinds) do |
| then newargs[p] = pp | | if tostring(p) == tostring(zz) then |
| stop = true
| | newargs[p] = pp |
| do break end end | | stop = true |
| end end
| | do |
| if not stop
| | break |
| then local kind = newargs[kinds[1]] or newargs[tonumber(kinds[1])]
| | end |
| if kind ~= nil | | end |
| then equalerror("תוכן כפול: " .. kind .. " וגם " .. p .. "=" .. pp)
| |
| else newargs[kinds[1]] = p .. "=" .. pp end end
| |
| end
| |
| return frame:expandTemplate({title = frame.args["קוד"], args = newargs})
| |
| end | |
| | |
| function short(frame)
| |
| local pframe = frame:getParent()
| |
| type = sub1(pframe:getTitle(), 7)
| |
| local found
| |
| for p, pp in pairs(pframe.args) do
| |
| found = false
| |
| for z, zz in ipairs(frame.args) do
| |
| if tostring(p) == tostring(zz)
| |
| then found = true
| |
| end | | end |
| end | | end |
| if not found and not (p == 1 and pp == "") | | if not stop then |
| then equalerror("פרמטר לא ידוע: " .. p .. " = '" .. pp .. "'") | | local kind = newargs[kinds[1]] or newargs[tonumber(kinds[1])] |
| | if kind ~= nil then |
| | equalerror("תוכן כפול: " .. kind .. " וגם " .. p .. "=" .. pp) |
| | else newargs[kinds[1]] = p .. "=" .. pp |
| | end |
| end | | end |
| end | | end |
| | return frame:expandTemplate({title = frame.args["קוד"], args = newargs}) |
| end | | end |
|
| |
|
| שורה 216: |
שורה 43: |
| function decode(frame) | | function decode(frame) |
| return mw.uri.decode(frame.args[1]) | | return mw.uri.decode(frame.args[1]) |
| | end |
| | |
| | function googleurl(frame) |
| | --return a .. mw.uri.parseQueryString( frame.args[1] )['http://www.google.co.il/url?url'] |
| | --p = '' |
| | --for k, v in pairs(mw.uri.new( frame.args[1] ).query['url']) |
| | --do return 'a' .. k .. 'c' end --p = p .. '+++' .. k .. ':' .. v end |
| | --return p-- |
| | local q = mw.uri.new(frame.args[1]).query |
| | return q and (q['url'] or q['q']) or '' |
| | --or mw.uri.parseQueryString( frame.args[1] )['http://www.google.co.il/url?url'] or '' |
| end | | end |
|
| |
|
| שורה 232: |
שורה 70: |
| end | | end |
|
| |
|
| function biurim(frame) | | function showparams( frame ) |
| pframe = frame:getParent()
| | local ans = '', k |
| local newargs = {} | | for i, v in pairs(frame.args) do |
| for a, aa in pairs(pframe.args) do | | if tonumber(i) then |
| if a == "קבוצה" then | | k = v |
| error('פרמטר "קבוצה" כפול[[category:' .. | | else |
| tostring(mw.message.new("Cite-tracking-category-cite-error")) .. ']]', 0)
| | k = i |
| | end |
| | k = mw.ustring.gsub(k, '\n', '') |
| | if mw.ustring.find(k, '|') then |
| | k = k .. ' (' .. mw.ustring.sub(k, 3, mw.ustring.find(k, '|') - 1) .. ')' |
| end | | end |
| newargs[a] = aa | | ans = ans .. '#' .. k .. '\n' |
| end | | end |
| newargs["קבוצה"] = frame.args[1] or "hebrew"
| | return ans |
| return frame:expandTemplate{title = "הערות שוליים", args = newargs} | |
| end | | end |
| function checktemplatedata(frame)
| | |
| end
| | |
| function test(frame) | | local function main() end |
| return mw.language.fetchLanguageName( "no", "he" ) | | |
| end
| | return { |
| return {main = main, equal = equal, decode = decode, short = short, biur = biur, biurim = biurim, | | main = main, |
| checktemplatedata = checktemplatedata, test = test} | | equal = equal, |
| | decode = decode, |
| | googleurl = googleurl, |
| | biur = biur, |
| | showparams = showparams, |
| | } |
-- This function is used for תבנית:הערה parameters control
function equal(frame)
local pframe = frame:getParent()
type = mw.ustring.sub(pframe:getTitle(), 7)
oldargs = pframe.args
local newargs = {}
local kinds = frame.args
local stop
for p, pp in pairs(oldargs) do
stop = false
if tostring(p) == tostring(kinds[1]) and newargs[p] == nil then
newargs[p] = pp
stop = true
elseif tostring(p) == tostring(kinds[1]) then
equalerror("תוכן כפול: " .. newargs[p] .. " וגם " .. pp)
stop = true
else
for z, zz in ipairs(kinds) do
if tostring(p) == tostring(zz) then
newargs[p] = pp
stop = true
do
break
end
end
end
end
if not stop then
local kind = newargs[kinds[1]] or newargs[tonumber(kinds[1])]
if kind ~= nil then
equalerror("תוכן כפול: " .. kind .. " וגם " .. p .. "=" .. pp)
else newargs[kinds[1]] = p .. "=" .. pp
end
end
end
return frame:expandTemplate({title = frame.args["קוד"], args = newargs})
end
function equalerror(message)
error("[[קטגוריה:שגיאות קריאה לתבנית " .. type .. "]] (בקריאה ל[[תבנית:" .. type .. "]]) " .. message, 0)
end
function decode(frame)
return mw.uri.decode(frame.args[1])
end
function googleurl(frame)
--return a .. mw.uri.parseQueryString( frame.args[1] )['http://www.google.co.il/url?url']
--p = ''
--for k, v in pairs(mw.uri.new( frame.args[1] ).query['url'])
--do return 'a' .. k .. 'c' end --p = p .. '+++' .. k .. ':' .. v end
--return p--
local q = mw.uri.new(frame.args[1]).query
return q and (q['url'] or q['q']) or ''
--or mw.uri.parseQueryString( frame.args[1] )['http://www.google.co.il/url?url'] or ''
end
function biur(frame)
pframe = frame:getParent()
local newargs = {}
for a, aa in pairs(pframe.args) do
if a == "קבוצה" then
error('פרמטר "קבוצה" כפול[[category:' ..
tostring(mw.message.new("Cite-tracking-category-cite-error")) .. ']]', 0)
end
newargs[a] = aa
end
newargs["קבוצה"] = frame.args[1] or "hebrew"
return frame:expandTemplate{title = "הערה", args = newargs}
end
function showparams( frame )
local ans = '', k
for i, v in pairs(frame.args) do
if tonumber(i) then
k = v
else
k = i
end
k = mw.ustring.gsub(k, '\n', '')
if mw.ustring.find(k, '|') then
k = k .. ' (' .. mw.ustring.sub(k, 3, mw.ustring.find(k, '|') - 1) .. ')'
end
ans = ans .. '#' .. k .. '\n'
end
return ans
end
local function main() end
return {
main = main,
equal = equal,
decode = decode,
googleurl = googleurl,
biur = biur,
showparams = showparams,
}