42 $config = MediaWikiServices::getInstance()->getMainConfig();
43 $disableOutputCompression = $config->get( MainConfigNames::DisableOutputCompression );
45 if ( ( $phase & PHP_OUTPUT_HANDLER_CLEAN ) === PHP_OUTPUT_HANDLER_CLEAN ) {
46 $logger = LoggerFactory::getInstance(
'output' );
47 $logger->debug( __METHOD__ .
" entrypoint={entry}; size={size}; phase=$phase", [
49 'size' => strlen(
$s ),
57 $phpHandlesCompression = (
58 ini_get(
'output_handler' ) ===
'ob_gzhandler' ||
59 ini_get(
'zlib.output_handler' ) ===
'ob_gzhandler' ||
61 strtolower( ini_get(
'zlib.output_compression' ) ),
68 !$phpHandlesCompression &&
70 !defined(
'MW_NO_OUTPUT_COMPRESSION' ) &&
72 !$disableOutputCompression
74 $s = self::handleGzip(
$s );
79 !$phpHandlesCompression &&
81 !ini_get(
'output_handler' ) &&
82 !ini_get(
'zlib.output_handler' )
84 self::emitContentLength( strlen(
$s ) );
100 private static function findUriExtension() {
102 if ( isset( $_SERVER[
'REQUEST_URI'] ) ) {
104 $path = explode(
'?', $_SERVER[
'REQUEST_URI'], 2 )[0];
105 } elseif ( isset( $_SERVER[
'SCRIPT_NAME'] ) ) {
107 $path = $_SERVER[
'SCRIPT_NAME'];
113 $period = strrpos(
$path,
'.' );
114 if ( $period !==
false ) {
115 return strtolower( substr(
$path, $period ) );
130 private static function handleGzip(
$s ) {
131 if ( !function_exists(
'gzencode' ) ) {
132 wfDebug( __METHOD__ .
"() skipping compression (gzencode unavailable)" );
135 if ( headers_sent() ) {
136 wfDebug( __METHOD__ .
"() skipping compression (headers already sent)" );
140 $ext = self::findUriExtension();
141 if (
$ext ==
'.gz' ||
$ext ==
'.tgz' ) {
157 wfDebug( __METHOD__ .
"() is compressing output" );
158 header(
'Content-Encoding: gzip' );
159 $s = gzencode(
$s, 6 );
163 $headers = headers_list();
165 foreach ( $headers as
$header ) {
166 $headerName = strtolower( substr(
$header, 0, 5 ) );
167 if ( $headerName ==
'vary:' ) {
173 header(
'Vary: Accept-Encoding' );
193 private static function emitContentLength( $length ) {
194 if ( headers_sent() ) {
195 wfDebug( __METHOD__ .
"() headers already sent" );
200 in_array( http_response_code(), [ 200, 404 ],
true ) ||
201 ( $_SERVER[
'SERVER_PROTOCOL'] ??
null ) ===
'HTTP/1.0'
203 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