יחידה:Citation/CS1: הבדלים בין גרסאות בדף
אין תקציר עריכה |
מ 111 גרסאות של הדף wikipedia:he:יחידה:Citation/CS1 יובאו |
||
| (39 גרסאות ביניים של 6 משתמשים אינן מוצגות) | |||
| שורה 8: | שורה 8: | ||
properties_cats = {}; -- for categorizing citations based on certain properties, language of source for instance | properties_cats = {}; -- for categorizing citations based on certain properties, language of source for instance | ||
} | } | ||
function local_date( date_string, format ) | |||
if format==nil then | |||
if date_string:match("^%d%d%d%d%-%d%d%-%d%d$") then --year month day format | |||
format = 'j xg Y' | |||
elseif date_string:match("^%a+ +[1-9]%d?, +[1-9]%d%d%d%a?$") then -- month day, year | |||
format = 'j xg Y' | |||
elseif date_string:match("^[1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day-initial: day month year | |||
format = 'j xg Y' | |||
elseif date_string:match("^%a+ +%d%d%d%d%a?$") then -- month/season year | |||
format='F Y' | |||
--list of accepted formats derived from Citation/CS1/Date validation - in case we may want to localize them later | |||
--elseif date_string:match("^%a+ +[1-9]%d?–[1-9]%d?, +[1-9]%d%d%d%a?$") then -- month-initial day range: month day–day, year; days are separated by endash | |||
--elseif date_string:match("^[1-9]%d?–[1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day-range-initial: day–day month year; days are separated by endash | |||
--elseif date_string:match("^[1-9]%d? +%a+ – [1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day initial month-day-range: day month - day month year; uses spaced endash | |||
--elseif date_string:match("^%a+ +[1-9]%d? – %a+ +[1-9]%d?, +[1-9]%d%d%d?%a?$") then -- month initial month-day-range: month day – month day, year; uses spaced endash | |||
--elseif date_string:match("^[1-9]%d? +%a+ +[1-9]%d%d%d – [1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day initial month-day-year-range: day month year - day month year; uses spaced endash | |||
--elseif date_string:match("^%a+ +[1-9]%d?, +[1-9]%d%d%d – %a+ +[1-9]%d?, +[1-9]%d%d%d%a?$") then -- month initial month-day-year-range: month day, year – month day, year; uses spaced endash | |||
--elseif date_string:match("^%a+ +[1-9]%d%d%d–%d%d%a?$") then -- special case Winter/Summer year-year (YYYY-YY); year separated with unspaced endash | |||
--elseif date_string:match("^%a+ +[1-9]%d%d%d–[1-9]%d%d%d%a?$") then -- special case Winter/Summer year-year; year separated with unspaced endash | |||
--elseif date_string:match("^%a+ +[1-9]%d%d%d% – %a+ +[1-9]%d%d%d%a?$") then -- month/season year - month/season year; separated by spaced endash | |||
--elseif date_string:match ("^%a+–%a+ +[1-9]%d%d%d%a?$") then -- month/season range year; months separated by endash | |||
--elseif date_string:match("^[1-9]%d%d%d?–[1-9]%d%d%d?%a?$") then -- Year range: YYY-YYY or YYY-YYYY or YYYY–YYYY; separated by unspaced endash; 100-9999 | |||
--elseif date_string:match("^[1-9]%d%d%d–%d%d%a?$") then -- Year range: YYYY–YY; separated by unspaced endash | |||
--elseif date_string:match("^[1-9]%d%d%d?%a?$") then -- year; here accept either YYY or YYYY | |||
else | |||
--return date_string | |||
error('Unsupported format') | |||
end | |||
end | |||
return mw.getContentLanguage():formatDate(format, date_string) | |||
end | |||
-- Whether variable is set or not | -- Whether variable is set or not | ||
| שורה 160: | שורה 194: | ||
]] | ]] | ||
function wrap_style (key, str) | function wrap_style (key, str, lang) | ||
if not is_set( str ) then | if not is_set( str ) then | ||
return ""; | return ""; | ||
elseif inArray( key, { 'italic-title', 'trans-italic-title' } ) then | elseif inArray( key, { 'italic-title', 'trans-italic-title' } ) then | ||
str = safeforitalics( str ); | -- avoid italics for hebrew script | ||
local isHebrew = mw.ustring.find( str, '[א-ת]' ) | |||
if (is_set(lang) and lang == 'he') or (isHebrew~=nil) then | |||
return str | |||
else | |||
str = '<span dir="auto">'..safeforitalics( str )..'</span>'; | |||
end | |||
end | end | ||
| שורה 204: | שורה 244: | ||
-- our code | -- our code | ||
if is_set (transchapter) then | if is_set (transchapter) then | ||
transchapter = '<span class="mw-content-rtl">' .. transchapter .. "</span> | transchapter = '<span class="mw-content-rtl">' .. transchapter .. "</span>"; | ||
end | end | ||
-- our code end | -- our code end | ||
| שורה 645: | שורה 685: | ||
]] | ]] | ||
function pmc(id, embargo) | function pmc(id, embargo) | ||
local test_limit = | local test_limit = 6000000; -- update this value as PMCs approach | ||
local handler = cfg.id_handlers['PMC']; | local handler = cfg.id_handlers['PMC']; | ||
local err_cat = ''; -- presume that PMC is valid | local err_cat = ''; -- presume that PMC is valid | ||
| שורה 1,006: | שורה 1,046: | ||
return str; | return str; | ||
else | else | ||
if str:sub(1,1) == "'" then str = "<span />" .. str; end | if str:sub(1,1) == "'" then str = "<span></span>" .. str; end | ||
if str:sub(-1,-1) == "'" then str = str .. "<span />"; end | if str:sub(-1,-1) == "'" then str = str .. "<span></span>"; end | ||
-- Remove newlines as they break italics. | -- Remove newlines as they break italics. | ||
| שורה 1,037: | שורה 1,077: | ||
for _, value in ipairs( tbl ) do | for _, value in ipairs( tbl ) do | ||
if value == nil then value = ''; end | if value == nil then value = ''; end | ||
if str == '' then | if str == '' then | ||
str = value; | str = value; | ||
| שורה 1,491: | שורה 1,530: | ||
local test=''; | local test=''; | ||
-- if 0 == namespace and (('he' == lang:lower()) or ('hebrew' == lang:lower())) then | |||
-- table.insert (z.maintenance_cats, 'תבנית ציטוט עם ציון עברית בתור שפה זרה'); -- add maintenance category if |language=Hebrew or |language=he in article space | |||
-- end | |||
if 2 == lang:len() then -- ISO639-1 language code are 2 characters (fetchLanguageName also supports 3 character codes) | if 2 == lang:len() then -- ISO639-1 language code are 2 characters (fetchLanguageName also supports 3 character codes) | ||
| שורה 1,499: | שורה 1,538: | ||
end | end | ||
-- | -- our part | ||
if not is_set (name) then | if not is_set (name) then | ||
local langs = mw.language.fetchLanguageNames( "en" ) | local langs = mw.language.fetchLanguageNames( "en" ) | ||
| שורה 1,511: | שורה 1,550: | ||
end | end | ||
end | end | ||
-- | -- our part end | ||
if is_set (name) then -- if Language specified a valid ISO639-1 code | if is_set (name) then -- if Language specified a valid ISO639-1 code | ||
| שורה 1,519: | שורה 1,558: | ||
end | end | ||
-- | -- our part | ||
if name == ' | if name == 'ויאטנמית' | ||
then name = ' | then name = 'וייטנאמית' | ||
end | end | ||
-- | -- our part end | ||
if is_set (code) then | if is_set (code) then | ||
if 0 == namespace and 'he' ~= code then -- is this page main / article space and Hebrew not the language? | if 0 == namespace and 'he' ~= code then -- is this page main / article space and Hebrew not the language? | ||
| שורה 1,534: | שורה 1,573: | ||
end | end | ||
function restoreDate(inputDate) | |||
return inputDate | |||
-- Until the problem of Month-Year -> Fill Current day will be resolved | |||
-- if inputDate == "" then | |||
-- return "" | |||
-- end | |||
-- return mw.text.trim(globalframe:expandTemplate({title = "זמןמ", args = {'', inputDate, ["שגיאה"] = "ללא"}})); | |||
end | |||
function autoDir(str) | |||
if str and str ~= '' then | |||
return '<span dir="auto">' ..str .. '</span>' | |||
end | |||
return str | |||
end | |||
function translateEdition(str) | |||
if str=='1st' then | |||
return 'ראשונה' | |||
elseif str=='2nd' then | |||
return 'שנייה' | |||
end | |||
return str | |||
end | |||
--[[--------------------------< C I T A T I O N 0 >------------------------------------------------------------ | --[[--------------------------< C I T A T I O N 0 >------------------------------------------------------------ | ||
This is the main function doing the majority of the citation | This is the main function doing the majority of the citation | ||
| שורה 1,565: | שורה 1,625: | ||
local Year = A['Year']; | local Year = A['Year']; | ||
local PublicationDate = A['PublicationDate']; | local PublicationDate = restoreDate(A['PublicationDate']); | ||
local OrigYear = A['OrigYear']; | local OrigYear = A['OrigYear']; | ||
local Date = A['Date']; | local Date = restoreDate(A['Date']); | ||
local LayDate = A['LayDate']; | local LayDate = restoreDate(A['LayDate']); | ||
------------------------------------------------- Get title data | ------------------------------------------------- Get title data | ||
local Title = A['Title']; | local Title = A['Title']; | ||
| שורה 1,577: | שורה 1,637: | ||
local TitleNote = A['TitleNote']; | local TitleNote = A['TitleNote']; | ||
local TitleLink = A['TitleLink']; | local TitleLink = A['TitleLink']; | ||
local Chapter = A['Chapter']; | local Chapter = autoDir(A['Chapter']); | ||
local ChapterLink = A['ChapterLink']; -- deprecated | local ChapterLink = A['ChapterLink']; -- deprecated | ||
local TransChapter = A['TransChapter']; | local TransChapter = A['TransChapter']; | ||
| שורה 1,600: | שורה 1,660: | ||
local At = A['At']; | local At = A['At']; | ||
local Edition = A['Edition']; | local Edition = translateEdition(A['Edition']); | ||
local PublicationPlace = A['PublicationPlace'] | local PublicationPlace = autoDir(A['PublicationPlace']) | ||
local Place = A['Place']; | local Place = autoDir(A['Place']); | ||
local PublisherName = A['PublisherName']; | local PublisherName = autoDir(A['PublisherName']); | ||
local RegistrationRequired = A['RegistrationRequired']; | local RegistrationRequired = A['RegistrationRequired']; | ||
local SubscriptionRequired = A['SubscriptionRequired']; | local SubscriptionRequired = A['SubscriptionRequired']; | ||
local Via = A['Via']; | local Via = A['Via']; | ||
local AccessDate = A['AccessDate']; | local AccessDate = restoreDate(A['AccessDate']); | ||
local ArchiveDate = A['ArchiveDate']; | local ArchiveDate = restoreDate(A['ArchiveDate']); | ||
local Agency = A['Agency']; | local Agency = A['Agency']; | ||
local DeadURL = A['DeadURL'] | local DeadURL = A['DeadURL'] | ||
local Language = A['Language']; | local Language = A['Language']; | ||
local LangCode = A['Language']; | |||
local Format = A['Format']; | local Format = A['Format']; | ||
local ChapterFormat = A['ChapterFormat']; | local ChapterFormat = A['ChapterFormat']; | ||
| שורה 1,638: | שורה 1,699: | ||
-- our code start | -- our code start | ||
local Month = A['Month']; | local Month = A['Month']; | ||
LangCode = mw.ustring.gsub( Language, '-.*', '' ); | |||
Language = LangCode; | |||
-- our code end | -- our code end | ||
| שורה 1,651: | שורה 1,714: | ||
local COinS_date; -- used in the COinS metadata | local COinS_date; -- used in the COinS metadata | ||
local IsValidDate, LocalDate | |||
local DateFormat = nil | |||
-- Set postscript default. | -- Set postscript default. | ||
if not is_set (PostScript) then -- if |postscript= has not been set (Postscript is nil which is the default for {{citation}}) and | if not is_set (PostScript) then -- if |postscript= has not been set (Postscript is nil which is the default for {{citation}}) and | ||
| שורה 1,775: | שורה 1,840: | ||
if is_set(Others) then | if is_set(Others) then | ||
if is_set(TitleType) then | if is_set(TitleType) then | ||
Others = ' ' .. TitleType .. ' | Others = ' ' .. TitleType .. ' עם ' .. Others; | ||
TitleType = ''; | TitleType = ''; | ||
else | else | ||
Others = ' ' .. ' | Others = ' ' .. 'ראיון עם ' .. Others; | ||
end | end | ||
else | else | ||
Others = '( | Others = '(ראיון)'; | ||
end | end | ||
end | end | ||
| שורה 1,841: | שורה 1,906: | ||
end | end | ||
else | else | ||
DateFormat = 'Y' | |||
Date = Year; -- promote Year to Date | Date = Year; -- promote Year to Date | ||
Year = nil; -- make nil so Year as empty string isn't used for CITEREF | Year = nil; -- make nil so Year as empty string isn't used for CITEREF | ||
if is_set(Date) then | if is_set(Date) then | ||
if is_set(Month) then | if is_set(Month) then | ||
DateFormat = 'M Y' | |||
Date = Month .. " " .. Date; | Date = Month .. " " .. Date; | ||
end | end | ||
| שורה 2,090: | שורה 2,157: | ||
if is_set(TransTitle) then | if is_set(TransTitle) then | ||
if is_set(Title) then | if is_set(Title) then | ||
TransTitle = ' <span class="mw-content-rtl">' .. TransTitle .. "</span> | TransTitle = ' <span class="mw-content-rtl">' .. TransTitle .. "</span>"; | ||
else | else | ||
TransError = " " .. seterror( 'trans_missing_title' ); | TransError = " " .. seterror( 'trans_missing_title' ); | ||
| שורה 2,096: | שורה 2,163: | ||
end | end | ||
if is_set(Title) then | |||
-- bidi isolation. ideally we should use here bidi-isolate once browsers supports it properly. | |||
Title = mw.ustring.format( '<span style="unicode-bidi:embed;">%s</span>', Title) | |||
end | |||
Title = Title .. TransTitle; | Title = Title .. TransTitle; | ||
| שורה 2,135: | שורה 2,206: | ||
end | end | ||
end | end | ||
Position = " " .. TimeCaption | Position = " " .. TimeCaption .. Time; | ||
end | end | ||
end | end | ||
| שורה 2,149: | שורה 2,220: | ||
Pages = ": " .. Pages; | Pages = ": " .. Pages; | ||
elseif tonumber(Pages) ~= nil then | elseif tonumber(Pages) ~= nil then | ||
Pages = sepc .." " .. PPrefix .. Pages; | Pages = sepc ..'<span dir="rtl"> ' .. PPrefix .. Pages .. '</span>'; | ||
else | else | ||
Pages = sepc .." " .. PPPrefix .. Pages; | Pages = sepc ..' <span dir="rtl">' .. PPPrefix .. Pages .. '</span>'; | ||
end | end | ||
end | end | ||
| שורה 2,159: | שורה 2,230: | ||
Page = ": " .. Page; | Page = ": " .. Page; | ||
else | else | ||
Page = sepc .." " .. PPrefix .. Page; | Page = sepc ..' <span dir="rtl">' .. PPrefix .. Page ..'</span>'; | ||
end | end | ||
end | end | ||
| שורה 2,241: | שורה 2,312: | ||
if is_set(AccessDate) then | if is_set(AccessDate) then | ||
local retrv_text = " " .. cfg.messages['retrieved'] | local retrv_text = " " .. cfg.messages['retrieved'] | ||
is_accesssdate_ok, AccessDateParsed = pcall(local_date, AccessDate, 'j xg Y') -- local canonical format for dates | |||
if is_accesssdate_ok then | |||
AccessDate= AccessDateParsed | |||
end | |||
AccessDate = nowrap_date (AccessDate); -- wrap in nowrap span if date in appropriate format | AccessDate = nowrap_date (AccessDate); -- wrap in nowrap span if date in appropriate format | ||
if (sepc ~= ".") then retrv_text = retrv_text:lower() end -- if 'citation', lower case | if (sepc ~= ".") then retrv_text = retrv_text:lower() end -- if 'citation', lower case | ||
| שורה 2,363: | שורה 2,437: | ||
if is_set(Periodical) then | if is_set(Periodical) then | ||
if is_set(Title) or is_set(TitleNote) then | if is_set(Title) or is_set(TitleNote) then | ||
Periodical = sepc .. " " .. wrap_style ('italic-title', Periodical) | Periodical = sepc .. " " .. wrap_style ('italic-title', Periodical, LangCode) | ||
else | else | ||
Periodical = wrap_style ('italic-title', Periodical) | Periodical = wrap_style ('italic-title', Periodical, LangCode) | ||
end | end | ||
end | end | ||
| שורה 2,405: | שורה 2,479: | ||
local text; | local text; | ||
local pgtext = Position .. Page .. Pages .. At; | local pgtext = Position .. Page .. Pages .. At; | ||
-- local canonical format for dates | |||
if is_set(Date) then | |||
IsValidDate, LocalDate = pcall(local_date, Date, DateFormat) | |||
if IsValidDate then | |||
Date = mw.ustring.format( '<span style="direction:rtl;unicode-bidi:embed;">%s</span>', LocalDate) | |||
end | |||
end | |||
if is_set(Authors) then | if is_set(Authors) then | ||
if is_set(Coauthors) then | if is_set(Coauthors) then | ||
| שורה 2,564: | שורה 2,644: | ||
-- This is used by templates such as {{cite book}} to create the actual citation text. | -- This is used by templates such as {{cite book}} to create the actual citation text. | ||
function z.citation(frame) | function z.citation(frame) | ||
globalframe = frame | |||
local pframe = frame:getParent() | local pframe = frame:getParent() | ||