From 22c8d2d293757099b2329fe5d12f7ae0f28c555f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 19 Sep 2008 00:11:41 +0000 Subject: [PATCH] * Clean up patrol code to not possibly log twice (depended on slave lag) * Make notifyEdit() return the whole RC object * Spacing tweaks * Wrap patrolling in a transaction --- includes/Article.php | 14 ++++++++------ includes/RecentChange.php | 30 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 3a58dc4acd..c0ff600f6e 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1512,14 +1512,13 @@ class Article { # Update recentchanges if( !( $flags & EDIT_SUPPRESS_RC ) ) { - $rcid = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary, + $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary, $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize, $revisionId ); # Mark as patrolled if the user can do so if( $GLOBALS['wgUseRCPatrol'] && $user->isAllowed( 'autopatrol' ) ) { - RecentChange::markPatrolled( $rcid ); - PatrolLog::record( $rcid, true ); + RecentChange::markPatrolled( $rc, true ); } } $user->incEditCount(); @@ -1580,12 +1579,11 @@ class Article { wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) ); if( !( $flags & EDIT_SUPPRESS_RC ) ) { - $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot, + $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot, '', strlen( $text ), $revisionId ); # Mark as patrolled if the user can if( ($GLOBALS['wgUseRCPatrol'] || $GLOBALS['wgUseNPPatrol']) && $user->isAllowed( 'autopatrol' ) ) { - RecentChange::markPatrolled( $rcid ); - PatrolLog::record( $rcid, true ); + RecentChange::markPatrolled( $rc, true ); } } $user->incEditCount(); @@ -1660,7 +1658,11 @@ class Article { $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges'; $return = Title::makeTitle( NS_SPECIAL, $returnto ); + $dbw = wfGetDB( DB_MASTER ); + $dbw->begin(); $errors = $rc->doMarkPatrolled(); + $dbw->commit(); + if ( in_array(array('rcpatroldisabled'), $errors) ) { $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' ); return; diff --git a/includes/RecentChange.php b/includes/RecentChange.php index c22c9ea5a5..c0b02dcff6 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -249,24 +249,26 @@ class RecentChange * Mark a given change as patrolled * * @param mixed $change RecentChange or corresponding rc_id + * @param bool $auto for automatic patrol * @return See doMarkPatrolled(), or null if $change is not an existing rc_id */ - public static function markPatrolled( $change ) { + public static function markPatrolled( $change, $auto = false ) { $change = $change instanceof RecentChange ? $change : RecentChange::newFromId($change); if(!$change instanceof RecentChange) return null; - return $change->doMarkPatrolled(); + return $change->doMarkPatrolled( $auto ); } /** * Mark this RecentChange as patrolled * * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors + * @param bool $auto for automatic patrol * @return array of permissions errors, see Title::getUserPermissionsErrors() */ - public function doMarkPatrolled() { + public function doMarkPatrolled( $auto = false ) { global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol; $errors = array(); // If recentchanges patrol is disabled, only new pages @@ -274,23 +276,22 @@ class RecentChange if(!$wgUseRCPatrol && (!$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW)) $errors[] = array('rcpatroldisabled'); $errors = array_merge($errors, $this->getTitle()->getUserPermissionsErrors('patrol', $wgUser)); - if(!wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$wgUser, false))) + if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$wgUser, false)) ) $errors[] = array('hookaborted'); // Users without the 'autopatrol' right can't patrol their // own revisions - if($wgUser->getName() == $this->getAttribute('rc_user_text') && - !$wgUser->isAllowed('autopatrol')) + if( $wgUser->getName() == $this->getAttribute('rc_user_text') && !$wgUser->isAllowed('autopatrol') ) $errors[] = array('markedaspatrollederror-noautopatrol'); - if(!empty($errors)) + if( !empty($errors) ) return $errors; - // If the change was patrolled already, do nothing - if($this->getAttribute('rc_patrolled')) + if( $this->getAttribute('rc_patrolled') ) return array(); + // Actually set the 'patrolled' flag in RC $this->reallyMarkPatrolled(); - PatrolLog::record($this); - wfRunHooks('MarkPatrolledComplete', - array($this->getAttribute('rc_id'), &$wgUser, false)); + // Log this patrol event + PatrolLog::record( $this, $auto ); + wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$wgUser, false) ); return array(); } @@ -315,8 +316,7 @@ class RecentChange # Makes an entry in the database corresponding to an edit public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, - $oldId, $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, - $newId = 0) + $oldId, $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0) { if ( !$ip ) { $ip = wfGetIP(); @@ -361,7 +361,7 @@ class RecentChange 'newSize' => $newSize, ); $rc->save(); - return( $rc->mAttribs['rc_id'] ); + return $rc; } /** -- 2.20.1