+ $warned = [];
+
+ // Process all non-templates and save templates for secondary
+ // processing.
+ $toProcess = [];
+ foreach ( $params as $paramName => $paramSettings ) {
+ if ( isset( $paramSettings[self::PARAM_TEMPLATE_VARS] ) ) {
+ $toProcess[] = [ $paramName, $paramSettings[self::PARAM_TEMPLATE_VARS], $paramSettings ];
+ } else {
+ try {
+ $results[$paramName] = $this->getParameterFromSettings(
+ $paramName, $paramSettings, $parseLimit
+ );
+ } catch ( ApiUsageException $ex ) {
+ $results[$paramName] = $ex;
+ }
+ }
+ }
+
+ // Now process all the templates by successively replacing the
+ // placeholders with all client-supplied values.
+ // This bit duplicates JavaScript logic in
+ // ApiSandbox.PageLayout.prototype.updateTemplatedParams().
+ // If you update this, see if that needs updating too.
+ while ( $toProcess ) {
+ list( $name, $targets, $settings ) = array_shift( $toProcess );
+
+ foreach ( $targets as $placeholder => $target ) {
+ if ( !array_key_exists( $target, $results ) ) {
+ // The target wasn't processed yet, try the next one.
+ // If all hit this case, the parameter has no expansions.
+ continue;
+ }
+ if ( !is_array( $results[$target] ) || !$results[$target] ) {
+ // The target was processed but has no (valid) values.
+ // That means it has no expansions.
+ break;
+ }
+
+ // Expand this target in the name and all other targets,
+ // then requeue if there are more targets left or put in
+ // $results if all are done.
+ unset( $targets[$placeholder] );
+ $placeholder = '{' . $placeholder . '}';
+ foreach ( $results[$target] as $value ) {
+ if ( !preg_match( '/^[^{}]*$/', $value ) ) {
+ // Skip values that make invalid parameter names.
+ $encTargetName = $this->encodeParamName( $target );
+ if ( !isset( $warned[$encTargetName][$value] ) ) {
+ $warned[$encTargetName][$value] = true;
+ $this->addWarning( [
+ 'apiwarn-ignoring-invalid-templated-value',
+ wfEscapeWikiText( $encTargetName ),
+ wfEscapeWikiText( $value ),
+ ] );
+ }
+ continue;
+ }