Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ApiRsd | |
0.00% |
0 / 58 |
|
0.00% |
0 / 7 |
182 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| getCustomPrinter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| isReadMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRsdApiList | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
| formatRsdApiList | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
56 | |||
| getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * API for MediaWiki 1.17+ |
| 5 | * |
| 6 | * Copyright © 2010 Bryan Tong Minh and Brooke Vibber |
| 7 | * |
| 8 | * @license GPL-2.0-or-later |
| 9 | * @file |
| 10 | */ |
| 11 | |
| 12 | namespace MediaWiki\Api; |
| 13 | |
| 14 | use MediaWiki\MediaWikiServices; |
| 15 | use MediaWiki\Title\Title; |
| 16 | |
| 17 | /** |
| 18 | * API module for sending out RSD information |
| 19 | * @ingroup API |
| 20 | */ |
| 21 | class 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 | |
| 41 | /** @inheritDoc */ |
| 42 | public function getCustomPrinter() { |
| 43 | return new ApiFormatXmlRsd( $this->getMain(), 'xml' ); |
| 44 | } |
| 45 | |
| 46 | /** @inheritDoc */ |
| 47 | protected function getExamplesMessages() { |
| 48 | return [ |
| 49 | 'action=rsd' |
| 50 | => 'apihelp-rsd-example-simple', |
| 51 | ]; |
| 52 | } |
| 53 | |
| 54 | /** @inheritDoc */ |
| 55 | public function isReadMode() { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Builds an internal list of APIs to expose information about. |
| 61 | * Normally this only lists the MediaWiki API, with its base URL, |
| 62 | * link to documentation, and a marker as to available authentication |
| 63 | * (to aid in OAuth client apps switching to support in the future). |
| 64 | * |
| 65 | * Extensions can expose other APIs, such as WordPress or Twitter- |
| 66 | * compatible APIs, by hooking 'ApiRsdServiceApis' and adding more |
| 67 | * elements to the array. |
| 68 | * |
| 69 | * See https://cyber.harvard.edu/blogs/gems/tech/rsd.html for |
| 70 | * the base RSD spec, and check WordPress and StatusNet sites for |
| 71 | * in-production examples listing several blogging and micrblogging |
| 72 | * APIs. |
| 73 | * |
| 74 | * @return array[] |
| 75 | */ |
| 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 | |
| 103 | /** |
| 104 | * Formats the internal list of exposed APIs into an array suitable |
| 105 | * to pass to the API's XML formatter. |
| 106 | * |
| 107 | * @return array |
| 108 | */ |
| 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 | |
| 147 | /** @inheritDoc */ |
| 148 | public function getHelpUrls() { |
| 149 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Rsd'; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /** @deprecated class alias since 1.43 */ |
| 154 | class_alias( ApiRsd::class, 'ApiRsd' ); |