Module:Disambiguation

local p = {}local mRedirect = require('Module:Redirect')local disambiguationTemplates = mw.loadData('Module:Disambiguation/templates')local function capitalize(s)-- This function only works on ASCII strings. If your wiki has-- disambiguation templates that use Unicode strings, use the commented-out-- line instead. Enwiki uses ASCII string manipulation only here to improve-- performance.return s:sub(1, 1):upper() .. s:sub(2, -1)-- return mw.ustring.upper(mw.ustring.sub(1, 1)) .. mw.ustring.sub(2, -1)endlocal function isDisambiguationTemplate(template)return disambiguationTemplates[capitalize(template)] or falseendp.isDisambiguation = function(content)-- false if there is no contentif content == nil thenreturn falseend-- redirects are not disambiguation pagesif mRedirect.getTargetFromText(content) ~= nil thenreturn falseend-- check for disambiguation templates in the contentlocal templateNames = {}for template in string.gmatch(content, "{{%s*([^|}]-)%s*[|}]") doif isDisambiguationTemplate(template) thenreturn trueendend-- check for magic wordif string.find(content, "__DISAMBIG__", 1, true) ~= nil thenreturn trueendreturn falseendp._isDisambiguationPage = function(page)-- Look "(disambiguation)" in the titleif string.find(page, "(disambiguation)",0,true) ~= nil thenreturn true;end-- Look for disamiguation template in page contentlocal title = mw.title.new(page)if not title then return false endlocal content = title:getContent()return p.isDisambiguation(content)end-- Entry points for templatesp.isDisambiguationPage = function(frame)local title = frame.args[1]return p._isDisambiguationPage(title) and "yes" or ""endreturn p