Index: branches/uploadwizard/extensions/UploadWizard/UploadWizardMessages.php |
— | — | @@ -49,7 +49,8 @@ |
50 | 50 | $messagesForJs[ $key ] = wfMsgGetKey( $key, /*DB*/true, $language, /*Transform*/false ); |
51 | 51 | } |
52 | 52 | |
53 | | - $messagesJson = FormatJson::encode( $messagesForJs ); |
| 53 | + $json = new Services_JSON(); |
| 54 | + $messagesJson = $json->encode( $messagesForJs ); |
54 | 55 | return 'mw.addMessages(' . $messagesJson . ');'; |
55 | 56 | } |
56 | 57 | |
— | — | @@ -68,3 +69,5 @@ |
69 | 70 | } |
70 | 71 | |
71 | 72 | } |
| 73 | + |
| 74 | +?> |
Index: branches/uploadwizard/extensions/UploadWizard/SessionStash.php |
— | — | @@ -1,14 +1,4 @@ |
2 | 2 | <?php |
3 | | -/** |
4 | | - * SessionStash is intended to accomplish a few things: |
5 | | - * - enable applications to temporarily stash files without publishing them to the wiki. |
6 | | - * - Several parts of MediaWiki do this in similar ways: UploadBase, UploadWizard, and FirefoggChunkedExtension |
7 | | - * the idea is to unify them all here |
8 | | - * - enable applications to find said files later, as long as the session or temp files haven't been purged. |
9 | | - * - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL. |
10 | | - * We accomplish this by making the session serve as a URL->file mapping, on the assumption that nobody else can access |
11 | | - * the session, even the uploading user. |
12 | | - */ |
13 | 3 | |
14 | 4 | class SessionStash { |
15 | 5 | // repository that this uses to store temp files |
— | — | @@ -17,12 +7,9 @@ |
18 | 8 | // array of initialized objects obtained from session (lazily initialized upon getFile()) |
19 | 9 | private $files = array(); |
20 | 10 | |
21 | | - // the base URL for files in the stash |
22 | | - private $baseUrl; |
23 | | - |
24 | | - // TODO: Once UploadBase starts using this, switch to use these constants rather than UploadBase::SESSION* |
25 | | - // const SESSION_VERSION = 2; |
26 | | - // const SESSION_KEYNAME = 'wsUploadData'; |
| 11 | + const SESSION_VERSION = 2; |
| 12 | + const SESSION_KEYNAME = 'wsUploadData'; |
| 13 | + const SESSION_THUMB_KEYNAME = 'wsUploadDataThumb'; |
27 | 14 | |
28 | 15 | /** |
29 | 16 | * Represents the session which contain temporarily stored files. |
— | — | @@ -40,15 +27,14 @@ |
41 | 28 | throw new MWException( 'session not available' ); |
42 | 29 | } |
43 | 30 | |
44 | | - if ( ! array_key_exists( UploadBase::SESSION_KEYNAME, $_SESSION ) ) { |
45 | | - $_SESSION[UploadBase::SESSION_KEYNAME] = array(); |
| 31 | + if ( ! array_key_exists( self::SESSION_KEYNAME, $_SESSION ) ) { |
| 32 | + $_SESSION[self::SESSION_KEYNAME] = array(); |
46 | 33 | } |
47 | | - |
48 | | - $this->baseUrl = SpecialPage::getTitleFor( 'SessionStash' )->getLocalURL(); |
49 | 34 | } |
50 | 35 | |
51 | 36 | public function getBaseUrl() { |
52 | | - return $this->baseUrl; |
| 37 | + // XXX do this better |
| 38 | + return '/wiki/Special:SessionStash'; |
53 | 39 | } |
54 | 40 | |
55 | 41 | /** |
— | — | @@ -59,9 +45,9 @@ |
60 | 46 | */ |
61 | 47 | public function getFile( $key ) { |
62 | 48 | if ( !array_key_exists( $key, $this->files ) ) { |
63 | | - $stashData = $_SESSION[UploadBase::SESSION_KEYNAME][$key]; |
| 49 | + $stashData = $_SESSION[self::SESSION_KEYNAME][$key]; |
64 | 50 | |
65 | | - if ($stashData['version'] !== UploadBase::SESSION_VERSION ) { |
| 51 | + if ($stashData['version'] !== self::SESSION_VERSION ) { |
66 | 52 | throw new MWException( 'session item schema does not match current software' ); |
67 | 53 | } |
68 | 54 | |
— | — | @@ -110,7 +96,7 @@ |
111 | 97 | 'mTempPath' => $stashPath, |
112 | 98 | 'mFileSize' => $fileSize, |
113 | 99 | 'mFileProps' => $fileProps, |
114 | | - 'version' => UploadBase::SESSION_VERSION |
| 100 | + 'version' => self::SESSION_VERSION |
115 | 101 | ); |
116 | 102 | |
117 | 103 | // put extended info into the session (this changes from application to application). |
— | — | @@ -121,7 +107,7 @@ |
122 | 108 | } |
123 | 109 | } |
124 | 110 | |
125 | | - $_SESSION[UploadBase::SESSION_KEYNAME][$key] = $stashData; |
| 111 | + $_SESSION[self::SESSION_KEYNAME][$key] = $stashData; |
126 | 112 | |
127 | 113 | wfDebug( "SESSION\n=====\n " . print_r( $_SESSION, 1 ) . "\n" ); |
128 | 114 | |
— | — | @@ -170,9 +156,6 @@ |
171 | 157 | * Find or guess extension -- ensuring that our extension matches our mime type. |
172 | 158 | * Since these files are constructed from php tempnames they may not start off |
173 | 159 | * with an extension |
174 | | - * This does not override getExtension because things like getMimeType already call getExtension, |
175 | | - * and that results in infinite recursion. So, we preemptively *set* the extension so getExtension can find it. |
176 | | - * For obvious reasons this should be called as early as possible, as part of initialization |
177 | 160 | */ |
178 | 161 | public function setExtension() { |
179 | 162 | // Does this have an extension? |
— | — | @@ -196,7 +179,7 @@ |
197 | 180 | throw 'cannot determine extension'; |
198 | 181 | } |
199 | 182 | |
200 | | - $this->extension = parent::normalizeExtension( $extension ); |
| 183 | + return parent::normalizeExtension( $extension ); |
201 | 184 | } |
202 | 185 | |
203 | 186 | /** |
— | — | @@ -205,7 +188,7 @@ |
206 | 189 | * buggy code elsewhere that expects a boolean 'suffix' |
207 | 190 | * |
208 | 191 | * @param {String|false} name of thumbnail (e.g. "120px-123456.jpg" ), or false to just get the path |
209 | | - * @return {String} path thumbnail should take on filesystem, or containing directory if thumbname is false |
| 192 | + * @param {String} path thumbnail should take on filesystem, or containing directory if thumbname is false |
210 | 193 | */ |
211 | 194 | public function getThumbPath( $thumbName=false ) { |
212 | 195 | $path = dirname( $this->path ); |
— | — | @@ -268,7 +251,6 @@ |
269 | 252 | /** |
270 | 253 | * Return the URL of the file, if for some reason we wanted to download it |
271 | 254 | * We tend not to do this for the original file, but we do want thumb icons |
272 | | - * @return {String} url |
273 | 255 | */ |
274 | 256 | public function getUrl() { |
275 | 257 | if ( !isset( $this->url ) ) { |
— | — | @@ -286,7 +268,7 @@ |
287 | 269 | public function transform( $params, $flags=0 ) { |
288 | 270 | |
289 | 271 | // force it to get a thumbnail right away |
290 | | - $flags |= self::RENDER_NOW; |
| 272 | + $flags &= self::RENDER_NOW; |
291 | 273 | |
292 | 274 | // returns a ThumbnailImage object containing the url and path. Note. NOT A FILE OBJECT. |
293 | 275 | $thumb = parent::transform( $params, $flags ); |
— | — | @@ -300,10 +282,12 @@ |
301 | 283 | } |
302 | 284 | |
303 | 285 | $stashedThumbFile = $this->sessionStash->stashFile( $key, $thumb->path ); |
304 | | - $thumb->url = $stashedThumbFile->getUrl(); |
| 286 | + $thumb->url = $this->sessionStash->getBaseUrl() . '/' . $key . "." . $stashedThumbFile->extension; |
305 | 287 | |
306 | 288 | return $thumb; |
307 | 289 | |
308 | 290 | } |
309 | 291 | |
310 | 292 | } |
| 293 | + |
| 294 | +?> |