Jump to content

Module:Citation/CS1: Difference between revisions

Subscription/Registration help; Via cat fix; identifier protocol relative urls; PMC identifier fix; iso639-1 support;
m>Gadget850
(Fix via/subscription bug)
m>Trappist the monk
(Subscription/Registration help; Via cat fix; identifier protocol relative urls; PMC identifier fix; iso639-1 support;)
Line 216: Line 216:
         label=handler.label , prefix="//www.amazon."..domain.."/dp/",id=id,
         label=handler.label , prefix="//www.amazon."..domain.."/dp/",id=id,
         encode=handler.encode, separator = handler.separator})
         encode=handler.encode, separator = handler.separator})
end
--[[
Formats a PMC and checks for embargoed articles.  The embargo parameter takes a date for a value. If the embargo date is in the futue
the PMC identifier will not be linked to the article.  If the embargo specifies a date in the past, or if it is empty or omitted, then
the PMC identifier is linked to the article through the link at cfg.id_handlers['PMC'].link.
The {{citation/core}} version of {{cite journal}} links the citation title (if url parameter is empty) when embargo date is in the past
or when embargo parameter is missing or empty. That behavior is inconsistent with the behavior of other identifiers used in CS1 and is
not supported here.
]]
function pmc(id, embargo)
local handler = cfg.id_handlers['PMC'];
   
