Module:Citation/CS1: Difference between revisions

sync with sandbox, merge cite_web_title to bare_url, better style control on translations, category suppression by config, tweak display authors
m>Dragons flight
(sync to sandbox, mostly translation handles almost uniformity for archiveurl errors.)
m>Dragons flight
(sync with sandbox, merge cite_web_title to bare_url, better style control on translations, category suppression by config, tweak display authors)
Line 28: Line 28:
     message = message:sub(1,-2);
     message = message:sub(1,-2);
     return message;
     return message;
end
-- Wraps a string using a message_list configuration taking one argument
function wrap( message_key, str )
    if str == nil or str == "" then
        return "";
    end
    if message_key == 'italic-title' or
            message_key == 'trans-italic-title' then
        str = safeforitalics( str );
    end
    return substitute( cfg.message_list[message_key], {str} );
end
end


Line 89: Line 101:
function errorcomment( content, hidden )
function errorcomment( content, hidden )
     if hidden then  
     if hidden then  
         return substitute( cfg.message_list['hidden-error'], { content } );
         return wrap( 'hidden-error', content );
     else
     else
         return substitute( cfg.message_list['visible-error'], { content } );
         return wrap( 'visible-error', content );
     end         
     end         
end
end
Line 462: Line 474:
     local text = {}
     local text = {}
     local etal = false;
     local etal = false;
    if maximum < 1 then return "", 0; end
     for i,person in ipairs(people) do
     for i,person in ipairs(people) do
         if (person.last ~= nil or person.last ~= "") then
         if (person.last ~= nil or person.last ~= "") then
             local mask = person.mask
             local mask = person.mask
             local one
             local one
             if ( maximum ~= nil and i == maximum + 1 ) then
            local sep_one = sep;
             if ( maximum ~= nil and i > maximum ) then
                 etal = true;
                 etal = true;
                 break;
                 break;
Line 474: Line 488:
                     one = string.rep("&mdash;",n)
                     one = string.rep("&mdash;",n)
                 else
                 else
                     one = mask
                     one = mask;
                    sep_one = " ";
                 end
                 end
             else
             else
