MediaWiki master
ApiRsd.php
Go to the documentation of this file.
1<?php
2
12namespace MediaWiki\Api;
13
16
21class ApiRsd extends ApiBase {
22 public function execute() {
23 $result = $this->getResult();
24
25 $result->addValue( null, 'version', '1.0' );
26 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
27
28 $service = [
29 'apis' => $this->formatRsdApiList(),
30 'engineName' => 'MediaWiki',
31 'engineLink' => 'https://www.mediawiki.org/',
32 'homePageLink' => Title::newMainPage()->getCanonicalURL(),
33 ];
34
35 ApiResult::setSubelementsList( $service, [ 'engineName', 'engineLink', 'homePageLink' ] );
36 ApiResult::setIndexedTagName( $service['apis'], 'api' );
37
38 $result->addValue( null, 'service', $service );
39 }
40
42 public function getCustomPrinter() {
43 return new ApiFormatXmlRsd( $this->getMain(), 'xml' );
44 }
45
47 protected function getExamplesMessages() {
48 return [
49 'action=rsd'
50 => 'apihelp-rsd-example-simple',
51 ];
52 }
53
55 public function isReadMode() {
56 return false;
57 }
58
76 protected function getRsdApiList() {
77 // Loaded here rather than injected due to the direct extension of ApiBase.
78 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
79 $apis = [
80 'MediaWiki' => [
81 // The API link is required for all RSD API entries.
82 'apiLink' => (string)$urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ),
83
84 // Docs link is optional, but recommended.
85 'docs' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/API',
86
87 // Some APIs may need a blog ID, but it may be left blank.
88 'blogID' => '',
89
90 // Additional settings are optional.
91 'settings' => [
92 // Change this to true in the future as an aid to
93 // machine discovery of OAuth for API access.
94 'OAuth' => false,
95 ]
96 ],
97 ];
98 $this->getHookRunner()->onApiRsdServiceApis( $apis );
99
100 return $apis;
101 }
102
109 protected function formatRsdApiList() {
110 $apis = $this->getRsdApiList();
111
112 $outputData = [];
113 foreach ( $apis as $name => $info ) {
114 $data = [
115 'name' => $name,
116 'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
117 'apiLink' => $info['apiLink'],
118 'blogID' => $info['blogID'] ?? '',
119 ];
120 $settings = [];
121 if ( isset( $info['docs'] ) ) {
122 $settings['docs'] = $info['docs'];
123 ApiResult::setSubelementsList( $settings, 'docs' );
124 }
125 if ( isset( $info['settings'] ) ) {
126 foreach ( $info['settings'] as $setting => $val ) {
127 if ( is_bool( $val ) ) {
128 $xmlVal = wfBoolToStr( $val );
129 } else {
130 $xmlVal = $val;
131 }
132 $setting = [ 'name' => $setting ];
133 ApiResult::setContentValue( $setting, 'value', $xmlVal );
134 $settings[] = $setting;
135 }
136 }
137 if ( count( $settings ) ) {
138 ApiResult::setIndexedTagName( $settings, 'setting' );
139 $data['settings'] = $settings;
140 }
141 $outputData[] = $data;
142 }
143
144 return $outputData;
145 }
146
148 public function getHelpUrls() {
149 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Rsd';
150 }
151}
152
154class_alias( ApiRsd::class, 'ApiRsd' );
const PROTO_CURRENT
Definition Defines.php:222
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:61
getHookRunner()
Get an ApiHookRunner for running core API hooks.
Definition ApiBase.php:767
getMain()
Get the main module.
Definition ApiBase.php:561
getResult()
Get the result object.
Definition ApiBase.php:682
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes.
API module for sending out RSD information.
Definition ApiRsd.php:21
getCustomPrinter()
If the module may only be used with a certain format module, it should override this method to return...
Definition ApiRsd.php:42
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
Definition ApiRsd.php:47
getRsdApiList()
Builds an internal list of APIs to expose information about.
Definition ApiRsd.php:76
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition ApiRsd.php:22
formatRsdApiList()
Formats the internal list of exposed APIs into an array suitable to pass to the API's XML formatter.
Definition ApiRsd.php:109
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
Definition ApiRsd.php:148
isReadMode()
Indicates whether this module requires read rights.to override bool
Definition ApiRsd.php:55
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Represents a title within MediaWiki.
Definition Title.php:69