This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
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.
A more complex version of Module:Data with more options and the ability to select indexes with an inequality operator.
Zeroth parameter is the name of the data module to read, without Module:, e.g. Example/data
Next parameters, for an index N starting at one, are called |N= for the exact index you need, coerced to number if possible, |N lteq= to select the highest numerical index less than or equal to the argument, or |N gteq= for the opposite.
|template= is a printf-style string to interpolate the resulting value(s) into, e.g. <b>%s</b>.
|preprocess= is like |template= except that frame:preprocess is run on it; this makes e.g. template transclusions work.
|if nil= is the string to return if the result is nil. Default is nil, which comes out as the empty string.
localp={}-- Finds the next key key <= or >= the given i.-- operator is ±1localfunctionfindItemRange(data,i,operator)localbestIndex=nili=i*operatorfork,vinpairs(data)dolocalkop=type(k)=='number'andk*operatorifkopandkop<=iand(bestIndex==nilorkop>bestIndex*operator)thenbestIndex=kendendifbestIndexthenreturndata[bestIndex]elsereturnnilendendlocalfunctionload(datamodule,frame)localargs=frame.argslocaldata=mw.loadData(datamodule)fori=1,20doifargs[i]thendata=data[tonumber(args[i])orargs[i]]elseifargs[i..' lteq']thendata=findItemRange(data,tonumber(args[i..' lteq']),1)elseifargs[i..' gteq']thendata=findItemRange(data,tonumber(args[i..' gteq']),-1)elsebreakendendifdata==nilthenreturnargs['if_nil']-- not a required argument, OK to return nil here.endiftype(data)=='table'then-- Put the table into another table because the return value of loadData-- is a "fake" table that only has certain metamethods.localrealdata={}fork,vinpairs(data)dorealdata[k]=venddata=realdataelsedata={data}endifargs['template']thenreturnmw.text.unstripNoWiki(args['template']):format(unpack(data))elseifargs['preprocess']thenreturnframe:preprocess(mw.text.unstripNoWiki(args['preprocess']):format(unpack(data)))elsereturntable.concat(data)endendreturnsetmetatable({},{__index=function(t,k)returnfunction(frame)ifk:sub(-5)=='.json'thenreturnload(mw.text.jsonDecode(mw.title.new(k).getContent()),frame)elsereturnload(mw.loadData('Module:'..k),frame)endendend})