Module:WikiProject quality summary

MyWikiBiz, Author Your Legacy — Sunday April 14, 2024
Jump to navigationJump to search
-- This module's function lookup table, used by the calling context
local p = {}

-- Extract article counts from the WP 1.0 quality categories for a WikiProject
-- Returns a wikitext prose description of the numbers.
-- TODO:
-- * The output is hardcoded, which is inflexible. Move out to calling template?
-- * Need to evaluate if all relevant QA Class categories are handled.
-- * Bad input leads to nonsensical output. Should default to reasonable nil values.
function p.qstats(frame)

  -- Determine the WikiProject for which to grab stats.
  local topic
  if frame.args.topic then -- Use the argument provided.
    topic = frame.args.topic
  elseif frame.args[1] then -- Specialcase use the first (only) positional argument
    topic = frame.args[1]
  else -- By default grab the calling context's title as the topic.
    -- Get the name of the calling page and extract everything after "WikiProject ".
    local title = mw.title.getCurrentTitle()
    topic = string.sub(title.rootText, 13, -1)

  -- WP 1.0 category names follow the pattern "<class>-Class <topic> articles".
  local cSuffix = "-Class " .. topic .. " articles"

  -- Get the article counts for each handled class.
  local qFA    ="FA"    .. cSuffix, "pages")
  local qGA    ="GA"    .. cSuffix, "pages")
  local qA     ="A"     .. cSuffix, "pages")
  local qB     ="B"     .. cSuffix, "pages")
  local qC     ="C"     .. cSuffix, "pages")
  local qStart ="Start" .. cSuffix, "pages")
  local qStub  ="Stub"  .. cSuffix, "pages")
  local qList  ="List"  .. cSuffix, "pages")
  local qFL    ="FL"    .. cSuffix, "pages")

  -- Sum of all class article counts; i.e. all articles in scope of the WikiProject.
  local total = qFA + qGA + qA + qB + qC + qStart + qStub + qList + qFL

  -- Sum of featured content (FA + FL).
  local qFeatured = qFA + qFL

  -- Calculate numerical and percentage proportion of articles at FA or FL level.
  local pnFeatured = total / (qFA + qFL)
  local ppFeatured = (100 / total) * (qFA + qFL)

  -- Calculate numerical and percentage proportion of articles at GA level.
  local pnGood = total / qGA
  local ppGood = (100 / total) * qGA

  -- Calculate numerical and percentage proportion of articles at FA, FL, and GA level.
  local pnForG = total / (qFA + qGA + qFL)
  local ppForG = (100 / total) * (qFA + qGA + qFL)

  -- Create the wikitext output and return it to the calling template.
  local format = [=[There are '''%d''' articles within the scope of the %s project. Currently the project has '''%d''' [[WP:FA|Featured articles]] and [[WP:FL|lists]], or 1 out of every %d articles in the project (%.1f%%). It also has '''%d''' [[WP:GA|Good articles]]: 1 out of every %d articles (%.1f%%). Thus, one in '''%d''' articles in the project is rated GA or higher (%.1f%%).]=]
  return mw.ustring.format(format, total, topic, qFeatured, pnFeatured, ppFeatured, qGA, pnGood, ppGood, pnForG, ppForG)

return p