Minor followup to r75621, add whitespace
[lhc/web/wiklou.git] / includes / api / ApiRsd.php
1 <?php
2
3 /**
4 * API for MediaWiki 1.17+
5 *
6 * Created on October 26, 2010
7 *
8 * Copyright © 2010 Bryan Tong Minh and Brion Vibber
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 * @file
26 */
27
28 if ( !defined( 'MEDIAWIKI' ) ) {
29 require_once( 'ApiBase.php' );
30 }
31
32 /**
33 * API interface for page purging
34 * @ingroup API
35 */
36 class ApiRsd extends ApiBase {
37
38 public function __construct( $main, $action ) {
39 parent::__construct( $main, $action );
40 }
41
42 public function execute() {
43 $result = $this->getResult();
44
45
46 $result->addValue( null, 'version', '1.0' );
47 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
48
49 $service = array(
50 'engineName' => array(
51 '*' => 'MediaWiki'
52 ),
53 'engineLink' => array(
54 '*' => 'http://www.mediawiki.org/'
55 ),
56 'apis' => $this->formatRsdApiList()
57 );
58
59 $result->setIndexedTagName( $service['apis'], 'api' );
60
61 $result->addValue( null, 'service', $service );
62 }
63
64 public function getCustomPrinter() {
65 return new ApiFormatXmlRsd( $this->getMain(), 'xml' );
66 }
67
68 public function getAllowedParams() {
69 return array();
70 }
71
72 public function getParamDescription() {
73 return array();
74 }
75
76 public function getDescription() {
77 return 'Export an RSD schema';
78 }
79
80 protected function getExamples() {
81 return array(
82 'api.php?action=rsd'
83 );
84 }
85
86 /**
87 * Builds an internal list of APIs to expose information about.
88 * Normally this only lists the MediaWiki API, with its base URL,
89 * link to documentation, and a marker as to available authentication
90 * (to aid in OAuth client apps switching to support in the future).
91 *
92 * Extensions can expose other APIs, such as WordPress or Twitter-
93 * compatible APIs, by hooking 'ApiRsdServiceApis' and adding more
94 * elements to the array.
95 *
96 * See http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html for
97 * the base RSD spec, and check WordPress and StatusNet sites for
98 * in-production examples listing several blogging and micrblogging
99 * APIs.
100 *
101 * @return array
102 */
103 protected function getRsdApiList() {
104 $apis = array(
105 'MediaWiki' => array(
106 // The API link is required for all RSD API entries.
107 'apiLink' => wfExpandUrl( wfScript( 'api' ) ),
108
109 // Docs link is optional, but recommended.
110 'docs' => 'http://mediawiki.org/wiki/API',
111
112 // Some APIs may need a blog ID, but it may be left blank.
113 'blogID' => '',
114
115 // Additional settings are optional.
116 'settings' => array(
117 // Change this to true in the future as an aid to
118 // machine discovery of OAuth for API access.
119 'OAuth' => false,
120 )
121 ),
122 );
123 wfRunHooks( 'ApiRsdServiceApis', array( &$apis ) );
124 return $apis;
125 }
126
127 /**
128 * Formats the internal list of exposed APIs into an array suitable
129 * to pass to the API's XML formatter.
130 *
131 * @return array
132 */
133 protected function formatRsdApiList() {
134 $apis = $this->getRsdApiList();
135
136 $outputData = array();
137 foreach ( $apis as $name => $info ) {
138 $data = array(
139 'name' => $name,
140 'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
141 'apiLink' => $info['apiLink'],
142 'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : ''
143 );
144 if ( isset( $info['docs'] ) ) {
145 $data['settings']['docs'] = array(
146 '*' => $info['docs'],
147 );
148 }
149 if ( isset( $info['settings'] ) ) {
150 foreach ( $info['settings'] as $setting => $val ) {
151 if ( is_bool( $val ) ) {
152 $xmlVal = wfBoolToStr( $val );
153 } else {
154 $xmlVal = $val;
155 }
156 $data['settings'][] = array(
157 'name' => $setting,
158 '*' => $xmlVal,
159 );
160 }
161 }
162 if ( isset( $data['settings'] ) ) {
163 $data['settings']['_element'] = 'setting';
164 }
165 $outputData[] = $data;
166 }
167 return $outputData;
168 }
169
170 public function getVersion() {
171 return __CLASS__ . ': $Id$';
172 }
173 }
174
175 class ApiFormatXmlRsd extends ApiFormatXml {
176 public function __construct( $main, $format ) {
177 parent::__construct( $main, $format );
178 $this->setRootElement( 'rsd' );
179 }
180
181 public function getMimeType() {
182 return 'application/rsd+xml';
183 }
184
185 public function getVersion() {
186 return __CLASS__ . ': $Id$';
187 }
188 }