/**
  * Wrapper to set permissions on wiki attachments.
  */
 function setWikiAttachmentPerms()
 {
     global $feedback;
     $wa = new WikiAttachment($this->gid);
     $wa->initWithId($_POST['object_id']);
     if ($_POST['reset']) {
         $ret = $wa->resetPermissions();
     } else {
         $ret = $wa->setPermissions($_POST['ugroups']);
     }
     if (!$ret) {
         exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('wiki_actions_wikiserviceadmin', 'update_attachment_perm_err', array($feedback)));
     }
 }
 /**
  * 
  */
 function getFilename()
 {
     if (empty($this->filename)) {
         $wa = new WikiAttachment();
         // @todo: catch error when wiki no attachementId is set.
         $wa->initWithId($this->attachmentId);
         // @todo: catch error when given attchId do not exist
         $this->displayFilename = $wa->getFilename();
         $this->filename = $wa->getFilesystemName();
     }
     return $this->filename;
 }
    /**
     * @access public
     */
    function browseAttachment()
    {
        $attachmentId = (int) $_GET['id'];
        $wa = new WikiAttachment($this->gid);
        $wa->initWithId($attachmentId);
        echo $GLOBALS['Language']->getText('wiki_views_wkserviews', 'browse_attachment_title', array($this->wikiname, $wa->getFilename()));
        // if($wari->exist()) {
        print html_build_list_table_top(array($GLOBALS['Language']->getText('wiki_views_wkserviews', 'attachment_revision'), $GLOBALS['Language']->getText('wiki_views_wkserviews', 'attachment_date'), $GLOBALS['Language']->getText('wiki_views_wkserviews', 'attachment_author'), $GLOBALS['Language']->getText('wiki_views_wkserviews', 'attachment_size')));
        $wari =& WikiAttachmentRevision::getRevisionIterator($this->gid, $attachmentId);
        $wari->rewind();
        while ($wari->valid()) {
            $war =& $wari->current();
            print '
             <tr>
	       <td><a href="/wiki/uploads/' . $this->gid . '/' . $wa->getFilename() . '/' . ($war->getRevision() + 1) . '">' . ($war->getRevision() + 1) . '</a></td>
	       <td>' . strftime("%e %b %Y %H:%M", $war->getDate()) . '</td>
               <td><a href="/users/' . user_getname($war->getOwnerId()) . '/">' . user_getname($war->getOwnerId()) . '</td>
	       <td>' . $war->getSize() . '</td>
	     </tr>';
            $wari->next();
        }
        print '</table>';
        // }
        // else {
        //   print 'not found';
        // }
        print '<hr/><p><a href="' . $this->wikiAdminLink . '&view=wikiAttachments">' . $GLOBALS['Language']->getText('wiki_views_wkserviews', 'back_admin') . '</a></p>' . "\n";
    }
