Files drupal6/includes/.bootstrap.inc.swp and drupal6lang/includes/.bootstrap.inc.swp differ diff -urNp drupal6/includes/bootstrap.inc drupal6lang/includes/bootstrap.inc --- drupal6/includes/bootstrap.inc 2007-01-29 14:25:19.000000000 -0500 +++ drupal6lang/includes/bootstrap.inc 2007-03-25 18:05:09.796875000 -0400 @@ -85,15 +85,20 @@ define('DRUPAL_BOOTSTRAP_SESSION', 4); define('DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE', 5); /** - * Seventh bootstrap phase: set $_GET['q'] to Drupal path of request. + * Seventh bootstrap phase: find out language of the page. */ -define('DRUPAL_BOOTSTRAP_PATH', 6); +define('DRUPAL_BOOTSTRAP_LANGUAGE', 6); + +/** + * Eighth bootstrap phase: set $_GET['q'] to Drupal path of request. + */ +define('DRUPAL_BOOTSTRAP_PATH', 7); /** * Final bootstrap phase: Drupal is fully loaded; validate and fix * input data. */ -define('DRUPAL_BOOTSTRAP_FULL', 7); +define('DRUPAL_BOOTSTRAP_FULL', 8); /** * Role ID for anonymous users; should match what's in the "role" table. @@ -106,6 +111,30 @@ define('DRUPAL_ANONYMOUS_RID', 1); define('DRUPAL_AUTHENTICATED_RID', 2); /** + * No language negotiation. The default language is used. + */ +define('LANGUAGE_NEGOTIATION_NONE', 0); + +/** + * Path based negotiation with fallback to default language + * if no defined path prefix identified. + */ +define('LANGUAGE_NEGOTIATION_PATH_DEFAULT', 1); + +/** + * Path based negotiation with fallback to user preferences + * and browser language detection if no defined path prefix + * identified. + */ +define('LANGUAGE_NEGOTIATION_PATH', 2); + +/** + * Domain based negotiation with fallback to default language + * if no language identified by domain. + */ +define('LANGUAGE_NEGOTIATION_DOMAIN', 3); + +/** * Start the timer with the specified name. If you start and stop * the same timer multiple times, the measured intervals will be * accumulated. @@ -409,6 +438,7 @@ function variable_del($name) { unset($conf[$name]); } + /** * Retrieve the current page from the cache. * @@ -761,11 +791,12 @@ function drupal_anonymous_user($session * DRUPAL_BOOTSTRAP_SESSION: initialize session handling. * DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE: load bootstrap.inc and module.inc, start * the variable system and try to serve a page from the cache. + * DRUPAL_BOOTSTRAP_LANGUAGE: identify the language used on the page. * DRUPAL_BOOTSTRAP_PATH: set $_GET['q'] to Drupal path of request. * DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data. */ function drupal_bootstrap($phase) { - static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL); + static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL); while (!is_null($current_phase = array_shift($phases))) { _drupal_bootstrap($current_phase); @@ -823,6 +854,10 @@ function _drupal_bootstrap($phase) { drupal_page_header(); break; + case DRUPAL_BOOTSTRAP_LANGUAGE: + drupal_init_language(); + break; + case DRUPAL_BOOTSTRAP_PATH: require_once './includes/path.inc'; // Initialize $_GET['q'] prior to loading modules and invoking hook_init(). @@ -897,3 +932,65 @@ function get_t() { } return $t; } + +/** + * Choose a language for the current page, based on site and user preferences. + */ +function drupal_init_language() { + global $language, $user; + + // Ensure the language is correctly returned, even without multilanguage support. + // Useful for eg. XML/HTML 'lang' attributes. + if (variable_get('language_count', 1) == 1) { + $language = language_default(); + } + else { + include_once './includes/language.inc'; + $language = language_initialize(); + } +} + +/** + * Get a list of languages set up indexed by the specified key + * + * @param $field The field to index the list with. + * @param $reset Boolean to request a reset of the list. + */ +function language_list($field = 'language', $reset = FALSE) { + static $languages = NULL; + + // Reset language list + if ($reset) { + $languages = NULL; + } + + // Init language list + if (!isset($languages)) { + $result = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC'); + while ($row = db_fetch_object($result)) { + $languages['language'][$row->language] = $row; + } + } + + // Return the array indexed by the right field + if (!isset($languages[$field])) { + $languages[$field] = array(); + foreach($languages['language'] as $lang) { + // Some values should be collected into an array + if (in_array($field, array('enabled', 'weight'))) { + $languages[$field][$lang->$field][$lang->language] = $lang; + } + else { + $languages[$field][$lang->$field] = $lang; + } + } + } + return $languages[$field]; +} + +/** + * Default language used on the site + */ +function language_default() { + return variable_get('language_default', (object) array('language' => 'en', 'name' => 'English', 'direction' => 0, 'native' => 'English')); +} diff -urNp drupal6/includes/common.inc drupal6lang/includes/common.inc --- drupal6/includes/common.inc 2007-03-25 14:35:26.000000000 -0400 +++ drupal6lang/includes/common.inc 2007-03-25 14:35:00.718750000 -0400 @@ -600,33 +600,6 @@ function fix_gpc_magic() { } /** - * Initialize the localization system. - */ -function locale_initialize() { - global $user; - - if (function_exists('i18n_get_lang')) { - return i18n_get_lang(); - } - - if (function_exists('locale')) { - $languages = locale_supported_languages(); - $languages = $languages['name']; - } - else { - // Ensure the locale/language is correctly returned, even without locale.module. - // Useful for e.g. XML/HTML 'lang' attributes. - $languages = array('en' => 'English'); - } - if ($user->uid && isset($languages[$user->language])) { - return $user->language; - } - else { - return key($languages); - } -} - -/** * Translate strings to the current locale. * * All human-readable text that will be displayed somewhere within a page should be @@ -722,8 +695,8 @@ function locale_initialize() { * The translated string. */ function t($string, $args = 0) { - global $locale; - if (function_exists('locale') && $locale != 'en') { + global $language; + if (function_exists('locale') && $language->language != 'en') { $string = locale($string); } if (!$args) { @@ -1177,6 +1150,11 @@ function url($path = NULL, $options = ar 'absolute' => FALSE, 'alias' => FALSE, ); + + // May need language dependant rewriting if language.inc is present + if (function_exists('language_url_rewrite')) { + language_url_rewrite($path, $options); + } if ($options['fragment']) { $options['fragment'] = '#'. $options['fragment']; } @@ -1884,7 +1862,6 @@ function xmlrpc($url) { function _drupal_bootstrap_full() { static $called; - global $locale; if ($called) { return; @@ -1908,8 +1885,6 @@ function _drupal_bootstrap_full() { fix_gpc_magic(); // Load all enabled modules module_load_all(); - // Initialize the localization system. Depends on i18n.module being loaded already. - $locale = locale_initialize(); // Let all modules take action before menu system handles the reqest module_invoke_all('init'); diff -urNp drupal6/includes/language.inc drupal6lang/includes/language.inc --- drupal6/includes/language.inc 1969-12-31 19:00:00.000000000 -0500 +++ drupal6lang/includes/language.inc 2007-03-25 16:10:05.484375000 -0400 @@ -0,0 +1,136 @@ +domain); + if ($_SERVER['SERVER_NAME'] == $parts['host']) { + return $language; + } + } + return language_default(); + + case LANGUAGE_NEGOTIATION_PATH_DEFAULT: + case LANGUAGE_NEGOTIATION_PATH: + $languages = language_list('prefix'); + $args = explode('/', $_GET['q']); + $language = array_shift($args); + if (isset($languages[$language])) { + $_GET['q'] = implode('/', $args); + return $languages[$language]; + } + elseif ($mode == LANGUAGE_NEGOTIATION_PATH_DEFAULT) { + return language_default(); + } + break; + } + + // User language. + $languages = language_list(); + if ($user->uid && isset($languages[$user->language])) { + return $languages[$user->language]; + } + + // Browser accept-language parsing. + if ($language = language_from_browser()) { + return $language; + } + + // Fall back on the default if everything else fails. + return language_default(); +} + +/** + * Indetify language from the Accept-language HTTP header we got. + */ +function language_from_browser() { + // Specified by the user via the browser's Accept Language setting + // Samples: "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5" + $browser_langs = array(); + + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + $browser_accept = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); + for ($i = 0; $i < count($browser_accept); $i++) { + // The language part is either a code or a code with a quality. + // We cannot do anything with a * code, so it is skipped. + // If the quality is missing, it is assumed to be 1 according to the RFC. + if (preg_match("!([a-z-]+)(;q=([0-9\\.]+))?!", trim($browser_accept[$i]), $found)) { + $browser_langs[$found[1]] = (isset($found[3]) ? (float) $found[3] : 1.0); + } + } + } + + // Order the codes by quality + arsort($browser_langs); + + // Try to find the first preferred language we have + $languages = language_list('enabled'); + foreach ($browser_langs as $langcode => $q) { + if (isset($languages['1'][$langcode])) { + return $languages['1'][$langcode]; + } + } +} + +/** + * Rewrite URL's with language based prefix. Parameters are the same + * as those of the url() function. + */ +function language_url_rewrite(&$path, &$options) { + global $language; + + // Only modify relative (insite) URLs. + if (!$options['absolute']) { + + // Language can be passed as an option, or we go for current language. + $path_language = isset($options['language']) ? $options['language'] : $language; + switch(variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) { + + case LANGUAGE_NEGOTIATION_NONE: + break; + + case LANGUAGE_NEGOTIATION_DOMAIN: + if ($rewritelang->domain) { + $options['absolute'] = TRUE; + $path = $path_language->domain .'/'. $path; + } + break; + + case LANGUAGE_NEGOTIATION_PATH_DEFAULT: + $default = language_default(); + if ($path_language->language == $default->language) { + break; + } + // Intentionally no break here. + + case LANGUAGE_NEGOTIATION_PATH: + if (isset($path_language->prefix) && $path_language->prefix) { + // Get alias if not already aliased. + if (!$options['alias']) { + $path = drupal_get_path_alias($path, $path_language->language); + $options['alias'] = TRUE; + } + $path = empty($path) ? $path_language->prefix : $path_language->prefix .'/'. $path; + } + break; + + } + } +} diff -urNp drupal6/includes/locale.inc drupal6lang/includes/locale.inc --- drupal6/includes/locale.inc 2007-03-25 14:07:53.000000000 -0400 +++ drupal6lang/includes/locale.inc 2007-03-25 15:54:38.390625000 -0400 @@ -7,92 +7,101 @@ */ // --------------------------------------------------------------------------------- -// Language addition functionality (administration only) +// Language management functionality (administration only) /** * Helper function to add a language - */ -function _locale_add_language($code, $name, $onlylanguage = TRUE) { - db_query("INSERT INTO {locales_meta} (locale, name) VALUES ('%s','%s')", $code, $name); + * + * @param $code + * Language code. + * @param $name + * English name of the language + * @param $native + * Native name of the language + * @param $direction + * 0 for left to right, 1 for right to left direction + * @param $domain + * Optional custom domain name with protocol, without + * trailing slash (eg. http://de.example.com). + * @param $prefix + * Optional path prefix for the language. Defaults to the + * language code if omitted. + * @param $verbose + * Switch to omit the verbose message to the user when used + * only as a utility function. + */ +function _locale_add_language($code, $name, $native, $direction = 0, $domain = '', $prefix = '', $verbose = TRUE) { + if (empty($prefix)) { + $prefix = $code; + } + db_query("INSERT INTO {languages} (language, name, native, direction, domain, prefix) VALUES ('%s', '%s', '%s', %d, '%s', '%s')", $code, $name, $native, $direction, $domain, $prefix); $result = db_query("SELECT lid FROM {locales_source}"); while ($string = db_fetch_object($result)) { - db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d,'%s', '')", $string->lid, $code); + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d,'%s', '')", $string->lid, $code); } // If only the language was added, and not a PO file import triggered // the language addition, we need to inform the user on how to start - // a translation - if ($onlylanguage) { - drupal_set_message(t('The language %locale has been created and can now be used to import a translation. More information is available in the help screen.', array('%locale' => t($name), '@locale-help' => url('admin/help/locale')))); + // working with the language. + if ($verbose) { + drupal_set_message(t('The language %language has been created and can now be used. More information is available on the help screen.', array('%language' => t($name), '@locale-help' => url('admin/help/locale')))); } else { - drupal_set_message(t('The language %locale has been created.', array('%locale' => t($name)))); + drupal_set_message(t('The language %language has been created.', array('%language' => t($name)))); } - watchdog('locale', t('The %language language (%locale) has been created.', array('%language' => $name, '%locale' => $code))); + watchdog('locale', t('The %language language (%code) has been created.', array('%language' => t($name), '%code' => $code))); } /** * User interface for the language management screen. */ function _locale_admin_manage_screen() { - $languages = locale_supported_languages(TRUE, TRUE); + $languages = language_list('language', TRUE); $options = array(); - $form['name'] = array('#tree' => TRUE); - foreach ($languages['name'] as $key => $lang) { - $options[$key] = ''; - $status = db_fetch_object(db_query("SELECT isdefault, enabled FROM {locales_meta} WHERE locale = '%s'", $key)); - if ($status->enabled) { - $enabled[] = $key; - } - if ($status->isdefault) { - $isdefault = $key; - } - if ($key == 'en') { - $form['name']['en'] = array('#value' => check_plain($lang)); - } - else { - $original = db_fetch_object(db_query("SELECT COUNT(*) AS strings FROM {locales_source}")); - $translation = db_fetch_object(db_query("SELECT COUNT(*) AS translation FROM {locales_target} WHERE locale = '%s' AND translation != ''", $key)); - - $ratio = ($original->strings > 0 && $translation->translation > 0) ? round(($translation->translation/$original->strings)*100., 2) : 0; - - $form['name'][$key] = array('#type' => 'textfield', - '#default_value' => $lang, - '#size' => 15, - '#maxlength' => 64, - ); - $form['translation'][$key] = array('#value' => "$translation->translation/$original->strings ($ratio%)"); - } + $form['weight'] = array('#tree' => TRUE); + foreach ($languages as $langcode => $language) { + + $options[$langcode] = ''; + if ($language->enabled) { + $enabled[] = $langcode; + } + $form['weight'][$langcode] = array( + '#type' => 'weight', + '#default_value' => $language->weight + ); + $form['name'][$langcode] = array('#value' => check_plain($language->name)); + $form['native'][$langcode] = array('#value' => check_plain($language->native)); + $form['direction'][$langcode] = array('#value' => ($language->direction ? 'Right to left' : 'Left to right')); } $form['enabled'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $enabled, ); + $default = language_default(); $form['site_default'] = array('#type' => 'radios', '#options' => $options, - '#default_value' => $isdefault, + '#default_value' => $default->language, ); $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); - $form['#submit']['locale_admin_manage_screen_submit'] = array(); - $form['#validate']['locale_admin_manage_screen_validate'] = array(); + $form['#submit']['_locale_admin_manage_screen_submit'] = array(); $form['#theme'] = 'locale_admin_manage_screen'; return $form; } /** - * Theme the locale admin manager form. + * Theme the admin langauge manager form. */ function theme_locale_admin_manage_screen($form) { foreach ($form['name'] as $key => $element) { // Do not take form control structures. if (is_array($element) && element_child($key)) { - $rows[] = array(check_plain($key), drupal_render($form['name'][$key]), drupal_render($form['enabled'][$key]), drupal_render($form['site_default'][$key]), ($key != 'en' ? drupal_render($form['translation'][$key]) : t('n/a')), ($key != 'en' ? l(t('delete'), 'admin/build/locale/language/delete/'. $key) : '')); + $rows[] = array(array('data' => drupal_render($form['enabled'][$key]), 'align' => 'center'), check_plain($key), ''. drupal_render($form['name'][$key]) .'', drupal_render($form['native'][$key]), drupal_render($form['direction'][$key]), drupal_render($form['site_default'][$key]), drupal_render($form['weight'][$key]), l(t('edit'), 'admin/build/locale/language/edit/'. $key). ($key != 'en' ? ' ' .l(t('delete'), 'admin/build/locale/language/delete/'. $key) : '')); } } - $header = array(array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Translated')), array('data' => t('Operations'))); + $header = array(array('data' => t('Enabled')), array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Native name')), array('data' => t('Direction')), array('data' => t('Default')), array('data' => t('Weight')), array('data' => t('Operations'))); $output = theme('table', $header, $rows); $output .= drupal_render($form); @@ -104,69 +113,165 @@ function theme_locale_admin_manage_scree */ function _locale_admin_manage_screen_submit($form_id, $form_values) { // Save changes to existing languages. - $languages = locale_supported_languages(FALSE, TRUE); - foreach ($languages['name'] as $key => $value) { - if ($form_values['site_default'] == $key) { - $form_values['enabled'][$key] = 1; // autoenable the default language - } - $enabled = $form_values['enabled'][$key] ? 1 : 0; - if ($key == 'en') { - // Disallow name change for English locale. - db_query("UPDATE {locales_meta} SET isdefault = %d, enabled = %d WHERE locale = 'en'", ($form_values['site_default'] == $key), $enabled); + $languages = language_list(); + $enabled_count = 0; + foreach ($languages as $langcode => $language) { + if ($form_values['site_default'] == $langcode) { + $form_values['enabled'][$langcode] = 1; // autoenable the default language + } + if ($form_values['enabled'][$langcode]) { + $enabled_count++; + $language->enabled = 1; } else { - db_query("UPDATE {locales_meta} SET name = '%s', isdefault = %d, enabled = %d WHERE locale = '%s'", $form_values['name'][$key], ($form_values['site_default'] == $key), $enabled, $key); - } + $language->enabled = 0; + } + $language->weight = $form_values['weight'][$langcode]; + db_query("UPDATE {languages} SET enabled = %d, weight = %d WHERE language = '%s'", $language->enabled, $language->weight, $langcode); + $languages[$langcode] = $language; } drupal_set_message(t('Configuration saved.')); + variable_set('language_default', $languages[$form_values['site_default']]); + variable_set('language_count', $enabled_count); - // Changing the locale settings impacts the interface: + // Changing the language settings impacts the interface. cache_clear_all('*', 'cache_page', TRUE); return 'admin/build/locale/language/overview'; } +/** + * Predefined language setup form. + */ function locale_add_language_form() { - $isocodes = _locale_prepare_iso_list(); + $predefined = _locale_prepare_predefined_list(); $form = array(); $form['language list'] = array('#type' => 'fieldset', - '#title' => t('Language list'), + '#title' => t('Predefined language'), '#collapsible' => TRUE, ); $form['language list']['langcode'] = array('#type' => 'select', '#title' => t('Language name'), - '#default_value' => key($isocodes), - '#options' => $isocodes, - '#description' => t('Select your language here, or add it below, if you are unable to find it.'), + '#default_value' => key($predefined), + '#options' => $predefined, + '#description' => t('Select the desired language here, or add it below, if you are unable to find it in the list.'), ); $form['language list']['submit'] = array('#type' => 'submit', '#value' => t('Add language')); return $form; } +/** + * Custom language addition form. + */ function locale_custom_language_form() { $form = array(); $form['custom language'] = array('#type' => 'fieldset', '#title' => t('Custom language'), '#collapsible' => TRUE, ); - $form['custom language']['langcode'] = array('#type' => 'textfield', - '#title' => t('Language code'), - '#size' => 12, - '#maxlength' => 60, - '#required' => TRUE, - '#description' => t('Commonly this is an ISO 639 language code with an optional country code for regional variants. Examples include "en", "en-US" and "zh-cn".', array('@iso-codes' => 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm')), + _locale_language_form($form['custom language']); + $form['custom language']['submit'] = array( + '#type' => 'submit', + '#value' => t('Add custom language') ); - $form['custom language']['langname'] = array('#type' => 'textfield', + // Use the validation and submit functions of the add language form. + $form['#submit']['locale_add_language_form_submit'] = array(); + $form['#validate']['locale_add_language_form_validate'] = array(); + $form['#theme'] = 'locale_add_language_form'; + return $form; +} + +/** + * Editing screen for a particular language. + * + * @param $langcode + * Languauge code of the language to edit. + */ +function _locale_admin_manage_edit_screen($langcode) { + if ($language = db_fetch_object(db_query("SELECT * FROM {languages} WHERE language = '%s'", $langcode))) { + $form = array(); + _locale_language_form($form, $language); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save language') + ); + $form['#submit']['locale_edit_language_form_submit'] = array(); + $form['#validate']['locale_edit_language_form_validate'] = array(); + $form['#theme'] = 'locale_edit_language_form'; + return $form; + } + else { + drupal_not_found(); + } +} + +/** + * Common pieces of the language addition and editing form. + * + * @param $form + * A parent form item (or empty array) to add items below. + * @param $language + * Language object to edit. + */ +function _locale_language_form(&$form, $language = NULL) { + if (!is_object($language)) { + $language = new stdClass(); + } + if (isset($language->language)) { + $form['langcode_view'] = array( + '#type' => 'item', + '#title' => t('Language code'), + '#value' => $language->language + ); + $form['langcode'] = array( + '#type' => 'value', + '#value' => $language->language + ); + } + else { + $form['langcode'] = array('#type' => 'textfield', + '#title' => t('Language code'), + '#size' => 12, + '#maxlength' => 60, + '#required' => TRUE, + '#default_value' => @$language->language, + '#disabled' => (isset($language->language)), + '#description' => t('This should be an RFC 4646 compliant language identifier. Basic tags use a country code with an optional script or regional variant name, like "en", "en-US" and "zh-Hant".', array('@rfc4646' => 'http://www.ietf.org/rfc/rfc4646.txt')), + ); + } + $form['langname'] = array('#type' => 'textfield', '#title' => t('Language name in English'), '#maxlength' => 64, + '#default_value' => @$language->name, '#required' => TRUE, '#description' => t('Name of the language. Will be available for translation in all languages.'), ); - $form['custom language']['submit'] = array('#type' => 'submit', '#value' => t('Add custom language')); - // Use the validation and submit functions of the add language form. - $form['#submit']['locale_add_language_form_submit'] = array(); - $form['#validate']['locale_add_language_form_validate'] = array(); - $form['#theme'] = 'locale_add_language_form'; + $form['langnative'] = array('#type' => 'textfield', + '#title' => t('Native language name'), + '#maxlength' => 64, + '#default_value' => @$language->native, + '#required' => TRUE, + '#description' => t('Name of the language in the language being added.'), + ); + $form['prefix'] = array('#type' => 'textfield', + '#title' => t('Path prefix'), + '#maxlength' => 64, + '#default_value' => @$language->prefix, + '#description' => t('Optional path prefix, for example "deutsch" for the German version. This value is not used in the "None" and "Domain" negotiation schemes. You can leave this empty if you use "Path only" negotiation and this is the default language. Changing this will break existing URLs.') + ); + $form['domain'] = array('#type' => 'textfield', + '#title' => t('Language domain'), + '#maxlength' => 64, + '#default_value' => @$language->domain, + '#description' => t('Optional custom domain with protocol (eg. "http://example.de" or "http://de.example.com" for the German version). This value is only used in the "Domain" negotiation mode. If left empty and in "Domain" mode, this language will not be accessible.'), + ); + $form['direction'] = array('#type' => 'radios', + '#title' => t('Direction'), + '#required' => TRUE, + '#description' => t('Direction of the text being written in this language.'), + '#default_value' => @$language->direction, + '#options' => array(0 => t('Left to right'), 1 => t('Right to left')) + ); return $form; } @@ -183,16 +288,21 @@ function _locale_admin_manage_add_screen * Validate the language addition form. */ function locale_add_language_form_validate($form_id, $form_values) { - if ($duplicate = db_num_rows(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $form_values['langcode'])) != 0) { - form_set_error(t('The language %language (%code) already exists.', array('%language' => $form_values['langname'], '%code' => $form_values['langcode']))); + if ($duplicate = db_num_rows(db_query("SELECT language FROM {languages} WHERE language = '%s'", $form_values['langcode'])) != 0) { + form_set_error('langcode', t('The language %language (%code) already exists.', array('%language' => $form_values['langname'], '%code' => $form_values['langcode']))); } if (!isset($form_values['langname'])) { - $isocodes = _locale_get_iso639_list(); - if (!isset($isocodes[$form_values['langcode']])) { + // Predefined language selection. + $predefined = _locale_get_predefined_list(); + if (!isset($predefined[$form_values['langcode']])) { form_set_error('langcode', t('Invalid language code.')); } } + else { + // Reuse the editing form validation routine if we add a custom language + locale_edit_language_form_validate($form_id, $form_values); + } } /** @@ -201,31 +311,108 @@ function locale_add_language_form_valida function locale_add_language_form_submit($form_id, $form_values) { if (isset($form_values['langname'])) { // Custom language form. - _locale_add_language($form_values['langcode'], $form_values['langname']); + _locale_add_language($form_values['langcode'], $form_values['langname'], $form_values['langnative'], $form_values['direction'], $form_values['domain'], $form_values['prefix']); } else { - $isocodes = _locale_get_iso639_list(); - _locale_add_language($form_values['langcode'], $isocodes[$form_values['langcode']][0]); + // Predefined language selection. + $predefined = _locale_get_predefined_list(); + $lang = &$predefined[$form_values['langcode']]; + _locale_add_language($form_values['langcode'], $lang[0], isset($lang[1]) ? $lang[1] : $lang[0], isset($lang[2]) ? $lang[2] : 0, '', $form_values['langcode']); + } + + return 'admin/build/locale'; +} + +/** + * Validate the language editing form. Reused for custom language addition too. + */ +function locale_edit_language_form_validate($form_id, $form_values) { + if (!empty($form_values['domain']) && !empty($form_values['prefix'])) { + form_set_error('prefix', t('Domain and path prefix values should not be set at the same time.')); + } + if (!empty($form_values['domain']) && $duplicate = db_fetch_object(db_query("SELECT language FROM {languages} WHERE domain = '%s' AND language != '%s'", $form_values['domain'], $form_values['langcode']))) { + form_set_error('domain', t('The domain (%domain) is already tied to a language (%language).', array('%domain' => $form_values['domain'], '%language' => $duplicate->language))); + } + $default = language_default(); + if (empty($form_values['prefix']) && $default->language != $form_values['langcode'] && empty($form_values['domain'])) { + form_set_error('prefix', t('Only the default language can have both the domain and prefix empty.')); } + if (!empty($form_values['prefix']) && $duplicate = db_fetch_object(db_query("SELECT language FROM {languages} WHERE prefix = '%s' AND language != '%s'", $form_values['prefix'], $form_values['langcode']))) { + form_set_error('prefix', t('The prefix (%prefix) is already tied to a language (%language).', array('%prefix' => $form_values['prefix'], '%language' => $duplicate->language))); + } +} + +/** + * Process the language editing form submission. + */ +function locale_edit_language_form_submit($form_id, $form_values) { + db_query("UPDATE {languages} SET name = '%s', native = '%s', domain = '%s', prefix = '%s', direction = %d WHERE language = '%s'", $form_values['langname'], $form_values['langnative'], $form_values['domain'], $form_values['prefix'], $form_values['direction'], $form_values['langcode']); + $default = language_default(); + if ($default->language == $form_values['langcode']) { + $default->name = $form_values['langname']; + $default->native = $form_values['langnative']; + $default->domain = $form_values['domain']; + $default->prefix = $form_values['prefix']; + $default->direction = $form_values['direction']; + variable_set('language_default', $default); + } + return 'admin/build/locale'; +} + +/** + * Setting for language negotiation options + */ +function locale_configure_language_form() { + $form['language_negotiation'] = array( + '#title' => t('Language negotiation'), + '#type' => 'radios', + '#options' => array( + LANGUAGE_NEGOTIATION_NONE => t('None. Language will be independent of visitor preferences and language prefixes or domains.'), + LANGUAGE_NEGOTIATION_PATH_DEFAULT => t('Path prefix only. If a suitable path prefix is not identified, the default language is used.'), + LANGUAGE_NEGOTIATION_PATH => t('Path prefix with language fallback. If a suitable path prefix is not identified, language is based on user preferences and browser language settings.'), + LANGUAGE_NEGOTIATION_DOMAIN => t('Domain name only. If a suitable domain name is not identified, the default language is used.')), + '#default_value' => variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE), + '#description' => t('How should languages get detected? Changing this also changes how paths are constructed, so setting a different value breaks all URLs. Do not change on a live site without thinking twice!') + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save settings') + ); + return $form; +} +/** + * Submit function for language negotiation settings. + */ +function locale_configure_language_form_submit($form_id, $form_values) { + variable_set('language_negotiation', $form_values['language_negotiation']); + drupal_set_message(t('Language negotiation configuration saved.')); return 'admin/build/locale'; } +// --------------------------------------------------------------------------------- +// Translation import/export screens (administration only) + /** * User interface for the translation import screen. */ function _locale_admin_import() { - $languages = locale_supported_languages(FALSE, TRUE); - $languages = array_map('t', $languages['name']); + $languages = language_list(); + $names = array(); + foreach ($languages as $langcode => $language) { + $names[$langcode] = t($language->name); + } + // English means the factory default strings, + // we should not import into it. unset($languages['en']); if (!count($languages)) { - $languages = _locale_prepare_iso_list(); + $languages = _locale_prepare_predefined_list(); } else { $languages = array( t('Already added languages') => $languages, - t('Languages not yet added') => _locale_prepare_iso_list() + t('Languages not yet added') => _locale_prepare_predefined_list() ); } @@ -240,7 +427,7 @@ function _locale_admin_import() { ); $form['import']['langcode'] = array('#type' => 'select', '#title' => t('Import into'), - '#options' => $languages, + '#options' => $names, '#description' => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'), ); $form['import']['mode'] = array('#type' => 'radios', @@ -259,10 +446,11 @@ function _locale_admin_import() { */ function _locale_admin_import_submit($form_id, $form_values) { // Add language, if not yet supported - $languages = locale_supported_languages(TRUE, TRUE); - if (!isset($languages['name'][$form_values['langcode']])) { - $isocodes = _locale_get_iso639_list(); - _locale_add_language($form_values['langcode'], $isocodes[$form_values['langcode']][0], FALSE); + $languages = language_list('language', TRUE); + if (!isset($languages[$form_values['langcode']])) { + $predefined = _locale_get_predefined_list(); + $lang = &$predefined[$form_values['langcode']]; + _locale_add_language($form_values['langcode'], $lang[0], isset($lang[1]) ? $lang[1] : '', isset($lang[2]) ? $lang[2] : 0, '', '', FALSE); } // Now import strings into the language @@ -283,7 +471,7 @@ function _locale_export_po_form($languag ); $form['export']['langcode'] = array('#type' => 'select', '#title' => t('Language name'), - '#options' => $languages, + '#options' => array_keys($languages), '#description' => t('Select the language you would like to export in gettext Portable Object (.po) format.'), ); $form['export']['submit'] = array('#type' => 'submit', '#value' => t('Export')); @@ -308,8 +496,11 @@ function _locale_export_pot_form() { * User interface for the translation export screen */ function _locale_admin_export_screen() { - $languages = locale_supported_languages(FALSE, TRUE); - $languages = array_map('t', $languages['name']); + $languages = language_list(); + $names = array(); + foreach ($languages as $langcode => $language) { + $names[$langcode] = t($language->name); + } unset($languages['en']); $output = ''; @@ -330,14 +521,20 @@ function _locale_export_po_form_submit($ _locale_export_po($form_values['langcode']); } +// --------------------------------------------------------------------------------- +// String search and editing (administration only) + /** * User interface for the string search screen */ function _locale_string_seek_form() { // Get *all* languages set up - $languages = locale_supported_languages(FALSE, TRUE); - asort($languages['name']); unset($languages['name']['en']); - $languages['name'] = array_map('check_plain', $languages['name']); + $languages = language_list(); + unset($languages['en']); + $names = array(); + foreach ($languages as $language) { + $names[$language->language] = check_plain(t($language->name)); + } // Present edit form preserving previous user settings $query = _locale_string_seek_query(); @@ -347,19 +544,19 @@ function _locale_string_seek_form() { ); $form['search']['string'] = array('#type' => 'textfield', '#title' => t('Strings to search for'), - '#default_value' => $query->string, + '#default_value' => @$query['string'], '#size' => 30, '#maxlength' => 30, '#description' => t('Leave blank to show all strings. The search is case sensitive.'), ); $form['search']['language'] = array('#type' => 'radios', '#title' => t('Language'), - '#default_value' => ($query->language ? $query->language : 'all'), - '#options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages['name']), + '#default_value' => (!empty($query['language']) ? $query['language'] : 'all'), + '#options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $names), ); $form['search']['searchin'] = array('#type' => 'radios', '#title' => t('Search in'), - '#default_value' => ($query->searchin ? $query->searchin : 'all'), + '#default_value' => (!empty($query['searchin']) ? $query['searchin'] : 'all'), '#options' => array('all' => t('All strings in that language'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')), ); $form['search']['submit'] = array('#type' => 'submit', '#value' => t('Search')); @@ -372,10 +569,10 @@ function _locale_string_seek_form() { * User interface for string editing. */ function _locale_string_edit($lid) { - $languages = locale_supported_languages(FALSE, TRUE); - unset($languages['name']['en']); + $languages = language_list(); + unset($languages['en']); - $result = db_query('SELECT DISTINCT s.source, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid); + $result = db_query('SELECT DISTINCT s.source, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid); $form = array(); $form['translations'] = array('#tree' => TRUE); while ($translation = db_fetch_object($result)) { @@ -384,13 +581,13 @@ function _locale_string_edit($lid) { // Approximate the number of rows in a textfield with a maximum of 10. $rows = min(ceil(str_word_count($orig) / 12), 10); - $form['translations'][$translation->locale] = array( + $form['translations'][$translation->language] = array( '#type' => 'textarea', - '#title' => $languages['name'][$translation->locale], + '#title' => $languages[$translation->language]->name, '#default_value' => $translation->translation, '#rows' => $rows, ); - unset($languages['name'][$translation->locale]); + unset($languages[$translation->language]); } // Handle erroneous lid. @@ -406,10 +603,10 @@ function _locale_string_edit($lid) { '#weight' => -1, ); - foreach ($languages['name'] as $key => $lang) { - $form['translations'][$key] = array( + foreach ($languages as $langcode => $language) { + $form['translations'][$langcode] = array( '#type' => 'textarea', - '#title' => $lang, + '#title' => t($language->name), '#rows' => $rows, ); } @@ -427,12 +624,12 @@ function _locale_string_edit($lid) { function _locale_string_edit_submit($form_id, $form_values) { $lid = $form_values['lid']; foreach ($form_values['translations'] as $key => $value) { - $trans = db_fetch_object(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $key)); + $trans = db_fetch_object(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND languauge = '%s'", $lid, $key)); if (isset($trans->translation)) { - db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND locale = '%s'", $value, $lid, $key); + db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND language = '%s'", $value, $lid, $key); } else { - db_query("INSERT INTO {locales_target} (lid, translation, locale) VALUES (%d, '%s', '%s')", $lid, $value, $key); + db_query("INSERT INTO {locales_target} (lid, translation, language) VALUES (%d, '%s', '%s')", $lid, $value, $key); } } drupal_set_message(t('The string has been saved.')); @@ -457,6 +654,9 @@ function _locale_string_delete($lid) { drupal_goto('admin/build/locale/string/search'); } +// --------------------------------------------------------------------------------- +// Utility functions + /** * Parses Gettext Portable Object file information and inserts into database * @@ -474,7 +674,7 @@ function _locale_import_po($file, $lang, } // Check if we have the language already in the database - if (!db_fetch_object(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $lang))) { + if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $lang))) { drupal_set_message(t('The language selected for import is not supported.'), 'error'); return FALSE; } @@ -708,10 +908,10 @@ function _locale_import_one_string($op, // Get the plural formula if ($hdr["Plural-Forms"] && $p = _locale_import_parse_plural_forms($hdr["Plural-Forms"], $file->filename)) { list($nplurals, $plural) = $p; - db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", $nplurals, $plural, $lang); + db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", $nplurals, $plural, $lang); } else { - db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", 0, '', $lang); + db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", 0, '', $lang); } $headerdone = TRUE; } @@ -738,13 +938,13 @@ function _locale_import_one_string($op, $lid = $loc->lid; // update location field db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $comments, $lid); - $trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); + $trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $lang)); if (!$trans2->lid) { // no translation in current language - db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); + db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); $additions++; } // translation exists else if ($mode == 'overwrite' || $trans2->translation == '') { - db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", $trans, $plid, $key, $lang, $lid); + db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $trans, $plid, $key, $lang, $lid); if ($trans2->translation == '') { $additions++; } @@ -757,7 +957,7 @@ function _locale_import_one_string($op, db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english[$key]); $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); $lid = $loc->lid; - db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); + db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); if ($trans != '') { $additions++; } @@ -775,13 +975,13 @@ function _locale_import_one_string($op, $lid = $loc->lid; // update location field db_query("UPDATE {locales_source} SET location = '%s' WHERE source = '%s'", $comments, $english); - $trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); + $trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $lang)); if (!$trans->lid) { // no translation in current language - db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); $additions++; } // translation exists else if ($mode == 'overwrite') { //overwrite in any case - db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid); + db_query("UPDATE {locales_target} SET translation = '%s' WHERE language = '%s' AND lid = %d", $translation, $lang, $lid); if ($trans->translation == '') { $additions++; } @@ -790,7 +990,7 @@ function _locale_import_one_string($op, } } // overwrite if empty string else if ($trans->translation == '') { - db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid); + db_query("UPDATE {locales_target} SET translation = '%s' WHERE language = '%s' AND lid = %d", $translation, $lang, $lid); $additions++; } } @@ -798,7 +998,7 @@ function _locale_import_one_string($op, db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english); $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); $lid = $loc->lid; - db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); if ($translation != '') { $additions++; } @@ -1104,8 +1304,8 @@ function _locale_export_po($language) { // Get language specific strings, or all strings if ($language) { - $meta = db_fetch_object(db_query("SELECT * FROM {locales_meta} WHERE locale = '%s'", $language)); - $result = db_query("SELECT s.lid, s.source, s.location, t.translation, t.plid, t.plural FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.locale = '%s' ORDER BY t.plid, t.plural", $language); + $meta = db_fetch_object(db_query("SELECT * FROM {languages} WHERE language = '%s'", $language)); + $result = db_query("SELECT s.lid, s.source, s.location, t.translation, t.plid, t.plural FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.language = '%s' ORDER BY t.plid, t.plural", $language); } else { $result = db_query("SELECT s.lid, s.source, s.location, t.plid, t.plural FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid ORDER BY t.plid, t.plural"); @@ -1290,40 +1490,27 @@ function _locale_string_language_list($t // Add CSS drupal_add_css(drupal_get_path('module', 'locale') .'/locale.css', 'module', 'all', FALSE); - $languages = locale_supported_languages(FALSE, TRUE); - unset($languages['name']['en']); + $languages = language_list(); + unset($languages['en']); $output = ''; - foreach ($languages['name'] as $key => $value) { - if (isset($translation[$key])) { - $output .= ($translation[$key] != '') ? $key .' ' : "$key "; - } + foreach ($languages as $langcode => $language) { + $output .= (!empty($translation[$langcode])) ? $langcode .' ' : "$langcode "; } return $output; } /** - * Build object out of search criteria specified in request variables + * Build array out of search criteria specified in request variables */ function _locale_string_seek_query() { - static $query; + static $query = NULL; if (!isset($query)) { + $query = array(); $fields = array('string', 'language', 'searchin'); - $query = new stdClass(); - if (is_array($_REQUEST['edit'])) { - foreach ($_REQUEST['edit'] as $key => $value) { - if (!empty($value) && in_array($key, $fields)) { - $query->$key = $value; - } - } - } - else { - foreach ($_REQUEST as $key => $value) { - if (!empty($value) && in_array($key, $fields)) { - $query->$key = strpos(',', $value) ? explode(',', $value) : $value; - } - } + foreach ($fields as $field) { + $query[$field] = !empty($_REQUEST[$field]) ? $_REQUEST[$field] : ''; } } return $query; @@ -1333,37 +1520,39 @@ function _locale_string_seek_query() { * Perform a string search and display results in a table */ function _locale_string_seek() { + $output = ''; + // We have at least one criterion to match if ($query = _locale_string_seek_query()) { - $join = "SELECT s.source, s.location, s.lid, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid "; + $join = "SELECT s.source, s.location, s.lid, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid "; $arguments = array(); // Compute LIKE section - switch ($query->searchin) { + switch ($query['searchin']) { case 'translated': $where = "WHERE (t.translation LIKE '%%%s%%' AND t.translation != '')"; $orderby = "ORDER BY t.translation"; - $arguments[] = $query->string; + $arguments[] = $query['string']; break; case 'untranslated': $where = "WHERE (s.source LIKE '%%%s%%' AND t.translation = '')"; $orderby = "ORDER BY s.source"; - $arguments[] = $query->string; + $arguments[] = $query['string']; break; case 'all' : default: $where = "WHERE (s.source LIKE '%%%s%%' OR t.translation LIKE '%%%s%%')"; $orderby = ''; - $arguments[] = $query->string; - $arguments[] = $query->string; + $arguments[] = $query['string']; + $arguments[] = $query['string']; break; } - switch ($query->language) { + switch ($query['language']) { // Force search in source strings case "en": $sql = $join ." WHERE s.source LIKE '%%%s%%' ORDER BY s.source"; - $arguments = array($query->string); // $where is not used, discard its arguments + $arguments = array($query['string']); // $where is not used, discard its arguments break; // Search in all languages case "all": @@ -1371,8 +1560,8 @@ function _locale_string_seek() { break; // Some different language default: - $sql = "$join $where AND t.locale = '%s' $orderby"; - $arguments[] = $query->language; + $sql = "$join $where AND t.language = '%s' $orderby"; + $arguments[] = $query['language']; } $result = pager_query($sql, 50, 0, NULL, $arguments); @@ -1380,25 +1569,19 @@ function _locale_string_seek() { $header = array(t('String'), t('Locales'), array('data' => t('Operations'), 'colspan' => '2')); $arr = array(); while ($locale = db_fetch_object($result)) { - $arr[$locale->lid]['locales'][$locale->locale] = $locale->translation; + $arr[$locale->lid]['locales'][$locale->language] = $locale->translation; $arr[$locale->lid]['location'] = $locale->location; $arr[$locale->lid]['source'] = $locale->source; } + $rows = array(); foreach ($arr as $lid => $value) { $rows[] = array(array('data' => check_plain(truncate_utf8($value['source'], 150, FALSE, TRUE)) .'
'. $value['location'] .''), array('data' => _locale_string_language_list($value['locales']), 'align' => 'center'), array('data' => l(t('edit'), "admin/build/locale/string/edit/$lid"), 'class' => 'nowrap'), array('data' => l(t('delete'), "admin/build/locale/string/delete/$lid"), 'class' => 'nowrap')); } - $request = array(); - if (count($query)) { - foreach ($query as $key => $value) { - $request[$key] = (is_array($value)) ? implode(',', $value) : $value; - } - } - if (count($rows)) { $output .= theme('table', $header, $rows); } - if ($pager = theme('pager', NULL, 50, 0, $request)) { + if ($pager = theme('pager', NULL, 50)) { $output .= $pager; } } @@ -1412,24 +1595,25 @@ function _locale_string_seek() { /** * Prepares the language code list for a select form item with only the unsupported ones */ -function _locale_prepare_iso_list() { - $languages = locale_supported_languages(FALSE, TRUE); - $isocodes = _locale_get_iso639_list(); - foreach ($isocodes as $key => $value) { - if (isset($languages['name'][$key])) { - unset($isocodes[$key]); +function _locale_prepare_predefined_list() { + $languages = language_list(); + $predefined = _locale_get_predefined_list(); + foreach ($predefined as $key => $value) { + if (isset($languages[$key])) { + unset($predefined[$key]); continue; } + // Include native name in output, if possible if (count($value) == 2) { $tname = t($value[0]); - $isocodes[$key] = ($tname == $value[1]) ? $tname : "$tname ($value[1])"; + $predefined[$key] = ($tname == $value[1]) ? $tname : "$tname ($value[1])"; } else { - $isocodes[$key] = t($value[0]); + $predefined[$key] = t($value[0]); } } - asort($isocodes); - return $isocodes; + asort($predefined); + return $predefined; } /** @@ -1437,7 +1621,7 @@ function _locale_prepare_iso_list() { * * Based on ISO 639 and http://people.w3.org/rishida/names/languages.html */ -function _locale_get_iso639_list() { +function _locale_get_predefined_list() { return array( "aa" => array("Afar"), "ab" => array("Abkhazian", "аҧсуа бызшәа"), @@ -1445,7 +1629,7 @@ function _locale_get_iso639_list() { "af" => array("Afrikaans"), "ak" => array("Akan"), "am" => array("Amharic", "አማርኛ"), - "ar" => array("Arabic", "العربية"), + "ar" => array("Arabic", /* Left-to-right marker "‭" */ "العربية", 1), "as" => array("Assamese"), "av" => array("Avar"), "ay" => array("Aymara"), @@ -1480,7 +1664,7 @@ function _locale_get_iso639_list() { "es" => array("Spanish", "Español"), "et" => array("Estonian", "Eesti"), "eu" => array("Basque", "Euskera"), - "fa" => array("Persian", "فارسی"), + "fa" => array("Persian", /* Left-to-right marker "‭" */ "فارسی", 1), "ff" => array("Fulah", "Fulfulde"), "fi" => array("Finnish", "Suomi"), "fj" => array("Fiji"), @@ -1494,7 +1678,7 @@ function _locale_get_iso639_list() { "gu" => array("Gujarati"), "gv" => array("Manx"), "ha" => array("Hausa"), - "he" => array("Hebrew", "עברית"), + "he" => array("Hebrew", /* Left-to-right marker "‭" */ "עברית", 1), "hi" => array("Hindi", "हिन्दी"), "ho" => array("Hiri Motu"), "hr" => array("Croatian", "Hrvatski"), @@ -1561,7 +1745,7 @@ function _locale_get_iso639_list() { "pa" => array("Punjabi"), "pi" => array("Pali"), "pl" => array("Polish", "Polski"), - "ps" => array("Pashto", "پښتو"), + "ps" => array("Pashto", /* Left-to-right marker "‭" */ "پښتو", 1), "pt" => array("Portuguese, Portugal", "Português"), "pt-br" => array("Portuguese, Brazil", "Português"), "qu" => array("Quechua"), @@ -1605,7 +1789,7 @@ function _locale_get_iso639_list() { "ty" => array("Tahitian"), "ug" => array("Uighur"), "uk" => array("Ukrainian", "Українська"), - "ur" => array("Urdu", "اردو"), + "ur" => array("Urdu", /* Left-to-right marker "‭" */ "اردو", 1), "uz" => array("Uzbek", "o'zbek"), "ve" => array("Venda"), "vi" => array("Vietnamese", "Tiếng Việt"), diff -urNp drupal6/includes/locale.inc.orig drupal6lang/includes/locale.inc.orig --- drupal6/includes/locale.inc.orig 1969-12-31 19:00:00.000000000 -0500 +++ drupal6lang/includes/locale.inc.orig 2007-03-25 14:07:53.546875000 -0400 @@ -0,0 +1,1621 @@ +lid, $code); + } + + // If only the language was added, and not a PO file import triggered + // the language addition, we need to inform the user on how to start + // a translation + if ($onlylanguage) { + drupal_set_message(t('The language %locale has been created and can now be used to import a translation. More information is available in the help screen.', array('%locale' => t($name), '@locale-help' => url('admin/help/locale')))); + } + else { + drupal_set_message(t('The language %locale has been created.', array('%locale' => t($name)))); + } + + watchdog('locale', t('The %language language (%locale) has been created.', array('%language' => $name, '%locale' => $code))); +} + +/** + * User interface for the language management screen. + */ +function _locale_admin_manage_screen() { + $languages = locale_supported_languages(TRUE, TRUE); + + $options = array(); + $form['name'] = array('#tree' => TRUE); + foreach ($languages['name'] as $key => $lang) { + $options[$key] = ''; + $status = db_fetch_object(db_query("SELECT isdefault, enabled FROM {locales_meta} WHERE locale = '%s'", $key)); + if ($status->enabled) { + $enabled[] = $key; + } + if ($status->isdefault) { + $isdefault = $key; + } + if ($key == 'en') { + $form['name']['en'] = array('#value' => check_plain($lang)); + } + else { + $original = db_fetch_object(db_query("SELECT COUNT(*) AS strings FROM {locales_source}")); + $translation = db_fetch_object(db_query("SELECT COUNT(*) AS translation FROM {locales_target} WHERE locale = '%s' AND translation != ''", $key)); + + $ratio = ($original->strings > 0 && $translation->translation > 0) ? round(($translation->translation/$original->strings)*100., 2) : 0; + + $form['name'][$key] = array('#type' => 'textfield', + '#default_value' => $lang, + '#size' => 15, + '#maxlength' => 64, + ); + $form['translation'][$key] = array('#value' => "$translation->translation/$original->strings ($ratio%)"); + } + } + $form['enabled'] = array('#type' => 'checkboxes', + '#options' => $options, + '#default_value' => $enabled, + ); + $form['site_default'] = array('#type' => 'radios', + '#options' => $options, + '#default_value' => $isdefault, + ); + $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); + $form['#submit']['locale_admin_manage_screen_submit'] = array(); + $form['#validate']['locale_admin_manage_screen_validate'] = array(); + $form['#theme'] = 'locale_admin_manage_screen'; + + return $form; +} + +/** + * Theme the locale admin manager form. + */ +function theme_locale_admin_manage_screen($form) { + foreach ($form['name'] as $key => $element) { + // Do not take form control structures. + if (is_array($element) && element_child($key)) { + $rows[] = array(check_plain($key), drupal_render($form['name'][$key]), drupal_render($form['enabled'][$key]), drupal_render($form['site_default'][$key]), ($key != 'en' ? drupal_render($form['translation'][$key]) : t('n/a')), ($key != 'en' ? l(t('delete'), 'admin/build/locale/language/delete/'. $key) : '')); + } + } + $header = array(array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Translated')), array('data' => t('Operations'))); + $output = theme('table', $header, $rows); + $output .= drupal_render($form); + + return $output; +} + +/** + * Process locale admin manager form submissions. + */ +function _locale_admin_manage_screen_submit($form_id, $form_values) { + // Save changes to existing languages. + $languages = locale_supported_languages(FALSE, TRUE); + foreach ($languages['name'] as $key => $value) { + if ($form_values['site_default'] == $key) { + $form_values['enabled'][$key] = 1; // autoenable the default language + } + $enabled = $form_values['enabled'][$key] ? 1 : 0; + if ($key == 'en') { + // Disallow name change for English locale. + db_query("UPDATE {locales_meta} SET isdefault = %d, enabled = %d WHERE locale = 'en'", ($form_values['site_default'] == $key), $enabled); + } + else { + db_query("UPDATE {locales_meta} SET name = '%s', isdefault = %d, enabled = %d WHERE locale = '%s'", $form_values['name'][$key], ($form_values['site_default'] == $key), $enabled, $key); + } + } + drupal_set_message(t('Configuration saved.')); + + // Changing the locale settings impacts the interface: + cache_clear_all('*', 'cache_page', TRUE); + + return 'admin/build/locale/language/overview'; +} + +function locale_add_language_form() { + $isocodes = _locale_prepare_iso_list(); + $form = array(); + $form['language list'] = array('#type' => 'fieldset', + '#title' => t('Language list'), + '#collapsible' => TRUE, + ); + $form['language list']['langcode'] = array('#type' => 'select', + '#title' => t('Language name'), + '#default_value' => key($isocodes), + '#options' => $isocodes, + '#description' => t('Select your language here, or add it below, if you are unable to find it.'), + ); + $form['language list']['submit'] = array('#type' => 'submit', '#value' => t('Add language')); + return $form; +} + +function locale_custom_language_form() { + $form = array(); + $form['custom language'] = array('#type' => 'fieldset', + '#title' => t('Custom language'), + '#collapsible' => TRUE, + ); + $form['custom language']['langcode'] = array('#type' => 'textfield', + '#title' => t('Language code'), + '#size' => 12, + '#maxlength' => 60, + '#required' => TRUE, + '#description' => t('Commonly this is an ISO 639 language code with an optional country code for regional variants. Examples include "en", "en-US" and "zh-cn".', array('@iso-codes' => 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm')), + ); + $form['custom language']['langname'] = array('#type' => 'textfield', + '#title' => t('Language name in English'), + '#maxlength' => 64, + '#required' => TRUE, + '#description' => t('Name of the language. Will be available for translation in all languages.'), + ); + $form['custom language']['submit'] = array('#type' => 'submit', '#value' => t('Add custom language')); + // Use the validation and submit functions of the add language form. + $form['#submit']['locale_add_language_form_submit'] = array(); + $form['#validate']['locale_add_language_form_validate'] = array(); + $form['#theme'] = 'locale_add_language_form'; + return $form; +} + +/** + * User interface for the language addition screen. + */ +function _locale_admin_manage_add_screen() { + $output = drupal_get_form('locale_add_language_form'); + $output .= drupal_get_form('locale_custom_language_form'); + return $output; +} + +/** + * Validate the language addition form. + */ +function locale_add_language_form_validate($form_id, $form_values) { + if ($duplicate = db_num_rows(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $form_values['langcode'])) != 0) { + form_set_error(t('The language %language (%code) already exists.', array('%language' => $form_values['langname'], '%code' => $form_values['langcode']))); + } + + if (!isset($form_values['langname'])) { + $isocodes = _locale_get_iso639_list(); + if (!isset($isocodes[$form_values['langcode']])) { + form_set_error('langcode', t('Invalid language code.')); + } + } +} + +/** + * Process the language addition form submission. + */ +function locale_add_language_form_submit($form_id, $form_values) { + if (isset($form_values['langname'])) { + // Custom language form. + _locale_add_language($form_values['langcode'], $form_values['langname']); + } + else { + $isocodes = _locale_get_iso639_list(); + _locale_add_language($form_values['langcode'], $isocodes[$form_values['langcode']][0]); + } + + return 'admin/build/locale'; +} + +/** + * User interface for the translation import screen. + */ +function _locale_admin_import() { + $languages = locale_supported_languages(FALSE, TRUE); + $languages = array_map('t', $languages['name']); + unset($languages['en']); + + if (!count($languages)) { + $languages = _locale_prepare_iso_list(); + } + else { + $languages = array( + t('Already added languages') => $languages, + t('Languages not yet added') => _locale_prepare_iso_list() + ); + } + + $form = array(); + $form['import'] = array('#type' => 'fieldset', + '#title' => t('Import translation'), + ); + $form['import']['file'] = array('#type' => 'file', + '#title' => t('Language file'), + '#size' => 50, + '#description' => t('A gettext Portable Object (.po) file.'), + ); + $form['import']['langcode'] = array('#type' => 'select', + '#title' => t('Import into'), + '#options' => $languages, + '#description' => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'), + ); + $form['import']['mode'] = array('#type' => 'radios', + '#title' => t('Mode'), + '#default_value' => 'overwrite', + '#options' => array('overwrite' => t('Strings in the uploaded file replace existing ones, new ones are added'), 'keep' => t('Existing strings are kept, only new strings are added')), + ); + $form['import']['submit'] = array('#type' => 'submit', '#value' => t('Import')); + $form['#attributes']['enctype'] = 'multipart/form-data'; + + return $form; +} + +/** + * Process the locale import form submission. + */ +function _locale_admin_import_submit($form_id, $form_values) { + // Add language, if not yet supported + $languages = locale_supported_languages(TRUE, TRUE); + if (!isset($languages['name'][$form_values['langcode']])) { + $isocodes = _locale_get_iso639_list(); + _locale_add_language($form_values['langcode'], $isocodes[$form_values['langcode']][0], FALSE); + } + + // Now import strings into the language + $file = file_check_upload('file'); + if ($ret = _locale_import_po($file, $form_values['langcode'], $form_values['mode']) == FALSE) { + $message = t('The translation import of %filename failed.', array('%filename' => $file->filename)); + drupal_set_message($message, 'error'); + watchdog('locale', $message, WATCHDOG_ERROR); + } + + return 'admin/build/locale'; +} + +function _locale_export_po_form($languages) { + $form['export'] = array('#type' => 'fieldset', + '#title' => t('Export translation'), + '#collapsible' => TRUE, + ); + $form['export']['langcode'] = array('#type' => 'select', + '#title' => t('Language name'), + '#options' => $languages, + '#description' => t('Select the language you would like to export in gettext Portable Object (.po) format.'), + ); + $form['export']['submit'] = array('#type' => 'submit', '#value' => t('Export')); + return $form; +} + +function _locale_export_pot_form() { + // Complete template export of the strings + $form['export'] = array('#type' => 'fieldset', + '#title' => t('Export template'), + '#collapsible' => TRUE, + '#description' => t('Generate a gettext Portable Object Template (.pot) file with all the interface strings from the Drupal locale database.'), + ); + $form['export']['submit'] = array('#type' => 'submit', '#value' => t('Export')); + $form['#submit']['_locale_export_po_form_submit'] = array(); + $form['#validate']['_locale_export_po_form_validate'] = array(); + $form['#theme'] = '_locale_export_po_form'; + return $form; +} + +/** + * User interface for the translation export screen + */ +function _locale_admin_export_screen() { + $languages = locale_supported_languages(FALSE, TRUE); + $languages = array_map('t', $languages['name']); + unset($languages['en']); + + $output = ''; + // Offer language specific export if any language is set up + if (count($languages)) { + $output = drupal_get_form('_locale_export_po_form', $languages); + } + + $output .= drupal_get_form('_locale_export_pot_form'); + + return $output; +} + +/** + * Process a locale export form submissions. + */ +function _locale_export_po_form_submit($form_id, $form_values) { + _locale_export_po($form_values['langcode']); +} + +/** + * User interface for the string search screen + */ +function _locale_string_seek_form() { + // Get *all* languages set up + $languages = locale_supported_languages(FALSE, TRUE); + asort($languages['name']); unset($languages['name']['en']); + $languages['name'] = array_map('check_plain', $languages['name']); + + // Present edit form preserving previous user settings + $query = _locale_string_seek_query(); + $form = array(); + $form['search'] = array('#type' => 'fieldset', + '#title' => t('Search'), + ); + $form['search']['string'] = array('#type' => 'textfield', + '#title' => t('Strings to search for'), + '#default_value' => $query->string, + '#size' => 30, + '#maxlength' => 30, + '#description' => t('Leave blank to show all strings. The search is case sensitive.'), + ); + $form['search']['language'] = array('#type' => 'radios', + '#title' => t('Language'), + '#default_value' => ($query->language ? $query->language : 'all'), + '#options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages['name']), + ); + $form['search']['searchin'] = array('#type' => 'radios', + '#title' => t('Search in'), + '#default_value' => ($query->searchin ? $query->searchin : 'all'), + '#options' => array('all' => t('All strings in that language'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')), + ); + $form['search']['submit'] = array('#type' => 'submit', '#value' => t('Search')); + $form['#redirect'] = FALSE; + + return $form; +} + +/** + * User interface for string editing. + */ +function _locale_string_edit($lid) { + $languages = locale_supported_languages(FALSE, TRUE); + unset($languages['name']['en']); + + $result = db_query('SELECT DISTINCT s.source, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid); + $form = array(); + $form['translations'] = array('#tree' => TRUE); + while ($translation = db_fetch_object($result)) { + $orig = $translation->source; + + // Approximate the number of rows in a textfield with a maximum of 10. + $rows = min(ceil(str_word_count($orig) / 12), 10); + + $form['translations'][$translation->locale] = array( + '#type' => 'textarea', + '#title' => $languages['name'][$translation->locale], + '#default_value' => $translation->translation, + '#rows' => $rows, + ); + unset($languages['name'][$translation->locale]); + } + + // Handle erroneous lid. + if (!isset($orig)){ + drupal_set_message(t('String not found.')); + drupal_goto('admin/build/locale/string/search'); + } + + // Add original text. Assign negative weight so that it floats to the top. + $form['item'] = array('#type' => 'item', + '#title' => t('Original text'), + '#value' => check_plain(wordwrap($orig, 0)), + '#weight' => -1, + ); + + foreach ($languages['name'] as $key => $lang) { + $form['translations'][$key] = array( + '#type' => 'textarea', + '#title' => $lang, + '#rows' => $rows, + ); + } + + $form['lid'] = array('#type' => 'value', '#value' => $lid); + $form['submit'] = array('#type' => 'submit', '#value' => t('Save translations')); + + return $form; +} + +/** + * Process string editing form submissions. + * Saves all translations of one string submitted from a form. + */ +function _locale_string_edit_submit($form_id, $form_values) { + $lid = $form_values['lid']; + foreach ($form_values['translations'] as $key => $value) { + $trans = db_fetch_object(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $key)); + if (isset($trans->translation)) { + db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND locale = '%s'", $value, $lid, $key); + } + else { + db_query("INSERT INTO {locales_target} (lid, translation, locale) VALUES (%d, '%s', '%s')", $lid, $value, $key); + } + } + drupal_set_message(t('The string has been saved.')); + + // Refresh the locale cache. + locale_refresh_cache(); + // Rebuild the menu, strings may have changed. + menu_rebuild(); + + return 'admin/build/locale/string/search'; +} + +/** + * Delete a language string. + */ +function _locale_string_delete($lid) { + db_query('DELETE FROM {locales_source} WHERE lid = %d', $lid); + db_query('DELETE FROM {locales_target} WHERE lid = %d', $lid); + locale_refresh_cache(); + drupal_set_message(t('The string has been removed.')); + + drupal_goto('admin/build/locale/string/search'); +} + +/** + * Parses Gettext Portable Object file information and inserts into database + * + * @param $file + * Drupal file object corresponding to the PO file to import + * @param $lang + * Language code + * @param $mode + * Should existing translations be replaced ('overwrite' or 'keep') + */ +function _locale_import_po($file, $lang, $mode) { + // If not in 'safe mode', increase the maximum execution time: + if (!ini_get('safe_mode')) { + set_time_limit(240); + } + + // Check if we have the language already in the database + if (!db_fetch_object(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $lang))) { + drupal_set_message(t('The language selected for import is not supported.'), 'error'); + return FALSE; + } + + // Get strings from file (returns on failure after a partial import, or on success) + $status = _locale_import_read_po('db-store', $file, $mode, $lang); + if ($status === FALSE) { + // error messages are set in _locale_import_read_po + return FALSE; + } + + // Get status information on import process + list($headerdone, $additions, $updates) = _locale_import_one_string('db-report'); + + if (!$headerdone) { + drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array('%filename' => $file->filename)), 'error'); + } + + // rebuild locale cache + cache_clear_all("locale:$lang", 'cache'); + + // rebuild the menu, strings may have changed + menu_rebuild(); + + drupal_set_message(t('The translation was successfully imported. There are %number newly created translated strings and %update strings were updated.', array('%number' => $additions, '%update' => $updates))); + watchdog('locale', t('Imported %file into %locale: %number new strings added and %update updated.', array('%file' => $file->filename, '%locale' => $lang, '%number' => $additions, '%update' => $updates))); + return TRUE; +} + +/** + * Parses Gettext Portable Object file into an array + * + * @param $op + * Storage operation type: db-store or mem-store + * @param $file + * Drupal file object corresponding to the PO file to import + * @param $mode + * Should existing translations be replaced ('overwrite' or 'keep') + * @param $lang + * Language code + */ +function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL) { + + $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return + if (!$fd) { + _locale_import_message('The translation import failed, because the file %filename could not be read.', $file); + return FALSE; + } + + $context = "COMMENT"; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR + $current = array(); // Current entry being read + $plural = 0; // Current plural form + $lineno = 0; // Current line + + while (!feof($fd)) { + $line = fgets($fd, 10*1024); // A line should not be this long + $lineno++; + $line = trim(strtr($line, array("\\\n" => ""))); + + if (!strncmp("#", $line, 1)) { // A comment + if ($context == "COMMENT") { // Already in comment context: add + $current["#"][] = substr($line, 1); + } + elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one + _locale_import_one_string($op, $current, $mode, $lang); + $current = array(); + $current["#"][] = substr($line, 1); + $context = "COMMENT"; + } + else { // Parse error + _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno); + return FALSE; + } + } + elseif (!strncmp("msgid_plural", $line, 12)) { + if ($context != "MSGID") { // Must be plural form for current entry + _locale_import_message('The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.', $file, $lineno); + return FALSE; + } + $line = trim(substr($line, 12)); + $quoted = _locale_import_parse_quoted($line); + if ($quoted === FALSE) { + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); + return FALSE; + } + $current["msgid"] = $current["msgid"] ."\0". $quoted; + $context = "MSGID_PLURAL"; + } + elseif (!strncmp("msgid", $line, 5)) { + if ($context == "MSGSTR") { // End current entry, start a new one + _locale_import_one_string($op, $current, $mode, $lang); + $current = array(); + } + elseif ($context == "MSGID") { // Already in this context? Parse error + _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno); + return FALSE; + } + $line = trim(substr($line, 5)); + $quoted = _locale_import_parse_quoted($line); + if ($quoted === FALSE) { + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); + return FALSE; + } + $current["msgid"] = $quoted; + $context = "MSGID"; + } + elseif (!strncmp("msgstr[", $line, 7)) { + if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[] + _locale_import_message('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.', $file, $lineno); + return FALSE; + } + if (strpos($line, "]") === FALSE) { + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); + return FALSE; + } + $frombracket = strstr($line, "["); + $plural = substr($frombracket, 1, strpos($frombracket, "]") - 1); + $line = trim(strstr($line, " ")); + $quoted = _locale_import_parse_quoted($line); + if ($quoted === FALSE) { + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); + return FALSE; + } + $current["msgstr"][$plural] = $quoted; + $context = "MSGSTR_ARR"; + } + elseif (!strncmp("msgstr", $line, 6)) { + if ($context != "MSGID") { // Should come just after a msgid block + _locale_import_message('The translation file %filename contains an error: "msgstr" is unexpected on line %line.', $file, $lineno); + return FALSE; + } + $line = trim(substr($line, 6)); + $quoted = _locale_import_parse_quoted($line); + if ($quoted === FALSE) { + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); + return FALSE; + } + $current["msgstr"] = $quoted; + $context = "MSGSTR"; + } + elseif ($line != "") { + $quoted = _locale_import_parse_quoted($line); + if ($quoted === FALSE) { + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); + return FALSE; + } + if (($context == "MSGID") || ($context == "MSGID_PLURAL")) { + $current["msgid"] .= $quoted; + } + elseif ($context == "MSGSTR") { + $current["msgstr"] .= $quoted; + } + elseif ($context == "MSGSTR_ARR") { + $current["msgstr"][$plural] .= $quoted; + } + else { + _locale_import_message('The translation file %filename contains an error: there is an unexpected string on line %line.', $file, $lineno); + return FALSE; + } + } + } + + // End of PO file, flush last entry + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { + _locale_import_one_string($op, $current, $mode, $lang); + } + elseif ($context != "COMMENT") { + _locale_import_message('The translation file %filename ended unexpectedly at line %line.', $file, $lineno); + return FALSE; + } + +} + +/** + * Sets an error message occurred during locale file parsing. + * + * @param $message + * The message to be translated + * @param $file + * Drupal file object corresponding to the PO file to import + * @param $lineno + * An optional line number argument + */ +function _locale_import_message($message, $file, $lineno = NULL) { + $vars = array('%filename' => $file->filename); + if (isset($lineno)) { + $vars['%line'] = $lineno; + } + $t = get_t(); + drupal_set_message($t($message, $vars), 'error'); +} + +/** + * Imports a string into the database + * + * @param $op + * Operation to perform: 'db-store', 'db-report', 'mem-store' or 'mem-report' + * @param $value + * Details of the string stored + * @param $mode + * Should existing translations be replaced ('overwrite' or 'keep') + * @param $lang + * Language to store the string in + */ +function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL) { + static $additions = 0; + static $updates = 0; + static $headerdone = FALSE; + static $strings = array(); + + switch ($op) { + // Return stored strings + case 'mem-report': + return $strings; + + // Store string in memory (only supports single strings) + case 'mem-store': + $strings[$value['msgid']] = $value['msgstr']; + return; + + // Called at end of import to inform the user + case 'db-report': + return array($headerdone, $additions, $updates); + + // Store the string we got in the database + case 'db-store': + // We got header information + if ($value['msgid'] == '') { + $hdr = _locale_import_parse_header($value['msgstr']); + + // Get the plural formula + if ($hdr["Plural-Forms"] && $p = _locale_import_parse_plural_forms($hdr["Plural-Forms"], $file->filename)) { + list($nplurals, $plural) = $p; + db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", $nplurals, $plural, $lang); + } + else { + db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", 0, '', $lang); + } + $headerdone = TRUE; + } + + // Some real string to import + else { + $comments = _locale_import_shorten_comments($value['#']); + + // Handle a translation for some plural string + if (strpos($value['msgid'], "\0")) { + $english = explode("\0", $value['msgid'], 2); + $entries = array_keys($value['msgstr']); + for ($i = 3; $i <= count($entries); $i++) { + $english[] = $english[1]; + } + $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); + $english = array_map('_locale_import_append_plural', $english, $entries); + foreach ($translation as $key => $trans) { + if ($key == 0) { + $plid = 0; + } + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); + if ($loc->lid) { // a string exists + $lid = $loc->lid; + // update location field + db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $comments, $lid); + $trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); + if (!$trans2->lid) { // no translation in current language + db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); + $additions++; + } // translation exists + else if ($mode == 'overwrite' || $trans2->translation == '') { + db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", $trans, $plid, $key, $lang, $lid); + if ($trans2->translation == '') { + $additions++; + } + else { + $updates++; + } + } + } + else { // no string + db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english[$key]); + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); + $lid = $loc->lid; + db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); + if ($trans != '') { + $additions++; + } + } + $plid = $lid; + } + } + + // A simple translation + else { + $english = $value['msgid']; + $translation = $value['msgstr']; + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); + if ($loc->lid) { // a string exists + $lid = $loc->lid; + // update location field + db_query("UPDATE {locales_source} SET location = '%s' WHERE source = '%s'", $comments, $english); + $trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); + if (!$trans->lid) { // no translation in current language + db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); + $additions++; + } // translation exists + else if ($mode == 'overwrite') { //overwrite in any case + db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid); + if ($trans->translation == '') { + $additions++; + } + else { + $updates++; + } + } // overwrite if empty string + else if ($trans->translation == '') { + db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid); + $additions++; + } + } + else { // no string + db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english); + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); + $lid = $loc->lid; + db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); + if ($translation != '') { + $additions++; + } + } + } + } + } // end of db-store operation +} + +/** + * Parses a Gettext Portable Object file header + * + * @param $header A string containing the complete header + * @return An associative array of key-value pairs + */ +function _locale_import_parse_header($header) { + $hdr = array(); + + $lines = explode("\n", $header); + foreach ($lines as $line) { + $line = trim($line); + if ($line) { + list($tag, $contents) = explode(":", $line, 2); + $hdr[trim($tag)] = trim($contents); + } + } + + return $hdr; +} + +/** + * Parses a Plural-Forms entry from a Gettext Portable Object file header + * + * @param $pluralforms + * A string containing the Plural-Forms entry + * @param $filename + * A string containing the filename + * @return + * An array containing the number of plurals and a + * formula in PHP for computing the plural form + */ +function _locale_import_parse_plural_forms($pluralforms, $filename) { + // First, delete all whitespace + $pluralforms = strtr($pluralforms, array(" " => "", "\t" => "")); + + // Select the parts that define nplurals and plural + $nplurals = strstr($pluralforms, "nplurals="); + if (strpos($nplurals, ";")) { + $nplurals = substr($nplurals, 9, strpos($nplurals, ";") - 9); + } + else { + return FALSE; + } + $plural = strstr($pluralforms, "plural="); + if (strpos($plural, ";")) { + $plural = substr($plural, 7, strpos($plural, ";") - 7); + } + else { + return FALSE; + } + + // Get PHP version of the plural formula + $plural = _locale_import_parse_arithmetic($plural); + + if ($plural !== FALSE) { + return array($nplurals, $plural); + } + else { + drupal_set_message(t('The translation file %filename contains an error: the plural formula could not be parsed.', array('%filename' => $filename)), 'error'); + return FALSE; + } +} + +/** + * Parses and sanitizes an arithmetic formula into a PHP expression + * + * While parsing, we ensure, that the operators have the right + * precedence and associativity. + * + * @param $string A string containing the arithmetic formula + * @return The PHP version of the formula + */ +function _locale_import_parse_arithmetic($string) { + // Operator precedence table + $prec = array("(" => -1, ")" => -1, "?" => 1, ":" => 1, "||" => 3, "&&" => 4, "==" => 5, "!=" => 5, "<" => 6, ">" => 6, "<=" => 6, ">=" => 6, "+" => 7, "-" => 7, "*" => 8, "/" => 8, "%" => 8); + // Right associativity + $rasc = array("?" => 1, ":" => 1); + + $tokens = _locale_import_tokenize_formula($string); + + // Parse by converting into infix notation then back into postfix + $opstk = array(); + $elstk = array(); + + foreach ($tokens as $token) { + $ctok = $token; + + // Numbers and the $n variable are simply pushed into $elarr + if (is_numeric($token)) { + $elstk[] = $ctok; + } + elseif ($ctok == "n") { + $elstk[] = '$n'; + } + elseif ($ctok == "(") { + $opstk[] = $ctok; + } + elseif ($ctok == ")") { + $topop = array_pop($opstk); + while (($topop != NULL) && ($topop != "(")) { + $elstk[] = $topop; + $topop = array_pop($opstk); + } + } + elseif ($prec[$ctok]) { + // If it's an operator, then pop from $oparr into $elarr until the + // precedence in $oparr is less than current, then push into $oparr + $topop = array_pop($opstk); + while (($topop != NULL) && ($prec[$topop] >= $prec[$ctok]) && !(($prec[$topop] == $prec[$ctok]) && $rasc[$topop] && $rasc[$ctok])) { + $elstk[] = $topop; + $topop = array_pop($opstk); + } + if ($topop) { + $opstk[] = $topop; // Return element to top + } + $opstk[] = $ctok; // Parentheses are not needed + } + else { + return FALSE; + } + } + + // Flush operator stack + $topop = array_pop($opstk); + while ($topop != NULL) { + $elstk[] = $topop; + $topop = array_pop($opstk); + } + + // Now extract formula from stack + $prevsize = count($elstk) + 1; + while (count($elstk) < $prevsize) { + $prevsize = count($elstk); + for ($i = 2; $i < count($elstk); $i++) { + $op = $elstk[$i]; + if ($prec[$op]) { + $f = ""; + if ($op == ":") { + $f = $elstk[$i - 2] ."):". $elstk[$i - 1] .")"; + } + elseif ($op == "?") { + $f = "(". $elstk[$i - 2] ."?(". $elstk[$i - 1]; + } + else { + $f = "(". $elstk[$i - 2] . $op . $elstk[$i - 1] .")"; + } + array_splice($elstk, $i - 2, 3, $f); + break; + } + } + } + + // If only one element is left, the number of operators is appropriate + if (count($elstk) == 1) { + return $elstk[0]; + } + else { + return FALSE; + } +} + +/** + * Backward compatible implementation of token_get_all() for formula parsing + * + * @param $string A string containing the arithmetic formula + * @return The PHP version of the formula + */ +function _locale_import_tokenize_formula($formula) { + $formula = str_replace(" ", "", $formula); + $tokens = array(); + for ($i = 0; $i < strlen($formula); $i++) { + if (is_numeric($formula[$i])) { + $num = $formula[$i]; + $j = $i + 1; + while ($j < strlen($formula) && is_numeric($formula[$j])) { + $num .= $formula[$j]; + $j++; + } + $i = $j - 1; + $tokens[] = $num; + } + elseif ($pos = strpos(" =<>!&|", $formula[$i])) { // We won't have a space + $next = $formula[$i + 1]; + switch ($pos) { + case 1: + case 2: + case 3: + case 4: + if ($next == '=') { + $tokens[] = $formula[$i] .'='; + $i++; + } + else { + $tokens[] = $formula[$i]; + } + break; + case 5: + if ($next == '&') { + $tokens[] = '&&'; + $i++; + } + else { + $tokens[] = $formula[$i]; + } + break; + case 6: + if ($next == '|') { + $tokens[] = '||'; + $i++; + } + else { + $tokens[] = $formula[$i]; + } + break; + } + } + else { + $tokens[] = $formula[$i]; + } + } + return $tokens; +} + +/** + * Modify a string to contain proper count indices + * + * This is a callback function used via array_map() + * + * @param $entry An array element + * @param $key Index of the array element + */ +function _locale_import_append_plural($entry, $key) { + // No modifications for 0, 1 + if ($key == 0 || $key == 1) { + return $entry; + } + + // First remove any possibly false indices, then add new ones + $entry = preg_replace('/(@count)\[[0-9]\]/', '\\1', $entry); + return preg_replace('/(@count)/', "\\1[$key]", $entry); +} + +/** + * Generate a short, one string version of the passed comment array + * + * @param $comment An array of strings containing a comment + * @return Short one string version of the comment + */ +function _locale_import_shorten_comments($comment) { + $comm = ''; + while (count($comment)) { + $test = $comm . substr(array_shift($comment), 1) .', '; + if (strlen($comm) < 130) { + $comm = $test; + } + else { + break; + } + } + return substr($comm, 0, -2); +} + +/** + * Parses a string in quotes + * + * @param $string A string specified with enclosing quotes + * @return The string parsed from inside the quotes + */ +function _locale_import_parse_quoted($string) { + if (substr($string, 0, 1) != substr($string, -1, 1)) { + return FALSE; // Start and end quotes must be the same + } + $quote = substr($string, 0, 1); + $string = substr($string, 1, -1); + if ($quote == '"') { // Double quotes: strip slashes + return stripcslashes($string); + } + elseif ($quote == "'") { // Simple quote: return as-is + return $string; + } + else { + return FALSE; // Unrecognized quote + } +} + +/** + * Exports a Portable Object (Template) file for a language + * + * @param $language Selects a language to generate the output for + */ +function _locale_export_po($language) { + global $user; + + // Get language specific strings, or all strings + if ($language) { + $meta = db_fetch_object(db_query("SELECT * FROM {locales_meta} WHERE locale = '%s'", $language)); + $result = db_query("SELECT s.lid, s.source, s.location, t.translation, t.plid, t.plural FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.locale = '%s' ORDER BY t.plid, t.plural", $language); + } + else { + $result = db_query("SELECT s.lid, s.source, s.location, t.plid, t.plural FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid ORDER BY t.plid, t.plural"); + } + + // Build array out of the database results + $parent = array(); + while ($child = db_fetch_object($result)) { + if ($child->source != '') { + $parent[$child->lid]['comment'] = $child->location; + $parent[$child->lid]['msgid'] = $child->source; + $parent[$child->lid]['translation'] = $child->translation; + if ($child->plid) { + $parent[$child->lid]['child'] = 1; + $parent[$child->plid]['plural'] = $child->lid; + } + } + } + + // Generating Portable Object file for a language + if ($language) { + $filename = $language .'.po'; + $header .= "# $meta->name translation of ". variable_get('site_name', 'Drupal') ."\n"; + $header .= '# Copyright (c) '. date('Y') .' '. $user->name .' <'. $user->mail .">\n"; + $header .= "#\n"; + $header .= "msgid \"\"\n"; + $header .= "msgstr \"\"\n"; + $header .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n"; + $header .= "\"POT-Creation-Date: ". date("Y-m-d H:iO") ."\\n\"\n"; + $header .= "\"PO-Revision-Date: ". date("Y-m-d H:iO") ."\\n\"\n"; + $header .= "\"Last-Translator: ". $user->name .' <'. $user->mail .">\\n\"\n"; + $header .= "\"Language-Team: ". $meta->name .' <'. $user->mail .">\\n\"\n"; + $header .= "\"MIME-Version: 1.0\\n\"\n"; + $header .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n"; + $header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n"; + if ($meta->formula && $meta->plurals) { + $header .= "\"Plural-Forms: nplurals=". $meta->plurals ."; plural=". strtr($meta->formula, array('$' => '')) .";\\n\"\n"; + } + $header .= "\n"; + watchdog('locale', t('Exported %locale translation file: %filename.', array('%locale' => $meta->name, '%filename' => $filename))); + } + + // Generating Portable Object Template + else { + $filename = 'drupal.pot'; + $header .= "# LANGUAGE translation of PROJECT\n"; + $header .= "# Copyright (c) YEAR NAME \n"; + $header .= "#\n"; + $header .= "msgid \"\"\n"; + $header .= "msgstr \"\"\n"; + $header .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n"; + $header .= "\"POT-Creation-Date: ". date("Y-m-d H:iO") ."\\n\"\n"; + $header .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n"; + $header .= "\"Last-Translator: NAME \\n\"\n"; + $header .= "\"Language-Team: LANGUAGE \\n\"\n"; + $header .= "\"MIME-Version: 1.0\\n\"\n"; + $header .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n"; + $header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n"; + $header .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n"; + $header .= "\n"; + watchdog('locale', t('Exported translation file: %filename.', array('%filename' => $filename))); + } + + // Start download process + header("Content-Disposition: attachment; filename=$filename"); + header("Content-Type: text/plain; charset=utf-8"); + + print $header; + + foreach ($parent as $lid => $message) { + if (!isset($message['child'])) { + if ($message['comment']) { + print '#: '. $message['comment'] ."\n"; + } + print 'msgid '. _locale_export_print($message['msgid']); + if ($plural = $message['plural']) { + print 'msgid_plural '. _locale_export_print($parent[$plural]['msgid']); + if ($language) { + $translation = $message['translation']; + for ($i = 0; $i < $meta->plurals; $i++) { + print 'msgstr['. $i .'] '. _locale_export_print($translation); + if ($plural) { + $translation = $parent[$plural]['translation']; + if ($i > 1) { + $translation = _locale_export_remove_plural($translation); + } + $plural = $parent[$plural]['plural']; + } + else { + $translation = ''; + } + } + } + else { + print 'msgstr[0] ""'. "\n"; + print 'msgstr[1] ""'. "\n"; + } + } + else { + if ($language) { + print 'msgstr '. _locale_export_print($message['translation']); + } + else { + print 'msgstr ""'. "\n"; + } + } + print "\n"; + } + } + die(); +} + +/** + * Print out a string on multiple lines + */ +function _locale_export_print($str) { + $stri = addcslashes($str, "\0..\37\\\""); + $parts = array(); + + // Cut text into several lines + while ($stri != "") { + $i = strpos($stri, "\\n"); + if ($i === FALSE) { + $curstr = $stri; + $stri = ""; + } + else { + $curstr = substr($stri, 0, $i + 2); + $stri = substr($stri, $i + 2); + } + $curparts = explode("\n", _locale_export_wrap($curstr, 70)); + $parts = array_merge($parts, $curparts); + } + + if (count($parts) > 1) { + return "\"\"\n\"". implode("\"\n\"", $parts) ."\"\n"; + } + else { + return "\"$parts[0]\"\n"; + } +} + +/** + * Custom word wrapping for Portable Object (Template) files. + */ +function _locale_export_wrap($str, $len) { + $words = explode(' ', $str); + $ret = array(); + + $cur = ""; + $nstr = 1; + while (count($words)) { + $word = array_shift($words); + if ($nstr) { + $cur = $word; + $nstr = 0; + } + elseif (strlen("$cur $word") > $len) { + $ret[] = $cur . " "; + $cur = $word; + } + else { + $cur = "$cur $word"; + } + } + $ret[] = $cur; + + return implode("\n", $ret); +} + +/** + * Removes plural index information from a string + */ +function _locale_export_remove_plural($entry) { + return preg_replace('/(@count)\[[0-9]\]/', '\\1', $entry); +} + +/** + * List languages in search result table + */ +function _locale_string_language_list($translation) { + // Add CSS + drupal_add_css(drupal_get_path('module', 'locale') .'/locale.css', 'module', 'all', FALSE); + + $languages = locale_supported_languages(FALSE, TRUE); + unset($languages['name']['en']); + $output = ''; + foreach ($languages['name'] as $key => $value) { + if (isset($translation[$key])) { + $output .= ($translation[$key] != '') ? $key .' ' : "$key "; + } + } + + return $output; +} + +/** + * Build object out of search criteria specified in request variables + */ +function _locale_string_seek_query() { + static $query; + + if (!isset($query)) { + $fields = array('string', 'language', 'searchin'); + $query = new stdClass(); + if (is_array($_REQUEST['edit'])) { + foreach ($_REQUEST['edit'] as $key => $value) { + if (!empty($value) && in_array($key, $fields)) { + $query->$key = $value; + } + } + } + else { + foreach ($_REQUEST as $key => $value) { + if (!empty($value) && in_array($key, $fields)) { + $query->$key = strpos(',', $value) ? explode(',', $value) : $value; + } + } + } + } + return $query; +} + +/** + * Perform a string search and display results in a table + */ +function _locale_string_seek() { + // We have at least one criterion to match + if ($query = _locale_string_seek_query()) { + $join = "SELECT s.source, s.location, s.lid, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid "; + + $arguments = array(); + // Compute LIKE section + switch ($query->searchin) { + case 'translated': + $where = "WHERE (t.translation LIKE '%%%s%%' AND t.translation != '')"; + $orderby = "ORDER BY t.translation"; + $arguments[] = $query->string; + break; + case 'untranslated': + $where = "WHERE (s.source LIKE '%%%s%%' AND t.translation = '')"; + $orderby = "ORDER BY s.source"; + $arguments[] = $query->string; + break; + case 'all' : + default: + $where = "WHERE (s.source LIKE '%%%s%%' OR t.translation LIKE '%%%s%%')"; + $orderby = ''; + $arguments[] = $query->string; + $arguments[] = $query->string; + break; + } + + switch ($query->language) { + // Force search in source strings + case "en": + $sql = $join ." WHERE s.source LIKE '%%%s%%' ORDER BY s.source"; + $arguments = array($query->string); // $where is not used, discard its arguments + break; + // Search in all languages + case "all": + $sql = "$join $where $orderby"; + break; + // Some different language + default: + $sql = "$join $where AND t.locale = '%s' $orderby"; + $arguments[] = $query->language; + } + + $result = pager_query($sql, 50, 0, NULL, $arguments); + + $header = array(t('String'), t('Locales'), array('data' => t('Operations'), 'colspan' => '2')); + $arr = array(); + while ($locale = db_fetch_object($result)) { + $arr[$locale->lid]['locales'][$locale->locale] = $locale->translation; + $arr[$locale->lid]['location'] = $locale->location; + $arr[$locale->lid]['source'] = $locale->source; + } + foreach ($arr as $lid => $value) { + $rows[] = array(array('data' => check_plain(truncate_utf8($value['source'], 150, FALSE, TRUE)) .'
'. $value['location'] .''), array('data' => _locale_string_language_list($value['locales']), 'align' => 'center'), array('data' => l(t('edit'), "admin/build/locale/string/edit/$lid"), 'class' => 'nowrap'), array('data' => l(t('delete'), "admin/build/locale/string/delete/$lid"), 'class' => 'nowrap')); + } + + $request = array(); + if (count($query)) { + foreach ($query as $key => $value) { + $request[$key] = (is_array($value)) ? implode(',', $value) : $value; + } + } + + if (count($rows)) { + $output .= theme('table', $header, $rows); + } + if ($pager = theme('pager', NULL, 50, 0, $request)) { + $output .= $pager; + } + } + + return $output; +} + +// --------------------------------------------------------------------------------- +// List of some of the most common languages (administration only) + +/** + * Prepares the language code list for a select form item with only the unsupported ones + */ +function _locale_prepare_iso_list() { + $languages = locale_supported_languages(FALSE, TRUE); + $isocodes = _locale_get_iso639_list(); + foreach ($isocodes as $key => $value) { + if (isset($languages['name'][$key])) { + unset($isocodes[$key]); + continue; + } + if (count($value) == 2) { + $tname = t($value[0]); + $isocodes[$key] = ($tname == $value[1]) ? $tname : "$tname ($value[1])"; + } + else { + $isocodes[$key] = t($value[0]); + } + } + asort($isocodes); + return $isocodes; +} + +/** + * Some of the common languages with their English and native names + * + * Based on ISO 639 and http://people.w3.org/rishida/names/languages.html + */ +function _locale_get_iso639_list() { + return array( + "aa" => array("Afar"), + "ab" => array("Abkhazian", "аҧсуа бызшәа"), + "ae" => array("Avestan"), + "af" => array("Afrikaans"), + "ak" => array("Akan"), + "am" => array("Amharic", "አማርኛ"), + "ar" => array("Arabic", "العربية"), + "as" => array("Assamese"), + "av" => array("Avar"), + "ay" => array("Aymara"), + "az" => array("Azerbaijani", "azərbaycan"), + "ba" => array("Bashkir"), + "be" => array("Belarusian", "Беларуская"), + "bg" => array("Bulgarian", "Български"), + "bh" => array("Bihari"), + "bi" => array("Bislama"), + "bm" => array("Bambara", "Bamanankan"), + "bn" => array("Bengali"), + "bo" => array("Tibetan"), + "br" => array("Breton"), + "bs" => array("Bosnian", "Bosanski"), + "ca" => array("Catalan", "Català"), + "ce" => array("Chechen"), + "ch" => array("Chamorro"), + "co" => array("Corsican"), + "cr" => array("Cree"), + "cs" => array("Czech", "Čeština"), + "cu" => array("Old Slavonic"), + "cv" => array("Chuvash"), + "cy" => array("Welsh", "Cymraeg"), + "da" => array("Danish", "Dansk"), + "de" => array("German", "Deutsch"), + "dv" => array("Maldivian"), + "dz" => array("Bhutani"), + "ee" => array("Ewe", "Ɛʋɛ"), + "el" => array("Greek", "Ελληνικά"), + "en" => array("English"), + "eo" => array("Esperanto"), + "es" => array("Spanish", "Español"), + "et" => array("Estonian", "Eesti"), + "eu" => array("Basque", "Euskera"), + "fa" => array("Persian", "فارسی"), + "ff" => array("Fulah", "Fulfulde"), + "fi" => array("Finnish", "Suomi"), + "fj" => array("Fiji"), + "fo" => array("Faeroese"), + "fr" => array("French", "Français"), + "fy" => array("Frisian", "Frysk"), + "ga" => array("Irish", "Gaeilge"), + "gd" => array("Scots Gaelic"), + "gl" => array("Galician", "Galego"), + "gn" => array("Guarani"), + "gu" => array("Gujarati"), + "gv" => array("Manx"), + "ha" => array("Hausa"), + "he" => array("Hebrew", "עברית"), + "hi" => array("Hindi", "हिन्दी"), + "ho" => array("Hiri Motu"), + "hr" => array("Croatian", "Hrvatski"), + "hu" => array("Hungarian", "Magyar"), + "hy" => array("Armenian", "Հայերեն"), + "hz" => array("Herero"), + "ia" => array("Interlingua"), + "id" => array("Indonesian", "Bahasa Indonesia"), + "ie" => array("Interlingue"), + "ig" => array("Igbo"), + "ik" => array("Inupiak"), + "is" => array("Icelandic", "Íslenska"), + "it" => array("Italian", "Italiano"), + "iu" => array("Inuktitut"), + "ja" => array("Japanese", "日本語"), + "jv" => array("Javanese"), + "ka" => array("Georgian"), + "kg" => array("Kongo"), + "ki" => array("Kikuyu"), + "kj" => array("Kwanyama"), + "kk" => array("Kazakh", "Қазақ"), + "kl" => array("Greenlandic"), + "km" => array("Cambodian"), + "kn" => array("Kannada", "ಕನ್ನಡ"), + "ko" => array("Korean", "한국어"), + "kr" => array("Kanuri"), + "ks" => array("Kashmiri"), + "ku" => array("Kurdish", "Kurdî"), + "kv" => array("Komi"), + "kw" => array("Cornish"), + "ky" => array("Kirghiz", "Кыргыз"), + "la" => array("Latin", "Latina"), + "lb" => array("Luxembourgish"), + "lg" => array("Luganda"), + "ln" => array("Lingala"), + "lo" => array("Laothian"), + "lt" => array("Lithuanian", "Lietuviškai"), + "lv" => array("Latvian", "Latviešu"), + "mg" => array("Malagasy"), + "mh" => array("Marshallese"), + "mi" => array("Maori"), + "mk" => array("Macedonian", "Македонски"), + "ml" => array("Malayalam", "മലയാളം"), + "mn" => array("Mongolian"), + "mo" => array("Moldavian"), + "mr" => array("Marathi"), + "ms" => array("Malay", "Bahasa Melayu"), + "mt" => array("Maltese", "Malti"), + "my" => array("Burmese"), + "na" => array("Nauru"), + "nd" => array("North Ndebele"), + "ne" => array("Nepali"), + "ng" => array("Ndonga"), + "nl" => array("Dutch", "Nederlands"), + "nb" => array("Norwegian Bokmål", "Bokmål"), + "nn" => array("Norwegian Nynorsk", "Nynorsk"), + "nr" => array("South Ndebele"), + "nv" => array("Navajo"), + "ny" => array("Chichewa"), + "oc" => array("Occitan"), + "om" => array("Oromo"), + "or" => array("Oriya"), + "os" => array("Ossetian"), + "pa" => array("Punjabi"), + "pi" => array("Pali"), + "pl" => array("Polish", "Polski"), + "ps" => array("Pashto", "پښتو"), + "pt" => array("Portuguese, Portugal", "Português"), + "pt-br" => array("Portuguese, Brazil", "Português"), + "qu" => array("Quechua"), + "rm" => array("Rhaeto-Romance"), + "rn" => array("Kirundi"), + "ro" => array("Romanian", "Română"), + "ru" => array("Russian", "Русский"), + "rw" => array("Kinyarwanda"), + "sa" => array("Sanskrit"), + "sc" => array("Sardinian"), + "sd" => array("Sindhi"), + "se" => array("Northern Sami"), + "sg" => array("Sango"), + "sh" => array("Serbo-Croatian"), + "si" => array("Singhalese"), + "sk" => array("Slovak", "Slovenčina"), + "sl" => array("Slovenian", "Slovenščina"), + "sm" => array("Samoan"), + "sn" => array("Shona"), + "so" => array("Somali"), + "sq" => array("Albanian", "Shqip"), + "sr" => array("Serbian", "Српски"), + "ss" => array("Siswati"), + "st" => array("Sesotho"), + "su" => array("Sudanese"), + "sv" => array("Swedish", "Svenska"), + "sw" => array("Swahili", "Kiswahili"), + "ta" => array("Tamil", "தமிழ்"), + "te" => array("Telugu", "తెలుగు"), + "tg" => array("Tajik"), + "th" => array("Thai", "ภาษาไทย"), + "ti" => array("Tigrinya"), + "tk" => array("Turkmen"), + "tl" => array("Tagalog"), + "tn" => array("Setswana"), + "to" => array("Tonga"), + "tr" => array("Turkish", "Türkçe"), + "ts" => array("Tsonga"), + "tt" => array("Tatar", "Tatarça"), + "tw" => array("Twi"), + "ty" => array("Tahitian"), + "ug" => array("Uighur"), + "uk" => array("Ukrainian", "Українська"), + "ur" => array("Urdu", "اردو"), + "uz" => array("Uzbek", "o'zbek"), + "ve" => array("Venda"), + "vi" => array("Vietnamese", "Tiếng Việt"), + "wo" => array("Wolof"), + "xh" => array("Xhosa", "isiXhosa"), + "yi" => array("Yiddish"), + "yo" => array("Yoruba", "Yorùbá"), + "za" => array("Zhuang"), + "zh-hans" => array("Chinese, Simplified", "简体中文"), + "zh-hant" => array("Chinese, Traditional", "繁體中文"), + "zu" => array("Zulu", "isiZulu"), + ); +} diff -urNp drupal6/includes/path.inc drupal6lang/includes/path.inc --- drupal6/includes/path.inc 2007-01-24 09:48:35.000000000 -0500 +++ drupal6lang/includes/path.inc 2007-03-25 14:28:45.453125000 -0400 @@ -34,15 +34,21 @@ function drupal_init_path() { * - source: return the Drupal system URL for a path alias (if one exists). * @param $path * The path to investigate for corresponding aliases or system URLs. + * @param $path_language + * Optional language code to search the path with. Defaults to the page language. + * If there's no path defined for that language it will search paths without + * language. * * @return * Either a Drupal system path, an aliased path, or FALSE if no path was * found. */ -function drupal_lookup_path($action, $path = '') { - // $map keys are Drupal paths and the values are the corresponding aliases - static $map = array(), $no_src = array(); - static $count; +function drupal_lookup_path($action, $path = '', $path_language = '') { + global $language; + // $map is an array with language keys, holding arrays of Drupal paths to alias relations + static $map = array(), $no_src = array(), $count; + + $path_language = $path_language ? $path_language : $language->language; // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases if (!isset($count)) { @@ -55,26 +61,29 @@ function drupal_lookup_path($action, $pa } elseif ($count > 0 && $path != '') { if ($action == 'alias') { - if (isset($map[$path])) { - return $map[$path]; + if (isset($map[$path_language][$path])) { + return $map[$path_language][$path]; } - $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path)); - $map[$path] = $alias; + // Get the most fitting result falling back with alias without language + $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language)); + $map[$path_language][$path] = $alias; return $alias; } // Check $no_src for this $path in case we've already determined that there // isn't a path that has this alias - elseif ($action == 'source' && !isset($no_src[$path])) { + elseif ($action == 'source' && !isset($no_src[$path_language][$path])) { // Look for the value $path within the cached $map - if (!$src = array_search($path, $map)) { - if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) { - $map[$src] = $path; + $src = ''; + if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) { + // Get the most fitting result falling back with alias without language + if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) { + $map[$path_language][$src] = $path; } else { // We can't record anything into $map because we do not have a valid // index and there is no need because we have not learned anything // about any Drupal path. Thus cache to $no_src. - $no_src[$path] = TRUE; + $no_src[$path_language][$path] = TRUE; } } return $src; @@ -89,18 +98,20 @@ function drupal_lookup_path($action, $pa * * @param $path * An internal Drupal path. + * @param $path_language + * An optional language code to look up the path in. * * @return * An aliased path if one was found, or the original path if no alias was * found. */ -function drupal_get_path_alias($path) { +function drupal_get_path_alias($path, $path_language = '') { $result = $path; - if ($alias = drupal_lookup_path('alias', $path)) { + if ($alias = drupal_lookup_path('alias', $path, $path_language)) { $result = $alias; } if (function_exists('custom_url_rewrite')) { - $result = custom_url_rewrite('alias', $result, $path); + $result = custom_url_rewrite('alias', $result, $path, $path_language); } return $result; } @@ -110,18 +121,20 @@ function drupal_get_path_alias($path) { * * @param $path * A Drupal path alias. + * @param $path_language + * An optional language code to look up the path in. * * @return * The internal path represented by the alias, or the original alias if no * internal path was found. */ -function drupal_get_normal_path($path) { +function drupal_get_normal_path($path, $path_language = '') { $result = $path; - if ($src = drupal_lookup_path('source', $path)) { + if ($src = drupal_lookup_path('source', $path, $path_language)) { $result = $src; } if (function_exists('custom_url_rewrite')) { - $result = custom_url_rewrite('source', $result, $path); + $result = custom_url_rewrite('source', $result, $path, $path_language); } return $result; } diff -urNp drupal6/modules/locale/locale.install drupal6lang/modules/locale/locale.install --- drupal6/modules/locale/locale.install 2006-11-14 01:20:40.000000000 -0500 +++ drupal6lang/modules/locale/locale.install 2007-03-25 14:28:55.609375000 -0400 @@ -11,14 +11,18 @@ function locale_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': - db_query("CREATE TABLE {locales_meta} ( - locale varchar(12) NOT NULL default '', + db_query("CREATE TABLE {languages} ( + language varchar(12) NOT NULL default '', name varchar(64) NOT NULL default '', + native varchar(64) NOT NULL default '', + direction int NOT NULL default '0', enabled int NOT NULL default '0', - isdefault int NOT NULL default '0', plurals int NOT NULL default '0', formula varchar(128) NOT NULL default '', - PRIMARY KEY (locale) + domain varchar(128) NOT NULL default '', + prefix varchar(128) NOT NULL default '', + weight int NOT NULL default '0', + PRIMARY KEY (language) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); db_query("CREATE TABLE {locales_source} ( @@ -32,25 +36,29 @@ function locale_install() { db_query("CREATE TABLE {locales_target} ( lid int NOT NULL default '0', translation blob NOT NULL, - locale varchar(12) NOT NULL default '', + language varchar(12) NOT NULL default '', plid int NOT NULL default '0', plural int NOT NULL default '0', KEY lid (lid), - KEY lang (locale), + KEY lang (language), KEY plid (plid), KEY plural (plural) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); break; case 'pgsql': - db_query("CREATE TABLE {locales_meta} ( - locale varchar(12) NOT NULL default '', + db_query("CREATE TABLE {languages} ( + language varchar(12) NOT NULL default '', name varchar(64) NOT NULL default '', + native varchar(64) NOT NULL default '', + direction int NOT NULL default '0', enabled int NOT NULL default '0', - isdefault int NOT NULL default '0', plurals int NOT NULL default '0', formula varchar(128) NOT NULL default '', - PRIMARY KEY (locale) + domain varchar(128) NOT NULL default '', + prefix varchar(128) NOT NULL default '', + weight int NOT NULL default '0', + PRIMARY KEY (language) )"); db_query("CREATE TABLE {locales_source} ( @@ -63,25 +71,86 @@ function locale_install() { db_query("CREATE TABLE {locales_target} ( lid int NOT NULL default '0', translation text NOT NULL, - locale varchar(12) NOT NULL default '', + language varchar(12) NOT NULL default '', plid int NOT NULL default '0', plural int NOT NULL default '0' )"); db_query("CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)"); - db_query("CREATE INDEX {locales_target}_locale_idx ON {locales_target} (locale)"); + db_query("CREATE INDEX {locales_target}_language_idx ON {locales_target} (language)"); db_query("CREATE INDEX {locales_target}_plid_idx ON {locales_target} (plid)"); db_query("CREATE INDEX {locales_target}_plural_idx ON {locales_target} (plural)"); db_query("CREATE INDEX {locales_source}_source_idx ON {locales_source} (source)"); break; } - db_query("INSERT INTO {locales_meta} (locale, name, enabled, isdefault) VALUES ('en', 'English', '1', '1')"); + db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight) VALUES ('en', 'English', 'English', '0', '1', '0')"); } /** + * @defgroup updates-5.0-to-x.x Locale updates from 5.0 to x.x + * @{ + */ + +function locale_update_2001() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {languages} ( + language varchar(12) NOT NULL default '', + name varchar(64) NOT NULL default '', + native varchar(64) NOT NULL default '', + direction int NOT NULL default '0', + enabled int NOT NULL default '0', + plurals int NOT NULL default '0', + formula varchar(128) NOT NULL default '', + domain varchar(128) NOT NULL default '', + prefix varchar(128) NOT NULL default '', + weight int NOT NULL default '0', + PRIMARY KEY (language) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + break; + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {languages} ( + language varchar(12) NOT NULL default '', + name varchar(64) NOT NULL default '', + native varchar(64) NOT NULL default '', + direction int NOT NULL default '0', + enabled int NOT NULL default '0', + plurals int NOT NULL default '0', + formula varchar(128) NOT NULL default '', + domain varchar(128) NOT NULL default '', + prefix varchar(128) NOT NULL default '', + weight int NOT NULL default '0', + PRIMARY KEY (language) + )"); + break; + } + + // Save the languages + $ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, '', 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}"); + + // Save the language count in the variable table + $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1')); + variable_set('language_count', $count); + + // Save the default language in the variable table + $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE isdefault = 1')); + variable_set('language_default', (object) array('language' => $default->locale, 'name' => $default->name, 'native' => '', 'direction' => 0, 'enabled' => 1, 'plurals' => $default->plurals, 'formula' => $default->formula, 'domain' => '', 'prefix' => $default->locale, 'weight' => 0)); + + $ret[] = update_sql("DROP TABLE {locales_meta}"); + return $ret; +} + +/** + * @} End of "defgroup updates-5.0-to-x.x" + * The next series of updates should start at 3000. + */ + +/** * Implementation of hook_uninstall(). */ function locale_uninstall() { - db_query('DROP TABLE {locales_meta}'); + db_query('DROP TABLE {languages}'); db_query('DROP TABLE {locales_source}'); db_query('DROP TABLE {locales_target}'); } diff -urNp drupal6/modules/locale/locale.module drupal6lang/modules/locale/locale.module --- drupal6/modules/locale/locale.module 2007-02-27 07:29:22.000000000 -0500 +++ drupal6lang/modules/locale/locale.module 2007-03-25 18:39:01.046875000 -0400 @@ -25,6 +25,7 @@ function locale_help($section) { $output .= '

'. t('For more information please read the configuration and customization handbook Locale page.', array('@locale' => 'http://drupal.org/handbook/modules/locale/')) .'

'; return $output; case 'admin/build/locale': + case 'admin/build/locale/language': case 'admin/build/locale/language/overview': return t("

Drupal provides support for the translation of its interface text into different languages. This page provides an overview of the installed languages. You can add a language on the add language page, or directly by importing a translation. If multiple languages are enabled, registered users will be able to set their preferred language. The site default will be used for anonymous visitors and for users without their own settings.

Drupal interface translations may be added or extended by several courses: by importing an existing translation, by translating everything from scratch, or by a combination of these approaches.

", array("@search" => url("admin/build/locale/string/search"), "@import" => url("admin/build/locale/language/import"), "@add-language" => url("admin/build/locale/language/add"))); case 'admin/build/locale/language/add': @@ -35,6 +36,8 @@ function locale_help($section) { return '

'. t("This page allows you to export Drupal strings. The first option is to export a translation so it can be shared. The second option generates a translation template, which contains all Drupal strings, but without their translations. You can use this template to start a new translation using various software packages designed for this task.") .'

'; case 'admin/build/locale/string/search': return '

'. t("It is often convenient to get the strings from your setup on the export page, and use a desktop Gettext translation editor to edit the translations. On this page you can search in the translated and untranslated strings, and the default English texts provided by Drupal.", array("@export" => url("admin/build/locale/language/export"))) .'

'; + case 'admin/build/locale/language/configure': + return '

'. t('The language used to display a web page is determined with a negotiation algorithm. You can choose how this algorithm should work. By default, there is no negotiation and the default language is used. You can use path prefixes (like "de" and "it" for German and Italian content) with different fallback options, so you can have web addresses like /de/contact and /it/contact. Alternatively you can use custom domains like de.example.com and it.example.com. Customize path prefixes and set domain names on the language editing pages.', array('@languages' => url('admin/build/locale/language/overview'))) .'

'; } } @@ -44,8 +47,8 @@ function locale_help($section) { function locale_menu() { // Main admin menu item $items['admin/build/locale'] = array( - 'title' => t('Localization'), - 'description' => t('Configure site localization and user interface translation.'), + 'title' => t('Languages'), + 'description' => t('Configure languages and user interface translation.'), 'page callback' => 'locale_admin_manage', 'access arguments' => array('administer locales'), ); @@ -56,8 +59,8 @@ function locale_menu() { 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items['admin/build/locale/string/search'] = array( - 'title' => t('Manage strings'), + $items['admin/build/locale/string'] = array( + 'title' => t('Manage interface strings'), 'page callback' => 'locale_string_search', 'weight' => 10, 'type' => MENU_LOCAL_TASK, @@ -76,13 +79,32 @@ function locale_menu() { 'weight' => 5, 'type' => MENU_LOCAL_TASK, ); - $items['admin/build/locale/language/import'] = array( + $items['admin/build/locale/language/configure'] = array( + 'title' => t('Configure'), + 'page callback' => 'locale_admin_manage_configure', + 'weight' => 10, + 'type' => MENU_LOCAL_TASK, + ); + $items['admin/build/locale/language/edit/%'] = array( + 'title' => t('Edit language'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('locale_admin_manage_edit', 5), + 'type' => MENU_CALLBACK, + ); + + // Manage interface translations subtabs + $items['admin/build/locale/string/search'] = array( + 'title' => t('Search'), + 'weight' => 0, + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + $items['admin/build/locale/string/import'] = array( 'title' => t('Import'), 'page callback' => 'locale_admin_import', 'weight' => 10, 'type' => MENU_LOCAL_TASK, ); - $items['admin/build/locale/language/export'] = array( + $items['admin/build/locale/string/export'] = array( 'title' => t('Export'), 'page callback' => 'locale_admin_export', 'weight' => 20, @@ -124,12 +146,17 @@ function locale_perm() { * Implementation of hook_user(). */ function locale_user($type, $edit, &$user, $category = NULL) { - $languages = locale_supported_languages(); - if ($type == 'form' && $category == 'account' && count($languages['name']) > 1) { + if ($type == 'form' && $category == 'account' && variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_PATH) { + $languages = language_list('enabled'); + $languages = $languages['1']; if ($user->language == '') { - $user->language = key($languages['name']); + $default = language_default(); + $user->language = $default->language; + } + $names = array(); + foreach($languages as $langcode => $language) { + $names[$langcode] = t($language->name) .' ('. $language->native .')'; } - $languages['name'] = array_map('check_plain', array_map('t', $languages['name'])); $form['locale'] = array('#type' => 'fieldset', '#title' => t('Interface language settings'), '#weight' => 1, @@ -137,13 +164,31 @@ function locale_user($type, $edit, &$use $form['locale']['language'] = array('#type' => 'radios', '#title' => t('Language'), '#default_value' => $user->language, - '#options' => $languages['name'], + '#options' => $names, '#description' => t('Selecting a different locale will change the interface language of the site.'), ); return $form; } } +/** + * Implementation of hook_form_alter(). Adds language fields to forms. + */ +function locale_form_alter($form_id, &$form) { + switch ($form_id) { + case 'path_admin_edit': + $form['language'] = array( + '#type' => 'radios', + '#title' => t('Language'), + '#options' => array('' => t('All languages')) + locale_language_list('name'), + '#default_value' => $form['#alias'] ? $form['#alias']['language'] : '', + '#weight' => -10 + ); + break; + } +} + + // --------------------------------------------------------------------------------- // Locale core functionality (needed on all page loads) @@ -153,16 +198,14 @@ function locale_user($type, $edit, &$use * This function is called from t() to translate a string if needed. */ function locale($string) { - global $locale; + global $language; static $locale_t; // Store database cached translations in a static var. if (!isset($locale_t)) { - $cache = cache_get("locale:$locale", 'cache'); - - if (!$cache) { + if (!($cache = cache_get('locale:'. $language->language, 'cache'))) { locale_refresh_cache(); - $cache = cache_get("locale:$locale", 'cache'); + $cache = cache_get('locale:'. $language->language, 'cache'); } $locale_t = unserialize($cache->data); } @@ -175,7 +218,7 @@ function locale($string) { // We do not have this translation cached, so get it from the DB. else { - $result = db_query("SELECT s.lid, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = '%s' AND t.locale = '%s'", $string, $locale); + $result = db_query("SELECT s.lid, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = '%s' AND t.language = '%s'", $string, $language->language); // Translation found if ($trans = db_fetch_object($result)) { if (!empty($trans->translation)) { @@ -189,20 +232,20 @@ function locale($string) { $result = db_query("SELECT lid, source FROM {locales_source} WHERE source = '%s'", $string); // We have no such translation if ($obj = db_fetch_object($result)) { - if ($locale) { - db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '')", $obj->lid, $locale); + if ($language) { + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $obj->lid, $language->language); } } // We have no such source string else { db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", request_uri(), $string); - if ($locale) { + if ($language) { $lid = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $string)); - db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '')", $lid->lid, $locale); + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $lid->lid, $language->language); } } // Clear locale cache in DB - cache_clear_all("locale:$locale", 'cache'); + cache_clear_all('locale:' . $language->language, 'cache'); } } @@ -215,61 +258,31 @@ function locale($string) { * We only store short strings to improve performance and consume less memory. */ function locale_refresh_cache() { - $languages = locale_supported_languages(); + $languages = language_list('enabled'); + $languages = $languages['1']; - foreach (array_keys($languages['name']) as $locale) { - $result = db_query("SELECT s.source, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.locale = '%s' AND LENGTH(s.source) < 75", $locale); + foreach ($languages as $language) { + $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.language = '%s' AND LENGTH(s.source) < 75", $language->language); $t = array(); while ($data = db_fetch_object($result)) { $t[$data->source] = (empty($data->translation) ? TRUE : $data->translation); } - cache_set("locale:$locale", 'cache', serialize($t)); + cache_set('locale:' . $language->language, 'cache', serialize($t)); } } /** - * Returns list of languages supported on this site. - * - * @param $reset Refresh cached language list. - * @param $getall Return all languages (even disabled ones) - */ -function locale_supported_languages($reset = FALSE, $getall = FALSE) { - static $enabled = NULL; - static $all = NULL; - - if ($reset) { - unset($enabled); unset($all); - } - - if (!isset($enabled)) { - $enabled = $all = array(); - $all['name'] = $all['formula'] = $enabled['name'] = $enabled['formula'] = array(); - $result = db_query('SELECT locale, name, formula, enabled FROM {locales_meta} ORDER BY isdefault DESC, enabled DESC, name ASC'); - while ($row = db_fetch_object($result)) { - $all['name'][$row->locale] = $row->name; - $all['formula'][$row->locale] = $row->formula; - if ($row->enabled) { - $enabled['name'][$row->locale] = $row->name; - $enabled['formula'][$row->locale] = $row->formula; - } - } - } - return $getall ? $all : $enabled; -} - -/** * Returns plural form index for a specific number. * * The index is computed from the formula of this language. */ function locale_get_plural($count) { - global $locale; + global $language; static $locale_formula, $plurals = array(); if (!isset($plurals[$count])) { if (!isset($locale_formula)) { - $languages = locale_supported_languages(); - $locale_formula = $languages['formula'][$locale]; + $locale_formula = $language->formula; } if ($locale_formula) { $n = $count; @@ -284,6 +297,34 @@ function locale_get_plural($count) { return $plurals[$count]; } + +/** + * Returns a language name + */ +function locale_language_name($lang) { + static $list = NULL; + if (!isset($list)) { + $list = locale_language_list(); + } + return ($lang && isset($list[$lang])) ? $list[$lang] : t('All'); +} + +/** + * Returns array of language names + * + * @param $field + * 'name' => names in current language, localized + * 'native' => native names + */ +function locale_language_list($field = 'name') { + $languages = language_list('enabled'); + $list = array(); + foreach($languages[1] as $language) { + $list[$language->language] = ($field == 'name') ? t($language->name) : $language->$field; + } + return $list; +} + // --------------------------------------------------------------------------------- // Language management functionality (administration only) @@ -308,14 +349,15 @@ function locale_admin_manage_delete_form } // For other locales, warn user that data loss is ahead. - $languages = locale_supported_languages(FALSE, TRUE); + $languages = language_list(); - if (!isset($languages['name'][$langcode])) { + if (!isset($languages[$langcode])) { drupal_not_found(); } else { $form['langcode'] = array('#type' => 'value', '#value' => $langcode); - return confirm_form($form, t('Are you sure you want to delete the language %name?', array('%name' => t($languages['name'][$langcode]))), 'admin/build/locale/language/overview', t('Deleting a language will remove all data associated with it. This action cannot be undone.'), t('Delete'), t('Cancel')); + $form['#submit']['locale_admin_manage_delete_form_submit'] = array(); + return confirm_form($form, t('Are you sure you want to delete the language %name?', array('%name' => t($languages[$langcode]->name))), 'admin/build/locale/language/overview', t('Deleting a language will remove all data associated with it. This action cannot be undone.'), t('Delete'), t('Cancel')); } } @@ -323,11 +365,11 @@ function locale_admin_manage_delete_form * Process language deletion submissions. */ function locale_admin_manage_delete_form_submit($form_id, $form_values) { - $languages = locale_supported_languages(FALSE, TRUE); - if (isset($languages['name'][$form_values['langcode']])) { - db_query("DELETE FROM {locales_meta} WHERE locale = '%s'", $form_values['langcode']); - db_query("DELETE FROM {locales_target} WHERE locale = '%s'", $form_values['langcode']); - $message = t('The language %locale has been removed.', array('%locale' => t($languages['name'][$form_values['langcode']]))); + $languages = language_list(); + if (isset($languages[$form_values['langcode']])) { + db_query("DELETE FROM {languages} WHERE language = '%s'", $form_values['langcode']); + db_query("DELETE FROM {locales_target} WHERE language = '%s'", $form_values['langcode']); + $message = t('The language %locale has been removed.', array('%locale' => t($languages[$form_values['langcode']]->name))); drupal_set_message($message); watchdog('locale', $message); } @@ -346,6 +388,16 @@ function locale_admin_manage_add() { return _locale_admin_manage_add_screen(); } +function locale_admin_manage_edit($langcode) { + include_once './includes/locale.inc'; + return _locale_admin_manage_edit_screen($langcode); +} + +function locale_admin_manage_configure() { + include_once './includes/locale.inc'; + return drupal_get_form("locale_configure_language_form"); +} + // --------------------------------------------------------------------------------- // Gettext Portable Object import functionality (administration only) diff -urNp drupal6/modules/node/node.module drupal6lang/modules/node/node.module --- drupal6/modules/node/node.module 2007-03-17 14:30:14.000000000 -0400 +++ drupal6lang/modules/node/node.module 2007-03-25 14:29:07.812500000 -0400 @@ -1751,7 +1751,7 @@ function node_block($op = 'list', $delta * The link should be an absolute URL. */ function node_feed($nodes = 0, $channel = array()) { - global $base_url, $locale; + global $base_url, $language; if (!$nodes) { $nodes = db_query_range(db_rewrite_sql('SELECT n.nid, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.created DESC'), 0, variable_get('feed_default_items', 10)); @@ -1813,7 +1813,7 @@ function node_feed($nodes = 0, $channel 'title' => variable_get('site_name', 'Drupal') .' - '. variable_get('site_slogan', ''), 'link' => $base_url, 'description' => variable_get('site_mission', ''), - 'language' => $locale + 'language' => $language->language ); $channel = array_merge($channel_defaults, $channel); diff -urNp drupal6/modules/path/path.module drupal6lang/modules/path/path.module --- drupal6/modules/path/path.module 2007-03-17 14:30:14.000000000 -0400 +++ drupal6lang/modules/path/path.module 2007-03-25 14:29:12.156250000 -0400 @@ -26,6 +26,7 @@ function path_help($section) { $output .= '

'. t('For more information please read the configuration and customization handbook Path page.', array('@path' => 'http://drupal.org/handbook/modules/path/')) .'

'; return $output; case 'admin/build/path': + case 'admin/build/path/list': return '

'. t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'. Each system path can have multiple aliases.") .'

'; case 'admin/build/path/add': return '

'. t('Enter the path you wish to create the alias for, followed by the name of the new alias.') .'

'; @@ -105,7 +106,6 @@ function path_admin_delete_confirm($pid) $_GET['destination'] ? $_GET['destination'] : 'admin/build/path', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } - return $output; } @@ -127,49 +127,51 @@ function path_admin_delete($pid = 0) { drupal_set_message(t('The alias has been deleted.')); } - - /** * Set an aliased path for a given Drupal path, preventing duplicates. */ -function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) { +function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') { if ($path && !$alias) { - db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path); + // Delete based on path + db_query("DELETE FROM {url_alias} WHERE src = '%s' AND language = '%s'", $path, $language); db_query("UPDATE {menu} SET link_path = path WHERE path = '%s'", $path); drupal_clear_path_cache(); } else if (!$path && $alias) { - db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias); + // Delete based on alias + db_query("DELETE FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $alias, $language); db_query("UPDATE {menu} SET link_path = path WHERE link_path = '%s'", $alias); drupal_clear_path_cache(); } else if ($path && $alias) { $path = urldecode($path); - $path_count = db_result(db_query("SELECT COUNT(src) FROM {url_alias} WHERE src = '%s'", $path)); + $path_count = db_result(db_query("SELECT COUNT(src) FROM {url_alias} WHERE src = '%s' AND language = '%s'", $path, $language)); $alias = urldecode($alias); // Alias count can only be 0 or 1. - $alias_count = db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s'", $alias)); + $alias_count = db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $alias, $language)); if ($alias_count == 0) { if ($pid) { - db_query("UPDATE {url_alias} SET dst = '%s', src = '%s' WHERE pid = %d", $alias, $path, $pid); + // Existing path changed data + db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE pid = %d", $path, $alias, $language, $pid); } else { - db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias); + // No such alias yet in this language + db_query("INSERT INTO {url_alias} (src, dst, language) VALUES ('%s', '%s', '%s')", $path, $alias, $language); } } // The alias exists. else { // This path has no alias yet, so we redirect the alias here. if ($path_count == 0) { - db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s'", $path, $alias); + db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s' AND language = '%s'", $path, $alias, $language); } else { // This will delete the path that alias was originally pointing to. - path_set_alias(NULL, $alias); + path_set_alias(NULL, $alias, NULL, $language); // This will remove the current aliases of the path. - path_set_alias($path); - path_set_alias($path, $alias); + path_set_alias($path, NULL, NULL, $language); + path_set_alias($path, $alias, NULL, $language); } } if ($alias_count == 0 || $path_count == 0) { @@ -186,6 +188,7 @@ function path_form($edit = '') { $form['#submit']['path_form_submit'] = array(); $form['#validate']['path_form_validate'] = array(); $form['#theme'] = 'path_form'; + $form['#alias'] = $edit; $form['src'] = array( '#type' => 'textfield', @@ -198,13 +201,13 @@ function path_form($edit = '') { ); $form['dst'] = array( '#type' => 'textfield', + '#title' => t('Path alias'), '#default_value' => $edit['dst'], '#maxlength' => 64, '#size' => 45, '#description' => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') ); - if ($edit['pid']) { $form['pid'] = array('#type' => 'hidden', '#value' => $edit['pid']); $form['submit'] = array('#type' => 'submit', '#value' => t('Update alias')); @@ -227,7 +230,8 @@ function path_nodeapi(&$node, $op, $arg) switch ($op) { case 'validate': $node->path = trim($node->path); - if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s'", $node->path, "node/$node->nid"))) { + $language = isset($node->language) ? $node->language : ''; + if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) { form_set_error('path', t('The path is already in use.')); } break; @@ -307,23 +311,37 @@ function path_perm() { * Return a listing of all defined URL aliases. */ function path_overview() { + // Enable language column if locale is enabled or if we have any alias with language + $count = db_result(db_query("SELECT COUNT(*) FROM {url_alias} WHERE language != ''")); + $multilanguage = (module_exists('locale') || $count); + $sql = 'SELECT * FROM {url_alias}'; $header = array( array('data' => t('Alias'), 'field' => 'dst', 'sort' => 'asc'), array('data' => t('System'), 'field' => 'src'), array('data' => t('Operations'), 'colspan' => '2') ); + if ($multilanguage) { + $header[3] = $header[2]; + $header[2] = array('data' => t('Language'), 'field' => 'language'); + } $sql .= tablesort_sql($header); $result = pager_query($sql, 50); $rows = array(); $destination = drupal_get_destination(); while ($data = db_fetch_object($result)) { - $rows[] = array(check_plain($data->dst), check_plain($data->src), l(t('edit'), "admin/build/path/edit/$data->pid", array('query' => $destination)), l(t('delete'), "admin/build/path/delete/$data->pid", array('query' => $destination))); + $row = array(check_plain($data->dst), check_plain($data->src), l(t('edit'), "admin/build/path/edit/$data->pid", array('query' => $destination)), l(t('delete'), "admin/build/path/delete/$data->pid", array('query' => $destination))); + if ($multilanguage) { + $row[4] = $row[3]; + $row[3] = $row[2]; + $row[2] = module_invoke('locale', 'language_name', $data->language); + } + $rows[] = $row; } if (empty($rows)) { - $rows[] = array(array('data' => t('No URL aliases available.'), 'colspan' => '4')); + $rows[] = array(array('data' => t('No URL aliases available.'), 'colspan' => ($multilanguage ? 5 : 4))); } $output = theme('table', $header, $rows); @@ -345,9 +363,11 @@ function path_form_validate($form_id, $f $src = $form_values['src']; $dst = $form_values['dst']; $pid = $form_values['pid']; + // Language is only set if locale module is enabled, otherwise save for all languages. + $language = isset($form_values['language']) ? $form_values['language'] : ''; - if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid != %d AND dst = '%s'", $pid, $dst))) { - form_set_error('dst', t('The alias %alias is already in use.', array('%alias' => $dst))); + if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid != %d AND dst = '%s' AND language = '%s'", $pid, $dst, $language))) { + form_set_error('dst', t('The alias %alias is already in use in this language.', array('%alias' => $dst))); } } @@ -355,7 +375,8 @@ function path_form_validate($form_id, $f * Save a new URL alias to the database. */ function path_form_submit($form_id, $form_values) { - path_set_alias($form_values['src'], $form_values['dst'], $form_values['pid']); + // Language is only set if locale module is enabled + path_set_alias($form_values['src'], $form_values['dst'], $form_values['pid'], isset($form_values['language']) ? $form_values['language'] : ''); drupal_set_message(t('The alias has been saved.')); return 'admin/build/path'; Files drupal6/modules/system/.system.module.swp and drupal6lang/modules/system/.system.module.swp differ diff -urNp drupal6/modules/system/system.install drupal6lang/modules/system/system.install --- drupal6/modules/system/system.install 2007-03-18 21:13:28.000000000 -0400 +++ drupal6lang/modules/system/system.install 2007-03-25 14:29:17.562500000 -0400 @@ -440,8 +440,9 @@ function system_install() { pid int unsigned NOT NULL auto_increment, src varchar(128) NOT NULL default '', dst varchar(128) NOT NULL default '', + language varchar(12) NOT NULL default '', PRIMARY KEY (pid), - UNIQUE KEY dst (dst), + UNIQUE KEY dst_language (dst, language), KEY src (src) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); @@ -585,7 +586,8 @@ function system_install() { db_query("CREATE TABLE {variable} ( name varchar(128) NOT NULL default '', value longtext NOT NULL, - PRIMARY KEY (name) + language varchar(12) NOT NULL default '', + PRIMARY KEY (name, language) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); db_query("CREATE TABLE {vocabulary} ( @@ -926,10 +928,11 @@ function system_install() { pid serial CHECK (pid >= 0), src varchar(128) NOT NULL default '', dst varchar(128) NOT NULL default '', - PRIMARY KEY (pid), - UNIQUE (dst) + language varchar(12) NOT NULL default '', + PRIMARY KEY (pid) )"); db_query("CREATE INDEX {url_alias}_src_idx ON {url_alias} (src)"); + db_query("CREATE UNIQUE INDEX {url_alias}_dst_language_idx ON {url_alias} (dst, language)"); db_query("CREATE TABLE {permission} ( rid int_unsigned NOT NULL default '0', @@ -1072,7 +1075,8 @@ function system_install() { db_query("CREATE TABLE {variable} ( name varchar(128) NOT NULL default '', value text NOT NULL, - PRIMARY KEY (name) + language varchar(12) NOT NULL default '', + PRIMARY KEY (name, language) )"); db_query("CREATE TABLE {vocabulary} ( @@ -3689,6 +3693,27 @@ function system_update_2004() { } /** + * Add language to url_alias table and modify indexes. + */ +function system_update_2005() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_add_column($ret, 'url_alias', 'language', 'varchar(12)', array('default' => "''", 'not null' => TRUE)); + $ret[] = update_sql('DROP INDEX {url_alias}_dst_idx'); + $ret[] = update_sql('CREATE UNIQUE INDEX {url_alias}_dst_language_idx ON {url_alias}(dst, language)'); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {url_alias} ADD language varchar(12) NOT NULL default ''"); + $ret[] = update_sql("ALTER TABLE {url_alias} DROP INDEX dst"); + $ret[] = update_sql("ALTER TABLE {url_alias} ADD UNIQUE dst_language (dst, language)"); + break; + } + return $ret; +} + +/** * @} End of "defgroup updates-5.0-to-x.x" * The next series of updates should start at 3000. */ diff -urNp drupal6/modules/system/system.install.orig drupal6lang/modules/system/system.install.orig --- drupal6/modules/system/system.install.orig 1969-12-31 19:00:00.000000000 -0500 +++ drupal6lang/modules/system/system.install.orig 2007-03-18 21:13:28.000000000 -0400 @@ -0,0 +1,3694 @@ + $t('Drupal'), + 'value' => VERSION, + 'severity' => REQUIREMENT_INFO, + 'weight' => -10, + ); + } + + // Test web server + $software = $_SERVER['SERVER_SOFTWARE']; + $requirements['webserver'] = array( + 'title' => $t('Web server'), + 'value' => $software, + ); + // Use server info string, if present. + if ($software && preg_match('![0-9]!', $software)) { + list($server, $version) = split('[ /]', $software); + switch ($server) { + case 'Apache': + if (version_compare($version, DRUPAL_MINIMUM_APACHE) < 0) { + $requirements['webserver']['description'] = $t('Your Apache server is too old. Drupal requires at least Apache %version.', array('%version' => DRUPAL_MINIMUM_APACHE)); + $requirements['webserver']['severity'] = REQUIREMENT_ERROR; + } + break; + + default: + $requirements['webserver']['description'] = $t('The web server you\'re using has not been tested with Drupal and might not work properly.'); + $requirements['webserver']['severity'] = REQUIREMENT_WARNING; + break; + } + } + else { + $requirements['webserver']['value'] = $software ? $software : $t('Unknown'); + $requirements['webserver']['description'] = $t('Unable to determine your web server type and version. Drupal might not work properly.'); + $requirements['webserver']['severity'] = REQUIREMENT_WARNING; + } + + // Test PHP version + $requirements['php'] = array( + 'title' => $t('PHP'), + 'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/logs/status/php') : phpversion(), + ); + if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) { + $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP)); + $requirements['php']['severity'] = REQUIREMENT_ERROR; + } + + // Test DB version + global $db_type; + if (function_exists('db_status_report')) { + $requirements += db_status_report($phase); + } + + // Test settings.php file writability + if ($phase == 'runtime') { + if (!drupal_verify_install_file(conf_path() .'/settings.php', FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE)) { + $requirements['settings.php'] = array( + 'value' => $t('Not protected'), + 'severity' => REQUIREMENT_ERROR, + 'description' => $t('The file %file is not protected from modifications and poses a security risk. You must change the file\'s permissions to be non-writable.', array('%file' => conf_path() .'/settings.php')), + ); + } + else { + $requirements['settings.php'] = array( + 'value' => $t('Protected'), + ); + } + $requirements['settings.php']['title'] = $t('Configuration file'); + } + + // Report cron status + if ($phase == 'runtime') { + $cron_last = variable_get('cron_last', NULL); + + if (is_numeric($cron_last)) { + $requirements['cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(time() - $cron_last))); + } + else { + $requirements['cron'] = array( + 'description' => $t('Cron has not run. It appears cron jobs have not been setup on your system. Please check the help pages for configuring cron jobs.', array('@url' => 'http://drupal.org/cron')), + 'severity' => REQUIREMENT_ERROR, + 'value' => $t('Never run'), + ); + } + $requirements['cron'] += array('description' => ''); + + $requirements['cron']['description'] .= ' '. t('You can run cron manually.', array('@cron' => url('admin/logs/status/run-cron'))); + + $requirements['cron']['title'] = $t('Cron maintenance tasks'); + } + + // Test files directory + if ($phase == 'runtime') { + $directory = file_directory_path(); + $is_writable = is_writable($directory); + $is_directory = is_dir($directory); + if (!$is_writable || !$is_directory) { + if (!$is_directory) { + $error = $t('The directory %directory does not exist.', array('%directory' => $directory)); + } + else { + $error = $t('The directory %directory is not writable.', array('%directory' => $directory)); + } + $requirements['file system'] = array( + 'value' => $t('Not writable'), + 'severity' => REQUIREMENT_ERROR, + 'description' => $error .' '. $t('You may need to set the correct directory at the file system settings page or change the current directory\'s permissions so that it is writable.', array('@admin-file-system' => url('admin/settings/file-system'))), + ); + } + else { + if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) { + $requirements['file system'] = array( + 'value' => $t('Writable (public download method)'), + ); + } + else { + $requirements['file system'] = array( + 'value' => $t('Writable (private download method)'), + ); + } + } + $requirements['file system']['title'] = $t('File system'); + } + + // See if updates are available in update.php. + if ($phase == 'runtime') { + $requirements['update'] = array( + 'title' => $t('Database schema'), + 'severity' => REQUIREMENT_OK, + 'value' => $t('Up to date'), + ); + + // Check installed modules. + foreach (module_list() as $module) { + $updates = drupal_get_schema_versions($module); + if ($updates !== FALSE) { + $default = drupal_get_installed_schema_version($module); + if (max($updates) > $default) { + $requirements['update']['severity'] = REQUIREMENT_ERROR; + $requirements['update']['value'] = $t('Out of date'); + $requirements['update']['description'] = $t('Some modules have database schema updates to install. You should run the database update script immediately.', array('@update' => base_path() .'update.php')); + break; + } + } + } + } + + // Test Unicode library + include_once './includes/unicode.inc'; + $requirements = array_merge($requirements, unicode_requirements()); + + return $requirements; +} + + +/** + * Implementation of hook_install(). + */ +function system_install() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + db_query("CREATE TABLE {access} ( + aid int NOT NULL auto_increment, + mask varchar(255) NOT NULL default '', + type varchar(255) NOT NULL default '', + status tinyint NOT NULL default '0', + PRIMARY KEY (aid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {authmap} ( + aid int unsigned NOT NULL auto_increment, + uid int NOT NULL default '0', + authname varchar(128) NOT NULL default '', + module varchar(128) NOT NULL default '', + PRIMARY KEY (aid), + UNIQUE KEY authname (authname) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {blocks} ( + module varchar(64) DEFAULT '' NOT NULL, + delta varchar(32) NOT NULL default '0', + theme varchar(255) NOT NULL default '', + status tinyint DEFAULT '0' NOT NULL, + weight tinyint DEFAULT '0' NOT NULL, + region varchar(64) DEFAULT 'left' NOT NULL, + custom tinyint DEFAULT '0' NOT NULL, + throttle tinyint DEFAULT '0' NOT NULL, + visibility tinyint DEFAULT '0' NOT NULL, + pages text NOT NULL, + title varchar(64) DEFAULT '' NOT NULL + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {boxes} ( + bid int NOT NULL, + body longtext, + info varchar(128) NOT NULL default '', + format int NOT NULL default '0', + PRIMARY KEY (bid), + UNIQUE KEY info (info) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {cache} ( + cid varchar(255) NOT NULL default '', + data longblob, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + PRIMARY KEY (cid), + INDEX expire (expire) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + db_query("CREATE TABLE {cache_filter} ( + cid varchar(255) NOT NULL default '', + data longblob, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + PRIMARY KEY (cid), + INDEX expire (expire) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + db_query("CREATE TABLE {cache_page} ( + cid varchar(255) BINARY NOT NULL default '', + data longblob, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + PRIMARY KEY (cid), + INDEX expire (expire) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {comments} ( + cid int NOT NULL auto_increment, + pid int NOT NULL default '0', + nid int NOT NULL default '0', + uid int NOT NULL default '0', + subject varchar(64) NOT NULL default '', + comment longtext NOT NULL, + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0', + score mediumint NOT NULL default '0', + status tinyint unsigned NOT NULL default '0', + format int NOT NULL default '0', + thread varchar(255) NOT NULL, + users longtext, + name varchar(60) default NULL, + mail varchar(64) default NULL, + homepage varchar(255) default NULL, + PRIMARY KEY (cid), + KEY lid (nid), + KEY status (status) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {node_comment_statistics} ( + nid int unsigned NOT NULL auto_increment, + last_comment_timestamp int NOT NULL default '0', + last_comment_name varchar(60) default NULL, + last_comment_uid int NOT NULL default '0', + comment_count int unsigned NOT NULL default '0', + PRIMARY KEY (nid), + KEY node_comment_timestamp (last_comment_timestamp) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {files} ( + fid int unsigned NOT NULL default 0, + nid int unsigned NOT NULL default 0, + filename varchar(255) NOT NULL default '', + filepath varchar(255) NOT NULL default '', + filemime varchar(255) NOT NULL default '', + filesize int unsigned NOT NULL default 0, + PRIMARY KEY (fid), + KEY nid (nid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {file_revisions} ( + fid int unsigned NOT NULL default 0, + vid int unsigned NOT NULL default 0, + description varchar(255) NOT NULL default '', + list tinyint unsigned NOT NULL default 0, + PRIMARY KEY (fid, vid), + KEY (vid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {filter_formats} ( + format int NOT NULL auto_increment, + name varchar(255) NOT NULL default '', + roles varchar(255) NOT NULL default '', + cache tinyint NOT NULL default '0', + PRIMARY KEY (format), + UNIQUE KEY (name) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {filters} ( + format int NOT NULL default '0', + module varchar(64) NOT NULL default '', + delta tinyint DEFAULT '0' NOT NULL, + weight tinyint DEFAULT '0' NOT NULL, + INDEX (weight) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {flood} ( + event varchar(64) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0' + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {history} ( + uid int NOT NULL default '0', + nid int NOT NULL default '0', + timestamp int NOT NULL default '0', + PRIMARY KEY (uid,nid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {menu} ( + mid int NOT NULL default 0, + pid int NOT NULL default 0, + path varchar(255) NOT NULL default '', + load_functions varchar(255) NOT NULL default '', + to_arg_functions varchar(255) NOT NULL default '', + access_callback varchar(255) NOT NULL default '', + access_arguments text, + page_callback varchar(255) NOT NULL default '', + page_arguments text, + fit int NOT NULL default 0, + number_parts int NOT NULL default 0, + mleft int NOT NULL default 0, + mright int NOT NULL default 0, + visible int NOT NULL default 0, + parents varchar(255) NOT NULL default '', + depth int NOT NULL default 0, + has_children int NOT NULL default 0, + tab int NOT NULL default 0, + title varchar(255) NOT NULL default '', + parent varchar(255) NOT NULL default '', + type int NOT NULL default 0, + block_callback varchar(255) NOT NULL default '', + description varchar(255) NOT NULL default '', + position varchar(255) NOT NULL default '', + link_path varchar(255) NOT NULL default '', + attributes varchar(255) NOT NULL default '', + query varchar(255) NOT NULL default '', + fragment varchar(255) NOT NULL default '', + absolute INT NOT NULL default 0, + html INT NOT NULL default 0, + PRIMARY KEY (path), + KEY fit (fit), + KEY visible (visible), + KEY pid (pid), + KEY parent (parent) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {node} ( + nid int unsigned NOT NULL auto_increment, + vid int unsigned NOT NULL default '0', + type varchar(32) NOT NULL default '', + title varchar(128) NOT NULL default '', + uid int NOT NULL default '0', + status int NOT NULL default '1', + created int NOT NULL default '0', + changed int NOT NULL default '0', + comment int NOT NULL default '0', + promote int NOT NULL default '0', + moderate int NOT NULL default '0', + sticky int NOT NULL default '0', + PRIMARY KEY (nid, vid), + UNIQUE KEY vid (vid), + KEY node_type (type(4)), + KEY node_title_type (title, type(4)), + KEY status (status), + KEY uid (uid), + KEY node_moderate (moderate), + KEY node_promote_status (promote, status), + KEY node_created (created), + KEY node_changed (changed), + KEY node_status_type (status, type, nid), + KEY nid (nid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {node_access} ( + nid int unsigned NOT NULL default '0', + gid int unsigned NOT NULL default '0', + realm varchar(255) NOT NULL default '', + grant_view tinyint unsigned NOT NULL default '0', + grant_update tinyint unsigned NOT NULL default '0', + grant_delete tinyint unsigned NOT NULL default '0', + PRIMARY KEY (nid,gid,realm) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {node_revisions} ( + nid int unsigned NOT NULL, + vid int unsigned NOT NULL, + uid int NOT NULL default '0', + title varchar(128) NOT NULL default '', + body longtext NOT NULL, + teaser longtext NOT NULL, + log longtext NOT NULL, + timestamp int NOT NULL default '0', + format int NOT NULL default '0', + PRIMARY KEY (vid), + KEY nid (nid), + KEY uid (uid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {node_type} ( + type varchar(32) NOT NULL, + name varchar(255) NOT NULL default '', + module varchar(255) NOT NULL, + description mediumtext NOT NULL, + help mediumtext NOT NULL, + has_title tinyint unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body tinyint unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count smallint unsigned NOT NULL, + custom tinyint NOT NULL DEFAULT '0', + modified tinyint NOT NULL DEFAULT '0', + locked tinyint NOT NULL DEFAULT '0', + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {url_alias} ( + pid int unsigned NOT NULL auto_increment, + src varchar(128) NOT NULL default '', + dst varchar(128) NOT NULL default '', + PRIMARY KEY (pid), + UNIQUE KEY dst (dst), + KEY src (src) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {permission} ( + rid int unsigned NOT NULL default '0', + perm longtext, + tid int unsigned NOT NULL default '0', + KEY rid (rid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {role} ( + rid int unsigned NOT NULL auto_increment, + name varchar(64) NOT NULL default '', + PRIMARY KEY (rid), + UNIQUE KEY name (name) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {blocks_roles} ( + module varchar(64) NOT NULL, + delta varchar(32) NOT NULL, + rid int unsigned NOT NULL, + PRIMARY KEY (module, delta, rid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {sessions} ( + uid int unsigned NOT NULL, + sid varchar(64) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0', + cache int NOT NULL default '0', + session longtext, + KEY uid (uid), + PRIMARY KEY (sid), + KEY timestamp (timestamp) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {sequences} ( + name varchar(255) NOT NULL default '', + id int unsigned NOT NULL default '0', + PRIMARY KEY (name) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {node_counter} ( + nid int NOT NULL default '0', + totalcount bigint unsigned NOT NULL default '0', + daycount mediumint unsigned NOT NULL default '0', + timestamp int unsigned NOT NULL default '0', + PRIMARY KEY (nid), + KEY totalcount (totalcount), + KEY daycount (daycount), + KEY timestamp (timestamp) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {system} ( + filename varchar(255) NOT NULL default '', + name varchar(255) NOT NULL default '', + type varchar(255) NOT NULL default '', + description varchar(255) NOT NULL default '', + status int NOT NULL default '0', + throttle tinyint DEFAULT '0' NOT NULL, + bootstrap int NOT NULL default '0', + schema_version smallint NOT NULL default -1, + weight int NOT NULL default '0', + PRIMARY KEY (filename), + KEY (weight) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {term_data} ( + tid int unsigned NOT NULL auto_increment, + vid int unsigned NOT NULL default '0', + name varchar(255) NOT NULL default '', + description longtext, + weight tinyint NOT NULL default '0', + PRIMARY KEY (tid), + KEY vid (vid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {term_hierarchy} ( + tid int unsigned NOT NULL default '0', + parent int unsigned NOT NULL default '0', + KEY tid (tid), + KEY parent (parent), + PRIMARY KEY (tid, parent) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {term_node} ( + nid int unsigned NOT NULL default '0', + vid int unsigned NOT NULL default '0', + tid int unsigned NOT NULL default '0', + KEY nid (nid), + KEY vid (vid), + KEY tid (tid), + PRIMARY KEY (vid,tid,nid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {term_relation} ( + tid1 int unsigned NOT NULL default '0', + tid2 int unsigned NOT NULL default '0', + KEY tid1 (tid1), + KEY tid2 (tid2) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {term_synonym} ( + tid int unsigned NOT NULL default '0', + name varchar(255) NOT NULL default '', + KEY tid (tid), + KEY name (name(3)) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {users} ( + uid int unsigned NOT NULL default '0', + name varchar(60) NOT NULL default '', + pass varchar(32) NOT NULL default '', + mail varchar(64) default '', + mode tinyint NOT NULL default '0', + sort tinyint default '0', + threshold tinyint default '0', + theme varchar(255) NOT NULL default '', + signature varchar(255) NOT NULL default '', + created int NOT NULL default '0', + access int NOT NULL default '0', + login int NOT NULL default '0', + status tinyint NOT NULL default '0', + timezone varchar(8) default NULL, + language varchar(12) NOT NULL default '', + picture varchar(255) NOT NULL DEFAULT '', + init varchar(64) default '', + data longtext, + PRIMARY KEY (uid), + UNIQUE KEY name (name), + KEY created (created), + KEY access (access) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {users_roles} ( + uid int unsigned NOT NULL default '0', + rid int unsigned NOT NULL default '0', + PRIMARY KEY (uid, rid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {variable} ( + name varchar(128) NOT NULL default '', + value longtext NOT NULL, + PRIMARY KEY (name) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {vocabulary} ( + vid int unsigned NOT NULL auto_increment, + name varchar(255) NOT NULL default '', + description longtext, + help varchar(255) NOT NULL default '', + relations tinyint unsigned NOT NULL default '0', + hierarchy tinyint unsigned NOT NULL default '0', + multiple tinyint unsigned NOT NULL default '0', + required tinyint unsigned NOT NULL default '0', + tags tinyint unsigned NOT NULL default '0', + module varchar(255) NOT NULL default '', + weight tinyint NOT NULL default '0', + PRIMARY KEY (vid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {vocabulary_node_types} ( + vid int unsigned NOT NULL DEFAULT '0', + type varchar(32) NOT NULL DEFAULT '', + PRIMARY KEY (vid, type) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + db_query("CREATE TABLE {watchdog} ( + wid int NOT NULL auto_increment, + uid int NOT NULL default '0', + type varchar(16) NOT NULL default '', + message longtext NOT NULL, + severity tinyint unsigned NOT NULL default '0', + link varchar(255) NOT NULL default '', + location text NOT NULL, + referer varchar(128) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0', + PRIMARY KEY (wid), + KEY (type) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + + break; + case 'pgsql': + /* create unsigned types */ + db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)"); + db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)"); + db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)"); + + /* create functions */ + db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS + \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\' + LANGUAGE \'sql\'' + ); + db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS + \'SELECT greatest($1, greatest($2, $3));\' + LANGUAGE \'sql\'' + ); + if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'"))) { + db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS + \'SELECT random();\' + LANGUAGE \'sql\'' + ); + } + + if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'"))) { + db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS + \'SELECT $1 || $2;\' + LANGUAGE \'sql\'' + ); + } + db_query('CREATE OR REPLACE FUNCTION "if"(boolean, text, text) RETURNS text AS + \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\' + LANGUAGE \'sql\'' + ); + db_query('CREATE OR REPLACE FUNCTION "if"(boolean, integer, integer) RETURNS integer AS + \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\' + LANGUAGE \'sql\'' + ); + + /* create tables */ + db_query("CREATE TABLE {access} ( + aid serial, + mask varchar(255) NOT NULL default '', + type varchar(255) NOT NULL default '', + status smallint NOT NULL default '0', + PRIMARY KEY (aid) + )"); + + db_query("CREATE TABLE {authmap} ( + aid serial CHECK (aid >= 0), + uid int NOT NULL default '0', + authname varchar(128) NOT NULL default '', + module varchar(128) NOT NULL default '', + PRIMARY KEY (aid), + UNIQUE (authname) + )"); + + db_query("CREATE TABLE {blocks} ( + module varchar(64) DEFAULT '' NOT NULL, + delta varchar(32) NOT NULL default '0', + theme varchar(255) NOT NULL default '', + status smallint DEFAULT '0' NOT NULL, + weight smallint DEFAULT '0' NOT NULL, + region varchar(64) DEFAULT 'left' NOT NULL, + custom smallint DEFAULT '0' NOT NULL, + throttle smallint DEFAULT '0' NOT NULL, + visibility smallint DEFAULT '0' NOT NULL, + pages text DEFAULT '' NOT NULL, + title varchar(64) DEFAULT '' NOT NULL + )"); + + db_query("CREATE TABLE {boxes} ( + bid serial, + body text, + info varchar(128) NOT NULL default '', + format smallint NOT NULL default '0', + PRIMARY KEY (bid), + UNIQUE (info) + )"); + + db_query("CREATE TABLE {cache} ( + cid varchar(255) NOT NULL default '', + data bytea, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + PRIMARY KEY (cid) + )"); + db_query("CREATE TABLE {cache_filter} ( + cid varchar(255) NOT NULL default '', + data bytea, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + PRIMARY KEY (cid) + )"); + db_query("CREATE TABLE {cache_page} ( + cid varchar(255) NOT NULL default '', + data bytea, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + PRIMARY KEY (cid) + )"); + db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)"); + db_query("CREATE INDEX {cache_filter}_expire_idx ON {cache_filter} (expire)"); + db_query("CREATE INDEX {cache_page}_expire_idx ON {cache_page} (expire)"); + + db_query("CREATE TABLE {comments} ( + cid serial, + pid int NOT NULL default '0', + nid int NOT NULL default '0', + uid int NOT NULL default '0', + subject varchar(64) NOT NULL default '', + comment text NOT NULL, + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0', + score int NOT NULL default '0', + status smallint_unsigned NOT NULL default '0', + format smallint NOT NULL default '0', + thread varchar(255) NOT NULL, + users text, + name varchar(60) default NULL, + mail varchar(64) default NULL, + homepage varchar(255) default NULL, + PRIMARY KEY (cid) + )"); + db_query("CREATE INDEX {comments}_nid_idx ON {comments} (nid)"); + db_query("CREATE INDEX {comments}_status_idx ON {comments} (status)"); + + db_query("CREATE TABLE {node_comment_statistics} ( + nid serial CHECK (nid >= 0), + last_comment_timestamp int NOT NULL default '0', + last_comment_name varchar(60) default NULL, + last_comment_uid int NOT NULL default '0', + comment_count int_unsigned NOT NULL default '0', + PRIMARY KEY (nid) + )"); + db_query("CREATE INDEX {node_comment_statistics}_node_comment_timestamp_idx ON {node_comment_statistics} (last_comment_timestamp)"); + + db_query("CREATE TABLE {files} ( + fid serial CHECK (fid >= 0), + nid int_unsigned NOT NULL default 0, + filename varchar(255) NOT NULL default '', + filepath varchar(255) NOT NULL default '', + filemime varchar(255) NOT NULL default '', + filesize int_unsigned NOT NULL default 0, + PRIMARY KEY (fid) + )"); + db_query("CREATE INDEX {files}_nid_idx ON {files} (nid)"); + + db_query("CREATE TABLE {file_revisions} ( + fid int_unsigned NOT NULL default 0, + vid int_unsigned NOT NULL default 0, + description varchar(255) NOT NULL default '', + list smallint_unsigned NOT NULL default 0, + PRIMARY KEY (fid, vid) + )"); + db_query("CREATE INDEX {file_revisions}_vid_idx ON {file_revisions} (vid)"); + + db_query("CREATE TABLE {filter_formats} ( + format serial, + name varchar(255) NOT NULL default '', + roles varchar(255) NOT NULL default '', + cache smallint NOT NULL default '0', + PRIMARY KEY (format), + UNIQUE (name) + )"); + + db_query("CREATE TABLE {filters} ( + format int NOT NULL default '0', + module varchar(64) NOT NULL default '', + delta smallint DEFAULT '0' NOT NULL, + weight smallint DEFAULT '0' NOT NULL + )"); + db_query("CREATE INDEX {filters}_weight_idx ON {filters} (weight)"); + + db_query("CREATE TABLE {flood} ( + event varchar(64) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0' + )"); + + db_query("CREATE TABLE {history} ( + uid int NOT NULL default '0', + nid int NOT NULL default '0', + timestamp int NOT NULL default '0', + PRIMARY KEY (uid,nid) + )"); + + db_query("CREATE TABLE {menu} ( + mid int NOT NULL default 0, + pid int NOT NULL default 0, + path varchar(255) NOT NULL default '', + load_functions varchar(255) NOT NULL default '', + to_arg_functions varchar(255) NOT NULL default '', + access_callback varchar(255) NOT NULL default '', + access_arguments text, + page_callback varchar(255) NOT NULL default '', + page_arguments text, + fit int NOT NULL default 0, + number_parts int NOT NULL default 0, + mleft int NOT NULL default 0, + mright int NOT NULL default 0, + visible int NOT NULL default 0, + parents varchar(255) NOT NULL default '', + depth int NOT NULL default 0, + has_children int NOT NULL default 0, + tab int NOT NULL default 0, + title varchar(255) NOT NULL default '', + parent varchar(255) NOT NULL default '', + type int NOT NULL default 0, + block_callback varchar(255) NOT NULL default '', + description varchar(255) NOT NULL default '', + position varchar(255) NOT NULL default '', + link_path varchar(255) NOT NULL default '', + attributes varchar(255) NOT NULL default '', + query varchar(255) NOT NULL default '', + fragment varchar(255) NOT NULL default '', + absolute INT NOT NULL default 0, + html INT NOT NULL default 0, + PRIMARY KEY (path) + )"); + + db_query("CREATE INDEX {menu}_fit_idx ON {menu} (fit)"); + db_query("CREATE INDEX {menu}_visible_idx ON {menu} (visible)"); + db_query("CREATE INDEX {menu}_parent_idx ON {menu} (parent)"); + db_query("CREATE INDEX {menu}_pid_idx ON {menu} (parent)"); + + db_query("CREATE TABLE {node} ( + nid serial CHECK (nid >= 0), + vid int_unsigned NOT NULL default '0', + type varchar(32) NOT NULL default '', + title varchar(128) NOT NULL default '', + uid int NOT NULL default '0', + status int NOT NULL default '1', + created int NOT NULL default '0', + changed int NOT NULL default '0', + comment int NOT NULL default '0', + promote int NOT NULL default '0', + moderate int NOT NULL default '0', + sticky int NOT NULL default '0', + PRIMARY KEY (nid, vid), + UNIQUE (vid) + )"); + db_query("CREATE INDEX {node}_node_type_idx ON {node} (substr (type, 1, 4))"); + db_query("CREATE INDEX {node}_node_title_type_idx ON {node} (title, substr(type, 1, 4))"); + db_query("CREATE INDEX {node}_status_idx ON {node} (status)"); + db_query("CREATE INDEX {node}_uid_idx ON {node} (uid)"); + db_query("CREATE INDEX {node}_node_moderate_idx ON {node} (moderate)"); + db_query("CREATE INDEX {node}_node_promote_status_idx ON {node} (promote, status)"); + db_query("CREATE INDEX {node}_node_created_idx ON {node} (created)"); + db_query("CREATE INDEX {node}_node_changed_idx ON {node} (changed)"); + db_query("CREATE INDEX {node}_node_status_type_idx ON {node} (status, type, nid)"); + db_query("CREATE INDEX {node}_nid_idx ON {node} (nid)"); + + db_query("CREATE TABLE {node_access} ( + nid int_unsigned NOT NULL default '0', + gid int_unsigned NOT NULL default '0', + realm varchar(255) NOT NULL default '', + grant_view smallint_unsigned NOT NULL default '0', + grant_update smallint_unsigned NOT NULL default '0', + grant_delete smallint_unsigned NOT NULL default '0', + PRIMARY KEY (nid,gid,realm) + )"); + + db_query("CREATE TABLE {node_revisions} ( + nid int_unsigned NOT NULL, + vid serial CHECK (vid >= 0), + uid int NOT NULL default '0', + title varchar(128) NOT NULL default '', + body text NOT NULL default '', + teaser text NOT NULL default '', + log text NOT NULL default '', + timestamp int NOT NULL default '0', + format int NOT NULL default '0', + PRIMARY KEY (vid) + )"); + db_query("CREATE INDEX {node_revisions}_nid_idx ON {node_revisions} (nid)"); + db_query("CREATE INDEX {node_revisions}_uid_idx ON {node_revisions} (uid)"); + + db_query("CREATE TABLE {node_type} ( + type varchar(32) NOT NULL, + name varchar(255) NOT NULL default '', + module varchar(255) NOT NULL, + description text NOT NULL, + help text NOT NULL, + has_title smallint_unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body smallint_unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count smallint_unsigned NOT NULL, + custom smallint NOT NULL DEFAULT '0', + modified smallint NOT NULL DEFAULT '0', + locked smallint NOT NULL DEFAULT '0', + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) + )"); + + db_query("CREATE TABLE {url_alias} ( + pid serial CHECK (pid >= 0), + src varchar(128) NOT NULL default '', + dst varchar(128) NOT NULL default '', + PRIMARY KEY (pid), + UNIQUE (dst) + )"); + db_query("CREATE INDEX {url_alias}_src_idx ON {url_alias} (src)"); + + db_query("CREATE TABLE {permission} ( + rid int_unsigned NOT NULL default '0', + perm text, + tid int_unsigned NOT NULL default '0' + )"); + db_query("CREATE INDEX {permission}_rid_idx ON {permission} (rid)"); + + db_query("CREATE TABLE {role} ( + rid serial CHECK (rid >= 0), + name varchar(64) NOT NULL default '', + PRIMARY KEY (rid), + UNIQUE (name) + )"); + + db_query("CREATE TABLE {blocks_roles} ( + module varchar(64) NOT NULL, + delta varchar(32) NOT NULL, + rid int_unsigned NOT NULL, + PRIMARY KEY (module, delta, rid) + )"); + + db_query("CREATE TABLE {sessions} ( + uid int_unsigned NOT NULL, + sid varchar(64) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0', + cache int NOT NULL default '0', + session text, + PRIMARY KEY (sid) + )"); + db_query("CREATE INDEX {sessions}_uid_idx ON {sessions} (uid)"); + db_query("CREATE INDEX {sessions}_timestamp_idx ON {sessions} (timestamp)"); + +/* Only used for MySQL + db_query("CREATE TABLE {sequences} ( + name varchar(255) NOT NULL default '', + id int_unsigned NOT NULL default '0', + PRIMARY KEY (name) + )"); */ + + db_query("CREATE TABLE {node_counter} ( + nid int NOT NULL default '0', + totalcount bigint_unsigned NOT NULL default '0', + daycount int_unsigned NOT NULL default '0', + timestamp int_unsigned NOT NULL default '0', + PRIMARY KEY (nid) + )"); + db_query("CREATE INDEX {node_counter}_totalcount_idx ON {node_counter} (totalcount)"); + db_query("CREATE INDEX {node_counter}_daycount_idx ON {node_counter} (daycount)"); + db_query("CREATE INDEX {node_counter}_timestamp_idx ON {node_counter} (timestamp)"); + + db_query("CREATE TABLE {system} ( + filename varchar(255) NOT NULL default '', + name varchar(255) NOT NULL default '', + type varchar(255) NOT NULL default '', + description varchar(255) NOT NULL default '', + status int NOT NULL default '0', + throttle smallint DEFAULT '0' NOT NULL, + bootstrap int NOT NULL default '0', + schema_version smallint NOT NULL default -1, + weight int NOT NULL default '0', + PRIMARY KEY (filename) + )"); + db_query("CREATE INDEX {system}_weight_idx ON {system} (weight)"); + + db_query("CREATE TABLE {term_data} ( + tid serial CHECK (tid >= 0), + vid int_unsigned NOT NULL default '0', + name varchar(255) NOT NULL default '', + description text, + weight smallint NOT NULL default '0', + PRIMARY KEY (tid) + )"); + db_query("CREATE INDEX {term_data}_vid_idx ON {term_data} (vid)"); + + db_query("CREATE TABLE {term_hierarchy} ( + tid int_unsigned NOT NULL default '0', + parent int_unsigned NOT NULL default '0', + PRIMARY KEY (tid, parent) + )"); + db_query("CREATE INDEX {term_hierarchy}_tid_idx ON {term_hierarchy} (tid)"); + db_query("CREATE INDEX {term_hierarchy}_parent_idx ON {term_hierarchy} (parent)"); + + db_query("CREATE TABLE {term_node} ( + nid int_unsigned NOT NULL default '0', + vid int_unsigned NOT NULL default '0', + tid int_unsigned NOT NULL default '0', + PRIMARY KEY (tid,nid,vid) + )"); + db_query("CREATE INDEX {term_node}_nid_idx ON {term_node} (nid)"); + db_query("CREATE INDEX {term_node}_vid_idx ON {term_node} (vid)"); + db_query("CREATE INDEX {term_node}_tid_idx ON {term_node} (tid)"); + + db_query("CREATE TABLE {term_relation} ( + tid1 int_unsigned NOT NULL default '0', + tid2 int_unsigned NOT NULL default '0' + )"); + db_query("CREATE INDEX {term_relation}_tid1_idx ON {term_relation} (tid1)"); + db_query("CREATE INDEX {term_relation}_tid2_idx ON {term_relation} (tid2)"); + + db_query("CREATE TABLE {term_synonym} ( + tid int_unsigned NOT NULL default '0', + name varchar(255) NOT NULL default '' + )"); + db_query("CREATE INDEX {term_synonym}_tid_idx ON {term_synonym} (tid)"); + db_query("CREATE INDEX {term_synonym}_name_idx ON {term_synonym} (substr(name, 1, 3))"); + + db_query("CREATE TABLE {users} ( + uid serial CHECK (uid >= 0), + name varchar(60) NOT NULL default '', + pass varchar(32) NOT NULL default '', + mail varchar(64) default '', + mode smallint NOT NULL default '0', + sort smallint default '0', + threshold smallint default '0', + theme varchar(255) NOT NULL default '', + signature varchar(255) NOT NULL default '', + created int NOT NULL default '0', + access int NOT NULL default '0', + login int NOT NULL default '0', + status smallint NOT NULL default '0', + timezone varchar(8) default NULL, + language varchar(12) NOT NULL default '', + picture varchar(255) NOT NULL DEFAULT '', + init varchar(64) default '', + data text, + PRIMARY KEY (uid), + UNIQUE (name) + )"); + db_query("CREATE INDEX {users}_access_idx ON {users} (access)"); + db_query("CREATE INDEX {users}_created_idx ON {users} (created)"); + + db_query("CREATE TABLE {users_roles} ( + uid int_unsigned NOT NULL default '0', + rid int_unsigned NOT NULL default '0', + PRIMARY KEY (uid, rid) + )"); + + db_query("CREATE TABLE {variable} ( + name varchar(128) NOT NULL default '', + value text NOT NULL, + PRIMARY KEY (name) + )"); + + db_query("CREATE TABLE {vocabulary} ( + vid serial CHECK (vid >= 0), + name varchar(255) NOT NULL default '', + description text, + help varchar(255) NOT NULL default '', + relations smallint_unsigned NOT NULL default '0', + hierarchy smallint_unsigned NOT NULL default '0', + multiple smallint_unsigned NOT NULL default '0', + required smallint_unsigned NOT NULL default '0', + tags smallint_unsigned NOT NULL default '0', + module varchar(255) NOT NULL default '', + weight smallint NOT NULL default '0', + PRIMARY KEY (vid) + )"); + + db_query("CREATE TABLE {vocabulary_node_types} ( + vid int_unsigned NOT NULL DEFAULT '0', + type varchar(32) NOT NULL DEFAULT '', + PRIMARY KEY (vid, type) + )"); + + db_query("CREATE TABLE {watchdog} ( + wid serial, + uid int NOT NULL default '0', + type varchar(16) NOT NULL default '', + message text NOT NULL, + severity smallint_unsigned NOT NULL default '0', + link varchar(255) NOT NULL default '', + location text NOT NULL default '', + referer varchar(128) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0', + PRIMARY KEY (wid) + )"); + db_query("CREATE INDEX {watchdog}_type_idx ON {watchdog} (type)"); + break; + } + + db_query("INSERT INTO {system} (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/engines/phptemplate/phptemplate.engine', 'phptemplate', 'theme_engine', '', 1, 0, 0, 0)"); + db_query("INSERT INTO {system} (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/garland/page.tpl.php', 'garland', 'theme', 'themes/engines/phptemplate/phptemplate.engine', 1, 0, 0, 0)"); + + db_query("INSERT INTO {users} (uid,name,mail) VALUES(0,'','')"); + + db_query("INSERT INTO {role} (name) VALUES ('anonymous user')"); + db_query("INSERT INTO {role} (name) VALUES ('authenticated user')"); + + db_query("INSERT INTO {permission} VALUES (1,'access content',0)"); + db_query("INSERT INTO {permission} VALUES (2,'access comments, access content, post comments, post comments without approval',0)"); + + db_query("INSERT INTO {variable} (name,value) VALUES('theme_default', 's:7:\"garland\";')"); + + db_query("INSERT INTO {blocks} (module,delta,theme,status,pages) VALUES('user', 0, 'garland', 1, '')"); + db_query("INSERT INTO {blocks} (module,delta,theme,status,pages) VALUES('user', 1, 'garland', 1, '')"); + + db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)"); + + db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Filtered HTML',',1,2,',1)"); + db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('PHP code','',0)"); + db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Full HTML','',1)"); + + db_query("INSERT INTO {filters} VALUES (1,'filter',3,0)"); + db_query("INSERT INTO {filters} VALUES (1,'filter',0,1)"); + db_query("INSERT INTO {filters} VALUES (1,'filter',2,2)"); + + db_query("INSERT INTO {filters} VALUES (2,'filter',1,0)"); + + db_query("INSERT INTO {filters} VALUES (3,'filter',3,0)"); + db_query("INSERT INTO {filters} VALUES (3,'filter',2,1)"); + + db_query("INSERT INTO {variable} (name,value) VALUES ('filter_html_1','i:1;')"); + + db_query("INSERT INTO {variable} (name, value) VALUES ('node_options_forum', '%s')", 'a:1:{i:0;s:6:"status";}'); +} + +// Updates for core + +function system_update_110() { + $ret = array(); + + // TODO: needs PGSQL version + if ($GLOBALS['db_type'] == 'mysql') { + /* + ** Search + */ + + $ret[] = update_sql('DROP TABLE {search_index}'); + $ret[] = update_sql("CREATE TABLE {search_index} ( + word varchar(50) NOT NULL default '', + sid int unsigned NOT NULL default '0', + type varchar(16) default NULL, + fromsid int unsigned NOT NULL default '0', + fromtype varchar(16) default NULL, + score int unsigned default NULL, + KEY sid (sid), + KEY fromsid (fromsid), + KEY word (word) + )"); + + $ret[] = update_sql("CREATE TABLE {search_total} ( + word varchar(50) NOT NULL default '', + count int unsigned default NULL, + PRIMARY KEY word (word) + )"); + + + /* + ** Blocks + */ + + $ret[] = update_sql('ALTER TABLE {blocks} DROP path'); + $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility tinyint NOT NULL'); + $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text NOT NULL'); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + /* + ** Search + */ + $ret[] = update_sql('DROP TABLE {search_index}'); + $ret[] = update_sql("CREATE TABLE {search_index} ( + word varchar(50) NOT NULL default '', + sid integer NOT NULL default '0', + type varchar(16) default NULL, + fromsid integer NOT NULL default '0', + fromtype varchar(16) default NULL, + score integer default NULL + )"); + $ret[] = update_sql("CREATE INDEX {search_index}_sid_idx on {search_index}(sid)"); + $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_idx on {search_index}(fromsid)"); + $ret[] = update_sql("CREATE INDEX {search_index}_word_idx on {search_index}(word)"); + + $ret[] = update_sql("CREATE TABLE {search_total} ( + word varchar(50) NOT NULL default '' PRIMARY KEY, + count integer default NULL + )"); + + + /* + ** Blocks + */ + // Postgres can only drop columns since 7.4 + #$ret[] = update_sql('ALTER TABLE {blocks} DROP path'); + + $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility smallint'); + $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN visibility set default 0"); + $ret[] = update_sql('UPDATE {blocks} SET visibility = 0'); + $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN visibility SET NOT NULL'); + $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text'); + $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN pages set default ''"); + $ret[] = update_sql("UPDATE {blocks} SET pages = ''"); + $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN pages SET NOT NULL'); + + } + + $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'"); + + $ret[] = update_sql('UPDATE {blocks} SET status = 1, custom = 2 WHERE status = 0 AND custom = 1'); + + return $ret; +} + +function system_update_111() { + $ret = array(); + + $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'throttle_%'"); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql('ALTER TABLE {sessions} ADD PRIMARY KEY sid (sid)'); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql('ALTER TABLE {sessions} ADD UNIQUE(sid)'); + } + + return $ret; +} + +function system_update_112() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("CREATE TABLE {flood} ( + event varchar(64) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp int NOT NULL default '0' + );"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("CREATE TABLE {flood} ( + event varchar(64) NOT NULL default '', + hostname varchar(128) NOT NULL default '', + timestamp integer NOT NULL default 0 + );"); + } + + return $ret; +} + +function system_update_113() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql('ALTER TABLE {accesslog} ADD aid int NOT NULL auto_increment, ADD PRIMARY KEY (aid)'); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("SELECT * INTO TEMPORARY {accesslog}_t FROM {accesslog}"); + $ret[] = update_sql("DROP TABLE {accesslog}"); + $ret[] = update_sql("CREATE TABLE {accesslog} ( + aid serial, + title varchar(255) default NULL, + path varchar(255) default NULL, + url varchar(255) default NULL, + hostname varchar(128) default NULL, + uid integer default '0', + timestamp integer NOT NULL default '0' + )"); + $ret[] = update_sql("INSERT INTO {accesslog} (title, path, url, hostname, uid, timestamp) SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}_t"); + + $ret[] = update_sql("DROP TABLE {accesslog}_t"); + $ret[] = update_sql("CREATE INDEX {accesslog}_timestamp_idx ON {accesslog} (timestamp);"); + + } + + // Flush the menu cache: + cache_clear_all('menu:', TRUE); + + return $ret; +} + +function system_update_114() { + $ret = array(); + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("CREATE TABLE {queue} ( + nid int unsigned NOT NULL, + uid int unsigned NOT NULL, + vote int NOT NULL default '0', + PRIMARY KEY (nid, uid) + )"); + } + else if ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("CREATE TABLE {queue} ( + nid integer NOT NULL default '0', + uid integer NOT NULL default '0', + vote integer NOT NULL default '0', + PRIMARY KEY (nid, uid) + )"); + $ret[] = update_sql("CREATE INDEX {queue}_nid_idx ON queue(nid)"); + $ret[] = update_sql("CREATE INDEX {queue}_uid_idx ON queue(uid)"); + } + + $result = db_query("SELECT nid, votes, score, users FROM {node}"); + while ($node = db_fetch_object($result)) { + if (isset($node->users)) { + $arr = explode(',', $node->users); + unset($node->users); + foreach ($arr as $value) { + $arr2 = explode('=', trim($value)); + if (isset($arr2[0]) && isset($arr2[1])) { + switch ($arr2[1]) { + case '+ 1': + db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], 1); + break; + case '- 1': + db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], -1); + break; + default: + db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], 0); + } + } + } + } + } + + if ($GLOBALS['db_type'] == 'mysql') { + // Postgres only supports dropping of columns since 7.4 + $ret[] = update_sql("ALTER TABLE {node} DROP votes"); + $ret[] = update_sql("ALTER TABLE {node} DROP score"); + $ret[] = update_sql("ALTER TABLE {node} DROP users"); + } + + return $ret; +} + +function system_update_115() { + $ret = array(); + + // This update has been moved to update_fix_watchdog_115 in update.php because it + // is needed for the basic functioning of the update script. + + return $ret; +} + +function system_update_116() { + return array(update_sql("DELETE FROM {system} WHERE name = 'admin'")); +} + +function system_update_117() { + $ret = array(); + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} ( + vid int NOT NULL default '0', + type varchar(16) NOT NULL default '', + PRIMARY KEY (vid, type))"); + } + else if ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} ( + vid serial, + type varchar(16) NOT NULL default '', + PRIMARY KEY (vid, type)) "); + } + return $ret; +} + +function system_update_118() { + $ret = array(); + $node_types = array(); + $result = db_query('SELECT vid, nodes FROM {vocabulary}'); + while ($vocabulary = db_fetch_object($result)) { + $node_types[$vocabulary->vid] = explode(',', $vocabulary->nodes); + } + foreach ($node_types as $vid => $type_array) { + foreach ($type_array as $type) { + db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vid, $type); + } + } + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {vocabulary} DROP nodes"); + } + return $ret; +} + +function system_update_119() { + $ret = array(); + + foreach (node_get_types() as $type => $name) { + $node_options = array(); + if (variable_get('node_status_'. $type, 1)) { + $node_options[] = 'status'; + } + if (variable_get('node_moderate_'. $type, 0)) { + $node_options[] = 'moderate'; + } + if (variable_get('node_promote_'. $type, 1)) { + $node_options[] = 'promote'; + } + if (variable_get('node_sticky_'. $type, 0)) { + $node_options[] = 'sticky'; + } + if (variable_get('node_revision_'. $type, 0)) { + $node_options[] = 'revision'; + } + variable_set('node_options_'. $type, $node_options); + variable_del('node_status_'. $type); + variable_del('node_moderate_'. $type); + variable_del('node_promote_'. $type); + variable_del('node_sticky_'. $type); + variable_del('node_revision_'. $type); + } + + return $ret; +} + +function system_update_120() { + $ret = array(); + + // Rewrite old URL aliases. Works for both PostgreSQL and MySQL + $result = db_query("SELECT pid, src FROM {url_alias} WHERE src LIKE 'blog/%%'"); + while ($alias = db_fetch_object($result)) { + list(, $page, $op, $uid) = explode('/', $alias->src); + if ($page == 'feed') { + $new = "blog/$uid/feed"; + update_sql("UPDATE {url_alias} SET src = '%s' WHERE pid = '%s'", $new, $alias->pid); + } + } + + return $ret; +} + +function system_update_121() { + $ret = array(); + + // Remove the unused page table. + $ret[] = update_sql('DROP TABLE {page}'); + + return $ret; +} + +function system_update_122() { + + $ret = array(); + $ret[] = update_sql("ALTER TABLE {blocks} ADD types text"); + return $ret; + +} + +function system_update_123() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255) NOT NULL default ''"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255)"); + $ret[] = update_sql("UPDATE {vocabulary} SET module = ''"); + $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET NOT NULL"); + $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET DEFAULT ''"); + } + + $ret[] = update_sql("UPDATE {vocabulary} SET module = 'taxonomy'"); + $vid = variable_get('forum_nav_vocabulary', ''); + if (!empty($vid)) { + $ret[] = update_sql("UPDATE {vocabulary} SET module = 'forum' WHERE vid = " . $vid); + } + + return $ret; +} + +function system_update_124() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + // redo update_105, correctly creating node_comment_statistics + $ret[] = update_sql("DROP TABLE IF EXISTS {node_comment_statistics}"); + + $ret[] = update_sql("CREATE TABLE {node_comment_statistics} ( + nid int unsigned NOT NULL auto_increment, + last_comment_timestamp int NOT NULL default '0', + last_comment_name varchar(60) default NULL, + last_comment_uid int NOT NULL default '0', + comment_count int unsigned NOT NULL default '0', + PRIMARY KEY (nid), + KEY node_comment_timestamp (last_comment_timestamp) + )"); + } + + else { + // also drop incorrectly named table for PostgreSQL + $ret[] = update_sql("DROP TABLE {node}_comment_statistics"); + + $ret[] = update_sql("CREATE TABLE {node_comment_statistics} ( + nid integer NOT NULL, + last_comment_timestamp integer NOT NULL default '0', + last_comment_name varchar(60) default NULL, + last_comment_uid integer NOT NULL default '0', + comment_count integer NOT NULL default '0', + PRIMARY KEY (nid) + )"); + + $ret[] = update_sql("CREATE INDEX {node_comment_statistics}_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp); +"); + } + + // initialize table + $ret[] = update_sql("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, 0, 0 FROM {node} n"); + + // fill table + $result = db_query("SELECT c.nid, c.timestamp, c.name, c.uid, COUNT(c.nid) as comment_count FROM {node} n LEFT JOIN {comments} c ON c.nid = n.nid WHERE c.status = 0 GROUP BY c.nid, c.timestamp, c.name, c.uid"); + while ($comment_record = db_fetch_object($result)) { + $count = db_result(db_query('SELECT COUNT(cid) FROM {comments} WHERE nid = %d AND status = 0', $comment_record->nid)); + db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $comment_record->timestamp, $comment_record->name, $comment_record->uid, $comment_record->nid); + } + + return $ret; +} + +function system_update_125() { + // Postgres only update. + $ret = array(); + + if ($GLOBALS['db_type'] == 'pgsql') { + + $ret[] = update_sql("CREATE OR REPLACE FUNCTION if(boolean, anyelement, anyelement) RETURNS anyelement AS ' + SELECT CASE WHEN $1 THEN $2 ELSE $3 END; + ' LANGUAGE 'sql'"); + + $ret[] = update_sql("CREATE FUNCTION greatest(integer, integer, integer) RETURNS integer AS ' + SELECT greatest($1, greatest($2, $3)); + ' LANGUAGE 'sql'"); + + } + + return $ret; +} + +function system_update_126() { + variable_set('forum_block_num_0', variable_get('forum_block_num', 5)); + variable_set('forum_block_num_1', variable_get('forum_block_num', 5)); + variable_del('forum_block_num'); + + return array(); +} + +function system_update_127() { + $ret = array(); + if ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("ALTER TABLE {poll} RENAME voters TO polled"); + } + else if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {poll} CHANGE voters polled longtext"); + } + return $ret; +} + +function system_update_128() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)'); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)'); + } + + return $ret; +} + +function system_update_129() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {vocabulary} ADD tags tinyint unsigned default '0' NOT NULL"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + db_add_column($ret, 'vocabulary', 'tags', 'smallint', array('default' => 0, 'not null' => TRUE)); + } + + return $ret; +} + +function system_update_130() { + $ret = array(); + + // This update has been moved to update_fix_sessions in update.php because it + // is needed for the basic functioning of the update script. + + return $ret; +} + +function system_update_131() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {boxes} DROP INDEX title"); + // Removed recreation of the index, which is not present in the db schema + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("ALTER TABLE {boxes} DROP CONSTRAINT {boxes}_title_key"); + } + + return $ret; +} + +function system_update_132() { + /** + * PostgreSQL only update. + */ + $ret = array(); + + if (!variable_get('update_132_done', FALSE)) { + if ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql('DROP TABLE {search_total}'); + $ret[] = update_sql("CREATE TABLE {search_total} ( + word varchar(50) NOT NULL default '', + count float default NULL)"); + $ret[] = update_sql('CREATE INDEX {search_total}_word_idx ON {search_total}(word)'); + + /** + * Wipe the search index + */ + include_once './'. drupal_get_path('module', 'search') .'/search.module'; + search_wipe(); + } + + variable_del('update_132_done'); + } + + return $ret; +} + +function system_update_133() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("CREATE TABLE {contact} ( + subject varchar(255) NOT NULL default '', + recipients longtext NOT NULL, + reply longtext NOT NULL + )"); + $ret[] = update_sql("ALTER TABLE {users} ADD login int NOT NULL default '0'"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + // Table {contact} is changed in update_143() so I have moved it's creation there. + // It was never created here for postgres because of errors. + + db_add_column($ret, 'users', 'login', 'int', array('default' => 0, 'not null' => TRUE)); + } + + return $ret; +} + +function system_update_134() { + $ret = array(); + $ret[] = update_sql('ALTER TABLE {blocks} DROP types'); + return $ret; +} + +function system_update_135() { + if (!variable_get('update_135_done', FALSE)) { + $result = db_query("SELECT delta FROM {blocks} WHERE module = 'aggregator'"); + while ($block = db_fetch_object($result)) { + list($type, $id) = explode(':', $block->delta); + db_query("UPDATE {blocks} SET delta = '%s' WHERE module = 'aggregator' AND delta = '%s'", $type .'-'. $id, $block->delta); + } + + variable_del('update_135_done'); + } + return array(); +} + +function system_update_136() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'pgsql': + $ret[] = update_sql("DROP INDEX {users}_changed_idx"); // We drop the index first because it won't be renamed + $ret[] = update_sql("ALTER TABLE {users} RENAME changed TO access"); + $ret[] = update_sql("CREATE INDEX {users}_access_idx on {users}(access)"); // Re-add the index + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {users} CHANGE COLUMN changed access int NOT NULL default '0'"); + break; + } + + $ret[] = update_sql('UPDATE {users} SET access = login WHERE login > created'); + $ret[] = update_sql('UPDATE {users} SET access = created WHERE access = 0'); + return $ret; +} + +function system_update_137() { + $ret = array(); + + if (!variable_get('update_137_done', FALSE)) { + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {locales_source} CHANGE location location varchar(255) NOT NULL default ''"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + db_change_column($ret, 'locales_source', 'location', 'location', 'varchar(255)', array('not null' => TRUE, 'default' => "''")); + } + variable_del('update_137_done'); + } + + return $ret; +} + +function system_update_138() { + $ret = array(); + // duplicate of update_97 which never got into the default database.* files. + $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('node/feed', 'rss.xml')"); + return $ret; +} + +function system_update_139() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_add_column($ret, 'accesslog', 'timer', 'int', array('not null' => TRUE, 'default' => 0)); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {accesslog} ADD timer int unsigned NOT NULL default '0'"); + break; + } + + return $ret; +} + +function system_update_140() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX (src)"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("CREATE INDEX {url_alias}_src_idx ON {url_alias}(src)"); + } + return $ret; +} + +function system_update_141() { + $ret = array(); + + variable_del('upload_maxsize_total'); + + return $ret; +} + +function system_update_142() { + $ret = array(); + + // This update has been moved to update_fix_sessions in update.php because it + // is needed for the basic functioning of the update script. + + return $ret; +} + +function system_update_143() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {contact} CHANGE subject category VARCHAR(255) NOT NULL "); + $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (category)"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + // Why the table is created here? See update_133(). + $ret[] = update_sql("CREATE TABLE {contact} ( + category varchar(255) NOT NULL default '', + recipients text NOT NULL default '', + reply text NOT NULL default '', + PRIMARY KEY (category))"); + } + + return $ret; +} + +function system_update_144() { + $ret = array(); + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {node} CHANGE type type VARCHAR(32) NOT NULL"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("DROP INDEX {node}_type_idx"); // Drop indexes using "type" column + $ret[] = update_sql("DROP INDEX {node}_title_idx"); + db_change_column($ret, 'node', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''")); + // Let's recreate the indexes + $ret[] = update_sql("CREATE INDEX {node}_type_idx ON {node}(type)"); + $ret[] = update_sql("CREATE INDEX {node}_title_type_idx ON {node}(title,type)"); + $ret[] = update_sql("CREATE INDEX {node}_status_type_nid_idx ON {node}(status,type,nid)"); + } + return $ret; +} + +function system_update_145() { + $default_theme = variable_get('theme_default', 'garland'); + + $themes = list_themes(); + if (!array_key_exists($default_theme, $themes)) { + variable_set('theme_default', 'garland'); + $default_theme = 'garland'; + } + + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_change_column($ret, 'blocks', 'region', 'region', 'varchar(64)', array('default' => "'left'", 'not null' => TRUE)); + db_add_column($ret, 'blocks', 'theme', 'varchar(255)', array('not null' => TRUE, 'default' => "''")); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {blocks} CHANGE region region varchar(64) default 'left' NOT NULL"); + $ret[] = update_sql("ALTER TABLE {blocks} ADD theme varchar(255) NOT NULL default ''"); + break; + } + + // Intialize block data for default theme + $ret[] = update_sql("UPDATE {blocks} SET region = 'left' WHERE region = '0'"); + $ret[] = update_sql("UPDATE {blocks} SET region = 'right' WHERE region = '1'"); + db_query("UPDATE {blocks} SET theme = '%s'", $default_theme); + + // Initialize block data for other enabled themes. + $themes = list_themes(); + foreach (array_keys($themes) as $theme) { + if (($theme != $default_theme) && $themes[$theme]->status == 1) { + system_initialize_theme_blocks($theme); + } + } + + return $ret; +} + +function system_update_146() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("CREATE TABLE {node_revisions} + SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format + FROM {node}"); + + $ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int unsigned NOT NULL default '0'"); + $ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext"); + + $ret[] = update_sql("ALTER TABLE {node} ADD vid int unsigned NOT NULL default '0'"); + $ret[] = update_sql("ALTER TABLE {files} ADD vid int unsigned NOT NULL default '0'"); + $ret[] = update_sql("ALTER TABLE {book} ADD vid int unsigned NOT NULL default '0'"); + $ret[] = update_sql("ALTER TABLE {forum} ADD vid int unsigned NOT NULL default '0'"); + + $ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY"); + $ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY"); + $ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY"); + + $ret[] = update_sql("UPDATE {node} SET vid = nid"); + $ret[] = update_sql("UPDATE {forum} SET vid = nid"); + $ret[] = update_sql("UPDATE {book} SET vid = nid"); + $ret[] = update_sql("UPDATE {files} SET vid = nid"); + + $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)"); + $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)"); + $ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)"); + $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)"); + $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)"); + + $ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''"); + + $ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)"); + $ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)"); + $ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)"); + $ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)"); + $vid = db_next_id('{node}_nid'); + $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)"); + } + else { // pgsql + $ret[] = update_sql("CREATE TABLE {node_revisions} ( + nid integer NOT NULL default '0', + vid integer NOT NULL default '0', + uid integer NOT NULL default '0', + title varchar(128) NOT NULL default '', + body text NOT NULL default '', + teaser text NOT NULL default '', + log text NOT NULL default '', + timestamp integer NOT NULL default '0', + format int NOT NULL default '0', + PRIMARY KEY (vid))"); + $ret[] = update_sql("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, timestamp, format) + SELECT nid, nid AS vid, uid, title, body, teaser, changed AS timestamp, format + FROM {node}"); + $ret[] = update_sql('CREATE INDEX {node_revisions}_nid_idx ON {node_revisions}(nid)'); + $ret[] = update_sql('CREATE INDEX {node_revisions}_uid_idx ON {node_revisions}(uid)'); + $vid = db_next_id('{node}_nid'); + $ret[] = update_sql("CREATE SEQUENCE {node_revisions}_vid_seq INCREMENT 1 START $vid"); + + db_add_column($ret, 'node', 'vid', 'int', array('not null' => TRUE, 'default' => 0)); + db_add_column($ret, 'files', 'vid', 'int', array('not null' => TRUE, 'default' => 0)); + db_add_column($ret, 'book', 'vid', 'int', array('not null' => TRUE, 'default' => 0)); + db_add_column($ret, 'forum', 'vid', 'int', array('not null' => TRUE, 'default' => 0)); + + $ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT {book}_pkey"); + $ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT {forum}_pkey"); + $ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT {files}_pkey"); + + $ret[] = update_sql("UPDATE {node} SET vid = nid"); + $ret[] = update_sql("UPDATE {forum} SET vid = nid"); + $ret[] = update_sql("UPDATE {book} SET vid = nid"); + $ret[] = update_sql("UPDATE {files} SET vid = nid"); + + $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY (vid)"); + $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY (vid)"); + + $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''"); + + $ret[] = update_sql('CREATE INDEX {node}_vid_idx ON {node}(vid)'); + $ret[] = update_sql('CREATE INDEX {forum}_nid_idx ON {forum}(nid)'); + $ret[] = update_sql('CREATE INDEX {files}_fid_idx ON {files}(fid)'); + $ret[] = update_sql('CREATE INDEX {files}_vid_idx ON {files}(vid)'); + } + + // Move logs too. + $result = db_query("SELECT nid, log FROM {book} WHERE log != ''"); + while ($row = db_fetch_object($result)) { + db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $row->log, $row->nid); + } + + $ret[] = update_sql("ALTER TABLE {book} DROP log"); + $ret[] = update_sql("ALTER TABLE {node} DROP teaser"); + $ret[] = update_sql("ALTER TABLE {node} DROP body"); + $ret[] = update_sql("ALTER TABLE {node} DROP format"); + $ret[] = update_sql("ALTER TABLE {node} DROP revisions"); + + return $ret; +} + +function system_update_147() { + $ret = array(); + + // this update is mysql only, pgsql should get it right in the first try. + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {node_revisions} DROP type"); + } + + return $ret; +} + +function system_update_148() { + $ret = array(); + + // Add support for tracking users' session ids (useful for tracking anon users) + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_add_column($ret, 'accesslog', 'sid', 'varchar(32)', array('not null' => TRUE, 'default' => "''")); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {accesslog} ADD sid varchar(32) NOT NULL default ''"); + break; + } + + return $ret; +} + +function system_update_149() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_add_column($ret, 'files', 'description', 'varchar(255)', array('not null' => TRUE, 'default' => "''")); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {files} ADD COLUMN description VARCHAR(255) NOT NULL DEFAULT ''"); + break; + default: + break; + } + + return $ret; +} + +function system_update_150() { + $ret = array(); + + $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'"); + $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'minimum_word_size'"); + $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'remove_short'"); + + $ret[] = update_sql("DELETE FROM {node_counter} WHERE nid = 0"); + + $ret[] = update_sql('DROP TABLE {search_index}'); + $ret[] = update_sql('DROP TABLE {search_total}'); + + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $ret[] = update_sql("CREATE TABLE {search_dataset} ( + sid int unsigned NOT NULL default '0', + type varchar(16) default NULL, + data longtext NOT NULL, + KEY sid_type (sid, type) + )"); + + $ret[] = update_sql("CREATE TABLE {search_index} ( + word varchar(50) NOT NULL default '', + sid int unsigned NOT NULL default '0', + type varchar(16) default NULL, + fromsid int unsigned NOT NULL default '0', + fromtype varchar(16) default NULL, + score float default NULL, + KEY sid_type (sid, type), + KEY from_sid_type (fromsid, fromtype), + KEY word (word) + )"); + + $ret[] = update_sql("CREATE TABLE {search_total} ( + word varchar(50) NOT NULL default '', + count float default NULL, + PRIMARY KEY word (word) + )"); + break; + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {search_dataset} ( + sid integer NOT NULL default '0', + type varchar(16) default NULL, + data text NOT NULL default '')"); + $ret[] = update_sql("CREATE INDEX {search_dataset}_sid_type_idx ON {search_dataset}(sid, type)"); + + $ret[] = update_sql("CREATE TABLE {search_index} ( + word varchar(50) NOT NULL default '', + sid integer NOT NULL default '0', + type varchar(16) default NULL, + fromsid integer NOT NULL default '0', + fromtype varchar(16) default NULL, + score float default NULL)"); + $ret[] = update_sql("CREATE INDEX {search_index}_sid_type_idx ON {search_index}(sid, type)"); + $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_fromtype_idx ON {search_index}(fromsid, fromtype)"); + $ret[] = update_sql("CREATE INDEX {search_index}_word_idx ON {search_index}(word)"); + + $ret[] = update_sql("CREATE TABLE {search_total} ( + word varchar(50) NOT NULL default '', + count float default NULL, + PRIMARY KEY(word))"); + break; + default: + break; + } + return $ret; +} + +function system_update_151() { + $ret = array(); + + $ts = variable_get('theme_settings', NULL); + + // set up data array so we can loop over both sets of links + $menus = array(0 => array('links_var' => 'primary_links', + 'toggle_var' => 'toggle_primary_links', + 'more_var' => 'primary_links_more', + 'menu_name' => 'Primary links', + 'menu_var' => 'menu_primary_menu', + 'pid' => 0), + 1 => array('links_var' => 'secondary_links', + 'toggle_var' => 'toggle_secondary_links', + 'more_var' => 'secondary_links_more', + 'menu_name' => 'Secondary links', + 'menu_var' => 'menu_secondary_menu', + 'pid' => 0)); + + for ($loop = 0; $loop <= 1 ; $loop ++) { + // create new Primary and Secondary links menus + $menus[$loop]['pid'] = db_next_id('{menu}_mid'); + $ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " . + "VALUES ({$menus[$loop]['pid']}, 0, '', '{$menus[$loop]['menu_name']}', '', 0, 115)"); + + // Gather links from various settings into a single array. + $phptemplate_links = variable_get("phptemplate_". $menus[$loop]['links_var'], array()); + if (empty($phptemplate_links)) { + $phptemplate_links = array('text' => array(), 'link' => array()); + } + if (isset($ts) && is_array($ts)) { + if (is_array($ts[$menus[$loop]['links_var']])) { + $theme_links = $ts[$menus[$loop]['links_var']]; + } + else { + // Convert old xtemplate style links. + preg_match_all('/(.*?)<\/a>/i', $ts[$menus[$loop]['links_var']], $urls); + $theme_links['text'] = $urls[2]; + $theme_links['link'] = $urls[1]; + } + } + else { + $theme_links = array('text' => array(), 'link' => array()); + } + $links['text'] = array_merge($phptemplate_links['text'], $theme_links['text']); + $links['link'] = array_merge($phptemplate_links['link'], $theme_links['link']); + + // insert all entries from theme links into new menus + $num_inserted = 0; + for ($i = 0; $i < count($links['text']); $i++) { + if ($links['text'][$i] != "" && $links['link'][$i] != "") { + $num_inserted ++; + $node_unalias = db_fetch_array(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $links['link'][$i])); + if (isset($node_unalias) && is_array($node_unalias)) { + $link_path = $node_unalias['src']; + } + else { + $link_path = $links['link'][$i]; + } + + $mid = db_next_id('{menu}_mid'); + $ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " . + "VALUES ($mid, {$menus[$loop]['pid']}, '" . db_escape_string($link_path) . + "', '" . db_escape_string($links['text'][$i]) . + "', '" . db_escape_string($links['description'][$i]) . "', 0, 118)"); + } + } + // delete Secondary links if not populated. + if ($loop == 1 && $num_inserted == 0) { + db_query("DELETE FROM {menu} WHERE mid={$menus[$loop]['pid']}"); + } + + // Set menu_primary_menu and menu_primary_menu variables if links were + // imported. If the user had links but the toggle display was off, they + // will need to disable the new links manually in admins/settings/menu. + if ($num_inserted == 0) { + variable_set($menus[$loop]['menu_var'], 0); + } + else { + variable_set($menus[$loop]['menu_var'], $menus[$loop]['pid']); + } + variable_del('phptemplate_' .$menus[$loop]['links_var']); + variable_del('phptemplate_'. $menus[$loop]['links_var'] .'_more'); + variable_del($menus[$loop]['toggle_var']); + variable_del($menus[$loop]['more_var']); + // If user has old xtemplate links in a string, leave them in the var. + if (isset($ts) && is_array($ts) && is_array($ts[$menus[$loop]['links_var']])) { + variable_del($menus[$loop]['links_var']); + } + } + + if (isset($ts) && is_array($ts)) { + variable_set('theme_settings', $ts); + } + + $ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'menu'"); + + return $ret; +} + +function system_update_152() { + $ret = array(); + + // Postgresql only update + switch ($GLOBALS['db_type']) { + case 'pgsql': + $ret[] = update_sql("ALTER TABLE {forum} DROP shadow"); + break; + case 'mysql': + case 'mysqli': + break; + } + + return $ret; +} + +function system_update_153(){ + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'pgsql': + $ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT {contact}_pkey"); + $ret[] = update_sql("CREATE SEQUENCE {contact}_cid_seq"); + db_add_column($ret, 'contact', 'cid', 'int', array('not null' => TRUE, 'default' => "nextval('{contact}_cid_seq')")); + $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (cid)"); + $ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT {contact}_category_key UNIQUE (category)"); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {contact} DROP PRIMARY KEY"); + $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int NOT NULL PRIMARY KEY auto_increment"); + $ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE KEY category (category)"); + break; + } + return $ret; +} + +function system_update_154() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_add_column($ret, 'contact', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0)); + db_add_column($ret, 'contact', 'selected', 'smallint', array('not null' => TRUE, 'default' => 0)); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN weight tinyint NOT NULL DEFAULT 0"); + $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN selected tinyint NOT NULL DEFAULT 0"); + break; + } + return $ret; +} + +function system_update_155() { + $ret = array(); + + // Postgresql only update + switch ($GLOBALS['db_type']) { + case 'pgsql': + $ret[] = update_sql("DROP TABLE {cache}"); + $ret[] = update_sql("CREATE TABLE {cache} ( + cid varchar(255) NOT NULL default '', + data bytea default '', + expire integer NOT NULL default '0', + created integer NOT NULL default '0', + headers text default '', + PRIMARY KEY (cid) + )"); + $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache}(expire)"); + break; + case 'mysql': + case 'mysqli': + break; + } + + return $ret; +} + +function system_update_156() { + $ret = array(); + $ret[] = update_sql("DELETE FROM {cache}"); + system_themes(); + return $ret; +} + +function system_update_157() { + $ret = array(); + $ret[] = update_sql("DELETE FROM {url_alias} WHERE src = 'node/feed' AND dst = 'rss.xml'"); + $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('rss.xml', 'node/feed')"); + return $ret; +} + +function system_update_158() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $ret[] = update_sql("ALTER TABLE {old_revisions} ADD done tinyint NOT NULL DEFAULT 0"); + $ret[] = update_sql("ALTER TABLE {old_revisions} ADD INDEX (done)"); + break; + + case 'pgsql': + db_add_column($ret, 'old_revisions', 'done', 'smallint', array('not null' => TRUE, 'default' => 0)); + $ret[] = update_sql('CREATE INDEX {old_revisions}_done_idx ON {old_revisions}(done)'); + break; + } + + return $ret; +} + +/** + * Retrieve data out of the old_revisions table and put into new revision + * system. + * + * The old_revisions table is not deleted because any data which could not be + * put into the new system is retained. + */ +function system_update_159() { + $ret = array(); + + $result = db_query_range("SELECT * FROM {old_revisions} WHERE done = 0 AND type IN ('page', 'story', 'poll', 'book', 'forum', 'blog') ORDER BY nid DESC", 0, 20); + + if (db_num_rows($result)) { + $vid = db_next_id('{node_revisions}_vid'); + while ($node = db_fetch_object($result)) { + $revisions = unserialize($node->revisions); + if (isset($revisions) && is_array($revisions) && count($revisions) > 0) { + $revisions_query = array(); + $revisions_args = array(); + $book_query = array(); + $book_args = array(); + $forum_query = array(); + $forum_args = array(); + foreach ($revisions as $version) { + $revision = array(); + foreach ($version['node'] as $node_field => $node_value) { + $revision[$node_field] = $node_value; + } + $revision['uid'] = $version['uid']; + $revision['timestamp'] = $version['timestamp']; + $vid++; + $revisions_query[] = "(%d, %d, %d, '%s', '%s', '%s', '%s', %d, %d)"; + $revisions_args = array_merge($revisions_args, array($node->nid, $vid, $revision['uid'], $revision['title'], $revision['body'], $revision['teaser'], $revision['log'], $revision['timestamp'], $revision['format'])); + switch ($node->type) { + case 'forum': + if ($revision['tid'] > 0) { + $forum_query[] = "(%d, %d, %d)"; + $forum_args = array_merge($forum_args, array($vid, $node->nid, $revision['tid'])); + } + break; + + case 'book': + $book_query[] = "(%d, %d, %d, %d)"; + $book_args = array_merge($book_args, array($vid, $node->nid, $revision['parent'], $revision['weight'])); + break; + } + } + if (count($revisions_query)) { + $revision_status = db_query("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, log, timestamp, format) VALUES ". implode(',', $revisions_query), $revisions_args); + } + if (count($forum_query)) { + $forum_status = db_query("INSERT INTO {forum} (vid, nid, tid) VALUES ". implode(',', $forum_query), $forum_args); + } + if (count($book_query)) { + $book_status = db_query("INSERT INTO {book} (vid, nid, parent, weight) VALUES ". implode(',', $book_query), $book_args); + } + $delete = FALSE; + switch ($node->type) { + case 'forum': + if ($forum_status && $revision_status) { + $delete = TRUE; + } + break; + + case 'book': + if ($book_status && $revision_status) { + $delete = TRUE; + } + break; + + default: + if ($revision_status) { + $delete = TRUE; + } + break; + } + + if ($delete) { + db_query('DELETE FROM {old_revisions} WHERE nid = %d', $node->nid); + } + else { + db_query('UPDATE {old_revisions} SET done = 1 WHERE nid = %d', $node->nid); + } + + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $ret[] = update_sql("UPDATE {sequences} SET id = $vid WHERE name = '{node_revisions}_vid'"); + break; + + case 'pgsql': + $ret[] = update_sql("SELECT setval('{node_revisions}_vid_seq', $vid)"); + break; + } + } + else { + db_query('UPDATE {old_revisions} SET done = 1 WHERE nid = %d', $node->nid); + watchdog('php', "Recovering old revisions for node $node->nid failed.", WATCHDOG_WARNING); + } + } + } + + if (db_num_rows($result) < 20) { + $ret[] = update_sql('ALTER TABLE {old_revisions} DROP done'); + } + else { + $ret['#finished'] = FALSE; + } + + return $ret; +} + +function system_update_160() { + $types = module_invoke('node', 'get_types'); + if (is_array($types)) { + foreach ($types as $type) { + if (!is_array(variable_get("node_options_$type", array()))) { + variable_set("node_options_$type", array()); + } + } + } + return array(); +} + +function system_update_161() { + variable_del('forum_icon_path'); + return array(); +} + +function system_update_162() { + $ret = array(); + + // PostgreSQL only update + switch ($GLOBALS['db_type']) { + case 'pgsql': + + $ret[] = update_sql('DROP INDEX {book}_parent'); + $ret[] = update_sql('CREATE INDEX {book}_parent_idx ON {book}(parent)'); + + $ret[] = update_sql('DROP INDEX {node_comment_statistics}_timestamp_idx'); + $ret[] = update_sql('CREATE INDEX {node_comment_statistics}_last_comment_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp)'); + + $ret[] = update_sql('ALTER TABLE {filters} ALTER delta SET DEFAULT 0'); + $ret[] = update_sql('DROP INDEX {filters}_module_idx'); + + $ret[] = update_sql('DROP INDEX {locales_target}_lid_idx'); + $ret[] = update_sql('DROP INDEX {locales_target}_lang_idx'); + $ret[] = update_sql('CREATE INDEX {locales_target}_locale_idx ON {locales_target}(locale)'); + + $ret[] = update_sql('DROP INDEX {node}_created'); + $ret[] = update_sql('CREATE INDEX {node}_created_idx ON {node}(created)'); + $ret[] = update_sql('DROP INDEX {node}_changed'); + $ret[] = update_sql('CREATE INDEX {node}_changed_idx ON {node}(changed)'); + + $ret[] = update_sql('DROP INDEX {profile_fields}_category'); + $ret[] = update_sql('CREATE INDEX {profile_fields}_category_idx ON {profile_fields}(category)'); + + $ret[] = update_sql('DROP INDEX {url_alias}_dst_idx'); + $ret[] = update_sql('CREATE UNIQUE INDEX {url_alias}_dst_idx ON {url_alias}(dst)'); + + $ret[] = update_sql('CREATE INDEX {sessions}_uid_idx ON {sessions}(uid)'); + $ret[] = update_sql('CREATE INDEX {sessions}_timestamp_idx ON {sessions}(timestamp)'); + + $ret[] = update_sql('ALTER TABLE {accesslog} DROP mask'); + + db_change_column($ret, 'accesslog', 'path', 'path', 'text'); + db_change_column($ret, 'accesslog', 'url', 'url', 'text'); + db_change_column($ret, 'watchdog', 'link', 'link', 'text', array('not null' => TRUE, 'default' => "''")); + db_change_column($ret, 'watchdog', 'location', 'location', 'text', array('not null' => TRUE, 'default' => "''")); + db_change_column($ret, 'watchdog', 'referer', 'referer', 'text', array('not null' => TRUE, 'default' => "''")); + + break; + } + + return $ret; +} + +function system_update_163() { + $ret = array(); + if ($GLOBALS['db_type'] == 'mysql' || $GLOBALS['db_type'] == 'mysqli') { + $ret[] = update_sql('ALTER TABLE {cache} CHANGE data data LONGBLOB'); + } + return $ret; +} + +function system_update_164() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {poll_votes} ( + nid int unsigned NOT NULL, + uid int unsigned NOT NULL default 0, + hostname varchar(128) NOT NULL default '', + INDEX (nid), + INDEX (uid), + INDEX (hostname) + )"); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {poll_votes} ( + nid int NOT NULL, + uid int NOT NULL default 0, + hostname varchar(128) NOT NULL default '' + )"); + $ret[] = update_sql('CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)'); + $ret[] = update_sql('CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)'); + $ret[] = update_sql('CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)'); + break; + } + + $result = db_query('SELECT nid, polled FROM {poll}'); + while ($poll = db_fetch_object($result)) { + foreach (explode(' ', $poll->polled) as $polled) { + if ($polled[0] == '_') { + // $polled is a user id + db_query('INSERT INTO {poll_votes} (nid, uid) VALUES (%d, %d)', $poll->nid, substr($polled, 1, -1)); + } + else { + // $polled is a host + db_query("INSERT INTO {poll_votes} (nid, hostname) VALUES (%d, '%s')", $poll->nid, $polled); + } + } + } + + $ret[] = update_sql('ALTER TABLE {poll} DROP polled'); + + return $ret; +} + +function system_update_165() { + $cron_last = max(variable_get('drupal_cron_last', 0), variable_get('ping_cron_last', 0)); + variable_set('cron_last', $cron_last); + variable_del('drupal_cron_last'); + variable_del('ping_cron_last'); + return array(); +} + +function system_update_166() { + $ret = array(); + + $ret[] = update_sql("DROP TABLE {directory}"); + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $ret[] = update_sql("CREATE TABLE {client} ( + cid int unsigned NOT NULL auto_increment, + link varchar(255) NOT NULL default '', + name varchar(128) NOT NULL default '', + mail varchar(128) NOT NULL default '', + slogan longtext NOT NULL, + mission longtext NOT NULL, + users int NOT NULL default '0', + nodes int NOT NULL default '0', + version varchar(35) NOT NULL default'', + created int NOT NULL default '0', + changed int NOT NULL default '0', + PRIMARY KEY (cid) + )"); + $ret[] = update_sql("CREATE TABLE {client_system} ( + cid int NOT NULL default '0', + name varchar(255) NOT NULL default '', + type varchar(255) NOT NULL default '', + PRIMARY KEY (cid,name) + )"); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {client} ( + cid SERIAL, + link varchar(255) NOT NULL default '', + name varchar(128) NOT NULL default '', + mail varchar(128) NOT NULL default '', + slogan text NOT NULL default '', + mission text NOT NULL default '', + users integer NOT NULL default '0', + nodes integer NOT NULL default '0', + version varchar(35) NOT NULL default'', + created integer NOT NULL default '0', + changed integer NOT NULL default '0', + PRIMARY KEY (cid) + )"); + $ret[] = update_sql("CREATE TABLE {client_system} ( + cid integer NOT NULL, + name varchar(255) NOT NULL default '', + type varchar(255) NOT NULL default '', + PRIMARY KEY (cid,name) + )"); + break; + } + + return $ret; +} + +function system_update_167() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $ret[] = update_sql("ALTER TABLE {vocabulary_node_types} CHANGE type type varchar(32) NOT NULL default ''"); + break; + case 'pgsql': + db_change_column($ret, 'vocabulary_node_types', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''")); + $ret[] = update_sql("ALTER TABLE {vocabulary_node_types} ADD PRIMARY KEY (vid, type)"); + break; + } + + return $ret; +} + +function system_update_168() { + $ret = array(); + + $ret[] = update_sql("ALTER TABLE {term_hierarchy} ADD PRIMARY KEY (tid, parent)"); + + return $ret; +} + +function system_update_169() { + // Warn PGSQL admins if their database is set up incorrectly + if ($GLOBALS['db_type'] == 'pgsql') { + $encoding = db_result(db_query('SHOW server_encoding')); + if (!in_array(strtolower($encoding), array('unicode', 'utf8'))) { + $msg = 'Your PostgreSQL database is set up with the wrong character encoding ('. $encoding .'). It is possible it will not work as expected. It is advised to recreate it with UTF-8/Unicode encoding. More information can be found in the PostgreSQL documentation.'; + watchdog('php', $msg, WATCHDOG_WARNING); + drupal_set_message($msg, 'status'); + } + } + + // Note: 'access' table manually updated in update.php + return _system_update_utf8(array( + 'accesslog', 'aggregator_category', + 'aggregator_category_feed', 'aggregator_category_item', + 'aggregator_feed', 'aggregator_item', 'authmap', 'blocks', + 'book', 'boxes', 'cache', 'comments', 'contact', + 'node_comment_statistics', 'client', 'client_system', 'files', + 'filter_formats', 'filters', 'flood', 'forum', 'history', + 'locales_meta', 'locales_source', 'locales_target', 'menu', + 'node', 'node_access', 'node_revisions', 'profile_fields', + 'profile_values', 'url_alias', 'permission', 'poll', 'poll_votes', + 'poll_choices', 'role', 'search_dataset', 'search_index', + 'search_total', 'sessions', 'sequences', 'node_counter', + 'system', 'term_data', 'term_hierarchy', 'term_node', + 'term_relation', 'term_synonym', 'users', 'users_roles', 'variable', + 'vocabulary', 'vocabulary_node_types', 'watchdog' + )); +} + +function system_update_170() { + if (!variable_get('update_170_done', FALSE)) { + switch ($GLOBALS['db_type']) { + case 'pgsql': + $ret = array(); + db_change_column($ret, 'system', 'schema_version', 'schema_version', 'smallint', array('not null' => TRUE, 'default' => -1)); + break; + + case 'mysql': + case 'mysqli': + db_query('ALTER TABLE {system} CHANGE schema_version schema_version smallint not null default -1'); + break; + } + // Set schema version -1 (uninstalled) for disabled modules (only affects contrib). + db_query('UPDATE {system} SET schema_version = -1 WHERE status = 0 AND schema_version = 0'); + } + return array(); +} + +function system_update_171() { + $ret = array(); + $ret[] = update_sql('DELETE FROM {users_roles} WHERE rid IN ('. DRUPAL_ANONYMOUS_RID. ', '. DRUPAL_AUTHENTICATED_RID. ')'); + return $ret; +} + +function system_update_172() { + // Multi-part update + if (!isset($_SESSION['system_update_172'])) { + $_SESSION['system_update_172'] = 0; + $_SESSION['system_update_172_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments}')); + } + + include_once './'. drupal_get_path('module', 'comment') .'/comment.module'; + + $limit = 20; + $result = db_query_range("SELECT cid, thread FROM {comments} WHERE cid > %d ORDER BY cid ASC", $_SESSION['system_update_172'], 0, $limit); + while ($comment = db_fetch_object($result)) { + $_SESSION['system_update_172'] = $comment->cid; + $thread = explode('.', rtrim($comment->thread, '/')); + foreach ($thread as $i => $offset) { + // Decode old-style comment codes: 1,2,...,9,90,91,92,...,99,990,991,... + $thread[$i] = int2vancode((strlen($offset) - 1) * 10 + substr($offset, -1, 1)); + } + $thread = implode('.', $thread) .'/'; + db_query("UPDATE {comments} SET thread = '%s' WHERE cid = %d", $thread, $comment->cid); + } + + if ($_SESSION['system_update_172'] == $_SESSION['system_update_172_max']) { + unset($_SESSION['system_update_172']); + unset($_SESSION['system_update_172_max']); + return array(); + } + return array('#finished' => $_SESSION['system_update_172'] / $_SESSION['system_update_172_max']); +} + +function system_update_173() { + $ret = array(); + // State tracker to determine whether we keep a backup of the files table or not. + $safe = TRUE; + + // PostgreSQL needs CREATE TABLE foobar _AS_ SELECT ... + $AS = ($GLOBALS['db_type'] == 'pgsql') ? 'AS' : ''; + + // Backup the files table. + $ret[] = update_sql("CREATE TABLE {files_backup} $AS SELECT * FROM {files}"); + + // Do some files table sanity checking and cleanup. + $ret[] = update_sql('DELETE FROM {files} WHERE fid = 0'); + $ret[] = update_sql('UPDATE {files} SET vid = nid WHERE vid = 0'); + + // Create a temporary table to build the new file_revisions and files tables from. + $ret[] = update_sql("CREATE TABLE {files_tmp} $AS SELECT * FROM {files}"); + $ret[] = update_sql('DROP TABLE {files}'); + + switch ($GLOBALS['db_type']) { + case 'pgsql': + // create file_revisions table + $ret[] = update_sql("CREATE TABLE {file_revisions} ( + fid integer NOT NULL default 0, + vid integer NOT NULL default 0, + description varchar(255) NOT NULL default '', + list smallint NOT NULL default 0, + PRIMARY KEY (fid, vid))"); + $result = update_sql("INSERT INTO {file_revisions} SELECT DISTINCT ON (fid,vid) fid, vid, description, list FROM {files_tmp}"); + $ret[] = $result; + if ($result['success'] === FALSE) { + $safe = FALSE; + } + + // Create normalized files table + $ret[] = update_sql("CREATE TABLE {files} ( + fid SERIAL, + nid integer NOT NULL default 0, + filename varchar(255) NOT NULL default '', + filepath varchar(255) NOT NULL default '', + filemime varchar(255) NOT NULL default '', + filesize integer NOT NULL default 0, + PRIMARY KEY (fid))"); + $result = update_sql("INSERT INTO {files} SELECT DISTINCT ON (fid) fid, nid, filename, filepath, filemime, filesize FROM {files_tmp}"); + $ret[] = $result; + if ($result['success'] === FALSE) { + $safe = FALSE; + } + + $ret[] = update_sql("SELECT setval('{files}_fid_seq', max(fid)) FROM {files}"); + + break; + + case 'mysqli': + case 'mysql': + // create file_revisions table + $ret[] = update_sql("CREATE TABLE {file_revisions} ( + fid int unsigned NOT NULL default 0, + vid int unsigned NOT NULL default 0, + description varchar(255) NOT NULL default '', + list tinyint unsigned NOT NULL default 0, + PRIMARY KEY (fid, vid) + ) /*!40100 DEFAULT CHARACTER SET utf8 */"); + + // Try as you might mysql only does distinct row if you are selecting more than 1 column. + $result = update_sql('INSERT INTO {file_revisions} SELECT DISTINCT fid , vid, description, list FROM {files_tmp}'); + $ret[] = $result; + if ($result['success'] === FALSE) { + $safe = FALSE; + } + + $ret[] = update_sql("CREATE TABLE {files} ( + fid int unsigned NOT NULL default 0, + nid int unsigned NOT NULL default 0, + filename varchar(255) NOT NULL default '', + filepath varchar(255) NOT NULL default '', + filemime varchar(255) NOT NULL default '', + filesize int unsigned NOT NULL default 0, + PRIMARY KEY (fid) + ) /*!40100 DEFAULT CHARACTER SET utf8 */"); + $result = update_sql("INSERT INTO {files} SELECT DISTINCT fid, nid, filename, filepath, filemime, filesize FROM {files_tmp}"); + $ret[] = $result; + if ($result['success'] === FALSE) { + $safe = FALSE; + } + + break; + } + + $ret[] = update_sql("DROP TABLE {files_tmp}"); + + // Remove original files table if all went well. Otherwise preserve it and notify user. + if ($safe) { + $ret[] = update_sql("DROP TABLE {files_backup}"); + } + else { + drupal_set_message('Normalizing files table failed. A backup of the original table called {files_backup} remains in your database.'); + } + + return $ret; +} + +function system_update_174() { + // This update (update comments system variables on upgrade) has been removed. + return array(); +} + +function system_update_175() { + $result = db_query('SELECT * FROM {url_alias}'); + while ($path = db_fetch_object($result)) { + $path->src = urldecode($path->src); + $path->dst = urldecode($path->dst); + db_query("UPDATE {url_alias} SET dst = '%s', src = '%s' WHERE pid = %d", $path->dst, $path->src, $path->pid); + } + return array(); +} + +function system_update_176() { + $ret = array(); + $ret[] = update_sql('ALTER TABLE {filter_formats} ADD UNIQUE (name)'); + return $ret; +} + +function system_update_177() { + $ret = array(); + $message_ids = array( + 'welcome_subject' => 'Welcome subject', + 'welcome_body' => 'Welcome body text', + 'approval_subject' => 'Approval subject', + 'approval_body' => 'Approval body text', + 'pass_subject' => 'Password reset subject', + 'pass_body' => 'Password reset body text', + ); + foreach ($message_ids as $message_id => $message_text) { + if ($admin_setting = variable_get('user_mail_'. $message_id, FALSE)) { + // Insert newlines and escape for display as HTML + $admin_setting = nl2br(check_plain($message_text ."\n\n". $admin_setting)); + watchdog('legacy', $admin_setting); + $last = db_fetch_object(db_query('SELECT max(wid) AS wid FROM {watchdog}')); + // Deleting is required, because _user_mail_text() checks for the existance of the variable. + variable_del('user_mail_'. $message_id); + $ret[] = array( + 'query' => strtr('The mail template %message_id has been reset to the default. The old template has been saved.', array('%message_id' => 'user_mail_'. $message_id, '@url' => url('admin/logs/event/'. $last->wid))), + 'success' => TRUE + ); + } + } + return $ret; +} + +function _update_178_url_fix($text) { + // Key is the attribute to replace. + $urlpatterns['href'] = "/]+href=\"([^\"]+)/i"; + $urlpatterns['src'] = "/]+src=\"([^\"]+)/i"; + + $old = $text; + foreach ($urlpatterns as $type => $pattern) { + if (preg_match_all($pattern, $text, $matches)) { + foreach ($matches[1] as $url) { + if ($url != '' && !strstr($url, 'mailto:') && !strstr($url, '://') && !strstr($url, '../') && !strstr($url, './') && $url[0] != '/' && $url[0] != '#') { + $text = preg_replace('|'. $type .'\s*=\s*"'. preg_quote($url) .'\s*"|', $type. '="'.base_path(). $url .'"', $text); + } + } + } + } + return $text != $old ? $text : FALSE; +} + +function _update_178_url_formats() { + $formats = array(); + + // Any format with the HTML filter in it + $result = db_query("SELECT format FROM {filters} WHERE module = 'filter' AND delta = 0"); + while ($format = db_fetch_object($result)) { + $formats[$format->format] = TRUE; + } + + // Any format with only the linebreak filter in it + $result = db_query("SELECT format FROM {filters} WHERE module = 'filter' AND delta = 2"); + while ($format = db_fetch_object($result)) { + if (db_result(db_query('SELECT COUNT(*) FROM {filters} WHERE format = %d', $format->format)) == 1) { + $formats[$format->format] = TRUE; + } + } + + // Any format with 'HTML' in its name + $result = db_query("SELECT format FROM {filter_formats} WHERE name LIKE '%HTML%'"); + while ($format = db_fetch_object($result)) { + $formats[$format->format] = TRUE; + } + + return $formats; +} + +/** + * Update base paths for relative URLs in node and comment content. + */ +function system_update_178() { + + if (variable_get('clean_url', 0) == 1) { + // Multi-part update + if (!isset($_SESSION['system_update_178_comment'])) { + // Check which formats need to be converted + $formats = _update_178_url_formats(); + if (count($formats) == 0) { + return array(); + } + + // Build format query string + $_SESSION['formats'] = array_keys($formats); + $_SESSION['format_string'] = '('. substr(str_repeat('%d, ', count($formats)), 0, -2) .')'; + + // Begin update + $_SESSION['system_update_178_comment'] = 0; + $_SESSION['system_update_178_node'] = 0; + $_SESSION['system_update_178_comment_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments} WHERE format IN '. $_SESSION['format_string'], $_SESSION['formats'])); + $_SESSION['system_update_178_node_max'] = db_result(db_query('SELECT MAX(vid) FROM {node_revisions} WHERE format IN '. $_SESSION['format_string'], $_SESSION['formats'])); + } + + $limit = 20; + + // Comments + if ($_SESSION['system_update_178_comment'] != $_SESSION['system_update_178_comment_max']) { + $args = array_merge(array($_SESSION['system_update_178_comment']), $_SESSION['formats']); + $result = db_query_range("SELECT cid, comment FROM {comments} WHERE cid > %d AND format IN ". $_SESSION['format_string'] .' ORDER BY cid ASC', $args, 0, $limit); + while ($comment = db_fetch_object($result)) { + $_SESSION['system_update_178_comment'] = $comment->cid; + $comment->comment = _update_178_url_fix($comment->comment); + if ($comment->comment !== FALSE) { + db_query("UPDATE {comments} SET comment = '%s' WHERE cid = %d", $comment->comment, $comment->cid); + } + } + } + + // Node revisions + $args = array_merge(array($_SESSION['system_update_178_node']), $_SESSION['formats']); + $result = db_query_range("SELECT vid, teaser, body FROM {node_revisions} WHERE vid > %d AND format IN ". $_SESSION['format_string'] .' ORDER BY vid ASC', $args, 0, $limit); + while ($node = db_fetch_object($result)) { + $_SESSION['system_update_178_node'] = $node->vid; + $set = array(); + $args = array(); + + $node->teaser = _update_178_url_fix($node->teaser); + if ($node->teaser !== FALSE) { + $set[] = "teaser = '%s'"; + $args[] = $node->teaser; + } + + $node->body = _update_178_url_fix($node->body); + if ($node->body !== FALSE) { + $set[] = "body = '%s'"; + $args[] = $node->body; + } + + if (count($set)) { + $args[] = $node->vid; + db_query('UPDATE {node_revisions} SET '. implode(', ', $set) .' WHERE vid = %d', $args); + } + + } + + if ($_SESSION['system_update_178_comment'] == $_SESSION['system_update_178_comment_max'] && + $_SESSION['system_update_178_node'] == $_SESSION['system_update_178_node_max']) { + unset($_SESSION['system_update_178_comment']); + unset($_SESSION['system_update_178_comment_max']); + unset($_SESSION['system_update_178_node']); + unset($_SESSION['system_update_178_node_max']); + return array(); + } + else { + // Report percentage finished + return array('#finished' => + ($_SESSION['system_update_178_comment'] + $_SESSION['system_update_178_node']) / + ($_SESSION['system_update_178_comment_max'] + $_SESSION['system_update_178_node_max']) + ); + } + } + + return array(); +} + +/** + * Update base paths for relative URLs in custom blocks, profiles and various variables. + */ +function system_update_179() { + + if (variable_get('clean_url', 0) == 1) { + // Multi-part update + if (!isset($_SESSION['system_update_179_uid'])) { + // Check which formats need to be converted + $formats = _update_178_url_formats(); + if (count($formats) == 0) { + return array(); + } + + // Custom Blocks (too small for multipart) + $format_string = '('. substr(str_repeat('%d, ', count($formats)), 0, -2) .')'; + $result = db_query("SELECT bid, body FROM {boxes} WHERE format IN ". $format_string, array_keys($formats)); + while ($block = db_fetch_object($result)) { + $block->body = _update_178_url_fix($block->body); + if ($block->body !== FALSE) { + db_query("UPDATE {boxes} SET body = '%s' WHERE bid = %d", $block->body, $block->bid); + } + } + + // Variables (too small for multipart) + $vars = array('site_mission', 'site_footer', 'user_registration_help'); + foreach (node_get_types() as $type => $name) { + $vars[] = $type .'_help'; + } + foreach ($vars as $var) { + $value = variable_get($var, NULL); + if (!is_null($value)) { + $value = _update_178_url_fix($value); + if ($value !== FALSE) { + variable_set($var, $value); + } + } + } + + // See if profiles need to be updated: is the default format HTML? + if (!isset($formats[variable_get('filter_default_format', 1)])) { + return array(); + } + $result = db_query("SELECT fid FROM {profile_fields} WHERE type = 'textarea'"); + $fields = array(); + while ($field = db_fetch_object($result)) { + $fields[] = $field->fid; + } + if (count($fields) == 0) { + return array(); + } + + // Begin multi-part update for profiles + $_SESSION['system_update_179_fields'] = $fields; + $_SESSION['system_update_179_field_string'] = '('. substr(str_repeat('%d, ', count($fields)), 0, -2) .')'; + $_SESSION['system_update_179_uid'] = 0; + $_SESSION['system_update_179_fid'] = 0; + $_SESSION['system_update_179_max'] = db_result(db_query('SELECT MAX(uid) FROM {profile_values} WHERE fid IN '. $_SESSION['system_update_179_field_string'], $_SESSION['system_update_179_fields'])); + } + + // Fetch next 20 profile values to convert + $limit = 20; + $args = array_merge(array($_SESSION['system_update_179_uid'], $_SESSION['system_update_179_fid'], $_SESSION['system_update_179_uid']), $_SESSION['system_update_179_fields']); + $result = db_query_range("SELECT fid, uid, value FROM {profile_values} WHERE ((uid = %d AND fid > %d) OR uid > %d) AND fid IN ". $_SESSION['system_update_179_field_string'] .' ORDER BY uid ASC, fid ASC', $args, 0, $limit); + while ($field = db_fetch_object($result)) { + $_SESSION['system_update_179_uid'] = $field->uid; + $_SESSION['system_update_179_fid'] = $field->fid; + $field->value = _update_178_url_fix($field->value); + if ($field->value !== FALSE) { + db_query("UPDATE {profile_values} SET value = '%s' WHERE uid = %d AND fid = %d", $field->value, $field->uid, $field->fid); + } + + } + + // Done? + if (db_num_rows($result) == 0) { + unset($_SESSION['system_update_179_uid']); + unset($_SESSION['system_update_179_fid']); + unset($_SESSION['system_update_179_max']); + return array(); + } + else { + // Report percentage finished + // (Note: make sure we complete all fields for the last user by not reporting 100% too early) + return array('#finished' => $_SESSION['system_update_179_uid'] / ($_SESSION['system_update_179_max'] + 1)); + } + } + + return array(); +} + +function system_update_180() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {node} DROP PRIMARY KEY"); + $ret[] = update_sql("ALTER TABLE {node} ADD PRIMARY KEY (nid, vid)"); + $ret[] = update_sql("ALTER TABLE {node} DROP INDEX vid"); + $ret[] = update_sql("ALTER TABLE {node} ADD UNIQUE (vid)"); + $ret[] = update_sql("ALTER TABLE {node} ADD INDEX (nid)"); + + $ret[] = update_sql("ALTER TABLE {node_counter} CHANGE nid nid int NOT NULL DEFAULT '0'"); + break; + case 'pgsql': + $ret[] = update_sql("ALTER TABLE {node} DROP CONSTRAINT {node}_pkey"); // Change PK + $ret[] = update_sql("ALTER TABLE {node} ADD PRIMARY KEY (nid, vid)"); + $ret[] = update_sql('DROP INDEX {node}_vid_idx'); // Change normal index to UNIQUE index + $ret[] = update_sql('CREATE UNIQUE INDEX {node}_vid_idx ON {node}(vid)'); + $ret[] = update_sql('CREATE INDEX {node}_nid_idx ON {node}(nid)'); // Add index on nid + break; + } + + return $ret; +} + +function system_update_181() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {profile_fields} ADD autocomplete TINYint NOT NULL AFTER visibility ;"); + break; + case 'pgsql': + db_add_column($ret, 'profile_fields', 'autocomplete', 'smallint', array('not null' => TRUE, 'default' => 0)); + break; + } + return $ret; +} + +/** + * The lid field in pgSQL should not be UNIQUE, but an INDEX. + */ +function system_update_182() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql('ALTER TABLE {locales_target} DROP CONSTRAINT {locales_target}_lid_key'); + $ret[] = update_sql('CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)'); + } + + return $ret; +} + +/** + * @defgroup updates-4.7-to-5.0 System updates from 4.7 to 5.0 + * @{ + */ + +function system_update_1000() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {blocks_roles} ( + module varchar(64) NOT NULL, + delta varchar(32) NOT NULL, + rid int unsigned NOT NULL, + PRIMARY KEY (module, delta, rid) + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {blocks_roles} ( + module varchar(64) NOT NULL, + delta varchar(32) NOT NULL, + rid integer NOT NULL, + PRIMARY KEY (module, delta, rid) + );"); + break; + + } + return $ret; +} + +function system_update_1001() { + // change DB schema for better poll support + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + // alter poll_votes table + $ret[] = update_sql("ALTER TABLE {poll_votes} ADD COLUMN chorder int NOT NULL default -1 AFTER uid"); + break; + + case 'pgsql': + db_add_column($ret, 'poll_votes', 'chorder', 'int', array('not null' => TRUE, 'default' => "'-1'")); + break; + } + + return $ret; +} + +function system_update_1002() { + // Make the forum's vocabulary the highest in list, if present + $ret = array(); + + if ($vid = (int) variable_get('forum_nav_vocabulary', 0)) { + $ret[] = update_sql('UPDATE {vocabulary} SET weight = -10 WHERE vid = '. $vid); + } + + return $ret; +} + +function system_update_1003() { + // Make use of guid in feed items + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {aggregator_item} ADD guid varchar(255) AFTER timestamp ;"); + break; + case 'pgsql': + db_add_column($ret, 'aggregator_item', 'guid', 'varchar(255)'); + break; + } + return $ret; +} + + +function system_update_1004() { + // Increase the size of bid in boxes and aid in access + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {access} CHANGE `aid` `aid` int NOT NULL AUTO_INCREMENT "); + $ret[] = update_sql("ALTER TABLE {boxes} CHANGE `bid` `bid` int NOT NULL AUTO_INCREMENT "); + break; + case 'pgsql': + // No database update required for PostgreSQL because it already uses big SERIAL numbers. + break; + } + return $ret; +} + +function system_update_1005() { + // Add ability to create dynamic node types like the CCK module + $ret = array(); + + // The node_type table may already exist for anyone who ever used CCK in 4.7, + // even if CCK is no longer installed. We need to make sure any previously + // created table gets renamed before we create the new node_type table in + // order to ensure that the new table gets created without errors. + // TODO: This check should be removed for Drupal 6. + if (db_table_exists('node_type')) { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('RENAME TABLE {node_type} TO {node_type_content}'); + break; + + case 'pgsql': + $ret[] = update_sql('ALTER TABLE {node_type} RENAME TO {node_type_content}'); + break; + } + } + + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + // Create node_type table + $ret[] = update_sql("CREATE TABLE {node_type} ( + type varchar(32) NOT NULL, + name varchar(255) NOT NULL, + module varchar(255) NOT NULL, + description mediumtext NOT NULL, + help mediumtext NOT NULL, + has_title tinyint unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body tinyint unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count smallint unsigned NOT NULL, + custom tinyint NOT NULL DEFAULT '0', + modified tinyint NOT NULL DEFAULT '0', + locked tinyint NOT NULL DEFAULT '0', + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; + + case 'pgsql': + // add new unsigned types for pgsql + $ret[] = update_sql("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)"); + $ret[] = update_sql("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)"); + $ret[] = update_sql("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)"); + + $ret[] = update_sql("CREATE TABLE {node_type} ( + type varchar(32) NOT NULL, + name varchar(255) NOT NULL, + module varchar(255) NOT NULL, + description text NOT NULL, + help text NOT NULL, + has_title smallint_unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body smallint_unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count smallint_unsigned NOT NULL, + custom smallint NOT NULL DEFAULT '0', + modified smallint NOT NULL DEFAULT '0', + locked smallint NOT NULL DEFAULT '0', + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) + );"); + break; + } + + // Insert default user-defined node types into the database. + $types = array( + array( + 'type' => 'page', + 'name' => t('Page'), + 'module' => 'node', + 'description' => t('If you want to add a static page, like a contact page or an about page, use a page.'), + 'custom' => TRUE, + 'modified' => TRUE, + 'locked' => FALSE, + ), + array( + 'type' => 'story', + 'name' => t('Story'), + 'module' => 'node', + 'description' => t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.'), + 'custom' => TRUE, + 'modified' => TRUE, + 'locked' => FALSE, + ) + ); + + foreach ($types as $type) { + $type = (object) _node_type_set_defaults($type); + node_type_save($type); + } + + cache_clear_all(); + system_modules(); + menu_rebuild(); + node_types_rebuild(); + + // Migrate old values for 'minimum_x_size' variables to the node_type table. + $query = db_query('SELECT type FROM {node_type}'); + while ($result = db_fetch_object($query)) { + $variable_name = 'minimum_'. $result->type .'_size'; + if ($value = db_fetch_object(db_query("SELECT value FROM {variable} WHERE name = '%s'", $variable_name))) { + $value = (int) unserialize($value->value); + db_query("UPDATE {node_type} SET min_word_count = %d, modified = %d WHERE type = '%s'", $value, 1, $result->type); + variable_del($variable_name); + } + } + + node_types_rebuild(); + + return $ret; +} + +function system_update_1006() { + // Add a customizable title to all blocks. + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {blocks} ADD title VARCHAR(64) NOT NULL DEFAULT ''"); + break; + case 'pgsql': + db_add_column($ret, 'blocks', 'title', 'varchar(64)', array('default' => "''", 'not null' => TRUE)); + break; + } + // Migrate custom block titles to new column. + $boxes = db_query('SELECT bid, title from {boxes}'); + while ($box = db_fetch_object($boxes)) { + db_query("UPDATE {blocks} SET title = '%s' WHERE delta = %d and module = 'block'", $box->title, $box->bid); + } + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {boxes} DROP title'); + break; + case 'pgsql': + $ret[] = update_sql('ALTER TABLE {boxes} DROP COLUMN title'); + break; + } + return $ret; +} + +function system_update_1007() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {aggregator_item} ADD INDEX (fid)"); + break; + case 'pgsql': + $ret[] = update_sql("CREATE INDEX {aggregator_item}_fid_idx ON {aggregator_item} (fid)"); + break; + } + return $ret; +} + +/** + * Performance update for queries that are related to the locale.module + */ +function system_update_1008() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {locales_source} ADD KEY source (source(30))'); + break; + case 'pgsql': + $ret[] = update_sql("CREATE INDEX {locales_source}_source_idx on {locales_source} (source)"); + } + + return $ret; +} + +function system_update_1010() { + $ret = array(); + + // Disable urlfilter.module, if it exists. + if (module_exists('urlfilter')) { + module_disable(array('urlfilter')); + $ret[] = update_sql("UPDATE {filter_formats} SET module = 'filter', delta = 3 WHERE module = 'urlfilter'"); + $ret[] = t('URL Filter module was disabled; this functionality has now been added to core.'); + } + + return $ret; +} + +function system_update_1011() { + $ret = array(); + $ret[] = update_sql('UPDATE {menu} SET mid = 2 WHERE mid = 0'); + cache_clear_all(); + return $ret; +} + +function system_update_1012() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {file_revisions} ADD INDEX(vid)"); + $ret[] = update_sql("ALTER TABLE {files} ADD INDEX(nid)"); + break; + case 'pgsql': + $ret[] = update_sql('CREATE INDEX {file_revisions}_vid_idx ON {file_revisions} (vid)'); + $ret[] = update_sql('CREATE INDEX {files}_nid_idx ON {files} (nid)'); + break; + } + return $ret; +} + +function system_update_1013() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {sessions} CHANGE COLUMN sid sid varchar(64) NOT NULL default ''"); + break; + case 'pgsql': + db_change_column($ret, 'sessions', 'sid', 'sid', 'varchar(64)', array('not null' => TRUE, 'default' => "''")); + break; + } + return $ret; +} + +function system_update_1014() { + variable_del('cron_busy'); + return array(); +} + + +/** + * Add an index on watchdog type. + */ +function system_update_1015() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {watchdog} ADD INDEX (type)'); + break; + case 'pgsql': + $ret[] = update_sql('CREATE INDEX {watchdog}_type_idx ON {watchdog}(type)'); + break; + } + return $ret; +} + +/** + * Allow for longer URL encoded (%NN) UTF-8 characters in the location field of watchdog table. + */ +function system_update_1016() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {watchdog} CHANGE COLUMN location location text NOT NULL"); + break; + case 'pgsql': + db_change_column($ret, 'watchdog', 'location', 'location', 'text', array('not null' => TRUE, 'default' => "''")); + break; + } + return $ret; +} + +/** + * Allow role names to be up to 64 characters. + */ +function system_update_1017() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_change_column($ret, 'role', 'name', 'name', 'varchar(64)', array('not null' => TRUE, 'default' => "''")); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {role} CHANGE name name varchar(64) NOT NULL default ''"); + break; + } + return $ret; +} + +/** + * Change break tag (was removed, see 1020). + */ +function system_update_1018() { + variable_set('update_1020_ok', TRUE); + return array(); +} + +/** + * Change variable format for user-defined e-mails. + */ +function system_update_1019() { + $message_ids = array('welcome_subject', 'welcome_body', + 'approval_subject', 'approval_body', + 'pass_subject', 'pass_body', + ); + foreach ($message_ids as $id) { + // Replace all %vars with !vars + if ($message = variable_get('user_mail_'. $id, NULL)) { + $fixed = preg_replace('/%([A-Za-z_-]+)/', '!\1', $message); + variable_set('user_mail_'. $id, $fixed); + } + } + return array(); +} + +/** + * Change break tag back (was removed from head). + */ +function system_update_1020() { + $ret = array(); + if (!variable_get('update_1020_ok', FALSE)) { + $ret[] = update_sql("UPDATE {node_revisions} SET body = REPLACE(body, '', '')"); + } + variable_del('update_1020_ok'); + return $ret; +} + +/** + * Update two more variables that were missing from system_update_1019. + */ +function system_update_1021() { + $message_ids = array('admin_body', 'admin_subject'); + foreach ($message_ids as $id) { + // Replace all %vars with !vars + if ($message = variable_get('user_mail_'. $id, NULL)) { + $fixed = preg_replace('/%([A-Za-z_-]+)/', '!\1', $message); + variable_set('user_mail_'. $id, $fixed); + } + } + return array(); +} + +/** + * @} End of "defgroup updates-4.7-to-5.0" + */ + + +/** + * @defgroup updates-5.x-extra Extra system updates for 5.x + * @{ + */ + +/** + * Add index on users created column. + */ +function system_update_1022() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {users} ADD KEY created (created)'); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE INDEX {users}_created_idx ON {users} (created)"); + break; + } + // Also appears as system_update_2004(). Ensure we don't update twice. + variable_set('system_update_1022', TRUE); + return $ret; +} + +/** + * @} End of "defgroup updates-5.x-extra" + */ + +/** + * @defgroup updates-5.0-to-x.x System updates from 5.0 to x.x + * @{ + * @todo Start this series of updates at 2000. + */ + +/** + * Remove auto_increment from {boxes} to allow adding custom blocks with + * visibility settings. + */ +function system_update_2000() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $max = (int)db_result(db_query('SELECT MAX(bid) FROM {boxes}')); + $ret[] = update_sql('ALTER TABLE {boxes} CHANGE COLUMN bid bid int NOT NULL'); + $ret[] = update_sql("REPLACE INTO {sequences} VALUES ('{boxes}_bid', $max)"); + break; + } + return $ret; +} + +/** + * Add version id column to {term_node} to allow taxonomy module to use revisions. + */ +function system_update_2001() { + $ret = array(); + // Add revision id to term-node relation. + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {term_node} ADD vid int NOT NULL default '0'"); + $ret[] = update_sql('ALTER TABLE {term_node} DROP PRIMARY KEY'); + $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid,vid)'); + $ret[] = update_sql('ALTER TABLE {term_node} ADD KEY vid (vid)'); + break; + + case 'pgsql': + db_add_column($ret, 'term_node', 'vid', 'int', array('not null' => TRUE, 'default' => 0)); + $ret[] = update_sql("ALTER TABLE {term_node} DROP CONSTRAINT {term_node}_pkey"); + $ret[] = update_sql("ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid,vid)"); + $ret[] = update_sql("CREATE INDEX {term_node}_vid_idx ON {term_node} (vid)"); + break; + } + // Update all entries with the current revision number. + $nodes = db_query('SELECT nid, vid FROM {node}'); + while ($node = db_fetch_object($nodes)) { + db_query('UPDATE {term_node} SET vid = %d WHERE nid = %d', $node->vid, $node->nid); + } + return $ret; +} + +/** + * Increase the maximum length of variable names from 48 to 128. + */ +function system_update_2002() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'pgsql': + db_change_column($ret, 'variable', 'name', 'name', 'varchar(128)', array('not null' => TRUE, 'default' => "''")); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {variable} CHANGE name name varchar(128) NOT NULL default ''"); + break; + } + return $ret; +} + +/** + * Add index on comments status column. + */ +function system_update_2003() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {comments} ADD KEY status (status)'); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE INDEX {comments}_status_idx ON {comments} (status)"); + break; + } + return $ret; +} + +/** + * Add index on users created column. + */ +function system_update_2004() { + // Already run as system_update_1022? + if (variable_get('system_update_1022', FALSE)) { + variable_del('system_update_1022'); + return array(); + } + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {users} ADD KEY created (created)'); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE INDEX {users}_created_idx ON {users} (created)"); + break; + } + return $ret; +} + +/** + * @} End of "defgroup updates-5.0-to-x.x" + * The next series of updates should start at 3000. + */ diff -urNp drupal6/sites/default/modules/contrib-5/coder/coder.css drupal6lang/sites/default/modules/contrib-5/coder/coder.css --- drupal6/sites/default/modules/contrib-5/coder/coder.css 2007-02-14 09:05:24.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/coder.css 1969-12-31 19:00:00.000000000 -0500 @@ -1,16 +0,0 @@ -/* $Id: coder.css,v 1.2.2.3 2007/02/14 14:05:24 drupalgreen Exp $ */ - -img.coder { - padding: 2px; -} - -.coder-normal { - background-color: #ffd; -} - -.coder-minor { -} - -.coder-critical { - background-color: #ffe7dd; -} diff -urNp drupal6/sites/default/modules/contrib-5/coder/coder.info drupal6lang/sites/default/modules/contrib-5/coder/coder.info --- drupal6/sites/default/modules/contrib-5/coder/coder.info 2007-02-13 09:03:51.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/coder.info 1969-12-31 19:00:00.000000000 -0500 @@ -1,5 +0,0 @@ -; $Id: coder.info,v 1.4.4.1 2007/02/13 14:03:51 drupalgreen Exp $ -name = Coder -description = Developer Module that assists with code review and version upgrade -version = "$Name: DRUPAL-5 $" -package = Development diff -urNp drupal6/sites/default/modules/contrib-5/coder/coder.js drupal6lang/sites/default/modules/contrib-5/coder/coder.js --- drupal6/sites/default/modules/contrib-5/coder/coder.js 2007-02-17 14:30:48.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/coder.js 1969-12-31 19:00:00.000000000 -0500 @@ -1,54 +0,0 @@ -// $Id: coder.js,v 1.1.2.3 2007/02/17 19:30:48 drupalgreen Exp $ - -if (Drupal.jsEnabled) { - jQuery.fn.extend({ - check : function() { return this.each(function() { this.checked = true; }); }, - uncheck : function() { return this.each(function() { this.checked = false; }); } - }); - - $(document).ready( - function() { - $("input:checkbox").click( - function() { - core = this.form.elements.namedItem("edit-coder-core"); - active = this.form.elements.namedItem("edit-coder-active-modules"); - if (this == core || this == active) { - modules = "input[@id^=edit-coder-modules-]"; - themes = "input[@id^=edit-coder-themes-]"; - if (core.checked || active.checked) { - $(modules).uncheck(); - $(themes).uncheck(); - if (core.checked) { - modules += '.coder-core'; - themes += '.coder-core'; - } - if (active.checked) { - modules += '.coder-active'; - themes += '.coder-active'; - } - $(modules).check(); - $(themes).check(); - } - else { - if (this == active) { - modules += ".coder-active"; - themes += ".coder-active"; - } - else { - modules += ".coder-core"; - themes += ".coder-core"; - } - $(modules).uncheck(); - $(themes).uncheck(); - } - } - else if (this.id.substr(0, 19) == "edit-coder-modules-" || this.id.substr(0, 18) == "edit-coder-themes-") { - core.checked = false; - active.checked = false; - } - return true; - } - ); - } - ); -} diff -urNp drupal6/sites/default/modules/contrib-5/coder/coder.module drupal6lang/sites/default/modules/contrib-5/coder/coder.module --- drupal6/sites/default/modules/contrib-5/coder/coder.module 2007-02-18 00:28:01.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/coder.module 1969-12-31 19:00:00.000000000 -0500 @@ -1,1126 +0,0 @@ -filename); - $_coder_coders[] = $file->name; - } -} - -/** - * Get all of the code review modules - */ -function _coder_reviews() { - $reviews = array(); - - // get the review definitions from the include directory - global $_coder_coders; - if ($_coder_coders) { - foreach ($_coder_coders as $coder) { - $function = $coder .'_reviews'; - if (function_exists($function)) { - if ($review = call_user_func($function)) { - $reviews = array_merge($reviews, $review); - } - } - } - } - - // get the contributed module review definitions - if ($review = module_invoke_all('reviews')) { - $reviews = array_merge($reviews, $review); - } - - return $reviews; -} - -/** - * Implementation of hook_cron(). - */ -function coder_cron() { - if ($use_cache = variable_get('coder_cache', 1)) { - // TODO: move some of the work here... is this really worth it? - } -} - -/** - * Implementation of hook_perm(). - */ -function coder_perm() { - return array('view code review', 'view code review all'); -} - -/** - * Implementation of hook_menu(). - */ -function coder_menu($may_cache = TRUE) { - $items = array(); - - if ($may_cache) { - if (substr(VERSION, 0, 1) == '6') { - $items['coder'] = array( - 'title' => t('Code review'), - 'page callback' => 'coder_page', - 'access arguments' => array('view code review'), - 'type' => MENU_NORMAL_ITEM, - ); - $items['coder/settings'] = array( - 'title' => t('Selection Form'), - 'page callback' => 'coder_page', - 'access arguments' => array('view code review'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -2, - ); - $items['coder/default'] = array( - 'title' => t('Default'), - 'page callback' => 'coder_page', - 'access arguments' => array('view code review'), - 'type' => MENU_LOCAL_TASK, - 'weight' => -1, - ); - $items['coder/core'] = array( - 'title' => t('Core'), - 'page callback' => 'coder_page', - 'access arguments' => array('view code review'), - 'type' => MENU_LOCAL_TASK, - ); - $items['coder/active'] = array( - 'title' => t('Active'), - 'page callback' => 'coder_page', - 'access arguments' => array('view code review'), - 'type' => MENU_LOCAL_TASK, - ); - $items['coder/all'] = array( - 'title' => t('All'), - 'page callback' => 'coder_page', - 'access arguments' => array('view code review all'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 1, - ); - $items['admin/settings/coder'] = array( - 'title' => t('Code review'), - 'description' => t('Select code review plugins and modules'), - 'page callback' => 'drupal_get_form', - 'page arguments' => array('coder_admin_settings'), - 'access arguments' => array('administer site configuration'), - ); - } - else { - $items[] = array( - 'path' => 'coder', - 'title' => t('Code review'), - 'callback' => 'coder_page', - 'access' => user_access('view code review'), - 'type' => MENU_NORMAL_ITEM, - ); - $items[] = array( - 'path' => 'coder/settings', - 'title' => t('Selection Form'), - 'callback' => 'coder_page', - 'access' => user_access('view code review'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -2, - ); - $items[] = array( - 'path' => 'coder/default', - 'title' => t('Default'), - 'callback' => 'coder_page', - 'access' => user_access('view code review'), - 'type' => MENU_LOCAL_TASK, - 'weight' => -1, - ); - $items[] = array( - 'path' => 'coder/core', - 'title' => t('Core'), - 'callback' => 'coder_page', - 'access' => user_access('view code review'), - 'type' => MENU_LOCAL_TASK, - ); - $items[] = array( - 'path' => 'coder/active', - 'title' => t('Active'), - 'callback' => 'coder_page', - 'access' => user_access('view code review'), - 'type' => MENU_LOCAL_TASK, - ); - $items[] = array( - 'path' => 'coder/all', - 'title' => t('All'), - 'callback' => 'coder_page', - 'access' => user_access('view code review all'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 1, - ); - $items[] = array( - 'path' => 'admin/settings/coder', - 'title' => t('Code review'), - 'description' => t('Select code review plugins and modules'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'coder_admin_settings', - 'access' => user_access('administer site configuration'), - ); - } - } - - return $items; -} - -/** - * Implementation of hook_form_alter(). - */ -function coder_form_alter($form_id, &$form) { - if ($form_id == 'system_modules') { - if (user_access('view code review')) { - foreach ($form['name'] as $name => $data) { - $form['name'][$name]['#value'] = l($data['#value'], "coder/$name"); - } - } - } -} - -/** - * Helper functions for settings form - */ -function _coder_default_reviews() { - return drupal_map_assoc(array('style', 'security')); -} - -function _coder_settings_form($settings, &$system, &$files) { - // add the javascript - $path = drupal_get_path('module', 'coder'); - drupal_add_js($path .'/coder.js'); - - // create the list of review options from the coder review plug-ins - $reviews = _coder_reviews(); - foreach ($reviews as $name => $review) { - $review_options[$name] = l($review['#title'], $review['#link']); - } - - // what review standards should be applied - $form['coder_reviews_group'] = array( - '#type' => 'fieldset', - '#title' => t('Reviews'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - ); - $form['coder_reviews_group']['coder_reviews'] = array( - '#type' => 'checkboxes', - '#options' => $review_options, - '#description' => t('apply the checked coding reviews'), - '#default_value' => $settings['coder_reviews'], - ); - $form['coder_reviews_group']['coder_severity'] = array( - '#type' => 'radios', - '#options' => array( - 1 => 'minor (most)', - 5 => 'normal', - 9 => 'critical (fewest)' - ), - '#description' => t('show warnings at or above the severity warning level'), - '#default_value' => $settings['coder_severity'], - ); - - // get the modules and theme - $sql = "SELECT name, filename, type, status FROM {system} WHERE type='module' OR type='theme' ORDER BY weight ASC, filename ASC"; - $result = db_query($sql); - $system_modules = array(); - $system_themes = array(); - while ($system = db_fetch_object($result)) { - $display_name = $system->name; - if ($system->status) { - $display_name .= t(' (active)'); - $system_active[$system->name] = $system->name; - } - if (_coder_is_drupal_core($system)) { - $display_name .= t(' (core)'); - $system_core[$system->name] = $system->name; - } - if ($system->type == 'module') { - $system_modules[$system->name] = $system->name; - } - else { - $system_themes[$system->name] = $system->name; - } - $system_links[$system->name] = l($display_name, "coder/$system->name"); - $files[$system->name] = $system->filename; - } - - // display what to review options - $form['coder_what'] = array( - '#type' => 'fieldset', - '#title' => t('What to review'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - ); - $form['coder_what']['coder_active_modules'] = array( // NOTE: should rename var - '#type' => 'checkbox', - '#default_value' => isset($settings['coder_active_modules']) ? $settings['coder_active_modules'] : 0, - '#title' => t('active modules and themes'), - ); - $form['coder_what']['coder_core'] = array( - '#type' => 'checkbox', - '#default_value' => isset($settings['coder_core']) ? $settings['coder_core'] : 0, - '#title' => t('core files (php, modules, and includes)'), - ); - $form['coder_what']['coder_includes'] = array( - '#type' => 'checkbox', - '#default_value' => $settings['coder_includes'], - '#title' => t('include files (.inc and .php files)'), - ); - if (arg(0) == 'admin') { - $form['coder_what']['coder_cache'] = array( - '#type' => 'checkbox', - '#default_value' => $settings['coder_cache'], - '#title' => t('use the experimental coder cache'), - ); - } - - // display the modules in a fieldset - $form['coder_what']['coder_modules'] = array( - '#type' => 'fieldset', - '#title' => t('Select Specific Modules'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - if (isset($settings['coder_all'])) { - $modules = $system_modules; - } - elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) { - if (isset($settings['coder_core']) && $settings['coder_core']) { - $modules = array_intersect($system_active, $system_core); - $modules = array_intersect($modules, $system_modules); - } - else { - $modules = array_intersect($system_active, $system_modules); - } - } - elseif (isset($settings['coder_core']) && $settings['coder_core']) { - $modules = array_intersect($system_core, $system_modules); - } - elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) { - $modules = array_intersect($system_active, $system_modules); - } - else { - $modules = isset($settings['coder_modules']) && is_array($settings['coder_modules']) ? $settings['coder_modules'] : array(); - } - - // display the themes in a fieldset - $form['coder_what']['coder_themes'] = array( - '#type' => 'fieldset', - '#title' => t('Select Specific Themes'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - if (isset($settings['coder_all'])) { - $themes = $system_themes; - } - elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) { - if (isset($settings['coder_core']) && $settings['coder_core']) { - $themes = array_intersect($system_active, $system_core); - $themes = array_intersect($themes, $system_themes); - } - else { - $themes = array_intersect($system_active, $system_themes); - } - } - elseif (isset($settings['coder_core']) && $settings['coder_core']) { - $themes = array_intersect($system_core, $system_themes); - } - elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) { - $themes = array_intersect($system_active, $system_themes); - } - else { - $themes = isset($settings['coder_themes']) && is_array($settings['coder_themes']) ? $settings['coder_themes'] : array(); - } - - foreach ($system_links as $name => $link) { - $classes = array(); - if (in_array($name, $system_active)) { - $classes[] = "coder-active"; - } - if (in_array($name, $system_core)) { - $classes[] = "coder-core"; - } - if (in_array($name, $system_themes)) { - $type = 'theme'; - $default_value = isset($themes[$name]); - } - else { - $type = 'module'; - $default_value = isset($modules[$name]); - } - $form['coder_what']["coder_${type}s"]["coder_${type}s-$name"] = array( - '#type' => 'checkbox', - '#title' => $link, - '#default_value' => $default_value, - '#attributes' => array('class' => implode(' ', $classes)), - ); - } - - $system = array_merge($modules, $themes); - return $form; -} - -/** - * Implementation of settings page for Drupal 5 - */ -function coder_admin_settings() { - $settings = _coder_get_default_settings(); - $form = _coder_settings_form($settings, $system, $files); - $form['#submit']['coder_settings_form_submit'] = array(); - $form['#submit']['system_settings_form_submit'] = array(); - return system_settings_form($form); -} - -function coder_settings_form_submit($form_id, &$form_values) { - variable_set('coder_modules', _coder_settings_array($form_values, 'module')); - variable_set('coder_themes', _coder_settings_array($form_values, 'theme')); -} - -function _coder_settings_array(&$form_values, $type) { - $typekey = "coder_{$type}s-"; - $typelen = strlen($typekey); - $systems = array(); - foreach ($form_values as $key => $value) { - if (substr($key, 0, $typelen) == $typekey) { - if ($value == 1) { - $system = substr($key, $typelen); - $systems[$system] = 1; - } - unset($form_values[$key]); - } - } - return $systems; -} - -function coder_page_form_submit($form_id, $form_values) { - // HELP: is there a better way to get these to coder_page_form()??? - return FALSE; -} - -/** - * Implementation of code review page - */ -function coder_page() { - return drupal_get_form('coder_page_form'); -} - -function _coder_get_default_settings($args = 'default') { - $settings['coder_reviews'] = variable_get('coder_reviews', _coder_default_reviews()); - $settings['coder_severity'] = variable_get('coder_severity', 5); - $settings['coder_cache'] = variable_get('coder_cache', 1); - - // determine any options based on the passed in URL, - switch ($args) { - case 'settings': - $settings['coder_includes'] = 1; - break; - - case 'active': - $settings['coder_active_modules'] = 1; - break; - - case 'core': - $settings['coder_core'] = 1; - $settings['coder_includes'] = 1; - break; - - case 'all': - $settings['coder_core'] = 1; - $settings['coder_includes'] = 1; - $settings['coder_all'] = 1; - break; - - case 'default': - $settings['coder_active_modules'] = variable_get('coder_active_modules', 1); - $settings['coder_core'] = variable_get('coder_core', 0); - $settings['coder_includes'] = variable_get('coder_includes', 0); - $settings['coder_modules'] = variable_get('coder_modules', array()); - $settings['coder_themes'] = variable_get('coder_themes', array()); - break; - - default: - $settings['coder_includes'] = 1; - // TODO: does this need to go into coder_themes sometimes? - $settings['coder_modules'] = array($args => $args); - break; - } - return $settings; -} - -function coder_page_form() { - // HELP: is there a better way to get these from coder_page_form_submit()??? - $form_values = $_POST; - if (isset($form_values['op'])) { - $settings = $form_values; - $settings['coder_modules'] = _coder_settings_array($form_values, 'module'); - $settings['coder_themes'] = _coder_settings_array($form_values, 'theme'); - drupal_set_title(t('Code review (submitted options)')); - } - else { - $options = arg(1); - $settings = _coder_get_default_settings($options); - if ($options) { - drupal_set_title(t('Code review (@options)', array('@options' => isset($options) ? $options : 'default options'))); - } - } - - // get this once - list of the reviews to perform - $reviews = array(); - $avail_reviews = _coder_reviews(); - $selected_reviews = $settings['coder_reviews']; - foreach ($selected_reviews as $name => $checked) { - if ($checked) { - $reviews[$name] = $avail_reviews[$name]; - } - } - - if ($coder_form = _coder_settings_form($settings, $system, $files)) { - // add style sheet - $path = drupal_get_path('module', 'coder'); - drupal_add_css($path .'/coder.css', 'module'); - - // code review non-module core files - $module_weight = 0; - if (isset($settings['coder_core']) && $settings['coder_core']) { - $coder_args = array( - '#reviews' => $reviews, - '#severity' => $settings['coder_severity'], - '#filename' => $filename, - ); - - $form['core_php'] = array( - '#type' => 'fieldset', - '#title' => 'core (php)', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => ++ $module_weight, - ); - $phpfiles = file_scan_directory('.', '.*\.php', array('.', '..', 'CVS'), 0, FALSE, 'name', 0); - _coder_page_form_includes($form, $coder_args, 'core_php', $phpfiles, 2); - - $form['core_includes'] = array( - '#type' => 'fieldset', - '#title' => 'core (includes)', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => ++ $module_weight, - ); - $includefiles = drupal_system_listing('.*\.inc$', 'includes', 'name', 0); - _coder_page_form_includes($form, $coder_args, 'core_includes', $includefiles, 0); - } - - // loop through the selected modules and themes - if (isset($system)) { - $dups = array(); // used to avoid duplicate includes - foreach ($system as $name => $checked) { - if ($checked) { - // process this one file - $filename = $files[$name]; - if (!$filename) { - drupal_set_message(t('Code Review file for %module not found', array('%module' => $name))); - continue; - } - $coder_args = array( - '#reviews' => $reviews, - '#severity' => $settings['coder_severity'], - '#filename' => $filename, - ); - $results = do_coder_reviews($coder_args); - - // output the results in a collapsible fieldset - $form[$name] = array( - '#type' => 'fieldset', - '#title' => $filename, - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => ++ $module_weight, - ); - if (count($results) == 0) { - $results[] = t('No Problems Found'); - } - else { - $form[$name]['#collapsed'] = FALSE; - } - $form[$name]['output'] = array( - '#value' => theme('coder', $name, $filename, $results), - '#weight' => -1, - ); - - // process the same directory include files - if ($settings['coder_includes']) { - // NOTE: convert to the realpath here so drupal_system_listing - // doesn't return additional paths (i.e., try "module"). - $path = str_replace('\\', '/', dirname(realpath($filename))); - $offset = strpos($path, dirname($filename)); - if (!isset($dups[$path])) { - if (substr($filename, -7) == '.module') { - $coder_args['#php_minor'] = 1; - } - $dups[$path] = 1; - $includefiles = drupal_system_listing('.*\.(inc|php)$', $path, 'name', 0); - _coder_page_form_includes($form, $coder_args, $name, $includefiles, $offset); - } - } - } - } - } - - // prepend the settings form - $form['settings'] = array( - '#type' => 'fieldset', - '#title' => t('Selection Form'), - '#collapsible' => TRUE, - '#collapsed' => isset($form), - '#weight' => -1, - ); - if ($form['settings']['#collapsed']) { - $form['settings']['#prefix'] = t('
Use the Selection Form to select options for this code review, or change the Default Settings and use the Default tab above.
', array('@settings' => url('admin/settings/coder'), '@default' => url('coder/default'))); - } - $form['settings'][] = $coder_form; - $form['settings']['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - $form['#action'] = url('coder'); - } - return $form; -} - -function _coder_page_form_includes(&$form, $coder_args, $name, $files, $offset) { - $coder_args['#name'] = $name; - foreach ($files as $file) { - $filename = drupal_substr($file->filename, $offset); - $coder_args['#filename'] = $filename; - $results = do_coder_reviews($coder_args); - - // output the results in a collapsible fieldset - $form[$name][$filename] = array( - '#type' => 'fieldset', - '#title' => $filename, - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => ++ $weight, - ); - if (count($results) == 0) { - $results[] = t('No Problems Found'); - } - else { - $form[$name][$filename]['#collapsed'] = FALSE; - $form[$name]['#collapsed'] = FALSE; - } - $form[$name][$filename]['output'] = array( - '#value' => theme('coder', $name, $filename, $results), - ); - } -} - -function _coder_modified() { - static $_coder_mtime; - if (!isset($_coder_mtime)) { - $path = drupal_get_path('module', 'coder'); - $includefiles = drupal_system_listing('.*\.(inc|module)$', $path, 'name', 0); - $_coder_mtime = 0; - foreach ($includefiles as $file) { - $mtime = filemtime(realpath($file->filename)); - if ($mtime > $_coder_mtime) { - $_coder_mtime = $mtime; - } - } - } - return $_coder_mtime; -} - -function do_coder_reviews($coder_args) { - // the cache is still experimental, so users must enable it - if ($use_cache = variable_get('coder_cache', 1)) { - // cache the results because: - $cache_key = 'coder:'. implode(':', array_keys($coder_args['#reviews'])) . $coder_args['#severity'] .':'. $coder_args['#filename']; - $cache_mtime = filemtime(realpath($coder_args['#filename'])); - if ($cache_serialized_results = cache_get($cache_key)) { - $cache_results = unserialize($cache_serialized_results->data); - - if ($cache_results['mtime'] == $cache_mtime && _coder_modified() < $cache_serialized_results->created) { - return $cache_results['results']; - } - } - } - - $results = array(); - - // skip php include files when the user requested severity is above minor - if ($coder_args['#php_minor'] && drupal_substr($coder_args['#filename'], -4) == '.php') { - if ($coder_args['#severity'] > 1) { - return $results; - } - } - - // read the file - if (_coder_read_and_parse_file($coder_args)) { - // do all of the code reviews - foreach ($coder_args['#reviews'] as $review) { - if ($result = do_coder_review($coder_args, $review)) { - $results += $result; - } - } - - // sort the results - ksort($results, SORT_NUMERIC); - } - else { - _coder_error_msg($results, t('Could not read the file'), 'critical'); - } - - // save the results in the cache - if ($use_cache) { - $cache_results = array( - 'mtime' => $cache_mtime, - 'results' => $results, - ); - cache_set($cache_key, 'cache', serialize($cache_results)); - } - - return $results; -} - -function _coder_read_and_parse_file(&$coder_args) { - // get the path to the module file - if ($filepath = realpath($coder_args['#filename'])) { - // read the file - $content = file_get_contents($filepath); - $content_length = drupal_strlen($content); - - // parse the file: - // - strip comments - // - strip quote content // - strip stuff not in php // - break into lines - $lineno = 0; - for ($pos = 0; $pos < $content_length; $pos ++) { - // get the current character - $char = $content[$pos]; - if ($char == "\n") { - if ($in_comment == '/') { // end C++ style comments on newline - unset($in_comment); - } - - // assume that html inside quotes doesn't span newlines - unset($in_quote_html); - - // remove blank lines now, so we avoid processing them over-and-over - if (trim($all_lines[$lineno]) == '') { - unset($all_lines[$lineno]); - } - if (trim($php_lines[$lineno]) == '') { - unset($php_lines[$lineno]); - } - if (trim($html_lines[$lineno]) == '') { - unset($html_lines[$lineno]); - } - - $lineno ++; - $beginning_of_line = 1; - continue; - } - $all_lines[$lineno] .= $char; - - if ($in_php) { - // look for the ending php tag which tags precedence over everything - if ($char == '?' && $content[$pos + 1] == '>') { - unset($char); - unset($in_php); - $all_lines[$lineno] .= '>'; - $pos ++; - } - - // when in a quoted string, look for the trailing quote - // strip characters in the string, replacing with '' or "" - elseif ($in_quote) { - if ($in_backslash) { - unset($in_backslash); - } - elseif ($char == '\\') { - $in_backslash = '\\'; - } - elseif ($char == $in_quote && !$in_backslash) { - unset($in_quote); - } - elseif ($char == '<') { - $in_quote_html = '>'; - } - if ($in_quote && $in_quote_html) { - $html_lines[$lineno] .= $char; - } - if ($char == $in_quote_html) { - unset($in_quote_html); - } - unset($char); // NOTE: trailing char output with starting one - } - - elseif ($in_heredoc) { - if ($beginning_of_line && $char == $in_heredoc[0] && substr($content, $pos, $in_heredoc_length) == $in_heredoc) { - $all_lines[$lineno] .= substr($content, $pos + 1, $in_heredoc_length - 1); - unset($in_heredoc); - $pos += $in_heredoc_length; - } - elseif ($char == '<') { - $in_heredoc_html = '>'; - } - if ($in_heredoc && $in_heredoc_html) { - $html_lines[$lineno] .= $char; - } - if ($char == $in_heredoc_html) { - unset($in_heredoc_html); - } - unset($char); - } - - // when in a comment look for the trailing comment - elseif ($in_comment) { - if ($in_comment == '*' && $char == '*' && $content[$pos + 1] == '/') { - unset($in_comment); - $all_lines[$lineno] .= '/'; - $pos ++; - } - unset($char); // don't add comments to php output - } - - else { - switch ($char) { - case '\'': - case '"': - if ($content[$pos - 1] != '\\') { - $php_lines[$lineno] .= $char; - $in_quote = $char; - } - break; - - case '/': - $next_char = $content[$pos + 1]; - if ($next_char == '/' || $next_char == '*') { - unset($char); - $in_comment = $next_char; - $all_lines[$lineno] .= $next_char; - $pos ++; - } - break; - - case '<': - if ($content[$pos + 1] == '<' && $content[$pos + 2] == '<') { - unset($char); - $all_lines[$lineno] .= '<<'; - - // get the heredoc word - // read until the end-of-line - for ($pos += 3; $pos < $content_length; $pos ++) { - $char = $content[$pos]; - if ($char == "\n") { - $pos --; - if (preg_match('/^\s+(\w+)/', $heredoc, $match)) { - $in_heredoc = $match[1]; - $in_heredoc_length = drupal_strlen($in_heredoc); - } - break; - } - $all_lines[$lineno] .= $char; - $heredoc .= $char; - } - unset($heredoc); - - // replace heredoc's with an empty string - $php_lines[$lineno] .= "''"; - unset($char); - } - break; - } - } - if (isset($char)) { - $php_lines[$lineno] .= $char; - } - } - else { - switch ($char) { - case '<': - if ($content[$pos + 1] == '?') { - if ($content[$pos + 2] == ' ') { - $in_php = 1; - $all_lines[$lineno] .= '? '; - $pos += 2; - } - elseif (substr($content, $pos + 2, 3) == 'php') { - $in_php = 1; - $all_lines[$lineno] .= '?php'; - $pos += 4; - } - break; - } - // FALTHROUGH - default: - $html_lines[$lineno] .= $char; - break; - } - } - } - - // add the files lines to the arguments - $coder_args['#all_lines'] = $all_lines; - $coder_args['#php_lines'] = $php_lines; - $coder_args['#html_lines'] = $html_lines; - return 1; - } -} - -function _coder_severity($severity_name, $default_value = 5) { - // NOTE: implemented this way in hopes that it is faster than a php switch - if (!isset($severity_names)) { - $severity_names = array( - 'minor' => 1, - 'normal' => 5, - 'critical' => 9, - ); - } - if (isset($severity_names[$severity_name])) { - return $severity_names[$severity_name]; - } - return $default_value; -} - -function _coder_severity_name($coder_args, $review, $rule) { - // NOTE: warnings in php includes are suspicious because - // php includes are frequently 3rd party products - if ($coder_args['#php_minor'] && substr($coder_args['#filename'], -4) == '.php') { - return 'minor'; - } - - // get the severity as defined by the rule - if (isset($rule['#severity'])) { - return $rule['#severity']; - } - - // if it's not defined in the rule, then it can be defined by the review - if (isset($review['#severity'])) { - return $review['#severity']; - } - - // use the default - return 'normal'; -} - -function do_coder_review($coder_args, $review) { - $results = array(); - if ($review['#rules']) { - // get the review's severity, used when the rule severity is not defined - $default_severity = _coder_severity($review['#severity']); - - foreach ($review['#rules'] as $rule) { - // perform the review if above the user requested severity - $severity = _coder_severity($rule['#severity'], $default_severity); - if ($severity >= $coder_args['#severity']) { - if (isset($rule['#original'])) { // deprecated - $lines = $coder_args['#all_lines']; - } - elseif (isset($rule['#source'])) { // all, html, comment, or php - $source = '#'. $rule['#source'] .'_lines'; - $lines = $coder_args[$source]; - } - else { - $lines = $coder_args['#php_lines']; - } - if ($lines) { - switch ($rule['#type']) { - case 'regex': - do_coder_review_regex($coder_args, $review, $rule, $lines, $results); - break; - case 'grep': - do_coder_review_grep($coder_args, $review, $rule, $lines, $results); - break; - case 'callback': - do_coder_review_callback($coder_args, $review, $rule, $lines, $results); - break; - } - } - } - } - } - return $results; -} - -function do_coder_review_regex(&$coder_args, $review, $rule, $lines, &$results) { - if ($regex = $rule['#value']) { - $regex = '/'. $regex .'/i'; - foreach ($lines as $lineno => $line) { - if (preg_match($regex, $line, $matches)) { - // don't match some regex's - if ($not = $rule['#not']) { - foreach ($matches as $match) { - if (preg_match('/'. $not .'/i', $match)) { - continue 2; - } - } - } - - $line = $coder_args['#all_lines'][$lineno]; - $severity_name = _coder_severity_name($coder_args, $review, $rule); - _coder_error($results, $rule, $severity_name, $lineno, $line); - } - } - } -} - -function _coder_error(&$results, $rule, $severity_name, $lineno = -1, $line = '', $original = '') { - if (isset($rule['#warning_callback'])) { - if (function_exists($rule['#warning_callback'])) { - $warning = $rule['#warning_callback'](); - } - else { // if this happens, there is an error in the rule definition - $warning = t('please report this !warning', - array( - '@report' => 'http://drupal.org/node/add/project_issue/coder/bug', - '!warning' => $rule['#warning_callback'], - ) - ); - } - } - else { - $warning = t($rule['#warning']); - } - - return _coder_error_msg($results, $warning, $severity_name, $lineno, $line); -} - -function _coder_error_msg(&$results, $warning, $severity_name, $lineno = -1, $line = '') { - // Note: The use of the $key allows multiple errors on one line. - // This assumes that no line of source has more than 10000 lines of code - // and that we have fewer than 10000 errors. - global $_coder_errno; - $key = ($lineno + 1) * 10000 + ($_coder_errno ++); - $results[$key] = theme('coder_warning', $warning, $severity_name, $lineno + 1, $line); -} - -function do_coder_review_grep(&$coder_args, $review, $rule, $lines, &$results) { - if ($regex = $rule['#value']) { - $regex = '/'. $regex .'/i'; - foreach ($lines as $lineno => $line) { - if (preg_match($regex, $line)) { - return; - } - } - $severity_name = _coder_severity_name($coder_args, $review, $rule); - _coder_error($results, $rule, $severity_name); - } -} - -function do_coder_review_callback(&$coder_args, $review, $rule, $lines, &$results) { - if ($function = $rule['#value']) { - if (function_exists($function)) { - call_user_func_array($function, array(&$coder_args, $review, $rule, $lines, &$results)); - } - } -} - -function _coder_is_drupal_core($module) { - static $core; - if (!isset($core)) { - $core = array( - // modules - 'aggregator' => 1, - 'archive' => 1, - 'block' => 1, - 'blog' => 1, - 'blogapi' => 1, - 'book' => 1, - 'color' => 1, - 'comment' => 1, - 'contact' => 1, - 'drupal' => 1, - 'filter' => 1, - 'forum' => 1, - 'help' => 1, - 'legacy' => 1, - 'locale' => 1, - 'menu' => 1, - 'node' => 1, - 'page' => 1, - 'path' => 1, - 'ping' => 1, - 'poll' => 1, - 'profile' => 1, - 'search' => 1, - 'statistics' => 1, - 'system' => 1, - 'taxonomy' => 1, - 'throttle' => 1, - 'tracker' => 1, - 'upload' => 1, - 'user' => 1, - 'watchdog' => 1, - - // themes - 'bluemarine' => 1, - 'chameleon' => 1, - 'garland' => 1, - 'pushbutton' => 1, - ); - } - return isset($core[$module->name]) ? 1 : 0; -} - -/** - * Theming functions below... - */ - -function theme_coder($name, $filename, $results) { - $output = '

'. basename($filename) .'

'; - if (count($results)) { - $output .= theme('item_list', $results); - } - $output .= '
'; - return $output; -} - -function theme_coder_warning($warning, $severity_name, $lineno = 0, $line = '') { - if ($lineno) { - $warning = t('Line @number: !warning', array('@number' => $lineno, '!warning' => $warning)); - if ($line) { - $warning .= '
'. check_plain($line) .'
'; - } - } - $class = "coder-warning"; - if ($severity_name) { - $class .= " coder-$severity_name"; - } - $path = drupal_get_path('module', 'coder'); - $img = theme('image', $path ."/images/$severity_name.png", t('severity: @severity', array('@severity' => $severity_name)), '', array('align' => 'right', 'class' => 'coder'), FALSE); - return '
'. $img . $warning .'
'; -} - -function theme_drupalapi($function, $version = 'HEAD') { - return l($function, "http://api.drupal.org/api/$version/function/$function"); -} Files drupal6/sites/default/modules/contrib-5/coder/images/critical.png and drupal6lang/sites/default/modules/contrib-5/coder/images/critical.png differ Files drupal6/sites/default/modules/contrib-5/coder/images/minor.png and drupal6lang/sites/default/modules/contrib-5/coder/images/minor.png differ Files drupal6/sites/default/modules/contrib-5/coder/images/normal.png and drupal6lang/sites/default/modules/contrib-5/coder/images/normal.png differ diff -urNp drupal6/sites/default/modules/contrib-5/coder/includes/coder_47.inc drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_47.inc --- drupal6/sites/default/modules/contrib-5/coder/includes/coder_47.inc 2007-02-13 09:03:51.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_47.inc 1969-12-31 19:00:00.000000000 -0500 @@ -1,227 +0,0 @@ - 4.7 upgrades - * - * Todo: The rules for this review have not yet been defined. - */ - -function coder_47_reviews() { - $rules = array( - array( - '#type' => 'regex', - '#value' => 'function\s+\w+(_node_name|_node_type)\s*\(', - '#warning_callback' => '_coder_47_hook_node_info_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]node_load\s*\(\s*array\s*\(', - '#warning_callback' => '_coder_47_node_load_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]node_list\s*\(', - '#warning_callback' => '_coder_47_node_list_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]module_get_node_name\s*\(', - '#warning_callback' => '_coder_47_module_get_name_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]format_name\s*\(', - '#warning_callback' => '_coder_47_format_name_warning', - ), - array( - '#type' => 'regex', - '#value' => '^\s*(taxonomy_save_vocabulary|taxonomy_save_term)\s*\(', - '#warning' => 'check the return and display a status message', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]message_access\s*\(', - '#warning_callback' => '_coder_47_message_access_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(](strlen|strtolower|strtoupper|substr|ucfirst)\s*\(', - '#warning' => 'in most cases, replace the string function with the drupal_ equivalent string functions', - '#severity' => 'minor', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]conf_url_rewrite\s*\(', - '#warning_callback' => '_coder_47_conf_url_rewrite_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]node_delete\s*\(\s*array\s*\(', - '#warning_callback' => '_coder_47_node_delete_warning', - ), - array( - '#type' => 'regex', - '#source' => 'all', - '#value' => '[\s\(]variable_get\s*\(\s*[\'"]+file_directory_temp[\'"]+\s*,', - '#warning_callback' => '_coder_47_file_directory_temp_warning', - ), - array( - '#type' => 'regex', - '#source' => 'all', - '#value' => '[\s\(]variable_get\s*\(\s*[\'"]+file_directory_path[\'"]+\s*,', - '#warning_callback' => '_coder_47_file_directory_path_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]array2object\s*\(', - '#warning_callback' => '_coder_47_array2object_warning', - ), - array( - '#type' => 'regex', - '#value' => 'function\s+\w+_onload\s*\(', - '#warning_callback' => '_coder_47_hook_onload_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]node_validate_title\s*\(', - '#warning_callback' => '_coder_47_node_validate_title_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]tablesort_pager\s*\(', - '#warning_callback' => '_coder_47_tablesort_pager_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]form_(textfield|radio|group|select|checkbox|textarea)\s*\(', - '#warning' => 'replace form_ functions with the forms api', - ), - ); - $review = array( - '#title' => t('Converting 4.6.x modules to 4.7.x'), - '#link' => 'http://drupal.org/node/22218', - '#rules' => $rules, - '#severity' => 'critical', - ); - return array('upgrade47' => $review); -} - -/** - * Define the warning callbacks - */ - -function _coder_47_hook_node_info_warning() { - return t('implement !hook_node_info() to create a module which defines node type(s)', - array( - '!hook_node_info' => theme('drupalapi', 'hook_node_info'), - ) - ); -} - -function _coder_47_node_load_warning() { - return t('use !node_load($nid) instead of !node_load(array(\'nid\' => $nid))', - array( - '!node_load' => theme('drupalapi', 'node_load'), - ) - ); -} - -function _coder_47_node_list_warning() { - return t('!node_list() became node_get_types and now returns an associative array about node types', - array( - '!node_list' => theme('drupalapi', 'node_list'), - ) - ); -} - -function _coder_47_module_get_name_warning() { - return t('!module_get_node_name() deprecated and now handled by !node_get_base().', - array( - '!module_get_node_name' => theme('drupalapi', 'module_get_node_name', '4.6'), - '!node_get_base' => theme('drupalapi', 'node_get_base'), - ) - ); -} - -function _coder_47_format_name_warning() { - return t('!format_name() was renamed to !theme_username()', - array( - '!format_name' => theme('drupalapi', 'format_name', '4.6'), - '!theme_username' => theme('drupalapi', 'theme_username'), - ) - ); -} - -function _coder_47_message_access_warning() { - return t('!message_access() was removed, replace with a nice case error message', - array( - '!message_access' => theme('drupalapi', 'message_access', '4.6'), - ) - ); -} - -function _coder_47_conf_url_rewrite_warning() { - return t('!conf_url_rewrite() became !custom_url_rewrite()', - array( - '!conf_url_rewrite' => theme('drupalapi', 'conf_url_rewrite', '4.6'), - '!custom_url_rewrite' => theme('drupalapi', 'custom_url_rewrite'), - ) - ); -} - -function _coder_47_node_delete_warning() { - return t('use !node_delete($nid) instead of !node_delete(array(\'nid\' => $nid))', - array( - '!node_delete' => theme('drupalapi', 'node_delete'), - ) - ); -} - -function _coder_47_file_directory_temp_warning() { - return t('use !file_directory_temp() function instead of variable', - array( - '!file_directory_temp' => theme('drupalapi', 'file_directory_temp'), - ) - ); -} - -function _coder_47_file_directory_path_warning() { - return t('use !file_directory_path() function instead of variable', - array( - '!file_directory_path' => theme('drupalapi', 'file_directory_path'), - ) - ); -} - -function _coder_47_array2object_warning() { - return t('!array2object() replaced by native PHP type conversion (typecase to (object)', - array( - '!array2object' => theme('drupalapi', 'array2object', '4.6'), - ) - ); -} - -function _coder_47_hook_onload_warning() { - return t('!hook_onload replaced by javascript addLoadEvent()', - array( - '!hook_onload' => theme('drupalapi', 'hook_onload', '4.6'), - ) - ); -} - -function _coder_47_node_validate_title_warning() { - return t('!node_validate_title() was removed', - array( - '!node_validate_title' => theme('drupalapi', 'node_validate_title', '4.6'), - ) - ); -} - -function _coder_47_node_tablesort_pager_warning() { - return t('!tablesort_pager() was removed', - array( - '!tablesort_pager' => theme('drupalapi', 'tablesort_pager', '4.6'), - ) - ); -} diff -urNp drupal6/sites/default/modules/contrib-5/coder/includes/coder_50.inc drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_50.inc --- drupal6/sites/default/modules/contrib-5/coder/includes/coder_50.inc 2007-02-15 02:02:37.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_50.inc 1969-12-31 19:00:00.000000000 -0500 @@ -1,164 +0,0 @@ - 5.0 upgrades - */ - -function coder_50_reviews() { - $rules = array( - array( - '#type' => 'regex', - '#value' => '[\s\(]user_mail\s*\(', - '#warning_callback' => '_coder_50_user_mail_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]user_mail_wrapper\s*\(', - '#warning_callback' => '_coder_50_user_mail_wrapper_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]message_na\s*\(', - '#warning_callback' => '_coder_50_message_na_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]module_exist\s*\(', - '#warning_callback' => '_coder_50_module_exist_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]drupal_call_js\s*\(', - '#warning_callback' => '_coder_50_drupal_call_js_warning', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(]system_listing\s*\(', - '#warning_callback' => '_coder_50_system_listing_warning', - ), - array( - '#type' => 'regex', - '#source' => 'all', - '#value' => '\$_POST\s*\[\s*[\'"]?op[\'"]?\s*\]', - '#warning' => '$_POST[\'op\'] deprecated in favor of $form_values[\'op\']', - '#severity' => 'normal', - ), - array( - '#type' => 'callback', - '#value' => '_coder_50_callback', - ), - array( - '#type' => 'regex', - '#source' => 'all', - '#value' => '[\s\(]theme_add_style\s*\(', - '#warning_callback' => '_coder_50_theme_add_style_warning', - ), - array( - '#type' => 'regex', - '#source' => 'all', - '#value' => '[\s\(]form_render\s*\(', - '#warning_callback' => '_coder_50_form_render_warning', - ), - ); - $review = array( - '#title' => t('Converting 4.7.x modules to 5.x'), - '#link' => 'http://drupal.org/node/64279', - '#rules' => $rules, - '#severity' => 'critical', - ); - return array('upgrade50' => $review); -} - -/** - * Define the rule callbacks - */ - -function _coder_50_callback(&$coder_args, $review, $rule, $lines, &$results) { - // only perform this check on module's (not includes) - $filename = $coder_args['#filename']; - if (substr($filename, -7) == '.module') { - // make sure that a .info file exists - $filename = drupal_substr(realpath($filename), 0, -7) .'.info'; - if (!file_exists($filename)) { - $severity_name = _coder_severity_name($review, $rule); - $results[0] = theme('coder_warning', $severity_name, $lineno, t('All modules now need to have a modulename.info file', array('@info' => 'http://drupal.org/node/101009'))); - } - } -} - -/** - * Define the warning callbacks - */ - -function _coder_50_user_mail_warning() { - return t('!user_mail() is replaced by !drupal_mail()', - array( - '!user_mail' => theme('drupalapi', 'user_mail', '4.7'), - '!drupal_mail' => theme('drupalapi', 'drupal_mail'), - ) - ); -} - -function _coder_50_drupal_mail_wrapper_warning() { - return t('!user_mail_wrapper() changed to !drupal_mail_wrapper()', - array( - '!user_mail_wrapper' => theme('drupalapi', 'user_mail_wrapper', '4.7'), - '!drupal_mail_wrapper' => theme('drupalapi', 'drupal_mail_wrapper'), - ) - ); -} - -function _coder_50_message_na_warning() { - return t('The function !message_na() was removed, remove it from your modules as well and replace it with !t(\'n/a\')', - array( - '!message_na' => theme('drupalapi', 'message_na', '4.7'), - '!t' => theme('drupalapi', 't'), - ) - ); -} - -function _coder_50_module_exist_warning() { - return t('!module_exist() is now !module_exists()', - array( - '!module_exist' => theme('drupalapi', 'module_exist', '4.7'), - '!module_exists' => theme('drupalapi', 'module_exists'), - ) - ); -} - -function _coder_50_drupal_call_js_warning() { - return t('Remove !drupal_call_js(), use "!drupal_add_js(\'myCustomFunction(your, parameters, here)\', \'inline\');" instead', - array( - '!drupal_call_js' => theme('drupalapi', 'drupal_call_js', '4.7'), - '!drupal_add_js' => theme('drupalapi', 'drupal_add_js'), - ) - ); -} - -function _coder_50_system_listing_warning() { - return t('!system_listing() is now !drupal_system_listing()', - array( - '!system_listing' => theme('drupalapi', 'system_listing', '4.7'), - '!drupal_system_listing' => theme('drupalapi', 'drupal_system_listing'), - ) - ); -} - -function _coder_50_theme_add_style_warning() { - return t('Replace !theme_add_style() with !drupal_add_css()', - array( - '!theme_add_style' => theme('drupalapi', 'theme_add_style', '4.7'), - '!drupal_add_css' => theme('drupalapi', 'drupal_add_css'), - ) - ); -} - -function _coder_50_form_render_warning() { - return t('Replace !form_render() with !drupal_render()', - array( - '!form_render' => theme('drupalapi', 'form_render', '4.7'), - '!drupal_render' => theme('drupalapi', 'drupal_render'), - ) - ); -} diff -urNp drupal6/sites/default/modules/contrib-5/coder/includes/coder_performance.inc drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_performance.inc --- drupal6/sites/default/modules/contrib-5/coder/includes/coder_performance.inc 2007-03-20 20:13:11.000000000 -0400 +++ drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_performance.inc 1969-12-31 19:00:00.000000000 -0500 @@ -1,74 +0,0 @@ - 'regex', - '#value' => 'TRUE', - '#warning_callback' => '_coder_performance_true_warning', - ), - array( - '#type' => 'regex', - '#value' => '^\s*\$\w+\+\+\s*;', - '#warning_callback' => '_coder_performance_increment_warning', - ), - array( - '#type' => 'regex', - '#value' => '\(strlen\(\$\w+\) < \d+\)', - '#warning_callback' => '_coder_performance_strlen_less_than_warning', - ), - array( - '#type' => 'regex', - '#value' => '\(strlen\(\$\w+\) > \d+\)', - '#warning_callback' => '_coder_performance_strlen_greater_than_warning', - ), - array( - '#type' => 'regex', - '#value' => '^\s*print ', - '#warning_callback' => '_coder_performance_print_warning', - ), - array( - '#type' => 'regex', - '#value' => 'in_array\(\'\', \$\w+\)', - '#warning_callback' => '_coder_performance_in_array_warning', - ), - ); - $review = array( - '#title' => 'Performance Optimization', - '#link' => 'http://drupal.org/node/110128', - '#rules' => $rules, - '#severity' => 'minor', - ); - return array('performance' => $review); -} - -function _coder_performance_true_warning() { - return t('true is faster than TRUE'); -} - -function _coder_performance_increment_warning() { - return t('++ $i is faster than $ i++'); -} - -function _coder_performance_strlen_less_than_warning() { - return t('if (!isset($foo{5})) is faster than if (strlen($foo) < 5)'); -} - -function _coder_performance_strlen_greater_than_warning() { - return t('if (isset($foo{6})) is faster than if (strlen($foo) > 5)'); -} - -function _coder_performance_print_warning() { - return t('echo is faster than print (when the return value from print is not used)'); -} - -function _coder_performance_in_array_warning() { - return t('if (isset($keys[\'foo\'])) is faster than if (in_array(\'foo\', $keys))'); -} diff -urNp drupal6/sites/default/modules/contrib-5/coder/includes/coder_security.inc drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_security.inc --- drupal6/sites/default/modules/contrib-5/coder/includes/coder_security.inc 2007-02-13 09:03:51.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_security.inc 1969-12-31 19:00:00.000000000 -0500 @@ -1,73 +0,0 @@ - 'regex', - '#value' => 'l\(check_plain\(', - '#warning_callback' => '_coder_security_l_check_plain_warning', - ), -/* array( - '#type' => 'callback', - '#value' => _coder_security_callback, - ), */ - array( - '#type' => 'regex', - '#value' => '(?-i)\$REQUEST_URI', - '#warning_callback' => '_coder_security_request_uri_warning', - ), - array( - '#type' => 'regex', - '#source' => 'all', - '#value' => '(?-i)\"REQUEST_URI\"|\'REQUEST_URI\'', - '#warning_callback' => '_coder_security_request_uri_warning', - ), - ); - $review = array( - '#title' => 'Handle text in a secure fashion', - '#link' => 'http://drupal.org/node/28984', - '#rules' => $rules, - '#severity' => 'critical', - ); - return array('security' => $review); -} - - -/** - * Define the warning callbacks - */ - -/* function _coder_security_callback(&$coder_args, $review, $rule, $lines, &$results) { - if (!isset($coder_args['#tokens'])) { - $source = implode('', $lines); - $coder_args['#tokens'] = token_get_all($source); - } -} */ - -/** - * Define the warning callbacks - */ - -function _coder_security_l_check_plain_warning() { - return t('!l() already contains a !check_plain() call by default', - array( - '!l' => theme('drupalapi', 'l'), - '!check_plain' => theme('drupalapi', 'check_plain'), - ) - ); -} - -function _coder_security_request_uri_warning() { - return t('the use of REQUEST_URI is prone to XSS exploits and does not work on IIS; use !request_uri() instead', - array( - '!request_uri' => theme('drupalapi', 'request_uri'), - ) - ); -} diff -urNp drupal6/sites/default/modules/contrib-5/coder/includes/coder_style.inc drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_style.inc --- drupal6/sites/default/modules/contrib-5/coder/includes/coder_style.inc 2007-02-15 02:02:38.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/includes/coder_style.inc 1969-12-31 19:00:00.000000000 -0500 @@ -1,204 +0,0 @@ - 'regex', - '#value' => '\t', - '#warning' => 'Use an indent of 2 spaces, with no tabs', - ), - array( - '#type' => 'regex', - '#value' => '\s(if|elseif|while|foreach|switch|return|for)\(', - '#warning' => 'Control statements should have one space between the control keyword and opening parenthesis', - ), - array( - '#type' => 'regex', - '#value' => '[\s\(](\w+)\s\(', - '#not' => '^(if|elseif|while|foreach|switch|return|for)$', - '#warning' => 'Functions should be called with no spaces between the function name', - ), - array( - '#type' => 'regex', - '#value' => '\){', - '#warning' => 'use a space between the closing parenthesis and the open bracket', - ), - array( - '#type' => 'regex', - '#value' => '(\S=>|=>\S)', - '#warning' => 'Arrays should be formatted with a space separating each element and assignment operator', - ), - array( - '#type' => 'regex', - '#value' => '(\.\s\'\'|\'\'\s\.|\.\s""|\.\s"")', - '#warning' => 'string concatenation should be formatted without a space separating the operators (dot .) and a quote', - ), - array( - '#type' => 'regex', - '#value' => '([^\'\"\s0-9]\.|\.[^\'\"\=\s0-9])', - '#warning' => 'string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms', - ), - array( - '#type' => 'regex', - '#value' => '<\?(\w+)', - '#not' => '^(php|xml)$', - '#warning' => 'Always use <?php ?> to delimit PHP code, not the <? ?> shorthand', - ), - array( - '#type' => 'grep', - '#source' => 'all', - '#value' => '\$Id', - '#warning' => 'Include the Id CVS keyword in each file', - ), - array( - '#type' => 'regex', - '#value' => 'global\s+\$(\w+)(,\s\$(\w+))*', - '#not' => '^_|^('. _coder_style_core_global_regex() .')$', - '#warning' => 'global variables should start with a single underscore followed by the module and another underscore', - ), - array( - '#type' => 'callback', - '#value' => '_coder_style_callback', - ), - array( - '#type' => 'regex', - '#value' => '}\s*else', - '#warning' => 'else statements should begin on a new line', - ), - array( - '#type' => 'regex', - '#value' => '[,][^ \n\r]', - '#warning' => 'missing space after comma', - ), - array( - '#type' => 'regex', - '#value' => '^\s*{', - '#warning' => 'curly braces { should end a line, not start one', - ), - array( - '#type' => 'regex', - '#value' => '(?-i)(([a-z]+[A-Z]+([a-z]*[A-Z]*)*)|([A-Z]+[a-z]+([A-Z]*[a-z]*)*))', - '#not' => '(?-i)^(stdClass|StdClass|x[A-F]+)$', - '#warning' => 'do not use mixed case (camelCase), use lower case and _', - ), - array( - '#type' => 'regex', - '#value' => '\s(stdclass)\s*\(', - '#not' => '^(?-i)stdClass$', - '#warning' => 'use stdClass caseCapitalization, it\'s the one exception to the mixed case style standard', - ), - array( - '#type' => 'regex', - '#source' => 'html', - '#value' => '<'. $br .'>', // NOTE: use $br only to avoid a warning - '#warning' => 'use <br /> instead of <br>', - '#severity' => 'minor', - ), - array( - '#type' => 'regex', - '#source' => 'html', - '#value' => '(?-i)<[A-Z]+', - '#warning_callback' => '_coder_style_xhtml_warning', - '#severity' => 'minor', - ), - ); - $review = array( - '#title' => t('Drupal Coding Standards'), - '#link' => 'http://drupal.org/node/318', - '#rules' => $rules, - ); - return array('style' => $review); -} - -/** - * Define the rule callbacks - */ - -function _coder_style_callback(&$coder_args, $review, $rule, $lines, &$results) { - for ($lineno = -1; $last = array_slice($lines, $lineno); $lineno --) { - $lastline = $last[0]; - if (preg_match('/\S/', $lastline)) { - break; - } - } - if ($last && $lastline && preg_match('/\?>/i', $lastline)) { - $severity_name = _coder_severity_name($review, $rule); - _coder_error_msg($results, 'the final ?> should be omitted from all code files', $severity_name, count($lines)); - } -} - -function _coder_style_core_global_regex() { - static $coreglobalregex, $coreglobalvars; - if (!isset($coreglobalregex)) { - // Note: there's a little extra overhead in formatting this list as an - // array, but I think it makes it more readable and maintainable - $coreglobalvars = array( - // from the Drupal 5 includes/ directory - 'active_db', - 'base_path', - 'base_root', - 'base_url', - 'conf', - 'custom_theme', - 'db_prefix', - 'db_type', - 'db_url', - 'form_button_counter', - 'form_submitted', - 'form_values', - 'install_locale', - 'installed_profile', - 'last_result', - 'locale', - 'multibyte', - 'pager_page_array', - 'pager_total', - 'pager_total_items', - 'profile', - 'queries', - 'theme', - 'theme_engine', - 'theme_key', - 'timers', - 'user', - - // from the Drupal 5 modules/ directory - - // Note: IMHO these should not be allowed, but until we fix core, - // other modules will need them - 'channel', - 'element', - 'forum_topic_list_header', - 'id', - 'image', - 'item', - 'items', - 'last_change', - 'last_nid', - 'nid', - 'recent_activity', - 'tag', - ); - $coreglobalregex = implode('|', $coreglobalvars); - } - return $coreglobalregex; -} - -/** - * Define the warning callbacks - */ - -function _coder_style_xhtml_warning() { - return t('use lowercase html tags to comply with XHTML', - array( - '@XHTML' => 'http://www.w3.org/TR/xhtml1/#h-4.2', - ) - ); -} diff -urNp drupal6/sites/default/modules/contrib-5/coder/tests/coder_style.inc drupal6lang/sites/default/modules/contrib-5/coder/tests/coder_style.inc --- drupal6/sites/default/modules/contrib-5/coder/tests/coder_style.inc 2007-02-13 09:03:51.000000000 -0500 +++ drupal6lang/sites/default/modules/contrib-5/coder/tests/coder_style.inc 1969-12-31 19:00:00.000000000 -0500 @@ -1,72 +0,0 @@ -This is embedded php and should Not trigger a camelCase error.This second embedded php and should Not trigger -a camelCase error.Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. They are usually generated automatically by modules, but administrators can create blocks manually.

-

Only enabled blocks are shown. You can position blocks by specifying which area of the page they should appear in (e.g., a sidebar). Highlighted labels on this page show the regions into which blocks can be rendered. You can specify where within a region a block will appear by adjusting its weight.

-

If you want certain blocks to disable themselves temporarily during high server loads, check the "Throttle" box. You can configure the auto-throttle on the throttle configuration page after having enabled the throttle module.

-

You can configure the behaviour of each block (for example, specifying on which pages and for what users it will appear) by clicking the "configure" link for each block.

', array('@throttle' => url('admin/settings/throttle'))); -} - -function coder_break() { - print '
'; // should generate an error - ?>
- -__EOD__; -} - -function coder_dot() { - if ($file = file_check_upload($fieldname . '_upload')) { // not ok - } - $v .= 'bugger'; // ok - $a = $v .'bugger'; // ok - $a = $v ."bugger"; // ok - $a = $v.'bugger'; // not ok - $a = $some_func().'bugger'; // not ok -} - -// should generate an error about the trailing php close -?> diff -urNp drupal6/themes/engines/phptemplate/phptemplate.engine drupal6lang/themes/engines/phptemplate/phptemplate.engine --- drupal6/themes/engines/phptemplate/phptemplate.engine 2007-02-15 06:40:19.000000000 -0500 +++ drupal6lang/themes/engines/phptemplate/phptemplate.engine 2007-03-25 14:29:28.562500000 -0400 @@ -205,7 +205,7 @@ function phptemplate_page($content, $sho 'head' => drupal_get_html_head(), 'head_title' => implode(' | ', $head_title), 'help' => theme('help'), - 'language' => $GLOBALS['locale'], + 'language' => $GLOBALS['language'], 'layout' => $layout, 'logo' => theme_get_setting('logo'), 'messages' => theme('status_messages'),