Implements{{split article}}
localMessageBox=require("Module:Message box")localyesno=require("Module:Yesno")localp={}localfunctiondemoCheck(args)returnyesno(args["demo"])oryesno(args["nocat"])endlocalfunctionshowWarning(text,nocat)mw.addWarning(text)returnnocatand""or"[[Category:Pages with split article warnings]]"endlocalfunctiondelink(text)iftext==nilthenreturnnilendreturnstring.gsub(string.gsub(require("Module:Delink")._delink{text},"%[%[",""),"%]%]","")endlocalfunctionshowError(text,nocat)returnstring.format("%s%s %s",nocatand""or"[[Category:Pages with split article errors]] ",tostring(mw.html.create("span"):css("color","red"):css("font-weight","bold"):wikitext("Error:")),text)endlocalfunctionsingleText(args)localtext=""-- from1 also included in case someone filed the template improperlylocalfrom=delink(args["from"]orargs["from1"])ormw.title.getCurrentTitle().subjectPageTitle.prefixedTextlocalfromTalk=mw.title.new(from).talkPageTitle.prefixedTextifargs["from1"]thentext=text..showWarning("<code>from</code> is not a row-based parameter. Use <code>from</code> instead of <code>from1</code>.",demoCheck(args))end-- Row-based parameterslocalto=delink(args["to"]orargs["to1"])localdiff=args["diff"]orargs["diff1"]localdate=args["date"]orargs["date1"]localfrom_oldid=args["from_oldid"]orargs["from_oldid1"]ifto==nilthenreturnshowError("Target page was not specified with <code>to</code>.",demoCheck(args))endifdate==nilthentext=text..showWarning("Split date was not specified with <code>date</code>. This may cause an error in the future.",demoCheck(args))endtext=string.format("Material from [[%s]] was split out into [[%s]]",from,to,date)ifdiff~=nilanddate~=nilthenifdiff:match("^[0123456789/]+$")thentext=string.format("%s on [[Special:Diff/%s|%s]]",text,diff,date)elsetext=string.format("%s on [%s %s]",text,diff,date)endelseifdate~=nilthentext=string.format("%s on %s",text,date)endiffrom_oldid~=niltheniffrom_oldid:match("^[0123456789/]+$")thentext=string.format("%s from [[Special:Diff/%s|this version]]",text,from_oldid)elsetext=string.format("%s from [%s this version]",text,from_oldid)endendtext=string.format("%s. The former page's [[Special:PageHistory/%s|history]] now serves to ".."[[Wikipedia:Copying within Wikipedia|provide attribution]] for that content ".."in the latter page, and it must not be deleted so long as the latter page ".."exists. Please leave this template in place to link the article histories ".."and preserve this attribution.",text,from)iffromTalk~=mw.title.getCurrentTitle().prefixedTextthentext=string.format("%s The former page's talk page can be accessed at [[%s]].",text,fromTalk)endreturntextendlocalfunctionrow(args,i)localtext=""localto=delink(args["to"..i]or(i==1andargs["to"]ornil))localtoTalk=mw.title.new(delink(to)).subjectPageTitle.prefixedTextlocaldiff=args["diff"..i]or(i==1andargs["diff"]ornil)localdate=args["date"..i]or(i==1andargs["date"]ornil)localfrom_oldid=args["from_oldid"..i]or(i==1andargs["from_oldid"]ornil)ifdate==nilthentext=text..showWarning(string.format("Split date for\"%s\" (<code>to%s</code>) was not specified with <code>date</code>. This may cause an error in the future.",to,i),demoCheck(args))endlocalrowText=string.format("[[%s]] ([[%s|talk]] | [[Special:PageHistory/%s|history]])",to,toTalk,to,date,diff)ifdiff~=nilanddate~=nilthenifdiff:match("^[0123456789/]+$")thenrowText=string.format("%s on [[Special:Diff/%s|%s]]",rowText,diff,date)elserowText=string.format("%s on [%s %s]",rowText,diff,date)endelseifdate~=nilthenrowText=string.format("%s on %s",rowText,date)endiffrom_oldid~=niltheniffrom_oldid:match("^%d+$")thenrowText=string.format("%s from [[Special:Diff/%s|this version]]",rowText,from_oldid)elserowText=string.format("%s from [%s this version]",rowText,from_oldid)endendreturnmw.html.create("li"):wikitext(rowText)endlocalfunctionmultiText(args)localtext=""-- from1 also included in case someone filed the template improperlylocalfrom=delink(args["from"]orargs["from1"])ormw.title.getCurrentTitle().subjectPageTitle.prefixedTextlocalfromTalk=mw.title.new(delink(from)).talkPageTitle.prefixedTextlocalcollapse=tonumber(args["collapse"])oryesno(args["collapse"])ifargs["from1"]thentext=text..showWarning("<code>from</code> is not a row-based parameter. Use <code>from</code> instead of <code>from1</code>.",demoCheck(args))endifargs["from_oldid1"]thentext=text..showWarning("<code>from_oldid</code> is not a row-based parameter. Use <code>from_oldid</code> instead of <code>from_oldid1</code>.",demoCheck(args))endtext=string.format("Material from [[%s]] was split out into other pages. The former page's ".."[[Special:PageHistory/%s|history]] now serves to ".."[[Wikipedia:Copying within Wikipedia|provide attribution]] for that content ".."in the latter pages, and it must not be deleted so long as the latter pages ".."exist. Please leave this template in place to link the article histories ".."and preserve this attribution.",from,from)localul=mw.html.create("ul")localul2localtarget=ul-- Row-based parameterslocali=1whileargs["to"..i]or(i==1andargs["to"])do-- Swap out ul with collapsible table if collapsibleifcollapse==trueandi==1then-- Only on first runtarget=mw.html.create("table"):attr("class","mw-collapsible mw-collapsed"):attr("style","width:100%; background-color: var( --background-color-warning-subtle, #fdf2d5 ); color: inherit;"):node(mw.html.create("tr"):node(mw.html.create("th"):wikitext("Page splits"))):node(mw.html.create("td"):node(ul))elseifcollapse==(i-1)thenul2=ulul=mw.html.create("ul")-- Only once threshold has been reachedtarget=mw.html.create("table"):attr("class","mw-collapsible mw-collapsed"):attr("style","width:100%; background-color: var( --background-color-warning-subtle, #fdf2d5 ); color: inherit;"):node(mw.html.create("tr"):node(mw.html.create("th"):wikitext("Other page splits"))):node(mw.html.create("tr"):node(mw.html.create("td"):node(ul)))endul:node(row(args,i))i=i+1endiffromTalk~=mw.title.getCurrentTitle().prefixedTextthentext=string.format("%s The former page's talk page can be accessed at [[%s]].",text,fromTalk)endtext=text.." "..tostring(ul2or"")..tostring(target)returntextendlocalfunctionbannerText(args)-- Checks if there are multiple rowslocaltextifargs["to2"]~=niland((args["to1"]orargs["to"])~=nil)thentext=multiText(args)--.. categories(args,true)elsetext=singleText(args)--.. categories(args,false)endreturntextendfunctionp.renderBanner(args)returnMessageBox.main('tmbox',{name="split-article",small=args["small"],image='[[File:Split-arrows.svg|50px]]',text=bannerText(args)})endfunctionp.main(frame)localgetArgs=require('Module:Arguments').getArgslocalargs=getArgs(frame,{trim=true,removeBlanks=true})returnp.renderBanner(args)endreturnp