Skip to content

Commit 439d2e4

Browse files
authored
Merge pull request #31 from Bapham12/main
Pull request
2 parents 62b3e67 + 190e288 commit 439d2e4

2 files changed

Lines changed: 245 additions & 0 deletions

File tree

IMPORTANT/High-use.lua

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
local p = {}
2+
3+
-- _fetch looks at the "demo" argument.
4+
local _fetch = require('Mô đun:Transclusion_count').fetch
5+
local yesno = require('Mô đun:Yesno')
6+
7+
function p.num(frame, count)
8+
if count == nil then
9+
if yesno(frame.args['fetch']) == false then
10+
if (frame.args[1] or '') ~= '' then count = tonumber(frame.args[1]) end
11+
else
12+
count = _fetch(frame)
13+
end
14+
end
15+
16+
-- Build output string
17+
local return_value = ""
18+
if count == nil then
19+
if frame.args[1] == "risk" then
20+
return_value = "một số lượng lớn"
21+
else
22+
return_value = "rất nhiều"
23+
end
24+
else
25+
-- Use 2 significant figures for smaller numbers and 3 for larger ones
26+
local sigfig = 2
27+
if count >= 100000 then
28+
sigfig = 3
29+
end
30+
31+
-- Prepare to round to appropriate number of sigfigs
32+
local f = math.floor(math.log10(count)) - sigfig + 1
33+
34+
-- Round and insert "approximately" or "+" when appropriate
35+
if (frame.args[2] == "yes") or (mw.ustring.sub(frame.args[1],-1) == "+") then
36+
-- Round down
37+
return_value = string.format("%s+", mw.getContentLanguage():formatNum(math.floor( (count / 10^(f)) ) * (10^(f))) )
38+
else
39+
-- Round to nearest
40+
return_value = string.format("khoảng %s", mw.getContentLanguage():formatNum(math.floor( (count / 10^(f)) + 0.5) * (10^(f))) )
41+
end
42+
43+
-- Insert percentage of pages if that is likely to be >= 1% and when |no-percent= not set to yes
44+
if count and count > 250000 and not yesno (frame:getParent().args['no-percent']) then
45+
local percent = math.floor( ( (count/frame:callParserFunction('NUMBEROFPAGES', 'R') ) * 100) + 0.5)
46+
if percent >= 1 then
47+
return_value = string.format("%s trang, chiếm ≈ %s%% tổng số", return_value, percent)
48+
end
49+
end
50+
end
51+
52+
return return_value
53+
end
54+
55+
-- Actions if there is a large (greater than or equal to 100,000) transclusion count
56+
function p.risk(frame)
57+
local return_value = ""
58+
if frame.args[1] == "risk" then
59+
return_value = "risk"
60+
else
61+
local count = _fetch(frame)
62+
if count and count >= 100000 then return_value = "risk" end
63+
end
64+
return return_value
65+
end
66+
67+
function p.text(frame, count)
68+
-- Only show the information about how this template gets updated if someone
69+
-- is actually editing the page and maybe trying to update the count.
70+
local bot_text = (frame:preprocess("{{REVISIONID}}") == "") and "\n\n----\n'''Thông báo xem trước''': Số lượt nhúng được cập nhật định kì ([[Bản mẫu:High-risk/doc#Chi tiết kĩ thuật|xem tài liệu]])." or ''
71+
72+
if count == nil then
73+
if yesno(frame.args['fetch']) == false then
74+
if (frame.args[1] or '') ~= '' then count = tonumber(frame.args[1]) end
75+
else
76+
count = _fetch(frame)
77+
end
78+
end
79+
local title = mw.title.getCurrentTitle()
80+
if title.subpageText == "doc" or title.subpageText == "sandbox" then
81+
title = title.basePageTitle
82+
end
83+
84+
local systemMessages = frame.args['system']
85+
if frame.args['system'] == '' then
86+
systemMessages = nil
87+
end
88+
89+
-- This retrieves the project URL automatically to simplify localiation.
90+
local templateCount = ('ở rất nhiều trang'):format(
91+
mw.title.getCurrentTitle():fullUrl():gsub('//(.-)/.*', '%1'),
92+
mw.uri.encode(title.fullText), p.num(frame, count))
93+
local used_on_text = "'''" .. (mw.title.getCurrentTitle().namespace == 828 and 'Mô đun Lua' or 'Bản mẫu') .. ' này được sử dụng ';
94+
if systemMessages then
95+
used_on_text = used_on_text .. systemMessages ..
96+
((count and count > 2000) and ("''', và " .. templateCount) or "'''")
97+
else
98+
used_on_text = used_on_text .. templateCount .. "'''"
99+
end
100+
101+
102+
local sandbox_text = ("trang con [[%s/sandbox|/sandbox]], [[%s/testcases|/testcases]] của %s, hoặc ở %s. "):format(
103+
title.fullText, title.fullText,
104+
(mw.title.getCurrentTitle().namespace == 828 and "mô đun" or "bản mẫu"),
105+
mw.title.getCurrentTitle().namespace == 828 and "[[Mô đun:Sandbox|chỗ thử mô đun]]" or "không gian người dùng của bạn"
106+
)
107+
108+
local infoArg = frame.args["info"] ~= "" and frame.args["info"]
109+
if (systemMessages or frame.args[1] == "risk" or (count and count >= 100000) ) then
110+
local info = systemMessages and '.<br />Thay đổi đến nó có thể dẫn đến thay đổi ngay lập tức giao diện người dùng BKDatabase.' or '.'
111+
if infoArg then
112+
info = info .. '<br />' .. infoArg
113+
end
114+
sandbox_text = info .. '<br />Để tránh gây lỗi trên quy mô lớn' ..
115+
(count and count >= 100000 and ' và [[:mw:Manual:Job queue|tải máy chủ]] không cần thiết' or '') ..
116+
', tất cả thay đổi cần được thử nghiệm ở ' .. sandbox_text ..
117+
'Các thay đổi đã được thử nghiệm có thể thêm vào ' .. (mw.title.getCurrentTitle().namespace == 828 and "mô đun" or "bản mẫu") ..
118+
' bằng một sửa đổi duy nhất. '
119+
else
120+
sandbox_text = (infoArg and ('.<br />' .. infoArg .. ' N') or ', vì thế n') ..
121+
'hững thay đổi đến nó sẽ hiện ra rõ ràng. Vui lòng thử nghiệm các thay đổi ở ' .. sandbox_text
122+
end
123+
124+
125+
local discussion_text = (systemMessages or frame.args[1] == "risk" or (count and count >= 100000)) and 'Xin hãy thảo luận các thay đổi ' or 'Cân nhắc thảo luận các thay đổi '
126+
if frame.args["2"] and frame.args["2"] ~= "" and frame.args["2"] ~= "yes" then
127+
discussion_text = string.format("%stại [[%s]]", discussion_text, frame.args["2"])
128+
else
129+
discussion_text = string.format("%stại [[%s|trang thảo luận]]", discussion_text, title.talkPageTitle.fullText )
130+
end
131+
132+
return used_on_text .. sandbox_text .. discussion_text .. ' trước khi áp dụng sửa đổi.' .. bot_text
133+
end
134+
135+
function p.main(frame)
136+
local count = nil
137+
if yesno(frame.args['fetch']) == false then
138+
if (frame.args[1] or '') ~= '' then count = tonumber(frame.args[1]) end
139+
else
140+
count = _fetch(frame)
141+
end
142+
local image = "[[Tập_tin:BrainrotBiohazard.png|40px|alt=Chú ý|link=]]"
143+
local type_param = "style"
144+
local epilogue = ''
145+
if frame.args['system'] and frame.args['system'] ~= '' then
146+
image = "[[Tập_tin:BrainrotBiohazard.png|40px|alt=Chú ý|link=]]"
147+
type_param = "content"
148+
local nocat = frame:getParent().args['nocat'] or frame.args['nocat']
149+
local categorise = (nocat == '' or not yesno(nocat))
150+
if categorise then
151+
epilogue = frame:preprocess('{{Sandbox other||{{#switch:{{#gọi:Effective protection level|{{#switch:{{NAMESPACE}}|{{ns:6}}=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|interfaceadmin=|#default=}}}}')
152+
end
153+
elseif (frame.args[1] == "risk" or (count and count >= 100000)) then
154+
image = "[[Tập_tin:BrainrotBiohazard.png|40px|alt=Chú ý|link=]]"
155+
type_param = "content"
156+
end
157+
158+
if frame.args["form"] == "editnotice" then
159+
return frame:expandTemplate{
160+
title = 'editnotice',
161+
args = {
162+
["image"] = image,
163+
["text"] = p.text(frame, count),
164+
["expiry"] = (frame.args["expiry"] or "")
165+
}
166+
} .. epilogue
167+
else
168+
return require('Mô đun:Message box').main('ombox', {
169+
type = type_param,
170+
image = image,
171+
text = p.text(frame, count),
172+
expiry = (frame.args["expiry"] or "")
173+
}) .. epilogue
174+
end
175+
end
176+
177+
return p

