MediaWiki  1.29.1
StoreFileOp.php
Go to the documentation of this file.
1 <?php
29 class StoreFileOp extends FileOp {
30  protected function allowedParams() {
31  return [
32  [ 'src', 'dst' ],
33  [ 'overwrite', 'overwriteSame', 'headers' ],
34  [ 'src', 'dst' ]
35  ];
36  }
37 
38  protected function doPrecheck( array &$predicates ) {
40  // Check if the source file exists on the file system
41  if ( !is_file( $this->params['src'] ) ) {
42  $status->fatal( 'backend-fail-notexists', $this->params['src'] );
43 
44  return $status;
45  // Check if the source file is too big
46  } elseif ( filesize( $this->params['src'] ) > $this->backend->maxFileSizeInternal() ) {
47  $status->fatal( 'backend-fail-maxsize',
48  $this->params['dst'], $this->backend->maxFileSizeInternal() );
49  $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
50 
51  return $status;
52  // Check if a file can be placed/changed at the destination
53  } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
54  $status->fatal( 'backend-fail-usable', $this->params['dst'] );
55  $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
56 
57  return $status;
58  }
59  // Check if destination file exists
60  $status->merge( $this->precheckDestExistence( $predicates ) );
61  $this->params['dstExists'] = $this->destExists; // see FileBackendStore::setFileCache()
62  if ( $status->isOK() ) {
63  // Update file existence predicates
64  $predicates['exists'][$this->params['dst']] = true;
65  $predicates['sha1'][$this->params['dst']] = $this->sourceSha1;
66  }
67 
68  return $status; // safe to call attempt()
69  }
70 
71  protected function doAttempt() {
72  if ( !$this->overwriteSameCase ) {
73  // Store the file at the destination
74  return $this->backend->storeInternal( $this->setFlags( $this->params ) );
75  }
76 
77  return StatusValue::newGood();
78  }
79 
80  protected function getSourceSha1Base36() {
81  MediaWiki\suppressWarnings();
82  $hash = sha1_file( $this->params['src'] );
83  MediaWiki\restoreWarnings();
84  if ( $hash !== false ) {
85  $hash = Wikimedia\base_convert( $hash, 16, 36, 31 );
86  }
87 
88  return $hash;
89  }
90 
91  public function storagePathsChanged() {
92  return [ $this->params['dst'] ];
93  }
94 }
FileOp\$sourceSha1
string $sourceSha1
Definition: FileOp.php:62
StoreFileOp\doPrecheck
doPrecheck(array &$predicates)
Definition: StoreFileOp.php:38
FileOp
FileBackend helper class for representing operations.
Definition: FileOp.php:37
FileOp\$destExists
bool $destExists
Definition: FileOp.php:68
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
php
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:35
StoreFileOp\getSourceSha1Base36
getSourceSha1Base36()
precheckDestExistence() helper function to get the source file SHA-1.
Definition: StoreFileOp.php:80
FileOp\setFlags
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition: FileOp.php:335
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:76
StoreFileOp\doAttempt
doAttempt()
Definition: StoreFileOp.php:71
StoreFileOp
Store a file into the backend from a file on the file system.
Definition: StoreFileOp.php:29
StoreFileOp\allowedParams
allowedParams()
Get the file operation parameters.
Definition: StoreFileOp.php:30
FileOp\precheckDestExistence
precheckDestExistence(array $predicates)
Check for errors with regards to the destination file already existing.
Definition: FileOp.php:365
StoreFileOp\storagePathsChanged
storagePathsChanged()
Get a list of storage paths written to for this operation.
Definition: StoreFileOp.php:91
array
the array() calling protocol came about after MediaWiki 1.4rc1.