Module:Sortkey: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
Module:Arguments defaults to removing blank arguments but gives an error with string.find; for example List of rampage killers (Asia) uses {{hs|}} |
||
Line 14: | Line 14: | ||
function p.encode(frame) |
function p.encode(frame) |
||
local args = getArgs(frame); |
local args = getArgs(frame); |
||
return p._encode(args[1]) |
return p._encode(args[1] or "") |
||
end |
end |
||
Revision as of 01:43, 28 June 2018
![]() | 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.
Usage
{{#invoke:Sortkey|escape|sortkey to sanitize}}
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p._encode(sortkey)
-- Protect against sortkey nesting.
-- Example: {{sort|{{dts|2013|07|07}}|{{dts|1990|12|01}}}}
if string.find(sortkey, "sortkey") or string.find(sortkey, "data-sort-value") then
return "";
end
return mw.text.encode(sortkey)
end
function p.encode(frame)
local args = getArgs(frame);
return p._encode(args[1] or "")
end
return p