10use InvalidArgumentException;
25 self::FORMAT_WIKITEXT =>
'plain',
26 self::FORMAT_HTML =>
'html',
27 self::FORMAT_PAGEBUNDLE =>
'json',
28 self::FORMAT_LINT =>
'json',
49 string $format, ?
string $contentVersion =
null
52 throw new InvalidArgumentException(
'$contentVersion is required for this format' );
57 $contentType =
'text/plain';
60 $profile =
'https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0';
63 $contentType =
'text/html';
64 $profile =
'https://www.mediawiki.org/wiki/Specs/HTML/' . $contentVersion;
67 $contentType =
'application/json';
68 $profile =
'https://www.mediawiki.org/wiki/Specs/pagebundle/' . $contentVersion;
71 throw new InvalidArgumentException(
"Invalid format $format" );
73 return "$contentType; charset=utf-8; profile=\"$profile\"";
85 ?
string $contentVersion =
null
87 $response->setHeader(
'Content-Type', self::getContentType( $format, $contentVersion ) );
99 string $contentTypeHeader, ?
string &$format =
null
101 $newProfileSyntax =
'https://www.mediawiki.org/wiki/Specs/(HTML|pagebundle)/';
102 $oldProfileSyntax =
'mediawiki.org/specs/(html)/';
103 $profileRegex =
"#\bprofile=\"(?:$newProfileSyntax|$oldProfileSyntax)(\d+\.\d+\.\d+)\"#";
104 preg_match( $profileRegex, $contentTypeHeader, $m );
106 switch ( $m[1] ?: $m[2] ) {
109 $format = self::FORMAT_HTML;
112 $format = self::FORMAT_PAGEBUNDLE;
if(!defined('MW_SETUP_CALLBACK'))