Editing Module:High-use

From Georgia Tech Student Wiki

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 can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 3: Line 3:
 
-- _fetch looks at the "demo" argument.
 
-- _fetch looks at the "demo" argument.
 
local _fetch = require('Module:Transclusion_count').fetch
 
local _fetch = require('Module:Transclusion_count').fetch
local yesno = require('Module:Yesno')
 
   
 
function p.num(frame, count)
 
function p.num(frame, count)
if count == nil then
+
if count == nil then count = _fetch(frame) end
if yesno(frame.args['fetch']) == false then
 
if (frame.args[1] or '') ~= '' then count = tonumber(frame.args[1]) end
 
else
 
count = _fetch(frame)
 
end
 
end
 
 
 
 
-- Build output string
 
-- Build output string
Line 40: Line 33:
 
return_value = string.format("approximately %s", mw.getContentLanguage():formatNum(math.floor( (count / 10^(f)) + 0.5) * (10^(f))) )
 
return_value = string.format("approximately %s", mw.getContentLanguage():formatNum(math.floor( (count / 10^(f)) + 0.5) * (10^(f))) )
 
end
 
end
  +
 
-- Insert percentage of pages if that is likely to be >= 1% and when |no-percent= not set to yes
+
-- Insert percentage of pages if that is likely to be >= 1%
if count and count > 250000 and not yesno (frame:getParent().args['no-percent']) then
+
if count and count > 250000 then
 
local percent = math.floor( ( (count/frame:callParserFunction('NUMBEROFPAGES', 'R') ) * 100) + 0.5)
 
local percent = math.floor( ( (count/frame:callParserFunction('NUMBEROFPAGES', 'R') ) * 100) + 0.5)
 
if percent >= 1 then
 
if percent >= 1 then
Line 69: Line 62:
 
local bot_text = (frame:preprocess("{{REVISIONID}}") == "") and "\n\n----\n'''Preview message''': Transclusion count updated automatically ([[Template:High-use/doc#Technical details|see documentation]])." or ''
 
local bot_text = (frame:preprocess("{{REVISIONID}}") == "") and "\n\n----\n'''Preview message''': Transclusion count updated automatically ([[Template:High-use/doc#Technical details|see documentation]])." or ''
 
 
if count == nil then
+
if count == nil then count = _fetch(frame) end
if yesno(frame.args['fetch']) == false then
 
if (frame.args[1] or '') ~= '' then count = tonumber(frame.args[1]) end
 
else
 
count = _fetch(frame)
 
end
 
end
 
 
local title = mw.title.getCurrentTitle()
 
local title = mw.title.getCurrentTitle()
 
if title.subpageText == "doc" or title.subpageText == "sandbox" then
 
if title.subpageText == "doc" or title.subpageText == "sandbox" then
Line 85: Line 72:
 
systemMessages = nil
 
systemMessages = nil
 
end
 
end
  +
 
 
local templateCount = ('on [https://templatecount.toolforge.org/index.php?lang=en&namespace=%s&name=%s %s pages]'):format(
-- This retrieves the project URL automatically to simplify localiation.
 
 
mw.title.getCurrentTitle().namespace, mw.uri.encode(title.text), p.num(frame, count))
local templateCount = ('on [https://linkcount.toolforge.org/index.php?project=%s&page=%s %s pages]'):format(
 
mw.title.getCurrentTitle():fullUrl():gsub('//(.-)/.*', '%1'),
 
mw.uri.encode(title.fullText), p.num(frame, count))
 
 
local used_on_text = "'''This " .. (mw.title.getCurrentTitle().namespace == 828 and "Lua module" or "template") .. ' is used ';
 
local used_on_text = "'''This " .. (mw.title.getCurrentTitle().namespace == 828 and "Lua module" or "template") .. ' is used ';
 
if systemMessages then
 
if systemMessages then
Line 132: Line 117:
   
 
function p.main(frame)
 
function p.main(frame)
local count = nil
+
local count = _fetch(frame)
if yesno(frame.args['fetch']) == false then
 
if (frame.args[1] or '') ~= '' then count = tonumber(frame.args[1]) end
 
else
 
count = _fetch(frame)
 
end
 
 
local image = "[[File:Ambox warning yellow.svg|40px|alt=Warning|link=]]"
 
local image = "[[File:Ambox warning yellow.svg|40px|alt=Warning|link=]]"
 
local type_param = "style"
 
local type_param = "style"
Line 145: Line 125:
 
type_param = "content"
 
type_param = "content"
 
local nocat = frame:getParent().args['nocat'] or frame.args['nocat']
 
local nocat = frame:getParent().args['nocat'] or frame.args['nocat']
local categorise = (nocat == '' or not yesno(nocat))
+
local categorise = (nocat == '' or not require('Module:Yesno')(nocat))
 
if categorise then
 
if categorise then
 
epilogue = frame:preprocess('{{Sandbox other||{{#switch:{{#invoke:Effective protection level|{{#switch:{{NAMESPACE}}|File=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|templateeditor|interfaceadmin=|#default=[[Category:Pages used in system messages needing protection]]}}}}')
 
epilogue = frame:preprocess('{{Sandbox other||{{#switch:{{#invoke:Effective protection level|{{#switch:{{NAMESPACE}}|File=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|templateeditor|interfaceadmin=|#default=[[Category:Pages used in system messages needing protection]]}}}}')

Please note that all contributions to Georgia Tech Student Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see GT Student Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, 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. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: