Deprecate rarely or unused *LinkAttributes methods in Linker
[lhc/web/wiklou.git] / includes / api / ApiPageSet.php
index 3bdecaa..ea85cac 100644 (file)
@@ -68,6 +68,8 @@ class ApiPageSet extends ApiBase {
        private $mPendingRedirectIDs = array();
        private $mConvertedTitles = array();
        private $mGoodRevIDs = array();
+       private $mLiveRevIDs = array();
+       private $mDeletedRevIDs = array();
        private $mMissingRevIDs = array();
        private $mFakePageId = -1;
        private $mCacheMode = 'public';
@@ -596,13 +598,29 @@ class ApiPageSet extends ApiBase {
        }
 
        /**
-        * Get the list of revision IDs (requested with the revids= parameter)
+        * Get the list of valid revision IDs (requested with the revids= parameter)
         * @return array Array of revID (int) => pageID (int)
         */
        public function getRevisionIDs() {
                return $this->mGoodRevIDs;
        }
 
+       /**
+        * Get the list of non-deleted revision IDs (requested with the revids= parameter)
+        * @return array Array of revID (int) => pageID (int)
+        */
+       public function getLiveRevisionIDs() {
+               return $this->mLiveRevIDs;
+       }
+
+       /**
+        * Get the list of revision IDs that were associated with deleted titles.
+        * @return array Array of revID (int) => pageID (int)
+        */
+       public function getDeletedRevisionIDs() {
+               return $this->mDeletedRevIDs;
+       }
+
        /**
         * Revision IDs that were not found in the database
         * @return array Array of revision IDs
@@ -669,6 +687,10 @@ class ApiPageSet extends ApiBase {
 
        /**
         * Populate this PageSet from a rowset returned from the database
+        *
+        * Note that the query result must include the columns returned by
+        * $this->getPageTableFields().
+        *
         * @param DatabaseBase $db
         * @param ResultWrapper $queryResult Query result object
         */
@@ -897,6 +919,7 @@ class ApiPageSet extends ApiBase {
                                $revid = intval( $row->rev_id );
                                $pageid = intval( $row->rev_page );
                                $this->mGoodRevIDs[$revid] = $pageid;
+                               $this->mLiveRevIDs[$revid] = $pageid;
                                $pageids[$pageid] = '';
                                unset( $remaining[$revid] );
                        }
@@ -907,6 +930,51 @@ class ApiPageSet extends ApiBase {
 
                // Populate all the page information
                $this->initFromPageIds( array_keys( $pageids ) );
+
+               // If the user can see deleted revisions, pull out the corresponding
+               // titles from the archive table and include them too. We ignore
+               // ar_page_id because deleted revisions are tied by title, not page_id.
+               if ( !empty( $this->mMissingRevIDs ) && $this->getUser()->isAllowed( 'deletedhistory' ) ) {
+                       $remaining = array_flip( $this->mMissingRevIDs );
+                       $tables = array( 'archive' );
+                       $fields = array( 'ar_rev_id', 'ar_namespace', 'ar_title' );
+                       $where = array( 'ar_rev_id' => $this->mMissingRevIDs );
+
+                       $this->profileDBIn();
+                       $res = $db->select( $tables, $fields, $where, __METHOD__ );
+                       $titles = array();
+                       foreach ( $res as $row ) {
+                               $revid = intval( $row->ar_rev_id );
+                               $titles[$revid] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+                               unset( $remaining[$revid] );
+                       }
+                       $this->profileDBOut();
+
+                       $this->initFromTitles( $titles );
+
+                       foreach ( $titles as $revid => $title ) {
+                               $ns = $title->getNamespace();
+                               $dbkey = $title->getDBkey();
+
+                               // Handle converted titles
+                               if ( !isset( $this->mAllPages[$ns][$dbkey] ) &&
+                                       isset( $this->mConvertedTitles[$title->getPrefixedText()] )
+                               ) {
+                                       $title = Title::newFromText( $this->mConvertedTitles[$title->getPrefixedText()] );
+                                       $ns = $title->getNamespace();
+                                       $dbkey = $title->getDBkey();
+                               }
+
+                               if ( isset( $this->mAllPages[$ns][$dbkey] ) ) {
+                                       $this->mGoodRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
+                                       $this->mDeletedRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
+                               } else {
+                                       $remaining[$revid] = true;
+                               }
+                       }
+
+                       $this->mMissingRevIDs = array_keys( $remaining );
+               }
        }
 
        /**
@@ -1135,26 +1203,46 @@ class ApiPageSet extends ApiBase {
        public function getAllowedParams( $flags = 0 ) {
                $result = array(
                        'titles' => array(
-                               ApiBase::PARAM_ISMULTI => true
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_HELP_MSG => 'api-pageset-param-titles',
                        ),
                        'pageids' => array(
                                ApiBase::PARAM_TYPE => 'integer',
-                               ApiBase::PARAM_ISMULTI => true
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_HELP_MSG => 'api-pageset-param-pageids',
                        ),
                        'revids' => array(
                                ApiBase::PARAM_TYPE => 'integer',
-                               ApiBase::PARAM_ISMULTI => true
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_HELP_MSG => 'api-pageset-param-revids',
+                       ),
+                       'generator' => array(
+                               ApiBase::PARAM_TYPE => null,
+                               ApiBase::PARAM_VALUE_LINKS => array(),
+                               ApiBase::PARAM_HELP_MSG => 'api-pageset-param-generator',
+                       ),
+                       'redirects' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_HELP_MSG => $this->mAllowGenerator
+                                       ? 'api-pageset-param-redirects-generator'
+                                       : 'api-pageset-param-redirects-nogenerator',
+                       ),
+                       'converttitles' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_HELP_MSG => array(
+                                       'api-pageset-param-converttitles',
+                                       $this->getLanguage()->commaList( LanguageConverter::$languagesWithVariants ),
+                               ),
                        ),
-                       'redirects' => false,
-                       'converttitles' => false,
                );
-               if ( $this->mAllowGenerator ) {
-                       if ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
-                               $result['generator'] = array(
-                                       ApiBase::PARAM_TYPE => $this->getGenerators()
-                               );
-                       } else {
-                               $result['generator'] = null;
+
+               if ( !$this->mAllowGenerator ) {
+                       unset( $result['generator'] );
+               } elseif ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
+                       $result['generator'][ApiBase::PARAM_TYPE] = $this->getGenerators();
+                       foreach ( $result['generator'][ApiBase::PARAM_TYPE] as $g ) {
+                               $result['generator'][ApiBase::PARAM_TYPE][] = $g;
+                               $result['generator'][ApiBase::PARAM_VALUE_LINKS][$g] = "Special:ApiHelp/query+$g";
                        }
                }
 
@@ -1188,23 +1276,4 @@ class ApiPageSet extends ApiBase {
 
                return self::$generators;
        }
-
-       public function getParamDescription() {
-               return array(
-                       'titles' => 'A list of titles to work on',
-                       'pageids' => 'A list of page IDs to work on',
-                       'revids' => 'A list of revision IDs to work on',
-                       'generator' => array(
-                               'Get the list of pages to work on by executing the specified query module.',
-                               'NOTE: generator parameter names must be prefixed with a \'g\', see examples'
-                       ),
-                       'redirects' => 'Automatically resolve redirects',
-                       'converttitles' => array(
-                               'Convert titles to other variants if necessary. Only works if ' .
-                                       'the wiki\'s content language supports variant conversion.',
-                               'Languages that support variant conversion include ' .
-                                       implode( ', ', LanguageConverter::$languagesWithVariants )
-                       ),
-               );
-       }
 }