Module:Documentation: Difference between revisions

From WoopMC
Maraheze>Tera458
m (1 revision imported)
 
m (1 revision imported)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- <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( nil )
pageType = 'message'
            :tag( 'div' )
end
                :addClass( 'mbox mbox-low mbox-documentationsub' )
                :attr( 'role', 'presentation')
return pageType
                :tag( 'span' )
end
                    :addClass( 'mbox-title' )
                    :tag( 'span' )
                        :addClass( 'mbox-icon metadata' )
                        :wikitext( '[[File:WikimediaUI-Notice.svg|14px|link=]]' )
                        :done()
                    :wikitext( 'This is a documentation subpage for ' .. page .. '.' )
                    :done()
                :tag( 'span' )
                    :addClass( 'mbox-text' )
                    :wikitext(
                        string.format(
                            'It contains usage information, categories, and other content that is not part of the [[' .. page .. '|original %s page]].',
                            onModule and 'module' or 'template'
                        )
                    )
                    :done()
                :done()
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Mbox/styles.css'} })
            :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 == 828 then -- Module namespace
local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage
            cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
            ret2 = addDependencyList and dependencyList._main() or ''
local out
        else
if not args.content and tostring( page ) == docPage then
            cats = ''
out = f:preprocess( '{{subst:Template:Documentation/preload}}' )
            ret2 = ''
else
        end
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 = '{{documentation|' .. table.concat( templateArgs, '|' ) .. '}}'
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
        return tostring( ret ) .. ret2 .. cats
function p.docPage( f )
    end
local args = require( 'Module:ProcessArgs' ).merge( true )
   
local badDoc = args.baddoc
    -- template header
if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then
    -- don't use mw.html as we aren't closing the main div tag
if badDoc then
    ret1 = '<div class="documentation">'
f:callParserFunction( '#dplvar:set', '$doc bad', '1' )
end
return
end
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 pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
local body = mw.html.create( 'div' ):addClass( 'documentation-header' )
body
:addClass( badDoc and 'documentation-badDoc' or '' )
:css{
['margin-bottom'] = '0.8em',
padding = '0.8em 1em 0.7em',
['background-color'] = '#' .. ( badDoc and 'F9F2EA' or 'EAF4F9' ),
border = '1px solid #AAA'
}
: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


-- Wrapper around the documentation on the main page
    ret2 = mw.html.create( nil )
function p.page( f )
        :tag( 'div' )
-- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings
            :addClass( 'documentation-header' )
local function trim( s )
            :tag( 'span' )
return (s:gsub( '^[\t\r\n\f ]+', '' ):gsub( '[\t\r\n\f ]+$', '' ))
                :addClass( 'documentation-title' )
--return string.gsub( s, '^[\t\r\n\f ]*(.-)[\t\r\n\f ]*$', '%1' )
                :wikitext( string.format('%s documentation', onModule and 'Module' or 'Template') )
end
                :done()
local args = require( 'Module:ProcessArgs' ).merge( true )
            :tag( 'span' )
local page = mw.title.getCurrentTitle()
                :addClass( 'documentation-links plainlinks' )
local subpage = page.subpageText
                :wikitext(
if subpage == 'sandbox' or subpage == 'testcases' then
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' view]]' ..
page = page.basePageTitle
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
end
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
local namespace = page.nsText
                    '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]'
local docText = trim( args.content or '' )
                )
if docText == '' then docText = nil end
                :done()
            :done()
local docPage
        :tag( 'div' )
local noDoc
            :addClass( 'documentation-subheader' )
if docText then
            :tag( 'span' )
docPage = page
                :addClass( 'documentation-documentation' )
else
                :wikitext( 'This documentation is transcluded from [[' .. page .. '/doc]]. Changes can be proposed in the talk page.' )
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/' .. defaultDocPage )
                :done()
noDoc = args.nodoc or not docPage.exists
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Mbox/styles.css'} })
end
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Documentation/styles.css'} })
local badDoc = args.baddoc
            :done()
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
   
    ret3 = addDependencyList and dependencyList._main() or ''
if not docText and not noDoc then
       
f:callParserFunction( '#dplvar:set', '$doc noheader', '1' )
    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. ret3
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 = f:preprocess('{{lc:{{int:edit}}}}')
local preload = ''
local docClass = ''
local colour = 'EAF4F9'
local message
local category
if noDoc then
action = f:preprocess('{{lc:{{int:create}}}}')
preload = '&preload=Template:Documentation/preload'
docClass = 'documentation-noDoc'
colour = 'F9EAEA'
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'] = '#EAF4F9',
['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'] = '#EAF4F9',
['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
end


return p
return p
-- </nowiki>

Latest revision as of 17:14, 26 May 2024

Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Documentation/doc. Changes can be proposed in the talk page.

Module:Documentation implements Template:Documentation for templates and modules.


-- <nowiki>
local dependencyList = require( 'Module:DependencyList' )
local yn = require( 'Module:Yesno' )
local p = {}

function p.doc( frame )
    local title = mw.title.getCurrentTitle()
    local args = frame:getParent().args
    local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
    local addDependencyList = yn( args.DependencyList or true )
    local ret, cats, ret1, ret2, ret3
    local onModule = title.namespace == 828
    
    -- subpage header
    if title.subpageText == 'doc' then
        ret = mw.html.create( nil )
            :tag( 'div' )
                :addClass( 'mbox mbox-low mbox-documentationsub' )
                :attr( 'role', 'presentation')
                :tag( 'span' )
                    :addClass( 'mbox-title' )
                    :tag( 'span' )
                        :addClass( 'mbox-icon metadata' )
                        :wikitext( '[[File:WikimediaUI-Notice.svg|14px|link=]]' )
                        :done()
                    :wikitext( 'This is a documentation subpage for ' .. page .. '.' )
                    :done()
                :tag( 'span' )
                    :addClass( 'mbox-text' )
                    :wikitext(
                        string.format(
                            'It contains usage information, categories, and other content that is not part of the [[' .. page .. '|original %s page]].',
                            onModule and 'module' or 'template'
                        )
                    )
                    :done()
                :done()
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Mbox/styles.css'} })
            :done()

        if title.namespace == 10 then -- Template namespace
            cats = '[[Category:Template documentation|' .. title.baseText .. ']]'
            ret2 = addDependencyList and dependencyList._main() or ''
        elseif title.namespace == 828 then -- Module namespace
            cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
            ret2 = addDependencyList and dependencyList._main() or ''
        else
            cats = ''
            ret2 = ''
        end

        return tostring( ret ) .. ret2 .. cats
    end
    
    -- template header
    -- don't use mw.html as we aren't closing the main div tag
    ret1 = '<div class="documentation">'

    ret2 = mw.html.create( nil )
        :tag( 'div' )
            :addClass( 'documentation-header' )
            :tag( 'span' )
                :addClass( 'documentation-title' )
                :wikitext( string.format('%s documentation', onModule and 'Module' or 'Template') )
                :done()
            :tag( 'span' )
                :addClass( 'documentation-links plainlinks' )
                :wikitext(
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' view]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
                    '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]'
                )
                :done()
            :done()
        :tag( 'div' )
            :addClass( 'documentation-subheader' )
            :tag( 'span' )
                :addClass( 'documentation-documentation' )
                :wikitext( 'This documentation is transcluded from [[' .. page .. '/doc]]. Changes can be proposed in the talk page.' )
                :done()
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Mbox/styles.css'} })
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Documentation/styles.css'} })
            :done()
    
    ret3 = addDependencyList and dependencyList._main() or ''
        
    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. ret3
end

return p

-- </nowiki>