X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiQueryLogEvents.php;h=68902a31c8f325dbd58de3e2cf06c6de3a44e198;hp=3e8bccc74daa5f57093ceea239b7554f110fc6db;hb=a2c8c2969420a0f150c03f76e3a0bf9028fcda43;hpb=70d904b5bd04deb758272fc897d52e83a4141104 diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 3e8bccc74d..68902a31c8 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -1,9 +1,5 @@ @gmail.com" * * This program is free software; you can redistribute it and/or modify @@ -31,6 +27,8 @@ */ class ApiQueryLogEvents extends ApiQueryBase { + private $commentStore; + public function __construct( ApiQuery $query, $moduleName ) { parent::__construct( $query, $moduleName, 'le' ); } @@ -43,6 +41,7 @@ class ApiQueryLogEvents extends ApiQueryBase { public function execute() { $params = $this->extractRequestParams(); $db = $this->getDB(); + $this->commentStore = CommentStore::getStore(); $this->requireMaxOneParameter( $params, 'title', 'prefix', 'namespace' ); $prop = array_flip( $params['prop'] ); @@ -63,11 +62,15 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addWhere( $hideLogs ); } - // Order is significant here - $this->addTables( [ 'logging', 'user', 'page' ] ); + $actorMigration = ActorMigration::newMigration(); + $actorQuery = $actorMigration->getJoin( 'log_user' ); + $this->addTables( 'logging' ); + $this->addTables( $actorQuery['tables'] ); + $this->addTables( [ 'user', 'page' ] ); + $this->addJoinConds( $actorQuery['joins'] ); $this->addJoinConds( [ 'user' => [ 'LEFT JOIN', - 'user_id=log_user' ], + 'user_id=' . $actorQuery['fields']['log_user'] ], 'page' => [ 'LEFT JOIN', [ 'log_namespace=page_namespace', 'log_title=page_title' ] ] ] ); @@ -85,15 +88,21 @@ class ApiQueryLogEvents extends ApiQueryBase { // 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( [ 'log_user', 'log_user_text', 'user_name' ], $this->fld_user ); - $this->addFieldsIf( 'log_user', $this->fld_userid ); + $this->addFieldsIf( $actorQuery['fields'] + [ 'user_name' ], $this->fld_user ); + $this->addFieldsIf( $actorQuery['fields'], $this->fld_userid ); $this->addFieldsIf( [ 'log_namespace', 'log_title' ], $this->fld_title || $this->fld_parsedcomment ); - $this->addFieldsIf( 'log_comment', $this->fld_comment || $this->fld_parsedcomment ); $this->addFieldsIf( 'log_params', $this->fld_details ); + if ( $this->fld_comment || $this->fld_parsedcomment ) { + $commentQuery = $this->commentStore->getJoin( 'log_comment' ); + $this->addTables( $commentQuery['tables'] ); + $this->addFields( $commentQuery['fields'] ); + $this->addJoinConds( $commentQuery['joins'] ); + } + if ( $this->fld_tags ) { $this->addTables( 'tag_summary' ); $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', 'log_id=ts_log_id' ] ] ); @@ -161,12 +170,14 @@ class ApiQueryLogEvents extends ApiQueryBase { $user = $params['user']; if ( !is_null( $user ) ) { - $userid = User::idFromName( $user ); - if ( $userid ) { - $this->addWhereFld( 'log_user', $userid ); - } else { - $this->addWhereFld( 'log_user_text', $user ); - } + // Note the joins in $q are the same as those from ->getJoin() above + // so we only need to add 'conds' here. + // Don't query by user ID here, it might be able to use the + // log_user_text_time or log_user_text_type_time index. + $q = $actorMigration->getWhere( + $db, 'log_user', User::newFromName( $params['user'], false ), false + ); + $this->addWhere( $q['conds'] ); } $title = $params['title']; @@ -327,18 +338,19 @@ class ApiQueryLogEvents extends ApiQueryBase { $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->log_timestamp ); } - if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->log_comment ) ) { + if ( $this->fld_comment || $this->fld_parsedcomment ) { if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) { $vals['commenthidden'] = true; $anyHidden = true; } if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $user ) ) { + $comment = $this->commentStore->getComment( 'log_comment', $row )->text; if ( $this->fld_comment ) { - $vals['comment'] = $row->log_comment; + $vals['comment'] = $comment; } if ( $this->fld_parsedcomment ) { - $vals['parsedcomment'] = Linker::formatComment( $row->log_comment, $title ); + $vals['parsedcomment'] = Linker::formatComment( $comment, $title ); } } }