Пример #1
0
 function buffer_output($compress = true)
 {
     // FIXME: disables sessions (some byte before all headers_sent())
     /*if (defined('USECACHE') and !USECACHE) {
           $this->_is_buffering_output = false;
           return;
       }*/
     if (defined('COMPRESS_OUTPUT')) {
         if (!COMPRESS_OUTPUT) {
             $compress = false;
         }
     } elseif (!check_php_version(4, 2, 3)) {
         $compress = false;
     } elseif (isCGI()) {
         // necessary?
         $compress = false;
     }
     if ($this->getArg('start_debug')) {
         $compress = false;
     }
     // Should we compress even when apache_note is not available?
     // sf.net bug #933183 and http://bugs.php.net/17557
     // This effectively eliminates CGI, but all other servers also. hmm.
     if ($compress and (!function_exists('ob_gzhandler') or !function_exists('apache_note'))) {
         $compress = false;
     }
     // "output handler 'ob_gzhandler' cannot be used twice"
     // http://www.php.net/ob_gzhandler
     if ($compress and ini_get("zlib.output_compression")) {
         $compress = false;
     }
     // New: we check for the client Accept-Encoding: "gzip" presence also
     // This should eliminate a lot or reported problems.
     if ($compress and (!$this->get("HTTP_ACCEPT_ENCODING") or !strstr($this->get("HTTP_ACCEPT_ENCODING"), "gzip"))) {
         $compress = false;
     }
     // Most RSS clients are NOT(!) application/xml gzip compatible yet.
     // Even if they are sending the accept-encoding gzip header!
     // wget is, Mozilla, and MSIE no.
     // Of the RSS readers only MagpieRSS 0.5.2 is. http://www.rssgov.com/rssparsers.html
     // See also http://phpwiki.sourceforge.net/phpwiki/KnownBugs
     if ($compress and $this->getArg('format') and strstr($this->getArg('format'), 'rss')) {
         $compress = false;
     }
     if ($compress) {
         ob_start('phpwiki_gzhandler');
         // TODO: dont send a length or get the gzip'ed data length.
         $this->_is_compressing_output = true;
         header("Content-Encoding: gzip");
         /*
          * Attempt to prevent Apache from doing the dreaded double-gzip.
          *
          * It would be better if we could detect when apache was going
          * to zip for us, and then let it ... but I have yet to figure
          * out how to do that.
          */
         if (function_exists('apache_note')) {
             @apache_note('no-gzip', 1);
         }
     } else {
         // Now we alway buffer output.
         // This is so we can set HTTP headers (e.g. for redirect)
         // at any point.
         // FIXME: change the name of this method.
         ob_start();
         $this->_is_compressing_output = false;
     }
     $this->_is_buffering_output = true;
     $this->_ob_get_length = 0;
 }
Пример #2
0
 /**
  * Constructor
  * 
  * @param object $request The global WikiRequest object.
  */
 function GroupLdap()
 {
     //$this->request = &$GLOBALS['request'];
     $this->username = $this->_getUserName();
     $this->membership = array();
     if (!defined("LDAP_AUTH_HOST")) {
         trigger_error(sprintf(_("%s not defined"), "LDAP_AUTH_HOST"), E_USER_WARNING);
         return false;
     }
     // We should ignore multithreaded environments, not generally windows.
     // CGI does work.
     if (!function_exists('ldap_connect') and (!isWindows() or isCGI())) {
         // on MacOSX >= 4.3 you'll need PHP_SHLIB_SUFFIX instead.
         dl("ldap" . defined('PHP_SHLIB_SUFFIX') ? PHP_SHLIB_SUFFIX : DLL_EXT);
         if (!function_exists('ldap_connect')) {
             trigger_error(_("No LDAP in this PHP version"), E_USER_WARNING);
             return false;
         }
     }
     if (!defined("LDAP_BASE_DN")) {
         define("LDAP_BASE_DN", '');
     }
     $this->base_dn = LDAP_BASE_DN;
     // if no users ou (organizational unit) is defined,
     // then take out the ou= from the base_dn (if exists) and append a default
     // from users and group
     if (!LDAP_OU_USERS) {
         if (strstr(LDAP_BASE_DN, "ou=")) {
             $this->base_dn = preg_replace("/(ou=\\w+,)?()/", "\$2", LDAP_BASE_DN);
         }
     }
     if (!isset($this->user) or !isa($this->user, '_LDAPPassUser')) {
         $this->_user = new _LDAPPassUser('LdapGroupTest');
     } else {
         $this->_user =& $this->user;
     }
 }
