summaryrefslogtreecommitdiff
path: root/includes/upload/UploadStash.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/upload/UploadStash.php')
-rw-r--r--includes/upload/UploadStash.php48
1 files changed, 39 insertions, 9 deletions
diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php
index ad153d2f..c7fd23a9 100644
--- a/includes/upload/UploadStash.php
+++ b/includes/upload/UploadStash.php
@@ -1,5 +1,27 @@
<?php
/**
+ * Temporary storage for uploaded files.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Upload
+ */
+
+/**
* UploadStash is intended to accomplish a few things:
* - enable applications to temporarily stash files without publishing them to the wiki.
* - Several parts of MediaWiki do this in similar ways: UploadBase, UploadWizard, and FirefoggChunkedExtension
@@ -46,9 +68,11 @@ class UploadStash {
/**
* Represents a temporary filestore, with metadata in the database.
- * Designed to be compatible with the session stashing code in UploadBase (should replace it eventually)
+ * Designed to be compatible with the session stashing code in UploadBase
+ * (should replace it eventually).
*
* @param $repo FileRepo
+ * @param $user User (default null)
*/
public function __construct( FileRepo $repo, $user = null ) {
// this might change based on wiki's configuration.
@@ -215,10 +239,14 @@ class UploadStash {
}
}
// at this point, $error should contain the single "most important" error, plus any parameters.
- throw new UploadStashFileException( "Error storing file in '$path': " . wfMessage( $error )->text() );
+ $errorMsg = array_shift( $error );
+ throw new UploadStashFileException( "Error storing file in '$path': " . wfMessage( $errorMsg, $error )->text() );
}
$stashPath = $storeStatus->value;
+ // we have renamed the file so we have to cleanup once done
+ unlink($path);
+
// fetch the current user ID
if ( !$this->isLoggedIn ) {
throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' );
@@ -391,6 +419,7 @@ class UploadStash {
* with an extension.
* XXX this is somewhat redundant with the checks that ApiUpload.php does with incoming
* uploads versus the desired filename. Maybe we can get that passed to us...
+ * @return string
*/
public static function getExtensionForPath( $path ) {
// Does this have an extension?
@@ -419,6 +448,7 @@ class UploadStash {
* Helper function: do the actual database query to fetch file metadata.
*
* @param $key String: key
+ * @param $readFromDB: constant (default: DB_SLAVE)
* @return boolean
*/
protected function fetchFileMetadata( $key, $readFromDB = DB_SLAVE ) {
@@ -451,7 +481,6 @@ class UploadStash {
/**
* Helper function: Initialize the UploadStashFile for a given file.
*
- * @param $path String: path to file
* @param $key String: key under which to store the object
* @throws UploadStashZeroLengthFileException
* @return bool
@@ -498,7 +527,7 @@ class UploadStashFile extends UnregisteredLocalFile {
}
// check if path exists! and is a plain file.
- if ( ! $repo->fileExists( $path, FileRepo::FILES_ONLY ) ) {
+ if ( ! $repo->fileExists( $path ) ) {
wfDebug( "UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not found\n" );
throw new UploadStashFileNotFoundException( 'cannot find path, or not a plain file' );
}
@@ -543,16 +572,17 @@ class UploadStashFile extends UnregisteredLocalFile {
* ugly file name.
*
* @param $params Array: handler-specific parameters
+ * @param $flags integer Bitfield that supports THUMB_* constants
* @return String: base name for URL, like '120px-12345.jpg', or null if there is no handler
*/
- function thumbName( $params ) {
+ function thumbName( $params, $flags = 0 ) {
return $this->generateThumbName( $this->getUrlName(), $params );
}
/**
* Helper function -- given a 'subpage', return the local URL e.g. /wiki/Special:UploadStash/subpage
- * @param {String} $subPage
- * @return {String} local URL for this subpage in the Special:UploadStash space.
+ * @param $subPage String
+ * @return String: local URL for this subpage in the Special:UploadStash space.
*/
private function getSpecialUrl( $subPage ) {
return SpecialPage::getTitleFor( 'UploadStash', $subPage )->getLocalURL();
@@ -622,7 +652,7 @@ class UploadStashFile extends UnregisteredLocalFile {
* @return Status: success
*/
public function remove() {
- if ( !$this->repo->fileExists( $this->path, FileRepo::FILES_ONLY ) ) {
+ if ( !$this->repo->fileExists( $this->path ) ) {
// Maybe the file's already been removed? This could totally happen in UploadBase.
return true;
}
@@ -631,7 +661,7 @@ class UploadStashFile extends UnregisteredLocalFile {
}
public function exists() {
- return $this->repo->fileExists( $this->path, FileRepo::FILES_ONLY );
+ return $this->repo->fileExists( $this->path );
}
}