From 8c76a6f0ff0a25145234127b71c2c2124a74d7f0 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 21 Aug 2015 11:48:03 -0400 Subject: [PATCH] Unbreak wfResetOutputBuffers Sometime between 5.3 and 5.6, PHP changed from considering the default output buffer (ob_start() or ob_start( null )) as "user" to considering it as "internal", which prevents wfResetOutputBuffers() from removing any buffers. What we really should do here is test directly for whether the buffer can be deleted, using the 'del' flag in PHP 5.3 or 'flags' in PHP 5.4+. As for HHVM, we'll need to continue falling back to testing 'type' for now thanks to https://github.com/facebook/hhvm/issues/5563. Bug: T109842 Change-Id: If0163257a8fb471fd594a3754a20c65274f84a4c --- includes/GlobalFunctions.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index c3740a0146..e158e5cc40 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2179,10 +2179,16 @@ function wfResetOutputBuffers( $resetGzipEncoding = true ) { $wgDisableOutputCompression = true; } while ( $status = ob_get_status() ) { - if ( $status['type'] == 0 /* PHP_OUTPUT_HANDLER_INTERNAL */ ) { - // Probably from zlib.output_compression or other - // PHP-internal setting which can't be removed. - // + if ( isset( $status['flags'] ) ) { + $flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE; + $deleteable = ( $status['flags'] & $flags ) === $flags; + } elseif ( isset( $status['del'] ) ) { + $deleteable = $status['del']; + } else { + // Guess that any PHP-internal setting can't be removed. + $deleteable = $status['type'] !== 0; /* PHP_OUTPUT_HANDLER_INTERNAL */ + } + if ( !$deleteable ) { // Give up, and hope the result doesn't break // output behavior. break; -- 2.20.1