Index: trunk/phase3/includes/upload/UploadStash.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | class UploadStash { |
19 | 19 | |
20 | 20 | // Format of the key for files -- has to be suitable as a filename itself (e.g. ab12cd34ef.jpg) |
21 | | - const KEY_FORMAT_REGEX = '/^[\w-]+\.\w*$/'; |
| 21 | + const KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/'; |
22 | 22 | |
23 | 23 | // When a given stashed file can't be loaded, wait for the slaves to catch up. If they're more than MAX_LAG |
24 | 24 | // behind, throw an exception instead. (at what point is broken better than slow?) |
— | — | @@ -184,7 +184,6 @@ |
185 | 185 | throw new UploadStashBadPathException( "path doesn't exist" ); |
186 | 186 | } |
187 | 187 | $fileProps = File::getPropsFromPath( $path ); |
188 | | - |
189 | 188 | wfDebug( __METHOD__ . " stashing file at '$path'\n" ); |
190 | 189 | |
191 | 190 | // we will be initializing from some tmpnam files that don't have extensions. |
— | — | @@ -198,10 +197,17 @@ |
199 | 198 | $path = $pathWithGoodExtension; |
200 | 199 | } |
201 | 200 | |
202 | | - // If no key was supplied, use content hash. Also has the nice property of collapsing multiple identical files |
203 | | - // uploaded this session, which could happen if uploads had failed. |
| 201 | + // If no key was supplied, make one. a mysql insertid would be totally reasonable here, except |
| 202 | + // that some users of this function might expect to supply the key instead of using the generated one. |
204 | 203 | if ( is_null( $key ) ) { |
205 | | - $key = $fileProps['sha1'] . "." . $extension; |
| 204 | + // some things that when combined will make a suitably unique key. |
| 205 | + // see: http://www.jwz.org/doc/mid.html |
| 206 | + list ($usec, $sec) = explode( ' ', microtime() ); |
| 207 | + $usec = substr($usec, 2); |
| 208 | + $key = wfBaseConvert( $sec . $usec, 10, 36 ) . '.' . |
| 209 | + wfBaseConvert( mt_rand(), 10, 36 ) . '.'. |
| 210 | + $this->userId . '.' . |
| 211 | + $extension; |
206 | 212 | } |
207 | 213 | |
208 | 214 | $this->fileProps[$key] = $fileProps; |