示例#1
0
 function update($newvalue)
 {
     if (!$this->_init) {
         // invalidate etag to force fresh output
         $GLOBALS['request']->setValidators(array('%mtime' => false));
         update_locale($newvalue ? $newvalue : $GLOBALS['LANG']);
     }
 }
示例#2
0
 function _notAuthorized($require_level)
 {
     // Display the authority message in the Wiki's default
     // language, in case it is not english.
     //
     // Note that normally a user will not see such an error once
     // logged in, unless the admin has altered the default
     // disallowed wikiactions. In that case we should probably
     // check the user's language prefs too at this point; this
     // would be a situation which is not really handled with the
     // current code.
     if (empty($GLOBALS['LANG'])) {
         update_locale(DEFAULT_LANGUAGE);
     }
     // User does not have required authority.  Prompt for login.
     $what = $this->getActionDescription($this->getArg('action'));
     $pass_required = $require_level >= WIKIAUTH_USER;
     if ($require_level == WIKIAUTH_UNOBTAINABLE) {
         global $DisabledActions;
         if ($DisabledActions and in_array($action, $DisabledActions)) {
             $msg = fmt("%s is disallowed on this wiki.", $this->getDisallowedActionDescription($this->getArg('action')));
             $this->finish();
             return;
         }
         // Is the reason a missing ACL or just wrong user or password?
         if (class_exists('PagePermission')) {
             $user =& $this->_user;
             $status = $user->isAuthenticated() ? _("authenticated") : _("not authenticated");
             $msg = fmt("%s %s %s is disallowed on this wiki for %s user '%s' (level: %s).", _("Missing PagePermission:"), action2access($this->getArg('action')), $this->getArg('pagename'), $status, $user->getId(), $this->getLevelDescription($user->_level));
             // TODO: add link to action=setacl
             $user->PrintLoginForm($this, compact('pass_required'), $msg);
             $this->finish();
             return;
         } else {
             $msg = fmt("%s is disallowed on this wiki.", $this->getDisallowedActionDescription($this->getArg('action')));
             $this->_user->PrintLoginForm($this, compact('require_level', 'pass_required'), $msg);
             $this->finish();
             return;
         }
     } elseif ($require_level == WIKIAUTH_BOGO) {
         $msg = fmt("You must sign in to %s.", $what);
     } elseif ($require_level == WIKIAUTH_USER) {
         $msg = fmt("You must log in to %s.", $what);
     } elseif ($require_level == WIKIAUTH_ANON) {
         $msg = fmt("Access for you is forbidden to %s.", $what);
     } else {
         $msg = fmt("You must be an administrator to %s.", $what);
     }
     $this->_user->PrintLoginForm($this, compact('require_level', 'pass_required'), $msg);
     $this->finish();
     // NORETURN
 }
示例#3
0
    }
    if (!count($locales)) {
        $locales = array("en_US" => "en_US");
    }
    return $locales;
}
// setlang is on the link at the login page
if (isset($_REQUEST["setlang"])) {
    $lang = $_REQUEST["setlang"];
    $setlang = $_REQUEST["setlang"];
} elseif (isset($_COOKIE['lang'])) {
    $lang = $_COOKIE['lang'];
}
$langpath = bindtextdomain("alternc", ALTERNC_LOCALES);
// Create or update a locale.php file if it is outdated.
$locales = update_locale($langpath);
// Default to en_US :
if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
    $_SERVER["HTTP_ACCEPT_LANGUAGE"] = "en_US";
}
if (!isset($lang)) {
    // Use the browser first preferred language
    $lang = strtolower(substr(trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]), 0, 5));
}
if (!isset($locales[$lang])) {
    // Requested language not found in locales
    // treat special cases such as en_AU or fr_BF : use the language only, not the country.
    $ll = substr($lang, 0, 2);
    foreach ($locales as $l) {
        if (substr($l, 0, 2) == $ll) {
            $lang = $l;
示例#4
0
 function PrintLoginForm(&$request, $args, $fail_message = false, $seperate_page = true)
 {
     include_once 'lib/Template.php';
     // Call update_locale in case the system's default language is not 'en'.
     // (We have no user pref for lang at this point yet, no one is logged in.)
     update_locale(DEFAULT_LANGUAGE);
     $userid = '';
     $require_level = 0;
     extract($args);
     // fixme
     $require_level = max(0, min(WIKIAUTH_ADMIN, (int) $require_level));
     $pagename = $request->getArg('pagename');
     $login = new Template('login', $request, compact('pagename', 'userid', 'require_level', 'fail_message', 'pass_required'));
     if ($seperate_page) {
         $request->discardOutput();
         $page = $request->getPage($pagename);
         $revision = $page->getCurrentRevision();
         return GeneratePage($login, _("Sign In"), $revision);
     } else {
         return $login;
     }
 }
示例#5
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']);
    }
}
示例#6
0
 function translate($text, $to_lang, $from_lang = false)
 {
     if (!$from_lang) {
         $from_lang = $this->lang;
     }
     // current locale
     if ($from_lang == $to_lang) {
         return $text;
     }
     // Speed up hash lookup. Not needed for gettext module
     if (!isset($this->_locales[$from_lang]) and !function_exists('bindtextdomain')) {
         $this->init_locale($from_lang);
     }
     if ($from_lang != 'en') {
         // get reverse gettext: translate to english
         $en = $this->translate_to_en($text, $from_lang);
         // and then to target
         update_locale($to_lang);
         $result = gettext($en);
         update_locale($from_lang);
     } else {
         // locale switching is very slow with the gettext extension.
         // better use fast_translate
         if ($from_lang != $to_lang) {
             update_locale($to_lang);
         }
         $result = gettext($text);
         if ($from_lang != $to_lang) {
             update_locale($from_lang);
         }
     }
     return $result;
 }