devel.admin.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. function devel_admin_settings() {
  3. $form['queries'] = array('#type' => 'fieldset', '#title' => t('Query log'));
  4. $description = t('Display a log of the database queries needed to generate the current page, and the execution time for each. Also, queries which are repeated during a single page view are summed in the # column, and printed in red since they are candidates for caching.');
  5. if (!devel_is_compatible_optimizer()) {
  6. $description = t('You must disable or upgrade the php Zend Optimizer extension in order to enable this feature. The minimum required version is 3.2.8. Earlier versions of Zend Optimizer are <a href="!url">horribly buggy and segfault your Apache</a> ... ', array('!url' => url('http://drupal.org/node/126098'))) . $description;
  7. }
  8. $form['queries']['devel_query_display'] = array('#type' => 'checkbox',
  9. '#title' => t('Display query log'),
  10. '#default_value' => variable_get('devel_query_display', 0),
  11. '#description' => $description,
  12. '#disabled' => !devel_is_compatible_optimizer(),
  13. );
  14. $form['queries']['settings'] = array(
  15. '#type' => 'container',
  16. '#states' => array(
  17. // Hide the query log settings when not displaying query log.
  18. 'invisible' => array(
  19. 'input[name="devel_query_display"]' => array('checked' => FALSE),
  20. ),
  21. ),
  22. );
  23. $form['queries']['settings']['devel_query_sort'] = array('#type' => 'radios',
  24. '#title' => t('Sort query log'),
  25. '#default_value' => variable_get('devel_query_sort', DEVEL_QUERY_SORT_BY_SOURCE),
  26. '#options' => array(t('by source'), t('by duration')),
  27. '#description' => t('The query table can be sorted in the order that the queries were executed or by descending duration.'),
  28. );
  29. $form['queries']['settings']['devel_execution'] = array('#type' => 'textfield',
  30. '#title' => t('Slow query highlighting'),
  31. '#default_value' => variable_get('devel_execution', 5),
  32. '#size' => 4,
  33. '#maxlength' => 4,
  34. '#description' => t('Enter an integer in milliseconds. Any query which takes longer than this many milliseconds will be highlighted in the query log. This indicates a possibly inefficient query, or a candidate for caching.'),
  35. );
  36. $form['xhprof'] = array(
  37. '#type' => 'fieldset',
  38. '#title' => 'XHProf',
  39. '#description' => t('XHProf is a php extension which is essential for profiling your Drupal site. It pinpoints slow functions, and also memory hogging functions.'),
  40. );
  41. $description = extension_loaded('xhprof') ? t('Profile requests with the xhprof php extension.') : '<span class="warning">' . t('You must enable the <a href="!url">xhprof php extension</a> to use this feature.', array('!url' => url('http://techportal.ibuildings.com/2009/12/01/profiling-with-xhprof/'))) . '</span>';
  42. $form['xhprof']['devel_xhprof_enabled'] = array(
  43. '#type' => 'checkbox',
  44. '#title' => t('Enable profiling of all page views and <a href="!drush">drush</a> requests.', array('!drush' => url('http://drush.ws'))),
  45. '#default_value' => variable_get('devel_xhprof_enabled', FALSE),
  46. '#description' => $description,
  47. '#disabled' => !extension_loaded('xhprof'),
  48. );
  49. $form['xhprof']['settings'] = array(
  50. '#type' => 'container',
  51. '#states' => array(
  52. 'invisible' => array(
  53. 'input[name="devel_xhprof_enabled"]' => array('checked' => FALSE),
  54. ),
  55. ),
  56. );
  57. $form['xhprof']['settings']['devel_xhprof_directory'] = array(
  58. '#type' => 'textfield',
  59. '#title' => 'xhprof directory',
  60. '#description' => t('Location of the xhprof source code on your system, where the directory "xhprof_lib" can be found, usually somewhere in /usr/local/share or /usr/share, include the leading forward slash.'),
  61. '#default_value' => variable_get('devel_xhprof_directory', ''),
  62. '#states' => array(
  63. 'invisible' => array(
  64. 'input[name="devel_xhprof_enabled"]' => array('checked' => FALSE),
  65. ),
  66. ),
  67. );
  68. $form['xhprof']['settings']['devel_xhprof_url'] = array(
  69. '#type' => 'textfield',
  70. '#title' => 'XHProf URL',
  71. '#description' => t('Path to the publically accessible xhprof_html - required to display profiler reports. You will need to set this up outside Drupal, for example at http://xhprof.localhost/xhprof_html'),
  72. '#default_value' => variable_get('devel_xhprof_url', ''),
  73. '#states' => array(
  74. 'invisible' => array(
  75. 'input[name="devel_xhprof_enabled"]' => array('checked' => FALSE),
  76. ),
  77. ),
  78. );
  79. $form['devel_api_url'] = array('#type' => 'textfield',
  80. '#title' => t('API Site'),
  81. '#default_value' => variable_get('devel_api_url', 'api.drupal.org'),
  82. '#description' => t('The base URL for your developer documentation links. You might change this if you run <a href="!url">api.module</a> locally.', array('!url' => url('http://drupal.org/project/api'))));
  83. $form['dev_timer'] = array('#type' => 'checkbox',
  84. '#title' => t('Display page timer'),
  85. '#default_value' => variable_get('dev_timer', 0),
  86. '#description' => t('Display page execution time in the query log box.'),
  87. );
  88. $form['devel_memory'] = array('#type' => 'checkbox',
  89. '#title' => t('Display memory usage'),
  90. '#default_value' => variable_get('devel_memory', 0),
  91. '#description' => t('Display how much memory is used to generate the current page. This will show memory usage when devel_init() is called and when devel_exit() is called.'),
  92. );
  93. $form['devel_redirect_page'] = array('#type' => 'checkbox',
  94. '#title' => t('Display redirection page'),
  95. '#default_value' => variable_get('devel_redirect_page', 0),
  96. '#description' => t('When a module executes drupal_goto(), the query log and other developer information is lost. Enabling this setting presents an intermediate page to developers so that the log can be examined before continuing to the destination page.'),
  97. );
  98. $form['devel_page_alter'] = array('#type' => 'checkbox',
  99. '#title' => t('Display $page array'),
  100. '#default_value' => variable_get('devel_page_alter', FALSE),
  101. '#description' => t('Display $page array from <a href="http://api.drupal.org/api/function/hook_page_alter/7">hook_page_alter()</a> in the messages area of each page.'),
  102. );
  103. $form['devel_raw_names'] = array('#type' => 'checkbox',
  104. '#title' => t('Display machine names of permissions and modules'),
  105. '#default_value' => variable_get('devel_raw_names', FALSE),
  106. '#description' => t('Display the language-independent machine names of the permissions in mouse-over hints on the !Permissions page and the module base file names on the @Permissions and !Modules pages.', array('!Permissions' => l(t('Permissions'), 'admin/people/permissions'), '@Permissions' => t('Permissions'), '!Modules' => l(t('Modules'), 'admin/modules'))),
  107. );
  108. $error_handlers = devel_get_handlers();
  109. $form['devel_error_handlers'] = array(
  110. '#type' => 'select',
  111. '#title' => t('Error handlers'),
  112. '#options' => array(
  113. DEVEL_ERROR_HANDLER_NONE => t('None'),
  114. DEVEL_ERROR_HANDLER_STANDARD => t('Standard Drupal'),
  115. DEVEL_ERROR_HANDLER_BACKTRACE_DPM => t('Krumo backtrace in the message area'),
  116. DEVEL_ERROR_HANDLER_BACKTRACE_KRUMO => t('Krumo backtrace above the rendered page'),
  117. ),
  118. '#multiple' => TRUE,
  119. '#default_value' => empty($error_handlers) ? DEVEL_ERROR_HANDLER_NONE : $error_handlers,
  120. '#description' => t('Select the error handler(s) to use, in case you <a href="@choose">choose to show errors on screen</a>.', array('@choose' => url('admin/config/development/logging'))) . '<ul>' .
  121. '<li>' . t('<em>None</em> is a good option when stepping through the site in your debugger.') . '</li>' .
  122. '<li>' . t('<em>Standard Drupal</em> does not display all the information that is often needed to resolve an issue.') . '</li>' .
  123. '<li>' . t('<em>Krumo backtrace</em> displays nice debug information when any type of error is noticed, but only to users with the %perm permission.', array('%perm' => t('Access developer information'))) . '</li></ul>' .
  124. t('Depending on the situation, the theme, the size of the call stack and the arguments, etc., some handlers may not display their messages, or display them on the subsequent page. Select <em>Standard Drupal</em> <strong>and</strong> <em>Krumo backtrace above the rendered page</em> to maximize your chances of not missing any messages.') . '<br />' .
  125. t('Demonstrate the current error handler(s):') . ' ' . l('notice+warning', $_GET['q'], array('query' => array('demo' => 'warning'))) . ', ' . l('notice+warning+error', $_GET['q'], array('query' => array('demo' => 'error'))) . ' ' . t('(The presentation of the @error is determined by PHP.)', array('@error' => 'error')),
  126. );
  127. $form['devel_error_handlers']['#size'] = count($form['devel_error_handlers']['#options']);
  128. if (empty($_POST) && !empty($_GET['demo'])) {
  129. devel_demonstrate_error_handlers($_GET['demo']);
  130. }
  131. $options = drupal_map_assoc(array('default', 'blue', 'green', 'orange', 'white', 'disabled'));
  132. $form['devel_krumo_skin'] = array(
  133. '#type' => 'radios',
  134. '#title' => t('Krumo display'),
  135. '#description' => t('Select a skin for your debug messages or select <em>disabled</em> to display object and array output in standard PHP format.'),
  136. '#options' => $options,
  137. '#default_value' => variable_get('devel_krumo_skin', 'default'),
  138. );
  139. $form['devel_rebuild_theme_registry'] = array(
  140. '#type' => 'checkbox',
  141. '#title' => t('Rebuild the theme registry on every page load'),
  142. '#description' => t('While creating new templates and theme_ overrides the theme registry needs to be rebuilt.'),
  143. '#default_value' => variable_get('devel_rebuild_theme_registry', FALSE),
  144. );
  145. $form['devel_use_uncompressed_jquery'] = array(
  146. '#type' => 'checkbox',
  147. '#title' => t('Use uncompressed jQuery'),
  148. '#default_value' => variable_get('devel_use_uncompressed_jquery', FALSE),
  149. '#description' => t("Use a human-readable version of jQuery instead of the minified version that ships with Drupal, to make JavaScript debugging easier."),
  150. );
  151. return system_settings_form($form);
  152. }
  153. function devel_demonstrate_error_handlers($severity) {
  154. switch ($severity) {
  155. case 'warning':
  156. $undefined = $undefined;
  157. 1/0;
  158. break;
  159. case 'error':
  160. $undefined = $undefined;
  161. 1/0;
  162. devel_undefined_function();
  163. break;
  164. }
  165. }