2 # Utility class for creating new RC entries
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
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)
26 prefixedDBkey prefixed db key, used by external app via msg queue
27 lastTimestamp timestamp of previous entry, used in WHERE clause during update
28 lang the interwiki prefix, automatically set in save()
33 var $mAttribs = array(), $mExtra = array();
34 var $mTitle = false, $mMovedToTitle = false;
38 /* static */ function newFromRow( $row )
40 $rc = new RecentChange
;
41 $rc->loadFromRow( $row );
47 function setAttribs( $attribs )
49 $this->mAttribs
= $attribs;
52 function setExtra( $extra )
54 $this->mExtra
= $extra;
59 if ( $this->mTitle
=== false ) {
60 $this->mTitle
= Title
::makeTitle( $this->mAttribs
['rc_namespace'], $this->mAttribs
['rc_title'] );
65 function getMovedToTitle()
67 if ( $this->mMovedToTitle
=== false ) {
68 $this->mMovedToTitle
= Title
::makeTitle( $this->mAttribs
['rc_moved_to_ns'],
69 $this->mAttribs
['rc_moved_to_title'] );
71 return $this->mMovedToTitle
;
74 # Writes the data in this object to the database
77 global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki;
78 $fname = "RecentChange::save";
80 if ( !is_array($this->mExtra
) ) {
81 $this->mExtra
= array();
83 $this->mExtra
['lang'] = $wgLocalInterwiki;
86 wfInsertArray( "recentchanges", $this->mAttribs
, $fname );
88 # Update old rows, if necessary
89 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
90 $oldid = $this->mAttribs
['rc_last_oldid'];
91 $ns = $this->mAttribs
['rc_namespace'];
92 $title = wfStrencode($this->mAttribs
['rc_title']);
93 $lastTime = $this->mExtra
['lastTimestamp'];
94 $now = $this->mAttribs
['rc_timestamp'];
95 $curId = $this->mAttribs
['rc_cur_id'];
97 # Update rc_this_oldid for the entries which were current
98 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
99 "WHERE rc_namespace=$ns AND rc_title='$title' AND rc_timestamp='$lastTime'";
100 wfQuery( $sql, DB_WRITE
, $fname );
103 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
104 "WHERE rc_cur_id=" . $curId;
105 wfQuery( $sql, DB_WRITE
, $fname );
108 # Notify external application
109 if ( $wgUseRCQueue ) {
110 $queue = msg_get_queue( $wgRCQueueID );
111 if (!msg_send( $queue, array_merge( $this->mAttribs
, 1, $this->mExtra
),
112 true, false, $error ))
114 wfDebug( "Error sending message to RC queue, code $error\n" );
119 # Makes an entry in the database corresponding to an edit
120 /*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
121 $oldId, $lastTimestamp )
123 $rc = new RecentChange
;
124 $rc->mAttribs
= array(
125 'rc_timestamp' => $timestamp,
126 'rc_cur_time' => $timestamp,
127 'rc_namespace' => $title->getNamespace(),
128 'rc_title' => $title->getDBkey(),
129 'rc_type' => RC_EDIT
,
130 'rc_minor' => $minor ?
1 : 0,
131 'rc_cur_id' => $title->getArticleID(),
132 'rc_user' => $user->getID(),
133 'rc_user_text' => $user->getName(),
134 'rc_comment' => $comment,
135 'rc_this_oldid' => 0,
136 'rc_last_oldid' => $oldId,
137 'rc_bot' => $user->isBot() ?
1 : 0,
138 'rc_moved_to_ns' => 0,
139 'rc_moved_to_title' => ''
143 'prefixedDBkey' => $title->getPrefixedDBkey(),
144 'lastTimestamp' => $lastTimestamp
149 # Makes an entry in the database corresponding to page creation
150 # Note: the title object must be loaded with the new id using resetArticleID()
151 /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment )
153 $rc = new RecentChange
;
154 $rc->mAttribs
= array(
155 'rc_timestamp' => $timestamp,
156 'rc_cur_time' => $timestamp,
157 'rc_namespace' => $title->getNamespace(),
158 'rc_title' => $title->getDBkey(),
160 'rc_minor' => $minor ?
1 : 0,
161 'rc_cur_id' => $title->getArticleID(),
162 'rc_user' => $user->getID(),
163 'rc_user_text' => $user->getName(),
164 'rc_comment' => $comment,
165 'rc_this_oldid' => 0,
166 'rc_last_oldid' => 0,
167 'rc_bot' => $user->isBot() ?
1 : 0,
168 'rc_moved_to_ns' => 0,
169 'rc_moved_to_title' => ''
173 'prefixedDBkey' => $title->getPrefixedDBkey(),
179 # Makes an entry in the database corresponding to a rename
180 /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment )
182 $rc = new RecentChange
;
183 $rc->mAttribs
= array(
184 'rc_timestamp' => $timestamp,
185 'rc_cur_time' => $timestamp,
186 'rc_namespace' => $oldTitle->getNamespace(),
187 'rc_title' => $oldTitle->getDBkey(),
188 'rc_type' => RC_MOVE
,
190 'rc_cur_id' => $oldTitle->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' => 0,
196 'rc_bot' => $user->isBot() ?
1 : 0,
197 'rc_moved_to_ns' => $newTitle->getNamespace(),
198 'rc_moved_to_title' => $newTitle->getDBkey()
202 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
203 'lastTimestamp' => 0,
204 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
209 # A log entry is different to an edit in that previous revisions are
211 /*static*/ function notifyLog( $timestamp, &$title, &$user, $comment )
213 $rc = new RecentChange
;
214 $rc->mAttribs
= array(
215 'rc_timestamp' => $timestamp,
216 'rc_cur_time' => $timestamp,
217 'rc_namespace' => $title->getNamespace(),
218 'rc_title' => $title->getDBkey(),
221 'rc_cur_id' => $title->getArticleID(),
222 'rc_user' => $user->getID(),
223 'rc_user_text' => $user->getName(),
224 'rc_comment' => $comment,
225 'rc_this_oldid' => 0,
226 'rc_last_oldid' => 0,
228 'rc_moved_to_ns' => 0,
229 'rc_moved_to_title' => ''
232 'prefixedDBkey' => $title->getPrefixedDBkey(),
238 # Initialises the members of this object from a mysql row object
239 function loadFromRow( $row )
241 $this->mAttribs
= get_object_vars( $row );
242 $this->mExtra
= array();
245 # Gets the end part of the diff URL assoicated with this object
246 # Blank if no diff link should be displayed
247 function diffLinkTrail( $forceCur )
249 if ( $this->mAttribs
['rc_type'] == RC_EDIT
) {
250 $trail = "curid=" . (int)($this->mAttribs
['rc_cur_id']) .
251 "&oldid=" . (int)($this->mAttribs
['rc_last_oldid']);
253 $trail .= "&diff=0" ;
255 $trail .= "&diff=" . (int)($this->mAttribs
['rc_this_oldid']);