When using latest MediaWiki [1], running update.php for new wikis without any revisions yet [2] fails when update.php attempts to run populateArchiveRevId.php. Error is:
[f23412f367e067bd4890429d] [no req] UnexpectedValueException from line 223 of /opt/htdocs/mediawiki/maintenance/populateArchiveRevId.php: No revisions are available to copy Backtrace: #0 /opt/htdocs/mediawiki/maintenance/populateArchiveRevId.php(107): PopulateArchiveRevId::makeDummyRevisionRow(Wikimedia\Rdbms\DatabaseMysqli) #1 /opt/htdocs/mediawiki/maintenance/populateArchiveRevId.php(53): PopulateArchiveRevId::checkMysqlAutoIncrementBug(Wikimedia\Rdbms\DatabaseMysqli) #2 /opt/htdocs/mediawiki/maintenance/Maintenance.php(1699): PopulateArchiveRevId->doDBUpdates() #3 /opt/htdocs/mediawiki/includes/installer/DatabaseUpdater.php(1329): LoggedUpdateMaintenance->execute() #4 /opt/htdocs/mediawiki/includes/installer/DatabaseUpdater.php(485): DatabaseUpdater->populateArchiveRevId() #5 /opt/htdocs/mediawiki/includes/installer/DatabaseUpdater.php(449): DatabaseUpdater->runUpdates(array, boolean) #6 /opt/htdocs/mediawiki/maintenance/update.php(200): DatabaseUpdater->doUpdates(array) #7 /opt/htdocs/mediawiki/maintenance/doMaintenance.php(94): UpdateMediaWiki->execute() #8 /opt/htdocs/mediawiki/maintenance/update.php(245): require_once(string) #9 {main}
Failing line is [3], which throws an exception when trying to generate a dummy revision based off of any revision in the revision table. One workaround is:
// Comment out the line below since it breaks wikis without anything in revision table // throw new UnexpectedValueException( 'No revisions are available to copy' ); // Instead just generate a dummy revision like this: $rev = [ 'rev_id' => 'will be replaced', 'rev_page' => 0, 'rev_text_id' => 0, 'rev_comment' => 'will be replaced', 'rev_user' => 'will be replaced', 'rev_user_text' => 'will be replaced', 'rev_timestamp' => 'will be replaced', 'rev_minor_edit' => 0, 'rev_deleted' => 0, 'rev_len' => 0, 'rev_parent_id' => 0, 'rev_sha1' => '189028adf7407c10da205bccd58390610b92c738', // random sha1 'rev_content_model' => NULL, 'rev_content_format' => NULL, ];
[1] as of this writing latest MW is 2d4256d2ec2d5a402c8afddcdf9691911179e55c
[2] This problem does not exist if using the web installer or running maintenance/install.php, since both of these generate a Main Page revision. Manually generating a MediaWiki database by sourcing maintenance/tables.sql does not generate any revisions, and thus is susceptible to this problem.
[3] https://github.com/wikimedia/mediawiki/blame/2d4256d2ec2d5a402c8afddcdf9691911179e55c/maintenance/populateArchiveRevId.php#L223