Jump to content

Module:Portal image banner

Permanently protected module
From Wikipedia, the free encyclopedia

localp={}localrandomModule=require('Module:Random')p.main=function(frame)localparent=frame.getParent(frame)localparentArgs=parent.argslocalargs=cleanupArgs(parentArgs)localoutput=p._main(args)returnframe:preprocess(output)endfunctioncleanupArgs(argsTable)localcleanArgs={}forkey,valinpairs(argsTable)doiftype(val)=='string'thenval=val:match('^%s*(.-)%s*$')ifval~=''thencleanArgs[key]=valendelsecleanArgs[key]=valendendreturncleanArgsendp._main=function(args)ifnotargs[1]thenreturnerror('No page specified',0)endlocallines=makeGalleryLinesTable(args)returnmakeOutput(lines,args.overflow,args.maxheight,args.mode,args.croptop)endfunctionmakeGalleryLine(file,caption,link)localtitle=mw.title.new(file,"File")locallinktext=(linkand'{{!}}link='..linkor'')localmaxImageWidth='{{!}}800px'return'[['..title.prefixedText..(captionand'{{!}}'..captionor'')..maxImageWidth..linktext..']]'..(captionand'\n<div style="text-align:center;">'..caption..'</div>'or'\n')endfunctionmakeGalleryLineSlideshow(file,caption)localtitle=mw.title.new(file,"File")localcaptiontext='[[File:OOjs_UI_icon_info-progressive.svg|link=:'..title.prefixedText..']]&nbsp;<span style="font-size:110%;">'..(captionor'')..'</span>'returntitle.prefixedText..'{{!}}'..captiontextendfunctionmakeGalleryLinesTable(args)localgalleryLinesTable={}locali=1whileargs[i]doifnotargs.modethentable.insert(galleryLinesTable,makeGalleryLine(args[i],args[i+1],args.link))elseifargs.mode=='slideshow'thentable.insert(galleryLinesTable,makeGalleryLineSlideshow(args[i],args[i+1],args.link))elseerror('Mode not supported')endi=i+2endreturngalleryLinesTableendfunctionmakeOutput(imageLines,overflow,maxHeight,mode,croptop)localrandomiseArgs={['t']=imageLines}localrandomisedLines=randomModule.main('array',randomiseArgs)localoutput,galleryContentifnotmodethengalleryContent=table.concat(randomisedLines,'\n',1,1)seperate=mw.text.split(galleryContent,'\n')output='<div class="portal-banner-image" style="max-height:'..(maxHeightor'initial')..'; overflow:'..(overflowor'auto')..';"><div class="portal-banner-image-crop" style="position:relative; margin-top:-'..(croptopor'0')..'%;">'..seperate[1]..'</div></div>'..seperate[2]elseifmode=='slideshow'thengalleryContent=table.concat(randomisedLines,'\n')output='<div class="portal-banner-image-slideshow nomobile" style="max-height:'..(maxHeightor'initial')..'; overflow:'..(overflowor'auto')..';"><div class="portal-banner-image-crop" style="position:relative; margin-top:-'..(croptopor'0')..'%;">'..'{{#tag:gallery|'..galleryContent..'|mode=slideshow}}'..'</div></div>'elseerror('Mode not supported')endreturnoutputendreturnp
close