Exemple #1
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;
 }
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     $user =& $request->_user;
     if (isa($request, 'MockRequest')) {
         return '';
     }
     if (!$request->isActionPage($request->getArg('pagename')) and (!isset($user->_prefs->_method) or !in_array($user->_prefs->_method, array('ADODB', 'SQL'))) or in_array($request->getArg('action'), array('zip', 'ziphtml', 'dumphtml')) or isa($user, '_ForbiddenUser')) {
         $no_args = $this->getDefaultArguments();
         // ?
         //            foreach ($no_args as $key => $value) {
         //                $no_args[$value] = false;
         //            }
         $no_args['errmsg'] = HTML(HTML::h2(_("Error: The user HomePage must be a valid WikiWord. Sorry, UserPreferences cannot be saved."), HTML::hr()));
         $no_args['isForm'] = false;
         return Template('userprefs', $no_args);
     }
     $userid = $user->UserName();
     if ($user->isAuthenticated() and !empty($userid)) {
         $pref =& $request->_prefs;
         $args['isForm'] = true;
         //trigger_error("DEBUG: reading prefs from getPreferences".print_r($pref));
         if ($request->isPost()) {
             $errmsg = '';
             $delete = $request->getArg('delete');
             if ($delete and $request->getArg('verify')) {
                 // deleting prefs, verified
                 $default_prefs = $pref->defaultPreferences();
                 $default_prefs['userid'] = $user->UserName();
                 $user->setPreferences($default_prefs);
                 $request->_setUser($user);
                 $request->setArg("verify", false);
                 $request->setArg("delete", false);
                 $alert = new Alert(_("Message"), _("Your UserPreferences have been successfully deleted."));
                 $alert->show();
                 return;
             } elseif ($delete and !$request->getArg('verify')) {
                 return HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), HiddenInputs(array('verify' => 1)), HiddenInputs($request->getArgs()), HTML::p(_("Do you really want to delete all your UserPreferences?")), HTML::p(Button('submit:delete', _("Yes"), 'delete'), HTML::Raw(' '), Button('cancel', _("Cancel"))));
             } elseif ($rp = $request->getArg('pref')) {
                 // replace only changed prefs in $pref with those from request
                 if (!empty($rp['passwd']) and $rp['passwd2'] != $rp['passwd']) {
                     $errmsg = _("Wrong password. Try again.");
                 } else {
                     //trigger_error("DEBUG: reading prefs from request".print_r($rp));
                     //trigger_error("DEBUG: writing prefs with setPreferences".print_r($pref));
                     if (empty($rp['passwd'])) {
                         unset($rp['passwd']);
                     }
                     // fix to set system pulldown's. empty values don't get posted
                     if (empty($rp['theme'])) {
                         $rp['theme'] = '';
                     }
                     if (empty($rp['lang'])) {
                         $rp['lang'] = '';
                     }
                     $num = $user->setPreferences($rp);
                     if (!empty($rp['passwd'])) {
                         $passchanged = false;
                         if ($user->mayChangePass()) {
                             if (method_exists($user, 'storePass')) {
                                 $passchanged = $user->storePass($rp['passwd']);
                             }
                             if (!$passchanged and method_exists($user, 'changePass')) {
                                 $passchanged = $user->changePass($rp['passwd']);
                             }
                             if ($passchanged) {
                                 $errmsg = _("Password updated.");
                             } else {
                                 $errmsg = _("Password was not changed.");
                             }
                         } else {
                             $errmsg = _("Password cannot be changed.");
                         }
                     }
                     if (!$num) {
                         $errmsg .= " " . _("No changes.");
                     } else {
                         $request->_setUser($user);
                         $pref = $user->_prefs;
                         $errmsg .= sprintf(_("%d UserPreferences fields successfully updated."), $num);
                     }
                 }
                 $args['errmsg'] = HTML(HTML::h2($errmsg), HTML::hr());
             }
         }
         $args['available_themes'] = listAvailableThemes();
         $args['available_languages'] = listAvailableLanguages();
         return Template('userprefs', $args);
     } else {
         // wrong or unauthenticated user
         return $request->_notAuthorized(WIKIAUTH_BOGO);
         //return $user->PrintLoginForm ($request, $args, false, false);
     }
 }
Exemple #3
0
 function supported_languages()
 {
     $available_languages = listAvailableLanguages();
     natcasesort($available_languages);
     return sprintf(_("Total of %d languages: "), count($available_languages)) . implode(', ', $available_languages) . ". " . sprintf(_("Current language: '%s'"), $GLOBALS['LANG']) . (DEFAULT_LANGUAGE != $GLOBALS['LANG'] ? ". " . sprintf(_("Default language: '%s'"), DEFAULT_LANGUAGE) : '');
 }