8 * Utility class for creating new RC entries
10 * rc_id id of the row in the recentchanges table
11 * rc_timestamp time the entry was made
12 * rc_cur_time timestamp on the cur row
13 * rc_namespace namespace #
14 * rc_title non-prefixed db key
15 * rc_type is new entry, used to determine whether updating is necessary
17 * rc_cur_id page_id of associated page entry
18 * rc_user user id who made the entry
19 * rc_user_text user name who made the entry
20 * rc_comment edit summary
21 * rc_this_oldid rev_id associated with this entry (or zero)
22 * rc_last_oldid rev_id associated with the entry before this one (or zero)
23 * rc_bot is bot, hidden
24 * rc_ip IP address of the user in dotted quad notation
25 * rc_new obsolete, use rc_type==RC_NEW
26 * rc_patrolled boolean whether or not someone has marked this edit as patrolled
29 * prefixedDBkey prefixed db key, used by external app via msg queue
30 * lastTimestamp timestamp of previous entry, used in WHERE clause during update
31 * lang the interwiki prefix, automatically set in save()
32 * oldSize text size before the change
33 * newSize text size after the change
35 * temporary: not stored in the database
36 * notificationtimestamp
37 * numberofWatchingusers
39 * @todo document functions and variables
46 $mMovedToTitle = false,
49 /** @todo FIXME should those really be public ? */
54 $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked
58 static function newFromRow( $row ) {
59 $rc = new RecentChange
;
60 $rc->loadFromRow( $row );
64 static function newFromCurRow( $row, $rc_this_oldid = 0 ) {
65 $rc = new RecentChange
;
66 $rc->loadFromCurRow( $row, $rc_this_oldid );
67 $rc->notificationtimestamp
= false;
68 $rc->numberofWatchingusers
= false;
74 function setAttribs( $attribs )
76 $this->mAttribs
= $attribs;
79 function setExtra( $extra )
81 $this->mExtra
= $extra;
86 if ( $this->mTitle
=== false ) {
87 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
92 function getMovedToTitle()
94 if ( $this->mMovedToTitle
=== false ) {
95 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
96 $this->mAttribs
['rc_moved_to_title'] );
98 return $this->mMovedToTitle
;
101 # Writes the data in this object to the database
104 global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix, $wgUseRCPatrol;
105 $fname = 'RecentChange::save';
107 $dbw =& wfGetDB( DB_MASTER
);
108 if ( !is_array($this->mExtra
) ) {
109 $this->mExtra
= array();
111 $this->mExtra
['lang'] = $wgLocalInterwiki;
113 if ( !$wgPutIPinRC ) {
114 $this->mAttribs
['rc_ip'] = '';
117 # Fixup database timestamps
118 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp($this->mAttribs
['rc_timestamp']);
119 $this->mAttribs
['rc_cur_time'] = $dbw->timestamp($this->mAttribs
['rc_cur_time']);
120 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'rc_rc_id_seq' );
123 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
126 $this->mAttribs
['rc_id'] = $dbw->insertId();
128 # Update old rows, if necessary
129 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
130 $lastTime = $this->mExtra
['lastTimestamp'];
131 #$now = $this->mAttribs['rc_timestamp'];
132 #$curId = $this->mAttribs['rc_cur_id'];
134 # Don't bother looking for entries that have probably
135 # been purged, it just locks up the indexes needlessly.
137 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
138 if( $age < $wgRCMaxAge ) {
139 # live hack, will commit once tested - kate
140 # Update rc_this_oldid for the entries which were current
142 #$oldid = $this->mAttribs['rc_last_oldid'];
143 #$ns = $this->mAttribs['rc_namespace'];
144 #$title = $this->mAttribs['rc_title'];
146 #$dbw->update( 'recentchanges',
148 # 'rc_this_oldid' => $oldid
149 # ), array( /* WHERE */
150 # 'rc_namespace' => $ns,
151 # 'rc_title' => $title,
152 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
158 #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
159 # array( 'rc_cur_id' => $curId ), $fname );
162 # Notify external application via UDP
163 if ( $wgRC2UDPAddress ) {
164 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
166 $line = $wgRC2UDPPrefix . $this->getIRCLine();
167 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
168 socket_close( $conn );
172 // E-mail notifications
175 # this would be better as an extension hook
176 include_once( "UserMailer.php" );
177 $enotif = new EmailNotification();
178 $title = Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
179 $enotif->notifyOnPageChange( $title,
180 $this->mAttribs
['rc_timestamp'],
181 $this->mAttribs
['rc_comment'],
182 $this->mAttribs
['rc_minor'],
183 $this->mAttribs
['rc_last_oldid'] );
188 # Marks a certain row as patrolled
189 function markPatrolled( $rcid )
191 $fname = 'RecentChange::markPatrolled';
193 $dbw =& wfGetDB( DB_MASTER
);
195 $dbw->update( 'recentchanges',
198 ), array( /* WHERE */
204 # Makes an entry in the database corresponding to an edit
205 static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
206 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
209 if ( $bot == 'default ' ) {
210 $bot = $user->isBot();
220 $rc = new RecentChange
;
221 $rc->mAttribs
= array(
222 'rc_timestamp' => $timestamp,
223 'rc_cur_time' => $timestamp,
224 'rc_namespace' => $title->getNamespace(),
225 'rc_title' => $title->getDBkey(),
226 'rc_type' => RC_EDIT
,
227 'rc_minor' => $minor ?
1 : 0,
228 'rc_cur_id' => $title->getArticleID(),
229 'rc_user' => $user->getID(),
230 'rc_user_text' => $user->getName(),
231 'rc_comment' => $comment,
232 'rc_this_oldid' => $newId,
233 'rc_last_oldid' => $oldId,
234 'rc_bot' => $bot ?
1 : 0,
235 'rc_moved_to_ns' => 0,
236 'rc_moved_to_title' => '',
239 'rc_new' => 0 # obsolete
243 'prefixedDBkey' => $title->getPrefixedDBkey(),
244 'lastTimestamp' => $lastTimestamp,
245 'oldSize' => $oldSize,
246 'newSize' => $newSize,
249 return( $rc->mAttribs
['rc_id'] );
252 # Makes an entry in the database corresponding to page creation
253 # Note: the title object must be loaded with the new id using resetArticleID()
254 static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
255 $ip='', $size = 0, $newId = 0 )
263 if ( $bot == 'default' ) {
264 $bot = $user->isBot();
267 $rc = new RecentChange
;
268 $rc->mAttribs
= array(
269 'rc_timestamp' => $timestamp,
270 'rc_cur_time' => $timestamp,
271 'rc_namespace' => $title->getNamespace(),
272 'rc_title' => $title->getDBkey(),
274 'rc_minor' => $minor ?
1 : 0,
275 'rc_cur_id' => $title->getArticleID(),
276 'rc_user' => $user->getID(),
277 'rc_user_text' => $user->getName(),
278 'rc_comment' => $comment,
279 'rc_this_oldid' => $newId,
280 'rc_last_oldid' => 0,
281 'rc_bot' => $bot ?
1 : 0,
282 'rc_moved_to_ns' => 0,
283 'rc_moved_to_title' => '',
286 'rc_new' => 1 # obsolete
290 'prefixedDBkey' => $title->getPrefixedDBkey(),
291 'lastTimestamp' => 0,
296 return( $rc->mAttribs
['rc_id'] );
299 # Makes an entry in the database corresponding to a rename
300 static function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
309 $rc = new RecentChange
;
310 $rc->mAttribs
= array(
311 'rc_timestamp' => $timestamp,
312 'rc_cur_time' => $timestamp,
313 'rc_namespace' => $oldTitle->getNamespace(),
314 'rc_title' => $oldTitle->getDBkey(),
315 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
317 'rc_cur_id' => $oldTitle->getArticleID(),
318 'rc_user' => $user->getID(),
319 'rc_user_text' => $user->getName(),
320 'rc_comment' => $comment,
321 'rc_this_oldid' => 0,
322 'rc_last_oldid' => 0,
323 'rc_bot' => $user->isBot() ?
1 : 0,
324 'rc_moved_to_ns' => $newTitle->getNamespace(),
325 'rc_moved_to_title' => $newTitle->getDBkey(),
327 'rc_new' => 0, # obsolete
332 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
333 'lastTimestamp' => 0,
334 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
339 static function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
340 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
343 static function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
344 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
347 # A log entry is different to an edit in that previous revisions are
349 static function notifyLog( $timestamp, &$title, &$user, $comment, $ip='',
350 $type, $action, $target, $logComment, $params )
359 $rc = new RecentChange
;
360 $rc->mAttribs
= array(
361 'rc_timestamp' => $timestamp,
362 'rc_cur_time' => $timestamp,
363 'rc_namespace' => $title->getNamespace(),
364 'rc_title' => $title->getDBkey(),
367 'rc_cur_id' => $title->getArticleID(),
368 'rc_user' => $user->getID(),
369 'rc_user_text' => $user->getName(),
370 'rc_comment' => $comment,
371 'rc_this_oldid' => 0,
372 'rc_last_oldid' => 0,
373 'rc_bot' => $user->isBot() ?
1 : 0,
374 'rc_moved_to_ns' => 0,
375 'rc_moved_to_title' => '',
378 'rc_new' => 0 # obsolete
381 'prefixedDBkey' => $title->getPrefixedDBkey(),
382 'lastTimestamp' => 0,
384 'logAction' => $action,
385 'logComment' => $logComment,
386 'logTarget' => $target,
387 'logParams' => $params
392 # Initialises the members of this object from a mysql row object
393 function loadFromRow( $row )
395 $this->mAttribs
= get_object_vars( $row );
396 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
397 $this->mExtra
= array();
400 # Makes a pseudo-RC entry from a cur row, for watchlists and things
401 function loadFromCurRow( $row )
403 $this->mAttribs
= array(
404 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
405 'rc_cur_time' => $row->rev_timestamp
,
406 'rc_user' => $row->rev_user
,
407 'rc_user_text' => $row->rev_user_text
,
408 'rc_namespace' => $row->page_namespace
,
409 'rc_title' => $row->page_title
,
410 'rc_comment' => $row->rev_comment
,
411 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
412 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
413 'rc_cur_id' => $row->page_id
,
414 'rc_this_oldid' => $row->rev_id
,
415 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
417 'rc_moved_to_ns' => 0,
418 'rc_moved_to_title' => '',
420 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
421 # currently because it uses cur, not recentchanges
422 'rc_new' => $row->page_is_new
# obsolete
425 $this->mExtra
= array();
430 * Gets the end part of the diff URL associated with this object
431 * Blank if no diff link should be displayed
433 function diffLinkTrail( $forceCur )
435 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
436 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
437 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
439 $trail .= '&diff=0' ;
441 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
449 function cleanupForIRC( $text ) {
450 return str_replace(array("\n", "\r"), array("", ""), $text);
453 function getIRCLine() {
454 global $wgUseRCPatrol;
456 extract($this->mAttribs
);
457 extract($this->mExtra
);
459 $titleObj =& $this->getTitle();
460 if ( $rc_type == RC_LOG
) {
461 $title = Namespace::getCanonicalName( $titleObj->getNamespace() ) . $titleObj->getText();
463 $title = $titleObj->getPrefixedText();
465 $title = $this->cleanupForIRC( $title );
467 $bad = array("\n", "\r");
468 $empty = array("", "");
469 $title = $titleObj->getPrefixedText();
470 $title = str_replace($bad, $empty, $title);
472 // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
473 if ( $rc_type == RC_LOG
) {
475 } elseif ( $rc_new && $wgUseRCPatrol ) {
476 $url = $titleObj->getInternalURL("rcid=$rc_id");
477 } else if ( $rc_new ) {
478 $url = $titleObj->getInternalURL();
479 } else if ( $wgUseRCPatrol ) {
480 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid&rcid=$rc_id");
482 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid");
485 if ( isset( $oldSize ) && isset( $newSize ) ) {
486 $szdiff = $newSize - $oldSize;
487 if ($szdiff < -500) {
488 $szdiff = "\002$szdiff\002";
489 } elseif ($szdiff >= 0) {
490 $szdiff = '+' . $szdiff ;
492 $szdiff = '(' . $szdiff . ')' ;
497 $user = $this->cleanupForIRC( $rc_user_text );
499 if ( $rc_type == RC_LOG
) {
500 $logTargetText = $logTarget->getPrefixedText();
501 $comment = $this->cleanupForIRC( str_replace( $logTargetText, "\00302$logTargetText\00310", $rc_comment ) );
504 $comment = $this->cleanupForIRC( $rc_comment );
505 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
507 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
508 # no colour (\003) switches back to the term default
509 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
510 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";