r104954 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104953‎ | r104954 | r104955 >
Date:05:40, 2 December 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Refactored MediaTransformOutput by removing getPath() and giving it hasFile(), fileIsSource(), and streamFile() as needed by thumb.php
* Made thumb.php account for the fact that $img->thumbName( $params ) can return null
* Replace filesize() call in doTransform() with $out->hasTransformedFile()
* Comment tweaks
Modified paths:
  • /branches/FileBackend/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/Generic.php (modified) (history)
  • /branches/FileBackend/phase3/includes/media/MediaTransformOutput.php (modified) (history)
  • /branches/FileBackend/phase3/thumb.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php
@@ -187,7 +187,7 @@
188188 * Implementations should flush the output buffer before sending data.
189189 * $params include:
190190 * src : source storage path
191 - * headers : additional headers to send on success
 191+ * headers : additional HTTP headers to send on success
192192 *
193193 * @param Array $params
194194 * @return Status
Index: branches/FileBackend/phase3/includes/filerepo/FileRepo.php
@@ -1146,7 +1146,7 @@
11471147 * Attempt to stream a file with the given virtual URL/storage path
11481148 *
11491149 * @param $virtualUrl string
1150 - * @param $headers Array Extra headers to send on success
 1150+ * @param $headers Array Additional HTTP headers to send on success
11511151 * @return bool Success
11521152 */
11531153 public function streamFile( $virtualUrl, $headers = array() ) {
Index: branches/FileBackend/phase3/includes/media/MediaTransformOutput.php
@@ -22,32 +22,25 @@
2323 /**
2424 * Get the width of the output box
2525 */
26 - function getWidth() {
 26+ public function getWidth() {
2727 return $this->width;
2828 }
2929
3030 /**
3131 * Get the height of the output box
3232 */
33 - function getHeight() {
 33+ public function getHeight() {
3434 return $this->height;
3535 }
3636
3737 /**
3838 * @return string The thumbnail URL
3939 */
40 - function getUrl() {
 40+ public function getUrl() {
4141 return $this->url;
4242 }
4343
4444 /**
45 - * @return String: destination file path (local filesystem)
46 - */
47 - function getPath() {
48 - return $this->path;
49 - }
50 -
51 - /**
5245 * Fetch HTML for this transform output
5346 *
5447 * @param $options array Associative array of options. Boolean options
@@ -67,16 +60,47 @@
6861 *
6962 * @return string
7063 */
71 - abstract function toHtml( $options = array() );
 64+ abstract public function toHtml( $options = array() );
7265
7366 /**
7467 * This will be overridden to return true in error classes
7568 */
76 - function isError() {
 69+ public function isError() {
7770 return false;
7871 }
7972
8073 /**
 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+ /**
81105 * Wrap some XHTML text in an anchor tag with the given attributes
82106 *
83107 * @param $linkAttribs array
@@ -97,7 +121,7 @@
98122 * @param $params array
99123 * @return array
100124 */
101 - function getDescLinkAttribs( $title = null, $params = '' ) {
 125+ public function getDescLinkAttribs( $title = null, $params = '' ) {
102126 $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : '';
103127 if( $params ) {
104128 $query .= $query ? '&'.$params : $params;
Index: branches/FileBackend/phase3/includes/media/Generic.php
@@ -216,7 +216,7 @@
217217 $out = $this->doFSTransform( $image, $tmpDest, $dstUrl, $params, $flags );
218218 // Copy any thumbnail from FS into storage at $dstpath
219219 // 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() ) {
221221 $op = array( 'op' => 'store',
222222 'src' => $tmpDest, 'dst' => $dstPath, 'overwriteDest' => true );
223223 if ( !$image->getRepo()->getBackend()->doOperation( $op )->isOK() ) {
Index: branches/FileBackend/phase3/thumb.php
@@ -124,7 +124,7 @@
125125 // Stream the file if it exists already...
126126 try {
127127 $thumbName = $img->thumbName( $params );
128 - if ( $thumbName !== false ) { // valid params?
 128+ if ( strlen( $thumbName ) ) { // valid params?
129129 $thumbPath = $img->getThumbPath( $thumbName );
130130 if ( $img->getRepo()->fileExists( $thumbPath ) ) {
131131 $img->getRepo()->streamFile( $thumbPath, $headers );
@@ -141,7 +141,7 @@
142142 // Thumbnail isn't already there, so create the new thumbnail...
143143 try {
144144 $thumb = $img->transform( $params, File::RENDER_NOW );
145 - } catch( Exception $ex ) {
 145+ } catch ( Exception $ex ) {
146146 // Tried to select a page on a non-paged file?
147147 $thumb = false;
148148 }
@@ -152,18 +152,18 @@
153153 $errorMsg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' );
154154 } elseif ( $thumb->isError() ) {
155155 $errorMsg = $thumb->getHtmlMsg();
156 - } elseif ( !$thumb->getPath() ) {
 156+ } elseif ( !$thumb->hasFile() ) {
157157 $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?' );
161161 }
162162
163163 if ( $errorMsg !== false ) {
164164 wfThumbError( 500, $errorMsg );
165165 } else {
166166 // Stream the file if there were no errors
167 - StreamFile::stream( $thumb->getPath(), $headers );
 167+ $thumb->streamFile( $headers );
168168 }
169169
170170 wfProfileOut( __METHOD__ );

Status & tagging log