2009-02-02 20:07:33 +00:00
|
|
|
<?php
|
2010-02-23 12:30:23 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2009-02-02 20:07:33 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Feb 2, 2009
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
|
2009-02-02 20:07:33 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-02 20:07:33 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2009-02-02 20:07:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Formatter that spits out anything you like with any desired MIME type
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiFormatRaw extends ApiFormatBase {
|
|
|
|
|
|
2009-03-20 11:40:54 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
* @param $main ApiMain object
|
2011-02-19 00:30:18 +00:00
|
|
|
* @param $errorFallback ApiFormatBase object to fall back on for errors
|
2009-03-20 11:40:54 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $errorFallback ) {
|
2010-02-23 12:30:23 +00:00
|
|
|
parent::__construct( $main, 'raw' );
|
2009-03-20 11:40:54 +00:00
|
|
|
$this->mErrorFallback = $errorFallback;
|
2009-02-02 20:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getMimeType() {
|
|
|
|
|
$data = $this->getResultData();
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-02-23 12:30:23 +00:00
|
|
|
if ( isset( $data['error'] ) ) {
|
2009-03-20 11:40:54 +00:00
|
|
|
return $this->mErrorFallback->getMimeType();
|
2010-02-23 12:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $data['mime'] ) ) {
|
|
|
|
|
ApiBase::dieDebug( __METHOD__, 'No MIME type set for raw formatter' );
|
|
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2009-02-02 20:07:33 +00:00
|
|
|
return $data['mime'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$data = $this->getResultData();
|
2010-02-23 12:30:23 +00:00
|
|
|
if ( isset( $data['error'] ) ) {
|
2009-03-20 11:40:54 +00:00
|
|
|
$this->mErrorFallback->execute();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-02-23 12:30:23 +00:00
|
|
|
|
|
|
|
|
if ( !isset( $data['text'] ) ) {
|
|
|
|
|
ApiBase::dieDebug( __METHOD__, 'No text given for raw formatter' );
|
|
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->printText( $data['text'] );
|
2009-02-02 20:07:33 +00:00
|
|
|
}
|
|
|
|
|
}
|