Index: trunk/phase3/includes/specials/SpecialUploadStash.php |
— | — | @@ -20,12 +20,6 @@ |
21 | 21 | // UploadStash |
22 | 22 | private $stash; |
23 | 23 | |
24 | | - // is the edit request authorized? boolean |
25 | | - private $isEditAuthorized; |
26 | | - |
27 | | - // did the user request us to clear the stash? boolean |
28 | | - private $requestedClear; |
29 | | - |
30 | 24 | // Since we are directly writing the file to STDOUT, |
31 | 25 | // we should not be reading in really big files and serving them out. |
32 | 26 | // |
— | — | @@ -37,16 +31,12 @@ |
38 | 32 | const MAX_SERVE_BYTES = 262144; // 256K |
39 | 33 | |
40 | 34 | public function __construct() { |
41 | | - global $wgRequest; |
42 | | - |
43 | 35 | parent::__construct( 'UploadStash', 'upload' ); |
44 | 36 | try { |
45 | 37 | $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash(); |
46 | 38 | } catch ( UploadStashNotAvailableException $e ) { |
47 | 39 | return null; |
48 | 40 | } |
49 | | - |
50 | | - $this->loadRequest( $wgRequest ); |
51 | 41 | } |
52 | 42 | |
53 | 43 | /** |
— | — | @@ -293,24 +283,7 @@ |
294 | 284 | header( "Content-Length: $size", true ); |
295 | 285 | } |
296 | 286 | |
297 | | - |
298 | 287 | /** |
299 | | - * Initialize authorization & actions to take, from the request |
300 | | - * @param $request: WebRequest |
301 | | - */ |
302 | | - private function loadRequest( $request ) { |
303 | | - global $wgUser; |
304 | | - if ( $request->wasPosted() ) { |
305 | | - |
306 | | - $token = $request->getVal( 'wpEditToken' ); |
307 | | - $this->isEditAuthorized = $wgUser->matchEditToken( $token ); |
308 | | - |
309 | | - $this->requestedClear = $request->getBool( 'clear' ); |
310 | | - |
311 | | - } |
312 | | - } |
313 | | - |
314 | | - /** |
315 | 288 | * Static callback for the HTMLForm in showUploads, to process |
316 | 289 | * Note the stash has to be recreated since this is being called in a static context. |
317 | 290 | * This works, because there really is only one stash per logged-in user, despite appearances. |
— | — | @@ -318,9 +291,8 @@ |
319 | 292 | * @return Status |
320 | 293 | */ |
321 | 294 | public static function tryClearStashedUploads( $formData ) { |
322 | | - wfDebug( __METHOD__ . " form data : " . print_r( $formData, 1 ) ); |
323 | | - if ( isset( $formData['clear'] ) and $formData['clear'] ) { |
324 | | - $stash = new UploadStash(); |
| 295 | + if ( isset( $formData['Clear'] ) ) { |
| 296 | + $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash(); |
325 | 297 | wfDebug( "stash has: " . print_r( $stash->listFiles(), 1 ) ); |
326 | 298 | if ( ! $stash->clear() ) { |
327 | 299 | return Status::newFatal( 'uploadstash-errclear' ); |
— | — | @@ -355,29 +327,31 @@ |
356 | 328 | 'name' => 'clear', |
357 | 329 | ) |
358 | 330 | ), 'clearStashedUploads' ); |
359 | | - $form->setSubmitCallback( array( __CLASS__, 'tryClearStashedUploads' ) ); |
| 331 | + $form->setSubmitCallback( __CLASS__ . '::tryClearStashedUploads' ); |
360 | 332 | $form->setTitle( $this->getTitle() ); |
361 | | - $form->addHiddenField( 'clear', true, array( 'type' => 'boolean' ) ); |
362 | 333 | $form->setSubmitText( wfMsg( 'uploadstash-clear' ) ); |
363 | 334 | |
364 | | - $form->prepareForm(); |
365 | | - $formResult = $form->tryAuthorizedSubmit(); |
| 335 | + $form->prepareForm(); |
| 336 | + $formResult = $form->tryAuthorizedSubmit(); |
366 | 337 | |
367 | 338 | |
368 | 339 | // show the files + form, if there are any, or just say there are none |
369 | | - $refreshHtml = Html::element( 'a', array( 'href' => $this->getTitle()->getLocalURL() ), wfMsg( 'uploadstash-refresh' ) ); |
| 340 | + $refreshHtml = Html::element( 'a', |
| 341 | + array( 'href' => $this->getTitle()->getLocalURL() ), |
| 342 | + wfMsg( 'uploadstash-refresh' ) ); |
370 | 343 | $files = $this->stash->listFiles(); |
371 | 344 | if ( count( $files ) ) { |
372 | 345 | sort( $files ); |
373 | 346 | $fileListItemsHtml = ''; |
374 | 347 | foreach ( $files as $file ) { |
| 348 | + // TODO: Use Linker::link or even construct the list in plain wikitext |
375 | 349 | $fileListItemsHtml .= Html::rawElement( 'li', array(), |
376 | 350 | Html::element( 'a', array( 'href' => |
377 | 351 | $this->getTitle( "file/$file" )->getLocalURL() ), $file ) |
378 | 352 | ); |
379 | 353 | } |
380 | 354 | $wgOut->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) ); |
381 | | - $form->displayForm( $formResult ); |
| 355 | + $form->displayForm( $formResult ); |
382 | 356 | $wgOut->addHtml( Html::rawElement( 'p', array(), $refreshHtml ) ); |
383 | 357 | } else { |
384 | 358 | $wgOut->addHtml( Html::rawElement( 'p', array(), |