Merge "Perform a permission check on the title when changing the page language"
[lhc/web/wiklou.git] / includes / api / ApiQueryLangBacklinks.php
index 9f77b84..fd67d7c 100644 (file)
@@ -51,7 +51,14 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
                $params = $this->extractRequestParams();
 
                if ( isset( $params['title'] ) && !isset( $params['lang'] ) ) {
-                       $this->dieUsageMsg( array( 'missingparam', 'lang' ) );
+                       $this->dieWithError(
+                               [
+                                       'apierror-invalidparammix-mustusewith',
+                                       $this->encodeParamName( 'title' ),
+                                       $this->encodeParamName( 'lang' )
+                               ],
+                               'nolang'
+                       );
                }
 
                if ( !is_null( $params['continue'] ) ) {
@@ -76,11 +83,11 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
                $lllang = isset( $prop['lllang'] );
                $lltitle = isset( $prop['lltitle'] );
 
-               $this->addTables( array( 'langlinks', 'page' ) );
+               $this->addTables( [ 'langlinks', 'page' ] );
                $this->addWhere( 'll_from = page_id' );
 
-               $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect',
-                       'll_from', 'll_lang', 'll_title' ) );
+               $this->addFields( [ 'page_id', 'page_title', 'page_namespace', 'page_is_redirect',
+                       'll_from', 'll_lang', 'll_title' ] );
 
                $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
                if ( isset( $params['lang'] ) ) {
@@ -89,24 +96,24 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
                                $this->addWhereFld( 'll_title', $params['title'] );
                                $this->addOption( 'ORDER BY', 'll_from' . $sort );
                        } else {
-                               $this->addOption( 'ORDER BY', array(
+                               $this->addOption( 'ORDER BY', [
                                        'll_title' . $sort,
                                        'll_from' . $sort
-                               ) );
+                               ] );
                        }
                } else {
-                       $this->addOption( 'ORDER BY', array(
+                       $this->addOption( 'ORDER BY', [
                                'll_lang' . $sort,
                                'll_title' . $sort,
                                'll_from' . $sort
-                       ) );
+                       ] );
                }
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
 
                $res = $this->select( __METHOD__ );
 
-               $pages = array();
+               $pages = [];
 
                $count = 0;
                $result = $this->getResult();
@@ -125,7 +132,7 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
                        if ( !is_null( $resultPageSet ) ) {
                                $pages[] = Title::newFromRow( $row );
                        } else {
-                               $entry = array( 'pageid' => $row->page_id );
+                               $entry = [ 'pageid' => $row->page_id ];
 
                                $title = Title::makeTitle( $row->page_namespace, $row->page_title );
                                ApiQueryBase::addTitleInfo( $entry, $title );
@@ -142,7 +149,7 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
                                        $entry['lltitle'] = $row->ll_title;
                                }
 
-                               $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
+                               $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $entry );
                                if ( !$fit ) {
                                        $this->setContinueEnumParameter(
                                                'continue',
@@ -154,7 +161,7 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
                }
 
                if ( is_null( $resultPageSet ) ) {
-                       $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'll' );
+                       $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'll' );
                } else {
                        $resultPageSet->populateFromTitles( $pages );
                }
@@ -165,48 +172,48 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
        }
 
        public function getAllowedParams() {
-               return array(
+               return [
                        'lang' => null,
                        'title' => null,
-                       'continue' => array(
+                       'continue' => [
                                ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
-                       ),
-                       'limit' => array(
+                       ],
+                       '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
-                       ),
-                       'prop' => array(
+                       ],
+                       'prop' => [
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_DFLT => '',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'lllang',
                                        'lltitle',
-                               ),
-                               ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
-                       ),
-                       'dir' => array(
+                               ],
+                               ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                       ],
+                       'dir' => [
                                ApiBase::PARAM_DFLT => 'ascending',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'ascending',
                                        'descending'
-                               )
-                       ),
-               );
+                               ]
+                       ],
+               ];
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=query&list=langbacklinks&lbltitle=Test&lbllang=fr'
                                => 'apihelp-query+langbacklinks-example-simple',
                        'action=query&generator=langbacklinks&glbltitle=Test&glbllang=fr&prop=info'
                                => 'apihelp-query+langbacklinks-example-generator',
-               );
+               ];
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Langbacklinks';
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Langbacklinks';
        }
 }