示例#1
0
 /**
  * Updates an existing Time model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelUP = new UploadForm();
     if ($model->load(Yii::$app->request->post())) {
         $modelUP->imageFile = UploadedFile::getInstance($model, 'escudo');
         $nome = md5(uniqid(""));
         $modelUP->upload($model->id, $nome);
         $model->escudo = $nome . '.' . $modelUP->imageFile->extension;
         $modelUP->imageFile = UploadedFile::getInstance($model, 'icon_mascote');
         $nome = md5(uniqid(""));
         $modelUP->upload($model->id, $nome);
         $model->icon_mascote = $nome . '.' . $modelUP->imageFile->extension;
         $modelUP->imageFile = UploadedFile::getInstance($model, 'mascote');
         $nome = md5(uniqid(""));
         $modelUP->upload($model->id, $nome);
         $model->mascote = $nome . '.' . $modelUP->imageFile->extension;
         $modelUP->imageFile = UploadedFile::getInstance($model, 'icon_mascote_i');
         $nome = md5(uniqid(""));
         $modelUP->upload($model->id, $nome);
         $model->icon_mascote_i = $nome . '.' . $modelUP->imageFile->extension;
         if ($model->save()) {
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
 /**
  * Constructor
  */
 public function __construct(&$request)
 {
     # overwrite action parameter
     $_REQUEST['action'] = 'submit';
     # and call parent
     parent::__construct($request);
 }
 function processUpload()
 {
     global $wgMaxUploadFiles, $wgOut;
     parent::processUpload();
     $wgOut->redirect('');
     // clear the redirect
 }
示例#4
0
 /**
  * 多文件缩略图
  *
  * @param array $setting {@link getDefaultOptions()}
  * @param string $basename
  * @param bool $cleanSquid
  * @return array 出错返回 false
  */
 public function thumbAll($setting, $basename = null, $cleanSquid = false)
 {
     $setting = CMap::mergeArray($this->getDefaultOptions(), $setting);
     $upload = $setting['upload'];
     $isCheck = $upload['isCheck'];
     unset($setting['upload']);
     unset($upload['isCheck']);
     $model = UploadForm::getInstance($upload);
     if ($isCheck && !$model->validate()) {
         $this->_error = implode($model->getErrors('filedata'));
         return false;
     }
     $infos = array();
     empty($basename) && ($basename = uniqid() . sprintf('%07x', mt_rand(1000000, 9999999)));
     foreach ($model->filedata as $id => $cu) {
         $file['name'] = $cu->name;
         $file['size'] = $cu->size;
         $file['type'] = $cu->type;
         $file['temp'] = $cu->tempName;
         $info = $this->handleFile($file, $setting, $basename, $cleanSquid, $id);
         if (!$info) {
             return false;
         }
         $infos[] = $info;
     }
     return $infos;
 }
