try {
$this->main();
} catch ( ErrorPageError $e ) {
+ $out = $this->context->getOutput();
+ // TODO: Should ErrorPageError::report accept a OutputPage parameter?
+ $e->report( ErrorPageError::STAGE_OUTPUT );
+
// T64091: while exceptions are convenient to bubble up GUI errors,
// they are not internal application faults. As with normal requests, this
// should commit, print the output, do deferred updates, jobs, and profiling.
$this->doPreOutputCommit();
- $e->report(); // display the GUI error
+ $out->output(); // display the GUI error
}
} catch ( Exception $e ) {
$context = $this->context;
*/
class BadRequestError extends ErrorPageError {
- public function report() {
+ public function report( $action = self::SEND_OUTPUT ) {
global $wgOut;
$wgOut->setStatusCode( 400 );
- parent::report();
+ parent::report( $action );
}
}
* @ingroup Exception
*/
class ErrorPageError extends MWException implements ILocalizedException {
+ const SEND_OUTPUT = 0;
+ const STAGE_OUTPUT = 1;
public $title, $msg, $params;
/**
return wfMessage( $this->msg, $this->params );
}
- public function report() {
+ public function report( $action = self::SEND_OUTPUT ) {
if ( self::isCommandLine() || defined( 'MW_API' ) ) {
parent::report();
} else {
global $wgOut;
$wgOut->showErrorPage( $this->title, $this->msg, $this->params );
- $wgOut->output();
+ // Allow skipping of the final output step, so that web-based page views
+ // from MediaWiki.php, can inspect the staged OutputPage state, and perform
+ // graceful shutdown via doPreOutputCommit first, just like for regular
+ // output when there isn't an error page.
+ if ( $action === self::SEND_OUTPUT ) {
+ $wgOut->output();
+ }
}
}
}
parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
}
- public function report() {
+ public function report( $action = self::SEND_OUTPUT ) {
global $wgOut;
$wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
- $wgOut->output();
+ if ( $action === self::SEND_OUTPUT ) {
+ $wgOut->output();
+ }
}
}
);
}
- public function report() {
+ public function report( $action = ErrorPageError::SEND_OUTPUT ) {
global $wgOut;
$wgOut->setStatusCode( 429 );
- parent::report();
+ parent::report( $action );
}
}
* Redirect to Special:Userlogin if the specified message is compatible. Otherwise,
* show an error page as usual.
*/
- public function report() {
+ public function report( $action = self::SEND_OUTPUT ) {
// If an unsupported message is used, don't try redirecting to Special:Userlogin,
// since the message may not be compatible.
if ( !in_array( $this->msg, LoginHelper::getValidErrorMessages() ) ) {
- parent::report();
+ parent::report( $action );
return;
}
'warning' => $this->msg,
] ) );
- $output->output();
+ if ( $action === self::SEND_OUTPUT ) {
+ $output->output();
+ }
}
}
);
}
- public function report() {
+ public function report( $action = self::SEND_OUTPUT ) {
global $wgOut;
$wgOut->setStatusCode( 429 );
- parent::report();
+ parent::report( $action );
}
}