Merge "Missing space between variable name and docstring"
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 0cf6b04..276aafb 100644 (file)
@@ -118,7 +118,7 @@ class ApiQueryInfo extends ApiQueryBase {
                return $this->tokenFunctions;
        }
 
-       static protected $cachedTokens = [];
+       protected static $cachedTokens = [];
 
        /**
         * @deprecated since 1.24
@@ -411,8 +411,8 @@ class ApiQueryInfo extends ApiQueryBase {
 
                if ( $titleExists ) {
                        $pageInfo['touched'] = wfTimestamp( TS_ISO_8601, $this->pageTouched[$pageid] );
-                       $pageInfo['lastrevid'] = intval( $this->pageLatest[$pageid] );
-                       $pageInfo['length'] = intval( $this->pageLength[$pageid] );
+                       $pageInfo['lastrevid'] = (int)$this->pageLatest[$pageid];
+                       $pageInfo['length'] = (int)$this->pageLength[$pageid];
 
                        if ( isset( $this->pageIsRedir[$pageid] ) && $this->pageIsRedir[$pageid] ) {
                                $pageInfo['redirect'] = true;
@@ -515,23 +515,37 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
 
-               if ( $this->fld_varianttitles ) {
-                       if ( isset( $this->variantTitles[$pageid] ) ) {
-                               $pageInfo['varianttitles'] = $this->variantTitles[$pageid];
-                       }
+               if ( $this->fld_varianttitles && isset( $this->variantTitles[$pageid] ) ) {
+                       $pageInfo['varianttitles'] = $this->variantTitles[$pageid];
                }
 
                if ( $this->params['testactions'] ) {
-                       $limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML1 : self::LIMIT_SML2;
+                       $limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML2 : self::LIMIT_SML1;
                        if ( $this->countTestedActions >= $limit ) {
                                return null; // force a continuation
                        }
 
+                       $detailLevel = $this->params['testactionsdetail'];
+                       $rigor = $detailLevel === 'quick' ? 'quick' : 'secure';
+                       $errorFormatter = $this->getErrorFormatter();
+                       if ( $errorFormatter->getFormat() === 'bc' ) {
+                               // Eew, no. Use a more modern format here.
+                               $errorFormatter = $errorFormatter->newWithFormat( 'plaintext' );
+                       }
+
                        $user = $this->getUser();
                        $pageInfo['actions'] = [];
                        foreach ( $this->params['testactions'] as $action ) {
                                $this->countTestedActions++;
-                               $pageInfo['actions'][$action] = $title->userCan( $action, $user );
+
+                               if ( $detailLevel === 'boolean' ) {
+                                       $pageInfo['actions'][$action] = $title->userCan( $action, $user );
+                               } else {
+                                       $pageInfo['actions'][$action] = $errorFormatter->arrayFromStatus( $this->errorArrayToStatus(
+                                               $title->getUserPermissionsErrors( $action, $user, $rigor ),
+                                               $user
+                                       ) );
+                               }
                        }
                }
 
@@ -694,10 +708,11 @@ class ApiQueryInfo extends ApiQueryBase {
         */
        private function getTSIDs() {
                $getTitles = $this->talkids = $this->subjectids = [];
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
 
                /** @var Title $t */
                foreach ( $this->everything as $t ) {
-                       if ( MWNamespace::isTalk( $t->getNamespace() ) ) {
+                       if ( $nsInfo->isTalk( $t->getNamespace() ) ) {
                                if ( $this->fld_subjectid ) {
                                        $getTitles[] = $t->getSubjectPage();
                                }
@@ -705,7 +720,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                $getTitles[] = $t->getTalkPage();
                        }
                }
-               if ( !count( $getTitles ) ) {
+               if ( $getTitles === [] ) {
                        return;
                }
 
@@ -720,12 +735,12 @@ class ApiQueryInfo extends ApiQueryBase {
                $this->addWhere( $lb->constructSet( 'page', $db ) );
                $res = $this->select( __METHOD__ );
                foreach ( $res as $row ) {
-                       if ( MWNamespace::isTalk( $row->page_namespace ) ) {
-                               $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] =
-                                       intval( $row->page_id );
+                       if ( $nsInfo->isTalk( $row->page_namespace ) ) {
+                               $this->talkids[$nsInfo->getSubject( $row->page_namespace )][$row->page_title] =
+                                       (int)( $row->page_id );
                        } else {
-                               $this->subjectids[MWNamespace::getTalk( $row->page_namespace )][$row->page_title] =
-                                       intval( $row->page_id );
+                               $this->subjectids[$nsInfo->getTalk( $row->page_namespace )][$row->page_title] =
+                                       (int)( $row->page_id );
                        }
                }
        }
@@ -735,7 +750,7 @@ class ApiQueryInfo extends ApiQueryBase {
 
                $pageIds = array_keys( $this->titles );
 
-               if ( !count( $pageIds ) ) {
+               if ( $pageIds === [] ) {
                        return;
                }
 
@@ -752,7 +767,7 @@ class ApiQueryInfo extends ApiQueryBase {
        }
 
        private function getVariantTitles() {
-               if ( !count( $this->titles ) ) {
+               if ( $this->titles === [] ) {
                        return;
                }
                $this->variantTitles = [];
@@ -955,11 +970,19 @@ class ApiQueryInfo extends ApiQueryBase {
                                        // need to be added to getCacheMode()
                                ],
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                               ApiBase::PARAM_DEPRECATED_VALUES => [
+                                       'readable' => true, // Since 1.32
+                               ],
                        ],
                        'testactions' => [
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_ISMULTI => true,
                        ],
+                       'testactionsdetail' => [
+                               ApiBase::PARAM_TYPE => [ 'boolean', 'full', 'quick' ],
+                               ApiBase::PARAM_DFLT => 'boolean',
+                               ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                       ],
                        'token' => [
                                ApiBase::PARAM_DEPRECATED => true,
                                ApiBase::PARAM_ISMULTI => true,