Modul:Citation: Redaktələr arasındakı fərq

Redaktənin izahı yoxdur
Redaktənin izahı yoxdur
 
(Eyni redaktor tərəfindən edilmiş 3 ara dəyişiklik göstərilmir)
Sətir 43: Sətir 43:
end
end


-- This returns a string with HTML character entities for wikitext markup characters.
function wikiescape(text)
    text = text:gsub( '[&\'%[%]{|}]', {   
            ['&'] = '&',   
            ["'"] = ''',   
            ['['] = '[',   
            [']'] = ']',
            ['{'] = '{',
            ['|'] = '|',
            ['}'] = '}' } );
    return text;
end


function createTag(t, frame)
    local name = t.name or "!-- --"
    local content = t.contents or ""
    local attrs = {}
    if ( z.extensiontags[name] ) then
        -- We have to preprocess these, so that they are properly turned into so-called "strip markers" in the generated wikitext.
        if ( not frame ) then error ("Please supply an extra frame argument to the createTag() function.") end
        local params = {}
        for n,v in pairs(t.params) do
            table.insert(params, "|" .. n .. "=" .. v)
        end
        return frame:preprocess("{{#tag:" .. name .. "|" .. content .. table.concat(params) .. "}}")
    else 
        for n,v in pairs(t.params) do
            if (v) then
                table.insert(attrs, n .. "=\"" .. wikiescape(v) .. "\"")
            else
                table.insert(attrs, n)
            end
        end
        if ("" == content) then
            return "<" .. name .. " " .. table.concat(attrs, " ") .. "/>"
        else
            return "<" .. name .. " " .. table.concat(attrs, " ") .. ">" .. content .. "</" .. name .. ">"
        end
    end
end
--[[
This is a clone of mw.text.nowiki.  When the mw.text library is installed,
this can be replaced by a call to that library. ]]
function nowiki( s )
    -- string.gsub is safe here, because we're only caring about ASCII chars
    s = string.gsub( s, '["&\'<=>%[%]{|}]', {
        ['"'] = '&#34;',
        ['&'] = '&#38;',
        ["'"] = '&#39;',
        ['<'] = '&#60;',
        ['='] = '&#61;',
        ['>'] = '&#62;',
        ['['] = '&#91;',
        [']'] = '&#93;',
        ['{'] = '&#123;',
        ['|'] = '&#124;',
        ['}'] = '&#125;',
    } )
    s = string.sub( string.gsub( '\n' .. s, '\n[#*:;]', {
        ["\n#"] = "\n&#35;",
        ["\n*"] = "\n&#42;",
        ["\n:"] = "\n&#58;",
        ["\n;"] = "\n&#59;",
    } ), 2 )
    s = string.gsub( s, '://', '&#58;//' )
    s = string.gsub( s, 'ISBN ', 'ISBN&#32;' )
    s = string.gsub( s, 'RFC ', 'RFC&#32;' )
    return s
end
function externallinkid(args)
    local sep = args.separator or "&nbsp;"
    args.suffix = args.suffix or ""
    local url_string = args.id
    if args.encode == true or args.encode == nil then
        url_string = mw.uri.encode( url_string );
    end
   
    local t0 = onlyinprint(args.label .. sep .. args.id)
    local t1 = hideinprint("[[" .. args.link .. "|" .. args.label .. "]]" .. sep .. "[" .. args.prefix .. url_string .. args.suffix .. " " .. nowiki(args.id) .. "]")
   
    return t0 .. t1
end
function doi(id, inactive, nocat)
    local cat = ""
    local text;
    if ( inactive ~= nil ) then
        text = "[[Digital object identifier|doi]]:" .. id;
        cat = cat .. "[[Category:Pages with DOIs inactive since " .. selectyear(inactive) .. "]]"
        inactive = " (inactive " .. inactive .. ")"
    else
        text = externallinkid({link="Digital object identifier",label="doi",prefix="http://dx.doi.org/",id=id,separator=":"})
        inactive = ""
    end
    if ( string.sub(id,1,3) ~= "10." ) then
        cat = cat .. "[[Category:Pages with DOI errors]]" .. '<span class="error"> Bad DOI (expected "10." prefix) in code number</span>'
    end
    if ( nocat and nocat ~= "" ) then cat = "" end
    return text .. inactive .. cat   
end
function selectyear( str )
    local lang = mw.getContentLanguage();
    local good, result;
    good, result = pcall( lang.formatDate, lang, 'Y', str )
    if good then
        return result;
    else
        return '';
    end
end
function anchorid(label, args)
    local P1 = trim(args[1]) or ""
    local P2 = trim(args[2]) or ""
    local P3 = trim(args[3]) or ""
    local P4 = trim(args[4]) or ""
    local P5 = trim(args[5]) or ""
    local anchor = P1 .. P2 .. P3 .. P4 .. P5;
    if anchor ~= '' then  -- See bug description in Citation/CS1
        anchor = mw.uri.anchorEncode( anchor );
    end
   
    return label .. anchor
end


function refid(label, args)
function refid(label, args)
Sətir 205: Sətir 332:
end
end


-- This is used by templates such as {{SfnRef}} to create the (encoded) anchor name for a Harvard cross-reference hyperlink.
function z.SFNID(frame)
    local pframe = frame:getParent()
    return anchorid('FOOTNOTE', pframe.args)
end
-- This is used by templates such as {{Harvard citation}} to create the Harvard cross-reference text.
function z.Harvard(frame)
    local pframe = frame:getParent()
    return crossref(frame, pframe.args)
end
-- This is used by templates such as {{sfn}} to create the entire cross-reference.
function z.sfn(frame)
    local pframe = frame:getParent()
    pframe.args.Postscript = pframe.args.postscript or pframe.args.ps or ".";
   
    local content = crossref(frame, 'CITEREF', pframe.args)
    local args = { name = refid( 'FOOTNOTE', pframe.args) }
    return createTag({name = "ref", contents = content, params = args}, frame)
end
-- This is used by template {{r}}.
function z.r(frame)
    local pframe = frame:getParent()
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    args.page1 = args.page1 or args.page
    local text = ""
    -- This would be shorter using ipairs(), but that doesn't work on an arguments table supplied to a template.
    local index = 1
    while args[index] ~= nil do
        local arg = args[index]
        local t = r0(frame, arg, args.group, args["page" .. index])
        text = text .. t
        index = index + 1
    end
    return text
end
-- This is used by template {{ref label}}.
function z.reflabel(frame)
    local pframe = frame:getParent()
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local P1 = args[1] or ""
    local P2 = args[2] or ""
    local P3 = args[3] or ""
    local id = nil
    local contents = "[[#endnote_" .. P1 .. P3 .. "|&#91;" .. P2 .. "&#93;]]"
    local params = {}
    params.class="reference"
    if ( args.noid == nil or args.noid == "" ) then params.id = "ref_" .. P1 .. P3 end
    return createTag({name="sup",contents=contents,params=params})
end


-- This is used by template {{note label}}.
function z.notelabel(frame)
    local pframe = frame:getParent()
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local id = args[1] or ""
    local arrow = args[3] or ""
    local postscript = args[4] or ""
    local contents
    if arrow ~= "" then
        local sup_arrow = createTag({name="sup",contents=arrow,params={}})
        contents = "[[#ref_" .. id .. arrow .. "|<b>" .. sup_arrow .. "</b>]]" .. postscript
        if "none" == arrow then arrow = "^" end -- Change this AFTER using it in the ID parameter and the contents.
    else
        contents = (args[2] or "") .. postscript
    end
    local params = { class="citation wikicite" }
    if id ~= "" and ( args.noid == nil or args.noid == "" ) then
        params.id = mw.uri.anchorEncode("endnote_" .. id .. arrow)
    end
    return createTag({name="span",contents=contents,params=params})
end


-- This is used by templates {{reflist}} and {{notelist}}.
-- This is used by templates {{reflist}} and {{notelist}}.