r81209 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81208‎ | r81209 | r81210 >
Date:16:57, 30 January 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
As per my comments on bug 27038 and my comments on r75906, use a /thumb and /file prefix for files fetched via Special:UploadStash. Make filenames more consistent with regular thumbs by using the /thumb/$fileName/$thumbName scheme. Now uses MediaHandler::parseParamString so that params like page are properly handled.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUploadStash.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadStash.php
@@ -358,7 +358,7 @@
359359 */
360360 public function getThumbUrl( $thumbName = false ) {
361361 wfDebug( __METHOD__ . " getting for $thumbName \n" );
362 - return $this->getSpecialUrl( $thumbName );
 362+ return $this->getSpecialUrl( 'thumb/' . $this->getUrlName() . '/' . $thumbName );
363363 }
364364
365365 /**
@@ -382,7 +382,7 @@
383383 */
384384 public function getUrl() {
385385 if ( !isset( $this->url ) ) {
386 - $this->url = $this->getSpecialUrl( $this->getUrlName() );
 386+ $this->url = $this->getSpecialUrl( 'file/' . $this->getUrlName() );
387387 }
388388 return $this->url;
389389 }
Index: trunk/phase3/includes/specials/SpecialUploadStash.php
@@ -84,11 +84,11 @@
8585 $wgOut->disable();
8686
8787 try {
88 - if ( preg_match( '/^(\d+)px-(.*)$/', $key, $matches ) ) {
89 - list( /* full match */, $width, $key ) = $matches;
90 - return $this->outputThumbFromStash( $key, $width );
 88+ $params = $this->parseKey( $key );
 89+ if ( $params['type'] === 'thumb' ) {
 90+ return $this->outputThumbFromStash( $params['file'], $params['params'] );
9191 } else {
92 - return $this->outputFileFromStash( $key );
 92+ return $this->outputLocalFile( $params['file'] );
9393 }
9494 } catch( UploadStashFileNotFoundException $e ) {
9595 $code = 404;
@@ -110,43 +110,64 @@
111111 wfHttpError( $code, OutputPage::getStatusMessage( $code ), $message );
112112 return false;
113113 }
114 -
 114+
115115 /**
116 - * Get a file from stash and stream it out. Rely on parent to catch exceptions and transform them into HTTP
117 - * @param String: $key - key of this file in the stash, which probably looks like a filename with extension.
118 - * @return boolean
 116+ * Parse the key passed to the SpecialPage. Returns an array containing
 117+ * the associated file object, the type ('file' or 'thumb') and if
 118+ * application the transform parameters
 119+ *
 120+ * @param string $key
 121+ * @return array
119122 */
120 - private function outputFileFromStash( $key ) {
121 - $file = $this->stash->getFile( $key );
122 - return $this->outputLocalFile( $file );
 123+ private function parseKey( $key ) {
 124+ $type = strtok( $key, '/' );
 125+
 126+ if ( $type !== 'file' && $type !== 'thumb' ) {
 127+ throw new UploadStashBadPathException( "Unknown type '$type'" );
 128+ }
 129+ $fileName = strtok( '/' );
 130+ $thumbPart = strtok( '/' );
 131+ $file = $this->stash->getFile( $fileName );
 132+ if ( $type === 'thumb' ) {
 133+
 134+ $parts = explode( "-{$fileName}", $thumbPart );
 135+
 136+ if ( count( $parts ) != 2 || $parts[1] !== '' ) {
 137+ throw new UploadStashBadPathException( 'Invalid suffix' );
 138+ }
 139+
 140+
 141+ $handler = $file->getHandler();
 142+ $params = $handler->parseParamString( $parts[0] );
 143+ return array( 'file' => $file, 'type' => $type, 'params' => $params );
 144+ }
 145+
 146+ return array( 'file' => $file, 'type' => $type );
123147 }
 148+
124149
125150
 151+
126152 /**
127153 * Get a thumbnail for file, either generated locally or remotely, and stream it out
128154 * @param String $key: key for the file in the stash
129155 * @param int $width: width of desired thumbnail
130156 * @return boolean success
131157 */
132 - private function outputThumbFromStash( $key, $width ) {
 158+ private function outputThumbFromStash( $file, $params ) {
133159
134160 // this global, if it exists, points to a "scaler", as you might find in the Wikimedia Foundation cluster. See outputRemoteScaledThumb()
135161 // this is part of our horrible NFS-based system, we create a file on a mount point here, but fetch the scaled file from somewhere else that
136162 // happens to share it over NFS
137163 global $wgUploadStashScalerBaseUrl;
138164
139 - // let exceptions propagate to caller.
140 - $file = $this->stash->getFile( $key );
141 -
142 - // OK, we're here and no exception was thrown,
143 - // so the original file must exist.
144 -
145 - // let's get ready to transform the original -- these are standard
146 - $params = array( 'width' => $width );
147165 $flags = 0;
 166+ if ( $wgUploadStashScalerBaseUrl ) {
 167+ $this->outputRemoteScaledThumb( $file, $params, $flags );
 168+ } else {
 169+ $this->outputLocallyScaledThumb( $file, $params, $flags );
 170+ }
148171
149 - return $wgUploadStashScalerBaseUrl ? $this->outputRemoteScaledThumb( $file, $params, $flags )
150 - : $this->outputLocallyScaledThumb( $file, $params, $flags );
151172
152173 }
153174
@@ -353,7 +374,8 @@
354375 $fileListItemsHtml = '';
355376 foreach ( $files as $file ) {
356377 $fileListItemsHtml .= Html::rawElement( 'li', array(),
357 - Html::element( 'a', array( 'href' => $this->getTitle( $file )->getLocalURL() ), $file )
 378+ Html::element( 'a', array( 'href' =>
 379+ $this->getTitle( "file/$file" )->getLocalURL() ), $file )
358380 );
359381 }
360382 $wgOut->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r81262Follow-up r81209: Use the same param detection method as WebStore, so that th...btongminh18:07, 31 January 2011
r814111.17: MFT r81186, r81187, r81197, r81209, r81210, r81211, r81215, r81238, r81...catrope20:23, 2 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r75906core changes for UploadWizard (merged from r73549 to HEAD in branches/uploadw...neilk04:32, 3 November 2010

Comments

#Comment by Bawolff (talk | contribs)   19:49, 30 January 2011

UploadStash::getThumbUrl returns url's with two extensions like:

http://localhost/w/phase3/index.php/Special:UploadStash/thumb/012.pdf/page3-100px-012.pdf.jpg

when the thumb's mimetype is different from the original file's mimetype. However, UploadStash::parseKey seems to want urls like:

http://localhost/w/phase3/index.php/Special:UploadStash/thumb/012.pdf/page3-100px-012.pdf

with just the original extension.

#Comment by Bryan (talk | contribs)   18:08, 31 January 2011

Fixed in r81262.

#Comment by Bawolff (talk | contribs)   03:53, 1 February 2011

The test i was doing now works. As an aside, urls like http://localhost/w/phase3/index.php/Special:UploadStash/thumb/012.pdf/page5-100px-012.pdf.exe now work, but I assume that is not an issue because we do all that fancy IEContentAnalyzer stuff.

#Comment by Bryan (talk | contribs)   09:19, 1 February 2011

That also works for normal thumbs.

Status & tagging log