Merge "Move up devunt's name to Developers"
[lhc/web/wiklou.git] / includes / api / ApiQueryIWLinks.php
index bb388cd..6d9c2ca 100644 (file)
@@ -42,16 +42,23 @@ class ApiQueryIWLinks extends ApiQueryBase {
                }
 
                $params = $this->extractRequestParams();
+               $prop = array_flip( (array)$params['prop'] );
 
                if ( isset( $params['title'] ) && !isset( $params['prefix'] ) ) {
-                       $this->dieUsageMsg( array( 'missingparam', 'prefix' ) );
+                       $this->dieUsageMsg( [ 'missingparam', 'prefix' ] );
                }
 
-               $this->addFields( array(
+               // Handle deprecated param
+               $this->requireMaxOneParameter( $params, 'url', 'prop' );
+               if ( $params['url'] ) {
+                       $prop = [ 'url' => 1 ];
+               }
+
+               $this->addFields( [
                        'iwl_from',
                        'iwl_prefix',
                        'iwl_title'
-               ) );
+               ] );
 
                $this->addTables( 'iwlinks' );
                $this->addWhereFld( 'iwl_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
@@ -80,21 +87,21 @@ class ApiQueryIWLinks extends ApiQueryBase {
                                $this->addWhereFld( 'iwl_title', $params['title'] );
                                $this->addOption( 'ORDER BY', 'iwl_from' . $sort );
                        } else {
-                               $this->addOption( 'ORDER BY', array(
+                               $this->addOption( 'ORDER BY', [
                                        'iwl_from' . $sort,
                                        'iwl_title' . $sort
-                               ) );
+                               ] );
                        }
                } else {
                        // Don't order by iwl_from if it's constant in the WHERE clause
                        if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
                                $this->addOption( 'ORDER BY', 'iwl_prefix' . $sort );
                        } else {
-                               $this->addOption( 'ORDER BY', array(
+                               $this->addOption( 'ORDER BY', [
                                        'iwl_from' . $sort,
                                        'iwl_prefix' . $sort,
                                        'iwl_title' . $sort
-                               ) );
+                               ] );
                        }
                }
 
@@ -112,16 +119,16 @@ class ApiQueryIWLinks extends ApiQueryBase {
                                );
                                break;
                        }
-                       $entry = array( 'prefix' => $row->iwl_prefix );
+                       $entry = [ 'prefix' => $row->iwl_prefix ];
 
-                       if ( $params['url'] ) {
+                       if ( isset( $prop['url'] ) ) {
                                $title = Title::newFromText( "{$row->iwl_prefix}:{$row->iwl_title}" );
                                if ( $title ) {
                                        $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
                                }
                        }
 
-                       ApiResult::setContent( $entry, $row->iwl_title );
+                       ApiResult::setContentValue( $entry, 'title', $row->iwl_title );
                        $fit = $this->addPageSubItem( $row->iwl_from, $entry );
                        if ( !$fit ) {
                                $this->setContinueEnumParameter(
@@ -138,48 +145,45 @@ class ApiQueryIWLinks extends ApiQueryBase {
        }
 
        public function getAllowedParams() {
-               return array(
-                       'url' => false,
-                       'limit' => array(
-                               ApiBase::PARAM_DFLT => 10,
-                               ApiBase::PARAM_TYPE => 'limit',
-                               ApiBase::PARAM_MIN => 1,
-                               ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
-                               ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
-                       ),
-                       'continue' => null,
+               return [
+                       'prop' => [
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_TYPE => [
+                                       'url',
+                               ],
+                               ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                       ],
                        'prefix' => null,
                        'title' => null,
-                       'dir' => array(
+                       'dir' => [
                                ApiBase::PARAM_DFLT => 'ascending',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'ascending',
                                        'descending'
-                               )
-                       ),
-               );
-       }
-
-       public function getParamDescription() {
-               return array(
-                       'url' => 'Whether to get the full URL',
-                       'limit' => 'How many interwiki links to return',
-                       'continue' => 'When more results are available, use this to continue',
-                       'prefix' => 'Prefix for the interwiki',
-                       'title' => "Interwiki link to search for. Must be used with {$this->getModulePrefix()}prefix",
-                       'dir' => 'The direction in which to list',
-               );
-       }
-
-       public function getDescription() {
-               return 'Returns all interwiki links from the given page(s).';
+                               ]
+                       ],
+                       'limit' => [
+                               ApiBase::PARAM_DFLT => 10,
+                               ApiBase::PARAM_TYPE => 'limit',
+                               ApiBase::PARAM_MIN => 1,
+                               ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+                               ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+                       ],
+                       'continue' => [
+                               ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+                       ],
+                       'url' => [
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ],
+               ];
        }
 
-       public function getExamples() {
-               return array(
-                       'api.php?action=query&prop=iwlinks&titles=Main%20Page'
-                               => 'Get interwiki links from the [[Main Page]]',
-               );
+       protected function getExamplesMessages() {
+               return [
+                       'action=query&prop=iwlinks&titles=Main%20Page'
+                               => 'apihelp-query+iwlinks-example-simple',
+               ];
        }
 
        public function getHelpUrls() {