Selasa, 29 September 2026
05:53 WIB
TERKINI
Berita Fenomena Unik 'Hujan Salju' di Lapangan Sempur Bogor, Warga Sambut Riang Internasional Profesor Biao Xiang: Idola Gen Z China yang Berani Bahas Kecemasan Hidup Berita Pelaku Injak Al-Qur'an di Lebak Divonis Penjara, Wajib Minta Maaf Publik Berita Dilema Ganjil Genap Jakarta: Evaluasi Setelah 1 Dekade, Relaksasi Jadi Perdebatan Berita Evakuasi Buaya Peliharaan di Bandar Lampung Penuh Haru, Pemilik Sempat Pingsan Berita Polemik Buku 'Memburu Muhammad': Penulis dan Tokoh Islam Jelaskan Niat Baik Regional Flyover Ciroyom Bandung Rampung, Solusi Baru Atasi Kemacetan Kota Regional Informasi Persiapan Vihara Jelang Imlek Belum Tersedia Regional Wujudkan Rumah Impian: Pendaftaran KPR Kini dalam Genggaman dengan BTN Mobile Prelude Mengungkap Akal-akalan Aturan Pemilu Melalui Lensa Pareto Berita Fenomena Unik 'Hujan Salju' di Lapangan Sempur Bogor, Warga Sambut Riang Internasional Profesor Biao Xiang: Idola Gen Z China yang Berani Bahas Kecemasan Hidup Berita Pelaku Injak Al-Qur'an di Lebak Divonis Penjara, Wajib Minta Maaf Publik Berita Dilema Ganjil Genap Jakarta: Evaluasi Setelah 1 Dekade, Relaksasi Jadi Perdebatan Berita Evakuasi Buaya Peliharaan di Bandar Lampung Penuh Haru, Pemilik Sempat Pingsan Berita Polemik Buku 'Memburu Muhammad': Penulis dan Tokoh Islam Jelaskan Niat Baik Regional Flyover Ciroyom Bandung Rampung, Solusi Baru Atasi Kemacetan Kota Regional Informasi Persiapan Vihara Jelang Imlek Belum Tersedia Regional Wujudkan Rumah Impian: Pendaftaran KPR Kini dalam Genggaman dengan BTN Mobile Prelude Mengungkap Akal-akalan Aturan Pemilu Melalui Lensa Pareto

Modul:Portal

Wikimedia module

Dokumentasi modullihatsuntingriwayatsegarkan
WarningModul Lua ini digunakan pada sekitar 528.000 halaman, atau sekira 12% dari keseluruhan halaman.
Untuk mencegah suntingan mengganggu skala besar dan beban peladen, setiap perubahan harus diuji di subhalaman /bak pasir atau /kasus uji Modul:Portal, atau bak pasir modul Anda. Perubahan yang telah diuji kemudian dapat ditambahkan ke halaman ini dalam satu suntingan. Pertimbangkan untuk mendiskusikan perubahan di halaman pembicaraan sebelum mengimplementasikannya.
DiproteksiModul ini dilindungi. Modul ini sangat mencolok yang digunakan oleh banyak halaman, atau sangat sering disubstitusikan. Karena vandalisme atau kesalahan akan mempengaruhi banyak halaman, dan suntingan kecil dapat memberi beban besar pada server, modul ini dilindungi dari penyuntingan.
Modul ini menggunakan Lua:
CSSModul ini menggunakan TemplateStyles:

Modul ini memiliki dua fungsi, portal dan gambar. portal menghasilkan kotak dengan tautan ke portal atau ke beberapa portal, dan digunakan oleh {{portal}} templat. Ini paling sering digunakan dalam "Lihat juga" bagian dari sebuah artikel. image fungsi menghasilkan nama gambar yang digunakan oleh portal yang ditentukan.

Lihat here, here, dan here untuk kasus uji.

Fungsi portalFungsi portal

Fungsi portal menghasilkan kotak tautan portal.

