Module:FeaturedTopicSum
This module is used to find out whether a topic is good or featured.
Each call to a new topic, using any of the functions in this module, will use three expensive parser function calls. This means that only 133 different topics can be listed on a page before the page goes over the limit of 500 expensive parser function calls per page (not counting other expensive function calls that might be used).
Usage
From wikitext
From wikitext this module should be used via Template:FeaturedTopicSum. Please see the template page for documentation.
From Lua
First, load the module.
<syntaxhighlight lang="lua"> local mFTS = require('Module:FeaturedTopicSum') </syntaxhighlight>
Then, you can find the status of a topic with the status
function.
<syntaxhighlight lang="lua"> mFTS.status(topic) </syntaxhighlight>
The topic parameter is the name of the topic (a string). For example, it would be "Norid" for Wikipedia:Featured topics/Norid. If the topic is featured, the function will return "FT", and if not, the function will return "GT". (Topics that aren't featured are assumed to be Good Topics.)
It is also possible to use the _main
function in the same manner as you would use Template:FeaturedTopicSum. However, this is not recommended, as using the status
function with if .. then .. else .. end statements is usually more readable, and can be more efficient.
<syntaxhighlight lang="lua"> mFTS._main(args) </syntaxhighlight>
The args parameter is a table of arguments. Please consult the template page for documentation.
-- This module implements {{FeaturedTopicSum}}. local p = {} local function pagesInCategory(category) -- Gets the number of pages in a category. Counting pages in a category is -- expensive, so use pcall in case we are being used on pages with lots of -- expensive function calls. local success, noPages = pcall( mw.site.stats.pagesInCategory, category, 'pages' ) return success and noPages or 0 end function p.status(topic) if not topic then error('no topic specified', 2) end local baseCategory = 'Wikipedia featured topics ' .. topic local noGood = pagesInCategory(baseCategory .. ' good content') local noFeatured = pagesInCategory(baseCategory .. ' featured content') local noOther = pagesInCategory(baseCategory) -- For a topic to be featured: -- 1) it must contain at least two featured articles, and -- 2) 50% or more of its articles must be featured. -- If either of these criteria are not met, the topic is assumed to be a -- good topic. if noFeatured >= 2 and noFeatured >= (noGood + noOther) then return 'FT' else return 'GT' end end function p._main(args) local status = p.status(args[1]) if status == 'FT' then return args[2] else return args[3] end end function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { wrappers = 'Template:FeaturedTopicSum' }) return p._main(args) end return p