Modul:Portal bar: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Tidak ada ringkasan suntingan
Taylor 49 (bicara | kontrib)
-require('Module:No globals')
 
(10 revisi perantara oleh 2 pengguna tidak ditampilkan)
Baris 1:
-- This module implements {{portal bar}}.
 
require('Module:No globalsstrict')
 
local p = {}
local function checkPortalExists(portal)
 
return not (mw.title.makeTitle(100, portal).id == 0)
local buildNavbox = require( 'Module:Navbox' )._navbox
end
local getImageName = require( 'Module:Portal' ).image
local yesno = require( 'Module:Yesno' )
Baris 11 ⟶ 12:
-- Builds the portal bar used by {{portal bar}}.
function p._main( portals, args )
if #portals < 1 then return '' end -- Don't display a blank navbox if no portals were specified.
local nav = mw.html.create( 'div' )
:addClass( 'noprint metadata' )
:attr( 'role', 'navigation' )
:attr( 'aria-label' , 'Portals' )
:css( 'font-sizeweight', '88%bold' )
if yesno( args.border ) == false then
nav
:css( 'padding', '1px0.3em 1.7em 0.1em' )
:css( 'widthfont-size', '10088%' )
:css( 'text-align', 'center' )
else
nav
:addClass( 'navbox' )
:css( 'white-spacepadding', 'nowrap0.4em 0em' )
end
-- scan for nonexistent portals, if they exist remove them from the portals table. If redlinks=yes, then don't remove
local portallen = #portals
-- traverse the list backwards to ensure that no portals are missed (table.remove also moves down the portals in the list, so that the next portal isn't checked if going fowards.
-- going backwards allows us to circumvent this issue
for i=portallen,1,-1 do
-- the use of pcall here catches any errors that may occour when attempting to locate pages when the page name is invalid
-- if pcall returns true, then rerun the function to find if the page exists
if not pcall(checkPortalExists, portals[i]) or not checkPortalExists(portals[i]) then
-- Getting here means a redlinked portal has been found
if (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
nav:wikitext('[[Kategori:Templat portal dengan portal berpranala merah]]')
break
end
-- remove the portal (this does not happen if redlinks=yes)
table.remove(portals,i)
end
end
-- 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 then
return '[[Kategori:Templat portal dengan seluruh portal berpranala merah]]'
end
nav:wikitext('[[Kategori:Templat portal dengan seluruh portal berpranala merah]]')
end
local list = mw.html.create( 'ul' )
:css( 'margin', '0.1em 0 0' )
for _, portal in ipairs( portals ) do
list
:tag( 'li' )
:css( 'display', 'inline' )
:tag( 'span' ) -- Inline-block on inner span for IE6-7 compatibility.
:css( 'white-space', 'nowrap' )
:tagcss( 'spandisplay', 'inline-block' )
:css( 'marginwhite-space', 'auto 0.5emnowrap' )
:tag( 'span' )
:wikitext( string.format( '[[File:%s|24x21px]]', getImageName{ portal } ) )
:donecss( 'margin', '0 0.5em' )
:wikitext( string.format( '[[File:%s|24x21px]]', getImageName{ portal } ) )
:tag( 'span' )
:cssdone( 'font-weight', 'bold' )
:wikitext( string.format( '[[Portal:%s|Portal %s]]', portal, portal ) )
end
if yesno( args.border ) == false then -- Don't display a border if args.border is "no", "n", "false", 0 or false.
nav
return tostring(
mw.html.create:node( 'div'list )
:addClass( 'noprint metadata' )
return tostring( nav )
:css( 'width', '100%' )
:css( 'text-align', 'center' )
:css( 'padding', '1px' )
:css( 'font-size', '88%' )
:node( list )
)
else
return buildNavbox{
navbar = 'off',
bodyclass = 'noprint',
list1 = tostring( list )
}
end
end