Module:Subject page header
Appearance
| This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
This module is used from the interface message MediaWiki:Subjectpageheader, shown at the top of all non-talk pages.
The interface message is parsed on every page view. There is no caching (although for logged-out users Varnish caches the entire HTML before it even reaches MediaWiki). So, please ensure this module runs as fast as possible. Some tips:
- Avoid unconditional imports of other modules. Instead, import them inside conditional blocks where they are needed.
- Avoid unconditionally performing expensive lookups. For example, to check if a page is JSON, first check if the page name suffix is
.json(which is very fast) and only then look up the content model.
Usage
{{#invoke:Subject page header|main}}
local p = {}
p.main = function(frame)
local title = mw.title.getCurrentTitle()
-- Bail out quickly on main namespace
if title.namespace == 0 then
return ''
end
local pageName = title.fullText
-- Optimization: first check page name suffix before looking up content model
local isJsonPage = pageName:len() > 5 and pageName:sub(-5) == ".json" and title.contentModel == 'json'
if isJsonPage then
local Hatnote = require('Module:Hatnote')
local docPageName = pageName .. '/doc'
local docTitle = mw.title.new(docPageName)
local content = ''
if docTitle.exists then
content =
'<hr>' ..
Hatnote._hatnote(
'The following documentation is located at [['..docPageName..']].<span class="mw-editsection-like plainlinks">[ [[Special:EditPage/'..docPageName..'|edit]] ] [ [[Special:PageHistory/'..docPageName..'|history]] ]</span>'
) ..
frame:preprocess(docTitle.content)
else
content = Hatnote._hatnote('Documentation for this JSON page can be created at the [['..docPageName..'|/doc]] subpage.')
end
return '<div class="mw-parser-output">' .. content .. '</div>'
elseif title.namespace == 8 and title.contentModel == 'SecurePoll' then
local Hatnote = require('Module:Hatnote')
return '<div class="mw-parser-output">'..Hatnote._hatnote('This page contains the configuration for a [[m:SecurePoll|SecurePoll]] election. It cannot be directly edited. Any changes must be done via [[Special:SecurePoll]].')..'</div>'
end
return ''
end
return p