22use InvalidArgumentException;
37 self::FORMAT_WIKITEXT =>
'plain',
38 self::FORMAT_HTML =>
'html',
39 self::FORMAT_PAGEBUNDLE =>
'json',
40 self::FORMAT_LINT =>
'json',
61 string $format, ?
string $contentVersion =
null
64 throw new InvalidArgumentException(
'$contentVersion is required for this format' );
69 $contentType =
'text/plain';
72 $profile =
'https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0';
75 $contentType =
'text/html';
76 $profile =
'https://www.mediawiki.org/wiki/Specs/HTML/' . $contentVersion;
79 $contentType =
'application/json';
80 $profile =
'https://www.mediawiki.org/wiki/Specs/pagebundle/' . $contentVersion;
83 throw new InvalidArgumentException(
"Invalid format $format" );
85 return "$contentType; charset=utf-8; profile=\"$profile\"";
97 ?
string $contentVersion =
null
99 $response->setHeader(
'Content-Type', self::getContentType( $format, $contentVersion ) );
111 string $contentTypeHeader, ?
string &$format =
null
113 $newProfileSyntax =
'https://www.mediawiki.org/wiki/Specs/(HTML|pagebundle)/';
114 $oldProfileSyntax =
'mediawiki.org/specs/(html)/';
115 $profileRegex =
"#\bprofile=\"(?:$newProfileSyntax|$oldProfileSyntax)(\d+\.\d+\.\d+)\"#";
116 preg_match( $profileRegex, $contentTypeHeader, $m );
118 switch ( $m[1] ?: $m[2] ) {
121 $format = self::FORMAT_HTML;
124 $format = self::FORMAT_PAGEBUNDLE;
if(!defined('MW_SETUP_CALLBACK'))