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'] = '';
104 $dbw->insertArray( "recentchanges", $this->mAttribs
, $fname );
106 # Update old rows, if necessary
107 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
108 $oldid = $this->mAttribs
['rc_last_oldid'];
109 $ns = $this->mAttribs
['rc_namespace'];
110 $title = $this->mAttribs
['rc_title'];
111 $lastTime = $this->mExtra
['lastTimestamp'];
112 $now = $this->mAttribs
['rc_timestamp'];
113 $curId = $this->mAttribs
['rc_cur_id'];
115 # Update rc_this_oldid for the entries which were current
116 $dbw->updateArray( 'recentchanges',
118 'rc_this_oldid' => $oldid
119 ), array( /* WHERE */
120 'rc_namespace' => $ns,
121 'rc_title' => $title,
122 'rc_timestamp' => $lastTime
127 $dbw->updateArray( 'recentchanges', array( 'rc_cur_time' => $now ),
128 array( 'rc_cur_id' => $curId ), $fname );
131 # Notify external application
132 if ( $wgUseRCQueue ) {
133 $queue = msg_get_queue( $wgRCQueueID );
134 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
135 true, false, $error ))
137 wfDebug( "Error sending message to RC queue, code $error\n" );
142 # Marks a certain row as patrolled
143 function markPatrolled( $rcid )
145 $fname = "RecentChange::markPatrolled";
147 $dbw =& wfGetDB( DB_MASTER
);
149 $dbw->updateArray( 'recentchanges',
152 ), array( /* WHERE */
158 # Makes an entry in the database corresponding to an edit
159 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
160 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
162 if ( $bot == "default " ) {
163 $bot = $user->isBot();
168 $ip = empty( $wgIP ) ?
'' : $wgIP;
171 $rc = new RecentChange
;
172 $rc->mAttribs
= array(
173 'rc_timestamp' => $timestamp,
174 'rc_cur_time' => $timestamp,
175 'rc_namespace' => $title->getNamespace(),
176 'rc_title' => $title->getDBkey(),
177 'rc_type' => RC_EDIT
,
178 'rc_minor' => $minor ?
1 : 0,
179 'rc_cur_id' => $title->getArticleID(),
180 'rc_user' => $user->getID(),
181 'rc_user_text' => $user->getName(),
182 'rc_comment' => $comment,
183 'rc_this_oldid' => 0,
184 'rc_last_oldid' => $oldId,
185 'rc_bot' => $bot ?
1 : 0,
186 'rc_moved_to_ns' => 0,
187 'rc_moved_to_title' => '',
189 'rc_new' => 0 # obsolete
193 'prefixedDBkey' => $title->getPrefixedDBkey(),
194 'lastTimestamp' => $lastTimestamp
199 # Makes an entry in the database corresponding to page creation
200 # Note: the title object must be loaded with the new id using resetArticleID()
201 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
205 $ip = empty( $wgIP ) ?
'' : $wgIP;
207 if ( $bot == "default" ) {
208 $bot = $user->isBot();
211 $rc = new RecentChange
;
212 $rc->mAttribs
= array(
213 'rc_timestamp' => $timestamp,
214 'rc_cur_time' => $timestamp,
215 'rc_namespace' => $title->getNamespace(),
216 'rc_title' => $title->getDBkey(),
218 'rc_minor' => $minor ?
1 : 0,
219 'rc_cur_id' => $title->getArticleID(),
220 'rc_user' => $user->getID(),
221 'rc_user_text' => $user->getName(),
222 'rc_comment' => $comment,
223 'rc_this_oldid' => 0,
224 'rc_last_oldid' => 0,
225 'rc_bot' => $bot ?
1 : 0,
226 'rc_moved_to_ns' => 0,
227 'rc_moved_to_title' => '',
229 'rc_new' => 1 # obsolete
233 'prefixedDBkey' => $title->getPrefixedDBkey(),
239 # Makes an entry in the database corresponding to a rename
240 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
244 $ip = empty( $wgIP ) ?
'' : $wgIP;
246 $rc = new RecentChange
;
247 $rc->mAttribs
= array(
248 'rc_timestamp' => $timestamp,
249 'rc_cur_time' => $timestamp,
250 'rc_namespace' => $oldTitle->getNamespace(),
251 'rc_title' => $oldTitle->getDBkey(),
252 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
254 'rc_cur_id' => $oldTitle->getArticleID(),
255 'rc_user' => $user->getID(),
256 'rc_user_text' => $user->getName(),
257 'rc_comment' => $comment,
258 'rc_this_oldid' => 0,
259 'rc_last_oldid' => 0,
260 'rc_bot' => $user->isBot() ?
1 : 0,
261 'rc_moved_to_ns' => $newTitle->getNamespace(),
262 'rc_moved_to_title' => $newTitle->getDBkey(),
264 'rc_new' => 0, # obsolete
269 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
270 'lastTimestamp' => 0,
271 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
276 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
277 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
280 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
281 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
284 # A log entry is different to an edit in that previous revisions are
286 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
290 $ip = empty( $wgIP ) ?
'' : $wgIP;
292 $rc = new RecentChange
;
293 $rc->mAttribs
= array(
294 'rc_timestamp' => $timestamp,
295 'rc_cur_time' => $timestamp,
296 'rc_namespace' => $title->getNamespace(),
297 'rc_title' => $title->getDBkey(),
300 'rc_cur_id' => $title->getArticleID(),
301 'rc_user' => $user->getID(),
302 'rc_user_text' => $user->getName(),
303 'rc_comment' => $comment,
304 'rc_this_oldid' => 0,
305 'rc_last_oldid' => 0,
307 'rc_moved_to_ns' => 0,
308 'rc_moved_to_title' => '',
311 'rc_new' => 0 # obsolete
314 'prefixedDBkey' => $title->getPrefixedDBkey(),
320 # Initialises the members of this object from a mysql row object
321 function loadFromRow( $row )
323 $this->mAttribs
= get_object_vars( $row );
324 $this->mExtra
= array();
327 # Makes a pseudo-RC entry from a cur row, for watchlists and things
328 function loadFromCurRow( $row )
330 $this->mAttribs
= array(
331 "rc_timestamp" => $row->cur_timestamp
,
332 "rc_cur_time" => $row->cur_timestamp
,
333 "rc_user" => $row->cur_user
,
334 "rc_user_text" => $row->cur_user_text
,
335 "rc_namespace" => $row->cur_namespace
,
336 "rc_title" => $row->cur_title
,
337 "rc_comment" => $row->cur_comment
,
338 "rc_minor" => !!$row->cur_minor_edit
,
339 "rc_type" => $row->cur_is_new ? RC_NEW
: RC_EDIT
,
340 "rc_cur_id" => $row->cur_id
,
341 'rc_this_oldid' => 0,
342 'rc_last_oldid' => 0,
344 'rc_moved_to_ns' => 0,
345 'rc_moved_to_title' => '',
347 'rc_patrolled' => '1', # we can't support patrolling on the Watchlist
348 # currently because it uses cur, not recentchanges
349 'rc_new' => $row->cur_is_new
# obsolete
352 $this->mExtra
= array();
356 # Gets the end part of the diff URL assoicated with this object
357 # Blank if no diff link should be displayed
358 function diffLinkTrail( $forceCur )
360 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
361 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
362 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
364 $trail .= "&diff=0" ;
366 $trail .= "&diff=" . (int)($this->mAttribs
['rc_this_oldid']);