return $this->mDisabled;
}
+ /**
+ * Whether this formatter can handle printing API errors. If this returns
+ * false, then on API errors the default printer will be instantiated.
+ * @since 1.23
+ * @return bool
+ */
+ public function canPrintErrors() {
+ return true;
+ }
+
/**
* Initialize the printer function and prepare the output headers, etc.
* This method must be the first outputting method during execution.
return true;
}
+ /**
+ * ChannelFeed doesn't give us a method to print errors in a friendly
+ * manner, so just punt errors to the default printer.
+ * @return false
+ */
+ public function canPrintErrors() {
+ return false;
+ }
+
/**
* This class expects the result data to be in a custom format set by self::setResult()
* $result['_feed'] - an instance of one of the $wgFeedClasses classes
global $wgShowHostnames;
$result = $this->getResult();
+
// Printer may not be initialized if the extractRequestParams() fails for the main module
if ( !isset( $this->mPrinter ) ) {
// The printer has not been created yet. Try to manually get formatter value.
}
$this->mPrinter = $this->createPrinterByName( $value );
- if ( $this->mPrinter->getNeedsRawData() ) {
- $result->setRawMode();
- }
}
+ // Printer may not be able to handle errors. This is particularly
+ // likely if the module returns something for getCustomPrinter().
+ if ( !$this->mPrinter->canPrintErrors() ) {
+ $this->mPrinter->safeProfileOut();
+ $this->mPrinter = $this->createPrinterByName( self::API_DEFAULT_FORMAT );
+ }
+
+ // Update raw mode flag for the selected printer.
+ $result->setRawMode( $this->mPrinter->getNeedsRawData() );
+
if ( $e instanceof UsageException ) {
// User entered incorrect parameters - print usage screen
$errMessage = $e->getMessageArray();
/**
* Call this function when special elements such as '_element'
* are needed by the formatter, for example in XML printing.
+ * @since 1.23 $flag parameter added
+ * @param bool $flag Set the raw mode flag to this state
*/
- public function setRawMode() {
- $this->mIsRawMode = true;
+ public function setRawMode( $flag = true ) {
+ $this->mIsRawMode = $flag;
}
/**