Exemple #1
0
 function WikiDB_ADODB($dbparams)
 {
     $backend = 'ADODB';
     if (is_array($dbparams['dsn'])) {
         $backend = $dbparams['dsn']['phptype'];
     } elseif (preg_match('/^(\\w+):/', $dbparams['dsn'], $m)) {
         $backend = $m[1];
     }
     // Do we have a override? (currently: mysql, sqlite, oracle, mssql, oci8po, postgres7)
     // TODO: mysqlt (innodb or bdb)
     if ($backend == 'pgsql') {
         // PearDB DSN cross-compatiblity hack (for unit testing)
         $backend = 'postgres7';
         if (is_string($dbparams['dsn'])) {
             $dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 6);
         }
     }
     if (FindFile("lib/WikiDB/backend/ADODB_" . $backend . ".php", true)) {
         $backend = 'ADODB_' . $backend;
     } else {
         $backend = 'ADODB';
     }
     include_once "lib/WikiDB/backend/" . $backend . ".php";
     $backend_class = "WikiDB_backend_" . $backend;
     $backend = new $backend_class($dbparams);
     if (!$backend->_dbh->_connectionID) {
         return false;
     }
     $this->WikiDB($backend, $dbparams);
 }
Exemple #2
0
 /**
  * Constructor.
  */
 function WikiDB_backend_ADODB_sqlite($dbparams)
 {
     $parsed = parseDSN($dbparams['dsn']);
     if (!file_exists($parsed['database'])) {
         // creating the empty database
         $db = $parsed['database'];
         $schema = FindFile("schemas/sqlite.sql");
         `sqlite {$db} < {$schema}`;
     }
     $this->WikiDB_backend_ADODB($dbparams);
 }
Exemple #3
0
	static function zdb()
	{
		static $db = NULL;
		if ( $db == NULL )
		{
			
			$config = new Zend_Config_Xml(FindFile("Tools/config.xml"));
			$db = Zend_Db::factory($config->default->database);
		}
		return $db;
	}
Exemple #4
0
 function _ensure_loaded($pagename)
 {
     global $request;
     $dbi = $request->getDbh();
     if (!$dbi->isWikiPage($pagename)) {
         require_once 'lib/loadsave.php';
         $request->setArg('source', FindFile('pgsrc/' . urlencode($pagename)));
         $request->setArg('overwrite', 1);
         LoadAny($request, $request->getArg('source'));
         $request->setArg('source', false);
     }
 }
Exemple #5
0
function __CuberAutoloader($class_name) {
	if ( $class_name == "DB" )
		include "Tools/database.php";
	else
	{
		$class_name = strtolower($class_name);
		$file = FindFile($class_name . ".php");
		if ( $file )
		{
			include $file;
		}
	}
}
Exemple #6
0
	public function IncFile($folder, $file, $parse=array())
	{
		$view = is_array($parse)?
			new Record($parse) : $parse;
			
		$local = $this->local;
		$title = $this->title;
		
		//echo "parsing view: $folder/$file<br />";
		
		$file = FindFile("$folder/$file.php");
		include FindFile($file);
	}
Exemple #7
0
 function testSetupWiki()
 {
     global $request;
     purge_testbox();
     $dbi = $request->getDbh();
     $dbi->purgePage('HomePage');
     // possibly in cache
     $this->assertFalse($dbi->isWikiPage('HomePage'));
     $request->setArg('source', FindFile('pgsrc'));
     $request->setArg('overwrite', 1);
     LoadAny($request, $request->getArg('source'));
     $request->setArg('source', false);
     $request->setArg('overwrite', false);
     $this->assertTrue($dbi->isWikiPage('HomePage'));
 }
