--this is a comment-- Task 2
p = -- an empty table
function p.CleverName(frame) return "Hello world."end
-- Task 6, mwLibrarieslocal function fallbacklangcount (langcode) local langslist = mw.language.getFallbacksFor(langcode) local count = 0 for k, v in pairs(langslist) do count = count + 1 end return countend
function p.fallbackfindmost (frame) local langslist = mw.language.fetchLanguageNames local langs = local max = 0 for k, v in pairs(langslist) do local count = fallbacklangcount (k) if count > max then max = count langs = table.insert(langs, k) elseif count
function p.fallbacklangs (frame) local langcode = frame.args.langcode or "" local langslist = mw.language.getFallbacksFor(langcode) local out = "" local count = 0 for k, v in pairs(langslist) do out = out .. k .. " - " .. v .. "
" count = count + 1 end return langcode .. " has " .. count .. " fallback languages:
" .. outend
p.Hi = function(frame) strName = frame.args.name or "Jimbo" return "Hello from Lua to my friend " .. strName .. ".
"end
-- Task 6, mwLibrariesfunction 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
-- Task 6 - pginfop.pginfo = function(frame) local title = frame.args.title or "" if title
-- Task 6 - pgtitlep.pgtitle = function(frame) local title = frame.args.title local ttlobj = mw.title.new(title) local txt = ttlobj.text return txtend
-- Task 5 - Lua librariesfunction p.sent(frame) local txt = frame.args.text or ""-- local out = txt-- local out = string.sub(txt, 1, 1)-- local out = string.sub(txt, 2) local out = string.upper(string.sub(txt, 1, 1)) .. string.sub(txt, 2) return outend
function p.Temperature(frame) cel = tonumber(frame.args.celsius) or 0 fah = cel * 9 / 5 + 32 if cel > 10 then msg = ". It is warm." else msg = ". It is quit cold." end return "The temperature of " .. cel .. " degrees Celsius equals to " .. fah .. " degrees Fahrenheit." .. msgend
-- Task 4 - Loopsp.Times = function(frame) local num = tonumber(frame.args.num) or 2 local out = num .. " times table
" for i = 1, 10 do out = out .. i .. " times " .. num .. " gives " .. i * num .. "
" end return outend
-- Task 5 - Lua librariesfunction p.unpack(frame) local dmy = frame.args.dmydate or "" local d, m, y = string.match(dmy, "(%d+) (%w+) (%d+)") return "Year = " .. y .. "
Day = " .. d .. "
Month = " .. mend
function p.unpackAmerican(frame) local dmy = frame.args.dmydate or "" local m, d, y = string.match(dmy, "(%w+) (%d+), (%d+)") return "Year = " .. y .. "
Day = " .. d .. "
Month = " .. mend
-- Get datefunction p.getdate(frame) local qid = frame.args.qid or "" local prop = frame.args.prop or "" if qid
"" then return "Call this function with a qid and a prop, both being named parameters" end 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+)") return "Year = " .. y .. "
Day = " .. d .. "
Month = " .. mend
-- Get fulldatefunction p.getfulldate(frame) local qid = frame.args.qid or "" local prop = frame.args.prop or "" if qid
"" then return "Call this function with a qid and a prop, both being named parameters" end local monthname = 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+)") out = d .. " " .. monthname[tonumber(m)] .. " " .. y return outend
function p.getitem(frame) local qid = frame.args.qid or "" local prop = frame.args.prop or "" if qid
"" then return "Call this function with a qid and a prop, both being named parameters" end local valtbl = mw.wikibase.getBestStatements(qid, prop) local id = valtbl[1].mainsnak.datavalue.value.id local label = mw.wikibase.getLabel(id) return labelend
return p