MediaWiki
master
Toggle main menu visibility
ApiFormatRaw.php
Go to the documentation of this file.
1
<?php
8
9
namespace
MediaWiki\Api
;
10
15
class
ApiFormatRaw
extends
ApiFormatBase
{
16
18
private
$errorFallback;
20
private
$mFailWithHTTPError =
false
;
21
26
public
function
__construct
(
ApiMain
$main, ?
ApiFormatBase
$errorFallback =
null
) {
27
parent::__construct( $main,
'raw'
);
28
$this->errorFallback = $errorFallback ??
29
$main->
createPrinterByName
( $main->
getParameter
(
'format'
) );
30
}
31
33
public
function
getMimeType
() {
34
$data = $this->
getResult
()->getResultData();
35
36
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
37
return
$this->errorFallback->getMimeType();
38
}
39
40
if
( !isset( $data[
'mime'
] ) ) {
41
ApiBase::dieDebug
( __METHOD__,
'No MIME type set for raw formatter'
);
42
}
43
44
return
$data[
'mime'
];
45
}
46
48
public
function
getFilename
() {
49
$data = $this->
getResult
()->getResultData();
50
if
( isset( $data[
'error'
] ) ) {
51
return
$this->errorFallback->getFilename();
52
} elseif ( !isset( $data[
'filename'
] ) || $this->
getIsWrappedHtml
() || $this->
getIsHtml
() ) {
53
return
parent::getFilename();
54
}
else
{
55
return
$data[
'filename'
];
56
}
57
}
58
60
public
function
initPrinter
( $unused =
false
) {
61
$data = $this->
getResult
()->getResultData();
62
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
63
$this->errorFallback->initPrinter( $unused );
64
if
( $this->mFailWithHTTPError ) {
65
$this->
getMain
()->getRequest()->response()->statusHeader( 400 );
66
}
67
}
else
{
68
parent::initPrinter( $unused );
69
}
70
}
71
72
public
function
closePrinter
() {
73
$data = $this->
getResult
()->getResultData();
74
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
75
$this->errorFallback->closePrinter();
76
}
else
{
77
parent::closePrinter();
78
}
79
}
80
81
public
function
execute
() {
82
$data = $this->
getResult
()->getResultData();
83
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
84
$this->errorFallback->execute();
85
return
;
86
}
87
88
if
( !isset( $data[
'text'
] ) ) {
89
ApiBase::dieDebug
( __METHOD__,
'No text given for raw formatter'
);
90
}
91
$this->
printText
( $data[
'text'
] );
92
}
93
103
public
function
setFailWithHTTPError
( $fail ) {
104
$this->mFailWithHTTPError = $fail;
105
}
106
}
107
109
class_alias( ApiFormatRaw::class,
'ApiFormatRaw'
);
MediaWiki\Api\ApiBase\getMain
getMain()
Get the main module.
Definition
ApiBase.php:574
MediaWiki\Api\ApiBase\getResult
getResult()
Get the result object.
Definition
ApiBase.php:695
MediaWiki\Api\ApiBase\dieDebug
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition
ApiBase.php:1719
MediaWiki\Api\ApiBase\getParameter
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
Definition
ApiBase.php:951
MediaWiki\Api\ApiFormatBase
This is the abstract base class for API formatters.
Definition
ApiFormatBase.php:29
MediaWiki\Api\ApiFormatBase\getIsWrappedHtml
getIsWrappedHtml()
Returns true when the special-wrapped mode is enabled.
Definition
ApiFormatBase.php:118
MediaWiki\Api\ApiFormatBase\printText
printText( $text)
Append text to the output buffer.
Definition
ApiFormatBase.php:369
MediaWiki\Api\ApiFormatBase\getIsHtml
getIsHtml()
Returns true when the HTML pretty-printer should be used.
Definition
ApiFormatBase.php:108
MediaWiki\Api\ApiFormatRaw
Formatter that spits out anything you like with any desired MIME type.
Definition
ApiFormatRaw.php:15
MediaWiki\Api\ApiFormatRaw\setFailWithHTTPError
setFailWithHTTPError( $fail)
Output HTTP error code 400 when if an error is encountered.
Definition
ApiFormatRaw.php:103
MediaWiki\Api\ApiFormatRaw\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition
ApiFormatRaw.php:81
MediaWiki\Api\ApiFormatRaw\initPrinter
initPrinter( $unused=false)
Initialize the printer function and prepare the output headers.
Definition
ApiFormatRaw.php:60
MediaWiki\Api\ApiFormatRaw\getMimeType
getMimeType()
Overriding class returns the MIME type that should be sent to the client.When getIsHtml() returns tru...
Definition
ApiFormatRaw.php:33
MediaWiki\Api\ApiFormatRaw\__construct
__construct(ApiMain $main, ?ApiFormatBase $errorFallback=null)
Definition
ApiFormatRaw.php:26
MediaWiki\Api\ApiFormatRaw\closePrinter
closePrinter()
Finish printing and output buffered data.
Definition
ApiFormatRaw.php:72
MediaWiki\Api\ApiFormatRaw\getFilename
getFilename()
Return a filename for this module's output.If $this->getIsWrappedHtml() || $this->getIsHtml(),...
Definition
ApiFormatRaw.php:48
MediaWiki\Api\ApiMain
This is the main API class, used for both external and internal processing.
Definition
ApiMain.php:66
MediaWiki\Api\ApiMain\createPrinterByName
createPrinterByName( $format)
Create an instance of an output formatter by its name.
Definition
ApiMain.php:904
MediaWiki\Api
Definition
ApiAcquireTempUserName.php:8
includes
Api
ApiFormatRaw.php
Generated on
for MediaWiki by
1.18.0