Exemple #8
0
 function WikiDB_PDO($dbparams)
 {
     if (is_array($dbparams['dsn'])) {
         $backend = $dbparams['dsn']['phptype'];
     } elseif (preg_match('/^(\\w+):/', $dbparams['dsn'], $m)) {
         $backend = $m[1];
     }
     // Do we have a override? Currently none: mysql, sqlite, oci, mssql
     if (FindFile("lib/WikiDB/backend/PDO_{$backend}.php", true)) {
         $backend = 'PDO_' . $backend;
     } else {
         $backend = 'PDO';
     }
     include_once "lib/WikiDB/backend/{$backend}.php";
     $backend_class = "WikiDB_backend_{$backend}";
     $backend = new $backend_class($dbparams);
     $this->WikiDB($backend, $dbparams);
 }
Exemple #9
0
 function imdb()
 {
     global $DBParams;
     $ini = parse_ini_file(FindFile("config/SqlResult.ini"));
     $dsn = $ini['imdb'];
     if ($DBParams['dbtype'] == 'SQL') {
         $this->_dbh = DB::connect($dsn);
         $this->_dbtype = "PearDB";
     } else {
         if ($DBParams['dbtype'] != 'ADODB') {
             // require_once('lib/WikiDB/adodb/adodb-errorhandler.inc.php');
             require_once 'lib/WikiDB/adodb/adodb-pear.inc.php';
         }
         $parsed = parseDSN($dsn);
         $this->_dbh =& ADONewConnection($parsed['phptype']);
         $conn = $this->_dbh->Connect($parsed['hostspec'], $parsed['username'], $parsed['password'], $parsed['database']);
         $this->_dbtype = "ADODB";
     }
     $this->_title_1_1 = array("business", "moviebudgets", "colorinfo", "mpaaratingsreasons");
     $this->_title_1_n = array("akatitles", "alternateversions", "miscellaneouscompanies", "moviecountries", "certificates", "completecast", "completecrew", "crazycredits", "genres", "goofs", "keywords", "movielinks", "plot", "quotes", "ratings", "soundtracks", "specialeffectscompanies", "taglines", "trivia", "distributors", "language", "laserdisc", "literature", "locations", "miscellaneouscompanies", "productioncompanies", "releasedates", "runningtimes", "soundmix", "technical");
 }
Exemple #10
0
/**
 * HomePage was not found so first-time install is supposed to run.
 * - import all pgsrc pages.
 * - Todo: installer interface to edit config/config.ini settings
 * - Todo: ask for existing old index.php to convert to config/config.ini
 * - Todo: theme-specific pages: 
 *   blog - HomePage, ADMIN_USER/Blogs
 */
function SetupWiki(&$request)
{
    global $GenericPages, $LANG;
    //FIXME: This is a hack (err, "interim solution")
    // This is a bogo-bogo-login:  Login without
    // saving login information in session state.
    // This avoids logging in the unsuspecting
    // visitor as "The PhpWiki programming team".
    //
    // This really needs to be cleaned up...
    // (I'm working on it.)
    $real_user = $request->_user;
    if (ENABLE_USER_NEW) {
        $request->_user = new _BogoUser(_("The PhpWiki programming team"));
    } else {
        $request->_user = new WikiUser($request, _("The PhpWiki programming team"), WIKIAUTH_BOGO);
    }
    StartLoadDump($request, _("Loading up virgin wiki"));
    echo "<dl>\n";
    $pgsrc = FindLocalizedFile(WIKI_PGSRC);
    $default_pgsrc = FindFile(DEFAULT_WIKI_PGSRC);
    $request->setArg('overwrite', true);
    if ($default_pgsrc != $pgsrc) {
        LoadAny($request, $default_pgsrc, $GenericPages);
    }
    $request->setArg('overwrite', false);
    LoadAny($request, $pgsrc);
    $dbi =& $request->_dbi;
    // Ensure that all mandatory pages are loaded
    $finder = new FileFinder();
    foreach (array_merge(explode(':', 'OldTextFormattingRules:TextFormattingRules:PhpWikiAdministration'), $GLOBALS['AllActionPages'], array(constant('HOME_PAGE'))) as $f) {
        $page = gettext($f);
        $epage = urlencode($page);
        if (!$dbi->isWikiPage($page)) {
            // translated version provided?
            if ($lf = FindLocalizedFile($pgsrc . $finder->_pathsep . $epage, 1)) {
                LoadAny($request, $lf);
            } else {
                // load english version of required action page
                LoadAny($request, FindFile(DEFAULT_WIKI_PGSRC . $finder->_pathsep . urlencode($f)));
                $page = $f;
            }
        }
        if (!$dbi->isWikiPage($page)) {
            trigger_error(sprintf("Mandatory file %s couldn't be loaded!", $page), E_USER_WARNING);
        }
    }
    echo "</dl>\n";
    EndLoadDump($request);
}
Exemple #11
0
/**
 * HomePage was not found so first-time install is supposed to run.
 * - import all pgsrc pages.
 * - Todo: installer interface to edit config/config.ini settings
 * - Todo: ask for existing old index.php to convert to config/config.ini
 * - Todo: theme-specific pages: 
 *   blog - HomePage, ADMIN_USER/Blogs
 */
