Wiki autonumber hack

Rationale edit

If you want to create a more 'formal' type of document it would be nice to have the headings autonumber. In most other cases this is unwanted functionality and headings without any numbering would be nice.

So having a per article option to enable autonumbering for the headings would be the way to go. (Perhaps also an option to disable autonumbering for a particular article?).

Implementation edit

I went looking for the place where the user perference Auto-number headings gets processed and added lines that will check for a new 'Magic Word' __NUMBERHEADINGS__ if the option is not already on.

Details edit

These hacks are based on the MediaWiki 1.5.0 'final' version.

This required hacking three different source file. The modifications of which will be described in the following paragraphs.

includes/Parser.php edit

In Parser.php, on line 2456 in the function formatHeadings, just below the line that says:

$doNumberHeadings = $this->mOptions->getNumberHeadings();

add the following code:

		if (! $doNumberHeadings )
		{
			$doNumberHeadingsObj =& MagicWord::get( MAG_NUMBERHEADINGS );
			if ($doNumberHeadingsObj->matchAndRemove ( $text ) )
			{
				$doNumberHeadings = 1;
			}
		}

includes/MagicWord.php edit

In the list of defines for the keywords, as the last define (below line 57) add the following code:

define('MAG_NUMBERHEADINGS',            44);

The number 44 is the next in the sequence. If the MediaWiki coders decide to implement a new MagicWord this number could become invalid and needs to be updated.

languages/Language.php edit

In Language.php the actual keyword needs to be defined. In the list of magic words definitions (search for __TOC__ to find it. Just below line 196 or there abouts add the following code:

	MAG_NUMBERHEADINGS       => array( 0,    '__NUMBERHEADINGS__'     ),

__NUMBERHEADINGS__

Alternative hack for MWv1.15.1 edit

http://www.mediawiki.org/wiki/User:Revansx#Getting_Behavior_Switch_.22Number_Headings.22_in_MW1.15.1_with_simple_hack