r81401 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81400‎ | r81401 | r81402 >
Date:16:07, 2 February 2011
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
Cleanup SpecialUploadStash

Follow-up r78426:
* Fix clearing the stash; The data array passed has as keys the keys passed used in the descriptor, not the HTML input name
* Transform array( __CLASS__, $fname ) to __CLASS__ . "::$fname", because not all PHP version support the first
* Remove addHiddenField; not needed
* Fix indentation
* Kill loadRequest all together; all this stuff is handled by HTMLForm
Follow-up r80993: Use LocalRepo to create the UploadStash
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUploadStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUploadStash.php
@@ -20,12 +20,6 @@
2121 // UploadStash
2222 private $stash;
2323
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 -
3024 // Since we are directly writing the file to STDOUT,
3125 // we should not be reading in really big files and serving them out.
3226 //
@@ -37,16 +31,12 @@
3832 const MAX_SERVE_BYTES = 262144; // 256K
3933
4034 public function __construct() {
41 - global $wgRequest;
42 -
4335 parent::__construct( 'UploadStash', 'upload' );
4436 try {
4537 $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
4638 } catch ( UploadStashNotAvailableException $e ) {
4739 return null;
4840 }
49 -
50 - $this->loadRequest( $wgRequest );
5141 }
5242
5343 /**
@@ -293,24 +283,7 @@
294284 header( "Content-Length: $size", true );
295285 }
296286
297 -
298287 /**
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 - /**
315288 * Static callback for the HTMLForm in showUploads, to process
316289 * Note the stash has to be recreated since this is being called in a static context.
317290 * This works, because there really is only one stash per logged-in user, despite appearances.
@@ -318,9 +291,8 @@
319292 * @return Status
320293 */
321294 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();
325297 wfDebug( "stash has: " . print_r( $stash->listFiles(), 1 ) );
326298 if ( ! $stash->clear() ) {
327299 return Status::newFatal( 'uploadstash-errclear' );
@@ -355,29 +327,31 @@
356328 'name' => 'clear',
357329 )
358330 ), 'clearStashedUploads' );
359 - $form->setSubmitCallback( array( __CLASS__, 'tryClearStashedUploads' ) );
 331+ $form->setSubmitCallback( __CLASS__ . '::tryClearStashedUploads' );
360332 $form->setTitle( $this->getTitle() );
361 - $form->addHiddenField( 'clear', true, array( 'type' => 'boolean' ) );
362333 $form->setSubmitText( wfMsg( 'uploadstash-clear' ) );
363334
364 - $form->prepareForm();
365 - $formResult = $form->tryAuthorizedSubmit();
 335+ $form->prepareForm();
 336+ $formResult = $form->tryAuthorizedSubmit();
366337
367338
368339 // 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' ) );
370343 $files = $this->stash->listFiles();
371344 if ( count( $files ) ) {
372345 sort( $files );
373346 $fileListItemsHtml = '';
374347 foreach ( $files as $file ) {
 348+ // TODO: Use Linker::link or even construct the list in plain wikitext
375349 $fileListItemsHtml .= Html::rawElement( 'li', array(),
376350 Html::element( 'a', array( 'href' =>
377351 $this->getTitle( "file/$file" )->getLocalURL() ), $file )
378352 );
379353 }
380354 $wgOut->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) );
381 - $form->displayForm( $formResult );
 355+ $form->displayForm( $formResult );
382356 $wgOut->addHtml( Html::rawElement( 'p', array(), $refreshHtml ) );
383357 } else {
384358 $wgOut->addHtml( Html::rawElement( 'p', array(),

Follow-up revisions

RevisionCommit summaryAuthorDate
r81638Follow-up r81401: fix callback, apparently it was the other way around than I...btongminh18:13, 7 February 2011
r850001.17wmf1: MFT changes for UploadWizard deployment: r78426, r81393, r81401, r8...catrope08:20, 30 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78426added a page to list all stashed files, and clear them if necessary -- helpfu...neilk01:21, 15 December 2010
r80993Make the UploadStash repo specific by creating FileRepo::getUploadStash(). In...btongminh21:26, 25 January 2011

Comments

#Comment by Catrope (talk | contribs)   16:20, 2 February 2011

Untag 1.17, this depends on previous UploadStash changes that aren't tagged 1.17.

#Comment by Nikerabbit (talk | contribs)   09:08, 3 February 2011

From the PHP docs:

call_user_func(array($classname, 'say_hello'));
call_user_func($classname .'::say_hello'); // As of 5.2.3
#Comment by Bryan (talk | contribs)   09:22, 3 February 2011

Thanks, I always thought that it was the other way around.

Status & tagging log