44 require_once __DIR__ .
'/../Maintenance.php';
65 parent::__construct();
67 $this->
addOption(
'type',
'Set compression type to either: gzip|concat',
false,
true,
't' );
70 'Maximum number of revisions in a concat chunk',
77 'Earliest date to check for uncompressed revisions',
82 $this->
addOption(
'end-date',
'Latest revision date to compress',
false,
true,
'e' );
85 'The id to start from (gzip -> text table, concat -> page table)',
92 'Store specified revisions in an external cluster (untested)',
98 'The page_id to stop at (only when using concat compression type)',
107 if ( !function_exists(
"gzdeflate" ) ) {
108 $this->
error(
"You must enable zlib support in PHP to compress old revisions!\n" .
109 "Please see http://www.php.net/manual/en/ref.zlib.php\n",
true );
113 $chunkSize = $this->
getOption(
'chunksize', 20 );
114 $startId = $this->
getOption(
'startid', 0 );
115 $beginDate = $this->
getOption(
'begin-date',
'' );
116 $endDate = $this->
getOption(
'end-date',
'' );
117 $extDB = $this->
getOption(
'extdb',
'' );
118 $endId = $this->
getOption(
'endid',
false );
121 $this->
error(
"Type \"{$type}\" not supported" );
124 if ( $extDB !=
'' ) {
125 $this->
output(
"Compressing database {$wgDBname} to external cluster {$extDB}\n"
126 . str_repeat(
'-', 76 ) .
"\n\n" );
128 $this->
output(
"Compressing database {$wgDBname}\n"
129 . str_repeat(
'-', 76 ) .
"\n\n" );
133 if (
$type ==
'concat' ) {
135 $endDate, $extDB, $endId );
141 $this->
output(
"Done.\n" );
153 $this->
output(
"Starting from old_id $start...\n" );
158 [
'old_id',
'old_flags',
'old_text' ],
161 [
'ORDER BY' =>
'old_id',
'LIMIT' => $chunksize,
'FOR UPDATE' ]
164 if (
$res->numRows() == 0 ) {
170 foreach (
$res as $row ) {
171 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
173 $last = $row->old_id;
176 $start =
$last + 1; # Deletion may leave
long empty stretches
177 $this->
output(
"$start...\n" );
189 if (
false !== strpos( $row->old_flags,
'gzip' )
190 ||
false !== strpos( $row->old_flags,
'object' )
192 # print "Already compressed row {$row->old_id}\n";
196 $flags = $row->old_flags ?
"{$row->old_flags},gzip" :
"gzip";
197 $compress = gzdeflate( $row->old_text );
199 # Store in external storage if required
200 if ( $extdb !==
'' ) {
202 $compress = $storeObj->
store( $extdb, $compress );
203 if ( $compress ===
false ) {
204 $this->
error(
"Unable to store object" );
211 $dbw->update(
'text',
214 'old_text' => $compress
216 'old_id' => $row->old_id
236 $endDate, $extdb =
"", $maxPageId =
false
238 $loadStyle = self::LS_CHUNKED;
243 # Set up external storage
244 if ( $extdb !=
'' ) {
248 # Get all articles by page_id
250 $maxPageId =
$dbr->selectField(
'page',
'max(page_id)',
'', __METHOD__ );
252 $this->
output(
"Starting from $startId of $maxPageId\n" );
265 # For each article, get a list of revisions which fit the criteria
267 # No recompression, use a condition on old_flags
268 # Don't compress object type entities, because that might produce data loss when
269 # overwriting bulk storage concat rows. Don't compress external references, because
270 # the script doesn't yet delete rows from external storage.
272 'old_flags NOT ' .
$dbr->buildLike(
$dbr->anyString(),
'object',
$dbr->anyString() )
273 .
' AND old_flags NOT '
274 .
$dbr->buildLike(
$dbr->anyString(),
'external',
$dbr->anyString() )
278 if ( !preg_match(
'/^\d{14}$/', $beginDate ) ) {
279 $this->
error(
"Invalid begin date \"$beginDate\"\n" );
283 $conds[] =
"rev_timestamp>'" . $beginDate .
"'";
286 if ( !preg_match(
'/^\d{14}$/', $endDate ) ) {
287 $this->
error(
"Invalid end date \"$endDate\"\n" );
291 $conds[] =
"rev_timestamp<'" . $endDate .
"'";
293 if ( $loadStyle == self::LS_CHUNKED ) {
294 $tables = [
'revision',
'text' ];
295 $fields = [
'rev_id',
'rev_text_id',
'old_flags',
'old_text' ];
296 $conds[] =
'rev_text_id=old_id';
297 $revLoadOptions =
'FOR UPDATE';
300 $fields = [
'rev_id',
'rev_text_id' ];
301 $revLoadOptions = [];
304 # Don't work with current revisions
305 # Don't lock the page table for update either -- TS 2006-04-04
306 # $tables[] = 'page';
307 # $conds[] = 'page_id=rev_page AND rev_id != page_latest';
309 for ( $pageId = $startId; $pageId <= $maxPageId; $pageId++ ) {
316 $pageRes =
$dbr->select(
'page',
317 [
'page_id',
'page_namespace',
'page_title',
'page_latest' ],
318 $pageConds + [
'page_id' => $pageId ], __METHOD__ );
319 if ( $pageRes->numRows() == 0 ) {
322 $pageRow =
$dbr->fetchObject( $pageRes );
325 $titleObj =
Title::makeTitle( $pageRow->page_namespace, $pageRow->page_title );
326 $this->
output(
"$pageId\t" . $titleObj->getPrefixedDBkey() .
" " );
329 $revRes = $dbw->select(
$tables, $fields,
331 'rev_page' => $pageRow->page_id,
332 # Don
't operate on the current revision
333 # Use < instead of <> in case the current revision has changed
334 # since the page select, which wasn't locking
335 'rev_id < ' . $pageRow->page_latest
341 foreach ( $revRes
as $revRow ) {
345 if ( count( $revs ) < 2 ) {
346 # No revisions matching, no further processing
353 while ( $i < count( $revs ) ) {
354 if ( $i < count( $revs ) - $maxChunkSize ) {
355 $thisChunkSize = $maxChunkSize;
357 $thisChunkSize = count( $revs ) - $i;
364 $primaryOldid = $revs[$i]->rev_text_id;
367 # Get the text of each revision and add it to the object
368 for ( $j = 0; $j < $thisChunkSize && $chunk->isHappy(); $j++ ) {
370 $oldid = $revs[$i + $j]->rev_text_id;
373 if ( $loadStyle == self::LS_INDIVIDUAL ) {
374 $textRow = $dbw->selectRow(
'text',
375 [
'old_flags',
'old_text' ],
376 [
'old_id' => $oldid ],
385 if ( $text ===
false ) {
386 $this->
error(
"\nError, unable to get text in old_id $oldid" );
387 # $dbw->delete( 'old', [ 'old_id' => $oldid ] );
390 if ( $extdb ==
"" && $j == 0 ) {
391 $chunk->setText( $text );
394 # Don't make a stub if it's going to be longer than the article
395 # Stubs are typically about 100 bytes
396 if ( strlen( $text ) < 120 ) {
402 $stub->setReferrer( $oldid );
411 # If we couldn't actually use any stubs because the pages were too small, do nothing
413 if ( $extdb !=
"" ) {
414 # Move blob objects to External Storage
415 $stored = $storeObj->store( $extdb,
serialize( $chunk ) );
416 if ( $stored ===
false ) {
417 $this->
error(
"Unable to store object" );
421 # Store External Storage URLs instead of Stub placeholders
422 foreach ( $stubs
as $stub ) {
423 if ( $stub ===
false ) {
426 # $stored should provide base path to a BLOB
427 $url = $stored .
"/" . $stub->getHash();
428 $dbw->update(
'text',
431 'old_flags' =>
'external,utf-8',
433 'old_id' => $stub->getReferrer(),
438 # Store the main object locally
439 $dbw->update(
'text',
442 'old_flags' =>
'object,utf-8',
444 'old_id' => $primaryOldid
448 # Store the stub objects
449 for ( $j = 1; $j < $thisChunkSize; $j++ ) {
450 # Skip if not compressing and don't overwrite the first revision
451 if ( $stubs[$j] !==
false && $revs[$i + $j]->rev_text_id != $primaryOldid ) {
452 $dbw->update(
'text',
455 'old_flags' =>
'object,utf-8',
457 'old_id' => $revs[$i + $j]->rev_text_id
467 $i += $thisChunkSize;
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
compressPage($row, $extdb)
Compress the text in gzip format.
static getRevisionText($row, $prefix= 'old_', $wiki=false)
Get revision text associated with an old or archive row $row is usually an object from wfFetchRow()...
wfWaitForSlaves($ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
const LS_CHUNKED
Option to load revisions in chunks.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB($db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
require_once RUN_MAINTENANCE_IF_MAIN
when a variable name is used in a it is silently declared as a new local masking the global
Pointer object for an item within a CGZ blob stored in the text table.
compressOldPages($start=0, $extdb= '')
Fetch the text row-by-row to 'compressPage' function for compression.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
const LS_INDIVIDUAL
Option to load each revision individually.
addOption($name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Concatenated gzip (CGZ) storage Improves compression ratio by concatenating like objects before gzipp...
setLocation($id)
Sets the location (old_id) of the main object to which this object points.
addDescription($text)
Set the description text.
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
getOption($name, $default=null)
Get an option, or return the default.
output($out, $channel=null)
Throw some output to the user.
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
error($err, $die=0)
Throw an error to the user.
compressWithConcat($startId, $maxChunkSize, $beginDate, $endDate, $extdb="", $maxPageId=false)
Compress the text in chunks after concatenating the revisions.
Maintenance script that compress the text of a wiki.
controlled by $wgMainCacheType controlled by $wgParserCacheType controlled by $wgMessageCacheType If you set CACHE_NONE to one of the three control default value for MediaWiki still create a but requests to it are no ops and we always fall through to the database If the cache daemon can t be it should also disable itself fairly smoothly By $wgMemc is used but when it is $parserMemc or $messageMemc this is mentioned $wgDBname
DB accessable external objects.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.