Extension:MagicNumberedHeadings

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
MagicNumberedHeadings
Release status: stable
Implementation Extended syntax
Description Adds MagicWord __NUMBEREDHEADINGS__ to force autonumbering of the headings of a page
Author(s) Purodha Blissenbach (Purodhatalk)
Latest version 1.14 (2016-09-15)
MediaWiki 1.26+
License GPL
Download see the code section
Hooks used
ParserBeforeInternalParse
MagicWordwgVariableIDs
MagicWordMagicWords
Translate the MagicNumberedHeadings extension if it is available at translatewiki.net
Check usage and version matrix.

The MagicNumberedHeadings extension adds MagicWord __NUMBEREDHEADINGS__ to force autonumbering of the headings of a page. It was created so as to resolve bug 3254.

This extension adds a Magic Word __NUMBEREDHEADINGS__ to the parser. If an article contains this MagicWord, automatic numbering of the headings in this page is performed, regardless of the user preference setting.

Usage[edit]

  • Add "__NUMBEREDHEADINGS__" to any article.

Installation[edit]

Download the code, see below, into this directory:

$IP/extensions/MagicNumberedHeadings/

Note, $IP is the MediaWiki installation directory. You should end up with these files:

$IP/extensions/MagicNumberedHeadings/MagicNumberedHeadings.php
$IP/extensions/MagicNumberedHeadings/MagicNumberedHeadings.i18n.php

Changes to LocalSettings.php[edit]

Add this line towards the end of your $IP/LocalSettings.php

require_once($IP.'/extensions/MagicNumberedHeadings/MagicNumberedHeadings.php');

Note, $IP is the MediaWiki installation directory.

Code[edit]

MagicNumberedHeadings.php[edit]

<?php
/**
 * @copyright Copyright © 2007, Purodha Blissenabch.
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, version 2
 * of the License.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 * See the GNU General Public License for more details.
 */
/**
 * This extension realizes a new MagicWord __NUMBEREDHEADINGS__.
 * If an article contains this MagicWord, numbering of the
 * headings is performed regardless of the user preference setting.
 * 
 * How to use:
 * * include this extension in LocalSettings.php: 
 *   require_once($IP.'/extensions/MagicNoNumberedHeadings.php');
 * * Add "__NUMBEREDHEADINGS__" to any article of your choice.
 * 
 * @author Purodha Blissenbach
 * @version $Revision: 1.14
 */
if ( !defined( 'MEDIAWIKI' ) ) {
	die( "This requires the MediaWiki enviroment." );
}

$wgExtensionCredits['parserhook'][] = array(
	'name' => 'MagicNumberedHeadings',
	'version' => '1.14',
	'author' => 'Purodha Blissenbach',
	'url' => 'https://www.mediawiki.org/wiki/Extension:MagicNumberedHeadings',
	'description' => 'Adds MagicWord "<nowiki>__NUMBEREDHEADINGS__</nowiki>"',
);
$wgHooks['MagicWordMagicWords'][] = 'MagicNumberedHeadingsMagicWordMagicWords';
$wgHooks['MagicWordwgVariableIDs'][] = 'MagicNumberedHeadingsMagicWordwgVariableIDs';
$wgHooks['ParserBeforeInternalParse'][] = 'MagicNumberedHeadingsParserBeforeInternalParse';
$wgExtensionMessagesFiles['MAGICNUMBEREDHEADINGS'] = __DIR__ . '/MagicNumberedHeadings.i18n.php';

function MagicNumberedHeadingsMagicWordMagicWords( &$magicWords ) {
	$magicWords[] = 'MAG_NUMBEREDHEADINGS';
	return true;
}

function MagicNumberedHeadingsMagicWordwgVariableIDs( &$wgVariableIDs ) {
	$wgVariableIDs[] = 'MAG_NUMBEREDHEADINGS';
	return true;
}

function MagicNumberedHeadingsParserBeforeInternalParse( &$parser, &$text, &$strip_state ) {
	if ( MagicWord::get( 'MAG_NUMBEREDHEADINGS' )->matchAndRemove( $text ) ) {
		$parser->mOptions->setNumberHeadings( true );
	}
	return true;
}

MagicNumberedHeadings.i18n.php[edit]

<?php

$messages = array();

$magicWords = array();

$magicWords['en'] = array(
        'MAG_NUMBEREDHEADINGS' => array( 0, '__NUMBEREDHEADINGS__' ),
);

$magicWords['de'] = array(
        'MAG_NUMBEREDHEADINGS' => array( 0, '__ÜBERSCHRIFTENNUMMERIERUNG__' ),
);

$magicWords['ksh'] = array(
        'MAG_NUMBEREDHEADINGS' => array( 0, '__ÖVVERSCHRIFTENUMMERIERE__' ),
);

See also[edit]

Related extensions:

Bugzilla: