Ejemplo n.º 1
0
/**
 * Handle page 'subscribe'
 *
 * Throws exception on error.
 *
 * @author Adrian Lang <*****@*****.**>
 *
 * @param string $act action command
 * @return string action command
 * @throws Exception if (un)subscribing fails
 */
function act_subscription($act)
{
    global $lang;
    global $INFO;
    global $ID;
    /* @var Input $INPUT */
    global $INPUT;
    // subcriptions work for logged in users only
    if (!$INPUT->server->str('REMOTE_USER')) {
        return 'show';
    }
    // get and preprocess data.
    $params = array();
    foreach (array('target', 'style', 'action') as $param) {
        if ($INPUT->has("sub_{$param}")) {
            $params[$param] = $INPUT->str("sub_{$param}");
        }
    }
    // any action given? if not just return and show the subscription page
    if (empty($params['action']) || !checkSecurityToken()) {
        return $act;
    }
    // Handle POST data, may throw exception.
    trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, 'subscription_handle_post');
    $target = $params['target'];
    $style = $params['style'];
    $action = $params['action'];
    // Perform action.
    $sub = new Subscription();
    if ($action == 'unsubscribe') {
        $ok = $sub->remove($target, $INPUT->server->str('REMOTE_USER'), $style);
    } else {
        $ok = $sub->add($target, $INPUT->server->str('REMOTE_USER'), $style);
    }
    if ($ok) {
        msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), prettyprint_id($target)), 1);
        act_redirect($ID, $act);
    } else {
        throw new Exception(sprintf($lang["subscr_{$action}_error"], hsc($INFO['userinfo']['name']), prettyprint_id($target)));
    }
    // Assure that we have valid data if act_redirect somehow fails.
    $INFO['subscribed'] = $sub->user_subscription();
    return 'show';
}
Ejemplo n.º 2
0
/**
 * Return info about the current document as associative
 * array.
 *
 * @author Andreas Gohr <*****@*****.**>
 *
 * @return array with info about current document
 */
