Module:Citation/CS1: Difference between revisions

2,195 bytes added ,  11 years ago
sync to sandbox, changes in support of additional modes and minro bug fixes
m>Dragons flight
(sync to sandbox, fixes a problem that can cause a script error in rare circumstances)
m>Dragons flight
(sync to sandbox, changes in support of additional modes and minro bug fixes)
Line 6: Line 6:


-- Include translation message hooks, ID and error handling configuration settings.
-- Include translation message hooks, ID and error handling configuration settings.
-- Note that require has tested to be significantly faster than loadData for this
local cfg = mw.loadData( 'Module:Citation/CS1/Configuration' );
-- usage.  This might be a side effect of the unnecessary cloning described
-- in bugzilla 47300.
local cfg = require( 'Module:Citation/CS1/Configuration' );


-- Contains a list of all recognized parameters
-- Contains a list of all recognized parameters
Line 48: Line 45:


-- Wraps a string using a message_list configuration taking one argument
-- Wraps a string using a message_list configuration taking one argument
function wrap( key, str )
function wrap( key, str, lower )
     if not is_set( str ) then
     if not is_set( str ) then
         return "";
         return "";
Line 54: Line 51:
         str = safeforitalics( str );
         str = safeforitalics( str );
     end
     end
     return substitute( cfg.messages[key], {str} );
     if lower == true then
        return substitute( cfg.messages[key]:lower(), {str} );
    else
        return substitute( cfg.messages[key], {str} );
    end       
end
end


Line 79: Line 80:
             local args, list, v = args, cfg.aliases[k];
             local args, list, v = args, cfg.aliases[k];
              
              
             if list == nil then
             if type( list ) == 'table' then
                error( cfg.messages['unknown_argument_map'] );
            elseif type( list ) == 'string' then
                v, origin[k] = args[list], list;
            else
                 v, origin[k] = selectone( args, list, 'redundant_parameters' );
                 v, origin[k] = selectone( args, list, 'redundant_parameters' );
                 if origin[k] == nil then
                 if origin[k] == nil then
                     origin[k] = '';   --Empty string, not nil;
                     origin[k] = ''; -- Empty string, not nil
                 end
                 end
            elseif list ~= nil then
                v, origin[k] = args[list], list;
            else
                -- maybe let through instead of raising an error?
                -- v, origin[k] = args[k], k;
                error( cfg.messages['unknown_argument_map'] );
             end
             end
              
              
            -- Empty strings, not nil;
             if v == nil then
             if v == nil then
                 v = cfg.defaults[k] or "";
                 v = cfg.defaults[k] or '';
                 origin[k] = '';  --Empty string, not nil;
                 origin[k] = '';
             end
             end
              
              
Line 872: Line 876:
     local no_tracking_cats = A['NoTracking'];
     local no_tracking_cats = A['NoTracking'];


    local use_lowercase = ( sepc ~= '.' );
     local this_page = mw.title.getCurrentTitle();  --Also used for COinS
     local this_page = mw.title.getCurrentTitle();  --Also used for COinS
      
      
Line 1,002: Line 1,007:
         Authors = listpeople(control, a)  
         Authors = listpeople(control, a)  
     end
     end
   
 
     local EditorCount
     local EditorCount
     if not is_set(Editors) then
     if not is_set(Editors) then
Line 1,025: Line 1,030:
     else
     else
         EditorCount = 1;
         EditorCount = 1;
    end
    local Cartography = "";
    local Scale = "";
    if config.CitationClass == "map" then
        if not is_set( Authors ) and is_set( PublisherName ) then
            Authors = PublisherName;
            PublisherName = "";
        end
        Cartography = A['Cartography'];
        if is_set( Cartography ) then
            Cartography = sepc .. " " .. wrap( 'cartography', Cartography, use_lowercase );
        end       
        Scale = A['Scale'];
        if is_set( Scale ) then
            Scale = sepc .. " " .. Scale;
        end       
     end
     end
      
      
