Skip to content

Commit

Permalink
Merge pull request pressflow#10 from pdrakeweb/module_implements
Browse files Browse the repository at this point in the history
[#27386523] Merge feature branch with pressflow-6.25.108.
  • Loading branch information
Peter committed Apr 3, 2012
2 parents c133d6d + 6847e40 commit 5e0b959
Show file tree
Hide file tree
Showing 43 changed files with 679 additions and 279 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@

Drupal 6.25, 2012-02-29
----------------------
- Fixed regressions introduced in Drupal 6.24 only.

Drupal 6.24, 2012-02-01
----------------------
- Improved performance of search indexing and user operations by adding indexes.
- Fixed issues with themes getting disabled due to missing locking in
system_theme_data().
- Fix issue with blocks being disabled on updates in _block_rehash().
- Further improvements to PHP 5.3, PHP 4 and PostgreSQL compatibility.
- Improved code documentation at various places.
- Fixed a variety of other bugs.

Drupal 6.23, 2012-02-01
----------------------
- Fixed security issues (Cross site scripting), see SA-CORE-2012-001.
Expand Down
4 changes: 2 additions & 2 deletions INSTALL.mysql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ initial database files. Next you must login and set the access database rights:
Again, you will be asked for the 'username' database password. At the MySQL
prompt, enter following command:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
ON databasename.*
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,
CREATE TEMPORARY TABLES ON databasename.*
TO 'username'@'localhost' IDENTIFIED BY 'password';

where
Expand Down
21 changes: 1 addition & 20 deletions includes/actions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@
* @} End of "defgroup actions".
*/

/**
* @defgroup actions Actions
* @{
* Functions that perform an action on a certain system object.
*
* All modules should declare their action functions to be in this group and
* each action function should reference its configuration form, validate, and
* submit functions using \@see. Conversely, form, validate, and submit
* functions should reference the action function using \@see. For examples of
* this see comment_unpublish_by_keyword_action(), which has the following in
* its doxygen documentation:
*
* \@ingroup actions
* \@see comment_unpublish_by_keyword_action_form().
* \@see comment_unpublish_by_keyword_action_submit().
*
* @} End of "defgroup actions".
*/

