X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FOutputHandler.php;h=abf091e29661ffbd0cb2307c4566d377bb00a1fe;hb=21b7b27f0379cff1b06efa95d27fa88684b65c57;hp=3d123c34abf95dc3dcbd8e77cbcdaeba09326d67;hpb=da85e1731621ea528cc99c48c8881a00cfd3e1ab;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputHandler.php b/includes/OutputHandler.php index 3d123c34ab..abf091e296 100644 --- a/includes/OutputHandler.php +++ b/includes/OutputHandler.php @@ -1,12 +1,36 @@ $value ) { @@ -35,9 +59,11 @@ function wfOutputHandler( $s ) { * the currently-requested URL. * This isn't on WebRequest because we need it when things aren't initialized * @private + * + * @return string */ function wfRequestExtension() { - /// @fixme -- this sort of dupes some code in WebRequest::getRequestUrl() + /// @todo FIXME: this sort of dupes some code in WebRequest::getRequestUrl() if( isset( $_SERVER['REQUEST_URI'] ) ) { // Strip the query string... list( $path ) = explode( '?', $_SERVER['REQUEST_URI'], 2 ); @@ -59,9 +85,18 @@ function wfRequestExtension() { /** * Handler that compresses data with gzip if allowed by the Accept header. * Unlike ob_gzhandler, it works for HEAD requests too. + * + * @param $s string + * + * @return string */ function wfGzipHandler( $s ) { - if( !function_exists( 'gzencode' ) || headers_sent() ) { + if( !function_exists( 'gzencode' ) ) { + wfDebug( __FUNCTION__ . "() skipping compression (gzencode unavaible)\n" ); + return $s; + } + if( headers_sent() ) { + wfDebug( __FUNCTION__ . "() skipping compression (headers already sent)\n" ); return $s; } @@ -74,12 +109,10 @@ function wfGzipHandler( $s ) { return $s; } - if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { - $tokens = preg_split( '/[,; ]/', $_SERVER['HTTP_ACCEPT_ENCODING'] ); - if ( in_array( 'gzip', $tokens ) ) { - header( 'Content-Encoding: gzip' ); - $s = gzencode( $s, 3 ); - } + if( wfClientAcceptsGzip() ) { + wfDebug( __FUNCTION__ . "() is compressing output\n" ); + header( 'Content-Encoding: gzip' ); + $s = gzencode( $s, 6 ); } // Set vary header if it hasn't been set already @@ -93,13 +126,20 @@ function wfGzipHandler( $s ) { } if ( !$foundVary ) { header( 'Vary: Accept-Encoding' ); - header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip' ); + global $wgUseXVO; + if ( $wgUseXVO ) { + header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip' ); + } } return $s; } /** * Mangle flash policy tags which open up the site to XSS attacks. + * + * @param $s string + * + * @return string */ function wfMangleFlashPolicy( $s ) { # Avoid weird excessive memory usage in PCRE on big articles @@ -112,66 +152,34 @@ function wfMangleFlashPolicy( $s ) { /** * Add a Content-Length header if possible. This makes it cooperate with squid better. + * + * @param $length int */ function wfDoContentLength( $length ) { - if ( !headers_sent() && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' ) { + if ( !headers_sent() && isset( $_SERVER['SERVER_PROTOCOL'] ) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' ) { header( "Content-Length: $length" ); } } /** * Replace the output with an error if the HTML is not valid + * + * @param $s string + * + * @return string */ function wfHtmlValidationHandler( $s ) { - global $IP, $wgTidyInternal, $wgTidyConf; - if ( $wgTidyInternal ) { - $tidy = new tidy; - - $tidy->parseString( $s, $wgTidyConf, 'utf8' ); - if ( $tidy->getStatus() == 0 ) { - return $s; - } - $errors = $tidy->errorBuffer; - } else { - // Copied from Parser::externalTidy(); - global $wgTidyBin, $wgTidyOpts; - - $cleansource = ''; - $opts = ' -utf8'; - - $descriptorspec = array( - 0 => array( 'pipe', 'r' ), - 1 => array( 'file', wfGetNull(), 'a' ), - 2 => array( 'pipe', 'w' ) - ); - $pipes = array(); - if( function_exists( 'proc_open' ) ) { - $process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts$opts", $descriptorspec, $pipes ); - if ( is_resource( $process ) ) { - fwrite( $pipes[0], $s ); - fclose( $pipes[0] ); - while( !feof( $pipes[2] ) ) { - $errors .= fgets( $pipes[2], 1024 ); - } - fclose( $pipes[2] ); - $ret = proc_close( $process ); - if( ( $ret < 0 && $errors == '' ) || $ret == 0 ) - return $s; - } else { - return $s; - } - - } else { - return $s; - } + $errors = ''; + if ( MWTidy::checkErrors( $s, $errors ) ) { + return $s; } header( 'Cache-Control: no-cache' ); $out = << - + HTML validation error