Module:Editnotice load explained

local p = local getArgs = require('Module:Arguments').getArgslocal cfg = mw.loadData("Module:Editnotice load/config")local pseudoNs = mw.title.new(cfg.pseudo_ns_name)local enTypes = cfg.editnotice_typeslocal enNames = cfg.editnotice_names

local function getNoticeContent(frame, title, args) local success, result = pcall(frame.expandTemplate, frame,) if success then result = mw.text.trim(result) if result ~= and result ~= '-' then return result end end return end

local function makeLink(builder, links, target, text, contents) if contents

or contents

nil then builder = links builder = builder :tag('li') else builder = builder:tag('span') end builder = builder :addClass('editnotice-link') :css('clear', 'both') :css('float', 'right') :css('margin', '0px 0.8em') :css('padding', 0) :css('line-height', '1em') :css('font-size', '90%') if contents

or contents

nil then builder = builder:addClass('editnotice-redlink') end builder:wikitext(string.format('%s ', target, text))end

local function displayEditnotice(builder, class, content) if content then return builder:tag('div') :addClass(class) :css('clear', 'both') :css('width', '100%') :wikitext(content) endend

function getEditnoticeType(title) if title.baseText

title.rootText then return title.subpageText else return getEditnoticeType(title.basePageTitle) endend

function getEditnoticeMainPage(currPage, editNoticeType) return mw.ustring.gsub(currPage.text, pseudoNs.text .. "/" .. editNoticeType .. "/", "") .. ""end

function p.page(frame) local args = getArgs(frame) local currPage = args['title'] and mw.title.new(args['title']) or mw.title.getCurrentTitle local editnoticeType = p.editnotice(frame) return mw.ustring.gsub(currPage.text, pseudoNs.text .. "/" .. enTypes[editnoticeType] .. "/", "") .. ""end

function p.editnotice(frame) local args = getArgs(frame) local currPage = args['title'] and mw.title.new(args['title']) or mw.title.getCurrentTitle if currPage.rootText

pseudoNs.text and currPage.nsText

pseudoNs.nsText then local editNoticeType = getEditnoticeType(currPage) if editNoticeType

pseudoNs.text then return pseudoNs.text elseif editNoticeType

enTypes["protection"] then return "protection" elseif editNoticeType

enTypes["protection_id"] then local title = pcall(function return mw.title.new(tonumber(getEditnoticeMainPage(currPage, editNoticeType))).text end) or nil return title ~= nil and "protection_id" or nil elseif editNoticeType

enTypes["title"] then return "title" elseif editNoticeType

enTypes["page"] then local title = pcall(function return mw.title.new(tonumber(getEditnoticeMainPage(currPage, editNoticeType))).text end) or nil return title ~= nil and "page" or nil elseif editNoticeType

enTypes["group"] then return "group" elseif editNoticeType

enTypes["category"] then return "category" else return nil end endend

function p.main(frame) local args = getArgs(frame,) local noticeAction = args['notice action'] local noticeArgs = local currentTitle = args['title'] and mw.title.new(args['title']) or mw.title.getCurrentTitle local builder = mw.html.create('div') :attr('id', 'editnotice-area') :addClass('editnotice-area') :css('clear', 'both') :css('width', '100%') local links = builder:tag("div"):addClass('editnotice-links'):addClass(cfg.editnotice_classes):tag("ul") :attr("id", "editnotice-links") :css("display", "block") :addClass('mw-collapsible mw-collapsed') :attr("data-expandtext", cfg.show_editnotice_redlinks) :attr("data-collapsetext", cfg.hide_editnotice_redlinks)

if noticeAction ~= 'view' then local namespace = currentTitle.nsText if namespace

then namespace = 'Main' end local nsNoticeName = pseudoNs.prefixedText .. "/" .. enTypes["namespace"] .. "/" .. currentTitle.rootPageTitle.prefixedText local nsNoticeContent = getNoticeContent(frame, nsNoticeName, noticeArgs) makeLink(builder, links, nsNoticeName, enNames["namespace"], nsNoticeContent) displayEditnotice(builder, 'editnotice-ns', nsNoticeContent) end

if mw.site.namespaces[currentTitle.namespace].hasSubpages then local splitTitle = mw.text.split(currentTitle.fullText, "/") local groupTitle = for k,v in ipairs(splitTitle) do groupTitle = groupTitle .. v local groupNoticeName = pseudoNs.prefixedText .. "/" .. enTypes["group"] .. "/" .. groupTitle local groupNoticeContent = getNoticeContent(frame, groupNoticeName, noticeArgs) makeLink(builder, links, groupNoticeName, enNames["group"] .. ' (' .. groupTitle .. ')', groupNoticeContent) displayEditnotice(builder, 'editnotice-group', groupNoticeContent) groupTitle = groupTitle .. '/' end end if user_editnotice ~= nil and ((currentTitle:hasSubjectNamespace(2) or currentTitle:hasSubjectNamespace(3)) and not currentTitle.isSubpage) then -- display user page notice local userPageNoticeName = currentTitle.prefixedText .. '/' .. cfg.user_editnotice local userPageNoticeContent = getNoticeContent(frame, userPageNoticeName, noticeArgs) makeLink(builder, links, userPageNoticeName, enNames["user"], userPageNoticeContent) displayEditnotice(builder, 'usernotice-page', userPageNoticeContent) end local titleNoticeName = pseudoNs.prefixedText .. "/" .. enTypes["title"] .. "/" .. currentTitle.rootPageTitle.prefixedText local titleNoticeContent = getNoticeContent(frame, titleNoticeName, noticeArgs) makeLink(builder, links, titleNoticeName, enNames["title"], titleNoticeContent) displayEditnotice(builder, 'editnotice-title', titleNoticeContent) local pageNoticeName = pseudoNs.prefixedText .. "/" .. enTypes["page"] .. "/" .. currentTitle.id local pageNoticeContent = getNoticeContent(frame, pageNoticeName, noticeArgs) makeLink(builder, links, pageNoticeName, enNames["page"], pageNoticeContent) displayEditnotice(builder, 'editnotice-page', pageNoticeContent) local categories = mw.title.getCurrentTitle.categories mw.logObject(categories) for k,v in ipairs(categories) do local categoryNoticeName = pseudoNs.prefixedText .. "/" .. enTypes["category"] .. "/" .. v local categoryNoticeContent = getNoticeContent(frame, categoryNoticeName, noticeArgs) makeLink(builder, links, categoryNoticeName, enNames["category"] .. ' (' .. v .. ')', categoryNoticeContent) displayEditnotice(builder, 'editnotice-category', categoryNoticeContent) end builder:tag('div') :css('clear', 'both') return builderend

return p