Merge "Escape message 'redirectto' in Article"
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 5e61ed1..02c88c4 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' );
        }
@@ -58,10 +60,10 @@ class ApiQueryInfo extends ApiQueryBase {
         */
        public function requestExtraData( $pageSet ) {
                $pageSet->requestField( 'page_restrictions' );
-               // when resolving redirects, no page will have this field
-               if ( !$pageSet->isResolvingRedirects() ) {
-                       $pageSet->requestField( 'page_is_redirect' );
-               }
+               // If the pageset is resolving redirects we won't get page_is_redirect.
+               // But we can't know for sure until the pageset is executed (revids may
+               // turn it off), so request it unconditionally.
+               $pageSet->requestField( 'page_is_redirect' );
                $pageSet->requestField( 'page_is_new' );
                $config = $this->getConfig();
                $pageSet->requestField( 'page_touched' );
@@ -104,7 +106,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        'import' => array( 'ApiQueryInfo', 'getImportToken' ),
                        'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
                );
-               wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions ) );
+               Hooks::run( 'APIQueryInfoTokens', array( &$this->tokenFunctions ) );
 
                return $this->tokenFunctions;
        }
@@ -357,7 +359,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 +376,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 +421,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] ) ) {
@@ -463,7 +472,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                $pageInfo['preload'] = '';
                        } else {
                                $text = null;
-                               wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
+                               Hooks::run( 'EditFormPreloadText', array( &$text, &$title ) );
 
                                $pageInfo['preload'] = $text;
                        }
@@ -477,6 +486,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 +593,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 +602,9 @@ class ApiQueryInfo extends ApiQueryBase {
                        } else {
                                $others[] = $title;
                        }
+                       // Applicable protection types
+                       $this->restrictionTypes[$title->getNamespace()][$title->getDBkey()] =
+                               array_values( $title->getRestrictionTypes() );
                }
 
                if ( count( $others ) ) {
@@ -811,7 +840,13 @@ class ApiQueryInfo extends ApiQueryBase {
                                        'displaytitle',
                                        // If you add more properties here, please consider whether they
                                        // need to be added to getCacheMode()
-                               ) ),
+                               ),
+                               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,