MediaWiki  REL1_21
purgeParserCache.php
Go to the documentation of this file.
00001 <?php
00025 require( __DIR__ . '/Maintenance.php' );
00026 
00032 class PurgeParserCache extends Maintenance {
00033         public $lastProgress;
00034 
00035         function __construct() {
00036                 parent::__construct();
00037                 $this->addDescription( "Remove old objects from the parser cache. " .
00038                         "This only works when the parser cache is in an SQL database." );
00039                 $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
00040                 $this->addOption( 'age',
00041                         'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime ' .
00042                                 'has been consistent.',
00043                         false, true );
00044         }
00045 
00046         function execute() {
00047                 $inputDate = $this->getOption( 'expiredate' );
00048                 $inputAge = $this->getOption( 'age' );
00049                 if ( $inputDate !== null ) {
00050                         $date = wfTimestamp( TS_MW, strtotime( $inputDate ) );
00051                 } elseif ( $inputAge !== null ) {
00052                         global $wgParserCacheExpireTime;
00053                         $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) );
00054                 } else {
00055                         $this->error( "Must specify either --expiredate or --age", 1 );
00056                 }
00057 
00058                 $english = Language::factory( 'en' );
00059                 $this->output( "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n" );
00060 
00061                 $pc = wfGetParserCacheStorage();
00062                 $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) );
00063                 if ( !$success ) {
00064                         $this->error( "\nCannot purge this kind of parser cache.", 1 );
00065                 }
00066                 $this->showProgress( 100 );
00067                 $this->output( "\nDone\n" );
00068         }
00069 
00070         function showProgress( $percent ) {
00071                 $percentString = sprintf( "%.2f", $percent );
00072                 if ( $percentString === $this->lastProgress ) {
00073                         return;
00074                 }
00075                 $this->lastProgress = $percentString;
00076 
00077                 $stars = floor( $percent / 2 );
00078                 $this->output( '[' . str_repeat( '*', $stars ) . str_repeat( '.', 50 - $stars ) . '] ' .
00079                         "$percentString%\r" );
00080 
00081         }
00082 }
00083 $maintClass = 'PurgeParserCache';
00084 require_once( RUN_MAINTENANCE_IF_MAIN );