Exemplo n.º 1
0
/**
 * Used to write out a DokuWiki page to file, and send IO_WIKIPAGE_WRITE events.
 *
 * This generates an action event and delegates to io_saveFile().
 * Action plugins are allowed to modify the page content in transit.
 * The file path should not be changed.
 * (The append parameter is set to false.)
 *
 * Event data:
 * $data[0]    The raw arguments for io_saveFile as an array.
 * $data[1]    ns: The colon separated namespace path minus the trailing page name. (false if root ns)
 * $data[2]    page_name: The wiki page name.
 * $data[3]    rev: The page revision, false for current wiki pages.
 *
 * @author Ben Coburn <*****@*****.**>
 */
function io_writeWikiPage($file, $content, $id, $rev = false)
{
    if (empty($rev)) {
        $rev = false;
    }
    if ($rev === false) {
        io_createNamespace($id);
    }
    // create namespaces as needed
    $data = array(array($file, $content, false), getNS($id), noNS($id), $rev);
    return trigger_event('IO_WIKIPAGE_WRITE', $data, '_io_writeWikiPage_action', false);
}
Exemplo n.º 2
0
function ajax_mediaupload()
{
    global $NS, $MSG, $INPUT;
    if ($_FILES['qqfile']['tmp_name']) {
        $id = $INPUT->post->str('mediaid', $_FILES['qqfile']['name']);
    } elseif ($INPUT->get->has('qqfile')) {
        $id = $INPUT->get->str('qqfile');
    }
    $id = cleanID($id);
    $NS = $INPUT->str('ns');
    $ns = $NS . ':' . getNS($id);
    $AUTH = auth_quickaclcheck("{$ns}:*");
    if ($AUTH >= AUTH_UPLOAD) {
        io_createNamespace("{$ns}:xxx", 'media');
    }
    if ($_FILES['qqfile']['error']) {
        unset($_FILES['qqfile']);
    }
    if ($_FILES['qqfile']['tmp_name']) {
        $res = media_upload($NS, $AUTH, $_FILES['qqfile']);
    }
    if ($INPUT->get->has('qqfile')) {
        $res = media_upload_xhr($NS, $AUTH);
    }
    if ($res) {
        $result = array('success' => true, 'link' => media_managerURL(array('ns' => $ns, 'image' => $NS . ':' . $id), '&'), 'id' => $NS . ':' . $id, 'ns' => $NS);
    }
    if (!$result) {
        $error = '';
        if (isset($MSG)) {
            foreach ($MSG as $msg) {
                $error .= $msg['msg'];
            }
        }
        $result = array('error' => $msg['msg'], 'ns' => $NS);
    }
    $json = new JSON();
    echo htmlspecialchars($json->encode($result), ENT_NOQUOTES);
}
Exemplo n.º 3
0
 /**
  * Moves the temporary file to its final destination.
  *
  * Michael Klier <*****@*****.**>
  */
 function _media_upload_action($data)
 {
     global $conf;
     if (is_array($data) && count($data) === 5) {
         io_createNamespace($data[2], 'media');
         if (rename($data[0], $data[1])) {
             chmod($data[1], $conf['fmode']);
             media_notify($data[2], $data[1], $data[3]);
             // add a log entry to the media changelog
             if ($data[4]) {
                 addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT);
             } else {
                 addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE);
             }
             return $data[2];
         } else {
             return new IXR_ERROR(1, 'Upload failed.');
         }
     } else {
         return new IXR_ERROR(1, 'Upload failed.');
     }
 }
Exemplo n.º 4
0
/**
 * Saves an uploaded media file
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Michael Klier <*****@*****.**>
 * @author Kate Arzamastseva <*****@*****.**>
 */
