Revision as of 23:19, 8 October 2021 by Mediawiki>Mdaniels5757(Protected "Module:Transclude": High-risk Lua module ([Edit=Allow only template editors and administrators] (indefinite) [Move=Allow only template editors and administrators] (indefinite)))
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
Usage
{{#invoke:Transclude|template_name}}
-- <nowiki>---------------------------------------------------------------------------------- Module that allows transcluding a template with all parent arguments.-- Useful in `/i18n` template subpages that delegate to a `/layout` subpage.---- @module transclude-- @author [[User:ExE Boss]]-- @require [[Module:No globals]]--------------------------------------------------------------------------------require('Module:No globals')localcheckType=require('libraryUtil').checkType;localp={}localINVALID_TITLES={["."]=true,[".."]=true,};localfunction_ne(value)returnvalueandvalue~=''end---------------------------------------------------------------------------------- Helper function that merges argument tables.---- @function mergeArgs-- @param {table} inArgs-- @param {table} outArgs--------------------------------------------------------------------------------localfunctionmergeArgs(inArgs,outArgs,opts)checkType("mergeArgs",1,inArgs,"table");checkType("mergeArgs",2,outArgs,"table");checkType("mergeArgs",3,opts,"table",true);opts=optsor{}localignoredParams=opts.ignoredParams;localignoredPrefix=opts.ignoredPrefix;forname,valueinpairs(inArgs)doif(type(name)=="string")thenifnot((ignoredParamsandignoredParams[name]==true)or(ignoredPrefixandignoredPrefix==name:sub(1,ignoredPrefix:len())))thenoutArgs[name]=value;endelseoutArgs[name]=value;endendreturnoutArgs;end-- Exported for testing:p['#mergeArgs']=mergeArgs;localmt={};functionmt.__index(_,name)if(type(name)~="string"orINVALID_TITLES[name]ormw.ustring.find(name,"#",nil,true))thenreturnnil;endlocaltitle=mw.title.new(name,"Template")if(nottitle)thenreturnnil;endreturnfunction(frame)checkType('transclude["'..name..'"]',1,frame,"table");localparentFrame=frame:getParent();localignoredParams,ignoredPrefix;if_ne(frame.args["#ignoredParams"])thenignoredParams={};forminmw.text.gsplit(frame.args["#ignoredParams"],'|',true)doignoredParams[mw.text.trim(m)]=true;endendif_ne(frame.args['#ignoredPrefix'])thenignoredPrefix=frame.args['#ignoredPrefix'];endlocalargs={};if(parentFrame)thenmergeArgs(parentFrame.args,args,{ignoredParams=ignoredParams,ignoredPrefix=ignoredPrefix,});endmergeArgs(frame.args,args,{ignoredPrefix="#",});if(nottitle.exists)thenreturn"[[:"..title.fullText.."]]";endreturnframe:expandTemplate{title=title,args=args,};endendreturnsetmetatable(p,mt);