Modul:Excerpt: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Update from master using Synchronizer
Update from master using Synchronizer #synchronizer
 
(2 revisi perantara oleh pengguna yang sama tidak ditampilkan)
Baris 1:
-- Module:Excerpt implements the Excerpt template
-- Documentation and master version: https://wwwen.mediawikiwikipedia.org/wiki/Module:Excerpt
-- ByAuthors: User:Sophivorus, User:Certes, User:Aidan9382 & others
-- VersionLicense: 1CC-BY-SA-3.60
-- License CC BY-SA-3.0
 
local Transcluder = require( 'Module:Transcluder' )
Baris 16 ⟶ 15:
-- Helper function to get arguments
local args
local function getArg( key, default )
local value = args[ key ]
if value and mw.text.trim( value ) ~= '' then
Baris 25 ⟶ 24:
 
-- Helper function to handle errors
local function getError( message, value )
if type( message ) == 'string' then
message = Transcluder.getError( message, value )
Baris 36 ⟶ 35:
 
-- Helper function to get localized messages
local function getMessage( key )
local ok, TNT = pcall( require, 'Module:TNT' )
if not ok then return key end
Baris 42 ⟶ 41:
end
 
-- Main entry point for templates
function p.main( frame )
args = Transcluder.parseArgs( frame )
Baris 47:
-- Make sure the requested page exists
local page = getArg( 1 )
if not page or page == '{{{1}}}' then return getError( 'no-page' ) end
local title = mw.title.new(page)
if not title then return getError( 'noinvalid-pagetitle', page ) end
if title.isRedirect then title = title.redirectTarget end
if not title.exists then return getError( 'page-not-found', page ) end
Baris 70:
local noBold = not yesno( getArg( 'bold' ) )
local onlyFreeFiles = yesno( getArg( 'onlyfreefiles', true ) )
local briefDates = yesno( getArg( 'briefdates', false ) )
local inline = yesno( getArg( 'inline' ) )
local quote = yesno( getArg( 'quote' ) )
Baris 88 ⟶ 89:
end
hat = hat .. ' ' .. getMessage( 'excerpt' ) .. ' '
if section and not fragment then
hat = hat .. '[[:' .. page .. '#' .. mw.uri.anchorEncode( section ) .. '|' .. displaytitle
.. ' § ' .. mw.ustring.gsub( section, '%[%[([^]|]+)|?[^]]*%]%]', '%1' ) .. ']].' -- remove nested links
Baris 142 ⟶ 143:
if mw.text.trim( excerpt ) == '' and not only then
if section then return getError( 'section-empty', section ) else return getError( 'lead-empty' ) end
end
 
-- Fix birth and death dates, but only in the first paragraph
if briefDates then
local startpos = 1 -- skip initial templates
local s
local e = 0
repeat
startpos = e + 1
s, e = mw.ustring.find( excerpt, "%s*%b{}%s*", startpos )
until not s or s > startpos
s, e = mw.ustring.find( excerpt, "%b()", startpos ) -- get (...), which may be (year–year)
if s and s < startpos + 100 then -- look only near the start
local year1, conjunction, year2 = mw.ustring.match( mw.ustring.sub( excerpt, s, e ), '(%d%d%d+)(.-)(%d%d%d+)' )
if year1 and year2 and (mw.ustring.match( conjunction, '[%-–—]' ) or mw.ustring.match( conjunction, '{{%s*[sS]nd%s*}}' )) then
local y1 = tonumber(year1)
local y2 = tonumber(year2)
if y2 > y1 and y2 < y1 + 125 and y1 <= tonumber( os.date( "%Y" )) then
excerpt = mw.ustring.sub( excerpt, 1, s ) .. year1 .. "–" .. year2 .. mw.ustring.sub( excerpt, e )
end
end
end
end