Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
BRUS Wikipedia
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Random portal component
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Get shortened URL
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
-- This module implements [[Template:Random portal component]] local p = {} local mRandom = require('Module:Random') local currentTitle = mw.title.getCurrentTitle() -- tracking function added by BHG 29/04/2019 -- called as subPageTrackingCategories(pages, args.max) local function subPageTrackingCategories(pages, max, header) local retval = ""; local thispagetitle = mw.title.getCurrentTitle().text -- don't track DYK etc, only selected/featured articles, biogs etc if ((string.find(header, "/[sS]elected") == -1) and (string.find(header, "/[fF]eatured") == -1)) then return retval end -- no tracking unless we are in Portal namespace if (mw.title.getCurrentTitle().nsText ~= "Portal") then return "" end -- no tracking if this is a subpage if ((mw.ustring.match(thispagetitle, "/") ~= nil) and (thispagetitle ~= "AC/DC")) then return retval end local maxNum = tonumber(max) local availableSubPageCount = maxNum -- Check for missing subpages at end of alleged number range while availableSubPageCount > 0 and not mw.title.new(pages.subpage .. '/' .. tostring(availableSubPageCount)).exists do availableSubPageCount = availableSubPageCount - 1 end if availableSubPageCount < maxNum then retval = retval .. "[[Category:Random portal component with fewer available subpages than specified max]]" else -- Check for spurious subpages beyond end of alleged number range while mw.title.new(pages.subpage .. '/' .. tostring(availableSubPageCount + 1)).exists do availableSubPageCount = availableSubPageCount + 1 end if availableSubPageCount > maxNum then retval = retval .. "[[Category:Random portal component with more available subpages than specified max]]" end end -- before categorising, check what type of subpage we are categorising, and if detected, categorise images separately local subpageType = "subpages" -- generic type local subpageName = pages.subpage subpageName = mw.ustring.gsub(subpageName, "^[^/]*/", "") subpageName = mw.ustring.lower(subpageName) if ((mw.ustring.find(subpageName, "picture", 1, true) ~= nil) or (mw.ustring.find(subpageName, "image", 1, true) ~= nil) or (mw.ustring.find(subpageName, "panorama", 1, true) ~= nil)) then subpageType = "image subpages" end if (availableSubPageCount < 2) then retval = retval .. "[[Category:Random portal component with less than 2 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 5) then retval = retval .. "[[Category:Random portal component with 2β5 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 10) then retval = retval .. "[[Category:Random portal component with 6β10 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 15) then retval = retval .. "[[Category:Random portal component with 11β15 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 20) then retval = retval .. "[[Category:Random portal component with 16β20 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 25) then retval = retval .. "[[Category:Random portal component with 21β25 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 30) then retval = retval .. "[[Category:Random portal component with 26β30 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 40) then retval = retval .. "[[Category:Random portal component with 31β40 available " .. subpageType .. "]]" elseif (availableSubPageCount <= 50) then retval = retval .. "[[Category:Random portal component with 41β50 available " .. subpageType .. "]]" else retval = retval .. "[[Category:Random portal component with over 50 available " .. subpageType .. "]]" end return retval; end local function getRandomNumber(max) -- gets a random integer between 1 and max; max defaults to 1 return mRandom.number{max or 1} end local function expandArg(args, key) -- Emulate how unspecified template parameters appear in wikitext. If the -- specified argument exists, its value is returned, and if not the argument -- name is returned inside triple curly braces. local val = args[key] if val then return val else return string.format('{{{%s}}}', key) end end local function getPages(args) local pages = {} pages.root = args.rootpage or currentTitle.prefixedText pages.subpage = pages.root .. '/' .. expandArg(args, 'subpage') local tries = 10 repeat pages.random = pages.subpage .. '/' .. getRandomNumber(args.max) tries = tries - 1 until tries < 1 or mw.title.new(pages.random).exists pages.footer = 'Template:Box-footer' return pages end local function tryExpandTemplate(frame, title, args) local success, result = pcall(frame.expandTemplate, frame, {title = title, args = args}) if success then return result else local msg = string.format( '<strong class="error">The page "[[%s]]" does not exist.</strong>', title ) if mw.title.getCurrentTitle().namespace == 100 then -- is in the portal namespace msg = msg .. '[[Category:Portals needing attention]]' end return msg end end local function getHeader(frame, pages, header, template) return tryExpandTemplate( frame, template or pages.root .. '/box-header', {header, pages.random} ) end local function getRandomSubpageContent(frame, pages) return tryExpandTemplate( frame, pages.random ) end local function getFooter(frame, pages, link) return tryExpandTemplate( frame, pages.footer, {link} ) end function p._main(args, frame) frame = frame or mw.getCurrentFrame() local pages = getPages(args) local ret = {} ret[#ret + 1] = getHeader(frame, pages, args.header or 'subpage', args.headertemplate) ret[#ret + 1] = getRandomSubpageContent(frame, pages) if not args.footer or not args.footer:find('%S') then ret[#ret + 1] = '<div style="clear:both;"></div></div>' else ret[#ret + 1] = getFooter(frame, pages, string.format( '[[%s|%s]]', pages.subpage, expandArg(args, 'footer') )) end return table.concat(ret, '\n') .. subPageTrackingCategories(pages, args.max, args.header) end function p._nominate(args, frame) frame = frame or mw.getCurrentFrame() local pages = getPages(args) local ret = {} ret[#ret + 1] = getHeader(frame, pages, expandArg(args, 'header'), args.headertemplate) ret[#ret + 1] = getRandomSubpageContent(frame, pages) ret[#ret + 1] = getFooter(frame, pages, string.format( '[[/Nominate/%s|Suggest]] β’ [[%s|%s]] ', expandArg(args, 'subpage'), pages.subpage, args.footer or 'Archive' )) return table.concat(ret, '\n') .. subPageTrackingCategories(pages, args.max, args.header) end local function makeInvokeFunction(func) return function (frame) local args = require('Module:Arguments').getArgs(frame, { trim = false, removeBlanks = false, wrappers = { 'Template:Random portal component', 'Template:Random portal component/BHG-test', 'Template:Random portal component with nominate' } }) return func(args, frame) end end p.main = makeInvokeFunction(p._main) p.nominate = makeInvokeFunction(p._nominate) return p
Summary:
Please note that all contributions to BRUS Wikipedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BRUS Wikipedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
Template:Category link
(
edit
)
Template:Category link/core
(
edit
)
Template:Cl
(
edit
)
Template:Lua
(
edit
)
Template:Main other
(
edit
)
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Navbox
(
edit
)
Template:Nowrap
(
edit
)
Template:Ombox
(
edit
)
Template:Portal templates navbox
(
edit
)
Template:Template link
(
edit
)
Template:Tl
(
edit
)
Template:Tooltip
(
edit
)
Template:Uses Lua
(
edit
)
Template:Yesno
(
edit
)
Template:Yesno-no
(
edit
)
Template:Yesno-yes
(
edit
)
Module:Arguments
(
edit
)
Module:Check for unknown parameters
(
edit
)
Module:List
(
edit
)
Module:Lua banner
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Navbar
(
edit
)
Module:Navbar/configuration
(
edit
)
Module:Navbox
(
edit
)
Module:Navbox/configuration
(
edit
)
Module:Random portal component/doc
(
edit
)
Module:String
(
edit
)
Module:TableTools
(
edit
)
Module:Yesno
(
edit
)