Modul:Portal: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Perbarui sintaks LUA per versi terbaru dari modul yang bersangkutan.
Tidak ada ringkasan suntingan
Baris 1:
--[==[ This module is a Lua implementation of the old {{Portal}} template. As of February 2019 itIt is used on nearly 7,900,0006000 articles.
-- 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 (args.left == 'yes' and '0.5em 1em 0.5em 0') or '0.5em 0 0.5em 1em'nil)
:css('border', 'solid #aaa 1px')
: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
root:wikitext('<strong class="error">No portals specified: please specify at least one portal</strong>[[Kategori:Templat portal tanpa parameter]]')
-- 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 == 'yes') or (args.redlinks == 'y') or (args.redlinks == 'true') or (args.redlinks == 'include') then
-- 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('[[Kategori:Templat portal dengan portal berpranala merah]]')
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 #portals == 0(trackingEnabled) then
if #portals == 0 then
return '[[Kategori:Templat portal dengan seluruh portal berpranala merah]]'
return '[[Category:Portal templates with all redlinked portals]]'
end
else
root:wikitext('[[Kategori:Templat portal dengan portal berpranala merah]]')
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('display', 'table')
:css('box-sizing', 'border-box')
:css('padding', '0.1em')
:css('max-width', '175px')
:css('width', type(args.boxsize) == 'string' and (args.boxsize .. 'px') or nil)
:css('background', '#f9f9f9')
:css('font-size', '85%')
:css('line-height', '110%')
:css('font-style', 'italic')
:css('font-weight', 'bold')
 
-- Display the portals specified in the positional arguments.
Baris 147 ⟶ 210:
:newline()
:tag('li')
:css('display', 'table-row')
:tag('span')
:css('display', 'table-cell')
:css('padding', '0.2em')
:css('vertical-align', 'middle')
:css('text-align', 'center')
:wikitext(string.format('[[File:%s|32x28px|class=noviewer]]', image))
:done()
:tag('span')
:css('display', 'table-cell')
:css('padding', '0.2em 0.2em 0.2em 0.3em')
:css('vertical-align', 'middle')
:wikitext(string.format('[[Portal:%s|%s%sportal]]', portal, portal, args['break'] and '<br />' or ' '))
end
Baris 264 ⟶ 319:
end
end
return p[funcName](processPortalArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments.
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