local text;
if is_set(embargo) then
local lang = mw.getContentLanguage();
local good1, embargo_date, good2, todays_date;
good1, embargo_date = pcall( lang.formatDate, lang, 'U', embargo );
good2, todays_date = pcall( lang.formatDate, lang, 'U' );
if good1 and good2 and tonumber( embargo_date ) < tonumber( todays_date ) then --if embargo date is in the past then
text = externallinkid({link = handler.link, label = handler.label, --ok to link to article
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
else
text="[[" .. handler.link .. "|" .. handler.label .. "]]:" .. handler.separator .. id; --still embargoed so no external link
end
else
text = externallinkid({link = handler.link, label = handler.label, --no embargo date, ok to link to article
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
end
return text
end
end


Line 445: Line 478:
         local lang = mw.getContentLanguage();
         local lang = mw.getContentLanguage();
         local good, result;
         local good, result;
         good, result = pcall( lang.formatDate, lang, 'Y', str )
         good, result = pcall( lang.formatDate, lang, 'Y', str );
         if good then  
         if good then  
             return result;
             return result;
         else
         else
             -- Can't make sense of this input, return blank.
             -- extract year if the date uses seasons
             return "";
            str=string.lower (str);
         end
            local seasons={"winter", "spring", "summer", "fall", "autumn"};
     end
            local date_string_split=mw.text.split (str, "[%s%-/–]");      -- split date string into parts; white space, hyphen, forward slash, and ndash are allowed separators
end
            local has_season=false;
           
            for n,season_value in ipairs(seasons) do                -- for each season ...
                for n,split_value in ipairs(date_string_split) do  -- ... loop through date string values
                    if split_value == season_value then            -- does the split value match the season value?
                        if has_season==false then                  -- found one. if this one is the first we've found ...
                            has_season=true;                        -- ... remember that we found a season
                        end
                    elseif has_season==true then                    -- if split_value isn't a season, and we've previously found a season ...
                        num = tonumber( split_value );              -- ... convert current split value to a number if we can
                        if num ~= nil and num > 0 and num < 2100 and num == math.floor(num) then    -- if it's a suitable number
                            return tostring( num );                                                -- return it as a string
                        end -- if num
                    end -- if string.find
                end -- for split value loop
             end -- season value loop
         end -- if good
     end -- if num
end -- selectyear


-- Attempts to convert names to initials.
-- Attempts to convert names to initials.
Line 588: Line 639:
         elseif k == 'OL' then
         elseif k == 'OL' then
             table.insert( new_list, {handler.label, openlibrary( v ) } );
             table.insert( new_list, {handler.label, openlibrary( v ) } );
        elseif k == 'PMC' then
            table.insert( new_list, {handler.label, pmc( v, options.Embargo ) } );
         elseif k == 'ISBN' then
         elseif k == 'ISBN' then
             local ISBN = internallinkid( handler );
             local ISBN = internallinkid( handler );
Line 863: Line 916:
     local ASINTLD = A['ASINTLD'];
     local ASINTLD = A['ASINTLD'];
     local IgnoreISBN = A['IgnoreISBN'];
     local IgnoreISBN = A['IgnoreISBN'];
    local Embargo = A['Embargo'];


     local ID_list = extractids( args );
     local ID_list = extractids( args );
Line 878: Line 932:


     local use_lowercase = ( sepc ~= '.' );
     local use_lowercase = ( sepc ~= '.' );
     local this_page = mw.title.getCurrentTitle();  --Also used for COinS
     local this_page = mw.title.getCurrentTitle();  --Also used for COinS and for language
      
      
     if not is_set(no_tracking_cats) then
     if not is_set(no_tracking_cats) then
Line 885: Line 939:
                 no_tracking_cats = "true";
                 no_tracking_cats = "true";
                 break;
                 break;
            end
        end
    end
    if ( config.CitationClass == "journal" ) then
        if not is_set(URL) and is_set(ID_list['PMC']) then
            local Embargo = A['Embargo'];
            if is_set(Embargo) then
                local lang = mw.getContentLanguage();
                local good1, result1, good2, result2;
                good1, result1 = pcall( lang.formatDate, lang, 'U', Embargo );
                good2, result2 = pcall( lang.formatDate, lang, 'U' );
               
                if good1 and good2 and tonumber( result1 ) < tonumber( result2 ) then
                    URL = "http://www.ncbi.nlm.nih.gov/pmc/articles/PMC" .. ID_list['PMC'];
                    URLorigin = cfg.id_handlers['PMC'].parameters[1];
                end
            else
                URL = "http://www.ncbi.nlm.nih.gov/pmc/articles/PMC" .. ID_list['PMC'];
                URLorigin = cfg.id_handlers['PMC'].parameters[1];
             end
             end
         end
         end
Line 1,281: Line 1,315:
         At = At .. Section .. Inset;         
         At = At .. Section .. Inset;         
     end     
     end     
   
 
--[[Look in the list of iso639-1 language codes to see if the value provided in the language parameter matches one of them.  If a match is found,
use that value; if not, then use the value that was provided with the language parameter.
Categories are assigned in a manner similar to the {{xx icon}} templates - categorizes only mainspace citations and only when the language code is not 'en' (English).
]]
if is_set (Language) then
local name = cfg.iso639_1[Language:lower()]; -- get the language name if Language parameter has a valid iso 639-1 code
if nil == name then
Language=" " .. wrap( 'language', Language ); -- no match, use parameter's value
else
if 0 == this_page.namespace and 'en' ~= Language:lower() then --found a match; is this page main / article space and English not the language?
Language=" " .. wrap( 'language', name .. '[[Category:Articles with ' .. name .. '-language external links]]' ); -- in main space and not English: categorize
else
Language=" " .. wrap( 'language', name ); --not in mainspace or language is English so don't categorize
end
end
else
Language=""; -- language not specified so make sure this is an empty string;
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 "";
     TitleNote = is_set(TitleNote) and (sepc .. " " .. TitleNote) or "";
     TitleNote = is_set(TitleNote) and (sepc .. " " .. TitleNote) or "";
    Language = is_set(Language) and (" " .. wrap( 'language', Language )) or "";
     Edition = is_set(Edition) and (" " .. wrap( 'edition', Edition )) or "";
     Edition = is_set(Edition) and (" " .. wrap( 'edition', Edition )) or "";
     Issue = is_set(Issue) and (" (" .. Issue .. ")") or "";
     Issue = is_set(Issue) and (" (" .. Issue .. ")") or "";
Line 1,300: Line 1,353:
      
      
     ------------------------------------ totally unrelated data
     ------------------------------------ totally unrelated data
     -- Mimic {{subscription required}} template;  
     --[[ Loosely mimic {{subscription required}} template; Via parameter identifies a delivery source that is not the publisher; these sources often, but not always, exist
    behind a registration or paywall.  So here, we've chosen to decouple via from subscription (via has never been part of the registration required template).
   
    Subscription implies paywall; Registration does not.  If both are used in a citation, the subscription required link note is displayed. There are no error messages for this condition.
    ]]
     if is_set(Via) then
     if is_set(Via) then
         Via = " " .. wrap( 'via', Via );
         Via = " " .. wrap( 'via', Via );
     end
     end
--      SubscriptionRequired = sepc .. " " .. cfg.messages['subscription'];  --citation always requires subscription if 'via' parameter is used
 
                                                                              -- This line removed because of editors desire to use via for citations that do not require subscriptions
if is_set(SubscriptionRequired) then
    if is_set(SubscriptionRequired) then
         SubscriptionRequired = sepc .. " " .. cfg.messages['subscription']; --here when 'via' parameter not used but 'subscription' is
         SubscriptionRequired = sepc .. " " .. cfg.messages['subscription_no_via']; --here when 'via' parameter not used but 'subscription' is
     elseif is_set(RegistrationRequired) then
     elseif is_set(RegistrationRequired) then
         SubscriptionRequired = sepc .. " " .. cfg.messages['registration']; --here when 'via' and 'subscription' parameters not used but 'registration' is
         SubscriptionRequired = sepc .. " " .. cfg.messages['registration']; --here when 'via' and 'subscription' parameters not used but 'registration' is
Line 1,321: Line 1,377:
     if is_set(ID) then ID = sepc .." ".. ID; end
     if is_set(ID) then ID = sepc .." ".. ID; end
      
      
     ID_list = buildidlist( ID_list, {DoiBroken = DoiBroken, ASINTLD = ASINTLD, IgnoreISBN = IgnoreISBN} );
     ID_list = buildidlist( ID_list, {DoiBroken = DoiBroken, ASINTLD = ASINTLD, IgnoreISBN = IgnoreISBN, Embargo=Embargo} );


     if is_set(URL) then
     if is_set(URL) then
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.