Page MenuHomePhabricator

Exports are corrupted with Warning: Cannot modify header information
Closed, ResolvedPublicBUG REPORT


Steps to Reproduce:
Make a query with format CSV or JSON (these were the ones I tested, but the bug should affect all the export formats).

In order for the problem to happen, some debug options must be enabled in LocalSettings.php, In my LocalSettings.php I have the following:

// Debug errors
error_reporting( -1 );
ini_set( 'display_errors', 1 );
$wgShowExceptionDetails = true;
$wgShowDBErrorBacktrace = true;
$wgShowSQLErrors = 1;

Actual Results:
We get the CSV or JSON data, but there are several PHP warnings appended at the end (which corrupt the format of the data).

The warnings, rendered in HTML, are like this one (I am getting 6 of them):

Expected Results:
CSV, JSON, or any other format without warnings appended at the end.

The problem is related to the OutputPage class. The special page that runs the exports (CargoExport.php) is first writing the headers and the output to php://output, but then the OutputPage class tries to write a page with his own headers. To fix the problem, the OutputPage class should be disabled, this is explained in

Event Timeline

Change 509612 had a related patch set uploaded (by Tombolano; owner: Tombolano):
[mediawiki/extensions/Cargo@master] Fix for exports formats

Aklapper renamed this task from Exports are corrupted with warnings to Exports are corrupted with Warning: Cannot modify header information.May 12 2019, 12:46 PM

I was checking again this problem and I realized that I had several options set to debug errors on LocalSetting.php. Disabling this options solves the problem since no warnings are appended at the output, so this bug only occurs when using the debug options. I updated the bug description with this information.

Thanks for this bug report. Are all the warnings just "Cannot modify header information" - maybe some of the first ones are different from that?

All the warnings are "Cannot modify header information". I am getting 6 of them, the given locations of the warnings in OutputPage.php are: 2665, 2667, 2681, 2531, 2575, and 2576, which are the lines that set the headers.

I have uploaded a second patch. In the first patch that I uploaded I disabled the output in the constructor of the CargoExport class, but that made the MediaWiki SpecialPages page to be blank, I have no idea why, it is very strange, everything else seems to work fine. I uploaded a second patch where I just replaced the line "$this->getOutput()->setArticleBodyOnly( true );" with "$this->getOutput()->disable();", that seems to work fine.

Change 509612 merged by jenkins-bot:
[mediawiki/extensions/Cargo@master] Fix for export formats

Yaron_Koren claimed this task.

Thanks for the patch! Simple patches are the best kind. I just merged it in.