MediaWiki master
ApiRsd.php
Go to the documentation of this file.
1<?php
2
28
33class ApiRsd extends ApiBase {
34 public function execute() {
35 $result = $this->getResult();
36
37 $result->addValue( null, 'version', '1.0' );
38 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
39
40 $service = [
41 'apis' => $this->formatRsdApiList(),
42 'engineName' => 'MediaWiki',
43 'engineLink' => 'https://www.mediawiki.org/',
44 'homePageLink' => Title::newMainPage()->getCanonicalURL(),
45 ];
46
47 ApiResult::setSubelementsList( $service, [ 'engineName', 'engineLink', 'homePageLink' ] );
48 ApiResult::setIndexedTagName( $service['apis'], 'api' );
49
50 $result->addValue( null, 'service', $service );
51 }
52
53 public function getCustomPrinter() {
54 return new ApiFormatXmlRsd( $this->getMain(), 'xml' );
55 }
56
57 protected function getExamplesMessages() {
58 return [
59 'action=rsd'
60 => 'apihelp-rsd-example-simple',
61 ];
62 }
63
64 public function isReadMode() {
65 return false;
66 }
67
85 protected function getRsdApiList() {
86 // Loaded here rather than injected due to the direct extension of ApiBase.
87 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
88 $apis = [
89 'MediaWiki' => [
90 // The API link is required for all RSD API entries.
91 'apiLink' => (string)$urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ),
92
93 // Docs link is optional, but recommended.
94 'docs' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/API',
95
96 // Some APIs may need a blog ID, but it may be left blank.
97 'blogID' => '',
98
99 // Additional settings are optional.
100 'settings' => [
101 // Change this to true in the future as an aid to
102 // machine discovery of OAuth for API access.
103 'OAuth' => false,
104 ]
105 ],
106 ];
107 $this->getHookRunner()->onApiRsdServiceApis( $apis );
108
109 return $apis;
110 }
111
118 protected function formatRsdApiList() {
119 $apis = $this->getRsdApiList();
120
121 $outputData = [];
122 foreach ( $apis as $name => $info ) {
123 $data = [
124 'name' => $name,
125 'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
126 'apiLink' => $info['apiLink'],
127 'blogID' => $info['blogID'] ?? '',
128 ];
129 $settings = [];
130 if ( isset( $info['docs'] ) ) {
131 $settings['docs'] = $info['docs'];
132 ApiResult::setSubelementsList( $settings, 'docs' );
133 }
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;
140 }
141 $setting = [ 'name' => $setting ];
142 ApiResult::setContentValue( $setting, 'value', $xmlVal );
143 $settings[] = $setting;
144 }
145 }
146 if ( count( $settings ) ) {
147 ApiResult::setIndexedTagName( $settings, 'setting' );
148 $data['settings'] = $settings;
149 }
150 $outputData[] = $data;
151 }
152
153 return $outputData;
154 }
155
156 public function getHelpUrls() {
157 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Rsd';
158 }
159}
const PROTO_CURRENT
Definition Defines.php:207
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:64
getMain()
Get the main module.
Definition ApiBase.php:550
getResult()
Get the result object.
Definition ApiBase.php:671
getHookRunner()
Get an ApiHookRunner for running core API hooks.
Definition ApiBase.php:756
API module for sending out RSD information.
Definition ApiRsd.php:33
isReadMode()
Indicates whether this module requires read rights.
Definition ApiRsd.php:64
formatRsdApiList()
Formats the internal list of exposed APIs into an array suitable to pass to the API's XML formatter.
Definition ApiRsd.php:118
getExamplesMessages()
Returns usage examples for this module.
Definition ApiRsd.php:57
getHelpUrls()
Return links to more detailed help pages about the module.
Definition ApiRsd.php:156
getRsdApiList()
Builds an internal list of APIs to expose information about.
Definition ApiRsd.php:85
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition ApiRsd.php:34
getCustomPrinter()
If the module may only be used with a certain format module, it should override this method to return...
Definition ApiRsd.php:53
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:78