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
44 var $mAttribs = array(), $mExtra = array();
45 var $mTitle = false, $mMovedToTitle = false;
46 var $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked
50 /* static */ function newFromRow( $row )
52 $rc = new RecentChange
;
53 $rc->loadFromRow( $row );
57 /* static */ function newFromCurRow( $row, $rc_this_oldid = 0 )
59 $rc = new RecentChange
;
60 $rc->loadFromCurRow( $row, $rc_this_oldid );
61 $rc->notificationtimestamp
= false;
62 $rc->numberofWatchingusers
= false;
68 function setAttribs( $attribs )
70 $this->mAttribs
= $attribs;
73 function setExtra( $extra )
75 $this->mExtra
= $extra;
80 if ( $this->mTitle
=== false ) {
81 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
86 function getMovedToTitle()
88 if ( $this->mMovedToTitle
=== false ) {
89 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
90 $this->mAttribs
['rc_moved_to_title'] );
92 return $this->mMovedToTitle
;
95 # Writes the data in this object to the database
98 global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix, $wgUseRCPatrol;
99 $fname = 'RecentChange::save';
101 $dbw =& wfGetDB( DB_MASTER
);
102 if ( !is_array($this->mExtra
) ) {
103 $this->mExtra
= array();
105 $this->mExtra
['lang'] = $wgLocalInterwiki;
107 if ( !$wgPutIPinRC ) {
108 $this->mAttribs
['rc_ip'] = '';
111 ## If our database is strict about IP addresses, use NULL instead of an empty string
112 if ( $dbw->strictIPs() and $this->mAttribs
['rc_ip'] == '' ) {
113 unset( $this->mAttribs
['rc_ip'] );
116 # Fixup database timestamps
117 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp($this->mAttribs
['rc_timestamp']);
118 $this->mAttribs
['rc_cur_time'] = $dbw->timestamp($this->mAttribs
['rc_cur_time']);
119 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'rc_rc_id_seq' );
121 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
122 if ( $dbw->cascadingDeletes() and $this->mAttribs
['rc_cur_id']==0 ) {
123 unset ( $this->mAttribs
['rc_cur_id'] );
127 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
130 $this->mAttribs
['rc_id'] = $dbw->insertId();
132 # Update old rows, if necessary
133 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
134 $lastTime = $this->mExtra
['lastTimestamp'];
135 #$now = $this->mAttribs['rc_timestamp'];
136 #$curId = $this->mAttribs['rc_cur_id'];
138 # Don't bother looking for entries that have probably
139 # been purged, it just locks up the indexes needlessly.
141 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
142 if( $age < $wgRCMaxAge ) {
143 # live hack, will commit once tested - kate
144 # Update rc_this_oldid for the entries which were current
146 #$oldid = $this->mAttribs['rc_last_oldid'];
147 #$ns = $this->mAttribs['rc_namespace'];
148 #$title = $this->mAttribs['rc_title'];
150 #$dbw->update( 'recentchanges',
152 # 'rc_this_oldid' => $oldid
153 # ), array( /* WHERE */
154 # 'rc_namespace' => $ns,
155 # 'rc_title' => $title,
156 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
162 #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
163 # array( 'rc_cur_id' => $curId ), $fname );
166 # Notify external application via UDP
167 if ( $wgRC2UDPAddress ) {
168 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
170 $line = $wgRC2UDPPrefix . $this->getIRCLine();
171 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
172 socket_close( $conn );
176 // E-mail notifications
179 # this would be better as an extension hook
180 include_once( "UserMailer.php" );
181 $enotif = new EmailNotification();
182 $title = Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
183 $enotif->notifyOnPageChange( $title,
184 $this->mAttribs
['rc_timestamp'],
185 $this->mAttribs
['rc_comment'],
186 $this->mAttribs
['rc_minor'],
187 $this->mAttribs
['rc_last_oldid'] );
192 # Marks a certain row as patrolled
193 function markPatrolled( $rcid )
195 $fname = 'RecentChange::markPatrolled';
197 $dbw =& wfGetDB( DB_MASTER
);
199 $dbw->update( 'recentchanges',
202 ), array( /* WHERE */
208 # Makes an entry in the database corresponding to an edit
209 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
210 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
213 if ( $bot == 'default' ) {
214 $bot = $user->isAllowed( 'bot' );
224 $rc = new RecentChange
;
225 $rc->mAttribs
= array(
226 'rc_timestamp' => $timestamp,
227 'rc_cur_time' => $timestamp,
228 'rc_namespace' => $title->getNamespace(),
229 'rc_title' => $title->getDBkey(),
230 'rc_type' => RC_EDIT
,
231 'rc_minor' => $minor ?
1 : 0,
232 'rc_cur_id' => $title->getArticleID(),
233 'rc_user' => $user->getID(),
234 'rc_user_text' => $user->getName(),
235 'rc_comment' => $comment,
236 'rc_this_oldid' => $newId,
237 'rc_last_oldid' => $oldId,
238 'rc_bot' => $bot ?
1 : 0,
239 'rc_moved_to_ns' => 0,
240 'rc_moved_to_title' => '',
243 'rc_new' => 0 # obsolete
247 'prefixedDBkey' => $title->getPrefixedDBkey(),
248 'lastTimestamp' => $lastTimestamp,
249 'oldSize' => $oldSize,
250 'newSize' => $newSize,
253 return( $rc->mAttribs
['rc_id'] );
257 * Makes an entry in the database corresponding to page creation
258 * Note: the title object must be loaded with the new id using resetArticleID()
259 * @todo Document parameters and return
263 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
264 $ip='', $size = 0, $newId = 0 )
272 if ( $bot == 'default' ) {
273 $bot = $user->isAllowed( 'bot' );
276 $rc = new RecentChange
;
277 $rc->mAttribs
= array(
278 'rc_timestamp' => $timestamp,
279 'rc_cur_time' => $timestamp,
280 'rc_namespace' => $title->getNamespace(),
281 'rc_title' => $title->getDBkey(),
283 'rc_minor' => $minor ?
1 : 0,
284 'rc_cur_id' => $title->getArticleID(),
285 'rc_user' => $user->getID(),
286 'rc_user_text' => $user->getName(),
287 'rc_comment' => $comment,
288 'rc_this_oldid' => $newId,
289 'rc_last_oldid' => 0,
290 'rc_bot' => $bot ?
1 : 0,
291 'rc_moved_to_ns' => 0,
292 'rc_moved_to_title' => '',
295 'rc_new' => 1 # obsolete
299 'prefixedDBkey' => $title->getPrefixedDBkey(),
300 'lastTimestamp' => 0,
305 return( $rc->mAttribs
['rc_id'] );
308 # Makes an entry in the database corresponding to a rename
309 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
318 $rc = new RecentChange
;
319 $rc->mAttribs
= array(
320 'rc_timestamp' => $timestamp,
321 'rc_cur_time' => $timestamp,
322 'rc_namespace' => $oldTitle->getNamespace(),
323 'rc_title' => $oldTitle->getDBkey(),
324 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
326 'rc_cur_id' => $oldTitle->getArticleID(),
327 'rc_user' => $user->getID(),
328 'rc_user_text' => $user->getName(),
329 'rc_comment' => $comment,
330 'rc_this_oldid' => 0,
331 'rc_last_oldid' => 0,
332 'rc_bot' => $user->isAllowed( 'bot' ) ?
1 : 0,
333 'rc_moved_to_ns' => $newTitle->getNamespace(),
334 'rc_moved_to_title' => $newTitle->getDBkey(),
336 'rc_new' => 0, # obsolete
341 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
342 'lastTimestamp' => 0,
343 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
348 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
349 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
352 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
353 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
356 # A log entry is different to an edit in that previous revisions are
358 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='',
359 $type, $action, $target, $logComment, $params )
368 $rc = new RecentChange
;
369 $rc->mAttribs
= array(
370 'rc_timestamp' => $timestamp,
371 'rc_cur_time' => $timestamp,
372 'rc_namespace' => $title->getNamespace(),
373 'rc_title' => $title->getDBkey(),
376 'rc_cur_id' => $title->getArticleID(),
377 'rc_user' => $user->getID(),
378 'rc_user_text' => $user->getName(),
379 'rc_comment' => $comment,
380 'rc_this_oldid' => 0,
381 'rc_last_oldid' => 0,
382 'rc_bot' => $user->isAllowed( 'bot' ) ?
1 : 0,
383 'rc_moved_to_ns' => 0,
384 'rc_moved_to_title' => '',
387 'rc_new' => 0 # obsolete
390 'prefixedDBkey' => $title->getPrefixedDBkey(),
391 'lastTimestamp' => 0,
393 'logAction' => $action,
394 'logComment' => $logComment,
395 'logTarget' => $target,
396 'logParams' => $params
401 # Initialises the members of this object from a mysql row object
402 function loadFromRow( $row )
404 $this->mAttribs
= get_object_vars( $row );
405 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
406 $this->mExtra
= array();
409 # Makes a pseudo-RC entry from a cur row, for watchlists and things
410 function loadFromCurRow( $row )
412 $this->mAttribs
= array(
413 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
414 'rc_cur_time' => $row->rev_timestamp
,
415 'rc_user' => $row->rev_user
,
416 'rc_user_text' => $row->rev_user_text
,
417 'rc_namespace' => $row->page_namespace
,
418 'rc_title' => $row->page_title
,
419 'rc_comment' => $row->rev_comment
,
420 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
421 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
422 'rc_cur_id' => $row->page_id
,
423 'rc_this_oldid' => $row->rev_id
,
424 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
426 'rc_moved_to_ns' => 0,
427 'rc_moved_to_title' => '',
429 'rc_id' => $row->rc_id
,
430 'rc_patrolled' => $row->rc_patrolled
,
431 'rc_new' => $row->page_is_new
# obsolete
434 $this->mExtra
= array();
439 * Gets the end part of the diff URL associated with this object
440 * Blank if no diff link should be displayed
442 function diffLinkTrail( $forceCur )
444 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
445 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
446 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
448 $trail .= '&diff=0' ;
450 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
458 function cleanupForIRC( $text ) {
459 return str_replace(array("\n", "\r"), array("", ""), $text);
462 function getIRCLine() {
463 global $wgUseRCPatrol;
465 extract($this->mAttribs
);
466 extract($this->mExtra
);
468 $titleObj =& $this->getTitle();
469 if ( $rc_type == RC_LOG
) {
470 $title = Namespace::getCanonicalName( $titleObj->getNamespace() ) . $titleObj->getText();
472 $title = $titleObj->getPrefixedText();
474 $title = $this->cleanupForIRC( $title );
476 $bad = array("\n", "\r");
477 $empty = array("", "");
478 $title = $titleObj->getPrefixedText();
479 $title = str_replace($bad, $empty, $title);
481 // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
482 if ( $rc_type == RC_LOG
) {
484 } elseif ( $rc_new && $wgUseRCPatrol ) {
485 $url = $titleObj->getInternalURL("rcid=$rc_id");
486 } else if ( $rc_new ) {
487 $url = $titleObj->getInternalURL();
488 } else if ( $wgUseRCPatrol ) {
489 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid&rcid=$rc_id");
491 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid");
494 if ( isset( $oldSize ) && isset( $newSize ) ) {
495 $szdiff = $newSize - $oldSize;
496 if ($szdiff < -500) {
497 $szdiff = "\002$szdiff\002";
498 } elseif ($szdiff >= 0) {
499 $szdiff = '+' . $szdiff ;
501 $szdiff = '(' . $szdiff . ')' ;
506 $user = $this->cleanupForIRC( $rc_user_text );
508 if ( $rc_type == RC_LOG
) {
509 $logTargetText = $logTarget->getPrefixedText();
510 $comment = $this->cleanupForIRC( str_replace( $logTargetText, "\00302$logTargetText\00310", $rc_comment ) );
513 $comment = $this->cleanupForIRC( $rc_comment );
514 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
516 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
517 # no colour (\003) switches back to the term default
518 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
519 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";