|
|
(21 intermediate revisions by 15 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 177: |
Line 177: |
| -- env.sandboxTitle - the /sandbox subpage. | | -- env.sandboxTitle - the /sandbox subpage. |
| -- env.testcasesTitle - the /testcases subpage. | | -- env.testcasesTitle - the /testcases subpage. |
| -- env.printTitle - the print version of the template, located at the /Print subpage.
| |
| -- | | -- |
| -- 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 271: |
Line 269: |
| --]] | | --]] |
| return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage')) | | return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage')) |
| end
| |
|
| |
| function envFuncs.printTitle()
| |
| --[[
| |
| -- Title object for the /Print subpage.
| |
| -- Messages:
| |
| -- 'print-subpage' --> 'Print'
| |
| --]]
| |
| return env.templateTitle:subPageTitle(message('print-subpage'))
| |
| 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 332: |
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 498: |
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 524: |
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 539: |
Line 403: |
| function p.renderStartBoxLinks(data) | | function p.renderStartBoxLinks(data) |
| --[[ | | --[[ |
| -- Generates the [view][edit][history][purge] or [create] links from the data table. | | -- Generates the [view][edit][history][purge] or [create][purge] links from the data table. |
| -- @data - a table of data generated by p.makeStartBoxLinksData | | -- @data - a table of data generated by p.makeStartBoxLinksData |
| --]] | | --]] |
Line 553: |
Line 417: |
| local docTitle = data.docTitle | | local docTitle = data.docTitle |
| local title = data.title | | local title = data.title |
| | local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, data.purgeLinkDisplay) |
| if docTitle.exists then | | if docTitle.exists then |
| local viewLink = makeWikilink(docTitle.prefixedText, data.viewLinkDisplay) | | local viewLink = makeWikilink(docTitle.prefixedText, data.viewLinkDisplay) |
| local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay) | | local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay) |
| local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) | | local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) |
| local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, data.purgeLinkDisplay)
| |
| ret = '[%s] [%s] [%s] [%s]' | | ret = '[%s] [%s] [%s] [%s]' |
| ret = escapeBrackets(ret) | | ret = escapeBrackets(ret) |
Line 563: |
Line 427: |
| else | | else |
| local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) | | local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) |
| ret = '[%s]' | | ret = '[%s] [%s]' |
| ret = escapeBrackets(ret) | | ret = escapeBrackets(ret) |
| ret = mw.ustring.format(ret, createLink) | | ret = mw.ustring.format(ret, createLink, purgeLink) |
| end | | end |
| return ret | | return ret |
Line 640: |
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 667: |
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 |
Line 740: |
Line 609: |
| end | | end |
| text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') --"Subpages of this template" | | text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') --"Subpages of this template" |
| local printBlurb = p.makePrintBlurb(args, env) -- Two-line blurb about print versions of templates.
| |
| if printBlurb then
| |
| text = text .. '<br />' .. printBlurb
| |
| end
| |
| end | | end |
| end | | end |
Line 749: |
Line 614: |
| local box = mw.html.create('div') | | local box = mw.html.create('div') |
| -- 'documentation-metadata' | | -- 'documentation-metadata' |
| box:addClass(message('end-box-class')) | | box:attr('role', 'note') |
| | :addClass(message('end-box-class')) |
| -- 'plainlinks' | | -- 'plainlinks' |
| :addClass(message('end-box-plainlinks')) | | :addClass(message('end-box-plainlinks')) |
Line 959: |
Line 825: |
| ) | | ) |
| return message('subpages-blurb', {subpagesLink}) | | return message('subpages-blurb', {subpagesLink}) |
| end
| |
|
| |
| function p.makePrintBlurb(args, env)
| |
| --[=[
| |
| -- Generates the blurb displayed when there is a print version of the template available.
| |
| -- @args - a table of arguments passed by the user
| |
| -- @env - environment table containing title objects, etc., generated with p.getEnvironment
| |
| --
| |
| -- Messages:
| |
| -- 'print-link-display' --> '/Print'
| |
| -- 'print-blurb' --> 'A [[Help:Books/for experts#Improving the book layout|print version]]'
| |
| -- .. ' of this template exists at $1.'
| |
| -- .. ' If you make a change to this template, please update the print version as well.'
| |
| -- 'display-print-category' --> true
| |
| -- 'print-category' --> 'Templates with print versions'
| |
| --]=]
| |
| local printTitle = env.printTitle
| |
| if not printTitle then
| |
| return nil
| |
| end
| |
| local ret
| |
| if printTitle.exists then
| |
| local printLink = makeWikilink(printTitle.prefixedText, message('print-link-display'))
| |
| ret = message('print-blurb', {printLink})
| |
| local displayPrintCategory = message('display-print-category', nil, 'boolean')
| |
| if displayPrintCategory then
| |
| ret = ret .. makeCategoryLink(message('print-category'))
| |
| end
| |
| end
| |
| return ret
| |
| end | | end |
|
| |
|