Module:Citation/CS1: Difference between revisions

1,001 bytes removed ,  11 years ago
merge from sandbox. Removes unused functions (moved to Module:Citation) and updates page handling
m>Dragons flight
(remove Module:Wikitext requirement no longer used here, and remove parts of createTag no longer needed)
m>Dragons flight
(merge from sandbox. Removes unused functions (moved to Module:Citation) and updates page handling)
Line 20: Line 20:
             ['&'] = '&',     
             ['&'] = '&',     
             ["'"] = ''',     
             ["'"] = ''',     
             ['['] = '[',
             ['['] = '[',  
             [']'] = ']',
             [']'] = ']',
             ['{'] = '{',
             ['{'] = '{',
Line 140: Line 140:


function hyphentodash( str )
function hyphentodash( str )
    if str == nil then
        return nil;
    end   
     return str:gsub( '-', '–' );
     return str:gsub( '-', '–' );
end
end
Line 302: Line 305:
end
end


function refid(args)
    local p = args.p or ""
    local pp = args.pp or ""
    local loc = args.loc or ""
    return anchorid(args) .. p .. pp .. loc   
end
function name(args)
    local P1 = args[1] or ""
    if ( args[5] ~= nil) then
        return P1 .. " et al."
    else
        local P2 = args[2] or ""
        local P3 = args[3] or ""
        local P4 = args[4] or ""
        if ( args[4] ~= nil ) then
            P4 = " " .. P4
            P3 = ", & " .. P3
            P2 = ", " .. P2
        elseif ( args[3] ~= nil ) then
            P3 = " " .. P3
            P2 = " & " .. P2
        elseif ( args[2] ~= nil ) then
            P2 = " " .. P2           
        end
        return P1 .. P2 .. P3 .. P4
    end
end
function crossref(frame, args)
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local LB = config.BracketLeft or ""
    local RB = config.BracketRight or ""
    local anchor = args.ref or args.Ref or anchorid(args)
    local text = name(args)
    local loc = args.loc
    local page
    local pages = args.pp or args.pages
    if pages == nil or pages == '' then
        page = args.p or args.page;
    end
    if nil == loc then loc = "" else loc = " " .. loc end
    if ( page ~= nil ) then
        local pagesep = config.PageSep or ", p. "
        loc = loc .. pagesep .. page
    end
    if ( pages ~= nil ) then
        local pagessep = config.PagesSep or ", pp. "
        loc = loc .. pagessep .. pages
    end       
    local pagename = args.pagename or ""
    local ps = args.Postscript or ""
    return LB .. "[[" .. pagename .. "#" .. anchor .. "|" .. text .. "]]" .. loc .. RB .. ps
end
   
function extractauthors(args)
function extractauthors(args)
     local authors = {};
     local authors = {};
Line 477: Line 425:
     local Issue = args.issue or args.number
     local Issue = args.issue or args.number
     local Position = nil
     local Position = nil
     local Page
     local Page = args.p or args.page
     local Pages = args.pages
     local Pages = hyphentodash( args.pp or args.pages )
     if Pages == nil or Pages == '' then
    local At = args.at
        Page = args.page  -- allows Pages to override Page
    local page_error = false;
    else
   
         Pages = hyphentodash( Pages );
     if Page ~= nil and Page ~= '' then
     end
        if (Pages ~= nil and Pages ~= '') or (At ~= nil and At ~= '') then
 
            Pages = nil;
            At = nil;
            page_error = true;
         end
    elseif Pages ~= nil and Pages ~= '' then
        if At ~= nil and At ~= '' then
            At = nil;
            page_error = true;
        end
     end            
   
     local PP = args.pp
     local PP = args.pp
    local At = args.at
     local Edition = args.edition
     local Edition = args.edition
     local PublicationPlace = args["publication-place"] or args.publicationplace or args.place or args.location
     local PublicationPlace = args["publication-place"] or args.publicationplace or args.place or args.location
Line 792: Line 749:
     if ( nil == Page or "" == Page ) then  
     if ( nil == Page or "" == Page ) then  
         Page = ""  
         Page = ""  
    elseif ( Periodical ~= nil and Periodical ~= "" and
        if ( nil == Pages or "" == Pages) then
            config.CitationClass ~= "encyclopaedia" and
            Pages = ""
            config.CitationClass ~= "web" and
        elseif ( Periodical ~= nil and Periodical ~= "" and
            config.CitationClass ~= "book" and
                config.CitationClass ~= "encyclopaedia" and
            config.CitationClass ~= "news") then
                config.CitationClass ~= "web" and
         Page = ": " .. Page
                config.CitationClass ~= "book" and
                config.CitationClass ~= "news") then
            Pages = ": " .. Pages
         else
            if ( tonumber(Pages) ~= nil ) then
              Pages = sepc .." " .. PPrefix .. Pages
            else Pages = sepc .." " .. PPPrefix .. Pages
            end
        end
     else
     else
         Page = sepc .." " .. PPrefix .. Page
         Pages = ""
    end
        if ( Periodical ~= nil and Periodical ~= "" and
    if ( nil == Pages or "" == Pages) then
        Pages = ""
    elseif ( Periodical ~= nil and Periodical ~= "" and
             config.CitationClass ~= "encyclopaedia" and
             config.CitationClass ~= "encyclopaedia" and
             config.CitationClass ~= "web" and
             config.CitationClass ~= "web" and
             config.CitationClass ~= "book" and
             config.CitationClass ~= "book" and
             config.CitationClass ~= "news") then
             config.CitationClass ~= "news") then
        Pages = ": " .. Pages
            Page = ": " .. Page
    else
        else
        if ( tonumber(Pages) ~= nil ) then
            Page = sepc .." " .. PPrefix .. Page
          Pages = sepc .." " .. PPrefix .. Pages
        else Pages = sepc .." " .. PPPrefix .. Pages
         end
         end
     end
     end
Line 1,008: Line 968:
     local text
     local text
     local pgtext = Page .. Pages .. At
     local pgtext = Page .. Pages .. At
    if page_error then
        pgtext = pgtext .. '[[Category:References with multiple page specifications]]<!-- Bad page specification here -->';
    end
   
     if ( "" ~= Authors ) then
     if ( "" ~= Authors ) then
         if (Coauthors ~= "")  
         if (Coauthors ~= "")  
Line 1,224: Line 1,188:
--14Mar2013 Fixed double-dot before "p." or "pp." page number.
--14Mar2013 Fixed double-dot before "p." or "pp." page number.
--14Mar2013 Fixed config.CitationClass "book" to use p./pp. page.
--14Mar2013 Fixed config.CitationClass "book" to use p./pp. page.
--18Mar2013 Fixed "page=" to override "pages=" as in markup-based cites.
--
--
--End
--End
Anonymous user