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