26 require_once __DIR__ .
'/Maintenance.php';
35 parent::__construct();
36 $this->mDescription =
"Rebuild recent changes";
45 $this->
output(
"Done.\n" );
55 $dbw->delete(
'recentchanges',
'*' );
57 $this->
output(
"Loading from page and revision tables...\n" );
61 $this->
output(
'$wgRCMaxAge=' . $wgRCMaxAge );
62 $days = $wgRCMaxAge / 24 / 3600;
63 if ( intval( $days ) == $days ) {
64 $this->
output(
" (" . $days .
" days)\n" );
66 $this->
output(
" (approx. " . intval( $days ) .
" days)\n" );
69 $cutoff = time() - $wgRCMaxAge;
70 $dbw->insertSelect(
'recentchanges',
array(
'page',
'revision' ),
72 'rc_timestamp' =>
'rev_timestamp',
73 'rc_user' =>
'rev_user',
74 'rc_user_text' =>
'rev_user_text',
75 'rc_namespace' =>
'page_namespace',
76 'rc_title' =>
'page_title',
77 'rc_comment' =>
'rev_comment',
78 'rc_minor' =>
'rev_minor_edit',
80 'rc_new' =>
'page_is_new',
81 'rc_cur_id' =>
'page_id',
82 'rc_this_oldid' =>
'rev_id',
84 'rc_type' => $dbw->conditional(
'page_is_new != 0',
RC_NEW,
RC_EDIT ),
86 'rc_deleted' =>
'rev_deleted'
88 'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
92 array(
'ORDER BY' =>
'rev_timestamp DESC',
'LIMIT' => 5000 )
102 list( $recentchanges, $revision ) = $dbw->tableNamesN(
'recentchanges',
'revision' );
104 $this->
output(
"Updating links and size differences...\n" );
106 # Fill in the rc_last_oldid field, which points to the previous edit
107 $sql =
"SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
108 "ORDER BY rc_cur_id,rc_timestamp";
113 foreach (
$res as $obj ) {
115 if ( $obj->rc_cur_id != $lastCurId ) {
116 # Switch! Look up the previous last edit, if any
117 $lastCurId = intval( $obj->rc_cur_id );
118 $emit = $obj->rc_timestamp;
119 $sql2 =
"SELECT rev_id,rev_len FROM $revision " .
120 "WHERE rev_page={$lastCurId} " .
121 "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC";
122 $sql2 = $dbw->limitResult( $sql2, 1,
false );
123 $res2 = $dbw->query( $sql2 );
124 $row = $dbw->fetchObject( $res2 );
126 $lastOldId = intval( $row->rev_id );
127 # Grab the last text size if available
128 $lastSize = !is_null( $row->rev_len ) ? intval( $row->rev_len ) :
null;
136 if ( $lastCurId == 0 ) {
137 $this->
output(
"Uhhh, something wrong? No curid\n" );
139 # Grab the entry's text size
140 $size = $dbw->selectField(
'revision',
'rev_len',
array(
'rev_id' => $obj->rc_this_oldid ) );
142 $dbw->update(
'recentchanges',
144 'rc_last_oldid' => $lastOldId,
148 'rc_old_len' => $lastSize,
149 'rc_new_len' =>
$size,
151 'rc_cur_id' => $lastCurId,
152 'rc_this_oldid' => $obj->rc_this_oldid,
157 $lastOldId = intval( $obj->rc_this_oldid );
170 $this->
output(
"Loading from user, page, and logging tables...\n" );
172 global $wgRCMaxAge, $wgLogTypes, $wgLogRestrictions;
174 $basicRCLogs = array_diff( $wgLogTypes, array_keys( $wgLogRestrictions ) );
177 $selectLogs =
array();
178 foreach ( $basicRCLogs
as $logtype ) {
179 $safetype = $dbw->strencode( $logtype );
180 $selectLogs[] =
"'$safetype'";
183 $cutoff = time() - $wgRCMaxAge;
184 list( $logging, $page ) = $dbw->tableNamesN(
'logging',
'page' );
185 $dbw->insertSelect(
'recentchanges',
array(
'user',
"$logging LEFT JOIN $page ON (log_namespace=page_namespace AND log_title=page_title)" ),
187 'rc_timestamp' =>
'log_timestamp',
188 'rc_user' =>
'log_user',
189 'rc_user_text' =>
'user_name',
190 'rc_namespace' =>
'log_namespace',
191 'rc_title' =>
'log_title',
192 'rc_comment' =>
'log_comment',
197 'rc_this_oldid' => 0,
198 'rc_last_oldid' => 0,
201 'rc_cur_id' => $dbw->cascadingDeletes() ?
'page_id' :
'COALESCE(page_id, 0)',
202 'rc_log_type' =>
'log_type',
203 'rc_log_action' =>
'log_action',
204 'rc_logid' =>
'log_id',
205 'rc_params' =>
'log_params',
206 'rc_deleted' =>
'log_deleted'
208 'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
210 'log_type IN(' . implode(
',', $selectLogs ) .
')'
213 array(
'ORDER BY' =>
'log_timestamp DESC',
'LIMIT' => 5000 )
226 list( $recentchanges, $usergroups,
$user ) = $dbw->tableNamesN(
'recentchanges',
'user_groups',
'user' );
230 # Flag our recent bot edits
231 if ( !empty( $botgroups ) ) {
232 $botwhere = $dbw->makeList( $botgroups );
235 $this->
output(
"Flagging bot account edits...\n" );
237 # Find all users that are bots
238 $sql =
"SELECT DISTINCT user_name FROM $usergroups, $user " .
239 "WHERE ug_group IN($botwhere) AND user_id = ug_user";
242 foreach (
$res as $obj ) {
243 $botusers[] = $dbw->addQuotes( $obj->user_name );
245 # Fill in the rc_bot field
246 if ( !empty( $botusers ) ) {
247 $botwhere = implode(
',', $botusers );
248 $sql2 =
"UPDATE $recentchanges SET rc_bot=1 " .
249 "WHERE rc_user_text IN($botwhere)";
250 $dbw->query( $sql2 );
254 # Flag our recent autopatrolled edits
255 if ( !$wgMiserMode && !empty( $autopatrolgroups ) ) {
256 $patrolwhere = $dbw->makeList( $autopatrolgroups );
257 $patrolusers =
array();
259 $this->
output(
"Flagging auto-patrolled edits...\n" );
261 # Find all users in RC with autopatrol rights
262 $sql =
"SELECT DISTINCT user_name FROM $usergroups, $user " .
263 "WHERE ug_group IN($patrolwhere) AND user_id = ug_user";
266 foreach (
$res as $obj ) {
267 $patrolusers[] = $dbw->addQuotes( $obj->user_name );
270 # Fill in the rc_patrolled field
271 if ( !empty( $patrolusers ) ) {
272 $patrolwhere = implode(
',', $patrolusers );
273 $sql2 =
"UPDATE $recentchanges SET rc_patrolled=1 " .
274 "WHERE rc_user_text IN($patrolwhere)";
275 $dbw->query( $sql2 );
286 $this->
output(
"Deleting feed timestamps.\n" );
288 foreach ( $wgFeedClasses
as $feed => $className ) {