Example #1
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'])) {
        $info['userinfo'] = $USERINFO;
        $info['perm'] = auth_quickaclcheck($ID);
        $info['subscribed'] = get_info_subscribed();
        $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;
}
Example #2
0
/**
 * Handle page 'subscribe'
 *
 * Throws exception on error.
 *
 * @author Adrian Lang <*****@*****.**>
 */
function act_subscription($act)
{
    global $lang;
    global $INFO;
    global $ID;
    // get and preprocess data.
    $params = array();
    foreach (array('target', 'style', 'action') as $param) {
        if (isset($_REQUEST["sub_{$param}"])) {
            $params[$param] = $_REQUEST["sub_{$param}"];
        }
    }
    // any action given? if not just return and show the subscription page
    if (!$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'];
    $data = $params['data'];
    $action = $params['action'];
    // Perform action.
    require_once DOKU_INC . 'inc/subscription.php';
    if (!subscription_set($_SERVER['REMOTE_USER'], $target, $style, $data)) {
        throw new Exception(sprintf($lang["subscr_{$action}_error"], hsc($INFO['userinfo']['name']), prettyprint_id($target)));
    }
    msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), prettyprint_id($target)), 1);
    act_redirect($ID, $act);
    // Assure that we have valid data if act_redirect somehow fails.
    $INFO['subscribed'] = get_info_subscribed();
    return 'show';
}