Module:Csdcheck
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
This is the Lua module called by {{csdcheck}}. Please see the main template page for documentation.
--
-- This module checks whether any of a given set of input criteria are valid CSD criteria.
-- It is also possible to specify pre-defined or custom sets of CSD criteria to check against.
--
local p = {}
function critMatch(s,test_values) -- returns true if s matches one of the table of test_values
if type(test_values) == "table" then
for n,value in ipairs(test_values) do
if s == value then
return true
end
end
else
error("the second parameter passed to critMatch() must be a table",2)
end
end
function p.check(frame) -- the main CSD check function
-- get arguments
local args;
if frame == mw.getCurrentFrame() then
-- We're being called via #invoke. If the invoking template passed any args, use
-- them. Otherwise, use the args that were passed into the template.
args = frame:getParent().args;
for k, v in pairs(frame.args) do
args = frame.args;
break
end
else
-- We're being called from another module or from the debug console, so assume
-- the args are passed in directly.
args = frame;
end
-- define variables
local input_values = {};
local test_criteria = {};
local all_criteria = { -- all valid CSD criteria
"G1" , "G2" , "G3" , "G4" , "G5" , "G6" , "G7" , "G8" , "G9" , "G10" , "G11" , "G12" , "G13" , "G14" ,"G15",
"A1" , "A2" , "A3" , "A7" , "A9" , "A10" , "A11",
"F1" , "F2" , "F3" , "F4" , "F5" , "F6" , "F7" , "F8" , "F9" , "F11" ,
"C1" , "C2", "C4",
"T5",
"U1" , "U2" , "U6" , "U7" ,
"R2" , "R3" , "R4"
};
local tag_criteria = { -- all CSD criteria used by [[Template:Db-multiple]]
"G1" , "G2" , "G3" , "G4" , "G5" , "G6" , "G7" , "G8" , "G10" , "G11" , "G12" , "G13" , "G14" ,"G15",
"A1" , "A2" , "A3" , "A7" , "A9" , "A10" , "A11",
"F1" , "F2" , "F3" , "F7" , "F8" , "F9" ,
"C1" , "C4",
"T5",
"U1" , "U2" , "U6" , "U7" ,
"R2" , "R3" , "R4"
};
local notice_criteria = { -- all CSD criteria used by [[Template:Db-notice-multiple]]
"G1" , "G2" , "G3" , "G4" , "G10" , "G11" , "G12" , "G13" , "G14" ,"G15",
"A1" , "A2" , "A3" , "A7" , "A9" , "A10" , "A11",
"F1" , "F2" , "F3" , "F7" , "F9" ,
"C1" ,
"R2" , "R3" , "R4"
};
-- build tables of input values and test criteria
for k,v in pairs(args) do
v = mw.ustring.upper(v);
-- insert positional parameter values into input_values
if type(k) == "number" then
v = mw.ustring.gsub(v,"^%s*(.-)%s*$","%1"); -- strip whitespace from positional parameters
table.insert(input_values,v)
-- insert critn parameter values into test_criteria
elseif mw.ustring.match(k,"^crit[1-9]%d*$") then
if critMatch(v,all_criteria) then -- check to make sure the criteria are valid
table.insert(test_criteria,v)
end
end
end
-- work out which set of CSD criteria to check against
local criteria_set = {}
if next(test_criteria) then -- if any test criteria are specified, use those regardless of the "set" parameter
criteria_set = test_criteria;
elseif args["set"] == "tag" then
criteria_set = tag_criteria;
elseif args["set"] == "notice" then
criteria_set = notice_criteria;
else
criteria_set = all_criteria;
end
-- check the input values against the criteria set and output "yes" if there is a match
for i,v in ipairs(input_values) do
if critMatch(v,criteria_set) then
return "yes"
end
end
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.