Other/Transclusion count.lua

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
local p = {}
2+
3+
function p._fetch(args)
4+
local template = nil
5+
local return_value = nil
6+
7+
-- Use demo parameter if it exists, otherwise use current template name
8+
local namespace = mw.title.getCurrentTitle().namespace
9+
if args["demo"] and args["demo"] ~= "" then
10+
template = mw.ustring.gsub(args["demo"],"^[Bb]ản mẫu:","")
11+
elseif namespace == 10 then -- Template namespace
12+
template = mw.title.getCurrentTitle().text
13+
elseif namespace == 828 then -- Module namespace
14+
template = (mw.site.namespaces[828].name .. ":" .. mw.title.getCurrentTitle().text)
15+
end
16+
17+
-- If in template or module namespace, look up count in /data
18+
if template ~= nil then
19+
namespace = mw.title.new(template, "Template").namespace
20+
if namespace == 10 or namespace == 828 then
21+
template = mw.ustring.gsub(template, "/doc$", "") -- strip /doc from end
22+
template = mw.ustring.gsub(template, "/tài liệu$", "") -- cho mô đun tại viwiki
23+
template = mw.ustring.gsub(template, "/sandbox$", "") -- strip /sandbox from end
24+
local index = mw.ustring.sub(mw.title.new(template).text,1,1)
25+
local status, data = pcall(function ()
26+
return(mw.loadData('Module:Transclusion_count/data/' .. (mw.ustring.find(index, "[A-Z]") and index or "other")))
27+
end) -- xếp và tìm kiếm Á, Ẩ, Đ, Ý,... trên viwiki tại other
28+
if status then
29+
return_value = tonumber(data[mw.ustring.gsub(template, " ", "_")])
30+
end
31+
end
32+
end
33+
34+
-- If database value doesn't exist, use value passed to template
35+
if return_value == nil and args[1] ~= nil then
36+
local arg1=mw.ustring.match(args[1], '[%d,]+')
37+
if arg1 and arg1 ~= '' then
38+
return_value = tonumber(mw.getCurrentFrame():callParserFunction('formatnum', arg1, 'R'))
39+
end
40+
end
41+
42+
return return_value
43+
end
44+
45+
function p.fetch(frame)
46+
return p._fetch(frame.args)
47+
end
48+
49+
-- Tabulate this data for most used templates on pages
50+
function p.tabulate()
51+
local list = {}
52+
for i = 65, 91 do
53+
local data = mw.loadData('Module:Transclusion count/data/' .. ((i == 91) and 'other' or string.char(i)))
54+
for name, count in pairs(data) do
55+
table.insert(list, {mw.title.new(name, "Template").fullText, count})
56+
end
57+
end
58+
table.sort(list, function(a, b)
59+
return (a[2] == b[2]) and (a[1] < b[1]) or (a[2] > b[2])
60+
end)
61+
local lang = mw.getContentLanguage();
62+
for i = 1, #list do
63+
list[i] = ('|-\n| %d || [[%s]] || %s\n'):format(i, list[i][1]:gsub('_', ' '), lang:formatNum(list[i][2]))
64+
end
65+
return table.concat(list)
66+
end
67+
68+
return p

0 commit comments

Comments
 (0)