r85000 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84999‎ | r85000 | r85001 >
Date:08:20, 30 March 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT changes for UploadWizard deployment: r78426, r81393, r81401, r81638, r84731, r84761, r84762
Modified paths:
  • /branches/wmf/1.17wmf1/includes/api/ApiUpload.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/specials/SpecialUpload.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/specials/SpecialUploadStash.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/upload/UploadBase.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/upload/UploadFromUrl.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/upload/UploadStash.php (modified) (history)
  • /branches/wmf/1.17wmf1/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/languages/messages/MessagesEn.php
@@ -2185,6 +2185,15 @@
21862186 'upload-unknown-size' => 'Unknown size',
21872187 'upload-http-error' => 'An HTTP error occured: $1',
21882188
 2189+# Special:UploadStash
 2190+'uploadstash' => 'Upload stash',
 2191+'uploadstash-summary' => 'This page provides access to files which are uploaded (or in the process of uploading) but are not yet published to the wiki. These files are not visible to anyone but the user who uploaded them. See the documentation for the upload API.',
 2192+'uploadstash-clear' => 'Clear stashed files',
 2193+'uploadstash-nofiles' => 'You have no stashed files.',
 2194+'uploadstash-badtoken' => 'We could not perform that action, perhaps because your editing credentials expired. Try again.',
 2195+'uploadstash-errclear' => 'We could not clear the files.',
 2196+'uploadstash-refresh' => 'Refresh the list of files',
 2197+
21892198 # img_auth script messages
21902199 'img-auth-accessdenied' => 'Access denied',
21912200 'img-auth-nopathinfo' => 'Missing PATH_INFO.
Index: branches/wmf/1.17wmf1/includes/specials/SpecialUpload.php
@@ -445,7 +445,7 @@
446446 }
447447
448448 // Verify permissions for this title
449 - $permErrors = $this->mUpload->verifyPermissions( $wgUser );
 449+ $permErrors = $this->mUpload->verifyTitlePermissions( $wgUser );
