Improved response time for username autofill; fix JS login box in Safari (bug surfaced only after 1.0.1)
authorDan
Mon, 24 Sep 2007 21:29:19 -0400
changeset 144 380e55865f86
parent 143 c8bfd324cb03
child 145 6f0bbf88c325
child 148 42c6c83b8a00
Improved response time for username autofill; fix JS login box in Safari (bug surfaced only after 1.0.1)
ajax.php
includes/clientside/static/misc.js
includes/common.php
--- a/ajax.php	Sun Sep 23 23:22:25 2007 -0400
+++ b/ajax.php	Mon Sep 24 21:29:19 2007 -0400
@@ -12,6 +12,59 @@
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
  */
  
+  // fillusername should be done without the help of the rest of Enano - all we need is the DBAL
+  if ( isset($_GET['_mode']) && $_GET['_mode'] == 'fillusername' )
+  {
+    // setup and load a very basic, specialized instance of the Enano API
+    function dc_here($m)     { return false; }
+    function dc_dump($a, $g) { return false; }
+    function dc_watch($n)    { return false; }
+    function dc_start_timer($u) { return false; }
+    function dc_stop_timer($m) { return false; }
+    // Determine directory (special case for development servers)
+    if ( strpos(__FILE__, '/repo/') && file_exists('.enanodev') )
+    {
+      $filename = str_replace('/repo/', '/', __FILE__);
+    }
+    else
+    {
+      $filename = __FILE__;
+    }
+    define('ENANO_ROOT', dirname($filename));
+    require(ENANO_ROOT.'/includes/functions.php');
+    require(ENANO_ROOT.'/includes/dbal.php');
+    $db = new mysql();
+    $db->connect();
+    
+    // should be connected now
+    $name = (isset($_GET['name'])) ? $db->escape($_GET['name']) : false;
+    if ( !$name )
+    {
+      die('userlist = new Array(); errorstring=\'Invalid URI\'');
+    }
+    $q = $db->sql_query('SELECT username,user_id FROM '.table_prefix.'users WHERE lcase(username) LIKE lcase(\'%'.$name.'%\');');
+    if ( !$q )
+    {
+      die('userlist = new Array(); errorstring=\'MySQL error selecting username data: '.addslashes(mysql_error()).'\'');
+    }
+    if($db->numrows() < 1)
+    {
+      die('userlist = new Array(); errorstring=\'No usernames found\';');
+    }
+    echo 'var errorstring = false; userlist = new Array();';
+    $i = 0;
+    while($r = $db->fetchrow())
+    {
+      echo "userlist[$i] = '".addslashes($r['username'])."'; ";
+      $i++;
+    }
+    $db->free_result();
+    
+    // all done! :-)
+    $db->close();
+    exit;
+  }
+ 
   require('includes/common.php');
   
   global $db, $session, $paths, $template, $plugins; // Common objects
@@ -105,28 +158,6 @@
       echo PageUtils::setpass($paths->cpage['urlname_nons'], $paths->namespace, $_POST['password']);
       break;
     case "fillusername":
-      $name = (isset($_GET['name'])) ? $db->escape($_GET['name']) : false;
-      if ( !$name ) 
-      {
-        die('userlist = new Array(); errorstring=\'Invalid URI\'');
-      }
-      $q = $db->sql_query('SELECT username,user_id FROM '.table_prefix.'users WHERE lcase(username) LIKE lcase(\'%'.$name.'%\');');
-      if ( !$q )
-      {
-        die('userlist = new Array(); errorstring=\'MySQL error selecting username data: '.addslashes(mysql_error()).'\'');
-      }
-      if($db->numrows() < 1)
-      {
-        die('userlist = new Array(); errorstring=\'No usernames found\';');
-      }
-      echo 'var errorstring = false; userlist = new Array();';
-      $i = 0;
-      while($r = $db->fetchrow())
-      {
-        echo "userlist[$i] = '".addslashes($r['username'])."'; ";
-        $i++;
-      }
-      $db->free_result();
       break;
     case "fillpagename":
       $name = (isset($_GET['name'])) ? $_GET['name'] : false;
--- a/includes/clientside/static/misc.js	Sun Sep 23 23:22:25 2007 -0400
+++ b/includes/clientside/static/misc.js	Mon Sep 24 21:29:19 2007 -0400
@@ -446,14 +446,8 @@
     'level' : ajax_auth_level_cache
   };
   
-  if ( window.console )
-    window.console.debug(json_data);
   json_data = toJSONString(json_data);
-  if ( window.console )
-    window.console.debug(json_data);
   json_data = encodeURIComponent(json_data);
-  if ( window.console )
-    window.console.debug(json_data);
   
   var loading_win = '<div align="center" style="text-align: center;"> \
       <p>Logging in...</p> \
--- a/includes/common.php	Sun Sep 23 23:22:25 2007 -0400
+++ b/includes/common.php	Mon Sep 24 21:29:19 2007 -0400
@@ -268,7 +268,7 @@
       
       $text = RenderMan::render($n) . '
       <div class="info-box">
-        If you have an administrative account, you may <a href="'.makeUrlNS('Special', 'Login').'">log in</a> to the site or <a href="'.makeUrlNS('Special', 'Administration').'">use the administration panel</a>.
+        If you have an administrative account, you may <a href="'.makeUrlNS('Special', 'Login').'">log in</a> to the site.
       </div>';
       $paths->wiki_mode = 0;
       die_semicritical('Site disabled', $text);