Module:Excerpt/ja: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tag: Manual revert |
||
Line 1: | Line 1: | ||
-- Module:Excerpt implements the Excerpt template | -- Module:Excerpt implements the Excerpt template | ||
-- Documentation | -- Documentation https://www.mediawiki.org/wiki/Module:Excerpt | ||
-- | -- By User:Sophivorus, User:Certes & others | ||
-- License | -- Version 1.5 | ||
-- License CC BY-SA-3.0 | |||
local Transcluder = require( 'Module:Transcluder' ) | local Transcluder = require( 'Module:Transcluder' ) | ||
Line 15: | Line 16: | ||
-- Helper function to get arguments | -- Helper function to get arguments | ||
local args | local args | ||
function getArg( key, default ) | |||
local value = args[ key ] | local value = args[ key ] | ||
if value and mw.text.trim( value ) ~= '' then | if value and mw.text.trim( value ) ~= '' then | ||
Line 24: | Line 25: | ||
-- Helper function to handle errors | -- Helper function to handle errors | ||
function getError( message, value ) | |||
if type( message ) == 'string' then | if type( message ) == 'string' then | ||
message = Transcluder.getError( message, value ) | message = Transcluder.getError( message, value ) | ||
Line 35: | Line 36: | ||
-- Helper function to get localized messages | -- Helper function to get localized messages | ||
function getMessage( key ) | |||
local ok, TNT = pcall( require, 'Module:TNT' ) | local ok, TNT = pcall( require, 'Module:TNT' ) | ||
if not ok then return key end | if not ok then return key end | ||
Line 41: | Line 42: | ||
end | end | ||
function p.main( frame ) | function p.main( frame ) | ||
args = Transcluder.parseArgs( frame ) | args = Transcluder.parseArgs( frame ) | ||
Line 47: | Line 47: | ||
-- Make sure the requested page exists | -- Make sure the requested page exists | ||
local page = getArg( 1 ) | local page = getArg( 1 ) | ||
if not page | if not page then return getError( 'no-page' ) end | ||
local title = mw.title.new(page) | local title = mw.title.new(page) | ||
if not title then return getError( ' | if not title then return getError( 'no-page' ) end | ||
if title.isRedirect then title = title.redirectTarget end | if title.isRedirect then title = title.redirectTarget end | ||
if not title.exists then return getError( 'page-not-found', page ) end | if not title.exists then return getError( 'page-not-found', page ) end | ||
Line 70: | Line 70: | ||
local noBold = not yesno( getArg( 'bold' ) ) | local noBold = not yesno( getArg( 'bold' ) ) | ||
local onlyFreeFiles = yesno( getArg( 'onlyfreefiles', true ) ) | local onlyFreeFiles = yesno( getArg( 'onlyfreefiles', true ) ) | ||
local inline = yesno( getArg( 'inline' ) ) | local inline = yesno( getArg( 'inline' ) ) | ||
local quote = yesno( getArg( 'quote' ) ) | local quote = yesno( getArg( 'quote' ) ) | ||
local more = yesno( getArg( 'more' ) ) | local more = yesno( getArg( 'more' ) ) | ||
local class = getArg( 'class' ) | local class = getArg( 'class' ) | ||
-- Build the hatnote | -- Build the hatnote | ||
Line 89: | Line 87: | ||
end | end | ||
hat = hat .. ' ' .. getMessage( 'excerpt' ) .. ' ' | hat = hat .. ' ' .. getMessage( 'excerpt' ) .. ' ' | ||
if section then | if section and not fragment then | ||
hat = hat .. '[[:' .. page .. '#' .. mw.uri.anchorEncode( section ) .. '|' .. | hat = hat .. '[[:' .. page .. '#' .. mw.uri.anchorEncode( section ) .. '|' .. page | ||
.. ' § ' .. mw.ustring.gsub( section, '%[%[([^]|]+)|?[^]]*%]%]', '%1' ) .. ']].' -- remove nested links | .. ' § ' .. mw.ustring.gsub( section, '%[%[([^]|]+)|?[^]]*%]%]', '%1' ) .. ']].' -- remove nested links | ||
else | else | ||
hat = hat .. '[[:' .. page .. '|' .. | hat = hat .. '[[:' .. page .. '|' .. page .. ']].' | ||
end | end | ||
if edit then | if edit then | ||
Line 143: | Line 141: | ||
if mw.text.trim( excerpt ) == '' and not only then | if mw.text.trim( excerpt ) == '' and not only then | ||
if section then return getError( 'section-empty', section ) else return getError( 'lead-empty' ) end | if section then return getError( 'section-empty', section ) else return getError( 'lead-empty' ) end | ||
end | end | ||