Module:Documentation: Skirtumas tarp puslapio versijų

Pereiti į navigaciją Jump to search
4 545 baitai pašalinti ,  11 balandžio
S
nėra keitimo aprašymo
SNėra keitimo santraukos
SNėra keitimo santraukos
1 eilutė: 1 eilutė:
-- <nowiki>
local dependencyList = require( 'Module:DependencyList' )
local yn = require( 'Module:Yesno' )
local p = {}
local p = {}
local defaultDocPage = 'doc'


local getType = function( namespace, page )
function p.doc( frame )
local pageType = 'template'
    local title = mw.title.getCurrentTitle()
if namespace == 'Module' then
    local args = frame:getParent().args
pageType = 'module'
    local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
elseif namespace == 'Widget' then
    local addDependencyList = yn( args.DependencyList or true )
pageType = 'widget'
    local ret, cats, ret1, ret2, ret3
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.css$' ) then
    local onModule = title.namespace == 828
pageType = 'stylesheet'
   
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.js$' ) then
    -- subpage header
pageType = 'script'
    if title.subpageText == 'doc' then
elseif namespace == 'MediaWiki' then
        ret = mw.html.create( 'table' )
pageType = 'message'
            :addClass( 'messagebox' )
end
            :addClass( 'info' )
            :tag( 'tr' )
return pageType
                :tag( 'td' )
end
                    :css( 'width', '40px' )
                    :wikitext( '[[File:Information icon-grey.svg|35px|centre|link=]]' )
                    :done()
                :tag( 'td' )
                    :tag( 'b' )
                        :wikitext( 'This is a documentation subpage for [[' .. page .. ']].' )
                        :done()
                    :tag( 'div' )
                        :css({ ['font-size'] = '0.85em', ['line-height'] = '1.4em' })
                        :wikitext(
                        string.format(
                        'It contains usage information, categories, and other content that is not part of the original %s page.',
                            onModule and 'module' or 'template'
                        )
                    )
                        :done()
                    :done()
                :done()
            :done()


-- Creating a documentation page or transclusion through {{subst:docc}}
        if title.namespace == 10 then -- Template namespace
function p.create( f )
            cats = '[[Category:Template documentation|' .. title.baseText .. ']]'
local args = require( 'Module:ProcessArgs' ).norm()
            ret2 = addDependencyList and dependencyList._main() or ''
local page = mw.title.getCurrentTitle()
        elseif title.namespace == 116 then -- Calculator namespace
local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage
        cats = ''
        ret2 = addDependencyList and dependencyList._main() or ''
local out
        elseif title.namespace == 828 then -- Module namespace
if not args.content and tostring( page ) == docPage then
        cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
out = f:preprocess( '{{subst:Template:Documentation/preload}}' )
        ret2 = addDependencyList and dependencyList._main() or ''
else
        else
local templateArgs = {}
        cats = ''
for _, key in ipairs{ 'type', 'page', 'content' } do
        ret2 = ''
local val = args[key]
        end
if val then
       
if key == 'content' then val = '\n' .. val .. '\n' end
        return tostring( ret ) .. ret2 .. cats
table.insert( templateArgs, key .. '=' .. val )
    end
end
   
end
    -- template header
    -- don't use mw.html as we aren't closing the main div tag
out = '{{documentation|' .. table.concat( templateArgs, '|' ) .. '}}'
    ret1 = '<div class="documentation">'
out = out:gsub( '|}}', '}}' )
if not args.content then
out = out .. '\n<!-- Put categories/interwikis on the documentation page -->'
end
end
if not mw.isSubsting() then
out = f:preprocess( out )
if not args.nocat then
out = out .. '[[Category:Pages with templates requiring substitution]]'
end
end
return out
end


-- Header on the documentation page
    ret2 = mw.html.create( nil )
function p.docPage( f )
        :tag( 'div' )
local args = require( 'Module:ProcessArgs' ).merge( true )
            :addClass( 'doc-header documentation-header')
local badDoc = args.baddoc
            :tag( 'span' )
if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then
            :addClass( 'doc-title documentation-title' )
if badDoc then
            :wikitext( string.format('%s documentation', onModule and 'Module' or 'Template') )
f:callParserFunction( '#dplvar:set', '$doc bad', '1' )
            :done()
end
            :done()
return
        :tag( 'div' )
end
            :addClass( 'doc-transclusion documentation-subheader' )
            :tag( 'span' )
local page = mw.title.getCurrentTitle()
            :addClass( 'documentation-documentation' )
local subpage = page.subpageText
            :wikitext( 'This documentation is transcluded from [[' .. page .. '/doc]]. ' )
if subpage == 'sandbox' or subpage == 'testcases' then
            :done()
page = page.basePageTitle
            :tag( 'span' )
end
            :addClass( 'doc-editlinks documentation-links plainlinks' )
local namespace = page.nsText
            :wikitext(
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
            '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]] ' ..
            '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]] ' ..
local body = mw.html.create( 'div' ):addClass( 'documentation-header' )
                '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]'
body
            )
:addClass( badDoc and 'documentation-badDoc' or '' )
            :done()
