Commit 14b233ec authored by Dries's avatar Dries

- Patch #368408 by jeffschuler: improve consistency of API and settings on administration pages.

parent d55daf0f
......@@ -1946,14 +1946,14 @@ function format_interval($timestamp, $granularity = 2, $langcode = NULL) {
/**
* Format a date with the given configured format or a custom format string.
*
* Drupal allows administrators to select formatting strings for 'small',
* 'medium' and 'large' date formats. This function can handle these formats,
* Drupal allows administrators to select formatting strings for 'short',
* 'medium' and 'long' date formats. This function can handle these formats,
* as well as any custom format.
*
* @param $timestamp
* The exact date to format, as a UNIX timestamp.
* @param $type
* The format to use. Can be "small", "medium" or "large" for the preconfigured
* The format to use. Can be "short", "medium" or "long" for the preconfigured
* date formats. If "custom" is specified, then $format is required as well.
* @param $format
* A PHP date format string as required by date(). A backslash should be used
......@@ -1991,10 +1991,10 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL
}
switch ($type) {
case 'small':
case 'short':
$format = variable_get('date_format_short', 'm/d/Y - H:i');
break;
case 'large':
case 'long':
$format = variable_get('date_format_long', 'l, F j, Y - H:i');
break;
case 'custom':
......
......@@ -89,7 +89,7 @@ function comment_admin_overview($type = 'new', $arg) {
'subject' => l($comment->subject, 'comment/' . $comment->cid, array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid)),
'author' => theme('username', $comment),
'posted_in' => l($comment->node_title, 'node/' . $comment->nid),
'time' => format_date($comment->timestamp, 'small'),
'time' => format_date($comment->timestamp, 'short'),
'operations' => l(t('edit'), 'comment/edit/' . $comment->cid, array('query' => $destination)),
);
}
......
......@@ -64,7 +64,7 @@ function dblog_overview() {
// Cells
$icons[$dblog->severity],
t($dblog->type),
format_date($dblog->timestamp, 'small'),
format_date($dblog->timestamp, 'short'),
l(truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE), 'admin/reports/event/' . $dblog->wid, array('html' => TRUE)),
theme('username', $dblog),
$dblog->link,
......@@ -148,7 +148,7 @@ function dblog_event($id) {
),
array(
array('data' => t('Date'), 'header' => TRUE),
format_date($dblog->timestamp, 'large'),
format_date($dblog->timestamp, 'long'),
),
array(
array('data' => t('User'), 'header' => TRUE),
......
......@@ -451,7 +451,7 @@ function node_admin_nodes() {
$form['name'][$node->nid] = array('#markup' => check_plain(node_type_get_name($node)));
$form['username'][$node->nid] = array('#markup' => theme('username', $node));
$form['status'][$node->nid] = array('#markup' => ($node->status ? t('published') : t('not published')));
$form['changed'][$node->nid] = array('#markup' => format_date($node->changed, 'small'));
$form['changed'][$node->nid] = array('#markup' => format_date($node->changed, 'short'));
if ($multilanguage) {
$form['language'][$node->nid] = array('#markup' => empty($node->language) ? t('Language neutral') : t($languages[$node->language]->name));
}
......
......@@ -500,13 +500,13 @@ function node_revision_overview($node) {
$operations = array();
if ($revision->current_vid > 0) {
$row[] = array('data' => t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid"), '!username' => theme('username', $revision)))
$row[] = array('data' => t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'short'), "node/$node->nid"), '!username' => theme('username', $revision)))
. (($revision->log != '') ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : ''),
'class' => array('revision-current'));
$operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => array('revision-current'), 'colspan' => 2);
}
else {
$row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', $revision)))
$row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'short'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', $revision)))
. (($revision->log != '') ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : '');
if ($revert_permission) {
$operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
......
......@@ -102,7 +102,7 @@ function template_preprocess_search_result(&$variables) {
$info['user'] = $result['user'];
}
if (!empty($result['date'])) {
$info['date'] = format_date($result['date'], 'small');
$info['date'] = format_date($result['date'], 'short');
}
if (isset($result['extra']) && is_array($result['extra'])) {
$info = array_merge($info, $result['extra']);
......
......@@ -1244,9 +1244,9 @@ class FormatDateUnitTest extends DrupalWebTestCase {
$this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', 'en'), 'Sunday, 25-Mar-07 17:00:00 PDT', t('Test a different language.'));
$this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'Europe/London'), 'Monday, 26-Mar-07 01:00:00 BST', t('Test a different time zone.'));
$this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T'), 'domingo, 25-Mar-07 17:00:00 PDT', t('Test custom date format.'));
$this->assertIdentical(format_date($timestamp, 'large'), 'domingo, 25. marzo 2007 - 17:00', t('Test long date format.'));
$this->assertIdentical(format_date($timestamp, 'long'), 'domingo, 25. marzo 2007 - 17:00', t('Test long date format.'));
$this->assertIdentical(format_date($timestamp, 'medium'), '25. marzo 2007 - 17:00', t('Test medium date format.'));
$this->assertIdentical(format_date($timestamp, 'small'), '2007 Mar 25 - 5:00pm', t('Test short date format.'));
$this->assertIdentical(format_date($timestamp, 'short'), '2007 Mar 25 - 5:00pm', t('Test short date format.'));
$this->assertIdentical(format_date($timestamp), '25. marzo 2007 - 17:00', t('Test default date format.'));
// Restore the original user and language, and enable session saving.
......
......@@ -29,7 +29,7 @@ function statistics_recent_hits() {
$rows = array();
foreach ($result as $log) {
$rows[] = array(
array('data' => format_date($log->timestamp, 'small'), 'class' => array('nowrap')),
array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
_statistics_format_item($log->title, $log->path),
theme('username', $log),
l(t('details'), "admin/reports/access/$log->aid"));
......@@ -221,7 +221,7 @@ function statistics_access_log($aid) {
);
$rows[] = array(
array('data' => t('Date'), 'header' => TRUE),
format_date($access->timestamp, 'large')
format_date($access->timestamp, 'long')
);
$rows[] = array(
array('data' => t('User'), 'header' => TRUE),
......
......@@ -31,7 +31,7 @@ function statistics_node_tracker() {
$rows = array();
foreach ($result as $log) {
$rows[] = array(
array('data' => format_date($log->timestamp, 'small'), 'class' => array('nowrap')),
array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
_statistics_link($log->url),
theme('username', $log),
l(t('details'), "admin/reports/access/$log->aid"),
......@@ -74,7 +74,7 @@ function statistics_user_tracker() {
$rows = array();
foreach ($result as $log) {
$rows[] = array(
array('data' => format_date($log->timestamp, 'small'), 'class' => array('nowrap')),
array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
_statistics_format_item($log->title, $log->path),
l(t('details'), "admin/reports/access/$log->aid"));
}
......
......@@ -1218,7 +1218,7 @@ class TokenReplaceTestCase extends DrupalWebTestCase {
$source .= '[node:created:since]'; // Time since the node was created
$source .= '[current-user:name]'; // Current user's name
$source .= '[user:name]'; // No user passed in, should be untouched
$source .= '[date:small]'; // Small date format of REQUEST_TIME
$source .= '[date:short]'; // Short date format of REQUEST_TIME
$source .= '[bogus:token]'; // Nonexistent token, should be untouched
$target = check_plain($node->title);
......@@ -1226,7 +1226,7 @@ class TokenReplaceTestCase extends DrupalWebTestCase {
$target .= format_interval(REQUEST_TIME - $node->created, 2);
$target .= check_plain($user->name);
$target .= '[user:name]';
$target .= format_date(REQUEST_TIME, 'small');
$target .= format_date(REQUEST_TIME, 'short');
$target .= '[bogus:token]';
$result = token_replace($source, array('node' => $node));
......
......@@ -54,17 +54,17 @@ function system_token_info() {
);
// Date related tokens.
$date['small'] = array(
'name' => t("Small format"),
'description' => t("A date in 'small' format. (%date)", array('%date' => format_date(REQUEST_TIME, 'small'))),
$date['short'] = array(
'name' => t("Short format"),
'description' => t("A date in 'short' format. (%date)", array('%date' => format_date(REQUEST_TIME, 'short'))),
);
$date['medium'] = array(
'name' => t("Medium format"),
'description' => t("A date in 'medium' format. (%date)", array('%date' => format_date(REQUEST_TIME, 'medium'))),
);
$date['large'] = array(
'name' => t("Large format"),
'description' => t("A date in 'large' format. (%date)", array('%date' => format_date(REQUEST_TIME, 'large'))),
$date['long'] = array(
'name' => t("Long format"),
'description' => t("A date in 'long' format. (%date)", array('%date' => format_date(REQUEST_TIME, 'long'))),
);
$date['custom'] = array(
'name' => t("Custom format"),
......@@ -203,16 +203,16 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
$replacements[$original] = filter_xss($date);
break;
case 'small':
$replacements[$original] = format_date($date, 'small', '', NULL, $langcode);
case 'short':
$replacements[$original] = format_date($date, 'short', '', NULL, $langcode);
break;
case 'medium':
$replacements[$original] = format_date($date, 'medium', '', NULL, $langcode);
break;
case 'large':
$replacements[$original] = format_date($date, 'large', '', NULL, $langcode);
case 'long':
$replacements[$original] = format_date($date, 'long', '', NULL, $langcode);
break;
case 'since':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment