From: Daniel Kinzler Date: Sun, 30 Jul 2006 10:53:22 +0000 (+0000) Subject: Separated ajax search box features from core ajax framework. X-Git-Tag: 1.31.0-rc.0~56124 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=6a64a7eaee23b892637d977320f097a4fe207afc;p=lhc%2Fweb%2Fwiklou.git Separated ajax search box features from core ajax framework. Note that ajax search is currently broken (some issue with message parsing) --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index cb9538e92a..c050a44830 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 873bd5211f..8cd5f7d01b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/OutputPage.php b/includes/OutputPage.php index ce4f17608b..e677dcbacd 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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( "" ); $this->addScript( "\n" ); } + if ( $wgUseAjax && $wgAjaxSearch ) { + $this->addScript( "\n" ); + $this->addScript( "\n" ); + } + if ( '' != $this->mRedirect ) { if( substr( $this->mRedirect, 0, 4 ) != 'http' ) { # Standards require redirect URLs to be absolute diff --git a/includes/Setup.php b/includes/Setup.php index 68a4802e8b..2a8e6e5b92 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -168,6 +168,8 @@ wfProfileIn( $fname.'-misc2' ); $wgDeferredUpdateList = array(); $wgPostCommitUpdateList = array(); +if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch'; + wfSeedRandom(); # Placeholders in case of DB error diff --git a/skins/common/ajax.js b/skins/common/ajax.js index 9067654881..f9f9624443 100644 --- a/skins/common/ajax.js +++ b/skins/common/ajax.js @@ -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= '
' ; - 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 index 0000000000..f7973b7d7a --- /dev/null +++ b/skins/common/ajaxsearch.js @@ -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= '
' ; + 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"); +}