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.
This module depends on the following other modules:
This module sanitizes and escapes sortkeys so that they can be used inside the data-sort-value attribute of HTML tags in combination with table sorting. Use it when you cannot be certain that the provided sortkey input is a correct sortkey.
localgetArgs=require('Module:Arguments').getArgslocalp={}functionp._encode(sortkey)-- Protect against sortkey nesting.-- Example: {{sort|{{dts|2013|07|07}}|{{dts|1990|12|01}}}}ifstring.find(sortkey,"sortkey")orstring.find(sortkey,"data-sort-value")thenreturn"";endreturnmw.text.encode(sortkey)endfunctionp.encode(frame)localargs=getArgs(frame);returnp._encode(args[1]or"")endlocalfunctionvalid_number(num)-- Return true if num is a valid number.-- In Scribunto (different from some standard Lua), when expressed as a string,-- overflow or other problems are indicated with text like "inf" or "nan"-- which are regarded as invalid here (each contains "n").iftype(num)=='number'andtostring(num):find('n',1,true)==nilthenreturntrueendendfunctionp._sortKeyForNumber(value)localsortkeyifnotvalid_number(value)thenifvalue<0thensortkey='1000000000000000000'elsesortkey='9000000000000000000'endelseifvalue==0thensortkey='5000000000000000000'elselocalmag=math.floor(math.log10(math.abs(value))+1e-14)localprefixifvalue>0thenprefix=7000+magelseprefix=2999-magvalue=value+10^(mag+1)endsortkey=string.format('%d',prefix)..string.format('%015.0f',math.floor(value*10^(math.min(28,14-mag))))endreturnsortkey;endfunctionp.sortKeyForNumber(frame)localargs=getArgs(frame)returnp._sortKeyForNumber(args[1]or"")endreturnp