Extension:Managetemplates

What can this extension do?
ManageTemplates version 1.0ß is a derivation of the similar Extension:ManageCategories by Florian Mayrhuber. (That's an extension that allows user-friendly 	 add of categories to an article). ManageTemplates does the same for templates instead of categories: it allows to add existing templates to new articles and also to create new empty templates, which can be modified later. Both extensions can be used together. All inputs or changes to these fields are then transformed to wiki markup and put into the textarea of the editpage. Like ManageCategories, ManageTemplates is located beneath the main edit textarea and consists of: - a select box with all current templates of the wiki - a text field to create a new template - shows currently active templates represented with their names and check boxes

ManageTemplates is still in beta but has successfully been used and tested also in combination with ManageCategories under MW 1.17.0 and php 5.3.3 It only works along with the managetemplates.js which is included by the php-script itself. If you use rewrite-rules on your server and MW-installation make sure that MW can directly access the /extension/managetemplates/managetemplates.js - file.

Installation
''Note: $IP stands for the root directory of your MediaWiki installation.
 * Create the folder /managetemplates within the extension directory of your MW.
 * Create an empty managetemplates.php file and empty managetemplates.js - file
 * Copy the php-code below into the managetemplates.php and the js-code into the managetemplates.js -file
 * Copy both files into your managetemplates -folder on the server.
 * Include the managetemplates.php -script into your LocalSettings.php-file:

Usage

 * To add an existing template to the article pick it from the selectbox and click add.
 * To add a new empty template enter the template name into the text field and click create.
 * To remove a template uncheck the corresponding checkbox.

Code
Code for managetemplates.php

";   return true; }

/**	* retrieve all templates from the db using the mediawiki select wrapper * param: wiki db object * return: resultset with all templates function fnGetAllTemplates( $dbr ) {    $res = $dbr->select('templatelinks', // FROM        array('tl_title', 'tl_from'), // SELECT        array, $fname, array('GROUP BY' => 'tl_title'));// GROUP BY    return $res; }

/**	* determine to which templates the current article * is asigned and return array with results * param: wiki db object, article id	* return: resultset with templates function fnGetArticleTemplates( $dbr, $id ) {   $rs = array; $res = $dbr->select( 'templatelinks', // FROM       array('tl_title', 'tl_from'), // SELECT        array('tl_from' => $id) );// WHERE while ( $row = $dbr->fetchObject($res) ) {       $rs[] = $row->tl_title; }   return $rs; }

Code for managetemplates.js

Known issues

 * This extension may not work with FCKEditor, but this has not been tested yet.
 * Like Extension:ManageCategories it also may not work with the new usability initiative (Vector) editor: http://www.mediawiki.org/wiki/Extension:UsabilityInitiative
 * No translation for other languages than German and English are available at the moment. Although you can easily translate the inline texts within the code.