Module:Citation/CS1: Difference between revisions

sync with sandbox
m>Dragons flight
(sync to sandbox)
m>Dragons flight
(sync with sandbox)
Line 215: Line 215:
]]
]]
function selectyear( str )
function selectyear( str )
     local lang = mw.getContentLanguage();
    -- Is the input a simple number?
     local good, result;
     local num = tonumber( str );  
    good, result = pcall( lang.formatDate, lang, 'Y', str )
     if num ~= nil and num > 0 and num < 2100 and num == math.abs(num) then
    if good then  
         return str;
         return result;
     else
     else
         --[[
         -- Use formatDate to interpret more complicated formats
         FormatDate fails on years that are less than 4 digits. If the input
         local lang = mw.getContentLanguage();
         is a positive integer, assume it is a valid year even if it has less
         local good, result;
         than four digits. 
         good, result = pcall( lang.formatDate, lang, 'Y', str )
        ]]
         if good then  
        local num = tonumber( str );
             return result;
         if num ~= nil and num > 0 and num < 2100 and num == math.abs(num) then
             return str;
         else
         else
             return '';
            -- Can't make sense of this input, return blank.
             return "";
         end
         end
     end
     end
Line 418: Line 416:
     local TitleType = args.type
     local TitleType = args.type
     local ArchiveURL = args["archive-url"] or args.archiveurl
     local ArchiveURL = args["archive-url"] or args.archiveurl
     local URL = args.url
     local URL = args.url or args.URL
     local ChapterURL = args["chapter-url"] or args.chapterurl
     local ChapterURL = args["chapter-url"] or args.chapterurl
     local ConferenceURL = args["conference-url"] or args.conferenceurl
     local ConferenceURL = args["conference-url"] or args.conferenceurl
Line 623: Line 621:
     OCinStitle = OCinStitle .. "&rfr_id=info:sid/en.wikipedia.org:"
     OCinStitle = OCinStitle .. "&rfr_id=info:sid/en.wikipedia.org:"
       .. this_page.prefixedText  -- end COinS data by page's non-encoded pagename
       .. this_page.prefixedText  -- end COinS data by page's non-encoded pagename
    if (Periodical ~= nil and Periodical ~= "") and
        (Chapter == nil or Chapter == '') and
        (Title ~= nil and Title ~= "") then
            Chapter = Title
            ChapterLink = TitleLink
            TransChapter = TransTitle
            Title = nil
            TitleLink = nil
            TransTitle = nil           
    end


     -- Now perform various field substitutions.
     -- Now perform various field substitutions.
Line 714: Line 723:
     if ( Format ~= nil and Format ~="" ) then
     if ( Format ~= nil and Format ~="" ) then
         Format = " (" .. Format .. ")" else Format = "" end
         Format = " (" .. Format .. ")" else Format = "" end
   
    local OriginalURL = URL
     if ( ArchiveURL and "" < ArchiveURL ) then
     if ( ArchiveURL and "" < ArchiveURL ) then
         if ( DeadURL ~= "no" ) then
         if ( DeadURL ~= "no" ) then
          local temp = URL
            URL = ArchiveURL
          URL = ArchiveURL
         end
         end
     end
     end
Line 724: Line 734:
     if ( Chapter and "" < Chapter ) then
     if ( Chapter and "" < Chapter ) then
         if ( ChapterLink and "" < ChapterLink ) then Chapter = "[[" .. ChapterLink .. "|" .. Chapter .. "]]" end
         if ( ChapterLink and "" < ChapterLink ) then Chapter = "[[" .. ChapterLink .. "|" .. Chapter .. "]]" end
         if ( Periodical and "" < Periodical
         if ( Periodical and "" < Periodical ) and (Title ~= nil and Title ~= "" )
            and config.CitationClass ~= "encyclopaedia"
         then
         ) then
             Chapter = "''" .. safeforitalics(Chapter) .. "''"
             Chapter = "''" .. safeforitalics(Chapter) .. "''"
         else
         else
Line 937: Line 946:
             Archived = sepc .. " [" .. ArchiveURL .. arch_text .. "] from the original on" .. ArchiveDate
             Archived = sepc .. " [" .. ArchiveURL .. arch_text .. "] from the original on" .. ArchiveDate
         else
         else
             if args.url ~= nil and args.url ~= '' then
             if OriginalURL ~= nil and OriginalURL ~= '' then
                 Archived = sepc .. arch_text .. " from [" .. args.url .. " the original] on" .. ArchiveDate
                 Archived = sepc .. arch_text .. " from [" .. OriginalURL .. " the original] on" .. ArchiveDate
             else
             else
                 Archived = sepc .. arch_text .. " from <span class='error'>If you specify <code>archiveurl=</code>" ..
                 Archived = sepc .. arch_text .. " from <span class='error'>If you specify <code>archiveurl=</code>" ..
Line 1,006: Line 1,015:
         Periodical ~= "" ) then
         Periodical ~= "" ) then
         if (Others ~= "") then Others = Others .. sepc .. " " end
         if (Others ~= "") then Others = Others .. sepc .. " " end
         tcommon = safejoin( {Others, Title, TitleNote, Format, TitleType, Conference, Periodical, Series, Language, Edition, Publisher, Agency, Volume, Issue, Position}, sepc );
         tcommon = safejoin( {Others, Title, TitleNote, Format, Conference, Periodical, TitleType, Series, Language, Edition, Publisher, Agency, Volume, Issue, Position}, sepc );
     elseif ( config.CitationClass == "citation" ) or (config.CitationClass == "encyclopaedia" ) then
     elseif ( config.CitationClass == "citation" ) or (config.CitationClass == "encyclopaedia" ) then
         tcommon = safejoin( {Title, TitleNote, Format, TitleType, Conference, Periodical, Series, Language, Volume, Issue, Edition, Publisher, Agency, Others, Position}, sepc );
         tcommon = safejoin( {Title, TitleNote, Format, Conference, Periodical, TitleType, Series, Language, Volume, Issue, Edition, Publisher, Agency, Others, Position}, sepc );
     else  
     else  
         tcommon = safejoin( {Title, TitleNote, Series, Format, TitleType, Conference, Periodical, Language, Volume, Issue, Others, Edition, Publisher, Agency, Position}, sepc );
         tcommon = safejoin( {Title, TitleNote, Series, Format, TitleType, Conference, Periodical, Language, Volume, Issue, Others, Edition, Publisher, Agency, Position}, sepc );
Line 1,153: Line 1,162:
     local args = {};
     local args = {};
     for k, v in pairs( pframe.args ) do
     for k, v in pairs( pframe.args ) do
         args[k] = v;
         if v ~= '' then
            args[k] = v;
        elseif k == 'postscript' then
            args[k] = v;
        end       
     end     
     end     


Anonymous user