Bug 32673: Keep the username in the input field if not existing
[lhc/web/wiklou.git] / includes / specials / SpecialUploadStash.php
index 20a37f0..5d353f1 100644 (file)
@@ -35,7 +35,6 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                try {
                        $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
                } catch ( UploadStashNotAvailableException $e ) {
-                       return null;
                }
        }
 
@@ -46,21 +45,14 @@ class SpecialUploadStash extends UnlistedSpecialPage {
         * @return Boolean: success
         */
        public function execute( $subPage ) {
-               global $wgUser;
+               $this->checkPermissions();
 
-               if ( !$this->userCanExecute( $wgUser ) ) {
-                       $this->displayRestrictionError();
-                       return;
-               }
-
-               if ( !isset( $subPage ) || $subPage === '' ) {
+               if ( $subPage === null || $subPage === '' ) {
                        return $this->showUploads();
                }
-
                return $this->showUpload( $subPage );
        }
 
-
        /**
         * If file available in stash, cats it out to the client as a simple HTTP response.
         * n.b. Most sanity checking done in UploadStashLocalFile, so this is straightforward.
@@ -68,10 +60,8 @@ class SpecialUploadStash extends UnlistedSpecialPage {
         * @param $key String: the key of a particular requested file
         */
        public function showUpload( $key ) {
-               global $wgOut;
-
                // prevent callers from doing standard HTML output -- we'll take it from here
-               $wgOut->disable();
+               $this->getOutput()->disable();
 
                try {
                        $params = $this->parseKey( $key );
@@ -97,8 +87,7 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                        $message = $e->getMessage();
                }
 
-               wfHttpError( $code, HttpStatus::getMessage( $code ), $message );
-               return false;
+               throw new HttpError( $code, $message );
        }
 
        /**
@@ -210,12 +199,20 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                // this global probably looks something like 'http://upload.wikimedia.org/wikipedia/test/thumb/temp'
                // do not use trailing slash
                global $wgUploadStashScalerBaseUrl;
+               $scalerBaseUrl = $wgUploadStashScalerBaseUrl;
+
+               if( preg_match( '/^\/\//', $scalerBaseUrl ) ) {
+                       // this is apparently a protocol-relative URL, which makes no sense in this context,
+                       // since this is used for communication that's internal to the application.
+                       // default to http.
+                       $scalerBaseUrl = wfExpandUrl( $scalerBaseUrl, PROTO_CANONICAL );
+               }
 
                // We need to use generateThumbName() instead of thumbName(), because
                // the suffix needs to match the file name for the remote thumbnailer
                // to work
                $scalerThumbName = $file->generateThumbName( $file->getName(), $params );
-               $scalerThumbUrl = $wgUploadStashScalerBaseUrl . '/' . $file->getUrlRel() .
+               $scalerThumbUrl = $scalerBaseUrl . '/' . $file->getUrlRel() .
                        '/' . rawurlencode( $scalerThumbName );
 
                // make a curl call to the scaler to create a thumbnail
@@ -309,7 +306,6 @@ class SpecialUploadStash extends UnlistedSpecialPage {
         * @param Status : $status - the result of processRequest
         */
        private function showUploads( $status = null ) {
-               global $wgOut;
                if ( $status === null ) {
                        $status = Status::newGood();
                }
@@ -327,7 +323,7 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                                'default' => true,
                                'name' => 'clear',
                        )
-               ), 'clearStashedUploads' );
+               ), $this->getContext(), 'clearStashedUploads' );
                $form->setSubmitCallback( array( __CLASS__ , 'tryClearStashedUploads' ) );
                $form->setTitle( $this->getTitle() );
                $form->setSubmitText( wfMsg( 'uploadstash-clear' ) );
@@ -340,7 +336,7 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                        array( 'href' => $this->getTitle()->getLocalURL() ),
                        wfMsg( 'uploadstash-refresh' ) );
                $files = $this->stash->listFiles();
-               if ( count( $files ) ) {
+               if ( $files && count( $files ) ) {
                        sort( $files );
                        $fileListItemsHtml = '';
                        foreach ( $files as $file ) {
@@ -350,11 +346,11 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                                                $this->getTitle( "file/$file" )->getLocalURL() ), $file )
                                );
                        }
-                       $wgOut->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) );
+                       $this->getOutput()->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) );
                        $form->displayForm( $formResult );
-                       $wgOut->addHtml( Html::rawElement( 'p', array(), $refreshHtml ) );
+                       $this->getOutput()->addHtml( Html::rawElement( 'p', array(), $refreshHtml ) );
                } else {
-                       $wgOut->addHtml( Html::rawElement( 'p', array(),
+                       $this->getOutput()->addHtml( Html::rawElement( 'p', array(),
                                Html::element( 'span', array(), wfMsg( 'uploadstash-nofiles' ) )
                                . ' '
                                . $refreshHtml