پرش به محتوا

پودمان:Section link: تفاوت میان نسخه‌ها

۴۴۱ بایت اضافه‌شده ،  ‏۳۰ اکتبر ۲۰۲۲
صفحه‌ای تازه حاوی «-- This module implements {{section link}}. require('Module:No globals'); local checkType = require('libraryUtil').checkType local p = {}...» ایجاد کرد
fa>Wikivahdat
(use require('strict') instead of require('Module:No globals'))
 
(صفحه‌ای تازه حاوی «-- This module implements {{section link}}. require('Module:No globals'); local checkType = require('libraryUtil').checkType local p = {}...» ایجاد کرد)
خط ۱: خط ۱:
-- This module implements {{section link}}.
-- This module implements {{section link}}.
require('strict');
require('Module:No globals');


local checkType = require('libraryUtil').checkType
local checkType = require('libraryUtil').checkType
خط ۱۱: خط ۱۱:
-- MediaWiki doesn't allow these in `page`, so only need to do for `section`
-- MediaWiki doesn't allow these in `page`, so only need to do for `section`
if type(section) == 'string' then
if type(section) == 'string' then
section = string.gsub(section, "{", "{")
section = mw.ustring.gsub(section, "{", "{")
section = string.gsub(section, "}", "}")
section = mw.ustring.gsub(section, "}", "}")
end
end
return string.format('[[%s#%s|%s]]', page, section, display)
return mw.ustring.format('[[%s#%s|%s]]', page, section, display)
end
end


خط ۳۲: خط ۳۲:
sections = {sections}
sections = {sections}
elseif type(sections) ~= 'table' then
elseif type(sections) ~= 'table' then
error(string.format(
error(mw.ustring.format(
"type error in argument #2 to '_main' " ..
"خطای نوع در آرگومان #2 برای '_main' " ..
"(string, table or nil expected, got %s)",
"(رشته، جدول یا خالی مورد انتظار بود، در عوض %s دریافت شد)",
type(sections)
type(sections)
), 2)
), 2)
خط ۴۲: خط ۴۲:


-- Deal with blank page names elegantly
-- Deal with blank page names elegantly
if page and not page:find('%S') then
if page and not mw.ustring.find(page, '%S') then
page = nil
page = nil
options.nopage = true
options.nopage = true
خط ۵۱: خط ۵۱:
if #sections <= 1 then
if #sections <= 1 then
local linkPage = page or ''
local linkPage = page or ''
local section = sections[1] or 'Notes'
local section = sections[1] or 'یادداشت‌ها'
local display = '§&nbsp;' .. section
local display = '§&nbsp;' .. section
if isShowingPage then
if isShowingPage then
page = page or title.prefixedText
page = page or title.prefixedText
if options.display and options.display ~= '' then
if options.display or options['نمایش'] and (options.display or options['نمایش']) ~= '' then
if normalizeTitle(options.display) == normalizeTitle(page) then
if normalizeTitle(options.display or options['نمایش']) == normalizeTitle(page) then
display = options.display .. ' ' .. display
display = (options.display or options['نمایش']) .. ' ' .. display
else
else
error(string.format(
error(mw.ustring.format(
'Display title "%s" was ignored since it is ' ..
'از عنوان ظاهری «%s» صرف نظر شد؛ زیرا ' ..
"not equivalent to the page's actual title",
"این عنوان با عنوان اصلی صفحه یکسان نیست",
options.display
options.display or options['نمایش']
), 0)
), 0)
end
end
خط ۸۳: خط ۸۳:
local conjunction
local conjunction
if #sections == 2 then
if #sections == 2 then
conjunction = '&#8203; and '
conjunction = '&#8203; و '
else
else
conjunction = ', and '
conjunction = '، و '
end
end
ret = mw.text.listToText(ret, nil, conjunction)
ret = mw.text.listToText(ret, nil, conjunction)
خط ۱۰۳: خط ۱۰۳:
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local args = require('Module:Arguments').getArgs(frame, {
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Section link',
wrappers = {'الگو:پیوند بخش', 'الگو:لینک بخش'},
valueFunc = function (key, value)
valueFunc = function (key, value)
value = value:match('^%s*(.-)%s*$') -- Trim whitespace
value = mw.ustring.match(value, '^%s*(.-)%s*$') -- Trim whitespace
-- Allow blank first parameters, as the wikitext template does this.
-- Allow blank first parameters, as the wikitext template does this.
if value ~= '' or key == 1 then
if value ~= '' or key == 1 then
خط ۱۱۵: خط ۱۱۵:
for k, v in pairs(args) do -- replace underscores in the positional parameter values
for k, v in pairs(args) do -- replace underscores in the positional parameter values
if 'number' == type(k) then
if 'number' == type(k) then
if not yesno (args['keep-underscores']) then -- unless |keep-underscores=yes
if not yesno (args['keep-underscores'] or args['ماندن زیرخط']) then -- unless |keep-underscores=yes
args[k] = mw.uri.decode (v, 'WIKI'); -- percent-decode; replace underscores with space characters
args[k] = mw.uri.decode (v, 'WIKI'); -- percent-decode; replace underscores with space characters
else
else
خط ۱۳۸: خط ۱۳۸:
end
end
options.nopage = yesno (options.nopage); -- make boolean
options.nopage = yesno (options.nopage or options['بدون صفحه']); -- make boolean
-- Extract section from page, if present
-- Extract section from page, if present
if page then
if page then
local p, s = page:match('^(.-)#(.*)$')
local p, s = mw.ustring.match(page, '^(.-)#(.*)$')
if p then page, sections[1] = p, s end
if p then page, sections[1] = p, s end
end
end
۸٬۱۴۱

ویرایش