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 # Don't bother looking for entries that have probably
135 # been purged, it just locks up the indexes needlessly.
137 $age = time() - wfTimestamp( TS_UNIX
, $lastTime );
138 if( $age < $wgRCMaxAge ) {
139 # Update rc_this_oldid for the entries which were current
140 $dbw->update( 'recentchanges',
142 'rc_this_oldid' => $oldid
143 ), array( /* WHERE */
144 'rc_namespace' => $ns,
145 'rc_title' => $title,
146 'rc_timestamp' => $dbw->timestamp( $lastTime )
152 $dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
153 array( 'rc_cur_id' => $curId ), $fname );
156 # Notify external application
157 if ( $wgUseRCQueue ) {
158 $queue = msg_get_queue( $wgRCQueueID );
159 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
160 true, false, $error ))
162 wfDebug( "Error sending message to RC queue, code $error\n" );
167 # Marks a certain row as patrolled
168 function markPatrolled( $rcid )
170 $fname = 'RecentChange::markPatrolled';
172 $dbw =& wfGetDB( DB_MASTER
);
174 $dbw->update( 'recentchanges',
177 ), array( /* WHERE */
183 # Makes an entry in the database corresponding to an edit
184 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
185 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
187 if ( $bot == 'default ' ) {
188 $bot = $user->isBot();
193 $ip = empty( $wgIP ) ?
'' : $wgIP;
196 $rc = new RecentChange
;
197 $rc->mAttribs
= array(
198 'rc_timestamp' => $timestamp,
199 'rc_cur_time' => $timestamp,
200 'rc_namespace' => $title->getNamespace(),
201 'rc_title' => $title->getDBkey(),
202 'rc_type' => RC_EDIT
,
203 'rc_minor' => $minor ?
1 : 0,
204 'rc_cur_id' => $title->getArticleID(),
205 'rc_user' => $user->getID(),
206 'rc_user_text' => $user->getName(),
207 'rc_comment' => $comment,
208 'rc_this_oldid' => 0,
209 'rc_last_oldid' => $oldId,
210 'rc_bot' => $bot ?
1 : 0,
211 'rc_moved_to_ns' => 0,
212 'rc_moved_to_title' => '',
215 'rc_new' => 0 # obsolete
219 'prefixedDBkey' => $title->getPrefixedDBkey(),
220 'lastTimestamp' => $lastTimestamp
225 # Makes an entry in the database corresponding to page creation
226 # Note: the title object must be loaded with the new id using resetArticleID()
227 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
231 $ip = empty( $wgIP ) ?
'' : $wgIP;
233 if ( $bot == 'default' ) {
234 $bot = $user->isBot();
237 $rc = new RecentChange
;
238 $rc->mAttribs
= array(
239 'rc_timestamp' => $timestamp,
240 'rc_cur_time' => $timestamp,
241 'rc_namespace' => $title->getNamespace(),
242 'rc_title' => $title->getDBkey(),
244 'rc_minor' => $minor ?
1 : 0,
245 'rc_cur_id' => $title->getArticleID(),
246 'rc_user' => $user->getID(),
247 'rc_user_text' => $user->getName(),
248 'rc_comment' => $comment,
249 'rc_this_oldid' => 0,
250 'rc_last_oldid' => 0,
251 'rc_bot' => $bot ?
1 : 0,
252 'rc_moved_to_ns' => 0,
253 'rc_moved_to_title' => '',
256 'rc_new' => 1 # obsolete
260 'prefixedDBkey' => $title->getPrefixedDBkey(),
266 # Makes an entry in the database corresponding to a rename
267 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
271 $ip = empty( $wgIP ) ?
'' : $wgIP;
273 $rc = new RecentChange
;
274 $rc->mAttribs
= array(
275 'rc_timestamp' => $timestamp,
276 'rc_cur_time' => $timestamp,
277 'rc_namespace' => $oldTitle->getNamespace(),
278 'rc_title' => $oldTitle->getDBkey(),
279 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
281 'rc_cur_id' => $oldTitle->getArticleID(),
282 'rc_user' => $user->getID(),
283 'rc_user_text' => $user->getName(),
284 'rc_comment' => $comment,
285 'rc_this_oldid' => 0,
286 'rc_last_oldid' => 0,
287 'rc_bot' => $user->isBot() ?
1 : 0,
288 'rc_moved_to_ns' => $newTitle->getNamespace(),
289 'rc_moved_to_title' => $newTitle->getDBkey(),
291 'rc_new' => 0, # obsolete
296 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
297 'lastTimestamp' => 0,
298 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
303 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
304 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
307 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
308 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
311 # A log entry is different to an edit in that previous revisions are
313 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
317 $ip = empty( $wgIP ) ?
'' : $wgIP;
319 $rc = new RecentChange
;
320 $rc->mAttribs
= array(
321 'rc_timestamp' => $timestamp,
322 'rc_cur_time' => $timestamp,
323 'rc_namespace' => $title->getNamespace(),
324 'rc_title' => $title->getDBkey(),
327 'rc_cur_id' => $title->getArticleID(),
328 'rc_user' => $user->getID(),
329 'rc_user_text' => $user->getName(),
330 'rc_comment' => $comment,
331 'rc_this_oldid' => 0,
332 'rc_last_oldid' => 0,
334 'rc_moved_to_ns' => 0,
335 'rc_moved_to_title' => '',
338 'rc_new' => 0 # obsolete
341 'prefixedDBkey' => $title->getPrefixedDBkey(),
347 # Initialises the members of this object from a mysql row object
348 function loadFromRow( $row )
350 $this->mAttribs
= get_object_vars( $row );
351 $this->mExtra
= array();
354 # Makes a pseudo-RC entry from a cur row, for watchlists and things
355 function loadFromCurRow( $row )
357 $this->mAttribs
= array(
358 'rc_timestamp' => $row->rev_timestamp
,
359 'rc_cur_time' => $row->rev_timestamp
,
360 'rc_user' => $row->rev_user
,
361 'rc_user_text' => $row->rev_user_text
,
362 'rc_namespace' => $row->page_namespace
,
363 'rc_title' => $row->page_title
,
364 'rc_comment' => $row->rev_comment
,
365 'rc_minor' => !!$row->rev_minor_edit
,
366 'rc_type' => $row->page_is_new ? RC_NEW
: RC_EDIT
,
367 'rc_cur_id' => $row->page_id
,
368 'rc_this_oldid' => 0,
369 'rc_last_oldid' => 0,
371 'rc_moved_to_ns' => 0,
372 'rc_moved_to_title' => '',
374 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
375 # currently because it uses cur, not recentchanges
376 'rc_new' => $row->page_is_new
# obsolete
379 $this->mExtra
= array();
384 * Gets the end part of the diff URL assoicated with this object
385 * Blank if no diff link should be displayed
387 function diffLinkTrail( $forceCur )
389 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
390 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
391 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
393 $trail .= '&diff=0' ;
395 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);