function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'move_uploaded_file')
{
    global $conf;
    global $lang;
    global $REV;
    $old = @filemtime($fn);
    if (!@file_exists(mediaFN($id, $old)) && @file_exists($fn)) {
        // add old revision to the attic if missing
        media_saveOldRevision($id);
    }
    // prepare directory
    io_createNamespace($id, 'media');
    if ($move($fn_tmp, $fn)) {
        @clearstatcache(true, $fn);
        $new = @filemtime($fn);
        // Set the correct permission here.
        // Always chmod media because they may be saved with different permissions than expected from the php umask.
        // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
        chmod($fn, $conf['fmode']);
        msg($lang['uploadsucc'], 1);
        media_notify($id, $fn, $imime, $old);
        // add a log entry to the media changelog
        if ($REV) {
            addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_REVERT, sprintf($lang['restored'], dformat($REV)), $REV);
        } elseif ($overwrite) {
            addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_EDIT);
        } else {
            addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']);
        }
        return $id;
    } else {
        return array($lang['uploadfail'], -1);
    }
}
Exemplo n.º 5
0
    $NS = getNS($DEL);
} elseif ($_REQUEST['edit']) {
    $IMG = cleanID($_REQUEST['edit']);
    $NS = getNS($IMG);
} elseif ($_REQUEST['img']) {
    $IMG = cleanID($_REQUEST['img']);
    $NS = getNS($IMG);
} else {
    $NS = $_REQUEST['ns'];
    $NS = cleanID($NS);
}
// check auth
$AUTH = auth_quickaclcheck("{$NS}:*");
// create the given namespace (just for beautification)
if ($AUTH >= AUTH_UPLOAD) {
    io_createNamespace("{$NS}:xxx", 'media');
}
// handle flash upload
if (isset($_FILES['Filedata'])) {
    $_FILES['upload'] =& $_FILES['Filedata'];
    $JUMPTO = media_upload($NS, $AUTH);
    if ($JUMPTO == false) {
        header("HTTP/1.0 400 Bad Request");
        echo 'Upload failed';
    }
    echo 'ok';
    exit;
}
// give info on PHP catched upload errors
if ($_FILES['upload']['error']) {
    switch ($_FILES['upload']['error']) {
Exemplo n.º 6
0
function ajax_mediaupload()
{
    global $NS, $MSG;
    if ($_FILES['qqfile']['tmp_name']) {
        $id = empty($_POST['mediaid']) ? $_FILES['qqfile']['name'] : $_POST['mediaid'];
    } elseif (isset($_GET['qqfile'])) {
        $id = $_GET['qqfile'];
    }
    $id = cleanID($id, false, true);
    $NS = $_REQUEST['ns'];
    $ns = $NS . ':' . getNS($id);
    $AUTH = auth_quickaclcheck("{$ns}:*");
    if ($AUTH >= AUTH_UPLOAD) {
        io_createNamespace("{$ns}:xxx", 'media');
    }
    if ($_FILES['qqfile']['error']) {
        unset($_FILES['qqfile']);
    }
    if ($_FILES['qqfile']['tmp_name']) {
        $res = media_upload($NS, $AUTH, $_FILES['qqfile']);
    }
    if (isset($_GET['qqfile'])) {
        $res = media_upload_xhr($NS, $AUTH);
    }
    if ($res) {
        $result = array('success' => true, 'link' => media_managerURL(array('ns' => $ns, 'image' => $NS . ':' . $id), '&'), 'id' => $NS . ':' . $id, 'ns' => $NS);
    }
    if (!$result) {
        $error = '';
        if (isset($MSG)) {
            foreach ($MSG as $msg) {
                $error .= $msg['msg'];
            }
        }
        $result = array('error' => $msg['msg'], 'ns' => $NS);
    }
    echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
}
Exemplo n.º 7
0
/**
 * Saves an uploaded media file
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Michael Klier <*****@*****.**>
 */
function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite)
{
    global $conf;
    global $lang;
    // prepare directory
    io_createNamespace($id, 'media');
    if (move_uploaded_file($fn_tmp, $fn)) {
        // Set the correct permission here.
        // Always chmod media because they may be saved with different permissions than expected from the php umask.
        // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
        chmod($fn, $conf['fmode']);
        msg($lang['uploadsucc'], 1);
        media_notify($id, $fn, $imime);
        // add a log entry to the media changelog
        if ($overwrite) {
            addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_EDIT);
        } else {
            addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_CREATE);
        }
        return $id;
    } else {
        msg($lang['uploadfail'], -1);
    }
}
Exemplo n.º 8
0
 /**
  * Execute a media file move/rename
  *
  * @param string $src original ID
  * @param string $dst new ID
  * @return bool true if the move was successfully executed
  */
 public function moveMedia($src, $dst)
 {
     if (!$this->checkMedia($src, $dst)) {
         return false;
     }
     // get all pages using this media
     $affected_pages = idx_get_indexer()->lookupKey('relation_media', $src);
     $src_ns = getNS($src);
     $src_name = noNS($src);
     $dst_ns = getNS($dst);
     $dst_name = noNS($dst);
     // pass this info on to other plugins
     $eventdata = array('opts' => array('ns' => $src_ns, 'name' => $src_name, 'newns' => $dst_ns, 'newname' => $dst_name), 'affected_pages' => &$affected_pages, 'src_id' => $src, 'dst_id' => $dst);
     // give plugins the option to add their own meta files to the list of files that need to be moved
     // to the oldfiles/newfiles array or to adjust their own metadata, database, ...
     // and to add other pages to the affected pages
     $event = new Doku_Event('PLUGIN_MOVE_MEDIA_RENAME', $eventdata);
     if ($event->advise_before()) {
         /** @var helper_plugin_move_file $FileMover */
         $FileMover = plugin_load('helper', 'move_file');
         /** @var helper_plugin_move_rewrite $Rewriter */
         $Rewriter = plugin_load('helper', 'move_rewrite');
         // Move the Subscriptions & Indexes (new feature since Spring 2013 release)
         $Indexer = idx_get_indexer();
         if (($idx_msg = $Indexer->renameMetaValue('relation_media', $src, $dst)) !== true) {
             msg(sprintf($this->getLang('indexerror'), $idx_msg), -1);
             return false;
         }
         if (!$FileMover->moveMediaMeta($src_ns, $src_name, $dst_ns, $dst_name)) {
             msg(sprintf($this->getLang('mediametamoveerror'), $src), -1);
             return false;
         }
         // prepare directory
         io_createNamespace($dst, 'media');
         // move it FIXME this does not create a changelog entry!
         if (!io_rename(mediaFN($src), mediaFN($dst))) {
             msg(sprintf($this->getLang('mediamoveerror'), $src), -1);
             return false;
         }
         // clean up old ns
         io_sweepNS($src, 'mediadir');
         // Move the old revisions
         if (!$FileMover->moveMediaAttic($src_ns, $src_name, $dst_ns, $dst_name)) {
             // it's too late to stop the move, so just display a message.
             msg(sprintf($this->getLang('mediaatticmoveerror'), $src), -1);
         }
         // Add meta data to all affected pages, so links get updated later
         foreach ($affected_pages as $id) {
             $Rewriter->setMoveMeta($id, $src, $dst, 'media');
         }
     }
     $event->advise_after();
     // store this for later use
     $this->affectedPages = $affected_pages;
     return true;
 }
