Commit 2b17b3a9 authored by Dries's avatar Dries

- Patch #13907 by Neil: less ways to set the page title.

   * Less logic in theme code.
   * Encourages use of the menu system.
   * Easier to find where a title or breadcrumb comes from in other people's code because there are less places to look. Look in menu and then grep for the appropriate set function. Looking for calls to theme_page() is hard because there are too many of them.
   * Very slightly more efficient.
parent 5628256e
Drupal x.x.x, xxxx-xx-xx Drupal x.x.x, xxxx-xx-xx
------------------------ ------------------------
- blocks:
* reorganized the block configuration page.
- search: - search:
* added UTF-8 support to make it work with all languages. * added UTF-8 support to make it work with all languages.
* improved search indexing. * improved search indexing.
...@@ -12,6 +10,7 @@ Drupal x.x.x, xxxx-xx-xx ...@@ -12,6 +10,7 @@ Drupal x.x.x, xxxx-xx-xx
- flood control mechanism: - flood control mechanism:
* added a mechanism to throttle certain operations. * added a mechanism to throttle certain operations.
- usability: - usability:
* refactored the block configuration pages.
* refactored the statistics and log pages. * refactored the statistics and log pages.
* refactored the throttle module configuration. * refactored the throttle module configuration.
* added a 'add child page' link to book pages. * added a 'add child page' link to book pages.
......
...@@ -176,7 +176,8 @@ function drupal_not_found() { ...@@ -176,7 +176,8 @@ function drupal_not_found() {
} }
if ($status != MENU_FOUND) { if ($status != MENU_FOUND) {
print theme('page', '', t('Page not found')); drupal_set_title(t('Page not found'));
print theme('page', '');
} }
} }
...@@ -195,7 +196,8 @@ function drupal_access_denied() { ...@@ -195,7 +196,8 @@ function drupal_access_denied() {
} }
if ($status != MENU_FOUND) { if ($status != MENU_FOUND) {
print theme('page', message_access(), t('Access denied')); drupal_set_title(t('Access denied'));
print theme('page', message_access());
} }
} }
......
...@@ -337,23 +337,10 @@ function theme_get_styles() { ...@@ -337,23 +337,10 @@ function theme_get_styles() {
* *
* @param $content * @param $content
* A string to display in the main content area of the page. * A string to display in the main content area of the page.
* @param $title
* The title of the page, if different from that provided by the menu system.
* @param $breadcrumb
* The breadcrumb trail for the page, if different from that provided by the
* menu system. Use menu_set_location() instead, if possible.
* @return * @return
* A string containing the entire HTML page. * A string containing the entire HTML page.
*/ */
function theme_page($content, $title = NULL, $breadcrumb = NULL) { function theme_page($content) {
if (isset($title)) {
drupal_set_title($title);
}
if (isset($breadcrumb)) {
drupal_set_breadcrumb($breadcrumb);
}
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">'; $output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$output .= '<head>'; $output .= '<head>';
......
...@@ -141,7 +141,7 @@ function blog_page_user($uid) { ...@@ -141,7 +141,7 @@ function blog_page_user($uid) {
$account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1)); $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
if ($account->uid) { if ($account->uid) {
$title = t("%name's blog", array('%name' => $account->name)); drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));
if (($account->uid == $user->uid) && user_access('edit own blog')) { if (($account->uid == $user->uid) && user_access('edit own blog')) {
$output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>'; $output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>';
...@@ -165,7 +165,7 @@ function blog_page_user($uid) { ...@@ -165,7 +165,7 @@ function blog_page_user($uid) {
$output .= theme('xml_icon', url("blog/feed/$account->uid")); $output .= theme('xml_icon', url("blog/feed/$account->uid"));
drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/feed/$account->uid") .'" />'); drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/feed/$account->uid") .'" />');
print theme('page', $output, $title); print theme('page', $output);
} }
else { else {
drupal_not_found(); drupal_not_found();
......
...@@ -141,7 +141,7 @@ function blog_page_user($uid) { ...@@ -141,7 +141,7 @@ function blog_page_user($uid) {
$account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1)); $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
if ($account->uid) { if ($account->uid) {
$title = t("%name's blog", array('%name' => $account->name)); drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));
if (($account->uid == $user->uid) && user_access('edit own blog')) { if (($account->uid == $user->uid) && user_access('edit own blog')) {
$output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>'; $output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>';
...@@ -165,7 +165,7 @@ function blog_page_user($uid) { ...@@ -165,7 +165,7 @@ function blog_page_user($uid) {
$output .= theme('xml_icon', url("blog/feed/$account->uid")); $output .= theme('xml_icon', url("blog/feed/$account->uid"));
drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/feed/$account->uid") .'" />'); drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/feed/$account->uid") .'" />');
print theme('page', $output, $title); print theme('page', $output);
} }
else { else {
drupal_not_found(); drupal_not_found();
......
...@@ -291,7 +291,8 @@ function book_outline() { ...@@ -291,7 +291,8 @@ function book_outline() {
$output .= form_submit(t('Add to book outline')); $output .= form_submit(t('Add to book outline'));
} }
print theme('page', form($output), $node->title); drupal_set_title($node->title);
print theme('page', form($output));
} }
} }
} }
......
...@@ -291,7 +291,8 @@ function book_outline() { ...@@ -291,7 +291,8 @@ function book_outline() {
$output .= form_submit(t('Add to book outline')); $output .= form_submit(t('Add to book outline'));
} }
print theme('page', form($output), $node->title); drupal_set_title($node->title);
print theme('page', form($output));
} }
} }
} }
......
...@@ -124,7 +124,7 @@ function comment_menu($may_cache) { ...@@ -124,7 +124,7 @@ function comment_menu($may_cache) {
$access = user_access('post comments'); $access = user_access('post comments');
$items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'), $items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
'callback' => 'comment_reply', 'access' => $access, 'type' => MENU_CALLBACK); 'callback' => 'comment_reply', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/edit', 'title' => t('edit your comment'), $items[] = array('path' => 'comment/edit', 'title' => t('edit comment'),
'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK); 'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment', 'title' => t('reply to comment'), $items[] = array('path' => 'comment', 'title' => t('reply to comment'),
...@@ -341,7 +341,10 @@ function comment_edit($cid) { ...@@ -341,7 +341,10 @@ function comment_edit($cid) {
$comment = drupal_unpack($comment); $comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) { if (comment_access('edit', $comment)) {
print theme('page', comment_preview(object2array($comment)), t('Edit comment')); print theme('page', comment_preview(object2array($comment)));
}
else {
drupal_access_denied();
} }
} }
...@@ -356,13 +359,15 @@ function comment_reply($nid, $pid = NULL) { ...@@ -356,13 +359,15 @@ function comment_reply($nid, $pid = NULL) {
if ($_POST['op'] == t('Post comment')) { if ($_POST['op'] == t('Post comment')) {
$edit = $_POST['edit']; $edit = $_POST['edit'];
comment_validate_form($edit); comment_validate_form($edit);
print theme('page', comment_post($edit), t('Post comment')); drupal_set_title(t('Post comment'));
print theme('page', comment_post($edit));
return; return;
} }
else if ($_POST['op'] == t('Preview comment')) { else if ($_POST['op'] == t('Preview comment')) {
$edit = $_POST['edit']; $edit = $_POST['edit'];
comment_validate_form($edit); comment_validate_form($edit);
print theme('page', comment_preview($edit), t('Preview comment')); drupal_set_title(t('Preview comment'));
print theme('page', comment_preview($edit));
return; return;
} }
...@@ -397,7 +402,8 @@ function comment_reply($nid, $pid = NULL) { ...@@ -397,7 +402,8 @@ function comment_reply($nid, $pid = NULL) {
$output .= theme('box', t('Reply'), t('You are not authorized to view comments.')); $output .= theme('box', t('Reply'), t('You are not authorized to view comments.'));
} }
print theme('page', $output, t('Add new comment')); drupal_set_title(t('Add new comment'));
print theme('page', $output);
} }
function comment_validate_form($edit) { function comment_validate_form($edit) {
......
...@@ -124,7 +124,7 @@ function comment_menu($may_cache) { ...@@ -124,7 +124,7 @@ function comment_menu($may_cache) {
$access = user_access('post comments'); $access = user_access('post comments');
$items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'), $items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
'callback' => 'comment_reply', 'access' => $access, 'type' => MENU_CALLBACK); 'callback' => 'comment_reply', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment/edit', 'title' => t('edit your comment'), $items[] = array('path' => 'comment/edit', 'title' => t('edit comment'),
'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK); 'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'comment', 'title' => t('reply to comment'), $items[] = array('path' => 'comment', 'title' => t('reply to comment'),
...@@ -341,7 +341,10 @@ function comment_edit($cid) { ...@@ -341,7 +341,10 @@ function comment_edit($cid) {
$comment = drupal_unpack($comment); $comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) { if (comment_access('edit', $comment)) {
print theme('page', comment_preview(object2array($comment)), t('Edit comment')); print theme('page', comment_preview(object2array($comment)));
}
else {
drupal_access_denied();
} }
} }
...@@ -356,13 +359,15 @@ function comment_reply($nid, $pid = NULL) { ...@@ -356,13 +359,15 @@ function comment_reply($nid, $pid = NULL) {
if ($_POST['op'] == t('Post comment')) { if ($_POST['op'] == t('Post comment')) {
$edit = $_POST['edit']; $edit = $_POST['edit'];
comment_validate_form($edit); comment_validate_form($edit);
print theme('page', comment_post($edit), t('Post comment')); drupal_set_title(t('Post comment'));
print theme('page', comment_post($edit));
return; return;
} }
else if ($_POST['op'] == t('Preview comment')) { else if ($_POST['op'] == t('Preview comment')) {
$edit = $_POST['edit']; $edit = $_POST['edit'];
comment_validate_form($edit); comment_validate_form($edit);
print theme('page', comment_preview($edit), t('Preview comment')); drupal_set_title(t('Preview comment'));
print theme('page', comment_preview($edit));
return; return;
} }
...@@ -397,7 +402,8 @@ function comment_reply($nid, $pid = NULL) { ...@@ -397,7 +402,8 @@ function comment_reply($nid, $pid = NULL) {
$output .= theme('box', t('Reply'), t('You are not authorized to view comments.')); $output .= theme('box', t('Reply'), t('You are not authorized to view comments.'));
} }
print theme('page', $output, t('Add new comment')); drupal_set_title(t('Add new comment'));
print theme('page', $output);
} }
function comment_validate_form($edit) { function comment_validate_form($edit) {
......
...@@ -199,7 +199,7 @@ function drupal_menu($may_cache) { ...@@ -199,7 +199,7 @@ function drupal_menu($may_cache) {
* Menu callback; print Drupal-authentication-specific information from user/help. * Menu callback; print Drupal-authentication-specific information from user/help.
*/ */
function drupal_page_help() { function drupal_page_help() {
print theme('page', drupal_help('user/help#drupal'), t('Drupal')); print theme('page', drupal_help('user/help#drupal'));
} }
/** /**
......
...@@ -199,7 +199,7 @@ function drupal_menu($may_cache) { ...@@ -199,7 +199,7 @@ function drupal_menu($may_cache) {
* Menu callback; print Drupal-authentication-specific information from user/help. * Menu callback; print Drupal-authentication-specific information from user/help.
*/ */
function drupal_page_help() { function drupal_page_help() {
print theme('page', drupal_help('user/help#drupal'), t('Drupal')); print theme('page', drupal_help('user/help#drupal'));
} }
/** /**
......
...@@ -671,7 +671,7 @@ function filter_tips_long() { ...@@ -671,7 +671,7 @@ function filter_tips_long() {
else { else {
$output = theme('filter_tips', _filter_tips(-1, true)); $output = theme('filter_tips', _filter_tips(-1, true));
} }
print theme('page', $output, t('Compose Tips')); print theme('page', $output);
} }
/** /**
......
...@@ -671,7 +671,7 @@ function filter_tips_long() { ...@@ -671,7 +671,7 @@ function filter_tips_long() {
else { else {
$output = theme('filter_tips', _filter_tips(-1, true)); $output = theme('filter_tips', _filter_tips(-1, true));
} }
print theme('page', $output, t('Compose Tips')); print theme('page', $output);
} }
/** /**
......
...@@ -487,7 +487,8 @@ function forum_page($tid = 0) { ...@@ -487,7 +487,8 @@ function forum_page($tid = 0) {
print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page); print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page);
} }
else { else {
print theme('page', forum_help('admin/settings/forum'), t('Warning')); drupal_set_title(t('Warning'));
print theme('page', forum_help('admin/settings/forum'));
} }
} }
...@@ -501,7 +502,7 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p ...@@ -501,7 +502,7 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
// forum list, topics list, topic browser and 'add new topic' link // forum list, topics list, topic browser and 'add new topic' link
$vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', '')); $vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', ''));
$title = $vocabulary->name; drupal_set_title($title = $vocabulary->name);
// Breadcrumb navigation: // Breadcrumb navigation:
$breadcrumb = array(); $breadcrumb = array();
...@@ -554,11 +555,11 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p ...@@ -554,11 +555,11 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
$output .= '</div>'; $output .= '</div>';
} }
else { else {
$title = t('No forums defined'); drupal_set_title(t('No forums defined'));
$output = ''; $output = '';
} }
print theme('page', $output, $title); print theme('page', $output);
} }
/** /**
......
...@@ -487,7 +487,8 @@ function forum_page($tid = 0) { ...@@ -487,7 +487,8 @@ function forum_page($tid = 0) {
print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page); print theme('forum_display', $forums, $topics, $parents, $tid, $sortby, $forum_per_page);
} }
else { else {
print theme('page', forum_help('admin/settings/forum'), t('Warning')); drupal_set_title(t('Warning'));
print theme('page', forum_help('admin/settings/forum'));
} }
} }
...@@ -501,7 +502,7 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p ...@@ -501,7 +502,7 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
// forum list, topics list, topic browser and 'add new topic' link // forum list, topics list, topic browser and 'add new topic' link
$vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', '')); $vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', ''));
$title = $vocabulary->name; drupal_set_title($title = $vocabulary->name);
// Breadcrumb navigation: // Breadcrumb navigation:
$breadcrumb = array(); $breadcrumb = array();
...@@ -554,11 +555,11 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p ...@@ -554,11 +555,11 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
$output .= '</div>'; $output .= '</div>';
} }
else { else {
$title = t('No forums defined'); drupal_set_title(t('No forums defined'));
$output = ''; $output = '';
} }
print theme('page', $output, $title); print theme('page', $output);
} }
/** /**
......
...@@ -1514,7 +1514,8 @@ function node_page() { ...@@ -1514,7 +1514,8 @@ function node_page() {
if (is_numeric(arg(1))) { if (is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)), $_GET['revision']); $node = node_load(array('nid' => arg(1)), $_GET['revision']);
if ($node->nid) { if ($node->nid) {
print theme('page', node_show($node, arg(2)), $node->title); drupal_set_title($node->title);
print theme('page', node_show($node, arg(2)));
} }
else { else {
drupal_not_found(); drupal_not_found();
...@@ -1523,17 +1524,20 @@ function node_page() { ...@@ -1523,17 +1524,20 @@ function node_page() {
break; break;
case t('Preview'): case t('Preview'):
$edit = node_validate($edit); $edit = node_validate($edit);
print theme('page', node_preview($edit), t('Preview')); drupal_set_title(t('Preview'));
print theme('page', node_preview($edit));
break; break;
case t('Submit'): case t('Submit'):
drupal_set_title(t('Submit')); drupal_set_title(t('Submit'));
print theme('page', node_submit($edit)); print theme('page', node_submit($edit));
break; break;
case t('Delete'): case t('Delete'):
print theme('page', node_delete($edit), t('Delete')); drupal_set_title(t('Delete'));
print theme('page', node_delete($edit));
break; break;
default: default:
print theme('page', node_page_default(), ''); drupal_set_title('');
print theme('page', node_page_default());
} }
} }
......
...@@ -1514,7 +1514,8 @@ function node_page() { ...@@ -1514,7 +1514,8 @@ function node_page() {
if (is_numeric(arg(1))) { if (is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)), $_GET['revision']); $node = node_load(array('nid' => arg(1)), $_GET['revision']);
if ($node->nid) { if ($node->nid) {
print theme('page', node_show($node, arg(2)), $node->title); drupal_set_title($node->title);
print theme('page', node_show($node, arg(2)));
} }
else { else {
drupal_not_found(); drupal_not_found();
...@@ -1523,17 +1524,20 @@ function node_page() { ...@@ -1523,17 +1524,20 @@ function node_page() {
break; break;
case t('Preview'): case t('Preview'):
$edit = node_validate($edit); $edit = node_validate($edit);
print theme('page', node_preview($edit), t('Preview')); drupal_set_title(t('Preview'));
print theme('page', node_preview($edit));
break; break;
case t('Submit'): case t('Submit'):
drupal_set_title(t('Submit')); drupal_set_title(t('Submit'));
print theme('page', node_submit($edit)); print theme('page', node_submit($edit));
break; break;
case t('Delete'): case t('Delete'):
print theme('page', node_delete($edit), t('Delete')); drupal_set_title(t('Delete'));
print theme('page', node_delete($edit));
break; break;
default: default:
print theme('page', node_page_default(), ''); drupal_set_title('');
print theme('page', node_page_default());
} }
} }
......
...@@ -107,14 +107,14 @@ function path_admin_edit($pid = 0) { ...@@ -107,14 +107,14 @@ function path_admin_edit($pid = 0) {
} }
elseif ($pid) { elseif ($pid) {
$alias = path_load($pid); $alias = path_load($pid);
$title = $alias['dst']; drupal_set_title($alias['dst']);
$output = path_form(path_load($pid)); $output = path_form(path_load($pid));
} }
else { else {
$output = path_form(); $output = path_form();
} }
print theme('page', $output, $title); print theme('page', $output);
} }
/** /**
......
...@@ -107,14 +107,14 @@ function path_admin_edit($pid = 0) { ...@@ -107,14 +107,14 @@ function path_admin_edit($pid = 0) {
} }
elseif ($pid) { elseif ($pid) {
$alias = path_load($pid); $alias = path_load($pid);
$title = $alias['dst']; drupal_set_title($alias['dst']);
$output = path_form(path_load($pid)); $output = path_form(path_load($pid));
} }
else { else {
$output = path_form(); $output = path_form();
} }
print theme('page', $output, $title); print theme('page', $output);
} }
/** /**
......
...@@ -357,7 +357,8 @@ function poll_view_results(&$node, $main, $page, $block) { ...@@ -357,7 +357,8 @@ function poll_view_results(&$node, $main, $page, $block) {
*/ */
function poll_results() { function poll_results() {
if ($node = node_load(array('nid' => arg(1)))) { if ($node = node_load(array('nid' => arg(1)))) {
print theme('page', node_show($node, 0), $node->title); drupal_set_title($node->title);
print theme('page', node_show($node, 0));
} }
else { else {
drupal_not_found(); drupal_not_found();
......
...@@ -357,7 +357,8 @@ function poll_view_results(&$node, $main, $page, $block) { ...@@ -357,7 +357,8 @@ function poll_view_results(&$node, $main, $page, $block) {
*/ */
function poll_results() { function poll_results() {
if ($node = node_load(array('nid' => arg(1)))) { if ($node = node_load(array('nid' => arg(1)))) {
print theme('page', node_show($node, 0), $node->title); drupal_set_title($node->title);
print theme('page', node_show($node, 0));
} }
else { else {
drupal_not_found(); drupal_not_found();
......
...@@ -113,7 +113,8 @@ function profile_browse() { ...@@ -113,7 +113,8 @@ function profile_browse() {
} }
$output .= '</div>'; $output .= '</div>';
print theme('page', $output, $title); drupal_set_title($title);
print theme('page', $output);
} }
else if ($name && !$field->id) { else if ($name && !$field->id) {
drupal_not_found();