]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiRsd.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / api / ApiRsd.php
index 1274c85cfd88f54dd8832483391f53589a16d558..fdc62a8ea927c6dc9e94eea01c4ad85313dc3627 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       require_once( 'ApiBase.php' );
-}
-
 /**
  * API module for sending out RSD information
  * @ingroup API
  */
 class ApiRsd extends ApiBase {
 
-       public function __construct( $main, $action ) {
-               parent::__construct( $main, $action );
-       }
-
        public function execute() {
                $result = $this->getResult();
 
                $result->addValue( null, 'version', '1.0' );
                $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' );
 
-               $service = array( 'apis' => $this->formatRsdApiList() );
-               ApiResult::setContent( $service, 'MediaWiki', 'engineName' );
-               ApiResult::setContent( $service, 'http://www.mediawiki.org/', 'engineLink' );
+               $service = [
+                       'apis' => $this->formatRsdApiList(),
+                       'engineName' => 'MediaWiki',
+                       'engineLink' => 'https://www.mediawiki.org/',
+                       'homePageLink' => Title::newMainPage()->getCanonicalURL(),
+               ];
 
-               $result->setIndexedTagName( $service['apis'], 'api' );
+               ApiResult::setSubelementsList( $service, [ 'engineName', 'engineLink', 'homePageLink' ] );
+               ApiResult::setIndexedTagName( $service['apis'], 'api' );
 
                $result->addValue( null, 'service', $service );
        }
@@ -58,22 +54,15 @@ class ApiRsd extends ApiBase {
                return new ApiFormatXmlRsd( $this->getMain(), 'xml' );
        }
 
-       public function getAllowedParams() {
-               return array();
+       protected function getExamplesMessages() {
+               return [
+                       'action=rsd'
+                               => 'apihelp-rsd-example-simple',
+               ];
        }
 
-       public function getParamDescription() {
-               return array();
-       }
-
-       public function getDescription() {
-               return 'Export an RSD schema';
-       }
-
-       protected function getExamples() {
-               return array(
-                       'api.php?action=rsd'
-               );
+       public function isReadMode() {
+               return false;
        }
 
        /**
@@ -86,7 +75,7 @@ class ApiRsd extends ApiBase {
         * compatible APIs, by hooking 'ApiRsdServiceApis' and adding more
         * elements to the array.
         *
-        * See http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html for
+        * See https://cyber.harvard.edu/blogs/gems/tech/rsd.html for
         * the base RSD spec, and check WordPress and StatusNet sites for
         * in-production examples listing several blogging and micrblogging
         * APIs.
@@ -94,26 +83,27 @@ class ApiRsd extends ApiBase {
         * @return array
         */
        protected function getRsdApiList() {
-               $apis = array(
-                       'MediaWiki' => array(
+               $apis = [
+                       'MediaWiki' => [
                                // 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/Special:MyLanguage/API',
 
                                // Some APIs may need a blog ID, but it may be left blank.
                                'blogID' => '',
 
                                // Additional settings are optional.
-                               'settings' => array(
+                               'settings' => [
                                        // Change this to true in the future as an aid to
                                        // machine discovery of OAuth for API access.
                                        'OAuth' => false,
-                               )
-                       ),
-               );
-               wfRunHooks( 'ApiRsdServiceApis', array( &$apis ) );
+                               ]
+                       ],
+               ];
+               Hooks::run( 'ApiRsdServiceApis', [ &$apis ] );
+
                return $apis;
        }
 
@@ -126,17 +116,18 @@ class ApiRsd extends ApiBase {
        protected function formatRsdApiList() {
                $apis = $this->getRsdApiList();
 
-               $outputData = array();
+               $outputData = [];
                foreach ( $apis as $name => $info ) {
-                       $data = array(
+                       $data = [
                                'name' => $name,
                                'preferred' => wfBoolToStr( $name == 'MediaWiki' ),
                                'apiLink' => $info['apiLink'],
                                'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : '',
-                       );
-                       $settings = array();
+                       ];
+                       $settings = [];
                        if ( isset( $info['docs'] ) ) {
-                               ApiResult::setContent( $settings, $info['docs'], 'docs' );
+                               $settings['docs'] = $info['docs'];
+                               ApiResult::setSubelementsList( $settings, 'docs' );
                        }
                        if ( isset( $info['settings'] ) ) {
                                foreach ( $info['settings'] as $setting => $val ) {
@@ -145,36 +136,34 @@ class ApiRsd extends ApiBase {
                                        } else {
                                                $xmlVal = $val;
                                        }
-                                       $setting = array( 'name' => $setting );
-                                       ApiResult::setContent( $setting, $xmlVal );
+                                       $setting = [ 'name' => $setting ];
+                                       ApiResult::setContentValue( $setting, 'value', $xmlVal );
                                        $settings[] = $setting;
                                }
                        }
                        if ( count( $settings ) ) {
-                               $this->getResult()->setIndexedTagName( $settings, 'setting' );
+                               ApiResult::setIndexedTagName( $settings, 'setting' );
                                $data['settings'] = $settings;
                        }
                        $outputData[] = $data;
                }
-               return $outputData;
-       }
 
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
+               return $outputData;
        }
 }
 
 class ApiFormatXmlRsd extends ApiFormatXml {
-       public function __construct( $main, $format ) {
+       public function __construct( ApiMain $main, $format ) {
                parent::__construct( $main, $format );
                $this->setRootElement( 'rsd' );
        }
-       
+
        public function getMimeType() {
                return 'application/rsd+xml';
        }
 
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
+       public static function recXmlPrint( $name, $value, $indent, $attributes = [] ) {
+               unset( $attributes['_idx'] );
+               return parent::recXmlPrint( $name, $value, $indent, $attributes );
        }
 }