示例#5
0
/** */
function wfGetType($filename, $safe = true)
{
    global $wgTrivialMimeDetection;
    $ext = strrchr($filename, '.');
    $ext = $ext === false ? '' : strtolower(substr($ext, 1));
    # trivial detection by file extension,
    # used for thumbnails (thumb.php)
    if ($wgTrivialMimeDetection) {
        switch ($ext) {
            case 'gif':
                return 'image/gif';
            case 'png':
                return 'image/png';
            case 'jpg':
                return 'image/jpeg';
            case 'jpeg':
                return 'image/jpeg';
        }
        return 'unknown/unknown';
    }
    $magic = MimeMagic::singleton();
    // Use the extension only, rather than magic numbers, to avoid opening
    // up vulnerabilities due to uploads of files with allowed extensions
    // but disallowed types.
    $type = $magic->guessTypesForExtension($ext);
    /**
     * Double-check some security settings that were done on upload but might 
     * have changed since.
     */
    if ($safe) {
        global $wgFileBlacklist, $wgCheckFileExtensions, $wgStrictFileExtensions, $wgFileExtensions, $wgVerifyMimeType, $wgMimeTypeBlacklist, $wgRequest;
        $form = new UploadForm($wgRequest);
        list($partName, $extList) = $form->splitExtensions($filename);
        if ($form->checkFileExtensionList($extList, $wgFileBlacklist)) {
            return 'unknown/unknown';
        }
        if ($wgCheckFileExtensions && $wgStrictFileExtensions && !$form->checkFileExtensionList($extList, $wgFileExtensions)) {
            return 'unknown/unknown';
        }
        if ($wgVerifyMimeType && in_array(strtolower($type), $wgMimeTypeBlacklist)) {
            return 'unknown/unknown';
        }
    }
    return $type;
}
示例#6
0
 /**
  * static method used in hook
  *
  *
  * @access public
  * @static
  *
  * @param UploadForm $uploadForm -- uploadForm object
  */
 public static function uploadComplete($uploadForm)
 {
     if (!$uploadForm->getLocalFile() instanceof LocalFile) {
         return true;
     }
     $title = $uploadForm->getLocalFile()->getTitle();
     if (!$title instanceof Title) {
         return true;
     }
     wfProfileIn(__METHOD__);
     $mTitle = $title->getText();
     $relPath = $uploadForm->getLocalFile()->getRel();
     $fullPath = $uploadForm->getLocalFile()->getPath();
     $aHistory = $uploadForm->getLocalFile()->getHistory(1);
     $oldPath = false;
     if (isset($aHistory) && isset($aHistory[0])) {
         $oOldLocalFile = $aHistory[0];
         if (isset($oOldLocalFile) && $oOldLocalFile instanceof OldLocalFile) {
             $oldPath = $oOldLocalFile->getArchiveName();
         }
     }
     if (!empty($oldPath)) {
         $oldPath = sprintf("%s/%s", $uploadForm->getLocalFile()->getArchivePath(), $oldPath);
     }
     /**
      * write log to database
      */
     self::log($title, $fullPath, $relPath, $oldPath, "u");
     wfProfileOut(__METHOD__);
     return true;
 }
示例#7
0
 public function uploadAction()
 {
     $this->init();
     if (!is_dir($this->_dir)) {
         mkdir($this->_dir, 0777);
     }
     $form = new UploadForm($this->getServiceLocator(), $this->_dir, 'upload-form');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             // Form is valid, save the form!
             $this->setFileNames($data);
             // The data can be saved in the DataBase
             return $this->redirect()->toRoute('uploads');
         }
     }
     return new ViewModel(array('form' => $form));
 }
	function displayForm( $submitResult ) {
		global $wgOut;
		parent::displayForm( $submitResult );
		if ( method_exists( $wgOut, 'allowClickjacking' ) ) {
			$wgOut->allowClickjacking();
		}
	}
 protected function updateMenuItems($model = null)
 {
     // create static model if model is null
     if ($model == null) {
         $model = new UploadForm('install');
     }
     switch ($this->action->id) {
         case 'restore':
             $this->menu[] = array('label' => Yii::t('app', 'View Site'), 'url' => Yii::app()->HomeUrl);
         case 'create':
             $this->menu[] = array('label' => Yii::t('app', 'List Backup') . ' ' . $model->label(2), 'url' => array('index'));
             break;
         case 'upload':
             $this->menu[] = array('label' => Yii::t('app', 'Create Backup') . ' ' . $model->label(), 'url' => array('create'));
             break;
         default:
             $this->menu[] = array('label' => Yii::t('app', 'List Backup') . ' ' . $model->label(2), 'url' => array('index'));
             $this->menu[] = array('label' => Yii::t('app', 'Create Backup') . ' ' . $model->label(), 'url' => array('create'));
             $this->menu[] = array('label' => Yii::t('app', 'Upload Backup') . ' ' . $model->label(), 'url' => array('upload'));
             $this->menu[] = array('label' => Yii::t('app', 'Restore Backup') . ' ' . $model->label(), 'url' => array('restore'));
             $this->menu[] = array('label' => Yii::t('app', 'Clean Database') . ' ' . $model->label(), 'url' => array('clean'));
             $this->menu[] = array('label' => Yii::t('app', 'View Site'), 'url' => Yii::app()->HomeUrl);
             break;
     }
 }
