r71444 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71443‎ | r71444 | r71445 >
Date:21:14, 22 August 2010
Author:ashley
Status:ok (Comments)
Tags:
Comment:
coding style tweaks for ajax.js
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/skins/common/ajax.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/ajax.js
@@ -1,30 +1,35 @@
22 // remote scripting library
33 // (c) copyright 2005 modernmethod, inc
44 var sajax_debug_mode = false;
5 -var sajax_request_type = "GET";
 5+var sajax_request_type = 'GET';
66
77 /**
8 -* if sajax_debug_mode is true, this function outputs given the message into
9 -* the element with id = sajax_debug; if no such element exists in the document,
10 -* it is injected.
11 -*/
12 -function sajax_debug(text) {
13 - if (!sajax_debug_mode) return false;
 8+ * if sajax_debug_mode is true, this function outputs given the message into
 9+ * the element with id = sajax_debug; if no such element exists in the document,
 10+ * it is injected.
 11+ */
 12+function sajax_debug( text ) {
 13+ if ( !sajax_debug_mode ) {
 14+ return false;
 15+ }
1416
15 - var e= document.getElementById('sajax_debug');
 17+ var e = document.getElementById( 'sajax_debug' );
1618
17 - if (!e) {
18 - e= document.createElement("p");
19 - e.className= 'sajax_debug';
20 - e.id= 'sajax_debug';
 19+ if ( !e ) {
 20+ e = document.createElement( 'p' );
 21+ e.className = 'sajax_debug';
 22+ e.id = 'sajax_debug';
2123
22 - var b= document.getElementsByTagName("body")[0];
 24+ var b = document.getElementsByTagName( 'body' )[0];
2325
24 - if (b.firstChild) b.insertBefore(e, b.firstChild);
25 - else b.appendChild(e);
 26+ if ( b.firstChild ) {
 27+ b.insertBefore( e, b.firstChild );
 28+ } else {
 29+ b.appendChild( e );
 30+ }
2631 }
2732
28 - var m= document.createElement("div");
 33+ var m = document.createElement( 'div' );
2934 m.appendChild( document.createTextNode( text ) );
3035
3136 e.appendChild( m );
@@ -33,123 +38,131 @@
3439 }
3540
3641 /**
37 -* compatibility wrapper for creating a new XMLHttpRequest object.
38 -*/
 42+ * Compatibility wrapper for creating a new XMLHttpRequest object.
 43+ */
3944 function sajax_init_object() {
40 - sajax_debug("sajax_init_object() called..")
 45+ sajax_debug( 'sajax_init_object() called..' );
4146 var A;
4247 try {
4348 // Try the new style before ActiveX so we don't
4449 // unnecessarily trigger warnings in IE 7 when
4550 // set to prompt about ActiveX usage
4651 A = new XMLHttpRequest();
47 - } catch (e) {
 52+ } catch ( e ) {
4853 try {
49 - A=new ActiveXObject("Msxml2.XMLHTTP");
50 - } catch (e) {
 54+ A = new ActiveXObject( 'Msxml2.XMLHTTP' );
 55+ } catch ( e ) {
5156 try {
52 - A=new ActiveXObject("Microsoft.XMLHTTP");
53 - } catch (oc) {
54 - A=null;
 57+ A = new ActiveXObject( 'Microsoft.XMLHTTP' );
 58+ } catch ( oc ) {
 59+ A = null;
5560 }
5661 }
5762 }
58 - if (!A)
59 - sajax_debug("Could not create connection object.");
 63+ if ( !A ) {
 64+ sajax_debug( 'Could not create connection object.' );
 65+ }
6066
6167 return A;
6268 }
6369
6470 /**
65 -* Perform an ajax call to mediawiki. Calls are handeled by AjaxDispatcher.php
66 -* func_name - the name of the function to call. Must be registered in $wgAjaxExportList
67 -* args - an array of arguments to that function
68 -* target - the target that will handle the result of the call. If this is a function,
69 -* if will be called with the XMLHttpRequest as a parameter; if it's an input
70 -* element, its value will be set to the resultText; if it's another type of
71 -* element, its innerHTML will be set to the resultText.
72 -*
73 -* Example:
74 -* sajax_do_call('doFoo', [1, 2, 3], document.getElementById("showFoo"));
75 -*
76 -* This will call the doFoo function via MediaWiki's AjaxDispatcher, with
77 -* (1, 2, 3) as the parameter list, and will show the result in the element
78 -* with id = showFoo
79 -*/
80 -function sajax_do_call(func_name, args, target) {
 71+ * Perform an AJAX call to MediaWiki. Calls are handled by AjaxDispatcher.php
 72+ * func_name - the name of the function to call. Must be registered in $wgAjaxExportList
 73+ * args - an array of arguments to that function
 74+ * target - the target that will handle the result of the call. If this is a function,
 75+ * if will be called with the XMLHttpRequest as a parameter; if it's an input
 76+ * element, its value will be set to the resultText; if it's another type of
 77+ * element, its innerHTML will be set to the resultText.
 78+ *
 79+ * Example:
 80+ * sajax_do_call( 'doFoo', [1, 2, 3], document.getElementById( 'showFoo' ) );
 81+ *
 82+ * This will call the doFoo function via MediaWiki's AjaxDispatcher, with
 83+ * (1, 2, 3) as the parameter list, and will show the result in the element
 84+ * with id = showFoo
 85+ */
 86+function sajax_do_call( func_name, args, target ) {
8187 var i, x, n;
8288 var uri;
8389 var post_data;
8490 uri = wgServer +
85 - ((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript) +
86 - "?action=ajax";
87 - if (sajax_request_type == "GET") {
88 - if (uri.indexOf("?") == -1)
89 - uri = uri + "?rs=" + encodeURIComponent(func_name);
90 - else
91 - uri = uri + "&rs=" + encodeURIComponent(func_name);
92 - for (i = 0; i < args.length; i++)
93 - uri = uri + "&rsargs[]=" + encodeURIComponent(args[i]);
94 - //uri = uri + "&rsrnd=" + new Date().getTime();
 91+ ( ( wgScript == null ) ? ( wgScriptPath + '/index.php' ) : wgScript ) +
 92+ '?action=ajax';
 93+ if ( sajax_request_type == 'GET' ) {
 94+ if ( uri.indexOf( '?' ) == -1 ) {
 95+ uri = uri + '?rs=' + encodeURIComponent( func_name );
 96+ } else {
 97+ uri = uri + '&rs=' + encodeURIComponent( func_name );
 98+ }
 99+ for ( i = 0; i < args.length; i++ ) {
 100+ uri = uri + '&rsargs[]=' + encodeURIComponent( args[i] );
 101+ }
 102+ //uri = uri + '&rsrnd=' + new Date().getTime();
95103 post_data = null;
96104 } else {
97 - post_data = "rs=" + encodeURIComponent(func_name);
98 - for (i = 0; i < args.length; i++)
99 - post_data = post_data + "&rsargs[]=" + encodeURIComponent(args[i]);
 105+ post_data = 'rs=' + encodeURIComponent( func_name );
 106+ for ( i = 0; i < args.length; i++ ) {
 107+ post_data = post_data + '&rsargs[]=' + encodeURIComponent( args[i] );
 108+ }
100109 }
101110 x = sajax_init_object();
102 - if (!x) {
103 - alert("AJAX not supported");
 111+ if ( !x ) {
 112+ alert( 'AJAX not supported' );
104113 return false;
105114 }
106115
107116 try {
108 - x.open(sajax_request_type, uri, true);
109 - } catch (e) {
110 - if (window.location.hostname == "localhost") {
111 - alert("Your browser blocks XMLHttpRequest to 'localhost', try using a real hostname for development/testing.");
 117+ x.open( sajax_request_type, uri, true );
 118+ } catch ( e ) {
 119+ if ( window.location.hostname == 'localhost' ) {
 120+ alert( "Your browser blocks XMLHttpRequest to 'localhost', try using a real hostname for development/testing." );
112121 }
113122 throw e;
114123 }
115 - if (sajax_request_type == "POST") {
116 - x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
117 - x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 124+ if ( sajax_request_type == 'POST' ) {
 125+ x.setRequestHeader( 'Method', 'POST ' + uri + ' HTTP/1.1' );
 126+ x.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
118127 }
119 - x.setRequestHeader("Pragma", "cache=yes");
120 - x.setRequestHeader("Cache-Control", "no-transform");
 128+ x.setRequestHeader( 'Pragma', 'cache=yes' );
 129+ x.setRequestHeader( 'Cache-Control', 'no-transform' );
121130 x.onreadystatechange = function() {
122 - if (x.readyState != 4)
 131+ if ( x.readyState != 4 ) {
123132 return;
 133+ }
124134
125 - sajax_debug("received (" + x.status + " " + x.statusText + ") " + x.responseText);
 135+ sajax_debug( 'received (' + x.status + ' ' + x.statusText + ') ' + x.responseText );
126136
127 - //if (x.status != 200)
128 - // alert("Error: " + x.status + " " + x.statusText + ": " + x.responseText);
 137+ //if ( x.status != 200 )
 138+ // alert( 'Error: ' + x.status + ' ' + x.statusText + ': ' + x.responseText );
129139 //else
130140
131141 if ( typeof( target ) == 'function' ) {
132142 target( x );
133 - }
134 - else if ( typeof( target ) == 'object' ) {
 143+ } else if ( typeof( target ) == 'object' ) {
135144 if ( target.tagName == 'INPUT' ) {
136 - if (x.status == 200) target.value= x.responseText;
137 - //else alert("Error: " + x.status + " " + x.statusText + " (" + x.responseText + ")");
 145+ if ( x.status == 200 ) {
 146+ target.value= x.responseText;
 147+ }
 148+ //else alert( 'Error: ' + x.status + ' ' + x.statusText + ' (' + x.responseText + ')' );
 149+ } else {
 150+ if ( x.status == 200 ) {
 151+ target.innerHTML = x.responseText;
 152+ } else {
 153+ target.innerHTML = '<div class="error">Error: ' + x.status +
 154+ ' ' + x.statusText + ' (' + x.responseText + ')</div>';
 155+ }
138156 }
139 - else {
140 - if (x.status == 200) target.innerHTML = x.responseText;
141 - else target.innerHTML= "<div class='error'>Error: " + x.status + " " + x.statusText + " (" + x.responseText + ")</div>";
142 - }
 157+ } else {
 158+ alert( 'bad target for sajax_do_call: not a function or object: ' + target );
143159 }
144 - else {
145 - alert("bad target for sajax_do_call: not a function or object: " + target);
146 - }
147160
148161 return;
149162 }
150163
151 - sajax_debug(func_name + " uri = " + uri + " / post = " + post_data);
152 - x.send(post_data);
153 - sajax_debug(func_name + " waiting..");
 164+ sajax_debug( func_name + ' uri = ' + uri + ' / post = ' + post_data );
 165+ x.send( post_data );
 166+ sajax_debug( func_name + ' waiting..' );
154167 delete x;
155168
156169 return true;
@@ -164,4 +177,3 @@
165178 delete request;
166179 return supportsAjax;
167180 }
168 -
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1560,7 +1560,7 @@
15611561 * to ensure that client-side caches do not keep obsolete copies of global
15621562 * styles.
15631563 */
1564 -$wgStyleVersion = '300';
 1564+$wgStyleVersion = '301';
15651565
15661566 /**
15671567 * This will cache static pages for non-logged-in users to reduce

Comments

#Comment by Siebrand (talk | contribs)   22:22, 22 August 2010

No need to revert, but I think coding style changes do not require $wgStyleVersion to be updated, or do they?

#Comment by Hashar (talk | contribs)   06:48, 25 October 2010

I am for raising $wgStyleVersion since coding style might implements a bug^H^H^Hfeature :-)

Marking ok.

Status & tagging log