ee8f573cd022529efc02cdd99578ee7fabbf8682
[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 (C) 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 if ( !isset( $data['mime'] ) )
54 ApiBase::dieDebug( __METHOD__, "No MIME type set for raw formatter" );
55
56 return $data['mime'];
57 }
58
59 public function execute() {
60 $data = $this->getResultData();
61 if ( isset( $data['error'] ) )
62 {
63 $this->mErrorFallback->execute();
64 return;
65 }
66
67 if ( !isset( $data['text'] ) )
68 ApiBase::dieDebug( __METHOD__, "No text given for raw formatter" );
69 $this->printText( $data['text'] );
70 }
71
72 public function getVersion() {
73 return __CLASS__ . ': $Id$';
74 }
75 }