Module:CiteConversionTest: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
Line 32: | Line 32: | ||
local typ = frame.args[1] or frame.args.mode; |
local typ = frame.args[1] or frame.args.mode; |
||
local start = frame.args[2] or frame.args.start; |
local start = frame.args[2] or frame.args.start; |
||
local required = frame.args[3] or frame.args.require; |
|||
local tt = mw.title.new( start ); |
local tt = mw.title.new( start ); |
||
Line 69: | Line 70: | ||
local good = false; |
local good = false; |
||
for kw in string.gmatch( param, "[%s|](%w-)%s*=" ) do |
for kw in string.gmatch( param, "[%s|](%w-)%s*=" ) do |
||
if |
if required ~= nil then |
||
if kw == required then |
|||
good = true; |
|||
end |
end |
||
else |
|||
if param_list[kw] == nil then |
|||
good = true; |
|||
param_list[kw] = true; |
|||
end |
|||
end |
|||
end |
end |
||
if good or math.random(50) == 1 then |
if good or (required==nil and math.random(50) == 1) then |
||
result = result .. frame:preprocess( '<nowiki>{{cite compare|mode=' .. typ .. " | " .. param .. "}}</nowiki>" ) .. "\n<br />"; |
result = result .. frame:preprocess( '<nowiki>{{cite compare|mode=' .. typ .. " | " .. param .. "}}</nowiki>" ) .. "\n<br />"; |
||
end |
end |
Revision as of 20:54, 21 March 2013
c = {}
function c.test( frame )
local target = frame.args[1] or frame.args.target;
local tt = mw.title.new( target );
local content = tt:getContent();
local result = '';
local template;
local i = 1;
for template in string.gmatch( content, '%b{}' ) do
local mode, param;
mode, param = string.match( template, '{{%s*cite (%w*)%s*|([^}]*)}}' );
if mode ~= nil and mode ~= 'quick' then
result = result .. '\n{{cite compare|mode=' .. mode .. " | " .. param .. "}}\n";
i = i + 1;
end
mode, param = string.match( template, '{{%s*cite quick%s*|%s*(%w*)%s*|([^}]*)}}' );
if mode ~= nil then
result = result .. '\n{{cite compare|mode=' .. mode .. " | " .. param .. "}}\n";
i = i + 1;
end
if i > 90 then break; end --prevent time outs
end
return frame:preprocess(result);
end
function c.gather( frame )
local typ = frame.args[1] or frame.args.mode;
local start = frame.args[2] or frame.args.start;
local required = frame.args[3] or frame.args.require;
local tt = mw.title.new( start );
local content = tt:getContent();
local targets = {};
for w in string.gmatch( content, '%[%[(%w-)%]%]' ) do
targets[w] = true;
end
local targets2 = {}
for k in pairs( targets ) do
tt = mw.title.new( k );
content = tt:getContent();
for w in string.gmatch( content, '%[%[(%w-)%]%]' ) do
targets2[w] = true;
end
end
targets = targets2;
local result = '';
local cnt = 0;
local param_list = {};
for k in pairs( targets ) do
local tt = mw.title.new( k );
cnt = cnt + 1;
if tt ~= nil then
local content = tt:getContent() or '';
local template;
local i = 1;
for template in string.gmatch( content, '%b{}' ) do
local param;
param = string.match( template, '{{%s*cite ' .. typ .. '%s*|([^}]*)}}' );
if param ~= nil then
local good = false;
for kw in string.gmatch( param, "[%s|](%w-)%s*=" ) do
if required ~= nil then
if kw == required then
good = true;
end
else
if param_list[kw] == nil then
good = true;
param_list[kw] = true;
end
end
end
if good or (required==nil and math.random(50) == 1) then
result = result .. frame:preprocess( '<nowiki>{{cite compare|mode=' .. typ .. " | " .. param .. "}}</nowiki>" ) .. "\n<br />";
end
end
end
end
if cnt > 150 then break; end
end
return result
end
return c;