Heine

  • drupal
  • drupal core commits
  • about
Home

Commit 218236 by dries

- Patch #423196 by frega, Xano, alienbrain et al: clean up the URL settings page.

--- modules/system/system.admin.inc     2009/05/25 18:22:30     1.150
+++ modules/system/system.admin.inc     2009/05/29 19:51:43     1.151
@@ -1723,36 +1723,53 @@
 }
 
 /**
- * Form builder; Configure Clean URL settings.
+ * Form builder; Configure clean URL settings.
  *
  * @ingroup forms
  * @see system_settings_form()
  */
 function system_clean_url_settings() {
-  $form['clean_url'] = array(
-    '#type' => 'radios',
-    '#title' => t('Clean URLs'),
-    '#default_value' => 0,
-    '#options' => array(t('Disabled'), t('Enabled')),
-    '#description' => t('This option makes Drupal emit "clean" URLs (i.e. without <code>?q=</code> in the URL).'),
-  );
+  global $base_url;
 
-  if (!variable_get('clean_url', 0)) {
-    if (strpos(request_uri(), '?q=') !== FALSE) {
-      drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
+  // When accessing this form using a non-clean URL, allow a re-check to make
+  // sure clean URLs can be disabled at all times.
+  $available = FALSE;
+  if (strpos(request_uri(), '?q=') === FALSE || drupal_get_session('clean_url')) {
+    $available = TRUE;
+  }
+  else {
+    $request = drupal_http_request($base_url . '/admin/settings/clean-urls/check');
+    if (isset($request->code) && $request->code == 200) {
+      $available = TRUE;
+    }
+  }
 
-      $form['clean_url']['#description'] .= ' <span>' . t('Before enabling clean URLs, you must perform a test to determine if your server is properly configured. If you are able to see this page again after clicking the "Run the clean URL test" link, the test has succeeded and the radio buttons above will be available. If instead you are directed to a "Page not found" error, you will need to change the configuration of your server. The <a href="@handbook">handbook page on Clean URLs</a> has additional troubleshooting information.', array('@handbook' => 'http://drupal.org/node/15365')) . '</span>';
+  if ($available) {
+    drupal_set_session('clean_url', TRUE);
 
-      $form['clean_url']['#disabled'] = TRUE;
-      $form['clean_url']['#prefix'] = '<div id="clean-url">';
-      $form['clean_url']['#suffix'] = '<p>' . t('<a href="@clean_url">Run the clean url test</a>.', array('@clean_url' => base_path() . 'admin/settings/clean-urls')) . '</p></div>';
-    }
-    else {
-      $form['clean_url']['#description'] .= ' <div class="ok">' . t('Your server has been successfully tested to support this feature.') . '</div>';
-    }
+    $form['clean_url'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Enable clean URLs'),
+      '#default_value' => 0,
+      '#description' => t('Use URLs like <code>example.com/user</code> instead of <code>example.com/?q=user</code>.'),
+    );
+    $form = system_settings_form($form);
   }
+  else {
+    drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
 
-  return system_settings_form($form, TRUE);
+    $form['#redirect'] = $base_url . '/admin/settings/clean-urls';
+    $form['clean_url_description'] = array(
+      '#type' => 'markup',
+      '#markup' => '<p>' . t('Use URLs like <code>example.com/user</code> instead of <code>example.com/?q=user</code>.') . ' ' . t('If you are directed to a <em>Page not found (404)</em> error after testing for clean URLs, see the <a href="@handbook">online handbook</a>.', array('@handbook' => 'http://drupal.org/node/15365')) . '</p>',
+    );
+    $form['clean_url_test'] = array(
+      '#type' => 'submit',
+      '#value' => t('Run the clean URL test'),
+    );
+  }
+
+  return $form;
 }
 
 /**

--- modules/system/system.js    2009/05/15 03:38:25     1.25
+++ modules/system/system.js    2009/05/29 19:51:43     1.26
@@ -17,21 +17,12 @@
       return;
     }
     var url = settings.basePath + 'admin/settings/clean-urls/check';
-    $('#clean-url .description span').html('<div id="testing">' + Drupal.t('Testing clean URLs...') + '</div>');
-    $('#clean-url p').hide();
     $.ajax({
       url: location.protocol + '//' + location.host + url,
       dataType: 'json',
       success: function () {
-        // Check was successful.
-        $('#clean-url input.form-radio').attr('disabled', false);
-        $('#clean-url .description span').append('<div class="ok">' + Drupal.t('Your server has been successfully tested to support this feature.') + '</div>');
-        $('#testing').hide();
-      },
-      error: function () {
-        // Check failed.
-        $('#clean-url .description span').append('<div class="warning">' + Drupal.t('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.') + '</div>');
-        $('#testing').hide();
+        // Check was successful. Redirect using a "clean URL". This will force the form that allows enabling clean URLs.
+        location = settings.basePath +"admin/settings/clean-urls";
       }
     });
     $('#clean-url').addClass('clean-url-processed');

No votes yet
  • Drupal Core
  • Download patch

Recent posts

  • Menu access, a new pitfall when going back to Drupal 5
  • Drupal 6: $base_path doesn't always point to the frontpage
  • XNA SoundEffect ContentLoadException
  • A new form element in Drupal core
  • The backstabbing March-Hare

All-time popular content

  • Update UID 1 password via JS
  • Keeping an eye on Drupal core
  • Subversion on Strato V-PowerServer
  • A new form element in Drupal core
  • Access denied - Are you sure?
more

Tags

Captcha Coding Drupal FAPI IIS Let's hope it doesn't become popular Performance PHP Planet Drupal Quiz Security V-PowerServer
more tags
  • drupal
  • drupal core commits
  • about

Copyright © 2009 by Heine Deelstra. All rights reserved.