e7d16257a0b2ac07a1db324934e5fe7b363e7003
11 define( 'RC_MOVE', 2);
13 define( 'RC_MOVE_OVER_REDIRECT', 4);
17 * Utility class for creating new RC entries
19 * rc_id id of the row in the recentchanges table
20 * rc_timestamp time the entry was made
21 * rc_cur_time timestamp on the cur row
22 * rc_namespace namespace #
23 * rc_title non-prefixed db key
24 * rc_type is new entry, used to determine whether updating is necessary
26 * rc_cur_id id of associated cur entry
27 * rc_user user id who made the entry
28 * rc_user_text user name who made the entry
29 * rc_comment edit summary
30 * rc_this_oldid old_id associated with this entry (or zero)
31 * rc_last_oldid old_id associated with the entry before this one (or zero)
32 * rc_bot is bot, hidden
33 * rc_ip IP address of the user in dotted quad notation
34 * rc_new obsolete, use rc_type==RC_NEW
35 * rc_patrolled boolean whether or not someone has marked this edit as patrolled
38 * prefixedDBkey prefixed db key, used by external app via msg queue
39 * lastTimestamp timestamp of previous entry, used in WHERE clause during update
40 * lang the interwiki prefix, automatically set in save()
42 * @todo document functions and variables
46 var $mAttribs = array(), $mExtra = array();
47 var $mTitle = false, $mMovedToTitle = false;
51 /* static */ function newFromRow( $row )
53 $rc = new RecentChange
;
54 $rc->loadFromRow( $row );
58 /* static */ function newFromCurRow( $row )
60 $rc = new RecentChange
;
61 $rc->loadFromCurRow( $row );
67 function setAttribs( $attribs )
69 $this->mAttribs
= $attribs;
72 function setExtra( $extra )
74 $this->mExtra
= $extra;
79 if ( $this->mTitle
=== false ) {
80 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
85 function getMovedToTitle()
87 if ( $this->mMovedToTitle
=== false ) {
88 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
89 $this->mAttribs
['rc_moved_to_title'] );
91 return $this->mMovedToTitle
;
94 # Writes the data in this object to the database
97 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC;
98 $fname = 'RecentChange::save';
100 $dbw =& wfGetDB( DB_MASTER
);
101 if ( !is_array($this->mExtra
) ) {
102 $this->mExtra
= array();
104 $this->mExtra
['lang'] = $wgLocalInterwiki;
106 if ( !$wgPutIPinRC ) {
107 $this->mAttribs
['rc_ip'] = '';
110 # Fixup database timestamps
111 $this->mAttribs
['rc_timestamp']=$dbw->timestamp($this->mAttribs
['rc_timestamp']);
112 $this->mAttribs
['rc_cur_time']=$dbw->timestamp($this->mAttribs
['rc_cur_time']);
115 $dbw->insertArray( 'recentchanges', $this->mAttribs
, $fname );
117 # Update old rows, if necessary
118 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
119 $oldid = $this->mAttribs
['rc_last_oldid'];
120 $ns = $this->mAttribs
['rc_namespace'];
121 $title = $this->mAttribs
['rc_title'];
122 $lastTime = $this->mExtra
['lastTimestamp'];
123 $now = $this->mAttribs
['rc_timestamp'];
124 $curId = $this->mAttribs
['rc_cur_id'];
126 # Update rc_this_oldid for the entries which were current
127 $dbw->updateArray( 'recentchanges',
129 'rc_this_oldid' => $oldid
130 ), array( /* WHERE */
131 'rc_namespace' => $ns,
132 'rc_title' => $title,
133 'rc_timestamp' => $dbw->timestamp($lastTime)
138 $dbw->updateArray( 'recentchanges', array( 'rc_cur_time' => $now ),
139 array( 'rc_cur_id' => $curId ), $fname );
142 # Notify external application
143 if ( $wgUseRCQueue ) {
144 $queue = msg_get_queue( $wgRCQueueID );
145 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
146 true, false, $error ))
148 wfDebug( "Error sending message to RC queue, code $error\n" );
153 # Marks a certain row as patrolled
154 function markPatrolled( $rcid )
156 $fname = 'RecentChange::markPatrolled';
158 $dbw =& wfGetDB( DB_MASTER
);
160 $dbw->updateArray( 'recentchanges',
163 ), array( /* WHERE */
169 # Makes an entry in the database corresponding to an edit
170 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
171 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
173 if ( $bot == 'default ' ) {
174 $bot = $user->isBot();
179 $ip = empty( $wgIP ) ?
'' : $wgIP;
182 $rc = new RecentChange
;
183 $rc->mAttribs
= array(
184 'rc_timestamp' => $timestamp,
185 'rc_cur_time' => $timestamp,
186 'rc_namespace' => $title->getNamespace(),
187 'rc_title' => $title->getDBkey(),
188 'rc_type' => RC_EDIT
,
189 'rc_minor' => $minor ?
1 : 0,
190 'rc_cur_id' => $title->getArticleID(),
191 'rc_user' => $user->getID(),
192 'rc_user_text' => $user->getName(),
193 'rc_comment' => $comment,
194 'rc_this_oldid' => 0,
195 'rc_last_oldid' => $oldId,
196 'rc_bot' => $bot ?
1 : 0,
197 'rc_moved_to_ns' => 0,
198 'rc_moved_to_title' => '',
200 'rc_new' => 0 # obsolete
204 'prefixedDBkey' => $title->getPrefixedDBkey(),
205 'lastTimestamp' => $lastTimestamp
210 # Makes an entry in the database corresponding to page creation
211 # Note: the title object must be loaded with the new id using resetArticleID()
212 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
216 $ip = empty( $wgIP ) ?
'' : $wgIP;
218 if ( $bot == 'default' ) {
219 $bot = $user->isBot();
222 $rc = new RecentChange
;
223 $rc->mAttribs
= array(
224 'rc_timestamp' => $timestamp,
225 'rc_cur_time' => $timestamp,
226 'rc_namespace' => $title->getNamespace(),
227 'rc_title' => $title->getDBkey(),
229 'rc_minor' => $minor ?
1 : 0,
230 'rc_cur_id' => $title->getArticleID(),
231 'rc_user' => $user->getID(),
232 'rc_user_text' => $user->getName(),
233 'rc_comment' => $comment,
234 'rc_this_oldid' => 0,
235 'rc_last_oldid' => 0,
236 'rc_bot' => $bot ?
1 : 0,
237 'rc_moved_to_ns' => 0,
238 'rc_moved_to_title' => '',
240 'rc_new' => 1 # obsolete
244 'prefixedDBkey' => $title->getPrefixedDBkey(),
250 # Makes an entry in the database corresponding to a rename
251 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
255 $ip = empty( $wgIP ) ?
'' : $wgIP;
257 $rc = new RecentChange
;
258 $rc->mAttribs
= array(
259 'rc_timestamp' => $timestamp,
260 'rc_cur_time' => $timestamp,
261 'rc_namespace' => $oldTitle->getNamespace(),
262 'rc_title' => $oldTitle->getDBkey(),
263 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
265 'rc_cur_id' => $oldTitle->getArticleID(),
266 'rc_user' => $user->getID(),
267 'rc_user_text' => $user->getName(),
268 'rc_comment' => $comment,
269 'rc_this_oldid' => 0,
270 'rc_last_oldid' => 0,
271 'rc_bot' => $user->isBot() ?
1 : 0,
272 'rc_moved_to_ns' => $newTitle->getNamespace(),
273 'rc_moved_to_title' => $newTitle->getDBkey(),
275 'rc_new' => 0, # obsolete
280 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
281 'lastTimestamp' => 0,
282 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
287 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
288 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
291 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
292 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
295 # A log entry is different to an edit in that previous revisions are
297 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
301 $ip = empty( $wgIP ) ?
'' : $wgIP;
303 $rc = new RecentChange
;
304 $rc->mAttribs
= array(
305 'rc_timestamp' => $timestamp,
306 'rc_cur_time' => $timestamp,
307 'rc_namespace' => $title->getNamespace(),
308 'rc_title' => $title->getDBkey(),
311 'rc_cur_id' => $title->getArticleID(),
312 'rc_user' => $user->getID(),
313 'rc_user_text' => $user->getName(),
314 'rc_comment' => $comment,
315 'rc_this_oldid' => 0,
316 'rc_last_oldid' => 0,
318 'rc_moved_to_ns' => 0,
319 'rc_moved_to_title' => '',
322 'rc_new' => 0 # obsolete
325 'prefixedDBkey' => $title->getPrefixedDBkey(),
331 # Initialises the members of this object from a mysql row object
332 function loadFromRow( $row )
334 $this->mAttribs
= get_object_vars( $row );
335 $this->mExtra
= array();
338 # Makes a pseudo-RC entry from a cur row, for watchlists and things
339 function loadFromCurRow( $row )
341 $this->mAttribs
= array(
342 'rc_timestamp' => $row->cur_timestamp
,
343 'rc_cur_time' => $row->cur_timestamp
,
344 'rc_user' => $row->cur_user
,
345 'rc_user_text' => $row->cur_user_text
,
346 'rc_namespace' => $row->cur_namespace
,
347 'rc_title' => $row->cur_title
,
348 'rc_comment' => $row->cur_comment
,
349 'rc_minor' => !!$row->cur_minor_edit
,
350 'rc_type' => $row->cur_is_new ? RC_NEW
: RC_EDIT
,
351 'rc_cur_id' => $row->cur_id
,
352 'rc_this_oldid' => 0,
353 'rc_last_oldid' => 0,
355 'rc_moved_to_ns' => 0,
356 'rc_moved_to_title' => '',
358 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
359 # currently because it uses cur, not recentchanges
360 'rc_new' => $row->cur_is_new
# obsolete
363 $this->mExtra
= array();
368 * Gets the end part of the diff URL assoicated with this object
369 * Blank if no diff link should be displayed
371 function diffLinkTrail( $forceCur )
373 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
374 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
375 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
377 $trail .= '&diff=0' ;
379 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);