Separated ajax search box features from core ajax framework.
authorDaniel Kinzler <daniel@users.mediawiki.org>
Sun, 30 Jul 2006 10:53:22 +0000 (10:53 +0000)
committerDaniel Kinzler <daniel@users.mediawiki.org>
Sun, 30 Jul 2006 10:53:22 +0000 (10:53 +0000)
Note that ajax search is currently broken (some issue with message parsing)

RELEASE-NOTES
includes/DefaultSettings.php
includes/OutputPage.php
includes/Setup.php
skins/common/ajax.js
skins/common/ajaxsearch.js [new file with mode: 0644]

index cb9538e..c050a44 100644 (file)
@@ -105,7 +105,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   page title, etc. 
 * hooks registered with addOnloadHook are now called at the one of the html body
   by all skins.
-
+* Split ajax aided search from core ajax framework. Use wgUseAjax to enable the
+  framework and wgAjaxSearch to enable the suggest feature for the search box.
 
 == Languages updated ==
 
index 873bd52..8cd5f7d 100644 (file)
@@ -2136,14 +2136,22 @@ $wgUpdateRowsPerJob = 500;
 $wgUpdateRowsPerQuery = 10;
 
 /**
- * Enable use of AJAX features, currently auto suggestion for the search bar
+ * Enable AJAX framework
  */
 $wgUseAjax = false;
 
 /**
- * List of Ajax-callable functions
+ * Enable auto suggestion for the search bar 
+ * Requires $wgUseAjax to be true too.
+ * Causes wfSajaxSearch to be added to $wgAjaxExportList
  */
