Module:High-use
Appearance
Documentation for this module may be created at Module:High-use/doc
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local _fetch = require('Module:Transclusion_count')._fetch -- _fetch waxay fiirisaa doodda 'demo'
local yesno = require('Module:Yesno')
local lang_obj = mw.getContentLanguage() -- halkan waxaa loo dhigay sababtoo ah luqadda waxaa looga baahan yahay meelo badan oo moofalka ah
local large_count_cutoff = 100000
local approx_num_total_pages = 63000000
local user_subpage_info_page = 'Wikipedia:Bogga Isticmaalaha'
local sandbox_module_page = 'Module:bacaadka'
local system_messages_cat = 'Pages used in system messages needing protection'
local sandbox_word = 'bacaadka'
local testcases_word = 'tijaabo'
local doc_word = 'doc'
local function count_from_args(args)
if tonumber(args.count) then -- hubi haddii shaqada mar hore la isticmaalay
return tonumber(args.count) -- ka bax haddii ay saas tahay
end
local count
if yesno(args['fetch']) ~= false then
count = _fetch(args) -- soo qaado tirada isticmaalka (transclusion count)
end
-- isticmaal tirada si cad loo siiyay haddii soo-qaadistu fashilanto
if count == nil and args[1] ~= nil and args[1] ~= '' then
-- u beddel xarigga lambarka luqadda maxaliga ah lambar Lua fahmi karo
count = mw.ustring.gsub(args[1], '+$', '')
count = lang_obj:parseFormattedNumber(args[1])
end
-- haddii qof qoro lambar aan togan ahayn
if count and count > 0 then
return count
end
return nil
end
-- Tallaabooyinka haddii ay jirto tiro aad u badan (ka weyn ama la mid ah 100,000)
local function risk_boolean(args)
if args.risk == true or args.risk == false then
return args.risk
elseif args[1] == 'risk' then
return true
else
local count = count_from_args(args)
if count and count >= large_count_cutoff then
return true
end
end
return false
end
-- shaqadan waxaa loo haynaa is-waafajinta dib u laabashada (backwards compatibility)
function p._risk(args)
return risk_boolean(args) and 'risk' or ''
end
-- shaqadan waxaa loo haynaa is-waafajinta dib u laabashada
function p.risk(frame)
return p._risk(getArgs(frame))
end
-- doodaha count iyo no_percent waxaa loo haynaa is-waafajinta dib u laabashada
function p._num(args, count, no_percent)
if count == nil then
count = count_from_args(args)
end
args.count = count
args.risk = risk_boolean(args)
-- Dhis xarigga natiijada (output string)
local return_value = ''
if args.count == nil and args.risk then
return 'tiro aad u badan oo'
elseif args.count == nil then
return 'badan'
else
-- Isticmaal 2 qof (significant figures) tirooyinka yaryar iyo 3 kuwa waaweyn
local sigfig = 2
if args.count >= large_count_cutoff then
sigfig = 3
end
-- Isu diyaari in lagu wareejiyo qofka ku habboon
local f = math.floor(math.log10(args.count)) - sigfig + 1
-- Wareeji oo geli 'qiyaastii' ama '+' markii ay ku habboon tahay
if yesno(args[2]) == true or (type(args[1]) == 'string' and (mw.ustring.sub(args[1], -1) == '+')) then
-- Hoos u wareeji
return_value = string.format('%s+', lang_obj:formatNum(math.floor( (args.count / 10^(f)) ) * (10^(f))) )
else
-- U wareeji midka ugu dhow
return_value = string.format('qiyaastii %s', lang_obj:formatNum(math.floor( (args.count / 10^(f)) + 0.5) * (10^(f))) )
end
-- Geli boqolleyda boggaga haddii ay u dhowdahay >= 1% iyo markii |no-percent= aan loo dejin yes
no_percent = yesno(no_percent or args['no-percent'])
if args.count and args.count >= approx_num_total_pages/100 and not no_percent then
local num_total_pages = mw.getCurrentFrame():callParserFunction('NUMBEROFPAGES', 'R')
local total_percent = math.floor( ( ( args.count/num_total_pages ) * 100) + 0.5)
if total_percent >= 1 then
return_value = string.format('%s bog, ama qiyaastii %s%% dhammaan', return_value, total_percent)
end
end
end
return return_value
end
-- waxaa isticmaala [[Template:Stub documentation]] iyo boggaga kale
function p.num(frame, count)
return p._num(getArgs(frame), count)
end
function p._text(args, count)
--[=[
Kaliya tus macluumaadka ku saabsan sida tusaalahan loo cusboonaysiiyo
haddii uu qof dhab ahaan wax ka beddelayo bogga.
]=]
local bot_text = (mw.getCurrentFrame():preprocess('{{REVISIONID}}') == '') and ("\n\n----\n'''Farriinta hordhaca ah''':" .. ' Tirada isticmaalka waxaa loo cusboonaysiiyay si otomaatig ah ([[Template:High-use/doc#Technical details|eeg dukumintiga]]).') or ''
if count == nil then
count = count_from_args(args)
end
args.count = count
args.risk = risk_boolean(args)
-- jar /doc, /sandbox iyo /testcases
local title = args.title or (args.demo and args.demo ~= '' and mw.title.new(args.demo, 'Template')) or mw.title.getCurrentTitle()
if title.subpageText == doc_word or title.subpageText == sandbox_word or title.subpageText == testcases_word then
title = title.basePageTitle
end
-- isticmaal /testcases ee tusaalaha asalka ah
local testcases_page = mw.title.new(title.prefixedText .. '/' .. testcases_word)
-- exists waa qaali (expensive)
while testcases_page.basePageTitle.isSubpage and not testcases_page.exists do
testcases_page = mw.title.new(testcases_page.basePageTitle.basePageTitle.prefixedText .. '/' .. testcases_word)
end
local systemMessages = (args['system'] or '') ~= ''
-- Tani waxay si otomaatig ah u soo saartaa URL-ka mashruuca si loo fududeeyo u-beddelka.
local templateCount = ('ee [https://linkcount.toolforge.org/?project=%s&page=%s#transclusions %s bog]'):format(
title:fullUrl():gsub('//(.-)/.*', '%1'),
mw.uri.encode(title.fullText), p._num(args))
local used_on_text = "'''" .. (title:inNamespace('Module') and 'Module-kan Lua' or 'Template-kan') .. ' waxaa loo isticmaalay '
if systemMessages then
used_on_text = used_on_text .. args['system'] ..
((args.count and args.count > 2000) and ("''', iyo " .. templateCount) or ("'''"))
else
used_on_text = used_on_text .. templateCount .. "'''"
end
local sandbox_text = ('bog-hoosaadyada %s [[%s/bacaadka|/bacaadka]] ama [[%s|/tijaabo]], ama [[%s]] kaaga gaarka ah. '):format(
title:inNamespace('Module') and 'module-ka' or 'template-ka',
title.fullText,
testcases_page.fullText,
title:inNamespace('Module') and (sandbox_module_page .. '|modulka bacaadka') or (user_subpage_info_page .. '|bog-hoosaadka isticmaalaha')
)
local infoArg = args['info'] ~= '' and args['info']
if (systemMessages or args.risk) then
local info = '.'
if systemMessages then
info = info .. '<br />Isbeddellada lagu sameeyo waxay sababi karaan isbeddel degdeg ah oo ku yimaada interface-ka isticmaalaha ee ' .. mw.site.namespaces.Project.name .. '.'
end
if infoArg then
info = info .. '<br />' .. infoArg
end
sandbox_text = info .. '<br /> Si looga fogaado carqalad weyn' ..
(args.count and args.count >= large_count_cutoff and ' iyo culayska server-ka' or '') ..
', isbeddel kasta waa in lagu tijaabiyaa ' .. sandbox_text ..
'Isbeddellada la tijaabiyey waxaa lagu dari karaa boggan hal mar oo wax-ka-beddel ah. '
else
sandbox_text = (infoArg and ('.<br />' .. infoArg .. ' I') or ' iyo i') ..
'sbeddellada waxaa laga yaabaa in si weyn loo dareemo. Tijaabi isbeddellada gudaha ' .. sandbox_text
end
local discussion_text = systemMessages and 'Fadlan ka dood isbeddellada ' or 'Tixgeli inaad ka dooddo isbeddellada '
if args[2] ~= nil and args[2] ~= '' and yesno(args[2]) == nil then
discussion_text = string.format('%s gudaha [[%s]]', discussion_text, args[2])
else
discussion_text = string.format('%s ee [[%s|bogga doodda]]', discussion_text, title.talkPageTitle.fullText)
end
return used_on_text .. sandbox_text .. discussion_text .. ' ka hor intaanan la hirgelin.' .. bot_text
end
function p.text(frame, count)
return p._text(getArgs(frame), count)
end
function p._main(args, nocat)
args.count = count_from_args(args)
args.risk = risk_boolean(args)
args.title = (args.demo and args.demo ~= '' and mw.title.new(args.demo, 'Template')) or mw.title.getCurrentTitle()
local image = 'Ambox warning yellow.svg'
local type_param = 'style'
local epilogue = ''
if args['system'] and args['system'] ~= '' then
image = 'Ambox important.svg'
type_param = 'content'
if yesno(nocat or args['nocat']) ~= true and not args.title.isRedirect then
local protection_action = (args.title:inNamespace('File') and 'upload') or 'edit'
local protection_level = require('Module:Effective protection level')._main(protection_action, args.title.fullText)
if protection_level ~= 'sysop' and protection_level ~= 'templateeditor' and protection_level ~= 'interfaceadmin' then
epilogue = mw.getCurrentFrame():expandTemplate {
title = 'sandbox other',
args = {
[2] = '[[Category:' .. system_messages_cat .. ']]'
}
}
end
end
elseif args.risk then
image = 'Ambox warning orange.svg'
type_param = 'content'
end
image = '[[File:' .. image .. '|40px|alt=Digniin|link=]]'
if args['form'] == 'editnotice' then
return mw.getCurrentFrame():expandTemplate{
title = 'editnotice',
args = {
['image'] = image,
['text'] = p._text(args),
['expiry'] = (args['expiry'] or '')
}
} .. epilogue
else
return require('Module:Message box').main('ombox', {
type = type_param,
image = image,
text = p._text(args),
expiry = (args['expiry'] or '')
}) .. epilogue
end
end
function p.main(frame)
return p._main(getArgs(frame))
end
return p