? Drupal.watchdog.locale.patch Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.107 diff -u -r1.107 bootstrap.inc --- includes/bootstrap.inc 22 Jul 2006 07:00:30 -0000 1.107 +++ includes/bootstrap.inc 1 Aug 2006 15:19:29 -0000 @@ -510,6 +510,9 @@ * The category to which this message belongs. * @param $message * The message to store in the log. + * @param $vars + * Array of variables to replace in the message on display or + * NULL if message is already translated or not possible to translate. * @param $severity * The severity of the message. One of the following values: * - WATCHDOG_NOTICE @@ -518,7 +521,7 @@ * @param $link * A link to associate with the message. */ -function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) { +function watchdog($type, $message, $vars = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { global $user, $base_root; $current_db = db_set_active(); @@ -526,7 +529,7 @@ // Note: log the exact, entire absolute URL. $request_uri = $base_root . request_uri(); - db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, $request_uri, referer_uri(), $_SERVER['REMOTE_ADDR'], time()); + db_query("INSERT INTO {watchdog} (uid, type, message, vars, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, serialize($vars), $severity, $link, $request_uri, referer_uri(), $_SERVER['REMOTE_ADDR'], time()); if ($current_db) { db_set_active($current_db); Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.3 diff -u -r1.3 system.install --- modules/system/system.install 26 Jul 2006 07:19:41 -0000 1.3 +++ modules/system/system.install 1 Aug 2006 15:19:30 -0000 @@ -373,6 +373,7 @@ uid int(10) NOT NULL default '0', type varchar(16) NOT NULL default '', message longtext NOT NULL, + vars longtext NOT NULL, severity tinyint(3) unsigned NOT NULL default '0', link varchar(255) NOT NULL default '', location varchar(128) NOT NULL default '', Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.643 diff -u -r1.643 user.module --- modules/user/user.module 31 Jul 2006 11:25:55 -0000 1.643 +++ modules/user/user.module 1 Aug 2006 15:19:32 -0000 @@ -894,7 +894,7 @@ if (!$user->uid) { form_set_error('login', t('Sorry. Unrecognized username or password.') .' '. l(t('Have you forgotten your password?'), 'user/password')); - watchdog('user', t('Login attempt failed for %user.', array('%user' => theme('placeholder', $form_values['name'])))); + watchdog('user', 'Login attempt failed for %user.', array('%user' => theme('placeholder', $form_values['name']))); } } } @@ -904,14 +904,13 @@ global $user; if ($user->uid) { // To handle the edge case where this function is called during a - // bootstrap, check for the existence of t(). - if (function_exists('t')) { - $message = t('Session opened for %name.', array('%name' => theme('placeholder', $user->name))); + // bootstrap, check for the existence of theme(). + if (function_exists('theme')) { + watchdog('user', 'Session opened for %name.', array('%name' => theme('placeholder', $user->name))); } else { - $message = "Session opened for ". check_plain($user->name); + watchdog('user', 'Session opened for %name.', array('%name' => check_plain($user->name))); } - watchdog('user', $message); // Update the user table timestamp noting user has logged in. db_query("UPDATE {users} SET login = %d WHERE uid = %d", time(), $user->uid); @@ -945,7 +944,7 @@ if ($server && ($result = user_get_authmaps("$name@$server"))) { if (module_invoke(key($result), 'auth', $name, $pass, $server)) { $user = user_external_load("$name@$server"); - watchdog('user', t('External load by %user using module %module.', array('%user' => theme('placeholder', $name .'@'. $server), '%module' => theme('placeholder', key($result))))); + watchdog('user', 'External load by %user using module %module.', array('%user' => theme('placeholder', $name .'@'. $server), '%module' => theme('placeholder', key($result)))); } } @@ -964,7 +963,7 @@ $userinfo["authname_$module"] = $name; } $user = user_save('', $userinfo); - watchdog('user', t('New external user: %user using module %module.', array('%user' => theme('placeholder', $name), '%module' => theme('placeholder', $module))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit')); + watchdog('user', 'New external user: %user using module %module.', array('%user' => theme('placeholder', $name), '%module' => theme('placeholder', $module))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'); break; } } @@ -979,7 +978,7 @@ function user_logout() { global $user; - watchdog('user', t('Session closed for %name.', array('%name' => theme('placeholder', $user->name)))); + watchdog('user', 'Session closed for %name.', array('%name' => theme('placeholder', $user->name))); // Destroy the current session: session_destroy(); @@ -1040,11 +1039,11 @@ $mail_success = drupal_mail('user-pass', $account->mail, $subject, $body, $from); if ($mail_success) { - watchdog('user', t('Password reset instructions mailed to %name at %email.', array('%name' => ''. $account->name .'', '%email' => ''. $account->mail .''))); + watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))); drupal_set_message(t('Further instructions have been sent to your e-mail address.')); } else { - watchdog('user', t('Error mailing password reset instructions to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))), WATCHDOG_ERROR); + watchdog('user', 'Error mailing password reset instructions to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail)), WATCHDOG_ERROR); drupal_set_message(t('Unable to send mail. Please contact the site admin.')); } return 'user'; @@ -1081,7 +1080,7 @@ else if ($account->uid && $timestamp > $account->login && $timestamp < $current && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login)) { // First stage is a confirmation form, then login if ($action == 'login') { - watchdog('user', t('User %name used one-time login link at time %timestamp.', array('%name' => "$account->name", '%timestamp' => $timestamp))); + watchdog('user', 'User %name used one-time login link at time %timestamp.', array('%name' => "$account->name", '%timestamp' => $timestamp)); // Update the user table noting user has logged in. // And this also makes this hashed password a one-time-only login. db_query("UPDATE {users} SET login = %d WHERE uid = %d", time(), $account->uid); @@ -1192,12 +1191,12 @@ } if (!$admin && array_intersect(array_keys($form_values), array('uid', 'roles', 'init', 'session', 'status'))) { - watchdog('security', t('Detected malicious attempt to alter protected user fields.'), WATCHDOG_WARNING); + watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING); return 'user/register'; } $account = user_save('', array_merge($form_values, array('pass' => $pass, 'init' => $mail, 'roles' => $roles, 'status' => ($admin || variable_get('user_register', 1) == 1)))); - watchdog('user', t('New user: %name %email.', array('%name' => theme('placeholder', $name), '%email' => theme('placeholder', '<'. $mail .'>'))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit')); + watchdog('user', 'New user: %name %email.', array('%name' => theme('placeholder', $name), '%email' => theme('placeholder', '<'. $mail .'>')), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit')); $variables = array('%username' => $name, '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $mail, '%date' => format_date(time()), '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE), '%login_url' => user_pass_reset_url($account)); @@ -1371,7 +1370,7 @@ db_query('DELETE FROM {sessions} WHERE uid = %d', $account->uid); db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid); db_query('DELETE FROM {authmap} WHERE uid = %d', $account->uid); - watchdog('user', t('Deleted user: %name %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', '<'. $account->mail .'>'))), WATCHDOG_NOTICE); + watchdog('user', 'Deleted user: %name %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', '<'. $account->mail .'>')), WATCHDOG_NOTICE); drupal_set_message(t('The account has been deleted.')); module_invoke_all('user', 'delete', $edit, $account); drupal_goto('admin/user/user'); @@ -1406,10 +1405,9 @@ user_module_invoke('validate', $form_values, $form_values['_account'], $form_values['_category']); // Validate input to ensure that non-privileged users can't alter protected data. if ((!user_access('administer users') && array_intersect(array_keys($form_values), array('uid', 'init', 'session'))) || (!user_access('administer access control') && isset($form_values['roles']))) { - $message = t('Detected malicious attempt to alter protected user fields.'); - watchdog('security', $message, WATCHDOG_WARNING); + watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING); // set this to a value type field - form_set_error('category', $message); + form_set_error('category', t('Detected malicious attempt to alter protected user fields.')); } } Index: modules/watchdog/watchdog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/watchdog/watchdog.module,v retrieving revision 1.145 diff -u -r1.145 watchdog.module --- modules/watchdog/watchdog.module 31 Jul 2006 11:25:55 -0000 1.145 +++ modules/watchdog/watchdog.module 1 Aug 2006 15:19:32 -0000 @@ -78,6 +78,23 @@ } /** + * Formats a watchdog message. + * + * @param $watchdog + * A watchdog table row + */ +function _watchdog_format_message($watchdog) { + // Legacy messages and user specified text + if ($watchdog->vars === 'N;') { + return $watchdog->message; + } + // Message to translate with injected variables + else { + return t($watchdog->message, unserialize($watchdog->vars)); + } +} + +/** * Menu callback; displays a listing of log messages. */ function watchdog_overview() { @@ -132,7 +149,7 @@ $icons[$watchdog->severity], t($watchdog->type), format_date($watchdog->timestamp, 'small'), - l(truncate_utf8($watchdog->message, 56, TRUE, TRUE), 'admin/logs/event/'. $watchdog->wid, array(), NULL, NULL, FALSE, TRUE), + l(truncate_utf8(_watchdog_format_message($watchdog)), 56, TRUE, TRUE), 'admin/logs/event/'. $watchdog->wid, array(), NULL, NULL, FALSE, TRUE), theme('username', $watchdog), $watchdog->link, ), @@ -169,7 +186,7 @@ $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d', $id); if ($watchdog = db_fetch_object($result)) { $header = array(t('Type'), t('Date'), t('User'), t('Location'), t('Referrer'), t('Message'), t('Severity'), t('Hostname')); - $data = array(t($watchdog->type), format_date($watchdog->timestamp, 'large'), theme('username', $watchdog), l($watchdog->location, $watchdog->location), l($watchdog->referer, $watchdog->referer), $watchdog->message, $severity[$watchdog->severity], $watchdog->hostname); + $data = array(t($watchdog->type), format_date($watchdog->timestamp, 'large'), theme('username', $watchdog), l($watchdog->location, $watchdog->location), l($watchdog->referer, $watchdog->referer), _watchdog_format_message($watchdog), $severity[$watchdog->severity], $watchdog->hostname); $output = theme('watchdog_event', $header, $data); } return $output;