MediaWiki
REL1_19
|
00001 <?php 00002 00032 class ApiRsd extends ApiBase { 00033 00034 public function __construct( $main, $action ) { 00035 parent::__construct( $main, $action ); 00036 } 00037 00038 public function execute() { 00039 $result = $this->getResult(); 00040 00041 $result->addValue( null, 'version', '1.0' ); 00042 $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' ); 00043 00044 $service = array( 'apis' => $this->formatRsdApiList() ); 00045 ApiResult::setContent( $service, 'MediaWiki', 'engineName' ); 00046 ApiResult::setContent( $service, 'https://www.mediawiki.org/', 'engineLink' ); 00047 ApiResult::setContent( $service, Title::newMainPage()->getCanonicalUrl(), 'homePageLink' ); 00048 00049 $result->setIndexedTagName( $service['apis'], 'api' ); 00050 00051 $result->addValue( null, 'service', $service ); 00052 } 00053 00054 public function getCustomPrinter() { 00055 return new ApiFormatXmlRsd( $this->getMain(), 'xml' ); 00056 } 00057 00058 public function getAllowedParams() { 00059 return array(); 00060 } 00061 00062 public function getParamDescription() { 00063 return array(); 00064 } 00065 00066 public function getDescription() { 00067 return 'Export an RSD (Really Simple Discovery) schema'; 00068 } 00069 00070 public function getExamples() { 00071 return array( 00072 'api.php?action=rsd' 00073 ); 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 return $apis; 00115 } 00116 00123 protected function formatRsdApiList() { 00124 $apis = $this->getRsdApiList(); 00125 00126 $outputData = array(); 00127 foreach ( $apis as $name => $info ) { 00128 $data = array( 00129 'name' => $name, 00130 'preferred' => wfBoolToStr( $name == 'MediaWiki' ), 00131 'apiLink' => $info['apiLink'], 00132 'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : '', 00133 ); 00134 $settings = array(); 00135 if ( isset( $info['docs'] ) ) { 00136 ApiResult::setContent( $settings, $info['docs'], 'docs' ); 00137 } 00138 if ( isset( $info['settings'] ) ) { 00139 foreach ( $info['settings'] as $setting => $val ) { 00140 if ( is_bool( $val ) ) { 00141 $xmlVal = wfBoolToStr( $val ); 00142 } else { 00143 $xmlVal = $val; 00144 } 00145 $setting = array( 'name' => $setting ); 00146 ApiResult::setContent( $setting, $xmlVal ); 00147 $settings[] = $setting; 00148 } 00149 } 00150 if ( count( $settings ) ) { 00151 $this->getResult()->setIndexedTagName( $settings, 'setting' ); 00152 $data['settings'] = $settings; 00153 } 00154 $outputData[] = $data; 00155 } 00156 return $outputData; 00157 } 00158 00159 public function getVersion() { 00160 return __CLASS__ . ': $Id$'; 00161 } 00162 } 00163 00164 class ApiFormatXmlRsd extends ApiFormatXml { 00165 public function __construct( $main, $format ) { 00166 parent::__construct( $main, $format ); 00167 $this->setRootElement( 'rsd' ); 00168 } 00169 00170 public function getMimeType() { 00171 return 'application/rsd+xml'; 00172 } 00173 00174 public function getVersion() { 00175 return __CLASS__ . ': $Id$'; 00176 } 00177 }