-$wgAjaxExportList = array( 'wfSajaxSearch' );
+$wgAjaxSearch = false;
+
+/**
+ * List of Ajax-callable functions. 
+ * Extensions acting as Ajax callbacks must register here
+ */
+$wgAjaxExportList = array( );
 
 /**
  * Allow DISPLAYTITLE to change title display
index ce4f176..e677dcb 100644 (file)
@@ -484,7 +484,7 @@ class OutputPage {
        function output() {
                global $wgUser, $wgOutputEncoding;
                global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
-               global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
+               global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgScriptPath, $wgServer;
 
                if( $this->mDoNothing ){
                        return;
@@ -494,13 +494,14 @@ class OutputPage {
                $sk = $wgUser->getSkin();
 
                if ( $wgUseAjax ) {
-                       $this->addScript( "<script type=\"{$wgJsMimeType}\">
-                               var wgScriptPath=\"{$wgScriptPath}\";
-                               var wgServer=\"{$wgServer}\";
-                       </script>" );
                        $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
                }
 
+               if ( $wgUseAjax && $wgAjaxSearch ) {
+                       $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js\"></script>\n" );
+                       $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
+               }
+
                if ( '' != $this->mRedirect ) {
                        if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
                                # Standards require redirect URLs to be absolute
index 68a4802..2a8e6e5 100644 (file)
@@ -168,6 +168,8 @@ wfProfileIn( $fname.'-misc2' );
 $wgDeferredUpdateList = array();
 $wgPostCommitUpdateList = array();
 
+if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
+
 wfSeedRandom();
 
 # Placeholders in case of DB error
index 9067654..f9f9624 100644 (file)
@@ -3,18 +3,11 @@
 var sajax_debug_mode = false;
 var sajax_request_type = "GET";
 
-var started;
-var typing;
-var memory=null;
-var body=null;
-var oldbody=null;
-
 function sajax_debug(text) {
        if (sajax_debug_mode)
                alert("RSD: " + text)
 }
 
-
 function sajax_init_object() {
        sajax_debug("sajax_init_object() called..")
        var A;
@@ -80,98 +73,3 @@ function sajax_do_call(func_name, args) {
        sajax_debug(func_name + " waiting..");
        delete x;
 }
-
-// Remove the typing barrier to allow call() to complete
-function Search_doneTyping()
-{
-       typing=false;
-}
-
-// Wait 500ms to run call()
-function Searching_Go()
-{
-        setTimeout("Searching_Call()", 500);
-}
-
-// If the user is typing wait until they are done.
-function Search_Typing() {
-       started=true;
-       typing=true;
-       window.status = "Waiting until you're done typing...";
-       setTimeout("Search_doneTyping()", 500);
-
-       // I believe these are needed by IE for when the users press return?
-       if (window.event)
-       {
-               if (event.keyCode == 13)
-               {
-                       event.cancelBubble = true;
-                       event.returnValue = false;
-               }
-       }
-}
-
-// Set the body div to the results
-function Searching_SetResult(result)
-{
-        //body.innerHTML = result;
-       t = document.getElementById("searchTarget");
-       if ( t == null ) {
-               oldbody=body.innerHTML;
-               body.innerHTML= '<div id="searchTargetContainer"><div id="searchTarget" ></div></div>' ;
-               t = document.getElementById("searchTarget");
-       }
-       t.innerHTML = result;
-       t.style.display='block';
-}
-
-function Searching_Hide_Results()
-{
-       t = document.getElementById("searchTarget");
-       t.style.display='none';
-       body.innerHTML = oldbody;
-}
-
-
-// This will call the php function that will eventually
-// return a results table
-function Searching_Call()
-{
-       var x;
-       Searching_Go();
-
-       //Don't proceed if user is typing
-       if (typing)
-               return;
-
-       x = document.getElementById("searchInput").value;
-
-       // Don't search again if the query is the same
-       if (x==memory)
-               return;
-
-       memory=x;
-       if (started) {
-               // Don't search for blank or < 3 chars.
-               if ((x=="") || (x.length < 3))
-               {
-                       return;
-               }
-               x_wfSajaxSearch(x, Searching_SetResult);
-       }
-}
-
-function x_wfSajaxSearch() {
-       sajax_do_call( "wfSajaxSearch", x_wfSajaxSearch.arguments );
-}
-
-       
-//Initialize
-function sajax_onload() {
-       x = document.getElementById( 'searchInput' );
-       x.onkeypress= function() { Search_Typing(); };
-       Searching_Go();
-       body = document.getElementById("content");
-}
-
-hookEvent("load", sajax_onload);
diff --git a/skins/common/ajaxsearch.js b/skins/common/ajaxsearch.js
new file mode 100644 (file)
index 0000000..f7973b7
--- /dev/null
@@ -0,0 +1,101 @@
+// remote scripting library
+// (c) copyright 2005 modernmethod, inc
+
+var started;
+var typing;
+var memory=null;
+var body=null;
+var oldbody=null;
+
+// Remove the typing barrier to allow call() to complete
+function Search_doneTyping()
+{
+       typing=false;
+}
+
+// Wait 500ms to run call()
+function Searching_Go()
+{
+        setTimeout("Searching_Call()", 500);
+}
+
+// If the user is typing wait until they are done.
+function Search_Typing() {
+       started=true;
+       typing=true;
+       window.status = "Waiting until you're done typing...";
+       setTimeout("Search_doneTyping()", 500);
+
+       // I believe these are needed by IE for when the users press return?
+       if (window.event)
+       {
+               if (event.keyCode == 13)
+               {
+                       event.cancelBubble = true;
+                       event.returnValue = false;
+               }
+       }
+}
+
+// Set the body div to the results
+function Searching_SetResult(result)
+{
+        //body.innerHTML = result;
+       t = document.getElementById("searchTarget");
+       if ( t == null ) {
+               oldbody=body.innerHTML;
+               body.innerHTML= '<div id="searchTargetContainer"><div id="searchTarget" ></div></div>' ;
+               t = document.getElementById("searchTarget");
+       }
+       t.innerHTML = result;
+       t.style.display='block';
+}
+
+function Searching_Hide_Results()
+{
+       t = document.getElementById("searchTarget");
+       t.style.display='none';
+       body.innerHTML = oldbody;
+}
+
+
+// This will call the php function that will eventually
+// return a results table
+function Searching_Call()
+{
+       var x;
+       Searching_Go();
+
+       //Don't proceed if user is typing
+       if (typing)
+               return;
+
+       x = document.getElementById("searchInput").value;
+
+       // Don't search again if the query is the same
+       if (x==memory)
+               return;
+
+       memory=x;
+       if (started) {
+               // Don't search for blank or < 3 chars.
+               if ((x=="") || (x.length < 3))
+               {
+                       return;
+               }
+               x_wfSajaxSearch(x, Searching_SetResult);
+       }
+}
+
+function x_wfSajaxSearch() {
+       sajax_do_call( "wfSajaxSearch", x_wfSajaxSearch.arguments );
+}
+
+       
+//Initialize
+function sajax_onload() {
+       x = document.getElementById( 'searchInput' );
+       x.onkeypress= function() { Search_Typing(); };
+       Searching_Go();
+       body = document.getElementById("content");
+}