mediawiki-extensions-Visual.../includes/ParsoidClient.php
thiemowmde ab2cbb3b70 Change almost all code to use Bcp47Code instead of Language
This patch makes the following assumptions:

1. There is no class outside of this codebase that implements the
ParsoidClient interface. According to CodeSearch this appears to be
correct.

2. It is fine to use the Bcp47Code instead of the internal MediaWiki
language code in the "Accept-Language" HTTP header. As far as I
understand this might even qualify as a bugfix.

Depends-On: If059674597e261039df7f4613a89cb08120c3262
Change-Id: Icd160da2d5555891b9a91a0cb966bd36a55f6fdd
2023-07-12 09:38:16 +02:00

63 lines
2.2 KiB
PHP

<?php
namespace MediaWiki\Extension\VisualEditor;
use MediaWiki\Page\PageIdentity;
use MediaWiki\Revision\RevisionRecord;
use Wikimedia\Bcp47Code\Bcp47Code;
interface ParsoidClient {
/**
* Request page HTML
*
* @param RevisionRecord $revision Page revision
* @param Bcp47Code|null $targetLanguage Desired output language
*
* @return array An array containing the keys 'body', 'headers', and optionally 'error'
* @phan-return array{body:string,headers:array<string,string>,error?:non-empty-array}
*/
public function getPageHtml( RevisionRecord $revision, ?Bcp47Code $targetLanguage ): array;
/**
* Transform HTML to wikitext via Parsoid
*
* @param PageIdentity $page The page the content belongs to
* @param Bcp47Code $targetLanguage The desired output language
* @param string $html The HTML of the page to be transformed
* @param ?int $oldid What oldid revision, if any, to base the request from (default: `null`)
* @param ?string $etag The ETag to set in the HTTP request header
*
* @return array An array containing the keys 'body', 'headers', and optionally 'error'
* @phan-return array{body:string,headers:array<string,string>,error?:non-empty-array}
*/
public function transformHTML(
PageIdentity $page,
Bcp47Code $targetLanguage,
string $html,
?int $oldid,
?string $etag
): array;
/**
* Transform wikitext to HTML via Parsoid.
*
* @param PageIdentity $page The page the content belongs to
* @param Bcp47Code $targetLanguage The desired output language
* @param string $wikitext The wikitext fragment to parse
* @param bool $bodyOnly Whether to provide only the contents of the `<body>` tag
* @param ?int $oldid What oldid revision, if any, to base the request from (default: `null`)
* @param bool $stash Whether to stash the result in the server-side cache (default: `false`)
*
* @return array An array containing the keys 'body', 'headers', and optionally 'error'
* @phan-return array{body:string,headers:array<string,string>,error?:non-empty-array}
*/
public function transformWikitext(
PageIdentity $page,
Bcp47Code $targetLanguage,
string $wikitext,
bool $bodyOnly,
?int $oldid,
bool $stash
): array;
}