Remove --max-slave-lag options and remnants from maintenance scripts
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index e6667b4..5af44ee 100644 (file)
@@ -42,12 +42,14 @@ class ApiQueryInfo extends ApiQueryBase {
        private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched,
                $pageLatest, $pageLength;
 
-       private $protections, $watched, $watchers, $notificationtimestamps,
+       private $protections, $restrictionTypes, $watched, $watchers, $notificationtimestamps,
                $talkids, $subjectids, $displaytitles;
        private $showZeroWatchers = false;
 
        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();
@@ -419,6 +422,13 @@ class ApiQueryInfo extends ApiQueryBase {
                                        $this->protections[$ns][$dbkey];
                        }
                        $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
+
+                       $pageInfo['restrictiontypes'] = array();
+                       if ( isset( $this->restrictionTypes[$ns][$dbkey] ) ) {
+                               $pageInfo['restrictiontypes'] =
+                                       $this->restrictionTypes[$ns][$dbkey];
+                       }
+                       $this->getResult()->setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
                }
 
                if ( $this->fld_watched && isset( $this->watched[$ns][$dbkey] ) ) {
@@ -477,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;
        }
 
@@ -568,7 +594,8 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
 
-               // Cascading protections
+               // Separate good and missing titles into files and other pages
+               // and populate $this->restrictionTypes
                $images = $others = array();
                foreach ( $this->everything as $title ) {
                        if ( $title->getNamespace() == NS_FILE ) {
@@ -576,6 +603,9 @@ class ApiQueryInfo extends ApiQueryBase {
                        } else {
                                $others[] = $title;
                        }
+                       // Applicable protection types
+                       $this->restrictionTypes[$title->getNamespace()][$title->getDBkey()] =
+                               array_values( $title->getRestrictionTypes() );
                }
 
                if ( count( $others ) ) {
@@ -814,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,