Editing Module:Documentation

From WoopMC
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
-- <nowiki>
local dependencyList = require( 'Module:DependencyList' )
local yn = require( 'Module:Yesno' )
local p = {}
local p = {}
local defaultDocPage = 'doc'


function p.doc( frame )
local getType = function( namespace, page )
    local title = mw.title.getCurrentTitle()
local pageType = 'template'
    local args = frame:getParent().args
if namespace == 'Module' then
    local page = args[1] or mw.ustring.gsub( title.fullText, '/doc$', '' )
pageType = 'module'
    local addDependencyList = yn( args.DependencyList or true )
elseif namespace == 'Widget' then
    local ret, cats, ret1, ret2, ret3
pageType = 'widget'
    local onModule = title.namespace == 828
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.css$' ) then
   
pageType = 'stylesheet'
    -- subpage header
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.js$' ) then
    if title.subpageText == 'doc' then
pageType = 'script'
        ret = mw.html.create( nil )
elseif namespace == 'MediaWiki' then
            :tag( 'div' )
pageType = 'message'
                :addClass( 'mbox mbox-low mbox-documentationsub' )
end
                :attr( 'role', 'presentation')
                :tag( 'span' )
return pageType
                    :addClass( 'mbox-title' )
end
                    :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
-- Creating a documentation page or transclusion through {{subst:docc}}
            cats = '[[Category:Template documentation|' .. title.baseText .. ']]'
function p.create( f )
            ret2 = addDependencyList and dependencyList._main() or ''
local args = require( 'Module:ProcessArgs' ).norm()
        elseif title.namespace == 828 then -- Module namespace
local page = mw.title.getCurrentTitle()
            cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage
            ret2 = addDependencyList and dependencyList._main() or ''
        else
local out
            cats = ''
if not args.content and tostring( page ) == docPage then
            ret2 = ''
out = f:preprocess( '{{subst:Template:Documentation/preload}}' )
        end
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 = '{{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


        return tostring( ret ) .. ret2 .. cats
-- Header on the documentation page
    end
function p.docPage( f )
   
local args = require( 'Module:ProcessArgs' ).merge( true )
    -- template header
local badDoc = args.baddoc
    -- don't use mw.html as we aren't closing the main div tag
if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then
    ret1 = '<div class="documentation">'
if badDoc then
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


    ret2 = mw.html.create( nil )
-- Wrapper around the documentation on the main page
        :tag( 'div' )
function p.page( f )
            :addClass( 'documentation-header' )
-- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings
            :tag( 'span' )
local function trim( s )
                :addClass( 'documentation-title' )
return (s:gsub( '^[\t\r\n\f ]+', '' ):gsub( '[\t\r\n\f ]+$', '' ))
                :wikitext( string.format('%s documentation', onModule and 'Module' or 'Template') )
--return string.gsub( s, '^[\t\r\n\f ]*(.-)[\t\r\n\f ]*$', '%1' )
                :done()
end
            :tag( 'span' )
local args = require( 'Module:ProcessArgs' ).merge( true )
                :addClass( 'documentation-links plainlinks' )
local page = mw.title.getCurrentTitle()
                :wikitext(
local subpage = page.subpageText
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' view]]' ..
if subpage == 'sandbox' or subpage == 'testcases' then
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
page = page.basePageTitle
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
end
                    '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]'
local namespace = page.nsText
                )
local docText = trim( args.content or '' )
                :done()
if docText == '' then docText = nil end
            :done()
        :tag( 'div' )
local docPage
            :addClass( 'documentation-subheader' )
local noDoc
            :tag( 'span' )
if docText then
                :addClass( 'documentation-documentation' )
docPage = page
                :wikitext( 'This documentation is transcluded from [[' .. page .. '/doc]]. Changes can be proposed in the talk page.' )
else
                :done()
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/' .. defaultDocPage )
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Mbox/styles.css'} })
noDoc = args.nodoc or not docPage.exists
            :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Documentation/styles.css'} })
end
            :done()
local badDoc = args.baddoc
   
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
    ret3 = addDependencyList and dependencyList._main() or ''
       
if not docText and not noDoc then
    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. ret3
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 = 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>
Please note that all contributions to WoopMC may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WoopMC:Copyrights for details). Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)