r104872 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104871‎ | r104872 | r104873 >
Date:16:48, 1 December 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Update thumb.php to work with storage paths and added FileRepo::streamFile()
* Added 'headers' option to FileBackend::streamFile()
* Doc comments
Modified paths:
  • /branches/FileBackend/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php (modified) (history)
  • /branches/FileBackend/phase3/thumb.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php
@@ -635,7 +635,7 @@
636636 /**
637637 * Combines files from severals storage paths into a new file in the backend.
638638 * Parameters similar to FileBackend::concatenate(), which include:
639 - * sources : ordered source storage paths (e.g. chunk1,chunk2,...)
 639+ * sources : ordered source storage paths (e.g. chunk1, chunk2, ...)
640640 * dst : destination storage path
641641 * overwriteDest : do nothing and pass if an identical file exists at destination
642642 */
Index: branches/FileBackend/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -427,7 +427,10 @@
428428 return $status;
429429 }
430430
431 - $ok = StreamFile::stream( $source, array(), false );
 431+ $extraHeaders = isset( $params['headers'] )
 432+ ? $params['headers']
 433+ : array();
 434+ $ok = StreamFile::stream( $source, $extraHeaders, false );
432435 if ( !$ok ) {
433436 $status->fatal( 'backend-fail-stream', $params['src'] );
434437 return $status;
Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php
@@ -186,7 +186,8 @@
187187 * must be sent if streaming began, while none should be sent otherwise.
188188 * Implementations should flush the output buffer before sending data.
189189 * $params include:
190 - * src : source storage path
 190+ * src : source storage path
 191+ * headers : additional headers to send on success
191192 *
192193 * @param Array $params
193194 * @return Status
@@ -306,7 +307,7 @@
307308 * Combines files from severals storage paths into a new file in the backend.
308309 * Do not call this function from places outside FileBackend and FileOp.
309310 * $params include:
310 - * src : source storage path
 311+ * sources : ordered source storage paths (e.g. chunk1, chunk2, ...)
311312 * dst : destination storage path
312313 * overwriteDest : do nothing and pass if an identical file exists at destination
313314 *
Index: branches/FileBackend/phase3/includes/filerepo/FileRepo.php
@@ -1081,6 +1081,7 @@
10821082 * If a path is a virtual URL, resolve it to a storage path.
10831083 * Otherwise, just return the path as it is.
10841084 *
 1085+ * @param $path string
10851086 * @return string
10861087 * @throws MWException
10871088 */
@@ -1095,6 +1096,7 @@
10961097 * Get a local FS copy of a file with a given virtual URL/storage path.
10971098 * Returns null on failure.
10981099 *
 1100+ * @param $virtualUrl string
10991101 * @return TempFSFile|null
11001102 */
11011103 public function getLocalCopy( $virtualUrl ) {
@@ -1117,7 +1119,7 @@
11181120 /**
11191121 * Get the timestamp of a file with a given virtual URL/storage path
11201122 *
1121 - * @param $virtualUrl
 1123+ * @param $virtualUrl string
11221124 * @return string|false
11231125 */
11241126 public function getFileTimestamp( $virtualUrl ) {
@@ -1128,7 +1130,7 @@
11291131 /**
11301132 * Get the sha1 of a file with a given virtual URL/storage path
11311133 *
1132 - * @param $virtualUrl
 1134+ * @param $virtualUrl string
11331135 * @return string|false
11341136 */
11351137 public function getFileSha1( $virtualUrl ) {
@@ -1141,6 +1143,19 @@
11421144 }
11431145
11441146 /**
 1147+ * Attempt to stream a file with the given virtual URL/storage path
 1148+ *
 1149+ * @param $virtualUrl string
 1150+ * @param $headers Array Extra headers to send on success
 1151+ * @return bool Success
 1152+ */
 1153+ public function streamFile( $virtualUrl, $headers = array() ) {
 1154+ $path = $this->resolveToStoragePath( $virtualUrl );
 1155+ $params = array( 'src' => $path, 'headers' => $headers );
 1156+ return $this->backend->streamFile( $params )->isOK();
 1157+ }
 1158+
 1159+ /**
11451160 * Call a callback function for every public file in the repository.
11461161 * May use either the database or the filesystem.
11471162 *
Index: branches/FileBackend/phase3/thumb.php
@@ -111,9 +111,9 @@
112112 // Calculate time
113113 wfSuppressWarnings();
114114 $imsUnix = strtotime( $imsString );
115 - $stat = stat( $sourcePath );
116115 wfRestoreWarnings();
117 - if ( $stat['mtime'] <= $imsUnix ) {
 116+ $sourceTsUnix = wfTimestamp( TS_UNIX, $img->getTimestamp() );
 117+ if ( $sourceTsUnix <= $imsUnix ) {
118118 header( 'HTTP/1.1 304 Not Modified' );
119119 wfProfileOut( __METHOD__ );
120120 return;
@@ -125,8 +125,8 @@
126126 $thumbName = $img->thumbName( $params );
127127 if ( $thumbName !== false ) { // valid params?
128128 $thumbPath = $img->getThumbPath( $thumbName );
129 - if ( is_file( $thumbPath ) ) {
130 - StreamFile::stream( $thumbPath, $headers );
 129+ if ( $img->getRepo()->fileExists( $thumbPath ) ) {
 130+ $img->getRepo()->streamFile( $thumbPath, $headers );
131131 wfProfileOut( __METHOD__ );
132132 return;
133133 }
@@ -153,7 +153,7 @@
154154 $errorMsg = $thumb->getHtmlMsg();
155155 } elseif ( !$thumb->getPath() ) {
156156 $errorMsg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' );
157 - } elseif ( $thumb->getPath() == $img->getPath() ) {
 157+ } elseif ( $thumb->getPath() == $img->getLocalCopyPath() ) {
158158 $errorMsg = wfMsgHtml( 'thumbnail_error', 'Image was not scaled, ' .
159159 'is the requested width bigger than the source?' );
160160 }

Status & tagging log