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;
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 # Update old rows, if necessary
129 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
130 $oldid = $this->mAttribs
['rc_last_oldid'];
131 $ns = $this->mAttribs
['rc_namespace'];
132 $title = $this->mAttribs
['rc_title'];
133 $lastTime = $this->mExtra
['lastTimestamp'];
134 $now = $this->mAttribs
['rc_timestamp'];
135 $curId = $this->mAttribs
['rc_cur_id'];
137 # Don't bother looking for entries that have probably
138 # been purged, it just locks up the indexes needlessly.
140 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
141 if( $age < $wgRCMaxAge ) {
142 # live hack, will commit once tested - kate
143 # Update rc_this_oldid for the entries which were current
144 #$dbw->update( 'recentchanges',
146 # 'rc_this_oldid' => $oldid
147 # ), array( /* WHERE */
148 # 'rc_namespace' => $ns,
149 # 'rc_title' => $title,
150 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
156 $dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
157 array( 'rc_cur_id' => $curId ), $fname );
160 # Notify external application via UDP
161 if ( $wgRC2UDPAddress ) {
162 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
164 $line = $wgRC2UDPPrefix . $this->getIRCLine();
165 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
166 socket_close( $conn );
171 # Marks a certain row as patrolled
172 function markPatrolled( $rcid )
174 $fname = 'RecentChange::markPatrolled';
176 $dbw =& wfGetDB( DB_MASTER
);
178 $dbw->update( 'recentchanges',
181 ), array( /* WHERE */
187 # Makes an entry in the database corresponding to an edit
188 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
189 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
192 if ( $bot == 'default ' ) {
193 $bot = $user->isBot();
198 $ip = empty( $wgIP ) ?
'' : $wgIP;
201 $rc = new RecentChange
;
202 $rc->mAttribs
= array(
203 'rc_timestamp' => $timestamp,
204 'rc_cur_time' => $timestamp,
205 'rc_namespace' => $title->getNamespace(),
206 'rc_title' => $title->getDBkey(),
207 'rc_type' => RC_EDIT
,
208 'rc_minor' => $minor ?
1 : 0,
209 'rc_cur_id' => $title->getArticleID(),
210 'rc_user' => $user->getID(),
211 'rc_user_text' => $user->getName(),
212 'rc_comment' => $comment,
213 'rc_this_oldid' => $newId,
214 'rc_last_oldid' => $oldId,
215 'rc_bot' => $bot ?
1 : 0,
216 'rc_moved_to_ns' => 0,
217 'rc_moved_to_title' => '',
220 'rc_new' => 0 # obsolete
224 'prefixedDBkey' => $title->getPrefixedDBkey(),
225 'lastTimestamp' => $lastTimestamp,
226 'oldSize' => $oldSize,
227 'newSize' => $newSize,
232 # Makes an entry in the database corresponding to page creation
233 # Note: the title object must be loaded with the new id using resetArticleID()
234 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
235 $ip='', $size = 0, $newId = 0 )
239 $ip = empty( $wgIP ) ?
'' : $wgIP;
241 if ( $bot == 'default' ) {
242 $bot = $user->isBot();
245 $rc = new RecentChange
;
246 $rc->mAttribs
= array(
247 'rc_timestamp' => $timestamp,
248 'rc_cur_time' => $timestamp,
249 'rc_namespace' => $title->getNamespace(),
250 'rc_title' => $title->getDBkey(),
252 'rc_minor' => $minor ?
1 : 0,
253 'rc_cur_id' => $title->getArticleID(),
254 'rc_user' => $user->getID(),
255 'rc_user_text' => $user->getName(),
256 'rc_comment' => $comment,
257 'rc_this_oldid' => $newId,
258 'rc_last_oldid' => 0,
259 'rc_bot' => $bot ?
1 : 0,
260 'rc_moved_to_ns' => 0,
261 'rc_moved_to_title' => '',
264 'rc_new' => 1 # obsolete
268 'prefixedDBkey' => $title->getPrefixedDBkey(),
269 'lastTimestamp' => 0,
276 # Makes an entry in the database corresponding to a rename
277 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
281 $ip = empty( $wgIP ) ?
'' : $wgIP;
283 $rc = new RecentChange
;
284 $rc->mAttribs
= array(
285 'rc_timestamp' => $timestamp,
286 'rc_cur_time' => $timestamp,
287 'rc_namespace' => $oldTitle->getNamespace(),
288 'rc_title' => $oldTitle->getDBkey(),
289 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
291 'rc_cur_id' => $oldTitle->getArticleID(),
292 'rc_user' => $user->getID(),
293 'rc_user_text' => $user->getName(),
294 'rc_comment' => $comment,
295 'rc_this_oldid' => 0,
296 'rc_last_oldid' => 0,
297 'rc_bot' => $user->isBot() ?
1 : 0,
298 'rc_moved_to_ns' => $newTitle->getNamespace(),
299 'rc_moved_to_title' => $newTitle->getDBkey(),
301 'rc_new' => 0, # obsolete
306 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
307 'lastTimestamp' => 0,
308 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
313 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
314 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
317 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
318 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
321 # A log entry is different to an edit in that previous revisions are
323 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
327 $ip = empty( $wgIP ) ?
'' : $wgIP;
329 $rc = new RecentChange
;
330 $rc->mAttribs
= array(
331 'rc_timestamp' => $timestamp,
332 'rc_cur_time' => $timestamp,
333 'rc_namespace' => $title->getNamespace(),
334 'rc_title' => $title->getDBkey(),
337 'rc_cur_id' => $title->getArticleID(),
338 'rc_user' => $user->getID(),
339 'rc_user_text' => $user->getName(),
340 'rc_comment' => $comment,
341 'rc_this_oldid' => 0,
342 'rc_last_oldid' => 0,
343 'rc_bot' => $user->isBot() ?
1 : 0,
344 'rc_moved_to_ns' => 0,
345 'rc_moved_to_title' => '',
348 'rc_new' => 0 # obsolete
351 'prefixedDBkey' => $title->getPrefixedDBkey(),
357 # Initialises the members of this object from a mysql row object
358 function loadFromRow( $row )
360 $this->mAttribs
= get_object_vars( $row );
361 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
362 $this->mExtra
= array();
365 # Makes a pseudo-RC entry from a cur row, for watchlists and things
366 function loadFromCurRow( $row )
368 $this->mAttribs
= array(
369 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
370 'rc_cur_time' => $row->rev_timestamp
,
371 'rc_user' => $row->rev_user
,
372 'rc_user_text' => $row->rev_user_text
,
373 'rc_namespace' => $row->page_namespace
,
374 'rc_title' => $row->page_title
,
375 'rc_comment' => $row->rev_comment
,
376 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
377 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
378 'rc_cur_id' => $row->page_id
,
379 'rc_this_oldid' => $row->rev_id
,
380 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
382 'rc_moved_to_ns' => 0,
383 'rc_moved_to_title' => '',
385 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
386 # currently because it uses cur, not recentchanges
387 'rc_new' => $row->page_is_new
# obsolete
390 $this->mExtra
= array();
395 * Gets the end part of the diff URL associated with this object
396 * Blank if no diff link should be displayed
398 function diffLinkTrail( $forceCur )
400 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
401 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
402 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
404 $trail .= '&diff=0' ;
406 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
414 function getIRCLine() {
415 extract($this->mAttribs
);
416 extract($this->mExtra
);
418 $titleObj =& $this->getTitle();
420 $bad = array("\n", "\r");
421 $empty = array("", "");
422 $title = $titleObj->getPrefixedText();
423 $title = str_replace($bad, $empty, $title);
426 $url = $titleObj->getFullURL();
428 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid");
431 if ( isset( $oldSize ) && isset( $newSize ) ) {
432 $szdiff = $newSize - $oldSize;
434 $szdiff = "\002$szdiff\002";
435 else if ($szdiff >= 0)
436 $szdiff = "+$szdiff";
437 $szdiff = "($szdiff)";
442 $comment = str_replace($bad, $empty, $rc_comment);
443 $user = str_replace($bad, $empty, $rc_user_text);
444 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
445 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
446 # no colour (\003) switches back to the term default
447 $comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
448 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
449 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";