00001 <?php
00016 class SFFormPrinter {
00017
00018 public $mSemanticTypeHooks;
00019 public $mInputTypeHooks;
00020 public $standardInputsIncluded;
00021 public $mPageTitle;
00022
00023 public function __construct() {
00024
00025 $this->mSemanticTypeHooks = array();
00026 $this->mInputTypeHooks = array();
00027 $this->mInputTypeClasses = array();
00028 $this->mDefaultInputForPropType = array();
00029 $this->mDefaultInputForPropTypeList = array();
00030 $this->mPossibleInputsForPropType = array();
00031 $this->mPossibleInputsForPropTypeList = array();
00032
00033 $this->standardInputsIncluded = false;
00034
00035 $this->registerInputType( 'SFTextInput' );
00036 $this->registerInputType( 'SFTextWithAutocompleteInput' );
00037 $this->registerInputType( 'SFTextAreaInput' );
00038 $this->registerInputType( 'SFTextAreaWithAutocompleteInput' );
00039 $this->registerInputType( 'SFDateInput' );
00040 $this->registerInputType( 'SFDateTimeInput' );
00041 $this->registerInputType( 'SFYearInput' );
00042 $this->registerInputType( 'SFCheckboxInput' );
00043 $this->registerInputType( 'SFDropdownInput' );
00044 $this->registerInputType( 'SFRadioButtonInput' );
00045 $this->registerInputType( 'SFCheckboxesInput' );
00046 $this->registerInputType( 'SFListBoxInput' );
00047 $this->registerInputType( 'SFComboBoxInput' );
00048 $this->registerInputType( 'SFCategoryInput' );
00049 $this->registerInputType( 'SFCategoriesInput' );
00050 }
00051
00052 public function setSemanticTypeHook( $type, $is_list, $function_name, $default_args ) {
00053 $this->mSemanticTypeHooks[$type][$is_list] = array( $function_name, $default_args );
00054 }
00055
00056 public function setInputTypeHook( $input_type, $function_name, $default_args ) {
00057 $this->mInputTypeHooks[$input_type] = array( $function_name, $default_args );
00058 }
00059
00066 public function registerInputType( $inputTypeClass ) {
00067 $inputTypeName = call_user_func( array( $inputTypeClass, 'getName' ) );
00068 $this->mInputTypeClasses[$inputTypeName] = $inputTypeClass;
00069 $this->setInputTypeHook( $inputTypeName, array( $inputTypeClass, 'getHTML' ), array() );
00070
00071 $defaultProperties = call_user_func( array( $inputTypeClass, 'getDefaultPropTypes' ) );
00072 foreach ( $defaultProperties as $propertyType => $additionalValues ) {
00073 $this->setSemanticTypeHook( $propertyType, false, array( $inputTypeClass, 'getHTML' ), $additionalValues );
00074 $this->mDefaultInputForPropType[$propertyType] = $inputTypeName;
00075 }
00076 $defaultPropertyLists = call_user_func( array( $inputTypeClass, 'getDefaultPropTypeLists' ) );
00077 foreach ( $defaultPropertyLists as $propertyType => $additionalValues ) {
00078 $this->setSemanticTypeHook( $propertyType, true, array( $inputTypeClass, 'getHTML' ), $additionalValues );
00079 $this->mDefaultInputForPropTypeList[$propertyType] = $inputTypeName;
00080 }
00081
00082 $otherProperties = call_user_func( array( $inputTypeClass, 'getOtherPropTypesHandled' ) );
00083 foreach ( $otherProperties as $propertyTypeID ) {
00084 if ( array_key_exists( $propertyTypeID, $this->mPossibleInputsForPropType ) ) {
00085 $this->mPossibleInputsForPropType[$propertyTypeID][] = $inputTypeName;
00086 } else {
00087 $this->mPossibleInputsForPropType[$propertyTypeID] = array( $inputTypeName );
00088 }
00089 }
00090 $otherPropertyLists = call_user_func( array( $inputTypeClass, 'getOtherPropTypeListsHandled' ) );
00091 foreach ( $otherPropertyLists as $propertyTypeID ) {
00092 if ( array_key_exists( $propertyTypeID, $this->mPossibleInputsForPropTypeList ) ) {
00093 $this->mPossibleInputsForPropTypeList[$propertyTypeID][] = $inputTypeName;
00094 } else {
00095 $this->mPossibleInputsForPropTypeList[$propertyTypeID] = array( $inputTypeName );
00096 }
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 }
00113
00114 public function getInputType( $inputTypeName ) {
00115 if ( array_key_exists( $inputTypeName, $this->mInputTypeClasses ) ) {
00116 return $this->mInputTypeClasses[$inputTypeName];
00117 } else {
00118 return null;
00119 }
00120 }
00121
00122 public function getDefaultInputType( $isList, $propertyType ) {
00123 if ( $isList ) {
00124 if ( array_key_exists( $propertyType, $this->mDefaultInputForPropTypeList ) ) {
00125 return $this->mDefaultInputForPropTypeList[$propertyType];
00126 } else {
00127 return null;
00128 }
00129 } else {
00130 if ( array_key_exists( $propertyType, $this->mDefaultInputForPropType ) ) {
00131 return $this->mDefaultInputForPropType[$propertyType];
00132 } else {
00133 return null;
00134 }
00135 }
00136 }
00137
00138 public function getPossibleInputTypes( $isList, $propertyType ) {
00139 if ( $isList ) {
00140 if ( array_key_exists( $propertyType, $this->mPossibleInputsForPropTypeList ) ) {
00141 return $this->mPossibleInputsForPropTypeList[$propertyType];
00142 } else {
00143 return array();
00144 }
00145 } else {
00146 if ( array_key_exists( $propertyType, $this->mPossibleInputsForPropType ) ) {
00147 return $this->mPossibleInputsForPropType[$propertyType];
00148 } else {
00149 return array();
00150 }
00151 }
00152 }
00153
00154 public function getAllInputTypes() {
00155 return array_keys( $this->mInputTypeClasses );
00156 }
00157
00165 function showDeletionLog( $out ) {
00166
00167 if ( ! class_exists( 'LogEventsList' ) )
00168 return false;
00169
00170 global $wgUser;
00171 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
00172 $pager = new LogPager( $loglist, 'delete', false, $this->mPageTitle->getPrefixedText() );
00173 $count = $pager->getNumRows();
00174 if ( $count > 0 ) {
00175 $pager->mLimit = 10;
00176 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
00177 $out->addWikiMsg( 'moveddeleted-notice' );
00178 $out->addHTML(
00179 $loglist->beginLogEventsList() .
00180 $pager->getBody() .
00181 $loglist->endLogEventsList()
00182 );
00183 if ( $count > 10 ) {
00184 $out->addHTML( $wgUser->getSkin()->link(
00185 SpecialPage::getTitleFor( 'Log' ),
00186 wfMsgHtml( 'deletelog-fulllog' ),
00187 array(),
00188 array(
00189 'type' => 'delete',
00190 'page' => $this->mPageTitle->getPrefixedText() ) ) );
00191 }
00192 $out->addHTML( '</div>' );
00193 return true;
00194 }
00195
00196 return false;
00197 }
00198
00207 function strReplaceFirst( $search, $replace, $subject ) {
00208 $firstChar = strpos( $subject, $search );
00209 if ( $firstChar !== false ) {
00210 $beforeStr = substr( $subject, 0, $firstChar );
00211 $afterStr = substr( $subject, $firstChar + strlen( $search ) );
00212 return $beforeStr . $replace . $afterStr;
00213 } else {
00214 return $subject;
00215 }
00216 }
00217
00218 static function placeholderFormat( $templateName, $fieldName ) {
00219 return $templateName . '___' . $fieldName;
00220 }
00221
00222 static function makePlaceholderInWikiText( $str ) {
00223 return '@replace_' . $str . '@';
00224 }
00225
00226 static function makePlaceholderInFormHTML( $str ) {
00227 return '@insertHTML_' . $str . '@';
00228 }
00229
00234 function multipleTemplateInstanceTableHTML( $form_is_disabled, $mainText ) {
00235 global $sfgTabIndex, $sfgScriptPath;
00236
00237 $attributes = array(
00238 'tabindex' => $sfgTabIndex,
00239 'class' => 'remover',
00240 );
00241
00242 $rearranger = 'class="rearrangerImage"';
00243
00244 if ( $form_is_disabled ) {
00245 $attributes['disabled'] = 'disabled';
00246 $rearranger = '';
00247 }
00248
00249 $removeButton = Html::input( null, wfMsg( 'sf_formedit_remove' ), 'button', $attributes );
00250
00251 $text = <<<END
00252 <table>
00253 <tr>
00254 <td>$mainText</td>
00255 <td class="removeButton">$removeButton</td>
00256 <td class="instanceRearranger">
00257 <img src="$sfgScriptPath/skins/rearranger.png" $rearranger />
00258 </td>
00259 </tr>
00260 </table>
00261 END;
00262
00263 return $text;
00264 }
00265
00270 function multipleTemplateInstanceHTML( $form_is_disabled, $all_instances_printed, &$section, $instance_num, $add_button_text ) {
00271 global $sfgTabIndex;
00272
00273 if ( ! $all_instances_printed ) {
00274
00275
00276
00277 $section = str_replace( '[num]', "[{$instance_num}a]", $section );
00278
00279 $text = "\t\t" . Html::rawElement( 'div',
00280 array(
00281
00282
00283
00284 'class' => "multipleTemplateInstance multipleTemplate"
00285 ),
00286 $this->multipleTemplateInstanceTableHTML( $form_is_disabled, $section )
00287 ) . "\n";
00288
00289 } else {
00290
00291
00292
00293
00294 $text = "\t\t" . Html::rawElement( 'div',
00295 array(
00296 'class' => "multipleTemplateStarter",
00297 'style' => "display: none",
00298 ),
00299 $this->multipleTemplateInstanceTableHTML( $form_is_disabled, $section )
00300 ) . "\n";
00301
00302 $attributes = array(
00303 'tabindex' => $sfgTabIndex,
00304 'class' => 'multipleTemplateAdder',
00305 );
00306 if ( $form_is_disabled ) $attributes['disabled'] = true;
00307 $button = Html::input( null, Sanitizer::decodeCharReferences( $add_button_text ), 'button', $attributes );
00308 $text .= <<<END
00309 </div><!-- multipleTemplateList -->
00310 <p>$button</p>
00311 </div><!-- multipleTemplateWrapper -->
00312 END;
00313 }
00314 return $text;
00315 }
00316
00327 function formHTML( $form_def, $form_submitted, $source_is_page, $form_id = null, $existing_page_content = null, $page_name = null, $page_name_formula = null, $is_query = false, $is_embedded = false ) {
00328 global $wgRequest, $wgUser, $wgParser;
00329 global $sfgTabIndex;
00330 global $sfgFieldNum;
00331
00332 wfProfileIn( __METHOD__ );
00333
00334
00335 $sfgTabIndex = 1;
00336 $sfgFieldNum = 1;
00337 $source_page_matches_this_form = false;
00338 $form_page_title = null;
00339 $generated_page_name = $page_name_formula;
00340
00341
00342
00343
00344
00345 $form_is_partial = false;
00346 $new_text = "";
00347
00348 $onlyinclude_free_text = false;
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 if ( ! $wgRequest->getCheck( 'partial' ) ) {
00359 $original_page_content = $existing_page_content;
00360 } else {
00361 $original_page_content = null;
00362 if ( $wgRequest->getCheck( 'sf_free_text' ) ) {
00363 $existing_page_content = $wgRequest->getVal( 'sf_free_text' );
00364 $form_is_partial = true;
00365 }
00366 }
00367
00368
00369
00370
00371
00372
00373 if ( $is_embedded ) {
00374
00375
00376 global $wgTitle;
00377 $this->mPageTitle = $wgTitle;
00378 } elseif ( $is_query ) {
00379 $this->mPageTitle = Title::newFromText( 'RunQuery dummy title' );
00380 } elseif ( $page_name === '' || $page_name === null ) {
00381 $this->mPageTitle = Title::newFromText(
00382 $wgRequest->getVal( 'namespace' ) . ":Semantic Forms permissions test" );
00383 } else {
00384 $this->mPageTitle = Title::newFromText( $page_name );
00385 }
00386
00387 global $wgOut;
00388
00389 if ( ! $form_submitted && ( $this->mPageTitle && !$this->mPageTitle->exists() ) ) {
00390 $this->showDeletionLog( $wgOut );
00391 }
00392
00393
00394
00395
00396
00397 if ( !$is_query ) {
00398
00399 $permissionErrors = $this->mPageTitle->getUserPermissionsErrors( 'edit', $wgUser );
00400 $userCanEditPage = count( $permissionErrors ) == 0;
00401 wfRunHooks( 'sfUserCanEditPage', array( $this->mPageTitle, &$userCanEditPage ) );
00402 }
00403 $form_text = "";
00404 if ( $is_query || $userCanEditPage ) {
00405 $form_is_disabled = false;
00406
00407
00408
00409 if ( $wgUser->isAnon() && ! $is_query ) {
00410 $anon_edit_warning = preg_replace( "/'''(.*)'''/", "<strong>$1</strong>", wfMsg( 'anoneditwarning' ) );
00411 $form_text .= "<p>$anon_edit_warning</p>\n";
00412 }
00413 } else {
00414 $form_is_disabled = true;
00415 $wgOut->setPageTitle( wfMsg( 'badaccess' ) );
00416 $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permissionErrors, 'edit' ) );
00417 $wgOut->addHTML( "\n<hr />\n" );
00418 }
00419
00420 $oldParser = $wgParser;
00421
00422 $wgParser = unserialize( serialize( $oldParser ) );
00423 $wgParser->Options( ParserOptions::newFromUser( $wgUser ) );
00424 $wgParser->Title( $this->mPageTitle );
00425 $wgParser->clearState();
00426
00427 $form_def = SFFormUtils::getFormDefinition( $wgParser, $form_def, $form_id );
00428
00429
00430
00431 $form_def_sections = array();
00432 $start_position = 0;
00433 $section_start = 0;
00434 $free_text_was_included = false;
00435 $free_text_preload_page = null;
00436 $free_text_components = array();
00437 $all_values_for_template = array();
00438
00439
00440
00441
00442 $form_def = str_replace( array( '{', '|', '}' ), array( '{', '|', '}' ), $form_def );
00443
00444
00445 $form_def = str_replace( 'standard input|free text', 'field|<freetext>', $form_def );
00446 while ( $brackets_loc = strpos( $form_def, "{{{", $start_position ) ) {
00447 $brackets_end_loc = strpos( $form_def, "}}}", $brackets_loc );
00448 $bracketed_string = substr( $form_def, $brackets_loc + 3, $brackets_end_loc - ( $brackets_loc + 3 ) );
00449 $tag_components = SFUtils::getFormTagComponents( $bracketed_string );
00450 $tag_title = trim( $tag_components[0] );
00451 if ( $tag_title == 'for template' || $tag_title == 'end template' ) {
00452
00453 $section = substr( $form_def, $section_start, $brackets_loc - $section_start );
00454 $form_def_sections[] = $section;
00455 $section_start = $brackets_loc;
00456 }
00457 $start_position = $brackets_loc + 1;
00458 }
00459 $form_def_sections[] = trim( substr( $form_def, $section_start ) );
00460
00461
00462
00463
00464
00465 $all_fields = array();
00466 $data_text = "";
00467 $template_name = "";
00468 $allow_multiple = false;
00469 $instance_num = 0;
00470 $all_instances_printed = false;
00471 $strict_parsing = false;
00472
00473
00474 $curPlaceholder = null;
00475
00476
00477 $placeholderFields = array();
00478
00479 for ( $section_num = 0; $section_num < count( $form_def_sections ); $section_num++ ) {
00480 $start_position = 0;
00481 $template_text = "";
00482
00483
00484 $section = " " . $form_def_sections[$section_num];
00485
00486
00487 $multipleTemplateString = "";
00488
00489 while ( $brackets_loc = strpos( $section, '{{{', $start_position ) ) {
00490 $brackets_end_loc = strpos( $section, "}}}", $brackets_loc );
00491 $bracketed_string = substr( $section, $brackets_loc + 3, $brackets_end_loc - ( $brackets_loc + 3 ) );
00492 $tag_components = SFUtils::getFormTagComponents( $bracketed_string );
00493 $tag_title = trim( $tag_components[0] );
00494
00495
00496
00497 if ( $tag_title == 'for template' ) {
00498 $old_template_name = $template_name;
00499 $template_name = trim( $tag_components[1] );
00500 $tif = SFTemplateInForm::create( $template_name );
00501 $query_template_name = str_replace( ' ', '_', $template_name );
00502 $add_button_text = wfMsg( 'sf_formedit_addanother' );
00503
00504
00505 $query_template_name = str_replace( '.', '_', $query_template_name );
00506
00507 $query_template_name = str_replace( "'", "\'", $query_template_name );
00508
00509 for ( $i = 2; $i < count( $tag_components ); $i++ ) {
00510 $component = $tag_components[$i];
00511 if ( $component == 'multiple' ) $allow_multiple = true;
00512 if ( $component == 'strict' ) $strict_parsing = true;
00513 $sub_components = array_map( 'trim', explode( '=', $component, 2 ) );
00514 if ( count( $sub_components ) == 2 ) {
00515 if ( $sub_components[0] == 'label' ) {
00516 $template_label = $sub_components[1];
00517 } elseif ( $sub_components[0] == 'add button text' ) {
00518 $add_button_text = $sub_components[1];
00519 } elseif ( $sub_components[0] == 'embed in field' ) {
00520
00521
00522
00523
00524 preg_match( '/\s*(.*)\[(.*)\]\s*/', $sub_components[1], $matches );
00525 $curPlaceholder = ( count( $matches ) > 2 ) ? self::placeholderFormat( $matches[1], $matches[2] ) : null;
00526 unset ( $matches );
00527 }
00528 }
00529 }
00530
00531
00532
00533
00534
00535 if ( $old_template_name != $template_name ) {
00536 if ( isset( $template_label ) ) {
00537 $multipleTemplateString .= "<fieldset>\n";
00538 $multipleTemplateString .= "<legend>$template_label</legend>\n";
00539 }
00540
00541
00542
00543 if ( $allow_multiple ) {
00544 $multipleTemplateString .= "\t" . '<div class="multipleTemplateWrapper">' . "\n";
00545 $multipleTemplateString .= "\t" . '<div class="multipleTemplateList">' . "\n";
00546 }
00547 }
00548 if ( $curPlaceholder == null ) {
00549 $form_text .= $multipleTemplateString;
00550 }
00551 $template_text .= "{{" . $template_name;
00552 $all_fields = $tif->getAllFields();
00553
00554 $section = substr_replace( $section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
00555 $template_instance_query_values = $wgRequest->getArray( $query_template_name );
00556
00557
00558
00559
00560
00561 $existing_template_text = null;
00562 if ( $source_is_page || $form_is_partial ) {
00563
00564
00565 $search_template_str = str_replace( '_', ' ', $template_name );
00566 $preg_match_template_str = str_replace(
00567 array( '/', '(', ')' ),
00568 array( '\/', '\(', '\)' ),
00569 $search_template_str );
00570 $found_instance = preg_match( '/{{' . $preg_match_template_str . '\s*[\|}]/i', str_replace( '_', ' ', $existing_page_content ) );
00571 if ( $allow_multiple ) {
00572
00573
00574
00575
00576
00577
00578
00579 if ( $found_instance ) {
00580 $instance_num++;
00581 } else {
00582 $all_instances_printed = true;
00583 }
00584 }
00585
00586
00587 if ( $found_instance ) {
00588 $matches = array();
00589 $search_pattern = '/{{' . $preg_match_template_str . '\s*[\|}]/i';
00590 $content_str = str_replace( '_', ' ', $existing_page_content );
00591 preg_match( $search_pattern, $content_str, $matches, PREG_OFFSET_CAPTURE );
00592
00593 if ( array_key_exists( 0, $matches ) && array_key_exists( 1, $matches[0] ) ) {
00594 $start_char = $matches[0][1];
00595 $fields_start_char = $start_char + 2 + strlen( $search_template_str );
00596
00597 while ( in_array( $existing_page_content[$fields_start_char], array( ' ', '\n' ) ) ) {
00598 $fields_start_char++;
00599 }
00600
00601 if ( $existing_page_content[$fields_start_char] == '|' ) {
00602 $fields_start_char++;
00603 }
00604 $template_contents = array( '0' => '' );
00605
00606
00607 $field = "";
00608 $uncompleted_square_brackets = 0;
00609 $uncompleted_curly_brackets = 2;
00610 $template_ended = false;
00611 for ( $i = $fields_start_char; ! $template_ended && ( $i < strlen( $existing_page_content ) ); $i++ ) {
00612 $c = $existing_page_content[$i];
00613 if ( $c == '[' ) {
00614 $uncompleted_square_brackets++;
00615 } elseif ( $c == ']' && $uncompleted_square_brackets > 0 ) {
00616 $uncompleted_square_brackets--;
00617 } elseif ( $c == '{' ) {
00618 $uncompleted_curly_brackets++;
00619 } elseif ( $c == '}' && $uncompleted_curly_brackets > 0 ) {
00620 $uncompleted_curly_brackets--;
00621 }
00622
00623 $template_ended = ( $uncompleted_curly_brackets == 0 && $uncompleted_square_brackets == 0 );
00624 $field_ended = ( $c == '|' && $uncompleted_square_brackets == 0 && $uncompleted_curly_brackets <= 2 );
00625 if ( $template_ended || $field_ended ) {
00626
00627
00628 if ( $template_ended ) {
00629 $field = substr( $field, 0, - 1 );
00630 }
00631
00632
00633
00634 $sub_fields = explode( '=', $field, 2 );
00635 if ( count( $sub_fields ) > 1 ) {
00636 $template_contents[trim( $sub_fields[0] )] = trim( $sub_fields[1] );
00637 } else {
00638 $template_contents[] = trim( $sub_fields[0] );
00639 }
00640 $field = '';
00641 } else {
00642 $field .= $c;
00643 }
00644 }
00645
00646
00647
00648
00649
00650 if ( $uncompleted_curly_brackets > 0 || $uncompleted_square_brackets > 0 ) {
00651 $form_text .= "\t" . '<div class="warningbox">' . wfMsg( 'sf_formedit_mismatchedbrackets', $this->mPageTitle->getFullURL( array( 'action' => 'edit' ) ) ) . "</div>\n<br clear=\"both\" />\n";
00652 }
00653 $existing_template_text = substr( $existing_page_content, $start_char, $i - $start_char );
00654
00655
00656 if ( $existing_page_content && $form_is_partial && $wgRequest->getCheck( 'partial' ) ) {
00657
00658
00659 if ( strpos( $existing_page_content, $existing_template_text ) !== false ) {
00660 $existing_page_content = str_replace( '{{{insertionpoint}}}', '', $existing_page_content );
00661 $existing_page_content = str_replace( $existing_template_text, '{{{insertionpoint}}}', $existing_page_content );
00662 }
00663 } else {
00664 $existing_page_content = $this->strReplaceFirst( $existing_template_text, '', $existing_page_content );
00665 }
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 $source_page_matches_this_form = true;
00678
00679 }
00680 }
00681 }
00682
00683
00684
00685
00686
00687
00688 if ( ( ! $source_is_page ) && $allow_multiple && $wgRequest ) {
00689 $all_instances_printed = true;
00690 if ( $old_template_name != $template_name ) {
00691 $all_values_for_template = $wgRequest->getArray( $query_template_name );
00692 }
00693 if ( $all_values_for_template ) {
00694 $cur_key = key( $all_values_for_template );
00695
00696
00697 if ( $cur_key == 'num' ) {
00698 unset( $all_values_for_template[$cur_key] );
00699 $cur_key = key( $all_values_for_template );
00700 }
00701 if ( $template_instance_query_values = current( $all_values_for_template ) ) {
00702 $all_instances_printed = false;
00703 unset( $all_values_for_template[$cur_key] );
00704 }
00705 }
00706 }
00707
00708
00709
00710 } elseif ( $tag_title == 'end template' ) {
00711 if ( $source_is_page ) {
00712
00713 if ( isset( $template_contents ) ) {
00714 $form_text .= SFFormUtils::unhandledFieldsHTML( $template_name, $template_contents );
00715 $template_contents = null;
00716 }
00717 }
00718
00719 $section = substr_replace( $section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
00720 $template_name = null;
00721 if ( isset( $template_label ) && $curPlaceholder == null ) {
00722 $form_text .= "</fieldset>\n";
00723 unset ( $template_label );
00724 }
00725 $allow_multiple = false;
00726 $all_instances_printed = false;
00727 $instance_num = 0;
00728
00729
00730
00731 } elseif ( $tag_title == 'field' ) {
00732 $field_name = trim( $tag_components[1] );
00733 $fullFieldName = $template_name . '[' . $field_name . ']';
00734
00735 $is_mandatory = false;
00736 $is_hidden = false;
00737 $is_restricted = false;
00738 $is_uploadable = false;
00739 $is_list = false;
00740 $input_type = null;
00741 $field_args = array();
00742 $show_on_select = array();
00743 $default_value = null;
00744 $values = null;
00745 $possible_values = null;
00746 $semantic_property = null;
00747 $preload_page = null;
00748 $holds_template = false;
00749
00750 for ( $i = 2; $i < count( $tag_components ); $i++ ) {
00751
00752 $component = trim( $tag_components[$i] );
00753
00754 if ( $component == 'mandatory' ) {
00755 $is_mandatory = true;
00756 } elseif ( $component == 'hidden' ) {
00757 $is_hidden = true;
00758 } elseif ( $component == 'restricted' ) {
00759 $is_restricted = ( ! $wgUser || ! $wgUser->isAllowed( 'editrestrictedfields' ) );
00760 } elseif ( $component == 'list' ) {
00761 $is_list = true;
00762 } elseif ( $component == 'edittools' ) {
00763 $free_text_components[] = 'edittools';
00764 }
00765
00766 $sub_components = array_map( 'trim', explode( '=', $component, 2 ) );
00767
00768 if ( count( $sub_components ) == 1 ) {
00769
00770 $field_args[$sub_components[0]] = true;
00771
00772 if ( $component == 'holds template' ) {
00773 $is_hidden = true;
00774 $holds_template = true;
00775 $placeholderFields[] = self::placeholderFormat( $template_name, $field_name );
00776 }
00777 } elseif ( count( $sub_components ) == 2 ) {
00778
00779 $field_args[$sub_components[0]] = $sub_components[1];
00780
00781
00782 if ( $sub_components[0] == 'input type' ) {
00783 $input_type = $sub_components[1];
00784 } elseif ( $sub_components[0] == 'default' ) {
00785 $default_value = $wgParser->recursiveTagParse( $sub_components[1] );
00786 } elseif ( $sub_components[0] == 'preload' ) {
00787
00788 if ( $field_name == 'free text' || $field_name == '<freetext>' ) {
00789 $free_text_preload_page = $sub_components[1];
00790 } else {
00791 $preload_page = $sub_components[1];
00792 }
00793 } elseif ( $sub_components[0] == 'show on select' ) {
00794
00795 $vals = explode( ';', html_entity_decode( $sub_components[1] ) );
00796 foreach ( $vals as $val ) {
00797 $val = trim( $val );
00798 if ( empty( $val ) )
00799 continue;
00800 $option_div_pair = explode( '=>', $val, 2 );
00801 if ( count( $option_div_pair ) > 1 ) {
00802 $option = $option_div_pair[0];
00803 $div_id = $option_div_pair[1];
00804 if ( array_key_exists( $div_id, $show_on_select ) )
00805 $show_on_select[$div_id][] = $option;
00806 else
00807 $show_on_select[$div_id] = array( $option );
00808 } else {
00809 $show_on_select[$val] = array();
00810 }
00811 }
00812 } elseif ( $sub_components[0] == 'autocomplete on property' ) {
00813 $property_name = $sub_components[1];
00814 $propValue = SMWPropertyValue::makeUserProperty( $property_name );
00815 if ( $propValue->getPropertyTypeID() == '_wpg' ) {
00816 $field_args['autocomplete field type'] = 'relation';
00817 } else {
00818 $field_args['autocomplete field type'] = 'attribute';
00819 }
00820 $field_args['autocompletion source'] = $sub_components[1];
00821 } elseif ( $sub_components[0] == 'autocomplete on category' ) {
00822 $field_args['autocomplete field type'] = 'category';
00823 $field_args['autocompletion source'] = $sub_components[1];
00824 } elseif ( $sub_components[0] == 'autocomplete on concept' ) {
00825 $field_args['autocomplete field type'] = 'concept';
00826 $field_args['autocompletion source'] = $sub_components[1];
00827 } elseif ( $sub_components[0] == 'autocomplete on namespace' ) {
00828 $field_args['autocomplete field type'] = 'namespace';
00829 $autocompletion_source = $sub_components[1];
00830
00831 if ( $autocompletion_source == "" )
00832 $autocompletion_source = "main";
00833 $field_args['autocompletion source'] = $autocompletion_source;
00834 } elseif ( $sub_components[0] == 'autocomplete from url' ) {
00835 $field_args['autocomplete field type'] = 'external_url';
00836 $field_args['autocompletion source'] = $sub_components[1];
00837
00838 $field_args['remote autocompletion'] = true;
00839 } elseif ( $sub_components[0] == 'values' ) {
00840
00841
00842 $values = $sub_components[1];
00843 } elseif ( $sub_components[0] == 'values from property' ) {
00844 $propertyName = $sub_components[1];
00845 $possible_values = SFUtils::getAllValuesForProperty( $propertyName );
00846 } elseif ( $sub_components[0] == 'values from category' ) {
00847 $category_name = ucfirst( $sub_components[1] );
00848 $possible_values = SFUtils::getAllPagesForCategory( $category_name, 10 );
00849 } elseif ( $sub_components[0] == 'values from concept' ) {
00850 $possible_values = SFUtils::getAllPagesForConcept( $sub_components[1] );
00851 } elseif ( $sub_components[0] == 'values from namespace' ) {
00852 $possible_values = SFUtils::getAllPagesForNamespace( $sub_components[1] );
00853 } elseif ( $sub_components[0] == 'values dependent on' ) {
00854 global $sfgDependentFields;
00855 $sfgDependentFields[] = array( $sub_components[1], $fullFieldName );
00856 } elseif ( $sub_components[0] == 'property' ) {
00857 $semantic_property = $sub_components[1];
00858 } elseif ( $sub_components[0] == 'default filename' ) {
00859 $default_filename = str_replace( '<page name>', $page_name, $sub_components[1] );
00860
00861 $default_filename = $wgParser->recursiveTagParse( $default_filename );
00862 $field_args['default filename'] = $default_filename;
00863 } elseif ( $sub_components[0] == 'restricted' ) {
00864 $is_restricted = !array_intersect(
00865 $wgUser->getEffectiveGroups(), array_map( 'trim', explode( ',', $sub_components[1] ) )
00866 );
00867 }
00868 }
00869 }
00870
00871 if ( $input_type == 'datetime with timezone' ) {
00872 $input_type = 'datetime';
00873 $field_args['include timezone'] = true;
00874 } elseif ( $input_type == 'text' || $input_type == 'textarea' ) {
00875
00876
00877
00878
00879 $field_args['no autocomplete'] = true;
00880 }
00881 if ( $allow_multiple ) {
00882 $field_args['part_of_multiple'] = $allow_multiple;
00883 }
00884 if ( count( $show_on_select ) > 0 ) {
00885 $field_args['show on select'] = $show_on_select;
00886 }
00887
00888
00889 $cur_value = null;
00890 $escaped_field_name = str_replace( "'", "\'", $field_name );
00891 if ( isset( $template_instance_query_values ) &&
00892 $template_instance_query_values != null &&
00893 is_array( $template_instance_query_values ) ) {
00894
00895
00896
00897
00898
00899
00900 $field_query_val = null;
00901 if ( array_key_exists( $escaped_field_name, $template_instance_query_values ) ) {
00902 $field_query_val = $template_instance_query_values[$escaped_field_name];
00903 } elseif ( array_key_exists( $field_name, $template_instance_query_values ) ) {
00904 $field_query_val = $template_instance_query_values[$field_name];
00905 }
00906 if ( $form_submitted || ( $field_query_val != '' && ! is_array( $field_query_val ) ) ) {
00907 $cur_value = $field_query_val;
00908 }
00909 }
00910
00911 if ( empty( $cur_value ) && !$form_submitted ) {
00912 if ( !is_null( $default_value ) ) {
00913
00914 $cur_value = $default_value;
00915 } elseif ( $preload_page ) {
00916 $cur_value = SFFormUtils::getPreloadedText( $preload_page );
00917 }
00918 }
00919
00920
00921
00922
00923 if ( $source_is_page && ( ! empty( $existing_template_text ) ) ) {
00924 if ( isset( $template_contents[$field_name] ) ) {
00925 $cur_value = $template_contents[$field_name];
00926
00927
00928
00929
00930
00931
00932 if ( $holds_template ) {
00933 $existing_page_content = $existing_page_content . $cur_value;
00934 }
00935
00936
00937
00938
00939
00940
00941
00942 unset( $template_contents[$field_name] );
00943 } else {
00944 $cur_value = '';
00945 }
00946 }
00947
00948
00949 if ( $field_name == '<freetext>' ) {
00950
00951
00952
00953 if ( $is_hidden ) {
00954 $new_text = Html::hidden( 'sf_free_text', '!free_text!' );
00955 } else {
00956 $sfgTabIndex++;
00957 $sfgFieldNum++;
00958 if ( $cur_value === '' || is_null( $cur_value ) ) {
00959 $default_value = '!free_text!';
00960 } else {
00961 $default_value = $cur_value;
00962
00963
00964
00965 global $wgFCKEditorDir;
00966 if ( $wgFCKEditorDir && strpos( $existing_page_content, '__NORICHEDITOR__' ) === false ) {
00967 $showFCKEditor = SFFormUtils::getShowFCKEditor();
00968 if ( !$form_submitted && ( $showFCKEditor & RTE_VISIBLE ) ) {
00969 $default_value = SFFormUtils::prepareTextForFCK( $cur_value );
00970 }
00971 }
00972 }
00973 $new_text = SFTextAreaInput::getHTML( $default_value, 'sf_free_text', false, ( $form_is_disabled || $is_restricted ), $field_args );
00974 if ( in_array( 'edittools', $free_text_components ) ) {
00975
00976 $options[] = 'parse';
00977 $edittools_text = $wgParser->recursiveTagParse( wfMsg( 'edittools', array( 'content' ) ) );
00978
00979 $new_text .= <<<END
00980 <div class="mw-editTools">
00981 $edittools_text
00982 </div>
00983
00984 END;
00985 }
00986 }
00987 $free_text_was_included = true;
00988
00989 $data_text .= "!free_text!\n";
00990 }
00991
00992 if ( $template_name === '' || $field_name == '<freetext>' ) {
00993 $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
00994 } else {
00995 if ( is_array( $cur_value ) ) {
00996
00997 if ( array_key_exists( 'is_list', $cur_value ) &&
00998 $cur_value['is_list'] == true ) {
00999 $cur_value_in_template = "";
01000 if ( array_key_exists( 'delimiter', $field_args ) ) {
01001 $delimiter = $field_args['delimiter'];
01002 } else {
01003 $delimiter = ",";
01004 }
01005 foreach ( $cur_value as $key => $val ) {
01006 if ( $key !== "is_list" ) {
01007 if ( $cur_value_in_template != "" ) {
01008 $cur_value_in_template .= $delimiter . " ";
01009 }
01010 $cur_value_in_template .= $val;
01011 }
01012 }
01013 } else {
01014
01015
01016
01017
01018
01019 if ( count( $cur_value ) == 1 ) {
01020 $cur_value_in_template = SFUtils::getWordForYesOrNo( false );
01021 } elseif ( count( $cur_value ) == 2 ) {
01022 $cur_value_in_template = SFUtils::getWordForYesOrNo( true );
01023
01024 } elseif ( count( $cur_value ) >= 3 ) {
01025 $month = $cur_value['month'];
01026 $day = $cur_value['day'];
01027 if ( $day !== '' ) {
01028 global $wgAmericanDates;
01029 if ( $wgAmericanDates == false ) {
01030
01031 $day = str_pad( $day, 2, "0", STR_PAD_LEFT );
01032 }
01033 }
01034 $year = $cur_value['year'];
01035 $hour = $minute = $second = $ampm24h = $timezone = null;
01036 if ( isset( $cur_value['hour'] ) ) $hour = $cur_value['hour'];
01037 if ( isset( $cur_value['minute'] ) ) $minute = $cur_value['minute'];
01038 if ( isset( $cur_value['second'] ) ) $second = $cur_value['second'];
01039 if ( isset( $cur_value['ampm24h'] ) ) $ampm24h = $cur_value['ampm24h'];
01040 if ( isset( $cur_value['timezone'] ) ) $timezone = $cur_value['timezone'];
01041 if ( $month !== '' && $day !== '' && $year !== '' ) {
01042
01043
01044 global $wgAmericanDates;
01045 if ( $wgAmericanDates == true ) {
01046 $cur_value_in_template = "$month $day, $year";
01047 } else {
01048 $cur_value_in_template = "$year/$month/$day";
01049 }
01050
01051 if ( ! is_null( $hour ) )
01052 $cur_value_in_template .= " " . str_pad( intval( substr( $hour, 0, 2 ) ), 2, '0', STR_PAD_LEFT ) . ":" . str_pad( intval( substr( $minute, 0, 2 ) ), 2, '0', STR_PAD_LEFT );
01053 if ( ! is_null( $second ) )
01054 $cur_value_in_template .= ":" . str_pad( intval( substr( $second, 0, 2 ) ), 2, '0', STR_PAD_LEFT );
01055 if ( ! is_null( $ampm24h ) )
01056 $cur_value_in_template .= " $ampm24h";
01057 if ( ! is_null( $timezone ) )
01058 $cur_value_in_template .= " $timezone";
01059 } else {
01060 $cur_value_in_template = "";
01061 }
01062 }
01063 }
01064 } else {
01065 $cur_value_in_template = $cur_value;
01066 }
01067 if ( $template_name == null || $template_name === '' ) {
01068 $input_name = $field_name;
01069 } elseif ( $allow_multiple ) {
01070
01071
01072 $input_name = $template_name . '[num][' . $field_name . ']';
01073 $field_args['origName'] = $template_name . '[' . $field_name . ']';
01074 } else {
01075 $input_name = $template_name . '[' . $field_name . ']';
01076 }
01077
01078
01079
01080
01081 if ( ! empty( $values ) ) {
01082 if ( array_key_exists( 'delimiter', $field_args ) ) {
01083 $delimiter = $field_args['delimiter'];
01084 } else {
01085 $delimiter = ",";
01086 }
01087
01088 $possible_values = array_map( 'trim', explode( $delimiter, $values ) );
01089 $possible_values = array_map( 'htmlspecialchars_decode', $possible_values );
01090 }
01091
01092
01093
01094
01095 if ( $form_submitted && $generated_page_name !== '' ) {
01096
01097
01098 $generated_page_name = str_replace( ' ', '_', $generated_page_name );
01099 $escaped_input_name = str_replace( ' ', '_', $input_name );
01100 $generated_page_name = str_ireplace( "<$escaped_input_name>", $cur_value_in_template, $generated_page_name );
01101
01102
01103 $generated_page_name = str_replace( '_', ' ', $generated_page_name );
01104 }
01105
01106
01107 $is_disabled = ( $form_is_disabled || $is_restricted );
01108
01109
01110
01111 $form_field = SFFormField::createFromDefinition( $field_name,
01112 $input_name, $is_mandatory, $is_hidden, $is_uploadable,
01113 $possible_values, $is_disabled, $is_list, $input_type,
01114 $field_args, $all_fields, $strict_parsing );
01115
01116
01117
01118
01119
01120
01121 if ( $semantic_property != null ) {
01122 $form_field->template_field->setSemanticProperty( $semantic_property );
01123 }
01124 $semantic_property = $form_field->template_field->getSemanticProperty();
01125 if ( !is_null( $semantic_property ) ) {
01126 global $sfgFieldProperties;
01127 $sfgFieldProperties[$fullFieldName] = $semantic_property;
01128 }
01129
01130
01131
01132
01133
01134 if ( $form_submitted ) {
01135 wfRunHooks( 'sfCreateFormField', array( &$form_field, &$cur_value_in_template, true ) );
01136 } else {
01137 wfRunHooks( 'sfCreateFormField', array( &$form_field, &$cur_value, false ) );
01138 }
01139
01140
01141 if ( ! array_key_exists( 'part_of_multiple', $field_args ) ) {
01142 $sfgTabIndex++;
01143 }
01144
01145 $sfgFieldNum++;
01146
01147
01148
01149 if ( $default_value == 'now' &&
01150
01151
01152 ( $cur_value === '' || $cur_value == 'now' ) ) {
01153 if ( $input_type == 'date' || $input_type == 'datetime' ||
01154 $input_type == 'year' ||
01155 ( $input_type === '' && $form_field->getTemplateField()->getPropertyType() == '_dat' ) ) {
01156
01157 global $wgLocaltimezone;
01158 if ( isset( $wgLocaltimezone ) ) {
01159 $serverTimezone = date_default_timezone_get();
01160 date_default_timezone_set( $wgLocaltimezone );
01161 }
01162 $cur_time = time();
01163 $year = date( "Y", $cur_time );
01164 $month = date( "n", $cur_time );
01165 $day = date( "j", $cur_time );
01166 global $wgAmericanDates, $sfg24HourTime;
01167 if ( $wgAmericanDates == true ) {
01168 $month_names = SFFormUtils::getMonthNames();
01169 $month_name = $month_names[$month - 1];
01170 $cur_value_in_template = "$month_name $day, $year";
01171 } else {
01172 $cur_value_in_template = "$year/$month/$day";
01173 }
01174 if ( isset( $wgLocaltimezone ) ) {
01175 date_default_timezone_set( $serverTimezone );
01176 }
01177 if ( $input_type == 'datetime' ) {
01178 if ( $sfg24HourTime ) {
01179 $hour = str_pad( intval( substr( date( "G", $cur_time ), 0, 2 ) ), 2, '0', STR_PAD_LEFT );
01180 } else {
01181 $hour = str_pad( intval( substr( date( "g", $cur_time ), 0, 2 ) ), 2, '0', STR_PAD_LEFT );
01182 }
01183 $minute = str_pad( intval( substr( date( "i", $cur_time ), 0, 2 ) ), 2, '0', STR_PAD_LEFT );
01184 $second = str_pad( intval( substr( date( "s", $cur_time ), 0, 2 ) ), 2, '0', STR_PAD_LEFT );
01185 if ( $sfg24HourTime ) {
01186 $cur_value_in_template .= " $hour:$minute:$second";
01187 } else {
01188 $ampm = date( "A", $cur_time );
01189 $cur_value_in_template .= " $hour:$minute:$second $ampm";
01190 }
01191 }
01192 if ( array_key_exists( 'include timezone', $field_args ) ) {
01193 $timezone = date( "T", $cur_time );
01194 $cur_value_in_template .= " $timezone";
01195 }
01196 }
01197 }
01198
01199
01200
01201 if ( $default_value == 'current user' &&
01202
01203
01204 ( $cur_value === '' || $cur_value == 'current user' ) ) {
01205
01206 $cur_value_in_template = $wgUser->getName();
01207 $cur_value = $cur_value_in_template;
01208 }
01209
01210
01211
01213 if ( $holds_template ) {
01214 $cur_value = self::makePlaceholderInWikiText( self::placeholderFormat( $template_name, $field_name ) );
01215 }
01216
01217 $new_text = $this->formFieldHTML( $form_field, $cur_value );
01218
01219
01220
01221
01222 if ( $holds_template ) {
01223 $new_text .= self::makePlaceholderInFormHTML( self::placeholderFormat( $template_name, $field_name ) );
01224 }
01225
01226
01227
01228
01229 if ( $form_field->isDisabled() ) {
01230 if ( $field_name == 'free text' || $field_name == '<freetext>' ) {
01231 $new_text .= Html::hidden( 'sf_free_text', '!free_text!' );
01232 } else {
01233 $new_text .= Html::hidden( $input_name, $cur_value );
01234 }
01235 }
01236
01237 if ( $new_text ) {
01238
01239 if ( is_numeric( $field_name ) ) {
01240 $template_text .= "|$cur_value_in_template";
01241 } else {
01242
01243 if ( $cur_value_in_template !== '' ) {
01244 $template_text .= "\n|$field_name=$cur_value_in_template";
01245 }
01246 }
01247 $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
01248 } else {
01249 $start_position = $brackets_end_loc;
01250 }
01251 }
01252
01253
01254
01255 } elseif ( $tag_title == 'standard input' ) {
01256
01257 $input_name = $tag_components[1];
01258 $input_label = null;
01259 $attr = array();
01260
01261
01262 if ( ( $is_query && $input_name != 'run query' ) || ( !$is_query && $input_name == 'run query' ) ) {
01263 $new_text = "";
01264 $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
01265 continue;
01266 }
01267
01268 $this->standardInputsIncluded = true;
01269
01270 for ( $i = 2; $i < count( $tag_components ); $i++ ) {
01271 $component = $tag_components[$i];
01272 $sub_components = array_map( 'trim', explode( '=', $component ) );
01273 if ( count( $sub_components ) == 1 ) {
01274 if ( $sub_components[0] == 'edittools' ) {
01275 $free_text_components[] = 'edittools';
01276 }
01277 } elseif ( count( $sub_components ) == 2 ) {
01278 switch( $sub_components[0] ) {
01279 case 'label':
01280 $input_label = $sub_components[1];
01281 break;
01282 case 'class':
01283 case 'style':
01284 $attr[$sub_components[0]] = $sub_components[1];
01285 break;
01286 }
01287
01288 if ( $input_name == 'free text' || $input_name == '<freetext>' ) {
01289 if ( $sub_components[0] == 'preload' ) {
01290 $free_text_preload_page = $sub_components[1];
01291 }
01292 }
01293 }
01294 }
01295 if ( $input_name == 'summary' ) {
01296 $new_text = SFFormUtils::summaryInputHTML( $form_is_disabled, $input_label, $attr );
01297 } elseif ( $input_name == 'minor edit' ) {
01298 $new_text = SFFormUtils::minorEditInputHTML( $form_is_disabled, $input_label, $attr );
01299 } elseif ( $input_name == 'watch' ) {
01300 $new_text = SFFormUtils::watchInputHTML( $form_is_disabled, $input_label, $attr );
01301 } elseif ( $input_name == 'save' ) {
01302 $new_text = SFFormUtils::saveButtonHTML( $form_is_disabled, $input_label, $attr );
01303 } elseif ( $input_name == 'save and continue' ) {
01304 $new_text = SFFormUtils::saveAndContinueButtonHTML( $form_is_disabled, $input_label, $attr );
01305 } elseif ( $input_name == 'preview' ) {
01306 $new_text = SFFormUtils::showPreviewButtonHTML( $form_is_disabled, $input_label, $attr );
01307 } elseif ( $input_name == 'changes' ) {
01308 $new_text = SFFormUtils::showChangesButtonHTML( $form_is_disabled, $input_label, $attr );
01309 } elseif ( $input_name == 'cancel' ) {
01310 $new_text = SFFormUtils::cancelLinkHTML( $form_is_disabled, $input_label, $attr );
01311 } elseif ( $input_name == 'run query' ) {
01312 $new_text = SFFormUtils::runQueryButtonHTML( $form_is_disabled, $input_label, $attr );
01313 }
01314 $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
01315
01316
01317
01318 } elseif ( $tag_title == 'info' ) {
01319
01320 foreach ( array_slice( $tag_components, 1 ) as $component ) {
01321 $sub_components = array_map( 'trim', explode( '=', $component, 2 ) );
01322
01323 $tag = strtolower( $sub_components[0] );
01324 if ( $tag == 'create title' || $tag == 'add title' ) {
01325
01326
01327 if ( !$is_query && !$this->mPageTitle->exists() ) {
01328 $form_page_title = $sub_components[1];
01329 }
01330 } elseif ( $tag == 'edit title' ) {
01331
01332
01333 if ( !$is_query && $this->mPageTitle->exists() ) {
01334 $form_page_title = $sub_components[1];
01335 }
01336 } elseif ( $tag == 'query title' ) {
01337
01338
01339 if ( $is_query ) {
01340 $form_page_title = $sub_components[1];
01341 }
01342 } elseif ( $tag == 'partial form' ) {
01343 $form_is_partial = true;
01344
01345 $source_page_matches_this_form = true;
01346 } elseif ( $tag == 'includeonly free text' || $tag == 'onlyinclude free text' ) {
01347 $onlyinclude_free_text = true;
01348 } elseif ( $tag == 'query form at top' ) {
01349
01350
01351
01352
01353 global $sfgRunQueryFormAtTop;
01354 $sfgRunQueryFormAtTop = true;
01355 }
01356 }
01357 $section = substr_replace( $section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
01358
01359
01360
01361 } else {
01362
01363 $start_position = $brackets_end_loc;
01364 }
01365 }
01366
01367 if ( ! $all_instances_printed ) {
01368 if ( $template_text !== '' ) {
01369
01370
01371
01372 $template_text = preg_replace( '/\|*$/', '', $template_text );
01373
01374
01375 if ( strpos( $template_text, "\n" ) ) {
01376 $template_text .= "\n";
01377 }
01378
01379
01380 if ( !$allow_multiple ) {
01381 $template_text .= SFFormUtils::addUnhandledFields( $template_name );
01382 }
01383 $template_text .= "}}";
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393 $reptmp = self::makePlaceholderInWikiText( $curPlaceholder );
01394 if ( $curPlaceholder != null && $data_text && strpos( $data_text, $reptmp, 0 ) !== false ) {
01395 $data_text = preg_replace( '/' . $reptmp . '/', $template_text . $reptmp, $data_text );
01396 } else {
01397 $data_text .= $template_text . "\n";
01398 }
01399
01400
01401
01402
01403 if ( $existing_page_content && strpos( $existing_page_content, '{{{insertionpoint}}}', 0 ) !== false ) {
01404 $existing_page_content = preg_replace( '/\{\{\{insertionpoint\}\}\}(\r?\n?)/',
01405 preg_replace( '/\}\}/m', '}�',
01406 preg_replace( '/\{\{/m', '�{', $template_text ) ) .
01407 "\n{{{insertionpoint}}}",
01408 $existing_page_content );
01409
01410
01411 } elseif ( $form_is_partial && $wgRequest->getCheck( 'partial' ) ) {
01412 $existing_page_content = preg_replace( '/\}\}/m', '}�',
01413 preg_replace( '/\{\{/m', '�{', $template_text ) ) .
01414 "\n{{{insertionpoint}}}\n" . $existing_page_content;
01415 }
01416 }
01417 }
01418
01419 if ( $allow_multiple ) {
01420 if ( $curPlaceholder == null ) {
01421
01422 $form_text .= $this->multipleTemplateInstanceHTML( $form_is_disabled, $all_instances_printed, $section, $instance_num, $add_button_text );
01423 } else {
01424
01425
01426
01427
01428
01429 $multipleTemplateString .= $this->multipleTemplateInstanceHTML( $form_is_disabled, $all_instances_printed, $section, $instance_num, $add_button_text );
01430
01431
01432
01433 $multipleTemplateString .= self::makePlaceholderInFormHTML( $curPlaceholder );
01434 if ( isset( $template_label ) ) {
01435 $multipleTemplateString .= "</fieldset>\n";
01436 unset ( $template_label );
01437 }
01438 $form_text = preg_replace( '/' . self::makePlaceholderInFormHTML( $curPlaceholder ) . '/',
01439 $multipleTemplateString, $form_text );
01440 }
01441 if ( ! $all_instances_printed ) {
01442
01443
01444 $section_num--;
01445 }
01446 } else {
01447 $form_text .= $section;
01448 }
01449 $curPlaceholder = null;
01450
01451 }
01452
01453
01454
01455
01456 foreach ( $placeholderFields as $stringToReplace ) {
01457
01458 $data_text = preg_replace( '/' . self::makePlaceholderInWikiText( $stringToReplace ) . '/', '', $data_text );
01459
01460
01461 $form_text = preg_replace( '/' . self::makePlaceholderInFormHTML( $stringToReplace ) . '/', '', $form_text );
01462 }
01463
01464
01465
01466 if ( ! $free_text_was_included ) {
01467 $form_text .= Html::hidden( 'sf_free_text', '!free_text!' );
01468 }
01469
01470
01471
01472
01473
01474
01475 if ( $form_is_partial ) {
01476 if ( !$wgRequest->getCheck( 'partial' ) ) {
01477 $free_text = $original_page_content;
01478 $form_text .= Html::hidden( 'partial', 1 );
01479 } else {
01480 $free_text = null;
01481 $existing_page_content = preg_replace( array( '/�\{/m', '/\}�/m' ),
01482 array( '{{', '}}' ),
01483 $existing_page_content );
01484 $existing_page_content = preg_replace( '/\{\{\{insertionpoint\}\}\}/', '', $existing_page_content );
01485 }
01486 } elseif ( $source_is_page ) {
01487
01488
01489 $free_text = trim( $existing_page_content );
01490
01491 } elseif ( $wgRequest->getCheck( 'sf_free_text' ) ) {
01492 $free_text = $wgRequest->getVal( 'sf_free_text' );
01493 if ( ! $free_text_was_included ) {
01494 $data_text .= "!free_text!";
01495 }
01496
01497 } elseif ( $free_text_preload_page != null ) {
01498 $free_text = SFFormUtils::getPreloadedText( $free_text_preload_page );
01499 } else {
01500 $free_text = null;
01501 }
01502 if ( $onlyinclude_free_text ) {
01503
01504 $free_text = str_replace( "<onlyinclude>", '', $free_text );
01505 $free_text = str_replace( "</onlyinclude>", '', $free_text );
01506 $free_text = trim( $free_text );
01507 $data_text = str_replace( '!free_text!', '<onlyinclude>!free_text!</onlyinclude>', $data_text );
01508 }
01509
01510 wfRunHooks( 'sfModifyFreeTextField', array( &$free_text, $existing_page_content ) );
01511
01512 global $wgFCKEditorDir;
01513 if ( $wgFCKEditorDir && strpos( $existing_page_content, '__NORICHEDITOR__' ) === false ) {
01514 $showFCKEditor = SFFormUtils::getShowFCKEditor();
01515 if ( !$form_submitted && ( $showFCKEditor & RTE_VISIBLE ) ) {
01516 $free_text = SFFormUtils::prepareTextForFCK( $free_text );
01517 }
01518 } else {
01519 $showFCKEditor = 0;
01520 }
01521
01522 $escaped_free_text = Sanitizer::safeEncodeAttribute( $free_text );
01523 $form_text = str_replace( '!free_text!', $escaped_free_text, $form_text );
01524 $data_text = str_replace( '!free_text!', $free_text, $data_text );
01525
01526
01527
01528 if ( !$is_query && $this->mPageTitle->exists() && ( $existing_page_content !== '' ) && ! $source_page_matches_this_form ) {
01529 $form_text = "\t" . '<div class="warningbox">' . wfMsg( 'sf_formedit_formwarning', $this->mPageTitle->getFullURL() ) . "</div>\n<br clear=\"both\" />\n" . $form_text;
01530 }
01531
01532
01533 if ( !$this->standardInputsIncluded ) {
01534 if ( $is_query )
01535 $form_text .= SFFormUtils::queryFormBottom( $form_is_disabled );
01536 else
01537 $form_text .= SFFormUtils::formBottom( $form_is_disabled );
01538 }
01539
01540
01541 if ( !$is_query ) {
01542 $form_text .= Html::hidden( 'wpStarttime', wfTimestampNow() );
01543 $article = new Article( $this->mPageTitle, 0 );
01544 $form_text .= Html::hidden( 'wpEdittime', $article->getTimestamp() );
01545 }
01546
01547 $form_text .= "\t</form>\n";
01548
01549
01550 wfRunHooks( 'sfAddJavascriptToForm', array( &$javascript_text ) );
01551
01552
01553
01554 $javascript_text = "";
01555 if ( $free_text_was_included && $showFCKEditor > 0 ) {
01556 $javascript_text .= SFFormUtils::mainFCKJavascript( $showFCKEditor, $field_args );
01557 if ( $showFCKEditor & ( RTE_TOGGLE_LINK | RTE_POPUP ) ) {
01558 $javascript_text .= SFFormUTils::FCKToggleJavascript();
01559 }
01560 if ( $showFCKEditor & RTE_POPUP ) {
01561 $javascript_text .= SFFormUTils::FCKPopupJavascript();
01562 }
01563 }
01564
01565
01566
01567
01568 if ( $wgRequest->getCheck( 'partial' ) ) {
01569 $data_text = $existing_page_content;
01570 }
01571
01572 if ( !$is_embedded ) {
01573 $form_page_title = $wgParser->recursiveTagParse( str_replace( "{{!}}", "|", $form_page_title ) );
01574 } else {
01575 $form_page_title = null;
01576 }
01577
01578
01579
01580
01581 if ( $form_submitted ) {
01582 $javascript_text = '';
01583 }
01584
01585 $parserOutput = $wgParser->getOutput();
01586 $wgOut->addParserOutputNoText( $parserOutput );
01587
01588 $wgParser = $oldParser;
01589
01590 wfProfileOut( __METHOD__ );
01591
01592 return array( $form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name );
01593 }
01594
01598 function formFieldHTML( $form_field, $cur_value ) {
01599
01600
01601 $template_field = $form_field->getTemplateField();
01602
01603 if ( $form_field->isHidden() ) {
01604 $text = Html::hidden( $form_field->getInputName(), $cur_value );
01605 } elseif ( $form_field->getInputType() !== '' &&
01606 array_key_exists( $form_field->getInputType(), $this->mInputTypeHooks ) &&
01607 $this->mInputTypeHooks[$form_field->getInputType()] != null ) {
01608 $funcArgs = array();
01609 $funcArgs[] = $cur_value;
01610 $funcArgs[] = $form_field->getInputName();
01611 $funcArgs[] = $form_field->isMandatory();
01612 $funcArgs[] = $form_field->isDisabled();
01613
01614
01615
01616 $hook_values = $this->mInputTypeHooks[$form_field->getInputType()];
01617 $other_args = $form_field->getArgumentsForInputCall( $hook_values[1] );
01618 $funcArgs[] = $other_args;
01619 $text = call_user_func_array( $hook_values[0], $funcArgs );
01620 } else {
01621 $property_type = $template_field->getPropertyType();
01622 $is_list = ( $form_field->isList() || $template_field->isList() );
01623 if ( $property_type !== '' &&
01624 array_key_exists( $property_type, $this->mSemanticTypeHooks ) &&
01625 isset( $this->mSemanticTypeHooks[$property_type][$is_list] ) ) {
01626 $funcArgs = array();
01627 $funcArgs[] = $cur_value;
01628 $funcArgs[] = $form_field->getInputName();
01629 $funcArgs[] = $form_field->isMandatory();
01630 $funcArgs[] = $form_field->isDisabled();
01631 $hook_values = $this->mSemanticTypeHooks[$property_type][$is_list];
01632 $other_args = $form_field->getArgumentsForInputCall( $hook_values[1] );
01633 $funcArgs[] = $other_args;
01634 $text = call_user_func_array( $hook_values[0], $funcArgs );
01635 } else {
01636 $other_args = $form_field->getArgumentsForInputCall();
01637
01638 if ( $form_field->isList() ) {
01639 if ( ! array_key_exists( 'size', $other_args ) ) {
01640 $other_args['size'] = 100;
01641 }
01642 }
01643 $text = SFTextInput::getHTML( $cur_value, $form_field->getInputName(), $form_field->isMandatory(), $form_field->isDisabled(), $other_args );
01644 }
01645 }
01646 return $text;
01647 }
01648
01649 }