* (bug 7405) Make Linker methods static. Patch by Dan Li.
[lhc/web/wiklou.git] / includes / SpecialUpload.php
index ade5805..a43e2ea 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;
@@ -247,7 +254,7 @@ class UploadForm {
         * @access private
         */
        function processUpload() {
-               global $wgUser, $wgOut;
+               global $wgOut;
 
                /* Check for PHP error if any, requires php 4.2 or newer */
                if( $this->mUploadError == 1/*UPLOAD_ERR_INI_SIZE*/ ) {
@@ -388,18 +395,15 @@ class UploadForm {
                        }
 
                        if( $nt->getArticleID() ) {
-                               global $wgUser;
-                               $sk = $wgUser->getSkin();
-                               $dlink = $sk->makeKnownLinkObj( $nt );
+                               $dlink = Linker::makeKnownLinkObj( $nt );
                                $warning .= '<li>'.wfMsgHtml( 'fileexists', $dlink ).'</li>';
                        } else {
                                # If the file existed before and was deleted, warn the user of this
                                # Don't bother doing so if the image exists now, however
                                $image = new Image( $nt );
                                if( $image->wasDeleted() ) {
-                                       $skin = $wgUser->getSkin();
-                                       $ltitle = Title::makeTitle( NS_SPECIAL, 'Log' );
-                                       $llink = $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 'type=delete&page=' . $nt->getPrefixedUrl() );
+                                       $ltitle = SpecialPage::getTitleFor( 'Log' );
+                                       $llink = Linker::makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 'type=delete&page=' . $nt->getPrefixedUrl() );
                                        $warning .= wfOpenElement( 'li' ) . wfMsgWikiHtml( 'filewasdeleted', $llink ) . wfCloseElement( 'li' );
                                }
                        }
@@ -584,12 +588,11 @@ class UploadForm {
         * @access private
         */
        function showSuccess() {
-               global $wgUser, $wgOut, $wgContLang;
+               global $wgOut, $wgContLang;
 
-               $sk = $wgUser->getSkin();
-               $ilink = $sk->makeMediaLink( $this->mUploadSaveName, Image::imageUrl( $this->mUploadSaveName ) );
+               $ilink = Linker::makeMediaLink( $this->mUploadSaveName, Image::imageUrl( $this->mUploadSaveName ) );
                $dname = $wgContLang->getNsText( NS_IMAGE ) . ':'.$this->mUploadSaveName;
-               $dlink = $sk->makeKnownLink( $dname, $dname );
+               $dlink = Linker::makeKnownLink( $dname, $dname );
 
                $wgOut->addHTML( '<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n" );
                $text = wfMsgWikiHtml( 'fileuploaded', $ilink, $dlink );
@@ -632,7 +635,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 )
@@ -697,7 +700,6 @@ class UploadForm {
                $wgOut->addHTML( '<div id="uploadtext">' );
                $wgOut->addWikiText( wfMsg( 'uploadtext' ) );
                $wgOut->addHTML( '</div>' );
-               $sk = $wgUser->getSkin();
 
 
                $sourcefilename = wfMsgHtml( 'sourcefilename' );
@@ -712,12 +714,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"'
                        : '';