30require __DIR__ .
'/../CommandLineInc.php';
32if ( !isset( $args[0] ) ) {
33 echo
"Usage: php testCompression.php [--type=<type>] [--start=<start-date>] " .
34 "[--limit=<num-revs>] <page-title>\n";
38$lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage(
'en' );
39$title = Title::newFromText( $args[0] );
40if ( isset( $options[
'start'] ) ) {
41 $start =
wfTimestamp( TS_MW, strtotime( $options[
'start'] ) );
42 echo
"Starting from " .
$lang->timeanddate( $start ) .
"\n";
44 $start =
'19700101000000';
46if ( isset( $options[
'limit'] ) ) {
47 $limit = $options[
'limit'];
53$type = $options[
'type'] ?? ConcatenatedGzipHistoryBlob::class;
56$revStore = MediaWikiServices::getInstance()->getRevisionStore();
62 'page_namespace' =>
$title->getNamespace(),
63 'page_title' =>
$title->getDBkey(),
64 'rev_timestamp > ' .
$dbr->addQuotes(
$dbr->timestamp( $start ) ),
67 [
'LIMIT' => $limit ],
75$t = -microtime(
true );
76foreach (
$res as $row ) {
77 $revRecord =
$revStore->newRevisionFromRow( $row );
78 $text = $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
82 $hashes[$row->rev_id] = md5( $text );
90$t += microtime(
true );
91# print_r( $blob->mDiffMap );
93printf(
"%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
100printf(
"Compression time: %5.2f ms\n",
$t * 1000 );
102$t = -microtime(
true );
104foreach (
$keys as $id => $key ) {
105 $text =
$blob->getItem( $key );
106 if ( md5( $text ) !=
$hashes[$id] ) {
107 echo
"Content hash mismatch for rev_id $id\n";
111$t += microtime(
true );
112printf(
"Decompression time: %5.2f ms\n",
$t * 1000 );
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
foreach( $res as $row) $serialized
if(!isset( $args[0])) $lang