Title: Module:Transclusion count - freem URL Source: https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count Markdown Content: From freem _Documentation for this module may be created at [Module:Transclusion count/doc](https://freemwiki.com/index.php?title=Module:Transclusion\_count/doc&action=edit&redlink=1 "Module:Transclusion count/doc (page does not exist)")_ [](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-1)local p = {}[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-2)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-3)function p._fetch(args)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-4)local template = nil[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-5)local return_value = nil[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-6)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-7)-- Use demo parameter if it exists, otherwise use current template name[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-8)local namespace = mw.title.getCurrentTitle().namespace[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-9)if args["demo"] and args["demo"] ~= "" then[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-10)template = mw.ustring.gsub(args["demo"],"^[Tt]emplate:","")[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-11)elseif namespace == 10 then -- Template namespace[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-12)template = mw.title.getCurrentTitle().text[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-13)elseif namespace == 828 then -- Module namespace[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-14)template = (mw.site.namespaces[828].name .. ":" .. mw.title.getCurrentTitle().text)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-15)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-16)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-17)-- If in template or module namespace, look up count in /data[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-18)if template ~= nil then[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-19)namespace = mw.title.new(template, "Template").namespace[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-20)if namespace == 10 or namespace == 828 then[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-21)template = mw.ustring.gsub(template, "/doc$", "") -- strip /doc from end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-22)template = mw.ustring.gsub(template, "/sandbox$", "") -- strip /sandbox from end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-23)local index = mw.ustring.sub(mw.title.new(template).text,1,1)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-24)local status, data = pcall(function ()[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-25)return(mw.loadData('Module:Transclusion_count/data/' .. (mw.ustring.find(index, "%a") and index or "other")))[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-26)end)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-27)if status then[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-28)return_value = tonumber(data[mw.ustring.gsub(template, " ", "_")])[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-29)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-30)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-31)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-32)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-33)-- If database value doesn't exist, use value passed to template[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-34)if return_value == nil and args[1] ~= nil then[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-35)local arg1=mw.ustring.match(args[1], '[%d,]+')[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-36)if arg1 and arg1 ~= '' then[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-37)return_value = tonumber(mw.getCurrentFrame():callParserFunction('formatnum', arg1, 'R'))[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-38)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-39)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-40)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-41)return return_value[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-42)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-43)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-44)function p.fetch(frame)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-45)return p._fetch(frame.args)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-46)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-47)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-48)-- Tabulate this data for [[Wikipedia:Database reports/Templates transcluded on the most pages]][](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-49)function p.tabulate()[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-50)local list = {}[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-51)for i = 65, 91 do[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-52)local data = mw.loadData('Module:Transclusion count/data/' .. ((i == 91) and 'other' or string.char(i)))[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-53)for name, count in pairs(data) do[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-54)local title = mw.title.new(name, "Template")[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-55)table.insert(list, {title, count})[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-56)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-57)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-58)table.sort(list, function(a, b)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-59)return (a[2] == b[2]) and (a[1] < b[1]) or (a[2] > b[2])[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-60)end)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-61)local lang = mw.getContentLanguage();[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-62)for i = 1, #list do[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-63)local protLevel = ""[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-64)local title = list[i][1][](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-65)if i < 400 then[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-66)-- Stop at 400 to avoid breaching the expensive parser function call limit[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-67)protLevel = title.protectionLevels.edit[1] or "(unprotected)"[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-68)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-69)list[i] = ('|-\n| %d || [[%s]] || %s || %s \n'):format(i, title.fullText:gsub('_', ' '), lang:formatNum(list[i][2]), protLevel)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-70)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-71)return table.concat(list)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-72)end[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-73)[](https://freemwiki.com/index.php?oldid=579612&title=Module%3ATransclusion_count#L-74)return p