26require_once __DIR__ .
'/Maintenance.php';
43 parent::__construct();
48 "Only rebuild rows in requested time range (in YYYYMMDDHHMMSS format)",
54 "Only rebuild rows in requested time range (in YYYYMMDDHHMMSS format)",
66 $this->
fatalError(
"Both 'from' and 'to' must be given, or neither" );
69 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
78 $this->
output(
"Done.\n" );
86 $commentStore = CommentStore::getStore();
93 $days = $sec / 24 / 3600;
94 $this->
output(
"Rebuilding range of $sec seconds ($days days)\n" );
99 $this->
output(
"Rebuilding \$wgRCMaxAge=$wgRCMaxAge seconds ($days days)\n" );
102 $this->cutoffTo = time();
105 $this->
output(
"Clearing recentchanges table for time range...\n" );
106 $rcids = $dbw->selectFieldValues(
110 'rc_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
111 'rc_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
115 $dbw->delete(
'recentchanges', [
'rc_id' => $rcidBatch ], __METHOD__ );
119 $this->
output(
"Loading from page and revision tables...\n" );
121 $commentQuery = $commentStore->getJoin(
'rev_comment' );
122 $actorQuery = ActorMigration::newMigration()->getJoin(
'rev_user' );
124 [
'revision',
'page' ] + $commentQuery[
'tables'] + $actorQuery[
'tables'],
134 ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
136 'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
137 'rev_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
140 [
'ORDER BY' =>
'rev_timestamp DESC' ],
142 'page' => [
'JOIN',
'rev_page=page_id' ],
143 ] + $commentQuery[
'joins'] + $actorQuery[
'joins']
146 $this->
output(
"Inserting from page and revision tables...\n" );
148 $actorMigration = ActorMigration::newMigration();
149 foreach (
$res as $row ) {
150 $comment = $commentStore->getComment(
'rev_comment', $row );
155 'rc_timestamp' => $row->rev_timestamp,
156 'rc_namespace' => $row->page_namespace,
157 'rc_title' => $row->page_title,
158 'rc_minor' => $row->rev_minor_edit,
160 'rc_new' => $row->page_is_new,
161 'rc_cur_id' => $row->page_id,
162 'rc_this_oldid' => $row->rev_id,
163 'rc_last_oldid' => 0,
165 'rc_source' => $row->page_is_new ? RecentChange::SRC_NEW : RecentChange::SRC_EDIT,
166 'rc_deleted' => $row->rev_deleted
167 ] + $commentStore->insert( $dbw,
'rc_comment', $comment )
168 + $actorMigration->getInsertValues( $dbw,
'rc_user', $user ),
172 $rcid = $dbw->insertId();
175 [
'ct_rc_id' => $rcid ],
176 [
'ct_rev_id' => $row->rev_id ],
193 $this->
output(
"Updating links and size differences...\n" );
195 # Fill in the rc_last_oldid field, which points to the previous edit
198 [
'rc_cur_id',
'rc_this_oldid',
'rc_timestamp' ],
200 "rc_timestamp > " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
201 "rc_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
204 [
'ORDER BY' =>
'rc_cur_id,rc_timestamp' ]
211 foreach (
$res as $obj ) {
214 if ( $obj->rc_cur_id != $lastCurId ) {
215 # Switch! Look up the previous last edit, if any
216 $lastCurId =
intval( $obj->rc_cur_id );
217 $emit = $obj->rc_timestamp;
219 $row = $dbw->selectRow(
221 [
'rev_id',
'rev_len' ],
222 [
'rev_page' => $lastCurId,
"rev_timestamp < " . $dbw->addQuotes( $emit ) ],
224 [
'ORDER BY' =>
'rev_timestamp DESC' ]
227 $lastOldId =
intval( $row->rev_id );
228 # Grab the last text size if available
229 $lastSize = !
is_null( $row->rev_len ) ?
intval( $row->rev_len ) :
null;
238 if ( $lastCurId == 0 ) {
239 $this->
output(
"Uhhh, something wrong? No curid\n" );
241 # Grab the entry's text size
242 $size = (
int)$dbw->selectField(
245 [
'rev_id' => $obj->rc_this_oldid ],
252 'rc_last_oldid' => $lastOldId,
255 'rc_source' => $new === 1 ? RecentChange::SRC_NEW : RecentChange::SRC_EDIT,
257 'rc_new_len' => $size,
261 'rc_this_oldid' => $obj->rc_this_oldid,
262 'rc_timestamp' => $obj->rc_timestamp
267 $lastOldId =
intval( $obj->rc_this_oldid );
284 $commentStore = CommentStore::getStore();
289 $this->
output(
"Loading from user and logging tables...\n" );
291 $commentQuery = $commentStore->getJoin(
'log_comment' );
292 $actorQuery = ActorMigration::newMigration()->getJoin(
'log_user' );
294 [
'logging' ] + $commentQuery[
'tables'] + $actorQuery[
'tables'],
305 ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
307 'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
308 'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
313 [
'ORDER BY' =>
'log_timestamp DESC' ],
314 $commentQuery[
'joins'] + $actorQuery[
'joins']
317 $field = $dbw->fieldInfo(
'recentchanges',
'rc_cur_id' );
320 $actorMigration = ActorMigration::newMigration();
321 foreach (
$res as $row ) {
322 $comment = $commentStore->getComment(
'log_comment', $row );
327 'rc_timestamp' => $row->log_timestamp,
328 'rc_namespace' => $row->log_namespace,
329 'rc_title' => $row->log_title,
332 'rc_patrolled' => $row->log_type ==
'upload' ? 0 : 2,
334 'rc_this_oldid' => 0,
335 'rc_last_oldid' => 0,
337 'rc_source' => RecentChange::SRC_LOG,
338 'rc_cur_id' => $field->isNullable()
340 : (
int)$row->log_page,
341 'rc_log_type' => $row->log_type,
342 'rc_log_action' => $row->log_action,
343 'rc_logid' => $row->log_id,
344 'rc_params' => $row->log_params,
345 'rc_deleted' => $row->log_deleted
346 ] + $commentStore->insert( $dbw,
'rc_comment', $comment )
347 + $actorMigration->getInsertValues( $dbw,
'rc_user', $user ),
351 $rcid = $dbw->insertId();
354 [
'ct_rc_id' => $rcid ],
355 [
'ct_log_id' => $row->log_id ],
375 # @FIXME: recognize other bot account groups (not the same as users with 'bot' rights)
376 # @NOTE: users with 'bot' rights choose when edits are bot edits or not. That information
377 # may be lost at this point (aside from joining on the patrol log table entries).
378 $botgroups = [
'bot' ];
381 # Flag our recent bot edits
383 $this->
output(
"Flagging bot account edits...\n" );
385 # Find all users that are bots
387 array_merge( [
'user_groups' ], $userQuery[
'tables'] ),
388 $userQuery[
'fields'],
389 [
'ug_group' => $botgroups ],
392 [
'user_groups' => [
'JOIN',
'user_id = ug_user' ] ] + $userQuery[
'joins']
396 foreach (
$res as $obj ) {
400 # Fill in the rc_bot field
402 $actorQuery = ActorMigration::newMigration()->getWhere( $dbw,
'rc_user', $botusers,
false );
404 foreach ( $actorQuery[
'orconds'] as $cond ) {
405 $rcids =
array_merge( $rcids, $dbw->selectFieldValues(
406 [
'recentchanges' ] + $actorQuery[
'tables'],
409 "rc_timestamp > " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
410 "rc_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
424 [
'rc_id' => $rcidBatch ],
432 # Flag our recent autopatrolled edits
436 $this->
output(
"Flagging auto-patrolled edits...\n" );
438 # Find all users in RC with autopatrol rights
440 array_merge( [
'user_groups' ], $userQuery[
'tables'] ),
441 $userQuery[
'fields'],
442 [
'ug_group' => $autopatrolgroups ],
445 [
'user_groups' => [
'JOIN',
'user_id = ug_user' ] ] + $userQuery[
'joins']
448 foreach (
$res as $obj ) {
452 # Fill in the rc_patrolled field
453 if ( $patrolusers ) {
454 $actorQuery = ActorMigration::newMigration()->getWhere( $dbw,
'rc_user', $patrolusers,
false );
455 foreach ( $actorQuery[
'orconds'] as $cond ) {
458 [
'rc_patrolled' => 2 ],
461 'rc_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
462 'rc_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
480 $this->
output(
"Removing duplicate revision and logging entries...\n" );
483 [
'logging',
'log_search' ],
484 [
'ls_value',
'ls_log_id' ],
486 'ls_log_id = log_id',
487 'ls_field' =>
'associated_rev_id',
488 'log_type' =>
'upload',
489 'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
490 'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
496 foreach (
$res as $obj ) {
497 $rev_id = $obj->ls_value;
498 $log_id = $obj->ls_log_id;
503 [
'rc_this_oldid' => $rev_id ],
504 [
'rc_logid' => $log_id ],
511 [
'rc_this_oldid' => $rev_id,
'rc_logid' => 0 ],
527 $this->
output(
"Deleting feed timestamps.\n" );
529 $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
531 $wanCache->delete( $wanCache->makeKey(
'rcfeed', $feed,
'timestamp' ) ); # Good enough
for now.
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
$wgRCMaxAge
Recentchanges items are periodically purged; entries older than this many seconds will go.
$wgFeedClasses
Available feeds objects.
$wgFilterLogTypes
Show/hide links on Special:Log will be shown for these log types.
$wgMiserMode
Disable database-intensive features.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static validTypes()
Get the list of valid log types.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that rebuilds recent changes from scratch.
execute()
Do the actual work.
rebuildRecentChangesTablePass5(ILBFactory $lbFactory)
Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry for a...
int $cutoffFrom
UNIX timestamp.
rebuildRecentChangesTablePass3(ILBFactory $lbFactory)
Rebuild pass 3: Insert recentchanges entries for action logs.
rebuildRecentChangesTablePass4(ILBFactory $lbFactory)
Rebuild pass 4: Mark bot and autopatrolled entries.
int $cutoffTo
UNIX timestamp.
__construct()
Default constructor.
rebuildRecentChangesTablePass1(ILBFactory $lbFactory)
Rebuild pass 1: Insert recentchanges entries for page revisions.
rebuildRecentChangesTablePass2(ILBFactory $lbFactory)
Rebuild pass 2: Enhance entries for page revisions with references to the previous revision (rc_last_...
purgeFeeds()
Purge cached feeds in $wanCache.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
require_once RUN_MAINTENANCE_IF_MAIN