42 $config = MediaWikiServices::getInstance()->getMainConfig();
43 $disableOutputCompression = $config->get( MainConfigNames::DisableOutputCompression );
44 $mangleFlashPolicy = $config->get( MainConfigNames::MangleFlashPolicy );
46 if ( ( $phase & PHP_OUTPUT_HANDLER_CLEAN ) === PHP_OUTPUT_HANDLER_CLEAN ) {
47 $logger = LoggerFactory::getInstance(
'output' );
48 $logger->debug( __METHOD__ .
" entrypoint={entry}; size={size}; phase=$phase", [
50 'size' => strlen(
$s ),
56 if ( $mangleFlashPolicy ) {
57 $s = self::mangleFlashPolicy(
$s );
62 $phpHandlesCompression = (
63 ini_get(
'output_handler' ) ===
'ob_gzhandler' ||
64 ini_get(
'zlib.output_handler' ) ===
'ob_gzhandler' ||
66 strtolower( ini_get(
'zlib.output_compression' ) ),
73 !$phpHandlesCompression &&
75 !defined(
'MW_NO_OUTPUT_COMPRESSION' ) &&
77 !$disableOutputCompression
79 $s = self::handleGzip(
$s );
84 !$phpHandlesCompression &&
86 !ini_get(
'output_handler' ) &&
87 !ini_get(
'zlib.output_handler' )
89 self::emitContentLength( strlen(
$s ) );
107 if ( isset( $_SERVER[
'REQUEST_URI'] ) ) {
109 $path = explode(
'?', $_SERVER[
'REQUEST_URI'], 2 )[0];
110 } elseif ( isset( $_SERVER[
'SCRIPT_NAME'] ) ) {
112 $path = $_SERVER[
'SCRIPT_NAME'];
118 $period = strrpos(
$path,
'.' );
119 if ( $period !==
false ) {
120 return strtolower( substr(
$path, $period ) );
136 if ( !function_exists(
'gzencode' ) ) {
137 wfDebug( __METHOD__ .
"() skipping compression (gzencode unavailable)" );
140 if ( headers_sent() ) {
141 wfDebug( __METHOD__ .
"() skipping compression (headers already sent)" );
145 $ext = self::findUriExtension();
146 if (
$ext ==
'.gz' ||
$ext ==
'.tgz' ) {
162 wfDebug( __METHOD__ .
"() is compressing output" );
163 header(
'Content-Encoding: gzip' );
164 $s = gzencode(
$s, 6 );
168 $headers = headers_list();
170 foreach ( $headers as
$header ) {
171 $headerName = strtolower( substr(
$header, 0, 5 ) );
172 if ( $headerName ==
'vary:' ) {
178 header(
'Vary: Accept-Encoding' );
190 # Avoid weird excessive memory usage in PCRE on big articles
191 if ( preg_match(
'/<\s*cross-domain-policy(?=\s|>)/i',
$s ) ) {
192 return preg_replace(
'/<(\s*)(cross-domain-policy(?=\s|>))/i',
'<$1NOT-$2',
$s );
214 if ( headers_sent() ) {
215 wfDebug( __METHOD__ .
"() headers already sent" );
220 in_array( http_response_code(), [ 200, 404 ],
true ) ||
221 ( $_SERVER[
'SERVER_PROTOCOL'] ??
null ) ===
'HTTP/1.0'
223 header(
"Content-Length: $length" );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
if(!is_readable( $file)) $ext