Was occassionally failing due to race condition caused by mt_rand behaviour:
[mediawiki.git] / includes / api / ApiFormatRaw.php
blob02eccda6275a78acdf2b4860487cf72e85e773b0
1 <?php
3 /*
4 * Created on Feb 2, 2009
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
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.
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.
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
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiFormatBase.php');
31 /**
32 * Formatter that spits out anything you like with any desired MIME type
33 * @ingroup API
35 class ApiFormatRaw extends ApiFormatBase {
37 /**
38 * Constructor
39 * @param $main ApiMain object
40 * @param $errorFallback Formatter object to fall back on for errors
42 public function __construct($main, $errorFallback) {
43 parent :: __construct($main, 'raw');
44 $this->mErrorFallback = $errorFallback;
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'];
56 public function execute() {
57 $data = $this->getResultData();
58 if(isset($data['error']))
60 $this->mErrorFallback->execute();
61 return;
63 if(!isset($data['text']))
64 ApiBase::dieDebug(__METHOD__, "No text given for raw formatter");
65 $this->printText($data['text']);
68 public function getVersion() {
69 return __CLASS__ . ': $Id$';