Index: trunk/extensions/SemanticForms/SemanticForms.php |
— | — | @@ -93,12 +93,16 @@ |
94 | 94 | |
95 | 95 | // Page Schemas extension hooks |
96 | 96 | $wgHooks['PageSchemasGetObject'][] = 'SFPageSchemas::createPageSchemasObject' ; |
| 97 | +$wgHooks['PageSchemasGetPageList'][] = 'SFPageSchemas::getPageList' ; |
97 | 98 | $wgHooks['PageSchemasGeneratePages'][] = 'SFPageSchemas::generatePages' ; |
98 | | -$wgHooks['PSParseFieldElements'][] = 'SFPageSchemas::parseFieldElements' ; |
99 | | -$wgHooks['PageSchemasGetPageList'][] = 'SFPageSchemas::getPageList' ; |
| 99 | +$wgHooks['PageSchemasGetSchemaDisplayInfo'][] = 'SFPageSchemas::getFormDisplayInfo' ; |
| 100 | +$wgHooks['PageSchemasGetTemplateDisplayInfo'][] = 'SFPageSchemas::getTemplateDisplayInfo' ; |
| 101 | +$wgHooks['PageSchemasGetFieldDisplayInfo'][] = 'SFPageSchemas::getFormInputDisplayInfo' ; |
100 | 102 | $wgHooks['PageSchemasGetSchemaHTML'][] = 'SFPageSchemas::getSchemaHTML' ; |
| 103 | +$wgHooks['PageSchemasGetTemplateHTML'][] = 'SFPageSchemas::getTemplateHTML' ; |
101 | 104 | $wgHooks['PageSchemasGetFieldHTML'][] = 'SFPageSchemas::getFieldHTML' ; |
102 | 105 | $wgHooks['PageSchemasGetSchemaXML'][] = 'SFPageSchemas::getSchemaXML'; |
| 106 | +$wgHooks['PageSchemasGetTemplateXML'][] = 'SFPageSchemas::getTemplateXML'; |
103 | 107 | $wgHooks['PageSchemasGetFieldXML'][] = 'SFPageSchemas::getFieldXML'; |
104 | 108 | |
105 | 109 | $wgAPIModules['sfautocomplete'] = 'SFAutocompleteAPI'; |
Index: trunk/extensions/SemanticForms/includes/SF_PageSchemas.php |
— | — | @@ -30,6 +30,17 @@ |
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
| 34 | + if ( $objectName == "semanticforms_TemplateDetails" ) { |
| 35 | + foreach ( $xmlForField->children() as $tag => $child ) { |
| 36 | + if ( $tag == $objectName ) { |
| 37 | + foreach ( $child->children() as $tag => $formelem ) { |
| 38 | + $sfarray[(string)$tag] = (string)$formelem; |
| 39 | + } |
| 40 | + $object['sf'] = $sfarray; |
| 41 | + return true; |
| 42 | + } |
| 43 | + } |
| 44 | + } |
34 | 45 | if ( $objectName == "semanticforms_FormInput" ) { |
35 | 46 | foreach ( $xmlForField->children() as $tag => $child ) { |
36 | 47 | if ( $tag == $objectName ) { |
— | — | @@ -76,8 +87,33 @@ |
77 | 88 | } |
78 | 89 | |
79 | 90 | /** |
80 | | - * Creates Page Schemas XML for a specific form field. |
| 91 | + * Creates Page Schemas XML for form information on templates. |
81 | 92 | */ |
| 93 | + public static function getTemplateXML( $request, &$xmlArray ) { |
| 94 | + $xmlPerTemplate = array(); |
| 95 | + $templateNum = -1; |
| 96 | + foreach ( $request->getValues() as $var => $val ) { |
| 97 | + if ( substr( $var, 0, 18 ) == 'sf_template_label_' ) { |
| 98 | + $templateNum = substr( $var, 18 ); |
| 99 | + $xml = '<semanticforms_TemplateDetails>'; |
| 100 | + if ( !empty( $val ) ) { |
| 101 | + $xml .= "<Label>$val</Label>"; |
| 102 | + } |
| 103 | + } elseif ( substr( $var, 0, 23 ) == 'sf_template_addanother_' ) { |
| 104 | + if ( !empty( $val ) ) { |
| 105 | + $xml .= "<AddAnotherText>$val</AddAnotherText>"; |
| 106 | + } |
| 107 | + $xml .= '</semanticforms_TemplateDetails>'; |
| 108 | + $xmlPerTemplate[$templateNum] = $xml; |
| 109 | + } |
| 110 | + } |
| 111 | + $xmlArray['sf'] = $xmlPerTemplate; |
| 112 | + return true; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Creates Page Schemas XML for form fields. |
| 117 | + */ |
82 | 118 | public static function getFieldXML( $request, &$xmlArray ) { |
83 | 119 | $xmlPerField = array(); |
84 | 120 | $fieldNum = -1; |
— | — | @@ -126,35 +162,97 @@ |
127 | 163 | $hasExistingValues = true; |
128 | 164 | } |
129 | 165 | } |
| 166 | + |
| 167 | + // Get all the values from the page schema. |
130 | 168 | if ( array_key_exists( 'name', $form_array ) ) { |
131 | 169 | $formName = $form_array['name']; |
132 | 170 | } else { |
133 | 171 | $formName = ''; |
134 | 172 | } |
135 | | - $text = "\t<p>" . 'Name:' . ' ' . Html::input( 'sf_form_name', $formName, 'text', array( 'size' => 15 ) ) . "</p>\n"; |
136 | 173 | if ( array_key_exists( 'PageNameFormula', $form_array ) ) { |
137 | 174 | $pageNameFormula = $form_array['PageNameFormula']; |
138 | 175 | } else { |
139 | 176 | $pageNameFormula = ''; |
140 | 177 | } |
141 | | - $text .= "\t<p>" . wfMsg( 'sf-pageschemas-pagenameformula' ) . ' ' . Html::input( 'sf_page_name_formula', $pageNameFormula, 'text', array( 'size' => 20 ) ) . "</p>\n"; |
142 | 178 | if ( array_key_exists( 'CreateTitle', $form_array ) ) { |
143 | 179 | $createTitle = $form_array['CreateTitle']; |
144 | 180 | } else { |
145 | 181 | $createTitle = ''; |
146 | 182 | } |
147 | | - $text .= "\t<p>" . wfMsg( 'sf-pageschemas-createtitle' ) . ' ' . Html::input( 'sf_create_title', $createTitle, 'text', array( 'size' => 25 ) ) . "</p>\n"; |
148 | 183 | if ( array_key_exists( 'EditTitle', $form_array ) ) { |
149 | 184 | $editTitle = $form_array['EditTitle']; |
150 | 185 | } else { |
151 | 186 | $editTitle = ''; |
152 | 187 | } |
153 | | - $text .= "\t<p>" . wfMsg( 'sf-pageschemas-edittitle' ) . ' ' . Html::input( 'sf_edit_title', $editTitle, 'text', array( 'size' => 25 ) ) . "</p>\n"; |
| 188 | + |
| 189 | + $text = "\t<p>" . wfMsg( 'ps-namelabel' ) . ' ' . Html::input( 'sf_form_name', $formName, 'text', array( 'size' => 15 ) ) . "</p>\n"; |
| 190 | + // The checkbox isn't actually a field in the page schema - |
| 191 | + // we set it based on whether or not a page formula has been |
| 192 | + // specified. |
| 193 | + $twoStepProcessAttrs = array( 'id' => 'sf-two-step-process' ); |
| 194 | + if ( $pageNameFormula == '' ) { |
| 195 | + $twoStepProcessAttrs['checked'] = true; |
| 196 | + } |
| 197 | + $text .= '<p>' . Html::input( 'sf_two_step_process', null, 'checkbox', $twoStepProcessAttrs ); |
| 198 | + $text .= ' Users must enter the page name before getting to the form (default)'; |
| 199 | + $text .= "</p>\n"; |
| 200 | + $text .= "\t<p id=\"sf-page-name-formula\">" . wfMsg( 'sf-pageschemas-pagenameformula' ) . ' ' . Html::input( 'sf_page_name_formula', $pageNameFormula, 'text', array( 'size' => 30 ) ) . "</p>\n"; |
| 201 | + $text .= "\t<p>" . wfMsg( 'sf-pageschemas-createtitle' ) . ' ' . Html::input( 'sf_create_title', $createTitle, 'text', array( 'size' => 25 ) ) . "</p>\n"; |
| 202 | + $text .= "\t<p id=\"sf-edit-title\">" . wfMsg( 'sf-pageschemas-edittitle' ) . ' ' . Html::input( 'sf_edit_title', $editTitle, 'text', array( 'size' => 25 ) ) . "</p>\n"; |
| 203 | + |
| 204 | + // Javascript for getting the checkbox to hide certain fields |
| 205 | + $text .= <<<END |
| 206 | +<script type="text/javascript"> |
| 207 | +jQuery.fn.toggleFormDataDisplay = function() { |
| 208 | + if (jQuery(this).is(":checked")) { |
| 209 | + jQuery('#sf-page-name-formula').css('display', 'none'); |
| 210 | + jQuery('#sf-edit-title').css('display', 'block'); |
| 211 | + } else { |
| 212 | + jQuery('#sf-page-name-formula').css('display', 'block'); |
| 213 | + jQuery('#sf-edit-title').css('display', 'none'); |
| 214 | + } |
| 215 | +} |
| 216 | +jQuery('#sf-two-step-process').toggleFormDataDisplay(); |
| 217 | +jQuery('#sf-two-step-process').click( function() { |
| 218 | + jQuery(this).toggleFormDataDisplay(); |
| 219 | +} ); |
| 220 | +</script> |
| 221 | + |
| 222 | +END; |
| 223 | + |
154 | 224 | $extensionsHTML['sf'] = array( 'Form', '#CF9', $text, $hasExistingValues ); |
155 | 225 | |
156 | 226 | return true; |
157 | 227 | } |
158 | 228 | |
| 229 | + public static function getTemplateHTML( $templateObj, &$extensionsHTML ) { |
| 230 | + $form_array = array(); |
| 231 | + $hasExistingValues = false; |
| 232 | + $templateLabel = null; |
| 233 | + $addAnotherText = null; |
| 234 | + if ( !is_null( $templateObj ) ) { |
| 235 | + $obj = $templateObj->getObject( 'semanticforms_TemplateDetails' ); |
| 236 | + if ( array_key_exists( 'sf', $obj ) ) { |
| 237 | + $form_array = $obj['sf']; |
| 238 | + $hasExistingValues = true; |
| 239 | + } |
| 240 | + if ( array_key_exists( 'Label', $form_array ) ) { |
| 241 | + $templateLabel = $form_array['Label']; |
| 242 | + } |
| 243 | + if ( array_key_exists( 'AddAnotherText', $form_array ) ) { |
| 244 | + $addAnotherText = $form_array['AddAnotherText']; |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + $text = "\t<p>" . "The following fields are useful if there can be multiple instances of this template." . "</p>\n"; |
| 249 | + $text .= "\t<p>" . 'Label:' . ' ' . Html::input( 'sf_template_label_num', $templateLabel, 'text', array( 'size' => 15 ) ) . "</p>\n"; |
| 250 | + $text .= "\t<p>" . 'Text of button to add another instance (default is "Add another"):' . ' ' . Html::input( 'sf_template_addanother_num', $addAnotherText, 'text', array( 'size' => 25 ) ) . "</p>\n"; |
| 251 | + |
| 252 | + $extensionsHTML['sf'] = array( 'Details for template in form', '#CF9', $text, $hasExistingValues ); |
| 253 | + |
| 254 | + return true; |
| 255 | + } |
| 256 | + |
159 | 257 | /** |
160 | 258 | * Returns the HTML for inputs to define a single form field, |
161 | 259 | * within the Page Schemas 'edit schema' page. |
— | — | @@ -310,10 +408,12 @@ |
311 | 409 | * Creates a form page, when called from the 'generatepages' page |
312 | 410 | * of Page Schemas. |
313 | 411 | */ |
314 | | - public static function generateForm( $formName, $formTitle, $formTemplates, $formDataFromSchema ) { |
| 412 | + public static function generateForm( $formName, $formTitle, |
| 413 | + $formTemplates, $formDataFromSchema, $categoryName ) { |
315 | 414 | global $wgUser; |
316 | 415 | |
317 | 416 | $form = SFForm::create( $formName, $formTemplates ); |
| 417 | + $form->setAssociatedCategory( $categoryName ); |
318 | 418 | if ( array_key_exists( 'PageNameFormula', $formDataFromSchema ) ) { |
319 | 419 | $form->setPageNameFormula( $formDataFromSchema['PageNameFormula'] ); |
320 | 420 | } |
— | — | @@ -338,6 +438,7 @@ |
339 | 439 | global $wgOut, $wgUser; |
340 | 440 | |
341 | 441 | $templatesFromSchema = $psSchemaObj->getTemplates(); |
| 442 | + |
342 | 443 | $form_templates = array(); |
343 | 444 | $jobs = array(); |
344 | 445 | foreach ( $templatesFromSchema as $templateFromSchema ) { |
— | — | @@ -347,21 +448,40 @@ |
348 | 449 | $template_fields = array(); |
349 | 450 | $fullTemplateName = PageSchemas::titleString( $templateTitle ); |
350 | 451 | $template_fields = self::getFieldsFromTemplateSchema( $templateFromSchema ); |
| 452 | + $internalObjProperty = SIOPageSchemas::getInternalObjectPropertyName( $templateFromSchema ); |
| 453 | + // TODO - actually, the category-setting should be |
| 454 | + // smarter than this: if there's more than one |
| 455 | + // template in the schema, it should probably be only |
| 456 | + // the first non-multiple template that includes the |
| 457 | + // category tag. |
| 458 | + if ( $templateFromSchema->isMultiple() ) { |
| 459 | + $categoryName = null; |
| 460 | + } else { |
| 461 | + $categoryName = $psSchemaObj->getCategoryName(); |
| 462 | + } |
351 | 463 | $templateText = SFTemplateField::createTemplateText( $templateName, |
352 | | - $template_fields, null, $psSchemaObj->categoryName, null, null, null ); |
| 464 | + $template_fields, $internalObjProperty, $categoryName, null, null, null ); |
353 | 465 | if ( in_array( $fullTemplateName, $toGenPageList ) ) { |
| 466 | + // print_r($templateFromSchema); |
| 467 | + //print "$templateText"; |
354 | 468 | $params = array(); |
355 | 469 | $params['user_id'] = $wgUser->getId(); |
356 | 470 | $params['page_text'] = $templateText; |
357 | 471 | $jobs[] = new PSCreatePageJob( $templateTitle, $params ); |
358 | 472 | } |
359 | 473 | |
| 474 | + $templateValues = self::getTemplateValues( $templateFromSchema ); |
| 475 | + if ( array_key_exists( 'Label', $templateValues ) ) { |
| 476 | + $templateLabel = $templateValues['Label']; |
| 477 | + } else { |
| 478 | + $templateLabel = null; |
| 479 | + } |
360 | 480 | $form_fields = self::getFormFieldInfo( $templateFromSchema, $template_fields ); |
361 | 481 | // Create template info for form, for use in generating |
362 | 482 | // the form (if it will be generated). |
363 | 483 | $form_template = SFTemplateInForm::create( |
364 | 484 | $templateName, |
365 | | - $templateFromSchema->getLabel(), |
| 485 | + $templateLabel, |
366 | 486 | $templateFromSchema->isMultiple(), |
367 | 487 | null, |
368 | 488 | $form_fields |
— | — | @@ -371,35 +491,88 @@ |
372 | 492 | Job::batchInsert( $jobs ); |
373 | 493 | |
374 | 494 | // Create form, if it's specified. |
375 | | - $form_name = self::getFormName( $psSchemaObj ); |
376 | | - if ( !empty( $form_name ) ) { |
| 495 | + $formName = self::getFormName( $psSchemaObj ); |
| 496 | + if ( !empty( $formName ) ) { |
377 | 497 | $formInfo = self::getMainFormInfo( $psSchemaObj ); |
378 | | - $formTitle = Title::makeTitleSafe( SF_NS_FORM, $form_name ); |
| 498 | + $formTitle = Title::makeTitleSafe( SF_NS_FORM, $formName ); |
379 | 499 | $fullFormName = PageSchemas::titleString( $formTitle ); |
380 | 500 | if ( in_array( $fullFormName, $toGenPageList ) ) { |
381 | | - self::generateForm( $form_name, $formTitle, $form_templates, $formInfo ); |
| 501 | + self::generateForm( $formName, $formTitle, |
| 502 | + $form_templates, $formInfo, $categoryName ); |
382 | 503 | } |
383 | 504 | } |
384 | 505 | return true; |
385 | 506 | } |
386 | 507 | |
| 508 | + public static function getFormDisplayInfo( $schemaXML, &$text_object ) { |
| 509 | + foreach ( $schemaXML->children() as $tag => $child ) { |
| 510 | + if ( $tag == "semanticforms_Form" ) { |
| 511 | + $formName = $child->attributes()->name; |
| 512 | + $values = array(); |
| 513 | + foreach ( $child->children() as $tagName => $prop ) { |
| 514 | + $values[$tagName] = (string)$prop; |
| 515 | + } |
| 516 | + $text_object['sf'] = array( 'Form', $formName, '#CF9', $values ); |
| 517 | + break; |
| 518 | + } |
| 519 | + } |
| 520 | + return true; |
| 521 | + } |
| 522 | + |
| 523 | + public static function getTemplateValues( $psTemplate ) { |
| 524 | + $values = array(); |
| 525 | + if ( $psTemplate instanceof PSTemplate ) { |
| 526 | + $psTemplate = $psTemplate->templateXML; |
| 527 | + } |
| 528 | + foreach ( $psTemplate->children() as $tag => $child ) { |
| 529 | + if ( $tag == "semanticforms_TemplateDetails" ) { |
| 530 | + foreach ( $child->children() as $prop ) { |
| 531 | + $values[$prop->getName()] = (string)$prop; |
| 532 | + } |
| 533 | + } |
| 534 | + } |
| 535 | + return $values; |
| 536 | + } |
| 537 | + |
387 | 538 | /** |
388 | | - * Parses the field elements in the Page Schemas XML. |
| 539 | + * Displays form details for one template in the Page Schemas XML. |
389 | 540 | */ |
390 | | - public static function parseFieldElements( $field_xml, &$text_object ) { |
| 541 | + public static function getTemplateDisplayInfo( $templateXML, &$text_object ) { |
| 542 | + $templateValues = self::getTemplateValues( $templateXML ); |
| 543 | + if ( count( $templateValues ) == 0 ) { |
| 544 | + return true; |
| 545 | + } |
391 | 546 | |
392 | | - foreach ( $field_xml->children() as $tag => $child ) { |
| 547 | + $displayValues = array(); |
| 548 | + foreach ( $templateValues as $key => $value ) { |
| 549 | + if ( $key == 'Label' ) { |
| 550 | + $propName = 'Label'; |
| 551 | + } elseif ( $key == 'AddAnotherText' ) { |
| 552 | + $propName = "'Add another' button"; |
| 553 | + } |
| 554 | + $displayValues[$propName] = $value; |
| 555 | + } |
| 556 | + $text_object['sf'] = array( 'Details for template in form', null, '#CF9', $displayValues ); |
| 557 | + return true; |
| 558 | + } |
| 559 | + |
| 560 | + /** |
| 561 | + * Displays data on a single form input in the Page Schemas XML. |
| 562 | + */ |
| 563 | + public static function getFormInputDisplayInfo( $fieldXML, &$text_object ) { |
| 564 | + foreach ( $fieldXML->children() as $tag => $child ) { |
393 | 565 | if ( $tag == "semanticforms_FormInput" ) { |
394 | | - $text = PageSchemas::tableMessageRowHTML( "paramAttr", wfMsg( 'specialpages-group-sf_group' ), (string)$tag ); |
| 566 | + $inputName = $child->attributes()->name; |
| 567 | + $values = array(); |
395 | 568 | foreach ( $child->children() as $prop ) { |
396 | 569 | if ( $prop->getName() == 'InputType' ) { |
397 | 570 | $propName = 'Input type'; |
398 | 571 | } else { |
399 | 572 | $propName = (string)$prop->attributes()->name; |
400 | 573 | } |
401 | | - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $propName, (string)$prop ); |
| 574 | + $values[$propName] = (string)$prop; |
402 | 575 | } |
403 | | - $text_object['sf'] = $text; |
| 576 | + $text_object['sf'] = array( 'Form input', $inputName, '#CF9', $values ); |
404 | 577 | break; |
405 | 578 | } |
406 | 579 | } |