Merge "Special:ListGroupRights: Display the legend at the top"
[mediawiki.git] / includes / api / ApiRsd.php
blobd219c91c4c7378bd4fdcd90ae185e664f7403e75
1 <?php
3 /**
4 * API for MediaWiki 1.17+
6 * Created on October 26, 2010
8 * Copyright © 2010 Bryan Tong Minh and Brion Vibber
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @file
28 /**
29 * API module for sending out RSD information
30 * @ingroup API
32 class ApiRsd extends ApiBase {
34 public function execute() {
35 $result = $this->getResult();
37 $result->addValue( null, 'version', '1.0' );
38 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
40 $service = array( 'apis' => $this->formatRsdApiList() );
41 ApiResult::setContent( $service, 'MediaWiki', 'engineName' );
42 ApiResult::setContent( $service, 'https://www.mediawiki.org/', 'engineLink' );
43 ApiResult::setContent( $service, Title::newMainPage()->getCanonicalURL(), 'homePageLink' );
45 $result->setIndexedTagName( $service['apis'], 'api' );
47 $result->addValue( null, 'service', $service );
50 public function getCustomPrinter() {
51 return new ApiFormatXmlRsd( $this->getMain(), 'xml' );
54 public function getAllowedParams() {
55 return array();
58 public function getParamDescription() {
59 return array();
62 public function getDescription() {
63 return 'Export an RSD (Really Simple Discovery) schema';
66 public function getExamples() {
67 return array(
68 'api.php?action=rsd'
72 /**
73 * Builds an internal list of APIs to expose information about.
74 * Normally this only lists the MediaWiki API, with its base URL,
75 * link to documentation, and a marker as to available authentication
76 * (to aid in OAuth client apps switching to support in the future).
78 * Extensions can expose other APIs, such as WordPress or Twitter-
79 * compatible APIs, by hooking 'ApiRsdServiceApis' and adding more
80 * elements to the array.
82 * See http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html for
83 * the base RSD spec, and check WordPress and StatusNet sites for
84 * in-production examples listing several blogging and micrblogging
85 * APIs.
87 * @return array
89 protected function getRsdApiList() {
90 $apis = array(
91 'MediaWiki' => array(
92 // The API link is required for all RSD API entries.
93 'apiLink' => wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ),
95 // Docs link is optional, but recommended.
96 'docs' => 'https://www.mediawiki.org/wiki/API',
98 // Some APIs may need a blog ID, but it may be left blank.
99 'blogID' => '',
101 // Additional settings are optional.
102 'settings' => array(
103 // Change this to true in the future as an aid to
104 // machine discovery of OAuth for API access.
105 'OAuth' => false,
109 wfRunHooks( 'ApiRsdServiceApis', array( &$apis ) );
110 return $apis;
114 * Formats the internal list of exposed APIs into an array suitable
115 * to pass to the API's XML formatter.
117 * @return array
119 protected function formatRsdApiList() {
120 $apis = $this->getRsdApiList();
122 $outputData = array();
123 foreach ( $apis as $name => $info ) {
124 $data = array(
125 'name' => $name,
126 'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
127 'apiLink' => $info['apiLink'],
128 'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : '',
130 $settings = array();
131 if ( isset( $info['docs'] ) ) {
132 ApiResult::setContent( $settings, $info['docs'], 'docs' );
134 if ( isset( $info['settings'] ) ) {
135 foreach ( $info['settings'] as $setting => $val ) {
136 if ( is_bool( $val ) ) {
137 $xmlVal = wfBoolToStr( $val );
138 } else {
139 $xmlVal = $val;
141 $setting = array( 'name' => $setting );
142 ApiResult::setContent( $setting, $xmlVal );
143 $settings[] = $setting;
146 if ( count( $settings ) ) {
147 $this->getResult()->setIndexedTagName( $settings, 'setting' );
148 $data['settings'] = $settings;
150 $outputData[] = $data;
152 return $outputData;
156 class ApiFormatXmlRsd extends ApiFormatXml {
157 public function __construct( $main, $format ) {
158 parent::__construct( $main, $format );
159 $this->setRootElement( 'rsd' );
162 public function getMimeType() {
163 return 'application/rsd+xml';