From 0160b410bd514681b1637ccab2b7c79158fbfb29 Mon Sep 17 00:00:00 2001 From: cenarium Date: Sat, 7 Nov 2015 20:24:33 +0100 Subject: [PATCH] Option to associate a rev id to a RC log entry, allowing unpatrolled status This provides a mechanism to associate a revision id to an action. For example in core, it makes sense for moves and uploads, which both generate null revisions (also protections, but it isn't interesting if one has patrolling in mind). Crucially, in that case an unpatrolled status is allowed for the RC item. So if the performer of the action is not autopatrolled, it will be displayed as unpatrolled, and if the performer is autopatrolled, it will record an autopatrol action. When one associates a rev id to a type of action, one should also implement a mechanism to patrol said action, since getting the diff for the associated revision is not user friendly and works only if RC patrol is enabled. This is done for uploads in If71af58719a4461f12d125455b7bef07164525ca (with a new file patrol) and for moves in Ie0fa417feaf930c096b69521fc54d57aecd6cd51 (within RC patrol). Extensions might possess other such actions that could benefit from patrolling. Bug: T122089 Change-Id: I694424eca32b69e277f89d4c15183870983d0993 --- includes/changes/OldChangesList.php | 7 ++++++- includes/changes/RecentChange.php | 12 ++++++++--- includes/logging/LogEntry.php | 31 ++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/includes/changes/OldChangesList.php b/includes/changes/OldChangesList.php index 31b355d4cf..a2ea37c49f 100644 --- a/includes/changes/OldChangesList.php +++ b/includes/changes/OldChangesList.php @@ -74,10 +74,16 @@ class OldChangesList extends ChangesList { */ private function formatChangeLine( RecentChange $rc, array &$classes, $watched ) { $html = ''; + $unpatrolled = $this->showAsUnpatrolled( $rc ); if ( $rc->mAttribs['rc_log_type'] ) { $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] ); $this->insertLog( $html, $logtitle, $rc->mAttribs['rc_log_type'] ); + $flags = $this->recentChangesFlags( array( 'unpatrolled' =>$unpatrolled, + 'bot' => $rc->mAttribs['rc_bot'] ), '' ); + if ( $flags !== '' ) { + $html .= ' ' . $flags; + } // Log entries (old format) or log targets, and special pages } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { list( $name, $htmlubpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] ); @@ -86,7 +92,6 @@ class OldChangesList extends ChangesList { } // Regular entries } else { - $unpatrolled = $this->showAsUnpatrolled( $rc ); $this->insertDiffHist( $html, $rc, $unpatrolled ); # M, N, b and ! (minor, new, bot and unpatrolled) $html .= $this->recentChangesFlags( diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 7c6fbb9133..b0b88d3e64 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -700,10 +700,12 @@ class RecentChange { * @param string $params * @param int $newId * @param string $actionCommentIRC + * @param int $revId Id of associated revision, if any * @return RecentChange */ public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, - $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) { + $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '', + $revId = 0 ) { global $wgRequest; # # Get pageStatus for email notification @@ -727,6 +729,10 @@ class RecentChange { break; } + // Allow unpatrolled status when an associated rev id is passed + // May be used in core by moves and uploads + $markPatrolled = ( $revId > 0 ) ? $user->isAllowed( 'autopatrol' ) : true; + $rc = new RecentChange; $rc->mTitle = $target; $rc->mPerformer = $user; @@ -741,11 +747,11 @@ class RecentChange { 'rc_user' => $user->getId(), 'rc_user_text' => $user->getName(), 'rc_comment' => $logComment, - 'rc_this_oldid' => 0, + 'rc_this_oldid' => $revId, 'rc_last_oldid' => 0, 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0, 'rc_ip' => self::checkIPAddress( $ip ), - 'rc_patrolled' => 1, + 'rc_patrolled' => $markPatrolled ? 1 : 0, 'rc_new' => 0, # obsolete 'rc_old_len' => null, 'rc_new_len' => null, diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 8427adbb35..993f3de50e 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -386,6 +386,9 @@ class ManualLogEntry extends LogEntryBase { /** @var string Comment for the log entry */ protected $comment = ''; + /** @var int A rev id associated to the log entry */ + protected $revId = 0; + /** @var int Deletion state of the log entry */ protected $deleted; @@ -484,6 +487,17 @@ class ManualLogEntry extends LogEntryBase { $this->comment = $comment; } + /** + * Set an associated revision id. + * + * @since 1.27 + * + * @param int $revId + */ + public function setAssociatedRevId( $revId ) { + $this->revId = $revId; + } + /** * Set the 'legacy' flag * @@ -608,7 +622,8 @@ class ManualLogEntry extends LogEntryBase { $this->getComment(), LogEntryBase::makeParamBlob( $this->getParameters() ), $newId, - $formatter->getIRCActionComment() // Used for IRC feeds + $formatter->getIRCActionComment(), // Used for IRC feeds + $this->getAssociatedRevId() // Used for e.g. moves and uploads ); } @@ -632,6 +647,12 @@ class ManualLogEntry extends LogEntryBase { 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() ); + } } // LogEntry-> @@ -672,6 +693,14 @@ class ManualLogEntry extends LogEntryBase { return $this->comment; } + /** + * @since 1.27 + * @return int + */ + public function getAssociatedRevId() { + return $this->revId; + } + /** * @since 1.25 * @return bool -- 2.20.1