26require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
46 "Only rebuild rows in requested time range (in YYYYMMDDHHMMSS format)",
52 "Only rebuild rows in requested time range (in YYYYMMDDHHMMSS format)",
64 $this->
error(
"Both 'from' and 'to' must be given, or neither", 1 );
75 $this->
output(
"Done.\n" );
91 $days = $sec / 24 / 3600;
92 $this->
output(
"Rebuilding range of $sec seconds ($days days)\n" );
97 $this->
output(
"Rebuilding \$wgRCMaxAge=$wgRCMaxAge seconds ($days days)\n" );
100 $this->cutoffTo = time();
103 $this->
output(
"Clearing recentchanges table for time range...\n" );
104 $rcids = $dbw->selectFieldValues(
108 'rc_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
109 'rc_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
112 foreach ( array_chunk( $rcids, $this->mBatchSize ) as $rcidBatch ) {
113 $dbw->delete(
'recentchanges', [
'rc_id' => $rcidBatch ], __METHOD__ );
117 $this->
output(
"Loading from page and revision tables...\n" );
119 $commentQuery = $revCommentStore->getJoin();
121 [
'revision',
'page' ] + $commentQuery[
'tables'],
133 ] + $commentQuery[
'fields'],
135 'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
136 'rev_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
139 [
'ORDER BY' =>
'rev_timestamp DESC' ],
141 'page' => [
'JOIN',
'rev_page=page_id' ],
142 ] + $commentQuery[
'joins']
145 $this->
output(
"Inserting from page and revision tables...\n" );
147 foreach (
$res as $row ) {
148 $comment = $revCommentStore->getComment( $row );
152 'rc_timestamp' => $row->rev_timestamp,
153 'rc_user' => $row->rev_user,
154 'rc_user_text' => $row->rev_user_text,
155 'rc_namespace' => $row->page_namespace,
156 'rc_title' => $row->page_title,
157 'rc_minor' => $row->rev_minor_edit,
159 'rc_new' => $row->page_is_new,
160 'rc_cur_id' => $row->page_id,
161 'rc_this_oldid' => $row->rev_id,
162 'rc_last_oldid' => 0,
165 'rc_deleted' => $row->rev_deleted
166 ] + $rcCommentStore->insert( $dbw, $comment ),
169 if ( ( ++$inserted % $this->mBatchSize ) == 0 ) {
182 $this->
output(
"Updating links and size differences...\n" );
184 # Fill in the rc_last_oldid field, which points to the previous edit
187 [
'rc_cur_id',
'rc_this_oldid',
'rc_timestamp' ],
189 "rc_timestamp > " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
190 "rc_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
193 [
'ORDER BY' =>
'rc_cur_id,rc_timestamp' ]
200 foreach (
$res as $obj ) {
203 if ( $obj->rc_cur_id != $lastCurId ) {
204 # Switch! Look up the previous last edit, if any
205 $lastCurId = intval( $obj->rc_cur_id );
206 $emit = $obj->rc_timestamp;
208 $row = $dbw->selectRow(
210 [
'rev_id',
'rev_len' ],
211 [
'rev_page' => $lastCurId,
"rev_timestamp < " . $dbw->addQuotes( $emit ) ],
213 [
'ORDER BY' =>
'rev_timestamp DESC' ]
216 $lastOldId = intval( $row->rev_id );
217 # Grab the last text size if available
218 $lastSize = !is_null( $row->rev_len ) ? intval( $row->rev_len ) :
null;
227 if ( $lastCurId == 0 ) {
228 $this->
output(
"Uhhh, something wrong? No curid\n" );
230 # Grab the entry's text size
231 $size = (int)$dbw->selectField(
234 [
'rev_id' => $obj->rc_this_oldid ],
241 'rc_last_oldid' => $lastOldId,
245 'rc_old_len' => $lastSize,
246 'rc_new_len' => $size,
249 'rc_cur_id' => $lastCurId,
250 'rc_this_oldid' => $obj->rc_this_oldid,
251 'rc_timestamp' => $obj->rc_timestamp
256 $lastOldId = intval( $obj->rc_this_oldid );
259 if ( ( ++$updated % $this->mBatchSize ) == 0 ) {
276 $this->
output(
"Loading from user, page, and logging tables...\n" );
278 $commentQuery = $logCommentStore->getJoin();
280 [
'user',
'logging',
'page' ] + $commentQuery[
'tables'],
293 ] + $commentQuery[
'fields'],
295 'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
296 'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
303 [
'ORDER BY' =>
'log_timestamp DESC' ],
306 [
'LEFT JOIN', [
'log_namespace=page_namespace',
'log_title=page_title' ] ]
307 ] + $commentQuery[
'joins']
310 $field = $dbw->fieldInfo(
'recentchanges',
'rc_cur_id' );
313 foreach (
$res as $row ) {
314 $comment = $logCommentStore->getComment( $row );
318 'rc_timestamp' => $row->log_timestamp,
319 'rc_user' => $row->log_user,
320 'rc_user_text' => $row->user_name,
321 'rc_namespace' => $row->log_namespace,
322 'rc_title' => $row->log_title,
327 'rc_this_oldid' => 0,
328 'rc_last_oldid' => 0,
331 'rc_cur_id' => $field->isNullable()
333 : (int)$row->page_id,
334 'rc_log_type' => $row->log_type,
335 'rc_log_action' => $row->log_action,
336 'rc_logid' => $row->log_id,
337 'rc_params' => $row->log_params,
338 'rc_deleted' => $row->log_deleted
339 ] + $rcCommentStore->insert( $dbw, $comment ),
343 if ( ( ++$inserted % $this->mBatchSize ) == 0 ) {
357 list( $recentchanges, $usergroups, $user ) =
358 $dbw->tableNamesN(
'recentchanges',
'user_groups',
'user' );
360 # @FIXME: recognize other bot account groups (not the same as users with 'bot' rights)
361 # @NOTE: users with 'bot' rights choose when edits are bot edits or not. That information
362 # may be lost at this point (aside from joining on the patrol log table entries).
363 $botgroups = [
'bot' ];
364 $autopatrolgroups =
$wgUseRCPatrol ? User::getGroupsWithPermission(
'autopatrol' ) : [];
366 # Flag our recent bot edits
368 $botwhere = $dbw->makeList( $botgroups );
370 $this->
output(
"Flagging bot account edits...\n" );
372 # Find all users that are bots
373 $sql =
"SELECT DISTINCT user_name FROM $usergroups, $user " .
374 "WHERE ug_group IN($botwhere) AND user_id = ug_user";
375 $res = $dbw->query( $sql, __METHOD__ );
378 foreach (
$res as $obj ) {
379 $botusers[] = $obj->user_name;
382 # Fill in the rc_bot field
384 $rcids = $dbw->selectFieldValues(
388 'rc_user_text' => $botusers,
389 "rc_timestamp > " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
390 "rc_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
395 foreach ( array_chunk( $rcids, $this->mBatchSize ) as $rcidBatch ) {
399 [
'rc_id' => $rcidBatch ],
407 # Flag our recent autopatrolled edits
409 $patrolwhere = $dbw->makeList( $autopatrolgroups );
412 $this->
output(
"Flagging auto-patrolled edits...\n" );
414 # Find all users in RC with autopatrol rights
415 $sql =
"SELECT DISTINCT user_name FROM $usergroups, $user " .
416 "WHERE ug_group IN($patrolwhere) AND user_id = ug_user";
417 $res = $dbw->query( $sql, __METHOD__ );
419 foreach (
$res as $obj ) {
420 $patrolusers[] = $dbw->addQuotes( $obj->user_name );
423 # Fill in the rc_patrolled field
424 if ( $patrolusers ) {
425 $patrolwhere = implode(
',', $patrolusers );
426 $sql2 =
"UPDATE $recentchanges SET rc_patrolled=1 " .
427 "WHERE rc_user_text IN($patrolwhere) " .
428 "AND rc_timestamp > " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ) .
' ' .
429 "AND rc_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) );
430 $dbw->query( $sql2 );
442 $this->
output(
"Removing duplicate revision and logging entries...\n" );
445 [
'logging',
'log_search' ],
446 [
'ls_value',
'ls_log_id' ],
448 'ls_log_id = log_id',
449 'ls_field' =>
'associated_rev_id',
450 'log_type' =>
'upload',
451 'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
452 'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
458 foreach (
$res as $obj ) {
459 $rev_id = $obj->ls_value;
460 $log_id = $obj->ls_log_id;
465 [
'rc_this_oldid' => $rev_id ],
466 [
'rc_logid' => $log_id ],
473 [
'rc_this_oldid' => $rev_id,
'rc_logid' => 0 ],
477 if ( ( ++$updates % $this->mBatchSize ) == 0 ) {
489 $this->
output(
"Deleting feed timestamps.\n" );
491 $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
493 $wanCache->delete( $wanCache->makeKey(
'rcfeed', $feed,
'timestamp' ) ); # Good enough
for now.
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
$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.
$wgMiserMode
Disable database-intensive features.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfGetLBFactory()
Get the load balancer factory object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
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.
Maintenance script that rebuilds recent changes from scratch.
rebuildRecentChangesTablePass3()
Rebuild pass 3: Insert recentchanges entries for action logs.
rebuildRecentChangesTablePass5()
Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry for a...
rebuildRecentChangesTablePass4()
Rebuild pass 4: Mark bot and autopatrolled entries.
execute()
Do the actual work.
rebuildRecentChangesTablePass1()
Rebuild pass 1: Insert recentchanges entries for page revisions.
int $cutoffFrom
UNIX timestamp.
rebuildRecentChangesTablePass2()
Rebuild pass 2: Enhance entries for page revisions with references to the previous revision (rc_last_...
int $cutoffTo
UNIX timestamp.
__construct()
Default constructor.
purgeFeeds()
Purge cached feeds in $wanCache.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
require_once RUN_MAINTENANCE_IF_MAIN