Extension:IndentSections

From Linux Web Expert

MediaWiki extensions manual
IndentSections
Release status: unmaintained
Implementation User interface
Description Indents all sections according to their headers.
Author(s) James Paige
Latest version 0.1 (2008-03-19)
MediaWiki 1.7+
Database changes No
License MIT License
Download See the code section
Quarterly downloads Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin').
Public wikis using Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin').

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

Example

6.0 RESOURCE MANAGEMENT

6.1

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

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

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

  • <translate> <tvar name=1>Copy the code into a file</tvar> and place the file(s) in a directory called <tvar name=name>IndentSections</tvar> in your <tvar name=ext>extensions/</tvar> folder.</translate>
  • <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
    require_once "$IP/extensions/IndentSections/IndentSections.php";
    
  • File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>

Code

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);
	}
}

Contact

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

Similar Extensions

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