From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Release status: unmaintained
Implementation Page action
Description Provide selectable templates for new articles based on article title
Author(s) David Tod Sigafoos, mrvs
Latest version 0.3 (2007-10-02)
MediaWiki 1.7.1, 1.9.3, 1.10
License GNU General Public License 2.0 or later
Download #Code
Hooks used
Translate the BoilerplateSelection extension if it is available at translatewiki.net
Check usage and version matrix.


0.1 first release
0.2 Setting flag during foreach. This causes the process to use first hit as the template to use
0.3 made search case insensitive

What can this extension do?[edit]

This extension, based on the original work by User:RouslanZenetl, Extension:Boilerplate, was written to allow use of various Boilerplates based on the articles title.

We are documenting various functions of our system. We want predefined Boilerplate templates used but don't want the user to have to cut/paste the 'template' into a blank page. There are 'User Request', 'Technical Design', 'Functional Design' 'Data Design' and 'Scope' documents (templates). We have defined that articles of these types will have titles like '999 Purchasing Request' or '999 Make Wiki Better Functional'. So we add 'keyword' trigger to the title.

Boilerplateselection depending on article title, will be retrieved on any NEW page and presented to the user in edit mode.

If the user is creating a page which we have no Boilerplate for, we will create a new page using the default Boilerplate template.


Once installed simply create Boilerplate templates. To create a template, simply create a page titled "Template:{0}" where {0} is the name of your page template. So, to create the CopyBooks template below, you need to create a page with a title of "Template:CopyBooks". And, to create the default template that is used when no matches are found, create a page called "Template:Boilerplate".

Then modify $wgBoilerPlateAry as needed. One thing to keep in mind is the order of your key words in the array. An Example

	$wgBoilerPlateAry = array(
		'Copy.Books' => 'CopyBooks',
		'Technical' => 'TechnicalDesign',
		'Scope' => 'Scope',
		'Data Analysis' => 'DataAnalysis');

The process looks at each of the array elements[1] and tries to find a match in the article title. If you have a page with title 'Data Analysis' the process will find it last and try to get the template 'DataAnalysis'. If you had a page called 'Technical Review of Data Analysis' it will find Technical first and use that as your seed.


  • Create a the directory Boilerplateselection in your extensions folder. Then copy/paste the code into Boilerplateselection.php in that folder.
  • Make noted changes to LocalSettings.php
  • Create template Boilerplate and copy this code as the default 'new page'
  • Modify $wgBoilerPlateAry in LocalSettings.php to match your new article keywords and associated boilerplate templates



Changes to LocalSettings.php[edit]

global $wgBoilerPlateAry;
$wgBoilerPlateAry = array('Sandbox' => 'Boilerplate');


 * Extension to boiler plate function with boiler plate
 * defined for specific titles.  Not finding any match will cause
 * the process to load template Boilerplate.
 * If the wgBoilerPlateAry is not defined (in localsettings) it will be
 * set to null and the default behavior of loading 'Boilerplate' (look for
 * template Boilerplate) will happen
 * There is no 'internationalisation' file as no messages are returned
 * @author David Tod Sigafoos <dsig@sigafoos.org>  (based on work by RouslanZenetl)
 * @addtogroup Extensions
 * @copyright © 2007 David Tod Sigafoos
 * @licence GNU General Public Licence 2.0 or later
 *	date	inits	description
 *	22aug07	dsig	modified to drop out of foreach when a target found
 *	11sep09	MCA 	strip <includeonly> from preload text, per http://www.mediawiki.org/wiki/Manual:Creating_pages_with_preloaded_text

#	get out if not part of mediawiki .. 
if( !defined( 'MEDIAWIKI' ) ) {
	echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" );
	die( true );

$wgExtensionCredits['other'][] = array( 
	'name' => 'BoilerPlateSelection', 
	'author' => 'David Tod Sigafoos (based on work by RouslanZenetl)',
	'url' => 'http://www.mediawiki.org/wiki/Extension:BoilerPlateSelection',
	'description' => 'Create new pages based on new page title',
	'license-name' => 'GPL-2.0+' );

 * Set up hooks for discussion threading
 * @param $wgBoilerPlateAry global array of Title key words and associated templates

$wgHooks['EditPage::showEditForm:initial'][] = array('boilerplateselection');

function boilerplateselection($editpage) {
    // EditFormPreloadText
    global $wgOut;
    global $wgBoilerPlateAry;

    //	be sure that our var has been set else just default behavior
    if ( !isset($wgBoilerPlateAry) ) {
    	$wgBoilerPlateAry = '';
    if (!$editpage->preview 
        && $editpage->mArticle->mRevision == NULL 
        && $editpage->mArticle->mTitle->mNamespace==0) {
    	//	set default for article
		$boilerPlateArticle = 'Boilerplate';

		//	get the title for the current article
		$articleTitle = $editpage->mArticle->mTitle->getText();

		// loop through the array to find 'Key Word' in the array and 
		// associated template name
		// 22aug07	dsig	modified to drop out of foreach when a target found
 		$flgFound = false;
		if (is_array( $wgBoilerPlateAry )) {
			foreach ($wgBoilerPlateAry as $bpKey => $bpValue) {
				if ( !$flgFound ) {
					if (  preg_match("/".$bpKey."/i", $articleTitle) ) {
						$boilerPlateArticle = $bpValue;
						$flgFound = true;

			boilerPlateArticle is the associated name with the current title.
			'Boilerplate' is the default "NO HIT" which will cause a blank page
			to be displayed.
		$boilerplate_title = Title::newFromText('Template:' . $boilerPlateArticle);
        $boilerplate_article = new Article($boilerplate_title);
        $preload_text = $boilerplate_article->GetContent();
        $preload_text = preg_replace( '~</?includeonly>~', '', $preload_text ); // MCA

    return true;

Boilerplate Template[edit]

If wgBoilerPlateAry is not defined or you have not used a name the process recognizes then the default is 'Boilerplate' template. This is an example of the template we use.

<br />
     Beginning of page style.  Create an overall TABLE which the rest of the document will fit in 
     If we need an inner table it will be a row of its own.  Else we just stuff content into a row
{| style="background:white; color:black; width:100%;" border="0" cellpadding="5" cellspacing="2" align="center"  style="width:100%; background:#f5fffa; border:1px solid #cef2e0; color:black; align=center; vertical-align:top" 

| <!-- Little table to show a 'heading'  -->
{| style="color:black; width:100%; background-color:#cef2e0; font-weight:bold; border:1px solid #a3bfb1;" border="0" cellpadding="5" cellspacing="2" align="center"
|Source Item (program name) Walkthrough

== Author Info ==
Article Author: enter your name<br/>
Article Date:&nbsp;&nbsp;  mm/dd/yyyy<br/>
Last Update:&nbsp;&nbsp; ''click on the signature button'' <br/> <!-- NOTE: You have to replace the existing name/time (if there) with the signature tab EACH TIME you modify the page -->

== External Links ==
''Enter all external links (to this article) here.  if the link is to another wiki article use the double square brackets''
<pre>[[example here]]</pre>

<!-- Add the rest of your content here -->

See also[edit]