MediaWiki
REL1_23
|
00001 <?php 00002 00032 class ApiRsd extends ApiBase { 00033 00034 public function execute() { 00035 $result = $this->getResult(); 00036 00037 $result->addValue( null, 'version', '1.0' ); 00038 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' ); 00039 00040 $service = array( 'apis' => $this->formatRsdApiList() ); 00041 ApiResult::setContent( $service, 'MediaWiki', 'engineName' ); 00042 ApiResult::setContent( $service, 'https://www.mediawiki.org/', 'engineLink' ); 00043 ApiResult::setContent( $service, Title::newMainPage()->getCanonicalURL(), 'homePageLink' ); 00044 00045 $result->setIndexedTagName( $service['apis'], 'api' ); 00046 00047 $result->addValue( null, 'service', $service ); 00048 } 00049 00050 public function getCustomPrinter() { 00051 return new ApiFormatXmlRsd( $this->getMain(), 'xml' ); 00052 } 00053 00054 public function getAllowedParams() { 00055 return array(); 00056 } 00057 00058 public function getParamDescription() { 00059 return array(); 00060 } 00061 00062 public function getDescription() { 00063 return 'Export an RSD (Really Simple Discovery) schema.'; 00064 } 00065 00066 public function getExamples() { 00067 return array( 00068 'api.php?action=rsd' 00069 ); 00070 } 00071 00089 protected function getRsdApiList() { 00090 $apis = array( 00091 'MediaWiki' => array( 00092 // The API link is required for all RSD API entries. 00093 'apiLink' => wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ), 00094 00095 // Docs link is optional, but recommended. 00096 'docs' => 'https://www.mediawiki.org/wiki/API', 00097 00098 // Some APIs may need a blog ID, but it may be left blank. 00099 'blogID' => '', 00100 00101 // Additional settings are optional. 00102 'settings' => array( 00103 // Change this to true in the future as an aid to 00104 // machine discovery of OAuth for API access. 00105 'OAuth' => false, 00106 ) 00107 ), 00108 ); 00109 wfRunHooks( 'ApiRsdServiceApis', array( &$apis ) ); 00110 00111 return $apis; 00112 } 00113 00120 protected function formatRsdApiList() { 00121 $apis = $this->getRsdApiList(); 00122 00123 $outputData = array(); 00124 foreach ( $apis as $name => $info ) { 00125 $data = array( 00126 'name' => $name, 00127 'preferred' => wfBoolToStr( $name == 'MediaWiki' ), 00128 'apiLink' => $info['apiLink'], 00129 'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : '', 00130 ); 00131 $settings = array(); 00132 if ( isset( $info['docs'] ) ) { 00133 ApiResult::setContent( $settings, $info['docs'], 'docs' ); 00134 } 00135 if ( isset( $info['settings'] ) ) { 00136 foreach ( $info['settings'] as $setting => $val ) { 00137 if ( is_bool( $val ) ) { 00138 $xmlVal = wfBoolToStr( $val ); 00139 } else { 00140 $xmlVal = $val; 00141 } 00142 $setting = array( 'name' => $setting ); 00143 ApiResult::setContent( $setting, $xmlVal ); 00144 $settings[] = $setting; 00145 } 00146 } 00147 if ( count( $settings ) ) { 00148 $this->getResult()->setIndexedTagName( $settings, 'setting' ); 00149 $data['settings'] = $settings; 00150 } 00151 $outputData[] = $data; 00152 } 00153 00154 return $outputData; 00155 } 00156 } 00157 00158 class ApiFormatXmlRsd extends ApiFormatXml { 00159 public function __construct( $main, $format ) { 00160 parent::__construct( $main, $format ); 00161 $this->setRootElement( 'rsd' ); 00162 } 00163 00164 public function getMimeType() { 00165 return 'application/rsd+xml'; 00166 } 00167 }