Fix invalid ORDER BY
[mediawiki.git] / includes / OutputHandler.php
blobd7e7c90fe5852b6f29acab331deafa82dc381cc4
1 <?php
3 /**
4 * Standard output handler for use with ob_start
5 */
6 function wfOutputHandler( $s ) {
7 global $wgDisableOutputCompression;
8 $s = wfMangleFlashPolicy( $s );
9 if ( !$wgDisableOutputCompression && !ini_get( 'zlib.output_compression' ) ) {
10 if ( !defined( 'MW_NO_OUTPUT_COMPRESSION' ) ) {
11 $s = wfGzipHandler( $s );
13 if ( !ini_get( 'output_handler' ) ) {
14 wfDoContentLength( strlen( $s ) );
17 return $s;
20 /**
21 * Handler that compresses data with gzip if allowed by the Accept header.
22 * Unlike ob_gzhandler, it works for HEAD requests too.
24 function wfGzipHandler( $s ) {
25 if ( function_exists( 'gzencode' ) && !headers_sent() ) {
26 $tokens = preg_split( '/[,; ]/', $_SERVER['HTTP_ACCEPT_ENCODING'] );
27 if ( in_array( 'gzip', $tokens ) ) {
28 header( 'Content-Encoding: gzip' );
29 $s = gzencode( $s, 3 );
31 # Set vary header if it hasn't been set already
32 $headers = headers_list();
33 $foundVary = false;
34 foreach ( $headers as $header ) {
35 if ( substr( $header, 0, 5 ) == 'Vary:' ) {
36 $foundVary = true;
37 break;
40 if ( !$foundVary ) {
41 header( 'Vary: Accept-Encoding' );
45 return $s;
48 /**
49 * Mangle flash policy tags which open up the site to XSS attacks.
51 function wfMangleFlashPolicy( $s ) {
52 return preg_replace( '/\<\s*cross-domain-policy\s*\>/i', '<NOT-cross-domain-policy>', $s );
55 /**
56 * Add a Content-Length header if possible. This makes it cooperate with squid better.
58 function wfDoContentLength( $length ) {
59 if ( !headers_sent() && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' ) {
60 header( "Content-Length: $length" );