יחידה:פרמטרים: הבדלים בין גרסאות בדף
מראה
אין תקציר עריכה |
אין תקציר עריכה |
||
| שורה 3: | שורה 3: | ||
namespace = "תבנית:" | namespace = "תבנית:" | ||
pframe = frame:getParent() | pframe = frame:getParent() | ||
errors = 0 | |||
local template = pframe:getTitle() | local template = pframe:getTitle() | ||
local templatename = template | local templatename = template | ||
| שורה 23: | שורה 24: | ||
lastparam = v end end | lastparam = v end end | ||
if mustnum < numbered | if mustnum < numbered | ||
then out("צריך מקסימום " .. mustnum .. " פרמטרים ללא שם, ישנם " .. numbered .. ', והם:') | then out("צריך מקסימום " .. mustnum .. " פרמטרים ללא שם, ישנם " .. numbered .. ', והם:') | ||
errors = errors + 1 | |||
for k, v in pairs(pframe.args) do | |||
if type(k) ~= "string" then | |||
if not isempty(v) | |||
then out("''" .. k .. "'': " .. '<span style="color:green">"</span>' .. v .. '<span style="color:green">"</span>') | |||
elseif v == "" | |||
then out("''" .. k .. "'' כולל רק שטח ריק") | |||
else out("''" .. k .. "'' ריק") end end end end | |||
if ans == "" | if ans == "" | ||
then return ans end | then return ans end | ||
return '<div class="error parameters"><small>' .. " ''' | if errors > 1 | ||
then errors = "ו" | |||
else errors = "" end | |||
return '<div class="error parameters"><small>' .. " '''שגיא" .. errors .. "ת פרמטרים ב[[" | |||
.. template .. "]]:<br/>" .. ans .. "'''</td></tr></table></small></div>[[קטגוריה:שגיאות פרמטריות]]" | .. template .. "]]:<br/>" .. ans .. "'''</td></tr></table></small></div>[[קטגוריה:שגיאות פרמטריות]]" | ||
end | end | ||
| שורה 41: | שורה 46: | ||
if must == g .. "" | if must == g .. "" | ||
then if isempty(h) | then if isempty(h) | ||
then out("פרמטר חובה ריק: ''" .. g .. "''") end | then out("פרמטר חובה ריק: ''" .. g .. "''") | ||
errors = errors + 1 end | |||
return end end | return end end | ||
out("פרמטר חובה חסר: ''" .. must .. "''") | out("פרמטר חובה חסר: ''" .. must .. "''") | ||
errors = errors + 1 | |||
end | end | ||
| שורה 51: | שורה 58: | ||
if p == k | if p == k | ||
then return end end | then return end end | ||
errors = errors + 1 | |||
if suggestions[k] ~= nil | if suggestions[k] ~= nil | ||
then answer = answer .. ', <span style = "color:green">מומלץ ' .. "''" .. suggestions[k] .. "''</span>" end | then answer = answer .. ', <span style = "color:green">מומלץ ' .. "''" .. suggestions[k] .. "''</span>" end | ||
גרסה מ־13:27, 10 במאי 2015
function foo(frame)
ans = ""
namespace = "תבנית:"
pframe = frame:getParent()
errors = 0
local template = pframe:getTitle()
local templatename = template
if find1(templatename, namespace) == 1
then templatename = mw.ustring.sub(templatename, len1(namespace) + 1) end
local data = mw.loadData('יחידה:פרמטרים/' .. templatename)
local numbered = 0
local lastparam
local mustnum = data[1]
parameters = data[2]
must = data[3]
suggestions = data[4]
for tt, t in pairs(must) do
checkmust(t) end
for k, v in pairs(pframe.args) do
if type(k) == "string"
then checknamed(k)
elseif not isempty(v)
then numbered = k
lastparam = v end end
if mustnum < numbered
then out("צריך מקסימום " .. mustnum .. " פרמטרים ללא שם, ישנם " .. numbered .. ', והם:')
errors = errors + 1
for k, v in pairs(pframe.args) do
if type(k) ~= "string" then
if not isempty(v)
then out("''" .. k .. "'': " .. '<span style="color:green">"</span>' .. v .. '<span style="color:green">"</span>')
elseif v == ""
then out("''" .. k .. "'' כולל רק שטח ריק")
else out("''" .. k .. "'' ריק") end end end end
if ans == ""
then return ans end
if errors > 1
then errors = "ו"
else errors = "" end
return '<div class="error parameters"><small>' .. " '''שגיא" .. errors .. "ת פרמטרים ב[["
.. template .. "]]:<br/>" .. ans .. "'''</td></tr></table></small></div>[[קטגוריה:שגיאות פרמטריות]]"
end
function checkmust(must)
for g, h in pairs(pframe.args) do
if must == g .. ""
then if isempty(h)
then out("פרמטר חובה ריק: ''" .. g .. "''")
errors = errors + 1 end
return end end
out("פרמטר חובה חסר: ''" .. must .. "''")
errors = errors + 1
end
function checknamed(k)
local answer = "פרמטר לא ידוע: ''" .. k .. "''"
for p1, p in pairs(parameters) do
if p == k
then return end end
errors = errors + 1
if suggestions[k] ~= nil
then answer = answer .. ', <span style = "color:green">מומלץ ' .. "''" .. suggestions[k] .. "''</span>" end
out(answer)
end
function isempty(v)
for i = 1, len1(v) do
if mw.ustring.byte(v, i, i) > 32
then return false end end
return true
end
function out(new)
ans = ans .. new .. "</br>"
end
function find1(str, what, where)
local ans = mw.ustring.find(str, what, where, true)
if ans == nil
then ans = 0 end
return ans
end
function len1(s)
if s == nil
then return 0 end
return mw.ustring.len(s)
end
return {['main'] = foo}