MediaWiki
REL1_24
|
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 00072 public function isReadMode() { 00073 return false; 00074 } 00075 00093 protected function getRsdApiList() { 00094 $apis = array( 00095 'MediaWiki' => array( 00096 // The API link is required for all RSD API entries. 00097 'apiLink' => wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ), 00098 00099 // Docs link is optional, but recommended. 00100 'docs' => 'https://www.mediawiki.org/wiki/API', 00101 00102 // Some APIs may need a blog ID, but it may be left blank. 00103 'blogID' => '', 00104 00105 // Additional settings are optional. 00106 'settings' => array( 00107 // Change this to true in the future as an aid to 00108 // machine discovery of OAuth for API access. 00109 'OAuth' => false, 00110 ) 00111 ), 00112 ); 00113 wfRunHooks( 'ApiRsdServiceApis', array( &$apis ) ); 00114 00115 return $apis; 00116 } 00117 00124 protected function formatRsdApiList() { 00125 $apis = $this->getRsdApiList(); 00126 00127 $outputData = array(); 00128 foreach ( $apis as $name => $info ) { 00129 $data = array( 00130 'name' => $name, 00131 'preferred' => wfBoolToStr( $name == 'MediaWiki' ), 00132 'apiLink' => $info['apiLink'], 00133 'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : '', 00134 ); 00135 $settings = array(); 00136 if ( isset( $info['docs'] ) ) { 00137 ApiResult::setContent( $settings, $info['docs'], 'docs' ); 00138 } 00139 if ( isset( $info['settings'] ) ) { 00140 foreach ( $info['settings'] as $setting => $val ) { 00141 if ( is_bool( $val ) ) { 00142 $xmlVal = wfBoolToStr( $val ); 00143 } else { 00144 $xmlVal = $val; 00145 } 00146 $setting = array( 'name' => $setting ); 00147 ApiResult::setContent( $setting, $xmlVal ); 00148 $settings[] = $setting; 00149 } 00150 } 00151 if ( count( $settings ) ) { 00152 $this->getResult()->setIndexedTagName( $settings, 'setting' ); 00153 $data['settings'] = $settings; 00154 } 00155 $outputData[] = $data; 00156 } 00157 00158 return $outputData; 00159 } 00160 } 00161 00162 class ApiFormatXmlRsd extends ApiFormatXml { 00163 public function __construct( ApiMain $main, $format ) { 00164 parent::__construct( $main, $format ); 00165 $this->setRootElement( 'rsd' ); 00166 } 00167 00168 public function getMimeType() { 00169 return 'application/rsd+xml'; 00170 } 00171 }