Ouvrir le menu principal

Modifications

Module:Documentation

24 674 octets ajoutés, 11 octobre 2019 à 02:23
m
1 révision importée
--Ce This module implémente le modèle implements {{Documentationdocumentation}}.
-- Get required modules.
local getArgs = require('Module:Arguments').getArgs
local messageBox = require('Module:Message box')
 
-- Get the config table.
local cfg = mw.loadData('Module:Documentation/config')
local i18n = mw.loadData('Module:Documentation/i18n')
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 existePagemessage(cfgKey, valArray, expectType) --[[ -- Gets a message from the cfg table and formats it if appropriate. -- The function raises 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(pagemsg) ~= expectType then error(require('Module:TNT').format('I18n/Documentation', 'cfg-error-msg-type', cfgKey, expectType, type(msg)), 2) end if not valArray then return msg end  local function getMessageVal(match) match = tonumber(match) return page and pagevalArray[match] or error(require('Module:TNT').format('I18n/Documentation', 'cfg-error-msg-empty', '$' ..existsmatch, cfgKey), 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
p.makeUrlLink = makeUrlLink local function entetemakeToolbar(...) local ret = {} local lim = select(args'#', page...) if lim < 1 then return nil end for i = 1, doclim do ret[#ret + 1] = select(i, existeDoc...) local res end return '<small style= mw"font-style: normal;">(' .html.createtable.concat(ret, ' &#124; 'div) .. ')</small>'end
res :css('margin-bottom', '1ex') :css('border-bottom', '1px solid #aaa') :css('padding-bottom', '3px') :wikitext('[[Fichier:Test Template Info-Iconp.svg|50px|altmakeToolbar =|link=]]') :tag('span') :css('font-weight', 'bold') :css('font-size', '125%') :css('vertical-align', 'middle') :wikitext('&nbsp;') :wikitext(args.titre or 'Documentation') :done()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 ------------------------------------------------------------------------------ Load TemplateStyles---------------------------------------------------------------------------- p.main = function(frame) local parent = frame.getParent(frame) local output = p._main(parent.args) return frame:extensionTag{ name='templatestyles', args = { src= message('templatestyles-scr') } } .. frame:preprocess(output)end
editionLien---------------------------------------------------------------------------- :wikitext('&#93;&#32;&#91;')-- Main function :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-class')) :wikitext(p._startBox(args, env)) :wikitext(p._content(args, env)) :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' --> '[[w:Wikipedia:Template test cases|template sandbox]] page' then local texteBandeau = -- 'sandbox-notice-pagetype-module'<b-->Ce %s ne possède aucune '[[Aidew:Wikipedia: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.'Vous pouvez %s afin de documenter ce %s adéquatementsandboxTitle local templateTitle = env.templateTitle local subjectSpace = env.'subjectSpace if argsnot (subjectSpace and title and sandboxTitle and templateTitle and mw.title.module equals(title, sandboxTitle)) then texteBandeau return nil end -- Build the table of arguments to pass to {{ombox}}. We need just two fields, "image" and "text". local omargs = {} omargs.image = texteBandeaumessage('sandbox-notice-image') -- Get the text. We start with the opening blurb, which is something like -- "This is the template sandbox for [[Template:formatFoo]] (diff)." local text = 'module', lienUrl local frame = mw.getCurrentFrame() local isPreviewing = frame:preprocess(doc, 'créer cette sous-page{{REVISIONID}}', ) == 'edit', -- True if the page is being previewed. 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 isPreviewing or not compareUrl then text = text .. message('sandbox-notice-blurb'Country data, {pagetype, templateLink}) else local compareDisplay = message(' or page.text:subsandbox-notice-compare-link-display') local compareLink = makeUrlLink(1compareUrl, 12compareDisplay) text == text .. message('Utilisateur:sandbox-notice-diff-blurb' then, {pagetype, templateLink, compareLink}) end -- pas de catégorisation pour : modèles de données, pseudoGet the test cases page blurb if the page exists. This is something like --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 local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display') elselocal 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
omargs.class = message('sandbox-class')
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. res-- @env - environment table containing title objects, etc., generated with p.getEnvironment -- Messages:newline -- 'protection-template' --> 'pp-template' -- 'protection-template-args' --> {docusage = 'yes'} local title = env.title local protectionLevels local protectionTemplate = message('protection-template') local namespace = title.namespace if not (protectionTemplate and (namespace == 10 or namespace == 828)) then :tag(-- Don't display the protection template if we are not in the template or module namespaces. return nil end protectionLevels = env.protectionLevels if not protectionLevels then return nil end local editLevels = protectionLevels.edit local moveLevels = protectionLevels.move if moveLevels and moveLevels[1] == 'divsysop'or editLevels and editLevels[1] then -- The page is full-move protected, or full, template, or semi-protected. local frame = mw.getCurrentFrame() return frame:cssexpandTemplate{title = protectionTemplate, args = message('clearprotection-template-args', nil, 'bothtable')} else return nil return resend
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'|sous-page de documentation]]&nbsp;-> 'view') :tag( -- 'edit-link-display' --> 'spanedit') :css( -- 'fonthistory-sizelink-display', --> '89%history') :css( -- 'fontpurge-stylelink-display', --> 'normalpurge') -- 'file-docpage-preload' --> 'Template:wikitext(Documentation/preload-filespace' -- 'module-preload'(--> ') Template:wikitext(lienUrl(Documentation/preload-module-doc, 'modifier -- 'docpage-preload' --> 'Template:Documentation/preload')) :wikitext( -- 'create-link-display' --> '&nbsp;|&nbsp;create') :wikitext(lienUrl( --]] 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 = i18n['view-link-display'] data.editLinkDisplay = i18n['historiqueedit-link-display', ] data.historyLinkDisplay = i18n['history-link-display'))] :wikitext( data.purgeLinkDisplay = i18n['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 elseif subjectSpace == 828 then -- Module namespace preload = message(lienUrl(doc, '/Documentationmodule-preload')) :wikitext else preload = message('.<br /> docpage-preload')
end
end
data.preload = preload
data.createLinkDisplay = i18n['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=Documentation icon]]&nbsp;') :tag( -- 'template-namespace-heading' --> 'Template documentation' -- 'module-namespace-heading' --> 'Module documentation' -- 'file-namespace-heading' --> 'Summary' -- 'other-namespaces-heading' --> 'Documentation' -- 'start-box-linkclasses' --> 'spanmw-editsection-like plainlinks') :css( -- 'fontstart-box-sizelink-id', --> '89%doc_editlinks') :css( -- 'testcases-create-link-display'font-style-> '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 == 'normal')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 :wikitext( data.heading = i18n['(template-namespace-heading')] elseif subjectSpace == 828 then -- Module namespace :wikitext(lienUrl(pageBacasable, data.heading = i18n['modifiermodule-namespace-heading'))] elseif subjectSpace == 6 then -- File namespace :wikitext( data.heading = i18n[')file-namespace-heading')]
else
local preLoad data.heading = i18n['2other-namespaces-heading'] end -- Data for the [view][edit][history][purge] or [create] links. if args.module links then preLoad data.linksClass = nilmessage('start-box-linkclasses') data.linksId = message('start-box-link-id') data.links = links end contenuParagraphe return dataend function p.renderStartBox(data) -- Renders the start box html. -- @data - a table of data generated by p.makeStartBoxData. :wikitext local sbox = mw.html.create('bac à sable&nbsp;div') sbox :tagaddClass(message('spanheader-div-class')) :csstag('font-size', '89%div') :cssaddClass(message('fontheading-div-style', 'normalclass')) :wikitext(data.heading) local links = data.links if links then sbox :tag('(div') :wikitextaddClass(lienUrldata.linksClass) :attr(pageBacasable, 'créerid', 'edit', preLoad)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-- The line breaks below are necessary so that "=== Headings ===" at the start and end -- of docs are interpreted correctly. local cbox = mw.html.create('div') cbox :addClass(message('content-div-class')) :wikitext('\n' .. (content or '') .. '\n') return tostring(cbox)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) --[=[ -- This function generates the end box (also known as the link box). -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with p.getEnvironment --Bandeau pour les sous]=] -pages /Bac à sable- Get environment data. if pageenv = env or p.subpageText getEnvironment(args) local subjectSpace =env.subjectSpace local docTitle = 'Bac à sable' env.docTitle if not subjectSpace or not docTitle then resreturn nil end -- Check whether we should output the end box at all. Add the end :tag( -- box by default if the documentation exists or if we are in the -- user, module or template namespaces. local linkBox = args['divlink box')] :css('clear', if linkBox == 'bothoff') :done or not () :wikitext(mwdocTitle.getCurrentFrame():expandTemplate{title exists or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 'Sous-page de bac à sable'}10 ) then return nil
end
--Génération de la documentationAssemble the footer text field. local text = '' if linkBox then text = text .. linkBox reselse :tagtext = text .. (p.makeDocPageBlurb(args, env) or 'div')-- "This documentation is transcluded from [[Foo]]." if subjectSpace == 2 or subjectSpace == 10 or subjectSpace == 828 then :css('clear'-- We are in the user, template or module namespaces. -- Add sandbox and testcases links. -- "Editors can experiment in this template'both')s sandbox and testcases pages." :csstext = text .. (p.makeExperimentBlurb('margin'args, env) or '1em 0 0 0') :css(text = text .. 'border<br />', '1px solid #aaa') :css('background', if not args.content and not args[1] then -- "Please add categories to the /doc subpage.couleur or '#ecfcf4')" :css('padding -- Don't show this message with inline docs or with an explicitly specified doc page, '1em 1em 0 -- as then it is unclear where to add the categories.8em') :node text = text .. (entetep.makeCategoriesBlurb(args, page, doc, existeDocenv)or '') :wikitext(protection(page, doc, existeDoc, args[end text = text .. 'message protection'])) :node.. (contenup.makeSubpagesBlurb(args, doc, existeDocenv)or '')--"Subpages of this template" :node(noticelocal printBlurb = p.makePrintBlurb(args, page, doc, existeDocenv))  --Catégorisation des modules, en rangeant à part les modules de donnéesTwo-line blurb about print versions of templates. if args.module and page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' printBlurb then if page text = text .isSubpage and page.baseText == 'Country data<br />' then res:wikitext("[[Catégorie:Module d'informations pays|" .. page.subpageText .. "]]") elseprintBlurb res:wikitext("[[Catégorie:Module en langage Lua]]")end
end
end
local ebox = mw.html.create('div') ebox :addClass(message('footer-div-class')) :wikitext(text) return tostring(resebox)
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 = i18n['edit-link-display'] local editLink = makeUrlLink(editUrl, editDisplay) local historyUrl = docTitle:fullUrl{action = 'history'} local historyDisplay = i18n['history-link-display'] local args 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 = i18n['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) --[[ --Paramètres vides interprétés par LuaRenders the text "Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages." for cle-- @args - a table of arguments passed by the user -- @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 this module's $1 and $2 pages.' -- 'experiment-blurb-template' --> 'Editors can experiment in pairsthis 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('sandbox-link-display') local sandboxLink = makeWikilink(argsParentsandboxPage, sandboxDisplay) do local sandboxEditUrl = sandboxTitle:fullUrl{action = 'edit'} local sandboxEditDisplay = message('sandbox-edit-link-display') local sandboxEditLink = makeUrlLink(sandboxEditUrl, sandboxEditDisplay) local compareUrl = env.compareUrl local compareLink if val ~compareUrl then local compareDisplay = message('compare-link-display' ) compareLink = makeUrlLink(compareUrl, compareDisplay) end sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink) else local sandboxPreload if subjectSpace == 828 then args[cle] 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} 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) testcasesLinks = mwtestcasesLink .. ' ' .text.trimmakeToolbar(testcasesEditLink) else local testcasesPreload if subjectSpace == 828 then testcasesPreload = message(val'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
contributeur, Administrateurs
485

modifications