7 require( dirname( __FILE__
) . '/Maintenance.php' );
9 class PurgeParserCache
extends Maintenance
{
12 function __construct() {
13 parent
::__construct();
14 $this->addDescription( "Remove old objects from the parser cache. " .
15 "This only works when the parser cache is in an SQL database." );
16 $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
17 $this->addOption( 'age',
18 'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime '.
19 'has been consistent.',
24 $inputDate = $this->getOption( 'expiredate' );
25 $inputAge = $this->getOption( 'age' );
26 if ( $inputDate !== null ) {
27 $date = wfTimestamp( TS_MW
, strtotime( $inputDate ) );
28 } elseif ( $inputAge !== null ) {
29 global $wgParserCacheExpireTime;
30 $date = wfTimestamp( TS_MW
, time() +
$wgParserCacheExpireTime - intval( $inputAge ) );
32 echo "Must specify either --expiredate or --age\n";
36 $english = Language
::factory( 'en' );
37 echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n";
39 $pc = wfGetParserCacheStorage();
40 $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) );
42 echo "\nCannot purge this kind of parser cache.\n";
45 $this->showProgress( 100 );
49 function showProgress( $percent ) {
50 $percentString = sprintf( "%.2f", $percent );
51 if ( $percentString === $this->lastProgress
) {
54 $this->lastProgress
= $percentString;
56 $stars = floor( $percent / 2 );
57 echo '[' . str_repeat( '*', $stars ), str_repeat( '.', 50 - $stars ) . '] ' .
62 $maintClass = 'PurgeParserCache';
63 require_once( RUN_MAINTENANCE_IF_MAIN
);