diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
commit | 6dc1997577fab2c366781fd7048144935afa0012 (patch) | |
tree | 8918d28c7ab4342f0738985e37af1dfc42d0e93a /includes/api/ApiFormatRaw.php | |
parent | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (diff) | |
parent | fa89acd685cb09cdbe1c64cbb721ec64975bbbc1 (diff) |
Merge commit 'fa89acd'
# Conflicts:
# .gitignore
# extensions/ArchInterWiki.sql
Diffstat (limited to 'includes/api/ApiFormatRaw.php')
-rw-r--r-- | includes/api/ApiFormatRaw.php | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/includes/api/ApiFormatRaw.php b/includes/api/ApiFormatRaw.php index 7bb2453d..9dbd4a55 100644 --- a/includes/api/ApiFormatRaw.php +++ b/includes/api/ApiFormatRaw.php @@ -31,14 +31,20 @@ class ApiFormatRaw extends ApiFormatBase { private $errorFallback; + private $mFailWithHTTPError = false; + /** * @param ApiMain $main - * @param ApiFormatBase $errorFallback Object to fall back on for errors + * @param ApiFormatBase |null $errorFallback Object to fall back on for errors */ - public function __construct( ApiMain $main, ApiFormatBase $errorFallback ) { + public function __construct( ApiMain $main, ApiFormatBase $errorFallback = null ) { parent::__construct( $main, 'raw' ); - $this->errorFallback = $errorFallback; + if ( $errorFallback === null ) { + $this->errorFallback = $main->createPrinterByName( $main->getParameter( 'format' ) ); + } else { + $this->errorFallback = $errorFallback; + } } public function getMimeType() { @@ -59,6 +65,9 @@ class ApiFormatRaw extends ApiFormatBase { $data = $this->getResult()->getResultData(); if ( isset( $data['error'] ) ) { $this->errorFallback->initPrinter( $unused ); + if ( $this->mFailWithHTTPError ) { + $this->getMain()->getRequest()->response()->statusHeader( 400 ); + } } else { parent::initPrinter( $unused ); } @@ -85,4 +94,17 @@ class ApiFormatRaw extends ApiFormatBase { } $this->printText( $data['text'] ); } + + /** + * Output HTTP error code 400 when if an error is encountered + * + * The purpose is for output formats where the user-agent will + * not be able to interpret the validity of the content in any + * other way. For example subtitle files read by browser video players. + * + * @param bool $fail + */ + public function setFailWithHTTPError( $fail ) { + $this->mFailWithHTTPError = $fail; + } } |