MediaWiki
master
ApiFormatRaw.php
Go to the documentation of this file.
1
<?php
27
class
ApiFormatRaw
extends
ApiFormatBase
{
28
30
private
$errorFallback;
32
private
$mFailWithHTTPError =
false
;
33
38
public
function
__construct
(
ApiMain
$main,
ApiFormatBase
$errorFallback =
null
) {
39
parent::__construct( $main,
'raw'
);
40
$this->errorFallback = $errorFallback ?:
41
$main->
createPrinterByName
( $main->
getParameter
(
'format'
) );
42
}
43
44
public
function
getMimeType
() {
45
$data = $this->
getResult
()->getResultData();
46
47
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
48
return
$this->errorFallback->getMimeType();
49
}
50
51
if
( !isset( $data[
'mime'
] ) ) {
52
ApiBase::dieDebug
( __METHOD__,
'No MIME type set for raw formatter'
);
53
}
54
55
return
$data[
'mime'
];
56
}
57
58
public
function
getFilename
() {
59
$data = $this->
getResult
()->getResultData();
60
if
( isset( $data[
'error'
] ) ) {
61
return
$this->errorFallback->getFilename();
62
} elseif ( !isset( $data[
'filename'
] ) || $this->
getIsWrappedHtml
() || $this->
getIsHtml
() ) {
63
return
parent::getFilename();
64
}
else
{
65
return
$data[
'filename'
];
66
}
67
}
68
69
public
function
initPrinter
( $unused =
false
) {
70
$data = $this->
getResult
()->getResultData();
71
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
72
$this->errorFallback->initPrinter( $unused );
73
if
( $this->mFailWithHTTPError ) {
74
$this->
getMain
()->getRequest()->response()->statusHeader( 400 );
75
}
76
}
else
{
77
parent::initPrinter( $unused );
78
}
79
}
80
81
public
function
closePrinter
() {
82
$data = $this->
getResult
()->getResultData();
83
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
84
$this->errorFallback->closePrinter();
85
}
else
{
86
parent::closePrinter();
87
}
88
}
89
90
public
function
execute
() {
91
$data = $this->
getResult
()->getResultData();
92
if
( isset( $data[
'error'
] ) || isset( $data[
'errors'
] ) ) {
93
$this->errorFallback->execute();
94
return
;
95
}
96
97
if
( !isset( $data[
'text'
] ) ) {
98
ApiBase::dieDebug
( __METHOD__,
'No text given for raw formatter'
);
99
}
100
$this->
printText
( $data[
'text'
] );
101
}
102
112
public
function
setFailWithHTTPError
( $fail ) {
113
$this->mFailWithHTTPError = $fail;
114
}
115
}
ApiBase\getParameter
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
Definition
ApiBase.php:964
ApiBase\dieDebug
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition
ApiBase.php:1811
ApiBase\getMain
getMain()
Get the main module.
Definition
ApiBase.php:580
ApiBase\getResult
getResult()
Get the result object.
Definition
ApiBase.php:701
ApiFormatBase
This is the abstract base class for API formatters.
Definition
ApiFormatBase.php:37
ApiFormatBase\printText
printText( $text)
Append text to the output buffer.
Definition
ApiFormatBase.php:362
ApiFormatBase\getIsWrappedHtml
getIsWrappedHtml()
Returns true when the special-wrapped mode is enabled.
Definition
ApiFormatBase.php:126
ApiFormatBase\getIsHtml
getIsHtml()
Returns true when the HTML pretty-printer should be used.
Definition
ApiFormatBase.php:116
ApiFormatRaw
Formatter that spits out anything you like with any desired MIME type.
Definition
ApiFormatRaw.php:27
ApiFormatRaw\initPrinter
initPrinter( $unused=false)
Initialize the printer function and prepare the output headers.
Definition
ApiFormatRaw.php:69
ApiFormatRaw\closePrinter
closePrinter()
Finish printing and output buffered data.
Definition
ApiFormatRaw.php:81
ApiFormatRaw\setFailWithHTTPError
setFailWithHTTPError( $fail)
Output HTTP error code 400 when if an error is encountered.
Definition
ApiFormatRaw.php:112
ApiFormatRaw\__construct
__construct(ApiMain $main, ApiFormatBase $errorFallback=null)
Definition
ApiFormatRaw.php:38
ApiFormatRaw\getMimeType
getMimeType()
Overriding class returns the MIME type that should be sent to the client.
Definition
ApiFormatRaw.php:44
ApiFormatRaw\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition
ApiFormatRaw.php:90
ApiFormatRaw\getFilename
getFilename()
Return a filename for this module's output.
Definition
ApiFormatRaw.php:58
ApiMain
This is the main API class, used for both external and internal processing.
Definition
ApiMain.php:68
ApiMain\createPrinterByName
createPrinterByName( $format)
Create an instance of an output formatter by its name.
Definition
ApiMain.php:884
includes
api
ApiFormatRaw.php
Generated on Sat Sep 14 2024 14:22:19 for MediaWiki by
1.10.0