Ouvrir le menu principal

Modifications

Module:Documentation

25 813 octets ajoutés, 13 avril 2019 à 19:40
m
1 révision importée
--Ce This module implémente le modèle implements {{Documentationdocumentation}}. -- Get required modules.local getArgs = require('Module:Arguments').getArgslocal messageBox = require('Module:Message box') -- Get the config table.local cfg = mw.loadData('Module:Documentation/config')
local p = {}
-- Often-used functions.local ugsub = mw.ustring.gsub ------------------------------------------------------------------------------ Helper functions---- These are defined as local functions, but are made available in the p-- table for testing purposes.---------------------------------------------------------------------------- local function message(cfgKey, valArray, expectType) --[[ -- Gets a message from the cfg table and formats it if appropriate. -- The function existePageraises an error if the value from the cfg table is not -- of the type expectType. The default type for expectType is 'string'. -- If the table valArray is present, strings such as $1, $2 etc. in the -- message are substituted with values from the table keys [1], [2] etc. -- For example, if the message "foo-message" had the value 'Foo $2 bar $1.', -- message('foo-message', {'baz', 'qux'}) would return "Foo qux bar baz." --]] local msg = cfg[cfgKey] expectType = expectType or 'string' if type(msg) ~= expectType then error('message: type error in message cfg.' .. cfgKey .. ' (page' .. expectType .. ' expected, got ' .. type(msg) .. ')', 2) end if not valArray then return page and pagemsg end  local function getMessageVal(match) match = tonumber(match) return valArray[match] or error('message: no value found for key $' .. match .. ' in message cfg.' ..existscfgKey, 4) end  local ret = ugsub(msg, '$([1-9][0-9]*)', getMessageVal) return ret
end
local function nomDocumentation(page) --On n'est pas dans une sous-page if not pagep.isSubpage then return page.subjectNsText .. ':' .. page.text .. '/Documentation' endmessage = message
--On est dans une sous-page local sousPage = function makeWikilink(page.subpageText, display) if sousPage == 'Documentation' or sousPage == 'Bac à sable' or sousPage == 'Test' display then return page.subjectNsText mw.ustring. format(':[[%s|%s]]' .. , page.baseText .. '/Documentation', display)
else
return page.subjectNsText mw.ustring. format(':[[%s]]' .. , page.text .. '/Documentation')
end
end
local function lienUrl(nomPage, titrePage, action, pagePreload) local argument p.makeWikilink = {['action'] = action or 'edit'}makeWikilink
local function makeCategoryLink(cat, sort) if pagePreload then argumentlocal catns = mw.site.namespaces['preload'14] = .name return makeWikilink(catns .. 'Modèle:Documentation/Preload' .. pagePreloadcat, sort) end p.makeCategoryLink = makeCategoryLink
local function makeUrlLink(url, display) return mw.ustring.format('[%s %s]', nomPage:fullUrl(argument)url, titrePagedisplay)
end
local function entete(args, page, doc, existeDoc) local res p.makeUrlLink = mw.html.create('div')makeUrlLink
local function makeToolbar(...) reslocal ret = {} :css local lim = select('margin-bottom#', '1ex'...) if lim < 1 then :css('border-bottom'return nil end for i = 1, '1px solid #aaa')lim do :cssret[#ret + 1] = select('padding-bottom'i, '3px') :wikitext('[[Fichier:Test Template Info-Icon.svg|50px|alt=|link=]]'..) :tag('span') end :css( return '<small style="font-weight', 'bold') style:cssnormal;">('font-size', '125%') :css.. table.concat('vertical-align'ret, 'middle') :wikitext('&nbsp#124;') :wikitext(args.titre or . 'Documentation)</small>') :done()end  p.makeToolbar = makeToolbar
if not args.contenu then---------------------------------------------------------------------------- local editionLien = res:tag('span')-- Argument processing :addClass('mw-editsection plainlinks') :css('vertical-align', 'middle') :wikitext('&#91;')--------------------------------------------------------------------------
local function makeInvokeFunc(funcName) return function (frame) if existeDoc thenlocal args = getArgs(frame, { editionLien:wikitext(lienUrlvalueFunc = function (dockey, 'modifier')value) else if args.module type(value) == 'string' then editionLien value = value:wikitextmatch(lienUrl'^%s*(doc, .-)%s*$'créer) -- Remove whitespace. if key == ', heading'editor value ~= ', 'Module'))then return value else return nil end else return value editionLien:wikitext(lienUrl(doc, 'créer', 'edit', ''))end
end
}) return p[funcName](args) endend ------------------------------------------------------------------------------ Main function----------------------------------------------------------------------------
editionLien :wikitextp.main = makeInvokeFunc('&#93;&#32;&#91;_main') :wikitext(lienUrl(page, 'purger', 'purge')) :wikitext('&#93;') end
function p._main(args) --[[ -- This function defines logic flow for the module. -- @args - table of arguments passed by the user -- -- Messages: -- 'main-div-id' --> 'template-documentation' -- 'main-div-classes' --> 'template-documentation iezoomfix' --]] local env = p.getEnvironment(args) local root = mw.html.create() root :wikitext(p.protectionTemplate(env)) :wikitext(p.sandboxNotice(args, env)) -- This div tag is from {{documentation/start box}}, but moving it here -- so that we don't have to worry about unclosed tags. :tag('div') :attr('id', message('main-div-id')) :addClass(message('main-div-classes')) :newline() :wikitext(p._startBox(args, env)) :wikitext(p._content(args, env)) :tag('div') :css('clear', 'both') -- So right or left floating items don't stick out of the doc box. :newline() :done() :done() :wikitext(p._endBox(args, env)) :wikitext(p.addTrackingCategories(env)) return restostring(root)
end
local function protection(page, doc, existeDoc, message)---------------------------------------------------------------------------- -- Insertion automatique du modèle de protection.Environment settings local niveauProtection = page.protectionLevels.edit----------------------------------------------------------------------------
function p.getEnvironment(args) --[[ if niveauProtection -- Returns a table with information about the environment, including title objects and niveauProtection[1] thenother namespace- or -- path-related data. -- @args - table of arguments passed by the user -- -- Title objects include: local tableProtection = { -- env.title - the page we are making documentation for (usually the current title) autoconfirmed = {'semiProtection' -- env.templateTitle - the template (or module, file, '{{%s*[Ss]emi%etc.) -- env.docTitle - the /doc subpage. -- env.sandboxTitle - the /sandbox subpage. -- env.testcasesTitle - the /testcases subpage. -- env.printTitle -protection%s*[|}]'the print version of the template, '{{%s*[Ss]emi%located at the /Print subpage. -- -- Data includes: -- env.protectionLevels -the protection +longue%s*[|}]'},levels table of the title object. editextendedsemiprotected = {'semiProtectionEtendue', -- env.subjectSpace - the number of the title'{{%s*[Ss]emi%subject namespace. -- env.docSpace - the number of the namespace the title puts its documentation in. -- env.docpageBase -protection +étendue%s*[|}]'}the text of the base page of the /doc, /sandbox and /testcases pages,with namespace. -- env.compareUrl - URL of the Special:ComparePages page comparing the sandbox with the template. -- sysop = {'protection' -- All table lookups are passed through pcall so that errors are caught. If an error occurs, '{{%s*[Ppthe value -- returned will be nil. --]rotection%s*[|}]'}, } local protection env, envFuncs = tableProtection[niveauProtection[1]] if not protection then return '' end{}, {}
local alreadyShown = false if existeDoc then -- Set up the metatable. If triggered we call the corresponding function in the envFuncs table. The value -- Vérification qureturned by that function is memoized in the env table so that we don'il n'y a pas déjà un modèle det call any of the functions -- protection dans la documentation du modèlemore than once.(Nils won't be memoized.) setmetatable(env, { __index = function (t, key) local contenuDoc envFunc = doc:getContent()envFuncs[key] if contenuDoc:matchenvFunc then local success, val = pcall(protection[2]envFunc) or (protection if success then env[3key] and contenuDoc:match(protection[3])) then= val -- Memoise the value. return val alreadyShown = trueend
end
return nil
end
})
function envFuncs.title() -- The title object for the current page, or a test page passed with args.page. local title local titleArg = args.page if not alreadyShown titleArg then if message title == '' thenmw.title.new(titleArg) message = nil else end return require('Module:Protection')title = mw.title.maingetCurrentTitle({message}, protection[1], page)
end
return title
end
end
function envFuncs.templateTitle() -- pour les bacs à sable[[ -- The template (or module, on retire les balises de catégoriesetc.) title object. -- habituellement situées en "includeonly" à la fin de la documentationMessages: -- 'sandbox-subpage' --> 'sandbox' -- 'testcases-subpage' --> 'testcases' --]] local function retireBalisesCategories(contenuDoc)subjectSpace = env.subjectSpace local counttitle = env.title repeat local subpage = title.subpageText contenuDoc, count if subpage == message('sandbox-subpage') or subpage == message('testcases-subpage') then return mw.ustringtitle.gsubmakeTitle(contenuDocsubjectSpace, '%[%[Catégorie:[^%]]+%]%][\t\r\n\f ]*$'title.baseText) else return mw.title.makeTitle(subjectSpace, ''title.text) end until count == 0end
contenuDoc, count function envFuncs.docTitle() --[[ -- Title object of the /doc subpage. -- Messages: -- 'doc-subpage' --> 'doc' --]] local title = env.title local docname = args[1] -- User-specified doc page. local docpage if docname then docpage = docname else docpage = env.docpageBase .. '/' .. message('doc-subpage') end return mw.ustringtitle.gsubnew(contenuDoc, docpage) end function envFuncs.sandboxTitle() --[[ -- Title object for the /sandbox subpage. -- Messages: -- 'sandbox-subpage' --> 'sandbox' --]] return mw.title.new(env.docpageBase .. '/' .. message('sandbox-subpage')) end function envFuncs.testcasesTitle() --[\t\r\n\f [ -- Title object for the /testcases subpage. -- Messages: -- 'testcases-subpage' --> 'testcases' --]*$] 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
function envFuncs.protectionLevels() -- The protection levels table of the title object. return contenuDocenv.title.protectionLevels end
local function contenuenvFuncs.subjectSpace(args, doc, existeDoc) local page = -- The subject namespace number. return mw.site.namespaces[env.title.getCurrentTitle()namespace].subject.id local res = mw.html.create():newline()end
if existeDoc thenfunction envFuncs.docSpace() -- The documentation namespace number. For most namespaces this is the same as the -- subject namespace. However, pages in the Article, File, MediaWiki or Category -- namespaces must have their /doc, /sandbox and /testcases pages in talk space. local subjectSpace = env.subjectSpace if args.contenu subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then res :wikitext(args.contenu)return subjectSpace + 1 :newline() else :newline() return subjectSpace
end
end
local frame = mw function envFuncs.getCurrentFramedocpageBase() if frame.args -- The base page of the /doc, /sandbox, and frame/testcases subpages.args['contenu sous --For some namespaces this is the talk page'] then, rather than the template page. local templateTitle = env.templateTitle local docSpace = env.docSpace local contenuDoc docSpaceText = framemw.argssite.namespaces[docSpace].name -- Assemble the link. docSpace is never the main namespace, so we can hardcode the colon. return docSpaceText .. 'contenu sous:' .. templateTitle.text end function envFuncs.compareUrl() -page'- Diff link between the sandbox and the main template using [[Special:ComparePages]]. local templateTitle = env.templateTitle local sandboxTitle = env.sandboxTitle if pagetemplateTitle.exists and sandboxTitle.subpageText exists then local compareUrl == 'Bac à sable' or pagemw.uri.subpageText == fullUrl( 'TestSpecial:ComparePages' then, contenuDoc {page1 = retireBalisesCategories(contenuDoc)templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} end) res:wikitextreturn tostring(contenuDoccompareUrl)
else
local contenuDoc = frame:expandTemplate{title = doc.prefixedText} if page.subpageText == 'Bac à sable' or page.subpageText == 'Test' then contenuDoc = retireBalisesCategories(contenuDoc) end res:wikitext(contenuDoc)return nil
end
end
if args['complément'] then return env res :newline() :newline() :wikitext(args['complément']) end
elseif args.contenu then---------------------------------------------------------------------------- res:wikitext(args.contenu)-- Auxiliary templates----------------------------------------------------------------------------
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 elseif page-- -- Messages: -- 'sandbox-notice-image' --> '[[Image:Sandbox.subpageText ~svg|50px|alt=|link= ]]' -- 'Bac à sablesandbox-notice-blurb' and page--> 'This is the $1 for $2.' -- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).subpageText ~= 'Test -- 'sandbox-notice-pagetype-template' --> '[[Wikipedia:Template test cases|template sandbox]] page' then local texteBandeau = -- 'sandbox-notice-pagetype-module'<b-->Ce %s ne possède aucune '[[AideWikipedia:Documentation de modèleTemplate test cases|documentationmodule sandbox]] page' .. -- 'sandbox-notice-pagetype-other'explicative en sous--> 'sandbox page</b' -- 'sandbox-notice-compare-link-display' --> 'diff' -- 'sandbox-notice-testcases-blurb' -->, pas même une description succincte'See also the companion subpage for $1.<br' -- 'sandbox-notice-testcases-link-display' --> 'test cases' -- 'sandbox-category' --> 'Template sandboxes' --]=] local title = env.title local sandboxTitle = env.sandboxTitle local templateTitle = env.'Vous pouvez %s afin de documenter ce %s adéquatementtemplateTitle local subjectSpace = env.'subjectSpace if argsnot (subjectSpace and title and sandboxTitle and templateTitle and mw.title.module equals(title, sandboxTitle)) then texteBandeau = texteBandeau:format( return nil end 'module' -- Build the table of arguments to pass to {{ombox}}. We need just two fields,"image" and "text". lienUrl local omargs = {} omargs.image = message(doc, 'créer cette soussandbox-notice-pageimage') -- Get the text. We start with the opening blurb, which is something like -- "This is the template sandbox for [[Template:Foo]] (diff)." local text = 'edit', local pagetype if subjectSpace == 10 then pagetype = message('Modulesandbox-notice-pagetype-template'), elseif subjectSpace == 828 then pagetype = message('sandbox-notice-pagetype-module') else pagetype = message('sandbox-notice-pagetype-other') if page end local templateLink = makeWikilink(templateTitle.baseText prefixedText) local compareUrl =env.compareUrl if compareUrl then local compareDisplay = message('Country datasandbox-notice-compare-link-display' or page) local compareLink = makeUrlLink(compareUrl, compareDisplay) text = text ..text:submessage(1'sandbox-notice-diff-blurb', {pagetype, templateLink, 12compareLink}) else text == text .. message('Utilisateur:sandbox-notice-blurb' then, {pagetype, templateLink}) end --Get the test cases page blurb if the page exists. This is something like - pas de catégorisation pour : modèles de données, pseudo-namespace "ModuleSee also the companion subpage for [[Template:Utilisateur:TotoFoo/Nom du moduletestcases|test cases]]." local testcasesTitle = env.testcasesTitle if testcasesTitle and testcasesTitle.exists then if testcasesTitle.contentModel == "Scribunto"then elselocal 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) texteBandeau text = texteBandeau text .. '<br />' .. message('[[Catégorie:Module sans documentation]]sandbox-notice-testcases-run-blurb' end, {testcasesLink, testcasesRunLink})
else
texteBandeau local testcasesLinkDisplay = texteBandeau:formatmessage( 'modèle', lienUrl(doc, 'créer cette soussandbox-notice-testcases-link-page', 'edit', 'display'), 'modèle' local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay) texteBandeau text = texteBandeau text .. '[[Catégorie:Modèle sans documentation]]<br />'.. message('sandbox-notice-testcases-blurb', {testcasesLink})
end
local param = {
['icône'] = 'Book-cover-A-Z.svg',
alt = 'domaine public',
style = 'width:80%;',
texte = texteBandeau,
}
res:wikitext(require('Module:Bandeau')._bandeau(param))
end
-- Add the sandbox to the sandbox category.
text = text .. makeCategoryLink(message('sandbox-category'))
omargs.text = text
local ret = '<div style="clear: both;"></div>'
ret = ret .. messageBox.main('ombox', omargs)
return ret
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'} reslocal protectionLevels, mProtectionBanner local title = env.title 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. mProtectionBanner = require('Module:newline(Protection banner') :taglocal reason = message('divprotection-reason-edit') :css( return mProtectionBanner._main{reason, small = true} elseif moveProt and moveProt ~= 'clearautoconfirmed'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. mProtectionBanner = require('bothModule:Protection banner') return mProtectionBanner._main{action = 'move', small = true} else return resnil end
end
local function notice(args, page, doc, existeDoc)---------------------------------------------------------------------------- local res = mw.html.create('div')-- Start box :css('border-top', '1px solid #aaa') :css('margin', '1.5em 0 0')---------------------------------------------------------------------------
local contenuParagraphe p.startBox = res :tag('p') :addClass('plainlinks') :css('margin-bottom', '0') :css('padding-left', '1em') :cssmakeInvokeFunc('font-style', 'italic_startBox')
function p._startBox(args, env) --[[ if args-- This function generates the start box.contenu then if -- @args.notice then- a table of arguments passed by the user contenuParagraphe:wikitext(args.notice -- @env - environment table containing title objects, etc., generated with p. '<br />')getEnvironment else -- contenuParagraphe -- The actual work is done by p.makeStartBoxLinksData and p.renderStartBoxLinks which make :wikitext('La -- the [view] [Aide:Documentation de modèle|documentationedit][history] ') :wikitext('de ce [[Aide:Modèle|modèlepurge]] est directement ')links, and by p.makeStartBoxData and p.renderStartBox -- which generate the box HTML. :wikitext('[[Aide:Inclusion|incluse --]] dans le corps de ce dernier env = env or p. 'getEnvironment(args) :wikitext(lienUrl(page, 'Cliquez ici pour purger le cache', 'purge')) local links :wikitext(' local content = args.<br /> Si cette page est protégée, veuillez ')content if not content then :wikitext('transférer le contenu de la -- No need to include the links if the documentation vers sa ')is on the template page itself. :wikitext local linksData = p.makeStartBoxLinksData(lienUrl(doc, 'sous-page dédiée', 'edit'args, '')env) :wikitext if linksData then links = p.renderStartBoxLinks('.<br /> 'linksData)
end
end
-- Generate the start box html.
local data = p.makeStartBoxData(args, env, links)
if data then
return p.renderStartBox(data)
else
if existeDoc then local lienAide = '[[Aide:Modèle|modèle]]' if args-- User specified no heading.module then lienAide = '[[Aide:Module|module]]' return nil end contenuParagrapheend :wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ') :wikitextfunction p.makeStartBoxLinksData(lienAideargs, env) :wikitext(' est --[[ -- Does initial processing of data to make the [Aide:Inclusion|incluseview][edit] depuis sa [history] [')purge] links. -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- -- Messages:wikitext(tostring(doc)) :wikitext( -- 'view-link-display' --> 'view' -- 'edit-link-display'|sous-page de documentation]]&nbsp;-> 'edit') :tag( -- 'history-link-display'span--> 'history') :css( -- 'fontpurge-sizelink-display', --> '89%purge') -- 'file-docpage-preload' --> 'Template:css(Documentation/preload-filespace' -- 'fontmodule-stylepreload', --> 'normalTemplate:Documentation/preload-module-doc') -- 'docpage-preload' --> 'Template:wikitext(Documentation/preload' -- 'create-link-display' --> '(create') :wikitext --]] local subjectSpace = env.subjectSpace local title = env.title local docTitle = env.docTitle if not title or not docTitle then return nil end if docTitle.isRedirect then docTitle = docTitle.redirectTarget end  local data = {} data.title = title data.docTitle = docTitle -- View, display, edit, and purge links if /doc exists. data.viewLinkDisplay = message(lienUrl(doc, 'modifierview-link-display')) :wikitext data.editLinkDisplay = message('&nbsp;|&nbsp;edit-link-display') :wikitext data.historyLinkDisplay = message(lienUrl(doc, 'historique', 'history-link-display')) :wikitext data.purgeLinkDisplay = message('purge-link-display').<br -- Create link if /> doc doesn')t exist. local preload = args.preload if not preload then :done() if subjectSpace == 6 then -- File namespace :wikitext preload = message('Veuillez placer les catégories dans la sousfile-page docpage-preload') :wikitext(lienUrl elseif subjectSpace == 828 then -- Module namespace preload = message(doc, '/Documentationmodule-preload')) :wikitext else preload = message('.<br /> docpage-preload')
end
end
data.preload = preload
data.createLinkDisplay = message('create-link-display')
return data
end
function p.renderStartBoxLinks(data) --[[ -- Generates the [view][edit][history][purge] or [create] links from the data table. -- @data - a table of data generated by p.makeStartBoxLinksData --]] contenuParagraphe local function escapeBrackets(s) -- Escapes square brackets with HTML entities. s = s:wikitextgsub('Les éditeurs peuvent travailler dans le %[', '&#91;')-- Replace square brackets with HTML entities. s = s:gsub('%]', '&#93;') return s end
local titrePageBacasable ret local docTitle = data.docTitle local title = data.title if docTitle.exists then local viewLink = nomDocumentationmakeWikilink(pagedocTitle.prefixedText, data.viewLinkDisplay) local editLink = makeUrlLink(docTitle:gsubfullUrl{action = 'edit'}, data.editLinkDisplay) local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) local purgeLink = makeUrlLink(title:fullUrl{action = '/Documentationpurge'}, data.purgeLinkDisplay) ret = '/Bac à sable[%s] [%s] [%s] [%s]' ret = escapeBrackets(ret) ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink) else local pageBacasable createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) ret = '[%s]' ret = escapeBrackets(ret) ret = mw.titleustring.newformat(titrePageBacasableret, createLink) end return retend
function p.makeStartBoxData(args, env, links) --[=[ -- Does initial processing of data to pass to the start-box render function, p.renderStartBox. -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- @links - a string containing the [view][edit][history][purge] links - could be nil if existePage(pageBacasable) thenthere's an error. contenuParagraphe -- -- Messages: -- 'documentation-icon-wikitext(' --> '[[' File:Test Template Info-Icon - Version (2).. titrePageBacasable .. 'svg|50px|link=|bac à sablealt=]]&nbsp;') :tag( -- 'template-namespace-heading' --> 'Template documentation' -- 'module-namespace-heading' --> 'Module documentation' -- 'file-namespace-heading' --> 'Summary' -- 'other-namespaces-heading' --> 'Documentation' -- 'start-box-linkclasses' --> 'mw-editsection-like plainlinks' -- 'start-box-link-id' --> 'spandoc_editlinks') :css( -- 'testcases-create-link-display'font-size-> 'create' --]=] local subjectSpace = env.subjectSpace if not subjectSpace then -- Default to an "other namespaces" namespace, so that we get at least some output -- if an error occurs. subjectSpace = 2 end local data = {} -- Heading local heading = args.heading -- Blank values are not removed. if heading == '89%')then -- Don't display the start box if the heading arg is defined but blank. return nil end if heading then data.heading = heading elseif subjectSpace == 10 then -- Template namespace :css data.heading = message('fontdocumentation-styleicon-wikitext') .. ' ', .. message('normaltemplate-namespace-heading') : elseif subjectSpace == 828 then -- Module namespace data.heading = message('documentation-icon-wikitext') .. ' ' .. message('(module-namespace-heading') :wikitext elseif subjectSpace == 6 then -- File namespace data.heading = message(lienUrl(pageBacasable, 'modifierfile-namespace-heading')) :wikitext else data.heading = message('other-namespaces-heading') end -- Heading CSS local headingStyle = args['heading-style'] if headingStyle then data.headingStyleText = headingStyle elseif subjectSpace == 10 then -- We are in the template or template talk namespaces. data.headingFontWeight = 'bold' data.headingFontSize = '125%')
else
local preLoad data.headingFontSize = '2150%' end -- Data for the [view][edit][history][purge] or [create] links. if links then if argsdata.module thenlinksClass = message('start-box-linkclasses') preLoad data.linksId = nilmessage('start-box-link-id') data.links = links end return dataend contenuParagraphe :wikitextfunction p.renderStartBox(data) -- Renders the start box html. -- @data - a table of data generated by p.makeStartBoxData. local sbox = mw.html.create('bac à sable&nbsp;div') sbox :tagcss('spanpadding-bottom', '3px') :css('fontborder-sizebottom', '89%1px solid #aaa') :css('fontmargin-stylebottom', 'normal1ex') :newline() :wikitexttag('(span') :wikitextcssText(lienUrldata.headingStyleText) :css(pageBacasable, 'créerfont-weight', data.headingFontWeight) :css('editfont-size', preLoaddata.headingFontSize) :wikitext(data.heading) local links = data.links if links then sbox:wikitexttag('span') :addClass(data.linksClass) :attr('id', data.linksId) :wikitext(links)
end
return tostring(sbox)
end
if not args.module then---------------------------------------------------------------------------- contenuParagraphe:wikitext(' et la page de ')-- Documentation content----------------------------------------------------------------------------
local titrePageTest p.content = nomDocumentation(page):gsubmakeInvokeFunc('/Documentation', '/Test_content') local pageTest = mw.title.new(titrePageTest)
if existePagefunction p._content(pageTestargs, env) then contenuParagraphe -- Displays the documentation contents :wikitext('[[' .. titrePageTest .. '|test]]&nbsp;') -- @args - a table of arguments passed by the user :tag('span') :css('font --size', '89%') :css('font@env -style'environment table containing title objects, 'normal') :wikitext('(') :wikitext(lienUrl(pageTestetc., 'modifier'))generated with p.getEnvironment :wikitext(')') else contenuParagraphe :wikitext env = env or p.getEnvironment('test&nbsp;'args) :tag('span') local docTitle = env.docTitle :css('font-size', '89%') local content = args.content :css('font-style', 'normal') if not content and docTitle and docTitle.exists then :wikitext(' content = args._content or mw.getCurrentFrame(') :wikitext(lienUrl(pageTest, 'créer', 'edit', '3')) :wikitext(')') endexpandTemplate{title = docTitle.prefixedText}
end
contenuParagraphe:wikitext-- The line breaks below are necessary so that "=== Headings ===" at the start and end -- of docs are interpreted correctly. return '\n' .. (content or '') ..')\n' end
p.contentTitle = makeInvokeFunc('_contentTitle') function p._contentTitle(args, env) env = env or p.getEnvironment(args) local docTitle = env.docTitle if not args.content and docTitle and docTitle.exists then return resdocTitle.prefixedText else return '' end
end
function p._documentation(args)------------------------------------------------------------------------------ End box local page = mw.title.getCurrentTitle()---------------------------------------------------------------------------- local titreDoc = nomDocumentation(page) local doc = mwp.title.new(args[1] or titreDoc) local existeDoc endBox = existePage(doc) local res = mw.html.createmakeInvokeFunc('_endBox')
function p._endBox(args, env) --Bandeau pour les sous[=[ --pages /Bac à sableThis function generates the end box (also known as the link box). if page-- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.subpageText == 'Bac à sable' thengetEnvironment res -- -- Messages:tag( -- 'fmbox-id' --> 'divdocumentation-meta-data') -- 'fmbox-style' --> 'background-color:css(#ecfcf4' -- 'clearfmbox-textstyle', --> 'bothfont-style: italic') -- -- The HTML is generated by the {{fmbox}} template, courtesy of [[Module:doneMessage box]]. --]=] -- Get environment data. env = env or p.getEnvironment(args) :wikitext(mw local subjectSpace = env.subjectSpace local docTitle = env.docTitle if not subjectSpace or not docTitle then return nil end -- Check whether we should output the end box at all. Add the end -- box by default if the documentation exists or if we are in the -- user, module or template namespaces.getCurrentFrame():expandTemplate{title local linkBox = args['link box'] if linkBox == 'Sous-page de bac à sableoff'} or not ( docTitle.exists or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 ) then return nil
end
--Génération de la documentationAssemble the arguments for {{fmbox}}. reslocal fmargs = {} :tag fmargs.id = message('divfmbox-id') :css(-- Sets 'clear', 'bothdocumentation-meta-data') :css('margin fmargs.image = ', none'1em 0 0 0') :css fmargs.style = message('border', '1px solid #aaafmbox-style') :css(-- Sets 'background', args.couleur or '-color: #ecfcf4') :css fmargs.textstyle = message('paddingfmbox-textstyle', '1em 1em 0.8em) -- ') :node(entete(args, page, doc, existeDoc)) font-style:wikitext(protection(page, doc, existeDoc, args[italic;'message protection'])) :node(contenu(args, doc, existeDoc)) :node(notice(args, page, doc, existeDoc))
--Catégorisation des modules, en rangeant à part les modules de donnéesAssemble the fmbox text field. local text = '' if linkBox then text = text .. linkBox else text = text .. (p.makeDocPageBlurb(args, env) or '') -- "This documentation is transcluded from [[Foo]]." if subjectSpace == 2 or subjectSpace == 10 or subjectSpace == 828 then -- We are in the user, template or module namespaces. -- Add sandbox and testcases links. -- "Editors can experiment in this template's sandbox and pagetestcases pages.subpageText ~" text = text .. (p.makeExperimentBlurb(args, env) or 'Bac à sable' and page) text = text ..subpageText ~= 'Test<br />' then if pagenot args.isSubpage content and not args[1] then -- "Please add categories to the /doc subpage." -- Don't show this message with inline docs or with an explicitly specified doc page, -- as then it is unclear where to add the categories.baseText = text = text .. (p.makeCategoriesBlurb(args, env) or 'Country data' then) end res:wikitext("[[Catégorie:Module d'informations pays|" text = text .. page' ' .subpageText .(p. makeSubpagesBlurb(args, env) or '') --"]]Subpages of this template" local printBlurb = p.makePrintBlurb(args, env)-- Two-line blurb about print versions of templates. else if printBlurb then text = text .. '<br />' .. printBlurb res:wikitext("[[Catégorie:Module en langage Lua]]")end
end
end
fmargs.text = text
return tostringmessageBox.main(res'fmbox', fmargs)
end
function p.makeDocPageBlurb(args, env) --[=[ -- Makes the blurb "This documentationis transcluded from [[Template:Foo]] (frameedit, history)". -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- -- Messages: -- 'edit-link-display' --> 'edit' -- 'history-link-display' --> 'history' -- 'transcluded-from-blurb' --> -- 'The above [[Wikipedia:Template documentation|documentation]] -- is [[Wikipedia:Transclusion|transcluded]] from $1.' -- 'module-preload' --> 'Template:Documentation/preload-module-doc' -- 'create-link-display' --> 'create' -- 'create-module-doc-blurb' --> -- 'You might want to $1 a documentation page for this [[Wikipedia:Lua|Scribunto module]].' --]=] local docTitle = env.docTitle if not docTitle then return nil end local ret if docTitle.exists then -- /doc exists; link to it. local docLink = makeWikilink(docTitle.prefixedText) local editUrl = docTitle:fullUrl{action = 'edit'} local editDisplay = message('edit-link-display') local editLink = makeUrlLink(editUrl, editDisplay) local args historyUrl = docTitle:fullUrl{action = 'history'} local historyDisplay = message('history-link-display') local historyLink = makeUrlLink(historyUrl, historyDisplay) ret = message('transcluded-from-blurb', {docLink}) .. ' ' .. makeToolbar(editLink, historyLink) .. '<br />' elseif env.subjectSpace == 828 then -- /doc does not exist; ask to create it. local argsParent createUrl = framedocTitle:getParentfullUrl{action = 'edit', preload = message('module-preload')} local createDisplay = message('create-link-display') local createLink = makeUrlLink(createUrl, createDisplay) ret = message('create-module-doc-blurb', {createLink}) .args. '<br />' end return retend
function p.makeExperimentBlurb(args, env) --[[ -- Renders the text "Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages." --Paramètres vides interprétés par Lua@args - a table of arguments passed by the user for cle-- @env - environment table containing title objects, val etc., generated with p.getEnvironment -- -- Messages: -- 'sandbox-link-display' --> 'sandbox' -- 'sandbox-edit-link-display' --> 'edit' -- 'compare-link-display' --> 'diff' -- 'module-sandbox-preload' --> 'Template:Documentation/preload-module-sandbox' -- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox' -- 'sandbox-create-link-display' --> 'create' -- 'mirror-edit-summary' --> 'Create sandbox version of $1' -- 'mirror-link-display' --> 'mirror' -- 'mirror-link-preload' --> 'Template:Documentation/mirror' -- 'sandbox-link-display' --> 'sandbox' -- 'testcases-link-display' --> 'testcases' -- 'testcases-edit-link-display'--> 'edit' -- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox' -- 'testcases-create-link-display' --> 'create' -- 'testcases-link-display' --> 'testcases' -- 'testcases-edit-link-display' --> 'edit' -- 'module-testcases-preload' --> 'Template:Documentation/preload-module-testcases' -- 'template-testcases-preload' --> 'Template:Documentation/preload-testcases' -- 'experiment-blurb-module' --> 'Editors can experiment in pairsthis module's $1 and $2 pages.' -- 'experiment-blurb-template' --> 'Editors can experiment in this template's $1 and $2 pages.' --]] local subjectSpace = env.subjectSpace local templateTitle = env.templateTitle local sandboxTitle = env.sandboxTitle local testcasesTitle = env.testcasesTitle local templatePage = templateTitle.prefixedText if not subjectSpace or not templateTitle or not sandboxTitle or not testcasesTitle then return nil end -- Make links. local sandboxLinks, testcasesLinks if sandboxTitle.exists then local sandboxPage = sandboxTitle.prefixedText local sandboxDisplay = message(argsParent'sandbox-link-display') local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay) local sandboxEditUrl = sandboxTitle:fullUrl{action = 'edit'} local sandboxEditDisplay = message('sandbox-edit-link-display') local sandboxEditLink = makeUrlLink(sandboxEditUrl, sandboxEditDisplay) do local compareUrl = env.compareUrl local compareLink if val ~compareUrl then local compareDisplay = message('compare-link-display' then) args[cle] compareLink = mw.text.trimmakeUrlLink(valcompareUrl, compareDisplay)
end
sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
local sandboxPreload
if subjectSpace == 828 then
sandboxPreload = message('module-sandbox-preload')
else
sandboxPreload = message('template-sandbox-preload')
end
local sandboxCreateUrl = sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}
local sandboxCreateDisplay = message('sandbox-create-link-display')
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay)
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)})
local mirrorPreload = message('mirror-link-preload')
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary}
if subjectSpace == 828 then
mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templateTitle.prefixedText, summary = mirrorSummary}
end
local mirrorDisplay = message('mirror-link-display')
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)
sandboxLinks = message('sandbox-link-display') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
if testcasesTitle.exists then
local testcasesPage = testcasesTitle.prefixedText
local testcasesDisplay = message('testcases-link-display')
local testcasesLink = makeWikilink(testcasesPage, testcasesDisplay)
local testcasesEditUrl = testcasesTitle:fullUrl{action = 'edit'}
local testcasesEditDisplay = message('testcases-edit-link-display')
local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay)
-- for Modules, add testcases run link if exists
if testcasesTitle.contentModel == "Scribunto" and testcasesTitle.talkPageTitle and testcasesTitle.talkPageTitle.exists then
local testcasesRunLinkDisplay = message('testcases-run-link-display')
local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay)
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink, testcasesRunLink)
else
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
end
else
local testcasesPreload
if subjectSpace == 828 then
testcasesPreload = message('module-testcases-preload')
else
testcasesPreload = message('template-testcases-preload')
end
local testcasesCreateUrl = testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload}
local testcasesCreateDisplay = message('testcases-create-link-display')
local testcasesCreateLink = makeUrlLink(testcasesCreateUrl, testcasesCreateDisplay)
testcasesLinks = message('testcases-link-display') .. ' ' .. makeToolbar(testcasesCreateLink)
end
local messageName
if subjectSpace == 828 then
messageName = 'experiment-blurb-module'
else
messageName = 'experiment-blurb-template'
end
return message(messageName, {sandboxLinks, testcasesLinks})
end
function p.makeCategoriesBlurb(args, env) --[[ -- Generates the text "Please add categories to the /doc subpage." -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- Messages: -- 'doc-link-display' --> '/doc' -- 'add-categories-blurb' --> 'Please add categories to the $1 subpage.' --]] local docTitle = env.docTitle if not docTitle then return pnil end local docPathLink = makeWikilink(docTitle._documentationprefixedText, message(args'doc-link-display')) return message('add-categories-blurb', {docPathLink})
end
function p.nomDocumentationmakeSubpagesBlurb(frameargs, env) if frame--[[ -- Generates the "Subpages of this template" link. -- @args[- a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- Messages: -- 'template-pagetype' --> 'template' -- 'module-pagetype' --> 'module' -- 'default-pagetype' --> 'page' -- 'subpages-link-display' --> 'Subpages of this $1' --] and mw] local subjectSpace = env.textsubjectSpace local templateTitle = env.trimtemplateTitle if not subjectSpace or not templateTitle then return nil end local pagetype if subjectSpace == 10 then pagetype = message(frame.args[1]'template-pagetype') ~ elseif subjectSpace == '' 828 then return frame.args[1]pagetype = message('module-pagetype')
else
pagetype = message('default-pagetype') end local titreDoc subpagesLink = nomDocumentationmakeWikilink(mw 'Special:PrefixIndex/' .. templateTitle.prefixedText .title.getCurrentTitle'/', message('subpages-link-display', {pagetype}) ) 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 mwprintTitle.titleexists then local printLink = makeWikilink(printTitle.newprefixedText, message(titreDoc'print-link-display').exists ) ret = message('print-blurb', {printLink}) local displayPrintCategory = message('display-print-category', nil, 'boolean') if displayPrintCategory then return titreDocret = ret .. makeCategoryLink(message('print-category'))
end
end
return ret
end
 
----------------------------------------------------------------------------
-- Tracking categories
----------------------------------------------------------------------------
 
function p.addTrackingCategories(env)
--[[
-- Check if {{documentation}} is transcluded on a /doc or /testcases page.
-- @env - environment table containing title objects, etc., generated with p.getEnvironment
-- Messages:
-- 'display-strange-usage-category' --> true
-- 'doc-subpage' --> 'doc'
-- 'testcases-subpage' --> 'testcases'
-- 'strange-usage-category' --> 'Wikipedia pages with strange ((documentation)) usage'
--
-- /testcases pages in the module namespace are not categorised, as they may have
-- {{documentation}} transcluded automatically.
--]]
local title = env.title
local subjectSpace = env.subjectSpace
if not title or not subjectSpace then
return nil
end
local subpage = title.subpageText
local ret = ''
if message('display-strange-usage-category', nil, 'boolean')
and (
subpage == message('doc-subpage')
or subjectSpace ~= 828 and subpage == message('testcases-subpage')
)
then
ret = ret .. makeCategoryLink(message('strange-usage-category'))
end
return ret
end
return p