Esempio n. 1
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);
}
Esempio n. 2
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);
}
Esempio n. 3
0
function CheckPgsrcUpdate(&$request, $checkonly = false)
{
    echo "<h3>", _("check for necessary pgsrc updates"), "</h3>\n";
    $dbi = $request->getDbh();
    $path = FindLocalizedFile(WIKI_PGSRC);
    $pgsrc = new fileSet($path);
    // fixme: verification, ...
    $isHomePage = false;
    foreach ($pgsrc->getFiles() as $filename) {
        if (substr($filename, -1, 1) == '~') {
            continue;
        }
        $pagename = urldecode($filename);
        // don't ever update the HomePage
        if (defined(HOME_PAGE)) {
            if ($pagename == HOME_PAGE) {
                $isHomePage = true;
            } else {
                if ($pagename == _("HomePage")) {
                    $isHomePage = true;
                }
            }
        }
        if ($pagename == "HomePage") {
            $isHomePage = true;
        }
        if ($isHomePage) {
            echo "{$path}/{$pagename}: ", _("always skip the HomePage."), _(" skipped"), ".<br />\n";
            $isHomePage = false;
            continue;
        }
        if (!isActionPage($filename)) {
            doPgsrcUpdate($request, $pagename, $path, $filename, $checkonly);
        }
    }
    return;
}
Esempio n. 4
0
function update_locale($loc)
{
    // $LANG or DEFAULT_LANGUAGE is too less information, at least on unix for
    // setlocale(), for bindtextdomain() to succeed.
    $setlocale = guessing_setlocale(LC_ALL, $loc);
    // [56ms]
    if (!$setlocale) {
        // system has no locale for this language, so gettext might fail
        $setlocale = FileFinder::_get_lang();
        list($setlocale, ) = split('_', $setlocale, 2);
        $setlocale = guessing_setlocale(LC_ALL, $setlocale);
        // try again
        if (!$setlocale) {
            $setlocale = $loc;
        }
    }
    // Try to put new locale into environment (so any
    // programs we run will get the right locale.)
    if (!function_exists('bindtextdomain')) {
        // Reinitialize translation array.
        global $locale;
        $locale = array();
        // do reinit to purge PHP's static cache [43ms]
        if ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok', 'reinit')) {
            include $lcfile;
        }
    } else {
        // If PHP is in safe mode, this is not allowed,
        // so hide errors...
        @putenv("LC_ALL={$setlocale}");
        @putenv("LANG={$loc}");
        @putenv("LANGUAGE={$loc}");
    }
    // To get the POSIX character classes in the PCRE's (e.g.
    // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
    // to set the locale, using setlocale().
    //
    // The problem is which locale to set?  We would like to recognize all
    // upper-case characters in the iso-8859-1 character set as upper-case
    // characters --- not just the ones which are in the current $LANG.
    //
    // As it turns out, at least on my system (Linux/glibc-2.2) as long as
    // you setlocale() to anything but "C" it works fine.  (I'm not sure
    // whether this is how it's supposed to be, or whether this is a bug
    // in the libc...)
    //
    // We don't currently use the locale setting for anything else, so for
    // now, just set the locale to US English.
    //
    // FIXME: Not all environments may support en_US?  We should probably
    // have a list of locales to try.
    if (setlocale(LC_CTYPE, 0) == 'C') {
        $x = setlocale(LC_CTYPE, 'en_US.' . $GLOBALS['charset']);
    } else {
        $x = setlocale(LC_CTYPE, $setlocale);
    }
    return $loc;
}
Esempio n. 5
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;
 }
Esempio n. 6
0
 function CheckPgsrcUpdate()
 {
     // Check some theme specific pgsrc files (blog, wikilens, fusionforge, custom).
     // We check theme specific pgsrc first in case the page is present in both
     // theme specific and global pgsrc
     global $WikiTheme;
     $path = $WikiTheme->file("pgsrc");
     // TBD: the call to fileSet prints a warning:
     // Notice: Unable to open directory 'themes/MonoBook/pgsrc' for reading
     $pgsrc = new fileSet($path);
     if ($pgsrc->getFiles()) {
         echo "<h3>", sprintf(_("Check for necessary theme %s updates"), "pgsrc"), "</h3>\n";
         foreach ($pgsrc->getFiles() as $filename) {
             if (substr($filename, -1, 1) == '~') {
                 continue;
             }
             if (substr($filename, -5, 5) == '.orig') {
                 continue;
             }
             $pagename = urldecode($filename);
             $this->doPgsrcUpdate($pagename, $path, $filename);
         }
     }
     echo "<h3>", sprintf(_("Check for necessary %s updates"), "pgsrc"), "</h3>\n";
     if ($this->db_version < 1030.12200612) {
         echo "<h4>", _("rename to Help: pages"), "</h4>\n";
     }
     $path = FindLocalizedFile(WIKI_PGSRC);
     $pgsrc = new fileSet($path);
     // fixme: verification, ...
     foreach ($pgsrc->getFiles() as $filename) {
         if (substr($filename, -1, 1) == '~') {
             continue;
         }
         if (substr($filename, -5, 5) == '.orig') {
             continue;
         }
         $pagename = urldecode($filename);
         if (!isActionPage($filename)) {
             // There're a lot of now unneeded pages around.
             // At first rename the BlaPlugin pages to Help/<pagename> and then to the update.
             if ($this->db_version < 1030.12200612) {
                 $this->_rename_to_help_page($pagename);
             }
             $this->doPgsrcUpdate($pagename, $path, $filename);
         }
     }
 }
Esempio n. 7
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);
}