getName() !== 'wikilink' && $contextTok->getName() !== 'extlink' && $t instanceof SelfclosingTagTk && $t->getName() === 'meta' && TokenUtils::hasTypeOf( $t, 'mw:Transclusion' ) ) { return true; } elseif ( $t instanceof TagTk || $t instanceof EndTagTk || $t instanceof SelfclosingTagTk ) { // Since we encountered a complex token, we'll process this // in a subpipeline. return false; } } // No complex tokens at all -- no need to spin up a new pipeline return true; } /** * @param Token $scopeToken * @return array|null */ private function buildDOMFragment( Token $scopeToken ) { $contentKV = $scopeToken->getAttributeKV( 'content' ); $content = $contentKV->v; if ( is_string( $content ) || $this->subpipelineUnnecessary( $content, $scopeToken->getAttribute( 'contextTok' ) ) ) { // New pipeline not needed. Pass them through return [ 'tokens' => is_string( $content ) ? [ $content ] : $content ]; } else { // Source offsets of content $srcOffsets = $contentKV->srcOffsets; // Without source offsets for the content, it isn't possible to // compute DSR and template wrapping in content. So, users of // mw:dom-fragment-token should always set offsets on content // that comes from the top-level document. Assert::invariant( !empty( $this->options['inTemplate'] ) || (bool)$srcOffsets, 'Processing top-level content without source offsets' ); $pipelineOpts = [ 'inlineContext' => $scopeToken->getAttribute( 'inlineContext' ) === "1", 'expandTemplates' => $this->options['expandTemplates'], 'inTemplate' => $this->options['inTemplate'] ]; // Process tokens $dom = PipelineUtils::processContentInPipeline( $this->manager->env, $this->manager->getFrame(), // Append EOF array_merge( $content, [ new EOFTk() ] ), [ 'pipelineType' => 'tokens/x-mediawiki/expanded', 'pipelineOpts' => $pipelineOpts, 'srcOffsets' => $srcOffsets->value, 'sol' => true ] ); $toks = PipelineUtils::tunnelDOMThroughTokens( $this->manager->env, $scopeToken, DOMCompat::getBody( $dom ), [ "pipelineOpts" => $pipelineOpts ] ); return [ 'tokens' => $toks ]; } } /** * @inheritDoc */ public function onTag( Token $token ) { return $token->getName() === 'mw:dom-fragment-token' ? $this->buildDOMFragment( $token ) : $token; } }