function SetupWiki(&$request)
{
    global $GenericPages, $LANG;
    //FIXME: This is a hack (err, "interim solution")
    // This is a bogo-bogo-login:  Login without
    // saving login information in session state.
    // This avoids logging in the unsuspecting
    // visitor as "The PhpWiki programming team".
    //
    // This really needs to be cleaned up...
    // (I'm working on it.)
    $real_user = $request->_user;
    if (ENABLE_USER_NEW) {
        $request->_user = new _BogoUser(_("The PhpWiki programming team"));
    } else {
        $request->_user = new WikiUser($request, _("The PhpWiki programming team"), WIKIAUTH_BOGO);
    }
    // Get the localised wiki loading message
    $message = _("Loading up virgin wiki. Please wait until the end of the process, this will take few minutes.");
    StartLoadDump($request, $message);
    echo "<dl>\n";
    $pgsrc = FindLocalizedFile(WIKI_PGSRC);
    $default_pgsrc = FindFile(DEFAULT_WIKI_PGSRC);
    $request->setArg('overwrite', true);
    if ($default_pgsrc != $pgsrc) {
        LoadAny($request, $default_pgsrc, $GenericPages);
    }
    // Codendi - Commented-out the following line to make sure that wiki pages are properly instanciated
    // If the line is not commented, we randomly run into error messages like this at wiki init:
    // "...pagename has edit conflicts - skipped  (Merge Edit ) (Restore Anyway)"
    //$request->setArg('overwrite', false);
    LoadAny($request, $pgsrc);
    $dbi =& $request->_dbi;
    // Ensure that all mandatory pages are loaded
    $finder = new FileFinder();
    foreach (array_merge(explode(':', 'OldTextFormattingRules:TextFormattingRules:PhpWikiAdministration'), $GLOBALS['AllActionPages'], array(constant('HOME_PAGE'))) as $f) {
        $page = gettext($f);
        $epage = urlencode($page);
        if (!$dbi->isWikiPage($page)) {
            // translated version provided?
            if ($lf = FindLocalizedFile($pgsrc . $finder->_pathsep . $epage, 1)) {
                LoadAny($request, $lf);
            } else {
                // load english version of required action page
                LoadAny($request, FindFile(DEFAULT_WIKI_PGSRC . $finder->_pathsep . urlencode($f)));
                $page = $f;
            }
        }
        if (!$dbi->isWikiPage($page)) {
            trigger_error(sprintf("Mandatory file %s couldn't be loaded!", $page), E_USER_WARNING);
        }
        //WARNING  CODENDI CODE : give permissions to the administration pages of the wiki
        $pages = array("AdministrationDePhpWiki", "AdministrationDePhpWiki/Supprimer", "AdministrationDePhpWiki/Remplacer", "AdministrationDePhpWiki/Renommer", "PhpWikiAdministration", "PhpWikiAdministration/Replace", "PhpWikiAdministration/Remove", "PhpWikiAdministration/Rename");
        if (in_array($page, $pages)) {
            $group_id = $request->getArg('group_id');
            $wikiPage = new WikiPage($group_id, $page);
            $id = $wikiPage->getId();
            $pm = PermissionsManager::instance();
            $pm->addPermission('WIKIPAGE_READ', $id, $GLOBALS['UGROUP_PROJECT_ADMIN']);
            $pm->addPermission('WIKIPAGE_READ', $id, $GLOBALS['UGROUP_WIKI_ADMIN']);
        }
        //END WARNING
    }
    echo "</dl>\n";
    EndLoadDump($request);
}
Exemple #12
0
 function getDsn($alias)
 {
     $ini = parse_ini_file(FindFile("config/SqlResult.ini"));
     return $ini[$alias];
 }