450450 if( $permErrors !== true ) {
451451 $code = array_shift( $permErrors[0] );
452452 $this->showRecoverableUploadError( wfMsgExt( $code,
Property changes on: branches/wmf/1.17wmf1/includes/specials/SpecialUpload.php
___________________________________________________________________
Modified: svn:mergeinfo
453453 Merged /trunk/phase3/includes/specials/SpecialUpload.php:r78426,84731,84761-84762
Index: branches/wmf/1.17wmf1/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 //
@@ -34,19 +28,15 @@
3529 //
3630 // This service is really for thumbnails and other such previews while
3731 // uploading.
38 - const MAX_SERVE_BYTES = 262144; // 256K
 32+ const MAX_SERVE_BYTES = 1048576; // 1MB
3933
40 - public function __construct( $request = null ) {
41 - global $wgRequest;
42 -
 34+ public function __construct() {
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( is_null( $request ) ? $wgRequest : $request );
5141 }
5242
5343 /**
@@ -110,7 +100,7 @@
111101 wfHttpError( $code, OutputPage::getStatusMessage( $code ), $message );
112102 return false;
113103 }
114 -
 104+
115105 /**
116106 * Parse the key passed to the SpecialPage. Returns an array containing
117107 * the associated file object, the type ('file' or 'thumb') and if
@@ -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( array( __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(),
Property changes on: branches/wmf/1.17wmf1/includes/specials/SpecialUploadStash.php
___________________________________________________________________
Modified: svn:mergeinfo
385359 Merged /trunk/phase3/includes/specials/SpecialUploadStash.php:r78426,81393,81401,81638,84731,84761-84762
Index: branches/wmf/1.17wmf1/includes/api/ApiUpload.php
@@ -77,11 +77,15 @@
7878 // Check if the uploaded file is sane
7979 $this->verifyUpload();
8080
81 - // Check permission to upload this file
82 - $permErrors = $this->mUpload->verifyPermissions( $wgUser );
83 - if ( $permErrors !== true ) {
84 - // TODO: stash the upload and allow choosing a new name
85 - $this->dieUsageMsg( array( 'badaccess-groups' ) );
 81+ // Check if the user has the rights to modify or overwrite the requested title
 82+ // (This check is irrelevant if stashing is already requested, since the errors
 83+ // can always be fixed by changing the title)
 84+ if ( ! $this->mParams['stash'] ) {
 85+ $permErrors = $this->mUpload->verifyTitlePermissions( $wgUser );
 86+ if ( $permErrors !== true ) {
 87+ // TODO: stash the upload and allow choosing a new name
 88+ $this->dieUsageMsg( array( 'badaccess-groups' ) );
 89+ }
8690 }
8791
8892 // Prepare the API result
Property changes on: branches/wmf/1.17wmf1/includes/api/ApiUpload.php
___________________________________________________________________
Modified: svn:mergeinfo
8993 Merged /trunk/phase3/includes/api/ApiUpload.php:r78426,84731,84761-84762
Index: branches/wmf/1.17wmf1/includes/upload/UploadBase.php
@@ -25,7 +25,7 @@
2626 const EMPTY_FILE = 3;
2727 const MIN_LENGTH_PARTNAME = 4;
2828 const ILLEGAL_FILENAME = 5;
29 - const OVERWRITE_EXISTING_FILE = 7; # Not used anymore; handled by verifyPermissions()
 29+ const OVERWRITE_EXISTING_FILE = 7; # Not used anymore; handled by verifyTitlePermissions()
3030 const FILETYPE_MISSING = 8;
3131 const FILETYPE_BADTYPE = 9;
3232 const VERIFICATION_ERROR = 10;
@@ -381,6 +381,17 @@
382382 }
383383
384384 /**
 385+ * Alias for verifyTitlePermissions. The function was originally 'verifyPermissions'
 386+ * but that suggests it's checking the user, when it's really checking the title + user combination.
 387+ * @param $user User object to verify the permissions against
 388+ * @return mixed An array as returned by getUserPermissionsErrors or true
 389+ * in case the user has proper permissions.
 390+ */
 391+ public function verifyPermissions( $user ) {
 392+ return $this->verifyTitlePermissions( $user );
 393+ }
 394+
 395+ /**
385396 * Check whether the user can edit, upload and create the image. This
386397 * checks only against the current title; if it returns errors, it may
387398 * very well be that another title will not give errors. Therefore
@@ -391,7 +402,7 @@
392403 * @return mixed An array as returned by getUserPermissionsErrors or true
393404 * in case the user has proper permissions.
394405 */
395 - public function verifyPermissions( $user ) {
 406+ public function verifyTitlePermissions( $user ) {
396407 /**
397408 * If the image is protected, non-sysop users won't be able
398409 * to modify it by uploading a new revision.
Property changes on: branches/wmf/1.17wmf1/includes/upload/UploadBase.php
___________________________________________________________________
Modified: svn:mergeinfo
399410 Merged /trunk/phase3/includes/upload/UploadBase.php:r78426,84731,84761-84762
Index: branches/wmf/1.17wmf1/includes/upload/UploadStash.php
@@ -30,13 +30,11 @@
3131 /**
3232 * Represents the session which contains temporarily stored files.
3333 * Designed to be compatible with the session stashing code in UploadBase (should replace it eventually)
34 - *
35 - * @param $repo FileRepo: optional -- repo in which to store files. Will choose LocalRepo if not supplied.
3634 */
37 - public function __construct( $repo ) {
 35+ public function __construct() {
3836
3937 // this might change based on wiki's configuration.
40 - $this->repo = $repo;
 38+ $this->repo = RepoGroup::singleton()->getLocalRepo();
4139
4240 if ( ! isset( $_SESSION ) ) {
4341 throw new UploadStashNotAvailableException( 'no session variable' );
@@ -48,6 +46,7 @@
4947
5048 }
5149
 50+
5251 /**
5352 * Get a file and its metadata from the stash.
5453 * May throw exception if session data cannot be parsed due to schema change, or key not found.
@@ -78,7 +77,7 @@
7978 unset( $data['mTempPath'] );
8079
8180 $file = new UploadStashFile( $this, $this->repo, $path, $key, $data );
82 - if ( $file->getSize === 0 ) {
 81+ if ( $file->getSize() === 0 ) {
8382 throw new UploadStashZeroLengthFileException( "File is zero length" );
8483 }
8584 $this->files[$key] = $file;
@@ -167,6 +166,36 @@
168167 }
169168
170169 /**
 170+ * Remove all files from the stash.
 171+ * Does not clean up files in the repo, just the record of them.
 172+ * @return boolean: success
 173+ */
 174+ public function clear() {
 175+ $_SESSION[UploadBase::SESSION_KEYNAME] = array();
 176+ return true;
 177+ }
 178+
 179+
 180+ /**
 181+ * Remove a particular file from the stash.
 182+ * Does not clean up file in the repo, just the record of it.
 183+ * @return boolean: success
 184+ */
 185+ public function removeFile( $key ) {
 186+ unset ( $_SESSION[UploadBase::SESSION_KEYNAME][$key] );
 187+ return true;
 188+ }
 189+
 190+
 191+ /**
 192+ * List all files in the stash.
 193+ */
 194+ public function listFiles() {
 195+ return array_keys( $_SESSION[UploadBase::SESSION_KEYNAME] );
 196+ }
 197+
 198+
 199+ /**
171200 * Find or guess extension -- ensuring that our extension matches our mime type.
172201 * Since these files are constructed from php tempnames they may not start off
173202 * with an extension.
Property changes on: branches/wmf/1.17wmf1/includes/upload/UploadStash.php
___________________________________________________________________
Modified: svn:mergeinfo
174203 Merged /trunk/phase3/includes/upload/UploadStash.php:r78426,84731,84761-84762
Index: branches/wmf/1.17wmf1/includes/upload/UploadFromUrl.php
@@ -166,11 +166,11 @@
167167 * Wrapper around the parent function in order to defer checking protection
168168 * until we are sure that the file can actually be uploaded
169169 */
170 - public function verifyPermissions( $user ) {
 170+ public function verifyTitlePermissions( $user ) {
171171 if ( $this->mAsync ) {
172172 return true;
173173 }
174 - return parent::verifyPermissions( $user );
 174+ return parent::verifyTitlePermissions( $user );
175175 }
176176
177177 /**

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
r81393Remove the $request parameter fro SpecialUploadStash::__construct(). This par...btongminh15:30, 2 February 2011
r81401Cleanup SpecialUploadStash...btongminh16:07, 2 February 2011
r81638Follow-up r81401: fix callback, apparently it was the other way around than I...btongminh18:13, 7 February 2011
r84731fix bug #28071. Many video previews are relatively large, esp. since MediaWik...neilk06:37, 25 March 2011
r84761change the name of UploadBase::verifyPermissions() to verifyTitlePermissions(...neilk20:37, 25 March 2011
r84762don't check title permissions if upload is destined for stash anywayneilk20:42, 25 March 2011

Status & tagging log