Extension:Managetemplates

What can this extension do?
ManageTemplates version 1.3 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 has successfully been used and tested also in combination with ManageCategories under MW 1.17.0, php 5.3.3 and php 5.2.6 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.
 * Update: managetemplates.js now determines the cursor's position within the textarea of the editform, so it will put the template-code there. Just click into the editform at the position in which the template shall be placed. The JS works fine in IE9 and Firefox 5. Older browsers have not been tested yet.

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

 * Fixed: The template-tag is not inserted at the cursor's position within the editform, but normally at the bottom/end of MW-markup
 * This extension does not work with FCKEditor, tested with new FCKEditor. Reason: FCKEditor loads the textarea into a new DOM-level, which is invisible for this extension.
 * Like Extension:ManageCategories it also may not work with the new usability initiative (Vector) editor: http://www.mediawiki.org/wiki/Extension:UsabilityInitiative Update: Managetemplates is compatible with the new WikiEditor-extension, which is the successor of the UsabilityInitiative and is used as standard toolbar in MW 1.17.0.
 * 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.

Note

 * In case you use hundreds of templates in your MW this extension may slow down the load of the editpage dialog a bit because it has to query all template-names first. Currently there is no limit to the query!
 * The extension's dropdown box shows only templates which are already in use. If you create templates, which are not used anywhere they will not be displayed in the selectbox. The first time you use a template in an article the selectbox will offer it.

ToDos

 * Fixed: Fix the cursor problem mentioned above
 * Add config-params e.g. to enable setting a limit for the queries
 * More translations of the dialog's texts, create variables for them and put them into a new managetemplates.i18n.php

Bugreports and suggestions

 * Bug reports and suggestions for code optimization are welcome and should please be posted onto the Extension_talk:Managetemplates - page here. I will consider and test code enhancements and changes, and will post an update here if it's stable.
 * Fixed: Unchecking or re-checking an checkbox does not update the editfield