/**
 * Add's an entry to the changelog and saves the metadata for the page
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Esther Brunner <*****@*****.**>
 * @author Ben Coburn <*****@*****.**>
 */
function addLogEntry($date, $id, $type = DOKU_CHANGE_TYPE_EDIT, $summary = '', $extra = '', $flags = null)
{
    global $conf, $INFO;
    // check for special flags as keys
    if (!is_array($flags)) {
        $flags = array();
    }
    $flagExternalEdit = isset($flags['ExternalEdit']);
    $id = cleanid($id);
    $file = wikiFN($id);
    $created = @filectime($file);
    $minor = $type === DOKU_CHANGE_TYPE_MINOR_EDIT;
    $wasRemoved = $type === DOKU_CHANGE_TYPE_DELETE;
    if (!$date) {
        $date = time();
    }
    //use current time if none supplied
    $remote = !$flagExternalEdit ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
    $user = !$flagExternalEdit ? $_SERVER['REMOTE_USER'] : '';
    $strip = array("\t", "\n");
    $logline = array('date' => $date, 'ip' => $remote, 'type' => str_replace($strip, '', $type), 'id' => $id, 'user' => $user, 'sum' => str_replace($strip, '', $summary), 'extra' => str_replace($strip, '', $extra));
    // update metadata
    if (!$wasRemoved) {
        $oldmeta = p_read_metadata($id);
        $meta = array();
        if (!$INFO['exists'] && empty($oldmeta['persistent']['date']['created'])) {
            // newly created
            $meta['date']['created'] = $created;
            if ($user) {
                $meta['creator'] = $INFO['userinfo']['name'];
            }
        } elseif (!$INFO['exists'] && !empty($oldmeta['persistent']['date']['created'])) {
            // re-created / restored
            $meta['date']['created'] = $oldmeta['persistent']['date']['created'];
            $meta['date']['modified'] = $created;
            // use the files ctime here
            $meta['creator'] = $oldmeta['persistent']['creator'];
            if ($user) {
                $meta['contributor'][$user] = $INFO['userinfo']['name'];
            }
        } elseif (!$minor) {
            // non-minor modification
            $meta['date']['modified'] = $date;
            if ($user) {
                $meta['contributor'][$user] = $INFO['userinfo']['name'];
            }
        }
        $meta['last_change'] = $logline;
        p_set_metadata($id, $meta, true);
    }
    // add changelog lines
    $logline = implode("\t", $logline) . "\n";
    io_saveFile(metaFN($id, '.changes'), $logline, true);
    //page changelog
    io_saveFile($conf['changelog'], $logline, true);
    //global changelog cache
}
Exemple #2
0
/**
 * Add's an entry to the media changelog
 *
 * @author Michael Hamann <*****@*****.**>
 * @author Andreas Gohr <*****@*****.**>
 * @author Esther Brunner <*****@*****.**>
 * @author Ben Coburn <*****@*****.**>
 */
function addMediaLogEntry($date, $id, $type = DOKU_CHANGE_TYPE_EDIT, $summary = '', $extra = '', $flags = null)
{
    global $conf;
    $id = cleanid($id);
    if (!$date) {
        $date = time();
    }
    //use current time if none supplied
    $remote = clientIP(true);
    $user = $_SERVER['REMOTE_USER'];
    $strip = array("\t", "\n");
    $logline = array('date' => $date, 'ip' => $remote, 'type' => str_replace($strip, '', $type), 'id' => $id, 'user' => $user, 'sum' => utf8_substr(str_replace($strip, '', $summary), 0, 255), 'extra' => str_replace($strip, '', $extra));
    // add changelog lines
    $logline = implode("\t", $logline) . "\n";
    io_saveFile($conf['media_changelog'], $logline, true);
    //global media changelog cache
    io_saveFile(mediaMetaFN($id, '.changes'), $logline, true);
    //media file's changelog
}