<?php
/**
- *
- *
- * Created on Sep 7, 2006
- *
* Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
}
$this->tokenFunctions = [
- 'rollback' => [ 'ApiQueryRevisions', 'getRollbackToken' ]
+ 'rollback' => [ self::class, 'getRollbackToken' ]
];
Hooks::run( 'APIQueryRevisionsTokens', [ &$this->tokenFunctions ] );
}
$db = $this->getDB();
- $this->addTables( [ 'revision', 'page' ] );
- $this->addJoinConds(
- [ 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ] ]
- );
if ( $resultPageSet === null ) {
$this->parseParameters( $params );
$this->token = $params['token'];
- $this->addFields( Revision::selectFields() );
+ $opts = [];
if ( $this->token !== null || $pageCount > 0 ) {
- $this->addFields( Revision::selectPageFields() );
+ $opts[] = 'page';
+ }
+ if ( $this->fetchContent ) {
+ $opts[] = 'text';
}
+ if ( $this->fld_user ) {
+ $opts[] = 'user';
+ }
+ $revQuery = Revision::getQueryInfo( $opts );
+ $this->addTables( $revQuery['tables'] );
+ $this->addFields( $revQuery['fields'] );
+ $this->addJoinConds( $revQuery['joins'] );
} else {
$this->limit = $this->getParameter( 'limit' ) ?: 10;
+ // Always join 'page' so orphaned revisions are filtered out
+ $this->addTables( [ 'revision', 'page' ] );
+ $this->addJoinConds(
+ [ 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ] ]
+ );
$this->addFields( [ 'rev_id', 'rev_timestamp', 'rev_page' ] );
}
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
- if ( $this->fetchContent ) {
+ if ( $resultPageSet === null && $this->fetchContent ) {
// For each page we will request, the user must have read rights for that page
$user = $this->getUser();
$status = Status::newGood();
- /** @var $title Title */
+ /** @var Title $title */
foreach ( $pageSet->getGoodTitles() as $title ) {
if ( !$title->userCan( 'read', $user ) ) {
$status->fatal( ApiMessage::create(
if ( !$status->isGood() ) {
$this->dieStatus( $status );
}
-
- $this->addTables( 'text' );
- $this->addJoinConds(
- [ 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ] ]
- );
- $this->addFields( 'old_id' );
- $this->addFields( Revision::selectTextFields() );
- }
-
- // add user name, if needed
- if ( $this->fld_user ) {
- $this->addTables( 'user' );
- $this->addJoinConds( [ 'user' => Revision::userJoinCond() ] );
- $this->addFields( Revision::selectUserFields() );
}
if ( $enumRevMode ) {
$this->addWhereFld( 'rev_page', reset( $ids ) );
if ( $params['user'] !== null ) {
- $user = User::newFromName( $params['user'] );
- if ( $user && $user->getId() > 0 ) {
- $this->addWhereFld( 'rev_user', $user->getId() );
- } else {
- $this->addWhereFld( 'rev_user_text', $params['user'] );
- }
+ $actorQuery = ActorMigration::newMigration()
+ ->getWhere( $db, 'rev_user', User::newFromName( $params['user'], false ) );
+ $this->addTables( $actorQuery['tables'] );
+ $this->addJoinConds( $actorQuery['joins'] );
+ $this->addWhere( $actorQuery['conds'] );
} elseif ( $params['excludeuser'] !== null ) {
- $user = User::newFromName( $params['excludeuser'] );
- if ( $user && $user->getId() > 0 ) {
- $this->addWhere( 'rev_user != ' . $user->getId() );
- } else {
- $this->addWhere( 'rev_user_text != ' .
- $db->addQuotes( $params['excludeuser'] ) );
- }
+ $actorQuery = ActorMigration::newMigration()
+ ->getWhere( $db, 'rev_user', User::newFromName( $params['excludeuser'], false ) );
+ $this->addTables( $actorQuery['tables'] );
+ $this->addJoinConds( $actorQuery['joins'] );
+ $this->addWhere( 'NOT(' . $actorQuery['conds'] . ')' );
}
if ( $params['user'] !== null || $params['excludeuser'] !== null ) {
// Paranoia: avoid brute force searches (T19342)