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' => '',
203 'rc_new' => 0 # obsolete
207 'prefixedDBkey' => $title->getPrefixedDBkey(),
208 'lastTimestamp' => $lastTimestamp
213 # Makes an entry in the database corresponding to page creation
214 # Note: the title object must be loaded with the new id using resetArticleID()
215 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
219 $ip = empty( $wgIP ) ?
'' : $wgIP;
221 if ( $bot == 'default' ) {
222 $bot = $user->isBot();
225 $rc = new RecentChange
;
226 $rc->mAttribs
= array(
227 'rc_timestamp' => $timestamp,
228 'rc_cur_time' => $timestamp,
229 'rc_namespace' => $title->getNamespace(),
230 'rc_title' => $title->getDBkey(),
232 'rc_minor' => $minor ?
1 : 0,
233 'rc_cur_id' => $title->getArticleID(),
234 'rc_user' => $user->getID(),
235 'rc_user_text' => $user->getName(),
236 'rc_comment' => $comment,
237 'rc_this_oldid' => 0,
238 'rc_last_oldid' => 0,
239 'rc_bot' => $bot ?
1 : 0,
240 'rc_moved_to_ns' => 0,
241 'rc_moved_to_title' => '',
244 'rc_new' => 1 # obsolete
248 'prefixedDBkey' => $title->getPrefixedDBkey(),
254 # Makes an entry in the database corresponding to a rename
255 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
259 $ip = empty( $wgIP ) ?
'' : $wgIP;
261 $rc = new RecentChange
;
262 $rc->mAttribs
= array(
263 'rc_timestamp' => $timestamp,
264 'rc_cur_time' => $timestamp,
265 'rc_namespace' => $oldTitle->getNamespace(),
266 'rc_title' => $oldTitle->getDBkey(),
267 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
269 'rc_cur_id' => $oldTitle->getArticleID(),
270 'rc_user' => $user->getID(),
271 'rc_user_text' => $user->getName(),
272 'rc_comment' => $comment,
273 'rc_this_oldid' => 0,
274 'rc_last_oldid' => 0,
275 'rc_bot' => $user->isBot() ?
1 : 0,
276 'rc_moved_to_ns' => $newTitle->getNamespace(),
277 'rc_moved_to_title' => $newTitle->getDBkey(),
279 'rc_new' => 0, # obsolete
284 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
285 'lastTimestamp' => 0,
286 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
291 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
292 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
295 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
296 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
299 # A log entry is different to an edit in that previous revisions are
301 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
305 $ip = empty( $wgIP ) ?
'' : $wgIP;
307 $rc = new RecentChange
;
308 $rc->mAttribs
= array(
309 'rc_timestamp' => $timestamp,
310 'rc_cur_time' => $timestamp,
311 'rc_namespace' => $title->getNamespace(),
312 'rc_title' => $title->getDBkey(),
315 'rc_cur_id' => $title->getArticleID(),
316 'rc_user' => $user->getID(),
317 'rc_user_text' => $user->getName(),
318 'rc_comment' => $comment,
319 'rc_this_oldid' => 0,
320 'rc_last_oldid' => 0,
322 'rc_moved_to_ns' => 0,
323 'rc_moved_to_title' => '',
326 'rc_new' => 0 # obsolete
329 'prefixedDBkey' => $title->getPrefixedDBkey(),
335 # Initialises the members of this object from a mysql row object
336 function loadFromRow( $row )
338 $this->mAttribs
= get_object_vars( $row );
339 $this->mExtra
= array();
342 # Makes a pseudo-RC entry from a cur row, for watchlists and things
343 function loadFromCurRow( $row )
345 $this->mAttribs
= array(
346 'rc_timestamp' => $row->cur_timestamp
,
347 'rc_cur_time' => $row->cur_timestamp
,
348 'rc_user' => $row->cur_user
,
349 'rc_user_text' => $row->cur_user_text
,
350 'rc_namespace' => $row->cur_namespace
,
351 'rc_title' => $row->cur_title
,
352 'rc_comment' => $row->cur_comment
,
353 'rc_minor' => !!$row->cur_minor_edit
,
354 'rc_type' => $row->cur_is_new ? RC_NEW
: RC_EDIT
,
355 'rc_cur_id' => $row->cur_id
,
356 'rc_this_oldid' => 0,
357 'rc_last_oldid' => 0,
359 'rc_moved_to_ns' => 0,
360 'rc_moved_to_title' => '',
362 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
363 # currently because it uses cur, not recentchanges
364 'rc_new' => $row->cur_is_new
# obsolete
367 $this->mExtra
= array();
372 * Gets the end part of the diff URL assoicated with this object
373 * Blank if no diff link should be displayed
375 function diffLinkTrail( $forceCur )
377 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
378 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
379 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
381 $trail .= '&diff=0' ;
383 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);