9f926976aa077bdbc7f935d1e8b3363fd5c6768a
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;
56 var $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked
60 /* static */ function newFromRow( $row )
62 $rc = new RecentChange
;
63 $rc->loadFromRow( $row );
67 /* static */ function newFromCurRow( $row, $rc_this_oldid = 0 )
69 $rc = new RecentChange
;
70 $rc->loadFromCurRow( $row, $rc_this_oldid );
71 $rc->notificationtimestamp
= false;
72 $rc->numberofWatchingusers
= false;
78 function setAttribs( $attribs )
80 $this->mAttribs
= $attribs;
83 function setExtra( $extra )
85 $this->mExtra
= $extra;
90 if ( $this->mTitle
=== false ) {
91 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
96 function getMovedToTitle()
98 if ( $this->mMovedToTitle
=== false ) {
99 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
100 $this->mAttribs
['rc_moved_to_title'] );
102 return $this->mMovedToTitle
;
105 # Writes the data in this object to the database
108 global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix, $wgUseRCPatrol;
109 $fname = 'RecentChange::save';
111 $dbw =& wfGetDB( DB_MASTER
);
112 if ( !is_array($this->mExtra
) ) {
113 $this->mExtra
= array();
115 $this->mExtra
['lang'] = $wgLocalInterwiki;
117 if ( !$wgPutIPinRC ) {
118 $this->mAttribs
['rc_ip'] = '';
121 # Fixup database timestamps
122 $this->mAttribs
['rc_timestamp'] = $dbw->timestamp($this->mAttribs
['rc_timestamp']);
123 $this->mAttribs
['rc_cur_time'] = $dbw->timestamp($this->mAttribs
['rc_cur_time']);
124 $this->mAttribs
['rc_id'] = $dbw->nextSequenceValue( 'rc_rc_id_seq' );
127 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
129 if ( $wgUseRCPatrol ) {
130 # Retrieve the id assigned by the db, but only if we'll use it later
131 $this->mAttribs
['rc_id'] = $dbw->insertId();
134 # Update old rows, if necessary
135 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
136 $lastTime = $this->mExtra
['lastTimestamp'];
137 #$now = $this->mAttribs['rc_timestamp'];
138 #$curId = $this->mAttribs['rc_cur_id'];
140 # Don't bother looking for entries that have probably
141 # been purged, it just locks up the indexes needlessly.
143 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
144 if( $age < $wgRCMaxAge ) {
145 # live hack, will commit once tested - kate
146 # Update rc_this_oldid for the entries which were current
148 #$oldid = $this->mAttribs['rc_last_oldid'];
149 #$ns = $this->mAttribs['rc_namespace'];
150 #$title = $this->mAttribs['rc_title'];
152 #$dbw->update( 'recentchanges',
154 # 'rc_this_oldid' => $oldid
155 # ), array( /* WHERE */
156 # 'rc_namespace' => $ns,
157 # 'rc_title' => $title,
158 # 'rc_timestamp' => $dbw->timestamp( $lastTime )
164 #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
165 # array( 'rc_cur_id' => $curId ), $fname );
168 # Notify external application via UDP
169 if ( $wgRC2UDPAddress ) {
170 $conn = socket_create( AF_INET
, SOCK_DGRAM
, SOL_UDP
);
172 $line = $wgRC2UDPPrefix . $this->getIRCLine();
173 socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
174 socket_close( $conn );
178 // E-mail notifications
181 # this would be better as an extension hook
182 include_once( "UserMailer.php" );
183 $enotif = new EmailNotification();
184 $title = Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
185 $enotif->notifyOnPageChange( $title,
186 $this->mAttribs
['rc_timestamp'],
187 $this->mAttribs
['rc_comment'],
188 $this->mAttribs
['rc_minor'],
189 $this->mAttribs
['rc_last_oldid'] );
194 # Marks a certain row as patrolled
195 function markPatrolled( $rcid )
197 $fname = 'RecentChange::markPatrolled';
199 $dbw =& wfGetDB( DB_MASTER
);
201 $dbw->update( 'recentchanges',
204 ), array( /* WHERE */
210 # Makes an entry in the database corresponding to an edit
211 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
212 $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0,
215 if ( $bot == 'default ' ) {
216 $bot = $user->isBot();
226 $rc = new RecentChange
;
227 $rc->mAttribs
= array(
228 'rc_timestamp' => $timestamp,
229 'rc_cur_time' => $timestamp,
230 'rc_namespace' => $title->getNamespace(),
231 'rc_title' => $title->getDBkey(),
232 'rc_type' => RC_EDIT
,
233 'rc_minor' => $minor ?
1 : 0,
234 'rc_cur_id' => $title->getArticleID(),
235 'rc_user' => $user->getID(),
236 'rc_user_text' => $user->getName(),
237 'rc_comment' => $comment,
238 'rc_this_oldid' => $newId,
239 'rc_last_oldid' => $oldId,
240 'rc_bot' => $bot ?
1 : 0,
241 'rc_moved_to_ns' => 0,
242 'rc_moved_to_title' => '',
245 'rc_new' => 0 # obsolete
249 'prefixedDBkey' => $title->getPrefixedDBkey(),
250 'lastTimestamp' => $lastTimestamp,
251 'oldSize' => $oldSize,
252 'newSize' => $newSize,
257 # Makes an entry in the database corresponding to page creation
258 # Note: the title object must be loaded with the new id using resetArticleID()
259 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
260 $ip='', $size = 0, $newId = 0 )
268 if ( $bot == 'default' ) {
269 $bot = $user->isBot();
272 $rc = new RecentChange
;
273 $rc->mAttribs
= array(
274 'rc_timestamp' => $timestamp,
275 'rc_cur_time' => $timestamp,
276 'rc_namespace' => $title->getNamespace(),
277 'rc_title' => $title->getDBkey(),
279 'rc_minor' => $minor ?
1 : 0,
280 'rc_cur_id' => $title->getArticleID(),
281 'rc_user' => $user->getID(),
282 'rc_user_text' => $user->getName(),
283 'rc_comment' => $comment,
284 'rc_this_oldid' => $newId,
285 'rc_last_oldid' => 0,
286 'rc_bot' => $bot ?
1 : 0,
287 'rc_moved_to_ns' => 0,
288 'rc_moved_to_title' => '',
291 'rc_new' => 1 # obsolete
295 'prefixedDBkey' => $title->getPrefixedDBkey(),
296 'lastTimestamp' => 0,
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->isBot() ?
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='' )
362 $rc = new RecentChange
;
363 $rc->mAttribs
= array(
364 'rc_timestamp' => $timestamp,
365 'rc_cur_time' => $timestamp,
366 'rc_namespace' => $title->getNamespace(),
367 'rc_title' => $title->getDBkey(),
370 'rc_cur_id' => $title->getArticleID(),
371 'rc_user' => $user->getID(),
372 'rc_user_text' => $user->getName(),
373 'rc_comment' => $comment,
374 'rc_this_oldid' => 0,
375 'rc_last_oldid' => 0,
376 'rc_bot' => $user->isBot() ?
1 : 0,
377 'rc_moved_to_ns' => 0,
378 'rc_moved_to_title' => '',
381 'rc_new' => 0 # obsolete
384 'prefixedDBkey' => $title->getPrefixedDBkey(),
390 # Initialises the members of this object from a mysql row object
391 function loadFromRow( $row )
393 $this->mAttribs
= get_object_vars( $row );
394 $this->mAttribs
["rc_timestamp"] = wfTimestamp(TS_MW
, $this->mAttribs
["rc_timestamp"]);
395 $this->mExtra
= array();
398 # Makes a pseudo-RC entry from a cur row, for watchlists and things
399 function loadFromCurRow( $row )
401 $this->mAttribs
= array(
402 'rc_timestamp' => wfTimestamp(TS_MW
, $row->rev_timestamp
),
403 'rc_cur_time' => $row->rev_timestamp
,
404 'rc_user' => $row->rev_user
,
405 'rc_user_text' => $row->rev_user_text
,
406 'rc_namespace' => $row->page_namespace
,
407 'rc_title' => $row->page_title
,
408 'rc_comment' => $row->rev_comment
,
409 'rc_minor' => $row->rev_minor_edit ?
1 : 0,
410 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
411 'rc_cur_id' => $row->page_id
,
412 'rc_this_oldid' => $row->rev_id
,
413 'rc_last_oldid' => isset($row->rc_last_oldid
) ?
$row->rc_last_oldid
: 0,
415 'rc_moved_to_ns' => 0,
416 'rc_moved_to_title' => '',
418 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
419 # currently because it uses cur, not recentchanges
420 'rc_new' => $row->page_is_new
# obsolete
423 $this->mExtra
= array();
428 * Gets the end part of the diff URL associated with this object
429 * Blank if no diff link should be displayed
431 function diffLinkTrail( $forceCur )
433 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
434 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
435 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
437 $trail .= '&diff=0' ;
439 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);
447 function getIRCLine() {
448 global $wgUseRCPatrol;
450 extract($this->mAttribs
);
451 extract($this->mExtra
);
453 $titleObj =& $this->getTitle();
455 $bad = array("\n", "\r");
456 $empty = array("", "");
457 $title = $titleObj->getPrefixedText();
458 $title = str_replace($bad, $empty, $title);
460 if ( $rc_new && $wgUseRCPatrol ) {
461 $url = $titleObj->getFullURL("rcid=$rc_id");
462 } else if ( $rc_new ) {
463 $url = $titleObj->getFullURL();
464 } else if ( $wgUseRCPatrol ) {
465 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid&rcid=$rc_id");
467 $url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid");
470 if ( isset( $oldSize ) && isset( $newSize ) ) {
471 $szdiff = $newSize - $oldSize;
472 if ($szdiff < -500) {
473 $szdiff = "\002$szdiff\002";
474 } elseif ($szdiff >= 0) {
475 $szdiff = '+' . $szdiff ;
477 $szdiff = '(' . $szdiff . ')' ;
482 $comment = str_replace($bad, $empty, $rc_comment);
483 $user = str_replace($bad, $empty, $rc_user_text);
484 $flag = ($rc_minor ?
"M" : "") . ($rc_new ?
"N" : "");
485 # see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003,
486 # no colour (\003) switches back to the term default
487 $comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
488 $fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
489 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";