:css{
            :done()
['margin-bottom'] = '0.8em',
   
padding = '0.8em 1em 0.7em',
    ret3 = addDependencyList and dependencyList._main() or ''
['background-color'] = '#' .. ( badDoc and '888888' or '33333333' ),
       
border = '1px solid #AAA'
    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. ret3
}
:tag( 'div' )
:attr( 'id', 'documentation-header-tools' )
:css( 'float', 'right' )
:wikitext( '[[', page:fullUrl( 'action=purge' ), ' ' .. f:preprocess('{{lc:{{int:page-header-action-button-purge}}}}') .. ']]' )
:done()
:wikitext(
'This is the documentation page. It ',
pageType == 'module' and 'will' or 'should',
' be transcluded into the main ', pageType, ' page. ',
'See [[Template:Documentation]] for more information'
)
if badDoc then
body:wikitext( "<br>'''This ", pageType, "'s documentation needs improving or additional information.'''" )
end
if not ( args.nocat or namespace == 'User' ) then
body:wikitext( '[[Category:Documentation pages]]' )
end
return body
end
end


-- Wrapper around the documentation on the main page
return p
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( 'Module:ProcessArgs' ).merge( true )
local page = mw.title.getCurrentTitle()
local subpage = page.subpageText
if subpage == 'sandbox' or subpage == 'testcases' then
page = page.basePageTitle
end
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' )
if docPage.fullText ~= page.fullText then
    docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
end
if docPage.fullText == page.fullText then
    mw.log("Prevented recursive doc inclusion on " .. docPage.fullText)
end
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 = f:preprocess('{{lc:{{int:edit}}}}')
local preload = ''
local docClass = ''
local colour = '00000000'
local message
local category
if noDoc then
action = f:preprocess('{{lc:{{int:create}}}}')
preload = '&preload=Template:Documentation/preload'
docClass = 'documentation-noDoc'
colour = '33333333'
message = "'''This " .. pageType .. " has no documentation. " ..
"If you know how to use this " .. pageType .. ", please create it.'''"
if not ( args.nocat or namespace == 'User' ) then
category = pageType .. 's with no documentation'
if not mw.title.new( 'Category:' .. category ).exists then
category = 'Pages with no documentation'
end
end
elseif badDoc then
docClass = 'documentation-badDoc'
colour = 'F9F2EA'
message = "'''This " .. pageType .. "'s documentation needs improving or additional information.'''\n"
if not ( args.nocat or namespace == 'User' ) then
category = pageType .. 's with bad documentation'
if not mw.title.new( 'Category:' .. category ).exists then
category = 'Pages with bad documentation'
end
end
end
local links = {
'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']',
'[' .. docPage:fullUrl( 'action=history' ) .. ' ' .. f:preprocess('{{lc:{{int:history short}}}}') .. ']',
'[' .. page:fullUrl( 'action=purge' ) .. ' ' .. f:preprocess('{{lc:{{int:page-header-action-button-purge}}}}') .. ']'
}
if not noDoc and page ~= docPage then
table.insert( links, 1, '[[' .. docPage.fullText .. '|' .. f:preprocess('{{lc:{{int:view}}}}') .. ']]' )
end
links = mw.html.create( 'span' )
:attr( 'id', 'documentation-header-tools' )
:css( 'float', 'right' )
:wikitext( mw.text.nowiki( '[' ), table.concat( links, ' | ' ), mw.text.nowiki( ']' ) )
local body = mw.html.create( 'div' ):addClass( 'documentation' )
body
:addClass( docClass )
: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' )
:addClass( 'documentation-header-top' )
:css{
margin = '-0.8em -1em 0.8em',
padding = '0.8em 1em 0.7em',
['background-color'] = '#33333333',
['border-bottom'] = 'inherit'
}
header
:node( links )
:tag( 'span' )
:attr( 'id', 'documentation-header-title' )
:css{
['font-weight'] = 'bold',
['font-size'] = '130%',
['margin-right'] = '1em',
['line-height'] = '1'
}
:wikitext( 'Documentation' )
local codePages = {
module = true,
stylesheet = true,
script = true,
}
if not noDoc and codePages[pageType] then
header
:tag( 'span' )
:attr( 'id', 'documentation-jump-to-code' )
:css( 'white-space', 'nowrap' )
:wikitext( '[[#the-code|Jump to code ↴]]' )
end
body
:node( header ):done()
:wikitext( message )
:wikitext( docText )
if not noDoc and page ~= docPage then
body
:tag( 'div' )
:addClass( 'documentation-header-bottom' )
:css{
margin = '0.7em -1em -0.7em',
['background-color'] = '#33333333',
['border-top'] = 'inherit',
padding = '0.8em 1em 0.7em',
clear = 'both'
}
:node( links )
:wikitext( 'The above documentation is transcluded from [[', docPage.fullText, ']].' )
end
local anchor = ''
if not noDoc and pageType ~= 'template' and pageType ~= 'message' then
anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' )
end
return tostring( body ) .. tostring( anchor )
end


return p
-- </nowiki>

Naršymo meniu