MediaWiki r15888 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r15887‎ | r15888 (on ViewVC)‎ | r15889 >
Date:10:53, 30 July 2006
Author:daniel
Status:old
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
@@ -0,0 +1,101 @@
 2+// remote scripting library
 3+// (c) copyright 2005 modernmethod, inc
 4+
 5+var started;
 6+var typing;
 7+var memory=null;
 8+var body=null;
 9+var oldbody=null;
 10+
 11+// Remove the typing barrier to allow call() to complete
 12+function Search_doneTyping()
 13+{
 14+ typing=false;
 15+}
 16+
 17+// Wait 500ms to run call()
 18+function Searching_Go()
 19+{
 20+ setTimeout("Searching_Call()", 500);
 21+}
 22+
 23+// If the user is typing wait until they are done.
 24+function Search_Typing() {
 25+ started=true;
 26+ typing=true;
 27+ window.status = "Waiting until you're done typing...";
 28+ setTimeout("Search_doneTyping()", 500);
 29+
 30+ // I believe these are needed by IE for when the users press return?
 31+ if (window.event)
 32+ {
 33+ if (event.keyCode == 13)
 34+ {
 35+ event.cancelBubble = true;
 36+ event.returnValue = false;
 37+ }
 38+ }
 39+}
 40+
 41+// Set the body div to the results
 42+function Searching_SetResult(result)
 43+{
 44+ //body.innerHTML = result;
 45+ t = document.getElementById("searchTarget");
 46+ if ( t == null ) {
 47+ oldbody=body.innerHTML;
 48+ body.innerHTML= '<div id="searchTargetContainer"><div id="searchTarget" ></div></div>' ;
 49+ t = document.getElementById("searchTarget");
 50+ }
 51+ t.innerHTML = result;
 52+ t.style.display='block';
 53+}
 54+
 55+function Searching_Hide_Results()
 56+{
 57+ t = document.getElementById("searchTarget");
 58+ t.style.display='none';
 59+ body.innerHTML = oldbody;
 60+}
 61+
 62+
 63+// This will call the php function that will eventually
 64+// return a results table
 65+function Searching_Call()
 66+{
 67+ var x;
 68+ Searching_Go();
 69+
 70+ //Don't proceed if user is typing
 71+ if (typing)
 72+ return;
 73+
 74+ x = document.getElementById("searchInput").value;
 75+
 76+ // Don't search again if the query is the same
 77+ if (x==memory)
 78+ return;
 79+
 80+ memory=x;
 81+ if (started) {
 82+ // Don't search for blank or < 3 chars.
 83+ if ((x=="") || (x.length < 3))
 84+ {
 85+ return;
 86+ }
 87+ x_wfSajaxSearch(x, Searching_SetResult);
 88+ }
 89+}
 90+
 91+function x_wfSajaxSearch() {
 92+ sajax_do_call( "wfSajaxSearch", x_wfSajaxSearch.arguments );
 93+}
 94+
 95+
 96+//Initialize
 97+function sajax_onload() {
 98+ x = document.getElementById( 'searchInput' );
 99+ x.onkeypress= function() { Search_Typing(); };
 100+ Searching_Go();
 101+ body = document.getElementById("content");
 102+}