示例#10
0
 /**
  * Record a file upload in the upload log and the image table
  * @deprecated use upload()
  */
 function recordUpload($oldver, $desc, $license = '', $copyStatus = '', $source = '', $watch = false, $timestamp = false)
 {
     $pageText = UploadForm::getInitialPageText($desc, $license, $copyStatus, $source);
     if (!$this->recordUpload2($oldver, $desc, $pageText)) {
         return false;
     }
     if ($watch) {
         global $wgUser;
         $wgUser->addWatch($this->getTitle());
     }
     return true;
 }
示例#11
0
 /**
  * Allows the upload of a file.
  */
 public function actionUpload($code = '')
 {
     $model = new UploadForm();
     if (!Yii::app()->user->isGuest) {
         $model->byteacher = true;
     }
     $model->code = $code;
     $model->setUrlExample();
     if (isset($_POST['UploadForm'])) {
         $model->uploadedfile = CUploadedFile::getInstance($model, 'uploadedfile');
         $model->attributes = $_POST['UploadForm'];
         if ($model->validate()) {
             if ($file = $model->saveData(Yii::app()->basePath . DIRECTORY_SEPARATOR . Helpers::getYiiParam('uploadDirectory'))) {
                 if (!$model->byteacher) {
                     if ($file->exercise->assignment->notification) {
                         MailTemplate::model()->mailFromTemplate('new_work_notification', Helpers::getYiiParam('adminEmail'), array('student' => $model->exercise->student, 'file' => $file, 'url' => $this->createAbsoluteSslUrl('file/view', array('id' => $file->id, 'hash' => $file->md5))));
                     }
                     if ($model->exercise->student->email) {
                         MailTemplate::model()->mailFromTemplate('new_work_acknowledgement', array($model->exercise->student->email => $model->exercise->student), array('student' => $model->exercise->student, 'file' => $file, 'url' => $this->createAbsoluteSslUrl('file/view', array('id' => $file->id, 'hash' => $file->md5))));
                         Yii::app()->getUser()->setFlash('success', 'Work correctly uploaded / saved. An email has been sent to your address.');
                     }
                 } else {
                     Yii::app()->getUser()->setFlash('success', 'Work correctly uploaded / saved.');
                 }
                 $this->redirect(array('file/view', 'id' => $file->id, 'hash' => $file->md5, 'status' => 1));
             } else {
                 Yii::app()->getUser()->setFlash('error', 'The work could not be saved.');
             }
         }
     }
     $this->render('upload', array('model' => $model));
 }
 /**
  * Get an UploadForm instance with title and text properly set.
  *
  * @param string $message HTML string to add to the form
  * @param string $sessionKey Session key in case this is a stashed upload
  * @return UploadForm
  */
 protected function getUploadForm($message = '', $sessionKey = '', $hideIgnoreWarning = false)
 {
     global $wgOut;
     # Initialize form
     $form = new UploadForm(array('watch' => $this->getWatchCheck(), 'forreupload' => $this->mForReUpload, 'sessionkey' => $sessionKey, 'hideignorewarning' => $hideIgnoreWarning, 'destwarningack' => (bool) $this->mDestWarningAck, 'texttop' => $this->uploadFormTextTop, 'textaftersummary' => $this->uploadFormTextAfterSummary, 'destfile' => $this->mDesiredDestName));
     $form->setTitle($this->getTitle());
     # Check the token, but only if necessary
     if (!$this->mTokenOk && !$this->mCancelUpload && ($this->mUpload && $this->mUploadClicked)) {
         $form->addPreText(wfMsgExt('session_fail_preview', 'parseinline'));
     }
     # Add text to form
     $form->addPreText('<div id="uploadtext">' . wfMsgExt('uploadtext', 'parse', array($this->mDesiredDestName)) . '</div>');
     # Add upload error message
     $form->addPreText($message);
     # Add footer to form
     $uploadFooter = wfMsgNoTrans('uploadfooter');
     if ($uploadFooter != '-' && !wfEmptyMsg('uploadfooter', $uploadFooter)) {
         $form->addPostText('<div id="mw-upload-footer-message">' . $wgOut->parse($uploadFooter) . "</div>\n");
     }
     return $form;
 }