Exemple #13
0
/**
 * HomePage was not found so first-time install is supposed to run.
 * - import all pgsrc pages.
 * - Todo: installer interface to edit config/config.ini settings
 * - Todo: ask for existing old index.php to convert to config/config.ini
 * - Todo: theme-specific pages:
 *   blog - HomePage, ADMIN_USER/Blogs
 */
function SetupWiki(&$request)
{
    global $GenericPages, $LANG;
    //FIXME: This is a hack (err, "interim solution")
    // This is a bogo-bogo-login:  Login without
    // saving login information in session state.
    // This avoids logging in the unsuspecting
    // visitor as ADMIN_USER
    //
    // This really needs to be cleaned up...
    // (I'm working on it.)
    $real_user = $request->_user;
    if (ENABLE_USER_NEW) {
        $request->_user = new _BogoUser(ADMIN_USER);
    } else {
        $request->_user = new WikiUser($request, ADMIN_USER, WIKIAUTH_BOGO);
    }
    StartLoadDump($request, _("Loading up virgin wiki"));
    $pgsrc = FindLocalizedFile(WIKI_PGSRC);
    $default_pgsrc = FindFile(DEFAULT_WIKI_PGSRC);
    $request->setArg('overwrite', true);
    if ($default_pgsrc != $pgsrc) {
        LoadAny($request, $default_pgsrc, $GenericPages);
    }
    $request->setArg('overwrite', false);
    LoadAny($request, $pgsrc);
    $dbi =& $request->_dbi;
    // Ensure that all mandatory pages are loaded
    $finder = new FileFinder();
    if (!FUSIONFORGE) {
        $mandatory = explode(':', 'SandBox:Template/Category:Template/Talk:SpecialPages:CategoryCategory:CategoryActionPage:Help/OldTextFormattingRules:Help/TextFormattingRules:PhpWikiAdministration');
    } else {
        if (WIKI_NAME == "help") {
            $mandatory = explode(':', 'SandBox:Template/Category:Template/Talk:SpecialPages:CategoryCategory:CategoryActionPage:Help/TextFormattingRules:PhpWikiAdministration');
        } else {
            $mandatory = explode(':', 'SandBox:Template/UserPage:Template/Category:Template/Talk:SpecialPages:CategoryCategory:CategoryActionPage:TextFormattingRules:PhpWikiAdministration');
        }
    }
    foreach (array_merge($mandatory, $GLOBALS['AllActionPages'], array(constant('HOME_PAGE'))) as $f) {
        $page = gettext($f);
        $epage = urlencode($page);
        if (!$dbi->isWikiPage($page)) {
            // translated version provided?
            if ($lf = FindLocalizedFile($pgsrc . $finder->_pathsep . $epage, 1)) {
                LoadAny($request, $lf);
            } else {
                // load english version of required action page
                LoadAny($request, FindFile(DEFAULT_WIKI_PGSRC . $finder->_pathsep . urlencode($f)));
                $page = $f;
            }
        }
        if (!$dbi->isWikiPage($page)) {
            trigger_error(sprintf("Mandatory file %s couldn't be loaded!", $page), E_USER_WARNING);
        }
    }
    $pagename = _("InterWikiMap");
    $map = $dbi->getPage($pagename);
    $map->set('locked', true);
    PrintXML(HTML::p(HTML::em(WikiLink($pagename)), HTML::strong(" locked")));
    EndLoadDump($request);
}
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $source =& $this->source;
     if (empty($syntax)) {
         return $this->error(_("Syntax language not specified."));
     }
     if (!empty($source)) {
         $args = "";
         if (defined('HIGHLIGHT_DATA_DIR')) {
             $args .= " --data-dir " . HIGHLIGHT_DATA_DIR;
         }
         if ($number != 0) {
             $args .= " -l";
         }
         if ($wrap != 0) {
             $args .= " -V";
         }
         $html = HTML();
         if (!empty($color) and !preg_match('/^[\\w-]+$/', $color)) {
             $html->pushContent($this->error(fmt("invalid %s ignored", 'color')));
             $color = false;
         }
         if (!empty($color)) {
             $args .= " --style {$color} -c " . FindFile("uploads") . "/highlight-{$color}.css";
         }
         if (!empty($style)) {
             $args .= " -F {$style}";
         }
         $commandLine = HIGHLIGHT_EXE . "{$args} -q -X -f -S {$syntax}";
         if (check_php_version(4, 3, 0)) {
             $code = $this->newFilterThroughCmd($source, $commandLine);
         } else {
             $code = $this->oldFilterThroughCmd($source, $commandLine);
         }
         if (empty($code)) {
             return $this->error(fmt("Couldn't start commandline '%s'", $commandLine));
         }
         $pre = HTML::pre(HTML::raw($code));
         $pre->setAttr('class', 'tightenable top bottom');
         $html->pushContent($pre);
         $css = $GLOBALS['WikiTheme']->_CSSlink('', empty($color) ? 'highlight.css' : "uploads/highlight-{$color}.css", '');
         return HTML($css, $html);
     } else {
         return $this->error(fmt("empty source"));
     }
 }
