r15888 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r15887 | r15888 (on ViewVC) | r15889 >
Date:10:53, 30 July 2006
Author:daniel
Status:new
Tags:
Comment:Separated ajax search box features from core ajax framework.
Note that ajax search is currently broken (some issue with message parsing)
Modified paths:

Diff [purge]

Index: trunk/phase3/skins/common/ajaxsearch.js
===================================================================
--- trunk/phase3/skins/common/ajaxsearch.js	(revision 0)
+++ trunk/phase3/skins/common/ajaxsearch.js	(revision 15888)
@@ -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");
+}

Property changes on: trunk/phase3/skins/common/ajaxsearch.js
___________________________________________________________________
Name: svn:eol-style
   + native
Name: svn:keywords
   + Author Date Id Revision

Index: trunk/phase3/skins/common/ajax.js
===================================================================
--- trunk/phase3/skins/common/ajax.js	(revision 15887)
+++ trunk/phase3/skins/common/ajax.js	(revision 15888)
@@ -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 @@
 	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);
Index: trunk/phase3/includes/Setup.php
===================================================================
--- trunk/phase3/includes/Setup.php	(revision 15887)
+++ trunk/phase3/includes/Setup.php	(revision 15888)
@@ -168,6 +168,8 @@
 $wgDeferredUpdateList = array();
 $wgPostCommitUpdateList = array();
 
+if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
+
 wfSeedRandom();
 
 # Placeholders in case of DB error
Index: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php	(revision 15887)
+++ trunk/phase3/includes/OutputPage.php	(revision 15888)
@@ -484,7 +484,7 @@
 	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 @@
 		$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: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 15887)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 15888)
@@ -2136,16 +2136,24 @@
 $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
  */
 $wgAllowDisplayTitle = false ;
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 15887)
+++ trunk/phase3/RELEASE-NOTES	(revision 15888)
@@ -105,8 +105,9 @@
   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 ==
 
 * Albanian (sq)
Views
Toolbox