Index: trunk/phase3/includes/upload/UploadStash.php |
— | — | @@ -358,7 +358,7 @@ |
359 | 359 | */ |
360 | 360 | public function getThumbUrl( $thumbName = false ) { |
361 | 361 | wfDebug( __METHOD__ . " getting for $thumbName \n" ); |
362 | | - return $this->getSpecialUrl( $thumbName ); |
| 362 | + return $this->getSpecialUrl( 'thumb/' . $this->getUrlName() . '/' . $thumbName ); |
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
— | — | @@ -382,7 +382,7 @@ |
383 | 383 | */ |
384 | 384 | public function getUrl() { |
385 | 385 | if ( !isset( $this->url ) ) { |
386 | | - $this->url = $this->getSpecialUrl( $this->getUrlName() ); |
| 386 | + $this->url = $this->getSpecialUrl( 'file/' . $this->getUrlName() ); |
387 | 387 | } |
388 | 388 | return $this->url; |
389 | 389 | } |
Index: trunk/phase3/includes/specials/SpecialUploadStash.php |
— | — | @@ -84,11 +84,11 @@ |
85 | 85 | $wgOut->disable(); |
86 | 86 | |
87 | 87 | 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'] ); |
91 | 91 | } else { |
92 | | - return $this->outputFileFromStash( $key ); |
| 92 | + return $this->outputLocalFile( $params['file'] ); |
93 | 93 | } |
94 | 94 | } catch( UploadStashFileNotFoundException $e ) { |
95 | 95 | $code = 404; |
— | — | @@ -110,43 +110,64 @@ |
111 | 111 | wfHttpError( $code, OutputPage::getStatusMessage( $code ), $message ); |
112 | 112 | return false; |
113 | 113 | } |
114 | | - |
| 114 | + |
115 | 115 | /** |
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 |
119 | 122 | */ |
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 ); |
123 | 147 | } |
| 148 | + |
124 | 149 | |
125 | 150 | |
| 151 | + |
126 | 152 | /** |
127 | 153 | * Get a thumbnail for file, either generated locally or remotely, and stream it out |
128 | 154 | * @param String $key: key for the file in the stash |
129 | 155 | * @param int $width: width of desired thumbnail |
130 | 156 | * @return boolean success |
131 | 157 | */ |
132 | | - private function outputThumbFromStash( $key, $width ) { |
| 158 | + private function outputThumbFromStash( $file, $params ) { |
133 | 159 | |
134 | 160 | // this global, if it exists, points to a "scaler", as you might find in the Wikimedia Foundation cluster. See outputRemoteScaledThumb() |
135 | 161 | // 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 |
136 | 162 | // happens to share it over NFS |
137 | 163 | global $wgUploadStashScalerBaseUrl; |
138 | 164 | |
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 ); |
147 | 165 | $flags = 0; |
| 166 | + if ( $wgUploadStashScalerBaseUrl ) { |
| 167 | + $this->outputRemoteScaledThumb( $file, $params, $flags ); |
| 168 | + } else { |
| 169 | + $this->outputLocallyScaledThumb( $file, $params, $flags ); |
| 170 | + } |
148 | 171 | |
149 | | - return $wgUploadStashScalerBaseUrl ? $this->outputRemoteScaledThumb( $file, $params, $flags ) |
150 | | - : $this->outputLocallyScaledThumb( $file, $params, $flags ); |
151 | 172 | |
152 | 173 | } |
153 | 174 | |
— | — | @@ -353,7 +374,8 @@ |
354 | 375 | $fileListItemsHtml = ''; |
355 | 376 | foreach ( $files as $file ) { |
356 | 377 | $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 ) |
358 | 380 | ); |
359 | 381 | } |
360 | 382 | $wgOut->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) ); |