Ouvrir le menu principal

Modifications

Module:Documentation

25 813 octets supprimés, 19 mars 2019 à 10:46
Pourquoi changer cette icône ?, l'ancienne icône (Fichier:Test Template Info-Icon.svg) est beaucoup plus informative avec son point d'interrogation de type « aide » au milieu d'accolades ; cela correspond parfaitement à l'idée d'une documenta...
-- This Ce module implements implémente le modèle {{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 functionslocal function existePage(page) return page and page.existslocal ugsub = mw.ustring.gsubend
------------------------------------------------------------------------------ Helper functions---- These are defined as local functions, but are made available in the p-- table for testing purposes.---------------------------------------------------------------------------- local function messagenomDocumentation(cfgKey, valArray, expectTypepage) --[[ -On n'est pas dans une sous- Gets a message from the cfg table and formats it if appropriate.page -- The function raises an error if the value from the cfg table is not -- of the type expectTypepage. 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 isSubpage then error('message: type error in message cfg.' .return page. cfgKey subjectNsText .. ' (:' .. expectType .. ' expected, got ' .page. type(msg) text .. ')/Documentation', 2) end if not valArray then return msg
end
--On est dans une sous-page local function getMessageVal(match)sousPage = page.subpageText if sousPage == 'Documentation' match or sousPage == 'Bac à sable' or sousPage == tonumber(match)'Test' then return valArray[match] or error(page.subjectNsText .. 'message: no value found for key $' .. match page.baseText .. ' in message cfg/Documentation' else return page.subjectNsText ..':' .. cfgKey, 4)page.text .. '/Documentation'
end
 
local ret = ugsub(msg, '$([1-9][0-9]*)', getMessageVal)
return ret
end
p.message local function lienUrl(nomPage, titrePage, action, pagePreload) local argument = message{['action'] = action or 'edit'}
local function makeWikilink(page, display) if display pagePreload then return mw.ustring.format(argument['preload'[[%s|%s]]= 'Modèle:Documentation/Preload', page, display) else return mw.ustring.format('[[%s]]', page)pagePreload
end
end
 
p.makeWikilink = makeWikilink
local function makeCategoryLink(cat, sort) local catns = return mw.siteustring.namespacesformat('[14%s %s].name return makeWikilink(catns .. ', nomPage:' .. catfullUrl(argument), sorttitrePage)
end
plocal function entete(args, page, doc, existeDoc) local res = mw.makeCategoryLink = makeCategoryLinkhtml.create('div')
local function makeUrlLink res :css('margin-bottom', '1ex') :css('border-bottom', '1px solid #aaa') :css(url'padding-bottom', display'3px') return mw.ustring.format :wikitext('[%s %s[Fichier:Test Template Info-Icon.svg|50px|alt=|link=]]') :tag('span') :css('font-weight', url'bold') :css('font-size', display'125%')end :css('vertical-align', 'middle') :wikitext(' ') :wikitext(args.titre or 'Documentation') :done()
p if not args.makeUrlLink contenu then local editionLien = makeUrlLinkres:tag('span') :addClass('mw-editsection plainlinks') :css('vertical-align', 'middle') :wikitext('[')
local function makeToolbar if existeDoc then editionLien:wikitext(...) local ret = {} local lim = selectlienUrl(doc, '#modifier', ...)) else if lim < 1 args.module then return nil end for i = 1 editionLien:wikitext(lienUrl(doc, 'créer', lim do ret[#ret + 1] = select(i'edit', ...'Module')) end else return '<small style="font-style editionLien: normal;">wikitext(lienUrl(doc, 'créer', 'edit' .. table.concat(ret, ' &#124; ') .. ')</small>' end end
p.makeToolbar = makeToolbar ------------------------------------------------------------------------------ Argument processing---------------------------------------------------------------------------- local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame, {editionLien valueFunc = function :wikitext(key, value) if type(value) == 'string&#93;&#32;&#91;' then) value = value :matchwikitext('^%s*lienUrl(.-)%s*$page, ') -- Remove whitespace. if key == purger'heading, ' or value ~= purge'' then return value else return nil end else return value end)) end }) return p[funcName]:wikitext(args'&#93;')
end
end
------------------------------------------------------------------------------ Main function---------------------------------------------------------------------------- p.main = makeInvokeFunc('_main') 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 tostring(root)res
end
----------------------------------------------------------------------------local function protection(page, doc, existeDoc, message) -- Environment settingsInsertion automatique du modèle de protection.---------------------------------------------------------------------------- local niveauProtection = page.protectionLevels.edit
function p.getEnvironment(args) --[if niveauProtection and niveauProtection[1] then -- Returns a table with information about the environment, including title objects and other namespace- or local tableProtection = { -- path-related data. -- @args - table of arguments passed by the user -- -- Title objects include: -- env.title - the page we are making documentation for (usually the current title) -- env.templateTitle - the template (or module autoconfirmed = {'semiProtection', file, etc.) '{{%s*[Ss]emi%-- env.docTitle - the /doc subpage. -- env.sandboxTitle - the /sandbox subpage. -- env.testcasesTitle - the /testcases subpage. -- env.printTitle - the print version of the templateprotection%s*[|}]', located at the /Print subpage. -- -- Data includes: -- env.protectionLevels '{{%s*[Ss]emi%- the protection levels table of the title object.+longue%s*[|}]'}, -- env.subjectSpace - the number of the title editextendedsemiprotected = {'semiProtectionEtendue', '{{%s subject namespace. *[Ss]emi%-- env.docSpace - the number of the namespace the title puts its documentation in.protection +étendue%s*[|}]'}, -- env.docpageBase - the text of the base page of the /doc sysop = {'protection', /sandbox and /testcases pages'{{%s*[Pp]rotection%s*[|}]'}, with namespace. -- env.compareUrl - URL of the Special:ComparePages page comparing the sandbox with the template. } -- -- All table lookups are passed through pcall so that errors are caught. If an error occurs, the value -- returned will be nil. -- local protection = tableProtection[niveauProtection[1]] if not protection then return '' local env, envFuncs = {}, {} end
-- Set up the metatable. If triggered we call the corresponding function in the envFuncs table. The value local alreadyShown = false if existeDoc then -- returned by that function is memoized in the env table so that we donVérification qu't call any of the functionsil n'y a pas déjà un modèle de -- more than onceprotection dans la documentation du modèle. (Nils won't be memoized.) setmetatable(env, { __index local contenuDoc = function doc:getContent(t, key) local envFunc = envFuncsif contenuDoc:match(protection[2]) or (protection[key3] if envFunc then local success, val = pcalland contenuDoc:match(envFuncprotection[3])) then if success then env[key] alreadyShown = val -- Memoise the value. return val endtrue
end
return nil
end
})
function envFuncs.title() -- The title object for the current page, or a test page passed with args.page.if not alreadyShown then local title if message == '' then local titleArg message = args.pagenil if titleArg then end title = mw.title.newreturn require(titleArg'Module:Protection') else title = mw.title.getCurrentTitlemain({message}, protection[1], page)
end
return title
end
end
function envFuncs.templateTitle() --[[ -- The template (or modulepour les bacs à sable, etc.) title object.on retire les balises de catégories -- Messages:habituellement situées en "includeonly" à la fin de la documentation -- 'sandbox-subpage' --> 'sandbox' -- 'testcases-subpage' --> 'testcases' --]] local subjectSpace = env.subjectSpacefunction retireBalisesCategories(contenuDoc) local title = env.titlecount local subpage = title.subpageText repeat if subpage == message('sandbox-subpage') or subpage contenuDoc, count == message('testcases-subpage') then return mw.titleustring.makeTitlegsub(subjectSpacecontenuDoc, title.baseText) else return mw.title.makeTitle(subjectSpace'%[%[Catégorie:[^%]]+%]%][\t\r\n\f ]*$', title.text'') end enduntil count == 0
function envFuncs.docTitle() --[[ -- Title object of the /doc subpage. -- Messages: -- 'doc-subpage' --> 'doc' --]] local title contenuDoc, count = 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.titleustring.newgsub(docpage) end function envFuncs.sandboxTitle() --[[ -- Title object for the /sandbox subpage. -- Messages: -- contenuDoc, 'sandbox-subpage' --> 'sandbox' --]] return mw.title.new(env.docpageBase .. '/' .. message('sandbox-subpage')) end function envFuncs.testcasesTitle() --[[ -- Title object for the /testcases subpage. -- Messages: -- 'testcases-subpage' --> 'testcases' --\t\r\n\f ]] 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 env.title.protectionLevelscontenuDoc end
local function envFuncs.subjectSpacecontenu(args, doc, existeDoc) -- The subject namespace number. return local page = mw.site.namespaces[env.title.namespace]getCurrentTitle() local res = mw.subjecthtml.id endcreate():newline()
function envFuncs.docSpace()if existeDoc then -- The documentation namespace number. For most namespaces this is the same as the -- subject namespaceif args. 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 subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 contenu then return subjectSpace + 1res :wikitext(args.contenu) else :newline() return subjectSpace :newline()
end
end
function envFuncs local frame = mw.docpageBasegetCurrentFrame() -- The base page of the /doc, /sandbox, if frame.args and /testcases subpagesframe. args['contenu sous-- For some namespaces this is the talk page, rather than the template page.'] then local templateTitle = env.templateTitle local docSpace = env.docSpace local docSpaceText contenuDoc = mwframe.site.namespacesargs[docSpace'contenu sous-page'].name -- Assemble the link. docSpace is never the main namespace, so we can hardcode the colon. return docSpaceText . if page. subpageText == ':Bac à sable' or page.. templateTitle.text end function envFuncs.compareUrl() -- Diff link between the sandbox and the main template using [[Special:ComparePages]]. local templateTitle = env.templateTitle local sandboxTitle subpageText = env.sandboxTitle if templateTitle.exists and sandboxTitle.exists then local compareUrl = mw.uri.fullUrl( 'Special:ComparePagesTest',then {page1 contenuDoc = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText}retireBalisesCategories(contenuDoc) )end return tostringres:wikitext(compareUrlcontenuDoc)
else
return nillocal contenuDoc = frame:expandTemplate{title = doc.prefixedText} if page.subpageText == 'Bac à sable' or page.subpageText == 'Test' then contenuDoc = retireBalisesCategories(contenuDoc) end res:wikitext(contenuDoc)
end
end
return env if args['complément'] then res :newline() :newline() :wikitext(args['complément']) end
---------------------------------------------------------------------------- elseif args.contenu then-- Auxiliary templates---------------------------------------------------------------------------- res:wikitext(args.contenu)
function p elseif page.sandboxNotice(args, env) --[subpageText ~=[ -- 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-imageBac à sable' --> '[[Image:Sandboxand page.svg|50px|alt=|linksubpageText ~=]]' -- 'sandbox-notice-blurb' --> 'This is the $1 for $2.Test'then -- local texteBandeau = 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).' -- 'sandbox-notice-pagetype-template' --<b> 'Ce %s ne possède aucune [[WikipediaAide:Template test casesDocumentation de modèle|template sandboxdocumentation]] page' -- 'sandbox-notice-pagetype-module' --> '[[Wikipedia:Template test cases|module sandbox]] page ..' explicative en sous-- 'sandbox-notice-pagetype-other' --> 'sandbox page' -- 'sandbox-notice-compare-link-display' --</b> 'diff' -- 'sandbox-notice-testcases-blurb' --> 'See also the companion subpage for $1, pas même une description succincte.' -- 'sandbox-notice-testcases-link-display' --<br> '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équatement.templateTitle' local subjectSpace = env.subjectSpace if not (subjectSpace and title and sandboxTitle and templateTitle and mwargs.title.equals(title, sandboxTitle)) module then return nil texteBandeau = texteBandeau:format( end -- Build the table of arguments to pass to {{ombox}}. We need just two fields 'module', "image" and "text". local omargs = {} omargs.image = message lienUrl(doc, 'sandboxcréer cette sous-notice-imagepage') -- 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(, 'sandbox-notice-pagetype-templateModule'), elseif subjectSpace == 828 then pagetype = message( 'sandbox-notice-pagetype-module') else pagetype = message('sandbox-notice-pagetype-other' ) end local templateLink = makeWikilink(templateTitle if page.prefixedText) local compareUrl baseText = env.compareUrl if compareUrl then local compareDisplay = message('sandbox-notice-compare-link-displayCountry data') local compareLink = makeUrlLinkor page.text:sub(compareUrl1, compareDisplay12) text = text .. message(= 'Utilisateur:'sandboxthen -notice-diffpas de catégorisation pour : modèles de données, pseudo-blurb', {pagetype, templateLink, compareLink})namespace "Module:Utilisateur:Toto/Nom du module" else text texteBandeau = text texteBandeau .. 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 [[TemplateCatégorie:Foo/testcases|test casesModule sans documentation]]." 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})end
else
local testcasesLinkDisplay texteBandeau = messagetexteBandeau:format( 'sandboxmodèle', lienUrl(doc, 'créer cette sous-notice-testcases-link-displaypage', 'edit', ''), 'modèle' local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay) text texteBandeau = text texteBandeau .. '<br />[[Catégorie:Modèle sans documentation]]' .. 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.res -- @env - environment table containing title objects, etc., generated with p.getEnvironment -- Messages : -- 'protection-template' --> 'pp-template' -- 'protection-template-args' --> {docusage = 'yes'} local 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 = requirenewline('Module:Protection banner') local reason = message:tag('protection-reason-editdiv') return mProtectionBanner._main{reason, small = true} elseif moveProt and moveProt ~= :css('autoconfirmedclear' 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('Module:Protection bannerboth') return mProtectionBanner._main{action = 'move', small = true} else return nil endres
end
----------------------------------------------------------------------------local function notice(args, page, doc, existeDoc) local res = mw.html.create('div') :css('border-- Start boxtop', '1px solid #aaa')---------------------------------------------------------------------------- :css('margin', '1.5em 0 0')
local contenuParagraphe = res :tag('p.startBox = makeInvokeFunc') :addClass('plainlinks') :css('margin-bottom', '0') :css('padding-left', '1em') :css('_startBoxfont-style', 'italic')
function p if args._startBox(contenu then if args, env) --[[ -- This function generates the start box.notice then -- @ contenuParagraphe:wikitext(args - a table of arguments passed by the user -- @env - environment table containing title objects, etc., generated with pnotice ..getEnvironment'<br />') -- else -- The actual work is done by p.makeStartBoxLinksData and p.renderStartBoxLinks which make contenuParagraphe -- the :wikitext('La [[viewAide:Documentation de modèle|documentation]] ') :wikitext('de ce [edit] [historyAide:Modèle|modèle] [purge] links, and by p.makeStartBoxData and p.renderStartBoxest directement ') -- which generate the box HTML. -- :wikitext('[[Aide:Inclusion|incluse]]dans le corps de ce dernier. ') env = env or p.getEnvironment :wikitext(lienUrl(argspage, 'Cliquez ici pour purger le cache', 'purge')) local links local content = args :wikitext('.content<br /> Si cette page est protégée, veuillez ') if not content then :wikitext('transférer le contenu de la documentation vers sa ') :wikitext(lienUrl(doc, 'sous-- No need to include the links if the documentation is on the template page itself. local linksData = p.makeStartBoxLinksData(argsdédiée', 'edit', env'')) if linksData then links = p :wikitext('.renderStartBoxLinks(linksData<br /> ')
end
end
-- Generate the start box html.
local data = p.makeStartBoxData(args, env, links)
if data then
return p.renderStartBox(data)
else
-- User specified no headingif existeDoc then local lienAide = '[[Aide:Modèle|modèle]]' if args.module then return nil lienAide = '[[Aide:Module|module]]' endend contenuParagraphe :wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ')function p.makeStartBoxLinksData :wikitext(args, envlienAide) -- :wikitext(' est [[ -- Does initial processing of data to make the [viewAide:Inclusion|incluse] [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 :wikitext(tostring(doc)) -- -- Messages : -- wikitext('view|sous-link-display' --> 'viewpage de documentation]]&nbsp;') -- :tag('edit-link-display' --> 'editspan') -- :css('historyfont-link-displaysize' --> , 'history89%') -- :css('purgefont-link-displaystyle' --> , 'purgenormal') -- :wikitext('file-docpage-preload' --> 'Template:Documentation/preload-filespace(') -- 'module-preload' --> 'Template :Documentation/preload-module-wikitext(lienUrl(doc, 'modifier')) -- 'docpage-preload' --> 'Template :Documentation/preload' -- 'create-link-display' --> 'create' --]] 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 = messagewikitext('view-link-display&nbsp;|&nbsp;') data.editLinkDisplay = message :wikitext(lienUrl(doc, 'edit-link-displayhistorique') data.historyLinkDisplay = message(, 'history-link-display')) data.purgeLinkDisplay = message :wikitext('purge-link-display') -- Create link if .<br /doc doesn> 't exist.) local preload = args.preload :done() if not preload then if subjectSpace == 6 then -- File namespace preload = message :wikitext('fileVeuillez placer les catégories dans la sous-docpage-preloadpage ') elseif subjectSpace == 828 then -- Module namespace preload = message :wikitext(lienUrl(doc, 'module-preload/Documentation')) else preload = message :wikitext('docpage-preload.<br /> ')
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 --]] local function escapeBrackets(s) -- Escapes square brackets with HTML entities. s = scontenuParagraphe:gsubwikitext('%[', '&#91;Les éditeurs peuvent travailler dans le ') -- Replace square brackets with HTML entities. s = s:gsub('%]', '&#93;') return s end
local ret local docTitle = data.docTitle local title = data.title if docTitle.exists then local viewLink titrePageBacasable = makeWikilinknomDocumentation(docTitle.prefixedText, data.viewLinkDisplaypage) local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay) local historyLink = makeUrlLinkgsub(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) local purgeLink = makeUrlLink(title:fullUrl{action = 'purge/Documentation'}, data.purgeLinkDisplay) ret = '[%s] [%s] [%s] [%s]/Bac à sable' ret = escapeBrackets(ret) ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink) else local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) ret = '[%s]' ret = escapeBrackets(ret) ret pageBacasable = mw.ustringtitle.formatnew(ret, createLinktitrePageBacasable) end return retend
function p.makeStartBoxData if existePage(args, env, linkspageBacasable)then -- contenuParagraphe :wikitext('[=[ -- 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, etctitrePageBacasable ., generated with p.getEnvironment -- @links - a string containing the [view][edit][history'|bac à sable][purge] links - could be nil if there&nbsp;'s an error. --) -- Messages : -- 'documentation-icon-wikitexttag(' --> span'[[File) :Test Template Info-Icon - Version css(2).svg|50px|link=|alt=]]' -font- size'template-namespace-heading, ' --> 'Template documentation89%') -- 'module-namespace-heading' --> 'Module documentation' -- 'file-namespace-heading' --> 'Summary' -- 'other-namespaces-heading' --> 'Documentation' -- 'start-box-linkclasses' --> 'mw-editsection-like plainlinks' -- 'start-box-link-id :css(' font--> style'doc_editlinks' -- 'testcases-create-link-display' --> '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 data.heading = message :wikitext('documentation-icon-wikitext') .. ' ' .. message('template-namespace-heading') elseif subjectSpace == 828 then -- Module namespace data.heading = message :wikitext(lienUrl(pageBacasable, 'documentation-icon-wikitextmodifier') .. ' ' .. message('module-namespace-heading') elseif subjectSpace == 6 then -- File namespace data.heading = message :wikitext('file-namespace-heading)')
else
data.heading = message('other-namespaces-heading') end -- Heading CSS local headingStyle preLoad = args['heading-style2'] if headingStyle then dataargs.headingStyleText = headingStyle elseif subjectSpace == 10 module then -- We are in the template or template talk namespaces. data.headingFontWeight preLoad = 'bold'nil data.headingFontSize = '125%' else data.headingFontSize = '150%' end -- Data for the [view][edit][history][purge] or [create] links. if links then data.linksClass = message('start-box-linkclasses')contenuParagraphe data.linksId = message :wikitext('start-box-link-idbac à sable&nbsp;') data.links = links end return dataend function p.renderStartBox(data) -- Renders the start box html. -- @data - a table of data generated by p.makeStartBoxData. local sbox = mw.html.create :tag('divspan') sbox :css('paddingfont-bottomsize', '3px89%') :css('borderfont-bottomstyle', '1px solid #aaanormal') :csswikitext('margin-bottom', '1ex') :newline() :tag('span') :cssTextwikitext(data.headingStyleText) :csslienUrl(pageBacasable, 'font-weightcréer', data.headingFontWeight) :css('font-sizeedit', data.headingFontSizepreLoad)) :wikitext(data.heading) local links = data.links if links then sbox:tag('span') :addClass(data.linksClass) :attr('id', data.linksId) :wikitext(links)
end
return tostring(sbox)
end
---------------------------------------------------------------------------- if not args.module then-- Documentation content---------------------------------------------------------------------------- contenuParagraphe:wikitext(' et la page de ')
p.content local titrePageTest = makeInvokeFuncnomDocumentation(page):gsub('_content/Documentation', '/Test') local pageTest = mw.title.new(titrePageTest)
function p if existePage(pageTest) then contenuParagraphe :wikitext('[[' .._contenttitrePageTest .. '|test]]&nbsp;') :tag(args'span') :css('font-size', env'89%') :css('font-- Displays the documentation contentsstyle', 'normal') -- @args - a table of arguments passed by the user :wikitext('(') -- @env - environment table containing title objects :wikitext(lienUrl(pageTest, etc., generated with p.getEnvironment'modifier')) :wikitext(')') else contenuParagraphe :wikitext('test&nbsp;') env = env or p.getEnvironment :tag(args'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')) :expandTemplate{title = docTitle.prefixedText}wikitext(')') end
end
-- The line breaks below are necessary so that "=== Headings ===" at the start and end -- of docs are interpreted correctly. return '\ncontenuParagraphe:wikitext(' .. (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 docTitle.prefixedText else return '' endres
end
----------------------------------------------------------------------------function p._documentation(args)-- End box local page = mw.title.getCurrentTitle()---------------------------------------------------------------------------- local titreDoc = nomDocumentation(page) local doc = mw.title.new(args[1] or titreDoc) local existeDoc = existePage(doc) local res = mw.html.create()
p.endBox = makeInvokeFunc('_endBox') function p._endBox(args, env) --[=[ -Bandeau pour les sous- This function generates the end box (also known as the link box).pages /Bac à sable -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etcif page., generated with p.getEnvironmentsubpageText == 'Bac à sable' then -- res -- Messages : -- tag('fmbox-id' --> 'documentation-meta-datadiv') -- :css('fmbox-styleclear' --> , 'background-color: #ecfcf4both') -- 'fmbox-textstyle' --> 'font-style : italic'done() -- -- The HTML is generated by the {{fmbox}} template, courtesy of [[Module :Message box]]. --]=] -- Get environment data. env = env or pwikitext(mw.getEnvironmentgetCurrentFrame(args) local subjectSpace :expandTemplate{title = 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 'Sous-- user, module or template namespaces. local linkBox = args[page de bac à sable'link box'] if linkBox == 'off' or not ( docTitle.exists or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 }) then return nil
end
-- Assemble the arguments for {{fmbox}}.Génération de la documentation local fmargs = {}res fmargs.id = message :tag('fmbox-iddiv') -- Sets :css('documentation-meta-dataclear', 'both') fmargs.image = :css('margin', 'none1em 0 0 0') fmargs.style = message :css('fmbox-styleborder', '1px solid #aaa') -- Sets :css('background-color: ', args.couleur or '#ecfcf4') fmargs :css('padding', '1em 1em 0.textstyle = message8em') :node(entete(args, page, doc, existeDoc)) :wikitext(protection(page, doc, existeDoc, args['fmbox-textstylemessage protection']) -- 'font-style) :node(contenu(args, doc, existeDoc)) : italic;'node(notice(args, page, doc, existeDoc))
-- Assemble the fmbox text field.Catégorisation des modules, en rangeant à part les modules de données local text if args.module and page.subpageText ~= 'Bac à sable' if linkBox then text = text and page.. linkBox else text subpageText ~= text .. (p.makeDocPageBlurb(args, env) or 'Test') -- "This documentation is transcluded from [[Foo]]." then if subjectSpace == 2 or subjectSpace == 10 or subjectSpace == 828 then -- We are in the user, template or module namespacespage. -- Add sandbox isSubpage and testcases linkspage. -- "Editors can experiment in this template's sandbox and testcases pages." text baseText = text .. (p.makeExperimentBlurb(args, env) or '') text = text .. '<br />Country data'then if not args.content and not argsres:wikitext("[[1] then -- Catégorie:Module d'informations pays|"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. text = text subpageText .. (p.makeCategoriesBlurb(args, env) or ''"]]") end else text = text .. ' ' .. (p.makeSubpagesBlurbres:wikitext(args, env) or '') --"Subpages of this template[[Catégorie:Module en langage Lua]]" local printBlurb = p.makePrintBlurb(args, env) -- Two-line blurb about print versions of templates. if printBlurb then text = text .. '<br />' .. printBlurb end
end
end
fmargs.text = text
return messageBox.maintostring('fmbox', fmargsres)
end
function p.makeDocPageBlurb(args, env) --[=[ -- Makes the blurb "This documentation is transcluded from [[Template:Foo]] (edit, historyframe)". -- @local 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 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 createUrl argsParent = docTitleframe:fullUrl{action = 'edit', preload = message('module-preload')} local createDisplay = messagegetParent('create-link-display') local createLink = makeUrlLink(createUrl, createDisplay) ret = message('create-module-doc-blurb', {createLink}) .. '<br />' end return retendargs
function p.makeExperimentBlurb(args, env) --[[Paramètres vides interprétés par Lua -- Renders the text "Editors can experiment for cle, val in this template's sandbox (edit | diff) and testcases pairs(editargsParent) pages." -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, 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 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 thendo return nil end -- Make links. local sandboxLinks, testcasesLinks if sandboxTitle.exists then local sandboxPage = sandboxTitle.prefixedText local sandboxDisplay val ~= message('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) local compareUrl = env.compareUrl local compareLink if compareUrl then local compareDisplay args[cle] = message('compare-link-display') compareLink = makeUrlLinkmw.text.trim(compareUrl, compareDisplayval)
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 return p.makeCategoriesBlurb_documentation(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 nil end local docPathLink = makeWikilink(docTitle.prefixedText, message('doc-link-display')) return message('add-categories-blurb', {docPathLink})
end
function p.makeSubpagesBlurbnomDocumentation(args, envframe) --if frame.args[[ -- Generates the "Subpages of this template" link1] and mw. -- @args - a table of arguments passed by the user -- @env - environment table containing title objects, etctext., generated with ptrim(frame.getEnvironment -- Messages: -- 'template-pagetype' --> 'template' -- 'module-pagetype' --> 'module' -- 'default-pagetype' --> 'page' -- 'subpages-link-display' --> 'Subpages of this $args[1' --]] local subjectSpace = env.subjectSpace local templateTitle = env.templateTitle if not subjectSpace or not templateTitle then return nil end local pagetype if subjectSpace == 10 then pagetype ) ~= message('template-pagetype') elseif subjectSpace == 828 then pagetype = message('module-pagetype')return frame.args[1]
else
pagetype = message('default-pagetype') end local subpagesLink titreDoc = makeWikilinknomDocumentation( 'Special:PrefixIndex/' mw.title. templateTitle.prefixedText .. '/', message('subpages-link-display', {pagetype}) ) return messagegetCurrentTitle('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 printTitlemw.exists then local printLink = makeWikilink(printTitletitle.prefixedText, messagenew('print-link-display'titreDoc)) ret = message('print-blurb', {printLink}) local displayPrintCategory = message('display-print-category', nil, 'boolean') if displayPrintCategory .exists then ret = ret .. makeCategoryLink(message('print-category'))return titreDoc
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
Utilisateur anonyme