<?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;
}
-
+
/**
* Obtain the recent change with a given rc_id value
*
return NULL;
}
}
-
+
/**
* Find the first recent change matching some specific conditions
*
# Writes the data in this object to the database
function save()
{
- global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix;
+ global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPOmitBots;
$fname = 'RecentChange::save';
$dbw = wfGetDB( DB_MASTER );
$this->mAttribs['rc_ip'] = '';
}
- ## If our database is strict about IP addresses, use NULL instead of an empty string
+ # If our database is strict about IP addresses, use NULL instead of an empty string
if ( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) {
unset( $this->mAttribs['rc_ip'] );
}
# Set the ID
$this->mAttribs['rc_id'] = $dbw->insertId();
- # Update old rows, if necessary
- if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
- $lastTime = $this->mExtra['lastTimestamp'];
- #$now = $this->mAttribs['rc_timestamp'];
- #$curId = $this->mAttribs['rc_cur_id'];
-
- # Don't bother looking for entries that have probably
- # been purged, it just locks up the indexes needlessly.
- global $wgRCMaxAge;
- $age = time() - wfTimestamp( TS_UNIX, $lastTime );
- if( $age < $wgRCMaxAge ) {
- # live hack, will commit once tested - kate
- # Update rc_this_oldid for the entries which were current
- #
- #$oldid = $this->mAttribs['rc_last_oldid'];
- #$ns = $this->mAttribs['rc_namespace'];
- #$title = $this->mAttribs['rc_title'];
- #
- #$dbw->update( 'recentchanges',
- # array( /* SET */
- # 'rc_this_oldid' => $oldid
- # ), array( /* WHERE */
- # 'rc_namespace' => $ns,
- # 'rc_title' => $title,
- # 'rc_timestamp' => $dbw->timestamp( $lastTime )
- # ), $fname
- #);
- }
-
- # Update rc_cur_time
- #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
- # array( 'rc_cur_id' => $curId ), $fname );
- }
-
# Notify external application via UDP
- if ( $wgRC2UDPAddress ) {
- $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
- if ( $conn ) {
- $line = $wgRC2UDPPrefix . $this->getIRCLine();
- socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
- socket_close( $conn );
- }
+ if ( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
+ self::sendToUDP( $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
+ ## FIXME: Why is this treating log entries as changes to the page?
+ ## This causes problems when pages are deleted.
+ $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'],
wfRunHooks( 'RecentChange_save', array( &$this ) );
}
+ /**
+ * Send some text to UDP
+ * @param string $line
+ * @param string $prefix
+ * @param string $address
+ * @return bool success
+ */
+ public static function sendToUDP( $line, $address = '', $prefix = '' ) {
+ global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
+ # Assume default for standard RC case
+ $address = $address ? $address : $wgRC2UDPAddress;
+ $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
+ # Notify external application via UDP
+ if( $address ) {
+ $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
+ if( $conn ) {
+ $line = $prefix . $line;
+ socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
+ socket_close( $conn );
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Remove newlines and carriage returns
+ * @param string $line
+ * @return string
+ */
+ public static function cleanupForIRC( $text ) {
+ return str_replace(array("\n", "\r"), array("", ""), $text);
+ }
+
/**
* Mark a given change as patrolled
*
* @param mixed $change RecentChange or corresponding rc_id
- * @returns integer number of affected rows
+ * @param bool $auto for automatic patrol
+ * @return See doMarkPatrolled(), or null if $change is not an existing rc_id
+ */
+ public static function markPatrolled( $change, $auto = false ) {
+ $change = $change instanceof RecentChange
+ ? $change
+ : RecentChange::newFromId($change);
+ if( !$change instanceof RecentChange ) {
+ return null;
+ }
+ 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( $auto = false ) {
+ 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');
+ }
+
+ // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
+ $right = $auto ? 'autopatrol' : 'patrol';
+ $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $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( $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'), &$wgUser, false) );
+ return array();
+ }
+
+ /**
+ * Mark this RecentChange patrolled, without error checking
+ * @return int Number of affected rows
*/
- public static function markPatrolled( $change ) {
- $rcid = $change instanceof RecentChange
- ? $change->mAttribs['rc_id']
- : $change;
+ public function reallyMarkPatrolled() {
$dbw = wfGetDB( DB_MASTER );
$dbw->update(
'recentchanges',
'rc_patrolled' => 1
),
array(
- 'rc_id' => $rcid
+ 'rc_id' => $this->getAttribute('rc_id')
),
__METHOD__
);
# 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();
'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,
'newSize' => $newSize,
);
$rc->save();
- return( $rc->mAttribs['rc_id'] );
+ return $rc;
}
/**
'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,
'newSize' => $size
);
$rc->save();
- return( $rc->mAttribs['rc_id'] );
+ return $rc;
}
# Makes an entry in the database corresponding to a rename
'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, $comment, $ip='',
+ public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='',
$type, $action, $target, $logComment, $params, $newId=0 )
{
global $wgRequest;
'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,
'rc_last_oldid' => 0,
- 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot' , true ) : 0,
+ 'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
'rc_moved_to_ns' => 0,
'rc_moved_to_title' => '',
'rc_ip' => $ip,
$rc->mExtra = array(
'prefixedDBkey' => $title->getPrefixedDBkey(),
'lastTimestamp' => 0,
- 'logType' => $type,
- 'logAction' => $action,
- 'logComment' => $logComment,
- 'logTarget' => $target,
- 'logParams' => $params
+ 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
);
$rc->save();
}
return $trail;
}
- function cleanupForIRC( $text ) {
- return str_replace(array("\n", "\r"), array("", ""), $text);
- }
-
function getIRCLine() {
global $wgUseRCPatrol;
extract($this->mAttribs);
extract($this->mExtra);
- $titleObj =& $this->getTitle();
if ( $rc_type == RC_LOG ) {
- $title = MWNamespace::getCanonicalName( $titleObj->getNamespace() ) . $titleObj->getText();
+ $titleObj = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
} else {
- $title = $titleObj->getPrefixedText();
+ $titleObj =& $this->getTitle();
}
- $title = $this->cleanupForIRC( $title );
-
- $bad = array("\n", "\r");
- $empty = array("", "");
$title = $titleObj->getPrefixedText();
- $title = str_replace($bad, $empty, $title);
+ $title = self::cleanupForIRC( $title );
// FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
if ( $rc_type == RC_LOG ) {
$szdiff = '';
}
- $user = $this->cleanupForIRC( $rc_user_text );
+ $user = self::cleanupForIRC( $rc_user_text );
if ( $rc_type == RC_LOG ) {
- $logTargetText = $logTarget->getPrefixedText();
- $comment = $this->cleanupForIRC( str_replace( $logTargetText, "\00302$logTargetText\00310", $rc_comment ) );
- $flag = $logAction;
+ $targetText = $this->getTitle()->getPrefixedText();
+ $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
+ $flag = $rc_log_action;
} else {
- $comment = $this->cleanupForIRC( $rc_comment );
- $flag = ($rc_minor ? "M" : "") . ($rc_new ? "N" : "");
+ $comment = self::cleanupForIRC( $rc_comment );
+ $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
$formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape'),
$wgLang->formatNum($szdiff) );
- if( $szdiff < $wgRCChangedSizeThreshold ) {
- return '<strong class=\'mw-plusminus-neg\'>(' . $formatedSize . ')</strong>';
- } elseif( $szdiff === 0 ) {
- return '<span class=\'mw-plusminus-null\'>(' . $formatedSize . ')</span>';
+
+ if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
+ $tag = 'strong';
+ }
+ else{
+ $tag = 'span';
+ }
+
+ if( $szdiff === 0 ) {
+ return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
} elseif( $szdiff > 0 ) {
- return '<span class=\'mw-plusminus-pos\'>(+' . $formatedSize . ')</span>';
- } else {
- return '<span class=\'mw-plusminus-neg\'>(' . $formatedSize . ')</span>';
+ return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
+ } else {
+ return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
}
}
}
-
-