Module:Wikipedia ads
This module displays banner-style adverts for various Wikipedia projects, processes and pages. It implements Template:Wikipedia ads.
==}}
Usage
From wikitext
From wikitext, usually this module should be used via Template:Wikipedia ads. However, it is also possible to use the syntax {{#invoke:wikipedia ads|main|...}}
, where "..." are the template arguments. See the template page for documentation and for a list of available parameters.
From Lua
First, load the module:
local mWikipediaAds = require('Module:Wikipedia ads')
Then you can generate Wikipedia ads using the "_main" function:
mWikipediaAds._main(args)
args is a table of arguments that can be used by the module. See Template:Wikipedia ads for a complete list of arguments and for other documentation.
Adding and removing ads
For instructions on creating the animated GIF files used in the ads, see Template:Wikipedia ads#Creating ads. For instructions on adding and removing images from the module, see Module:Wikipedia ads/list.
local p = {}
function p.main(frame)
local pframe = frame:getParent()
local config = frame.args
local args = pframe.args
local ads = {}
local errors = {}
adslist = mw.loadData("Module:Wikipedia ads/list")
if args.navbox then
table.insert(ads, [[<table class="navbox collapsible collapsed" style="width: 100%;
background: #f7f8ff; text-align: left; border: solid 1px #AAAAAA; margin: 0px">]])
table.insert(ads, [[<th style="background: transparent; font-size: 105%; text-align: center;
font-weight: bold">]])
table.insert(ads, "[[Template:Wikipedia ads|Wikipedia ads]]: Overview</th><tr><td>")
table.insert(ads, [[<table class="plainlinks sortable wikitable" style="width: 100%;
text-align: left; margin: 0; font-size: 90%"><tr>]])
table.insert(ads, [[<th style="width: 3em">#</th><th class="unsortable">Image</th>
<th>Page</th><th>Author</th></tr>]])
if tonumber(adslist[1]) ~= nil and tonumber(adslist[2]) ~= nil then
local i = 1
while i < 400 == true and i <= (adslist[1] - adslist[2]) == true do
table.insert(ads, "<tr>")
if tonumber(adslist[i+3*adslist[1]+2]) == nil then
table.insert(errors, "Error: Argument " .. i+3*adslist[1]+2 .. " in [[Template:Wikipedia ads]] is not a number")
else
table.insert(ads, "<th>" .. (adslist[i+3*adslist[1]+2] or "") .. "</th>")
table.insert(ads, "<td>[[" .. (adslist[adslist[i+3*adslist[1]+2]*3] or "") .. "|140px]]</td>")
table.insert(ads, "<td>[[" .. (adslist[adslist[i+3*adslist[1]+2]*3+1] or "") .. "]]</td>")
table.insert(ads, "<td>" .. (adslist[adslist[i+3*adslist[1]+2]*3+2] or "") .. "</td>")
end
table.insert(ads, "</tr>")
i = i + 1
end
else
table.insert(errors, "Error: Table value 1 and/or 2 in [[Module:Wikipedia ads/list]] are not numbers")
end
table.insert(ads, "</table></td></tr></table>")
else
table.insert(ads, '<table class="plainlinks qxz-ads" style="color:' .. (args.color or "#555555") .. 'border:none;')
if args.background then
table.insert(ads, "background:" .. args.background .. ";")
end
table.insert(ads, "float:" .. (args.float or "margin:0 auto") .. ";")
table.insert(ads, [[line-height:1em; font-size:90%; display:block; overflow:auto;
max-width:477px"><tr><td colspan="2" style="border:none">]])
cal = math.random(adslist[1]-adslist[2])
if adslist[1] and adslist[2] == nil then
table.insert(error, "Error Argument 1 and 2 in [[Template:Wikipedia ads]] are not numbers")
end
if tonumber(args.ad) ~= nil then
argad = args.ad
else
local rawnumedits = mw.getContentLanguage():parseFormattedNumber(mw.site.stats.edits)
argad = rawnumedits % adslist[1] + 2
end
table.insert(ads, "[[" .. (adslist[(argad or cal)*3] or "") .. "|468px|link=" )
table.insert(ads, (adslist[(argad or cal)*3+1] or "") .. "]]</td></tr>")
if args.nolinks == nil then
table.insert(ads, '<tr><td style="border:none">[[Template:Wikipedia ads|<font color="')
table.insert(ads, (args.linkcolor or "#002bb8") .. '">Wikipedia Ads</font>]]</td>')
table.insert(ads, '<td style="text-align: right; border:none"> [')
if adslist[(argad or cal)*3] then
table.insert(ads, tostring(mw.uri.fullUrl(adslist[(argad or cal)*3])) )
end
table.insert(ads, ' <font color="' .. (args.linkcolor or "#002bb8") .. '">file info</font>]')
if args.showpurge then
table.insert(ads, "- [" .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().prefixedText, "action=purge")))
table.insert(ads, ' <font color="' .. (args.linkcolor or "#002bb8") .. '">show another</font>]')
elseif args.ad == nil then
table.insert(ads, "- [" .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().prefixedText, "action=purge")))
table.insert(ads, ' <font color="' .. (args.linkcolor or "#002bb8") .. '">show another</font>]')
end
table.insert(ads, " – #" .. (argad or cal) .. "</td></tr>")
end
table.insert(ads, "</table>")
end
return table.concat(errors) .. table.concat(ads)
end
return p