--{{#invoke:Sandbox/trappist the monk/template compare|compare|<template A>|<template B>}}require('strict');--[[--------------------------< T E M P L A T E _ P A R A M S _ G E T >----------------------------------------gets parameters used by template from unparsed template wikitext and adds each to param_list.returns true on success; false when template does not exist]]localfunctiontemplate_params_get(template,param_list)localcontent=mw.title.new(template):getContent();-- get unparsed wikitext from the templateifnotcontentthenreturnfalse;-- announce failureendforparamincontent:gmatch('{{{([^}|]+)')do-- fetch each parameter in the templateparam_list[param]=true;-- and add it to its list tableendreturntrue;-- announce successend--[[--------------------------< D I F F _ L I S T _ M A K E >--------------------------------------------------loop through source template's parameter list looking for parameters not also found in target's parameter list.when parameter is unique to source, add it to diff list with source template's namereturns nothing]]localfunctiondiff_list_make(src,tgt,src_name,diff)forparam,_inpairs(src)do-- look for source template parameters in target template's parameter listifnottgt[param]thendiff[param]=src_name;-- not found add to diff table with name of source templateendendend--[[--------------------------< C O M P A R E >----------------------------------------------------------------module entry pointcreate a list of parameter names not shared between two templatesreturns the list of unique parameter names]]localfunctioncompare(frame)localA={};-- table to hold the parameters used in the first of two templateslocalB={};-- table to hold the parameters used in the second of two templateslocaldiff={};-- table to hold the parameters that are not shared between the two templateslocalA_src=frame.args[1];-- get template nameslocalB_src=frame.args[2];ifnotA_src:match('^Template:')then-- if namespace missingA_src='Template:'..A_src;-- add itendifnotB_src:match('^Template:')then-- if namespace missingB_src='Template:'..B_src;-- add itendlocalret_val=template_params_get(A_src,A);-- get parameters from first templateifnotret_valthenreturn'<span style="font-size:100%;" class="error">error: no '..A_src..'</span>';endret_val=template_params_get(B_src,B);-- get parameters from second templateifnotret_valthenreturn'<span style="font-size:100%;" class="error">error: no '..B_src..'</span>';enddiff_list_make(A,B,A_src:gsub('^Template:',''),diff);-- add parameters used in A that are not used in B; strip namespace for readabilitydiff_list_make(B,A,B_src:gsub('^Template:',''),diff);-- add parameters used in B that are not used in Areturnmw.dumpObject(diff);-- for now; prettify laterend--[[--------------------------< L I S T >----------------------------------------------------------------------module entry pointcreate a list of parameter namesreturns the list of parameter names]]localfunctionlist(frame)localA={};-- table to hold the parameters used in the first of two templateslocalA_src=frame.args[1];-- get template namesifnotA_src:match('^Template:')then-- if namespace missingA_src='Template:'..A_src;-- add itendlocalret_val=template_params_get(A_src,A);-- get parameters from first templateifnotret_valthenreturn'<span style="font-size:100%;" class="error">error: no '..A_src..'</span>';endreturnmw.dumpObject(A);-- for now; prettify laterend--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------]]return{compare=compare,list=list,}