Module:User:Uzume/MWcap
Appearance
| This module is rated as alpha. It is ready for limited use and third-party feedback. It may be used on a small number of pages, but should be monitored closely. Suggestions for new features or adjustments to input and output are welcome. |
Usage
[edit]{{#invoke:User:Uzume/MWcap|function_name}}
Dashboard
[edit]Manually compare this with: Special:Version
| Capability String | Status | Mapped System Message Key |
|---|---|---|
fileUploads |
✔ Supported | MediaWiki:upload_directory_missing |
anonymousEdits |
✔ Supported | MediaWiki:anoneditwarning |
externalImages |
✔ Supported | MediaWiki:external_image_whitelist |
variantLogos |
❌ Missing | MediaWiki:variants-headline-wrong-key |
categoryTree |
✔ Supported | MediaWiki:categorytree-header |
citeTool |
✔ Supported | MediaWiki:cite_error |
citeThisPage |
✔ Supported | MediaWiki:citethispage-link |
codeEditor |
✔ Supported | MediaWiki:codeeditor-toolbar-toggle |
confirmEdit |
✔ Supported | MediaWiki:captcha-label |
imageMap |
✔ Supported | MediaWiki:imagemap_no_image |
inputBox |
✔ Supported | MediaWiki:inputbox-tryexact |
multimediaViewer |
✔ Supported | MediaWiki:multimediaviewer-repository-local |
nukeTool |
✔ Supported | MediaWiki:nuke-tools |
oathAuth |
✔ Supported | MediaWiki:oathauth-ui-general-help |
pageImages |
✔ Supported | MediaWiki:pageimages-info-label |
parserFunctions |
✔ Supported | MediaWiki:pfunc_time_error |
poemMarkup |
✔ Supported | MediaWiki:poem-desc |
replaceText |
❌ Missing | MediaWiki:replacetext_choose_pages |
spamBlacklist |
✔ Supported | MediaWiki:spam-blacklist |
syntaxHighlight |
✔ Supported | MediaWiki:syntaxhighlight-error-category |
templateData |
✔ Supported | MediaWiki:templatedata-doc-format-inline |
textExtracts |
✔ Supported | MediaWiki:textextracts-desc |
titleBlacklist |
✔ Supported | MediaWiki:titleblacklist-warning |
visualEditor |
✔ Supported | MediaWiki:visualeditor-preference-tabs |
wikiEditor |
✔ Supported | MediaWiki:wikieditor-realtimepreview-preview |
pageTranslation |
❌ Missing | MediaWiki:tpt-error-no-page |
scopedStyles |
✔ Supported | MediaWiki:content-model-sanitized-css |
mathRendering |
✔ Supported | MediaWiki:math_failure |
graphRendering |
❌ Missing | MediaWiki:graph-error-vega-invalid |
scoreMarkup |
✔ Supported | MediaWiki:score-compilererr |
easyTimeline |
✔ Supported | MediaWiki:timeline-invalidmap |
charInsert |
✔ Supported | MediaWiki:edittools |
codeMirror |
✔ Supported | MediaWiki:codemirror-toggle-label |
abuseFilter |
✔ Supported | MediaWiki:abusefilter-edit-builder-vars-action |
loginNotify |
✔ Supported | MediaWiki:echo-category-title-login-fail |
checkUser |
✔ Supported | MediaWiki:checkuser-reason |
notifications |
✔ Supported | MediaWiki:echo-category-title-system |
discussionTools |
✔ Supported | MediaWiki:discussiontools-replywidget-watchthis |
thanks |
✔ Supported | MediaWiki:logentry-thanks-thank |
pdfHandler |
✔ Supported | MediaWiki:exif-pdf-version |
timedMedia |
✔ Supported | MediaWiki:transcodestatistics |
linter |
✔ Supported | MediaWiki:linter-category-misnested-tag |
centralAuth |
✔ Supported | MediaWiki:centralauth-groupname |
centralNotice |
✔ Supported | MediaWiki:centralnotice |
cirrusSearch |
✔ Supported | MediaWiki:cirrussearch-backend-error |
globalPrefs |
✔ Supported | MediaWiki:globalpreferences |
globalUsage |
✔ Supported | MediaWiki:globalusage-more |
interwikiLinks |
✔ Supported | MediaWiki:interwiki_prefix |
babelBox |
✔ Supported | MediaWiki:babel-url |
contentTrans |
✔ Supported | MediaWiki:cx |
wikibaseClient |
✔ Supported | MediaWiki:wikibase-editlinkstitle |
wikibaseRepo |
❌ Missing | MediaWiki:wikibase-concepturi |
entitySchema |
✔ Supported | MediaWiki:entityschema-error-invalid-id |
proofreadPage |
❌ Missing | MediaWiki:namespace-Index |
pageAssessments |
✔ Supported | MediaWiki:specialpages-group-wiki |
quickSurveys |
✔ Supported | MediaWiki:ext-quicksurveys-example-external-survey-description |
disambiguator |
✔ Supported | MediaWiki:disambiguationpages |
require[[strict]]
local modname = ... or mw.getCurrentFrame():getTitle()
local modpath = modname:match("^(.*)/") and modname
local config = mw.loadData(modpath .. '/Config')
local message_map = config.map
local p = {}
local function CAP_FAILURE() end -- A unique sentinel to cache invalid results
local cap_cache = {} -- cache tracking true, false, or the failed sentinel
--[============================================================================[
-- OPTIMIZATION NOTE FOR MODULE DEVELOPERS:
-- If you see a [Capability Optimization Notice] in the parser profile logs,
-- you can enable page-level caching for that feature by creating a sub-page:
-- Module:Capability/featureName
--
-- The sub-page should contain this single line of code:
-- return require((...):match[[^(.*)/]])._internal.evaluate((...):match[[/([^/]*)$]])
--]============================================================================]
local function evaluate(feature)
local messageKey = message_map[feature]
if messageKey then
return mw.message.new(messageKey):exists()
end
end
local function has(feature)
local cachedValue = cap_cache[feature]
local result
if cachedValue ~= nil then
if cachedValue == CAP_FAILURE then return end
return cachedValue
end
--[[XXX: Possible optimization to enable page-level caching
local success
success, result = pcall(mw.loadData, modpath .. '/' .. feature)
if success and (result == true or result == false) then
cap_cache[feature] = result
return result
end
]]
result = evaluate(feature)
if result == true or result == false then
--[[XXX: Possible optimization to enable page-level caching
mw.log("[Capability Optimization Notice] Feature '" .. feature .. "' evaluated live. See source code comments in Module:Capability to enable page-wide caching.")
]]
cap_cache[feature] = result
return result
end
cap_cache[feature] = CAP_FAILURE
end
p._internal = { evaluate = evaluate }
p.api = { has = has }
function p.has(frame)
local args = frame.args
if '' ~= (args.usetemplate or '') then
args = frame:getParent().args
end
local feature = mw.text.trim(args['feature'] or args[1] or "")
local state = has(feature)
if nil == state then
return ('<span class="error" style="font-weight:bold; color:#d33;">Capability Error: \'%s\' is not a recognized or mapped capability string.</span>'):format(mw.text.nowiki(feature))
end
return state and "1" or ""
end
function p.dashboard(frame)
local html = {
'<table class="wikitable" style="width: 100%; border-collapse: collapse;">',
'<caption>Live Wiki Capability Status Dashboard</caption>',
'<tr>',
' <th scope="col" style="width: 30%; text-align: left;">Capability String</th>',
' <th scope="col" style="width: 20%; text-align: left;">Status</th>',
' <th scope="col" style="width: 50%; text-align: left;">Mapped System Message Key</th>',
'</tr>'
}
for _, entry in ipairs(config.list) do
local key = entry[1]
local msgKey = entry[2]
local isSupported = has(key)
local statusText, statusStyle
if isSupported then
statusText = '✔ Supported'
statusStyle = 'background-color: #e1f5fe; color: #0288d1; font-weight: bold;'
else
statusText = '❌ Missing'
statusStyle = 'background-color: #ffebee; color: #c62828; font-weight: bold;'
end
table.insert(html, '<tr>')
table.insert(html, (' <td><code>%s</code></td>'):format(mw.text.nowiki(key)))
table.insert(html, (' <td style="%s">%s</td>'):format(statusStyle, statusText))
table.insert(html, (' <td><code>MediaWiki:%s</code></td>'):format(mw.text.nowiki(msgKey)))
table.insert(html, '</tr>')
end
table.insert(html, '</table>')
return table.concat(html, '\n')
end
return p