28 require_once __DIR__ .
'/../Maintenance.php';
32 parent::__construct();
34 $this->
addArg(
'title',
'The page to test' );
36 $this->
addOption(
'type',
'The HistoryBlob subclass to use',
false,
true );
37 $this->
addOption(
'start',
'The start date',
false,
true );
38 $this->
addOption(
'limit',
'Maximum number of revisions to process',
false,
true );
43 $title = Title::newFromText( $this->
getArg( 0 ) );
47 echo
"Starting from " . $lang->timeanddate( $start ) .
"\n";
49 $start =
'19700101000000';
58 $type = $this->
getOption(
'type', ConcatenatedGzipHistoryBlob::class );
63 $res = $revStore->newSelectQueryBuilder( $dbr )
67 'page_namespace' => $title->getNamespace(),
68 'page_title' => $title->getDBkey(),
69 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $start ) ),
72 ->caller( __FILE__ )->fetchResultSet();
77 $uncompressedSize = 0;
78 $t = -microtime(
true );
79 foreach ( $res as $row ) {
80 $revRecord = $revStore->newRevisionFromRow( $row );
81 $text = $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
84 $uncompressedSize += strlen( $text );
85 $hashes[$row->rev_id] = md5( $text );
86 $keys[$row->rev_id] = $blob->addItem( $text );
87 if ( $untilHappy && !$blob->isHappy() ) {
92 $serialized = serialize( $blob );
93 $t += microtime(
true );
94 # print_r( $blob->mDiffMap );
96 printf(
"%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
99 $uncompressedSize / strlen( $serialized ),
100 $lang->formatSize( $uncompressedSize ),
101 strlen( $serialized )
103 printf(
"Compression time: %5.2f ms\n",
$t * 1000 );
105 $t = -microtime(
true );
106 $blob = unserialize( $serialized );
107 foreach ( $keys as $id => $key ) {
108 $text = $blob->getItem( $key );
109 if ( md5( $text ) != $hashes[$id] ) {
110 echo
"Content hash mismatch for rev_id $id\n";
114 $t += microtime(
true );
115 printf(
"Decompression time: %5.2f ms\n",
$t * 1000 );
120 require_once RUN_MAINTENANCE_IF_MAIN;
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=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
getArg( $argId=0, $default=null)
Get an argument.
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.
execute()
Do the actual work.
__construct()
Default constructor.