* Non-working API to facilitate dev collaboration. Do not enable this yet in localset...
[mediawiki.git] / includes / api / ApiResult.php
blob0a5abd3bae03d28d6214a654328da9e0f8412f9a
1 <?php
4 /*
5 * Created on Sep 4, 2006
7 * API for MediaWiki 1.8+
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * http://www.gnu.org/copyleft/gpl.html
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ("ApiBase.php");
32 class ApiResult extends ApiBase {
34 private $mData;
36 /**
37 * Constructor
39 public function __construct($main) {
40 parent :: __construct($main);
41 $this->Reset();
44 public function Reset() {
45 $this->mData = array();
48 function GetData() {
49 return $this->mData;
52 /* function addPage($title)
54 if (!isset($this->mPages))
55 $this->mPages &= $this->mData['pages'];
59 function AddMessage($mainSection, $subSection, $value, $preserveXmlSpacing = false) {
60 if (!array_key_exists($mainSection, $this->mData)) {
61 $this->mData[$mainSection] = array ();
63 if ($subSection !== null) {
64 if (!array_key_exists($subSection, $this->mData[$mainSection])) {
65 $this->mData[$mainSection][$subSection] = array ();
67 $element = & $this->mData[$mainSection][$subSection];
68 } else {
69 $element = & $this->mData[$mainSection];
71 if (is_array($value)) {
72 $element = array_merge($element, $value);
73 if (!array_key_exists('*', $element)) {
74 $element['*'] = '';
76 } else {
77 if (array_key_exists('*', $element)) {
78 $element['*'] .= $value;
79 } else {
80 $element['*'] = $value;
82 if ($preserveXmlSpacing) {
83 $element['xml:space'] = 'preserve';
88 /**
89 * Recursivelly removes any elements from the array that begin with an '_'.
90 * The content element '*' is the only special element that is left.
91 * Use this method when the entire data object gets sent to the user.
93 public function SanitizeData() {
94 ApiResult :: SanitizeDataInt($this->mData);
97 private static function SanitizeDataInt(& $data) {
98 foreach ($data as $key => & $value) {
99 if ($key[0] === '_') {
100 unset ($data[$key]);
102 elseif ($key === '*' && $value === '') {
103 unset ($data[$key]);
105 elseif (is_array($value)) {
106 ApiResult :: SanitizeDataInt($value);
111 public function Execute() {
112 $this->DieDebug("Execute() is not supported on Result object");