示例#13
0
        $this->caption = new Phorm_Field_Text('Caption', 50, 255);
    }
    public function save()
    {
        $data = $this->cleaned_data();
        $image_path = $data['image']->move_to($this->path);
        // do something with the data like saving it to a database...
        return $image_path;
    }
    public function report()
    {
        var_dump($this->cleaned_data());
    }
}
// Init form
$form = new UploadForm(UPLOAD_TARGET_DIRECTORY, 'post', TRUE);
// If the form is bound and valid, move the file to a more permanent location
$saved = NULL;
$file_error = NULL;
$photo_path = NULL;
if (($valid = $form->is_valid()) && $form->bound) {
    try {
        $photo_path = $form->save();
        $saved = TRUE;
    } catch (Exception $e) {
        $file_error = $e->message;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
示例#14
0
 /**
  * Get an UploadForm instance with title and text properly set.
  *
  * @param string $message HTML string to add to the form
  * @param string $sessionKey Session key in case this is a stashed upload
  * @param bool $hideIgnoreWarning Whether to hide "ignore warning" check box
  * @return UploadForm
  */
 protected function getUploadForm($message = '', $sessionKey = '', $hideIgnoreWarning = false)
 {
     # Initialize form
     $context = new DerivativeContext($this->getContext());
     $context->setTitle($this->getPageTitle());
     // Remove subpage
     $form = new UploadForm(array('watch' => $this->getWatchCheck(), 'forreupload' => $this->mForReUpload, 'sessionkey' => $sessionKey, 'hideignorewarning' => $hideIgnoreWarning, 'destwarningack' => (bool) $this->mDestWarningAck, 'description' => $this->mComment, 'texttop' => $this->uploadFormTextTop, 'textaftersummary' => $this->uploadFormTextAfterSummary, 'destfile' => $this->mDesiredDestName), $context);
     # Check the token, but only if necessary
     if (!$this->mTokenOk && !$this->mCancelUpload && ($this->mUpload && $this->mUploadClicked)) {
         $form->addPreText($this->msg('session_fail_preview')->parse());
     }
     # Give a notice if the user is uploading a file that has been deleted or moved
     # Note that this is independent from the message 'filewasdeleted' that requires JS
     $desiredTitleObj = Title::makeTitleSafe(NS_FILE, $this->mDesiredDestName);
     $delNotice = '';
     // empty by default
     if ($desiredTitleObj instanceof Title && !$desiredTitleObj->exists()) {
         LogEventsList::showLogExtract($delNotice, array('delete', 'move'), $desiredTitleObj, '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('upload-recreate-warning')));
     }
     $form->addPreText($delNotice);
     # Add text to form
     $form->addPreText('<div id="uploadtext">' . $this->msg('uploadtext', array($this->mDesiredDestName))->parseAsBlock() . '</div>');
     # Add upload error message
     $form->addPreText($message);
     # Add footer to form
     $uploadFooter = $this->msg('uploadfooter');
     if (!$uploadFooter->isDisabled()) {
         $form->addPostText('<div id="mw-upload-footer-message">' . $uploadFooter->parseAsBlock() . "</div>\n");
     }
     return $form;
 }
示例#15
0
 function processUpload()
 {
     global $wgUser, $wgOut, $wgLang, $wgContLang;
     global $wgUploadDirectory;
     global $wgUseCopyrightUpload, $wgCheckCopyrightUpload;
     global $up;
     /**
      * If there was no filename or a zero size given, give up quick.
      */
     if (trim($this->mOname) == '' || empty($this->mUploadSize)) {
         return $this->mainUploadForm('<li>' . wfMsg('emptyfile') . '</li>');
     }
     # 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) = UploadForm::splitExtensions($basename);
     if (count($ext)) {
         $finalExt = $ext[count($ext) - 1];
     } else {
         $finalExt = '';
     }
     $fullExt = implode('.', $ext);
     if (strlen($partname) < 3) {
         #$this->mainUploadForm( wfMsg( 'minlength' ) );
         return wfMsg('minlength') . " <b>" . $basename . "</b><br><br>";
     }
     /**
      * 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)) {
         #return $this->uploadError( wfMsg( 'illegalfilename', htmlspecialchars( $filtered ) ) );
         return wfMsg('illegalfilename', htmlspecialchars($filtered));
     }
     $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 wfMsg('protectedpage') . " <b>" . $basename . "</b><br><br>";
     }
     /* Don't allow users to override the blacklist (check file extension) */
     global $wgStrictFileExtensions;
     global $wgFileExtensions, $wgFileBlacklist;
     if (UploadForm::checkFileExtensionList($ext, $wgFileBlacklist) || $wgStrictFileExtensions && !UploadForm::checkFileExtension($finalExt, $wgFileExtensions)) {
         #return $this->uploadError( wfMsg( 'badfiletype', htmlspecialchars( $fullExt ) ) );
         return wfMsg('badfiletype', htmlspecialchars($fullExt) . " - <b>" . $basename . "</b><br><br>");
     }
     /**
      * 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) {
         $veri = $up->verify($this->mUploadTempName, $finalExt);
         if ($veri !== true) {
             //it's a wiki error...
             return $this->uploadError($veri->toString());
         }
     }
     /**
      * Check for non-fatal conditions
      */
     if (!$this->mIgnoreWarning) {
         $warning = '';
         global $wgCapitalLinks;
         if ($wgCapitalLinks) {
             $filtered = ucfirst($filtered);
         }
         if ($this->mUploadSaveName != $filtered) {
             $warning .= '<li>' . wfMsg('badfilename', htmlspecialchars($this->mUploadSaveName)) . '</li>';
         }
         global $wgCheckFileExtensions;
         if ($wgCheckFileExtensions) {
             if (!$up->checkFileExtension($finalExt, $wgFileExtensions)) {
                 $warning .= '<li>' . wfMsg('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>' . wfMsg('largefile', $wgUploadSizeWarning, $this->mUploadSize) . '</li>';
         }
         if ($this->mUploadSize == 0) {
             $warning .= '<li>' . wfMsg('emptyfile') . '</li>';
         }
         if ($nt->getArticleID()) {
             global $wgUser;
             $sk = $wgUser->getSkin();
             $dlink = $sk->makeKnownLinkObj($nt);
             $warning .= '<li>' . wfMsg('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 $warning . "<br />";
         }
     }
     /**
      * Try actually saving the thing...
      * It will show an error form on failure.
      */
     if ($up->saveUploadedFile($this->mUploadSaveName, $this->mUploadTempName, !empty($this->mSessionKey))) {
         /**
          * Update the upload log and create the description page
          * if it's a new file.
          */
         #$img = Image::newFromName( $this->mUploadSaveName );
         $success = $this->recordUpload($this->mUploadOldVersion, $this->mUploadDescription, $this->mUploadCopyStatus, $this->mUploadSource, $this->mWatchthis);
         if ($success) {
             # $this->showSuccess();
             # AWC - Edit...
             global $wgUser;
             $sk = $wgUser->getSkin();
             $dlink = $sk->makeKnownLinkObj($nt);
             return wfMsg('fileuploaded', $this->mUploadSaveName, $dlink) . "<br><br>";
         } else {
             // Image::recordUpload() fails if the image went missing, which is
             // unlikely, hence the lack of a specialised message
             $wgOut->fileNotFoundError($this->mUploadSaveName);
         }
     }
 }
示例#16
0
 /**
  * Print out the various links at the bottom of the image page, e.g. reupload,
  * external editing (and instructions link) etc.
  */
 function uploadLinksBox($writeIt = true)
 {
     global $wgUser, $wgOut, $wgTitle;
     if (!$this->img->isLocal()) {
         return;
     }
     $sk = $wgUser->getSkin();
     $html .= '<br /><ul>';
     # "Upload a new version of this file" link
     # Disabling upload a new version of this file link per Bug #585
     if (false && UploadForm::userCanReUpload($wgUser, $this->img->name)) {
         $ulink = $sk->makeExternalLink($this->getUploadUrl(), wfMsg('uploadnewversion-linktext'));
         $html .= "<li><div class='plainlinks'>{$ulink}</div></li>";
     }
     # External editing link
     //$elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
     //$wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
     //wikitext message
     $html .= '<li>' . wfMsg('image_instructions', $wgTitle->getFullText()) . '</li></ul>';
     if ($writeIt) {
         $wgOut->addHtml($html);
     } else {
         return $html;
     }
 }
示例#17
0
 /**
  * Print out the various links at the bottom of the image page, e.g. reupload,
  * external editing (and instructions link) etc.
  */
 protected function uploadLinksBox()
 {
     global $wgUser, $wgOut;
     $this->loadFile();
     if (!$this->img->isLocal()) {
         return;
     }
     $sk = $wgUser->getSkin();
     $wgOut->addHTML('<br /><ul>');
     # "Upload a new version of this file" link
     if (UploadForm::userCanReUpload($wgUser, $this->img->name)) {
         $ulink = $sk->makeExternalLink($this->getUploadUrl(), wfMsg('uploadnewversion-linktext'));
         $wgOut->addHTML("<li><div class='plainlinks'>{$ulink}</div></li>");
     }
     # Link to Special:FileDuplicateSearch
     $dupeLink = $sk->makeKnownLinkObj(SpecialPage::getTitleFor('FileDuplicateSearch', $this->mTitle->getDBkey()), wfMsgHtml('imagepage-searchdupe'));
     $wgOut->addHTML("<li>{$dupeLink}</li>");
     # External editing link
     $elink = $sk->makeKnownLinkObj($this->mTitle, wfMsgHtml('edit-externally'), 'action=edit&externaledit=true&mode=file');
     $wgOut->addHTML('<li>' . $elink . ' <small>' . wfMsgExt('edit-externally-help', array('parseinline')) . '</small></li>');
     $wgOut->addHTML('</ul>');
 }
示例#18
0
 protected function updateMenuItems($model = null)
 {
     // create static model if model is null
     if ($model == null) {
         $model = new UploadForm('install');
     }
     switch ($this->action->id) {
         case 'restore':
             $this->menu[] = array('label' => Yii::t('app', 'Inicio'), 'url' => Yii::app()->HomeUrl);
         case 'create':
             $this->menu[] = array('label' => Yii::t('app', 'Listar Respaldos') . ' ' . $model->label(2), 'url' => array('index'));
             break;
         case 'upload':
             $this->menu[] = array('label' => Yii::t('app', 'Crear Respaldo') . ' ' . $model->label(), 'url' => array('create'));
             break;
         default:
             $this->menu[] = array('label' => Yii::t('app', 'Listar Respaldos') . ' ' . $model->label(2), 'url' => array('index'));
             $this->menu[] = array('label' => Yii::t('app', 'Crear Respaldo') . ' ' . $model->label(), 'url' => array('create'));
             //$this->menu[] = array('label'=>Yii::t('app', 'Subir Respaldo') . ' ' . $model->label(), 'url'=>array('upload'));
             //$this->menu[] = array('label'=>Yii::t('app', 'Restaurar Respaldo') . ' ' . $model->label(), 'url'=>array('restore'));
             $this->menu[] = array('label' => Yii::t('app', 'Limpiar Base de Datos') . ' ' . $model->label(), 'url' => array('clean'));
             //$this->menu[] = array('label'=>Yii::t('app', 'Inicio') , 'url'=>Yii::app()->HomeUrl);
             break;
     }
 }
示例#19
0
 public function uploadFormAction()
 {
     $form = new UploadForm('upload-form');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             // Form is valid, save the form!
             return $this->redirect()->toRoute('product');
         }
     }
     return array('form' => $form);
 }
 /**
  * Really do the upload
  * Checks are made in SpecialUpload::execute()
  * @access private
  */
 function processUpload()
 {
     global $wgMaxUploadFiles, $wgOut;
     $wgOut->addHTML("<table>");
     $this->mShowUploadForm = false;
     for ($x = 0; $x < $wgMaxUploadFiles; $x++) {
         $this->mFileIndex = $x;
         if (!isset($this->mUploadTempNameArray[$x]) || $this->mUploadTempNameArray[$x] == null) {
             continue;
         }
         $this->mTempPath = $this->mUploadTempName = $this->mUploadTempNameArray[$x];
         $this->mFileSize = $this->mUploadSize = $this->mUploadSizeArray[$x];
         $this->mSrcName = $this->mOname = $this->mOnameArray[$x];
         $this->mUploadError = $this->mUploadErrorArray[$x];
         $this->mDesiredDestName = $this->mDestFileArray[$x];
         $this->mUploadDescription = $this->mUploadDescriptionArray[$x];
         $this->mComment = $this->mUploadDescriptionArray[$x];
         $this->mRemoveTempFile = true;
         $wgOut->addHTML("<tr><td>");
         parent::processUpload();
         $wgOut->addHTML("</td></tr>");
     }
     $wgOut->addHTML("</table>");
     $this->mShowUploadForm = false;
     $wgOut->redirect('');
     // clear the redirect, we want to show a nice page of images
     $this->mShowUploadForm = true;
     if ($this->mHasWarning) {
         $this->showWarningOptions();
     }
 }
示例#21
0
/**
 * Entry point
 */
function wfSpecialUpload()
{
    global $wgRequest;
    $form = new UploadForm($wgRequest);
    $form->execute();
}
示例#22
0
 /**
  * Print out the various links at the bottom of the image page, e.g. reupload,
  * external editing (and instructions link) etc.
  */
 function uploadLinksBox()
 {
     global $wgUser, $wgOut;
     if (!$this->img->isLocal()) {
         return;
     }
     $sk = $wgUser->getSkin();
     $wgOut->addHtml('<br /><ul>');
     # "Upload a new version of this file" link
     if (UploadForm::userCanReUpload($wgUser, $this->img->name)) {
         $ulink = $sk->makeExternalLink($this->getUploadUrl(), wfMsg('uploadnewversion-linktext'));
         $wgOut->addHtml("<li><div class='plainlinks'>{$ulink}</div></li>");
     }
     # External editing link
     $elink = $sk->makeKnownLinkObj($this->mTitle, wfMsgHtml('edit-externally'), 'action=edit&externaledit=true&mode=file');
     $wgOut->addHtml('<li>' . $elink . '<div>' . wfMsgWikiHtml('edit-externally-help') . '</div></li>');
     $wgOut->addHtml('</ul>');
 }
示例#23
0
 /** Generic wrapper function for a virus scanner program.
  * This relies on the $wgAntivirus and $wgAntivirusSetup variables.
  * $wgAntivirusRequired may be used to deny upload if the scan fails.
  *
  * @param string $file Pathname to the temporary upload file
  * @return mixed false if not virus is found, NULL if the scan fails or is disabled,
  *         or a string containing feedback from the virus scanner if a virus was found.
  *         If textual feedback is missing but a virus was found, this function returns true.
  */
 function detectVirus($file)
 {
     return UploadForm::detectVirus($file);
 }
示例#24
0
 protected function getDescriptionSection()
 {
     // get the usual one and clear out the DestFile
     $descriptor = parent::getDescriptionSection();
     unset($descriptor['DestFile']);
     return $descriptor;
 }
示例#25
0
    }
    protected function define_fields()
    {
        $this->image = new ImageField('Photo', 1024 * 1024, array('check_image_size'));
        $this->caption = new TextField('Caption', 50, 255);
    }
    public function save()
    {
        $data = $this->cleaned_data();
        $image_path = $data['image']->move_to($this->path);
        // do something with the data like saving it to a database...
        return $image_path;
    }
}
// Init form
$form = new UploadForm('/tmp', Phorm::POST, true);
// If the form is bound and valid, move the file to a more permanent location
$saved = null;
$file_error = null;
$photo_path = null;
if (($valid = $form->is_valid()) && $form->is_bound()) {
    try {
        $photo_path = $form->save();
        $saved = true;
    } catch (Exception $e) {
        $file_error = $e->message;
    }
}
?>
<html>
	<body>
示例#26
0
 /**
  * @since 1.1
  *
  * @param UploadForm $image
  *
  * @return true
  */
 public function onUploadComplete(UploadForm $image)
 {
     global $wgServerName, $wgScriptPath, $wgServer, $wgVersion;
     $urlServer = 'http://' . $wgServerName . $wgScriptPath;
     // $classe = get_class($image);
     if (compareMWVersion($wgVersion, '1.16.0') == -1) {
         $localfile = $image->mLocalFile;
     } else {
         $localfile = $image->getLocalFile();
     }
     $path = utils::prepareString($localfile->mime, $localfile->size, $wgServer . urldecode($localfile->url));
     if (!file_exists($path)) {
         $dbr = wfGetDB(DB_SLAVE);
         $lastRevision = Revision::loadFromTitle($dbr, $localfile->getTitle());
         if ($lastRevision->getPrevious() == null) {
             $rev_id = 0;
         } else {
             $rev_id = $lastRevision->getPrevious()->getId();
         }
         $revID = $lastRevision->getId();
         $model = DSMWRevisionManager::loadModel($rev_id);
         $patch = new DSMWPatch(false, true, null, $urlServer, $rev_id, null, null, null, $localfile->mime, $localfile->size, urldecode($localfile->url), null);
         $patch->storePage($localfile->getTitle(), $revID);
         // stores the patch in a wikipage
         DSMWRevisionManager::storeModel($revID, $sessionId = session_id(), $model, $blobCB = 0);
     }
     return true;
 }
	function execute() {
		// override MW's UploadForm with only the bits we want
		global $wgOut, $wgStylePath, $wgRequest;
		$wgOut->setArticleBodyOnly(true);
		$wgOut->addHTML("
 			<html>
                <head>
                    <title>". wfMsg('ct_upload', htmlspecialchars( $this->mType ) ) . " </title>
                </head>
            	<body>");
		$wgOut->addHTML("<h2>". wfMsg('ct_upload', htmlspecialchars( $this->mType ) ) . " </h2>");
		UploadForm::execute();
		$titleObj = SpecialPage::getTitleFor( 'CustomToolbarUpload' );
        $wgOut->addHTML("
				<script type='text/javascript'>
				var myForm = document.getElementById('uploadwarning');
				if(myForm != null) {
					myForm.action='".$titleObj->getLocalURL( 'action=submit' )."';
					var el = document.createElement('input');
				    el.type = 'hidden';
				    el.name = 'wpDestFileWarningAck';
				    el.value = '".$wgRequest->GetVal("wpDestFileWarningAck")."';
					el.id = 'wpDestFileWarningAck'
				    myForm.appendChild(el);
					
					var el2 = document.createElement('input');
				    el2.type = 'hidden';
				    el2.name = 'wpDestFile';
				    el2.value = '".$wgRequest->GetVal("wpDestFile")."';
					el2.id = 'wpDestFile'
				    myForm.appendChild(el2);
					
					var el3 = document.createElement('input');
				    el3.type = 'hidden';
				    el3.name = 'type';
				    el3.value = '".$wgRequest->GetVal("type")."';
					el3.id = 'type'
				    myForm.appendChild(el3);
				}
				</script>
				</body>
        	</html>");
	}
示例#28
0
 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;
 }