Exemple #15
0
function fixConfigIni($match, $new)
{
    $file = FindFile("config/config.ini");
    $found = false;
    if (is_writable($file)) {
        $in = fopen($file, "rb");
        $out = fopen($tmp = tempnam(FindFile("uploads"), "cfg"), "wb");
        if (isWindows()) {
            $tmp = str_replace("/", "\\", $tmp);
        }
        while ($s = fgets($in)) {
            if (preg_match($match, $s)) {
                $s = $new . (isWindows() ? "\r\n" : "\n");
                $found = true;
            }
            fputs($out, $s);
        }
        fclose($in);
        fclose($out);
        if (!$found) {
            echo " <b><font color=\"red\">", _("FAILED"), "</font></b>: ", sprintf(_("%s not found"), $match);
            unlink($out);
        } else {
            @unlink("{$file}.bak");
            @rename($file, "{$file}.bak");
            if (rename($tmp, $file)) {
                echo " <b>", _("FIXED"), "</b>";
            } else {
                echo " <b>", _("FAILED"), "</b>: ";
                sprintf(_("couldn't move %s to %s"), $tmp, $file);
                return false;
            }
        }
        return $found;
    } else {
        echo " <b><font color=\"red\">", _("FAILED"), "</font></b>: ", sprintf(_("%s is not writable"), $file);
        return false;
    }
}
Exemple #16
0
 function available_plugins()
 {
     $fileset = new FileSet(FindFile('lib/plugin'), '*.php');
     $list = $fileset->getFiles();
     natcasesort($list);
     reset($list);
     return sprintf(_("Total %d plugins: "), count($list)) . implode(', ', array_map(create_function('$f', 'return substr($f,0,-4);'), $list));
 }
