abstract class ApiFormatBase extends ApiBase {
private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared;
- private $mBufferResult = false, $mBuffer;
+ private $mBufferResult = false, $mBuffer, $mDisabled = false;
/**
* Constructor
return $this->getIsHtml();
}
+ /**
+ * Disable the formatter completely. This causes calls to initPrinter(),
+ * printText() and closePrinter() to be ignored.
+ */
+ public function disable() {
+ $this->mDisabled = true;
+ }
+
+ public function isDisabled() {
+ return $this->mDisabled;
+ }
+
/**
* Initialize the printer function and prepare the output headers, etc.
* This method must be the first outputing method during execution.
* @param $isError bool Whether an error message is printed
*/
function initPrinter( $isError ) {
+ if ( $this->mDisabled ) {
+ return;
+ }
$isHtml = $this->getIsHtml();
$mime = $isHtml ? 'text/html' : $this->getMimeType();
$script = wfScript( 'api' );
* Finish printing. Closes HTML tags.
*/
public function closePrinter() {
+ if ( $this->mDisabled ) {
+ return;
+ }
if ( $this->getIsHtml() ) {
?>
* @param $text string
*/
public function printText( $text ) {
+ if ( $this->mDisabled ) {
+ return;
+ }
if ( $this->mBufferResult ) {
$this->mBuffer = $text;
} elseif ( $this->getIsHtml() ) {
public function getModule() {
return $this->mModule;
}
+
+ /**
+ * Get the result formatter object. Only works after setupExecuteAction()
+ */
+ public function getPrinter() {
+ return $this->mPrinter;
+ }
/**
* Only kept for backwards compatibility
header( "Cache-Control: $ccHeader" );
- if ( $this->mPrinter->getIsHtml() ) {
+ if ( $this->mPrinter->getIsHtml() && !$this->mPrinter->isDisabled() ) {
echo wfReportTime();
}