Merge "(bug 42337) Simplify "my talk" link logic in personal tools"
[lhc/web/wiklou.git] / includes / api / ApiRsd.php
index 552de59..f0e1fad 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       require_once( 'ApiBase.php' );
-}
-
 /**
- * API interface for page purging
+ * API module for sending out RSD information
  * @ingroup API
  */
 class ApiRsd extends ApiBase {
@@ -41,20 +37,14 @@ class ApiRsd extends ApiBase {
 
        public function execute() {
                $result = $this->getResult();
-               
 
                $result->addValue( null, 'version', '1.0' );
                $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
 
-               $service = array(
-                        'engineName' => array(
-                                '*' => 'MediaWiki'
-                        ),
-                        'engineLink' => array(
-                                '*' => 'http://www.mediawiki.org/'
-                        ),
-                        'apis' => $this->formatRsdApiList()
-               );
+               $service = array( 'apis' => $this->formatRsdApiList() );
+               ApiResult::setContent( $service, 'MediaWiki', 'engineName' );
+               ApiResult::setContent( $service, 'https://www.mediawiki.org/', 'engineLink' );
+               ApiResult::setContent( $service, Title::newMainPage()->getCanonicalUrl(), 'homePageLink' );
 
                $result->setIndexedTagName( $service['apis'], 'api' );
 
@@ -74,10 +64,10 @@ class ApiRsd extends ApiBase {
        }
 
        public function getDescription() {
-               return 'Export an RSD schema';
+               return 'Export an RSD (Really Simple Discovery) schema';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=rsd'
                );
@@ -104,10 +94,10 @@ class ApiRsd extends ApiBase {
                $apis = array(
                        'MediaWiki' => array(
                                // The API link is required for all RSD API entries.
-                               'apiLink' => wfExpandUrl( wfScript( 'api' ) ),
+                               'apiLink' => wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ),
 
                                // Docs link is optional, but recommended.
-                               'docs' => 'http://mediawiki.org/wiki/API',
+                               'docs' => 'https://www.mediawiki.org/wiki/API',
 
                                // Some APIs may need a blog ID, but it may be left blank.
                                'blogID' => '',
@@ -139,12 +129,11 @@ class ApiRsd extends ApiBase {
                                'name' => $name,
                                'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
                                'apiLink' => $info['apiLink'],
-                               'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : ''
+                               'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : '',
                        );
+                       $settings = array();
                        if ( isset( $info['docs'] ) ) {
-                               $data['settings']['docs'] = array(
-                                       '*' => $info['docs'],
-                               );
+                               ApiResult::setContent( $settings, $info['docs'], 'docs' );
                        }
                        if ( isset( $info['settings'] ) ) {
                                foreach ( $info['settings'] as $setting => $val ) {
@@ -153,14 +142,14 @@ class ApiRsd extends ApiBase {
                                        } else {
                                                $xmlVal = $val;
                                        }
-                                       $data['settings'][] = array(
-                                               'name' => $setting,
-                                               '*' => $xmlVal,
-                                       );
+                                       $setting = array( 'name' => $setting );
+                                       ApiResult::setContent( $setting, $xmlVal );
+                                       $settings[] = $setting;
                                }
                        }
-                       if ( isset( $data['settings'] ) ) {
-                               $data['settings']['_element'] = 'setting';
+                       if ( count( $settings ) ) {
+                               $this->getResult()->setIndexedTagName( $settings, 'setting' );
+                               $data['settings'] = $settings;
                        }
                        $outputData[] = $data;
                }
@@ -177,7 +166,7 @@ class ApiFormatXmlRsd extends ApiFormatXml {
                parent::__construct( $main, $format );
                $this->setRootElement( 'rsd' );
        }
-       
+
        public function getMimeType() {
                return 'application/rsd+xml';
        }