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

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית
קפיצה לניווט קפיצה לחיפוש
(מויקיפדיה)
 
(ניסיון)
שורה 35: שורה 35:
 
end
 
end
 
return frame:expandTemplate({title = frame.args["קוד"], args = newargs})
 
return frame:expandTemplate({title = frame.args["קוד"], args = newargs})
 +
end
 +
 +
function short(frame)
 +
local pframe = frame:getParent()
 +
type = mw.ustring.sub(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
 +
if not found and not (p == 1 and pp == "") then
 +
equalerror("פרמטר לא ידוע: " .. p .. " = '" .. pp ..  "'")
 +
end
 +
end
 
end
 
end
  
שורה 43: שורה 60:
 
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
  
שורה 70: שורה 76:
 
end
 
end
  
function showparams( frame )
+
function biurim(frame)
local ans = '', k
+
pframe = frame:getParent()
for i, v in pairs(frame.args) do
+
local newargs = {}
if tonumber(i) then
+
for a, aa in pairs(pframe.args) do
k = v
+
if a == "קבוצה" then
else
+
error('פרמטר "קבוצה" כפול[[category:' ..
k = i
+
tostring(mw.message.new("Cite-tracking-category-cite-error")) .. ']]', 0)
 
end
 
end
k = mw.ustring.gsub(k, '\n', '')
+
newargs[a] = aa
if mw.ustring.find(k, '|') then
 
k = k .. ' (' .. mw.ustring.sub(k, 3, mw.ustring.find(k, '|') - 1) .. ')'
 
end
 
ans = ans .. '#' .. k .. '\n'
 
 
end
 
end
return ans
+
newargs["קבוצה"] = frame.args[1] or "hebrew"
 +
return frame:expandTemplate{title = "הערות שוליים", args = newargs}
 
end
 
end
  
 
+
return {main = require('Module:ParamValidator').validateparams, equal = equal, decode = decode, short = short, biur = biur,
local function main() end
+
biurim = biurim,}
 
return {
 
main = main,
 
equal = equal,  
 
decode = decode,  
 
googleurl = googleurl,
 
biur = biur,
 
showparams = showparams,
 
}
 

גרסה מ־21:00, 10 בפברואר 2021


-- 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 short(frame)
	local pframe = frame:getParent()
	type = mw.ustring.sub(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
		if not found and not (p == 1 and pp == "") then
			equalerror("פרמטר לא ידוע: " .. p .. " = '" .. pp ..  "'")
		end
	end
end

function equalerror(message)
	error("[[קטגוריה:שגיאות קריאה לתבנית " .. type .. "]] (בקריאה ל[[תבנית:" .. type .. "]]) " .. message, 0)
end

function decode(frame)
	return mw.uri.decode(frame.args[1])
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 biurim(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

return {main = require('Module:ParamValidator').validateparams, equal = equal, decode = decode, short = short, biur = biur,
	biurim = biurim,}