Пример #3
0
/** 
 * Define constants which are client or request specific and should not be dumped statically.
 * Such as the language, and the virtual and server paths, which might be overridden 
 * by startup scripts for wiki farms.
 */
function fixup_dynamic_configs($file)
{
    global $WikiNameRegexp;
    global $HTTP_SERVER_VARS, $DBParams, $LANG;
    if (defined('INCLUDE_PATH') and INCLUDE_PATH) {
        @ini_set('include_path', INCLUDE_PATH);
    }
    if (defined('SESSION_SAVE_PATH') and SESSION_SAVE_PATH) {
        @ini_set('session.save_path', SESSION_SAVE_PATH);
    }
    if (!defined('DEFAULT_LANGUAGE')) {
        // not needed anymore
        define('DEFAULT_LANGUAGE', '');
    }
    // detect from client
    update_locale(isset($LANG) ? $LANG : DEFAULT_LANGUAGE);
    if (empty($LANG)) {
        if (!defined("DEFAULT_LANGUAGE") or !DEFAULT_LANGUAGE) {
            // TODO: defer this to WikiRequest::initializeLang()
            $LANG = guessing_lang();
            guessing_setlocale(LC_ALL, $LANG);
        } else {
            $LANG = DEFAULT_LANGUAGE;
        }
    }
    // Set up (possibly fake) gettext()
    // Todo: this could be moved to fixup_static_configs()
    // Bug #1381464 with php-5.1.1
    if (!function_exists('bindtextdomain') and !function_exists('gettext') and !function_exists('_')) {
        $locale = array();
        function gettext($text)
        {
            global $locale;
            if (!empty($locale[$text])) {
                return $locale[$text];
            }
            return $text;
        }
        function _($text)
        {
            return gettext($text);
        }
    } else {
        // Working around really weird gettext problems: (4.3.2, 4.3.6 win)
        // bindtextdomain() returns the current domain path.
        // 1. If the script is not index.php but something like "de", on a different path
        //    then bindtextdomain() fails, but after chdir to the correct path it will work okay.
        // 2. But the weird error "Undefined variable: bindtextdomain" is generated then.
        $bindtextdomain_path = FindFile("locale", false, true);
        $chback = 0;
        if (isWindows()) {
            $bindtextdomain_path = str_replace("/", "\\", $bindtextdomain_path);
        }
        $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain_path);
        if (realpath($bindtextdomain_real) != realpath($bindtextdomain_path)) {
            // this will happen with virtual_paths. chdir and try again.
            chdir($bindtextdomain_path);
            $chback = 1;
            $bindtextdomain_real = @bindtextdomain("phpwiki", $bindtextdomain_path);
        }
        // tell gettext not to use unicode. PHP >= 4.2.0. Thanks to Kai Krakow.
        if (defined('CHARSET') and function_exists('bind_textdomain_codeset')) {
            @bind_textdomain_codeset("phpwiki", CHARSET);
        }
        textdomain("phpwiki");
        if ($chback) {
            // change back
            chdir($bindtextdomain_real . (isWindows() ? "\\.." : "/.."));
        }
    }
    // language dependent updates:
    $WikiNameRegexp = pcre_fix_posix_classes($WikiNameRegexp);
    //if ($KeywordLinkRegexp) $KeywordLinkRegexp = pcre_fix_posix_classes($KeywordLinkRegexp);
    if (!defined('CATEGORY_GROUP_PAGE')) {
        define('CATEGORY_GROUP_PAGE', _("CategoryGroup"));
    }
    if (!defined('WIKI_NAME')) {
        define('WIKI_NAME', _("An unnamed PhpWiki"));
    }
    if (!defined('HOME_PAGE')) {
        define('HOME_PAGE', _("HomePage"));
    }
    //////////////////////////////////////////////////////////////////
    // Autodetect URL settings:
    //
    foreach (array('SERVER_NAME', 'SERVER_PORT') as $var) {
        //FIXME: for CGI without _SERVER
        if (!defined($var) and !empty($HTTP_SERVER_VARS[$var])) {
            define($var, $HTTP_SERVER_VARS[$var]);
        }
    }
    if (!defined('SERVER_NAME')) {
        define('SERVER_NAME', '127.0.0.1');
    }
    if (!defined('SERVER_PORT')) {
        define('SERVER_PORT', 80);
    }
    if (!defined('SERVER_PROTOCOL')) {
        if (empty($HTTP_SERVER_VARS['HTTPS']) || $HTTP_SERVER_VARS['HTTPS'] == 'off') {
            define('SERVER_PROTOCOL', 'http');
        } else {
            define('SERVER_PROTOCOL', 'https');
        }
    }
    if (!defined('SCRIPT_NAME')) {
        define('SCRIPT_NAME', deduce_script_name());
    }
    if (!defined('USE_PATH_INFO')) {
        if (isCGI()) {
            define('USE_PATH_INFO', false);
        } else {
            /*
             * If SCRIPT_NAME does not look like php source file,
             * or user cgi we assume that php is getting run by an
             * action handler in /cgi-bin.  In this case,
             * I think there is no way to get Apache to pass
             * useful PATH_INFO to the php script (PATH_INFO
             * is used to the the php interpreter where the
             * php script is...)
             */
            switch (php_sapi_name()) {
                case 'apache':
                case 'apache2handler':
                    define('USE_PATH_INFO', true);
                    break;
                case 'cgi':
                case 'apache2filter':
                    define('USE_PATH_INFO', false);
                    break;
                default:
                    define('USE_PATH_INFO', ereg('\\.(php3?|cgi)$', SCRIPT_NAME));
                    break;
            }
        }
    }
    if (SERVER_PORT && SERVER_PORT != (SERVER_PROTOCOL == 'https' ? 443 : 80)) {
        define('SERVER_URL', SERVER_PROTOCOL . '://' . SERVER_NAME . ':' . SERVER_PORT);
    } else {
        define('SERVER_URL', SERVER_PROTOCOL . '://' . SERVER_NAME);
    }
    if (!defined('VIRTUAL_PATH')) {
        // We'd like to auto-detect when the cases where apaches
        // 'Action' directive (or similar means) is used to
        // redirect page requests to a cgi-handler.
        //
        // In cases like this, requests for e.g. /wiki/HomePage
        // get redirected to a cgi-script called, say,
        // /path/to/wiki/index.php.  The script gets all
        // of /wiki/HomePage as it's PATH_INFO.
        //
        // The problem is:
        //   How to detect when this has happened reliably?
        //   How to pick out the "virtual path" (in this case '/wiki')?
        //
        // (Another time an redirect might occur is to a DirectoryIndex
        // -- the requested URI is '/wikidir/', the request gets
        // passed to '/wikidir/index.php'.  In this case, the
        // proper VIRTUAL_PATH is '/wikidir/index.php', since the
        // pages will appear at e.g. '/wikidir/index.php/HomePage'.
        //
        $REDIRECT_URL =& $HTTP_SERVER_VARS['REDIRECT_URL'];
        if (USE_PATH_INFO and isset($REDIRECT_URL) and !IsProbablyRedirectToIndex()) {
            // FIXME: This is a hack, and won't work if the requested
            // pagename has a slash in it.
            $temp = strtr(dirname($REDIRECT_URL . 'x'), "\\", '/');
            if ($temp == '/' || $temp == '\\') {
                $temp = '';
            }
            define('VIRTUAL_PATH', $temp);
        } else {
            define('VIRTUAL_PATH', SCRIPT_NAME);
        }
    }
    if (!defined('PATH_INFO_PREFIX')) {
        if (VIRTUAL_PATH != SCRIPT_NAME) {
            // Apache action handlers are used.
            define('PATH_INFO_PREFIX', VIRTUAL_PATH . '/');
        } else {
            define('PATH_INFO_PREFIX', '/');
        }
    }
    define('PHPWIKI_BASE_URL', SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));
    // Detect PrettyWiki setup (not loading index.php directly)
    // $SCRIPT_FILENAME should be the same as __FILE__ in index.php
    if (!isset($SCRIPT_FILENAME)) {
        $SCRIPT_FILENAME = @$HTTP_SERVER_VARS['SCRIPT_FILENAME'];
    }
    if (!isset($SCRIPT_FILENAME)) {
        $SCRIPT_FILENAME = @$HTTP_ENV_VARS['SCRIPT_FILENAME'];
    }
    if (!isset($SCRIPT_FILENAME)) {
        $SCRIPT_FILENAME = dirname(__FILE__ . '/../') . '/index.php';
    }
    if (isWindows()) {
        $SCRIPT_FILENAME = str_replace('\\\\', '\\', strtr($SCRIPT_FILENAME, '/', '\\'));
    }
    define('SCRIPT_FILENAME', $SCRIPT_FILENAME);
    // Get remote host name, if apache hasn't done it for us
    if (empty($HTTP_SERVER_VARS['REMOTE_HOST']) and !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) and ENABLE_REVERSE_DNS) {
        $HTTP_SERVER_VARS['REMOTE_HOST'] = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']);
    }
}