Exemple #17
0
 function fixThemeTemplate($match, $new, $template)
 {
     // for all custom themes
     $ourthemes = explode(":", "blog:Crao:default:Hawaiian:MacOSX:MonoBook:Portland:shamino_com:SpaceWiki:wikilens:Wordpress");
     $themedir = NormalizeLocalFileName("themes");
     $dh = opendir($themedir);
     while ($r = readdir($dh)) {
         if (filetype($r) == 'dir' and $r[0] != '.' and !is_array($r, $ourthemes)) {
             $customthemes[] = $r;
         }
     }
     $success = true;
     $errors = '';
     foreach ($customthemes as $customtheme) {
         $template = FindFile("themes/{$customtheme}/templates/{$template}");
         $do = $this->parent->fixLocalFile($match, $new, template);
         if (!$do[0]) {
             $success = false;
             $errors .= $do[1] . " ";
             echo $do[1];
         }
     }
     return array($success, $errors);
 }
Exemple #18
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']);
    }
}
Exemple #19
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $this->args = $this->getArgs($argstr, $request);
     extract($this->args);
     $this->request =& $request;
     if (!$from_lang) {
         $from_lang = $request->getPref('lang');
     }
     if (!$from_lang) {
         $from_lang = $GLOBALS['LANG'];
     }
     $this->lang = $from_lang;
     if (empty($languages)) {
         $available_languages = listAvailableLanguages();
         if ($from_lang == 'en') {
             // "en" is always the first.
             array_shift($available_languages);
         }
         // put from_lang to the very end.
         if (in_array($from_lang, $available_languages)) {
             $languages = $available_languages;
         } else {
             $languages = array_merge($available_languages, array($from_lang));
         }
     } elseif (strstr($languages, ',')) {
         $languages = explode(',', $languages);
     } else {
         $languages = array($languages);
     }
     if (in_array('zh', $languages) or in_array('ja', $languages)) {
         // If the current charset != utf-8 the text will not be displayed correctly.
         // But here we cannot change the header anymore. So we can decide to ignore them,
         // or display them with all the errors.
         //FIXME: do iconv the ob
         if ($GLOBALS['charset'] != 'utf-8' and !defined('NEED_ICONV_TO')) {
             define('NEED_ICONV_TO', 'utf-8');
             //either the extension or external
             //$GLOBALS['charset'] = 'utf-8';
         }
     }
     $to_lang = $languages[0];
     if (!empty($string) and count($languages) == 1) {
         return $this->translate($string, $to_lang, $from_lang);
     }
     if (!empty($page)) {
         $pagename = $page;
         if ($dbi->isWikiPage($pagename)) {
             $url = '';
             // google can only translate from english and french
             if (in_array($from_lang, array('en', 'fr'))) {
                 $url = "http://translate.google.com/translate";
                 $url .= "?langpair=" . urlencode($from_lang . "|" . $to_lang);
                 $url .= "&u=" . urlencode(WikiURL($pagename, false, true));
             }
             // redirect or transclude?
             if ($url) {
                 return $request->redirect($url);
             }
             return HTML(fmt("TODO: Google can only translate from english and french. Find a translation service for %s to language %s", WikiURL($pagename, false, true), $to_lang));
         } else {
             return $this->error(fmt("%s is empty", $pagename));
         }
     }
     $pagelist = new PageList('', $exclude, $this->args);
     $pagelist->_columns[0]->_heading = "{$from_lang}";
     foreach ($languages as $lang) {
         if ($lang == $from_lang) {
             continue;
         }
         $field = "custom:{$lang}";
         $pagelist->addColumnObject(new _PageList_Column_customlang($field, $from_lang, $this));
     }
     if (!empty($string)) {
         $pagelist->addPage($string);
         return $pagelist;
     }
     switch ($what) {
         case 'allpages':
             $pagelist->addPages($dbi->getAllPages($include_empty, $sortby, $limit, $exclude));
             break;
         case 'pages':
             // not all pages, only the pgsrc pages
             if (!is_array($exclude)) {
                 $exclude = $pagelist->explodePageList($exclude, false, $sortby, $limit, $exclude);
             }
             $path = FindLocalizedFile(WIKI_PGSRC);
             $pgsrc = new fileSet($path);
             foreach ($pgsrc->getFiles($exclude, $sortby, $limit) as $pagename) {
                 $pagename = urldecode($pagename);
                 if (substr($pagename, -1, 1) == '~') {
                     continue;
                 }
                 if (in_array($pagename, $exclude)) {
                     continue;
                 }
                 // exclude page.
                 if ($match != '*' and !glob_match($match, $pagename)) {
                     continue;
                 }
                 $page_handle = $dbi->getPage($pagename);
                 $pagelist->addPage($page_handle);
             }
             break;
         case 'wikiwords':
             if (!isset($this->_locales[$from_lang])) {
                 $this->init_locale($from_lang);
             }
             $locale =& $this->_locales[$from_lang];
             if (is_array($locale)) {
                 $count = 0;
                 foreach ($locale as $from => $to) {
                     if ($match != '*' and !glob_match($match, $from)) {
                         continue;
                     }
                     if (isWikiWord($from)) {
                         $count++;
                         $pagelist->addPage($from);
                         if ($limit and $count > $limit) {
                             break;
                         }
                     }
                 }
             }
             break;
             // all Button texts, which need a localized .png
             // where to get them from? templates/*.tmpl: Button()
             // and WikiLink(?,'button')
             // navbar links, actionpages, and admin requests
         // all Button texts, which need a localized .png
         // where to get them from? templates/*.tmpl: Button()
         // and WikiLink(?,'button')
         // navbar links, actionpages, and admin requests
         case 'buttons':
             $buttons = $GLOBALS['AllActionPages'];
             $fileset = new FileSet(FindFile("themes/MacOSX/buttons/en"), "*.png");
             foreach ($fileset->getFiles() as $file) {
                 $b = urldecode(substr($file, 0, -4));
                 if (!in_array($b, $buttons)) {
                     $buttons[] = $b;
                 }
             }
             $count = 0;
             foreach ($buttons as $button) {
                 $pagelist->addPage($button);
                 if ($limit and ++$count > $limit) {
                     break;
                 }
             }
             break;
     }
     return $pagelist;
 }
