00001 <?php
00002
# Utility class for creating new RC entries
00003
00004 define(
"RC_EDIT", 0);
00005 define(
"RC_NEW", 1);
00006 define(
"RC_MOVE", 2);
00007 define(
"RC_LOG", 3);
00008 define(
"RC_MOVE_OVER_REDIRECT", 4);
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class RecentChange
00036 {
00037 var
$mAttribs = array(), $mExtra = array();
00038 var
$mTitle =
false, $mMovedToTitle =
false;
00039
00040
# Factory methods
00041
00042 function
newFromRow( $row )
00043 {
00044 $rc =
new RecentChange;
00045 $rc->loadFromRow( $row );
00046
return $rc;
00047 }
00048
00049 function
newFromCurRow( $row )
00050 {
00051 $rc =
new RecentChange;
00052 $rc->loadFromCurRow( $row );
00053
return $rc;
00054 }
00055
00056
# Accessors
00057
00058 function
setAttribs( $attribs )
00059 {
00060 $this->mAttribs = $attribs;
00061 }
00062
00063 function
setExtra( $extra )
00064 {
00065 $this->mExtra = $extra;
00066 }
00067
00068 function
getTitle()
00069 {
00070
if ( $this->mTitle ===
false ) {
00071 $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
00072 }
00073
return $this->mTitle;
00074 }
00075
00076 function
getMovedToTitle()
00077 {
00078
if ( $this->mMovedToTitle ===
false ) {
00079 $this->mMovedToTitle = Title::makeTitle( $this->mAttribs['rc_moved_to_ns'],
00080 $this->mAttribs['rc_moved_to_title'] );
00081 }
00082
return $this->mMovedToTitle;
00083 }
00084
00085
# Writes the data in this object to the database
00086 function
save()
00087 {
00088 global $wgUseRCQueue, $wgRCQueueID,
$wgLocalInterwiki, $wgPutIPinRC;
00089 $fname =
"RecentChange::save";
00090
00091
if ( !is_array($this->mExtra) ) {
00092 $this->mExtra = array();
00093 }
00094 $this->mExtra['lang'] =
$wgLocalInterwiki;
00095
00096
if ( !$wgPutIPinRC ) {
00097 $this->mAttribs['rc_ip'] = '';
00098 }
00099
00100
# Insert new row
00101
wfInsertArray(
"recentchanges", $this->mAttribs, $fname );
00102
00103
# Update old rows, if necessary
00104
if ( $this->mAttribs['rc_type'] ==
RC_EDIT ) {
00105 $oldid = $this->mAttribs['rc_last_oldid'];
00106 $ns = $this->mAttribs['rc_namespace'];
00107
$title =
wfStrencode($this->mAttribs['rc_title']);
00108 $lastTime = $this->mExtra['lastTimestamp'];
00109 $now = $this->mAttribs['rc_timestamp'];
00110 $curId = $this->mAttribs['rc_cur_id'];
00111
00112
# Update rc_this_oldid for the entries which were current
00113
$sql =
"UPDATE recentchanges SET rc_this_oldid={$oldid} " .
00114
"WHERE rc_namespace=$ns AND rc_title='$title' AND rc_timestamp='$lastTime'";
00115
wfQuery( $sql,
DB_WRITE, $fname );
00116
00117
# Update rc_cur_time
00118
$sql =
"UPDATE recentchanges SET rc_cur_time='{$now}' " .
00119
"WHERE rc_cur_id=" . $curId;
00120
wfQuery( $sql,
DB_WRITE, $fname );
00121 }
00122
00123
# Notify external application
00124
if ( $wgUseRCQueue ) {
00125
$queue = msg_get_queue( $wgRCQueueID );
00126
if (!msg_send( $queue, array_merge( $this->mAttribs, 1, $this->mExtra ),
00127
true,
false, $error ))
00128 {
00129
wfDebug(
"Error sending message to RC queue, code $error\n" );
00130 }
00131 }
00132 }
00133
00134
# Makes an entry in the database corresponding to an edit
00135 function
notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
00136 $oldId, $lastTimestamp, $bot =
"default", $ip = '' )
00137 {
00138
if ( $bot ==
"default " ) {
00139 $bot =
$user->isBot();
00140 }
00141
00142
if ( !$ip ) {
00143 global
$wgIP;
00144 $ip = empty( $wgIP ) ? '' :
$wgIP;
00145 }
00146
00147 $rc =
new RecentChange;
00148 $rc->mAttribs = array(
00149 'rc_timestamp' => $timestamp,
00150 'rc_cur_time' => $timestamp,
00151 'rc_namespace' => $
title->getNamespace(),
00152 'rc_title' =>
$title->getDBkey(),
00153 'rc_type' =>
RC_EDIT,
00154 'rc_minor' => $minor ? 1 : 0,
00155 'rc_cur_id' =>
$title->getArticleID(),
00156 'rc_user' =>
$user->getID(),
00157 'rc_user_text' =>
$user->getName(),
00158 'rc_comment' =>
$comment,
00159 'rc_this_oldid' => 0,
00160 'rc_last_oldid' => $oldId,
00161 'rc_bot' => $bot ? 1 : 0,
00162 'rc_moved_to_ns' => 0,
00163 'rc_moved_to_title' => '',
00164 'rc_ip' => $ip,
00165 'rc_new' => 0 #
obsolete
00166 );
00167
00168 $rc->mExtra = array(
00169 'prefixedDBkey' => $
title->getPrefixedDBkey(),
00170 'lastTimestamp' => $lastTimestamp
00171 );
00172 $rc->save();
00173 }
00174
00175
# Makes an entry in the database corresponding to page creation
00176
# Note: the title object must be loaded with the new id using resetArticleID()
00177 function
notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot =
"default", $ip='' )
00178 {
00179
if ( !$ip ) {
00180 global
$wgIP;
00181 $ip = empty( $wgIP ) ? '' :
$wgIP;
00182 }
00183
if ( $bot ==
"default" ) {
00184 $bot =
$user->isBot();
00185 }
00186
00187 $rc =
new RecentChange;
00188 $rc->mAttribs = array(
00189 'rc_timestamp' => $timestamp,
00190 'rc_cur_time' => $timestamp,
00191 'rc_namespace' => $
title->getNamespace(),
00192 'rc_title' =>
$title->getDBkey(),
00193 'rc_type' =>
RC_NEW,
00194 'rc_minor' => $minor ? 1 : 0,
00195 'rc_cur_id' =>
$title->getArticleID(),
00196 'rc_user' =>
$user->getID(),
00197 'rc_user_text' =>
$user->getName(),
00198 'rc_comment' =>
$comment,
00199 'rc_this_oldid' => 0,
00200 'rc_last_oldid' => 0,
00201 'rc_bot' => $bot ? 1 : 0,
00202 'rc_moved_to_ns' => 0,
00203 'rc_moved_to_title' => '',
00204 'rc_ip' => $ip,
00205 'rc_new' => 1 #
obsolete
00206 );
00207
00208 $rc->mExtra = array(
00209 'prefixedDBkey' => $
title->getPrefixedDBkey(),
00210 'lastTimestamp' => 0
00211 );
00212 $rc->save();
00213 }
00214
00215
# Makes an entry in the database corresponding to a rename
00216 function
notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir =
false )
00217 {
00218
if ( !$ip ) {
00219 global
$wgIP;
00220 $ip = empty( $wgIP ) ? '' :
$wgIP;
00221 }
00222 $rc =
new RecentChange;
00223 $rc->mAttribs = array(
00224 'rc_timestamp' => $timestamp,
00225 'rc_cur_time' => $timestamp,
00226 'rc_namespace' => $oldTitle->getNamespace(),
00227 'rc_title' => $oldTitle->getDBkey(),
00228 'rc_type' => $overRedir ?
RC_MOVE_OVER_REDIRECT :
RC_MOVE,
00229 'rc_minor' => 0,
00230 'rc_cur_id' => $oldTitle->getArticleID(),
00231 'rc_user' =>
$user->getID(),
00232 'rc_user_text' =>
$user->getName(),
00233 'rc_comment' =>
$comment,
00234 'rc_this_oldid' => 0,
00235 'rc_last_oldid' => 0,
00236 'rc_bot' =>
$user->isBot() ? 1 : 0,
00237 'rc_moved_to_ns' => $newTitle->getNamespace(),
00238 'rc_moved_to_title' => $newTitle->getDBkey(),
00239 'rc_ip' => $ip,
00240 'rc_new' => 0 #
obsolete
00241 );
00242
00243 $rc->mExtra = array(
00244 'prefixedDBkey' => $oldTitle->getPrefixedDBkey(),
00245 'lastTimestamp' => 0,
00246 'prefixedMoveTo' => $newTitle->getPrefixedDBkey()
00247 );
00248 $rc->save();
00249 }
00250
00251 function
notifyMoveToNew( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
00252
RecentChange::notifyMove( $timestamp, &$oldTitle, &$newTitle, &$
user, $comment, $ip,
false );
00253 }
00254
00255 function
notifyMoveOverRedirect( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='' ) {
00256
RecentChange::notifyMove( $timestamp, &$oldTitle, &$newTitle, &$
user, $comment, $ip='',
true );
00257 }
00258
00259
# A log entry is different to an edit in that previous revisions are
00260
# not kept
00261 function
notifyLog( $timestamp, &$title, &$user, $comment, $ip='' )
00262 {
00263
if ( !$ip ) {
00264 global
$wgIP;
00265 $ip = empty( $wgIP ) ? '' :
$wgIP;
00266 }
00267 $rc =
new RecentChange;
00268 $rc->mAttribs = array(
00269 'rc_timestamp' => $timestamp,
00270 'rc_cur_time' => $timestamp,
00271 'rc_namespace' => $
title->getNamespace(),
00272 'rc_title' =>
$title->getDBkey(),
00273 'rc_type' =>
RC_LOG,
00274 'rc_minor' => 0,
00275 'rc_cur_id' =>
$title->getArticleID(),
00276 'rc_user' =>
$user->getID(),
00277 'rc_user_text' =>
$user->getName(),
00278 'rc_comment' =>
$comment,
00279 'rc_this_oldid' => 0,
00280 'rc_last_oldid' => 0,
00281 'rc_bot' => 0,
00282 'rc_moved_to_ns' => 0,
00283 'rc_moved_to_title' => '',
00284 'rc_ip' => $ip,
00285 'rc_new' => 0 #
obsolete
00286 );
00287 $rc->mExtra = array(
00288 'prefixedDBkey' => $
title->getPrefixedDBkey(),
00289 'lastTimestamp' => 0
00290 );
00291 $rc->save();
00292 }
00293
00294
# Initialises the members of this object from a mysql row object
00295 function
loadFromRow( $row )
00296 {
00297 $this->mAttribs = get_object_vars( $row );
00298 $this->mExtra = array();
00299 }
00300
00301
# Makes a pseudo-RC entry from a cur row, for watchlists and things
00302 function
loadFromCurRow( $row )
00303 {
00304 $this->mAttribs = array(
00305
"rc_timestamp" => $row->cur_timestamp,
00306
"rc_cur_time" => $row->cur_timestamp,
00307
"rc_user" => $row->cur_user,
00308
"rc_user_text" => $row->cur_user_text,
00309
"rc_namespace" => $row->cur_namespace,
00310
"rc_title" => $row->cur_title,
00311
"rc_comment" => $row->cur_comment,
00312
"rc_minor" => !!$row->cur_minor_edit,
00313
"rc_type" => $row->cur_is_new ?
RC_NEW :
RC_EDIT,
00314
"rc_cur_id" => $row->cur_id,
00315 'rc_this_oldid' => 0,
00316 'rc_last_oldid' => 0,
00317 'rc_bot' => 0,
00318 'rc_moved_to_ns' => 0,
00319 'rc_moved_to_title' => '',
00320 'rc_ip' => '',
00321 'rc_new' => $row->cur_is_new #
obsolete
00322 );
00323
00324 $this->mExtra = array();
00325 }
00326
00327
00328
# Gets the end part of the diff URL assoicated with this object
00329
# Blank if no diff link should be displayed
00330 function
diffLinkTrail( $forceCur )
00331 {
00332
if ( $this->mAttribs['rc_type'] ==
RC_EDIT ) {
00333 $trail =
"curid=" . (
int)($this->mAttribs['rc_cur_id']) .
00334
"&oldid=" . (
int)($this->mAttribs['rc_last_oldid']);
00335
if ( $forceCur ) {
00336 $trail .=
"&diff=0" ;
00337 }
else {
00338 $trail .=
"&diff=" . (
int)($this->mAttribs['rc_this_oldid']);
00339 }
00340 }
else {
00341 $trail =
"";
00342 }
00343
return $trail;
00344 }
00345 }
00346 ?>