]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/api/ApiFormatRaw.php
MediaWiki 1.15.5
[autoinstallsdev/mediawiki.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                 if(isset($data['error']))
50                         return $this->mErrorFallback->getMimeType();
51                 if(!isset($data['mime']))
52                         ApiBase::dieDebug(__METHOD__, "No MIME type set for raw formatter");
53                 return $data['mime'];
54         }
55
56         public function execute() {
57                 $data = $this->getResultData();
58                 if(isset($data['error']))
59                 {
60                         $this->mErrorFallback->execute();
61                         return;
62                 }
63                 if(!isset($data['text']))
64                         ApiBase::dieDebug(__METHOD__, "No text given for raw formatter");
65                 $this->printText($data['text']);
66         }
67
68         public function getVersion() {
69                 return __CLASS__ . ': $Id: ApiFormatRaw.php 48629 2009-03-20 11:40:54Z catrope $';
70         }
71 }