2015-09-27 19:43:05 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Created on Sep 27, 2015
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2015 Brad Jorsch "bjorsch@wikimedia.org"
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query module to enumerate all revisions.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup API
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
class ApiQueryAllRevisions extends ApiQueryRevisionsBase {
|
|
|
|
|
|
|
|
|
|
public function __construct( ApiQuery $query, $moduleName ) {
|
|
|
|
|
parent::__construct( $query, $moduleName, 'arv' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ApiPageSet $resultPageSet
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function run( ApiPageSet $resultPageSet = null ) {
|
|
|
|
|
$db = $this->getDB();
|
|
|
|
|
$params = $this->extractRequestParams( false );
|
|
|
|
|
|
|
|
|
|
$result = $this->getResult();
|
|
|
|
|
|
|
|
|
|
$this->requireMaxOneParameter( $params, 'user', 'excludeuser' );
|
|
|
|
|
|
|
|
|
|
// Namespace check is likely to be desired, but can't be done
|
|
|
|
|
// efficiently in SQL.
|
|
|
|
|
$miser_ns = null;
|
|
|
|
|
$needPageTable = false;
|
|
|
|
|
if ( $params['namespace'] !== null ) {
|
|
|
|
|
$params['namespace'] = array_unique( $params['namespace'] );
|
|
|
|
|
sort( $params['namespace'] );
|
|
|
|
|
if ( $params['namespace'] != MWNamespace::getValidNamespaces() ) {
|
|
|
|
|
$needPageTable = true;
|
|
|
|
|
if ( $this->getConfig()->get( 'MiserMode' ) ) {
|
|
|
|
|
$miser_ns = $params['namespace'];
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addWhere( [ 'page_namespace' => $params['namespace'] ] );
|
2015-09-27 19:43:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addTables( 'revision' );
|
|
|
|
|
if ( $resultPageSet === null ) {
|
|
|
|
|
$this->parseParameters( $params );
|
|
|
|
|
$this->addTables( 'page' );
|
|
|
|
|
$this->addJoinConds(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page' => [ 'INNER JOIN', [ 'rev_page = page_id' ] ] ]
|
2015-09-27 19:43:05 +00:00
|
|
|
);
|
|
|
|
|
$this->addFields( Revision::selectFields() );
|
|
|
|
|
$this->addFields( Revision::selectPageFields() );
|
|
|
|
|
|
|
|
|
|
// Review this depeneding on the outcome of T113901
|
|
|
|
|
$this->addOption( 'STRAIGHT_JOIN' );
|
|
|
|
|
} else {
|
|
|
|
|
$this->limit = $this->getParameter( 'limit' ) ?: 10;
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addFields( [ 'rev_timestamp', 'rev_id' ] );
|
2015-09-27 19:43:05 +00:00
|
|
|
if ( $params['generatetitles'] ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addFields( [ 'rev_page' ] );
|
2015-09-27 19:43:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $needPageTable ) {
|
|
|
|
|
$this->addTables( 'page' );
|
|
|
|
|
$this->addJoinConds(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page' => [ 'INNER JOIN', [ 'rev_page = page_id' ] ] ]
|
2015-09-27 19:43:05 +00:00
|
|
|
);
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addFieldsIf( [ 'page_namespace' ], (bool)$miser_ns );
|
2015-09-27 19:43:05 +00:00
|
|
|
|
|
|
|
|
// Review this depeneding on the outcome of T113901
|
|
|
|
|
$this->addOption( 'STRAIGHT_JOIN' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 14:23:37 +00:00
|
|
|
$dir = $params['dir'];
|
|
|
|
|
$this->addTimestampWhereRange( 'rev_timestamp', $dir, $params['start'], $params['end'] );
|
|
|
|
|
|
2015-09-27 19:43:05 +00:00
|
|
|
if ( $this->fld_tags ) {
|
|
|
|
|
$this->addTables( 'tag_summary' );
|
|
|
|
|
$this->addJoinConds(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'tag_summary' => [ 'LEFT JOIN', [ 'rev_id=ts_rev_id' ] ] ]
|
2015-09-27 19:43:05 +00:00
|
|
|
);
|
|
|
|
|
$this->addFields( 'ts_tags' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->fetchContent ) {
|
|
|
|
|
$this->addTables( 'text' );
|
|
|
|
|
$this->addJoinConds(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ] ]
|
2015-09-27 19:43:05 +00:00
|
|
|
);
|
|
|
|
|
$this->addFields( 'old_id' );
|
|
|
|
|
$this->addFields( Revision::selectTextFields() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $params['user'] !== null ) {
|
|
|
|
|
$id = User::idFromName( $params['user'] );
|
|
|
|
|
if ( $id ) {
|
|
|
|
|
$this->addWhereFld( 'rev_user', $id );
|
|
|
|
|
} else {
|
|
|
|
|
$this->addWhereFld( 'rev_user_text', $params['user'] );
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $params['excludeuser'] !== null ) {
|
|
|
|
|
$id = User::idFromName( $params['excludeuser'] );
|
|
|
|
|
if ( $id ) {
|
|
|
|
|
$this->addWhere( 'rev_user != ' . $id );
|
|
|
|
|
} else {
|
|
|
|
|
$this->addWhere( 'rev_user_text != ' . $db->addQuotes( $params['excludeuser'] ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $params['user'] !== null || $params['excludeuser'] !== null ) {
|
|
|
|
|
// Paranoia: avoid brute force searches (bug 17342)
|
|
|
|
|
if ( !$this->getUser()->isAllowed( 'deletedhistory' ) ) {
|
|
|
|
|
$bitmask = Revision::DELETED_USER;
|
|
|
|
|
} elseif ( !$this->getUser()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
|
|
|
|
|
$bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
|
|
|
|
|
} else {
|
|
|
|
|
$bitmask = 0;
|
|
|
|
|
}
|
|
|
|
|
if ( $bitmask ) {
|
|
|
|
|
$this->addWhere( $db->bitAnd( 'rev_deleted', $bitmask ) . " != $bitmask" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $params['continue'] !== null ) {
|
|
|
|
|
$op = ( $dir == 'newer' ? '>' : '<' );
|
|
|
|
|
$cont = explode( '|', $params['continue'] );
|
|
|
|
|
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
|
|
|
|
$ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
|
|
|
|
$rev_id = (int)$cont[1];
|
|
|
|
|
$this->dieContinueUsageIf( strval( $rev_id ) !== $cont[1] );
|
|
|
|
|
$this->addWhere( "rev_timestamp $op $ts OR " .
|
|
|
|
|
"(rev_timestamp = $ts AND " .
|
|
|
|
|
"rev_id $op= $rev_id)" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addOption( 'LIMIT', $this->limit + 1 );
|
|
|
|
|
|
|
|
|
|
$sort = ( $dir == 'newer' ? '' : ' DESC' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$orderby = [];
|
2015-09-27 19:43:05 +00:00
|
|
|
// Targeting index rev_timestamp, user_timestamp, or usertext_timestamp
|
|
|
|
|
// But 'user' is always constant for the latter two, so it doesn't matter here.
|
|
|
|
|
$orderby[] = "rev_timestamp $sort";
|
|
|
|
|
$orderby[] = "rev_id $sort";
|
|
|
|
|
$this->addOption( 'ORDER BY', $orderby );
|
|
|
|
|
|
|
|
|
|
$res = $this->select( __METHOD__ );
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageMap = []; // Maps rev_page to array index
|
2015-09-27 19:43:05 +00:00
|
|
|
$count = 0;
|
|
|
|
|
$nextIndex = 0;
|
2016-02-17 09:09:32 +00:00
|
|
|
$generated = [];
|
2015-09-27 19:43:05 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
if ( ++$count > $this->limit ) {
|
|
|
|
|
// We've had enough
|
|
|
|
|
$this->setContinueEnumParameter( 'continue', "$row->rev_timestamp|$row->rev_id" );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Miser mode namespace check
|
|
|
|
|
if ( $miser_ns !== null && !in_array( $row->page_namespace, $miser_ns ) ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $resultPageSet !== null ) {
|
|
|
|
|
if ( $params['generatetitles'] ) {
|
|
|
|
|
$generated[$row->rev_page] = $row->rev_page;
|
|
|
|
|
} else {
|
|
|
|
|
$generated[] = $row->rev_id;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$revision = Revision::newFromRow( $row );
|
|
|
|
|
$rev = $this->extractRevisionInfo( $revision, $row );
|
|
|
|
|
|
|
|
|
|
if ( !isset( $pageMap[$row->rev_page] ) ) {
|
|
|
|
|
$index = $nextIndex++;
|
|
|
|
|
$pageMap[$row->rev_page] = $index;
|
|
|
|
|
$title = $revision->getTitle();
|
2016-02-17 09:09:32 +00:00
|
|
|
$a = [
|
2015-09-27 19:43:05 +00:00
|
|
|
'pageid' => $title->getArticleID(),
|
2016-02-17 09:09:32 +00:00
|
|
|
'revisions' => [ $rev ],
|
|
|
|
|
];
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiResult::setIndexedTagName( $a['revisions'], 'rev' );
|
|
|
|
|
ApiQueryBase::addTitleInfo( $a, $title );
|
2016-02-17 09:09:32 +00:00
|
|
|
$fit = $result->addValue( [ 'query', $this->getModuleName() ], $index, $a );
|
2015-09-27 19:43:05 +00:00
|
|
|
} else {
|
|
|
|
|
$index = $pageMap[$row->rev_page];
|
|
|
|
|
$fit = $result->addValue(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'query', $this->getModuleName(), $index, 'revisions' ],
|
2015-09-27 19:43:05 +00:00
|
|
|
null, $rev );
|
|
|
|
|
}
|
|
|
|
|
if ( !$fit ) {
|
|
|
|
|
$this->setContinueEnumParameter( 'continue', "$row->rev_timestamp|$row->rev_id" );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $resultPageSet !== null ) {
|
|
|
|
|
if ( $params['generatetitles'] ) {
|
|
|
|
|
$resultPageSet->populateFromPageIDs( $generated );
|
|
|
|
|
} else {
|
|
|
|
|
$resultPageSet->populateFromRevisionIDs( $generated );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'page' );
|
2015-09-27 19:43:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret = parent::getAllowedParams() + [
|
|
|
|
|
'user' => [
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'user',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'namespace' => [
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => 'namespace',
|
|
|
|
|
ApiBase::PARAM_DFLT => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'start' => [
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'timestamp',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'end' => [
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'timestamp',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'dir' => [
|
|
|
|
|
ApiBase::PARAM_TYPE => [
|
2015-09-27 19:43:05 +00:00
|
|
|
'newer',
|
|
|
|
|
'older'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'older',
|
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'excludeuser' => [
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'user',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'continue' => [
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'generatetitles' => [
|
2015-09-27 19:43:05 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2015-09-27 19:43:05 +00:00
|
|
|
|
|
|
|
|
if ( $this->getConfig()->get( 'MiserMode' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = [
|
2015-09-27 19:43:05 +00:00
|
|
|
'api-help-param-limited-in-miser-mode',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-09-27 19:43:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-09-27 19:43:05 +00:00
|
|
|
'action=query&list=allrevisions&arvuser=Example&arvlimit=50'
|
|
|
|
|
=> 'apihelp-query+allrevisions-example-user',
|
|
|
|
|
'action=query&list=allrevisions&arvdir=newer&arvlimit=50'
|
|
|
|
|
=> 'apihelp-query+allrevisions-example-ns-main',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-09-27 19:43:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getHelpUrls() {
|
|
|
|
|
return 'https://www.mediawiki.org/wiki/API:Allrevisions';
|
|
|
|
|
}
|
|
|
|
|
}
|