/**
* Perform a given list of actions by executing their callback functions.
*
Expand Down Expand Up @@ -355,7 +336,7 @@ function actions_synchronize($actions_in_code = array(), $delete_orphans = FALSE
else {
$link = l(t('Remove orphaned actions'), 'admin/settings/actions/orphan');
$count = count($actions_in_db);
watchdog('actions', format_plural($count, 'One orphaned action (%orphans) exists in the actions table. !link', '@count orphaned actions (%orphans) exist in the actions table. !link'), array('@count' => $count, '%orphans' => $orphans, '!link' => $link), WATCHDOG_WARNING);
watchdog('actions', format_plural($count, 'One orphaned action (%orphans) exists in the actions table. !link', '@count orphaned actions (%orphans) exist in the actions table. !link'), array('@count' => $count, '%orphans' => $orphans, '!link' => $link), WATCHDOG_INFO);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion includes/batch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function _batch_process() {
call_user_func_array($function, array_merge($args, array(&$batch_context)));
}

if ($finished == 1) {
if ($finished >= 1) {
// Make sure this step isn't counted double when computing $current.
$finished = 0;
// Remove the operation and clear the sandbox.
Expand Down
20 changes: 16 additions & 4 deletions includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,18 @@ function conf_init() {
global $db_url, $db_slave_url, $db_prefix, $db_collation, $cookie_domain, $conf, $installed_profile, $update_free_access;
$conf = array();

if (!isset($_SERVER['SERVER_PROTOCOL']) || ($_SERVER['SERVER_PROTOCOL'] != 'HTTP/1.0' && $_SERVER['SERVER_PROTOCOL'] != 'HTTP/1.1')) {
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
}

if (isset($_SERVER['HTTP_HOST'])) {
// As HTTP_HOST is user input, ensure it only contains characters allowed
// in hostnames. See RFC 952 (and RFC 2181).
// $_SERVER['HTTP_HOST'] is lowercased here per specifications.
$_SERVER['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']);
if (!drupal_valid_http_host($_SERVER['HTTP_HOST'])) {
// HTTP_HOST is invalid, e.g. if containing slashes it may be an attack.
header('HTTP/1.1 400 Bad Request');
header($_SERVER['SERVER_PROTOCOL'] .' 400 Bad Request');
exit;
}
}
Expand Down Expand Up @@ -1356,8 +1360,16 @@ function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
* TRUE if access is denied, FALSE if access is allowed.
*/
function drupal_is_denied($type, $mask) {
// Because this function is called for every page request, both cached
// and non-cached pages, we tried to optimize it as much as possible.
if ($type == 'host') {
// Because this function is called with $type == 'host' on every page
// request, we first check for an array of IP addresses in settings.php
// before querying the database. In the former case there is no wildcard
// support.
$blocked_ips = variable_get('blocked_ips', NULL);
if (isset($blocked_ips) && is_array($blocked_ips)) {
return in_array($mask, $blocked_ips);
}
}
// We deny access if the only matching records in the {access} table have
// status 0 (deny). If any have status 1 (allow), or if there are no
// matching records, we allow access.
Expand Down Expand Up @@ -1480,7 +1492,7 @@ function _drupal_bootstrap($phase) {
case DRUPAL_BOOTSTRAP_ACCESS:
// Deny access to hosts which were banned - t() is not yet available.
if (drupal_is_denied('host', ip_address())) {
header('HTTP/1.1 403 Forbidden');
header($_SERVER['SERVER_PROTOCOL'] .' 403 Forbidden');
print 'Sorry, '. check_plain(ip_address()) .' has been banned.';
exit();
}
Expand Down
64 changes: 51 additions & 13 deletions includes/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}

/**
* Error code indicating that the request made by drupal_http_request() exceeded
* the specified timeout.
*/
define('HTTP_REQUEST_TIMEOUT', -1);

/**
* Set content for a specified region.
*
Expand Down Expand Up @@ -347,7 +353,7 @@ function drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response
*/
function drupal_site_offline() {
drupal_maintenance_theme();
drupal_set_header('HTTP/1.1 503 Service unavailable');
drupal_set_header($_SERVER['SERVER_PROTOCOL'] .' 503 Service unavailable');
drupal_set_title(t('Site off-line'));
print theme('maintenance_page', filter_xss_admin(variable_get('site_offline_message',
t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Pressflow'))))));
Expand All @@ -357,7 +363,7 @@ function drupal_site_offline() {
* Generates a 404 error if the request can not be handled.
*/
function drupal_not_found() {
drupal_set_header('HTTP/1.1 404 Not Found');
drupal_set_header($_SERVER['SERVER_PROTOCOL'] .' 404 Not Found');

watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);

Expand Down Expand Up @@ -387,7 +393,7 @@ function drupal_not_found() {
* Generates a 403 error if the request is not allowed.
*/
function drupal_access_denied() {
drupal_set_header('HTTP/1.1 403 Forbidden');
drupal_set_header($_SERVER['SERVER_PROTOCOL'] .' 403 Forbidden');

watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);

Expand Down Expand Up @@ -428,11 +434,15 @@ function drupal_access_denied() {
* @param $retry
* An integer representing how many times to retry the request in case of a
* redirect.
* @param $timeout
* A float representing the maximum number of seconds the function call may
* take. The default is 30 seconds. If a timeout occurs, the error code is set
* to the HTTP_REQUEST_TIMEOUT constant.
* @return
* An object containing the HTTP request headers, response code, protocol,
* status message, headers, data and redirect status.
*/
function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3, $timeout = 30.0) {
global $db_prefix;

$result = new stdClass();
Expand All @@ -452,18 +462,20 @@ function drupal_http_request($url, $headers = array(), $method = 'GET', $data =
return $result;
}

timer_start(__FUNCTION__);

switch ($uri['scheme']) {
case 'http':
case 'feed':
$port = isset($uri['port']) ? $uri['port'] : 80;
$host = $uri['host'] . ($port != 80 ? ':'. $port : '');
$fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
$fp = @fsockopen($uri['host'], $port, $errno, $errstr, $timeout);
break;
case 'https':
// Note: Only works for PHP 4.3 compiled with OpenSSL.
$port = isset($uri['port']) ? $uri['port'] : 443;
$host = $uri['host'] . ($port != 443 ? ':'. $port : '');
$fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, 20);
$fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, $timeout);
break;
default:
$result->error = 'invalid schema '. $uri['scheme'];
Expand Down Expand Up @@ -537,11 +549,25 @@ function drupal_http_request($url, $headers = array(), $method = 'GET', $data =

$result->request = $request;

fwrite($fp, $request);
// Calculate how much time is left of the original timeout value.
$time_left = $timeout - timer_read(__FUNCTION__) / 1000;
if ($time_left > 0) {
stream_set_timeout($fp, floor($time_left), floor(1000000 * fmod($time_left, 1)));
fwrite($fp, $request);
}

// Fetch response.
$response = '';
while (!feof($fp) && $chunk = fread($fp, 1024)) {
while (!feof($fp)) {
// Calculate how much time is left of the original timeout value.
$time_left = $timeout - timer_read(__FUNCTION__) / 1000;
if ($time_left <= 0) {
$result->code = HTTP_REQUEST_TIMEOUT;
$result->error = 'request timed out';
return $result;
}
stream_set_timeout($fp, floor($time_left), floor(1000000 * fmod($time_left, 1)));
$chunk = fread($fp, 1024);
$response .= $chunk;
}
fclose($fp);
Expand Down Expand Up @@ -590,9 +616,13 @@ function drupal_http_request($url, $headers = array(), $method = 'GET', $data =
case 302: // Moved temporarily
case 307: // Moved temporarily
$location = $result->headers['Location'];

if ($retry) {
$result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry);
$timeout -= timer_read(__FUNCTION__) / 1000;
if ($timeout <= 0) {
$result->code = HTTP_REQUEST_TIMEOUT;
$result->error = 'request timed out';
}
elseif ($retry) {
$result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry, $timeout);
$result->redirect_code = $result->code;
}
$result->redirect_url = $location;
Expand Down Expand Up @@ -623,7 +653,7 @@ function drupal_error_handler($errno, $message, $filename, $line, $context) {
return;
}

if ($errno & (E_ALL ^ E_DEPRECATED ^ E_NOTICE)) {
if ($errno & (E_ALL ^ E_DEPRECATED)) {
$types = array(1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice', 2048 => 'strict warning', 4096 => 'recoverable fatal error');

// For database errors, we want the line number/file name of the place that
Expand All @@ -645,7 +675,9 @@ function drupal_error_handler($errno, $message, $filename, $line, $context) {
}
}

$entry = check_plain($types[$errno]) .': '. filter_xss($message) .' in '. check_plain($filename) .' on line '. check_plain($line) .'.';
// Try to use filter_xss(). If it's too early in the bootstrap process for
// filter_xss() to be loaded, use check_plain() instead.
$entry = check_plain($types[$errno]) .': '. (function_exists('filter_xss') ? filter_xss($message) : check_plain($message)) .' in '. check_plain($filename) .' on line '. check_plain($line) .'.';

// Force display of error messages in update.php.
if (variable_get('error_level', 1) == 1 || strstr($_SERVER['SCRIPT_NAME'], 'update.php')) {
Expand Down Expand Up @@ -1789,8 +1821,11 @@ function drupal_add_link($attributes) {
*
* Typical candidates for caching are for example styles for nodes across
* the site, or used in the theme.
*
* @return
* An array of CSS files.
*
* @see drupal_get_css()
*/
function drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE) {
static $css = array();
Expand Down Expand Up @@ -1836,8 +1871,11 @@ function drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preproc
* @param $css
* (optional) An array of CSS files. If no array is provided, the default
* stylesheets array is used instead.
*
* @return
* A string of XHTML CSS tags.
*
* @see drupal_add_css()
*/
function drupal_get_css($css = NULL) {
$output = '';
Expand Down
7 changes: 4 additions & 3 deletions includes/database.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ function db_prefix_tables($sql) {
* code.
*
* @param $name
* The name assigned to the newly active database connection. If omitted, the
* The key in the $db_url global variable from settings.php. If omitted, the
* default connection will be made active.
*
* @return the name of the previously active database or FALSE if non was found.
* @return
* The name of the previously active database, or FALSE if none was found.
*/
function db_set_active($name = 'default') {
global $db_url, $db_slave_url, $db_type, $active_db, $active_slave_db;
Expand Down Expand Up @@ -196,7 +197,7 @@ function _db_error_page($error = '') {
global $db_type;
drupal_init_language();
drupal_maintenance_theme();
drupal_set_header('HTTP/1.1 503 Service Unavailable');
drupal_set_header($_SERVER['SERVER_PROTOCOL'] .' 503 Service Unavailable');
drupal_set_title('Site off-line');

$message = '<p>The site is currently not available due to technical problems. Please try again later. Thank you for your understanding.</p>';
Expand Down
28 changes: 18 additions & 10 deletions includes/file.inc
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ function file_create_filename($basename, $directory) {
}
else {
$name = $basename;
$ext = '';
}

$counter = 0;
Expand Down Expand Up @@ -720,7 +721,7 @@ function file_validate_extensions($file, $extensions) {

// Bypass validation for uid = 1.
if ($user->uid != 1) {
$regex = '/\.('. ereg_replace(' +', '|', preg_quote($extensions)) .')$/i';
$regex = '/\.('. @ereg_replace(' +', '|', preg_quote($extensions)) .')$/i';
if (!preg_match($regex, $file->filename)) {
$errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $extensions));
}
Expand Down Expand Up @@ -868,8 +869,13 @@ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
/**
* Set the status of a file.
*
* @param file A Drupal file object
* @param status A status value to set the file to.
* @param $file
* A Drupal file object.
* @param $status
* A status value to set the file to. One of:
* - FILE_STATUS_PERMANENT
* - FILE_STATUS_TEMPORARY
*
* @return FALSE on failure, TRUE on success and $file->status will contain the
* status.
*/
Expand Down Expand Up @@ -956,6 +962,7 @@ function file_download() {

/**
* Finds all files that match a given mask in a given directory.
*
* Directories and files beginning with a period are excluded; this
* prevents hidden files and directories (such as SVN working directories)
* from being scanned.
Expand All @@ -972,18 +979,19 @@ function file_download() {
* When TRUE, the directory scan will recurse the entire tree
* starting at the provided directory.
* @param $key
* The key to be used for the returned array of files. Possible
* values are "filename", for the path starting with $dir,
* "basename", for the basename of the file, and "name" for the name
* of the file without an extension.
* The key to be used for the returned associative array of files. Possible
* values are "filename", for the path starting with $dir; "basename", for
* the basename of the file; and "name" for the name of the file without the
* extension.
* @param $min_depth
* Minimum depth of directories to return files from.
* @param $depth
* Current depth of recursion. This parameter is only used internally and should not be passed.
* Current depth of recursion. This parameter is only used internally and
* should not be passed in.
*
* @return
* An associative array (keyed on the provided key) of objects with
* "path", "basename", and "name" members corresponding to the
* "filename", "basename", and "name" members corresponding to the
* matching files.
*/
function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = 0, $recurse = TRUE, $key = 'filename', $min_depth = 0, $depth = 0) {
Expand All @@ -997,7 +1005,7 @@ function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $ca
// Give priority to files in this folder by merging them in after any subdirectory files.
$files = array_merge(file_scan_directory("$dir/$file", $mask, $nomask, $callback, $recurse, $key, $min_depth, $depth + 1), $files);
}
elseif ($depth >= $min_depth && ereg($mask, $file)) {
elseif ($depth >= $min_depth && @ereg($mask, $file)) {
// Always use this match over anything already set in $files with the same $$key.
$filename = "$dir/$file";
$basename = basename($file);
Expand Down
Loading

0 comments on commit 5e0b959

Please sign in to comment.