function axMultiEditImageUpload()
{
    global $wgRequest;
    $res = array();
    $postfix = $wgRequest->getVal('num');
    $infix = '';
    if ($wgRequest->getVal('infix') != '') {
        $infix = $wgRequest->getVal('infix');
    }
    // do the real upload
    $uploadform = new CreatePageImageUploadForm($wgRequest);
    $uploadform->mTempPath = $wgRequest->getFileTempName('wp' . $infix . 'UploadFile' . $postfix);
    $uploadform->mFileSize = $wgRequest->getFileSize('wp' . $infix . 'UploadFile' . $postfix);
    $uploadform->mSrcName = $wgRequest->getFileName('wp' . $infix . 'UploadFile' . $postfix);
    $uploadform->CurlError = $wgRequest->getUploadError('wp' . $infix . 'UploadFile' . $postfix);
    $uploadform->mLastTimestamp = $wgRequest->getText('wp' . $infix . 'LastTimestamp' . $postfix);
    $par_name = $wgRequest->getText('wp' . $infix . 'ParName' . $postfix);
    $file_ext = explode('.', $uploadform->mSrcName);
    $file_ext = @$file_ext[1];
    $uploadform->mParameterExt = $file_ext;
    if ($infix == '') {
        $uploadform->mDesiredDestName = $wgRequest->getText('Createtitle') . ' ' . trim($par_name);
    } else {
        $uploadform->mDesiredDestName = $wgRequest->getText('Createtitle');
    }
    $uploadform->mSessionKey = false;
    $uploadform->mStashed = false;
    $uploadform->mRemoveTempFile = false;
    // some of the values are fixed, we have no need to add them to the form itself
    $uploadform->mIgnoreWarning = 1;
    $uploadform->mUploadDescription = wfMsg('createpage-uploaded-from');
    $uploadform->mWatchthis = 1;
    $uploadedfile = $uploadform->execute();
    if ($uploadedfile['error'] == 0) {
        $imageobj = wfLocalFile($uploadedfile['timestamp']);
        $imageurl = $imageobj->createThumb(60);
        $res = array('error' => 0, 'msg' => $uploadedfile['msg'], 'url' => $imageurl, 'timestamp' => $uploadedfile['timestamp'], 'num' => $postfix);
    } else {
        if ($uploadedfile['once']) {
            #if ( !$error_once ) {
            $res = array('error' => 1, 'msg' => $uploadedfile['msg'], 'num' => $postfix);
            #}
            $error_once = true;
        } else {
            $res = array('error' => 1, 'msg' => $uploadedfile['msg'], 'num' => $postfix);
        }
    }
    $text = json_encode($res);
    $ar = new AjaxResponse($text);
    $ar->setContentType('text/html; charset=utf-8');
    return $ar;
}
 function glueArticle($preview = false, $render_option = true)
 {
     global $wgRequest, $wgOut;
     $text = '';
     $infoboxes = array();
     $categories = array();
     $optionals = array();
     $images = array();
     $all_images = array();
     $error_once = false;
     foreach ($_POST as $key => $value) {
         if (strpos($key, 'wpOptionals') !== false) {
             if ($render_option) {
                 // build optional data
                 $optionals = explode(',', $value);
             }
         } elseif (strpos($key, 'wpTextboxes') !== false) {
             // check if this was optional
             if (!in_array($key, $optionals)) {
                 $text .= "\n" . $value;
             }
         } elseif (strpos($key, 'wpInfoboxPar') !== false) {
             $infoboxes[] = $value;
         } elseif (strpos($key, 'category_') !== false) {
             $categories[] = $value;
         } elseif (strpos($key, 'wpDestFile') !== false) {
             $image_value = array();
             $postfix = substr($key, 10);
             if ($wgRequest->getVal('wpNoUse' . $postfix) == 'Yes') {
                 $infoboxes[] = $wgRequest->getVal('wpInfImg' . $postfix);
             } else {
                 $image_value['watchthis'] = $_POST['wpWatchthis' . $postfix];
                 // do the real upload
                 $uploadform = new CreatePageImageUploadForm($wgRequest);
                 $uploadform->mTempPath = $wgRequest->getFileTempName('wpUploadFile' . $postfix);
                 $uploadform->mFileSize = $wgRequest->getFileSize('wpUploadFile' . $postfix);
                 $uploadform->mSrcName = $wgRequest->getFileName('wpUploadFile' . $postfix);
                 $uploadform->CurlError = $wgRequest->getUploadError('wpUploadFile' . $postfix);
                 // required by latest functions
                 $par_name = $wgRequest->getText('wpParName' . $postfix);
                 if ($uploadform->mSrcName) {
                     $file_ext = explode('.', $uploadform->mSrcName);
                     $file_ext = $file_ext[1];
                 } else {
                     $file_ext = '';
                 }
                 $uploadform->mParameterExt = $file_ext;
                 $uploadform->mDesiredDestName = $wgRequest->getText('Createtitle') . ' ' . trim($par_name);
                 $uploadform->mSessionKey = false;
                 $uploadform->mStashed = false;
                 $uploadform->mRemoveTempFile = false;
                 // some of the values are fixed, we have no need to add them to the form itself
                 $uploadform->mIgnoreWarning = 1;
                 $uploadform->mUploadDescription = wfMsg('createpage-uploaded-from');
                 $uploadform->mWatchthis = 1;
                 $uploadedfile = $uploadform->execute();
                 if ($uploadedfile['error'] == 0) {
                     $infoboxes[] = $uploadedfile['msg'];
                 } else {
                     $infoboxes[] = '<!---imageupload--->';
                     if ($uploadedfile['once']) {
                         if (!$error_once) {
                             if (!$preview) {
                                 // certainly they'll notice things on preview
                                 $wgOut->addHTML("<p class='error'>{$uploadedfile['msg']}</p>");
                             }
                         }
                         $error_once = true;
                     } else {
                         if (!$preview) {
                             $wgOut->addHTML("<p class='error'>{$uploadedfile['msg']}</p>");
                         }
                     }
                 }
             }
         } elseif (strpos($key, 'wpAllDestFile') !== false) {
             // upload and glue in images that are within the article content too
             $image_value = array();
             $postfix = substr($key, 13);
             $image_value['watchthis'] = $_POST['wpWatchthis' . $postfix];
             $uploadform = new CreatePageImageUploadForm($wgRequest);
             $uploadform->mTempPath = $wgRequest->getFileTempName('wpAllUploadFile' . $postfix);
             $uploadform->mFileSize = $wgRequest->getFileSize('wpAllUploadFile' . $postfix);
             $uploadform->mSrcName = $wgRequest->getFileName('wpAllUploadFile' . $postfix);
             $uploadform->CurlError = $wgRequest->getUploadError('wpAllUploadFile' . $postfix);
             // required by latest functions
             if ($uploadform->mSrcName) {
                 $file_ext = explode('.', $uploadform->mSrcName);
                 $file_ext = $file_ext[1];
             } else {
                 $file_ext = '';
             }
             $uploadform->mParameterExt = $file_ext;
             $uploadform->mDesiredDestName = $wgRequest->getText('Createtitle');
             $uploadform->mSessionKey = false;
             $uploadform->mStashed = false;
             $uploadform->mRemoveTempFile = false;
             $uploadform->mIgnoreWarning = 1;
             $uploadform->mUploadDescription = wfMsg('createpage-uploaded-from');
             $uploadform->mWatchthis = 1;
             $uploadedfile = $uploadform->execute();
             if ($uploadedfile['error'] == 0) {
                 $all_images[] = $uploadedfile['msg'];
             } else {
                 $all_images[] = '<!---imageupload--->';
                 if ($uploadedfile['once']) {
                     if (!$error_once) {
                         if (!$preview) {
                             $wgOut->addHTML("<p class='error'>{$uploadedfile['msg']}</p>");
                         }
                     }
                     $error_once = true;
                 } else {
                     if (!$preview) {
                         $wgOut->addHTML("<p class='error'>{$uploadedfile['msg']}</p>");
                     }
                 }
             }
         }
     }
     if (is_array($all_images)) {
         // glue in images, replacing all image tags with content
         foreach ($all_images as $myimage) {
             $repl_count = 1;
             if ($myimage != '<!---imageupload--->') {
                 $text = $this->str_replace_once('<!---imageupload--->', '[[' . $myimage . '|thumb]]', $text);
             }
         }
     }
     if (isset($_POST['wpInfoboxValue'])) {
         $text = $this->glueInfobox($infoboxes, $_POST['wpInfoboxValue']) . $text;
     }
     if (isset($_POST['wpCategoryTextarea'])) {
         $text .= $this->glueCategories($categories, $_POST['wpCategoryTextarea']);
     }
     return $text;
 }