+ /**
+ * Mark this RecentChange as patrolled
+ *
+ * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
+ * @param $user User object doing the action
+ * @param $auto Boolean: for automatic patrol
+ * @return array of permissions errors, see Title::getUserPermissionsErrors()
+ */
+ public function doMarkPatrolled( User $user, $auto = false ) {
+ global $wgUseRCPatrol, $wgUseNPPatrol;
+ $errors = array();
+ // If recentchanges patrol is disabled, only new pages
+ // can be patrolled
+ if( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute('rc_type') != RC_NEW ) ) {
+ $errors[] = array('rcpatroldisabled');
+ }
+ // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
+ $right = $auto ? 'autopatrol' : 'patrol';
+ $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
+ if( !wfRunHooks('MarkPatrolled', array($this->getAttribute('rc_id'), &$user, false)) ) {
+ $errors[] = array('hookaborted');
+ }
+ // Users without the 'autopatrol' right can't patrol their
+ // own revisions
+ if( $user->getName() == $this->getAttribute('rc_user_text') && !$user->isAllowed('autopatrol') ) {
+ $errors[] = array('markedaspatrollederror-noautopatrol');
+ }
+ if( $errors ) {
+ return $errors;
+ }
+ // If the change was patrolled already, do nothing
+ if( $this->getAttribute('rc_patrolled') ) {
+ return array();
+ }
+ // Actually set the 'patrolled' flag in RC
+ $this->reallyMarkPatrolled();
+ // Log this patrol event
+ PatrolLog::record( $this, $auto );
+ wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) );
+ return array();
+ }
+
+ /**
+ * Mark this RecentChange patrolled, without error checking
+ * @return Integer: number of affected rows
+ */
+ public function reallyMarkPatrolled() {
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->update(
+ 'recentchanges',
+ array(
+ 'rc_patrolled' => 1
+ ),
+ array(
+ 'rc_id' => $this->getAttribute('rc_id')
+ ),
+ __METHOD__
+ );
+ return $dbw->affectedRows();
+ }
+
+ /**
+ * Makes an entry in the database corresponding to an edit
+ *
+ * @param $timestamp
+ * @param $title Title
+ * @param $minor
+ * @param $user User
+ * @param $comment
+ * @param $oldId
+ * @param $lastTimestamp
+ * @param $bot
+ * @param $ip string
+ * @param $oldSize int
+ * @param $newSize int
+ * @param $newId int
+ * @param $patrol int
+ * @return RecentChange
+ */
+ public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
+ $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) {
+ global $wgRequest;
+ if( !$ip ) {
+ $ip = $wgRequest->getIP();
+ if( !$ip ) $ip = '';