Remove --max-slave-lag options and remnants from maintenance scripts
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 05a1a15..5af44ee 100644 (file)
@@ -48,6 +48,8 @@ class ApiQueryInfo extends ApiQueryBase {
 
        private $tokenFunctions;
 
+       private $countTestedActions = 0;
+
        public function __construct( ApiQuery $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'in' );
        }
@@ -88,8 +90,9 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $this->tokenFunctions;
                }
 
-               // If we're in JSON callback mode, no tokens can be obtained
-               if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+               // If we're in a mode that breaks the same-origin policy, no tokens can
+               // be obtained
+               if ( $this->lacksSameOriginSecurity() ) {
                        return array();
                }
 
@@ -357,7 +360,7 @@ class ApiQueryInfo extends ApiQueryBase {
                /** @var $title Title */
                foreach ( $this->everything as $pageid => $title ) {
                        $pageInfo = $this->extractPageInfo( $pageid, $title );
-                       $fit = $result->addValue( array(
+                       $fit = $pageInfo !== null && $result->addValue( array(
                                'query',
                                'pages'
                        ), $pageid, $pageInfo );
@@ -374,7 +377,7 @@ class ApiQueryInfo extends ApiQueryBase {
         * Get a result array with information about a title
         * @param int $pageid Page ID (negative for missing titles)
         * @param Title $title
-        * @return array
+        * @return array|null
         */
        private function extractPageInfo( $pageid, $title ) {
                $pageInfo = array();
@@ -484,6 +487,22 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
 
+               if ( $this->params['testactions'] ) {
+                       $limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML1 : self::LIMIT_SML2;
+                       if ( $this->countTestedActions >= $limit ) {
+                               return null; // force a continuation
+                       }
+
+                       $user = $this->getUser();
+                       $pageInfo['actions'] = array();
+                       foreach ( $this->params['testactions'] as $action ) {
+                               $this->countTestedActions++;
+                               if ( $title->userCan( $action, $user ) ) {
+                                       $pageInfo['actions'][$action] = '';
+                               }
+                       }
+               }
+
                return $pageInfo;
        }
 
@@ -825,6 +844,10 @@ class ApiQueryInfo extends ApiQueryBase {
                                ),
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
                        ),
+                       'testactions' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ),
                        'token' => array(
                                ApiBase::PARAM_DEPRECATED => true,
                                ApiBase::PARAM_DFLT => null,