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 $lastTime = $this->mExtra
['lastTimestamp'];
136 #$now = $this->mAttribs['rc_timestamp'];
137 #$curId = $this->mAttribs['rc_cur_id'];
139 # Don't bother looking for entries that have probably
140 # been purged, it just locks up the indexes needlessly.
142 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
143 if( $age < $wgRCMaxAge ) {
144 # live hack, will commit once tested - kate
145 # Update rc_this_oldid for the entries which were current
147 #$oldid = $this->mAttribs['rc_last_oldid'];
148 #$ns = $this->mAttribs['rc_namespace'];
149 #$title = $this->mAttribs['rc_title'];
151 #$dbw->update( 'recentchanges',
153 # 'rc_this_oldid' => $oldid
154 # ), array( /* WHERE */
155 # 'rc_namespace' => $ns,
156 # 'rc_title' => $title,
157 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
163 #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
164 # array( 'rc_cur_id' => $curId ), $fname );
167 # Notify external application via UDP
168 if ( $wgRC2UDPAddress ) {
169 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
171 $line = $wgRC2UDPPrefix . $this->getIRCLine();
172 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
173 socket_close( $conn );
178 # Marks a certain row as patrolled
179 function markPatrolled( $rcid )
181 $fname = 'RecentChange::markPatrolled';
183 $dbw =& wfGetDB( DB_MASTER
);
185 $dbw->update( 'recentchanges',
188 ), array( /* WHERE */
194 # Makes an entry in the database corresponding to an edit
195 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
196 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
199 if ( $bot == 'default ' ) {
200 $bot = $user->isBot();
210 $rc = new RecentChange
;
211 $rc->mAttribs
= array(
212 'rc_timestamp' => $timestamp,
213 'rc_cur_time' => $timestamp,
214 'rc_namespace' => $title->getNamespace(),
215 'rc_title' => $title->getDBkey(),
216 'rc_type' => RC_EDIT
,
217 'rc_minor' => $minor ?
1 : 0,
218 'rc_cur_id' => $title->getArticleID(),
219 'rc_user' => $user->getID(),
220 'rc_user_text' => $user->getName(),
221 'rc_comment' => $comment,
222 'rc_this_oldid' => $newId,
223 'rc_last_oldid' => $oldId,
224 'rc_bot' => $bot ?
1 : 0,
225 'rc_moved_to_ns' => 0,
226 'rc_moved_to_title' => '',
229 'rc_new' => 0 # obsolete
233 'prefixedDBkey' => $title->getPrefixedDBkey(),
234 'lastTimestamp' => $lastTimestamp,
235 'oldSize' => $oldSize,
236 'newSize' => $newSize,
241 # Makes an entry in the database corresponding to page creation
242 # Note: the title object must be loaded with the new id using resetArticleID()
243 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
244 $ip='', $size = 0, $newId = 0 )
252 if ( $bot == 'default' ) {
253 $bot = $user->isBot();
256 $rc = new RecentChange
;
257 $rc->mAttribs
= array(
258 'rc_timestamp' => $timestamp,
259 'rc_cur_time' => $timestamp,
260 'rc_namespace' => $title->getNamespace(),
261 'rc_title' => $title->getDBkey(),
263 'rc_minor' => $minor ?
1 : 0,
264 'rc_cur_id' => $title->getArticleID(),
265 'rc_user' => $user->getID(),
266 'rc_user_text' => $user->getName(),
267 'rc_comment' => $comment,
268 'rc_this_oldid' => $newId,
269 'rc_last_oldid' => 0,
270 'rc_bot' => $bot ?
1 : 0,
271 'rc_moved_to_ns' => 0,
272 'rc_moved_to_title' => '',
275 'rc_new' => 1 # obsolete
279 'prefixedDBkey' => $title->getPrefixedDBkey(),
280 'lastTimestamp' => 0,
287 # Makes an entry in the database corresponding to a rename
288 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
297 $rc = new RecentChange
;
298 $rc->mAttribs
= array(
299 'rc_timestamp' => $timestamp,
300 'rc_cur_time' => $timestamp,
301 'rc_namespace' => $oldTitle->getNamespace(),
302 'rc_title' => $oldTitle->getDBkey(),
303 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
305 'rc_cur_id' => $oldTitle->getArticleID(),
306 'rc_user' => $user->getID(),
307 'rc_user_text' => $user->getName(),
308 'rc_comment' => $comment,
309 'rc_this_oldid' => 0,
310 'rc_last_oldid' => 0,
311 'rc_bot' => $user->isBot() ?
1 : 0,
312 'rc_moved_to_ns' => $newTitle->getNamespace(),
313 'rc_moved_to_title' => $newTitle->getDBkey(),
315 'rc_new' => 0, # obsolete
320 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
321 'lastTimestamp' => 0,
322 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
327 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
328 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
331 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
332 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
335 # A log entry is different to an edit in that previous revisions are
337 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
346 $rc = new RecentChange
;
347 $rc->mAttribs
= array(
348 'rc_timestamp' => $timestamp,
349 'rc_cur_time' => $timestamp,
350 'rc_namespace' => $title->getNamespace(),
351 'rc_title' => $title->getDBkey(),
354 'rc_cur_id' => $title->getArticleID(),
355 'rc_user' => $user->getID(),
356 'rc_user_text' => $user->getName(),
357 'rc_comment' => $comment,
358 'rc_this_oldid' => 0,
359 'rc_last_oldid' => 0,
360 'rc_bot' => $user->isBot() ?
1 : 0,
361 'rc_moved_to_ns' => 0,
362 'rc_moved_to_title' => '',
365 'rc_new' => 0 # obsolete
368 'prefixedDBkey' => $title->getPrefixedDBkey(),
374 # Initialises the members of this object from a mysql row object
375 function loadFromRow( $row )
377 $this->mAttribs
= get_object_vars( $row );
378 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
379 $this->mExtra
= array();
382 # Makes a pseudo-RC entry from a cur row, for watchlists and things
383 function loadFromCurRow( $row )
385 $this->mAttribs
= array(
386 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
387 'rc_cur_time' => $row->rev_timestamp
,
388 'rc_user' => $row->rev_user
,
389 'rc_user_text' => $row->rev_user_text
,
390 'rc_namespace' => $row->page_namespace
,
391 'rc_title' => $row->page_title
,
392 'rc_comment' => $row->rev_comment
,
393 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
394 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
395 'rc_cur_id' => $row->page_id
,
396 'rc_this_oldid' => $row->rev_id
,
397 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
399 'rc_moved_to_ns' => 0,
400 'rc_moved_to_title' => '',
402 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
403 # currently because it uses cur, not recentchanges
404 'rc_new' => $row->page_is_new
# obsolete
407 $this->mExtra
= array();
412 * Gets the end part of the diff URL associated with this object
413 * Blank if no diff link should be displayed
415 function diffLinkTrail( $forceCur )
417 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
418 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
419 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
421 $trail .= '&diff=0' ;
423 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
431 function getIRCLine() {
432 global $wgUseRCPatrol;
434 extract($this->mAttribs
);
435 extract($this->mExtra
);
437 $titleObj =& $this->getTitle();
439 $bad = array("\n", "\r");
440 $empty = array("", "");
441 $title = $titleObj->getPrefixedText();
442 $title = str_replace($bad, $empty, $title);
444 if ( $rc_new && $wgUseRCPatrol ) {
445 $url = $titleObj->getFullURL("rcid=$rc_id");
446 } else if ( $rc_new ) {
447 $url = $titleObj->getFullURL();
448 } else if ( $wgUseRCPatrol ) {
449 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid&rcid=$rc_id");
451 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid");
454 if ( isset( $oldSize ) && isset( $newSize ) ) {
455 $szdiff = $newSize - $oldSize;
456 if ($szdiff < -500) {
457 $szdiff = "\002$szdiff\002";
458 } elseif ($szdiff >= 0) {
459 $szdiff = '+' . $szdiff ;
461 $szdiff = '(' . $szdiff . ')' ;
466 $comment = str_replace($bad, $empty, $rc_comment);
467 $user = str_replace($bad, $empty, $rc_user_text);
468 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
469 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
470 # no colour (\003) switches back to the term default
471 $comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
472 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
473 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";