r74299 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74298‎ | r74299 | r74300 >
Date:13:41, 5 October 2010
Author:catrope
Status:deferred
Tags:
Comment:
uploadwizard: FIXMEs and a few changes for SpecialSessionStash
* Actually enforce the access restriction ('upload' right in this case). SpecialPage doesn't do this for you if you override execute()
* Put parentheses around an assignment inside an if() condition
* Add some FIXME comments
Modified paths:
  • /branches/uploadwizard/phase3/includes/specials/SpecialSessionStash.php (modified) (history)

Diff [purge]

Index: branches/uploadwizard/phase3/includes/specials/SpecialSessionStash.php
@@ -18,7 +18,7 @@
1919
2020 class SpecialSessionStash extends SpecialPage {
2121
22 - static $HttpErrors = array(
 22+ static $HttpErrors = array( // FIXME: Use OutputPage::getStatusMessage() --RK
2323 400 => 'Bad Request',
2424 403 => 'Access Denied',
2525 404 => 'File not found',
@@ -33,6 +33,7 @@
3434
3535 // $request is the request (usually wgRequest)
3636 // $subpage is everything in the URL after Special:SessionStash
 37+ // FIXME: These parameters don't match SpecialPage::__construct()'s params at all, and are unused --RK
3738 public function __construct( $request = null, $subpage = null ) {
3839 parent::__construct( 'SessionStash', 'upload' );
3940 $this->stash = new SessionStash();
@@ -42,11 +43,16 @@
4344 * If file available in stash, cats it out to the client as a simple HTTP response.
4445 * n.b. Most sanity checking done in SessionStashLocalFile, so this is straightforward.
4546 *
46 - * @param {String} subpage, e.g. in http://sample.com/wiki/Special:SessionStash/foo.jpg, the "foo".
 47+ * @param {String} $subPage: subpage, e.g. in http://example.com/wiki/Special:SessionStash/foo.jpg, the "foo.jpg" part
4748 * @return {Boolean} success
4849 */
4950 public function execute( $subPage ) {
50 - global $wgOut;
 51+ global $wgOut, $wgUser;
 52+
 53+ if ( !$this->userCanExecute( $wgUser ) ) {
 54+ $this->displayRestrictionError();
 55+ return;
 56+ }
5157
5258 // prevent callers from doing standard HTML output -- we'll take it from here
5359 $wgOut->disable();
@@ -93,6 +99,9 @@
94100 // if we couldn't find it, and it looks like a thumbnail,
95101 // and it looks like we have the original, go ahead and generate it
96102 $matches = array();
 103+ // FIXME: This code assumes all kinds of constraints apply to file keys:
 104+ // they can't contain whitespace, and keys for original files can't contain dashes.
 105+ // These assumptions should be documented and/or enforced --RK
97106 if ( ! preg_match( '/^(\d+)px-(\S+)$/', $key, $matches ) ) {
98107 // that doesn't look like a thumbnail. re-raise exception
99108 throw $e;
@@ -108,7 +117,7 @@
109118 // because the file is a SessionStashFile, this thumbnail will also be stashed,
110119 // and a thumbnailFile will be created in the thumbnailImage composite object
111120 $thumbnailImage = null;
112 - if ( ! $thumbnailImage = $origFile->getThumbnail( $width ) ) {
 121+ if ( !( $thumbnailImage = $origFile->getThumbnail( $width ) ) ) {
113122 throw new MWException( 'Could not obtain thumbnail' );
114123 }
115124 $file = $thumbnailImage->thumbnailFile;
@@ -127,7 +136,7 @@
128137 header( 'Content-Transfer-Encoding: binary', true );
129138 header( 'Expires: Sun, 17-Jan-2038 19:14:07 GMT', true );
130139 header( 'Pragma: public', true );
131 - header( 'Content-Length: ' . $file->getSize(), true );
 140+ header( 'Content-Length: ' . $file->getSize(), true ); // FIXME: PHP can handle Content-Length for you just fine --RK
132141 readfile( $file->getPath() );
133142 }
134143 }

Status & tagging log