Difference between revisions of "Module:Portal maintenance status/sandbox"
Jump to navigation
Jump to search
test>Evad37 (Create sandbox version of Module:Portal maintenance status) |
test>Evad37 (start making ready for {{Portal maintenance status}}) |
||
| Line 14: | Line 14: | ||
end | end | ||
return cleanArgs | return cleanArgs | ||
| + | end | ||
| + | |||
| + | local content = {} | ||
| + | |||
| + | function makeTemplatePattern(template) | ||
| + | local first = string.sub(template, 1, 1) | ||
| + | local rest = string.sub(template, 2) | ||
| + | local pattern = mw.ustring.format('%s[%s%s]%s%s', '%{%{%s*', mw.ustring.upper(first), mw.ustring.lower(first), rest, '%s*|[^%}]*%}%}') | ||
| + | return pattern | ||
| + | end | ||
| + | |||
| + | function makeParameterPattern(parameter, value) | ||
| + | return mw.ustring.format('%s%s%s%s', '|%s*', parameter, '%s*=%s*', value or '', '%s*[|%}]') | ||
| + | end | ||
| + | |||
| + | function contentContains(content, template, subpattern, leadOnly) | ||
| + | if leadOnly then | ||
| + | content = mw.ustring.gsub(content, "%c%s*==.*","") -- remove first ==Heading== and everything after it | ||
| + | end | ||
| + | local templateWikitext = string.match(content, makeTemplatePattern(template)) | ||
| + | if not templateWikitext then | ||
| + | return false | ||
| + | end | ||
| + | if subpattern then | ||
| + | return string.match(templateWikitext, subpattern) or false | ||
| + | else | ||
| + | return templateWikitext or false | ||
| + | end | ||
| + | end | ||
| + | |||
| + | function getSubjectPageContent(contentNamespaceNumber) | ||
| + | local namespace = mw.site.namespaces[contentNamespaceNumber] ["name"] | ||
| + | local talkTitle = mw.title.getCurrentTitle() | ||
| + | if talkTitle.namespace ~= namespaceNumber + 1 then | ||
| + | return error('Wrong namespace', 0) | ||
| + | end | ||
| + | local subjectTitle = mw.title.new(namespace .. ":" .. talkTitle.text) | ||
| + | return subjectTitle:getContent() | ||
end | end | ||
| Line 27: | Line 65: | ||
end | end | ||
else | else | ||
| − | local | + | portalContent = getSubjectPageContent(100) |
| − | + | end | |
| − | + | ||
| − | + | local status = mw.ustring.match(portalContent, makeTemplatePattern('Portal maintenance status')) or mw.ustring.match(portalContent, makeTemplatePattern('Portal flag')) | |
| − | + | if not status then | |
| − | + | return '' | |
end | end | ||
| − | local | + | local isManuallyMaintained = mw.ustring.match(status, makeParameterPattern(manual, '[~|%}]')) and true or false |
| − | local isNonstandard = mw.ustring. | + | local isNonstandard = mw.ustring.match(status, makeParameterPattern(manual, '[~|%}]')) and true or false |
| − | if (not | + | if (not isManuallyMaintained) and (not isNonstandard) then |
return '' | return '' | ||
end | end | ||
| − | local text = "This portal " .. ( | + | local text = "This portal " .. ( isManuallyMaintained and "'''is [[Wikipedia:WikiProject Portals#Specific portal maintainers|maintained]]'''" or '' ) .. ( ( isManuallyMaintained and isNonstandard ) and ' and ' or '' ) .. ( isNonstandard and "has a '''non-standard layout'''" or '' ) .. '.' |
| − | local subtext = "Please [[WP:CAREFUL|take care]] when editing, especially if using [[WP:ASSISTED|automated editing software]]" .. ( | + | local subtext = "Please [[WP:CAREFUL|take care]] when editing, especially if using [[WP:ASSISTED|automated editing software]]" .. ( isManuallyMaintained and ", and seek [[Wikipedia:Consensus|consensus]] before making major changes." or '.') |
return text .. '<br>' .. '<span style="font-size:90%">' .. subtext .. '</span>' | return text .. '<br>' .. '<span style="font-size:90%">' .. subtext .. '</span>' | ||
Revision as of 02:07, 10 June 2018
Documentation for this module may be created at Module:Portal maintenance status/sandbox/doc
local p = {}
function cleanupArgs(argsTable)
local cleanArgs = {}
for key, val in pairs(argsTable) do
if type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
if val ~= '' then
cleanArgs[key] = val
end
else
cleanArgs[key] = val
end
end
return cleanArgs
end
local content = {}
function makeTemplatePattern(template)
local first = string.sub(template, 1, 1)
local rest = string.sub(template, 2)
local pattern = mw.ustring.format('%s[%s%s]%s%s', '%{%{%s*', mw.ustring.upper(first), mw.ustring.lower(first), rest, '%s*|[^%}]*%}%}')
return pattern
end
function makeParameterPattern(parameter, value)
return mw.ustring.format('%s%s%s%s', '|%s*', parameter, '%s*=%s*', value or '', '%s*[|%}]')
end
function contentContains(content, template, subpattern, leadOnly)
if leadOnly then
content = mw.ustring.gsub(content, "%c%s*==.*","") -- remove first ==Heading== and everything after it
end
local templateWikitext = string.match(content, makeTemplatePattern(template))
if not templateWikitext then
return false
end
if subpattern then
return string.match(templateWikitext, subpattern) or false
else
return templateWikitext or false
end
end
function getSubjectPageContent(contentNamespaceNumber)
local namespace = mw.site.namespaces[contentNamespaceNumber] ["name"]
local talkTitle = mw.title.getCurrentTitle()
if talkTitle.namespace ~= namespaceNumber + 1 then
return error('Wrong namespace', 0)
end
local subjectTitle = mw.title.new(namespace .. ":" .. talkTitle.text)
return subjectTitle:getContent()
end
p.main = function(frame)
local parent = frame.getParent(frame)
local args = cleanupArgs(frame.args)
local demo = args.demo and true or false
local portalContent
if demo then
portalContent = '{{' .. args.demo .. '}}'
if args.demo2 then
portalContent = portalContent .. '{{' .. args.demo2 .. '}}'
end
else
portalContent = getSubjectPageContent(100)
end
local status = mw.ustring.match(portalContent, makeTemplatePattern('Portal maintenance status')) or mw.ustring.match(portalContent, makeTemplatePattern('Portal flag'))
if not status then
return ''
end
local isManuallyMaintained = mw.ustring.match(status, makeParameterPattern(manual, '[~|%}]')) and true or false
local isNonstandard = mw.ustring.match(status, makeParameterPattern(manual, '[~|%}]')) and true or false
if (not isManuallyMaintained) and (not isNonstandard) then
return ''
end
local text = "This portal " .. ( isManuallyMaintained and "'''is [[Wikipedia:WikiProject Portals#Specific portal maintainers|maintained]]'''" or '' ) .. ( ( isManuallyMaintained and isNonstandard ) and ' and ' or '' ) .. ( isNonstandard and "has a '''non-standard layout'''" or '' ) .. '.'
local subtext = "Please [[WP:CAREFUL|take care]] when editing, especially if using [[WP:ASSISTED|automated editing software]]" .. ( isManuallyMaintained and ", and seek [[Wikipedia:Consensus|consensus]] before making major changes." or '.')
return text .. '<br>' .. '<span style="font-size:90%">' .. subtext .. '</span>'
end
return p