پودمان:Footnotes: تفاوت میان نسخهها
جز (۱ نسخه واردشده) |
imported>Alpineer جز («پودمان:Footnotes» را محافظت کرد: الگو یا پودمان حساس: در مقالههای زیادی تراگنجایش شده است. ([ویرایش=تنها مدیران] (بیپایا...) |
||
خط ۱: | خط ۱: | ||
-- | -- این پودمان بهدقت بومیسازی شدهاست. هنگام بهروزرسانی دقت کنید | ||
local getArgs = require( | local getArgs = require('Module:Arguments').getArgs | ||
f = { | f = { | ||
args_default = { | args_default = { | ||
bracket_left = | bracket_left = '', | ||
bracket_right = | bracket_right = '', | ||
bracket_year_left = | bracket_year_left = '', | ||
bracket_year_right = | bracket_year_right = '', | ||
postscript = | postscript = '', | ||
page = | page = '', | ||
pages = | pages = '', | ||
location = | location = '', | ||
page_sep = | page_sep = 'ص.', | ||
pages_sep = | pages_sep = 'صص.', | ||
ref = | ref = '', | ||
P1 = | P1 = '', | ||
P2 = | P2 = '', | ||
P3 = | P3 = '', | ||
P4 = | P4 = '', | ||
P5 = | P5 = '', | ||
andOthers = 'و دیگران', | |||
amp = 'و', | |||
comma = '،', | |||
} | } | ||
} | } | ||
function trim( str ) | function trim( str ) | ||
if str == nil then | if str == nil then | ||
return nil | return nil | ||
end | end | ||
return | return mw.ustring.match (str, '^%s*(.-)%s*$') | ||
end | end | ||
local function is_year (param) | |||
return mw.ustring.match (param, '^%d%d%d%d?%l?$') or mw.ustring.match (param,'^n%.d%.%l?$') or mw.ustring.match (param,'^nd%l?$') or mw.ustring.match (param,'^c%. %d%d%d%d?%l?$') | |||
end | |||
function core( args ) | function core( args ) | ||
local result | local result | ||
if args.P5 ~= | if args.P5 ~= '' then | ||
if is_year (args.P5) then | |||
result = table.concat({args.P1, ' ', args.andOthers, ' ', args.bracket_year_left, args.P5, args.bracket_year_right}) | |||
elseif args.P4 ~= | else | ||
result = args.P1 . | args.P5 = '' -- when P5 not a year don't include in anchor | ||
args. | result = table.concat ({args.P1, ' ', args.andOthers}) -- and don't render it | ||
end | |||
result = args.P1 .. ' | elseif args.P4 ~= '' then | ||
args. | if is_year (args.P4) then | ||
result = table.concat ({args.P1, args.comma, ' ', args.P2, ' ', args.amp, ' ', args.P3, ' ', args.bracket_year_left, args.P4, args.bracket_year_right}) -- three names and a year | |||
else | |||
result = table.concat ({args.P1, ' ', args.andOthers}) -- four names | |||
end | |||
elseif args.P3 ~= '' then | |||
if is_year (args.P3) then | |||
result = table.concat ({args.P1, ' ', args.amp, ' ', args.P2, ' ', args.bracket_year_left, args.P3, args.bracket_year_right}) -- two names and a year | |||
else | |||
result = table.concat ({args.P1, args.comma, ' ', args.P2, ' ', args.amp, ' ', args.P3}) -- three names | |||
end | |||
elseif args.P2 ~= '' then | |||
if is_year (args.P2) then | |||
result = table.concat ({args.P1, ' ', args.bracket_year_left, args.P2, args.bracket_year_right}) -- one name and year | |||
else | |||
result = table.concat ({args.P1, ' ', args.amp, ' ', args.P2}) -- two names | |||
end | |||
else | else | ||
result = | result = args.P1 -- one name | ||
end | end | ||
if ('.' == result:sub(-1)) and ('' == args.page) and ('' == args.pages) and ('' == args.location) then | |||
args.postscript = '' -- prevent double periods when date is 'n.d.' | |||
end | |||
if args.ref ~= 'none' then | if args.ref ~= 'none' then | ||
if args.ref ~= | if args.ref ~= '' then | ||
result = | result = '[[#' .. mw.uri.anchorEncode(args.ref) .. '|' .. result .. ']]' | ||
else | else | ||
result = | result = '[[#CITEREF' .. mw.uri.anchorEncode(args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5) .. '|' .. result .. ']]' | ||
end | end | ||
end | end | ||
if args.page ~= | if args.page ~= '' then | ||
result = result .. args.page_sep .. args.page | result = result .. args.comma .. ' ' .. args.page_sep .. ' ' .. args.page | ||
elseif args.pages ~= | elseif args.pages ~= '' then | ||
result = result .. args.pages_sep .. args.pages | result = result .. args.comma .. ' ' .. args.pages_sep .. ' ' .. args.pages | ||
end | end | ||
if args.location ~= | if args.location ~= '' then | ||
result = result .. | result = result .. args.comma .. ' ' .. args.location | ||
end | end | ||
result = args.bracket_left .. result .. args.bracket_right .. args.postscript | result = args.bracket_left .. result .. args.bracket_right .. args.postscript | ||
return result | return result | ||
end | end | ||
function f.harvard_core( frame ) | function f.harvard_core( frame ) | ||
local | local args = {} | ||
local | local pArgs = getArgs(frame) | ||
args.bracket_left = pArgs.BracketLeft or '' | |||
args.bracket_right = pArgs.BracketRight or '' | |||
args.bracket_year_left = pArgs.BracketYearLeft or '' | |||
args.bracket_year_right = pArgs.BracketYearRight or '' | |||
args.postscript = pArgs.Postscript or '' | |||
if 'none' == args.postscript then | |||
args.postscript = '' | |||
end | |||
args.page = pArgs.p or pArgs.Page or pArgs.page or pArgs['ص'] or '' | |||
args.pages = pArgs.pp or pArgs.Pages or pArgs.pages or pArgs['صص'] or '' | |||
args.location = pArgs.Location or pArgs.loc or pArgs['محل'] or '' | |||
args.page_sep = trim(pArgs.PageSep) or '' | |||
args.pages_sep = trim( pArgs.PagesSep) or '' | |||
args.ref = pArgs.REF or '{{{REF}}}' | |||
args.P1 = trim( pArgs.P1 ) or '' | |||
args.P2 = trim( pArgs.P2 ) or '' | |||
args.P3 = trim( pArgs.P3 ) or '' | |||
args.P4 = trim( pArgs.P4 ) or '' | |||
args.P5 = trim( pArgs.P5 ) or '' | |||
args.andOthers = trim( pArgs.AndOthers ) or 'و دیگران' | |||
args.amp = trim( pArgs.amp ) or 'و' | |||
args.comma = trim( pArgs.comma ) or '،' | |||
return core( | return core( args ) | ||
end | end | ||
function f.harvard_citation( frame ) | function f.harvard_citation( frame ) | ||
local | local args = f.args_default | ||
local | local pArgs = getArgs(frame) | ||
args.bracket_left = '(' | |||
args.bracket_right = ')' | |||
args.page = pArgs.p or pArgs.page or pArgs['ص'] or '' | |||
args.pages = pArgs.pp or pArgs.pages or pArgs['صص'] or '' | |||
args.location = pArgs.loc or pArgs['محل'] or '' | |||
args.ref = pArgs.ref or pArgs.Ref or '' | |||
args.P1 = trim( pArgs[1] ) or '' | |||
args.P2 = trim( pArgs[2] ) or '' | |||
args.P3 = trim( pArgs[3] ) or '' | |||
args.P4 = trim( pArgs[4] ) or '' | |||
args.P5 = trim( pArgs[5] ) or '' | |||
args.andOthers = trim( pArgs.AndOthers ) or args.andOthers | |||
args.amp = trim( pArgs.amp ) or args.amp | |||
args.comma = trim( pArgs.comma ) or args.comma | |||
args.page_sep = trim( pArgs.PageSep ) or args.page_sep | |||
args.pages_sep = trim( pArgs.PagesSep ) or args.pages_sep | |||
return core( | return core( args ) | ||
end | end | ||
function f.harvard_citation_no_bracket( frame ) | function f.harvard_citation_no_bracket( frame ) | ||
local | local args = f.args_default | ||
local | local pArgs = getArgs(frame) | ||
args.page = pArgs.p or pArgs.page or pArgs['ص'] or '' | |||
args.pages = pArgs.pp or pArgs.pages or pArgs['صص'] or '' | |||
args.location = pArgs.loc or pArgs['محل'] or '' | |||
args.ref = pArgs.ref or pArgs.Ref or '' | |||
args.P1 = trim( pArgs[1] ) or '' | |||
args.P2 = trim( pArgs[2] ) or '' | |||
args.P3 = trim( pArgs[3] ) or '' | |||
args.P4 = trim( pArgs[4] ) or '' | |||
args.P5 = trim( pArgs[5] ) or '' | |||
args.andOthers = trim( pArgs.AndOthers ) or args.andOthers | |||
args.amp = trim( pArgs.amp ) or args.amp | |||
args.page_sep = trim( pArgs.PageSep ) or args.page_sep | |||
args.pages_sep = trim( pArgs.PagesSep ) or args.pages_sep | |||
args.comma = trim( pArgs.comma ) or args.comma | |||
return core( | return core( args ) | ||
end | end | ||
function f.sfn( frame ) | function f.sfn( frame ) | ||
local | local args = f.args_default | ||
local | local pArgs = getArgs(frame) | ||
for k, v in pairs( frame.args ) do -- for {{sfnp}}, override default with values provided in the #invoke: | |||
args[k] = v | |||
end | |||
args.postscript = pArgs.postscript or pArgs.ps or '.' | |||
if 'none' == args.postscript then | if 'none' == args.postscript then | ||
args.postscript = '' | args.postscript = '' | ||
end | end | ||
args.page = pArgs.p or pArgs.page or pArgs['ص'] or '' | |||
args.pages = pArgs.pp or pArgs.pages or pArgs['صص'] or '' | |||
args.location = pArgs.loc or pArgs['محل'] or '' | |||
args.ref = pArgs.ref or pArgs.Ref or '' | |||
args.P1 = trim( pArgs[1] ) or '' | |||
args.P2 = trim( pArgs[2] ) or '' | |||
args.P3 = trim( pArgs[3] ) or '' | |||
args.P4 = trim( pArgs[4] ) or '' | |||
args.P5 = trim( pArgs[5] ) or '' | |||
args.andOthers = trim( pArgs.AndOthers ) or args.andOthers | |||
args.amp = trim( pArgs.amp ) or args.amp | |||
args.comma = trim( pArgs.comma ) or args.comma | |||
args.page_sep = trim( pArgs.PageSep ) or args.page_sep | |||
args.pages_sep = trim( pArgs.PagesSep ) or args.pages_sep | |||
local result = core( | local result = core( args ) | ||
local name = | local name = 'FOOTNOTE' .. args.P1 .. args.P2 .. | ||
args.P3 .. args.P4 .. args.P5 .. args.page .. args.pages .. args.location | |||
result = frame:extensionTag{ name = | result = frame:extensionTag{ name = 'ref', args = {name=name}, content=result } | ||
return result | return result | ||
end | end | ||
return f | return f |
نسخهٔ ۱۸ دسامبر ۲۰۱۷، ساعت ۱۱:۱۲
توضیحات این پودمان میتواند در پودمان:Footnotes/توضیحات قرار گیرد.
-- این پودمان بهدقت بومیسازی شدهاست. هنگام بهروزرسانی دقت کنید
local getArgs = require('Module:Arguments').getArgs
f = {
args_default = {
bracket_left = '',
bracket_right = '',
bracket_year_left = '',
bracket_year_right = '',
postscript = '',
page = '',
pages = '',
location = '',
page_sep = 'ص.',
pages_sep = 'صص.',
ref = '',
P1 = '',
P2 = '',
P3 = '',
P4 = '',
P5 = '',
andOthers = 'و دیگران',
amp = 'و',
comma = '،',
}
}
function trim( str )
if str == nil then
return nil
end
return mw.ustring.match (str, '^%s*(.-)%s*$')
end
local function is_year (param)
return mw.ustring.match (param, '^%d%d%d%d?%l?$') or mw.ustring.match (param,'^n%.d%.%l?$') or mw.ustring.match (param,'^nd%l?$') or mw.ustring.match (param,'^c%. %d%d%d%d?%l?$')
end
function core( args )
local result
if args.P5 ~= '' then
if is_year (args.P5) then
result = table.concat({args.P1, ' ', args.andOthers, ' ', args.bracket_year_left, args.P5, args.bracket_year_right})
else
args.P5 = '' -- when P5 not a year don't include in anchor
result = table.concat ({args.P1, ' ', args.andOthers}) -- and don't render it
end
elseif args.P4 ~= '' then
if is_year (args.P4) then
result = table.concat ({args.P1, args.comma, ' ', args.P2, ' ', args.amp, ' ', args.P3, ' ', args.bracket_year_left, args.P4, args.bracket_year_right}) -- three names and a year
else
result = table.concat ({args.P1, ' ', args.andOthers}) -- four names
end
elseif args.P3 ~= '' then
if is_year (args.P3) then
result = table.concat ({args.P1, ' ', args.amp, ' ', args.P2, ' ', args.bracket_year_left, args.P3, args.bracket_year_right}) -- two names and a year
else
result = table.concat ({args.P1, args.comma, ' ', args.P2, ' ', args.amp, ' ', args.P3}) -- three names
end
elseif args.P2 ~= '' then
if is_year (args.P2) then
result = table.concat ({args.P1, ' ', args.bracket_year_left, args.P2, args.bracket_year_right}) -- one name and year
else
result = table.concat ({args.P1, ' ', args.amp, ' ', args.P2}) -- two names
end
else
result = args.P1 -- one name
end
if ('.' == result:sub(-1)) and ('' == args.page) and ('' == args.pages) and ('' == args.location) then
args.postscript = '' -- prevent double periods when date is 'n.d.'
end
if args.ref ~= 'none' then
if args.ref ~= '' then
result = '[[#' .. mw.uri.anchorEncode(args.ref) .. '|' .. result .. ']]'
else
result = '[[#CITEREF' .. mw.uri.anchorEncode(args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5) .. '|' .. result .. ']]'
end
end
if args.page ~= '' then
result = result .. args.comma .. ' ' .. args.page_sep .. ' ' .. args.page
elseif args.pages ~= '' then
result = result .. args.comma .. ' ' .. args.pages_sep .. ' ' .. args.pages
end
if args.location ~= '' then
result = result .. args.comma .. ' ' .. args.location
end
result = args.bracket_left .. result .. args.bracket_right .. args.postscript
return result
end
function f.harvard_core( frame )
local args = {}
local pArgs = getArgs(frame)
args.bracket_left = pArgs.BracketLeft or ''
args.bracket_right = pArgs.BracketRight or ''
args.bracket_year_left = pArgs.BracketYearLeft or ''
args.bracket_year_right = pArgs.BracketYearRight or ''
args.postscript = pArgs.Postscript or ''
if 'none' == args.postscript then
args.postscript = ''
end
args.page = pArgs.p or pArgs.Page or pArgs.page or pArgs['ص'] or ''
args.pages = pArgs.pp or pArgs.Pages or pArgs.pages or pArgs['صص'] or ''
args.location = pArgs.Location or pArgs.loc or pArgs['محل'] or ''
args.page_sep = trim(pArgs.PageSep) or ''
args.pages_sep = trim( pArgs.PagesSep) or ''
args.ref = pArgs.REF or '{{{REF}}}'
args.P1 = trim( pArgs.P1 ) or ''
args.P2 = trim( pArgs.P2 ) or ''
args.P3 = trim( pArgs.P3 ) or ''
args.P4 = trim( pArgs.P4 ) or ''
args.P5 = trim( pArgs.P5 ) or ''
args.andOthers = trim( pArgs.AndOthers ) or 'و دیگران'
args.amp = trim( pArgs.amp ) or 'و'
args.comma = trim( pArgs.comma ) or '،'
return core( args )
end
function f.harvard_citation( frame )
local args = f.args_default
local pArgs = getArgs(frame)
args.bracket_left = '('
args.bracket_right = ')'
args.page = pArgs.p or pArgs.page or pArgs['ص'] or ''
args.pages = pArgs.pp or pArgs.pages or pArgs['صص'] or ''
args.location = pArgs.loc or pArgs['محل'] or ''
args.ref = pArgs.ref or pArgs.Ref or ''
args.P1 = trim( pArgs[1] ) or ''
args.P2 = trim( pArgs[2] ) or ''
args.P3 = trim( pArgs[3] ) or ''
args.P4 = trim( pArgs[4] ) or ''
args.P5 = trim( pArgs[5] ) or ''
args.andOthers = trim( pArgs.AndOthers ) or args.andOthers
args.amp = trim( pArgs.amp ) or args.amp
args.comma = trim( pArgs.comma ) or args.comma
args.page_sep = trim( pArgs.PageSep ) or args.page_sep
args.pages_sep = trim( pArgs.PagesSep ) or args.pages_sep
return core( args )
end
function f.harvard_citation_no_bracket( frame )
local args = f.args_default
local pArgs = getArgs(frame)
args.page = pArgs.p or pArgs.page or pArgs['ص'] or ''
args.pages = pArgs.pp or pArgs.pages or pArgs['صص'] or ''
args.location = pArgs.loc or pArgs['محل'] or ''
args.ref = pArgs.ref or pArgs.Ref or ''
args.P1 = trim( pArgs[1] ) or ''
args.P2 = trim( pArgs[2] ) or ''
args.P3 = trim( pArgs[3] ) or ''
args.P4 = trim( pArgs[4] ) or ''
args.P5 = trim( pArgs[5] ) or ''
args.andOthers = trim( pArgs.AndOthers ) or args.andOthers
args.amp = trim( pArgs.amp ) or args.amp
args.page_sep = trim( pArgs.PageSep ) or args.page_sep
args.pages_sep = trim( pArgs.PagesSep ) or args.pages_sep
args.comma = trim( pArgs.comma ) or args.comma
return core( args )
end
function f.sfn( frame )
local args = f.args_default
local pArgs = getArgs(frame)
for k, v in pairs( frame.args ) do -- for {{sfnp}}, override default with values provided in the #invoke:
args[k] = v
end
args.postscript = pArgs.postscript or pArgs.ps or '.'
if 'none' == args.postscript then
args.postscript = ''
end
args.page = pArgs.p or pArgs.page or pArgs['ص'] or ''
args.pages = pArgs.pp or pArgs.pages or pArgs['صص'] or ''
args.location = pArgs.loc or pArgs['محل'] or ''
args.ref = pArgs.ref or pArgs.Ref or ''
args.P1 = trim( pArgs[1] ) or ''
args.P2 = trim( pArgs[2] ) or ''
args.P3 = trim( pArgs[3] ) or ''
args.P4 = trim( pArgs[4] ) or ''
args.P5 = trim( pArgs[5] ) or ''
args.andOthers = trim( pArgs.AndOthers ) or args.andOthers
args.amp = trim( pArgs.amp ) or args.amp
args.comma = trim( pArgs.comma ) or args.comma
args.page_sep = trim( pArgs.PageSep ) or args.page_sep
args.pages_sep = trim( pArgs.PagesSep ) or args.pages_sep
local result = core( args )
local name = 'FOOTNOTE' .. args.P1 .. args.P2 ..
args.P3 .. args.P4 .. args.P5 .. args.page .. args.pages .. args.location
result = frame:extensionTag{ name = 'ref', args = {name=name}, content=result }
return result
end
return f