MediaWiki  1.23.8
purgeParserCache.php
Go to the documentation of this file.
1 <?php
25 require __DIR__ . '/Maintenance.php';
26 
33  public $lastProgress;
34 
35  function __construct() {
36  parent::__construct();
37  $this->addDescription( "Remove old objects from the parser cache. " .
38  "This only works when the parser cache is in an SQL database." );
39  $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
40  $this->addOption( 'age',
41  'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime ' .
42  'has been consistent.',
43  false, true );
44  }
45 
46  function execute() {
47  $inputDate = $this->getOption( 'expiredate' );
48  $inputAge = $this->getOption( 'age' );
49  if ( $inputDate !== null ) {
50  $date = wfTimestamp( TS_MW, strtotime( $inputDate ) );
51  } elseif ( $inputAge !== null ) {
52  global $wgParserCacheExpireTime;
53  $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) );
54  } else {
55  $this->error( "Must specify either --expiredate or --age", 1 );
56  }
57 
58  $english = Language::factory( 'en' );
59  $this->output( "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n" );
60 
62  $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) );
63  if ( !$success ) {
64  $this->error( "\nCannot purge this kind of parser cache.", 1 );
65  }
66  $this->showProgress( 100 );
67  $this->output( "\nDone\n" );
68  }
69 
70  function showProgress( $percent ) {
71  $percentString = sprintf( "%.2f", $percent );
72  if ( $percentString === $this->lastProgress ) {
73  return;
74  }
75  $this->lastProgress = $percentString;
76 
77  $stars = floor( $percent / 2 );
78  $this->output( '[' . str_repeat( '*', $stars ) . str_repeat( '.', 50 - $stars ) . '] ' .
79  "$percentString%\r" );
80 
81  }
82 }
83 $maintClass = 'PurgeParserCache';
84 require_once RUN_MAINTENANCE_IF_MAIN;
PurgeParserCache\$lastProgress
$lastProgress
Definition: purgeParserCache.php:33
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:227
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
PurgeParserCache\execute
execute()
Do the actual work.
Definition: purgeParserCache.php:46
PurgeParserCache\showProgress
showProgress( $percent)
Definition: purgeParserCache.php:70
$success
$success
Definition: Utf8Test.php:91
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$maintClass
$maintClass
Definition: purgeParserCache.php:83
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2431
PurgeParserCache\__construct
__construct()
Default constructor.
Definition: purgeParserCache.php:35
wfGetParserCacheStorage
wfGetParserCacheStorage()
Get the cache object used by the parser cache.
Definition: GlobalFunctions.php:3986
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
PurgeParserCache
Maintenance script to remove old objects from the parser cache.
Definition: purgeParserCache.php:32
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184