MediaWiki REL1_39
ApiRsd.php
Go to the documentation of this file.
1<?php
2
30class ApiRsd extends ApiBase {
31
32 public function execute() {
33 $result = $this->getResult();
34
35 $result->addValue( null, 'version', '1.0' );
36 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
37
38 $service = [
39 'apis' => $this->formatRsdApiList(),
40 'engineName' => 'MediaWiki',
41 'engineLink' => 'https://www.mediawiki.org/',
42 'homePageLink' => Title::newMainPage()->getCanonicalURL(),
43 ];
44
45 ApiResult::setSubelementsList( $service, [ 'engineName', 'engineLink', 'homePageLink' ] );
46 ApiResult::setIndexedTagName( $service['apis'], 'api' );
47
48 $result->addValue( null, 'service', $service );
49 }
50
51 public function getCustomPrinter() {
52 return new ApiFormatXmlRsd( $this->getMain(), 'xml' );
53 }
54
55 protected function getExamplesMessages() {
56 return [
57 'action=rsd'
58 => 'apihelp-rsd-example-simple',
59 ];
60 }
61
62 public function isReadMode() {
63 return false;
64 }
65
83 protected function getRsdApiList() {
84 $apis = [
85 'MediaWiki' => [
86 // The API link is required for all RSD API entries.
87 'apiLink' => wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ),
88
89 // Docs link is optional, but recommended.
90 'docs' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/API',
91
92 // Some APIs may need a blog ID, but it may be left blank.
93 'blogID' => '',
94
95 // Additional settings are optional.
96 'settings' => [
97 // Change this to true in the future as an aid to
98 // machine discovery of OAuth for API access.
99 'OAuth' => false,
100 ]
101 ],
102 ];
103 $this->getHookRunner()->onApiRsdServiceApis( $apis );
104
105 return $apis;
106 }
107
114 protected function formatRsdApiList() {
115 $apis = $this->getRsdApiList();
116
117 $outputData = [];
118 foreach ( $apis as $name => $info ) {
119 $data = [
120 'name' => $name,
121 'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
122 'apiLink' => $info['apiLink'],
123 'blogID' => $info['blogID'] ?? '',
124 ];
125 $settings = [];
126 if ( isset( $info['docs'] ) ) {
127 $settings['docs'] = $info['docs'];
128 ApiResult::setSubelementsList( $settings, 'docs' );
129 }
130 if ( isset( $info['settings'] ) ) {
131 foreach ( $info['settings'] as $setting => $val ) {
132 if ( is_bool( $val ) ) {
133 $xmlVal = wfBoolToStr( $val );
134 } else {
135 $xmlVal = $val;
136 }
137 $setting = [ 'name' => $setting ];
138 ApiResult::setContentValue( $setting, 'value', $xmlVal );
139 $settings[] = $setting;
140 }
141 }
142 if ( count( $settings ) ) {
143 ApiResult::setIndexedTagName( $settings, 'setting' );
144 $data['settings'] = $settings;
145 }
146 $outputData[] = $data;
147 }
148
149 return $outputData;
150 }
151}
const PROTO_CURRENT
Definition Defines.php:198
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
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:56
getMain()
Get the main module.
Definition ApiBase.php:514
getResult()
Get the result object.
Definition ApiBase.php:629
getHookRunner()
Get an ApiHookRunner for running core API hooks.
Definition ApiBase.php:711
API module for sending out RSD information.
Definition ApiRsd.php:30
isReadMode()
Indicates whether this module requires read rights.
Definition ApiRsd.php:62
formatRsdApiList()
Formats the internal list of exposed APIs into an array suitable to pass to the API's XML formatter.
Definition ApiRsd.php:114
getExamplesMessages()
Returns usage examples for this module.
Definition ApiRsd.php:55
getRsdApiList()
Builds an internal list of APIs to expose information about.
Definition ApiRsd.php:83
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition ApiRsd.php:32
getCustomPrinter()
If the module may only be used with a certain format module, it should override this method to return...
Definition ApiRsd.php:51