Extension:CustomTOCLength

The CustomTOCLength 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). It is 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 the to-do 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
Please cut and paste the code found below and place it in. Note: stands for the root directory of your MediaWiki installation, the same directory that holds .

Installation
To install this extension, add the following to :

Configuration
sets the number of headings needed for the TOC to show up. Anything larger that 4 will change MediaWiki's 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.

To-do

 * 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.

Extremely ugly workaround:

1. Backup files

cp ~/includes/parser/Parser.php ~/includes/parser/Parser.php.bak sudo vim ~/includes/parser/Parser.php

2. Replace the '4' in below line:

( ( $numMatches >= 4 ) || $this->mForceTocPosition );

With the number that you want, for instance 2:

( ( $numMatches >= 2 ) || $this->mForceTocPosition );


 * Whenever MediaWiki comes with a proper TOC hook, use that instead.