same minor typo as in LocalSettings (in example config url)
[mediawiki.git] / includes / RecentChange.php
blob476b45d7be28a0dca8934939a14a1cf79246bbe3
1 <?
2 # Utility class for creating new RC entries
4 define( "RC_EDIT", 0);
5 define( "RC_NEW", 1);
6 define( "RC_MOVE", 2);
7 define( "RC_LOG", 3);
9 /*
10 mAttributes:
11 rc_timestamp time the entry was made
12 rc_cur_time timestamp on the cur row
13 rc_namespace namespace #
14 rc_title non-prefixed db key
15 rc_type is new entry, used to determine whether updating is necessary
16 rc_minor is minor
17 rc_cur_id id of associated cur entry
18 rc_user user id who made the entry
19 rc_user_text user name who made the entry
20 rc_comment edit summary
21 rc_this_oldid old_id associated with this entry (or zero)
22 rc_last_oldid old_id associated with the entry before this one (or zero)
23 rc_bot is bot, hidden
24 rc_new obsolete, use rc_type==RC_NEW
26 mExtra:
27 prefixedDBkey prefixed db key, used by external app via msg queue
28 lastTimestamp timestamp of previous entry, used in WHERE clause during update
29 lang the interwiki prefix, automatically set in save()
32 class RecentChange
34 var $mAttribs = array(), $mExtra = array();
35 var $mTitle = false, $mMovedToTitle = false;
37 # Factory methods
39 /* static */ function newFromRow( $row )
41 $rc = new RecentChange;
42 $rc->loadFromRow( $row );
43 return $rc;
46 /* static */ function newFromCurRow( $row )
48 $rc = new RecentChange;
49 $rc->loadFromCurRow( $row );
50 return $rc;
53 # Accessors
55 function setAttribs( $attribs )
57 $this->mAttribs = $attribs;
60 function setExtra( $extra )
62 $this->mExtra = $extra;
65 function getTitle()
67 if ( $this->mTitle === false ) {
68 $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
70 return $this->mTitle;
73 function getMovedToTitle()
75 if ( $this->mMovedToTitle === false ) {
76 $this->mMovedToTitle = Title::makeTitle( $this->mAttribs['rc_moved_to_ns'],
77 $this->mAttribs['rc_moved_to_title'] );
79 return $this->mMovedToTitle;
82 # Writes the data in this object to the database
83 function save()
85 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki;
86 $fname = "RecentChange::save";
88 if ( !is_array($this->mExtra) ) {
89 $this->mExtra = array();
91 $this->mExtra['lang'] = $wgLocalInterwiki;
93 # Insert new row
94 wfInsertArray( "recentchanges", $this->mAttribs, $fname );
96 # Update old rows, if necessary
97 if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
98 $oldid = $this->mAttribs['rc_last_oldid'];
99 $ns = $this->mAttribs['rc_namespace'];
100 $title = wfStrencode($this->mAttribs['rc_title']);
101 $lastTime = $this->mExtra['lastTimestamp'];
102 $now = $this->mAttribs['rc_timestamp'];
103 $curId = $this->mAttribs['rc_cur_id'];
105 # Update rc_this_oldid for the entries which were current
106 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
107 "WHERE rc_namespace=$ns AND rc_title='$title' AND rc_timestamp='$lastTime'";
108 wfQuery( $sql, DB_WRITE, $fname );
110 # Update rc_cur_time
111 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
112 "WHERE rc_cur_id=" . $curId;
113 wfQuery( $sql, DB_WRITE, $fname );
116 # Notify external application
117 if ( $wgUseRCQueue ) {
118 $queue = msg_get_queue( $wgRCQueueID );
119 if (!msg_send( $queue, array_merge( $this->mAttribs, 1, $this->mExtra ),
120 true, false, $error ))
122 wfDebug( "Error sending message to RC queue, code $error\n" );
127 # Makes an entry in the database corresponding to an edit
128 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
129 $oldId, $lastTimestamp )
131 $rc = new RecentChange;
132 $rc->mAttribs = array(
133 'rc_timestamp' => $timestamp,
134 'rc_cur_time' => $timestamp,
135 'rc_namespace' => $title->getNamespace(),
136 'rc_title' => $title->getDBkey(),
137 'rc_type' => RC_EDIT,
138 'rc_minor' => $minor ? 1 : 0,
139 'rc_cur_id' => $title->getArticleID(),
140 'rc_user' => $user->getID(),
141 'rc_user_text' => $user->getName(),
142 'rc_comment' => $comment,
143 'rc_this_oldid' => 0,
144 'rc_last_oldid' => $oldId,
145 'rc_bot' => $user->isBot() ? 1 : 0,
146 'rc_moved_to_ns' => 0,
147 'rc_moved_to_title' => '',
148 'rc_new' => 0 # obsolete
151 $rc->mExtra = array(
152 'prefixedDBkey' => $title->getPrefixedDBkey(),
153 'lastTimestamp' => $lastTimestamp
155 $rc->save();
158 # Makes an entry in the database corresponding to page creation
159 # Note: the title object must be loaded with the new id using resetArticleID()
160 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment )
162 $rc = new RecentChange;
163 $rc->mAttribs = array(
164 'rc_timestamp' => $timestamp,
165 'rc_cur_time' => $timestamp,
166 'rc_namespace' => $title->getNamespace(),
167 'rc_title' => $title->getDBkey(),
168 'rc_type' => RC_NEW,
169 'rc_minor' => $minor ? 1 : 0,
170 'rc_cur_id' => $title->getArticleID(),
171 'rc_user' => $user->getID(),
172 'rc_user_text' => $user->getName(),
173 'rc_comment' => $comment,
174 'rc_this_oldid' => 0,
175 'rc_last_oldid' => 0,
176 'rc_bot' => $user->isBot() ? 1 : 0,
177 'rc_moved_to_ns' => 0,
178 'rc_moved_to_title' => '',
179 'rc_new' => 1 # obsolete
182 $rc->mExtra = array(
183 'prefixedDBkey' => $title->getPrefixedDBkey(),
184 'lastTimestamp' => 0
186 $rc->save();
189 # Makes an entry in the database corresponding to a rename
190 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment )
192 $rc = new RecentChange;
193 $rc->mAttribs = array(
194 'rc_timestamp' => $timestamp,
195 'rc_cur_time' => $timestamp,
196 'rc_namespace' => $oldTitle->getNamespace(),
197 'rc_title' => $oldTitle->getDBkey(),
198 'rc_type' => RC_MOVE,
199 'rc_minor' => 0,
200 'rc_cur_id' => $oldTitle->getArticleID(),
201 'rc_user' => $user->getID(),
202 'rc_user_text' => $user->getName(),
203 'rc_comment' => $comment,
204 'rc_this_oldid' => 0,
205 'rc_last_oldid' => 0,
206 'rc_bot' => $user->isBot() ? 1 : 0,
207 'rc_moved_to_ns' => $newTitle->getNamespace(),
208 'rc_moved_to_title' => $newTitle->getDBkey(),
209 'rc_new' => 0 # obsolete
212 $rc->mExtra = array(
213 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
214 'lastTimestamp' => 0,
215 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
217 $rc->save();
220 # A log entry is different to an edit in that previous revisions are
221 # not kept
222 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment )
224 $rc = new RecentChange;
225 $rc->mAttribs = array(
226 'rc_timestamp' => $timestamp,
227 'rc_cur_time' => $timestamp,
228 'rc_namespace' => $title->getNamespace(),
229 'rc_title' => $title->getDBkey(),
230 'rc_type' => RC_LOG,
231 'rc_minor' => 0,
232 'rc_cur_id' => $title->getArticleID(),
233 'rc_user' => $user->getID(),
234 'rc_user_text' => $user->getName(),
235 'rc_comment' => $comment,
236 'rc_this_oldid' => 0,
237 'rc_last_oldid' => 0,
238 'rc_bot' => 0,
239 'rc_moved_to_ns' => 0,
240 'rc_moved_to_title' => '',
241 'rc_new' => 0 # obsolete
243 $rc->mExtra = array(
244 'prefixedDBkey' => $title->getPrefixedDBkey(),
245 'lastTimestamp' => 0
247 $rc->save();
250 # Initialises the members of this object from a mysql row object
251 function loadFromRow( $row )
253 $this->mAttribs = get_object_vars( $row );
254 $this->mExtra = array();
257 # Makes a pseudo-RC entry from a cur row, for watchlists and things
258 function loadFromCurRow( $row )
260 $this->mAttribs = array(
261 "rc_timestamp" => $row->cur_timestamp,
262 "rc_cur_time" => $row->cur_timestamp,
263 "rc_user" => $row->cur_user,
264 "rc_user_text" => $row->cur_user_text,
265 "rc_namespace" => $row->cur_namespace,
266 "rc_title" => $row->cur_title,
267 "rc_comment" => $row->cur_comment,
268 "rc_minor" => !!$row->cur_minor_edit,
269 "rc_type" => $row->cur_is_new ? RC_NEW : RC_EDIT,
270 "rc_cur_id" => $row->cur_id,
271 'rc_this_oldid' => 0,
272 'rc_last_oldid' => 0,
273 'rc_bot' => 0,
274 'rc_moved_to_ns' => 0,
275 'rc_moved_to_title' => '',
276 'rc_new' => $row->cur_is_new # obsolete
279 $this->mExtra = array();
283 # Gets the end part of the diff URL assoicated with this object
284 # Blank if no diff link should be displayed
285 function diffLinkTrail( $forceCur )
287 if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
288 $trail = "curid=" . (int)($this->mAttribs['rc_cur_id']) .
289 "&oldid=" . (int)($this->mAttribs['rc_last_oldid']);
290 if ( $forceCur ) {
291 $trail .= "&diff=0" ;
292 } else {
293 $trail .= "&diff=" . (int)($this->mAttribs['rc_this_oldid']);
295 } else {
296 $trail = "";
298 return $trail;