לדלג לתוכן

יחידה:פרמטרים: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
אין תקציר עריכה
מ 215 גרסאות של הדף wikipedia:he:יחידה:פרמטרים יובאו
 
(192 גרסאות ביניים של 10 משתמשים אינן מוצגות)
שורה 1: שורה 1:
function foo(frame)
-- This function is used for תבנית:הערה parameters control
ans = ""
function equal(frame)
namespace = "תבנית:"
local pframe = frame:getParent()
local pframe = frame:getParent()
local template = pframe:getTitle()
type = mw.ustring.sub(pframe:getTitle(), 7)
local templatename = template
oldargs = pframe.args
if find1(templatename, namespace) == 1 then templatename = mw.ustring.sub(templatename, len1(namespace) + 1) end
local newargs = {}
local data = mw.loadData('יחידה:פרמטרים/' .. templatename)
local kinds = frame.args
local numbered = 0
local stop
local mustnum = data[1]
for p, pp in pairs(oldargs) do
parameters = data[2]
stop = false
must = data[3]
if tostring(p) == tostring(kinds[1]) and newargs[p] == nil then
suggestions = data[4]
newargs[p] = pp
for tt, t in ipairs(must) do
stop = true
checkmust(t, pframe.args)
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
end
for k, v in pairs(pframe.args) do
return frame:expandTemplate({title = frame.args["קוד"], args = newargs})
if type(k) == 'string' then checknamed(k) elseif not isempty(v) then numbered = k end
end
if mustnum < numbered then out ("צריך מקסימום " .. mustnum .. " פרמטרים, ישנם " .. numbered) end
if (ans == "") then return ans end
return "<div class=error> '''שגיאת פרמטרים ב[[" .. template .. "]]:<br/>" .. ans .. "''' </div>[[קטגוריה:שגיאות פרמטריות]]"
end
end


function checknamed(k)
function equalerror(message)
local answer = "פרמטר לא ידוע: ''" .. k .. "''"
error("[[קטגוריה:שגיאות קריאה לתבנית " .. type .. "]] (בקריאה ל[[תבנית:" .. type .. "]]) " .. message, 0)
for p1, p in ipairs(parameters) do
if p == k then return end
end
if suggestions[k] ~= nil then answer = answer .. ', <span style = "color:green">מומלץ ' .. "''" .. suggestions[k] .. "''</span>" end
out(answer)
end
end


function checkmust(must, args)
function decode(frame)
for g, h in pairs(args) do
return mw.uri.decode(frame.args[1])
if must == g .. "" then if isempty(h) then out("פרמטר חובה ריק: ''" .. g .. "''") end return end
end
out("פרמטר חובה חסר: ''" .. must .. "''")
end
end
function isempty(v)
 
local i = 1
function googleurl(frame)
local b
--return a .. mw.uri.parseQueryString( frame.args[1] )['http://www.google.co.il/url?url']
while (i <= len1(v)) do
--p = ''
b = mw.ustring.byte(v, i, i)
--for k, v in pairs(mw.uri.new( frame.args[1] ).query['url'])
if (b > 32) then return false end
--do return 'a' .. k .. 'c' end --p = p .. '+++' .. k .. ':' .. v end
i = i + 1
--return p--
end
local q = mw.uri.new(frame.args[1]).query
return true
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


function out(new)
function biur(frame)
ans = ans .. new .. "</br>"
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
end


function find1(str, what, where)
function showparams( frame )
local ans = mw.ustring.find(str, what, where, true)
local ans = '', k
if ans == nil then ans = 0 end
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
return ans
end
end


function len1(s)
if s == nil then return 0 end
return mw.ustring.len(s)
end


return {['main'] = foo}
local function main() end
return {
main = main,
equal = equal,
decode = decode,
googleurl = googleurl,
biur = biur,
showparams = showparams,
}

גרסה אחרונה מ־10:58, 10 בנובמבר 2020


-- 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,
}