Exemple #20
0
 static function FindFile($pszClass, $utf8_path)
 {
     return FindFile($pszClass, $utf8_path);
 }
Exemple #21
0
 function sanify($value)
 {
     if (!empty($value) and FindFile($this->_themefile($value))) {
         return $value;
     }
     return $this->default_value;
 }
Exemple #22
0
 function ParseImages($text)
 {
     global $import_directory;
     global $q_warnings;
     global $q_errors;
     if (stripos(" " . $text, "<img") > 0) {
         $output = '';
         while ($text) {
             if (stripos(" " . $text, "<img") > 0) {
                 $pre = substr($text, 0, stripos($text, "<img"));
                 $imgtag = substr($text, stripos($text, "<img"));
                 $imgtag = substr($imgtag, 0, stripos($imgtag, ">") + 1);
                 $rest = substr($text, stripos($text, "<img"));
                 $rest = substr($rest, stripos($rest, ">") + 1);
                 $output .= $pre;
                 // we have a src tag?
                 if (stripos($imgtag, "src") > 0) {
                     $data = parseHtml($imgtag);
                     $src = $data['IMG'][0]['src'];
                     $basename = basename($src);
                     $filename = FindFile($import_directory, $basename);
                     if ($filename) {
                         $basename = basename($filename);
                         $uniqueFilename = unique_filename($basename);
                         copy($import_directory . "/" . $filename, $cfg_web_root . 'media/' . $uniqueFilename);
                         $data['IMG'][0]['src'] = "/media/" . $basename;
                         // recreate img tag
                         $imgtag = "<img ";
                         foreach ($src = $data['IMG'][0] as $tag => $value) {
                             $imgtag .= "{$tag}=\"{$value}\" ";
                         }
                         $imgtag .= "/>";
                     } else {
                         $q_warnings[] = "Missing image {$basename}";
                     }
                 }
                 $output .= $imgtag;
                 $text = $rest;
             } else {
                 $output .= $text;
                 $text = "";
             }
         }
         $text = $output;
     }
     return $text;
 }