Extension:CreateTpl

=Creating articles with template =

Installation
To install this extension
 * Create file in your /extension directory: CreateTpl.php (see section)
 * Add the following to LocalSettings.php:

Syntax


Overview
Displays a form that creates a page with a specified template. There is a check for the existence of the article. If an article exists, then a choice: either to continue (the contents of articles will be replaced by a template), or go back.

If the template parameter types are specified, then the entry form under the appropriate entry field in parentheses indicate its type. In the presence of input values for these parameters will also be made test for compliance specified in the template type. When discrepancies such as the transition to the creation of articles will be stopped, and will display a diagnostic message.

The parameter types are described in the text of the template as follows: Param_name1: type Param_name2: type

Possible types: number - the number date - date in format dd.mm.yyyy I appreciated this library, but had some trouble getting it working just right. The changes are posted below the original code. ~Juan

Code
";	}	$tt = Title::makeTitle( 10, $tpl_name );	$output .= 'Create a page with a template : getFullURL.'">'.$tpl_name.'    Article title: getVal("articletitle").'" style="width: 200px"/> Params: '.$form_inputs.' ';	$tpl_name_enc = urlencode($tpl_name);	$output = "".str_replace("\n", "", $output)."";	return $output; }

function preloadCreateTemplate(&$editpage, &$output) { global $wgRequest; if ( ($wgRequest->getVal("action") == "edit")	&& ($wgRequest->getVal("create") == "createtpl") ) { $tplname = urldecode($wgRequest->getVal("tplname")); $post_array = $wgRequest->getValues; $editpage->textbox1 = ''; }	return true; }

function preloadCreateTemplate_initial(&$editpage) { global $wgRequest; if ( ($wgRequest->getVal("action") == "edit")	&& ($wgRequest->getVal("create") == "createtpl") ) { $editpage->formtype = "initial"; }	return true; }

function fnCreateTplPositioning ( $tpl_name_enc, &$parser, &$text) { $label = "CreateTpl_$tpl_name_enc"; $text .= "document.getElementById(\"$label\").scrollIntoView(true); "; return true; }

function is_date($i_sDate) { $blnValid = TRUE; // check the format first (may not be necessary as we use checkdate below) if(!ereg ("^[0-9]{2}\.[0-9]{2}\.[0-9]{4}$", $i_sDate)) {   $blnValid = FALSE; }  else //format is okay, check that days, months, years are okay {     $arrDate = explode(".", $i_sDate); // break up date by slash $intDay = $arrDate[0]; $intMonth = $arrDate[1]; $intYear = $arrDate[2]; $intIsDate = checkdate($intMonth, $intDay, $intYear); if(!$intIsDate) {       $blnValid = FALSE; }  }//end else return ($blnValid); } ?>

Some Possible Changes
Originally, writing params as noted above:  Param_name1:type Param_name2:type  didn't work. Partially, this was because the code iteself was looking for newline characters rather than spaces. In the code below it looks for spaces.

Also, I've gone ahead and made it so the input type could be changed. Now for example, it recognizes a textarea type. Look in the switch statement below and add whatever you might need in your form.

Since the error checking wasn't working for me, both in checking and in the Vector skin look and feel, I removed the little tooltips that were displayed.

I redid most of the following code. One could just replace the appropriate section above. Note that I broke certain parts of the original to get the features I wanted. But I like this version much better, and as far as I know doesn't have any obvious bugs.

*/		$form_inputs .= " 		"; }	$tt = Title::makeTitle( 10, $tpl_name ); $output .= 'Create a page with a template : <a href="'.$tt->getFullURL.'">'.$tpl_name.'</a></B><BR/> <form action="" method="POST">