Mô đun:Citation/CS1/Arguments
< Mô đun:Citation | CS1
Cách sử dụng
Đưa mã nguồn này vào Đặc biệt:Bung bản mẫu và chép kết quả vào Mô đun:Citation/CS1/Whitelist:
{{#gọi:Citation/CS1/Arguments|build_whitelist}}
Xem thêm
local c = {};
local v = require "Module:Quốc ngữ"
exclude = { ['#'] = true, ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true, ['5'] = true, ['k'] = true, ['v'] = true, ['list'] = true };
function c.build_whitelist( frame )
local title = mw.title.new( "Module:Citation/CS1" );
local source = title:getContent();
local result = "whitelist = {<br />\n<br />\n";
local list = {};
for w in mw.ustring.gmatch(source, "args%[(.-)%]" ) do
w = mw.ustring.gsub(w, "%s*%.%.%s*i%s*%.%.%s*", "#" );
w = mw.ustring.gsub(w, "%s*%.%.%s*i", "#" );
w = mw.ustring.gsub(w, "i%s*%.%.%s*", "#" );
w = mw.ustring.gsub(w,'"', '' );
w = mw.ustring.gsub(w,'1(%D)', '#%1');
w = mw.ustring.gsub(w,'1$', '#');
list[w] = true;
end
for w in mw.ustring.gmatch(source, "args%.([%w%d_-]*)" ) do
w = mw.ustring.gsub(w,'1(%D)', '#%1');
w = mw.ustring.gsub(w,'1$', '#');
list[w] = true;
end
for s in mw.ustring.gmatch(source, "selectone%(%s*args%s*,%s*{(.-)}" ) do
for w in mw.ustring.gmatch(s, "%s*([^,]+)%s*" ) do
w = mw.ustring.gsub(w, "%s*%.%.%s*i%s*%.%.%s*", "#" );
w = mw.ustring.gsub(w, "%s*%.%.%s*i", "#" );
w = mw.ustring.gsub(w, "i%s*%.%.%s*", "#" );
w = mw.ustring.gsub(w, '"', '' );
w = mw.ustring.gsub(w, "'", '' );
w = mw.ustring.gsub(w,'1(%D)', '#%1');
w = mw.ustring.gsub(w,'1$', '#');
w = mw.ustring.match(w, "^%s*(.-)%s*$");
list[w] = true;
end
end
title = mw.title.new( "Module:Citation/CS1/Configuration" );
source = title:getContent();
for s in mw.ustring.gmatch(source, "%sparameters%s*=%s{(.-)}" ) do
for w in mw.ustring.gmatch(s, "%s*([^,]+)%s*" ) do
w = mw.ustring.gsub(w, "%s*%.%.%s*i%s*%.%.%s*", "#" );
w = mw.ustring.gsub(w, "%s*%.%.%s*i", "#" );
w = mw.ustring.gsub(w, "i%s*%.%.%s*", "#" );
w = mw.ustring.gsub(w, '"', '' );
w = mw.ustring.gsub(w, "'", '' );
w = mw.ustring.gsub(w,'1(%D)', '#%1');
w = mw.ustring.gsub(w,'1$', '#');
w = mw.ustring.match(w, "^%s*(.-)%s*$");
list[w] = true;
end
end
cfg = require( "Module:Citation/CS1/Configuration" );
for k, v in pairs( cfg.aliases ) do
if type( v ) == 'table' then
for k2, v2 in pairs( v ) do
list[v2] = true;
list[mw.ustring.gsub(v2,"#", "")] = true;
end
else
list[v] = true;
list[mw.ustring.gsub(v,"#", "")] = true;
end
end
local list2 = {};
for k in pairs( list ) do
if exclude[k] == nil then
table.insert( list2, k );
end
end
table.sort( list2, v.comp );
result = result .. "basic_arguments = {<br />\n";
for _, k in pairs( list2 ) do
if mw.ustring.match(k, "#" ) == nil then
result = result .. " ['" .. mw.text.trim(k) .. "'] = true," .. "<br />\n";
end
end
result = result .. "},<br /> \n<br /> \n";
result = result .. "numbered_arguments = {<br />\n";
for _, k in pairs( list2 ) do
if mw.ustring.match(k, "#" ) ~= nil then
result = result .. " ['" .. mw.text.trim(k) .. "'] = true," .. "<br />\n";
end
end
result = result .. "},<br /> \n";
result = result .. "};<br />\n<br />\nreturn whitelist;"
return result;
end
return c;