Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -151,12 +151,13 @@ |
152 | 152 | SMWPropertyValue::registerProperty( $id, $typeid, $label, true ); |
153 | 153 | } |
154 | 154 | } |
155 | | - /** |
156 | | - * Function to return the Property based on the xml passed from the PageSchema extension |
157 | | - */ |
| 155 | + |
| 156 | + /** |
| 157 | + * Function to return the property based on the XML passed from the Page Schemas extension |
| 158 | + */ |
158 | 159 | public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) { |
159 | | - $sfarray = array(); |
160 | | - $formName=""; |
| 160 | + $sfarray = array(); |
| 161 | + $formName=""; |
161 | 162 | if ( $objectName == "semanticforms_Form" ) { |
162 | 163 | foreach ( $xmlForField->children() as $tag => $child ) { |
163 | 164 | if ( $tag == $objectName ) { |
— | — | @@ -174,41 +175,41 @@ |
175 | 176 | foreach ( $xmlForField->children() as $tag => $child ) { |
176 | 177 | if ( $tag == $objectName ) { |
177 | 178 | foreach ( $child->children() as $prop ) { |
178 | | - if($prop->getName() == 'InputType'){ |
| 179 | + if ( $prop->getName() == 'InputType' ) { |
179 | 180 | $sfarray[$prop->getName()] = (string)$prop; |
180 | | - }else{ |
181 | | - //Remember these values can be null also. While polulating in the page text, take care of that. |
| 181 | + } else { |
| 182 | + //Remember these values can be null also. While polulating in the page text, take care of that. |
182 | 183 | $sfarray[(string)$prop->attributes()->name] = (string)$prop; |
183 | 184 | } |
184 | | - } |
| 185 | + } |
185 | 186 | } |
186 | 187 | } |
187 | | - //Setting value specific to SF in 'sf' index. |
| 188 | + //Setting value specific to SF in 'sf' index. |
188 | 189 | $object['sf'] = $sfarray; |
189 | 190 | } |
190 | 191 | return true; |
191 | 192 | } |
192 | | - public static function getXMLTextForPS( $wgRequest, &$text_extensions ){ |
193 | | - |
| 193 | + |
| 194 | + public static function getXMLTextForPS( $wgRequest, &$text_extensions ) { |
194 | 195 | $Xmltext = ""; |
195 | 196 | $form_xml_text = ""; |
196 | 197 | $templateNum = -1; |
197 | 198 | $xml_text_array = array(); |
198 | 199 | foreach ( $wgRequest->getValues() as $var => $val ) { |
199 | | - if(substr($var,0,13) == 'sf_form_name_'){ |
200 | | - $form_xml_text .= '<semanticforms_Form name="'.$val.'" >'; |
201 | | - }else if(substr($var,0,14) == 'sf_input_type_'){ |
202 | | - $templateNum = substr($var,14,1); |
| 200 | + if ( substr( $var, 0, 13) == 'sf_form_name_' ) { |
| 201 | + $form_xml_text .= '<semanticforms_Form name="'.$val.'" >'; |
| 202 | + } elseif ( substr( $var, 0, 14 ) == 'sf_input_type_') { |
| 203 | + $templateNum = substr( $var, 14, 1 ); |
203 | 204 | $Xmltext .= '<semanticforms_FormInput>'; |
204 | 205 | $Xmltext .= '<InputType>'.$val.'</InputType>'; |
205 | | - }else if(substr($var,0,21) == 'sf_page_name_formula_'){ |
| 206 | + } elseif ( substr( $var, 0, 21 ) == 'sf_page_name_formula_') { |
206 | 207 | $form_xml_text .= '<PageNameFormula>'.$val.'</PageNameFormula>'; |
207 | | - }else if(substr($var,0,16) == 'sf_create_title_'){ |
| 208 | + } elseif ( substr( $var, 0, 16 ) == 'sf_create_title_' ) { |
208 | 209 | $form_xml_text .= '<CreateTitle>'.$val.'</CreateTitle>'; |
209 | | - }else if(substr($var,0,14) == 'sf_edit_title_'){ |
| 210 | + } elseif ( substr( $var, 0, 14 ) == 'sf_edit_title_' ) { |
210 | 211 | $form_xml_text .= '<EditTitle>'.$val.'</EditTitle>'; |
211 | 212 | $form_xml_text .= '</semanticforms_Form>'; |
212 | | - }else if(substr($var,0,14) == 'sf_key_values_'){ |
| 213 | + } elseif ( substr( $var, 0, 14 ) == 'sf_key_values_' ) { |
213 | 214 | if ( $val != '' ) { |
214 | 215 | // replace the comma substitution character that has no chance of |
215 | 216 | // being included in the values list - namely, the ASCII beep |
— | — | @@ -219,58 +220,58 @@ |
220 | 221 | // replace beep back with comma, trim |
221 | 222 | $value = str_replace( "\a", $listSeparator, trim( $value ) ); |
222 | 223 | $param_value = explode( "=", $value ); |
223 | | - if($param_value[1] != null ) { |
224 | | - //handles Parameter name="size">20</Parameter> |
| 224 | + if ( $param_value[1] != null ) { |
| 225 | + //handles Parameter name="size">20</Parameter> |
225 | 226 | $Xmltext .= '<Parameter name="'.$param_value[0].'">'.$param_value[1].'</Parameter>'; |
226 | | - }else{ |
227 | | - //handlers <Parameter name="mandatory" /> |
| 227 | + } else { |
| 228 | + //handles <Parameter name="mandatory" /> |
228 | 229 | $Xmltext .= '<Parameter name="'.$param_value[0].'"/>'; |
229 | 230 | } |
230 | 231 | } |
231 | 232 | $Xmltext .= '</semanticforms_FormInput>'; |
232 | 233 | $xml_text_array[] = $Xmltext; |
233 | 234 | $Xmltext = ''; |
234 | | - } |
235 | | - } |
236 | | - } |
| 235 | + } |
| 236 | + } |
| 237 | + } |
237 | 238 | $text_extensions['sf'] = $xml_text_array; |
238 | 239 | $text_extensions['sf_form'] = $form_xml_text; |
239 | 240 | return true; |
240 | 241 | } |
241 | | - |
242 | | - public static function getFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ){ |
| 242 | + |
| 243 | + public static function getFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ) { |
243 | 244 | $template_fields = array(); |
244 | | - $html_text = ""; |
| 245 | + $html_text = ""; |
245 | 246 | $template_all = $pageSchemaObj->getTemplates(); |
246 | 247 | $html_text_array = array(); |
247 | 248 | $form_html_text = ""; |
248 | 249 | $obj = $pageSchemaObj->getObject('semanticforms_Form'); |
249 | | - |
| 250 | + |
250 | 251 | $form_array = $obj['sf']; |
251 | | - |
252 | | - $form_html_text .= '<fieldset style="background: #CF9;"><legend>Form</legend> |
253 | | - <p> Name: <input size="15" name="sf_form_name_starter" value= "'.$form_array['name'].'" ></p> |
| 252 | + |
| 253 | + $form_html_text .= '<fieldset style="background: #CF9;"><legend>Form</legend> |
| 254 | + <p> Name: <input size="15" name="sf_form_name_starter" value= "'.$form_array['name'].'" ></p> |
254 | 255 | <p> Page name formula: <input size="20" name="sf_page_name_formula_starter" value="'.$form_array['PageNameFormula'].'" ></p> |
255 | | - <p> Title of form for new pages: <input size="25" name="sf_create_title_starter" value="'.$form_array['CreateTitle'].'" ></p> |
256 | | - <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter" value="'.$form_array['EditTitle'].'" ></p> |
257 | | - </fieldset>'; |
| 256 | + <p> Title of form for new pages: <input size="25" name="sf_create_title_starter" value="'.$form_array['CreateTitle'].'" ></p> |
| 257 | + <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter" value="'.$form_array['EditTitle'].'" ></p> |
| 258 | + </fieldset>'; |
258 | 259 | foreach ( $template_all as $template ) { |
259 | | - $field_all = $template->getFields(); |
| 260 | + $field_all = $template->getFields(); |
260 | 261 | $field_count = 0; //counts the number of fields |
261 | | - |
262 | | - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
263 | | - $field_count++; |
| 262 | + |
| 263 | + foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
| 264 | + $field_count++; |
264 | 265 | $sf_array = $field->getObject('semanticforms_FormInput');//this returns an array with property values filled |
265 | | - $form_input_array = $sf_array['sf']; |
| 266 | + $form_input_array = $sf_array['sf']; |
266 | 267 | $html_text = '<fieldset style="background: #CF9;"><legend>Form input</legend> |
267 | 268 | <p> Input type: <input size="15" name="sf_input_type_starter" value='.$form_input_array['InputType'].'></p> |
268 | 269 | <p>Parameter name and its value as a key=value pair,seperated by comma (if a value contains a comma, replace it with "\,"): For eg. Size=20,mandatory=true</p>'; |
269 | 270 | $param_value_str= ""; |
270 | | - foreach($form_input_array as $param => $value){ |
271 | | - if($param != 'InputType'){ |
272 | | - if( $value != null ){ |
| 271 | + foreach($form_input_array as $param => $value) { |
| 272 | + if ( $param != 'InputType' ) { |
| 273 | + if ( $value != null ) { |
273 | 274 | $param_value_str .= $param.'='.$value.', '; |
274 | | - }else{ |
| 275 | + } else { |
275 | 276 | $param_value_str .= $param.'=true, '; |
276 | 277 | } |
277 | 278 | } |
— | — | @@ -280,24 +281,24 @@ |
281 | 282 | } |
282 | 283 | } |
283 | 284 | $text_extensions['sf'] = $html_text_array; |
284 | | - $text_extensions['sf_form']= $form_html_text; |
| 285 | + $text_extensions['sf_form']= $form_html_text; |
285 | 286 | return true; |
286 | | - } |
287 | | - public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) { |
| 287 | + } |
| 288 | + public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) { |
288 | 289 | $html_text = ""; |
289 | | - $form_text = "" ; |
290 | | - $form_text .= '<fieldset style="background: #CF9;"><legend>Form</legend> |
291 | | - <p> Name: <input size="15" name="sf_form_name_starter"></p> |
| 290 | + $form_text = "" ; |
| 291 | + $form_text .= '<fieldset style="background: #CF9;"><legend>Form</legend> |
| 292 | + <p> Name: <input size="15" name="sf_form_name_starter"></p> |
292 | 293 | <p> Page name formula: <input size="20" name="sf_page_name_formula_starter"></p> |
293 | | - <p> Title of form for new pages: <input size="25" name="sf_create_title_starter"></p> |
294 | | - <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter"></p> |
| 294 | + <p> Title of form for new pages: <input size="25" name="sf_create_title_starter"></p> |
| 295 | + <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter"></p> |
295 | 296 | </fieldset>'; |
296 | | - |
| 297 | + |
297 | 298 | $html_text .= '<fieldset style="background: #CF9;"> <legend>Form input</legend> |
298 | 299 | <p> Input type: <input size="15" name="sf_input_type_starter"></p> |
299 | 300 | <p>Parameter name and its value as a key=value pair,seperated by comma (if a value contains a comma, replace it with "\,"): For eg. Size=20,mandatory=true</p> |
300 | 301 | <p><input value="" name="sf_key_values_starter" size="80"></p></fieldset>'; |
301 | | - |
| 302 | + |
302 | 303 | $text_extensions['sf'] = $html_text; |
303 | 304 | $text_extensions['sf_form'] = $form_text; |
304 | 305 | return true; |
— | — | @@ -306,13 +307,13 @@ |
307 | 308 | */ |
308 | 309 | public static function getPageList( $psSchemaObj, &$genPageList ) { |
309 | 310 | global $wgOut, $wgUser; |
310 | | - $template_all = $psSchemaObj->getTemplates(); |
| 311 | + $template_all = $psSchemaObj->getTemplates(); |
311 | 312 | foreach ( $template_all as $template ) { |
312 | | - $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() ); |
| 313 | + $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() ); |
313 | 314 | $genPageList[] = $title; |
314 | 315 | } |
315 | 316 | $form_name = $psSchemaObj->getFormName(); |
316 | | - if( $form_name == null ){ |
| 317 | + if( $form_name == null ) { |
317 | 318 | return true; |
318 | 319 | } |
319 | 320 | //$form = SFForm::create( $form_name, $form_templates ); |
— | — | @@ -324,42 +325,42 @@ |
325 | 326 | */ |
326 | 327 | public static function generatePages( $psSchemaObj, $toGenPageList ) { |
327 | 328 | global $wgOut, $wgUser; |
328 | | - $template_all = $psSchemaObj->getTemplates(); |
| 329 | + $template_all = $psSchemaObj->getTemplates(); |
329 | 330 | $form_templates = array(); |
330 | 331 | $jobs = array(); |
331 | 332 | foreach ( $template_all as $template ) { |
332 | | - $template_array = array(); |
| 333 | + $template_array = array(); |
333 | 334 | $template_array['name'] = $template->getName(); |
334 | 335 | $template_array['category_name'] = $psSchemaObj->categoryName; |
335 | | - $field_all = $template->getFields(); |
| 336 | + $field_all = $template->getFields(); |
336 | 337 | $field_count = 0; //counts the number of fields |
337 | | - $template_fields = array(); |
338 | | - foreach( $field_all as $fieldObj ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
339 | | - $field_count++; |
| 338 | + $template_fields = array(); |
| 339 | + foreach( $field_all as $fieldObj ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
| 340 | + $field_count++; |
340 | 341 | $sf_array = $fieldObj->getObject('semanticforms_FormInput');//this returns an array with property values filled |
341 | 342 | $form_input_array = $sf_array['sf']; |
342 | | - $smw_array = $fieldObj->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
| 343 | + $smw_array = $fieldObj->getObject('semanticmediawiki_Property'); //this returns an array with property values filled |
343 | 344 | $prop_array = $smw_array['smw']; |
344 | 345 | $field_t = SFTemplateField::create( $fieldObj->getName(), $fieldObj->getLabel(), $prop_array['name'], $fieldObj->isList() ,$fieldObj->getDelimiter()); |
345 | 346 | $template_fields[] = $field_t; |
346 | 347 | } |
347 | | - $template_text = SFTemplateField::createTemplateText( $template->getName(), $template_fields, null, $psSchemaObj->categoryName, null, null, null ); |
348 | | - $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() ); |
| 348 | + $template_text = SFTemplateField::createTemplateText( $template->getName(), $template_fields, null, $psSchemaObj->categoryName, null, null, null ); |
| 349 | + $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() ); |
349 | 350 | $key_title = PageSchemas::titleString( $title ); |
350 | | - if( in_array($key_title, $toGenPageList )){ |
| 351 | + if ( in_array( $key_title, $toGenPageList ) ) { |
351 | 352 | $params = array(); |
352 | 353 | $params['user_id'] = $wgUser->getId(); |
353 | | - $params['page_text'] = $template_text; |
| 354 | + $params['page_text'] = $template_text; |
354 | 355 | $jobs[] = new PSCreatePageJob( $title, $params ); |
355 | 356 | } |
356 | 357 | //Creating Form Templates at this time |
357 | 358 | $form_template = SFTemplateInForm::create( $template->getName(), $template->getLabel(), $template->isMultiple() ); |
358 | 359 | $form_templates[] = $form_template; |
359 | | - } |
| 360 | + } |
360 | 361 | Job::batchInsert( $jobs ); |
361 | 362 | $form_name = $psSchemaObj->getFormName(); |
362 | | - $form_array = $psSchemaObj->getFormArray(); |
363 | | - if( $form_name == null ){ |
| 363 | + $form_array = $psSchemaObj->getFormArray(); |
| 364 | + if ( $form_name == null ) { |
364 | 365 | return true; |
365 | 366 | } |
366 | 367 | $form = SFForm::create( $form_name, $form_templates ); |
— | — | @@ -368,38 +369,40 @@ |
369 | 370 | $form->setEditTitle( $form_array['EditTitle'] ); |
370 | 371 | $title = Title::makeTitleSafe( SF_NS_FORM, $form->getFormName() ); |
371 | 372 | $key_title = PageSchemas::titleString( $title ); |
372 | | - if( in_array($key_title, $toGenPageList )){ |
373 | | - $full_text = $form->createMarkup(); |
| 373 | + if( in_array($key_title, $toGenPageList )) { |
| 374 | + $full_text = $form->createMarkup(); |
374 | 375 | $params = array(); |
375 | 376 | $params['user_id'] = $wgUser->getId(); |
376 | | - $params['page_text'] = $full_text; |
| 377 | + $params['page_text'] = $full_text; |
377 | 378 | $jobs = array( new PSCreatePageJob( $title, $params ) ); |
378 | | - Job::batchInsert( $jobs ); |
| 379 | + Job::batchInsert( $jobs ); |
379 | 380 | } |
380 | 381 | return true; |
381 | 382 | } |
| 383 | + |
382 | 384 | /** |
383 | | - *Thi Function parses the Field elements in the xml of the pages. Hooks for PageSchemas extension |
384 | | - */ |
| 385 | + * This function parses the field elements in the XML of the pages. Hooks for Page Schemas extension. |
| 386 | + */ |
385 | 387 | public static function parseFieldElements( $field_xml, &$text_object ) { |
386 | | - |
| 388 | + |
387 | 389 | foreach ( $field_xml->children() as $tag => $child ) { |
388 | | - if ( $tag == "semanticforms_FormInput" ) { |
389 | | - $text = ""; |
390 | | - $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticForms", (string)$tag ); |
391 | | - foreach ( $child->children() as $prop ) { |
392 | | - if( $prop->getName() == 'InputType' ){ |
393 | | - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop->getName(), $prop ); |
394 | | - }else { |
395 | | - $prop_name = (string)$prop->attributes()->name; |
396 | | - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop_name, (string)$prop ); |
397 | | - } |
| 390 | + if ( $tag == "semanticforms_FormInput" ) { |
| 391 | + $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticForms", (string)$tag ); |
| 392 | + foreach ( $child->children() as $prop ) { |
| 393 | + if ( $prop->getName() == 'InputType' ) { |
| 394 | + $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop->getName(), $prop ); |
| 395 | + } else { |
| 396 | + $prop_name = (string)$prop->attributes()->name; |
| 397 | + $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop_name, (string)$prop ); |
398 | 398 | } |
399 | | - $text_object['sf']=$text; |
400 | 399 | } |
| 400 | + $text_object['sf'] = $text; |
| 401 | + break; |
401 | 402 | } |
402 | | - return true; |
| 403 | + } |
| 404 | + return true; |
403 | 405 | } |
| 406 | + |
404 | 407 | public static function initProperties() { |
405 | 408 | global $sfgContLang; |
406 | 409 | |
— | — | @@ -468,14 +471,12 @@ |
469 | 472 | */ |
470 | 473 | public static function printRedirectForm( $title, $page_contents, $edit_summary, $is_save, $is_preview, $is_diff, $is_minor_edit, $watch_this, $start_time, $edit_time ) { |
471 | 474 | global $wgUser, $sfgScriptPath; |
472 | | - |
| 475 | + |
473 | 476 | if ( $is_save ) { |
474 | 477 | $action = "wpSave"; |
475 | | - } |
476 | | - elseif ( $is_preview ) { |
| 478 | + } elseif ( $is_preview ) { |
477 | 479 | $action = "wpPreview"; |
478 | | - } |
479 | | - else { // $is_diff |
| 480 | + } else { // $is_diff |
480 | 481 | $action = "wpDiff"; |
481 | 482 | } |
482 | 483 | |
— | — | @@ -616,7 +617,7 @@ |
617 | 618 | $wgOut->addLink( $link ); |
618 | 619 | } |
619 | 620 | } |
620 | | - |
| 621 | + |
621 | 622 | $scripts = array(); |
622 | 623 | if ( !$sfgUseFormEditPage ) |
623 | 624 | $scripts[] = "$sfgScriptPath/libs/SF_ajax_form_preview.js"; |