<?php
-/**
- *
- */
/**
* Utility class for creating new RC entries
return $rc;
}
- public static function newFromCurRow( $row, $rc_this_oldid = 0 )
+ public static function newFromCurRow( $row )
{
$rc = new RecentChange;
- $rc->loadFromCurRow( $row, $rc_this_oldid );
+ $rc->loadFromCurRow( $row );
$rc->notificationtimestamp = false;
$rc->numberofWatchingusers = false;
return $rc;
# Writes the data in this object to the database
function save()
{
- global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix;
+ global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress,
+ $wgRC2UDPPort, $wgRC2UDPPrefix, $wgRC2UDPOmitBots;
$fname = 'RecentChange::save';
$dbw = wfGetDB( DB_MASTER );
}
# Notify external application via UDP
- if ( $wgRC2UDPAddress ) {
+ if ( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
$conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
if ( $conn ) {
$line = $wgRC2UDPPrefix . $this->getIRCLine();
}
# E-mail notifications
- global $wgUseEnotif;
- if( $wgUseEnotif ) {
- # this would be better as an extension hook
- global $wgUser;
- $enotif = new EmailNotification;
+ global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
+ if( $wgUseEnotif || $wgShowUpdatedMarker ) {
+ // Users
+ if( $this->mAttribs['rc_user'] ) {
+ $editor = ($wgUser->getId() == $this->mAttribs['rc_user']) ?
+ $wgUser : User::newFromID( $this->mAttribs['rc_user'] );
+ // Anons
+ } else {
+ $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ?
+ $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false );
+ }
+ # FIXME: this would be better as an extension hook
+ $enotif = new EmailNotification();
$title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
- $enotif->notifyOnPageChange( $wgUser, $title,
+ $enotif->notifyOnPageChange( $editor, $title,
$this->mAttribs['rc_timestamp'],
$this->mAttribs['rc_comment'],
$this->mAttribs['rc_minor'],
* Mark a given change as patrolled
*
* @param mixed $change RecentChange or corresponding rc_id
- * @returns integer number of affected rows
+ * @return See doMarkPatrolled(), or null if $change is not an existing rc_id
*/
public static function markPatrolled( $change ) {
- $rcid = $change instanceof RecentChange
- ? $change->mAttribs['rc_id']
- : $change;
+ $change = $change instanceof RecentChange
+ ? $change
+ : RecentChange::newFromId($change);
+ if(!$change instanceof RecentChange)
+ return null;
+ return $change->doMarkPatrolled();
+ }
+
+ /**
+ * Mark this RecentChange as patrolled
+ *
+ * NOTE: Can also return 'rcpatroldisabled', 'hookaborted' and 'markedaspatrollederror-noautopatrol' as errors
+ * @return array of permissions errors, see Title::getUserPermissionsErrors()
+ */
+ public function doMarkPatrolled() {
+ global $wgUser, $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');
+ $errors = array_merge($errors, $this->getTitle()->getUserPermissionsErrors('patrol', $wgUser));
+ 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'))
+ $errors[] = array('markedaspatrollederror-noautopatrol');
+ if(!empty($errors))
+ return $errors;
+
+ // If the change was patrolled already, do nothing
+ if($this->getAttribute('rc_patrolled'))
+ return array();
+ $this->reallyMarkPatrolled();
+ PatrolLog::record($this);
+ wfRunHooks('MarkPatrolledComplete',
+ array($this->getAttribute('rc_id'), &$wgUser, false));
+ return array();
+ }
+
+ /**
+ * Mark this RecentChange patrolled, without error checking
+ * @return int Number of affected rows
+ */
+ public function reallyMarkPatrolled() {
$dbw = wfGetDB( DB_MASTER );
$dbw->update(
'recentchanges',
'rc_patrolled' => 1
),
array(
- 'rc_id' => $rcid
+ 'rc_id' => $this->getAttribute('rc_id')
),
__METHOD__
);
'rc_type' => RC_EDIT,
'rc_minor' => $minor ? 1 : 0,
'rc_cur_id' => $title->getArticleID(),
- 'rc_user' => $user->getID(),
+ 'rc_user' => $user->getId(),
'rc_user_text' => $user->getName(),
'rc_comment' => $comment,
'rc_this_oldid' => $newId,
'rc_type' => RC_NEW,
'rc_minor' => $minor ? 1 : 0,
'rc_cur_id' => $title->getArticleID(),
- 'rc_user' => $user->getID(),
+ 'rc_user' => $user->getId(),
'rc_user_text' => $user->getName(),
'rc_comment' => $comment,
'rc_this_oldid' => $newId,
'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT : RC_MOVE,
'rc_minor' => 0,
'rc_cur_id' => $oldTitle->getArticleID(),
- 'rc_user' => $user->getID(),
+ 'rc_user' => $user->getId(),
'rc_user_text' => $user->getName(),
'rc_comment' => $comment,
'rc_this_oldid' => 0,
RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
}
- # A log entry is different to an edit in that previous revisions are not kept
public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='',
$type, $action, $target, $logComment, $params, $newId=0 )
{
'rc_type' => RC_LOG,
'rc_minor' => 0,
'rc_cur_id' => $target->getArticleID(),
- 'rc_user' => $user->getID(),
+ 'rc_user' => $user->getId(),
'rc_user_text' => $user->getName(),
'rc_comment' => $logComment,
'rc_this_oldid' => 0,
$user = $this->cleanupForIRC( $rc_user_text );
if ( $rc_type == RC_LOG ) {
- $comment = $this->cleanupForIRC( str_replace( $title, "\00302$title\00310", $actionComment ) );
+ $logTargetText = $this->getTitle()->getPrefixedText();
+ $comment = $this->cleanupForIRC( str_replace($logTargetText,"\00302$logTargetText\00310",$actionComment) );
$flag = $rc_log_action;
} else {
$comment = $this->cleanupForIRC( $rc_comment );
- $flag = ($rc_minor ? "M" : "") . ($rc_new ? "N" : "");
+ $flag = ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
}
# see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
# no colour (\003) switches back to the term default