MediaWiki  1.33.0
testCompression.php
Go to the documentation of this file.
1 <?php
24 $optionsWithArgs = [ 'start', 'limit', 'type' ];
25 require __DIR__ . '/../commandLine.inc';
26 
27 if ( !isset( $args[0] ) ) {
28  echo "Usage: php testCompression.php [--type=<type>] [--start=<start-date>] " .
29  "[--limit=<num-revs>] <page-title>\n";
30  exit( 1 );
31 }
32 
35 if ( isset( $options['start'] ) ) {
36  $start = wfTimestamp( TS_MW, strtotime( $options['start'] ) );
37  echo "Starting from " . $lang->timeanddate( $start ) . "\n";
38 } else {
39  $start = '19700101000000';
40 }
41 if ( isset( $options['limit'] ) ) {
42  $limit = $options['limit'];
43  $untilHappy = false;
44 } else {
45  $limit = 1000;
46  $untilHappy = true;
47 }
49 
50 $dbr = $this->getDB( DB_REPLICA );
51 $revQuery = Revision::getQueryInfo( [ 'page', 'text' ] );
52 $res = $dbr->select(
53  $revQuery['tables'],
54  $revQuery['fields'],
55  [
56  'page_namespace' => $title->getNamespace(),
57  'page_title' => $title->getDBkey(),
58  'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $start ) ),
59  ],
60  __FILE__,
61  [ 'LIMIT' => $limit ],
62  $revQuery['joins']
63 );
64 
65 $blob = new $type;
66 $hashes = [];
67 $keys = [];
69 $t = -microtime( true );
70 foreach ( $res as $row ) {
71  $revision = new Revision( $row );
72  $text = $revision->getSerializedData();
73  $uncompressedSize += strlen( $text );
74  $hashes[$row->rev_id] = md5( $text );
75  $keys[$row->rev_id] = $blob->addItem( $text );
76  if ( $untilHappy && !$blob->isHappy() ) {
77  break;
78  }
79 }
80 
82 $t += microtime( true );
83 # print_r( $blob->mDiffMap );
84 
85 printf( "%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
86  $type,
87  count( $hashes ),
88  $uncompressedSize / strlen( $serialized ),
89  $lang->formatSize( $uncompressedSize ),
90  strlen( $serialized )
91 );
92 printf( "Compression time: %5.2f ms\n", $t * 1000 );
93 
94 $t = -microtime( true );
96 foreach ( $keys as $id => $key ) {
97  $text = $blob->getItem( $key );
98  if ( md5( $text ) != $hashes[$id] ) {
99  echo "Content hash mismatch for rev_id $id\n";
100  # var_dump( $text );
101  }
102 }
103 $t += microtime( true );
104 printf( "Decompression time: %5.2f ms\n", $t * 1000 );
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:249
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:81
$res
$res
Definition: testCompression.php:52
serialize
serialize()
Definition: ApiMessageTrait.php:134
$revQuery
$revQuery
Definition: testCompression.php:51
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$dbr
$dbr
Definition: testCompression.php:50
Revision
Definition: Revision.php:40
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:511
$blob
$blob
Definition: testCompression.php:65
$title
$title
Definition: testCompression.php:34
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
unserialize
unserialize( $serialized)
Definition: ApiMessageTrait.php:142
$args
if( $line===false) $args
Definition: cdb.php:64
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1985
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$keys
$keys
Definition: testCompression.php:67
$uncompressedSize
$uncompressedSize
Definition: testCompression.php:68
$hashes
$hashes
Definition: testCompression.php:66
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:215
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
$t
$t
Definition: testCompression.php:69
$optionsWithArgs
$optionsWithArgs
Definition: testCompression.php:24
$untilHappy
$untilHappy
Definition: testCompression.php:46
$type
$type
Definition: testCompression.php:48