Added placeholders for text injection by hooks to EditPage.php
[lhc/web/wiklou.git] / includes / SpecialUpload.php
index ade5805..768c14f 100644 (file)
@@ -28,6 +28,7 @@ class UploadForm {
        var $mUploadSaveName, $mUploadTempName, $mUploadSize, $mUploadOldVersion;
        var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload;
        var $mOname, $mSessionKey, $mStashed, $mDestFile, $mRemoveTempFile, $mSourceType;
+       var $mUploadTempFileSize = 0;
        /**#@-*/
 
        /**
@@ -125,7 +126,7 @@ class UploadForm {
         * Returns true if there was an error, false otherwise
         */
        private function curlCopy( $url, $dest ) {
-               global $wgMaxUploadSize, $wgUser;
+               global $wgMaxUploadSize, $wgUser, $wgOut;
 
                if( !$wgUser->isAllowed( 'upload_by_url' ) ) {
                        $wgOut->permissionRequired( 'upload_by_url' );
@@ -133,17 +134,18 @@ class UploadForm {
                }
 
                # Maybe remove some pasting blanks :-)
-               $url = strtolower( trim( $url ) );
-               if( substr( $url, 0, 7 ) != 'http://' && substr( $url, 0, 6 ) != 'ftp://' ) {
+               $url =  trim( $url );
+               if( stripos($url, 'http://') !== 0 && stripos($url, 'ftp://') !== 0 ) {
                        # Only HTTP or FTP URLs
+                       $wgOut->errorPage( 'upload-proto-error', 'upload-proto-error-text' );
                        return true;
                }
 
                # Open temporary file
-               $this->mUploadTempFileSize = 0;
                $this->mUploadTempFile = @fopen( $this->mUploadTempName, "wb" );
                if( $this->mUploadTempFile === false ) {
                        # Could not open temporary file to write in
+                       $wgOut->errorPage( 'upload-file-error', 'upload-file-error-text');
                        return true;
                }
                
@@ -155,13 +157,18 @@ class UploadForm {
                curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array( $this, 'uploadCurlCallback' ) );
                curl_exec( $ch );
                $error = curl_errno( $ch ) ? true : false;
-#              if ( $error ) print curl_error ( $ch ) ; # Debugging output
+               $errornum =  curl_errno( $ch );
+               // if ( $error ) print curl_error ( $ch ) ; # Debugging output
                curl_close( $ch );
                
                fclose( $this->mUploadTempFile );
                unset( $this->mUploadTempFile );
                if( $error ) {
                        unlink( $dest );
+                       if( wfEmptyMsg( "upload-curl-error$errornum", wfMsg("upload-curl-error$errornum") ) )
+                               $wgOut->errorPage( 'upload-misc-error', 'upload-misc-error-text' );
+                       else
+                               $wgOut->errorPage( "upload-curl-error$errornum", "upload-curl-error$errornum-text" );
                }
                
                return $error;
@@ -398,7 +405,7 @@ class UploadForm {
                                $image = new Image( $nt );
                                if( $image->wasDeleted() ) {
                                        $skin = $wgUser->getSkin();
-                                       $ltitle = Title::makeTitle( NS_SPECIAL, 'Log' );
+                                       $ltitle = SpecialPage::getTitleFor( 'Log' );
                                        $llink = $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 'type=delete&page=' . $nt->getPrefixedUrl() );
                                        $warning .= wfOpenElement( 'li' ) . wfMsgWikiHtml( 'filewasdeleted', $llink ) . wfCloseElement( 'li' );
                                }
@@ -632,7 +639,7 @@ class UploadForm {
                $reupload = wfMsgHtml( 'reupload' );
                $iw = wfMsgWikiHtml( 'ignorewarning' );
                $reup = wfMsgWikiHtml( 'reuploaddesc' );
-               $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' );
+               $titleObj = SpecialPage::getTitleFor( 'Upload' );
                $action = $titleObj->escapeLocalURL( 'action=submit' );
 
                if ( $wgUseCopyrightUpload )
@@ -712,12 +719,14 @@ class UploadForm {
                $ulb = wfMsgHtml( 'uploadbtn' );
 
 
-               $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' );
+               $titleObj = SpecialPage::getTitleFor( 'Upload' );
                $action = $titleObj->escapeLocalURL();
 
                $encDestFile = htmlspecialchars( $this->mDestFile );
 
-               $watchChecked = $wgUser->getOption( 'watchdefault' )
+               $watchChecked =
+                       ( $wgUser->getOption( 'watchdefault' ) ||
+                               ( $wgUser->getOption( 'watchcreations' ) && $this->mDestFile == '' ) )
                        ? 'checked="checked"'
                        : '';