Localisation updates for core and extension messages from translatewiki.net
[lhc/web/wiklou.git] / maintenance / purgeParserCache.php
1 <?php
2
3 require( dirname( __FILE__ ) . '/Maintenance.php' );
4
5 class PurgeParserCache extends Maintenance {
6 var $lastProgress;
7
8 function __construct() {
9 parent::__construct();
10 $this->addDescription( "Remove old objects from the parser cache. " .
11 "This only works when the parser cache is in an SQL database." );
12 $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
13 $this->addOption( 'age',
14 'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime '.
15 'has been consistent.',
16 false, true );
17 }
18
19 function execute() {
20 $inputDate = $this->getOption( 'expiredate' );
21 $inputAge = $this->getOption( 'age' );
22 if ( $inputDate !== null ) {
23 $date = wfTimestamp( TS_MW, strtotime( $inputDate ) );
24 } elseif ( $inputAge !== null ) {
25 global $wgParserCacheExpireTime;
26 $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) );
27 } else {
28 echo "Must specify either --expiredate or --age\n";
29 exit( 1 );
30 }
31
32 $english = Language::factory( 'en' );
33 echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n";
34
35 $pc = wfGetParserCacheStorage();
36 $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) );
37 if ( !$success ) {
38 echo "\nCannot purge this kind of parser cache.\n";
39 exit( 1 );
40 }
41 $this->showProgress( 100 );
42 echo "\nDone\n";
43 }
44
45 function showProgress( $percent ) {
46 $percentString = sprintf( "%.2f", $percent );
47 if ( $percentString === $this->lastProgress ) {
48 return;
49 }
50 $this->lastProgress = $percentString;
51
52 $stars = floor( $percent / 2 );
53 echo '[' . str_repeat( '*', $stars ), str_repeat( '.', 50 - $stars ) . '] ' .
54 "$percentString%\r";
55
56 }
57 }
58 $maintClass = 'PurgeParserCache';
59 require_once( RUN_MAINTENANCE_IF_MAIN );