Line 485: Line 500:
                 if (person.link ~= nil and person.link ~= "") then one = "[[" .. person.link .. "|" .. one .. "]]" end
                 if (person.link ~= nil and person.link ~= "") then one = "[[" .. person.link .. "|" .. one .. "]]" end
             end
             end
             table.insert(text, one)
             table.insert( text, one )
            table.insert( text, sep_one )
        end
    end
 
    local count = #text / 2;
    if count > 0 then
        if count > 1 and lastauthoramp ~= nil and lastauthoramp ~= "" and not etal then
            text[#text-2] = " & ";
         end
         end
        text[#text] = nil;
     end
     end
     local count = #text;
      
    if count > 1 and lastauthoramp ~= nil and lastauthoramp ~= "" and not etal then
     local result = table.concat(text) -- construct list
        text[count-1] = text[count-1] .. " & " .. text[count];
        text[count] = nil;
    end   
     local result = table.concat(text, sep) -- construct list
     if etal then  
     if etal then  
         local etal_text = cfg.message_list['et al'];
         local etal_text = cfg.message_list['et al'];
Line 770: Line 790:
     local sepc = A['Separator']
     local sepc = A['Separator']
     local LastAuthorAmp = A['LastAuthorAmp']
     local LastAuthorAmp = A['LastAuthorAmp']
     local no_tracking_cats = A['NoTracking'];
     local no_tracking_cats = A['NoTracking'] or "";
 
    local this_page = mw.title.getCurrentTitle();  --Also used for COinS
    if no_tracking_cats == "" then
        for k, v in pairs( cfg.uncategorized_namespaces ) do
            if this_page.nsText == v then
                no_tracking_cats = "true";
                break;
            end
        end
    end


     if ( config.CitationClass == "journal" ) then         
     if ( config.CitationClass == "journal" ) then         
Line 908: Line 938:
     end
     end
      
      
    local this_page = mw.title.getCurrentTitle();
     OCinStitle = OCinStitle .. "&rfr_id=info:sid/" .. mw.site.server:match( "[^/]*$" ) .. ":"
     OCinStitle = OCinStitle .. "&rfr_id=info:sid/" .. mw.site.server:match( "[^/]*$" ) .. ":"
       .. this_page.prefixedText  -- end COinS data by page's non-encoded pagename
       .. this_page.prefixedText  -- end COinS data by page's non-encoded pagename
Line 1,061: Line 1,090:
     end
     end


    if ( TransTitle and "" < TransTitle ) then TransTitle = " " .. substitute( cfg.message_list['trans-title'], { TransTitle } ) else TransTitle = "" end
    if ( TransChapter and "" < TransChapter ) then TransChapter = " " .. substitute( cfg.message_list['trans-title'], { TransChapter } ) else TransChapter = "" end
       
     -- Format chapter / article title
     -- Format chapter / article title
     if ( Chapter ~= nil and Chapter ~= "" ) then
     if ( Chapter ~= nil and Chapter ~= "" ) and ( ChapterLink and "" < ChapterLink ) then  
        if ( ChapterLink and "" < ChapterLink ) then Chapter = "[[" .. ChapterLink .. "|" .. Chapter .. "]]" end
        Chapter = "[[" .. ChapterLink .. "|" .. Chapter .. "]]";
        if ( Periodical and "" < Periodical ) and (Title ~= nil and Title ~= "" )
    end
         then
    if ( Periodical and "" < Periodical ) and (Title ~= nil and Title ~= "" ) then
            Chapter = substitute( cfg.message_list['italic-title'], { (safeforitalics(Chapter)) } );
         Chapter = wrap( 'italic-title', Chapter );
         else
         TransChapter = wrap( 'trans-italic-title', TransChapter );
            Chapter = substitute( cfg.message_list['quoted-title'], { Chapter } );
        end
     else
     else
         Chapter = "";
         Chapter = wrap( 'quoted-title', Chapter );
        TransChapter = wrap( 'trans-quoted-title', TransChapter );
     end
     end
      
      
Line 1,081: Line 1,106:
         TransError = " " .. seterror( 'trans_missing_chapter' );
         TransError = " " .. seterror( 'trans_missing_chapter' );
     end
     end
   
    if TransChapter ~= "" and Chapter ~= "" then TransChapter = " " .. TransChapter; end
     Chapter = Chapter .. TransChapter
     Chapter = Chapter .. TransChapter
   
     if Chapter ~= "" then
     if Chapter ~= "" then
         if ( ChapterLink == nil ) then
         if ( ChapterLink == nil ) then
Line 1,109: Line 1,137:
      
      
     -- Format main title.
     -- Format main title.
     if ( Title and "" < Title ) then
     if ( TitleLink and "" < TitleLink ) then
         if ( TitleLink and "" < TitleLink ) then
         if ( Title and "" < Title ) then
             Title = "[[" .. TitleLink .. "|" .. Title .. "]]" end
             Title = "[[" .. TitleLink .. "|" .. Title .. "]]"  
        if ( Periodical and "" < Periodical ) then
            Title = substitute( cfg.message_list['quoted-title'], { Title } );
        elseif ( config.CitationClass == "web"
                or config.CitationClass == "news"
                or config.CitationClass == "pressrelease" ) and
                Chapter == "" then
            Title = substitute( cfg.message_list['quoted-title'], { Title } );
        else
            Title = substitute( cfg.message_list['italic-title'], { (safeforitalics(Title)) } );
         end
         end
    end
    if ( Periodical and "" < Periodical ) then
        Title = wrap( 'quoted-title', Title );
        TransTitle = wrap( 'trans-quoted-title', TransTitle );
    elseif ( config.CitationClass == "web"
            or config.CitationClass == "news"
            or config.CitationClass == "pressrelease" ) and
            Chapter == "" then
        Title = wrap( 'quoted-title', Title );
        TransTitle = wrap( 'trans-quoted-title', TransTitle );
     else
     else
         Title = "";
         Title = wrap( 'italic-title', Title );
     end  
        TransTitle = wrap( 'trans-italic-title', TransTitle );
     end
      
      
     local TransError = "";
     local TransError = "";
Line 1,130: Line 1,161:
         TransError = " " .. seterror( 'trans_missing_title' );
         TransError = " " .. seterror( 'trans_missing_title' );
     end
     end
   
    if TransTitle ~= "" and Title ~= "" then TransTitle = " " .. TransTitle; end
     Title = Title .. TransTitle
     Title = Title .. TransTitle
   
     if Title ~= "" then
     if Title ~= "" then
         if ( TitleLink == nil and URL and "" < URL ) then  
         if ( TitleLink == nil and URL and "" < URL ) then  
Line 1,143: Line 1,177:
     if ( Place ~= nil and Place ~= "" ) then
     if ( Place ~= nil and Place ~= "" ) then
         if sepc == '.' then
         if sepc == '.' then
             Place = " " .. substitute( cfg.message_list['written'], {Place} ) .. sepc .. " ";
             Place = " " .. wrap( 'written', Place ) .. sepc .. " ";
         else
         else
             Place = " " .. substitute( cfg.message_list['written']:lower(), {Place} ) .. sepc .. " ";
             Place = " " .. substitute( cfg.message_list['written']:lower(), {Place} ) .. sepc .. " ";
Line 1,222: Line 1,256:
         TitleNote = sepc .. " " .. TitleNote else TitleNote = "" end
         TitleNote = sepc .. " " .. TitleNote else TitleNote = "" end
     if ( Language ~= nil and Language ~="" ) then
     if ( Language ~= nil and Language ~="" ) then
         Language = " " .. substitute( cfg.message_list['language'] , {Language} ) else Language = "" end
         Language = " " .. wrap( 'language', Language ) else Language = "" end
     if ( Edition ~= nil and Edition ~="" ) then
     if ( Edition ~= nil and Edition ~="" ) then
         Edition = " " .. substitute( cfg.message_list['edition'] , {Edition} ) else Edition = "" end
         Edition = " " .. wrap( 'edition', Edition ) else Edition = "" end
     if ( Volume ~= nil and Volume ~="" )
     if ( Volume ~= nil and Volume ~="" )
     then
     then
Line 1,243: Line 1,277:
     if ( Date ~= nil ) then Date = Date else Date = "" end
     if ( Date ~= nil ) then Date = Date else Date = "" end
     if ( Via ~= nil and Via ~="" ) then
     if ( Via ~= nil and Via ~="" ) then
         Via = " " .. substitute( cfg.message_list['via'], {Via} ) else Via = "" end
         Via = " " .. wrap( 'via', Via ) else Via = "" end
     if ( AccessDate ~= nil and AccessDate ~="" )
     if ( AccessDate ~= nil and AccessDate ~="" )
     then local retrv_text = " " .. cfg.message_list['retrieved']
     then local retrv_text = " " .. cfg.message_list['retrieved']
Line 1,261: Line 1,295:


     if ( URL ~= nil and URL ~="") then
     if ( URL ~= nil and URL ~="") then
         URL = " " .. externallink( URL, URL );
         URL = " " .. externallink( URL );
        local error_text = seterror( 'bare_url_missing_title' );
        if config.CitationClass == "web" then
            URL = URL .. " " .. seterror( 'cite_web_title' );
        else
            URL = URL .. error_text;
        end     
     else
     else
         URL = ""
         URL = ""
Line 1,277: Line 1,305:
         end
         end
          
          
         Quote = sepc .." " .. substitute( cfg.message_list['quoted-text'], { Quote } );  
         Quote = sepc .." " .. wrap( 'quoted-text', Quote );  
         PostScript = ""
         PostScript = ""
     else  
     else  
Line 1,322: Line 1,350:
         end
         end
         if sepc == '.' then
         if sepc == '.' then
             Lay = sepc .. " [" .. LaySummary .. " " .. cfg.message_list['lay summary'] .. "]" .. LaySource .. LayDate
             Lay = sepc .. " " .. externallink( LaySummary, cfg.message_list['lay summary'] ) .. LaySource .. LayDate
         else
         else
             Lay = sepc .. " [" .. LaySummary .. " " .. cfg.message_list['lay summary']:lower() .. "]" .. LaySource .. LayDate
             Lay = sepc .. " " .. externallink( LaySummary, cfg.message_list['lay summary']:lower() ) .. LaySource .. LayDate
         end             
         end             
     else
     else
Line 1,354: Line 1,382:
         if ( PublicationDate and PublicationDate ~="" ) then
         if ( PublicationDate and PublicationDate ~="" ) then
             if Publisher ~= '' then
             if Publisher ~= '' then
                 Publisher = Publisher .. ", " .. substitute( cfg.message_list['published'], {PublicationDate} );
                 Publisher = Publisher .. ", " .. wrap( 'published', PublicationDate );
             else
             else
                 Publisher = PublicationDate;
                 Publisher = PublicationDate;
Line 1,364: Line 1,392:
     else
     else
         if ( PublicationDate and PublicationDate ~="" ) then
         if ( PublicationDate and PublicationDate ~="" ) then
             PublicationDate = " (" .. substitute( cfg.message_list['published'], {PublicationDate} ) .. ")"
             PublicationDate = " (" .. wrap( 'published', PublicationDate ) .. ")"
         else  
         else  
             PublicationDate = ""
             PublicationDate = ""
Line 1,383: Line 1,411:
     if ( Periodical ~= nil and Periodical ~="" ) then  
     if ( Periodical ~= nil and Periodical ~="" ) then  
         if ( Title and Title ~= "" ) or ( TitleNote and TitleNote ~= "" ) then  
         if ( Title and Title ~= "" ) or ( TitleNote and TitleNote ~= "" ) then  
             Periodical = sepc .. " " .. substitute( cfg.message_list['italic-title'], { (safeforitalics(Periodical)) } )  
             Periodical = sepc .. " " .. wrap( 'italic-title', Periodical )  
         else  
         else  
             Periodical = substitute( cfg.message_list['italic-title'], { (safeforitalics(Periodical)) } )  
             Periodical = wrap( 'italic-title', Periodical )
         end
         end
     else Periodical = "" end
     else Periodical = "" end
Line 1,542: Line 1,570:
     end
     end
      
      
     if no_tracking_cats == nil then
    no_tracking_cats = no_tracking_cats:lower();
     if no_tracking_cats == "" or no_tracking_cats == "no" or
            no_tracking_cats == "false" or no_tracking_cats == "n" then
         for _, v in ipairs( z.error_categories ) do
         for _, v in ipairs( z.error_categories ) do
             text = text .. '[[Category:' .. v ..']]';
             text = text .. '[[Category:' .. v ..']]';
Anonymous user