Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -187,7 +187,7 @@ |
188 | 188 | * Implementations should flush the output buffer before sending data. |
189 | 189 | * $params include: |
190 | 190 | * src : source storage path |
191 | | - * headers : additional headers to send on success |
| 191 | + * headers : additional HTTP headers to send on success |
192 | 192 | * |
193 | 193 | * @param Array $params |
194 | 194 | * @return Status |
Index: branches/FileBackend/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -1146,7 +1146,7 @@ |
1147 | 1147 | * Attempt to stream a file with the given virtual URL/storage path |
1148 | 1148 | * |
1149 | 1149 | * @param $virtualUrl string |
1150 | | - * @param $headers Array Extra headers to send on success |
| 1150 | + * @param $headers Array Additional HTTP headers to send on success |
1151 | 1151 | * @return bool Success |
1152 | 1152 | */ |
1153 | 1153 | public function streamFile( $virtualUrl, $headers = array() ) { |
Index: branches/FileBackend/phase3/includes/media/MediaTransformOutput.php |
— | — | @@ -22,32 +22,25 @@ |
23 | 23 | /** |
24 | 24 | * Get the width of the output box |
25 | 25 | */ |
26 | | - function getWidth() { |
| 26 | + public function getWidth() { |
27 | 27 | return $this->width; |
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Get the height of the output box |
32 | 32 | */ |
33 | | - function getHeight() { |
| 33 | + public function getHeight() { |
34 | 34 | return $this->height; |
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @return string The thumbnail URL |
39 | 39 | */ |
40 | | - function getUrl() { |
| 40 | + public function getUrl() { |
41 | 41 | return $this->url; |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | | - * @return String: destination file path (local filesystem) |
46 | | - */ |
47 | | - function getPath() { |
48 | | - return $this->path; |
49 | | - } |
50 | | - |
51 | | - /** |
52 | 45 | * Fetch HTML for this transform output |
53 | 46 | * |
54 | 47 | * @param $options array Associative array of options. Boolean options |
— | — | @@ -67,16 +60,47 @@ |
68 | 61 | * |
69 | 62 | * @return string |
70 | 63 | */ |
71 | | - abstract function toHtml( $options = array() ); |
| 64 | + abstract public function toHtml( $options = array() ); |
72 | 65 | |
73 | 66 | /** |
74 | 67 | * This will be overridden to return true in error classes |
75 | 68 | */ |
76 | | - function isError() { |
| 69 | + public function isError() { |
77 | 70 | return false; |
78 | 71 | } |
79 | 72 | |
80 | 73 | /** |
| 74 | + * Check if an output thumbnail file was actually made. |
| 75 | + * This will return false if there was an error or the |
| 76 | + * thumnail is to be handled client-side only. |
| 77 | + * |
| 78 | + * @return Bool |
| 79 | + */ |
| 80 | + public function hasFile() { |
| 81 | + return ( !$this->isError() && $this->path ); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Check if the output thumbnail file is the same as the source. |
| 86 | + * This can occur if the requested width was bigger than the source. |
| 87 | + * |
| 88 | + * @return Bool |
| 89 | + */ |
| 90 | + public function fileIsSource() { |
| 91 | + return ( !$this->isError() && $this->path === $this->file->getLocalCopyPath() ); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Stream the file if there were no errors |
| 96 | + * |
| 97 | + * @param $headers Array Additional HTTP headers to send on success |
| 98 | + * @return Bool success |
| 99 | + */ |
| 100 | + public function streamFile( $headers = array() ) { |
| 101 | + return $this->path && StreamFile::stream( $this->path, $headers ); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
81 | 105 | * Wrap some XHTML text in an anchor tag with the given attributes |
82 | 106 | * |
83 | 107 | * @param $linkAttribs array |
— | — | @@ -97,7 +121,7 @@ |
98 | 122 | * @param $params array |
99 | 123 | * @return array |
100 | 124 | */ |
101 | | - function getDescLinkAttribs( $title = null, $params = '' ) { |
| 125 | + public function getDescLinkAttribs( $title = null, $params = '' ) { |
102 | 126 | $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : ''; |
103 | 127 | if( $params ) { |
104 | 128 | $query .= $query ? '&'.$params : $params; |
Index: branches/FileBackend/phase3/includes/media/Generic.php |
— | — | @@ -216,7 +216,7 @@ |
217 | 217 | $out = $this->doFSTransform( $image, $tmpDest, $dstUrl, $params, $flags ); |
218 | 218 | // Copy any thumbnail from FS into storage at $dstpath |
219 | 219 | // Note: no file is created if it's to be rendered client-side. |
220 | | - if ( !$out->isError() && filesize( $tmpDest ) ) { |
| 220 | + if ( !$out->isError() && $out->hasFile() ) { |
221 | 221 | $op = array( 'op' => 'store', |
222 | 222 | 'src' => $tmpDest, 'dst' => $dstPath, 'overwriteDest' => true ); |
223 | 223 | if ( !$image->getRepo()->getBackend()->doOperation( $op )->isOK() ) { |
Index: branches/FileBackend/phase3/thumb.php |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | // Stream the file if it exists already... |
126 | 126 | try { |
127 | 127 | $thumbName = $img->thumbName( $params ); |
128 | | - if ( $thumbName !== false ) { // valid params? |
| 128 | + if ( strlen( $thumbName ) ) { // valid params? |
129 | 129 | $thumbPath = $img->getThumbPath( $thumbName ); |
130 | 130 | if ( $img->getRepo()->fileExists( $thumbPath ) ) { |
131 | 131 | $img->getRepo()->streamFile( $thumbPath, $headers ); |
— | — | @@ -141,7 +141,7 @@ |
142 | 142 | // Thumbnail isn't already there, so create the new thumbnail... |
143 | 143 | try { |
144 | 144 | $thumb = $img->transform( $params, File::RENDER_NOW ); |
145 | | - } catch( Exception $ex ) { |
| 145 | + } catch ( Exception $ex ) { |
146 | 146 | // Tried to select a page on a non-paged file? |
147 | 147 | $thumb = false; |
148 | 148 | } |
— | — | @@ -152,18 +152,18 @@ |
153 | 153 | $errorMsg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' ); |
154 | 154 | } elseif ( $thumb->isError() ) { |
155 | 155 | $errorMsg = $thumb->getHtmlMsg(); |
156 | | - } elseif ( !$thumb->getPath() ) { |
| 156 | + } elseif ( !$thumb->hasFile() ) { |
157 | 157 | $errorMsg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' ); |
158 | | - } elseif ( $thumb->getPath() == $img->getLocalCopyPath() ) { |
159 | | - $errorMsg = wfMsgHtml( 'thumbnail_error', 'Image was not scaled, ' . |
160 | | - 'is the requested width bigger than the source?' ); |
| 158 | + } elseif ( $thumb->fileIsSource() ) { |
| 159 | + $errorMsg = wfMsgHtml( 'thumbnail_error', |
| 160 | + 'Image was not scaled, is the requested width bigger than the source?' ); |
161 | 161 | } |
162 | 162 | |
163 | 163 | if ( $errorMsg !== false ) { |
164 | 164 | wfThumbError( 500, $errorMsg ); |
165 | 165 | } else { |
166 | 166 | // Stream the file if there were no errors |
167 | | - StreamFile::stream( $thumb->getPath(), $headers ); |
| 167 | + $thumb->streamFile( $headers ); |
168 | 168 | } |
169 | 169 | |
170 | 170 | wfProfileOut( __METHOD__ ); |