*/
class ApiQueryLogEvents extends ApiQueryBase {
- public function __construct( $query, $moduleName ) {
+ public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'le' );
}
public function execute() {
$params = $this->extractRequestParams();
$db = $this->getDB();
+ $this->requireMaxOneParameter( $params, 'title', 'prefix', 'namespace' );
$prop = array_flip( $params['prop'] );
'log_title=page_title' ) ) ) );
$this->addFields( array(
+ 'log_id',
'log_type',
'log_action',
'log_timestamp',
'log_deleted',
) );
- $this->addFieldsIf( array( 'log_id', 'page_id' ), $this->fld_ids );
+ $this->addFieldsIf( 'page_id', $this->fld_ids );
+ // log_page is the page_id saved at log time, whereas page_id is from a
+ // join at query time. This leads to different results in various
+ // scenarios, e.g. deletion, recreation.
+ $this->addFieldsIf( 'log_page', $this->fld_ids );
$this->addFieldsIf( array( 'log_user', 'log_user_text', 'user_name' ), $this->fld_user );
$this->addFieldsIf( 'log_user', $this->fld_userid );
$this->addFieldsIf(
$params['start'],
$params['end']
);
+ // Include in ORDER BY for uniqueness
+ $this->addWhereRange( 'log_id', $params['dir'], null, null );
+
+ if ( !is_null( $params['continue'] ) ) {
+ $cont = explode( '|', $params['continue'] );
+ $this->dieContinueUsageIf( count( $cont ) != 2 );
+ $op = ( $params['dir'] === 'newer' ? '>' : '<' );
+ $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
+ $continueId = (int)$cont[1];
+ $this->dieContinueUsageIf( $continueId != $cont[1] );
+ $this->addWhere( "log_timestamp $op $continueTimestamp OR " .
+ "(log_timestamp = $continueTimestamp AND " .
+ "log_id $op= $continueId)"
+ );
+ }
$limit = $params['limit'];
$this->addOption( 'LIMIT', $limit + 1 );
$this->addWhereFld( 'log_title', $titleObj->getDBkey() );
}
+ if ( $params['namespace'] !== null ) {
+ $this->addWhereFld( 'log_namespace', $params['namespace'] );
+ }
+
$prefix = $params['prefix'];
if ( !is_null( $prefix ) ) {
}
// Paranoia: avoid brute force searches (bug 17342)
- if ( !is_null( $title ) || !is_null( $user ) ) {
+ if ( $params['namespace'] !== null || !is_null( $title ) || !is_null( $user ) ) {
if ( !$this->getUser()->isAllowed( 'deletedhistory' ) ) {
$titleBits = LogPage::DELETED_ACTION;
$userBits = LogPage::DELETED_USER;
$titleBits = 0;
$userBits = 0;
}
- if ( !is_null( $title ) && $titleBits ) {
+ if ( ( $params['namespace'] !== null || !is_null( $title ) ) && $titleBits ) {
$this->addWhere( $db->bitAnd( 'log_deleted', $titleBits ) . " != $titleBits" );
}
if ( !is_null( $user ) && $userBits ) {
if ( ++$count > $limit ) {
// We've reached the one extra which shows that there are
// additional pages to be had. Stop here...
- $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->log_timestamp ) );
+ $this->setContinueEnumParameter( 'continue', "$row->log_timestamp|$row->log_id" );
break;
}
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
if ( !$fit ) {
- $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->log_timestamp ) );
+ $this->setContinueEnumParameter( 'continue', "$row->log_timestamp|$row->log_id" );
break;
}
}
}
/**
- * @param $result ApiResult
- * @param $vals array
- * @param $params string
- * @param $type string
- * @param $action string
- * @param $ts
- * @param $legacy bool
+ * @param ApiResult $result
+ * @param array $vals
+ * @param string $params
+ * @param string $type
+ * @param string $action
+ * @param string $ts
+ * @param bool $legacy
* @return array
*/
public static function addLogParams( $result, &$vals, $params, $type,
}
if ( $this->fld_ids ) {
$vals['pageid'] = intval( $row->page_id );
+ $vals['logpage'] = intval( $row->log_page );
}
if ( $this->fld_details && $row->log_params !== '' ) {
self::addLogParams(
),
'user' => null,
'title' => null,
+ 'namespace' => array(
+ ApiBase::PARAM_TYPE => 'namespace'
+ ),
'prefix' => null,
'tag' => null,
'limit' => array(
ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
- )
+ ),
+ 'continue' => null,
);
}
'dir' => $this->getDirectionDescription( $p ),
'user' => 'Filter entries to those made by the given user',
'title' => 'Filter entries to those related to a page',
+ 'namespace' => 'Filter entries to those in the given namespace',
'prefix' => 'Filter entries that start with this prefix. Disabled in Miser Mode',
'limit' => 'How many total event entries to return',
'tag' => 'Only list event entries tagged with this tag',
+ 'continue' => 'When more results are available, use this to continue',
);
}