4 * API for MediaWiki 1.17+
6 * Copyright © 2010 Bryan Tong Minh and Brion Vibber
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
27 * API module for sending out RSD information
30 class ApiRsd
extends ApiBase
{
32 public function execute() {
33 $result = $this->getResult();
35 $result->addValue( null, 'version', '1.0' );
36 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
39 'apis' => $this->formatRsdApiList(),
40 'engineName' => 'MediaWiki',
41 'engineLink' => 'https://www.mediawiki.org/',
42 'homePageLink' => Title
::newMainPage()->getCanonicalURL(),
45 ApiResult
::setSubelementsList( $service, [ 'engineName', 'engineLink', 'homePageLink' ] );
46 ApiResult
::setIndexedTagName( $service['apis'], 'api' );
48 $result->addValue( null, 'service', $service );
51 public function getCustomPrinter() {
52 return new ApiFormatXmlRsd( $this->getMain(), 'xml' );
55 protected function getExamplesMessages() {
58 => 'apihelp-rsd-example-simple',
62 public function isReadMode() {
67 * Builds an internal list of APIs to expose information about.
68 * Normally this only lists the MediaWiki API, with its base URL,
69 * link to documentation, and a marker as to available authentication
70 * (to aid in OAuth client apps switching to support in the future).
72 * Extensions can expose other APIs, such as WordPress or Twitter-
73 * compatible APIs, by hooking 'ApiRsdServiceApis' and adding more
74 * elements to the array.
76 * See https://cyber.harvard.edu/blogs/gems/tech/rsd.html for
77 * the base RSD spec, and check WordPress and StatusNet sites for
78 * in-production examples listing several blogging and micrblogging
83 protected function getRsdApiList() {
86 // The API link is required for all RSD API entries.
87 'apiLink' => wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT
),
89 // Docs link is optional, but recommended.
90 'docs' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/API',
92 // Some APIs may need a blog ID, but it may be left blank.
95 // Additional settings are optional.
97 // Change this to true in the future as an aid to
98 // machine discovery of OAuth for API access.
103 Hooks
::run( 'ApiRsdServiceApis', [ &$apis ] );
109 * Formats the internal list of exposed APIs into an array suitable
110 * to pass to the API's XML formatter.
114 protected function formatRsdApiList() {
115 $apis = $this->getRsdApiList();
118 foreach ( $apis as $name => $info ) {
121 'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
122 'apiLink' => $info['apiLink'],
123 'blogID' => isset( $info['blogID'] ) ?
$info['blogID'] : '',
126 if ( isset( $info['docs'] ) ) {
127 $settings['docs'] = $info['docs'];
128 ApiResult
::setSubelementsList( $settings, 'docs' );
130 if ( isset( $info['settings'] ) ) {
131 foreach ( $info['settings'] as $setting => $val ) {
132 if ( is_bool( $val ) ) {
133 $xmlVal = wfBoolToStr( $val );
137 $setting = [ 'name' => $setting ];
138 ApiResult
::setContentValue( $setting, 'value', $xmlVal );
139 $settings[] = $setting;
142 if ( count( $settings ) ) {
143 ApiResult
::setIndexedTagName( $settings, 'setting' );
144 $data['settings'] = $settings;
146 $outputData[] = $data;
153 class ApiFormatXmlRsd
extends ApiFormatXml
{
154 public function __construct( ApiMain
$main, $format ) {
155 parent
::__construct( $main, $format );
156 $this->setRootElement( 'rsd' );
159 public function getMimeType() {
160 return 'application/rsd+xml';
163 public static function recXmlPrint( $name, $value, $indent, $attributes = [] ) {
164 unset( $attributes['_idx'] );
165 return parent
::recXmlPrint( $name, $value, $indent, $attributes );