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 # Fixup database timestamps
112 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp($this->mAttribs
['rc_timestamp']);
113 $this->mAttribs
['rc_cur_time'] = $dbw->timestamp($this->mAttribs
['rc_cur_time']);
114 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'rc_rc_id_seq' );
116 ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
117 if ( $dbw->cascadingDeletes() and $this->mAttribs
['rc_cur_id']==0 ) {
118 unset ( $this->mAttribs
['rc_cur_id'] );
122 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
125 $this->mAttribs
['rc_id'] = $dbw->insertId();
127 # Update old rows, if necessary
128 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
129 $lastTime = $this->mExtra
['lastTimestamp'];
130 #$now = $this->mAttribs['rc_timestamp'];
131 #$curId = $this->mAttribs['rc_cur_id'];
133 # Don't bother looking for entries that have probably
134 # been purged, it just locks up the indexes needlessly.
136 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
137 if( $age < $wgRCMaxAge ) {
138 # live hack, will commit once tested - kate
139 # Update rc_this_oldid for the entries which were current
141 #$oldid = $this->mAttribs['rc_last_oldid'];
142 #$ns = $this->mAttribs['rc_namespace'];
143 #$title = $this->mAttribs['rc_title'];
145 #$dbw->update( 'recentchanges',
147 # 'rc_this_oldid' => $oldid
148 # ), array( /* WHERE */
149 # 'rc_namespace' => $ns,
150 # 'rc_title' => $title,
151 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
157 #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
158 # array( 'rc_cur_id' => $curId ), $fname );
161 # Notify external application via UDP
162 if ( $wgRC2UDPAddress ) {
163 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
165 $line = $wgRC2UDPPrefix . $this->getIRCLine();
166 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
167 socket_close( $conn );
171 // E-mail notifications
174 # this would be better as an extension hook
175 include_once( "UserMailer.php" );
176 $enotif = new EmailNotification();
177 $title = Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
178 $enotif->notifyOnPageChange( $title,
179 $this->mAttribs
['rc_timestamp'],
180 $this->mAttribs
['rc_comment'],
181 $this->mAttribs
['rc_minor'],
182 $this->mAttribs
['rc_last_oldid'] );
187 # Marks a certain row as patrolled
188 function markPatrolled( $rcid )
190 $fname = 'RecentChange::markPatrolled';
192 $dbw =& wfGetDB( DB_MASTER
);
194 $dbw->update( 'recentchanges',
197 ), array( /* WHERE */
203 # Makes an entry in the database corresponding to an edit
204 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
205 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
208 if ( $bot == 'default' ) {
209 $bot = $user->isAllowed( 'bot' );
219 $rc = new RecentChange
;
220 $rc->mAttribs
= array(
221 'rc_timestamp' => $timestamp,
222 'rc_cur_time' => $timestamp,
223 'rc_namespace' => $title->getNamespace(),
224 'rc_title' => $title->getDBkey(),
225 'rc_type' => RC_EDIT
,
226 'rc_minor' => $minor ?
1 : 0,
227 'rc_cur_id' => $title->getArticleID(),
228 'rc_user' => $user->getID(),
229 'rc_user_text' => $user->getName(),
230 'rc_comment' => $comment,
231 'rc_this_oldid' => $newId,
232 'rc_last_oldid' => $oldId,
233 'rc_bot' => $bot ?
1 : 0,
234 'rc_moved_to_ns' => 0,
235 'rc_moved_to_title' => '',
238 'rc_new' => 0 # obsolete
242 'prefixedDBkey' => $title->getPrefixedDBkey(),
243 'lastTimestamp' => $lastTimestamp,
244 'oldSize' => $oldSize,
245 'newSize' => $newSize,
248 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 * @todo Document parameters and return
258 public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
259 $ip='', $size = 0, $newId = 0 )
267 if ( $bot == 'default' ) {
268 $bot = $user->isAllowed( 'bot' );
271 $rc = new RecentChange
;
272 $rc->mAttribs
= array(
273 'rc_timestamp' => $timestamp,
274 'rc_cur_time' => $timestamp,
275 'rc_namespace' => $title->getNamespace(),
276 'rc_title' => $title->getDBkey(),
278 'rc_minor' => $minor ?
1 : 0,
279 'rc_cur_id' => $title->getArticleID(),
280 'rc_user' => $user->getID(),
281 'rc_user_text' => $user->getName(),
282 'rc_comment' => $comment,
283 'rc_this_oldid' => $newId,
284 'rc_last_oldid' => 0,
285 'rc_bot' => $bot ?
1 : 0,
286 'rc_moved_to_ns' => 0,
287 'rc_moved_to_title' => '',
290 'rc_new' => 1 # obsolete
294 'prefixedDBkey' => $title->getPrefixedDBkey(),
295 'lastTimestamp' => 0,
300 return( $rc->mAttribs
['rc_id'] );
303 # Makes an entry in the database corresponding to a rename
304 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
313 $rc = new RecentChange
;
314 $rc->mAttribs
= array(
315 'rc_timestamp' => $timestamp,
316 'rc_cur_time' => $timestamp,
317 'rc_namespace' => $oldTitle->getNamespace(),
318 'rc_title' => $oldTitle->getDBkey(),
319 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
321 'rc_cur_id' => $oldTitle->getArticleID(),
322 'rc_user' => $user->getID(),
323 'rc_user_text' => $user->getName(),
324 'rc_comment' => $comment,
325 'rc_this_oldid' => 0,
326 'rc_last_oldid' => 0,
327 'rc_bot' => $user->isAllowed( 'bot' ) ?
1 : 0,
328 'rc_moved_to_ns' => $newTitle->getNamespace(),
329 'rc_moved_to_title' => $newTitle->getDBkey(),
331 'rc_new' => 0, # obsolete
336 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
337 'lastTimestamp' => 0,
338 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
343 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
344 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
347 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
348 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
351 # A log entry is different to an edit in that previous revisions are
353 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='',
354 $type, $action, $target, $logComment, $params )
363 $rc = new RecentChange
;
364 $rc->mAttribs
= array(
365 'rc_timestamp' => $timestamp,
366 'rc_cur_time' => $timestamp,
367 'rc_namespace' => $title->getNamespace(),
368 'rc_title' => $title->getDBkey(),
371 'rc_cur_id' => $title->getArticleID(),
372 'rc_user' => $user->getID(),
373 'rc_user_text' => $user->getName(),
374 'rc_comment' => $comment,
375 'rc_this_oldid' => 0,
376 'rc_last_oldid' => 0,
377 'rc_bot' => $user->isAllowed( 'bot' ) ?
1 : 0,
378 'rc_moved_to_ns' => 0,
379 'rc_moved_to_title' => '',
382 'rc_new' => 0 # obsolete
385 'prefixedDBkey' => $title->getPrefixedDBkey(),
386 'lastTimestamp' => 0,
388 'logAction' => $action,
389 'logComment' => $logComment,
390 'logTarget' => $target,
391 'logParams' => $params
396 # Initialises the members of this object from a mysql row object
397 function loadFromRow( $row )
399 $this->mAttribs
= get_object_vars( $row );
400 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
401 $this->mExtra
= array();
404 # Makes a pseudo-RC entry from a cur row, for watchlists and things
405 function loadFromCurRow( $row )
407 $this->mAttribs
= array(
408 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
409 'rc_cur_time' => $row->rev_timestamp
,
410 'rc_user' => $row->rev_user
,
411 'rc_user_text' => $row->rev_user_text
,
412 'rc_namespace' => $row->page_namespace
,
413 'rc_title' => $row->page_title
,
414 'rc_comment' => $row->rev_comment
,
415 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
416 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
417 'rc_cur_id' => $row->page_id
,
418 'rc_this_oldid' => $row->rev_id
,
419 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
421 'rc_moved_to_ns' => 0,
422 'rc_moved_to_title' => '',
424 'rc_id' => $row->rc_id
,
425 'rc_patrolled' => $row->rc_patrolled
,
426 'rc_new' => $row->page_is_new
# obsolete
429 $this->mExtra
= array();
434 * Gets the end part of the diff URL associated with this object
435 * Blank if no diff link should be displayed
437 function diffLinkTrail( $forceCur )
439 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
440 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
441 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
443 $trail .= '&diff=0' ;
445 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
453 function cleanupForIRC( $text ) {
454 return str_replace(array("\n", "\r"), array("", ""), $text);
457 function getIRCLine() {
458 global $wgUseRCPatrol;
460 extract($this->mAttribs
);
461 extract($this->mExtra
);
463 $titleObj =& $this->getTitle();
464 if ( $rc_type == RC_LOG
) {
465 $title = Namespace::getCanonicalName( $titleObj->getNamespace() ) . $titleObj->getText();
467 $title = $titleObj->getPrefixedText();
469 $title = $this->cleanupForIRC( $title );
471 $bad = array("\n", "\r");
472 $empty = array("", "");
473 $title = $titleObj->getPrefixedText();
474 $title = str_replace($bad, $empty, $title);
476 // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
477 if ( $rc_type == RC_LOG
) {
479 } elseif ( $rc_new && $wgUseRCPatrol ) {
480 $url = $titleObj->getInternalURL("rcid=$rc_id");
481 } else if ( $rc_new ) {
482 $url = $titleObj->getInternalURL();
483 } else if ( $wgUseRCPatrol ) {
484 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid&rcid=$rc_id");
486 $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid");
489 if ( isset( $oldSize ) && isset( $newSize ) ) {
490 $szdiff = $newSize - $oldSize;
491 if ($szdiff < -500) {
492 $szdiff = "\002$szdiff\002";
493 } elseif ($szdiff >= 0) {
494 $szdiff = '+' . $szdiff ;
496 $szdiff = '(' . $szdiff . ')' ;
501 $user = $this->cleanupForIRC( $rc_user_text );
503 if ( $rc_type == RC_LOG
) {
504 $logTargetText = $logTarget->getPrefixedText();
505 $comment = $this->cleanupForIRC( str_replace( $logTargetText, "\00302$logTargetText\00310", $rc_comment ) );
508 $comment = $this->cleanupForIRC( $rc_comment );
509 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
511 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
512 # no colour (\003) switches back to the term default
513 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
514 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";