3 require( dirname( __FILE__
) . '/Maintenance.php' );
5 class PurgeParserCache
extends Maintenance
{
8 function __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.',
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 ) );
28 echo "Must specify either --expiredate or --age\n";
32 $english = Language
::factory( 'en' );
33 echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n";
35 $pc = wfGetParserCacheStorage();
36 $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) );
38 echo "\nCannot purge this kind of parser cache.\n";
41 $this->showProgress( 100 );
45 function showProgress( $percent ) {
46 $percentString = sprintf( "%.2f", $percent );
47 if ( $percentString === $this->lastProgress
) {
50 $this->lastProgress
= $percentString;
52 $stars = floor( $percent / 2 );
53 echo '[' . str_repeat( '*', $stars ), str_repeat( '.', 50 - $stars ) . '] ' .
58 $maintClass = 'PurgeParserCache';
59 require_once( RUN_MAINTENANCE_IF_MAIN
);