X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flogging%2FLogEntry.php;h=21864eefbfc4cb08b8abaab995c243614d46cc1d;hb=3df3b575c6617df64ec98533cc7141bd2314e274;hp=e76aa29476d2f3644d9b20f7d968b535e01a468b;hpb=601519ee36462faabacf4547c9aefaf7e8726476;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index e76aa29476..8b51932be7 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -28,6 +28,8 @@ * @since 1.19 */ +use Wikimedia\Rdbms\IDatabase; + /** * Interface for log entries. Every log entry has these methods. * @@ -168,19 +170,21 @@ class DatabaseLogEntry extends LogEntryBase { * @return array */ public static function getSelectQueryData() { - $tables = [ 'logging', 'user' ]; + $commentQuery = CommentStore::newKey( 'log_comment' )->getJoin(); + + $tables = [ 'logging', 'user' ] + $commentQuery['tables']; $fields = [ 'log_id', 'log_type', 'log_action', 'log_timestamp', 'log_user', 'log_user_text', 'log_namespace', 'log_title', // unused log_page - 'log_comment', 'log_params', 'log_deleted', + 'log_params', 'log_deleted', 'user_id', 'user_name', 'user_editcount', - ]; + ] + $commentQuery['fields']; $joins = [ // IPs don't have an entry in user table 'user' => [ 'LEFT JOIN', 'log_user=user_id' ], - ]; + ] + $commentQuery['joins']; return [ 'tables' => $tables, @@ -320,7 +324,7 @@ class DatabaseLogEntry extends LogEntryBase { } public function getComment() { - return $this->row->log_comment; + return CommentStore::newKey( 'log_comment' )->getComment( $this->row )->text; } public function getDeleted() { @@ -378,7 +382,9 @@ class RCDatabaseLogEntry extends DatabaseLogEntry { } public function getComment() { - return $this->row->rc_comment; + return CommentStore::newKey( 'rc_comment' ) + // Legacy because the row probably used RecentChange::selectFields() + ->getCommentLegacy( wfGetDB( DB_REPLICA ), $this->row )->text; } public function getDeleted() { @@ -419,18 +425,22 @@ class ManualLogEntry extends LogEntryBase { /** @var int A rev id associated to the log entry */ protected $revId = 0; + /** @var array Change tags add to the log entry */ + protected $tags = null; + /** @var int Deletion state of the log entry */ protected $deleted; /** @var int ID of the log entry */ protected $id; + /** @var bool Can this log entry be patrolled? */ + protected $isPatrollable = false; + /** @var bool Whether this is a legacy log entry */ protected $legacy = false; /** - * Constructor. - * * @since 1.19 * @param string $type * @param string $subtype @@ -529,6 +539,32 @@ class ManualLogEntry extends LogEntryBase { $this->revId = $revId; } + /** + * Set change tags for the log entry. + * + * @since 1.27 + * @param string|string[] $tags + */ + public function setTags( $tags ) { + if ( is_string( $tags ) ) { + $tags = [ $tags ]; + } + $this->tags = $tags; + } + + /** + * Set whether this log entry should be made patrollable + * This shouldn't depend on config, only on whether there is full support + * in the software for patrolling this log entry. + * False by default + * + * @since 1.27 + * @param bool $patrollable + */ + public function setIsPatrollable( $patrollable ) { + $this->isPatrollable = (bool)$patrollable; + } + /** * Set the 'legacy' flag * @@ -557,10 +593,7 @@ class ManualLogEntry extends LogEntryBase { * @throws MWException */ public function insert( IDatabase $dbw = null ) { - global $wgContLang; - $dbw = $dbw ?: wfGetDB( DB_MASTER ); - $id = $dbw->nextSequenceValue( 'logging_log_id_seq' ); if ( $this->timestamp === null ) { $this->timestamp = wfTimestampNow(); @@ -569,9 +602,6 @@ class ManualLogEntry extends LogEntryBase { // Trim spaces on user supplied text $comment = trim( $this->getComment() ); - // Truncate for whole multibyte characters. - $comment = $wgContLang->truncate( $comment, 255 ); - $params = $this->getParameters(); $relations = $this->relations; @@ -583,7 +613,6 @@ class ManualLogEntry extends LogEntryBase { } $data = [ - 'log_id' => $id, 'log_type' => $this->getType(), 'log_action' => $this->getSubtype(), 'log_timestamp' => $dbw->timestamp( $this->getTimestamp() ), @@ -592,15 +621,15 @@ class ManualLogEntry extends LogEntryBase { 'log_namespace' => $this->getTarget()->getNamespace(), 'log_title' => $this->getTarget()->getDBkey(), 'log_page' => $this->getTarget()->getArticleID(), - 'log_comment' => $comment, 'log_params' => LogEntryBase::makeParamBlob( $params ), ]; if ( isset( $this->deleted ) ) { $data['log_deleted'] = $this->deleted; } + $data += CommentStore::newKey( 'log_comment' )->insert( $dbw, $comment ); $dbw->insert( 'logging', $data, __METHOD__ ); - $this->id = !is_null( $id ) ? $id : $dbw->insertId(); + $this->id = $dbw->insertId(); $rows = []; foreach ( $relations as $tag => $values ) { @@ -663,7 +692,8 @@ class ManualLogEntry extends LogEntryBase { LogEntryBase::makeParamBlob( $this->getParameters() ), $newId, $formatter->getIRCActionComment(), // Used for IRC feeds - $this->getAssociatedRevId() // Used for e.g. moves and uploads + $this->getAssociatedRevId(), // Used for e.g. moves and uploads + $this->getIsPatrollable() ); } @@ -672,31 +702,39 @@ class ManualLogEntry extends LogEntryBase { * * @param int $newId Id of the log entry. * @param string $to One of: rcandudp (default), rc, udp - * @return RecentChange|null */ public function publish( $newId, $to = 'rcandudp' ) { - $log = new LogPage( $this->getType() ); - if ( $log->isRestricted() ) { - return null; - } - - $rc = $this->getRecentChange( $newId ); - - if ( $to === 'rc' || $to === 'rcandudp' ) { - $rc->save( 'pleasedontudp' ); - } - - if ( $to === 'udp' || $to === 'rcandudp' ) { - $rc->notifyRCFeeds(); - } - - // Log the autopatrol if an associated rev id was passed - if ( $this->getAssociatedRevId() > 0 && - $rc->getAttribute( 'rc_patrolled' ) === 1 ) { - PatrolLog::record( $rc, true, $this->getPerformer() ); - } - - return $rc; + DeferredUpdates::addCallableUpdate( + function () use ( $newId, $to ) { + $log = new LogPage( $this->getType() ); + if ( !$log->isRestricted() ) { + $rc = $this->getRecentChange( $newId ); + + if ( $to === 'rc' || $to === 'rcandudp' ) { + // save RC, passing tags so they are applied there + $tags = $this->getTags(); + if ( is_null( $tags ) ) { + $tags = []; + } + $rc->addTags( $tags ); + $rc->save( 'pleasedontudp' ); + } + + if ( $to === 'udp' || $to === 'rcandudp' ) { + $rc->notifyRCFeeds(); + } + + // Log the autopatrol if the log entry is patrollable + if ( $this->getIsPatrollable() && + $rc->getAttribute( 'rc_patrolled' ) === 1 + ) { + PatrolLog::record( $rc, true, $this->getPerformer() ); + } + } + }, + DeferredUpdates::POSTSEND, + wfGetDB( DB_MASTER ) + ); } public function getType() { @@ -743,6 +781,24 @@ class ManualLogEntry extends LogEntryBase { return $this->revId; } + /** + * @since 1.27 + * @return array + */ + public function getTags() { + return $this->tags; + } + + /** + * Whether this log entry is patrollable + * + * @since 1.27 + * @return bool + */ + public function getIsPatrollable() { + return $this->isPatrollable; + } + /** * @since 1.25 * @return bool