示例#1
0
/**
 * Determine basic information for a request of $id
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Chris Smith <*****@*****.**>
 *
 * @param string $id         pageid
 * @param bool   $htmlClient add info about whether is mobile browser
 * @return array with info for a request of $id
 *
 */
function basicinfo($id, $htmlClient = true)
{
    global $USERINFO;
    /* @var Input $INPUT */
    global $INPUT;
    // set info about manager/admin status.
    $info = array();
    $info['isadmin'] = false;
    $info['ismanager'] = false;
    if ($INPUT->server->has('REMOTE_USER')) {
        $info['userinfo'] = $USERINFO;
        $info['perm'] = auth_quickaclcheck($id);
        $info['client'] = $INPUT->server->str('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'] = $INPUT->server->str('REMOTE_USER');
        }
    } else {
        $info['perm'] = auth_aclcheck($id, '', null);
        $info['client'] = clientIP(true);
    }
    $info['namespace'] = getNS($id);
    // mobile detection
    if ($htmlClient) {
        $info['ismobile'] = clientismobile();
    }
    return $info;
}
示例#2
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;
}
示例#3
0
 /**
  *  check ismobile
  */
 function test_ismobile()
 {
     global $ID, $conf;
     $ID = 'wiki:start';
     $info = $this->_get_expected_pageinfo();
     $info['id'] = 'wiki:start';
     $info['namespace'] = 'wiki';
     $info['filepath'] = $conf['datadir'] . '/wiki/start.txt';
     // overkill, ripped from clientismobile() as we aren't testing detection - but forcing it
     $_SERVER['HTTP_X_WAP_PROFILE'] = 'a fake url';
     $_SERVER['HTTP_ACCEPT'] .= ';wap';
     $_SERVER['HTTP_USER_AGENT'] = 'blackberry,symbian,hand,mobi,phone';
     $info['ismobile'] = clientismobile();
     $this->assertTrue(clientismobile());
     // ensure THIS test fails if clientismobile() returns false
     $this->assertEquals($info, pageinfo());
     // it would be a test failure not a pageinfo failure.
 }