Extension:CustomTOCLength

This extension allows for adjusting the number of headings in an article required for the table of contents (TOC) to show up. The default value on MediaWiki is 4, install this extension to be able to raise that value if you want TOC only for longer articles (or set it ridiculously high if you want no TOC's at all). Written for Säsongsmat.nu and tested there with MW 1.16 and 1.17.

Usage
Include the extension and set the variable  to any number in LocalSettings.php. Any number larger than 4 will change the number of headings required for TOC to show. It is currently not possible to lower the number (at least 4 headings is always needed for TOC to show up), see todo list below.

If you want to always hide the TOC you can use a very high number, or try Extension:NoTOC that does only this instead.

Download instructions
Please cut and paste the code found below and place it in. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation
To install this extension, add the following to LocalSettings.php:

Configuration parameters
sets the number of headings needed for the TOC to show up. Anything larger that 4 will change MediaWikis behaviour accordingly. Set to a very high number if you never want TOC to show. That will make the TOC disappear completely, not just hide it with CSS.

Todo

 * Make $wgTOCLimit < 4 work by altering Parser::mForceTocPosition. If $parser->mForceTocPosition is already set, or $wgTOCLimit <= 4, do nothing, otherwise set mForceTocPosition to true and insert after first paragraph in $text.
 * Whenever MediaWiki comes with a proper TOC hook, use that instead.