diff --git a/includes/parserfunctions/PF_TemplateParams.php b/includes/parserfunctions/PF_TemplateParams.php index d0317482..cf402bff 100644 --- a/includes/parserfunctions/PF_TemplateParams.php +++ b/includes/parserfunctions/PF_TemplateParams.php @@ -1,80 +1,82 @@ getTitle(); if ( $title->getNamespace() !== NS_TEMPLATE ) { return '
Error: #template_params can only be called within a template.
'; } // In theory, this will set a separate cache for each user // language - so that a user viewing the output of // #template_params in one language won't affect the display // for a user viewing it in another language. // In practice, setting this variable to *any* value seems to // just disable the cache entirely. That's probably alright, // though - template pages don't get viewed that frequently, // so disabling the cache for them probably will not have a // big effect on performance. $wgRenderHashAppend = ';lang=' . $wgLang->getCode(); $params = func_get_args(); array_shift( $params ); // We don't need the parser. $fieldData = []; foreach ( $params as $param ) { list( $fieldName, $fieldParams ) = self::parseWikitextString( $param ); - $fieldData[$fieldName] = $fieldParams; + if ( $fieldName !== '' ) { + $fieldData[$fieldName] = $fieldParams; + } } $parserOutput = $parser->getOutput(); $parserOutput->setProperty( 'PageFormsTemplateParams', serialize( $fieldData ) ); $text = wfMessage( "pf_template_docu", $title->getText() )->escaped(); $text .= "
\n{{" . $title->getText() . "\n";
 		foreach ( $fieldData as $fieldName => $fieldParams ) {
 			$text .= "|$fieldName=\n";
 		}
 		$text .= "}}
\n"; $text .= '

' . wfMessage( "pf_template_docufooter" )->escaped() . '

'; return [ $text, 'noparse' => true, 'isHTML' => true ]; } public static function parseWikitextString( $fieldString ) { $fieldParams = []; $matches = []; $foundMatch = preg_match( '/([^(]*)\s*\((.*)\)/s', $fieldString, $matches ); $allowedValuesParam = ""; if ( $foundMatch ) { $fieldName = trim( $matches[1] ); $extraParamsString = $matches[2]; $extraParams = explode( ';', $extraParamsString ); foreach ( $extraParams as $extraParam ) { $extraParamParts = explode( '=', $extraParam, 2 ); if ( count( $extraParamParts ) == 1 ) { $paramKey = strtolower( trim( $extraParamParts[0] ) ); $fieldParams[$paramKey] = true; } else { $paramKey = strtolower( trim( $extraParamParts[0] ) ); $paramValue = trim( $extraParamParts[1] ); $fieldParams[$paramKey] = $paramValue; } } } else { $fieldName = trim( $fieldString ); } return [ $fieldName, $fieldParams ]; } }