This is an old revision of this page, as edited by Fred Gandt(talk | contribs) at 15:52, 24 March 2016(a few simple comments and preparedness for expansion). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 15:52, 24 March 2016 by Fred Gandt(talk | contribs)(a few simple comments and preparedness for expansion)
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
{{ #invoke:NUMBEROFSECTIONS|main| page name [ # page name [ # ... ] ] | level = section level number(s) }}
Multiple page names (at least one required) are the # delimited names of any Wikipedia pages (including namespaces).
section level(s)(required) is any group of numerals between 1 and 6 (inclusive) e.g.435 or 5 3 4 equates to:
sections with a level 3 ( "===" ), 4 ( "====" ) or 5 ( "=====" ) heading.
{{#invoke:NUMBEROFSECTIONS|main|Wikipedia:Village pump (technical)|level=2}} produces Script error: The function "main" does not exist.
{{#invoke:NUMBEROFSECTIONS|main|Wikipedia:Village pump (technical)#Wikipedia:Village pump (proposals)|level=2}} produces Script error: The function "main" does not exist.
localp={}-- Counting function accepting a string haystack and table of needleslocalfunctioncount(haystack,needles)localnumber=0localindex=1localneedle=needles[index]-- While we have needles to look forwhileneedledo-- find them all in our haystackforminstring.gmatch(haystack,needle)donumber=number+1endindex=index+1needle=needles[index]endreturnnumberend-- Function accepting a page name and section level numbersfunctionp.sections(frame)localneedles={}locallevels=frame.args[2]localtitle=mw.title.new(frame.args[1])-- For every section level numberforlevelinmw.text.gsplit(levels,"")doiflevel~=" "then-- add the needle to our table of needlesneedles[#needles+1]="\n"..string.rep("=",tonumber(level)).."[^=]"endend-- then return how many needles are in our haystackreturncount(title:getContent(),needles)endreturnp