wiki.techinc.nl/includes/parser/Parsoid/ParsoidParserFactory.php
Subramanya Sastry c8d0470f4b Make ParsoidOutputAccess a wrapper over ParserOutputAccess
* Updated ParserOutput to set Parsoid render ids that REST API
  functionality expects in ParserOutput objects.
* CacheThresholdTime functionality no longer exists since it was
  implemented in ParsoidOutputAccess and ParserOutputAccess doesn't
  support it. This is tracked in T346765.
* Enforce the constraint that uncacheable parses are only for fake or
  mutable revisions. Updated tests that violated this constraint to
  use 'getParseOutput' instead of calling the parse method directly.
* Had to make some changes in ParsoidParser around use of preferredVariant
  passed to Parsoid. I also left some TODO comments for future fixes.
  T267067 is also relevant here.

PARSOID-SPECIFIC OPTIONS:
* logLinterData: linter data is always logged by default -- removed
  support to disable it. Linter extension handles stale lints properly
  and it is better to let it handle it rather than add special cases
  to the API.
* offsetType: Moved this support to ParsoidHandler as a post-processing
  of byte-offset output. This eliminates the need to support this
  Parsoid-specific options in the ContentHandler hierarchies.
* body_only / wrapSections: Handled this in HtmlOutputRendererHelper
  as a post-processing of regular output by removing sections and
  returning the body content only. This does result in some useless
  section-wrapping work with Parsoid, but the simplification is probably
  worth it. If in the future, we support Parsoid-specific options in
  the ContentHandler hierarchy, we could re-introduce this. But, in any
  case, this "fragment" flavor options is likely to get moved out of
  core into the VisualEditor extension code.

DEPLOYMENT:
* This patch changes the cache key by setting the useParsoid option
  in ParserOptions. The parent patch handles this to ensure we don't
  encounter a cold cache on deploy.

TESTS:
* Updated tests and mocks to reflect new reality.
* Do we need any new tests?

Bug: T332931
Change-Id: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
2023-10-13 15:03:03 -05:00

84 lines
2.2 KiB
PHP

<?php
namespace MediaWiki\Parser\Parsoid;
use MediaWiki\Languages\LanguageConverterFactory;
use MediaWiki\Parser\Parsoid\Config\PageConfigFactory;
use ParserFactory;
use Wikimedia\Parsoid\Config\DataAccess;
use Wikimedia\Parsoid\Config\SiteConfig;
use Wikimedia\Parsoid\Parsoid;
use Wikimedia\UUID\GlobalIdGenerator;
/**
* ParserFactory which uses a ParsoidParser.
*
* This is similar to \ParserFactory, but simplified since we don't need
* to try to reuse parser objects. Eventually we'll be able to simplify
* \ParserFactory the same way.
*
* @since 1.41
* @internal May be combined with \ParserFactory or otherwise refactored
*
* @file
* @ingroup Parser
*/
class ParsoidParserFactory /* eventually this may extend \ParserFactory */ {
/** @var SiteConfig */
private $siteConfig;
/** @var DataAccess */
private $dataAccess;
/** @var PageConfigFactory */
private $pageConfigFactory;
/** @var LanguageConverterFactory */
private $languageConverterFactory;
/** @var ParserFactory */
private $legacyParserFactory;
/** @var GlobalIdGenerator */
private $globalIdGenerator;
/**
* @param SiteConfig $siteConfig
* @param DataAccess $dataAccess
* @param PageConfigFactory $pageConfigFactory
* @param LanguageConverterFactory $languageConverterFactory
* @param ParserFactory $legacyParserFactory
*/
public function __construct(
SiteConfig $siteConfig,
DataAccess $dataAccess,
PageConfigFactory $pageConfigFactory,
LanguageConverterFactory $languageConverterFactory,
ParserFactory $legacyParserFactory,
GlobalIdGenerator $globalIdGenerator
) {
$this->siteConfig = $siteConfig;
$this->dataAccess = $dataAccess;
$this->pageConfigFactory = $pageConfigFactory;
$this->languageConverterFactory = $languageConverterFactory;
$this->legacyParserFactory = $legacyParserFactory;
$this->globalIdGenerator = $globalIdGenerator;
}
/**
* Creates a new Parsoid parser.
* @return ParsoidParser
* @since 1.41
* @unstable
*/
public function create(): ParsoidParser {
return new ParsoidParser(
new Parsoid( $this->siteConfig, $this->dataAccess ),
$this->pageConfigFactory,
$this->languageConverterFactory,
$this->legacyParserFactory,
$this->globalIdGenerator
);
}
}