|
|
(14 intermediate revisions by 9 users not shown) |
Line 133: |
Line 133: |
| local root = mw.html.create() | | local root = mw.html.create() |
| root | | root |
| :wikitext(p._getModuleWikitext(args, env))
| |
| :wikitext(p.protectionTemplate(env))
| |
| :wikitext(p.sandboxNotice(args, env))
| |
| :tag('div') | | :tag('div') |
| -- 'documentation-container' | | -- 'documentation-container' |
| :addClass(message('container')) | | :addClass(message('container')) |
| | :attr('role', 'complementary') |
| | :attr('aria-labelledby', args.heading ~= '' and 'documentation-heading' or nil) |
| | :attr('aria-label', args.heading == '' and 'Documentation' or nil) |
| :newline() | | :newline() |
| :tag('div') | | :tag('div') |
Line 179: |
Line 179: |
| -- | | -- |
| -- Data includes: | | -- Data includes: |
| -- env.protectionLevels - the protection levels table of the title object.
| |
| -- env.subjectSpace - the number of the title's subject namespace. | | -- env.subjectSpace - the number of the title's subject namespace. |
| -- env.docSpace - the number of the namespace the title puts its documentation in. | | -- env.docSpace - the number of the namespace the title puts its documentation in. |
Line 272: |
Line 271: |
| end | | end |
|
| |
|
| function envFuncs.protectionLevels()
| |
| -- The protection levels table of the title object.
| |
| return env.title.protectionLevels
| |
| end
| |
|
| |
|
| function envFuncs.subjectSpace() | | function envFuncs.subjectSpace() |
Line 322: |
Line 317: |
| return env | | return env |
| end | | end |
|
| |
| ----------------------------------------------------------------------------
| |
| -- Auxiliary templates
| |
| ----------------------------------------------------------------------------
| |
|
| |
| p.getModuleWikitext = makeInvokeFunc('_getModuleWikitext')
| |
|
| |
| function p._getModuleWikitext(args, env)
| |
| local currentTitle = mw.title.getCurrentTitle()
| |
| if currentTitle.contentModel ~= 'Scribunto' then return end
| |
| pcall(require, currentTitle.prefixedText) -- if it fails, we don't care
| |
| local moduleWikitext = package.loaded["Module:Module wikitext"]
| |
| if moduleWikitext then
| |
| return moduleWikitext.main()
| |
| end
| |
| end
| |
|
| |
| function p.sandboxNotice(args, env)
| |
| --[=[
| |
| -- Generates a sandbox notice for display above sandbox pages.
| |
| -- @args - a table of arguments passed by the user
| |
| -- @env - environment table containing title objects, etc., generated with p.getEnvironment
| |
| --
| |
| -- Messages:
| |
| -- 'sandbox-notice-image' --> '[[Image:Sandbox.svg|50px|alt=|link=]]'
| |
| -- 'sandbox-notice-blurb' --> 'This is the $1 for $2.'
| |
| -- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).'
| |
| -- 'sandbox-notice-pagetype-template' --> '[[Wikipedia:Template test cases|template sandbox]] page'
| |
| -- 'sandbox-notice-pagetype-module' --> '[[Wikipedia:Template test cases|module sandbox]] page'
| |
| -- 'sandbox-notice-pagetype-other' --> 'sandbox page'
| |
| -- 'sandbox-notice-compare-link-display' --> 'diff'
| |
| -- 'sandbox-notice-testcases-blurb' --> 'See also the companion subpage for $1.'
| |
| -- 'sandbox-notice-testcases-link-display' --> 'test cases'
| |
| -- 'sandbox-category' --> 'Template sandboxes'
| |
| --]=]
| |
| local title = env.title
| |
| local sandboxTitle = env.sandboxTitle
| |
| local templateTitle = env.templateTitle
| |
| local subjectSpace = env.subjectSpace
| |
| if not (subjectSpace and title and sandboxTitle and templateTitle
| |
| and mw.title.equals(title, sandboxTitle)) then
| |
| return nil
| |
| end
| |
| -- Build the table of arguments to pass to {{ombox}}. We need just two fields, "image" and "text".
| |
| local omargs = {}
| |
| omargs.image = message('sandbox-notice-image')
| |
| -- Get the text. We start with the opening blurb, which is something like
| |
| -- "This is the template sandbox for [[Template:Foo]] (diff)."
| |
| local text = ''
| |
| local pagetype
| |
| if subjectSpace == 10 then
| |
| pagetype = message('sandbox-notice-pagetype-template')
| |
| elseif subjectSpace == 828 then
| |
| pagetype = message('sandbox-notice-pagetype-module')
| |
| else
| |
| pagetype = message('sandbox-notice-pagetype-other')
| |
| end
| |
| local templateLink = makeWikilink(templateTitle.prefixedText)
| |
| local compareUrl = env.compareUrl
| |
| if compareUrl then
| |
| local compareDisplay = message('sandbox-notice-compare-link-display')
| |
| local compareLink = makeUrlLink(compareUrl, compareDisplay)
| |
| text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink})
| |
| else
| |
| text = text .. message('sandbox-notice-blurb', {pagetype, templateLink})
| |
| end
| |
| -- Get the test cases page blurb if the page exists. This is something like
| |
| -- "See also the companion subpage for [[Template:Foo/testcases|test cases]]."
| |
| local testcasesTitle = env.testcasesTitle
| |
| if testcasesTitle and testcasesTitle.exists then
| |
| if testcasesTitle.contentModel == "Scribunto" then
| |
| local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
| |
| local testcasesRunLinkDisplay = message('sandbox-notice-testcases-run-link-display')
| |
| local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
| |
| local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay)
| |
| text = text .. '<br />' .. message('sandbox-notice-testcases-run-blurb', {testcasesLink, testcasesRunLink})
| |
| else
| |
| local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
| |
| local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
| |
| text = text .. '<br />' .. message('sandbox-notice-testcases-blurb', {testcasesLink})
| |
| end
| |
| end
| |
| -- Add the sandbox to the sandbox category.
| |
| omargs.text = text .. makeCategoryLink(message('sandbox-category'))
| |
|
| |
| -- 'documentation-clear'
| |
| return '<div class="' .. message('clear') .. '"></div>'
| |
| .. require('Module:Message box').main('ombox', omargs)
| |
| end
| |
|
| |
| function p.protectionTemplate(env)
| |
| -- Generates the padlock icon in the top right.
| |
| -- @env - environment table containing title objects, etc., generated with p.getEnvironment
| |
| -- Messages:
| |
| -- 'protection-template' --> 'pp-template'
| |
| -- 'protection-template-args' --> {docusage = 'yes'}
| |
| local protectionLevels = env.protectionLevels
| |
| if not protectionLevels then
| |
| return nil
| |
| end
| |
| local editProt = protectionLevels.edit and protectionLevels.edit[1]
| |
| local moveProt = protectionLevels.move and protectionLevels.move[1]
| |
| if editProt then
| |
| -- The page is edit-protected.
| |
| return require('Module:Protection banner')._main{
| |
| message('protection-reason-edit'), small = true
| |
| }
| |
| elseif moveProt and moveProt ~= 'autoconfirmed' then
| |
| -- The page is move-protected but not edit-protected. Exclude move
| |
| -- protection with the level "autoconfirmed", as this is equivalent to
| |
| -- no move protection at all.
| |
| return require('Module:Protection banner')._main{
| |
| action = 'move', small = true
| |
| }
| |
| else
| |
| return nil
| |
| end
| |
| end
| |
|
| |
|
| ---------------------------------------------------------------------------- | | ---------------------------------------------------------------------------- |
Line 488: |
Line 365: |
| -- 'history-link-display' --> 'history' | | -- 'history-link-display' --> 'history' |
| -- 'purge-link-display' --> 'purge' | | -- 'purge-link-display' --> 'purge' |
| -- 'file-docpage-preload' --> 'Template:Documentation/preload-filespace'
| |
| -- 'module-preload' --> 'Template:Documentation/preload-module-doc' | | -- 'module-preload' --> 'Template:Documentation/preload-module-doc' |
| -- 'docpage-preload' --> 'Template:Documentation/preload' | | -- 'docpage-preload' --> 'Template:Documentation/preload' |
Line 514: |
Line 390: |
| local preload = args.preload | | local preload = args.preload |
| if not preload then | | if not preload then |
| if subjectSpace == 6 then -- File namespace | | if subjectSpace == 828 then -- Module namespace |
| preload = message('file-docpage-preload')
| |
| elseif subjectSpace == 828 then -- Module namespace
| |
| preload = message('module-preload') | | preload = message('module-preload') |
| else | | else |
Line 630: |
Line 504: |
| :tag('span') | | :tag('span') |
| :addClass(data.headingClass) | | :addClass(data.headingClass) |
| | :attr('id', 'documentation-heading') |
| :cssText(data.headingStyleText) | | :cssText(data.headingStyleText) |
| :wikitext(data.heading) | | :wikitext(data.heading) |
Line 657: |
Line 532: |
| if not content and docTitle and docTitle.exists then | | if not content and docTitle and docTitle.exists then |
| content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText} | | content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText} |
| | end |
| | if mw.site.siteName == "Miraheze Developers Wiki" and args.noexportinstructions ~= "yes" then |
| | local export = mw.getCurrentFrame():expandTemplate{title="How to export"} |
| | content = export .. "<br/>" .. (content or '') |
| end | | end |
| -- The line breaks below are necessary so that "=== Headings ===" at the start and end | | -- The line breaks below are necessary so that "=== Headings ===" at the start and end |