function wiki_attachment_restore_process($request, $group_id)
{
    $attachmentId = $request->getValidated('id', 'uint', 0);
    if ($attachmentId > 0) {
        $wikiAttachment = new WikiAttachment($group_id);
        $wikiAttachment->initWithId($attachmentId);
        if ($wikiAttachment->restoreDeletedAttachment($attachmentId)) {
            $GLOBALS['Response']->addFeedback('info', 'Wiki attachment restored');
        } else {
            $GLOBALS['Response']->addFeedback('error', 'Wiki attachment not restored');
        }
    } else {
        $GLOBALS['Response']->addFeedback('error', 'Bad attachment id');
    }
    $GLOBALS['Response']->redirect('?group_id=' . $group_id . '&focus=wiki_attachment');
}
Пример #5
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $this->disallowed_extensions = explode("\n", "ad[ep]\nasd\nba[st]\nchm\ncmd\ncom\ncgi\ncpl\ncrt\ndll\neml\nexe\nhlp\nhta\nin[fs]\nisp\njse?\nlnk\nmd[betw]\nms[cipt]\nnws\nocx\nops\npcd\np[ir]f\nphp\npl\npy\nreg\nsc[frt]\nsh[bsm]?\nswf\nurl\nvb[esx]?\nvxd\nws[cfh]");
     //removed "\{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\}"
     $args = $this->getArgs($argstr, $request);
     extract($args);
     $file_dir = getUploadFilePath();
     //$url_prefix = SERVER_NAME . DATA_PATH;
     $form = HTML::form(array('action' => $request->getPostURL(), 'enctype' => 'multipart/form-data', 'method' => 'post'));
     $contents = HTML::div(array('class' => 'wikiaction'));
     $contents->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => MAX_UPLOAD_SIZE)));
     /// MV add pv
     /// @todo: have a generic method to transmit pv
     if (!empty($_REQUEST['pv'])) {
         $contents->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'pv', 'value' => $_REQUEST['pv'])));
     }
     $contents->pushContent(HTML::input(array('name' => 'userfile', 'type' => 'file', 'size' => '50')));
     $contents->pushContent(HTML::raw(" "));
     $contents->pushContent(HTML::input(array('value' => _("Upload"), 'type' => 'submit')));
     $form->pushContent($contents);
     $message = HTML();
     if ($request->isPost() and $this->only_authenticated) {
         // Make sure that the user is logged in.
         $user = $request->getUser();
         if (!$user->isAuthenticated()) {
             $message->pushContent(HTML::h2(_("ACCESS DENIED: You must log in to upload files.")), HTML::br(), HTML::br());
             $result = HTML();
             $result->pushContent($form);
             $result->pushContent($message);
             return $result;
         }
     }
     $userfile = $request->getUploadedFile('userfile');
     if ($userfile) {
         $userfile_name = $userfile->getName();
         $userfile_name = trim(basename($userfile_name));
         $userfile_tmpname = $userfile->getTmpName();
         $err_header = HTML::h2(fmt("ERROR uploading '%s': ", $userfile_name));
         /// MV add
         /// Wiki attachments
         $wa = new WikiAttachment(GROUP_ID);
         $rev = $wa->createRevision($userfile_name, $userfile->getSize(), $userfile->getType(), $userfile->getTmpName());
         if ($rev >= 0) {
             $prev = $rev + 1;
             $interwiki = new PageType_interwikimap();
             $link = $interwiki->link("Upload:{$prev}/{$userfile_name}");
             $message->pushContent(HTML::h2(_("File successfully uploaded.")));
             $message->pushContent(HTML::ul(HTML::li($link)));
             // the upload was a success and we need to mark this event in the "upload log"
             if ($logfile) {
                 $upload_log = $file_dir . basename($logfile);
                 $this->log($userfile, $upload_log, $message);
             }
             if ($autolink) {
                 require_once "lib/loadsave.php";
                 $pagehandle = $dbi->getPage($page);
                 if ($pagehandle->exists()) {
                     // don't replace default contents
                     $current = $pagehandle->getCurrentRevision();
                     $version = $current->getVersion();
                     $text = $current->getPackedContent();
                     $newtext = $text . "\n* [Upload:{$userfile_name}]";
                     $meta = $current->_data;
                     $meta['summary'] = sprintf(_("uploaded %s"), $userfile_name);
                     $pagehandle->save($newtext, $version + 1, $meta);
                 }
             }
         } else {
             $message->pushContent($err_header);
             $message->pushContent(HTML::br(), _("Uploading failed."), HTML::br());
         }
     } else {
         $message->pushContent(HTML::br(), HTML::br());
     }
     /// {{{ Codendi Specific
     // URL arguments
     if (array_key_exists('offset', $_REQUEST)) {
         $offset = $_REQUEST['offset'];
     } else {
         $offset = 0;
     }
     if (array_key_exists('limit', $_REQUEST)) {
         $limit = $_REQUEST['limit'];
     } else {
         $limit = 10;
     }
     $attchTab = HTML::table(array('border' => '1', 'width' => '100%'));
     $attchTab->pushContent(HTML::tr(HTML::th(_("Attachment")), HTML::th(_("Number of revision"))));
     $wai =& WikiAttachment::getListWithCounter(GROUP_ID, user_getid(), array('offset' => $offset, 'nb' => $limit));
     $wai->rewind();
     while ($wai->valid()) {
         $wa =& $wai->current();
         $filename = basename($wa->getFilename());
         $url = getUploadDataPath() . urlencode($filename);
         $line = HTML::tr();
         $line->pushContent(HTML::td(HTML::a(array('href' => $url), "Attach:" . $filename)));
         $line->pushContent(HTML::td($wa->count()));
         $attchTab->pushContent($line);
         $wai->next();
     }
     $attchList = HTML();
     $attchList->pushContent(HTML::hr(), HTML::h2(_("Attached files")));
     $attchList->pushContent($attchTab);
     $url = WikiURL("UpLoad");
     if (!empty($_REQUEST['pv'])) {
         $url .= '&pv=' . $_REQUEST['pv'];
     }
     $attchList->pushContent(HTML::a(array('href' => $url . '&offset=' . ($offset - $limit)), "<- Previous"));
     $attchList->pushContent(" - ");
     $attchList->pushContent(HTML::a(array('href' => $url . '&offset=' . ($offset + $limit)), "Next ->"));
     /// }}}
     //$result = HTML::div( array( 'class' => 'wikiaction' ) );
     $result = HTML();
     $result->pushContent($form);
     $result->pushContent($message);
     $result->pushContent($attchList);
     return $result;
 }
Пример #6
0
 /**
  * Purge the attachments from FS and DB
  *
  * @param Integer $time
  *
  * @return Boolean
  */
 public function purgeAttachments($time)
 {
     $dao = $this->getDao();
     $dar = $dao->searchAttachmentToPurge($time);
     if ($dar && !$dar->isError()) {
         $purgeState = true;
         if ($dar->rowCount() > 0) {
             foreach ($dar as $row) {
                 $attachment = new WikiAttachment($this->gid);
                 $attachment->setFromRow($row);
                 $purgeState = $purgeState & $attachment->purgeAttachment();
             }
         }
         return $purgeState;
     }
     return false;
 }