![]() |
VOOZH | about |
This module implements {{Documentation}}.
localp={} -- Load modules (language wikis exclusive) -- ... -- Customizable strings locali18n={ -- default settings, change when necessary defaultDocPage='doc',-- documentation page suffix defaultSandboxPage='sandbox',-- sandbox page suffix defaultTestCasePage='testcases',-- testcases page suffix defaultPreload='Template:Documentation/preload',-- page that stores qualified documentation page contents defaultStyles='Module:Documentation/styles.css',-- stylesheet for this module when using TemplateStyles, remove or set to nil if your wiki not use this -- format strings, should not be translated commonInternalLink='[[%s]]', commonInternalLinkPipe='[[%s|%s]]', commonExternalLink='[%s]', commonExternalLinkWithName='[%s %s]', commonNamespacedPage='%s:%s', commonNamespacedPageWithSub='%s:%s/%s', -- namespace names, translate if your language prefers localized namespace name, although remain it untouched most likely not affect anything namespaceCategory='Category', namespaceSpecial='Special', namespaceUser='User', -- names of special pages, translate if your language prefers localized namespace name, although remain it untouched will still correctly linked to target page specialPurge='Purge', specialEdit='EditPage', specialHistory='PageHistory', -- translate following types if your language displays differ pageType_page='page', pageType_template='template', pageType_module='module', pageType_stylesheet='stylesheet', pageType_script='script', pageType_json='JSON', pageType_message='message', -- modify them if your wiki use different style to displaying links linkBar='%s',-- format used for whole link bar linkFormat=mw.text.nowiki('[')..'%s'..mw.text.nowiki(']'),-- format used for each individual links linkSeparator=' ',-- separator between links -- name of different type of links, change them if necessary linkTextPurge=mw.message.new('purge'):plain():lower(), linkTextView=mw.message.new('view'):plain():lower(), linkTextEdit=mw.message.new('edit'):plain():lower(), linkTextHistory=mw.message.new('history_short'):plain():lower(), linkTextCreate=mw.message.new('create'):plain():lower(), -- strings used in p.create(): contents shown when using {{docc}} or {{subst:docc}} createOutputFormat='%s%s',-- overall format createSplitDocPagePrompt='\n<!-- Put categories/interwikis on the documentation page -->',-- this string is shown when a separate documentation page is created createNoSubstCategory='Pages with templates requiring substitution',-- tracking category for using {{docc}} without substitution -- strings used in p.docPage(): contents shown in documentation page docPagePrompt='This is the documentation page. It %s transcluded into %s. See [[Template:Documentation]] for more information.',-- message shown as documentation header in documentation pages. Params: word used when page is a module or not; code page's type docPagePromptWill='is',-- word used when code page is a module page docPagePromptShould='should be',-- word used when code is not a module page docPageBadDocPrompt="<br>'''This %s's documentation needs improving or additional information.'''",-- additional message if a documentation page marked as baddoc docPageCategory='Documentation pages',-- tracking category for documentation pages -- strings used in p.page(): contents shown in code page pageNoDocPrompt="'''This %s has no documentation. If you know how to use this %s, please create it.'''",-- message shown when a separate documentation page is not exist, both parameters refers to page type pageNoDocCategory='%ss with no documentation',-- tracking category for pages without documentation, parameters refers to page type pageNoDocCategoryDefault='Pages with no documentation',-- fallback tracking category for pages without documentation pageBadDocPrompt="'''This %s's documentation needs improving or additional information.'''\n",-- message shown when a documentation page marked as baddoc, both parameters refers to page type pageBadDocCategory='%ss with bad documentation',-- tracking category for pages marked as baddoc, parameters refers to page type pageBadDocCategoryDefault='Pages with bad documentation',-- fallback tracking category for pages marked as baddoc pageDocHeaderTitle='Documentation',-- message shown as the title of the documentation header pageDocJumpToCode='Jump to code ↴',-- text of the link to jump to the code pageDocHeaderBottom='The above documentation is transcluded from %s.',-- message shown as the bottom line of the documentation header } -- Customizable functions localfunctionpageCategoryHandler(category) returnmw.getCurrentFrame():expandTemplate{title='translation category',args={category,project='0'}} end -- Load modules localloadStyles=require('Module:TSLoader').call -- Internal functions localfunctiongetType(namespace,page) localpageType='page' ifnamespace=='Template'then pageType='template' elseifnamespace=='Module'then pageType='module' elseifpage.fullText:gsub('/'..i18n.defaultDocPage..'$',''):find('%.css$')then pageType='stylesheet' elseifpage.fullText:gsub('/'..i18n.defaultDocPage..'$',''):find('%.js$')then pageType='script' elseifpage.fullText:gsub('/'..i18n.defaultDocPage..'$',''):find('%.json$')then pageType='json' elseifnamespace=='MediaWiki'then pageType='message' end returnpageType end localfunctiongetDisplayType(pageType) returni18n['pageType_'..pageType]ori18n.pageType_page end -- Exported functions functionp.create(f)-- Creating a documentation page or transclusion through {{subst:docc}} localargs=require('Module:ProcessArgs').norm() localpage=mw.title.getCurrentTitle() localdocPage=args.pageori18n.commonNamespacedPageWithSub:format(page.nsText,page.baseText,i18n.defaultDocPage) localout ifnotargs.contentandtostring(page)==docPagethen localpageType=mw.ustring.lower(args.typeorgetType(page.nsText,page)) localpageTypeDisplay=getDisplayType(pageType) out=f:preprocess(mw.title.new(i18n.defaultPreload):getContent():gsub('$1',pageTypeDisplay)) else localtemplateArgs={} for_,keyinipairs{'type','page','content','nodoc','baddoc'}do localval=args[key] ifvalthen ifkey=='content'thenval='\n'..val..'\n'end table.insert(templateArgs,key..'='..val) end end out='{{documentation|'..table.concat(templateArgs,'|')..'}}' out=out:gsub('|}}','}}') out=i18n.createOutputFormat:format(out,args.contentand''ori18n.createSplitDocPagePrompt) end ifnotmw.isSubsting()then out=f:preprocess(out) ifnotargs.nocatthen out=out..i18n.commonInternalLink:format(i18n.commonNamespacedPage:format(i18n.namespaceCategory,i18n.createNoSubstCategory)) end end returnout end functionp.docPage(f)-- Header on the documentation page localargs=require('Module:ProcessArgs').merge(true) localbadDoc=args.baddoc ifbadDocthen mw.ext.VariablesLua.vardefine('Documentation.badDoc','1') end localpage=mw.title.getCurrentTitle() localsubpage=page.subpageText ifsubpage==i18n.defaultSandboxPageorsubpage==i18n.defaultTestCasePagethen page=page.basePageTitle end localdocPage=mw.title.new(args.pageori18n.commonNamespacedPageWithSub:format(page.nsText,page.baseText,i18n.defaultDocPage)) ifdocPage~=pagethenreturnend localnamespace=page.nsText localpageType=mw.ustring.lower(args.typeorgetType(namespace,page)) localpageTypeDisplay=getDisplayType(pageType) localbody=mw.html.create('div'):addClass('documentation') body :addClass(badDocand'documentation-badDoc'or'') :tag('div'):addClass('documentation-header-tools') :wikitext(i18n.linkBar:format(i18n.linkFormat:format(i18n.commonInternalLinkPipe:format(i18n.commonNamespacedPageWithSub:format(i18n.namespaceSpecial,i18n.specialPurge,page.fullText),i18n.linkTextPurge)))) :done() :wikitext(i18n.docPagePrompt:format(pageType=='module'andi18n.docPagePromptWillori18n.docPagePromptShould,i18n.commonInternalLink:format(i18n.commonNamespacedPage:format(namespace,page.baseText)))) ifbadDocthen body:wikitext(i18n.docPageBadDocPrompt:format(pageTypeDisplay)) end ifnot(args.nocatornamespace==i18n.namespaceUser)then body:wikitext(i18n.commonInternalLink:format(i18n.commonNamespacedPage:format(i18n.namespaceCategory,i18n.docPageCategory))) end returnloadStyles(i18n.defaultStyles)..tostring(body) end functionp.page(f)-- Wrapper around the documentation on the main page -- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings localfunctiontrim(s) return(s:gsub('^[\t\r\n\f ]+',''):gsub('[\t\r\n\f ]+$','')) --return string.gsub( s, '^[\t\r\n\f ]*(.-)[\t\r\n\f ]*$', '%1' ) end localargs=require('Module:ProcessArgs').merge(true) localpage=mw.title.getCurrentTitle() localsubpage=page.subpageText ifsubpage==i18n.defaultSandboxPageorsubpage==i18n.defaultTestCasePagethen page=page.basePageTitle end localnamespace=page.nsText localdocText=trim(args.contentor'') ifdocText==''thendocText=nilend localdocPage localnoDoc ifdocTextthen docPage=page else docPage=mw.title.new(args.pageori18n.commonNamespacedPageWithSub:format(namespace,page.text,i18n.defaultDocPage)) noDoc=args.nodocornotdocPage.exists end localbadDoc=args.baddoc localpageType=mw.ustring.lower(args.typeorgetType(namespace,page)) localpageTypeDisplay=getDisplayType(pageType) ifnotdocTextandnotnoDocthen docText=trim(f:expandTemplate{title=':'..docPage.fullText}) ifmw.ext.VariablesLua.var('Documentation.badDoc')=='1'then badDoc=1 end ifdocText==''then docText=nil noDoc=1 end end ifdocTextthen docText='\n'..docText..'\n' end localdocClass='' localmessage localcategory ifnoDocthen docClass='documentation-noDoc' message=i18n.pageNoDocPrompt:format(pageTypeDisplay,pageTypeDisplay) ifnot(args.nocatornamespace==i18n.namespaceUser)then category=i18n.pageNoDocCategory:format(pageTypeDisplay) ifnotmw.title.new(i18n.commonNamespacedPage:format(i18n.namespaceCategory,category)).existsthen category=i18n.pageNoDocCategoryDefault end end elseifbadDocthen docClass='documentation-badDoc' message=i18n.pageBadDocPrompt:format(pageTypeDisplay) ifnot(args.nocatornamespace==i18n.namespaceUser)then category=i18n.pageBadDocCategory:format(pageTypeDisplay) ifnotmw.title.new(i18n.commonNamespacedPage:format(i18n.namespaceCategory,category)).existsthen category=i18n.pageBadDocCategoryDefault end end end -- Generates the link bar locallinks=mw.html.create('span'):addClass('documentation-header-tools') locallinkList={} ifnotnoDocthen ifpage~=docPagethen table.insert(linkList,i18n.linkFormat:format(i18n.commonInternalLinkPipe:format(docPage.fullText,i18n.linkTextView))) end table.insert(linkList,i18n.linkFormat:format(i18n.commonInternalLinkPipe:format(i18n.commonNamespacedPageWithSub:format(i18n.namespaceSpecial,i18n.specialEdit,docPage.fullText),i18n.linkTextEdit))) table.insert(linkList,i18n.linkFormat:format(i18n.commonInternalLinkPipe:format(i18n.commonNamespacedPageWithSub:format(i18n.namespaceSpecial,i18n.specialHistory,docPage.fullText),i18n.linkTextHistory))) else table.insert(linkList,i18n.linkFormat:format(i18n.commonExternalLinkWithName:format(docPage:canonicalUrl{action='edit',preload=i18n.defaultPreload,preloadparams=pageTypeDisplay},i18n.linkTextCreate))) end table.insert(linkList,i18n.linkFormat:format(i18n.commonInternalLinkPipe:format(i18n.commonNamespacedPageWithSub:format(i18n.namespaceSpecial,i18n.specialPurge,docPage.fullText),i18n.linkTextPurge))) links:wikitext(i18n.linkBar:format(table.concat(linkList,i18n.linkSeparator))) localbody=mw.html.create('div'):addClass('documentation') body :addClass(docClass) localheader=mw.html.create('div') :addClass('documentation-header-top') header :tag('span') :addClass('documentation-header-title') :wikitext(i18n.pageDocHeaderTitle) header :node(links) localcodePages={ module=true, stylesheet=true, script=true, } ifnotnoDocandcodePages[pageType]then header :tag('span') :attr('id','documentation-jump-to-code') :wikitext(i18n.commonInternalLinkPipe:format('#the-code',i18n.pageDocJumpToCode)) end body :node(header):done() :wikitext(message) :wikitext(docText) ifnotnoDocandpage~=docPagethen body :tag('div') :addClass('documentation-header-bottom') :node(links) :wikitext(i18n.pageDocHeaderBottom:format(i18n.commonInternalLink:format(docPage.fullText))) end ifcategorythen body:wikitext(pageCategoryHandler(category)) end localanchor='' ifnotnoDocandpageType~='template'andpageType~='message'then anchor=mw.html.create('div'):attr('id','the-code') end returnloadStyles(i18n.defaultStyles)..tostring(body)..tostring(anchor) end returnp