Sin resumen de edición |
Sin resumen de edición |
||
(No se muestran 4 ediciones intermedias de 2 usuarios) | |||
Línea 1: | Línea 1: | ||
local p = {} |
local p = {} |
||
+ | local defaultDocPage = 'doc' |
||
+ | |||
+ | local getType = function( namespace, page ) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | return pageType |
||
⚫ | |||
+ | |||
-- Creating a documentation page or transclution through {{subst:doc}} |
-- Creating a documentation page or transclution through {{subst:doc}} |
||
function p.create( f ) |
function p.create( f ) |
||
− | local |
+ | local args = require( 'Módulo:ProcessArgs' ).norm() |
− | page = mw.title. |
+ | local page = mw.title.getCurrentTitle() |
− | + | local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage |
|
⚫ | |||
local out |
local out |
||
− | if |
+ | if not args.content and tostring( page ) == docPage then |
− | out = f:preprocess( '{{ |
+ | out = f:preprocess( '{{subst:Plantilla:Documentación/preload}}' ) |
else |
else |
||
− | local |
+ | local templateArgs = {} |
+ | for _, key in ipairs{ 'type', 'page', 'content' } do |
||
⚫ | |||
− | + | local val = args[key] |
|
+ | if val then |
||
⚫ | |||
+ | if key == 'content' then val = '\n' .. val .. '\n' end |
||
⚫ | |||
− | table.insert( templateArgs, ' |
+ | table.insert( templateArgs, key .. '=' .. val ) |
+ | end |
||
end |
end |
||
− | out = '{{ |
+ | out = '{{documentación|' .. table.concat( templateArgs, '|' ) .. '}}' |
out = out:gsub( '|}}', '}}' ) |
out = out:gsub( '|}}', '}}' ) |
||
+ | |||
⚫ | |||
+ | out = out .. '\n<!-- Coloca las categorías/interwikis en la página de documentación -->' |
||
⚫ | |||
end |
end |
||
Línea 37: | Línea 60: | ||
local args = require( 'Módulo:ProcessArgs' ).merge( true ) |
local args = require( 'Módulo:ProcessArgs' ).merge( true ) |
||
local badDoc = args.baddoc |
local badDoc = args.baddoc |
||
− | if f: |
+ | if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then |
if badDoc then |
if badDoc then |
||
− | f:callParserFunction( '#dplvar:set', ' |
+ | f:callParserFunction( '#dplvar:set', '$doc bad', '1' ) |
end |
end |
||
− | return |
+ | return |
end |
end |
||
local page = mw.title.getCurrentTitle() |
local page = mw.title.getCurrentTitle() |
||
− | local namespace = |
+ | local namespace = page.nsText |
− | local pageType = |
+ | local pageType = mw.ustring.lower( args.type or getType( namespace, page ) ) |
⚫ | |||
⚫ | |||
⚫ | |||
− | art = 'este' |
||
⚫ | |||
− | pageType = 'hoja de estilo' |
||
⚫ | |||
⚫ | |||
− | art = 'este' |
||
⚫ | |||
⚫ | |||
− | art = 'este' |
||
⚫ | |||
+ | local body = mw.html.create( 'div' ):addClass( 'documentation-header' ) |
||
− | local colgour = 'EAF4F9' |
||
+ | body |
||
⚫ | |||
+ | :css{ |
||
+ | ['margin-bottom'] = '0.8em', |
||
+ | padding = '0.8em 1em 0.7em', |
||
+ | ['background-color'] = '#' .. ( badDoc and 'F9F2EA' or 'EAF4F9' ), |
||
+ | border = '1px solid #AAA' |
||
⚫ | |||
+ | :tag( 'div' ) |
||
+ | :css( 'float', 'right' ) |
||
⚫ | |||
+ | :done() |
||
+ | :wikitext( |
||
+ | 'Esta es la página de documentación. Esta ', |
||
+ | pageType == 'módulo' and 'será' or 'debería ser', |
||
+ | ' transcluída en la página', pageType, ' principal. ', |
||
+ | 'Véase la [[Plantilla:Documentación]] para más información' |
||
+ | ) |
||
if badDoc then |
if badDoc then |
||
+ | body:wikitext( "<br>''La documentación de esta/este ", pageType, " necesita mejorarse o más información.'''" ) |
||
− | colour = 'F9F2EA' |
||
− | message = "'''Es necesario añadir información adicional o mejorar la documentación de " .. art .. " " .. pageType .. ".'''" |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | local certainty = 'debería ser' |
||
− | if pageType == 'módulo' then |
||
− | certainty = 'será' |
||
end |
end |
||
+ | return body |
||
⚫ | |||
− | if not args.nocat then |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | local out = table.concat( { |
||
− | '<div style="margin-bottom:0.8em;padding:0.8em 1em 0.7em;background-color:#' .. colour .. ';border:1px solid #AAA">', |
||
⚫ | |||
− | '<p style="margin: 0">Esta es la página de documentación, la cual ' .. certainty .. ' incluida en la página principal de ' .. art .. ' ' .. pageType .. '. Véase [[Plantilla:Documentación]] para más información.</p>', |
||
⚫ | |||
− | '</div>', |
||
− | category |
||
− | }, '\n' ) |
||
⚫ | |||
− | return mw.text.trim( out ) |
||
end |
end |
||
-- Wrapper around the documentation on the main page |
-- Wrapper around the documentation on the main page |
||
function p.page( f ) |
function p.page( f ) |
||
+ | -- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings |
||
+ | local function trim( s ) |
||
+ | return (s:gsub( '^[\t\r\n\f ]+', '' ):gsub( '[\t\r\n\f ]+$', '' )) |
||
+ | --return string.gsub( s, '^[\t\r\n\f ]*(.-)[\t\r\n\f ]*$', '%1' ) |
||
+ | end |
||
local args = require( 'Módulo:ProcessArgs' ).merge( true ) |
local args = require( 'Módulo:ProcessArgs' ).merge( true ) |
||
local page = mw.title.getCurrentTitle() |
local page = mw.title.getCurrentTitle() |
||
− | local namespace = |
+ | local namespace = page.nsText |
− | local |
+ | local docText = trim( args.content or '' ) |
+ | if docText == '' then docText = nil end |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | local |
+ | local docPage |
− | local |
+ | local noDoc |
⚫ | |||
− | local art1 = 'Esta' |
||
+ | docPage = page |
||
− | local art2 = 'la' |
||
⚫ | |||
− | local art3 = 'esta' |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | art1 = 'Este' |
||
− | art2 = 'lo' |
||
− | art3 = 'este' |
||
− | elseif page.fullText:find( '.css$' ) then |
||
− | pageType = 'hoja' |
||
− | pageType2 = ' de estilos' |
||
− | elseif page.fullText:find( '.js$' ) then |
||
⚫ | |||
− | art1 = 'Este' |
||
− | art2 = 'lo' |
||
− | art3 = 'este' |
||
⚫ | |||
⚫ | |||
− | art1 = 'Este' |
||
− | art2 = 'lo' |
||
− | art3 = 'este' |
||
end |
end |
||
⚫ | |||
+ | local pageType = mw.ustring.lower( args.type or getType( namespace, page ) ) |
||
− | + | if not docText and not noDoc then |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
badDoc = 1 |
badDoc = 1 |
||
end |
end |
||
if docText == '' then |
if docText == '' then |
||
⚫ | |||
noDoc = 1 |
noDoc = 1 |
||
⚫ | |||
⚫ | |||
end |
end |
||
+ | end |
||
⚫ | |||
⚫ | |||
end |
end |
||
Línea 141: | Línea 142: | ||
local preload = '' |
local preload = '' |
||
local colour = 'EAF4F9' |
local colour = 'EAF4F9' |
||
− | local message |
+ | local message |
− | local category |
+ | local category |
if noDoc then |
if noDoc then |
||
action = 'crear' |
action = 'crear' |
||
preload = '&preload=Plantilla:Documentación/preload' |
preload = '&preload=Plantilla:Documentación/preload' |
||
colour = 'F9EAEA' |
colour = 'F9EAEA' |
||
− | message = "''' |
+ | message = "'''Esta/Este " .. pageType .. " no tiene documentación. " .. |
+ | "Si sabe cómo usar esta/este " .. pageType .. ", por favor créelo.'''" |
||
− | if not args.nocat then |
+ | if not ( args.nocat or namespace == 'Usuario' ) then |
⚫ | |||
− | + | category = pageType .. 's sin documentación' |
|
⚫ | |||
⚫ | |||
− | category = ' |
+ | category = 'Páginas sin documentación' |
end |
end |
||
end |
end |
||
elseif badDoc then |
elseif badDoc then |
||
colour = 'F9F2EA' |
colour = 'F9F2EA' |
||
− | message = "''' |
+ | message = "'''La documentación de esta/este " .. pageType .. " necesita mejorarse o más información.'''\n" |
− | if not args.nocat then |
+ | if not ( args.nocat or namespace == 'Usuario' ) then |
− | + | category = pageType .. 's con mala documentación' |
|
+ | if not mw.title.new( 'Categoría:' .. category ).exists then |
||
− | category = ' |
+ | category = 'Páginas con mala documentación' |
⚫ | |||
− | category = '[[Categoría:Páginas con una mala documentación]]' |
||
end |
end |
||
end |
end |
||
Línea 169: | Línea 169: | ||
local links = { |
local links = { |
||
'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']', |
'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']', |
||
+ | '[' .. docPage:fullUrl( 'action=history' ) .. ' historia]', |
||
'[' .. page:fullUrl( 'action=purge' ) .. ' depurar]' |
'[' .. page:fullUrl( 'action=purge' ) .. ' depurar]' |
||
} |
} |
||
+ | if not noDoc and page ~= docPage then |
||
− | local footer = '' |
||
⚫ | |||
table.insert( links, 1, '[[' .. docPage.fullText .. '|ver]]' ) |
table.insert( links, 1, '[[' .. docPage.fullText .. '|ver]]' ) |
||
− | footer = table.concat( { |
||
− | '<div style="margin:0.7em -1em -0.7em;background-color:#EAF4F9;border-top:1px solid #AAA;padding:0.8em 1em 0.7em;clear:both">\n', |
||
⚫ | |||
⚫ | |||
− | '</div>\n' |
||
⚫ | |||
end |
end |
||
+ | links = mw.html.create( 'span' ) |
||
+ | :css( 'float', 'right' ) |
||
⚫ | |||
+ | local body = mw.html.create( 'div' ):addClass( 'documentation' ) |
||
− | local out = { |
||
+ | body:css{ |
||
− | '<div style="backbground-color:#' .. colour .. ';border:1px solid #AAA;padding:0.8em 1em 0.7em;margin-top:1em;clear:both">\n', |
||
+ | ['background-color'] = '#' .. colour, |
||
− | '<div style="margin:-0.8em -1em 0.8em;padding: 0.8em 1em 0.7em;background-color:#EAF4F9;border-bottom:1px solid #AAA">\n', |
||
+ | border = '1px solid #AAA', |
||
− | '<div style="float:right">' .. mw.text.nowiki( '[' ) .. table.concat( links, ' | ' ) .. ']</div>\n', |
||
+ | padding = '0.8em 1em 0.7em', |
||
− | '<span style="font-weight:bold;font-size:130%">Documentación</span>', |
||
+ | ['margin-top'] = '1em', |
||
− | '</div>\n', |
||
+ | clear = 'both' |
||
− | message, |
||
⚫ | |||
− | footer, |
||
− | '</div>\n', |
||
− | category |
||
} |
} |
||
+ | local header = mw.html.create( 'div' ) |
||
− | return mw.text.trim( table.concat( out ) ) |
||
+ | :css{ |
||
+ | margin = '-0.8em -1em 0.8em', |
||
+ | padding = '0.8em 1em 0.7em', |
||
+ | ['background-color'] = '#EAF4F9', |
||
+ | ['border-bottom'] = 'inherit' |
||
+ | } |
||
⚫ | |||
+ | header |
||
+ | :node( links ) |
||
+ | :tag( 'span' ) |
||
+ | :css{ |
||
+ | ['font-weight'] = 'bold', |
||
+ | ['font-size'] = '130%', |
||
+ | ['margin-right'] = '1em', |
||
+ | ['line-height'] = '1' |
||
⚫ | |||
+ | :wikitext( 'Documentación' ) |
||
+ | |||
⚫ | |||
+ | module = true, |
||
+ | stylesheet = true, |
||
+ | script = true, |
||
+ | } |
||
+ | if not noDoc and codePages[pageType] then |
||
+ | header |
||
+ | :tag( 'span' ) |
||
+ | :css( 'white-space', 'nowrap' ) |
||
+ | :wikitext( '[[#el-código|Ver el código ↴]]' ) |
||
+ | end |
||
+ | |||
+ | body |
||
+ | :node( header ):done() |
||
⚫ | |||
+ | :wikitext( docText ) |
||
+ | |||
+ | if not noDoc and page ~= docPage then |
||
+ | body |
||
+ | :tag( 'div' ) |
||
+ | :css{ |
||
+ | margin = '0.7em -1em -0.7em', |
||
+ | ['background-color'] = '#EAF4F9', |
||
+ | ['border-top'] = 'inherit', |
||
+ | padding = '0.8em 1em 0.7em', |
||
+ | clear = 'both' |
||
+ | } |
||
+ | :node( links ) |
||
⚫ | |||
+ | end |
||
+ | |||
⚫ | |||
+ | body:wikitext( f:expandTemplate{ title = 'Translation category', args = { category, project = '0' } } ) |
||
+ | end |
||
+ | |||
⚫ | |||
+ | if not noDoc and pageType ~= 'plantilla' and pageType ~= 'mensaje' then |
||
+ | anchor = mw.html.create( 'div' ):attr( 'id', 'el-código' ) |
||
+ | end |
||
+ | |||
+ | return tostring( body ) .. tostring( anchor ) |
||
end |
end |
||
+ | |||
return p |
return p |
Revisión del 05:13 19 dic 2020
Este módulo implementa {{Documentación}}
.
Dependencias
[ver | editar | historia | depurar]La documentación arriba es transcluída desde Módulo:Documentation/doc.
local p = {}
local defaultDocPage = 'doc'
local getType = function( namespace, page )
local pageType = 'plantilla'
if namespace == 'Módulo' then
pageType = 'módulo'
elseif namespace == 'Widget' then
pageType = 'widget'
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.css$' ) then
pageType = 'stylesheet'
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.js$' ) then
pageType = 'script'
elseif namespace == 'MediaWiki' then
pageType = 'mensaje'
end
return pageType
end
-- Creating a documentation page or transclution through {{subst:doc}}
function p.create( f )
local args = require( 'Módulo:ProcessArgs' ).norm()
local page = mw.title.getCurrentTitle()
local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage
local out
if not args.content and tostring( page ) == docPage then
out = f:preprocess( '{{subst:Plantilla:Documentación/preload}}' )
else
local templateArgs = {}
for _, key in ipairs{ 'type', 'page', 'content' } do
local val = args[key]
if val then
if key == 'content' then val = '\n' .. val .. '\n' end
table.insert( templateArgs, key .. '=' .. val )
end
end
out = '{{documentación|' .. table.concat( templateArgs, '|' ) .. '}}'
out = out:gsub( '|}}', '}}' )
if not args.content then
out = out .. '\n<!-- Coloca las categorías/interwikis en la página de documentación -->'
end
end
if not mw.isSubsting() then
out = f:preprocess( out )
if not args.nocat then
out = out .. '[[Categoría:Páginas con plantillas que necesitan una sustitución]]'
end
end
return out
end
-- Header on the documentation page
function p.docPage( f )
local args = require( 'Módulo:ProcessArgs' ).merge( true )
local badDoc = args.baddoc
if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then
if badDoc then
f:callParserFunction( '#dplvar:set', '$doc bad', '1' )
end
return
end
local page = mw.title.getCurrentTitle()
local namespace = page.nsText
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
local body = mw.html.create( 'div' ):addClass( 'documentation-header' )
body
:css{
['margin-bottom'] = '0.8em',
padding = '0.8em 1em 0.7em',
['background-color'] = '#' .. ( badDoc and 'F9F2EA' or 'EAF4F9' ),
border = '1px solid #AAA'
}
:tag( 'div' )
:css( 'float', 'right' )
:wikitext( '[[', page:fullUrl( 'action=purge' ), ' depurar]]' )
:done()
:wikitext(
'Esta es la página de documentación. Esta ',
pageType == 'módulo' and 'será' or 'debería ser',
' transcluída en la página', pageType, ' principal. ',
'Véase la [[Plantilla:Documentación]] para más información'
)
if badDoc then
body:wikitext( "<br>''La documentación de esta/este ", pageType, " necesita mejorarse o más información.'''" )
end
if not ( args.nocat or namespace == 'Usuario' ) then
body:wikitext( '[[Categoría:Páginas de documentación]]' )
end
return body
end
-- Wrapper around the documentation on the main page
function p.page( f )
-- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings
local function trim( s )
return (s:gsub( '^[\t\r\n\f ]+', '' ):gsub( '[\t\r\n\f ]+$', '' ))
--return string.gsub( s, '^[\t\r\n\f ]*(.-)[\t\r\n\f ]*$', '%1' )
end
local args = require( 'Módulo:ProcessArgs' ).merge( true )
local page = mw.title.getCurrentTitle()
local namespace = page.nsText
local docText = trim( args.content or '' )
if docText == '' then docText = nil end
local docPage
local noDoc
if docText then
docPage = page
else
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/' .. defaultDocPage )
noDoc = args.nodoc or not docPage.exists
end
local badDoc = args.baddoc
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
if not docText and not noDoc then
f:callParserFunction( '#dplvar:set', '$doc noheader', '1' )
docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
if f:callParserFunction( '#dplvar', '$doc bad' ) == '1' then
badDoc = 1
end
if docText == '' then
docText = nil
noDoc = 1
end
end
if docText then
docText = '\n' .. docText .. '\n'
end
local action = 'editar'
local preload = ''
local colour = 'EAF4F9'
local message
local category
if noDoc then
action = 'crear'
preload = '&preload=Plantilla:Documentación/preload'
colour = 'F9EAEA'
message = "'''Esta/Este " .. pageType .. " no tiene documentación. " ..
"Si sabe cómo usar esta/este " .. pageType .. ", por favor créelo.'''"
if not ( args.nocat or namespace == 'Usuario' ) then
category = pageType .. 's sin documentación'
if not mw.title.new( 'Categoría:' .. category ).exists then
category = 'Páginas sin documentación'
end
end
elseif badDoc then
colour = 'F9F2EA'
message = "'''La documentación de esta/este " .. pageType .. " necesita mejorarse o más información.'''\n"
if not ( args.nocat or namespace == 'Usuario' ) then
category = pageType .. 's con mala documentación'
if not mw.title.new( 'Categoría:' .. category ).exists then
category = 'Páginas con mala documentación'
end
end
end
local links = {
'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']',
'[' .. docPage:fullUrl( 'action=history' ) .. ' historia]',
'[' .. page:fullUrl( 'action=purge' ) .. ' depurar]'
}
if not noDoc and page ~= docPage then
table.insert( links, 1, '[[' .. docPage.fullText .. '|ver]]' )
end
links = mw.html.create( 'span' )
:css( 'float', 'right' )
:wikitext( mw.text.nowiki( '[' ), table.concat( links, ' | ' ), mw.text.nowiki( ']' ) )
local body = mw.html.create( 'div' ):addClass( 'documentation' )
body:css{
['background-color'] = '#' .. colour,
border = '1px solid #AAA',
padding = '0.8em 1em 0.7em',
['margin-top'] = '1em',
clear = 'both'
}
local header = mw.html.create( 'div' )
:css{
margin = '-0.8em -1em 0.8em',
padding = '0.8em 1em 0.7em',
['background-color'] = '#EAF4F9',
['border-bottom'] = 'inherit'
}
header
:node( links )
:tag( 'span' )
:css{
['font-weight'] = 'bold',
['font-size'] = '130%',
['margin-right'] = '1em',
['line-height'] = '1'
}
:wikitext( 'Documentación' )
local codePages = {
module = true,
stylesheet = true,
script = true,
}
if not noDoc and codePages[pageType] then
header
:tag( 'span' )
:css( 'white-space', 'nowrap' )
:wikitext( '[[#el-código|Ver el código ↴]]' )
end
body
:node( header ):done()
:wikitext( message )
:wikitext( docText )
if not noDoc and page ~= docPage then
body
:tag( 'div' )
:css{
margin = '0.7em -1em -0.7em',
['background-color'] = '#EAF4F9',
['border-top'] = 'inherit',
padding = '0.8em 1em 0.7em',
clear = 'both'
}
:node( links )
:wikitext( 'La documentación arriba es transcluída desde [[', docPage.fullText, ']].' )
end
if category then
body:wikitext( f:expandTemplate{ title = 'Translation category', args = { category, project = '0' } } )
end
local anchor = ''
if not noDoc and pageType ~= 'plantilla' and pageType ~= 'mensaje' then
anchor = mw.html.create( 'div' ):attr( 'id', 'el-código' )
end
return tostring( body ) .. tostring( anchor )
end
return p