MediaWiki  1.34.0
ApiRsd.php
Go to the documentation of this file.
1 <?php
2 
30 class 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  Hooks::run( 'ApiRsdServiceApis', [ &$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 }
ApiRsd\getCustomPrinter
getCustomPrinter()
If the module may only be used with a certain format module, it should override this method to return...
Definition: ApiRsd.php:51
ApiRsd\formatRsdApiList
formatRsdApiList()
Formats the internal list of exposed APIs into an array suitable to pass to the API's XML formatter.
Definition: ApiRsd.php:114
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:640
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:649
ApiFormatXmlRsd
Definition: ApiFormatXmlRsd.php:27
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
wfBoolToStr
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
Definition: GlobalFunctions.php:2683
ApiResult\setContentValue
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
Definition: ApiResult.php:478
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2642
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:202
ApiRsd\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiRsd.php:32
ApiRsd\getRsdApiList
getRsdApiList()
Builds an internal list of APIs to expose information about.
Definition: ApiRsd.php:83
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
ApiRsd
API module for sending out RSD information.
Definition: ApiRsd.php:30
ApiRsd\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiRsd.php:55
ApiRsd\isReadMode
isReadMode()
Indicates whether this module requires read rights.
Definition: ApiRsd.php:62
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:536
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
ApiResult\setSubelementsList
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes.
Definition: ApiResult.php:565
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:491