Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php |
— | — | @@ -57,11 +57,13 @@ |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Register all information about the passed-in form input class. |
| 61 | + * |
| 62 | + * @param Class $inputTypeClass The class representing the new input. Must be derived from SFFormInput. |
61 | 63 | */ |
62 | 64 | public function registerInputType( $inputTypeClass ) { |
63 | 65 | global $smwgContLang; |
64 | 66 | global $sfgInitJSFunctions, $sfgValidationJSFunctions; |
65 | | - |
| 67 | + |
66 | 68 | $inputTypeName = call_user_func( array( $inputTypeClass, 'getName' ) ); |
67 | 69 | $this->mInputTypeClasses[$inputTypeName] = $inputTypeClass; |
68 | 70 | $this->setInputTypeHook( $inputTypeName, array( $inputTypeClass, 'getHTML' ), array() ); |
— | — | @@ -104,14 +106,19 @@ |
105 | 107 | } |
106 | 108 | } |
107 | 109 | |
108 | | - $initJSFunction = call_user_func( array( $inputTypeClass, 'getInitJSFunction' ) ); |
109 | | - if ( !is_null( $initJSFunction ) ) { |
110 | | - $sfgInitJSFunctions[] = $initJSFunction; |
111 | | - } |
112 | | - $validationJSFunctions = call_user_func( array( $inputTypeClass, 'getValidationJSFunctions' ) ); |
113 | | - if ( count( $validationJSFunctions ) > 0 ) { |
114 | | - $sfgValidationJSFunctions = array_merge( $sfgValidationJSFunctions, $initJSFunction ); |
115 | | - } |
| 110 | + // FIXME: No need to register these functions explicitly. Instead |
| 111 | + // formFieldHTML should call $someInput -> getJsInitFunctionData() and |
| 112 | + // store its return value. formHTML should at some (late) point use the |
| 113 | + // stored data. |
| 114 | +// $initJSFunction = call_user_func( array( $inputTypeClass, 'getJsInitFunctionData' ) ); |
| 115 | +// if ( !is_null( $initJSFunction ) ) { |
| 116 | +// $sfgInitJSFunctions[] = $initJSFunction; |
| 117 | +// } |
| 118 | +// |
| 119 | +// $validationJSFunctions = call_user_func( array( $inputTypeClass, 'getJsValidationFunctionData' ) ); |
| 120 | +// if ( count( $validationJSFunctions ) > 0 ) { |
| 121 | +// $sfgValidationJSFunctions = array_merge( $sfgValidationJSFunctions, $initJSFunction ); |
| 122 | +// } |
116 | 123 | } |
117 | 124 | |
118 | 125 | public function getInputType( $inputTypeName ) { |
— | — | @@ -253,7 +260,7 @@ |
254 | 261 | * only a page formula exists). |
255 | 262 | */ |
256 | 263 | 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, $embedded = false ) { |
257 | | - global $wgRequest, $wgUser, $wgOut; |
| 264 | + global $wgRequest, $wgUser, $wgOut, $wgParser; |
258 | 265 | global $sfgTabIndex; // used to represent the current tab index in the form |
259 | 266 | global $sfgFieldNum; // used for setting various HTML IDs |
260 | 267 | |
— | — | @@ -350,9 +357,12 @@ |
351 | 358 | // remove the '<nowiki>' tags, leaving us with what we need. |
352 | 359 | $form_def = "__NOEDITSECTION__" . strtr( $form_def, array( '{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>' ) ); |
353 | 360 | |
354 | | - $parser = new Parser(); |
| 361 | + $oldParser = $wgParser; |
355 | 362 | |
356 | | - // Get the form definition from the cache, if we're using caching and it's |
| 363 | + $wgParser = unserialize( serialize( $oldParser ) ); // deep clone of parser |
| 364 | + $wgParser->clearState(); |
| 365 | + |
| 366 | + // Get the form definition from the cache, if we're using caching and it's |
357 | 367 | // there. |
358 | 368 | // $got_form_def_from_cache = false; |
359 | 369 | // global $sfgCacheFormDefinitions; |
— | — | @@ -366,7 +376,7 @@ |
367 | 377 | // } |
368 | 378 | // Otherwise, parse it. |
369 | 379 | // if ( ! $got_form_def_from_cache ) { |
370 | | - $form_def = $parser->parse($form_def, $this->mPageTitle, ParserOptions::newFromUser($wgUser))->getText(); |
| 380 | + $form_def = $wgParser->parse($form_def, $this->mPageTitle, ParserOptions::newFromUser($wgUser))->getText(); |
371 | 381 | // } |
372 | 382 | |
373 | 383 | // Turn form definition file into an array of sections, one for each |
— | — | @@ -677,7 +687,7 @@ |
678 | 688 | if ( $sub_components[0] == 'input type' ) { |
679 | 689 | $input_type = $sub_components[1]; |
680 | 690 | } elseif ( $sub_components[0] == 'default' ) { |
681 | | - $default_value = $parser->recursiveTagParse( $sub_components[1] ); |
| 691 | + $default_value = $wgParser->recursiveTagParse( $sub_components[1] ); |
682 | 692 | } elseif ( $sub_components[0] == 'preload' ) { |
683 | 693 | // free text field has special handling |
684 | 694 | if ( $field_name == 'free text' || $field_name == '<freetext>' ) { |
— | — | @@ -1405,7 +1415,7 @@ |
1406 | 1416 | $data_text = $existing_page_content; |
1407 | 1417 | |
1408 | 1418 | if ( !$embedded ) { |
1409 | | - $form_page_title = $parser->recursiveTagParse( str_replace( "{{!}}", "|", $form_page_title ) ); |
| 1419 | + $form_page_title = $wgParser->recursiveTagParse( str_replace( "{{!}}", "|", $form_page_title ) ); |
1410 | 1420 | } else { |
1411 | 1421 | $form_page_title = null; |
1412 | 1422 | } |
— | — | @@ -1417,8 +1427,10 @@ |
1418 | 1428 | $javascript_text = ''; |
1419 | 1429 | } |
1420 | 1430 | |
1421 | | - $wgOut->addParserOutputNoText( $parser->getOutput() ); |
| 1431 | + $wgOut->addParserOutputNoText( $wgParser->getOutput() ); |
1422 | 1432 | |
| 1433 | + $wgParser = $oldParser; |
| 1434 | + |
1423 | 1435 | wfProfileOut( __METHOD__ ); |
1424 | 1436 | |
1425 | 1437 | return array( $form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name ); |