[drupal-devel] Drupal executes stuff in .inc files
Gerhard Killesreiter
killesreiter at physik.uni-freiburg.de
Sat Mar 5 20:51:24 UTC 2005
Hi there!
One of the problems that our Debian packager has had is that for example
the update script includes bootstrap.inc and common.inc. These in turn
include severayl other .inc files. In three of these files (bootstrap,
common, and session) there is php code that does not only define new
functions, but also executes them. This is pretty annoying, as it for
example starts a session which you might not want and initializes
several parts of Drupal you might prefer to not execute for some
reason. You'd however still like all the common.inc functions to be
available.
This will be neccessary to create a php solution for
downloading protected files without executing all of Drupal again.
In the attached patch, I've moved all the functions that should be
executed into index.php. This is again not ideal, as for example my
generate scripts will need to copy quite some code from index.php with
this patch. Ideally we'd have a bootstrap-exec.php and a common-exec.php
file that would hold all this function calls, leaving only the session
functions in index.php.
I believe that this approach might be helpfull for Adrian's installer as
well.
Comments?
Cheers,
Gerhard
-------------- next part --------------
Index: index.php
===================================================================
RCS file: /cvs/drupal/drupal/index.php,v
retrieving revision 1.82
diff -u -F^f -r1.82 index.php
--- index.php 21 Aug 2004 06:42:34 -0000 1.82
+++ index.php 5 Mar 2005 20:26:49 -0000
@@ -10,9 +10,67 @@
*/
include_once 'includes/bootstrap.inc';
+unset($conf);
+$config = conf_init();
+
+include_once "$config/settings.php";
+include_once 'includes/database.inc';
+include_once 'includes/session.inc';
+include_once 'includes/module.inc';
+
+// Initialize configuration variables, using values from conf.php if available.
+$conf = variable_init(isset($conf) ? $conf : array());
+
+// Start session
+session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");
+session_start();
+
drupal_page_header();
include_once 'includes/common.inc';
+// Set the Drupal custom error handler.
+set_error_handler('error_handler');
+
+include_once 'includes/theme.inc';
+include_once 'includes/pager.inc';
+include_once 'includes/menu.inc';
+include_once 'includes/tablesort.inc';
+include_once 'includes/file.inc';
+include_once 'includes/xmlrpc.inc';
+include_once 'includes/image.inc';
+
+// Emit the correct charset HTTP header.
+drupal_set_header('Content-Type: text/html; charset=utf-8');
+
+// Initialize $_GET['q'] prior to loading modules and invoking hook_init().
+if (!empty($_GET['q'])) {
+ $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
+}
+else {
+ $_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
+}
+
+// Initialize all enabled modules.
+module_init();
+
+if (!user_access('bypass input data check')) {
+ // We can't use $_REQUEST because it consists of the contents of $_POST,
+ // $_GET and $_COOKIE: if any of the input arrays share a key, only one
+ // value will be verified.
+ if (!valid_input_data($_GET)
+ || !valid_input_data($_POST)
+ || !valid_input_data($_COOKIE)
+ || !valid_input_data($_FILES)) {
+ die('Terminated request because of suspicious input data.');
+ }
+}
+
+// Initialize the localization system.
+$locale = locale_initialize();
+
+// Initialize the enabled theme.
+$theme = init_theme();
+
fix_gpc_magic();
$status = menu_execute_active_handler();
Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.38
diff -u -F^f -r1.38 bootstrap.inc
--- includes/bootstrap.inc 9 Jan 2005 09:22:38 -0000 1.38
+++ includes/bootstrap.inc 5 Mar 2005 20:26:54 -0000
@@ -628,15 +628,4 @@ function drupal_get_messages() {
return $messages;
}
-unset($conf);
-$config = conf_init();
-
-include_once "$config/settings.php";
-include_once 'includes/database.inc';
-include_once 'includes/session.inc';
-include_once 'includes/module.inc';
-
-// Initialize configuration variables, using values from conf.php if available.
-$conf = variable_init(isset($conf) ? $conf : array());
-
?>
Index: includes/session.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/session.inc,v
retrieving revision 1.14
diff -u -F^f -r1.14 session.inc
--- includes/session.inc 1 Mar 2005 20:15:10 -0000 1.14
+++ includes/session.inc 5 Mar 2005 20:26:55 -0000
@@ -6,9 +6,6 @@
* User session handling functions.
*/
-session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");
-session_start();
-
/*** Session functions *****************************************************/
function sess_open($save_path, $session_name) {
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.428
diff -u -F^f -r1.428 common.inc
--- includes/common.inc 3 Mar 2005 20:13:20 -0000 1.428
+++ includes/common.inc 5 Mar 2005 20:27:11 -0000
@@ -1863,48 +1863,4 @@ function drupal_get_path($type, $name) {
}
');
}
-
-// Set the Drupal custom error handler.
-set_error_handler('error_handler');
-
-include_once 'includes/theme.inc';
-include_once 'includes/pager.inc';
-include_once 'includes/menu.inc';
-include_once 'includes/tablesort.inc';
-include_once 'includes/file.inc';
-include_once 'includes/xmlrpc.inc';
-include_once 'includes/image.inc';
-
-// Emit the correct charset HTTP header.
-drupal_set_header('Content-Type: text/html; charset=utf-8');
-
-// Initialize $_GET['q'] prior to loading modules and invoking hook_init().
-if (!empty($_GET['q'])) {
- $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
-}
-else {
- $_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
-}
-
-// Initialize all enabled modules.
-module_init();
-
-if (!user_access('bypass input data check')) {
- // We can't use $_REQUEST because it consists of the contents of $_POST,
- // $_GET and $_COOKIE: if any of the input arrays share a key, only one
- // value will be verified.
- if (!valid_input_data($_GET)
- || !valid_input_data($_POST)
- || !valid_input_data($_COOKIE)
- || !valid_input_data($_FILES)) {
- die('Terminated request because of suspicious input data.');
- }
-}
-
-// Initialize the localization system.
-$locale = locale_initialize();
-
-// Initialize the enabled theme.
-$theme = init_theme();
-
?>
More information about the drupal-devel
mailing list