Exemplo n.º 9
0
    /**
     * Move media file
     *
     * @author  Michael Hamann <*****@*****.**>
     *
     * @param array $opts
     * @param bool  $checkonly Only execute the checks if the media file can be moved
     * @return bool If the move was executed
     */
    public function move_media(&$opts, $checkonly = false) {
        $opts['id'] = cleanID($opts['ns'].':'.$opts['name']);
        $opts['path'] = mediaFN($opts['id']);

        // Check we have rights to move this document
        if ( !file_exists(mediaFN($opts['id']))) {
            msg(sprintf($this->getLang('medianotexist'), hsc($opts['id'])), -1);
            return false;
        }

        if ( auth_quickaclcheck($opts['ns'].':*') < AUTH_DELETE ) {
            msg(sprintf($this->getLang('nomediarights'), hsc($opts['id'])), -1);
            return false;
        }

        // Assemble media name and path
        $opts['new_id'] = cleanID($opts['newns'].':'.$opts['newname']);
        $opts['new_path'] = mediaFN($opts['new_id']);

        // Has the document name and/or namespace changed?
        if ( $opts['newns'] == $opts['ns'] && $opts['newname'] == $opts['name'] ) {
            msg($this->getLang('nomediachange'), -1);
            return false;
        }
        // Check the page does not already exist
        if ( @file_exists($opts['new_path']) ) {
            msg(sprintf($this->getLang('mediaexisting'), $opts['newname'], ($opts['newns'] == '' ? $this->getLang('root') : $opts['newns'])), -1);
            return false;
        }

        // Check if the current user can create the new page
        if (auth_quickaclcheck($opts['new_ns'].':*') < AUTH_UPLOAD) {
            msg(sprintf($this->getLang('nomediatargetperms'), $opts['new_id']), -1);
            return false;
        }

        if ($checkonly) return true;

        /**
         * End of init (checks)
         */

        $affected_pages = idx_get_indexer()->lookupKey('relation_media', $opts['id']);

        $data = array('opts' => &$opts, 'affected_pages' => &$affected_pages);
        // give plugins the option to add their own meta files to the list of files that need to be moved
        // to the oldfiles/newfiles array or to adjust their own metadata, database, ...
        // and to add other pages to the affected pages
        $event = new Doku_Event('PLUGIN_MOVE_MEDIA_RENAME', $data);
        if ($event->advise_before()) {
            // Move the Subscriptions & Indexes
            if (method_exists('Doku_Indexer', 'renamePage')) { // new feature since Spring 2013 release
                $Indexer = idx_get_indexer();
            } else {
                $Indexer = new helper_plugin_move_indexer(); // copy of the new code
            }
            if (($idx_msg = $Indexer->renameMetaValue('relation_media', $opts['id'], $opts['new_id'])) !== true) {
                msg('Error while updating the search index '.$idx_msg, -1);
                return false;
            }
            if (!$this->movemediameta($opts)) {
                msg('The meta files of the media file '.$opts['id'].' couldn\'t be moved', -1);
                return false;
            }

            // prepare directory
            io_createNamespace($opts['new_id'], 'media');

            if (!io_rename($opts['path'], $opts['new_path'])) {
                msg('Moving the media file '.$opts['id'].' failed', -1);
                return false;
            }

            io_sweepNS($opts['id'], 'mediadir');

            // Move the old revisions
            if (!$this->movemediaattic($opts)) {
                // it's too late to stop the move, so just display a message.
                msg('The attic files of media file '.$opts['id'].' couldn\'t be moved. Please move them manually.', -1);
            }

            foreach ($affected_pages as $id) {
                if (!page_exists($id, '', false)) continue;
                $meta = $this->getMoveMeta($id);
                if (!$meta) $meta = array('media_moves' => array());
                if (!isset($meta['media_moves'])) $meta['media_moves'] = array();
                $meta['media_moves'] = $this->resolve_moves($meta['media_moves'], '__');
                $meta['media_moves'][$opts['id']] = $opts['new_id'];
                //if (empty($meta['moves'])) unset($meta['moves']);
                p_set_metadata($id, array('plugin_move' => $meta), false, true);
            }
        }

        $event->advise_after();
        return true;
    }
Exemplo n.º 10
0
/**
 * Saves an uploaded media file
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Michael Klier <*****@*****.**>
 */
function media_upload_finish($fn_tmp, $fn, $id, $imime)
{
    global $conf;
    global $lang;
    // prepare directory
    io_createNamespace($id, 'media');
    if (move_uploaded_file($fn_tmp, $fn)) {
        // Set the correct permission here.
        // Always chmod media because they may be saved with different permissions than expected from the php umask.
        // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
        chmod($fn, $conf['fmode']);
        msg($lang['uploadsucc'], 1);
        media_notify($id, $fn, $imime);
        return $id;
    } else {
        msg($lang['uploadfail'], -1);
    }
}