Go to the documentation of this file.
25 require_once __DIR__ .
'/Maintenance.php';
40 'upload' =>
array(
'upload' ),
41 'import' =>
array(
'upload',
'interwiki' ),
44 'delete' =>
array(
'delete',
'revision' ),
45 'suppress' =>
array(
'delete',
'revision' ),
48 'upload' =>
array(
'overwrite',
'revert' ),
49 'move' =>
array(
'move',
'move_redir' ),
64 parent::__construct();
65 $this->mDescription =
"Scan the logging table and purge files and thumbnails.";
66 $this->
addOption(
'starttime',
'Starting timestamp',
true,
true );
67 $this->
addOption(
'endtime',
'Ending timestamp',
true,
true );
68 $this->
addOption(
'type',
'Comma-separated list of types of changes to send purges for (' .
69 implode(
',', array_keys( self::$typeMappings ) ) .
',all)',
false,
true );
70 $this->
addOption(
'htcp-dest',
'HTCP announcement destination (IP:port)',
false,
true );
71 $this->
addOption(
'dry-run',
'Do not send purge requests' );
72 $this->
addOption(
'sleep-per-batch',
'Milliseconds to sleep between batches',
false,
true );
73 $this->
addOption(
'verbose',
'Show more output',
false,
false,
'v' );
81 $parts = explode(
':', $this->
getOption(
'htcp-dest' ) );
82 if ( count( $parts ) < 2 ) {
88 $wgHTCPRouting =
array(
89 '' =>
array(
'host' => $parts[0],
'port' => $parts[1] ),
91 $this->
verbose(
"HTCP broadcasts to {$parts[0]}:{$parts[1]}\n" );
95 $typeOpt = $this->
getOption(
'type',
'all' );
96 $validTypes = array_keys( self::$typeMappings );
97 if ( $typeOpt ===
'all' ) {
99 $typeOpt = implode(
',', $validTypes );
101 $typeList = explode(
',', $typeOpt );
102 foreach ( $typeList
as $type ) {
103 if ( !in_array(
$type, $validTypes ) ) {
104 $this->
error(
"\nERROR: Unknown type: {$type}\n" );
111 $this->startTimestamp =
$dbr->timestamp( $this->
getOption(
'starttime' ) );
112 $this->endTimestamp =
$dbr->timestamp( $this->
getOption(
'endtime' ) );
114 if ( $this->startTimestamp > $this->endTimestamp ) {
115 $this->
error(
"\nERROR: starttime after endtime\n" );
121 $this->mOptions[
'verbose'] = 1;
124 $this->
verbose(
'Purging files that were: ' . implode(
', ', $typeList ) .
"\n" );
125 foreach ( $typeList
as $type ) {
126 $this->
verbose(
"Checking for {$type} files...\n" );
129 $this->
verbose(
"...{$type} files purged.\n\n" );
143 foreach ( self::$typeMappings[
$type]
as $logType => $logActions ) {
144 $this->
verbose(
"Scanning for {$logType}/" . implode(
',', $logActions ) .
"\n" );
148 array(
'log_title',
'log_timestamp',
'log_params' ),
151 'log_type' => $logType,
152 'log_action' => $logActions,
153 'log_timestamp >= ' .
$dbr->addQuotes( $this->startTimestamp ),
154 'log_timestamp <= ' .
$dbr->addQuotes( $this->endTimestamp ),
160 foreach (
$res as $row ) {
164 $this->
verbose(
"{$type}[{$row->log_timestamp}]: {$row->log_title}\n" );
170 $file->purgeHistory();
172 if ( $logType ===
'delete' ) {
174 if ( !
$file->exists() && $repo->fileExists(
$file->getPath() ) ) {
176 if ( $repo->fileExists( $dpath ) ) {
178 $repo->getBackend()->delete(
array(
'src' =>
$file->getPath() ) );
179 $this->
verbose(
"Deleted orphan file: {$file->getPath()}.\n" );
182 $this->
error(
"File was not deleted: {$file->getPath()}.\n" );
189 } elseif ( $logType ===
'move' ) {
192 $params = unserialize( $row->log_params );
193 if ( isset(
$params[
'4::target'] ) ) {
194 $target =
$params[
'4::target'];
196 $targetFile->purgeCache();
197 $targetFile->purgeHistory();
198 $this->
verbose(
"Purged file {$target}; move target @{$row->log_timestamp}.\n" );
202 $this->
verbose(
"Purged file {$row->log_title}; {$type} @{$row->log_timestamp}.\n" );
204 if ( $this->
hasOption(
'sleep-per-batch' ) && ++$bSize > $this->mBatchSize ) {
207 usleep( 1000 * (
int)$this->
getOption(
'sleep-per-batch' ) );
217 array(
'fa_archive_name' ),
222 foreach (
$res as $row ) {
223 if ( $row->fa_archive_name ===
null ) {
234 $this->
output(
"Deleted orphan file: {$ofile->getPath()}.\n" );
237 $this->
error(
"File was not deleted: {$ofile->getPath()}.\n" );
246 $key =
"{$hash}.{$file->getExtension()}";
255 protected function verbose( $msg ) {
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static singleton()
Get a RepoGroup instance.
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
maybeHelp( $force=false)
Maybe show the help.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
require_once RUN_MAINTENANCE_IF_MAIN
purgeOldThumbnails( $archiveName)
Delete cached transformed files for an archived version only.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
verbose( $msg)
Send an output message iff the 'verbose' option has been provided.
& getDB( $db, $groups=array(), $wiki=false)
Returns a database to be used by current maintenance script.
getSlaveDB()
Get a connection to the slave DB.
purgeFromArchiveTable(LocalRepo $repo, LocalFile $file)
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
when a variable name is used in a it is silently declared as a new masking the global
fileExists( $file)
Checks existence of a a file.
getFileSha1( $virtualUrl)
Get the sha1 (base 36) of a file with a given virtual URL/storage path.
Class to represent a local file in the wiki's own database.
newFromArchiveName( $title, $archiveName)
getBackend()
Get the file backend instance.
execute()
Do the actual work.
getDeletedPath(LocalRepo $repo, LocalFile $file)
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks & $hash
if(PHP_SAPI !='cli') $file
purgeFromLogType( $type)
Purge cache and thumbnails for changes of the given type.
getOption( $name, $default=null)
Get an option, or return the default.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular param exists.
getDeletedHashPath( $key)
Get a relative path for a deletion archive key, e.g.
Maintenance script that scans the deletion log and purges affected files within a timeframe.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
setBatchSize( $s=0)
Set the batch size.