-- Ajuanca Google Code-in 2019, Introduction to Lua in Wikipedia.
local p =
function p.hello(frame) return "Hello, world!"end
p.Hi = function(frame) strName = frame.args.name or "Jimmy"end
function p.converttemp(frame) cels = tonumber(frame.args.celsius) or 0 fahr = (((cels * 9) / 5) + 32) kelvin = cels + 273.15 str = cels .. " degrees Celsius is " .. fahr .. " degrees Fahrenheit." str = str .. " That's the same as say " .. kelvin .. " Kelvin." if cels > 9 then str = str .. " It is warm." elseif cels < 9 then str = str .. " It is cold." else str = str .. " It isn't neither warm nor cold." end return strend
-- Task 4-- Timestable functionfunction p.timestable(frame) local random = math.random(-12, 12) local numb = tonumber(frame.args.numb) or random local out = "
-- People functionfunction p.people(frame) local friends = local msg = "" for i = 1, #friends do msg = msg .. "Hello " .. friends[i] .. "
" end return msgend
-- Task 5-- Sent functionfunction p.sent(frame) local txt = frame.args.text or "" local firstLetterCapitalized = string.upper(string.sub(txt, 1, 1)) local out = firstLetterCapitalized .. string.sub(txt, 2) return outend
-- Unpack functionfunction p.unpack(frame) local dmy = frame.args.dmydate or "" local d, m, y = string.match(dmy, "(%d+) (%w+) (%d+)") local annualPosition = ordinalMonth(m) return "Year = " .. y .. "
Day = " .. d .. "
Month = " .. m .. ", that is the " .. annualPosition .. " month.
"end
-- Unpack function for US date formatfunction p.unpackUS(frame) local mdy = frame.args.mdydate or "" local m, d, y = string.match(mdy, "(%w+) (%S+) (%d+)") d = string.sub(d, 1, #d - 1) local annualPosition = ordinalMonth(m) return "Year = " .. y .. "
Day = " .. d .. "
Month = " .. m .. ", that is the " .. annualPosition .. " month.
"end
-- Get month positionfunction ordinalMonth(month) local normalizedMonth = string.lower(month) local annualPosition if normalizedMonth
"february" then annualPosition = "second" elseif normalizedMonth
"april" then annualPosition = "fourth" elseif normalizedMonth
"june" then annualPosition = "sixth" elseif normalizedMonth
"august" then annualPosition = "eighth" elseif normalizedMonth
"october" then annualPosition = "tenth" elseif normalizedMonth
"december" then annualPosition = "twelfth" end return annualPositionend
-- Task 6-- Langs function.function p.langs(frame) local langslist = mw.language.fetchLanguageNames local out = "" local count = 0 for k, v in pairs(langslist) do out = out .. k .. " - " .. v .. "
" count = count + 1 end return out .. "
= " .. count .. " languages"end
-- Fallbacklangs function.function p.fallbacklangs(frame) local fallbackLanguages = mw.language.getFallbacksFor(frame.args.langcode) local out = "" local correctThere = "" local count = 0 for k, v in pairs(fallbackLanguages) do out = out .. k .. " - " .. v .. "
" count = count + 1 end if count
-- Page title function.p.pgtitle = function(frame) local title = frame.args.title local ttlobj = mw.title.new(title) local txt = ttlobj.text return txtend
-- Page information function.function p.pginfo(frame) local titleOfPage = frame.args.titleOfPage local titleObject = mw.title.new(titleOfPage) local output = "" if titleObject
-- Reutrn list with languages organized depending on number of fallback-languages.function p.orgnanizeLanguages local allLanguages = mw.language.fetchLanguageNames local numberedLanguages = local out = "" for k, v in pairs(allLanguages) do element = table.insert(numberedLanguages, element) end --table.sort(numberedLanguages, sortByFallbacks) function sortByFallbacks(a,b) if a.numberOfFallbacks>b.numberOfFallbacks then return true else return false end end for x, p in ipairs(numberedLanguages)do for c, s in ipairs(p)do out = out .. x end end return outend
-- Task 7-- Get date.function p.getdate(frame) local qid = frame.args.qid local prop = frame.args.prop local valtbl = mw.wikibase.getBestStatements(qid, prop) local timestamp = valtbl[1].mainsnak.datavalue.value.time local y, m, d = string.match(timestamp, "(%d+)-(%d+)-(%d+)") local str = "The year is " .. y .. ", the month is " .. m .. " and the day is " .. d .. ".
This date in an ISO-style is " .. y .. "-" .. m .. "-" .. d .. "." return strend
-- Readable datefunction p.getfulldate(frame) local monthname = local qid = frame.args.qid local prop = frame.args.prop local valtbl = mw.wikibase.getBestStatements(qid, prop) local timestamp = valtbl[1].mainsnak.datavalue.value.time local y, m, d = string.match(timestamp, "(%d+)-(%d+)-(%d+)") local str = d .. " " .. monthname[tonumber(m)] .. " " .. y return strend
-- Get structure of itemfunction p.getitem(frame) local qid = frame.args.qid local prop = frame.args.prop local valtbl = mw.wikibase.getBestStatements(qid, prop) local idstamp = valtbl[1].mainsnak.datavalue.value.id local title = mw.wikibase.getLabel(idstamp) -- local tbl = mw.wikibase.entity:formatPropertyValues('P42') return titleend
return p