Line 1,149: Line 1,171:
         Title = wrap( 'quoted-title', Title );
         Title = wrap( 'quoted-title', Title );
         TransTitle = wrap( 'trans-quoted-title', TransTitle );
         TransTitle = wrap( 'trans-quoted-title', TransTitle );
     elseif inArray(config.CitationClass, {"web","news","pressrelease"}) and
     elseif inArray(config.CitationClass, {"web","news","pressrelease","conference"}) and
             not is_set(Chapter) then
             not is_set(Chapter) then
         Title = wrap( 'quoted-title', Title );
         Title = wrap( 'quoted-title', Title );
Line 1,180: Line 1,202:
      
      
     if is_set(Place) then
     if is_set(Place) then
         if sepc == '.' then
         Place = " " .. wrap( 'written', Place, use_lowercase ) .. sepc .. " ";
            Place = " " .. wrap( 'written', Place ) .. sepc .. " ";
        else
            Place = " " .. substitute( cfg.messages['written']:lower(), {Place} ) .. sepc .. " ";
        end
     end
     end
      
      
Line 1,191: Line 1,209:
             Conference = externallink( ConferenceURL, Conference );
             Conference = externallink( ConferenceURL, Conference );
         end
         end
         Conference = " " .. Conference
         Conference = sepc .. " " .. Conference
     elseif is_set(ConferenceURL) then
     elseif is_set(ConferenceURL) then
         Conference = " " .. externallink( ConferenceURL, nil, ConferenceURLorigin );
         Conference = sepc .. " " .. externallink( ConferenceURL, nil, ConferenceURLorigin );
     end
     end
      
      
Line 1,239: Line 1,257:
      
      
     At = is_set(At) and (sepc .. " " .. At) or "";
     At = is_set(At) and (sepc .. " " .. At) or "";
    Position = is_set(Position) and (sepc .. " " .. Position) or "";
    if config.CitationClass == 'map' then
        local Section = A['Section'];
        local Inset = A['Inset'];
        if first_set( Pages, Page, At ) ~= nil or sepc ~= '.' then
            if is_set( Section ) then
                Section = ", " .. wrap( 'section', Section, true );
            end
            if is_set( Inset ) then
                Inset = ", " .. wrap( 'inset', Inset, true );
            end
        else
            if is_set( Section ) then
                Section = sepc .. " " .. wrap( 'section', Section, use_lowercase );
                if is_set( Inset ) then
                    Inset = ", " .. wrap( 'inset', Inset, true );
                end
            elseif is_set( Inset ) then
                Inset = sepc .. " " .. wrap( 'inset', Inset, use_lowercase );
            end           
        end           
        At = At .. Section .. Inset;       
    end   
   
     Others = is_set(Others) and (sepc .. " " .. Others) or "";
     Others = is_set(Others) and (sepc .. " " .. Others) or "";
     TitleType = is_set(TitleType) and (" (" .. TitleType .. ")") or "";
     TitleType = is_set(TitleType) and (" (" .. TitleType .. ")") or "";
Line 1,257: Line 1,299:
      
      
     ------------------------------------ totally unrelated data
     ------------------------------------ totally unrelated data
     if is_set(Via) then Via = " " .. wrap( 'via', Via ); end
    -- Mimic {{subscription required}} template;
     if is_set(Via) then
        Via = " " .. wrap( 'via', Via );
        SubscriptionRequired = sepc .. " " .. cfg.messages['subscription']; --citation always requires subscription if 'via' parameter is used
    elseif is_set(SubscriptionRequired) then
        SubscriptionRequired = sepc .. " " .. cfg.messages['subscription_no_via']; --here when 'via' parameter not used but 'subscription' is
    end
 
     if is_set(AccessDate) then
     if is_set(AccessDate) then
         local retrv_text = " " .. cfg.messages['retrieved']
         local retrv_text = " " .. cfg.messages['retrieved']
