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 * temporary: not stored in the database
44 * notificationtimestamp
45 * numberofWatchingusers
47 * @todo document functions and variables
52 var $mAttribs = array(), $mExtra = array();
53 var $mTitle = false, $mMovedToTitle = false;
57 /* static */ function newFromRow( $row )
59 $rc = new RecentChange
;
60 $rc->loadFromRow( $row );
64 /* static */ function newFromCurRow( $row )
66 $rc = new RecentChange
;
67 $rc->loadFromCurRow( $row );
68 $rc->notificationtimestamp
= false;
69 $rc->numberofWatchingusers
= false;
75 function setAttribs( $attribs )
77 $this->mAttribs
= $attribs;
80 function setExtra( $extra )
82 $this->mExtra
= $extra;
87 if ( $this->mTitle
=== false ) {
88 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
93 function getMovedToTitle()
95 if ( $this->mMovedToTitle
=== false ) {
96 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
97 $this->mAttribs
['rc_moved_to_title'] );
99 return $this->mMovedToTitle
;
102 # Writes the data in this object to the database
105 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC;
106 $fname = 'RecentChange::save';
108 $dbw =& wfGetDB( DB_MASTER
);
109 if ( !is_array($this->mExtra
) ) {
110 $this->mExtra
= array();
112 $this->mExtra
['lang'] = $wgLocalInterwiki;
114 if ( !$wgPutIPinRC ) {
115 $this->mAttribs
['rc_ip'] = '';
118 # Fixup database timestamps
119 $this->mAttribs
['rc_timestamp']=$dbw->timestamp($this->mAttribs
['rc_timestamp']);
120 $this->mAttribs
['rc_cur_time']=$dbw->timestamp($this->mAttribs
['rc_cur_time']);
123 $dbw->insert( 'recentchanges', $this->mAttribs
, $fname );
125 # Update old rows, if necessary
126 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
127 $oldid = $this->mAttribs
['rc_last_oldid'];
128 $ns = $this->mAttribs
['rc_namespace'];
129 $title = $this->mAttribs
['rc_title'];
130 $lastTime = $this->mExtra
['lastTimestamp'];
131 $now = $this->mAttribs
['rc_timestamp'];
132 $curId = $this->mAttribs
['rc_cur_id'];
134 # Update rc_this_oldid for the entries which were current
135 $dbw->update( 'recentchanges',
137 'rc_this_oldid' => $oldid
138 ), array( /* WHERE */
139 'rc_namespace' => $ns,
140 'rc_title' => $title,
141 'rc_timestamp' => $dbw->timestamp($lastTime)
146 $dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
147 array( 'rc_cur_id' => $curId ), $fname );
150 # Notify external application
151 if ( $wgUseRCQueue ) {
152 $queue = msg_get_queue( $wgRCQueueID );
153 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
154 true, false, $error ))
156 wfDebug( "Error sending message to RC queue, code $error\n" );
161 # Marks a certain row as patrolled
162 function markPatrolled( $rcid )
164 $fname = 'RecentChange::markPatrolled';
166 $dbw =& wfGetDB( DB_MASTER
);
168 $dbw->update( 'recentchanges',
171 ), array( /* WHERE */
177 # Makes an entry in the database corresponding to an edit
178 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
179 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
181 if ( $bot == 'default ' ) {
182 $bot = $user->isBot();
187 $ip = empty( $wgIP ) ?
'' : $wgIP;
190 $rc = new RecentChange
;
191 $rc->mAttribs
= array(
192 'rc_timestamp' => $timestamp,
193 'rc_cur_time' => $timestamp,
194 'rc_namespace' => $title->getNamespace(),
195 'rc_title' => $title->getDBkey(),
196 'rc_type' => RC_EDIT
,
197 'rc_minor' => $minor ?
1 : 0,
198 'rc_cur_id' => $title->getArticleID(),
199 'rc_user' => $user->getID(),
200 'rc_user_text' => $user->getName(),
201 'rc_comment' => $comment,
202 'rc_this_oldid' => 0,
203 'rc_last_oldid' => $oldId,
204 'rc_bot' => $bot ?
1 : 0,
205 'rc_moved_to_ns' => 0,
206 'rc_moved_to_title' => '',
209 'rc_new' => 0 # obsolete
213 'prefixedDBkey' => $title->getPrefixedDBkey(),
214 'lastTimestamp' => $lastTimestamp
219 # Makes an entry in the database corresponding to page creation
220 # Note: the title object must be loaded with the new id using resetArticleID()
221 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
225 $ip = empty( $wgIP ) ?
'' : $wgIP;
227 if ( $bot == 'default' ) {
228 $bot = $user->isBot();
231 $rc = new RecentChange
;
232 $rc->mAttribs
= array(
233 'rc_timestamp' => $timestamp,
234 'rc_cur_time' => $timestamp,
235 'rc_namespace' => $title->getNamespace(),
236 'rc_title' => $title->getDBkey(),
238 'rc_minor' => $minor ?
1 : 0,
239 'rc_cur_id' => $title->getArticleID(),
240 'rc_user' => $user->getID(),
241 'rc_user_text' => $user->getName(),
242 'rc_comment' => $comment,
243 'rc_this_oldid' => 0,
244 'rc_last_oldid' => 0,
245 'rc_bot' => $bot ?
1 : 0,
246 'rc_moved_to_ns' => 0,
247 'rc_moved_to_title' => '',
250 'rc_new' => 1 # obsolete
254 'prefixedDBkey' => $title->getPrefixedDBkey(),
260 # Makes an entry in the database corresponding to a rename
261 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
265 $ip = empty( $wgIP ) ?
'' : $wgIP;
267 $rc = new RecentChange
;
268 $rc->mAttribs
= array(
269 'rc_timestamp' => $timestamp,
270 'rc_cur_time' => $timestamp,
271 'rc_namespace' => $oldTitle->getNamespace(),
272 'rc_title' => $oldTitle->getDBkey(),
273 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
275 'rc_cur_id' => $oldTitle->getArticleID(),
276 'rc_user' => $user->getID(),
277 'rc_user_text' => $user->getName(),
278 'rc_comment' => $comment,
279 'rc_this_oldid' => 0,
280 'rc_last_oldid' => 0,
281 'rc_bot' => $user->isBot() ?
1 : 0,
282 'rc_moved_to_ns' => $newTitle->getNamespace(),
283 'rc_moved_to_title' => $newTitle->getDBkey(),
285 'rc_new' => 0, # obsolete
290 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
291 'lastTimestamp' => 0,
292 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
297 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
298 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
301 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
302 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
305 # A log entry is different to an edit in that previous revisions are
307 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
311 $ip = empty( $wgIP ) ?
'' : $wgIP;
313 $rc = new RecentChange
;
314 $rc->mAttribs
= array(
315 'rc_timestamp' => $timestamp,
316 'rc_cur_time' => $timestamp,
317 'rc_namespace' => $title->getNamespace(),
318 'rc_title' => $title->getDBkey(),
321 'rc_cur_id' => $title->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,
328 'rc_moved_to_ns' => 0,
329 'rc_moved_to_title' => '',
332 'rc_new' => 0 # obsolete
335 'prefixedDBkey' => $title->getPrefixedDBkey(),
341 # Initialises the members of this object from a mysql row object
342 function loadFromRow( $row )
344 $this->mAttribs
= get_object_vars( $row );
345 $this->mExtra
= array();
348 # Makes a pseudo-RC entry from a cur row, for watchlists and things
349 function loadFromCurRow( $row )
351 $this->mAttribs
= array(
352 'rc_timestamp' => $row->rev_timestamp
,
353 'rc_cur_time' => $row->rev_timestamp
,
354 'rc_user' => $row->rev_user
,
355 'rc_user_text' => $row->rev_user_text
,
356 'rc_namespace' => $row->page_namespace
,
357 'rc_title' => $row->page_title
,
358 'rc_comment' => $row->rev_comment
,
359 'rc_minor' => !!$row->rev_minor_edit
,
360 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
361 'rc_cur_id' => $row->page_id
,
362 'rc_this_oldid' => 0,
363 'rc_last_oldid' => 0,
365 'rc_moved_to_ns' => 0,
366 'rc_moved_to_title' => '',
368 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
369 # currently because it uses cur, not recentchanges
370 'rc_new' => $row->page_is_new
# obsolete
373 $this->mExtra
= array();
378 * Gets the end part of the diff URL assoicated with this object
379 * Blank if no diff link should be displayed
381 function diffLinkTrail( $forceCur )
383 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
384 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
385 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
387 $trail .= '&diff=0' ;
389 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);