Extension:IndentSections

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
IndentSections

Release status:Extension status unmaintained

ImplementationTemplate:Extension#type User interface
DescriptionTemplate:Extension#description Indents all sections according to their headers.
Author(s)Template:Extension#username James Paige
Latest versionTemplate:Extension#version 0.1 (2008-03-19)
MediaWikiTemplate:Extension#mediawiki 1.7+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license MIT License
Download See the code section
Hooks usedTemplate:Extension#hook
BeforePageDisplayManual:Hooks/BeforePageDisplay

Translate the IndentSections extension if it is available at translatewiki.net

Check usage and version matrix.

The IndentSections extension causes all sections to be automatically indented as if they were inside nested blockquotes like this:

Example[edit]

6.0 RESOURCE MANAGEMENT[edit]

6.1[edit]

Executive management shall participate in all resource discussions, and shall make the final decision on all significant expenditures. Resource allocation considerations shall include, but are not limited to: time, personnel requirements, salaries, skill levels, outsourcing, material, processes, and any other factors required to ensure adequate resources are available to achieve customer satisfaction.

6.1.1[edit]

Executive management shall consider data from corrective and preventive action, non-conformance reports, audit results, employee communications, management review activities, customer ratings, financial reports, and business conditions to determine resource requirements.

6.2[edit]

Executive management shall meet at a minimum of once per month or more often, as business dictates, to discuss resource requirements. (See Agenda Check Sheet)


This is suitable for corporate documentation wikis that mainly use sections to represent paragraphs of outline-structured business procedures.

Installation[edit]

  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/IndentSections/IndentSections.php";
    
  • YesY Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code[edit]

IndentSections.php
<?php
/*
 * Copyright © 2008, James Paige & West Coast Aerospace, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * 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.
 */
 
//---Ensure that the script cannot be executed outside of MediaWiki---
if ( !defined( 'MEDIAWIKI' ) ) {
	die( 'This is an extension to MediaWiki and cannot be run standalone.' );
}

//---Display extension properties on MediaWiki---
$wgExtensionCredits['other'][] = array(
	'path' => __FILE__,
	'name' => 'IndentSections',
	'version' => '0.1',
	'author' => 'James Paige',
	'url' => 'https://www.mediawiki.org/wiki/Extension:IndentSections',
	'description' => 'Indents all sections according to their headers'
);

//---Set up the hooks---
$wgHooks['BeforePageDisplay'][] = 'fnIndentSectionsBeforePageDisplay';

//---These two functions do the real work---
function fnIndentSectionsBeforePageDisplay(&$out) {
	$text =& $out->mBodytext;
		for($i = 6; $i > 1; $i -= 1){
		$pattern = sprintf('/(<h%d> ?<span class="editsection">.*?)(<h[1-%d]>)/mse', $i, $i-1);
		$text = preg_replace($pattern, '"<blockquote>$1</blockquote>$2"', $text);
	}
	return true;
}

Contact[edit]

If you have questions or suggestions, please use the talk page here.

Similar Extensions[edit]

For greater control over styling nested sections, see Extension:StyleByHeaderTree.