MediaWiki REL1_28
Go to the documentation of this file.
25require_once __DIR__ . '/Maintenance.php';
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Erases traces of deleted files.' );
39 $this->addOption( 'delete', 'Perform the deletion' );
40 $this->addOption( 'filename', 'File name', false, true );
41 $this->addOption( 'filekey', 'File storage key (with extension) or "*"', true, true );
42 }
44 public function execute() {
45 if ( !$this->hasOption( 'delete' ) ) {
46 $this->output( "Use --delete to actually confirm this script\n" );
47 }
49 $filekey = $this->getOption( 'filekey' );
50 $filename = $this->getOption( 'filename' );
52 if ( $filekey === '*' ) { // all versions by name
53 if ( !strlen( $filename ) ) {
54 $this->error( "Missing --filename parameter.", 1 );
55 }
56 $afile = false;
57 } else { // specified version
58 $dbw = $this->getDB( DB_MASTER );
59 $row = $dbw->selectRow( 'filearchive', '*',
60 [ 'fa_storage_group' => 'deleted', 'fa_storage_key' => $filekey ],
61 __METHOD__ );
62 if ( !$row ) {
63 $this->error( "No deleted file exists with key '$filekey'.", 1 );
64 }
65 $filename = $row->fa_name;
66 $afile = ArchivedFile::newFromRow( $row );
67 }
69 $file = wfLocalFile( $filename );
70 if ( $file->exists() ) {
71 $this->error( "File '$filename' is still a public file, use the delete form.\n", 1 );
72 }
74 $this->output( "Purging all thumbnails for file '$filename'..." );
75 $file->purgeCache();
76 $this->output( "done.\n" );
78 if ( $afile instanceof ArchivedFile ) {
79 $this->scrubVersion( $afile );
80 } else {
81 $this->output( "Finding deleted versions of file '$filename'...\n" );
82 $this->scrubAllVersions( $filename );
83 $this->output( "Done\n" );
84 }
85 }
87 protected function scrubAllVersions( $name ) {
88 $dbw = $this->getDB( DB_MASTER );
89 $res = $dbw->select( 'filearchive', '*',
90 [ 'fa_name' => $name, 'fa_storage_group' => 'deleted' ],
91 __METHOD__ );
92 foreach ( $res as $row ) {
93 $this->scrubVersion( ArchivedFile::newFromRow( $row ) );
94 }
95 }
97 protected function scrubVersion( ArchivedFile $archivedFile ) {
98 $key = $archivedFile->getStorageKey();
99 $name = $archivedFile->getName();
100 $ts = $archivedFile->getTimestamp();
101 $repo = RepoGroup::singleton()->getLocalRepo();
102 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
103 if ( $this->hasOption( 'delete' ) ) {
104 $status = $repo->getBackend()->delete( [ 'src' => $path ] );
105 if ( $status->isOK() ) {
106 $this->output( "Deleted version '$key' ($ts) of file '$name'\n" );
107 } else {
108 $this->output( "Failed to delete version '$key' ($ts) of file '$name'\n" );
109 $this->output( print_r( $status->getErrorsArray(), true ) );
110 }
111 } else {
112 $this->output( "Would delete version '{$key}' ({$ts}) of file '$name'\n" );
113 }
114 }
117$maintClass = "EraseArchivedFile";
118require_once RUN_MAINTENANCE_IF_MAIN;
wfLocalFile( $title)
Get an object referring to a locally registered file.
Class representing a row of the 'filearchive' table.
Return upload timestamp.
static newFromRow( $row)
Loads a file object from the filearchive table.
Return the FileStore key (overriding base File class)
Return the file name.
Maintenance script to delete archived (non-current) files from storage.
scrubVersion(ArchivedFile $archivedFile)
Do the actual work.
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
Definition database.txt:21
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
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
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Definition defines.php:23