Module:ManagePages
From Bodhicitta
Documentation for this module may be created at Module:ManagePages/doc
local p = {}
function p.main(frame)
local pargs = frame:getParent().args
local output = '<table id="dataTable" class="smwtable-clean border sortable th-nowrap"><tr>\
<th></th>\
<th>Parent</th>\
<th>Subpage</th>\
<th>Classification</th>\
<th>Type</th>\
<th># Used</th>\
<th>Issue</th>\
<th>Actions</th>\
</tr>'
local query = table.concat({
'[[Classification::Theme]]OR',
'[[Category:Glossary Terms]]OR',
'[[Category:Topic Pages]]OR',
'[[Has parent page::Key Terms||Topics||Glossary||Discover||Explore||Study||Practice]]',
'|?#-=Pagename',
'|?Classification#',
'|?Class#',
'|?Has parent page#',
'|limit=30000'
})
local queryData = mw.smw.ask(query)
if not (queryData and #queryData) then
return ''
end
for i, page in ipairs(queryData) do
local subpageName = frame:preprocess('{{SUBPAGENAME:' .. page.Pagename .. '}}')
if mw.ustring.match( subpageName, '(BCA [0-9]+\.[0-9]+)' ) or
mw.ustring.match( subpageName, '(BCA Chapter [0-9]+)' ) or
mw.ustring.match( subpageName, '(Śikṣā Chapter [0-9]+)' ) or
mw.ustring.match( subpageName, '(SSC [0-9]+\.[0-9]+)' ) or
mw.ustring.match( subpageName, '(SSC Chapter [0-9]+)' ) or
mw.ustring.match( subpageName, '(SSCK [0-9]+)' )
then
else
output = output .. '<tr>'
local iCell = '<td>' .. i .. '</td>'
local parentCell = '<td style="width: max-content;">' .. frame:preprocess('{{BASEPAGENAME:' .. page.Pagename .. '}}') .. '</td>'
local subpageCell = '<td style="min-width: 400px;">[[' .. page.Pagename .. '|' .. subpageName .. ']]</td>'
local classCell = '<td></td>'
if page.Classification then classCell = '<td>' .. page.Classification .. '</td>'
elseif page.Class then classCell = '<td>' .. page.Class .. '</td>'
end
local typeCell = '<td></td>'
local parent = page['Has parent page']
if parent == 'Topics' then
typeCell = '<td class="nowrap" style="background: lightgreen;">Topic</td>'
elseif parent == 'Key Terms' or parent == 'Glossary' then
typeCell = '<td class="nowrap" style="background: lightblue;">Term</td>'
elseif parent == 'Discover' and page.Classification == 'Theme' then
typeCell = '<td class="nowrap" style="background: lightyellow;">Theme - Discover</td>'
elseif parent == 'Explore' and page.Classification == 'Theme' then
typeCell = '<td class="nowrap" style="background: lightyellow;">Theme - Explore</td>'
elseif parent == 'Study' and page.Classification == 'Theme' then
typeCell = '<td class="nowrap" style="background: lightyellow;">Theme - Study</td>'
elseif parent == 'Practice' and page.Classification == 'Theme' then
typeCell = '<td class="nowrap" style="background: lightyellow;">Theme - Practice</td>'
elseif page.Classification ~= 'Theme' and ( parent == 'Discover' or parent == 'Explore' or parent == 'Study' or parent == 'Practice' ) then
typeCell = '<td class="nowrap" style="background: rgb(255 209 206);">' .. parent .. '</td>'
elseif page.Classification == 'Theme' and not parent then
typeCell = '<td class="nowrap" style="background: rgb(255 209 206);">Theme</td>'
end
local count = mw.smw.ask( '[[TermTopics::' .. subpageName .. ']]OR[[Theme::' .. subpageName .. ']]OR[[SubTheme::' .. subpageName .. ']]|format=count' )
local usageCell = '<td>' .. count .. '</td>'
local issueCell = '<td></td>'
if page.Classification ~= 'Theme' and ( parent == 'Discover' or parent == 'Explore' or parent == 'Study' or parent == 'Practice' ) then
issueCell = '<td class="nowrap">Not a theme?</td>'
elseif page.Classification == 'Theme' and not parent then
issueCell = '<td class="nowrap">No parent page!</td>'
end
local actionCell = '<td class="nowrap">[[Special:Edit/' .. page.Pagename .. '|Edit]] · [[Special:MovePage/' .. page.Pagename .. '|Move]] · [[Special:Delete/' .. page.Pagename .. '|Delete]]</td>'
output = output .. iCell .. parentCell .. subpageCell .. classCell .. typeCell .. usageCell .. issueCell .. actionCell .. '</tr>'
end
end
output = output .. '</table>'
return output
end
return p