Property changes on: trunk/phase3/skins/common/ajaxsearch.js
___________________________________________________________________
Name: svn:eol-style
1103 + native
Name: svn:keywords
2104 + Author Date Id Revision
Index: trunk/phase3/skins/common/ajax.js
@@ -3,18 +3,11 @@
44 var sajax_debug_mode = false;
55 var sajax_request_type = "GET";
66
7 -var started;
8 -var typing;
9 -var memory=null;
10 -var body=null;
11 -var oldbody=null;
12 -
137 function sajax_debug(text) {
148 if (sajax_debug_mode)
159 alert("RSD: " + text)
1610 }
1711
18 -
1912 function sajax_init_object() {
2013 sajax_debug("sajax_init_object() called..")
2114 var A;
@@ -80,98 +73,3 @@
8174 sajax_debug(func_name + " waiting..");
8275 delete x;
8376 }
84 -
85 -// Remove the typing barrier to allow call() to complete
86 -function Search_doneTyping()
87 -{
88 - typing=false;
89 -}
90 -
91 -// Wait 500ms to run call()
92 -function Searching_Go()
93 -{
94 - setTimeout("Searching_Call()", 500);
95 -}
96 -
97 -// If the user is typing wait until they are done.
98 -function Search_Typing() {
99 - started=true;
100 - typing=true;
101 - window.status = "Waiting until you're done typing...";
102 - setTimeout("Search_doneTyping()", 500);
103 -
104 - // I believe these are needed by IE for when the users press return?
105 - if (window.event)
106 - {
107 - if (event.keyCode == 13)
108 - {
109 - event.cancelBubble = true;
110 - event.returnValue = false;
111 - }
112 - }
113 -}
114 -
115 -// Set the body div to the results
116 -function Searching_SetResult(result)
117 -{
118 - //body.innerHTML = result;
119 - t = document.getElementById("searchTarget");
120 - if ( t == null ) {
121 - oldbody=body.innerHTML;
122 - body.innerHTML= '<div id="searchTargetContainer"><div id="searchTarget" ></div></div>' ;
123 - t = document.getElementById("searchTarget");
124 - }
125 - t.innerHTML = result;
126 - t.style.display='block';
127 -}
128 -
129 -function Searching_Hide_Results()
130 -{
131 - t = document.getElementById("searchTarget");
132 - t.style.display='none';
133 - body.innerHTML = oldbody;
134 -}
135 -
136 -
137 -// This will call the php function that will eventually
138 -// return a results table
139 -function Searching_Call()
140 -{
141 - var x;
142 - Searching_Go();
143 -
144 - //Don't proceed if user is typing
145 - if (typing)
146 - return;
147 -
148 - x = document.getElementById("searchInput").value;
149 -
150 - // Don't search again if the query is the same
151 - if (x==memory)
152 - return;
153 -
154 - memory=x;
155 - if (started) {
156 - // Don't search for blank or < 3 chars.
157 - if ((x=="") || (x.length < 3))
158 - {
159 - return;
160 - }
161 - x_wfSajaxSearch(x, Searching_SetResult);
162 - }
163 -}
164 -
165 -function x_wfSajaxSearch() {
166 - sajax_do_call( "wfSajaxSearch", x_wfSajaxSearch.arguments );
167 -}
168 -
169 -
170 -//Initialize
171 -function sajax_onload() {
172 - x = document.getElementById( 'searchInput' );
173 - x.onkeypress= function() { Search_Typing(); };
174 - Searching_Go();
175 - body = document.getElementById("content");
176 -}
177 -
178 -hookEvent("load", sajax_onload);
Index: trunk/phase3/includes/Setup.php
@@ -168,6 +168,8 @@
169169 $wgDeferredUpdateList = array();
170170 $wgPostCommitUpdateList = array();
171171
 172+if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
 173+
172174 wfSeedRandom();
173175
174176 # Placeholders in case of DB error
Index: trunk/phase3/includes/OutputPage.php
@@ -484,7 +484,7 @@
485485 function output() {
486486 global $wgUser, $wgOutputEncoding;
487487 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
488 - global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
 488+ global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgScriptPath, $wgServer;
489489
490490 if( $this->mDoNothing ){
491491 return;
@@ -494,13 +494,14 @@
495495 $sk = $wgUser->getSkin();
496496
497497 if ( $wgUseAjax ) {
498 - $this->addScript( "<script type=\"{$wgJsMimeType}\">
499 - var wgScriptPath=\"{$wgScriptPath}\";
500 - var wgServer=\"{$wgServer}\";
501 - </script>" );
502498 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
503499 }
504500
 501+ if ( $wgUseAjax && $wgAjaxSearch ) {
 502+ $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js\"></script>\n" );
 503+ $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
 504+ }
 505+
505506 if ( '' != $this->mRedirect ) {
506507 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
507508 # Standards require redirect URLs to be absolute
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2136,16 +2136,24 @@
21372137 $wgUpdateRowsPerQuery = 10;
21382138
21392139 /**
2140 - * Enable use of AJAX features, currently auto suggestion for the search bar
 2140+ * Enable AJAX framework
21412141 */
21422142 $wgUseAjax = false;
21432143
21442144 /**
2145 - * List of Ajax-callable functions
 2145+ * Enable auto suggestion for the search bar
 2146+ * Requires $wgUseAjax to be true too.
 2147+ * Causes wfSajaxSearch to be added to $wgAjaxExportList
21462148 */
2147 -$wgAjaxExportList = array( 'wfSajaxSearch' );
 2149+$wgAjaxSearch = false;
21482150
21492151 /**
 2152+ * List of Ajax-callable functions.
 2153+ * Extensions acting as Ajax callbacks must register here
 2154+ */
 2155+$wgAjaxExportList = array( );
 2156+
 2157+/**
21502158 * Allow DISPLAYTITLE to change title display
21512159 */
21522160 $wgAllowDisplayTitle = false ;
Index: trunk/phase3/RELEASE-NOTES
@@ -105,8 +105,9 @@
106106 page title, etc.
107107 * hooks registered with addOnloadHook are now called at the one of the html body
108108 by all skins.
 109+* Split ajax aided search from core ajax framework. Use wgUseAjax to enable the
 110+ framework and wgAjaxSearch to enable the suggest feature for the search box.
109111
110 -
111112 == Languages updated ==
112113
113114 * Albanian (sq)