+
+ /* -------------------------------------------------------------- */
+
+ /**
+ * Really do the upload
+ * Checks are made in SpecialUpload::execute()
+ * @access private
+ */
+ function processUpload() {
+ global $wgUser, $wgOut, $wgUploadDirectory;
+
+ /* Check for PHP error if any, requires php 4.2 or newer */
+ if ( $this->mUploadError == 1/*UPLOAD_ERR_INI_SIZE*/ ) {
+ $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
+ return;
+ }
+
+ /**
+ * If there was no filename or a zero size given, give up quick.
+ */
+ if( trim( $this->mOname ) == '' || empty( $this->mUploadSize ) ) {
+ $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
+ return;
+ }
+
+ # Chop off any directories in the given filename
+ if ( $this->mDestFile ) {
+ $basename = basename( $this->mDestFile );
+ } else {
+ $basename = basename( $this->mOname );
+ }
+
+ /**
+ * We'll want to blacklist against *any* 'extension', and use
+ * only the final one for the whitelist.
+ */
+ list( $partname, $ext ) = $this->splitExtensions( $basename );
+ if( count( $ext ) ) {
+ $finalExt = $ext[count( $ext ) - 1];
+ } else {
+ $finalExt = '';
+ }
+ $fullExt = implode( '.', $ext );
+
+ if ( strlen( $partname ) < 3 ) {
+ $this->mainUploadForm( wfMsgHtml( 'minlength' ) );
+ return;
+ }
+
+ /**
+ * Filter out illegal characters, and try to make a legible name
+ * out of it. We'll strip some silently that Title would die on.
+ */
+ $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $basename );
+ $nt = Title::newFromText( $filtered );
+ if( is_null( $nt ) ) {
+ $this->uploadError( wfMsgWikiHtml( 'illegalfilename', htmlspecialchars( $filtered ) ) );
+ return;
+ }
+ $nt =& Title::makeTitle( NS_IMAGE, $nt->getDBkey() );
+ $this->mUploadSaveName = $nt->getDBkey();
+
+ /**
+ * If the image is protected, non-sysop users won't be able
+ * to modify it by uploading a new revision.
+ */
+ if( !$nt->userCanEdit() ) {
+ return $this->uploadError( wfMsgWikiHtml( 'protectedpage' ) );
+ }
+
+ /**
+ * In some cases we may forbid overwriting of existing files.
+ */
+ $overwrite = $this->checkOverwrite( $this->mUploadSaveName );
+ if( WikiError::isError( $overwrite ) ) {
+ return $this->uploadError( $overwrite->toString() );
+ }
+
+ /* Don't allow users to override the blacklist (check file extension) */
+ global $wgStrictFileExtensions;
+ global $wgFileExtensions, $wgFileBlacklist;
+ if( $this->checkFileExtensionList( $ext, $wgFileBlacklist ) ||
+ ($wgStrictFileExtensions &&
+ !$this->checkFileExtension( $finalExt, $wgFileExtensions ) ) ) {
+ return $this->uploadError( wfMsgHtml( 'badfiletype', htmlspecialchars( $fullExt ) ) );
+ }
+
+ /**
+ * Look at the contents of the file; if we can recognize the
+ * type but it's corrupt or data of the wrong type, we should
+ * probably not accept it.
+ */
+ if( !$this->mStashed ) {
+ $this->checkMacBinary();
+ $veri = $this->verify( $this->mUploadTempName, $finalExt );
+
+ if( $veri !== true ) { //it's a wiki error...
+ return $this->uploadError( $veri->toString() );
+ }
+ }
+
+ /**
+ * Provide an opportunity for extensions to add futher checks
+ */
+ $error = '';
+ if( !wfRunHooks( 'UploadVerification',
+ array( $this->mUploadSaveName, $this->mUploadTempName, &$error ) ) ) {
+ return $this->uploadError( $error );
+ }
+
+ /**
+ * Check for non-fatal conditions
+ */
+ if ( ! $this->mIgnoreWarning ) {
+ $warning = '';
+
+ global $wgCapitalLinks;
+ if( $wgCapitalLinks ) {
+ $filtered = ucfirst( $filtered );
+ }
+ if( $this->mUploadSaveName != $filtered ) {
+ $warning .= '<li>'.wfMsgHtml( 'badfilename', htmlspecialchars( $this->mUploadSaveName ) ).'</li>';
+ }
+
+ global $wgCheckFileExtensions;
+ if ( $wgCheckFileExtensions ) {
+ if ( ! $this->checkFileExtension( $finalExt, $wgFileExtensions ) ) {
+ $warning .= '<li>'.wfMsgHtml( 'badfiletype', htmlspecialchars( $fullExt ) ).'</li>';
+ }
+ }
+
+ global $wgUploadSizeWarning;
+ if ( $wgUploadSizeWarning && ( $this->mUploadSize > $wgUploadSizeWarning ) ) {
+ # TODO: Format $wgUploadSizeWarning to something that looks better than the raw byte
+ # value, perhaps add GB,MB and KB suffixes?
+ $warning .= '<li>'.wfMsgHtml( 'largefile', $wgUploadSizeWarning, $this->mUploadSize ).'</li>';
+ }
+ if ( $this->mUploadSize == 0 ) {
+ $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>';
+ }
+
+ if( $nt->getArticleID() ) {
+ global $wgUser;
+ $sk = $wgUser->getSkin();
+ $dlink = $sk->makeKnownLinkObj( $nt );
+ $warning .= '<li>'.wfMsgHtml( 'fileexists', $dlink ).'</li>';
+ }
+
+ if( $warning != '' ) {
+ /**
+ * Stash the file in a temporary location; the user can choose
+ * to let it through and we'll complete the upload then.
+ */
+ return $this->uploadWarning( $warning );
+ }
+ }
+
+ /**
+ * Try actually saving the thing...
+ * It will show an error form on failure.
+ */
+ $hasBeenMunged = !empty( $this->mSessionKey ) || $this->mRemoveTempFile;
+ if( $this->saveUploadedFile( $this->mUploadSaveName,
+ $this->mUploadTempName,
+ $hasBeenMunged ) ) {
+ /**
+ * Update the upload log and create the description page
+ * if it's a new file.
+ */
+ $img = Image::newFromName( $this->mUploadSaveName );
+ $success = $img->recordUpload( $this->mUploadOldVersion,
+ $this->mUploadDescription,
+ $this->mLicense,
+ $this->mUploadCopyStatus,
+ $this->mUploadSource,
+ $this->mWatchthis );
+
+ if ( $success ) {
+ $this->showSuccess();
+ } else {
+ // Image::recordUpload() fails if the image went missing, which is
+ // unlikely, hence the lack of a specialised message
+ $wgOut->fileNotFoundError( $this->mUploadSaveName );
+ }
+ }