ed64ee213cad676a08daff191cf9f55b1339067b
2 # Utility class for creating new RC entries
8 define( "RC_MOVE_OVER_REDIRECT", 4);
13 rc_timestamp time the entry was made
14 rc_cur_time timestamp on the cur row
15 rc_namespace namespace #
16 rc_title non-prefixed db key
17 rc_type is new entry, used to determine whether updating is necessary
19 rc_cur_id id of associated cur entry
20 rc_user user id who made the entry
21 rc_user_text user name who made the entry
22 rc_comment edit summary
23 rc_this_oldid old_id associated with this entry (or zero)
24 rc_last_oldid old_id associated with the entry before this one (or zero)
26 rc_ip IP address of the user in dotted quad notation
27 rc_new obsolete, use rc_type==RC_NEW
30 prefixedDBkey prefixed db key, used by external app via msg queue
31 lastTimestamp timestamp of previous entry, used in WHERE clause during update
32 lang the interwiki prefix, automatically set in save()
37 var $mAttribs = array(), $mExtra = array();
38 var $mTitle = false, $mMovedToTitle = false;
42 /* static */ function newFromRow( $row )
44 $rc = new RecentChange
;
45 $rc->loadFromRow( $row );
49 /* static */ function newFromCurRow( $row )
51 $rc = new RecentChange
;
52 $rc->loadFromCurRow( $row );
58 function setAttribs( $attribs )
60 $this->mAttribs
= $attribs;
63 function setExtra( $extra )
65 $this->mExtra
= $extra;
70 if ( $this->mTitle
=== false ) {
71 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
76 function getMovedToTitle()
78 if ( $this->mMovedToTitle
=== false ) {
79 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
80 $this->mAttribs
['rc_moved_to_title'] );
82 return $this->mMovedToTitle
;
85 # Writes the data in this object to the database
88 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC;
89 $fname = "RecentChange::save";
91 if ( !is_array($this->mExtra
) ) {
92 $this->mExtra
= array();
94 $this->mExtra
['lang'] = $wgLocalInterwiki;
96 if ( !$wgPutIPinRC ) {
97 $this->mAttribs
['rc_ip'] = '';
101 wfInsertArray( "recentchanges", $this->mAttribs
, $fname );
103 # Update old rows, if necessary
104 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
105 $oldid = $this->mAttribs
['rc_last_oldid'];
106 $ns = $this->mAttribs
['rc_namespace'];
107 $title = wfStrencode($this->mAttribs
['rc_title']);
108 $lastTime = $this->mExtra
['lastTimestamp'];
109 $now = $this->mAttribs
['rc_timestamp'];
110 $curId = $this->mAttribs
['rc_cur_id'];
112 # Update rc_this_oldid for the entries which were current
113 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
114 "WHERE rc_namespace=$ns AND rc_title='$title' AND rc_timestamp='$lastTime'";
115 wfQuery( $sql, DB_WRITE
, $fname );
118 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
119 "WHERE rc_cur_id=" . $curId;
120 wfQuery( $sql, DB_WRITE
, $fname );
123 # Notify external application
124 if ( $wgUseRCQueue ) {
125 $queue = msg_get_queue( $wgRCQueueID );
126 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
127 true, false, $error ))
129 wfDebug( "Error sending message to RC queue, code $error\n" );
134 # Makes an entry in the database corresponding to an edit
135 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
136 $oldId, $lastTimestamp, $bot = "default", $ip = '' )
138 if ( $bot == "default " ) {
139 $bot = $user->isBot();
144 $ip = empty( $wgIP ) ?
'' : $wgIP;
147 $rc = new RecentChange
;
148 $rc->mAttribs
= array(
149 'rc_timestamp' => $timestamp,
150 'rc_cur_time' => $timestamp,
151 'rc_namespace' => $title->getNamespace(),
152 'rc_title' => $title->getDBkey(),
153 'rc_type' => RC_EDIT
,
154 'rc_minor' => $minor ?
1 : 0,
155 'rc_cur_id' => $title->getArticleID(),
156 'rc_user' => $user->getID(),
157 'rc_user_text' => $user->getName(),
158 'rc_comment' => $comment,
159 'rc_this_oldid' => 0,
160 'rc_last_oldid' => $oldId,
161 'rc_bot' => $bot ?
1 : 0,
162 'rc_moved_to_ns' => 0,
163 'rc_moved_to_title' => '',
165 'rc_new' => 0 # obsolete
169 'prefixedDBkey' => $title->getPrefixedDBkey(),
170 'lastTimestamp' => $lastTimestamp
175 # Makes an entry in the database corresponding to page creation
176 # Note: the title object must be loaded with the new id using resetArticleID()
177 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
181 $ip = empty( $wgIP ) ?
'' : $wgIP;
183 if ( $bot == "default" ) {
184 $bot = $user->isBot();
187 $rc = new RecentChange
;
188 $rc->mAttribs
= array(
189 'rc_timestamp' => $timestamp,
190 'rc_cur_time' => $timestamp,
191 'rc_namespace' => $title->getNamespace(),
192 'rc_title' => $title->getDBkey(),
194 'rc_minor' => $minor ?
1 : 0,
195 'rc_cur_id' => $title->getArticleID(),
196 'rc_user' => $user->getID(),
197 'rc_user_text' => $user->getName(),
198 'rc_comment' => $comment,
199 'rc_this_oldid' => 0,
200 'rc_last_oldid' => 0,
201 'rc_bot' => $bot ?
1 : 0,
202 'rc_moved_to_ns' => 0,
203 'rc_moved_to_title' => '',
205 'rc_new' => 1 # obsolete
209 'prefixedDBkey' => $title->getPrefixedDBkey(),
215 # Makes an entry in the database corresponding to a rename
216 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
220 $ip = empty( $wgIP ) ?
'' : $wgIP;
222 $rc = new RecentChange
;
223 $rc->mAttribs
= array(
224 'rc_timestamp' => $timestamp,
225 'rc_cur_time' => $timestamp,
226 'rc_namespace' => $oldTitle->getNamespace(),
227 'rc_title' => $oldTitle->getDBkey(),
228 'rc_type' => $overRedir ? RC_MOVE_OVER_REDIRECT
: RC_MOVE
,
230 'rc_cur_id' => $oldTitle->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' => $user->isBot() ?
1 : 0,
237 'rc_moved_to_ns' => $newTitle->getNamespace(),
238 'rc_moved_to_title' => $newTitle->getDBkey(),
240 'rc_new' => 0 # obsolete
244 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
245 'lastTimestamp' => 0,
246 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
251 /* static */ function notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
252 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, false );
255 /* static */ function notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
256 RecentChange
::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip='', true );
259 # A log entry is different to an edit in that previous revisions are
261 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
265 $ip = empty( $wgIP ) ?
'' : $wgIP;
267 $rc = new RecentChange
;
268 $rc->mAttribs
= array(
269 'rc_timestamp' => $timestamp,
270 'rc_cur_time' => $timestamp,
271 'rc_namespace' => $title->getNamespace(),
272 'rc_title' => $title->getDBkey(),
275 'rc_cur_id' => $title->getArticleID(),
276 'rc_user' => $user->getID(),
277 'rc_user_text' => $user->getName(),
278 'rc_comment' => $comment,
279 'rc_this_oldid' => 0,
280 'rc_last_oldid' => 0,
282 'rc_moved_to_ns' => 0,
283 'rc_moved_to_title' => '',
285 'rc_new' => 0 # obsolete
288 'prefixedDBkey' => $title->getPrefixedDBkey(),
294 # Initialises the members of this object from a mysql row object
295 function loadFromRow( $row )
297 $this->mAttribs
= get_object_vars( $row );
298 $this->mExtra
= array();
301 # Makes a pseudo-RC entry from a cur row, for watchlists and things
302 function loadFromCurRow( $row )
304 $this->mAttribs
= array(
305 "rc_timestamp" => $row->cur_timestamp
,
306 "rc_cur_time" => $row->cur_timestamp
,
307 "rc_user" => $row->cur_user
,
308 "rc_user_text" => $row->cur_user_text
,
309 "rc_namespace" => $row->cur_namespace
,
310 "rc_title" => $row->cur_title
,
311 "rc_comment" => $row->cur_comment
,
312 "rc_minor" => !!$row->cur_minor_edit
,
313 "rc_type" => $row->cur_is_new ? RC_NEW
: RC_EDIT
,
314 "rc_cur_id" => $row->cur_id
,
315 'rc_this_oldid' => 0,
316 'rc_last_oldid' => 0,
318 'rc_moved_to_ns' => 0,
319 'rc_moved_to_title' => '',
321 'rc_new' => $row->cur_is_new
# obsolete
324 $this->mExtra
= array();
328 # Gets the end part of the diff URL assoicated with this object
329 # Blank if no diff link should be displayed
330 function diffLinkTrail( $forceCur )
332 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
333 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
334 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
336 $trail .= "&diff=0" ;
338 $trail .= "&diff=" . (int)($this->mAttribs
['rc_this_oldid']);