FANDOM


 
--Module: Multiquote
 
local p={};
 
--expands source string into final string by replacing slashes with line breaks and 
--double slashes with a single slash
function p.expandQuote(source,trim)
    if source==nil then
        return "Error: Missing quotation text.<br> Please make sure the quotation text is the first parameter of the template.";
    end
 
    local strings={};
    strings[0]="";
    local index=0;
    local slash=false;
 
    --Create string table 
    for i=1, mw.ustring.len(source), 1 do
        --codepoint 47 == '/'
        if mw.ustring.codepoint(source,i)==47 then
            if not slash then
                --check next character to find out what to do with the slash
                slash=true;
            else
                --double slash, add to string
                strings[index]=strings[index] .. '/';
                slash=false;
            end
        else
            if slash then
                --single slash, create line break
                index=index+1;
                strings[index]="";
                slash=false;
            end
            strings[index]=strings[index] .. mw.ustring.char(mw.ustring.codepoint(source,i));
        end
    end
    --ignore slash at the end
 
    --create expanded string
    expanded="";
    for i=0, index, 1 do
        if trim then
            strings[i]=mw.text.trim(strings[i]);
        end
        --sorround with quotations
        expanded=expanded .. "\"\'\'" .. strings[i] .. "\'\'\"";
        if i~=index then
            expanded=expanded .. '<br>';
        end
    end
    return expanded;
end
 
--creates HTML representation of the multiquote
function p.createMultiquote(frame)
    --get parameters
    --required parameters:
    local quote=frame.args[1] or frame.args["quote"] or 
            frame:getParent().args[1] or frame:getParent().args["quote"];
    local author=frame.args[2] or frame.args["author"] or 
            frame:getParent().args[2] or frame:getParent().args["author"];
 
    --optional paramenters:
    local trim=frame.args["trim"] or frame:getParent().args["trim"];
    local img=frame.args["image"] or frame:getParent().args["image"];
 
    if author==nil then
        author="Error: no author given";
    end
 
    --check wether to trim spaces
    if trim=="yes" or trim==nil then
        trim=true;
    else
        trim=false;
    end
 
    --create root element
    local root=mw.html.create("div");
    root:css("display","block");
    root:css("width","85%");
    root:css("margin","20px");
 
    --create image element if an image was supplied
    if img~=nil then
        root
            :tag("div")
                :css("float","right")
                :css("padding-left","30px")
                :wikitext("[[FILE:" .. img .. "|80px]]")
                :done();
    end
 
    root
        :tag("div") --create quote block
            :css("text-align","center")
            :css("font-size","120%")
            :wikitext(p.expandQuote(quote,trim))
            :done()
        :tag("div") --create author block
            :css("clear","right")
            :css("text-align","right")
            :wikitext("&mdash; " .. author)
            :done();
 
    return tostring(root);
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.