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 06:21, 21 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*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 j
    
    local result = '';
    local item;
    for j = 1,3 do
        item = math.random( 2000000 );
        result = result .. item .. ':'
        local tt = mw.title.new( item );
        if tt ~= nil then            
        --    local content = tt:getContent();
        --    result = result .. string.len( content ) .. ' ';
        --[[
            local template;
            local i = 1;
            for template in string.gmatch( content, '%b{}' ) do
                local mode, param;
                mode, param = string.match( template, '{{%s*cite ' .. typ .. '%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*' .. typ .. '%s*|([^}]*)}}' );
                if mode ~= nil then
                    result = result .. '\n{{cite compare|mode=' .. mode .. " | " .. param .. "}}\n";
                    i = i + 1;
                end        
            end ]]
        end        
    end

    return result;
end


return c;