2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-03 20:33:01 +00:00
|
|
|
/**
|
2012-08-09 16:06:18 +00:00
|
|
|
* Rebuild recent changes from scratch. This takes several hours,
|
|
|
|
|
* depending on the database size and server configuration.
|
2004-09-03 20:33:01 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-08-09 16:06:18 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2009-08-02 19:35:17 +00:00
|
|
|
* @todo Document
|
2004-09-03 20:33:01 +00:00
|
|
|
*/
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2018-02-25 09:05:07 +00:00
|
|
|
|
2017-05-25 01:15:47 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-02-25 09:05:07 +00:00
|
|
|
use Wikimedia\Rdbms\ILBFactory;
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2012-08-09 16:06:18 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that rebuilds recent changes from scratch.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class RebuildRecentchanges extends Maintenance {
|
2017-08-20 11:20:59 +00:00
|
|
|
/** @var int UNIX timestamp */
|
2016-04-19 20:40:38 +00:00
|
|
|
private $cutoffFrom;
|
2017-08-20 11:20:59 +00:00
|
|
|
/** @var int UNIX timestamp */
|
2016-04-19 20:40:38 +00:00
|
|
|
private $cutoffTo;
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Rebuild recent changes' );
|
2016-04-19 17:58:22 +00:00
|
|
|
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'from',
|
2016-04-19 20:40:38 +00:00
|
|
|
"Only rebuild rows in requested time range (in YYYYMMDDHHMMSS format)",
|
2016-04-19 17:58:22 +00:00
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'to',
|
2016-04-19 20:40:38 +00:00
|
|
|
"Only rebuild rows in requested time range (in YYYYMMDDHHMMSS format)",
|
2016-04-19 17:58:22 +00:00
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
2016-04-19 20:40:38 +00:00
|
|
|
$this->setBatchSize( 200 );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2016-04-19 17:58:22 +00:00
|
|
|
if (
|
|
|
|
|
( $this->hasOption( 'from' ) && !$this->hasOption( 'to' ) ) ||
|
|
|
|
|
( !$this->hasOption( 'from' ) && $this->hasOption( 'to' ) )
|
|
|
|
|
) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Both 'from' and 'to' must be given, or neither" );
|
2016-04-19 17:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
|
|
|
|
$this->rebuildRecentChangesTablePass1( $lbFactory );
|
|
|
|
|
$this->rebuildRecentChangesTablePass2( $lbFactory );
|
|
|
|
|
$this->rebuildRecentChangesTablePass3( $lbFactory );
|
|
|
|
|
$this->rebuildRecentChangesTablePass4( $lbFactory );
|
|
|
|
|
$this->rebuildRecentChangesTablePass5( $lbFactory );
|
2016-04-19 17:58:22 +00:00
|
|
|
if ( !( $this->hasOption( 'from' ) && $this->hasOption( 'to' ) ) ) {
|
|
|
|
|
$this->purgeFeeds();
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Done.\n" );
|
|
|
|
|
}
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
/**
|
2015-12-29 00:33:01 +00:00
|
|
|
* Rebuild pass 1: Insert `recentchanges` entries for page revisions.
|
2019-07-10 22:06:05 +00:00
|
|
|
*
|
|
|
|
|
* @param ILBFactory $lbFactory
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
2018-02-25 09:05:07 +00:00
|
|
|
private function rebuildRecentChangesTablePass1( ILBFactory $lbFactory ) {
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2018-01-24 23:41:01 +00:00
|
|
|
$commentStore = CommentStore::getStore();
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2016-04-19 17:58:22 +00:00
|
|
|
if ( $this->hasOption( 'from' ) && $this->hasOption( 'to' ) ) {
|
|
|
|
|
$this->cutoffFrom = wfTimestamp( TS_UNIX, $this->getOption( 'from' ) );
|
|
|
|
|
$this->cutoffTo = wfTimestamp( TS_UNIX, $this->getOption( 'to' ) );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2016-04-19 17:58:22 +00:00
|
|
|
$sec = $this->cutoffTo - $this->cutoffFrom;
|
|
|
|
|
$days = $sec / 24 / 3600;
|
|
|
|
|
$this->output( "Rebuilding range of $sec seconds ($days days)\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
2016-04-19 17:58:22 +00:00
|
|
|
global $wgRCMaxAge;
|
|
|
|
|
|
|
|
|
|
$days = $wgRCMaxAge / 24 / 3600;
|
|
|
|
|
$this->output( "Rebuilding \$wgRCMaxAge=$wgRCMaxAge seconds ($days days)\n" );
|
|
|
|
|
|
|
|
|
|
$this->cutoffFrom = time() - $wgRCMaxAge;
|
|
|
|
|
$this->cutoffTo = time();
|
2016-04-19 20:40:38 +00:00
|
|
|
}
|
2016-04-19 17:58:22 +00:00
|
|
|
|
2016-04-19 20:40:38 +00:00
|
|
|
$this->output( "Clearing recentchanges table for time range...\n" );
|
|
|
|
|
$rcids = $dbw->selectFieldValues(
|
|
|
|
|
'recentchanges',
|
|
|
|
|
'rc_id',
|
|
|
|
|
[
|
|
|
|
|
'rc_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
|
|
|
|
|
'rc_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
|
|
|
|
|
]
|
|
|
|
|
);
|
2017-11-08 03:35:11 +00:00
|
|
|
foreach ( array_chunk( $rcids, $this->getBatchSize() ) as $rcidBatch ) {
|
2016-04-19 20:40:38 +00:00
|
|
|
$dbw->delete( 'recentchanges', [ 'rc_id' => $rcidBatch ], __METHOD__ );
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2016-04-19 17:58:22 +00:00
|
|
|
$this->output( "Loading from page and revision tables...\n" );
|
2017-06-06 17:39:14 +00:00
|
|
|
|
2018-01-24 23:41:01 +00:00
|
|
|
$commentQuery = $commentStore->getJoin( 'rev_comment' );
|
2017-09-12 17:12:29 +00:00
|
|
|
$actorQuery = ActorMigration::newMigration()->getJoin( 'rev_user' );
|
2016-04-19 20:40:38 +00:00
|
|
|
$res = $dbw->select(
|
2017-09-12 17:12:29 +00:00
|
|
|
[ 'revision', 'page' ] + $commentQuery['tables'] + $actorQuery['tables'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2016-04-19 20:40:38 +00:00
|
|
|
'rev_timestamp',
|
|
|
|
|
'rev_minor_edit',
|
|
|
|
|
'rev_id',
|
|
|
|
|
'rev_deleted',
|
|
|
|
|
'page_namespace',
|
|
|
|
|
'page_title',
|
|
|
|
|
'page_is_new',
|
|
|
|
|
'page_id'
|
2017-09-12 17:12:29 +00:00
|
|
|
] + $commentQuery['fields'] + $actorQuery['fields'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2016-04-19 17:58:22 +00:00
|
|
|
'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
|
2017-06-06 17:39:14 +00:00
|
|
|
'rev_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-04-23 18:09:26 +00:00
|
|
|
__METHOD__,
|
2017-06-06 17:39:14 +00:00
|
|
|
[ 'ORDER BY' => 'rev_timestamp DESC' ],
|
|
|
|
|
[
|
|
|
|
|
'page' => [ 'JOIN', 'rev_page=page_id' ],
|
2017-09-12 17:12:29 +00:00
|
|
|
] + $commentQuery['joins'] + $actorQuery['joins']
|
2009-08-02 19:35:17 +00:00
|
|
|
);
|
2016-04-19 20:40:38 +00:00
|
|
|
|
|
|
|
|
$this->output( "Inserting from page and revision tables...\n" );
|
|
|
|
|
$inserted = 0;
|
2017-09-12 17:12:29 +00:00
|
|
|
$actorMigration = ActorMigration::newMigration();
|
2016-04-19 20:40:38 +00:00
|
|
|
foreach ( $res as $row ) {
|
2018-01-24 23:41:01 +00:00
|
|
|
$comment = $commentStore->getComment( 'rev_comment', $row );
|
2017-09-12 17:12:29 +00:00
|
|
|
$user = User::newFromAnyId( $row->rev_user, $row->rev_user_text, $row->rev_actor );
|
2016-04-19 20:40:38 +00:00
|
|
|
$dbw->insert(
|
|
|
|
|
'recentchanges',
|
|
|
|
|
[
|
|
|
|
|
'rc_timestamp' => $row->rev_timestamp,
|
|
|
|
|
'rc_namespace' => $row->page_namespace,
|
|
|
|
|
'rc_title' => $row->page_title,
|
|
|
|
|
'rc_minor' => $row->rev_minor_edit,
|
|
|
|
|
'rc_bot' => 0,
|
|
|
|
|
'rc_new' => $row->page_is_new,
|
|
|
|
|
'rc_cur_id' => $row->page_id,
|
|
|
|
|
'rc_this_oldid' => $row->rev_id,
|
|
|
|
|
'rc_last_oldid' => 0, // is this ok?
|
|
|
|
|
'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
|
2017-06-06 17:39:14 +00:00
|
|
|
'rc_source' => $row->page_is_new ? RecentChange::SRC_NEW : RecentChange::SRC_EDIT,
|
2016-04-19 20:40:38 +00:00
|
|
|
'rc_deleted' => $row->rev_deleted
|
2017-09-12 17:12:29 +00:00
|
|
|
] + $commentStore->insert( $dbw, 'rc_comment', $comment )
|
|
|
|
|
+ $actorMigration->getInsertValues( $dbw, 'rc_user', $user ),
|
2016-04-19 20:40:38 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2019-03-01 03:47:38 +00:00
|
|
|
|
|
|
|
|
$rcid = $dbw->insertId();
|
|
|
|
|
$dbw->update(
|
|
|
|
|
'change_tag',
|
|
|
|
|
[ 'ct_rc_id' => $rcid ],
|
|
|
|
|
[ 'ct_rev_id' => $row->rev_id ],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
2017-11-08 03:35:11 +00:00
|
|
|
if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) {
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2016-04-19 20:40:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
/**
|
2015-12-29 00:33:01 +00:00
|
|
|
* Rebuild pass 2: Enhance entries for page revisions with references to the previous revision
|
|
|
|
|
* (rc_last_oldid, rc_new etc.) and size differences (rc_old_len, rc_new_len).
|
2019-07-10 22:06:05 +00:00
|
|
|
*
|
|
|
|
|
* @param ILBFactory $lbFactory
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
2018-02-25 09:05:07 +00:00
|
|
|
private function rebuildRecentChangesTablePass2( ILBFactory $lbFactory ) {
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Updating links and size differences...\n" );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Fill in the rc_last_oldid field, which points to the previous edit
|
2016-04-19 20:40:38 +00:00
|
|
|
$res = $dbw->select(
|
|
|
|
|
'recentchanges',
|
|
|
|
|
[ 'rc_cur_id', 'rc_this_oldid', 'rc_timestamp' ],
|
|
|
|
|
[
|
|
|
|
|
"rc_timestamp > " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
|
|
|
|
|
"rc_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) )
|
|
|
|
|
],
|
|
|
|
|
__METHOD__,
|
2019-11-29 22:01:07 +00:00
|
|
|
[ 'ORDER BY' => [ 'rc_cur_id', 'rc_timestamp' ] ]
|
2016-04-19 20:40:38 +00:00
|
|
|
);
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$lastCurId = 0;
|
|
|
|
|
$lastOldId = 0;
|
2016-04-19 20:40:38 +00:00
|
|
|
$lastSize = null;
|
|
|
|
|
$updated = 0;
|
2019-07-10 22:06:05 +00:00
|
|
|
foreach ( $res as $row ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$new = 0;
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2019-07-10 22:06:05 +00:00
|
|
|
if ( $row->rc_cur_id != $lastCurId ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
# Switch! Look up the previous last edit, if any
|
2019-07-10 22:06:05 +00:00
|
|
|
$lastCurId = intval( $row->rc_cur_id );
|
|
|
|
|
$emit = $row->rc_timestamp;
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2019-07-10 22:06:05 +00:00
|
|
|
$revRow = $dbw->selectRow(
|
2016-04-19 20:40:38 +00:00
|
|
|
'revision',
|
|
|
|
|
[ 'rev_id', 'rev_len' ],
|
|
|
|
|
[ 'rev_page' => $lastCurId, "rev_timestamp < " . $dbw->addQuotes( $emit ) ],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
[ 'ORDER BY' => 'rev_timestamp DESC' ]
|
|
|
|
|
);
|
2019-07-10 22:06:05 +00:00
|
|
|
if ( $revRow ) {
|
|
|
|
|
$lastOldId = intval( $revRow->rev_id );
|
2009-08-02 19:35:17 +00:00
|
|
|
# Grab the last text size if available
|
2020-01-09 23:48:34 +00:00
|
|
|
$lastSize = $revRow->rev_len !== null ? intval( $revRow->rev_len ) : null;
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
|
|
|
|
# No previous edit
|
|
|
|
|
$lastOldId = 0;
|
2018-02-21 00:32:03 +00:00
|
|
|
$lastSize = 0;
|
2009-08-02 19:35:17 +00:00
|
|
|
$new = 1; // probably true
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $lastCurId == 0 ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Uhhh, something wrong? No curid\n" );
|
|
|
|
|
} else {
|
|
|
|
|
# Grab the entry's text size
|
2016-04-19 20:40:38 +00:00
|
|
|
$size = (int)$dbw->selectField(
|
|
|
|
|
'revision',
|
|
|
|
|
'rev_len',
|
2019-07-10 22:06:05 +00:00
|
|
|
[ 'rev_id' => $row->rc_this_oldid ],
|
2016-04-19 20:40:38 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2016-04-19 20:40:38 +00:00
|
|
|
$dbw->update(
|
|
|
|
|
'recentchanges',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2010-12-05 19:34:40 +00:00
|
|
|
'rc_last_oldid' => $lastOldId,
|
2013-04-18 18:48:44 +00:00
|
|
|
'rc_new' => $new,
|
2016-04-19 20:40:38 +00:00
|
|
|
'rc_type' => $new ? RC_NEW : RC_EDIT,
|
2017-08-01 17:55:11 +00:00
|
|
|
'rc_source' => $new === 1 ? RecentChange::SRC_NEW : RecentChange::SRC_EDIT,
|
2013-04-18 18:48:44 +00:00
|
|
|
'rc_old_len' => $lastSize,
|
|
|
|
|
'rc_new_len' => $size,
|
2016-04-19 20:40:38 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-04-18 18:48:44 +00:00
|
|
|
'rc_cur_id' => $lastCurId,
|
2019-07-10 22:06:05 +00:00
|
|
|
'rc_this_oldid' => $row->rc_this_oldid,
|
|
|
|
|
'rc_timestamp' => $row->rc_timestamp // index usage
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2010-12-05 05:59:02 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2019-07-10 22:06:05 +00:00
|
|
|
$lastOldId = intval( $row->rc_this_oldid );
|
2009-08-02 19:35:17 +00:00
|
|
|
$lastSize = $size;
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2017-11-05 08:09:51 +00:00
|
|
|
if ( ( ++$updated % $this->getBatchSize() ) == 0 ) {
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2016-04-19 20:40:38 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
/**
|
2015-12-29 00:33:01 +00:00
|
|
|
* Rebuild pass 3: Insert `recentchanges` entries for action logs.
|
2019-07-10 22:06:05 +00:00
|
|
|
*
|
|
|
|
|
* @param ILBFactory $lbFactory
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
2018-02-25 09:05:07 +00:00
|
|
|
private function rebuildRecentChangesTablePass3( ILBFactory $lbFactory ) {
|
2017-07-28 01:44:21 +00:00
|
|
|
global $wgLogRestrictions, $wgFilterLogTypes;
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2018-01-24 23:41:01 +00:00
|
|
|
$commentStore = CommentStore::getStore();
|
2017-07-28 01:44:21 +00:00
|
|
|
$nonRCLogs = array_merge( array_keys( $wgLogRestrictions ),
|
|
|
|
|
array_keys( $wgFilterLogTypes ),
|
|
|
|
|
[ 'create' ] );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2018-02-09 01:22:23 +00:00
|
|
|
$this->output( "Loading from user and logging tables...\n" );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2018-01-24 23:41:01 +00:00
|
|
|
$commentQuery = $commentStore->getJoin( 'log_comment' );
|
2017-09-12 17:12:29 +00:00
|
|
|
$actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
|
2016-04-19 20:40:38 +00:00
|
|
|
$res = $dbw->select(
|
2018-02-09 01:22:23 +00:00
|
|
|
[ 'logging' ] + $commentQuery['tables'] + $actorQuery['tables'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2016-04-19 20:40:38 +00:00
|
|
|
'log_timestamp',
|
|
|
|
|
'log_namespace',
|
|
|
|
|
'log_title',
|
2018-02-09 01:22:23 +00:00
|
|
|
'log_page',
|
2016-04-19 20:40:38 +00:00
|
|
|
'log_type',
|
|
|
|
|
'log_action',
|
|
|
|
|
'log_id',
|
|
|
|
|
'log_params',
|
|
|
|
|
'log_deleted'
|
2017-09-12 17:12:29 +00:00
|
|
|
] + $commentQuery['fields'] + $actorQuery['fields'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2016-04-19 17:58:22 +00:00
|
|
|
'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
|
|
|
|
|
'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
|
2017-07-28 01:44:21 +00:00
|
|
|
// Some logs don't go in RC since they are private, or are included in the filterable log types.
|
|
|
|
|
'log_type' => array_diff( LogPage::validTypes(), $nonRCLogs ),
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-04-23 18:09:26 +00:00
|
|
|
__METHOD__,
|
2016-04-19 20:40:38 +00:00
|
|
|
[ 'ORDER BY' => 'log_timestamp DESC' ],
|
2018-02-09 01:22:23 +00:00
|
|
|
$commentQuery['joins'] + $actorQuery['joins']
|
2009-08-02 19:35:17 +00:00
|
|
|
);
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2016-09-16 05:33:10 +00:00
|
|
|
$field = $dbw->fieldInfo( 'recentchanges', 'rc_cur_id' );
|
|
|
|
|
|
2016-04-19 20:40:38 +00:00
|
|
|
$inserted = 0;
|
2017-09-12 17:12:29 +00:00
|
|
|
$actorMigration = ActorMigration::newMigration();
|
2016-04-19 20:40:38 +00:00
|
|
|
foreach ( $res as $row ) {
|
2018-01-24 23:41:01 +00:00
|
|
|
$comment = $commentStore->getComment( 'log_comment', $row );
|
2017-09-12 17:12:29 +00:00
|
|
|
$user = User::newFromAnyId( $row->log_user, $row->log_user_text, $row->log_actor );
|
2016-04-19 20:40:38 +00:00
|
|
|
$dbw->insert(
|
|
|
|
|
'recentchanges',
|
|
|
|
|
[
|
|
|
|
|
'rc_timestamp' => $row->log_timestamp,
|
|
|
|
|
'rc_namespace' => $row->log_namespace,
|
|
|
|
|
'rc_title' => $row->log_title,
|
|
|
|
|
'rc_minor' => 0,
|
|
|
|
|
'rc_bot' => 0,
|
2019-03-06 01:55:49 +00:00
|
|
|
'rc_patrolled' => $row->log_type == 'upload' ? 0 : 2,
|
2016-04-19 20:40:38 +00:00
|
|
|
'rc_new' => 0,
|
|
|
|
|
'rc_this_oldid' => 0,
|
|
|
|
|
'rc_last_oldid' => 0,
|
|
|
|
|
'rc_type' => RC_LOG,
|
2017-08-01 17:55:11 +00:00
|
|
|
'rc_source' => RecentChange::SRC_LOG,
|
2016-09-16 05:33:10 +00:00
|
|
|
'rc_cur_id' => $field->isNullable()
|
2018-02-09 01:22:23 +00:00
|
|
|
? $row->log_page
|
|
|
|
|
: (int)$row->log_page, // NULL => 0,
|
2016-04-19 20:40:38 +00:00
|
|
|
'rc_log_type' => $row->log_type,
|
|
|
|
|
'rc_log_action' => $row->log_action,
|
|
|
|
|
'rc_logid' => $row->log_id,
|
|
|
|
|
'rc_params' => $row->log_params,
|
|
|
|
|
'rc_deleted' => $row->log_deleted
|
2017-09-12 17:12:29 +00:00
|
|
|
] + $commentStore->insert( $dbw, 'rc_comment', $comment )
|
|
|
|
|
+ $actorMigration->getInsertValues( $dbw, 'rc_user', $user ),
|
2016-04-19 20:40:38 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
2019-03-01 03:47:38 +00:00
|
|
|
$rcid = $dbw->insertId();
|
|
|
|
|
$dbw->update(
|
|
|
|
|
'change_tag',
|
|
|
|
|
[ 'ct_rc_id' => $rcid ],
|
|
|
|
|
[ 'ct_log_id' => $row->log_id ],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
2017-11-05 08:09:51 +00:00
|
|
|
if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) {
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2016-04-19 20:40:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
/**
|
2015-12-29 00:33:01 +00:00
|
|
|
* Rebuild pass 4: Mark bot and autopatrolled entries.
|
2019-07-10 22:06:05 +00:00
|
|
|
*
|
|
|
|
|
* @param ILBFactory $lbFactory
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
2018-02-25 09:05:07 +00:00
|
|
|
private function rebuildRecentChangesTablePass4( ILBFactory $lbFactory ) {
|
2016-04-19 20:40:38 +00:00
|
|
|
global $wgUseRCPatrol, $wgMiserMode;
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2017-09-12 17:12:29 +00:00
|
|
|
$userQuery = User::getQueryInfo();
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2016-04-19 20:40:38 +00:00
|
|
|
# @FIXME: recognize other bot account groups (not the same as users with 'bot' rights)
|
|
|
|
|
# @NOTE: users with 'bot' rights choose when edits are bot edits or not. That information
|
|
|
|
|
# may be lost at this point (aside from joining on the patrol log table entries).
|
|
|
|
|
$botgroups = [ 'bot' ];
|
2019-08-22 02:22:26 +00:00
|
|
|
$autopatrolgroups = $wgUseRCPatrol ? MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->getGroupsWithPermission( 'autopatrol' ) : [];
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Flag our recent bot edits
|
2016-04-19 20:40:38 +00:00
|
|
|
if ( $botgroups ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Flagging bot account edits...\n" );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Find all users that are bots
|
2017-09-12 17:12:29 +00:00
|
|
|
$res = $dbw->select(
|
|
|
|
|
array_merge( [ 'user_groups' ], $userQuery['tables'] ),
|
|
|
|
|
$userQuery['fields'],
|
|
|
|
|
[ 'ug_group' => $botgroups ],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
[ 'DISTINCT' ],
|
2019-03-05 23:13:59 +00:00
|
|
|
[ 'user_groups' => [ 'JOIN', 'user_id = ug_user' ] ] + $userQuery['joins']
|
2017-09-12 17:12:29 +00:00
|
|
|
);
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2016-04-19 20:40:38 +00:00
|
|
|
$botusers = [];
|
2019-07-10 22:06:05 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$botusers[] = User::newFromRow( $row );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Fill in the rc_bot field
|
2016-04-19 20:40:38 +00:00
|
|
|
if ( $botusers ) {
|
2017-09-12 17:12:29 +00:00
|
|
|
$actorQuery = ActorMigration::newMigration()->getWhere( $dbw, 'rc_user', $botusers, false );
|
|
|
|
|
$rcids = [];
|
|
|
|
|
foreach ( $actorQuery['orconds'] as $cond ) {
|
|
|
|
|
$rcids = array_merge( $rcids, $dbw->selectFieldValues(
|
|
|
|
|
[ 'recentchanges' ] + $actorQuery['tables'],
|
|
|
|
|
'rc_id',
|
|
|
|
|
[
|
|
|
|
|
"rc_timestamp > " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
|
|
|
|
|
"rc_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
|
|
|
|
|
$cond,
|
|
|
|
|
],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
[],
|
|
|
|
|
$actorQuery['joins']
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
$rcids = array_values( array_unique( $rcids ) );
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2017-11-05 08:09:51 +00:00
|
|
|
foreach ( array_chunk( $rcids, $this->getBatchSize() ) as $rcidBatch ) {
|
2016-04-19 20:40:38 +00:00
|
|
|
$dbw->update(
|
|
|
|
|
'recentchanges',
|
|
|
|
|
[ 'rc_bot' => 1 ],
|
|
|
|
|
[ 'rc_id' => $rcidBatch ],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2016-04-19 20:40:38 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Flag our recent autopatrolled edits
|
2016-04-19 20:40:38 +00:00
|
|
|
if ( !$wgMiserMode && $autopatrolgroups ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$patrolusers = [];
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Flagging auto-patrolled edits...\n" );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Find all users in RC with autopatrol rights
|
2017-09-12 17:12:29 +00:00
|
|
|
$res = $dbw->select(
|
|
|
|
|
array_merge( [ 'user_groups' ], $userQuery['tables'] ),
|
|
|
|
|
$userQuery['fields'],
|
|
|
|
|
[ 'ug_group' => $autopatrolgroups ],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
[ 'DISTINCT' ],
|
2019-03-06 09:07:26 +00:00
|
|
|
[ 'user_groups' => [ 'JOIN', 'user_id = ug_user' ] ] + $userQuery['joins']
|
2017-09-12 17:12:29 +00:00
|
|
|
);
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2019-07-10 22:06:05 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$patrolusers[] = User::newFromRow( $row );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Fill in the rc_patrolled field
|
2016-04-19 20:40:38 +00:00
|
|
|
if ( $patrolusers ) {
|
2017-09-12 17:12:29 +00:00
|
|
|
$actorQuery = ActorMigration::newMigration()->getWhere( $dbw, 'rc_user', $patrolusers, false );
|
|
|
|
|
foreach ( $actorQuery['orconds'] as $cond ) {
|
|
|
|
|
$dbw->update(
|
|
|
|
|
'recentchanges',
|
2019-03-06 01:55:49 +00:00
|
|
|
[ 'rc_patrolled' => 2 ],
|
2017-09-12 17:12:29 +00:00
|
|
|
[
|
|
|
|
|
$cond,
|
|
|
|
|
'rc_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
|
|
|
|
|
'rc_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
|
2019-03-06 01:55:49 +00:00
|
|
|
'rc_patrolled' => 0
|
2017-09-12 17:12:29 +00:00
|
|
|
],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2017-09-12 17:12:29 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-28 18:04:40 +00:00
|
|
|
|
2015-12-29 01:16:10 +00:00
|
|
|
/**
|
2019-07-10 22:06:05 +00:00
|
|
|
* Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log
|
|
|
|
|
* entry for a single action (upload only, at the moment, but potentially move, protect, ...).
|
|
|
|
|
*
|
|
|
|
|
* @param ILBFactory $lbFactory
|
2015-12-29 01:16:10 +00:00
|
|
|
*/
|
2018-02-25 09:05:07 +00:00
|
|
|
private function rebuildRecentChangesTablePass5( ILBFactory $lbFactory ) {
|
2015-12-29 01:16:10 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
|
|
|
|
|
$this->output( "Removing duplicate revision and logging entries...\n" );
|
|
|
|
|
|
|
|
|
|
$res = $dbw->select(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'logging', 'log_search' ],
|
|
|
|
|
[ 'ls_value', 'ls_log_id' ],
|
|
|
|
|
[
|
2015-12-29 01:16:10 +00:00
|
|
|
'ls_log_id = log_id',
|
|
|
|
|
'ls_field' => 'associated_rev_id',
|
|
|
|
|
'log_type' => 'upload',
|
2016-04-19 17:58:22 +00:00
|
|
|
'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
|
|
|
|
|
'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-12-29 01:16:10 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2016-04-19 20:40:38 +00:00
|
|
|
|
|
|
|
|
$updates = 0;
|
2019-07-10 22:06:05 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$rev_id = $row->ls_value;
|
|
|
|
|
$log_id = $row->ls_log_id;
|
2015-12-29 01:16:10 +00:00
|
|
|
|
|
|
|
|
// Mark the logging row as having an associated rev id
|
|
|
|
|
$dbw->update(
|
|
|
|
|
'recentchanges',
|
2016-02-17 09:09:32 +00:00
|
|
|
/*SET*/ [ 'rc_this_oldid' => $rev_id ],
|
|
|
|
|
/*WHERE*/ [ 'rc_logid' => $log_id ],
|
2015-12-29 01:16:10 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Delete the revision row
|
|
|
|
|
$dbw->delete(
|
|
|
|
|
'recentchanges',
|
2016-02-17 09:09:32 +00:00
|
|
|
/*WHERE*/ [ 'rc_this_oldid' => $rev_id, 'rc_logid' => 0 ],
|
2015-12-29 01:16:10 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2016-04-19 20:40:38 +00:00
|
|
|
|
2017-11-05 08:09:51 +00:00
|
|
|
if ( ( ++$updates % $this->getBatchSize() ) == 0 ) {
|
2018-02-25 09:05:07 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2016-04-19 20:40:38 +00:00
|
|
|
}
|
2015-12-29 01:16:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-28 18:04:40 +00:00
|
|
|
/**
|
2017-05-25 01:15:47 +00:00
|
|
|
* Purge cached feeds in $wanCache
|
2009-08-28 18:04:40 +00:00
|
|
|
*/
|
|
|
|
|
private function purgeFeeds() {
|
2017-05-25 01:15:47 +00:00
|
|
|
global $wgFeedClasses;
|
2009-08-28 18:04:40 +00:00
|
|
|
|
|
|
|
|
$this->output( "Deleting feed timestamps.\n" );
|
|
|
|
|
|
2017-05-25 01:15:47 +00:00
|
|
|
$wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $wgFeedClasses as $feed => $className ) {
|
2017-05-25 01:15:47 +00:00
|
|
|
$wanCache->delete( $wanCache->makeKey( 'rcfeed', $feed, 'timestamp' ) ); # Good enough for now.
|
2009-08-28 18:04:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = RebuildRecentchanges::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|