0a79228043e0e45b24349576c6d4b9e0f8081e6f
10 define( 'RC_EDIT', 0);
12 define( 'RC_MOVE', 2);
14 define( 'RC_MOVE_OVER_REDIRECT', 4);
15 define( "RC_EDIT_COMMENT", 5);
19 * Utility class for creating new RC entries
21 * rc_id id of the row in the recentchanges table
22 * rc_timestamp time the entry was made
23 * rc_cur_time timestamp on the cur row
24 * rc_namespace namespace #
25 * rc_title non-prefixed db key
26 * rc_type is new entry, used to determine whether updating is necessary
28 * rc_cur_id id of associated cur entry
29 * rc_user user id who made the entry
30 * rc_user_text user name who made the entry
31 * rc_comment edit summary
32 * rc_this_oldid old_id associated with this entry (or zero)
33 * rc_last_oldid old_id associated with the entry before this one (or zero)
34 * rc_bot is bot, hidden
35 * rc_ip IP address of the user in dotted quad notation
36 * rc_new obsolete, use rc_type==RC_NEW
37 * rc_patrolled boolean whether or not someone has marked this edit as patrolled
40 * prefixedDBkey prefixed db key, used by external app via msg queue
41 * lastTimestamp timestamp of previous entry, used in WHERE clause during update
42 * lang the interwiki prefix, automatically set in save()
44 * @todo document functions and variables
49 var $mAttribs = array(), $mExtra = array();
50 var $mTitle = false, $mMovedToTitle = false;
54 /* static */ function newFromRow( $row )
56 $rc = new RecentChange
;
57 $rc->loadFromRow( $row );
61 /* static */ function newFromCurRow( $row )
63 $rc = new RecentChange
;
64 $rc->loadFromCurRow( $row );
70 function setAttribs( $attribs )
72 $this->mAttribs
= $attribs;
75 function setExtra( $extra )
77 $this->mExtra
= $extra;
82 if ( $this->mTitle
=== false ) {
83 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
88 function getMovedToTitle()
90 if ( $this->mMovedToTitle
=== false ) {
91 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
92 $this->mAttribs
['rc_moved_to_title'] );
94 return $this->mMovedToTitle
;
97 # Writes the data in this object to the database
100 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC;
101 $fname = 'RecentChange::save';
103 $dbw =& wfGetDB( DB_MASTER
);
104 if ( !is_array($this->mExtra
) ) {
105 $this->mExtra
= array();
107 $this->mExtra
['lang'] = $wgLocalInterwiki;
109 if ( !$wgPutIPinRC ) {
110 $this->mAttribs
['rc_ip'] = '';
113 # Fixup database timestamps
114 $this->mAttribs
['rc_timestamp']=$dbw->timestamp($this->mAttribs
['rc_timestamp']);
115 $this->mAttribs
['rc_cur_time']=$dbw->timestamp($this->mAttribs
['rc_cur_time']);
118 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
120 # Update old rows, if necessary
121 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
122 $oldid = $this->mAttribs
['rc_last_oldid'];
123 $ns = $this->mAttribs
['rc_namespace'];
124 $title = $this->mAttribs
['rc_title'];
125 $lastTime = $this->mExtra
['lastTimestamp'];
126 $now = $this->mAttribs
['rc_timestamp'];
127 $curId = $this->mAttribs
['rc_cur_id'];
129 # Update rc_this_oldid for the entries which were current
130 $dbw->update( 'recentchanges',
132 'rc_this_oldid' => $oldid
133 ), array( /* WHERE */
134 'rc_namespace' => $ns,
135 'rc_title' => $title,
136 'rc_timestamp' => $dbw->timestamp($lastTime)
141 $dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
142 array( 'rc_cur_id' => $curId ), $fname );
145 # Notify external application
146 if ( $wgUseRCQueue ) {
147 $queue = msg_get_queue( $wgRCQueueID );
148 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
149 true, false, $error ))
151 wfDebug( "Error sending message to RC queue, code $error\n" );
156 # Marks a certain row as patrolled
157 function markPatrolled( $rcid )
159 $fname = 'RecentChange::markPatrolled';
161 $dbw =& wfGetDB( DB_MASTER
);
163 $dbw->update( 'recentchanges',
166 ), array( /* WHERE */
172 # Makes an entry in the database corresponding to an edit
173 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
174 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
176 if ( $bot == 'default ' ) {
177 $bot = $user->isBot();
182 $ip = empty( $wgIP ) ?
'' : $wgIP;
185 $rc = new RecentChange
;
186 $rc->mAttribs
= array(
187 'rc_timestamp' => $timestamp,
188 'rc_cur_time' => $timestamp,
189 'rc_namespace' => $title->getNamespace(),
190 'rc_title' => $title->getDBkey(),
191 'rc_type' => RC_EDIT
,
192 'rc_minor' => $minor ?
1 : 0,
193 'rc_cur_id' => $title->getArticleID(),
194 'rc_user' => $user->getID(),
195 'rc_user_text' => $user->getName(),
196 'rc_comment' => $comment,
197 'rc_this_oldid' => 0,
198 'rc_last_oldid' => $oldId,
199 'rc_bot' => $bot ?
1 : 0,
200 'rc_moved_to_ns' => 0,
201 'rc_moved_to_title' => '',
204 'rc_new' => 0 # obsolete
208 'prefixedDBkey' => $title->getPrefixedDBkey(),
209 'lastTimestamp' => $lastTimestamp
214 # Makes an entry in the database corresponding to page creation
215 # Note: the title object must be loaded with the new id using resetArticleID()
216 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
220 $ip = empty( $wgIP ) ?
'' : $wgIP;
222 if ( $bot == 'default' ) {
223 $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(),
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' => 0,
239 'rc_last_oldid' => 0,
240 'rc_bot' => $bot ?
1 : 0,
241 'rc_moved_to_ns' => 0,
242 'rc_moved_to_title' => '',
245 'rc_new' => 1 # obsolete
249 'prefixedDBkey' => $title->getPrefixedDBkey(),
255 # Makes an entry in the database corresponding to a rename
256 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
260 $ip = empty( $wgIP ) ?
'' : $wgIP;
262 $rc = new RecentChange
;
263 $rc->mAttribs
= array(
264 'rc_timestamp' => $timestamp,
265 'rc_cur_time' => $timestamp,
266 'rc_namespace' => $oldTitle->getNamespace(),
267 'rc_title' => $oldTitle->getDBkey(),
268 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
270 'rc_cur_id' => $oldTitle->getArticleID(),
271 'rc_user' => $user->getID(),
272 'rc_user_text' => $user->getName(),
273 'rc_comment' => $comment,
274 'rc_this_oldid' => 0,
275 'rc_last_oldid' => 0,
276 'rc_bot' => $user->isBot() ?
1 : 0,
277 'rc_moved_to_ns' => $newTitle->getNamespace(),
278 'rc_moved_to_title' => $newTitle->getDBkey(),
280 'rc_new' => 0, # obsolete
285 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
286 'lastTimestamp' => 0,
287 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
292 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
293 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
296 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
297 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
300 # A log entry is different to an edit in that previous revisions are
302 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
306 $ip = empty( $wgIP ) ?
'' : $wgIP;
308 $rc = new RecentChange
;
309 $rc->mAttribs
= array(
310 'rc_timestamp' => $timestamp,
311 'rc_cur_time' => $timestamp,
312 'rc_namespace' => $title->getNamespace(),
313 'rc_title' => $title->getDBkey(),
316 'rc_cur_id' => $title->getArticleID(),
317 'rc_user' => $user->getID(),
318 'rc_user_text' => $user->getName(),
319 'rc_comment' => $comment,
320 'rc_this_oldid' => 0,
321 'rc_last_oldid' => 0,
323 'rc_moved_to_ns' => 0,
324 'rc_moved_to_title' => '',
327 'rc_new' => 0 # obsolete
330 'prefixedDBkey' => $title->getPrefixedDBkey(),
336 # Makes an entry in the database corresponding to editing a comment.
337 # Note: This code saves the old comment in 'rc_moved_to_title', which is only used
338 # for logging move operations.
339 /*static*/ function notifyEditComment( $timestamp, &$title, $minor, &$user, $comment, $oldComment,
340 $revId, $lastTimestamp, $ip = '' )
344 $ip = empty( $wgIP ) ?
'' : $wgIP;
347 $rc = new RecentChange
;
348 $rc->mAttribs
= array(
349 'rc_timestamp' => $timestamp,
350 'rc_cur_time' => $timestamp,
351 'rc_namespace' => $title->getNamespace(),
352 'rc_title' => $title->getDBkey(),
353 'rc_type' => RC_EDIT_COMMENT
,
354 'rc_minor' => $minor ?
1 : 0,
355 'rc_cur_id' => $title->getArticleID(),
356 'rc_user' => $user->getID(),
357 'rc_user_text' => $user->getName(),
358 'rc_comment' => $comment,
359 'rc_this_oldid' => $revId,
360 'rc_last_oldid' => 0,
362 'rc_moved_to_ns' => 0,
363 'rc_moved_to_title' => $oldComment,
366 'rc_new' => 0 # obsolete
370 'prefixedDBkey' => $title->getPrefixedDBkey(),
371 'lastTimestamp' => $lastTimestamp
376 # Initialises the members of this object from a mysql row object
377 function loadFromRow( $row )
379 $this->mAttribs
= get_object_vars( $row );
380 $this->mExtra
= array();
383 # Makes a pseudo-RC entry from a cur row, for watchlists and things
384 function loadFromCurRow( $row )
386 $this->mAttribs
= array(
387 'rc_timestamp' => $row->cur_timestamp
,
388 'rc_cur_time' => $row->cur_timestamp
,
389 'rc_user' => $row->cur_user
,
390 'rc_user_text' => $row->cur_user_text
,
391 'rc_namespace' => $row->cur_namespace
,
392 'rc_title' => $row->cur_title
,
393 'rc_comment' => $row->cur_comment
,
394 'rc_minor' => !!$row->cur_minor_edit
,
395 'rc_type' => $row->cur_is_new ? RC_NEW
: RC_EDIT
,
396 'rc_cur_id' => $row->cur_id
,
397 'rc_this_oldid' => 0,
398 'rc_last_oldid' => 0,
400 'rc_moved_to_ns' => 0,
401 'rc_moved_to_title' => '',
403 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
404 # currently because it uses cur, not recentchanges
405 'rc_new' => $row->cur_is_new
# obsolete
408 $this->mExtra
= array();
413 * Gets the end part of the diff URL assoicated with this object
414 * Blank if no diff link should be displayed
416 function diffLinkTrail( $forceCur )
418 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
419 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
420 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
422 $trail .= '&diff=0' ;
424 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);