2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-03 20:33:01 +00:00
|
|
|
/**
|
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
|
|
|
* Compress the text of a wiki.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
|
|
|
|
* Usage:
|
2004-10-30 14:39:40 +00:00
|
|
|
*
|
|
|
|
|
* Non-wikimedia
|
2005-08-14 14:43:55 +00:00
|
|
|
* php compressOld.php [options...]
|
2004-10-30 14:39:40 +00:00
|
|
|
*
|
|
|
|
|
* Wikimedia
|
2005-08-14 14:43:55 +00:00
|
|
|
* php compressOld.php <database> [options...]
|
2004-10-30 14:39:40 +00:00
|
|
|
*
|
2005-08-14 14:43:55 +00:00
|
|
|
* Options are:
|
|
|
|
|
* -t <type> set compression type to either:
|
|
|
|
|
* gzip: compress revisions independently
|
|
|
|
|
* concat: concatenate revisions and compress in chunks (default)
|
|
|
|
|
* -c <chunk-size> maximum number of revisions in a concat chunk
|
|
|
|
|
* -b <begin-date> earliest date to check for uncompressed revisions
|
|
|
|
|
* -e <end-date> latest revision date to compress
|
2012-03-20 10:07:51 +00:00
|
|
|
* -s <startid> the id to start from (referring to the text table for
|
|
|
|
|
* type gzip, and to the page table for type concat)
|
|
|
|
|
* -n <endid> the page_id to stop at (only when using concat compression type)
|
2005-08-14 14:43:55 +00:00
|
|
|
* --extdb <cluster> store specified revisions in an external cluster (untested)
|
2004-10-30 14:39:40 +00:00
|
|
|
*
|
2010-12-16 19:15:12 +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
|
|
|
|
|
*
|
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
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance ExternalStorage
|
2004-10-30 14:39:40 +00:00
|
|
|
*/
|
2019-04-02 14:37:55 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2024-01-17 17:48:40 +00:00
|
|
|
use Wikimedia\Rdbms\IExpression;
|
|
|
|
|
use Wikimedia\Rdbms\LikeValue;
|
2005-07-30 20:57:15 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/../Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2004-01-03 12:32:32 +00:00
|
|
|
|
2012-09-20 20:49:55 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that compress the text of a wiki.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance ExternalStorage
|
|
|
|
|
*/
|
2011-06-13 23:28:59 +00:00
|
|
|
class CompressOld extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Compress the text of a wiki' );
|
2011-06-13 23:28:59 +00:00
|
|
|
$this->addOption( 'type', 'Set compression type to either: gzip|concat', false, true, 't' );
|
2014-04-22 20:23:18 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'chunksize',
|
|
|
|
|
'Maximum number of revisions in a concat chunk',
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
'c'
|
|
|
|
|
);
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'begin-date',
|
|
|
|
|
'Earliest date to check for uncompressed revisions',
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
'b'
|
|
|
|
|
);
|
2011-06-13 23:28:59 +00:00
|
|
|
$this->addOption( 'end-date', 'Latest revision date to compress', false, true, 'e' );
|
2014-04-22 20:23:18 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'startid',
|
|
|
|
|
'The id to start from (gzip -> text table, concat -> page table)',
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
's'
|
|
|
|
|
);
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'extdb',
|
|
|
|
|
'Store specified revisions in an external cluster (untested)',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'endid',
|
|
|
|
|
'The page_id to stop at (only when using concat compression type)',
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
'n'
|
|
|
|
|
);
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
2004-10-30 14:39:40 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
public function execute() {
|
|
|
|
|
global $wgDBname;
|
|
|
|
|
if ( !function_exists( "gzdeflate" ) ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "You must enable zlib support in PHP to compress old revisions!\n" .
|
2019-04-12 04:41:14 +00:00
|
|
|
"Please see https://www.php.net/manual/en/ref.zlib.php\n" );
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
2004-10-30 14:39:40 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
$type = $this->getOption( 'type', 'concat' );
|
|
|
|
|
$chunkSize = $this->getOption( 'chunksize', 20 );
|
2012-03-01 11:33:38 +00:00
|
|
|
$startId = $this->getOption( 'startid', 0 );
|
2011-06-13 23:28:59 +00:00
|
|
|
$beginDate = $this->getOption( 'begin-date', '' );
|
|
|
|
|
$endDate = $this->getOption( 'end-date', '' );
|
|
|
|
|
$extDB = $this->getOption( 'extdb', '' );
|
|
|
|
|
$endId = $this->getOption( 'endid', false );
|
2004-10-30 14:39:40 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
if ( $type != 'concat' && $type != 'gzip' ) {
|
|
|
|
|
$this->error( "Type \"{$type}\" not supported" );
|
|
|
|
|
}
|
2004-01-03 12:32:32 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
if ( $extDB != '' ) {
|
|
|
|
|
$this->output( "Compressing database {$wgDBname} to external cluster {$extDB}\n"
|
|
|
|
|
. str_repeat( '-', 76 ) . "\n\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "Compressing database {$wgDBname}\n"
|
|
|
|
|
. str_repeat( '-', 76 ) . "\n\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$success = true;
|
|
|
|
|
if ( $type == 'concat' ) {
|
|
|
|
|
$success = $this->compressWithConcat( $startId, $chunkSize, $beginDate,
|
|
|
|
|
$endDate, $extDB, $endId );
|
|
|
|
|
} else {
|
|
|
|
|
$this->compressOldPages( $startId, $extDB );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $success ) {
|
|
|
|
|
$this->output( "Done.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-15 16:22:34 +00:00
|
|
|
/**
|
2015-02-05 13:13:43 +00:00
|
|
|
* Fetch the text row-by-row to 'compressPage' function for compression.
|
|
|
|
|
*
|
2014-08-15 16:22:34 +00:00
|
|
|
* @param int $start
|
|
|
|
|
* @param string $extdb
|
|
|
|
|
*/
|
2011-06-13 23:28:59 +00:00
|
|
|
private function compressOldPages( $start = 0, $extdb = '' ) {
|
|
|
|
|
$chunksize = 50;
|
|
|
|
|
$this->output( "Starting from old_id $start...\n" );
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2011-06-13 23:28:59 +00:00
|
|
|
do {
|
2023-07-18 22:56:37 +00:00
|
|
|
$res = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'old_id', 'old_flags', 'old_text' ] )
|
|
|
|
|
->forUpdate()
|
|
|
|
|
->from( 'text' )
|
|
|
|
|
->where( "old_id>=$start" )
|
|
|
|
|
->orderBy( 'old_id' )
|
|
|
|
|
->limit( $chunksize )
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2013-04-18 18:48:44 +00:00
|
|
|
if ( $res->numRows() == 0 ) {
|
2011-06-13 23:28:59 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
$last = $start;
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
# print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
|
|
|
|
|
$this->compressPage( $row, $extdb );
|
|
|
|
|
$last = $row->old_id;
|
|
|
|
|
}
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
$start = $last + 1; # Deletion may leave long empty stretches
|
|
|
|
|
$this->output( "$start...\n" );
|
2013-04-18 18:48:44 +00:00
|
|
|
} while ( true );
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-18 17:32:20 +00:00
|
|
|
/**
|
2015-02-05 13:13:43 +00:00
|
|
|
* Compress the text in gzip format.
|
|
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param stdClass $row
|
|
|
|
|
* @param string $extdb
|
2011-10-18 17:32:20 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-06-13 23:28:59 +00:00
|
|
|
private function compressPage( $row, $extdb ) {
|
2018-06-30 09:43:00 +00:00
|
|
|
if ( strpos( $row->old_flags, 'gzip' ) !== false
|
|
|
|
|
|| strpos( $row->old_flags, 'object' ) !== false
|
2014-04-22 20:23:18 +00:00
|
|
|
) {
|
2015-09-11 13:44:59 +00:00
|
|
|
# print "Already compressed row {$row->old_id}\n";
|
2011-06-13 23:28:59 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2011-06-13 23:28:59 +00:00
|
|
|
$flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
|
|
|
|
|
$compress = gzdeflate( $row->old_text );
|
|
|
|
|
|
|
|
|
|
# Store in external storage if required
|
|
|
|
|
if ( $extdb !== '' ) {
|
2023-08-31 09:21:12 +00:00
|
|
|
$esFactory = $this->getServiceContainer()->getExternalStoreFactory();
|
2018-02-27 06:24:46 +00:00
|
|
|
/** @var ExternalStoreDB $storeObj */
|
|
|
|
|
$storeObj = $esFactory->getStore( 'DB' );
|
2011-06-13 23:28:59 +00:00
|
|
|
$compress = $storeObj->store( $extdb, $compress );
|
|
|
|
|
if ( $compress === false ) {
|
|
|
|
|
$this->error( "Unable to store object" );
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Update text row
|
2024-04-14 18:36:13 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'text' )
|
|
|
|
|
->set( [
|
2011-06-13 23:28:59 +00:00
|
|
|
'old_flags' => $flags,
|
|
|
|
|
'old_text' => $compress
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->where( [
|
2011-06-13 23:28:59 +00:00
|
|
|
'old_id' => $row->old_id
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-18 17:32:20 +00:00
|
|
|
/**
|
2015-02-05 13:13:43 +00:00
|
|
|
* Compress the text in chunks after concatenating the revisions.
|
|
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param int $startId
|
|
|
|
|
* @param int $maxChunkSize
|
|
|
|
|
* @param string $beginDate
|
|
|
|
|
* @param string $endDate
|
|
|
|
|
* @param string $extdb
|
|
|
|
|
* @param bool|int $maxPageId
|
2011-10-18 17:32:20 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-06-13 23:28:59 +00:00
|
|
|
private function compressWithConcat( $startId, $maxChunkSize, $beginDate,
|
2013-12-01 20:39:00 +00:00
|
|
|
$endDate, $extdb = "", $maxPageId = false
|
|
|
|
|
) {
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
|
|
|
|
$dbw = $this->getPrimaryDB();
|
2011-06-13 23:28:59 +00:00
|
|
|
|
|
|
|
|
# Set up external storage
|
|
|
|
|
if ( $extdb != '' ) {
|
2023-08-31 09:21:12 +00:00
|
|
|
$esFactory = $this->getServiceContainer()->getExternalStoreFactory();
|
2018-02-27 06:24:46 +00:00
|
|
|
/** @var ExternalStoreDB $storeObj */
|
|
|
|
|
$storeObj = $esFactory->getStore( 'DB' );
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
2019-12-07 18:32:45 +00:00
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$blobStore = $this->getServiceContainer()
|
2019-09-20 18:11:35 +00:00
|
|
|
->getBlobStoreFactory()
|
|
|
|
|
->newSqlBlobStore();
|
2011-06-13 23:28:59 +00:00
|
|
|
|
|
|
|
|
# Get all articles by page_id
|
|
|
|
|
if ( !$maxPageId ) {
|
2023-07-18 22:56:37 +00:00
|
|
|
$maxPageId = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( 'max(page_id)' )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->caller( __METHOD__ )->fetchField();
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
|
|
|
|
$this->output( "Starting from $startId of $maxPageId\n" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageConds = [];
|
2011-06-13 23:28:59 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if ( $exclude_ns0 ) {
|
|
|
|
|
print "Excluding main namespace\n";
|
|
|
|
|
$pageConds[] = 'page_namespace<>0';
|
|
|
|
|
}
|
|
|
|
|
if ( $queryExtra ) {
|
2023-09-26 18:40:35 +00:00
|
|
|
$pageConds[] = $queryExtra;
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# For each article, get a list of revisions which fit the criteria
|
2004-01-03 12:32:32 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
# No recompression, use a condition on old_flags
|
|
|
|
|
# Don't compress object type entities, because that might produce data loss when
|
|
|
|
|
# overwriting bulk storage concat rows. Don't compress external references, because
|
|
|
|
|
# the script doesn't yet delete rows from external storage.
|
2023-09-26 18:40:35 +00:00
|
|
|
$slotRoleStore = $this->getServiceContainer()->getSlotRoleStore();
|
|
|
|
|
$queryBuilderTemplate = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'rev_id', 'old_id', 'old_flags', 'old_text' ] )
|
|
|
|
|
->forUpdate()
|
|
|
|
|
->from( 'revision' )
|
|
|
|
|
->join( 'slots', null, 'rev_id=slot_revision_id' )
|
|
|
|
|
->join( 'content', null, 'content_id=slot_content_id' )
|
|
|
|
|
->join( 'text', null, 'SUBSTRING(content_address, 4)=old_id' )
|
|
|
|
|
->where(
|
2024-01-17 17:48:40 +00:00
|
|
|
$dbr->expr(
|
|
|
|
|
'old_flags',
|
|
|
|
|
IExpression::NOT_LIKE,
|
|
|
|
|
new LikeValue( $dbr->anyString(), 'object', $dbr->anyString() )
|
|
|
|
|
)->and(
|
|
|
|
|
'old_flags',
|
|
|
|
|
IExpression::NOT_LIKE,
|
|
|
|
|
new LikeValue( $dbr->anyString(), 'external', $dbr->anyString() )
|
|
|
|
|
)
|
2023-09-26 18:40:35 +00:00
|
|
|
)
|
|
|
|
|
->andWhere( [
|
|
|
|
|
'slot_role_id' => $slotRoleStore->getId( SlotRecord::MAIN ),
|
|
|
|
|
'SUBSTRING(content_address, 1, 3)=' . $dbr->addQuotes( 'tt:' ),
|
|
|
|
|
] );
|
2004-01-03 12:32:32 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
if ( $beginDate ) {
|
|
|
|
|
if ( !preg_match( '/^\d{14}$/', $beginDate ) ) {
|
|
|
|
|
$this->error( "Invalid begin date \"$beginDate\"\n" );
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2024-07-22 20:29:20 +00:00
|
|
|
$queryBuilderTemplate->andWhere( $dbr->expr( 'rev_timestamp', '>', $beginDate ) );
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
2013-04-27 11:23:52 +00:00
|
|
|
if ( $endDate ) {
|
2011-06-13 23:28:59 +00:00
|
|
|
if ( !preg_match( '/^\d{14}$/', $endDate ) ) {
|
|
|
|
|
$this->error( "Invalid end date \"$endDate\"\n" );
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2024-07-22 20:29:20 +00:00
|
|
|
$queryBuilderTemplate->andWhere( $dbr->expr( 'rev_timestamp', '<', $endDate ) );
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
2019-04-02 14:37:55 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
for ( $pageId = $startId; $pageId <= $maxPageId; $pageId++ ) {
|
2022-10-24 18:31:49 +00:00
|
|
|
$this->waitForReplication();
|
2011-06-13 23:28:59 +00:00
|
|
|
|
|
|
|
|
# Wake up
|
|
|
|
|
$dbr->ping();
|
|
|
|
|
|
|
|
|
|
# Get the page row
|
2023-08-04 15:32:46 +00:00
|
|
|
$pageRow = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'page_id', 'page_namespace', 'page_title', 'rev_timestamp' ] )
|
2023-07-18 22:56:37 +00:00
|
|
|
->from( 'page' )
|
2023-08-04 15:32:46 +00:00
|
|
|
->straightJoin( 'revision', null, 'page_latest = rev_id' )
|
2023-07-18 22:56:37 +00:00
|
|
|
->where( $pageConds )
|
|
|
|
|
->andWhere( [ 'page_id' => $pageId ] )
|
2023-08-04 15:32:46 +00:00
|
|
|
->caller( __METHOD__ )->fetchRow();
|
|
|
|
|
if ( $pageRow === false ) {
|
2011-06-13 23:28:59 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Display progress
|
|
|
|
|
$titleObj = Title::makeTitle( $pageRow->page_namespace, $pageRow->page_title );
|
|
|
|
|
$this->output( "$pageId\t" . $titleObj->getPrefixedDBkey() . " " );
|
|
|
|
|
|
|
|
|
|
# Load revisions
|
2023-09-26 18:40:35 +00:00
|
|
|
$queryBuilder = clone $queryBuilderTemplate;
|
|
|
|
|
$revRes = $queryBuilder->where(
|
|
|
|
|
[
|
2011-06-13 23:28:59 +00:00
|
|
|
'rev_page' => $pageRow->page_id,
|
2023-09-26 18:40:35 +00:00
|
|
|
// Don't operate on the current revision
|
|
|
|
|
// Use < instead of <> in case the current revision has changed
|
|
|
|
|
// since the page select, which wasn't locking
|
2024-07-22 20:29:20 +00:00
|
|
|
$dbr->expr( 'rev_timestamp', '<', (int)$pageRow->rev_timestamp ),
|
2023-09-26 18:40:35 +00:00
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$revs = [];
|
2011-06-13 23:28:59 +00:00
|
|
|
foreach ( $revRes as $revRow ) {
|
|
|
|
|
$revs[] = $revRow;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 11:23:52 +00:00
|
|
|
if ( count( $revs ) < 2 ) {
|
2011-06-13 23:28:59 +00:00
|
|
|
# No revisions matching, no further processing
|
|
|
|
|
$this->output( "\n" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# For each chunk
|
|
|
|
|
$i = 0;
|
|
|
|
|
while ( $i < count( $revs ) ) {
|
|
|
|
|
if ( $i < count( $revs ) - $maxChunkSize ) {
|
|
|
|
|
$thisChunkSize = $maxChunkSize;
|
|
|
|
|
} else {
|
|
|
|
|
$thisChunkSize = count( $revs ) - $i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$chunk = new ConcatenatedGzipHistoryBlob();
|
2016-02-17 09:09:32 +00:00
|
|
|
$stubs = [];
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->beginTransaction( $dbw, __METHOD__ );
|
2011-06-13 23:28:59 +00:00
|
|
|
$usedChunk = false;
|
2019-04-02 14:37:55 +00:00
|
|
|
$primaryOldid = $revs[$i]->old_id;
|
2011-06-13 23:28:59 +00:00
|
|
|
|
|
|
|
|
# Get the text of each revision and add it to the object
|
|
|
|
|
for ( $j = 0; $j < $thisChunkSize && $chunk->isHappy(); $j++ ) {
|
2019-04-02 14:37:55 +00:00
|
|
|
$oldid = $revs[$i + $j]->old_id;
|
2011-06-13 23:28:59 +00:00
|
|
|
|
2019-09-20 18:11:35 +00:00
|
|
|
# Get text. We do not need the full `extractBlob` since the query is built
|
|
|
|
|
# to fetch non-externalstore blobs.
|
|
|
|
|
$text = $blobStore->decompressData(
|
|
|
|
|
$revs[$i + $j]->old_text,
|
|
|
|
|
explode( ',', $revs[$i + $j]->old_flags )
|
|
|
|
|
);
|
2011-06-13 23:28:59 +00:00
|
|
|
|
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
$this->error( "\nError, unable to get text in old_id $oldid" );
|
2016-09-27 03:15:08 +00:00
|
|
|
# $dbw->delete( 'old', [ 'old_id' => $oldid ] );
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $extdb == "" && $j == 0 ) {
|
|
|
|
|
$chunk->setText( $text );
|
|
|
|
|
$this->output( '.' );
|
|
|
|
|
} else {
|
|
|
|
|
# Don't make a stub if it's going to be longer than the article
|
|
|
|
|
# Stubs are typically about 100 bytes
|
|
|
|
|
if ( strlen( $text ) < 120 ) {
|
|
|
|
|
$stub = false;
|
|
|
|
|
$this->output( 'x' );
|
|
|
|
|
} else {
|
|
|
|
|
$stub = new HistoryBlobStub( $chunk->addItem( $text ) );
|
|
|
|
|
$stub->setLocation( $primaryOldid );
|
|
|
|
|
$stub->setReferrer( $oldid );
|
|
|
|
|
$this->output( '.' );
|
|
|
|
|
$usedChunk = true;
|
|
|
|
|
}
|
|
|
|
|
$stubs[$j] = $stub;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$thisChunkSize = $j;
|
|
|
|
|
|
|
|
|
|
# If we couldn't actually use any stubs because the pages were too small, do nothing
|
|
|
|
|
if ( $usedChunk ) {
|
|
|
|
|
if ( $extdb != "" ) {
|
|
|
|
|
# Move blob objects to External Storage
|
2022-03-29 18:11:06 +00:00
|
|
|
// @phan-suppress-next-line PhanPossiblyUndeclaredVariable storeObj is set when used
|
2014-04-22 20:23:18 +00:00
|
|
|
$stored = $storeObj->store( $extdb, serialize( $chunk ) );
|
2013-04-27 11:23:52 +00:00
|
|
|
if ( $stored === false ) {
|
2013-04-18 18:48:44 +00:00
|
|
|
$this->error( "Unable to store object" );
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
# Store External Storage URLs instead of Stub placeholders
|
2013-04-27 11:23:52 +00:00
|
|
|
foreach ( $stubs as $stub ) {
|
2013-04-18 18:48:44 +00:00
|
|
|
if ( $stub === false ) {
|
2011-06-13 23:28:59 +00:00
|
|
|
continue;
|
2013-04-18 18:48:44 +00:00
|
|
|
}
|
2011-06-13 23:28:59 +00:00
|
|
|
# $stored should provide base path to a BLOB
|
2013-04-13 11:36:24 +00:00
|
|
|
$url = $stored . "/" . $stub->getHash();
|
2024-04-14 18:36:13 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'text' )
|
|
|
|
|
->set( [
|
2011-06-13 23:28:59 +00:00
|
|
|
'old_text' => $url,
|
|
|
|
|
'old_flags' => 'external,utf-8',
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->where( [
|
2011-06-13 23:28:59 +00:00
|
|
|
'old_id' => $stub->getReferrer(),
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
# Store the main object locally
|
2024-04-14 18:36:13 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'text' )
|
|
|
|
|
->set( [
|
2011-06-13 23:28:59 +00:00
|
|
|
'old_text' => serialize( $chunk ),
|
|
|
|
|
'old_flags' => 'object,utf-8',
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->where( [
|
2011-06-13 23:28:59 +00:00
|
|
|
'old_id' => $primaryOldid
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2011-06-13 23:28:59 +00:00
|
|
|
|
|
|
|
|
# Store the stub objects
|
|
|
|
|
for ( $j = 1; $j < $thisChunkSize; $j++ ) {
|
|
|
|
|
# Skip if not compressing and don't overwrite the first revision
|
2019-04-02 14:37:55 +00:00
|
|
|
if ( $stubs[$j] !== false && $revs[$i + $j]->old_id != $primaryOldid ) {
|
2024-04-14 18:36:13 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'text' )
|
|
|
|
|
->set( [
|
2013-04-27 11:23:52 +00:00
|
|
|
'old_text' => serialize( $stubs[$j] ),
|
2011-06-13 23:28:59 +00:00
|
|
|
'old_flags' => 'object,utf-8',
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->where( [
|
2019-04-02 14:37:55 +00:00
|
|
|
'old_id' => $revs[$i + $j]->old_id
|
2024-04-14 18:36:13 +00:00
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2011-06-13 23:28:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# Done, next
|
|
|
|
|
$this->output( "/" );
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->commitTransaction( $dbw, __METHOD__ );
|
2011-06-13 23:28:59 +00:00
|
|
|
$i += $thisChunkSize;
|
|
|
|
|
}
|
|
|
|
|
$this->output( "\n" );
|
|
|
|
|
}
|
2014-04-22 20:23:18 +00:00
|
|
|
|
2011-06-13 23:28:59 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = CompressOld::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|