function processUpload() { global $wgRequest, $wgOut; // Fill in the form data as needed by the upload form $wgRequest->data['wpDestFile'] = $wgRequest->data['DrawingName']; $wgRequest->data['wpIgnoreWarning'] = '1'; $wgRequest->data['wpDestFileWarningAck'] = '1'; $wgRequest->data['wpUploadDescription'] = $wgRequest->data['UploadSummary']; $wgRequest->data['wpUploadFile'] = $wgRequest->data['DrawingData']; $_FILES['wpUploadFile'] = $_FILES['DrawingData']; $wgRequest->data['action'] = $wgRequest->data['Action']; // Upload the drawing $form = new UploadForm($wgRequest); $details = null; $outcome = $form->internalProcessUpload($details); $drawingTempFile = $wgRequest->getFileTempName('DrawingData'); $renderedTempFile = $wgRequest->getFileTempName('RenderedImageData'); $imageMapTempFile = $wgRequest->getFileTempName('ImageMapData'); // If we were successful so far, look whether a rendered image of the // drawing has been uploaded as well. if ($outcome == UploadForm::SUCCESS && $renderedTempFile != null) { $img = $form->mLocalFile; $thumbDir = $img->getThumbPath(); $params = array('width' => $img->getWidth()); $thumbName = $img->thumbName($params); if ($thumbName) { // 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. $veri = $form->verify($renderedTempFile, 'png'); if ($veri) { // Provide an opportunity for extensions to add further checks $error = ''; if (!wfRunHooks('UploadVerification', array($thumbName, $renderedTempFile, &$error))) { $veri = false; } } if ($veri) { if (!file_exists($thumbDir)) { $thumbDirExists = wfMkdirParents($thumbDir); } else { $thumbDirExists = true; } if ($thumbDirExists) { move_uploaded_file($renderedTempFile, $thumbDir . '/' . $thumbName); } } } } // Get rid of uploaded files if (file_exists($drawingTempFile)) { unlink($drawingTempFile); } if (file_exists($renderedTempFile)) { unlink($renderedTempFile); } if (file_exists($imageMapTempFile)) { unlink($imageMapTempFile); } // Return outcome along with an appropriate error message to the client switch ($outcome) { case UploadForm::SUCCESS: header('HTTP/1.0 200 OK'); echo '<html><body>Success.</body></html>'; break; case UploadForm::BEFORE_PROCESSING: header('HTTP/1.0 500 Internal Server Error'); echo '<html><body>Hook UploadForm:BeforeProcessing broke processing the file.</body></html>'; break; case UploadForm::LARGE_FILE_SERVER: header('HTTP/1.0 500 Internal Server Error'); echo '<html><body>' . wfMsgHtml('largefileserver') . '</body></html>'; break; case UploadForm::EMPTY_FILE: header('HTTP/1.0 400 Bad Request'); echo '<html><body>' . wfMsgHtml('emptyfile') . '</body></html>'; break; case UploadForm::MIN_LENGTH_PARTNAME: header('HTTP/1.0 400 Bad Request'); echo '<html><body>' . wfMsgHtml('minlength1') . '</body></html>'; break; case UploadForm::ILLEGAL_FILENAME: header('HTTP/1.0 400 Bad Request'); echo '<html><body>' . wfMsgHtml('illegalfilename', htmlspecialchars($wgRequest->data('DrawingName'))) . '</body></html>'; break; case UploadForm::PROTECTED_PAGE: header('HTTP/1.0 403 Forbidden'); echo '<html><body>'; echo '<p>You are not allowed to change this drawing:</p>'; $this->echoDetails($details['permissionserrors']); echo '</body></html>'; break; case UploadForm::OVERWRITE_EXISTING_FILE: header('HTTP/1.0 403 Forbidden'); echo '<html><body>You may not overwrite the existing drawing.</body></html>'; break; case UploadForm::FILETYPE_MISSING: header('HTTP/1.0 400 Bad Request'); echo '<html><body>The type of the uploaded file is not explicitly allowed.</body></html>'; break; case UploadForm::FILETYPE_BADTYPE: header('HTTP/1.0 400 Bad Request'); echo '<html><body>The type of the uploaded file is explicitly disallowed.</body></html>'; break; case UploadForm::VERIFICATION_ERROR: header('HTTP/1.0 400 Bad Request'); echo '<html><body>'; echo '<p>The uploaded file did not pass server verification.</p>'; echo '</body></html>'; break; case UploadForm::UPLOAD_VERIFICATION_ERROR: header('HTTP/1.0 403 Bad Request'); echo '<html><body>'; echo '<p>The uploaded file did not pass server verification:</p>'; $this->echoDetails($details['error']); echo '</body></html>'; break; case UploadForm::UPLOAD_WARNING: header('HTTP/1.0 400 Bad Request'); echo '<html><body>'; echo '<p>The server issued a warning for this file:</p>'; $this->echoDetails($details['warning']); echo '</body></html>'; break; case UploadForm::INTERNAL_ERROR: header('HTTP/1.0 500 Internal Server Error'); echo '<html><body>'; echo '<p>Function UploadForm:internalProcessUpload encountered an internal error.</p>'; echo '<p>' . $details['internal'] . '</p>'; echo '</body></html>'; break; default: header('HTTP/1.0 500 Internal Server Error'); echo '<html><body>Function UploadForm:internalProcessUpload returned an unknown code: ' . $outcome . '.</body></html>'; break; } exit; }