Line 1,263: Line 1,312:
         AccessDate = '<span class="reference-accessdate">' .. sepc
         AccessDate = '<span class="reference-accessdate">' .. sepc
             .. substitute( retrv_text, {AccessDate} ) .. '</span>'
             .. substitute( retrv_text, {AccessDate} ) .. '</span>'
    end
   
    if is_set(SubscriptionRequired) then
        SubscriptionRequired = sepc .. " " .. cfg.messages['subscription'];
     end
     end
      
      
Line 1,395: Line 1,440:
     if inArray(config.CitationClass, {"journal","citation"}) and is_set(Periodical) then
     if inArray(config.CitationClass, {"journal","citation"}) and is_set(Periodical) then
         if is_set(Others) then Others = Others .. sepc .. " " end
         if is_set(Others) then Others = Others .. sepc .. " " end
         tcommon = safejoin( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Series,  
         tcommon = safejoin( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Scale, Series,  
             Language, Edition, Publisher, Agency, Volume, Issue, Position}, sepc );
             Language, Cartography, Edition, Publisher, Agency, Volume, Issue}, sepc );
     else  
     else  
         tcommon = safejoin( {Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language,  
         tcommon = safejoin( {Title, TitleNote, Conference, Periodical, Format, TitleType, Scale, Series, Language,  
             Volume, Issue, Others, Edition, Publisher, Agency, Position}, sepc );
             Volume, Issue, Others, Cartography, Edition, Publisher, Agency}, sepc );
     end
     end
      
      
Line 1,410: Line 1,455:
     local idcommon = safejoin( { ID_list, URL, Archived, AccessDate, Via, SubscriptionRequired, Lay, Quote }, sepc );
     local idcommon = safejoin( { ID_list, URL, Archived, AccessDate, Via, SubscriptionRequired, Lay, Quote }, sepc );
     local text;
     local text;
     local pgtext = Page .. Pages .. At;
     local pgtext = Position .. Page .. Pages .. At;
      
      
     if is_set(Authors) then
     if is_set(Authors) then
Line 1,424: Line 1,469:
         end
         end
         if is_set(Editors) then
         if is_set(Editors) then
             local in_text = " " .. cfg.messages['in'] .. " "
             local in_text = " ";
            local post_text = "";
            if is_set(Chapter) then
                in_text = in_text .. cfg.messages['in'] .. " "
            else
                if EditorCount <= 1 then
                    post_text = ", " .. cfg.messages['editor'];
                else
                    post_text = ", " .. cfg.messages['editors'];
                end
            end
             if (sepc ~= '.') then in_text = in_text:lower() end
             if (sepc ~= '.') then in_text = in_text:lower() end
            Editors = in_text .. Editors .. post_text;
             if (string.sub(Editors,-1,-1) == sepc)
             if (string.sub(Editors,-1,-1) == sepc)
                 then Editors = in_text .. Editors .. " "
                 then Editors = Editors .. " "
                 else Editors = in_text .. Editors .. sepc .. " "
                 else Editors = Editors .. sepc .. " "
             end
             end
         end
         end
Line 1,494: Line 1,550:
         if ( "harv" == Ref ) then
         if ( "harv" == Ref ) then
             local names = {} --table of last names & year
             local names = {} --table of last names & year
             if is_set(Authors) then
             if #a > 0 then
                 for i,v in ipairs(a) do  
                 for i,v in ipairs(a) do  
                     names[i] = v.last  
                     names[i] = v.last  
                     if i == 4 then break end
                     if i == 4 then break end
                 end
                 end
             elseif is_set(Editors) then
             elseif #e > 0 then
                 for i,v in ipairs(e) do  
                 for i,v in ipairs(e) do  
                     names[i] = v.last  
                     names[i] = v.last  
Anonymous user