function pageinfo()
{
    global $ID;
    global $REV;
    global $RANGE;
    global $lang;
    /* @var Input $INPUT */
    global $INPUT;
    $info = basicinfo($ID);
    // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml
    // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary
    $info['id'] = $ID;
    $info['rev'] = $REV;
    if ($INPUT->server->has('REMOTE_USER')) {
        $sub = new Subscription();
        $info['subscribed'] = $sub->user_subscription();
    } else {
        $info['subscribed'] = false;
    }
    $info['locked'] = checklock($ID);
    $info['filepath'] = fullpath(wikiFN($ID));
    $info['exists'] = file_exists($info['filepath']);
    $info['currentrev'] = @filemtime($info['filepath']);
    if ($REV) {
        //check if current revision was meant
        if ($info['exists'] && $info['currentrev'] == $REV) {
            $REV = '';
        } elseif ($RANGE) {
            //section editing does not work with old revisions!
            $REV = '';
            $RANGE = '';
            msg($lang['nosecedit'], 0);
        } else {
            //really use old revision
            $info['filepath'] = fullpath(wikiFN($ID, $REV));
            $info['exists'] = file_exists($info['filepath']);
        }
    }
    $info['rev'] = $REV;
    if ($info['exists']) {
        $info['writable'] = is_writable($info['filepath']) && $info['perm'] >= AUTH_EDIT;
    } else {
        $info['writable'] = $info['perm'] >= AUTH_CREATE;
    }
    $info['editable'] = $info['writable'] && empty($info['locked']);
    $info['lastmod'] = @filemtime($info['filepath']);
    //load page meta data
    $info['meta'] = p_get_metadata($ID);
    //who's the editor
    $pagelog = new PageChangeLog($ID, 1024);
    if ($REV) {
        $revinfo = $pagelog->getRevisionInfo($REV);
    } else {
        if (!empty($info['meta']['last_change']) && is_array($info['meta']['last_change'])) {
            $revinfo = $info['meta']['last_change'];
        } else {
            $revinfo = $pagelog->getRevisionInfo($info['lastmod']);
            // cache most recent changelog line in metadata if missing and still valid
            if ($revinfo !== false) {
                $info['meta']['last_change'] = $revinfo;
                p_set_metadata($ID, array('last_change' => $revinfo));
            }
        }
    }
    //and check for an external edit
    if ($revinfo !== false && $revinfo['date'] != $info['lastmod']) {
        // cached changelog line no longer valid
        $revinfo = false;
        $info['meta']['last_change'] = $revinfo;
        p_set_metadata($ID, array('last_change' => $revinfo));
    }
    $info['ip'] = $revinfo['ip'];
    $info['user'] = $revinfo['user'];
    $info['sum'] = $revinfo['sum'];
    // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID.
    // Use $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT in place of $info['minor'].
    if ($revinfo['user']) {
        $info['editor'] = $revinfo['user'];
    } else {
        $info['editor'] = $revinfo['ip'];
    }
    // draft
    $draft = getCacheName($info['client'] . $ID, '.draft');
    if (file_exists($draft)) {
        if (@filemtime($draft) < @filemtime(wikiFN($ID))) {
            // remove stale draft
            @unlink($draft);
        } else {
            $info['draft'] = $draft;
        }
    }
    return $info;
}
Ejemplo n.º 3
0
/**
 * Return info about the current document as associative
 * array.
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function pageinfo()
{
    global $ID;
    global $REV;
    global $RANGE;
    global $USERINFO;
    global $lang;
    // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml
    // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary
    $info['id'] = $ID;
    $info['rev'] = $REV;
    // set info about manager/admin status.
    $info['isadmin'] = false;
    $info['ismanager'] = false;
    if (isset($_SERVER['REMOTE_USER'])) {
        $sub = new Subscription();
        $info['userinfo'] = $USERINFO;
        $info['perm'] = auth_quickaclcheck($ID);
        $info['subscribed'] = $sub->user_subscription();
        $info['client'] = $_SERVER['REMOTE_USER'];
        if ($info['perm'] == AUTH_ADMIN) {
            $info['isadmin'] = true;
            $info['ismanager'] = true;
        } elseif (auth_ismanager()) {
            $info['ismanager'] = true;
        }
        // if some outside auth were used only REMOTE_USER is set
        if (!$info['userinfo']['name']) {
            $info['userinfo']['name'] = $_SERVER['REMOTE_USER'];
        }
    } else {
        $info['perm'] = auth_aclcheck($ID, '', null);
        $info['subscribed'] = false;
        $info['client'] = clientIP(true);
    }
    $info['namespace'] = getNS($ID);
    $info['locked'] = checklock($ID);
    $info['filepath'] = fullpath(wikiFN($ID));
    $info['exists'] = @file_exists($info['filepath']);
    if ($REV) {
        //check if current revision was meant
        if ($info['exists'] && @filemtime($info['filepath']) == $REV) {
            $REV = '';
        } elseif ($RANGE) {
            //section editing does not work with old revisions!
            $REV = '';
            $RANGE = '';
            msg($lang['nosecedit'], 0);
        } else {
            //really use old revision
            $info['filepath'] = fullpath(wikiFN($ID, $REV));
            $info['exists'] = @file_exists($info['filepath']);
        }
    }
    $info['rev'] = $REV;
    if ($info['exists']) {
        $info['writable'] = is_writable($info['filepath']) && $info['perm'] >= AUTH_EDIT;
    } else {
        $info['writable'] = $info['perm'] >= AUTH_CREATE;
    }
    $info['editable'] = $info['writable'] && empty($info['locked']);
    $info['lastmod'] = @filemtime($info['filepath']);
    //load page meta data
    $info['meta'] = p_get_metadata($ID);
    //who's the editor
    if ($REV) {
        $revinfo = getRevisionInfo($ID, $REV, 1024);
    } else {
        if (is_array($info['meta']['last_change'])) {
            $revinfo = $info['meta']['last_change'];
        } else {
            $revinfo = getRevisionInfo($ID, $info['lastmod'], 1024);
            // cache most recent changelog line in metadata if missing and still valid
            if ($revinfo !== false) {
                $info['meta']['last_change'] = $revinfo;
                p_set_metadata($ID, array('last_change' => $revinfo));
            }
        }
    }
    //and check for an external edit
    if ($revinfo !== false && $revinfo['date'] != $info['lastmod']) {
        // cached changelog line no longer valid
        $revinfo = false;
        $info['meta']['last_change'] = $revinfo;
        p_set_metadata($ID, array('last_change' => $revinfo));
    }
    $info['ip'] = $revinfo['ip'];
    $info['user'] = $revinfo['user'];
    $info['sum'] = $revinfo['sum'];
    // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID.
    // Use $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT in place of $info['minor'].
    if ($revinfo['user']) {
        $info['editor'] = $revinfo['user'];
    } else {
        $info['editor'] = $revinfo['ip'];
    }
    // draft
    $draft = getCacheName($info['client'] . $ID, '.draft');
    if (@file_exists($draft)) {
        if (@filemtime($draft) < @filemtime(wikiFN($ID))) {
            // remove stale draft
            @unlink($draft);
        } else {
            $info['draft'] = $draft;
        }
    }
    // mobile detection
    $info['ismobile'] = clientismobile();
    return $info;
}