getDataAccess()->preprocessWikitext( $env->getPageConfig(), $env->getMetadata(), $wt ); // FIXME: Should this bump be len($ret) - len($wt)? // I could argue both ways. if ( !$env->bumpWt2HtmlResourceUse( 'wikitextSize', strlen( $ret ) ) ) { return [ 'error' => true, 'src' => "wt2html: wikitextSize limit exceeded", ]; } if ( $env->profiling() ) { $profile = $env->getCurrentProfile(); $profile->bumpMWTime( "Template", 1000 * ( microtime( true ) - $start ), "api" ); $profile->bumpCount( "Template" ); } return [ 'error' => false, 'src' => $ret, ]; } /** * Perform pre-save transformations * * @param Env $env * @param string $wt * @param bool $substTLTemplates Prefix each top-level template with 'subst' * @return string */ public static function pst( Env $env, string $wt, bool $substTLTemplates = false ) { if ( $substTLTemplates ) { // To make sure we do this for the correct templates, tokenize the // starting wikitext and use that to detect top-level templates. // Then, substitute each starting '{{' with '{{subst' using the // template token's tsr. $tokenizer = new PegTokenizer( $env ); $tokens = $tokenizer->tokenizeSync( $wt, [ 'sol' => true ] ); $tsrIncr = 0; foreach ( $tokens as $token ) { /** @var Token $token */ if ( $token->getName() === 'template' ) { $tsr = $token->dataParsoid->tsr; $wt = substr( $wt, 0, $tsr->start + $tsrIncr ) . '{{subst:' . substr( $wt, $tsr->start + $tsrIncr + 2 ); $tsrIncr += 6; } } } return $env->getDataAccess()->doPst( $env->getPageConfig(), $wt ); } }