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 id of associated cur 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 old_id associated with this entry (or zero)
32 * rc_last_oldid old_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()
43 * @todo document functions and variables
48 var $mAttribs = array(), $mExtra = array();
49 var $mTitle = false, $mMovedToTitle = false;
53 /* static */ function newFromRow( $row )
55 $rc = new RecentChange
;
56 $rc->loadFromRow( $row );
60 /* static */ function newFromCurRow( $row )
62 $rc = new RecentChange
;
63 $rc->loadFromCurRow( $row );
69 function setAttribs( $attribs )
71 $this->mAttribs
= $attribs;
74 function setExtra( $extra )
76 $this->mExtra
= $extra;
81 if ( $this->mTitle
=== false ) {
82 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
87 function getMovedToTitle()
89 if ( $this->mMovedToTitle
=== false ) {
90 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
91 $this->mAttribs
['rc_moved_to_title'] );
93 return $this->mMovedToTitle
;
96 # Writes the data in this object to the database
99 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC;
100 $fname = 'RecentChange::save';
102 $dbw =& wfGetDB( DB_MASTER
);
103 if ( !is_array($this->mExtra
) ) {
104 $this->mExtra
= array();
106 $this->mExtra
['lang'] = $wgLocalInterwiki;
108 if ( !$wgPutIPinRC ) {
109 $this->mAttribs
['rc_ip'] = '';
112 # Fixup database timestamps
113 $this->mAttribs
['rc_timestamp']=$dbw->timestamp($this->mAttribs
['rc_timestamp']);
114 $this->mAttribs
['rc_cur_time']=$dbw->timestamp($this->mAttribs
['rc_cur_time']);
117 $dbw->insertArray( 'recentchanges', $this->mAttribs
, $fname );
119 # Update old rows, if necessary
120 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
121 $oldid = $this->mAttribs
['rc_last_oldid'];
122 $ns = $this->mAttribs
['rc_namespace'];
123 $title = $this->mAttribs
['rc_title'];
124 $lastTime = $this->mExtra
['lastTimestamp'];
125 $now = $this->mAttribs
['rc_timestamp'];
126 $curId = $this->mAttribs
['rc_cur_id'];
128 # Update rc_this_oldid for the entries which were current
129 $dbw->updateArray( 'recentchanges',
131 'rc_this_oldid' => $oldid
132 ), array( /* WHERE */
133 'rc_namespace' => $ns,
134 'rc_title' => $title,
135 'rc_timestamp' => $dbw->timestamp($lastTime)
140 $dbw->updateArray( 'recentchanges', array( 'rc_cur_time' => $now ),
141 array( 'rc_cur_id' => $curId ), $fname );
144 # Notify external application
145 if ( $wgUseRCQueue ) {
146 $queue = msg_get_queue( $wgRCQueueID );
147 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
148 true, false, $error ))
150 wfDebug( "Error sending message to RC queue, code $error\n" );
155 # Marks a certain row as patrolled
156 function markPatrolled( $rcid )
158 $fname = 'RecentChange::markPatrolled';
160 $dbw =& wfGetDB( DB_MASTER
);
162 $dbw->updateArray( 'recentchanges',
165 ), array( /* WHERE */
171 # Makes an entry in the database corresponding to an edit
172 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
173 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
175 if ( $bot == 'default ' ) {
176 $bot = $user->isBot();
181 $ip = empty( $wgIP ) ?
'' : $wgIP;
184 $rc = new RecentChange
;
185 $rc->mAttribs
= array(
186 'rc_timestamp' => $timestamp,
187 'rc_cur_time' => $timestamp,
188 'rc_namespace' => $title->getNamespace(),
189 'rc_title' => $title->getDBkey(),
190 'rc_type' => RC_EDIT
,
191 'rc_minor' => $minor ?
1 : 0,
192 'rc_cur_id' => $title->getArticleID(),
193 'rc_user' => $user->getID(),
194 'rc_user_text' => $user->getName(),
195 'rc_comment' => $comment,
196 'rc_this_oldid' => 0,
197 'rc_last_oldid' => $oldId,
198 'rc_bot' => $bot ?
1 : 0,
199 'rc_moved_to_ns' => 0,
200 'rc_moved_to_title' => '',
202 'rc_new' => 0 # obsolete
206 'prefixedDBkey' => $title->getPrefixedDBkey(),
207 'lastTimestamp' => $lastTimestamp
212 # Makes an entry in the database corresponding to page creation
213 # Note: the title object must be loaded with the new id using resetArticleID()
214 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
218 $ip = empty( $wgIP ) ?
'' : $wgIP;
220 if ( $bot == 'default' ) {
221 $bot = $user->isBot();
224 $rc = new RecentChange
;
225 $rc->mAttribs
= array(
226 'rc_timestamp' => $timestamp,
227 'rc_cur_time' => $timestamp,
228 'rc_namespace' => $title->getNamespace(),
229 'rc_title' => $title->getDBkey(),
231 'rc_minor' => $minor ?
1 : 0,
232 'rc_cur_id' => $title->getArticleID(),
233 'rc_user' => $user->getID(),
234 'rc_user_text' => $user->getName(),
235 'rc_comment' => $comment,
236 'rc_this_oldid' => 0,
237 'rc_last_oldid' => 0,
238 'rc_bot' => $bot ?
1 : 0,
239 'rc_moved_to_ns' => 0,
240 'rc_moved_to_title' => '',
242 'rc_new' => 1 # obsolete
246 'prefixedDBkey' => $title->getPrefixedDBkey(),
252 # Makes an entry in the database corresponding to a rename
253 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
257 $ip = empty( $wgIP ) ?
'' : $wgIP;
259 $rc = new RecentChange
;
260 $rc->mAttribs
= array(
261 'rc_timestamp' => $timestamp,
262 'rc_cur_time' => $timestamp,
263 'rc_namespace' => $oldTitle->getNamespace(),
264 'rc_title' => $oldTitle->getDBkey(),
265 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
267 'rc_cur_id' => $oldTitle->getArticleID(),
268 'rc_user' => $user->getID(),
269 'rc_user_text' => $user->getName(),
270 'rc_comment' => $comment,
271 'rc_this_oldid' => 0,
272 'rc_last_oldid' => 0,
273 'rc_bot' => $user->isBot() ?
1 : 0,
274 'rc_moved_to_ns' => $newTitle->getNamespace(),
275 'rc_moved_to_title' => $newTitle->getDBkey(),
277 'rc_new' => 0, # obsolete
282 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
283 'lastTimestamp' => 0,
284 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
289 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
290 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
293 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
294 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
297 # A log entry is different to an edit in that previous revisions are
299 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
303 $ip = empty( $wgIP ) ?
'' : $wgIP;
305 $rc = new RecentChange
;
306 $rc->mAttribs
= array(
307 'rc_timestamp' => $timestamp,
308 'rc_cur_time' => $timestamp,
309 'rc_namespace' => $title->getNamespace(),
310 'rc_title' => $title->getDBkey(),
313 'rc_cur_id' => $title->getArticleID(),
314 'rc_user' => $user->getID(),
315 'rc_user_text' => $user->getName(),
316 'rc_comment' => $comment,
317 'rc_this_oldid' => 0,
318 'rc_last_oldid' => 0,
320 'rc_moved_to_ns' => 0,
321 'rc_moved_to_title' => '',
324 'rc_new' => 0 # obsolete
327 'prefixedDBkey' => $title->getPrefixedDBkey(),
333 # Initialises the members of this object from a mysql row object
334 function loadFromRow( $row )
336 $this->mAttribs
= get_object_vars( $row );
337 $this->mExtra
= array();
340 # Makes a pseudo-RC entry from a cur row, for watchlists and things
341 function loadFromCurRow( $row )
343 $this->mAttribs
= array(
344 'rc_timestamp' => $row->cur_timestamp
,
345 'rc_cur_time' => $row->cur_timestamp
,
346 'rc_user' => $row->cur_user
,
347 'rc_user_text' => $row->cur_user_text
,
348 'rc_namespace' => $row->cur_namespace
,
349 'rc_title' => $row->cur_title
,
350 'rc_comment' => $row->cur_comment
,
351 'rc_minor' => !!$row->cur_minor_edit
,
352 'rc_type' => $row->cur_is_new ? RC_NEW
: RC_EDIT
,
353 'rc_cur_id' => $row->cur_id
,
354 'rc_this_oldid' => 0,
355 'rc_last_oldid' => 0,
357 'rc_moved_to_ns' => 0,
358 'rc_moved_to_title' => '',
360 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
361 # currently because it uses cur, not recentchanges
362 'rc_new' => $row->cur_is_new
# obsolete
365 $this->mExtra
= array();
370 * Gets the end part of the diff URL assoicated with this object
371 * Blank if no diff link should be displayed
373 function diffLinkTrail( $forceCur )
375 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
376 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
377 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
379 $trail .= '&diff=0' ;
381 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);