|
| 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 |
0 commit comments