diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index c93f2a81c5e..649d1bf812a 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -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, diff --git a/includes/common.inc b/includes/common.inc index 1da21609595..d59e864a94f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -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 emphasized. * @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'); diff --git a/includes/file.inc b/includes/file.inc index 7e70ed882c5..1673b75da74 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -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: !htaccess", array('%directory' => $directory, '!htaccess' => '
'. nl2br(check_plain($htaccess_lines)))); - form_set_error($form_item, $message); - watchdog('security', $message, WATCHDOG_ERROR); + $variables = array('%directory' => $directory, '!htaccess' => '
'. 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: !htaccess", $variables)); + watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: !htaccess", $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; } diff --git a/includes/form.inc b/includes/form.inc index 8a5413272e7..dc843d2868c 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -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); } } } diff --git a/includes/image.inc b/includes/image.inc index 01db0c5e158..6f20c082d8f 100644 --- a/includes/image.inc +++ b/includes/image.inc @@ -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; } } diff --git a/includes/locale.inc b/includes/locale.inc index e9f60f627c6..fd9cbdcaab9 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -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 diff --git a/includes/unicode.inc b/includes/unicode.inc index 7f546d4f9c0..93ec8177213 100644 --- a/includes/unicode.inc +++ b/includes/unicode.inc @@ -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; } diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index ead329dad50..a544a286e21 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -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; } diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module index fa6cfc0faf0..d003ff42125 100644 --- a/modules/blogapi/blogapi.module +++ b/modules/blogapi/blogapi.module @@ -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; } diff --git a/modules/book/book.module b/modules/book/book.module index 9451e623d36..5c1c2e0bd77 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -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)); } } diff --git a/modules/contact/contact.module b/modules/contact/contact.module index 23d4e3cdfc3..cb3f7712ac3 100644 --- a/modules/contact/contact.module +++ b/modules/contact/contact.module @@ -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.')); diff --git a/modules/dblog/dblog.install b/modules/dblog/dblog.install index f94bab65110..44961f7b13b 100644 --- a/modules/dblog/dblog.install +++ b/modules/dblog/dblog.install @@ -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 '', diff --git a/modules/dblog/dblog.module b/modules/dblog/dblog.module index 6af3d26137d..ad72a5e7bf0 100644 --- a/modules/dblog/dblog.module +++ b/modules/dblog/dblog.module @@ -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)); + } +} diff --git a/modules/drupal/drupal.module b/modules/drupal/drupal.module index 980467109ad..a75b484789a 100644 --- a/modules/drupal/drupal.module +++ b/modules/drupal/drupal.module @@ -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, 'view'); + watchdog('client ping', 'Ping from %name (%link).', array('%name' => $client['name'], '%link' => $client['link']), WATCHDOG_NOTICE, 'view'); 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); } } diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 93c3e7c1f4b..3b12f637136 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -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); } /** diff --git a/modules/forum/forum.module b/modules/forum/forum.module index ac6bb27cc17..8cc65f98bb8 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -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'; } diff --git a/modules/locale/locale.module b/modules/locale/locale.module index a3d0438d341..e8233ce0e7a 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -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: diff --git a/modules/menu/menu.module b/modules/menu/menu.module index 94450391942..0f97771ee38 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -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'; diff --git a/modules/node/content_types.inc b/modules/node/content_types.inc index eef1589aa45..ff19c9c70a1 100644 --- a/modules/node/content_types.inc +++ b/modules/node/content_types.inc @@ -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(); diff --git a/modules/node/node.module b/modules/node/node.module index 766325645ec..d178e53b218 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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('view'), 'node/'. $node->nid)); drupal_set_message(t('The %post has been updated.', array('%post' => node_get_types('name', $node)))); } else { node_save($node); - watchdog('content', t('@type: added %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); + watchdog('content', '@type: added %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node)))); } if ($node->nid) { @@ -2353,7 +2353,7 @@ function node_delete($nid) { search_wipe($node->nid, 'node'); } drupal_set_message(t('%title has been deleted.', array('%title' => $node->title))); - watchdog('content', t('@type: deleted %title.', array('@type' => t($node->type), '%title' => $node->title))); + watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title)); } } diff --git a/modules/ping/ping.module b/modules/ping/ping.module index 85626d39ba1..025b5da17d2 100644 --- a/modules/ping/ping.module +++ b/modules/ping/ping.module @@ -52,7 +52,7 @@ function ping_ping($name = '', $url = '') { $result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url); if ($result === FALSE) { - watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING); + watchdog('directory ping', 'Failed to notify pingomatic.com (site).', WATCHDOG_WARNING); } } diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 3c0faa55da0..e023962ff86 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -372,7 +372,7 @@ function profile_field_form_submit($form_id, $form_values) { db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page']); drupal_set_message(t('The field has been created.')); - watchdog('profile', t('Profile field %field added under category %category.', array('%field' => $form_values['title'], '%category' => $form_values['category'])), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); + watchdog('profile', 'Profile field %field added under category %category.', array('%field' => $form_values['title'], '%category' => $form_values['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); } else { db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page'], $form_values['fid']); @@ -413,7 +413,7 @@ function profile_field_delete_submit($form_id, $form_values) { cache_clear_all(); drupal_set_message(t('The field %field has been deleted.', array('%field' => $form_values['title']))); - watchdog('profile', t('Profile field %field deleted.', array('%field' => $form_values['title'])), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); + watchdog('profile', 'Profile field %field deleted.', array('%field' => $form_values['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); return 'admin/user/profile'; } diff --git a/modules/search/search.module b/modules/search/search.module index 93cfeb0e6e0..be06edcce40 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -936,7 +936,7 @@ function search_view($type = 'node') { $results = ''; if (trim($keys)) { // Log the search keys: - watchdog('search', t('%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name'))), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys)); + watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys)); // Collect the search results: $results = search_data($keys, $type); diff --git a/modules/syslog/syslog.module b/modules/syslog/syslog.module index 74762269707..76ee75e573f 100644 --- a/modules/syslog/syslog.module +++ b/modules/syslog/syslog.module @@ -98,7 +98,8 @@ function theme_syslog_format($entry) { '@referer_uri' => $entry['referer'], '@uid' => $entry['user']->uid, '@link' => strip_tags($entry['link']), - '@message' => strip_tags($entry['message']), + // Keep message English, but replace variable components. + '@message' => strip_tags(strtr($entry['message'], $entry['variables'])), )); return $message; } diff --git a/modules/system/system.install b/modules/system/system.install index ab3bb09badb..334ff08c6ec 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -2353,7 +2353,7 @@ function system_update_159() { } else { db_query('UPDATE {old_revisions} SET done = 1 WHERE nid = %d', $node->nid); - watchdog('php', "Recovering old revisions for node $node->nid failed.", WATCHDOG_WARNING); + watchdog('php', "Recovering old revisions for node %nid failed.", array('%nid' => $node->nid), WATCHDOG_WARNING); } } } @@ -2583,7 +2583,7 @@ function system_update_169() { $encoding = db_result(db_query('SHOW server_encoding')); if (!in_array(strtolower($encoding), array('unicode', 'utf8'))) { $msg = 'Your PostgreSQL database is set up with the wrong character encoding ('. $encoding .'). It is possible it will not work as expected. It is advised to recreate it with UTF-8/Unicode encoding. More information can be found in the PostgreSQL documentation.'; - watchdog('php', $msg, WATCHDOG_WARNING); + watchdog('php', $msg, array(), WATCHDOG_WARNING); drupal_set_message($msg, 'status'); } } @@ -3777,6 +3777,26 @@ function system_update_6009() { return $ret; } +/** + * Add variable replacement for watchdog messages. + */ +function system_update_6009() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_add_column($ret, 'watchdog', 'variables', 'text', array('not null' => TRUE)); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {watchdog} ADD variables longtext NOT NULL"); + break; + } + // Ensure we have 'N;' (serialize(NULL)) as the default, so existing + // log messages will not get translated in the new system. + $ret[] = update_sql("UPDATE {watchdog} SET variables = 'N;'"); + return $ret; +} + /** * @} End of "defgroup updates-5.x-to-6.x" * The next series of updates should start at 7000.