MediaWiki REL1_34
CreateFileOp.php
Go to the documentation of this file.
1<?php
26class CreateFileOp extends FileOp {
27 protected function allowedParams() {
28 return [
29 [ 'content', 'dst' ],
30 [ 'overwrite', 'overwriteSame', 'headers' ],
31 [ 'dst' ]
32 ];
33 }
34
35 protected function doPrecheck( array &$predicates ) {
36 $status = StatusValue::newGood();
37
38 // Check if the source data is too big
39 $maxBytes = $this->backend->maxFileSizeInternal();
40 if ( strlen( $this->getParam( 'content' ) ) > $maxBytes ) {
41 $status->fatal( 'backend-fail-maxsize', $this->params['dst'], $maxBytes );
42
43 return $status;
44 }
45 // Check if an incompatible destination file exists
46 $status->merge( $this->precheckDestExistence( $predicates ) );
47 $this->params['dstExists'] = $this->destExists; // see FileBackendStore::setFileCache()
48 if ( $status->isOK() ) {
49 // Update file existence predicates
50 $predicates['exists'][$this->params['dst']] = true;
51 $predicates['sha1'][$this->params['dst']] = $this->sourceSha1;
52 }
53
54 return $status; // safe to call attempt()
55 }
56
57 protected function doAttempt() {
58 if ( $this->overwriteSameCase ) {
59 $status = StatusValue::newGood(); // nothing to do
60 } else {
61 // Create the file at the destination
62 $status = $this->backend->createInternal( $this->setFlags( $this->params ) );
63 }
64
65 return $status;
66 }
67
68 protected function getSourceSha1Base36() {
69 return Wikimedia\base_convert( sha1( $this->params['content'] ), 16, 36, 31 );
70 }
71
72 public function storagePathsChanged() {
73 return [ $this->params['dst'] ];
74 }
75}
Create a file in the backend with the given content.
doPrecheck(array &$predicates)
getSourceSha1Base36()
precheckDestExistence() helper function to get the source file SHA-1.
allowedParams()
Get the file operation parameters.
storagePathsChanged()
Get a list of storage paths written to for this operation.
FileBackend helper class for representing operations.
Definition FileOp.php:36
string $sourceSha1
Definition FileOp.php:61
getParam( $name)
Get the value of the parameter with the given name.
Definition FileOp.php:139
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:346
bool $destExists
Definition FileOp.php:67
precheckDestExistence(array $predicates)
Check for errors with regards to the destination file already existing.
Definition FileOp.php:376