UsageUsage

Basic usage

{{#invoke:Portal|portal |Portal 1 |Portal 2 |Portal 3 |... }}

LocationLocation

Within articles, the output of the portal function is meant to be placed at the top of the article's See also section. If there is no See also section, you may put it in the External links section instead; there is no need to create a new section just to house this template. If there is no External links section either, just put it below the article text in the place that seems most appropriate.

There are no particular rules about the placement of portals on other kinds of pages.

ImageImage

The portal image names are stored in subpages of Module:Portal/images, organised by the first letter of the portal name. For example, the first letter of Portal:Feminism is "F", so the image name is stored at Module:Portal/images/f. If there is an entry for a portal on the correct page then the corresponding image will be shown next to the portal link. If no image is found then File:Portal-puzzle.svg will be shown instead.

It is also possible to specify aliases for portal images. For example, the code {{Portal|Detroit}} produces the same image as the code {{Portal|Metro Detroit}}. The "Detroit" alias is found on the page Module:Portal/images/aliases.

The image-detection algorithm is case-insensitive. For example, the code {{Portal|Detroit}} will produce the same image as the code {{Portal|detroit}} (although the portal links will be different). Portal names are stored in lower case in the image subpages, and input is converted to lower case before being checked.

To add new images to the list, please make a protected edit request at Template talk:Portal to get an administrator to edit the correct subpage for you. Portal images must be either in the public domain or available under a free license that allows commercial reuse and derivative works; fair-use images are not acceptable. The template {{Portal icon demonstration}} may be of use when deciding whether an image is suitable for use as a portal icon; it formats an image using the same size and style that the {{Portal}} template uses by default.

A list of portals and aliases of portals without icons can be found at Category:Portal templates with default image.

List of image subpages
Page Description
Module:Portal/images/a For portal names starting with "A".
Module:Portal/images/b For portal names starting with "B".
Module:Portal/images/c For portal names starting with "C".
Module:Portal/images/d For portal names starting with "D".
Module:Portal/images/e For portal names starting with "E".
Module:Portal/images/f For portal names starting with "F".
Module:Portal/images/g For portal names starting with "G".
Module:Portal/images/h For portal names starting with "H".
Module:Portal/images/i For portal names starting with "I".
Module:Portal/images/j For portal names starting with "J".
Module:Portal/images/k For portal names starting with "K".
Module:Portal/images/l For portal names starting with "L".
Module:Portal/images/m For portal names starting with "M".
Module:Portal/images/n For portal names starting with "N".
Module:Portal/images/o For portal names starting with "O".
Module:Portal/images/p For portal names starting with "P".
Module:Portal/images/q For portal names starting with "Q".
Modulel:Portal/images/r For portal names starting with "R".
Modulel:Portal/images/s For portal names starting with "S".
Modulel:Portal/images/t For portal names starting with "T".
Modulel:Portal/images/u For portal names starting with "U".
Modulel:Portal/images/v For portal names starting with "V".
Modul:Portal/images/w For portal names starting with "W".
Modul:Portal/images/x For portal names starting with "X".
Modul:Portal/images/y For portal names starting with "Y".
Modul:Portal/images/z For portal names starting with "Z".
Module:Portal/images/other For portal names starting with any other letters. This includes numbers, letters with diacritics, and letters in non-Latin alphabets.
Module:Portal/images/aliases For adding aliases for existing portal names. Use this page for variations in spelling and diacritics, etc., no matter what letter the portal begins with.

ContohContoh

Kotak pada format kanan dengan teks kecil dapat menggabungkan beberapa portal.

Box

{{Portal|Kanada}}

{{Portal|Kanada|Contoh}}

Format sebaris untuk sisi kanan dengan teks berukuran normal: Lihat Template:Portal-inline untuk daftar parameter.

Inline

Format sebaris untuk sisi kanan dengan teks berukuran normal: Lihat Template:Portal untuk informasi lebih lanjut.

Bar

The bar format is normally used for multiple portals. This template does not belong in the "See also" section. Per MOS:SECTIONORDER, this template is bottom matter and goes below standard navigation templates.

{{Portal bar|Kanada|Contoh|border=no}}


ParametersParameters

Name Value Description
1, 2, 3 ... The portal name, e.g. Literature The positional parameters specify the portals to be displayed.
left yes If set to yes, the portal appears on the left side of the page instead of the right.
margin CSS margin value, e.g. 1.2em 3em 0.5em 1em This allows you to set a custom margin. All valid CSS margin values are accepted.
break yes If set to yes, a line break is inserted after the portal name and before the word portal.
redlinks Any of the following values: yes, y, true, or include Redlinks will be displayed. The default is to suppress redlinks.
nominimum Any of the following values: yes, y, or true Suppresses the warning if no parameters are supplied. This can be useful when Template:Portal is called by another template.
border Any of the following values: no, n, or false Turn off border and background
tracking Any of the following values: no, n, false Tracking categories will be suppressed. The default is to use tracking categories, except on certain namespaces and on pagenames which contain "/archive", "/doc" or "/test".

Error trackingError tracking

If the module is used incorrectly, the page will be added to a tracking category.

The tracking categories are not applied if any of the following is true:

  1. Tracking is specially disabled for that usage. This is done by setting the optional parameter |tracking= to any the following values: no, n, false
  2. the template is used on a page in any of these namespaces: Talk, User, User talk, Wikipedia talk, File talk, Template talk, Category talk, Portal talk, Draft, Draft talk, Module talk
  3. The title page on which the template is used includes any of the following case-insensitive strings: "/archive", "/doc", "/test"
Bersihkan tembolok server


Fungsi gambarFungsi gambar

Fungsi gambar menghasilkan nama gambar yang digunakan oleh portal yang ditentukan.

PenggunaPengguna

{{#invoke:Portal|image|portal}}

ContohContoh

  • {{#invoke:Portal|image|Art}} → Ballerina-icon.jpg

Fungsi penipuan gambarFungsi penipuan gambar

Fungsi duplikasi gambar mengembalikan daftar semua gambar yang digunakan oleh lebih dari satu portal (alias tidak termasuk). Ini dapat membantu dalam mengidentifikasi entri gambar yang harus diubah untuk menggunakan alias.

PenggunaPengguna

{{#invoke:Portal|imageDupes}}

Tampilkan semua fungsiTampilkan semua fungsi

gambar. Ini digunakan untuk pemeliharaan, dan tidak boleh ditampilkan dalam artikel, karena) ada sekitar 1000 portal dengan gambar, dan menampilkan 1000 gambar pada satu halaman membutuhkan banyak sumber daya server, dan b) Modul ini tidak memiliki cara untuk mengetahui kapitalisasi nama portal yang benar, sehingga beberapa tautan ke portal akan terputus. Output dari fungsi ini dapat dilihat di Template:Portal/doc/all.

PenggunaPengguna

{{#invoke:Portal|displayAll}}
Dokumentasi di atas ditransklusikan dari Modul:Portal/doc. (sunting | riwayat)
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
--[==[ This module is a Lua implementation of the old {{Portal}} template. As of October 2025 it is used on nearly 478,000 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.
-- The portal image data is kept in submodules of [[Module:Portal/images]], listed below:
-- [[Module:Portal/images/a]]		- for portal names beginning with "A".
-- [[Module:Portal/images/b]]		- for portal names beginning with "B".
-- [[Module:Portal/images/c]]		- for portal names beginning with "C".
-- [[Module:Portal/images/d]]		- for portal names beginning with "D".
-- [[Module:Portal/images/e]]		- for portal names beginning with "E".
-- [[Module:Portal/images/f]]		- for portal names beginning with "F".
-- [[Module:Portal/images/g]]		- for portal names beginning with "G".
-- [[Module:Portal/images/h]]		- for portal names beginning with "H".
-- [[Module:Portal/images/i]]		- for portal names beginning with "I".
-- [[Module:Portal/images/j]]		- for portal names beginning with "J".
-- [[Module:Portal/images/k]]		- for portal names beginning with "K".
-- [[Module:Portal/images/l]]		- for portal names beginning with "L".
-- [[Module:Portal/images/m]]		- for portal names beginning with "M".
-- [[Module:Portal/images/n]]		- for portal names beginning with "N".
-- [[Module:Portal/images/o]]		- for portal names beginning with "O".
-- [[Module:Portal/images/p]]		- for portal names beginning with "P".
-- [[Module:Portal/images/q]]		- for portal names beginning with "Q".
-- [[Module:Portal/images/r]]		- for portal names beginning with "R".
-- [[Module:Portal/images/s]]		- for portal names beginning with "S".
-- [[Module:Portal/images/t]]		- for portal names beginning with "T".
-- [[Module:Portal/images/u]]		- for portal names beginning with "U".
-- [[Module:Portal/images/v]]		- for portal names beginning with "V".
-- [[Module:Portal/images/w]]		- for portal names beginning with "W".
-- [[Module:Portal/images/x]]		- for portal names beginning with "X".
-- [[Module:Portal/images/y]]		- for portal names beginning with "Y".
-- [[Module:Portal/images/z]]		- for portal names beginning with "Z".
-- [[Module:Portal/images/other]]	- for portal names beginning with any other letters. This includes numbers,
-- 									  letters with diacritics, and letters in non-Latin alphabets.
-- [[Module:Portal/images/aliases]]	- for adding aliases for existing portal names. Use this page for variations
-- 									  in spelling and diacritics, etc., no matter what letter the portal begins with.
--
-- The images data pages are separated by the first letter to reduce server load when images are added, changed, or removed.
-- Previously all the images were on one data page at [[Module:Portal/images]], but this had the disadvantage that all
-- 5,000,000 pages using this module needed to be refreshed every time an image was added or removed.
]==]
localp={}
-- determine whether we're being called from a sandbox
localisSandbox=mw.getCurrentFrame():getTitle():find('sandbox',1,true)
localsandbox=isSandboxand'/sandbox'or''
localfunctionsandboxVersion(s)
returnisSandboxands..'-sand'ors
end
localtemplatestyles='Module:Portal'..sandbox..'/styles.css'
localgetArgs=require('Module:Arguments').getArgs
localyesno=require('Module:Yesno')
-- List of non-talk namespaces which should not be tracked (Talk pages are never tracked)
localbadNamespaces={'user','template','draft','wikipedia'}
-- Check whether to do tracking in this namespace
-- Returns true unless the page is one of the banned namespaces
localfunctioncheckTracking(title)
localthisPage=titleormw.title.getCurrentTitle()
ifthisPage.isTalkPagethen
returnfalse
end
localns=thisPage.nsText:lower()
for_,vinipairs(badNamespaces)do
ifns==vthen
returnfalse
end
end
returntrue
end
localfunctionmatchImagePage(s)
-- Finds the appropriate image subpage given a lower-case
-- portal name plus the first letter of that portal name.
iftype(s)~='string'or#s<1thenreturnend
localfirstLetter=mw.ustring.sub(s,1,1)
localimagePage
ifmw.ustring.find(firstLetter,'^[a-z]')then
imagePage='Module:Portal/images/'..firstLetter..sandbox
else
imagePage='Module:Portal/images/other'..sandbox
end
returnmw.loadData(imagePage)[s]
end
localfunctiongetAlias(s)
-- Gets an alias from the image alias data page.
localaliasData=mw.loadData('Module:Portal/images/aliases'..sandbox)
forportal,aliasesinpairs(aliasData)do
for_,aliasinipairs(aliases)do
ifalias==sthen
returnportal
end
end
end
end
localdefaultImage='Portal-puzzle.svg|link=|alt='
localfunctiongetImageName(s)
-- Gets the image name for a given string.
iftype(s)~='string'or#s<1then
returndefaultImage
end
s=mw.ustring.lower(s)
localimage=matchImagePage(s)ormatchImagePage(getAlias(s))ordefaultImage
image=mw.ustring.gsub(image,'^File:','')--- strip mistaken leading File: or Image:
image=mw.ustring.gsub(image,'^Image:','')
returnimage
end
localfunctionexists(title)
localsuccess,exists=pcall(function()returntitle.existsend)
-- If success = false, then we're out of expensive parser function calls and can't check whether it exists
-- in that case, don't throw a Lua error
returnnotsuccessorexists
end
-- Function to check argument portals for errors, generate tracking categories if needed
--     Function first checks for too few/many portals provided
--     Then checks the portal list to purge any portals that don't exist
-- Arguments:
--   portals: raw list of portals
--   args.tracking: is tracking requested? (will not track on bad titles or namespaces)
--   args.redlinks: should redlinks be displayed?
--   args.minPortals: minimum number of portal arguments
--   args.maxPortals: maximum number of portal arguments
-- Returns:
--   portals = list of portals, with redlinks purged (if args.redlinks=false)
--   trackingCat = possible tracking category
--   errorMsg = error message
functionp._checkPortals(portals,args)
localtrackingCat=''
localerrMsg=nil
-- 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 or pagename tests 
localtrackingEnabled=args.trackingandcheckTracking()
args.minPortals=args.minPortalsor1
args.maxPortals=args.maxPortalsor-1
-- check for too few portals
if#portals<args.minPortalsthen
errMsg='please specify at least '..args.minPortals..' portal'..(args.minPortals>1and's'or'')
trackingCat=(trackingEnabledand'[[Category:Portal templates with too few portals]]'or'')
returnportals,trackingCat,errMsg
end
-- check for too many portals
ifargs.maxPortals>=0and#portals>args.maxPortalsthen
errMsg='too many portals (maximum = '..args.maxPortals..')'
trackingCat=(trackingEnabledand'[[Category:Portal templates with too many portals]]'or'')
returnportals,trackingCat,errMsg
end
ifnotargs.redlinksortrackingEnabledthen
-- make new list of portals that exist
localexistingPortals={}
for_,portalinipairs(portals)do
localportalTitle=mw.title.new(portal,"Portal")
-- if portal exists, put it into list
ifportalTitleandexists(portalTitle)then
table.insert(existingPortals,portal)
-- otherwise set tracking cat
elseiftrackingEnabledthen
trackingCat="[[Category:Portal templates with redlinked portals]]"
end
end
-- If redlinks is off, use portal list purged of redlinks
portals=args.redlinksandportalsorexistingPortals
-- if nothing left after purge, set tracking cat
if#portals==0andtrackingEnabledthen
trackingCat=trackingCat.."[[Category:Pages with empty portal template]]"
end
end
returnportals,trackingCat,errMsg
end
localfunctionportalBox(args)
returnmw.html.create('ul')
:attr('role','navigation')
:attr('aria-label','Portals')
:addClass('noprint')
:addClass(args.errorand''orsandboxVersion('portalbox'))
:addClass(args.borderandsandboxVersion('portalborder')or'')
:addClass(sandboxVersion(args.leftand'portalleft'or'portalright'))
:css('margin',args.marginornil)
:newline()
end
localfunctionfillBox(root,contents)
for_,iteminipairs(contents)do
localentry=root:tag('li')
entry:addClass(sandboxVersion('portalbox-entry'))
localimage=entry:tag('span')
image:addClass(sandboxVersion('portalbox-image'))
image:wikitext(item[1])
locallink=entry:tag('span')
link:addClass(sandboxVersion('portalbox-link'))
link:wikitext(item[2])
end
returnroot
end
localfunctionnoviewer(portalImage)
-- Function to add noviewer class to filespec for portalImage
localportalImage,hasClass=mw.ustring.gsub(portalImage,"class%s*=[^%|]+","%0 noviewer")
ifhasClass==0then
portalImage=portalImage.."|class=noviewer"
end
returnportalImage
end
functionp._portal(portals,args)
-- This function builds the portal box used by the {{portal}} template.
-- Normalize all arguments
ifargs.redlinks=='include'thenargs.redlinks=trueend
args.addBreak=args['break']
forkey,defaultinpairs({left=false,tracking=true,nominimum=false,
redlinks=false,addBreak=false,border=true})do
ifargs[key]==nilthenargs[key]=defaultend
args[key]=yesno(args[key],default)
end
localroot=portalBox(args)
localtrackingCat=''
localerrMsg=nil
args.minPortals=args.nominimumand0or1
args.maxPortals=-1
portals,trackingCat,errMsg=p._checkPortals(portals,args)
root:wikitext(trackingCat)
-- if error message, put it in the box and return
iferrMsgthen
ifargs.borderthen-- suppress error message when border=no
args.error=true-- recreate box without fancy formatting
root=portalBox(args)
root:wikitext(trackingCat)
localerrTag=root:tag('strong')
errTag:addClass('error')
errTag:css('padding','0.2em')
errTag:wikitext('Error: '..errMsg)
end
returntostring(root)
end
-- if no portals (and no error), just return tracking category
if#portals==0then
returntrackingCat
end
localcontents={}
-- Display the portals specified in the positional arguments.
localdefaultUsed=nil
for_,portalinipairs(portals)do
localportalImage=getImageName(portal)
ifportalImage==defaultImagethen
defaultUsed=portal
else
portalImage=noviewer(portalImage)
end
localimage=string.format('[[File:%s|32x28px]]',
portalImage)
locallink=string.format('[[Portal:%s|Portal %s%s]]',
portal,portal,args.addBreakand'<br />'or' ')
table.insert(contents,{image,link})
end
ifdefaultUsedandargs.trackingandcheckTracking()then
localcat=string.format('[[Category:Portal templates with default image|%s]]',
defaultUsed)
root:wikitext(cat)
end
returntostring(fillBox(root,contents))
end
functionp._demo(imageList,args)
forkey,defaultinpairs({left=false,border=true})do
ifargs[key]==nilthenargs[key]=defaultend
args[key]=yesno(args[key],default)
end
localroot=portalBox(args)
localcontents={}
-- Display the portals specified in the positional arguments.
for_,fninipairs(imageList)do
localimage=string.format('[[File:%s|32x28px]]',noviewer(fn))
locallink=string.format('[[:File:%s|%s]]',fn,fn)
table.insert(contents,{image,link})
end
returntostring(fillBox(root,contents))
end
functionp._image(portal,keep)
-- Wrapper function to allow getImageName() to be accessed through #invoke.
-- backward compatibility: if table passed, take first element
iftype(portal)=='table'then
portal=portal[1]
end
localname=getImageName(portal)
-- If keep is yes (or equivalent), then allow all metadata (like image borders) to be returned
-- also, add "noviewer" class to metadata
localkeepargs=yesno(keep)
ifkeepargsthen
returnnoviewer(name)
end
-- otherwise, just keep filename, plus optional category
localargs=mw.text.split(name,"|",true)
localresult={args[1]}-- the filename always comes first
localcategory=''
-- parse name, looking for category arguments
fori=2,#argsdo
localm=mw.ustring.match(args[i],"^%s*category%s*=")
ifmthen
table.insert(result,args[i])
end
end
-- reassemble arguments
returntable.concat(result,"|")
end
localfunctiongetAllImageTable()
-- Returns an array containing all image subpages (minus aliases) as loaded by mw.loadData.
localimages={}
fori,subpageinipairs{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','other'}do
localimageTable=mw.loadData('Module:Portal/images/'..subpage..sandbox)
forportal,imageinpairs(imageTable)do
localargs=mw.text.split(image,"|")
images[portal]=args[1]-- just use image filename
end
end
returnimages
end
functionp._displayAll(portals,args)
-- This function displays all portals that have portal images. This function is for maintenance purposes and should not be used in
-- articles, for two reasons: 1) there are over 1500 portals with portal images, and 2) the module doesn't record how the portal
-- names are capitalized, so the portal links may be broken.
locallang=mw.language.getContentLanguage()
portals=portalsor{}
forportalinpairs(getAllImageTable())do
table.insert(portals,lang:ucfirst(portal))
end
table.sort(portals)
args.redlinks=args.redlinksor"yes"
returnp._portal(portals,args)
end
functionp._imageDupes()
-- This function searches the image subpages to find duplicate images. If duplicate images exist, it is not necessarily a bad thing,
-- as different portals might just happen to choose the same image. However, this function is helpful in identifying images that
-- should be moved to a portal alias for ease of maintenance.
localexists,dupes={},{}
forportal,imageinpairs(getAllImageTable())do
ifnotexists[image]then
exists[image]=portal
else
table.insert(dupes,string.format('The image "[[:File:%s|%s]]" is used for both portals "%s" and "%s".',image,image,exists[image],portal))
end
end
if#dupes<1then
return'No duplicate images found.'
else
return'The following duplicate images were found:\n* '..table.concat(dupes,'\n* ')
end
end
localfunctionprocessPortalArgs(args)
-- This function processes a table of arguments and returns two tables: an array of portal names for processing by ipairs, and a table of
-- the named arguments that specify style options, etc. We need to use ipairs because we want to list all the portals in the order
-- they were passed to the template, but we also want to be able to deal with positional arguments passed explicitly, for example
-- {{portal|2=Politics}}. The behaviour of ipairs is undefined if nil values are present, so we need to make sure they are all removed.
args=type(args)=='table'andargsor{}
localportals={}
localnamedArgs={}
fork,vinpairs(args)do
iftype(k)=='number'andtype(v)=='string'then-- Make sure we have no non-string portal names.
table.insert(portals,k)
elseiftype(k)~='number'then
namedArgs[k]=v
end
end
table.sort(portals)
fori,vinipairs(portals)do
portals[i]=args[v]
end
returnportals,namedArgs
end
-- Entry point for sorting portals from other named arguments
functionp._processPortalArgs(args)
returnprocessPortalArgs(args)
end
functionp.image(frame)
localorigArgs=getArgs(frame)
localportals,args=processPortalArgs(origArgs)
returnp._image(portals[1],args.border)
end
functionp.demo(frame)
localargs=getArgs(frame)
localstyles=frame:extensionTag{name='templatestyles',args={src=templatestyles}}
returnstyles..p._demo(args,args)
end
localfunctionmakeWrapper(funcName)
-- Processes external arguments and sends them to the other functions.
returnfunction(frame)
-- If called via #invoke, use the args passed into the invoking
-- template, or the args passed to #invoke if any exist. Otherwise
-- assume args are being passed directly in from the debug console
-- or from another Lua module. 
-- Also: trim whitespace and remove blank arguments
localorigArgs=getArgs(frame)
-- create two tables to pass to func: an array of portal names, and a table of named arguments.
localportals,args=processPortalArgs(origArgs)
localresults=''
iffuncName=='_portal'orfuncName=='_displayAll'then
results=frame:extensionTag{name='templatestyles',args={src=templatestyles}}
end
returnresults..p[funcName](portals,args)
end
end
for_,funcNameinipairs{'portal','imageDupes','displayAll'}do
p[funcName]=makeWrapper('_'..funcName)
end
returnp
Konten disalin dari Wikipedia Bahasa Indonesia (lisensi CC BY-SA) Lihat versi asli di Wikipedia

Rekomendasi Pilihan