10 define( 'RC_EDIT', 0);
12 define( 'RC_MOVE', 2);
14 define( 'RC_MOVE_OVER_REDIRECT', 4);
18 * Utility class for creating new RC entries
20 * rc_id id of the row in the recentchanges table
21 * rc_timestamp time the entry was made
22 * rc_cur_time timestamp on the cur row
23 * rc_namespace namespace #
24 * rc_title non-prefixed db key
25 * rc_type is new entry, used to determine whether updating is necessary
27 * rc_cur_id page_id of associated page entry
28 * rc_user user id who made the entry
29 * rc_user_text user name who made the entry
30 * rc_comment edit summary
31 * rc_this_oldid rev_id associated with this entry (or zero)
32 * rc_last_oldid rev_id associated with the entry before this one (or zero)
33 * rc_bot is bot, hidden
34 * rc_ip IP address of the user in dotted quad notation
35 * rc_new obsolete, use rc_type==RC_NEW
36 * rc_patrolled boolean whether or not someone has marked this edit as patrolled
39 * prefixedDBkey prefixed db key, used by external app via msg queue
40 * lastTimestamp timestamp of previous entry, used in WHERE clause during update
41 * lang the interwiki prefix, automatically set in save()
42 * oldSize text size before the change
43 * newSize text size after the change
45 * temporary: not stored in the database
46 * notificationtimestamp
47 * numberofWatchingusers
49 * @todo document functions and variables
54 var $mAttribs = array(), $mExtra = array();
55 var $mTitle = false, $mMovedToTitle = false;
59 /* static */ function newFromRow( $row )
61 $rc = new RecentChange
;
62 $rc->loadFromRow( $row );
66 /* static */ function newFromCurRow( $row, $rc_this_oldid = 0 )
68 $rc = new RecentChange
;
69 $rc->loadFromCurRow( $row, $rc_this_oldid );
70 $rc->notificationtimestamp
= false;
71 $rc->numberofWatchingusers
= false;
77 function setAttribs( $attribs )
79 $this->mAttribs
= $attribs;
82 function setExtra( $extra )
84 $this->mExtra
= $extra;
89 if ( $this->mTitle
=== false ) {
90 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
95 function getMovedToTitle()
97 if ( $this->mMovedToTitle
=== false ) {
98 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
99 $this->mAttribs
['rc_moved_to_title'] );
101 return $this->mMovedToTitle
;
104 # Writes the data in this object to the database
107 global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix, $wgUseRCPatrol;
108 $fname = 'RecentChange::save';
110 $dbw =& wfGetDB( DB_MASTER
);
111 if ( !is_array($this->mExtra
) ) {
112 $this->mExtra
= array();
114 $this->mExtra
['lang'] = $wgLocalInterwiki;
116 if ( !$wgPutIPinRC ) {
117 $this->mAttribs
['rc_ip'] = '';
120 # Fixup database timestamps
121 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp($this->mAttribs
['rc_timestamp']);
122 $this->mAttribs
['rc_cur_time'] = $dbw->timestamp($this->mAttribs
['rc_cur_time']);
123 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'rc_rc_id_seq' );
126 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
128 if ( $wgUseRCPatrol ) {
129 # Retrieve the id assigned by the db, but only if we'll use it later
130 $this->mAttribs
['rc_id'] = $dbw->insertId();
133 # Update old rows, if necessary
134 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
135 $oldid = $this->mAttribs
['rc_last_oldid'];
136 $ns = $this->mAttribs
['rc_namespace'];
137 $title = $this->mAttribs
['rc_title'];
138 $lastTime = $this->mExtra
['lastTimestamp'];
139 $now = $this->mAttribs
['rc_timestamp'];
140 $curId = $this->mAttribs
['rc_cur_id'];
142 # Don't bother looking for entries that have probably
143 # been purged, it just locks up the indexes needlessly.
145 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
146 if( $age < $wgRCMaxAge ) {
147 # live hack, will commit once tested - kate
148 # Update rc_this_oldid for the entries which were current
149 #$dbw->update( 'recentchanges',
151 # 'rc_this_oldid' => $oldid
152 # ), array( /* WHERE */
153 # 'rc_namespace' => $ns,
154 # 'rc_title' => $title,
155 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
161 #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
162 # array( 'rc_cur_id' => $curId ), $fname );
165 # Notify external application via UDP
166 if ( $wgRC2UDPAddress ) {
167 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
169 $line = $wgRC2UDPPrefix . $this->getIRCLine();
170 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
171 socket_close( $conn );
176 # Marks a certain row as patrolled
177 function markPatrolled( $rcid )
179 $fname = 'RecentChange::markPatrolled';
181 $dbw =& wfGetDB( DB_MASTER
);
183 $dbw->update( 'recentchanges',
186 ), array( /* WHERE */
192 # Makes an entry in the database corresponding to an edit
193 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
194 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
197 if ( $bot == 'default ' ) {
198 $bot = $user->isBot();
208 $rc = new RecentChange
;
209 $rc->mAttribs
= array(
210 'rc_timestamp' => $timestamp,
211 'rc_cur_time' => $timestamp,
212 'rc_namespace' => $title->getNamespace(),
213 'rc_title' => $title->getDBkey(),
214 'rc_type' => RC_EDIT
,
215 'rc_minor' => $minor ?
1 : 0,
216 'rc_cur_id' => $title->getArticleID(),
217 'rc_user' => $user->getID(),
218 'rc_user_text' => $user->getName(),
219 'rc_comment' => $comment,
220 'rc_this_oldid' => $newId,
221 'rc_last_oldid' => $oldId,
222 'rc_bot' => $bot ?
1 : 0,
223 'rc_moved_to_ns' => 0,
224 'rc_moved_to_title' => '',
227 'rc_new' => 0 # obsolete
231 'prefixedDBkey' => $title->getPrefixedDBkey(),
232 'lastTimestamp' => $lastTimestamp,
233 'oldSize' => $oldSize,
234 'newSize' => $newSize,
239 # Makes an entry in the database corresponding to page creation
240 # Note: the title object must be loaded with the new id using resetArticleID()
241 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
242 $ip='', $size = 0, $newId = 0 )
250 if ( $bot == 'default' ) {
251 $bot = $user->isBot();
254 $rc = new RecentChange
;
255 $rc->mAttribs
= array(
256 'rc_timestamp' => $timestamp,
257 'rc_cur_time' => $timestamp,
258 'rc_namespace' => $title->getNamespace(),
259 'rc_title' => $title->getDBkey(),
261 'rc_minor' => $minor ?
1 : 0,
262 'rc_cur_id' => $title->getArticleID(),
263 'rc_user' => $user->getID(),
264 'rc_user_text' => $user->getName(),
265 'rc_comment' => $comment,
266 'rc_this_oldid' => $newId,
267 'rc_last_oldid' => 0,
268 'rc_bot' => $bot ?
1 : 0,
269 'rc_moved_to_ns' => 0,
270 'rc_moved_to_title' => '',
273 'rc_new' => 1 # obsolete
277 'prefixedDBkey' => $title->getPrefixedDBkey(),
278 'lastTimestamp' => 0,
285 # Makes an entry in the database corresponding to a rename
286 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
295 $rc = new RecentChange
;
296 $rc->mAttribs
= array(
297 'rc_timestamp' => $timestamp,
298 'rc_cur_time' => $timestamp,
299 'rc_namespace' => $oldTitle->getNamespace(),
300 'rc_title' => $oldTitle->getDBkey(),
301 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
303 'rc_cur_id' => $oldTitle->getArticleID(),
304 'rc_user' => $user->getID(),
305 'rc_user_text' => $user->getName(),
306 'rc_comment' => $comment,
307 'rc_this_oldid' => 0,
308 'rc_last_oldid' => 0,
309 'rc_bot' => $user->isBot() ?
1 : 0,
310 'rc_moved_to_ns' => $newTitle->getNamespace(),
311 'rc_moved_to_title' => $newTitle->getDBkey(),
313 'rc_new' => 0, # obsolete
318 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
319 'lastTimestamp' => 0,
320 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
325 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
326 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
329 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
330 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
333 # A log entry is different to an edit in that previous revisions are
335 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
344 $rc = new RecentChange
;
345 $rc->mAttribs
= array(
346 'rc_timestamp' => $timestamp,
347 'rc_cur_time' => $timestamp,
348 'rc_namespace' => $title->getNamespace(),
349 'rc_title' => $title->getDBkey(),
352 'rc_cur_id' => $title->getArticleID(),
353 'rc_user' => $user->getID(),
354 'rc_user_text' => $user->getName(),
355 'rc_comment' => $comment,
356 'rc_this_oldid' => 0,
357 'rc_last_oldid' => 0,
358 'rc_bot' => $user->isBot() ?
1 : 0,
359 'rc_moved_to_ns' => 0,
360 'rc_moved_to_title' => '',
363 'rc_new' => 0 # obsolete
366 'prefixedDBkey' => $title->getPrefixedDBkey(),
372 # Initialises the members of this object from a mysql row object
373 function loadFromRow( $row )
375 $this->mAttribs
= get_object_vars( $row );
376 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
377 $this->mExtra
= array();
380 # Makes a pseudo-RC entry from a cur row, for watchlists and things
381 function loadFromCurRow( $row )
383 $this->mAttribs
= array(
384 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
385 'rc_cur_time' => $row->rev_timestamp
,
386 'rc_user' => $row->rev_user
,
387 'rc_user_text' => $row->rev_user_text
,
388 'rc_namespace' => $row->page_namespace
,
389 'rc_title' => $row->page_title
,
390 'rc_comment' => $row->rev_comment
,
391 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
392 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
393 'rc_cur_id' => $row->page_id
,
394 'rc_this_oldid' => $row->rev_id
,
395 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
397 'rc_moved_to_ns' => 0,
398 'rc_moved_to_title' => '',
400 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
401 # currently because it uses cur, not recentchanges
402 'rc_new' => $row->page_is_new
# obsolete
405 $this->mExtra
= array();
410 * Gets the end part of the diff URL associated with this object
411 * Blank if no diff link should be displayed
413 function diffLinkTrail( $forceCur )
415 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
416 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
417 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
419 $trail .= '&diff=0' ;
421 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
429 function getIRCLine() {
430 global $wgUseRCPatrol;
432 extract($this->mAttribs
);
433 extract($this->mExtra
);
435 $titleObj =& $this->getTitle();
437 $bad = array("\n", "\r");
438 $empty = array("", "");
439 $title = $titleObj->getPrefixedText();
440 $title = str_replace($bad, $empty, $title);
442 if ( $rc_new && $wgUseRCPatrol ) {
443 $url = $titleObj->getFullURL("rcid=$rc_id");
444 } else if ( $rc_new ) {
445 $url = $titleObj->getFullURL();
446 } else if ( $wgUseRCPatrol ) {
447 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid&rcid=$rc_id");
449 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid");
452 if ( isset( $oldSize ) && isset( $newSize ) ) {
453 $szdiff = $newSize - $oldSize;
455 $szdiff = "\002$szdiff\002";
456 else if ($szdiff >= 0)
457 $szdiff = "+$szdiff";
458 $szdiff = "($szdiff)";
463 $comment = str_replace($bad, $empty, $rc_comment);
464 $user = str_replace($bad, $empty, $rc_user_text);
465 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
466 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
467 # no colour (\003) switches back to the term default
468 $comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
469 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
470 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";