Correct the address of the FSF in some of the GPL headers
[lhc/web/wiklou.git] / includes / api / ApiFormatRaw.php
1 <?php
2
3 /**
4 * Created on Feb 2, 2009
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 */
25
26 if ( !defined( 'MEDIAWIKI' ) ) {
27 // Eclipse helper - will be ignored in production
28 require_once( 'ApiFormatBase.php' );
29 }
30
31 /**
32 * Formatter that spits out anything you like with any desired MIME type
33 * @ingroup API
34 */
35 class ApiFormatRaw extends ApiFormatBase {
36
37 /**
38 * Constructor
39 * @param $main ApiMain object
40 * @param $errorFallback Formatter object to fall back on for errors
41 */
42 public function __construct( $main, $errorFallback ) {
43 parent::__construct( $main, 'raw' );
44 $this->mErrorFallback = $errorFallback;
45 }
46
47 public function getMimeType() {
48 $data = $this->getResultData();
49
50 if ( isset( $data['error'] ) ) {
51 return $this->mErrorFallback->getMimeType();
52 }
53
54 if ( !isset( $data['mime'] ) ) {
55 ApiBase::dieDebug( __METHOD__, 'No MIME type set for raw formatter' );
56 }
57
58 return $data['mime'];
59 }
60
61 public function execute() {
62 $data = $this->getResultData();
63 if ( isset( $data['error'] ) ) {
64 $this->mErrorFallback->execute();
65 return;
66 }
67
68 if ( !isset( $data['text'] ) ) {
69 ApiBase::dieDebug( __METHOD__, 'No text given for raw formatter' );
70 }
71 $this->printText( $data['text'] );
72 }
73
74 public function getVersion() {
75 return __CLASS__ . ': $Id$';
76 }
77 }