MediaWiki
REL1_20
|
00001 <?php 00025 require( __DIR__ . '/Maintenance.php' ); 00026 00032 class PurgeParserCache extends Maintenance { 00033 var $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 echo "Must specify either --expiredate or --age\n"; 00056 exit( 1 ); 00057 } 00058 00059 $english = Language::factory( 'en' ); 00060 echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n"; 00061 00062 $pc = wfGetParserCacheStorage(); 00063 $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) ); 00064 if ( !$success ) { 00065 echo "\nCannot purge this kind of parser cache.\n"; 00066 exit( 1 ); 00067 } 00068 $this->showProgress( 100 ); 00069 echo "\nDone\n"; 00070 } 00071 00072 function showProgress( $percent ) { 00073 $percentString = sprintf( "%.2f", $percent ); 00074 if ( $percentString === $this->lastProgress ) { 00075 return; 00076 } 00077 $this->lastProgress = $percentString; 00078 00079 $stars = floor( $percent / 2 ); 00080 echo '[' . str_repeat( '*', $stars ), str_repeat( '.', 50 - $stars ) . '] ' . 00081 "$percentString%\r"; 00082 00083 } 00084 } 00085 $maintClass = 'PurgeParserCache'; 00086 require_once( RUN_MAINTENANCE_IF_MAIN );