Jump to content

Module:CiteConversionTest

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dragons flight (talk | contribs) at 05:10, 15 March 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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*File:[^%]]*%]%]' );
        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

return c;