Exemplo n.º 1
0
 /**
  * Get the wikitext output from a form.
  * @param $form Mixed: Title object of the form to use, or a String form definition.
  * @param $data Array: Associative array as would be POSTed to the form.
  * @return Wikitext
  */
 public static function getWikitext($form, $data = array())
 {
     $printer = new SFFormPrinter();
     if ($form instanceof Title) {
         $article = new Article($form);
         $form = $article->getContent();
     }
     global $wgRequest;
     // Process into arrays and what not
     $data = self::convertFlatToArray($data);
     $oldRequest = $wgRequest;
     $wgRequest = new FauxRequest($data);
     $output = $printer->formHTML($form, count($data) > 0, false);
     list($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = $output;
     $wgRequest = $oldRequest;
     return $data_text;
 }
 public static function newFromFormTag($tag_components)
 {
     global $wgParser;
     $template_name = str_replace('_', ' ', trim($tag_components[1]));
     $tif = SFTemplateInForm::create($template_name);
     $tif->mAddButtonText = wfMessage('sf_formedit_addanother')->text();
     // Cycle through the other components.
     for ($i = 2; $i < count($tag_components); $i++) {
         $component = $tag_components[$i];
         if ($component == 'multiple') {
             $tif->mAllowMultiple = true;
         } elseif ($component == 'strict') {
             $tif->mStrictParsing = true;
         }
         $sub_components = array_map('trim', explode('=', $component, 2));
         if (count($sub_components) == 2) {
             if ($sub_components[0] == 'label') {
                 $tif->mLabel = $sub_components[1];
             } elseif ($sub_components[0] == 'minimum instances') {
                 $tif->mMinAllowed = $sub_components[1];
             } elseif ($sub_components[0] == 'maximum instances') {
                 $tif->mMaxAllowed = $sub_components[1];
             } elseif ($sub_components[0] == 'add button text') {
                 $tif->mAddButtonText = $wgParser->recursiveTagParse($sub_components[1]);
             } elseif ($sub_components[0] == 'embed in field') {
                 // Placeholder on form template level. Assume that the template form def
                 // will have a multiple+placeholder parameters, and get the placeholder value.
                 // We expect something like TemplateName[fieldName], and convert it to the
                 // TemplateName___fieldName form used internally.
                 preg_match('/\\s*(.*)\\[(.*)\\]\\s*/', $sub_components[1], $matches);
                 if (count($matches) > 2) {
                     $tif->mEmbedInTemplate = $matches[1];
                     $tif->mEmbedInField = $matches[2];
                     $tif->mPlaceholder = SFFormPrinter::placeholderFormat($tif->mEmbedInTemplate, $tif->mEmbedInField);
                 }
             }
         }
     }
     return $tif;
 }
 public function additionalHTMLForInput($cur_value, $field_name, $template_name)
 {
     $text = '';
     // Add a field just after the hidden field, within the HTML, to
     // locate where the multiple-templates HTML, stored in
     // $multipleTemplateString, should be inserted.
     if ($this->mHoldsTemplate) {
         $text .= SFFormPrinter::makePlaceholderInFormHTML(SFFormPrinter::placeholderFormat($template_name, $field_name));
     }
     // If this field is disabled, add a hidden field holding
     // the value of this field, because disabled inputs for some
     // reason don't submit their value.
     if ($this->mIsDisabled) {
         if ($field_name == 'free text' || $field_name == '<freetext>') {
             $text .= Html::hidden('sf_free_text', '!free_text!');
         } else {
             if (is_array($cur_value)) {
                 $delimiter = $this->mFieldArgs['delimiter'];
                 $text .= Html::hidden($this->mInputName, implode($delimiter, $cur_value));
             } else {
                 $text .= Html::hidden($this->mInputName, $cur_value);
             }
         }
     }
     if ($this->hasFieldArg('mapping template') || $this->hasFieldArg('mapping property') || $this->hasFieldArg('mapping cargo table') && $this->hasFieldArg('mapping cargo field')) {
         if ($this->hasFieldArg('part_of_multiple')) {
             $text .= Html::hidden($template_name . '[num][map_field][' . $field_name . ']', 'true');
         } else {
             $text .= Html::hidden($template_name . '[map_field][' . $field_name . ']', 'true');
         }
     }
     if ($this->hasFieldArg('unique')) {
         $semantic_property = $this->template_field->getSemanticProperty();
         if ($semantic_property != null) {
             $text .= Html::hidden('input_' . $sfgFieldNum . '_unique_property', $semantic_property);
         }
         $fullCargoField = $this->template_field->getFullCargoField();
         if ($fullCargoField != null) {
             // It's inefficient to get these values via
             // text parsing, but oh well.
             list($cargo_table, $cargo_field) = explode('|', $fullCargoField, 2);
             $text .= Html::hidden('input_' . $sfgFieldNum . '_unique_cargo_table', $cargo_table);
             $text .= Html::hidden('input_' . $sfgFieldNum . '_unique_cargo_field', $cargo_field);
         }
         if ($this->hasFieldArg('unique_for_category')) {
             $text .= Html::hidden('input_' . $sfgFieldNum . '_unique_for_category', $this->getFieldArg('unique_for_category'));
         }
         if ($this->hasFieldArg('unique_for_namespace')) {
             $text .= Html::hidden('input_' . $sfgFieldNum . '_unique_for_namespace', $this->getFieldArg('unique_for_namespace'));
         }
         if ($this->hasFieldArg('unique_for_concept')) {
             $text .= Html::hidden('input_' . $sfgFieldNum . '_unique_for_concept', $this->getFieldArg('unique_for_concept'));
         }
     }
     return $text;
 }