Modul:Portal: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Perbarui sintaks LUA per versi terbaru dari modul yang bersangkutan. |
Hidayatsrf (bicara | kontrib) Tidak ada ringkasan suntingan |
||
Baris 1:
--[==[ This module is a Lua implementation of the old {{Portal}} template.
-- Please take care when updating it! It outputs two functions: p.portal, which generates a list of portals, and p.image, which
-- produces the image name for an individual portal.
Baris 41:
local p = {}
local trackingEnabled = true
local templatestyles = 'Module:Portal/styles.css'
local yesno = require('Module:Yesno')
-- Check whether to do tracking in this namespace
-- Returns true unless the page is one of the banned namespaces
local function checkTrackingNamespace()
local thisPage = mw.title.getCurrentTitle()
if (thisPage.namespace == 1) -- Talk
or (thisPage.namespace == 2) -- User
or (thisPage.namespace == 3) -- User talk
or (thisPage.namespace == 5) -- Wikipedia talk
or (thisPage.namespace == 7) -- File talk
or (thisPage.namespace == 11) -- Template talk
or (thisPage.namespace == 15) -- Category talk
or (thisPage.namespace == 101) -- Portal talk
or (thisPage.namespace == 109) -- Book talk
or (thisPage.namespace == 118) -- Draft
or (thisPage.namespace == 119) -- Draft talk
or (thisPage.namespace == 829) -- Module talk
then
return false
end
return true
end
-- Check whether to do tracking on this pagename
-- Returns false if the page title matches one of the banned strings
-- Otherwise returns true
local function checkTrackingPagename()
local thisPage = mw.title.getCurrentTitle()
local thisPageLC = mw.ustring.lower(thisPage.text)
if (string.match(thisPageLC, "/archive") ~= nil) then
return false
end
if (string.match(thisPageLC, "/doc") ~= nil) then
return false
end
if (string.match(thisPageLC, "/test") ~= nil) then
return false
end
return true
end
local function matchImagePage(s)
Baris 89 ⟶ 136:
:addClass('noprint portal plainlist')
:addClass(args.left and 'tleft' or 'tright')
:css('margin', args.margin or
:newline()
-- Tracking is on by default.
-- It is disabled if any of the following is true
-- 1/ the parameter "tracking" is set to 'no, 'n', or 'false'
-- 2/ the current page fails the namespace tests in checkTrackingNamespace()
-- 3/ the current page fails the pagename tests in checkTrackingPagename()
trackingEnabled = yesno(args.tracking, trackingEnabled)
if (checkTrackingNamespace() == false) then
trackingEnabled = false
end
if (checkTrackingPagename() == false) then
trackingEnabled = false
end
-- If no portals have been specified, display an error and add the page to a tracking category.
if not portals[1] then
if yesno(args.nominimum) then
-- if nominimum as been set to yes (or similar), omit the warning
else
root:wikitext('<strong class="error">No portals specified: please specify at least one portal</strong>')
end
if (trackingEnabled) then
root:wikitext('[[Category:Portal templates without a parameter]]')
end
return tostring(root)
end
Baris 108 ⟶ 175:
if not pcall(checkPortalExists, portals[i]) or not checkPortalExists(portals[i]) then
-- Getting here means a redlinked portal has been found
if yesno(args.redlinks
-- if redlinks as been set to yes (or similar), add the cleanup category and then break the loop before the portal is removed from the list
if (trackingEnabled) then
root:wikitext('[[Category:Portal templates with redlinked portals]]')
end
break
end
Baris 120 ⟶ 189:
-- if the length of the table is different, then rows were removed from the table, so portals were removed. If this is the case add the cleanup category
if not (portallen == #portals) then
if
if #portals == 0 then
return '[[Category:Portal templates with all redlinked portals]]'
else
root:wikitext('[[Category:Portal templates with redlinked portals]]')
end
end
end
-- Start the list. This corresponds to the start of the wikitext table in the old [[Template:Portal]].
local listroot = root:tag('ul')
:css('width', type(args.boxsize) == 'string' and (args.boxsize .. 'px') or nil)
-- Display the portals specified in the positional arguments.
Baris 147 ⟶ 210:
:newline()
:tag('li')
:tag('span')
:wikitext(string.format('[[File:%s|32x28px|class=noviewer]]', image))
:done()
:tag('span')
:wikitext(string.format('[[Portal:%s|%s%sportal]]', portal, portal, args['break'] and '<br />' or ' '))
end
Baris 264 ⟶ 319:
end
end
local results = ''
if funcName == '_portal' or funcName == '_displayAll' then
results = frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} }
end
return results .. p[funcName](processPortalArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments.
end
end
|