r88564 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88563‎ | r88564 | r88565 >
Date:08:41, 22 May 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
bugfix: use clone of wgParser instead of new Parser for form parsing
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -57,11 +57,13 @@
5858
5959 /**
6060 * 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.
6163 */
6264 public function registerInputType( $inputTypeClass ) {
6365 global $smwgContLang;
6466 global $sfgInitJSFunctions, $sfgValidationJSFunctions;
65 -
 67+
6668 $inputTypeName = call_user_func( array( $inputTypeClass, 'getName' ) );
6769 $this->mInputTypeClasses[$inputTypeName] = $inputTypeClass;
6870 $this->setInputTypeHook( $inputTypeName, array( $inputTypeClass, 'getHTML' ), array() );
@@ -104,14 +106,19 @@
105107 }
106108 }
107109
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+// }
116123 }
117124
118125 public function getInputType( $inputTypeName ) {
@@ -253,7 +260,7 @@
254261 * only a page formula exists).
255262 */
256263 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;
258265 global $sfgTabIndex; // used to represent the current tab index in the form
259266 global $sfgFieldNum; // used for setting various HTML IDs
260267
@@ -350,9 +357,12 @@
351358 // remove the '<nowiki>' tags, leaving us with what we need.
352359 $form_def = "__NOEDITSECTION__" . strtr( $form_def, array( '{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>' ) );
353360
354 - $parser = new Parser();
 361+ $oldParser = $wgParser;
355362
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
357367 // there.
358368 // $got_form_def_from_cache = false;
359369 // global $sfgCacheFormDefinitions;
@@ -366,7 +376,7 @@
367377 // }
368378 // Otherwise, parse it.
369379 // 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();
371381 // }
372382
373383 // Turn form definition file into an array of sections, one for each
@@ -677,7 +687,7 @@
678688 if ( $sub_components[0] == 'input type' ) {
679689 $input_type = $sub_components[1];
680690 } elseif ( $sub_components[0] == 'default' ) {
681 - $default_value = $parser->recursiveTagParse( $sub_components[1] );
 691+ $default_value = $wgParser->recursiveTagParse( $sub_components[1] );
682692 } elseif ( $sub_components[0] == 'preload' ) {
683693 // free text field has special handling
684694 if ( $field_name == 'free text' || $field_name == '<freetext>' ) {
@@ -1405,7 +1415,7 @@
14061416 $data_text = $existing_page_content;
14071417
14081418 if ( !$embedded ) {
1409 - $form_page_title = $parser->recursiveTagParse( str_replace( "{{!}}", "|", $form_page_title ) );
 1419+ $form_page_title = $wgParser->recursiveTagParse( str_replace( "{{!}}", "|", $form_page_title ) );
14101420 } else {
14111421 $form_page_title = null;
14121422 }
@@ -1417,8 +1427,10 @@
14181428 $javascript_text = '';
14191429 }
14201430
1421 - $wgOut->addParserOutputNoText( $parser->getOutput() );
 1431+ $wgOut->addParserOutputNoText( $wgParser->getOutput() );
14221432
 1433+ $wgParser = $oldParser;
 1434+
14231435 wfProfileOut( __METHOD__ );
14241436
14251437 return array( $form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name );

Follow-up revisions

RevisionCommit summaryAuthorDate
r88685followup r88564: no need to call clearState, it's called by parse anywayfoxtrott21:01, 23 May 2011