private $mAllPages = array(); // [ns][dbkey] => page_id or negative when missing
private $mTitles = array();
+ private $mGoodAndMissingPages = array(); // [ns][dbkey] => page_id or negative when missing
+ private $mGoodPages = array(); // [ns][dbkey] => page_id
private $mGoodTitles = array();
+ private $mMissingPages = array(); // [ns][dbkey] => fake page_id
private $mMissingTitles = array();
private $mInvalidTitles = array();
private $mMissingPageIDs = array();
private $mPendingRedirectIDs = array();
private $mConvertedTitles = array();
private $mGoodRevIDs = array();
+ private $mLiveRevIDs = array();
+ private $mDeletedRevIDs = array();
private $mMissingRevIDs = array();
private $mFakePageId = -1;
private $mCacheMode = 'public';
return count( $this->mTitles );
}
+ /**
+ * Returns an array [ns][dbkey] => page_id for all good titles.
+ * @return array
+ */
+ public function getGoodTitlesByNamespace() {
+ return $this->mGoodPages;
+ }
+
/**
* Title objects that were found in the database.
* @return Title[] Array page_id (int) => Title (obj)
return count( $this->mGoodTitles );
}
+ /**
+ * Returns an array [ns][dbkey] => fake_page_id for all missing titles.
+ * fake_page_id is a unique negative number.
+ * @return array
+ */
+ public function getMissingTitlesByNamespace() {
+ return $this->mMissingPages;
+ }
+
/**
* Title objects that were NOT found in the database.
* The array's index will be negative for each item
return $this->mMissingTitles;
}
+ /**
+ * Returns an array [ns][dbkey] => page_id for all good and missing titles.
+ * @return array
+ */
+ public function getGoodAndMissingTitlesByNamespace() {
+ return $this->mGoodAndMissingPages;
+ }
+
+ /**
+ * Title objects for good and missing titles.
+ * @return array
+ */
+ public function getGoodAndMissingTitles() {
+ return $this->mGoodTitles + $this->mMissingTitles;
+ }
+
/**
* Titles that were deemed invalid by Title::newFromText()
* The array's index will be unique and negative for each item
}
/**
- * 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
/**
* 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
*/
if ( $this->mResolveRedirects && $row->page_is_redirect == '1' ) {
$this->mPendingRedirectIDs[$pageId] = $title;
} else {
+ $this->mGoodPages[$row->page_namespace][$row->page_title] = $pageId;
+ $this->mGoodAndMissingPages[$row->page_namespace][$row->page_title] = $pageId;
$this->mGoodTitles[$pageId] = $title;
}
foreach ( array_keys( $dbkeys ) as $dbkey ) {
$title = Title::makeTitle( $ns, $dbkey );
$this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
+ $this->mMissingPages[$ns][$dbkey] = $this->mFakePageId;
+ $this->mGoodAndMissingPages[$ns][$dbkey] = $this->mFakePageId;
$this->mMissingTitles[$this->mFakePageId] = $title;
$this->mFakePageId--;
$this->mTitles[] = $title;
$revid = intval( $row->rev_id );
$pageid = intval( $row->rev_page );
$this->mGoodRevIDs[$revid] = $pageid;
+ $this->mLiveRevIDs[$revid] = $pageid;
$pageids[$pageid] = '';
unset( $remaining[$revid] );
}
// 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 );
+ }
}
/**
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";
}
}
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 )
- ),
- );
- }
}