Commit f73610be authored by Dries's avatar Dries

- Patch #76588 by Gabor: made log messages translatable. Yay.

parent ffe4dc84
......@@ -646,19 +646,26 @@ function request_uri() {
* @param $type
* The category to which this message belongs.
* @param $message
* The message to store in the log.
* The message to store in the log. See t() for documentation
* on how $message and $variables interact. Keep $message
* translateable by not concatenating dynamic values into it!
* @param $variables
* 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, as per RFC 3164
* @param $link
* A link to associate with the message.
*/
function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
global $user, $base_root;
// Prepare the fields to be logged
$log_message = array(
'type' => $type,
'message' => $message,
'variables' => $variables,
'severity' => $severity,
'link' => $link,
'user' => $user,
......
......@@ -332,7 +332,7 @@ function drupal_site_offline() {
function drupal_not_found() {
drupal_set_header('HTTP/1.1 404 Not Found');
watchdog('page not found', check_plain($_GET['q']), WATCHDOG_WARNING);
watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
// Keep old path for reference
if (!isset($_REQUEST['destination'])) {
......@@ -362,7 +362,7 @@ function drupal_not_found() {
*/
function drupal_access_denied() {
drupal_set_header('HTTP/1.1 403 Forbidden');
watchdog('access denied', check_plain($_GET['q']), WATCHDOG_WARNING);
watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
// Keep old path for reference
if (!isset($_REQUEST['destination'])) {
......@@ -556,7 +556,7 @@ function drupal_error_handler($errno, $message, $filename, $line) {
drupal_set_message($entry, 'error');
}
watchdog('php', t('%message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line)), WATCHDOG_ERROR);
watchdog('php', '%message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line), WATCHDOG_ERROR);
}
}
......@@ -653,7 +653,7 @@ function fix_gpc_magic() {
* - %variable, which indicates that the string should be highlighted with
* theme_placeholder() which shows up by default as <em>emphasized</em>.
* @code
* watchdog('mail', t('%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name)));
* $message = t('%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name));
* @endcode
*
* When using t(), try to put entire sentences and strings in one t() call.
......@@ -2041,14 +2041,14 @@ function drupal_cron_run() {
if (time() - $semaphore > 3600) {
// Either cron has been running for more than an hour or the semaphore
// was not reset due to a database error.
watchdog('cron', t('Cron has been running for more than an hour and is most likely stuck.'), WATCHDOG_ERROR);
watchdog('cron', 'Cron has been running for more than an hour and is most likely stuck.', array(), WATCHDOG_ERROR);
// Release cron semaphore
variable_del('cron_semaphore');
}
else {
// Cron is still running normally.
watchdog('cron', t('Attempting to re-run cron while it is already running.'), WATCHDOG_WARNING);
watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING);
}
}
else {
......@@ -2063,7 +2063,7 @@ function drupal_cron_run() {
// Record cron time
variable_set('cron_last', time());
watchdog('cron', t('Cron run completed.'), WATCHDOG_NOTICE);
watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE);
// Release cron semaphore
variable_del('cron_semaphore');
......@@ -2079,7 +2079,7 @@ function drupal_cron_run() {
function drupal_cron_cleanup() {
// See if the semaphore is still locked.
if (variable_get('cron_semaphore', FALSE)) {
watchdog('cron', t('Cron run exceeded the time limit and was aborted.'), WATCHDOG_WARNING);
watchdog('cron', 'Cron run exceeded the time limit and was aborted.', array(), WATCHDOG_WARNING);
// Release cron semaphore
variable_del('cron_semaphore');
......
......@@ -107,7 +107,7 @@ function file_check_directory(&$directory, $mode = 0, $form_item = NULL) {
}
else {
form_set_error($form_item, t('The directory %directory is not writable', array('%directory' => $directory)));
watchdog('file system', t('The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory)), WATCHDOG_ERROR);
watchdog('file system', 'The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory), WATCHDOG_ERROR);
return FALSE;
}
}
......@@ -119,9 +119,9 @@ function file_check_directory(&$directory, $mode = 0, $form_item = NULL) {
chmod($directory .'/.htaccess', 0664);
}
else {
$message = t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", array('%directory' => $directory, '!htaccess' => '<br />'. nl2br(check_plain($htaccess_lines))));
form_set_error($form_item, $message);
watchdog('security', $message, WATCHDOG_ERROR);
$variables = array('%directory' => $directory, '!htaccess' => '<br />'. nl2br(check_plain($htaccess_lines)));
form_set_error($form_item, t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables));
watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, WATCHDOG_ERROR);
}
}
......@@ -239,7 +239,7 @@ function file_check_upload($source = 'upload') {
// This overcomes open_basedir restrictions for future file operations.
if (!move_uploaded_file($_FILES["files"]["tmp_name"][$source], $file->filepath)) {
drupal_set_message(t('File upload error. Could not move uploaded file.'));
watchdog('file', t('Upload Error. Could not move uploaded file (%file) to destination (%destination).', array('%file' => $_FILES["files"]["tmp_name"][$source], '%destination' => $file->filepath)));
watchdog('file', 'Upload Error. Could not move uploaded file (%file) to destination (%destination).', array('%file' => $_FILES["files"]["tmp_name"][$source], '%destination' => $file->filepath));
return FALSE;
}
......@@ -320,7 +320,7 @@ function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
if ($basename === FALSE) {
$source = is_object($source) ? $source->filepath : $source;
drupal_set_message(t('The selected file %file could not be uploaded, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $dest)), 'error');
watchdog('file system', t('The selected file %file could not be uploaded, because the destination %directory could not be found, or because its permissions do not allow the file to be written.', array('%file' => $source, '%directory' => $dest)), WATCHDOG_ERROR);
watchdog('file system', 'The selected file %file could not be uploaded, because the destination %directory could not be found, or because its permissions do not allow the file to be written.', array('%file' => $source, '%directory' => $dest), WATCHDOG_ERROR);
return 0;
}
......
......@@ -553,13 +553,13 @@ function _form_validate($elements, $form_id = NULL) {
foreach ($value as $v) {
if (!isset($options[$v])) {
form_error($elements, t('An illegal choice has been detected. Please contact the site administrator.'));
watchdog('form', t('Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'])), WATCHDOG_ERROR);
watchdog('form', 'Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
}
}
}
elseif (!isset($options[$elements['#value']])) {
form_error($elements, t('An illegal choice has been detected. Please contact the site administrator.'));
watchdog('form', t('Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'])), WATCHDOG_ERROR);
watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
}
}
}
......
......@@ -58,7 +58,7 @@ function image_toolkit_invoke($method, $params = array()) {
return call_user_func_array($function, $params);
}
else {
watchdog('php', t("The selected image handling toolkit %toolkit can not correctly process %function.", array('%toolkit' => $toolkit, '%function' => $function)), WATCHDOG_ERROR);
watchdog('php', 'The selected image handling toolkit %toolkit can not correctly process %function.', array('%toolkit' => $toolkit, '%function' => $function), WATCHDOG_ERROR);
return FALSE;
}
}
......
......@@ -50,7 +50,7 @@ function _locale_add_language($code, $name, $native, $direction = 0, $domain = '
drupal_set_message(t('The language %language has been created.', array('%language' => t($name))));
}
watchdog('locale', t('The %language language (%code) has been created.', array('%language' => t($name), '%code' => $code)));
watchdog('locale', 'The %language language (%code) has been created.', array('%language' => $name, '%code' => $code));
}
/**
......@@ -457,9 +457,9 @@ function _locale_admin_import_submit($form_id, $form_values) {
// Now import strings into the language
if ($ret = _locale_import_po($file, $form_values['langcode'], $form_values['mode']) == FALSE) {
$message = t('The translation import of %filename failed.', array('%filename' => $file->filename));
drupal_set_message($message, 'error');
watchdog('locale', $message, WATCHDOG_ERROR);
$variables = array('%filename' => $file->filename);
drupal_set_message(t('The translation import of %filename failed.', $variables), 'error');
watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR);
}
}
else {
......@@ -704,7 +704,7 @@ function _locale_import_po($file, $lang, $mode) {
menu_rebuild();
drupal_set_message(t('The translation was successfully imported. There are %number newly created translated strings and %update strings were updated.', array('%number' => $additions, '%update' => $updates)));
watchdog('locale', t('Imported %file into %locale: %number new strings added and %update updated.', array('%file' => $file->filename, '%locale' => $lang, '%number' => $additions, '%update' => $updates)));
watchdog('locale', 'Imported %file into %locale: %number new strings added and %update updated.', array('%file' => $file->filename, '%locale' => $lang, '%number' => $additions, '%update' => $updates));
return TRUE;
}
......@@ -1353,7 +1353,7 @@ function _locale_export_po($language = NULL) {
$header .= "\"Plural-Forms: nplurals=". $meta->plurals ."; plural=". strtr($meta->formula, array('$' => '')) .";\\n\"\n";
}
$header .= "\n";
watchdog('locale', t('Exported %locale translation file: %filename.', array('%locale' => $meta->name, '%filename' => $filename)));
watchdog('locale', 'Exported %locale translation file: %filename.', array('%locale' => $meta->name, '%filename' => $filename));
}
// Generating Portable Object Template
......@@ -1374,7 +1374,7 @@ function _locale_export_po($language = NULL) {
$header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
$header .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n";
$header .= "\n";
watchdog('locale', t('Exported translation file: %filename.', array('%filename' => $filename)));
watchdog('locale', 'Exported translation file: %filename.', array('%filename' => $filename));
}
// Start download process
......
......@@ -148,7 +148,7 @@ function drupal_xml_parser_create(&$data) {
$data = ereg_replace('^(<\?xml[^>]+encoding)="([^"]+)"', '\\1="utf-8"', $out);
}
else {
watchdog('php', t("Could not convert XML encoding %s to UTF-8.", array('%s' => $encoding)), WATCHDOG_WARNING);
watchdog('php', 'Could not convert XML encoding %s to UTF-8.', array('%s' => $encoding), WATCHDOG_WARNING);
return 0;
}
}
......@@ -181,7 +181,7 @@ function drupal_convert_to_utf8($data, $encoding) {
$out = @recode_string($encoding .'..utf-8', $data);
}
else {
watchdog('php', t("Unsupported encoding %s. Please install iconv, GNU recode or mbstring for PHP.", array('%s' => $encoding)), WATCHDOG_ERROR);
watchdog('php', 'Unsupported encoding %s. Please install iconv, GNU recode or mbstring for PHP.', array('%s' => $encoding), WATCHDOG_ERROR);
return FALSE;
}
......
......@@ -395,7 +395,7 @@ function aggregator_form_category_submit($form_id, $form_values) {
}
}
else {
watchdog('aggregator', t('Category %category deleted.', array('%category' => $title)));
watchdog('aggregator', 'Category %category deleted.', array('%category' => $title));
drupal_set_message(t('The category %category has been deleted.', array('%category' => $title)));
if (arg(0) == 'admin') {
return 'admin/content/aggregator/';
......@@ -406,7 +406,7 @@ function aggregator_form_category_submit($form_id, $form_values) {
}
}
else {
watchdog('aggregator', t('Category %category added.', array('%category' => $form_values['title'])), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
watchdog('aggregator', 'Category %category added.', array('%category' => $form_values['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
drupal_set_message(t('The category %category has been added.', array('%category' => $form_values['title'])));
}
}
......@@ -531,7 +531,7 @@ function aggregator_form_feed_submit($form_id, $form_values) {
}
}
else {
watchdog('aggregator', t('Feed %feed deleted.', array('%feed' => $title)));
watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $title));
drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $title)));
if (arg(0) == 'admin') {
return 'admin/content/aggregator/';
......@@ -542,7 +542,7 @@ function aggregator_form_feed_submit($form_id, $form_values) {
}
}
else {
watchdog('aggregator', t('Feed %feed added.', array('%feed' => $form_values['title'])), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
watchdog('aggregator', 'Feed %feed added.', array('%feed' => $form_values['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
drupal_set_message(t('The feed %feed has been added.', array('%feed' => $form_values['title'])));
}
}
......@@ -731,7 +731,7 @@ function aggregator_refresh($feed) {
break;
case 301:
$feed['url'] = $result->redirect_url;
watchdog('aggregator', t('Updated URL for feed %title to %url.', array('%title' => $feed['title'], '%url' => $feed['url'])));
watchdog('aggregator', 'Updated URL for feed %title to %url.', array('%title' => $feed['title'], '%url' => $feed['url']));
case 200:
case 302:
......@@ -779,12 +779,12 @@ function aggregator_refresh($feed) {
cache_clear_all();
watchdog('aggregator', t('There is new syndicated content from %site.', array('%site' => $feed['title'])));
watchdog('aggregator', 'There is new syndicated content from %site.', array('%site' => $feed['title']));
drupal_set_message(t('There is new syndicated content from %site.', array('%site' => $feed['title'])));
}
break;
default:
watchdog('aggregator', t('The feed from %site seems to be broken, due to "%error".', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error)), WATCHDOG_WARNING);
watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error), WATCHDOG_WARNING);
drupal_set_message(t('The feed from %site seems to be broken, because of error "%error".', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error)));
}
}
......@@ -841,7 +841,7 @@ function aggregator_parse_feed(&$data, $feed) {
xml_set_character_data_handler($xml_parser, 'aggregator_element_data');
if (!xml_parse($xml_parser, $data, 1)) {
watchdog('aggregator', t('The feed from %site seems to be broken, due to an error "%error" on line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), WATCHDOG_WARNING);
watchdog('aggregator', 'The feed from %site seems to be broken, due to an error "%error" on line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser)), WATCHDOG_WARNING);
drupal_set_message(t('The feed from %site seems to be broken, because of error "%error" on line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), 'error');
return 0;
}
......
......@@ -218,7 +218,7 @@ function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $conte
$node = node_submit($edit);
node_save($node);
if ($node->nid) {
watchdog('content', t('@type: added %title using blog API.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
watchdog('content', '@type: added %title using blog API.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
// blogger.newPost returns a string so we cast the nid to a string by putting it in double quotes:
return "$node->nid";
}
......@@ -274,7 +274,7 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
$node = node_submit($node);
node_save($node);
if ($node->nid) {
watchdog('content', t('@type: updated %title using blog API.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
watchdog('content', '@type: updated %title using blog API.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
return TRUE;
}
......
......@@ -939,7 +939,7 @@ function book_admin_edit_submit($form_id, $form_values) {
$node->weight = $row['weight'];
node_save($node);
watchdog('content', t('%type: updated %title.', array('%type' => t('book'), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
watchdog('content', 'book: updated %title.', array('%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
}
}
......
......@@ -243,13 +243,13 @@ function contact_admin_edit_submit($form_id, $form_values) {
if (arg(3) == 'add') {
db_query("INSERT INTO {contact} (category, recipients, reply, weight, selected) VALUES ('%s', '%s', '%s', %d, %d)", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected']);
drupal_set_message(t('Category %category has been added.', array('%category' => $form_values['category'])));
watchdog('mail', t('Contact form: category %category added.', array('%category' => $form_values['category'])), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
watchdog('mail', 'Contact form: category %category added.', array('%category' => $form_values['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
}
else {
db_query("UPDATE {contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid = %d", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected'], $form_values['cid']);
drupal_set_message(t('Category %category has been updated.', array('%category' => $form_values['category'])));
watchdog('mail', t('Contact form: category %category updated.', array('%category' => $form_values['category'])), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
watchdog('mail', 'Contact form: category %category updated.', array('%category' => $form_values['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
}
return 'admin/build/contact';
......@@ -278,7 +278,7 @@ function contact_admin_delete($cid = NULL) {
function contact_admin_delete_submit($form_id, $form_values) {
db_query("DELETE FROM {contact} WHERE cid = %d", arg(4));
drupal_set_message(t('Category %category has been deleted.', array('%category' => $form_values['category'])));
watchdog('mail', t('Contact form: category %category deleted.', array('%category' => $form_values['category'])), WATCHDOG_NOTICE);
watchdog('mail', 'Contact form: category %category deleted.', array('%category' => $form_values['category']), WATCHDOG_NOTICE);
return 'admin/build/contact';
}
......@@ -393,7 +393,7 @@ function contact_mail_user_submit($form_id, $form_values) {
// Log the operation:
flood_register_event('contact');
watchdog('mail', t('%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name)));
watchdog('mail', '%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name));
// Set a status message:
drupal_set_message(t('The message has been sent.'));
......@@ -544,7 +544,7 @@ function contact_mail_page_submit($form_id, $form_values) {
// Log the operation:
flood_register_event('contact');
watchdog('mail', t('%name-from sent an e-mail regarding %category.', array('%name-from' => $form_values['name'] ." <$from>", '%category' => $contact->category)));
watchdog('mail', '%name-from sent an e-mail regarding %category.', array('%name-from' => $form_values['name'] ." <$from>", '%category' => $contact->category));
// Update user:
drupal_set_message(t('Your message has been sent.'));
......
......@@ -13,6 +13,7 @@ function dblog_install() {
uid int NOT NULL default '0',
type varchar(16) NOT NULL default '',
message longtext NOT NULL,
variables longtext NOT NULL,
severity tinyint unsigned NOT NULL default '0',
link varchar(255) NOT NULL default '',
location text NOT NULL,
......@@ -30,6 +31,7 @@ function dblog_install() {
uid int NOT NULL default '0',
type varchar(16) NOT NULL default '',
message text NOT NULL,
variables text NOT NULL,
severity smallint_unsigned NOT NULL default '0',
link varchar(255) NOT NULL default '',
location text NOT NULL default '',
......
......@@ -159,12 +159,12 @@ function dblog_overview() {
' ',
array('data' => t('Type'), 'field' => 'w.type'),
array('data' => t('Date'), 'field' => 'w.wid', 'sort' => 'desc'),
array('data' => t('Message'), 'field' => 'w.message'),
t('Message'),
array('data' => t('User'), 'field' => 'u.name'),
array('data' => t('Operations'))
);
$sql = "SELECT w.wid, w.uid, w.severity, w.type, w.timestamp, w.message, w.link, u.name FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid";
$sql = "SELECT w.wid, w.uid, w.severity, w.type, w.timestamp, w.message, w.variables, w.link, u.name FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid";
$tablesort = tablesort_sql($header);
$type = $_SESSION['dblog_overview_filter'];
if ($type != 'all') {
......@@ -181,7 +181,7 @@ function dblog_overview() {
$icons[$dblog->severity],
t($dblog->type),
format_date($dblog->timestamp, 'small'),
l(truncate_utf8($dblog->message, 56, TRUE, TRUE), 'admin/logs/event/'. $dblog->wid, array('html' => TRUE)),
l(truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE), 'admin/logs/event/'. $dblog->wid, array('html' => TRUE)),
theme('username', $dblog),
$dblog->link,
),
......@@ -211,11 +211,11 @@ function dblog_top($type) {
array('data' => t('Message'), 'field' => 'message')
);
$result = pager_query("SELECT COUNT(wid) AS count, message FROM {watchdog} WHERE type = '%s' GROUP BY message ". tablesort_sql($header), 30, 0, "SELECT COUNT(DISTINCT(message)) FROM {watchdog} WHERE type = '%s'", $type);
$result = pager_query("SELECT COUNT(wid) AS count, message, variables FROM {watchdog} WHERE type = '%s' GROUP BY message ". tablesort_sql($header), 30, 0, "SELECT COUNT(DISTINCT(message)) FROM {watchdog} WHERE type = '%s'", $type);
$rows = array();
while ($dblog = db_fetch_object($result)) {
$rows[] = array($dblog->count, truncate_utf8($dblog->message, 56, TRUE, TRUE));
$rows[] = array($dblog->count, truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE));
}
if (empty($rows)) {
......@@ -267,7 +267,7 @@ function dblog_event($id) {
),
array(
array('data' => t('Message'), 'header' => TRUE),
$dblog->message,
_dblog_format_message($dblog),
),
array(
array('data' => t('Severity'), 'header' => TRUE),
......@@ -302,12 +302,13 @@ function _dblog_get_message_types() {
function dblog_watchdog($log = array()) {
$current_db = db_set_active();
db_query("INSERT INTO {watchdog}
(uid, type, message, severity, link, location, referer, hostname, timestamp)
(uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
VALUES
(%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)",
(%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)",
$log['user']->uid,
$log['type'],
$log['message'],
serialize($log['variables']),
$log['severity'],
$log['link'],
$log['request_uri'],
......@@ -319,3 +320,20 @@ function dblog_watchdog($log = array()) {
db_set_active($current_db);
}
}
/**
* Formats a log message for display.
*
* @param $dblog
* An object with at least the message and variables properties
*/
function _dblog_format_message($dblog) {
// Legacy messages and user specified text
if ($dblog->variables === 'N;') {
return $dblog->message;
}
// Message to translate with injected variables
else {
return t($dblog->message, unserialize($dblog->variables));
}
}
......@@ -205,7 +205,7 @@ function drupal_client_ping($client, $system) {
db_query("INSERT INTO {client_system} (cid, name, type) VALUES (%d, '%s', '%s')", $client['cid'], $item['name'], $item['type']);
}
}
watchdog('client ping', t('Ping from %name (%link).', array('%name' => $client['name'], '%link' => $client['link'])), WATCHDOG_NOTICE, '<a href="'. check_url($client['link']) .'">view</a>');
watchdog('client ping', 'Ping from %name (%link).', array('%name' => $client['name'], '%link' => $client['link']), WATCHDOG_NOTICE, '<a href="'. check_url($client['link']) .'">view</a>');
return TRUE;
}
......@@ -300,7 +300,7 @@ function drupal_notify($server) {
$result = xmlrpc($server, 'drupal.client.ping', $client, $system);
if ($result === FALSE) {
watchdog('server ping', t('Failed to notify %server; error code: %errno; error message: %error_msg.', array('%server' => $server, '%errno' => xmlrpc_errno(), '%error_msg' => xmlrpc_error_msg())), WATCHDOG_WARNING);
watchdog('server ping', 'Failed to notify %server; error code: %errno; error message: %error_msg.', array('%server' => $server, '%errno' => xmlrpc_errno(), '%error_msg' => xmlrpc_error_msg()), WATCHDOG_WARNING);
}
}
......
......@@ -819,7 +819,7 @@ function filter_form_validate($form) {
}
}
form_error($form, t('An illegal choice has been detected. Please contact the site administrator.'));
watchdog('form', t('Illegal choice %choice in %name element.', array('%choice' => $form[$key]['#value'], '%name' => empty($form['#title']) ? $form['#parents'][0] : $form['#title'])), WATCHDOG_ERROR);
watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $form[$key]['#value'], '%name' => empty($form['#title']) ? $form['#parents'][0] : $form['#title']), WATCHDOG_ERROR);
}
/**
......
......@@ -615,7 +615,7 @@ function forum_confirm_delete($tid) {
function forum_confirm_delete_submit($form_id, $form_values) {
taxonomy_del_term($form_values['tid']);
drupal_set_message(t('The forum %term and all sub-forums and associated posts have been deleted.', array('%term' => $form_values['name'])));
watchdog('content', t('forum: deleted %term and all its sub-forums and associated posts.', array('%term' => $form_values['name'])));
watchdog('content', 'forum: deleted %term and all its sub-forums and associated posts.', array('%term' => $form_values['name']));
return 'admin/content/forum';
}
......
......@@ -383,9 +383,9 @@ function locale_admin_manage_delete_form_submit($form_id, $form_values) {
if (isset($languages[$form_values['langcode']])) {
db_query("DELETE FROM {languages} WHERE language = '%s'", $form_values['langcode']);
db_query("DELETE FROM {locales_target} WHERE language = '%s'", $form_values['langcode']);
$message = t('The language %locale has been removed.', array('%locale' => t($languages[$form_values['langcode']]->name)));
drupal_set_message($message);
watchdog('locale', $message);
$variables = array('%locale' => $languages[$form_values['langcode']]->name);
drupal_set_message(t('The language %locale has been removed.', $variables));
watchdog('locale', 'The language %locale has been removed.', $variables);
}
// Changing the locale settings impacts the interface:
......
......@@ -423,7 +423,7 @@ function menu_edit_item_save($edit) {
else {
db_query("INSERT INTO {menu_custom} (parent, path, title, description, weight, type, admin) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $parent, isset($edit['path']) ? $edit['path'] : $edit['original_path'], $edit['title'], $edit['description'], $edit['weight'], $edit['type'], isset($edit['path']));
}
watchdog('menu', t('Saved menu item %title.', $t_args), WATCHDOG_NOTICE, l(t('view'), 'admin/build/menu'));
watchdog('menu', 'Saved menu item %title.', $t_args, WATCHDOG_NOTICE, l(t('view'), 'admin/build/menu'));
drupal_set_message(t('The menu item %title has been saved.', $t_args));
menu_rebuild();
}
......@@ -500,11 +500,11 @@ function menu_item_delete_form_submit($form_id, $form_values) {
$t_args = array('%title' => $form_values['title']);
if ($form_values['type'] & MENU_IS_ROOT) {
drupal_set_message(t('The menu %title has been deleted.', $t_args));
watchdog('menu', t('Deleted menu %title.', $t_args), WATCHDOG_NOTICE);
watchdog('menu', 'Deleted menu %title.', $t_args, WATCHDOG_NOTICE);
}
else {
drupal_set_message(t('The menu item %title has been deleted.', $t_args));
watchdog('menu', t('Deleted menu item %title.', $t_args), WATCHDOG_NOTICE);
watchdog('menu', 'Deleted menu item %title.', $t_args, WATCHDOG_NOTICE);
}
return 'admin/build/menu';
......
......@@ -333,7 +333,7 @@ function node_type_form_submit($form_id, $form_values) {
}
elseif ($status == SAVED_NEW) {
drupal_set_message(t('The content type %name has been added.', $t_args));
watchdog('node', t('Added content type %name.', $t_args), WATCHDOG_NOTICE, l(t('view'), 'admin/content/types'));
watchdog('node', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l(t('view'), 'admin/content/types'));
}
return 'admin/content/types';
......@@ -401,7 +401,7 @@ function node_type_delete_confirm_submit($form_id, $form_values) {
$t_args = array('%name' => $form_values['name']);
drupal_set_message(t('The content type %name has been deleted.', $t_args));
watchdog('menu', t('Deleted content type %name.', $t_args), WATCHDOG_NOTICE);
watchdog('menu', 'Deleted content type %name.', $t_args, WATCHDOG_NOTICE);
node_types_rebuild();
menu_rebuild();
......
......@@ -1724,7 +1724,7 @@ function node_revision_revert($nid, $revision) {
node_save($node);
drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => format_date($node->revision_timestamp), '%title' => $node->title)));
watchdog('content', t('@type: reverted %title revision %revision.', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $revision)));
watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $node->type, '%title' => $node->title, '%revision' => $revision));
}
else {
drupal_set_message(t('You tried to revert to an invalid revision.'), 'error');
......@@ -1749,7 +1749,7 @@ function node_revision_delete($nid, $revision) {
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $nid, $revision);
node_invoke_nodeapi($node, 'delete revision');
drupal_set_message(t('Deleted %title revision %revision.', array('%title' => $node->title, '%revision' => $revision)));
watchdog('content', t('@type: deleted %title revision %revision.', array('@type' => t($node->type), '%title' => $node->title, '%revision' => $revision)));
watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node->type, '%title' => $node->title, '%revision' => $revision));
}
else {
......@@ -2286,12 +2286,12 @@ function node_form_submit($form_id, $form_values) {
// Prepare the node's body:
if ($node->nid) {
node_save($node);
watchdog('content', t('@type: updated %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
watchdog('content', '@type: updated %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t