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' );
117 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
119 if ( $wgUseRCPatrol ) {
120 # Retrieve the id assigned by the db, but only if we'll use it later
121 $this->mAttribs
['rc_id'] = $dbw->insertId();
124 # Update old rows, if necessary
125 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
126 $lastTime = $this->mExtra
['lastTimestamp'];
127 #$now = $this->mAttribs['rc_timestamp'];
128 #$curId = $this->mAttribs['rc_cur_id'];
130 # Don't bother looking for entries that have probably
131 # been purged, it just locks up the indexes needlessly.
133 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
134 if( $age < $wgRCMaxAge ) {
135 # live hack, will commit once tested - kate
136 # Update rc_this_oldid for the entries which were current
138 #$oldid = $this->mAttribs['rc_last_oldid'];
139 #$ns = $this->mAttribs['rc_namespace'];
140 #$title = $this->mAttribs['rc_title'];
142 #$dbw->update( 'recentchanges',
144 # 'rc_this_oldid' => $oldid
145 # ), array( /* WHERE */
146 # 'rc_namespace' => $ns,
147 # 'rc_title' => $title,
148 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
154 #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
155 # array( 'rc_cur_id' => $curId ), $fname );
158 # Notify external application via UDP
159 if ( $wgRC2UDPAddress ) {
160 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
162 $line = $wgRC2UDPPrefix . $this->getIRCLine();
163 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
164 socket_close( $conn );
168 // E-mail notifications
171 # this would be better as an extension hook
172 include_once( "UserMailer.php" );
173 $enotif = new EmailNotification();
174 $title = Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
175 $enotif->notifyOnPageChange( $title,
176 $this->mAttribs
['rc_timestamp'],
177 $this->mAttribs
['rc_comment'],
178 $this->mAttribs
['rc_minor'],
179 $this->mAttribs
['rc_last_oldid'] );
184 # Marks a certain row as patrolled
185 function markPatrolled( $rcid )
187 $fname = 'RecentChange::markPatrolled';
189 $dbw =& wfGetDB( DB_MASTER
);
191 $dbw->update( 'recentchanges',
194 ), array( /* WHERE */
200 # Makes an entry in the database corresponding to an edit
201 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
202 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
205 if ( $bot == 'default ' ) {
206 $bot = $user->isBot();
216 $rc = new RecentChange
;
217 $rc->mAttribs
= array(
218 'rc_timestamp' => $timestamp,
219 'rc_cur_time' => $timestamp,
220 'rc_namespace' => $title->getNamespace(),
221 'rc_title' => $title->getDBkey(),
222 'rc_type' => RC_EDIT
,
223 'rc_minor' => $minor ?
1 : 0,
224 'rc_cur_id' => $title->getArticleID(),
225 'rc_user' => $user->getID(),
226 'rc_user_text' => $user->getName(),
227 'rc_comment' => $comment,
228 'rc_this_oldid' => $newId,
229 'rc_last_oldid' => $oldId,
230 'rc_bot' => $bot ?
1 : 0,
231 'rc_moved_to_ns' => 0,
232 'rc_moved_to_title' => '',
235 'rc_new' => 0 # obsolete
239 'prefixedDBkey' => $title->getPrefixedDBkey(),
240 'lastTimestamp' => $lastTimestamp,
241 'oldSize' => $oldSize,
242 'newSize' => $newSize,
247 # Makes an entry in the database corresponding to page creation
248 # Note: the title object must be loaded with the new id using resetArticleID()
249 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
250 $ip='', $size = 0, $newId = 0 )
258 if ( $bot == 'default' ) {
259 $bot = $user->isBot();
262 $rc = new RecentChange
;
263 $rc->mAttribs
= array(
264 'rc_timestamp' => $timestamp,
265 'rc_cur_time' => $timestamp,
266 'rc_namespace' => $title->getNamespace(),
267 'rc_title' => $title->getDBkey(),
269 'rc_minor' => $minor ?
1 : 0,
270 'rc_cur_id' => $title->getArticleID(),
271 'rc_user' => $user->getID(),
272 'rc_user_text' => $user->getName(),
273 'rc_comment' => $comment,
274 'rc_this_oldid' => $newId,
275 'rc_last_oldid' => 0,
276 'rc_bot' => $bot ?
1 : 0,
277 'rc_moved_to_ns' => 0,
278 'rc_moved_to_title' => '',
281 'rc_new' => 1 # obsolete
285 'prefixedDBkey' => $title->getPrefixedDBkey(),
286 'lastTimestamp' => 0,
293 # Makes an entry in the database corresponding to a rename
294 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
303 $rc = new RecentChange
;
304 $rc->mAttribs
= array(
305 'rc_timestamp' => $timestamp,
306 'rc_cur_time' => $timestamp,
307 'rc_namespace' => $oldTitle->getNamespace(),
308 'rc_title' => $oldTitle->getDBkey(),
309 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
311 'rc_cur_id' => $oldTitle->getArticleID(),
312 'rc_user' => $user->getID(),
313 'rc_user_text' => $user->getName(),
314 'rc_comment' => $comment,
315 'rc_this_oldid' => 0,
316 'rc_last_oldid' => 0,
317 'rc_bot' => $user->isBot() ?
1 : 0,
318 'rc_moved_to_ns' => $newTitle->getNamespace(),
319 'rc_moved_to_title' => $newTitle->getDBkey(),
321 'rc_new' => 0, # obsolete
326 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
327 'lastTimestamp' => 0,
328 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
333 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
334 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
337 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
338 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
341 # A log entry is different to an edit in that previous revisions are
343 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='',
344 $type, $action, $target, $logComment, $params )
353 $rc = new RecentChange
;
354 $rc->mAttribs
= array(
355 'rc_timestamp' => $timestamp,
356 'rc_cur_time' => $timestamp,
357 'rc_namespace' => $title->getNamespace(),
358 'rc_title' => $title->getDBkey(),
361 'rc_cur_id' => $title->getArticleID(),
362 'rc_user' => $user->getID(),
363 'rc_user_text' => $user->getName(),
364 'rc_comment' => $comment,
365 'rc_this_oldid' => 0,
366 'rc_last_oldid' => 0,
367 'rc_bot' => $user->isBot() ?
1 : 0,
368 'rc_moved_to_ns' => 0,
369 'rc_moved_to_title' => '',
372 'rc_new' => 0 # obsolete
375 'prefixedDBkey' => $title->getPrefixedDBkey(),
376 'lastTimestamp' => 0,
378 'logAction' => $action,
379 'logComment' => $logComment,
380 'logTarget' => $target,
381 'logParams' => $params
386 # Initialises the members of this object from a mysql row object
387 function loadFromRow( $row )
389 $this->mAttribs
= get_object_vars( $row );
390 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
391 $this->mExtra
= array();
394 # Makes a pseudo-RC entry from a cur row, for watchlists and things
395 function loadFromCurRow( $row )
397 $this->mAttribs
= array(
398 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
399 'rc_cur_time' => $row->rev_timestamp
,
400 'rc_user' => $row->rev_user
,
401 'rc_user_text' => $row->rev_user_text
,
402 'rc_namespace' => $row->page_namespace
,
403 'rc_title' => $row->page_title
,
404 'rc_comment' => $row->rev_comment
,
405 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
406 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
407 'rc_cur_id' => $row->page_id
,
408 'rc_this_oldid' => $row->rev_id
,
409 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
411 'rc_moved_to_ns' => 0,
412 'rc_moved_to_title' => '',
414 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
415 # currently because it uses cur, not recentchanges
416 'rc_new' => $row->page_is_new
# obsolete
419 $this->mExtra
= array();
424 * Gets the end part of the diff URL associated with this object
425 * Blank if no diff link should be displayed
427 function diffLinkTrail( $forceCur )
429 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
430 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
431 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
433 $trail .= '&diff=0' ;
435 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
443 function cleanupForIRC( $text ) {
444 return str_replace(array("\n", "\r"), array("", ""), $text);
447 function getIRCLine() {
448 global $wgUseRCPatrol;
450 extract($this->mAttribs
);
451 extract($this->mExtra
);
453 $titleObj =& $this->getTitle();
454 if ( $rc_type == RC_LOG
) {
455 $title = Namespace::getCanonicalName( $titleObj->getNamespace() ) . $titleObj->getText();
457 $title = $titleObj->getPrefixedText();
459 $title = $this->cleanupForIRC( $title );
461 if ( $rc_type == RC_LOG
) {
463 } elseif ( $rc_new && $wgUseRCPatrol ) {
464 $url = $titleObj->getFullURL("rcid=$rc_id");
465 } else if ( $rc_new ) {
466 $url = $titleObj->getFullURL();
467 } else if ( $wgUseRCPatrol ) {
468 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid&rcid=$rc_id");
470 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid");
473 if ( isset( $oldSize ) && isset( $newSize ) ) {
474 $szdiff = $newSize - $oldSize;
475 if ($szdiff < -500) {
476 $szdiff = "\002$szdiff\002";
477 } elseif ($szdiff >= 0) {
478 $szdiff = '+' . $szdiff ;
480 $szdiff = '(' . $szdiff . ')' ;
485 $user = $this->cleanupForIRC( $rc_user_text );
487 if ( $rc_type == RC_LOG
) {
488 $logTargetText = $logTarget->getPrefixedText();
489 $comment = $this->cleanupForIRC( str_replace( $logTargetText, "\00302$logTargetText\003 ", $rc_comment ) );
492 $comment = $this->cleanupForIRC( $rc_comment );
493 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
495 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
496 # no colour (\003) switches back to the term default
497 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
498 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";