private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp;
private $mBuffer, $mDisabled = false;
private $mIsWrappedHtml = false;
+ private $mHttpStatus = false;
protected $mForceDefaultParams = false;
/**
}
}
+ /**
+ * Set the HTTP status code to be used for the response
+ * @since 1.29
+ * @param int $code
+ */
+ public function setHttpStatus( $code ) {
+ if ( $this->mDisabled ) {
+ return;
+ }
+
+ if ( $this->getIsHtml() ) {
+ $this->mHttpStatus = $code;
+ } else {
+ $this->getMain()->getRequest()->response()->statusHeader( $code );
+ }
+ }
+
/**
* Initialize the printer function and prepare the output headers.
* @param bool $unused Always false since 1.25
ApiHelp::fixHelpLinks( $header )
)
);
+
+ if ( $this->mHttpStatus && $this->mHttpStatus !== 200 ) {
+ $out->addHTML(
+ Html::rawElement( 'div', [ 'class' => 'api-pretty-header api-pretty-status' ],
+ $this->msg(
+ 'api-format-prettyprint-status',
+ $this->mHttpStatus,
+ HttpStatus::getMessage( $this->mHttpStatus )
+ )->parse()
+ )
+ );
+ }
}
if ( Hooks::run( 'ApiFormatHighlight', [ $context, $result, $mime, $format ] ) ) {
$time = microtime( true ) - $this->getConfig()->get( 'RequestTime' );
$json = FormatJson::encode(
[
+ 'status' => (int)( $this->mHttpStatus ?: 200 ),
+ 'statustext' => HttpStatus::getMessage( $this->mHttpStatus ?: 200 ),
'html' => $out->getHTML(),
'modules' => array_values( array_unique( array_merge(
$out->getModules(),