From 88ccac6ab26a49b40766d2fe1310073adf4ca7dc Mon Sep 17 00:00:00 2001 From: rurban Date: Thu, 27 May 2004 17:49:06 +0000 Subject: [PATCH] renamed DB_Session to DbSession (in CVS also) added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals remove leading slash in error message added force_unlock parameter to File_Passwd (no return on stale locks) fixed adodb session AffectedRows added FileFinder helpers to unify local filenames and DATA_PATH names editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@3563 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/DbSession.php | 54 ++++---- lib/ErrorManager.php | 16 ++- lib/FileFinder.php | 148 ++++++++++++++++----- lib/IniConfig.php | 11 +- lib/PagePerm.php | 21 +-- lib/Theme.php | 49 +++++-- lib/WikiDB.php | 19 ++- lib/WikiUserNew.php | 235 ++++++++++++++++++--------------- lib/editpage.php | 84 +++++++++++- lib/main.php | 25 ++-- lib/pear/File_Passwd.php | 21 ++- lib/plugin/WhoIsOnline.php | 16 ++- lib/plugin/WikiAdminSetAcl.php | 9 +- lib/plugin/WikiAdminUtils.php | 7 +- 14 files changed, 504 insertions(+), 211 deletions(-) diff --git a/lib/DbSession.php b/lib/DbSession.php index 714438055..560923d02 100644 --- a/lib/DbSession.php +++ b/lib/DbSession.php @@ -1,4 +1,4 @@ - * Minor rewrite by Reini Urban for Phpwiki. * Quasi-major rewrite/decruft/fix by Jeff Dairiki . + * ADODB and dba classes by Reini Urban. */ -class DB_Session +class DbSession { var $_backend; /** @@ -22,19 +23,19 @@ class DB_Session * @param string $table * Name of SQL table containing session data. */ - function DB_Session(&$dbh, $table = 'session') { + function DbSession(&$dbh, $table = 'session') { // Coerce WikiDB to PearDB or ADODB. // Todo: adodb/dba handlers - $db_type = $GLOBALS['DBParams']['dbtype']; + $db_type = $dbh->getParam('dbtype'); if (isa($dbh, 'WikiDB')) { $backend = &$dbh->_backend; $db_type = substr(get_class($dbh),7); - $class = "DB_Session_".$db_type; + $class = "DbSession_".$db_type; // < 4.1.2 crash on dba sessions at session_write_close(). // (Tested with 4.1.1 and 4.1.2) // Didn't try postgres sessions. - if (!check_php_version(4,1,2) and $db_type=='dba') + if (!check_php_version(4,1,2) and $db_type == 'dba') return false; if (class_exists($class)) { @@ -43,8 +44,8 @@ class DB_Session } } //Fixme: E_USER_WARNING ignored! - trigger_error(sprintf( -_("Your WikiDB DB backend '%s' cannot be used for DB_Session. Set USE_DB_SESSION to false."), + trigger_error(sprintf(_("Your WikiDB DB backend '%s' cannot be used for DbSession.")." ". + _("Set USE_DB_SESSION to false."), $db_type), E_USER_WARNING); return false; } @@ -61,12 +62,12 @@ _("Your WikiDB DB backend '%s' cannot be used for DB_Session. Set USE_DB_SESSION } -class DB_Session_SQL -extends DB_Session +class DbSession_SQL +extends DbSession { var $_backend_type = "SQL"; - function DB_Session_SQL (&$dbh, $table) { + function DbSession_SQL (&$dbh, $table) { $this->_dbh = $dbh; $this->_table = $table; @@ -88,7 +89,7 @@ extends DB_Session if (!$this->_connected) { $res = $dbh->connect($dbh->dsn); if (DB::isError($res)) { - error_log("PhpWiki::DB_Session::_connect: " . $res->getMessage()); + error_log("PhpWiki::DbSession::_connect: " . $res->getMessage()); } } return $dbh; @@ -182,7 +183,7 @@ extends DB_Session //$dbh->unlock(false,1); $table = $this->_table; $qid = $dbh->quote($id); - $qip = $dbh->quote($GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR']); + $qip = $dbh->quote($GLOBALS['request']->get('REMOTE_ADDR')); $time = time(); if (DEBUG and $sess_data == 'wiki_user|N;') { trigger_error("delete session $qid",E_USER_WARNING); @@ -199,11 +200,11 @@ extends DB_Session $res = $dbh->query("UPDATE $table" . " SET sess_data=$qdata, sess_date=$time, sess_ip=$qip" . " WHERE sess_id=$qid"); - if ( $dbh->affectedRows() < 1 ) // 0 (none) or -1 (failure) on mysql + if ( $dbh->affectedRows() < 1 ) { // 0 (none) or -1 (failure) on mysql $res = $dbh->query("INSERT INTO $table" . " (sess_id, sess_data, sess_date, sess_ip)" . " VALUES ($qid, $qdata, $time, $qip)"); - + } $this->_disconnect(); return ! DB::isError($res); } @@ -274,12 +275,12 @@ extends DB_Session } // self-written adodb-sessions -class DB_Session_ADODB -extends DB_Session +class DbSession_ADODB +extends DbSession { var $_backend_type = "ADODB"; - function DB_Session_ADODB ($dbh, $table) { + function DbSession_ADODB ($dbh, $table) { $this->_dbh = $dbh; $this->_table = $table; @@ -296,11 +297,11 @@ extends DB_Session } function _connect() { - global $DBParams; + global $request; static $parsed = false; $dbh = &$this->_dbh; if (!$dbh or !is_resource($dbh->_connectionID)) { - if (!$parsed) $parsed = parseDSN($DBParams['dsn']); + if (!$parsed) $parsed = parseDSN($request->_dbi->getParam('dsn')); $this->_dbh = &ADONewConnection($parsed['phptype']); // Probably only MySql works just now $this->_dbh->Connect($parsed['hostspec'],$parsed['username'], $parsed['password'], $parsed['database']); @@ -394,7 +395,7 @@ extends DB_Session $dbh = &$this->_connect(); $table = $this->_table; $qid = $dbh->qstr($id); - $qip = $dbh->qstr($GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR']); + $qip = $dbh->qstr($GLOBALS['request']->get('REMOTE_ADDR')); $time = time(); // postgres can't handle binary data in a TEXT field. @@ -404,10 +405,11 @@ extends DB_Session $rs = $dbh->Execute("UPDATE $table" . " SET sess_data=$qdata, sess_date=$time, sess_ip=$qip" . " WHERE sess_id=$qid"); - if ( $dbh->Affected_Rows() < 1 ) // 0 (none) or -1 (failure) on mysql + if ( ! $dbh->Affected_Rows() ) { // false or int $rs = $dbh->Execute("INSERT INTO $table" . " (sess_id, sess_data, sess_date, sess_ip)" . " VALUES ($qid, $qdata, $time, $qip)"); + } $result = ! $rs->EOF; if ($result) $rs->free(); $this->_disconnect(); @@ -489,12 +491,12 @@ extends DB_Session * Index: session_id * Values: date : IP : data */ -class DB_Session_dba -extends DB_Session +class DbSession_dba +extends DbSession { var $_backend_type = "dba"; - function DB_Session_dba (&$dbh, $table) { + function DbSession_dba (&$dbh, $table) { $this->_dbh = $dbh; ini_set('session.save_handler','user'); session_module_name('user'); // new style @@ -561,7 +563,7 @@ extends DB_Session function write ($id, $sess_data) { $dbh = &$this->_connect(); $time = time(); - $ip = $GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR']; + $ip = $GLOBALS['request']->get('REMOTE_ADDR'); $dbh->set($id,$time.':'.$ip.':'.$sess_data); $this->_disconnect(); return true; diff --git a/lib/ErrorManager.php b/lib/ErrorManager.php index cf6079e31..0b85ce4bc 100644 --- a/lib/ErrorManager.php +++ b/lib/ErrorManager.php @@ -1,4 +1,4 @@ -errfile = str_replace('/','\\',$this->errfile); - } + $dir .= "\\"; + } else + $dir .= '/'; $errfile = preg_replace('|^' . preg_quote($dir) . '|', '', $this->errfile); $lines = explode("\n", $this->errstr); @@ -479,11 +481,13 @@ class PhpErrorOnce extends PhpError { $what = 'Warning'; else $what = 'Fatal'; - $dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR : getcwd(); + $dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR : substr(dirname(__FILE__),0,-4); if (substr(PHP_OS,0,3) == 'WIN') { $dir = str_replace('/','\\',$dir); $this->errfile = str_replace('/','\\',$this->errfile); - } + $dir .= "\\"; + } else + $dir .= '/'; $errfile = preg_replace('|^' . preg_quote($dir) . '|', '', $this->errfile); $lines = explode("\n", $this->errstr); $msg = sprintf("%s:%d: %s[%d]: %s %s", @@ -509,6 +513,8 @@ if (!isset($GLOBALS['ErrorManager'])) { $GLOBALS['ErrorManager'] = new ErrorManager; } +// $Log: not supported by cvs2svn $ +// // (c-file-style: "gnu") // Local Variables: diff --git a/lib/FileFinder.php b/lib/FileFinder.php index 9bfb3d230..cdb54e662 100644 --- a/lib/FileFinder.php +++ b/lib/FileFinder.php @@ -1,4 +1,4 @@ -_not_found($file); } + /** + * Unify used pathsep character. + * Accepts array of paths also. + * This might not work on Windows95 or FAT volumes. (not tested) + */ function slashifyPath ($path) { + return $this->forcePathSlashes($path, $this->_pathsep); + } + + /** + * Force using '/' as path seperator. + */ + function forcePathSlashes ($path, $sep='/') { if (is_array($path)) { $result = array(); - foreach ($path as $dir) { $result[] = $this->slashifyPath($dir); } + foreach ($path as $dir) { $result[] = $this->forcePathSlashes($dir,$sep); } return $result; } else { - if ($this->_isOtherPathsep()) - return strtr($path,$this->_use_path_separator($path),'/'); - else + if ($this->_isOtherPathsep()) { + if (isMac()) $from = ":"; + elseif (isWindows()) $from = "\\"; + else $from = "\\"; + return strtr($path, $from, $sep); + } else return $path; } } @@ -74,12 +89,11 @@ class FileFinder return $ret; if (!$this->_is_abs($file)) { - if ( ($dir = $this->_search_path($file)) && is_file("$dir/$file")) { + if ( ($dir = $this->_search_path($file)) && is_file($dir . $this->_pathsep . $file)) { $this->_append_to_include_path($dir); return include_once($file); } } - return $this->_not_found($file); } @@ -98,8 +112,8 @@ class FileFinder */ function _get_syspath_separator () { if (!empty($this->_pathsep)) return $this->_pathsep; - elseif (isWindowsNT()) return '\\'; - elseif (isWindows()) return '\\'; + elseif (isWindowsNT()) return "/"; // we can safely use '/' + elseif (isWindows()) return "\\"; // FAT might use '\' elseif (isMac()) return ':'; // MacOsX is / // VMS or LispM is really weird, we ignore it. else return '/'; @@ -107,19 +121,23 @@ class FileFinder /** * The path-separator character of the given path. - * Windows accepts / also, but gets confused with mixed path_separators, + * Windows accepts "/" also, but gets confused with mixed path_separators, * e.g "C:\Apache\phpwiki/locale/button" - * > dir C:\Apache\phpwiki/locale/button => + * > dir "C:\Apache\phpwiki/locale/button" => * Parameterformat nicht korrekt - "locale" - * So if there's any \\ in the path, either fix them to / (not in Win95!) - * or use \\ for ours. + * So if there's any '\' in the path, either fix them to '/' (not in Win95 or FAT?) + * or use '\' for ours. * * @access private * @return string path_separator. */ function _use_path_separator ($path) { if (isWindows95()) { - return (strchr($path,'\\')) ? '\\' : '/'; + if (empty($path)) return "\\"; + else return (strchr($path,"\\")) ? "\\" : '/'; + } elseif (isMac()) { + if (empty($path)) return ":"; + else return (strchr($path,":")) ? ":" : '/'; } else { return $this->_get_syspath_separator(); } @@ -138,6 +156,24 @@ class FileFinder else return false; } + /** + * Strip ending '/' or '\' from path. + * + * @access private + * @param $path string Path. + * @return bool New path (destructive) + */ + function _strip_last_pathchar(&$path) { + if (isMac()) { + if (substr($path,-1) == ':' or substr($path,-1) == "/") + $path = substr($path,0,-1); + } else { + if (substr($path,-1) == '/' or substr($path,-1) == "\\") + $path = substr($path,0,-1); + } + return $path; + } + /** * Report a "file not found" error. * @@ -166,7 +202,7 @@ class FileFinder $file = $this->slashifyPath($file); if (file_exists($dir . $this->_pathsep . $file)) return $dir; - } elseif (@file_exists("$dir/$file")) + } elseif (@file_exists($dir . $this->_pathsep . $file)) return $dir; } return false; @@ -330,7 +366,7 @@ class PearFileFinder * "de_DE.iso8859-1", "de_DE" and "de". */ class LocalizedFileFinder - extends FileFinder +extends FileFinder { /** * Constructor. @@ -343,13 +379,14 @@ class LocalizedFileFinder $lang = $this->_get_lang(); assert(!empty($lang)); - if ($locales = $this->locale_versions($lang)) - foreach ($locales as $lang) { - if ($lang == 'C') $lang='en'; - foreach ($include_path as $dir) { - $path[] = $this->slashifyPath($dir) . "/locale/$lang"; + if ($locales = $this->locale_versions($lang)) { + foreach ($locales as $lang) { + if ($lang == 'C') $lang = 'en'; + foreach ($include_path as $dir) { + $path[] = $this->slashifyPath($dir . "/locale/$lang"); + } } - } + } $this->FileFinder(array_merge($path, $include_path)); } } @@ -366,7 +403,7 @@ class LocalizedFileFinder * "de_DE.iso8859-1", "de_DE" and "de". */ class LocalizedButtonFinder - extends FileFinder +extends FileFinder { /** * Constructor. @@ -384,9 +421,9 @@ class LocalizedButtonFinder $langs = $this->locale_versions($lang); foreach ($langs as $lang) { - if ($lang == 'C') $lang='en'; + if ($lang == 'C') $lang = 'en'; foreach ($include_path as $dir) { - $path[] = $Theme->file("buttons/$lang"); + $path[] = $this->slashifyPath($Theme->file("buttons/$lang")); } } @@ -404,11 +441,12 @@ function FindFile ($file, $missing_okay = false, $slashify = false) $wikidir = preg_replace('/.lib$/','',dirname(__FILE__)); $finder->_append_to_include_path($wikidir); $finder->_append_to_include_path(dirname(__FILE__)."/pear"); - define("INCLUDE_PATH",implode($finder->_get_ini_separator(), $finder->_path)); + // Don't override existing INCLUDE_PATH config. + define("INCLUDE_PATH", implode($finder->_get_ini_separator(), $finder->_path)); } $s = $finder->findFile($file, $missing_okay); if ($slashify) - $s = $finder->slashifyPath($s); + $s = $finder->slashifyPath($s); return $s; } @@ -430,6 +468,49 @@ function FindLocalizedButtonFile ($file, $missing_okay = false, $re_init = false return $buttonfinder->findFile($file, $missing_okay); } +/** + * Prefixes with PHPWIKI_DIR and slashify. + * For example to unify with + * require_once dirname(__FILE__).'/lib/file.php' + * require_once 'lib/file.php' loading style. + * Doesn't expand "~" or symlinks yet. truename would be perfect. + * + * NormalizeLocalFileName("lib/config.php") => /home/user/phpwiki/lib/config.php + */ +function NormalizeLocalFileName($file) { + static $finder; + if (!isset($finder)) { + $finder = new FileFinder; + } + // remove "/lib" from dirname(__FILE__) + if (defined("PHPWIKI_DIR")) $wikidir = PHPWIKI_DIR; + else $wikidir = preg_replace('/.lib$/','',dirname(__FILE__)); + $wikidir = $finder->_strip_last_pathchar($wikidir); + $pathsep = $finder->_use_path_separator($wikidir); + // return PHPWIKI_DIR . "/" . $file; + return $finder->slashifyPath($wikidir . $pathsep . $file); +} + +/** + * Prefixes with DATA_PATH and slashify + */ +function NormalizeWebFileName($file) { + static $finder; + if (!isset($finder)) { + $finder = new FileFinder; + } + if (defined("DATA_PATH")) { + $wikipath = DATA_PATH; + $wikipath = $finder->_strip_last_pathchar($wikipath); + if (!$file) + return $finder->forcePathSlashes($wikipath); + else + return $finder->forcePathSlashes($wikipath . '/' . $file); + } else { + return $finder->forcePathSlashes($file); + } +} + function isWindows() { static $win; if (isset($win)) return $win; @@ -457,10 +538,14 @@ function isWindowsNT() { return $winnt; } -// So far not supported. This has really ugly pathname semantics. -// :path is relative, Desktop:path (I think) is absolute. Please fix this someone. +/** + * This is for the OLD Macintosh OS, NOT MacOSX or Darwin! + * This has really ugly pathname semantics. + * ":path" is relative, "Desktop:path" (I think) is absolute. + * FIXME: Please fix this someone. So far not supported. + */ function isMac() { - return (substr(PHP_OS,0,3) == 'MAC'); // not tested! + return (substr(PHP_OS,0,9) == 'Macintosh'); // not tested! } // probably not needed, same behaviour as on unix. @@ -468,6 +553,9 @@ function isCygwin() { return (substr(PHP_OS,0,6) == 'CYGWIN'); } +// $Log: not supported by cvs2svn $ +// + // Local Variables: // mode: php // tab-width: 8 diff --git a/lib/IniConfig.php b/lib/IniConfig.php index 05f41e725..817dab5ac 100644 --- a/lib/IniConfig.php +++ b/lib/IniConfig.php @@ -1,5 +1,5 @@ exists() ) { $perm = new PagePermission(); - return ($perm->isAuthorized($access,$request->_user) === true); + return ($perm->isAuthorized($access, $request->_user) === true); } // no ACL defined; check for special dotfile or walk down if (! ($perm = getPagePermissions($page))) { if ($pagename[0] == '.') { $perm = new PagePermission(PagePermission::dotPerms()); - return ($perm->isAuthorized($access,$request->_user) === true); + return ($perm->isAuthorized($access, $request->_user) === true); } - return _requiredAuthorityForPagename($access,getParentPage($pagename)); + return _requiredAuthorityForPagename($access, getParentPage($pagename)); } // ACL defined; check if isAuthorized returns true or false or undecided - $authorized = $perm->isAuthorized($access,$request->_user); + $authorized = $perm->isAuthorized($access, $request->_user); if ($authorized != -1) // -1 for undecided return $authorized; else - return _requiredAuthorityForPagename($access,getParentPage($pagename)); + return _requiredAuthorityForPagename($access, getParentPage($pagename)); } /** @@ -314,10 +314,10 @@ class PagePermission { if (is_array($hash) and !empty($hash)) { $accessTypes = $this->accessTypes(); foreach ($hash as $access => $requires) { - if (in_array($access,$accessTypes)) + if (in_array($access, $accessTypes)) $this->perm[$access] = $requires; else - trigger_error(sprintf(_("Unsupported ACL access type %s ignored."),$access), + trigger_error(sprintf(_("Unsupported ACL access type %s ignored."), $access), E_USER_WARNING); } } else { @@ -664,6 +664,11 @@ class PagePermission { } // $Log: not supported by cvs2svn $ +// Revision 1.17 2004/05/16 23:10:44 rurban +// update_locale wrongly resetted LANG, which broke japanese. +// japanese now correctly uses EUC_JP, not utf-8. +// more charset and lang headers to help the browser. +// // Revision 1.16 2004/05/16 22:32:53 rurban // setacl icons // diff --git a/lib/Theme.php b/lib/Theme.php index bed8e9350..78120fd0a 100644 --- a/lib/Theme.php +++ b/lib/Theme.php @@ -1,4 +1,4 @@ -_name = $theme_name; - $themes_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/themes" : "themes"; - - $this->_path = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/" : ""; + $this->_themes_dir = NormalizeLocalFileName("themes"); + $this->_path = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : ""; $this->_theme = "themes/$theme_name"; if ($theme_name != 'default') @@ -209,7 +208,7 @@ class Theme { } function _findFile ($file, $missing_okay = false) { - if (file_exists($this->_path . "$this->_theme/$file")) + if (file_exists($this->file($file))) return "$this->_theme/$file"; // FIXME: this is a short-term hack. Delete this after all files @@ -217,7 +216,6 @@ class Theme { if (file_exists($this->_path . $file)) return $file; - if (isset($this->_default_theme)) { return $this->_default_theme->_findFile($file, $missing_okay); } @@ -371,7 +369,7 @@ class Theme { $mtime = $revision->get('mtime'); if ($mtime <= EPOCH) - return fmt("Never edited."); + return fmt("Never edited"); if ($show_version == 'auto') $show_version = !$revision->isCurrent(); @@ -382,9 +380,9 @@ class Theme { $date, $this->formatTime($mtime)); if ($show_version) - return fmt("Version %s, saved %s.", $revision->getVersion(), $date); + return fmt("Version %s, saved %s", $revision->getVersion(), $date); else - return fmt("Last edited %s.", $date); + return fmt("Last edited %s", $date); } if ($this->_showModTime) @@ -393,9 +391,9 @@ class Theme { $date = $this->formatDate($mtime); if ($show_version) - return fmt("Version %s, saved on %s.", $revision->getVersion(), $date); + return fmt("Version %s, saved on %s", $revision->getVersion(), $date); else - return fmt("Last edited on %s.", $date); + return fmt("Last edited on %s", $date); } function _relativeDay ($time_t) { @@ -422,6 +420,32 @@ class Theme { return false; } + /** + * Format the "Author" and "Owner" messages for a page revision. + */ + function getOwnerMessage ($page) { + $dbi =& $GLOBALS['request']->_dbi; + $owner = $page->getOwner(); + if ($owner) { + if ( $dbi->isWikiPage($owner) ) + return fmt("Owner: %s", WikiLink($owner)); + else + return fmt("Owner: \"%s\"", $owner); + } + } + function getAuthorMessage ($revision, $only_authenticated = true) { + $dbi =& $GLOBALS['request']->_dbi; + $author = $revision->get('author_id'); + if ( $author or $only_authenticated ) { + if (!$author) $author = $revision->get('author'); + if (!$author) return ''; + if ( $dbi->isWikiPage($author) ) + return fmt("by %s", WikiLink($author)); + else + return fmt("by \"%s\"", $author); + } + } + //////////////////////////////////////////////////////////////// // // Hooks for other formatting @@ -1319,6 +1343,9 @@ function listAvailableLanguages() { } // $Log: not supported by cvs2svn $ +// Revision 1.97 2004/05/18 16:23:39 rurban +// rename split_pagename to SplitPagename +// // Revision 1.96 2004/05/13 13:48:34 rurban // doc update for the new 1.3.10 release // diff --git a/lib/WikiDB.php b/lib/WikiDB.php index f2071dc7c..0c6d96052 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -1,5 +1,5 @@ _userid = $UserName; if ($this->hasHomePage()) @@ -821,13 +821,14 @@ extends _AnonUser // Check the configured Prefs methods $dbi = $this->getAuthDbh(); - if ( $dbi and !isset($this->_prefs->_select) and !empty($DBAuthParams['pref_select'])) { - $this->_prefs->_method = $DBParams['dbtype']; - $this->_prefs->_select = $this->prepare($DBAuthParams['pref_select'],"userid"); + $dbh = $GLOBALS['request']->getDbh(); + if ( $dbi and !isset($this->_prefs->_select) and $dbh->getAuthParam('pref_select')) { + $this->_prefs->_method = $dbh->getParam('dbtype'); + $this->_prefs->_select = $this->prepare($dbh->getAuthParam('pref_select'), "userid"); // read-only prefs? - if ( !isset($this->_prefs->_update) and !empty($DBAuthParams['pref_update'])) { - $this->_prefs->_update = $this->prepare($DBAuthParams['pref_update'], - array("userid","pref_blob")); + if ( !isset($this->_prefs->_update) and $dbh->getAuthParam('pref_update')) { + $this->_prefs->_update = $this->prepare($dbh->getAuthParam('pref_update'), + array("userid", "pref_blob")); } } else { $this->_prefs->_method = 'HomePage'; @@ -863,8 +864,8 @@ extends _AnonUser /*PHP5 patch*/$this = $user; return $user; } - } elseif (!empty($DBAuthParams['auth_check']) and - (!empty($DBAuthParams['auth_dsn']) or !empty($GLOBALS ['DBParams']['dsn']))) { + } elseif ($dbh->getAuthParam('auth_check') and + ($dbh->getAuthParam('auth_dsn') or $dbh->getParam('dsn'))) { if (check_php_version(5)) return new _DbPassUser($UserName,$this->_prefs); else { @@ -873,7 +874,8 @@ extends _AnonUser /*PHP5 patch*/$this = $user; return $user; } - } elseif (defined('LDAP_AUTH_HOST') and defined('LDAP_BASE_DN') and function_exists('ldap_open')) { + } elseif (defined('LDAP_AUTH_HOST') and defined('LDAP_BASE_DN') and + function_exists('ldap_open')) { if (check_php_version(5)) return new _LDAPPassUser($UserName,$this->_prefs); else { @@ -891,11 +893,11 @@ extends _AnonUser /*PHP5 patch*/$this = $user; return $user; } - } elseif (defined('AUTH_USER_FILE')) { + } elseif (defined('AUTH_USER_FILE') and file_exists(AUTH_USER_FILE)) { if (check_php_version(5)) - return new _FilePassUser($UserName,$this->_prefs); + return new _FilePassUser($UserName, $this->_prefs); else { - $user = new _FilePassUser($UserName,$this->_prefs); + $user = new _FilePassUser($UserName, $this->_prefs); //todo: with php5 comment the following line. /*PHP5 patch*/$this = $user; return $user; @@ -919,28 +921,29 @@ extends _AnonUser } function getAuthDbh () { - global $request, $DBParams, $DBAuthParams; + global $request; //, $DBParams, $DBAuthParams; + $dbh = $request->getDbh(); // session restauration doesn't re-connect to the database automatically, // so dirty it here. - if (($DBParams['dbtype'] == 'SQL') and isset($this->_auth_dbi) and + if (($dbh->getParam('dbtype') == 'SQL') and isset($this->_auth_dbi) and empty($this->_auth_dbi->connection)) unset($this->_auth_dbi); - if (($DBParams['dbtype'] == 'ADODB') and isset($this->_auth_dbi) and + if (($dbh->getParam('dbtype') == 'ADODB') and isset($this->_auth_dbi) and empty($this->_auth_dbi->_connectionID)) unset($this->_auth_dbi); if (empty($this->_auth_dbi)) { - if ($DBParams['dbtype'] != 'SQL' and $DBParams['dbtype'] != 'ADODB') + if ($dbh->getParam('dbtype') != 'SQL' and $dbh->getParam('dbtype') != 'ADODB') return false; - if (empty($DBAuthParams)) + if (empty($GLOBALS['DBAuthParams'])) return false; - if (empty($DBAuthParams['auth_dsn'])) { + if (!$dbh->getAuthParam('auth_dsn')) { $dbh = $request->getDbh(); // use phpwiki database - } elseif ($DBAuthParams['auth_dsn'] == $DBParams['dsn']) { + } elseif ($dbh->getAuthParam('auth_dsn') == $dbh->getParam('dsn')) { $dbh = $request->getDbh(); // same phpwiki database } else { // use another external database handle. needs PHP >= 4.1 - $local_params = array_merge($DBParams,$DBAuthParams); + $local_params = array_merge($GLOBALS['DBParams'],$GLOBALS['DBAuthParams']); $local_params['dsn'] = $local_params['auth_dsn']; $dbh = WikiDB::open($local_params); } @@ -963,7 +966,8 @@ extends _AnonUser // TODO: use it again for the auth and member tables function prepare ($stmt, $variables, $oldstyle = false) { - global $DBParams, $request; + global $request; + $dbi = $request->getDbh(); $this->getAuthDbh(); // "'\$userid"' => '%s' // variables can be old-style: '"\$userid"' or new-style: "'$userid'" or just "userid" @@ -988,14 +992,11 @@ extends _AnonUser if (!$var) $new = ''; else $new = '%s'; } + $prefix = $dbi->getParam('prefix'); // probably prefix table names if in same database - if (!empty($DBParams['prefix']) and - isset($this->_auth_dbi) and - isset($request->_dbi->_backend->_dbh) and - (!empty($GLOBALS['DBAuthParams']['auth_dsn']) and - $DBParams['dsn'] == $GLOBALS['DBAuthParams']['auth_dsn'])) + if ($prefix and isset($this->_auth_dbi) and isset($dbi->_backend->_dbh) and + ($dbi->getAuthParam('auth_dsn') and $dbi->getParam('dsn') == $dbi->getAuthParam('auth_dsn'))) { - $prefix = $DBParams['prefix']; if (!stristr($stmt, $prefix)) { //Do it automatically for the lazy admin? Esp. on sf.net it's nice to have trigger_error("TODO: Need to prefix the DBAuthParam tablename in index.php:\n $stmt", @@ -1387,8 +1388,22 @@ extends _PassUser exit; } $sess =& $GLOBALS['HTTP_SESSION_VARS']; - // FIXME: user hash: "[user][userid]" or object "user->id" - $this->_userid = $sess[AUTH_SESS_USER]; + // user hash: "[user][userid]" or object "user->id" + if (strstr(AUTH_SESS_USER,"][")) { + $sess = $GLOBALS['HTTP_SESSION_VARS']; + // recurse into hashes: "[user][userid]", sess = sess[user] => sess = sess[userid] + foreach (split("][",AUTH_SESS_USER) as $v) { + $v = str_replace(array("[","]"),'',$v); + $sess = $sess[$v]; + } + $this->_userid = $sess; + } elseif (strstr(AUTH_SESS_USER,"->")) { + // object "user->id" (no objects inside hashes supported!) + list($obj,$key) = split("->",AUTH_SESS_USER); + $this->_userid = $sess[$obj]->$key; + } else { + $this->_userid = $sess[AUTH_SESS_USER]; + } if (!isset($this->_prefs->_method)) _PassUser::_PassUser($this->_userid); $this->_level = AUTH_SESS_LEVEL; @@ -1443,7 +1458,9 @@ extends _PassUser $this->_authmethod = 'Db'; //$this->getAuthDbh(); //$this->_auth_crypt_method = @$GLOBALS['DBAuthParams']['auth_crypt_method']; - if ($GLOBALS['DBParams']['dbtype'] == 'ADODB') { + $dbi =& $GLOBALS['request']->_dbi; + $dbtype = $dbi->getParam('dbtype'); + if ($dbtype == 'ADODB') { if (check_php_version(5)) return new _AdoDbPassUser($UserName,$this->_prefs); else { @@ -1453,7 +1470,7 @@ extends _PassUser return $user; } } - elseif ($GLOBALS['DBParams']['dbtype'] == 'SQL') { + elseif ($dbtype == 'SQL') { if (check_php_version(5)) return new _PearDbPassUser($UserName,$this->_prefs); else { @@ -1485,7 +1502,7 @@ extends _DbPassUser { var $_authmethod = 'PearDb'; function _PearDbPassUser($UserName='',$prefs=false) { - global $DBAuthParams; + //global $DBAuthParams; if (!$this->_prefs and isa($this,"_PearDbPassUser")) { if ($prefs) $this->_prefs = $prefs; } @@ -1494,8 +1511,7 @@ extends _DbPassUser $this->_userid = $UserName; // make use of session data. generally we only initialize this every time, // but do auth checks only once - $this->_auth_crypt_method = @$DBAuthParams['auth_crypt_method']; - //$this->getAuthDbh(); + $this->_auth_crypt_method = $GLOBALS['request']->_dbi->getAuthParam('auth_crypt_method'); return $this; } @@ -1541,6 +1557,9 @@ extends _DbPassUser $dbh->simpleQuery(sprintf($this->_prefs->_update, $dbh->quote($packed), $dbh->quote($this->_userid))); + //delete pageprefs: + if ($this->_HomePagehandle and $this->_HomePagehandle->get('pref')) + $this->_HomePagehandle->set('pref', ''); } else { //store prefs in homepage, not in cookie if ($this->_HomePagehandle and !$id_only) @@ -1552,41 +1571,43 @@ extends _DbPassUser } function userExists() { - global $DBAuthParams; + //global $DBAuthParams; $this->getAuthDbh(); $dbh = &$this->_auth_dbi; if (!$dbh) { // needed? return $this->_tryNextUser(); } + $dbi =& $GLOBALS['request']->_dbi; // Prepare the configured auth statements - if (!empty($DBAuthParams['auth_check']) and empty($this->_authselect)) { - $this->_authselect = $this->prepare($DBAuthParams['auth_check'], - array("userid","password")); + if ($dbi->getAuthParam('auth_check') and empty($this->_authselect)) { + $this->_authselect = $this->prepare($dbi->getAuthParam('auth_check'), + array("userid", "password")); } if (empty($this->_authselect)) - trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'SQL'", + trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'", + 'DBAUTH_AUTH_CHECK', 'SQL'), E_USER_WARNING); //NOTE: for auth_crypt_method='crypt' no special auth_user_exists is needed if ($this->_auth_crypt_method == 'crypt') { - $rs = $dbh->query(sprintf($this->_authselect,$dbh->quote($this->_userid))); + $rs = $dbh->query(sprintf($this->_authselect, $dbh->quote($this->_userid))); if ($rs->numRows()) return true; } else { - if (! $GLOBALS['DBAuthParams']['auth_user_exists']) - trigger_error("\$DBAuthParams['auth_user_exists'] is missing", + if (! $dbi->getAuthParam('auth_user_exists')) + trigger_error(fmt("%s is missing",'DBAUTH_AUTH_USER_EXISTS'), E_USER_WARNING); - $this->_authcheck = $this->prepare($DBAuthParams['auth_user_exists'],"userid"); - $rs = $dbh->query(sprintf($this->_authcheck,$dbh->quote($this->_userid))); + $this->_authcheck = $this->prepare($dbi->getAuthParam('auth_user_exists'),"userid"); + $rs = $dbh->query(sprintf($this->_authcheck, $dbh->quote($this->_userid))); if ($rs->numRows()) return true; } // maybe the user is allowed to create himself. Generally not wanted in // external databases, but maybe wanted for the wiki database, for performance // reasons - if (empty($this->_authcreate) and !empty($DBAuthParams['auth_create'])) { - $this->_authcreate = $this->prepare($DBAuthParams['auth_create'], - array("userid","password")); + if (empty($this->_authcreate) and $dbi->getAuthParam('auth_create')) { + $this->_authcreate = $this->prepare($dbh->getAuthParam('auth_create'), + array("userid", "password")); } if (!empty($this->_authcreate)) { $dbh->simpleQuery(sprintf($this->_authcreate, @@ -1599,7 +1620,7 @@ extends _DbPassUser } function checkPass($submitted_password) { - global $DBAuthParams; + //global $DBAuthParams; $this->getAuthDbh(); if (!$this->_auth_dbi) { // needed? return $this->_tryNextPass($submitted_password); @@ -1607,13 +1628,14 @@ extends _DbPassUser if (!isset($this->_authselect)) $this->userExists(); if (!isset($this->_authselect)) - trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'SQL'", + trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'", + 'DBAUTH_AUTH_CHECK','SQL'), E_USER_WARNING); //NOTE: for auth_crypt_method='crypt' defined('ENCRYPTED_PASSWD',true) must be set $dbh = &$this->_auth_dbi; if ($this->_auth_crypt_method == 'crypt') { - $stored_password = $dbh->getOne(sprintf($this->_authselect,$dbh->quote($this->_userid))); + $stored_password = $dbh->getOne(sprintf($this->_authselect, $dbh->quote($this->_userid))); $result = $this->_checkPass($submitted_password, $stored_password); } else { $okay = $dbh->getOne(sprintf($this->_authselect, @@ -1631,18 +1653,20 @@ extends _DbPassUser } function mayChangePass() { - global $DBAuthParams; - return !empty($DBAuthParams['auth_update']); + return $GLOBALS['request']->_dbi->getAuthParam('auth_update'); } function storePass($submitted_password) { - global $DBAuthParams; - if (!empty($DBAuthParams['auth_update']) and empty($this->_authupdate)) { - $this->_authupdate = $this->prepare($DBAuthParams['auth_update'], - array("userid","password")); + $this->getAuthDbh(); + $dbh = &$this->_auth_dbi; + $dbi =& $GLOBALS['request']->_dbi; + if ($dbi->getAuthParam('auth_update') and empty($this->_authupdate)) { + $this->_authupdate = $this->prepare($dbi->getAuthParam('auth_update'), + array("userid", "password")); } if (empty($this->_authupdate)) { - trigger_error("Either \$DBAuthParams['auth_update'] not defined or \$DBParams['dbtype'] != 'SQL'", + trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'", + 'DBAUTH_AUTH_UPDATE','SQL'), E_USER_WARNING); return false; } @@ -1651,14 +1675,11 @@ extends _DbPassUser if (function_exists('crypt')) $submitted_password = crypt($submitted_password); } - $this->getAuthDbh(); - $dbh = &$this->_auth_dbi; $dbh->simpleQuery(sprintf($this->_authupdate, $dbh->quote($submitted_password), $dbh->quote($this->_userid) )); } - } class _AdoDbPassUser @@ -1683,8 +1704,8 @@ extends _DbPassUser _PassUser::_PassUser($UserName); } $this->_userid = $UserName; - $this->_auth_crypt_method = $GLOBALS['DBAuthParams']['auth_crypt_method']; $this->getAuthDbh(); + $this->_auth_crypt_method = $GLOBALS['request']->_dbi->getAuthParam('auth_crypt_method'); // Don't prepare the configured auth statements anymore return $this; } @@ -1695,7 +1716,7 @@ extends _DbPassUser $this->getAuthDbh(); if (isset($this->_prefs->_select)) { $dbh = & $this->_auth_dbi; - $rs = $dbh->Execute(sprintf($this->_prefs->_select,$dbh->qstr($this->_userid))); + $rs = $dbh->Execute(sprintf($this->_prefs->_select, $dbh->qstr($this->_userid))); if ($rs->EOF) { $rs->Close(); } else { @@ -1732,6 +1753,9 @@ extends _DbPassUser $dbh->qstr($packed), $dbh->qstr($this->_userid))); $db_result->Close(); + //delete pageprefs: + if ($this->_HomePagehandle and $this->_HomePagehandle->get('pref')) + $this->_HomePagehandle->set('pref', ''); } else { //store prefs in homepage, not in cookie if ($this->_HomePagehandle and !$id_only) @@ -1743,22 +1767,23 @@ extends _DbPassUser } function userExists() { - global $DBAuthParams; $this->getAuthDbh(); $dbh = &$this->_auth_dbi; if (!$dbh) { // needed? return $this->_tryNextUser(); } - if (empty($this->_authselect) and !empty($DBAuthParams['auth_check'])) { - $this->_authselect = $this->prepare($DBAuthParams['auth_check'], + $dbi =& $GLOBALS['request']->_dbi; + if (empty($this->_authselect) and $dbi->getAuthParam('auth_check')) { + $this->_authselect = $this->prepare($dbi->getAuthParam('auth_check'), array("userid","password")); } if (empty($this->_authselect)) - trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'ADODB'", + trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'", + 'DBAUTH_AUTH_CHECK', 'ADODB'), E_USER_WARNING); //NOTE: for auth_crypt_method='crypt' no special auth_user_exists is needed if ($this->_auth_crypt_method == 'crypt') { - $rs = $dbh->Execute(sprintf($this->_authselect,$dbh->qstr($this->_userid))); + $rs = $dbh->Execute(sprintf($this->_authselect, $dbh->qstr($this->_userid))); if (!$rs->EOF) { $rs->Close(); return true; @@ -1767,11 +1792,11 @@ extends _DbPassUser } } else { - if (! $DBAuthParams['auth_user_exists']) - trigger_error("\$DBAuthParams['auth_user_exists'] is missing", + if (! $dbi->getAuthParam('auth_user_exists')) + trigger_error(fmt("%s is missing", 'DBAUTH_AUTH_USER_EXISTS'), E_USER_WARNING); - $this->_authcheck = $this->prepare($DBAuthParams['auth_user_exists'],'userid'); - $rs = $dbh->Execute(sprintf($this->_authcheck,$dbh->qstr($this->_userid))); + $this->_authcheck = $this->prepare($dbi->getAuthParam('auth_user_exists'), 'userid'); + $rs = $dbh->Execute(sprintf($this->_authcheck, $dbh->qstr($this->_userid))); if (!$rs->EOF) { $rs->Close(); return true; @@ -1782,13 +1807,14 @@ extends _DbPassUser // maybe the user is allowed to create himself. Generally not wanted in // external databases, but maybe wanted for the wiki database, for performance // reasons - if (empty($this->_authcreate) and !empty($DBAuthParams['auth_create'])) { - $this->_authcreate = $this->prepare($DBAuthParams['auth_create'], - array("userid","password")); + if (empty($this->_authcreate) and $dbi->getAuthParam('auth_create')) { + $this->_authcreate = $this->prepare($dbi->getAuthParam('auth_create'), + array("userid", "password")); } if (!empty($this->_authcreate) and isset($GLOBALS['HTTP_POST_VARS']['auth']) and - isset($GLOBALS['HTTP_POST_VARS']['auth']['passwd'])) { + isset($GLOBALS['HTTP_POST_VARS']['auth']['passwd'])) + { $dbh->Execute(sprintf($this->_authcreate, $dbh->qstr($GLOBALS['HTTP_POST_VARS']['auth']['passwd']), $dbh->qstr($this->_userid))); @@ -1799,24 +1825,26 @@ extends _DbPassUser } function checkPass($submitted_password) { - global $DBAuthParams; + //global $DBAuthParams; $this->getAuthDbh(); if (!$this->_auth_dbi) { // needed? return $this->_tryNextPass($submitted_password); } - if (empty($this->_authselect) and !empty($DBAuthParams['auth_check'])) { - $this->_authselect = $this->prepare($DBAuthParams['auth_check'], - array("userid","password")); + $dbh =& $this->_auth_dbi; + $dbi =& $GLOBALS['request']->_dbi; + if (empty($this->_authselect) and $dbi->getAuthParam('auth_check')) { + $this->_authselect = $this->prepare($dbi->getAuthParam('auth_check'), + array("userid", "password")); } if (!isset($this->_authselect)) $this->userExists(); if (!isset($this->_authselect)) - trigger_error("Either \$DBAuthParams['auth_check'] is missing or \$DBParams['dbtype'] != 'ADODB'", + trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'", + 'DBAUTH_AUTH_CHECK', 'ADODB'), E_USER_WARNING); - $dbh = &$this->_auth_dbi; //NOTE: for auth_crypt_method='crypt' defined('ENCRYPTED_PASSWD',true) must be set if ($this->_auth_crypt_method == 'crypt') { - $rs = $dbh->Execute(sprintf($this->_authselect,$dbh->qstr($this->_userid))); + $rs = $dbh->Execute(sprintf($this->_authselect, $dbh->qstr($this->_userid))); if (!$rs->EOF) { $stored_password = $rs->fields['password']; $rs->Close(); @@ -1825,8 +1853,7 @@ extends _DbPassUser $rs->Close(); $result = false; } - } - else { + } else { $rs = $dbh->Execute(sprintf($this->_authselect, $dbh->qstr($submitted_password), $dbh->qstr($this->_userid))); @@ -1844,18 +1871,20 @@ extends _DbPassUser } function mayChangePass() { - global $DBAuthParams; - return !empty($DBAuthParams['auth_update']); + return $GLOBALS['request']->_dbi->getAuthParam('auth_update'); } function storePass($submitted_password) { - global $DBAuthParams; - if (!isset($this->_authupdate) and !empty($DBAuthParams['auth_update'])) { - $this->_authupdate = $this->prepare($DBAuthParams['auth_update'], - array("userid","password")); + $this->getAuthDbh(); + $dbh = &$this->_auth_dbi; + $dbi =& $GLOBALS['request']->_dbi; + if ($dbi->getAuthParam('auth_update') and empty($this->_authupdate)) { + $this->_authupdate = $this->prepare($dbi->getAuthParam('auth_update'), + array("userid", "password")); } if (!isset($this->_authupdate)) { - trigger_error("Either \$DBAuthParams['auth_update'] not defined or \$DBParams['dbtype'] != 'ADODB'", + trigger_error(fmt("Either %s is missing or DATABASE_TYPE != '%s'", + 'DBAUTH_AUTH_UPDATE', 'ADODB'), E_USER_WARNING); return false; } @@ -1864,8 +1893,6 @@ extends _DbPassUser if (function_exists('crypt')) $submitted_password = crypt($submitted_password); } - $this->getAuthDbh(); - $dbh = &$this->_auth_dbi; $rs = $dbh->Execute(sprintf($this->_authupdate, $dbh->qstr($submitted_password), $dbh->qstr($this->_userid) @@ -2082,8 +2109,8 @@ extends _PassUser // This can only be called from _PassUser, because the parent class // sets the pref methods, before this class is initialized. - function _FilePassUser($UserName='',$prefs=false,$file='') { - if (!$this->_prefs and isa($this,"_FilePassUser")) { + function _FilePassUser($UserName='', $prefs=false, $file='') { + if (!$this->_prefs and isa($this, "_FilePassUser")) { if ($prefs) $this->_prefs = $prefs; if (!isset($this->_prefs->_method)) _PassUser::_PassUser($UserName); @@ -2103,6 +2130,7 @@ extends _PassUser $lock = false; $lockfile = false; } + include_once(dirname(__FILE__)."/pear/File_Passwd.php"); // same style as in main.php // "__PHP_Incomplete_Class" if (!empty($file) or empty($this->_file) or !isa($this->_file,"File_Passwd")) $this->_file = new File_Passwd($file, $lock, $lockfile); @@ -2150,7 +2178,7 @@ extends _PassUser /** * Insert more auth classes here... * For example a customized db class for another db connection - * or a socket-based auth server + * or a socket-based auth server. * */ @@ -2466,18 +2494,16 @@ extends _UserPreference fixed version from http://www.zend.com/zend/spotlight/ev12apr.php */ function ValidateMail($email, $noconnect=false) { - if (!isset($_SERVER)) - $_SERVER =& $GLOBALS['HTTP_SERVER_VARS']; - $HTTP_HOST = $_SERVER['HTTP_HOST']; + $HTTP_HOST = $GLOBALS['request']->get('HTTP_HOST'); $result = array(); // well, technically ".a.a.@host.com" is also valid if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $result[0] = false; - $result[1] = sprintf(_("E-Mail address '%s' is not properly formatted"),$email); + $result[1] = sprintf(_("E-Mail address '%s' is not properly formatted"), $email); return $result; } if ($noconnect) - return array(true,sprintf(_("E-Mail address '%s' is properly formatted"),$email)); + return array(true,sprintf(_("E-Mail address '%s' is properly formatted"), $email)); list ( $Username, $Domain ) = split ("@",$email); //Todo: getmxrr workaround on windows or manual input field to verify it manually @@ -2853,6 +2879,9 @@ extends UserPreferences // $Log: not supported by cvs2svn $ +// Revision 1.77 2004/05/18 14:49:51 rurban +// Simplified strings for easier translation +// // Revision 1.76 2004/05/18 13:30:04 rurban // prevent from endless loop with oldstyle warnings // diff --git a/lib/editpage.php b/lib/editpage.php index 9ef0d0a0a..fa57bbce1 100644 --- a/lib/editpage.php +++ b/lib/editpage.php @@ -1,5 +1,5 @@ addMoreAttr('body'," onload='define_f()'"); + } else { + $GLOBALS['Theme']->addMoreAttr('body',"document.getElementById('edit[content]').editarea.focus()"); + } + if (defined('ENABLE_EDIT_TOOLBAR') and ENABLE_EDIT_TOOLBAR) { + $GLOBALS['Theme']->addMoreHeaders(JavaScript('',array('src'=>$GLOBALS['Theme']->_findData("toolbar.js")))); + $tokens['EDIT_TOOLBAR'] = $this->toolbar(); + } else { + $tokens['EDIT_TOOLBAR'] = ''; } return $this->output('editpage', _("Edit: %s")); } + function toolbar () { + global $Theme; + $toolarray = array( + array( + "image"=>"button_bold.png", + "open"=>"*", + "close"=>"*", + "sample"=>_("bold_sample"), + "tip"=>_("bold_tip")), + array("image"=>"button_italic.png", + "open"=>"_", + "close"=>"_", + "sample"=>_("italic_sample"), + "tip"=>_("italic_tip")), + array("image"=>"button_link.png", + "open"=>"[", + "close"=>"]", + "sample"=>_("link_sample"), + "tip"=>_("link_tip")), + array("image"=>"button_extlink.png", + "open"=>"[", + "close"=>"]", + "sample"=>_("extlink_sample"), + "tip"=>_("extlink_tip")), + array("image"=>"button_headline.png", + "open"=>"\\n!!! ", + "close"=>"\\n", + "sample"=>_("headline_sample"), + "tip"=>_("headline_tip")), + array("image"=>"button_image.png", + "open"=>"[ ", + "close"=>" ]", + "sample"=>_("image_sample"), + "tip"=>_("image_tip")), + array("image"=>"button_nowiki.png", + "open"=>"\\n\\\\n", + "close"=>"\\n\\\\n", + "sample"=>_("nowiki_sample"), + "tip"=>_("nowiki_tip")), + array("image"=>"button_sig.png", + "open" => "--" . $GLOBALS['request']->_user->UserName(), + "close" => "", + "sample"=>"", + "tip"=>_("sig_tip")), + array("image"=>"button_hr.png", + "open"=>"\\n----\\n", + "close"=>"", + "sample"=>"", + "tip"=>_("hr_tip")) + ); + $toolbar = "document.writeln(\"
\");\n"; + foreach ($toolarray as $tool) { + $image = $Theme->getImageURL($tool["image"]); + $open = $tool["open"]; + $close = $tool["close"]; + $sample = addslashes( $tool["sample"] ); + // Note that we use the tip both for the ALT tag and the TITLE tag of the image. + // Older browsers show a "speedtip" type message only for ALT. + // Ideally these should be different, realistically they + // probably don't need to be. + $tip = addslashes( $tool["tip"] ); + $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n"; + } + $toolbar.="addInfobox('" . addslashes( _( "infobox" ) ) . "');\n"; + $toolbar.="document.writeln(\"
\");"; + return Javascript($toolbar); + } + function output ($template, $title_fs) { global $Theme; $selected = &$this->selected; @@ -626,6 +703,11 @@ extends PageEditor /** $Log: not supported by cvs2svn $ + Revision 1.66 2004/04/29 23:25:12 rurban + re-ordered locale init (as in 1.3.9) + fixed loadfile with subpages, and merge/restore anyway + (sf.net bug #844188) + Revision 1.65 2004/04/18 01:11:52 rurban more numeric pagename fixes. fixed action=upload with merge conflict warnings. diff --git a/lib/main.php b/lib/main.php index e7809c521..abcd1a2c6 100644 --- a/lib/main.php +++ b/lib/main.php @@ -1,5 +1,5 @@ _dbi = WikiDB::open($GLOBALS['DBParams']); + if (in_array('File', $this->_dbi->getAuthParam('USER_AUTH_ORDER'))) { + // force our local copy, until the pear version is fixed. + include_once(dirname(__FILE__)."/pear/File_Passwd.php"); + } if (USE_DB_SESSION) { - include_once('lib/DB_Session.php'); - $prefix = isset($GLOBALS['DBParams']['prefix']) ? $GLOBALS['DBParams']['prefix'] : ''; - if (in_array('File',$GLOBALS['USER_AUTH_ORDER'])) { - include_once(dirname(__FILE__)."/pear/File_Passwd.php"); - } - $dbi = $this->getDbh(); - $this->_dbsession = & new DB_Session($dbi,$prefix . $GLOBALS['DBParams']['db_session_table']); + include_once('lib/DbSession.php'); + $dbi =& $this->_dbi; + $this->_dbsession = & new DbSession($dbi, $dbi->getParam('prefix') . $dbi->getParam('db_session_table')); } // Fixme: Does pear reset the error mask to 1? We have to find the culprit $x = error_reporting(); @@ -61,7 +61,7 @@ $this->version = phpwiki_version(); $this->_user->_file->lockfile and !$this->_user->_file->fplock ) { - $this->_user = new _FilePassUser($userid,$this->_user->_prefs,$this->_user->_file->filename); + $this->_user = new _FilePassUser($userid, $this->_user->_prefs, $this->_user->_file->filename); } /* if (!isa($user,WikiUserClassname()) or empty($this->_user->_level)) { @@ -190,10 +190,12 @@ $this->version = phpwiki_version(); * request.) */ function getPostURL ($pagename=false) { + global $HTTP_GET_VARS; + if ($pagename === false) $pagename = $this->getArg('pagename'); $action = $this->getArg('action'); - if (!empty($_GET['start_debug'])) // zend ide support + if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support return WikiURL($pagename, array('action' => $action, 'start_debug' => 1)); else return WikiURL($pagename, array('action' => $action)); @@ -943,6 +945,9 @@ main(); // $Log: not supported by cvs2svn $ +// Revision 1.151 2004/05/25 12:40:48 rurban +// trim the pagename +// // Revision 1.150 2004/05/25 10:18:44 rurban // Check for UTF-8 URLs; Internet Explorer produces these if you // type non-ASCII chars in the URL bar or follow unescaped links. diff --git a/lib/pear/File_Passwd.php b/lib/pear/File_Passwd.php index 0335dedf8..84dcfd620 100644 --- a/lib/pear/File_Passwd.php +++ b/lib/pear/File_Passwd.php @@ -16,7 +16,7 @@ // | Author: Rasmus Lerdorf | // +----------------------------------------------------------------------+ // -// $Id: File_Passwd.php,v 1.6 2004-04-26 20:44:36 rurban Exp $ +// $Id: File_Passwd.php,v 1.7 2004-05-27 17:49:06 rurban Exp $ // // Manipulate standard UNIX passwd,.htpasswd and CVS pserver passwd files @@ -88,14 +88,25 @@ class File_Passwd { $this->lockfile = $lockfile ; } - if($lock) { + if ($lock) { + //check if already locked, on some error or race condition or other user. + //FIXME: implement timeout as with dba + if (file_exists($this->lockfile)) { + if (isset($GLOBALS['HTTP_GET_VARS']['force_unlock'])) { + $this->fplock = fopen($this->lockfile, 'w'); + flock($this->fplock, LOCK_UN); + fclose($this->fplock); + } else { + trigger_error('File_Passwd lock conflict: Try &force_unlock=1',E_USER_NOTICE); + } + } $this->fplock = fopen($this->lockfile, 'w'); flock($this->fplock, LOCK_EX); $this->locked = true; } $fp = fopen($file,'r') ; - if( !$fp) { + if( !$fp ) { return new PEAR_Error( "Couldn't open '$file'!", 1, PEAR_ERROR_RETURN) ; } while(!feof($fp)) { @@ -111,7 +122,7 @@ class File_Passwd { } } fclose($fp); - } // end func File_Passwd() + } /** * Adds a user @@ -220,7 +231,7 @@ class File_Passwd { * @access public */ function close() { - if($this->locked) { + if ($this->locked) { foreach($this->users as $user => $pass) { if (isset($this->cvs[$user])) { fputs($this->fplock, "$user:$pass:" . $this->cvs[$user] . "\n"); diff --git a/lib/plugin/WhoIsOnline.php b/lib/plugin/WhoIsOnline.php index 518794612..058061378 100644 --- a/lib/plugin/WhoIsOnline.php +++ b/lib/plugin/WhoIsOnline.php @@ -1,5 +1,5 @@ subpages +// renamed PhpWikiRss to PhpWikiRecentChanges +// more docs, default configs, ... +// // Revision 1.5 2004/04/06 20:27:05 rurban // fixed guests (no wiki_user session) // added ip (to help in ip-throttling) diff --git a/lib/plugin/WikiAdminSetAcl.php b/lib/plugin/WikiAdminSetAcl.php index af67ec3db..0b2f4a910 100644 --- a/lib/plugin/WikiAdminSetAcl.php +++ b/lib/plugin/WikiAdminSetAcl.php @@ -1,9 +1,9 @@