Modul:Section link: Perbedaan antara revisi

Loncat ke navigasi Loncat ke pencarian
777 bita dihapus ,  2 tahun yang lalu
←Membuat halaman berisi '-- This module implements {{section link}}. local checkType = require('libraryUtil').checkType local p = {} local function makeSectionLink(page, section, display) display = display or section page = page or '' return string.format('%s', page, section, display) end local function normalizeTitle(title) title = mw.ustring.gsub(mw.ustring.gsub(title,"'",""),'"','') return mw.title.new(mw.ustring.gsub(title,"%b<>","")).prefixedText end function p._...'
dw>WOSlinker
(use require('strict') instead of require('Module:No globals'))
 
(←Membuat halaman berisi '-- This module implements {{section link}}. local checkType = require('libraryUtil').checkType local p = {} local function makeSectionLink(page, section, display) display = display or section page = page or '' return string.format('%s', page, section, display) end local function normalizeTitle(title) title = mw.ustring.gsub(mw.ustring.gsub(title,"'",""),'"','') return mw.title.new(mw.ustring.gsub(title,"%b<>","")).prefixedText end function p._...')
Baris 1: Baris 1:
-- This module implements {{section link}}.
-- This module implements {{section link}}.
require('strict');


local checkType = require('libraryUtil').checkType
local checkType = require('libraryUtil').checkType
Baris 9: Baris 8:
display = display or section
display = display or section
page = page or ''
page = page or ''
-- MediaWiki doesn't allow these in `page`, so only need to do for `section`
if type(section) == 'string' then
section = string.gsub(section, "{", "&#x7B;")
section = string.gsub(section, "}", "&#x7D;")
end
return string.format('[[%s#%s|%s]]', page, section, display)
return string.format('[[%s#%s|%s]]', page, section, display)
end
end


local function normalizeTitle(title)
local function normalizeTitle(title)
title = mw.ustring.gsub(mw.ustring.gsub(title, "'", ""), '"', '')
title = mw.ustring.gsub(mw.ustring.gsub(title,"'",""),'"','')
title = mw.ustring.gsub(title, "%b<>", "")
return mw.title.new(mw.ustring.gsub(title,"%b<>","")).prefixedText
return mw.title.new(title).prefixedText
end
end


Baris 51: Baris 44:
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 'Catatan'
local display = '§&nbsp;' .. section
local display = '§&nbsp;' .. section
if isShowingPage then
if isShowingPage then
Baris 60: Baris 53:
else
else
error(string.format(
error(string.format(
'Display title "%s" was ignored since it is ' ..
'Judul tampilan "%s" diabaikan karena ' ..
"not equivalent to the page's actual title",
"tidak sama dengan judul halaman yang sebenarnya",
options.display
options.display
), 0)
), 0)
Baris 101: Baris 94:


function p.main(frame)
function p.main(frame)
local yesno = require('Module:Yesno')
local args = require('Module:Arguments').getArgs(frame, {
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Section link',
wrappers = 'Template:Section link',
Baris 112: Baris 104:
end
end
})
})
for k, v in pairs(args) do -- replace underscores in the positional parameter values
if 'number' == type(k) then
if not yesno (args['keep-underscores']) then -- unless |keep-underscores=yes
args[k] = mw.uri.decode (v, 'WIKI'); -- percent-decode; replace underscores with space characters
else
args[k] = mw.uri.decode (v, 'PATH'); -- percent-decode; retain underscores
end
end
end


-- Sort the arguments.
-- Sort the arguments.
Baris 130: Baris 112:
-- Doing this in the loop because of a bug in [[Module:Arguments]]
-- Doing this in the loop because of a bug in [[Module:Arguments]]
-- when using pairs with deleted arguments.
-- when using pairs with deleted arguments.
page = mw.text.decode(v, true)
page = mw.text.decode(v, decodeNamedEntities)
elseif type(k) == 'number' then
elseif type(k) == 'number' then
sections[k] = v
sections[k] = v
Baris 137: Baris 119:
end
end
end
end
options.nopage = yesno (options.nopage); -- make boolean
-- Extract section from page, if present
-- Extract section from page, if present

Menu navigasi