2 # Utility class for creating new RC entries
8 define( 'RC_MOVE_OVER_REDIRECT', 4);
13 rc_id id of the row in the recentchanges table
14 rc_timestamp time the entry was made
15 rc_cur_time timestamp on the cur row
16 rc_namespace namespace #
17 rc_title non-prefixed db key
18 rc_type is new entry, used to determine whether updating is necessary
20 rc_cur_id id of associated cur entry
21 rc_user user id who made the entry
22 rc_user_text user name who made the entry
23 rc_comment edit summary
24 rc_this_oldid old_id associated with this entry (or zero)
25 rc_last_oldid old_id associated with the entry before this one (or zero)
27 rc_ip IP address of the user in dotted quad notation
28 rc_new obsolete, use rc_type==RC_NEW
29 rc_patrolled boolean whether or not someone has marked this edit as patrolled
32 prefixedDBkey prefixed db key, used by external app via msg queue
33 lastTimestamp timestamp of previous entry, used in WHERE clause during update
34 lang the interwiki prefix, automatically set in save()
39 var $mAttribs = array(), $mExtra = array();
40 var $mTitle = false, $mMovedToTitle = false;
44 /* static */ function newFromRow( $row )
46 $rc = new RecentChange
;
47 $rc->loadFromRow( $row );
51 /* static */ function newFromCurRow( $row )
53 $rc = new RecentChange
;
54 $rc->loadFromCurRow( $row );
60 function setAttribs( $attribs )
62 $this->mAttribs
= $attribs;
65 function setExtra( $extra )
67 $this->mExtra
= $extra;
72 if ( $this->mTitle
=== false ) {
73 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
78 function getMovedToTitle()
80 if ( $this->mMovedToTitle
=== false ) {
81 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
82 $this->mAttribs
['rc_moved_to_title'] );
84 return $this->mMovedToTitle
;
87 # Writes the data in this object to the database
90 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC;
91 $fname = 'RecentChange::save';
93 $dbw =& wfGetDB( DB_MASTER
);
94 if ( !is_array($this->mExtra
) ) {
95 $this->mExtra
= array();
97 $this->mExtra
['lang'] = $wgLocalInterwiki;
99 if ( !$wgPutIPinRC ) {
100 $this->mAttribs
['rc_ip'] = '';
103 # Fixup database timestamps
104 $this->mAttribs
['rc_timestamp']=$dbw->timestamp($this->mAttribs
['rc_timestamp']);
105 $this->mAttribs
['rc_cur_time']=$dbw->timestamp($this->mAttribs
['rc_cur_time']);
108 $dbw->insertArray( 'recentchanges', $this->mAttribs
, $fname );
110 # Update old rows, if necessary
111 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
112 $oldid = $this->mAttribs
['rc_last_oldid'];
113 $ns = $this->mAttribs
['rc_namespace'];
114 $title = $this->mAttribs
['rc_title'];
115 $lastTime = $this->mExtra
['lastTimestamp'];
116 $now = $this->mAttribs
['rc_timestamp'];
117 $curId = $this->mAttribs
['rc_cur_id'];
119 # Update rc_this_oldid for the entries which were current
120 $dbw->updateArray( 'recentchanges',
122 'rc_this_oldid' => $oldid
123 ), array( /* WHERE */
124 'rc_namespace' => $ns,
125 'rc_title' => $title,
126 'rc_timestamp' => $dbw->timestamp($lastTime)
131 $dbw->updateArray( 'recentchanges', array( 'rc_cur_time' => $now ),
132 array( 'rc_cur_id' => $curId ), $fname );
135 # Notify external application
136 if ( $wgUseRCQueue ) {
137 $queue = msg_get_queue( $wgRCQueueID );
138 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
139 true, false, $error ))
141 wfDebug( "Error sending message to RC queue, code $error\n" );
146 # Marks a certain row as patrolled
147 function markPatrolled( $rcid )
149 $fname = 'RecentChange::markPatrolled';
151 $dbw =& wfGetDB( DB_MASTER
);
153 $dbw->updateArray( 'recentchanges',
156 ), array( /* WHERE */
162 # Makes an entry in the database corresponding to an edit
163 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
164 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
166 if ( $bot == 'default ' ) {
167 $bot = $user->isBot();
172 $ip = empty( $wgIP ) ?
'' : $wgIP;
175 $rc = new RecentChange
;
176 $rc->mAttribs
= array(
177 'rc_timestamp' => $timestamp,
178 'rc_cur_time' => $timestamp,
179 'rc_namespace' => $title->getNamespace(),
180 'rc_title' => $title->getDBkey(),
181 'rc_type' => RC_EDIT
,
182 'rc_minor' => $minor ?
1 : 0,
183 'rc_cur_id' => $title->getArticleID(),
184 'rc_user' => $user->getID(),
185 'rc_user_text' => $user->getName(),
186 'rc_comment' => $comment,
187 'rc_this_oldid' => 0,
188 'rc_last_oldid' => $oldId,
189 'rc_bot' => $bot ?
1 : 0,
190 'rc_moved_to_ns' => 0,
191 'rc_moved_to_title' => '',
193 'rc_new' => 0 # obsolete
197 'prefixedDBkey' => $title->getPrefixedDBkey(),
198 'lastTimestamp' => $lastTimestamp
203 # Makes an entry in the database corresponding to page creation
204 # Note: the title object must be loaded with the new id using resetArticleID()
205 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
209 $ip = empty( $wgIP ) ?
'' : $wgIP;
211 if ( $bot == 'default' ) {
212 $bot = $user->isBot();
215 $rc = new RecentChange
;
216 $rc->mAttribs
= array(
217 'rc_timestamp' => $timestamp,
218 'rc_cur_time' => $timestamp,
219 'rc_namespace' => $title->getNamespace(),
220 'rc_title' => $title->getDBkey(),
222 'rc_minor' => $minor ?
1 : 0,
223 'rc_cur_id' => $title->getArticleID(),
224 'rc_user' => $user->getID(),
225 'rc_user_text' => $user->getName(),
226 'rc_comment' => $comment,
227 'rc_this_oldid' => 0,
228 'rc_last_oldid' => 0,
229 'rc_bot' => $bot ?
1 : 0,
230 'rc_moved_to_ns' => 0,
231 'rc_moved_to_title' => '',
233 'rc_new' => 1 # obsolete
237 'prefixedDBkey' => $title->getPrefixedDBkey(),
243 # Makes an entry in the database corresponding to a rename
244 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
248 $ip = empty( $wgIP ) ?
'' : $wgIP;
250 $rc = new RecentChange
;
251 $rc->mAttribs
= array(
252 'rc_timestamp' => $timestamp,
253 'rc_cur_time' => $timestamp,
254 'rc_namespace' => $oldTitle->getNamespace(),
255 'rc_title' => $oldTitle->getDBkey(),
256 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
258 'rc_cur_id' => $oldTitle->getArticleID(),
259 'rc_user' => $user->getID(),
260 'rc_user_text' => $user->getName(),
261 'rc_comment' => $comment,
262 'rc_this_oldid' => 0,
263 'rc_last_oldid' => 0,
264 'rc_bot' => $user->isBot() ?
1 : 0,
265 'rc_moved_to_ns' => $newTitle->getNamespace(),
266 'rc_moved_to_title' => $newTitle->getDBkey(),
268 'rc_new' => 0, # obsolete
273 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
274 'lastTimestamp' => 0,
275 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
280 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
281 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
284 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
285 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
288 # A log entry is different to an edit in that previous revisions are
290 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
294 $ip = empty( $wgIP ) ?
'' : $wgIP;
296 $rc = new RecentChange
;
297 $rc->mAttribs
= array(
298 'rc_timestamp' => $timestamp,
299 'rc_cur_time' => $timestamp,
300 'rc_namespace' => $title->getNamespace(),
301 'rc_title' => $title->getDBkey(),
304 'rc_cur_id' => $title->getArticleID(),
305 'rc_user' => $user->getID(),
306 'rc_user_text' => $user->getName(),
307 'rc_comment' => $comment,
308 'rc_this_oldid' => 0,
309 'rc_last_oldid' => 0,
311 'rc_moved_to_ns' => 0,
312 'rc_moved_to_title' => '',
315 'rc_new' => 0 # obsolete
318 'prefixedDBkey' => $title->getPrefixedDBkey(),
324 # Initialises the members of this object from a mysql row object
325 function loadFromRow( $row )
327 $this->mAttribs
= get_object_vars( $row );
328 $this->mExtra
= array();
331 # Makes a pseudo-RC entry from a cur row, for watchlists and things
332 function loadFromCurRow( $row )
334 $this->mAttribs
= array(
335 'rc_timestamp' => $row->cur_timestamp
,
336 'rc_cur_time' => $row->cur_timestamp
,
337 'rc_user' => $row->cur_user
,
338 'rc_user_text' => $row->cur_user_text
,
339 'rc_namespace' => $row->cur_namespace
,
340 'rc_title' => $row->cur_title
,
341 'rc_comment' => $row->cur_comment
,
342 'rc_minor' => !!$row->cur_minor_edit
,
343 'rc_type' => $row->cur_is_new ? RC_NEW
: RC_EDIT
,
344 'rc_cur_id' => $row->cur_id
,
345 'rc_this_oldid' => 0,
346 'rc_last_oldid' => 0,
348 'rc_moved_to_ns' => 0,
349 'rc_moved_to_title' => '',
351 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
352 # currently because it uses cur, not recentchanges
353 'rc_new' => $row->cur_is_new
# obsolete
356 $this->mExtra
= array();
360 # Gets the end part of the diff URL assoicated with this object
361 # Blank if no diff link should be displayed
362 function diffLinkTrail( $forceCur )
364 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
365 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
366 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
368 $trail .= '&diff=0' ;
370 $trail .= '&diff=' . (int)($this->mAttribs
['rc_this_oldid']);