2005-09-16 00:12:48 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-06-16 20:35:13 +00:00
|
|
|
* Corrects wrong values in the `page_latest` field in the database.
|
2009-08-02 19:35:17 +00:00
|
|
|
*
|
2010-09-05 13:15:48 +00:00
|
|
|
* Copyright © 2005 Brion Vibber <brion@pobox.com>
|
2014-03-20 15:45:01 +00:00
|
|
|
* https://www.mediawiki.org/
|
2005-09-16 00:12:48 +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.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-09-16 00:12:48 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-09-05 13:15:48 +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
|
2005-09-16 00:12:48 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-02-09 23:27:14 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-03-04 01:39:36 +00:00
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
2019-02-09 23:27:14 +00:00
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2012-06-16 20:35:13 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to correct wrong values in the `page_latest` field
|
|
|
|
|
* in the database.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class AttachLatest extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->addOption( "fix", "Actually fix the entries, will dry run otherwise" );
|
2014-03-12 11:41:10 +00:00
|
|
|
$this->addOption( "regenerate-all",
|
|
|
|
|
"Regenerate the page_latest field for all records in table page" );
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Fix page_latest entries in the page table' );
|
2005-09-16 00:12:48 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
|
|
|
|
$this->output( "Looking for pages with page_latest set to 0...\n" );
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = $this->getDB( DB_PRIMARY );
|
2016-02-17 09:09:32 +00:00
|
|
|
$conds = [ 'page_latest' => 0 ];
|
2014-03-12 11:41:10 +00:00
|
|
|
if ( $this->hasOption( 'regenerate-all' ) ) {
|
|
|
|
|
$conds = '';
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
$result = $dbw->select( 'page',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page_id', 'page_namespace', 'page_title' ],
|
2014-03-12 11:41:10 +00:00
|
|
|
$conds,
|
2009-08-02 19:35:17 +00:00
|
|
|
__METHOD__ );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2020-11-12 20:36:35 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$lbFactory = $services->getDBLoadBalancerFactory();
|
2019-07-04 07:31:06 +00:00
|
|
|
$dbDomain = $lbFactory->getLocalDomainID();
|
2020-11-12 20:36:35 +00:00
|
|
|
$wikiPageFactory = $services->getWikiPageFactory();
|
|
|
|
|
$revisionLookup = $services->getRevisionLookup();
|
2019-07-04 07:31:06 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$n = 0;
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $result as $row ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$pageId = intval( $row->page_id );
|
|
|
|
|
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
|
|
|
|
|
$name = $title->getPrefixedText();
|
|
|
|
|
$latestTime = $dbw->selectField( 'revision',
|
|
|
|
|
'MAX(rev_timestamp)',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'rev_page' => $pageId ],
|
2009-08-02 19:35:17 +00:00
|
|
|
__METHOD__ );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !$latestTime ) {
|
2019-07-04 07:31:06 +00:00
|
|
|
$this->output( "$dbDomain $pageId [[$name]] can't find latest rev time?!\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2020-11-12 20:36:35 +00:00
|
|
|
$revRecord = $revisionLookup->getRevisionByTimestamp( $title, $latestTime, RevisionLookup::READ_LATEST );
|
2020-03-04 01:39:36 +00:00
|
|
|
if ( $revRecord === null ) {
|
2019-07-04 07:31:06 +00:00
|
|
|
$this->output(
|
|
|
|
|
"$dbDomain $pageId [[$name]] latest time $latestTime, can't find revision id\n"
|
|
|
|
|
);
|
2009-08-02 19:35:17 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2020-04-24 00:55:09 +00:00
|
|
|
|
|
|
|
|
$id = $revRecord->getId();
|
2019-07-04 07:31:06 +00:00
|
|
|
$this->output( "$dbDomain $pageId [[$name]] latest time $latestTime, rev id $id\n" );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $this->hasOption( 'fix' ) ) {
|
2020-11-12 20:36:35 +00:00
|
|
|
$page = $wikiPageFactory->newFromTitle( $title );
|
2020-04-24 00:55:09 +00:00
|
|
|
$page->updateRevisionOn( $dbw, $revRecord );
|
2019-02-09 23:27:14 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
$n++;
|
|
|
|
|
}
|
|
|
|
|
$this->output( "Done! Processed $n pages.\n" );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !$this->hasOption( 'fix' ) ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "This was a dry run; rerun with --fix to update page_latest.\n" );
|
|
|
|
|
}
|
2009-06-24 02:49:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = AttachLatest::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|