Module:Sandbox/RexxS/GCI09
< Module:Sandbox | RexxS
Lua has a number of libraries, collections of useful built-in functions, and you can read about them at Standard Libraries, which use many of the standard features found in other popular programming languages like PHP and Python, such as regular expressions and string handling functions. Because Lua can access libraries written in C, custom extensions can be implemented.
The Scribunto extension for MediaWiki provides a number of libraries specifically for use in MediaWiki and you can read about the common ones at Scribunto libraries. The library used to import Wikidata into other projects is documented at Extension:Wikibase Client/Lua.
-- Module to demonstrate a MW library call for Google-Code-in-2017
-- Function langnames returns the list of languages known to MediaWiki
p = {}
p.langnames = function( frame )
local langs = mw.language.fetchLanguageNames()
local langlist = ""
local count = 0
for key, value in pairs( langs ) do
langlist = langlist .. key .. " - " .. value .. "<br>"
count = count + 1
end
return langlist .. "<br>= " .. count .. " languages"
end
p.fallbacks = function( frame )
local langcode = frame.args.langcode or ""
local fblist = mw.language.getFallbacksFor( langcode )
return table.concat(fblist, ", ")
end
p.showFallbacks = function( frame )
local langs = mw.language.fetchLanguageNames()
local langlist = ""
local count = 0
for key, value in pairs( langs ) do
langlist = langlist .. key .. " - " .. table.concat(mw.language.getFallbacksFor( key ), ", ") .. "<br>"
count = count + 1
end
return langlist .. "<br>= " .. count .. " languages"
end
return p