r62280 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62279‎ | r62280 | r62281 >
Date:23:29, 10 February 2010
Author:dale
Status:deferred
Tags:
Comment:
* some mw.ApiProxy clean up
* tested with /tests/testApiProxy.html
** renamed to mw.ApiProxy (since its an object should have upper case first letter)
** used local scope vars
** removed jQuery binding ( could be confusing with jquery 1.4 $j.proxy function )
Modified paths:
  • /branches/js2-work/phase3/js/apiProxyPage.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/NestedCallbackIframe.html (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/loader.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js (added) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.proxy.js (deleted) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html
@@ -32,7 +32,7 @@
3333 'action':'query',
3434 'meta':'userinfo'
3535 }
36 - // Do proxy request
 36+ // Do request ( will automatically invoke proxy because its a proxy action and remote url )
3737 mw.getJSON( remote_api_url, rObj, function( data ){
3838 //now we get the data back for that domain
3939 if( !data.query || !data.query.userinfo ){
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -2408,40 +2408,9 @@
24092409 // Get any extra categories or helpful links
24102410 description += resource.pSobj.getExtraResourceDescWiki( resource );
24112411 return description;
2412 - },
 2412+ },
24132413
24142414 /**
2415 - * Sets up the proxy for the remote inserts
2416 - *
2417 - * @param {Function} callbcak Function to call once proxy is setup.
2418 - */
2419 - setupProxy: function( callback ) {
2420 - var _this = this;
2421 -
2422 - if ( _this.proxySetupDone ) {
2423 - if ( callback )
2424 - callback();
2425 - return;
2426 - }
2427 - // setup the the proxy via $j.apiProxy loader:
2428 - if ( !_this.upload_api_proxy_frame ) {
2429 - mw.log( "Error:: remote api but no proxy frame target" );
2430 - return false;
2431 - } else {
2432 - $j.apiProxy(
2433 - 'client',
2434 - {
2435 - 'server_frame': _this.upload_api_proxy_frame
2436 - }, function() {
2437 - _this.proxySetupDone = true
2438 - if ( callback )
2439 - callback();
2440 - }
2441 - );
2442 - }
2443 - },
2444 -
2445 - /**
24462415 * Check the local wiki for a given fileName
24472416 *
24482417 * @param {String} fileName File Name of the requested file
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.proxy.js
@@ -1,337 +0,0 @@
2 -/**
3 -*
4 -* Api proxy system
5 -*
6 -* Supports cross domain uploading, and api actions for a approved set of domains.
7 -*
8 -* The framework /will/ support a request approval system for per-user domain approval
9 -* and a central blacklisting of domains controlled by the site
10 -*
11 -* Flow outline below:
12 -*
13 -* Domain A (lets say en.wiki)
14 -* invokes add-media-wizard and wants to upload to domain B ( commons.wiki )
15 -*
16 -* Domain A loads iframe to domain B ? with request param to to insert from Domain A
17 -* Domain B checks list of approved domains for (Domain A) & checks the user is logged in ( and if the same account name )
18 -* if user is not logged in
19 -* a _link_ to Domain B to new window login page is given
20 -* if user has not approved domain and (Domain A) is not pre-approved
21 -* a new page link is generated with a approve domain request
22 -* if user approves domain it goes into their User:{username}/apiProxyDomains.js config
23 -* If Domain A is approved we then:
24 -* loads a "push" and "pull" iframe back to Domain A
25 - (Domain B can change the #hash values of these children thereby proxy the data)
26 -* Domain A now gets the iframe "loaded" callback a does a initial echo to confirm cross domain proxy
27 -* echo sends "echo" to push and (Domain A) js passes the echo onto the "pull"
28 -* Domain A now sends api requests to the iframe "push" child and gets results from the iframe "pull"
29 -* api actions happen with status updates and everything and we can reuse existing api interface code
30 -*
31 -* if the browser supports it we can pass msgs with the postMessage API
32 -* http://ejohn.org/blog/cross-window-messaging/
33 -*
34 -* NOTE: it would be nice if this supported multiple proxy targets (ie to a bright widgets future)
35 -*
36 -*/
37 -
38 -mw.addMessages( {
39 - "mwe-setting-up-proxy" : "Setting up proxy...",
40 - "mwe-re-try" : "Retry API request",
41 - "mwe-re-trying" : "Retrying API request...",
42 - "mwe-proxy-not-ready" : "Proxy is not configured",
43 - "mwe-please-login" : "You are not <a target=\"_new\" href=\"$1\">logged in<\/a> on $2 or mwEmbed has not been enabled. Resolve the issue, and then retry the request.",
44 - "mwe-remember-loging" : "General security reminder: Only login to web sites when your address bar displays that site's address."
45 -} );
46 -
47 -
48 -
49 -
50 -/**
51 - * apiProxy jQuery binding
52 - *
53 - * Note: probably should split up "server" and "client" binding
54 - *
55 - * @param {String} mode Mode is either 'server' or 'client'
56 - * @param {Object} proxyConfig Proxy configuration
57 - * @param {Function} callback The function called once proxy request is done
58 - */
59 -( function( $ ) {
60 - $.apiProxy = function( mode, proxyConfig, callback ) {
61 - mw.log( 'do apiProxy setup' );
62 - // do the proxy setup or
63 - if ( mode == 'client' ) {
64 - // just do the setup (no callbcak for client setup)
65 - mw.proxy.client( proxyConfig );
66 - if ( callback )
67 - callback();
68 - } else if ( mode == 'server' ) {
69 - // Do the request with the callback
70 - mw.proxy.server( proxyConfig , callback );
71 - }
72 - }
73 -} )( jQuery );
74 -
75 -( function( $ ) {
76 -
77 - /**
78 - * Base API Proxy object
79 - *
80 - */
81 - $.proxy = { };
82 -
83 - /**
84 - * The client setup function:
85 - *
86 - * @param {Object} proxyConfig Holds the server_frame & client_frame_path vars
87 - */
88 - $.proxy.client = function( proxyConfig ) {
89 - var _this = this;
90 - // Do client setup:
91 - if ( proxyConfig.server_frame )
92 - $.proxy.server_frame = proxyConfig.server_frame;
93 -
94 - if ( proxyConfig.client_frame_path ) {
95 - $.proxy.client_frame_path = proxyConfig.client_frame_path;
96 - } else {
97 - // Set to default via mediaWiki vars:
98 - $.proxy.client_frame_path = wgServer + wgScriptPath + '/js/mwEmbed/modules/ApiProxy/NestedCallbackIframe.html';
99 - }
100 -
101 - if ( mw.isLocalDomain( $.proxy.server_frame ) ) {
102 - mw.log( "Error: trying to proxy local domain? " );
103 - return false;
104 - }
105 - return true;
106 - }
107 - // Set the frameProxy Flag:
108 - var frameProxyOk = false;
109 -
110 - /**
111 - * Does the frame proxy
112 - * Writes an iframe with a hashed value of the requestQuery
113 - *
114 - * @param {Object} requestQuery The api request object
115 - */
116 - $.proxy.doFrameProxy = function( requestQuery ) {
117 -
118 - var hashPack = {
119 - // Client domain:
120 - 'clientFrame' : $.proxy.client_frame_path,
121 - 'request' : requestQuery
122 - }
123 -
124 - mw.log( "Do frame proxy request on src: \n" + $.proxy.server_frame + "\n" + JSON.stringify( requestQuery ) );
125 -
126 - // We can't update src's so we have to remove and add all the time :(
127 - // NOTE: we should support frame msg system
128 - $j( '#frame_proxy' ).remove();
129 - $j( 'body' ).append( '<iframe style="display:none" id="frame_proxy" name="frame_proxy" ' +
130 - 'src="' + $.proxy.server_frame +
131 - '#' + escape( JSON.stringify( hashPack ) ) +
132 - '"></iframe>' );
133 -
134 - // add an onLoad hook:
135 - $j( '#frame_proxy' ).get( 0 ).onload = function() {
136 - // add a 8 second timeout for setting up the nested child callback (after page load)
137 - setTimeout( function() {
138 - if ( !frameProxyOk ) {
139 - // we timmed out no api proxy (should make sure the user is "logged in")
140 - mw.log( "Error:: api proxy timeout are we logged in? mwEmbed is on?" );
141 - $.proxy.proxyNotReadyDialog();
142 - }
143 - }, 8000 );
144 - }
145 - }
146 - var lastApiReq = { };
147 -
148 - /**
149 - * Dialog to send the user if a proxy to the remote server could not be created
150 - */
151 - $.proxy.proxyNotReadyDialog = function() {
152 - var buttons = { };
153 - buttons[ gM( 'mwe-re-try' ) ] = function() {
154 - mw.addLoaderDialog( gM( 'mwe-re-trying' ) );
155 - $.proxy.doFrameProxy( lastApiReq );
156 - }
157 - buttons[ gM( 'mwe-cancel' ) ] = function() {
158 - mw.closeLoaderDialog();
159 - }
160 - var pUri = mw.parseUri( $.proxy.server_frame );
161 -
162 - // FIXME we should have a Hosted page once we deploy mwEmbed on the servers.
163 - // A hosted page would be much faster since than a normal page view rewrite
164 -
165 - var login_url = pUri.protocol + '://' + pUri.host;
166 - login_url += pUri.path.replace( 'MediaWiki:ApiProxy', 'Special:UserLogin' );
167 -
168 - mw.addDialog(
169 - gM( 'mwe-proxy-not-ready' ),
170 - gM( 'mwe-please-login', [ login_url, pUri.host] ) +
171 - '<p style="font-size:small">' +
172 - gM( 'mwe-remember-loging' ) +
173 - '</p>',
174 - buttons
175 - )
176 - }
177 - /**
178 - * Takes a requestQuery, executes the query and then calls the callback
179 - * sets the local callback to be called once requestQuery completes
180 - *
181 - * @param {Object} requestQuery Api request object
182 - * @param {Function} callback Function called once the request is complete
183 - */
184 - $.proxy.doRequest = function( requestQuery, callback ) {
185 - mw.log( "doRequest:: " + JSON.stringify( requestQuery ) );
186 - lastApiReq = requestQuery;
187 - // setup the callback:
188 - $.proxy.callback = callback;
189 - // do the proxy req:
190 - $.proxy.doFrameProxy( requestQuery );
191 - }
192 -
193 - /**
194 - * The nested iframe action that passes its result back up to the top frame instance
195 - *
196 - * Entry point for hashResult from nested iframe
197 - *
198 - * @param {Object} hashResult Value to be sent to parent frame
199 - */
200 - $.proxy.nested = function( hashResult ) {
201 - // Close the loader if present:
202 - mw.closeLoaderDialog();
203 - mw.log( '$.proxy.nested callback :: ' + unescape( hashResult ) );
204 - frameProxyOk = true;
205 -
206 - // Try to parse the hash result
207 - try {
208 - var resultObject = JSON.parse( unescape( hashResult ) );
209 - } catch ( e ) {
210 - mw.log( "Error could not parse hashResult" );
211 - }
212 -
213 - // Special callback to frameProxyOk flag
214 - // (only used to test the proxy connection)
215 - if ( resultObject.state == 'ok' )
216 - return ;
217 -
218 - // Pass the result object to the callback:
219 - $.proxy.callback( resultObject );
220 - }
221 -
222 -
223 -
224 -
225 - /**
226 - * API iFrame Server::
227 - *
228 - * Handles the server side proxy of requests
229 - * it adds child frames pointing to the parent "blank" frames
230 - */
231 -
232 - /**
233 - * Api iFrame request:
234 - * @param {Object} requestObj Api request object
235 - */
236 - function doApiRequest( clientRequest ) {
237 -
238 - // Make sure its a json format
239 - clientRequest.request[ 'format' ] = 'json';
240 -
241 - // Process the API request. We don't use mw.apiReq since we need to "post"
242 - $j.post( wgScriptPath + '/api' + wgScriptExtension,
243 - clientRequest.request,
244 - function( data ) {
245 - // Put it result into nested frame hash string:
246 - outputResultsFrame( clientRequest.clientFrame, 'nested_push', JSON.parse( data ) );
247 - }
248 - );
249 - }
250 -
251 - /**
252 - * Outputs the result object to the client domain
253 - *
254 - * @param {clientFrame} clientFrame Client frame name
255 - * @param {String} nestName Name of iframe
256 - * @param {resultObj} the result to pass back to the client domain
257 - */
258 - function outputResultsFrame( clientFrame, nestName, resultObj ) {
259 - $j( '#nested_push' ).remove();
260 - // Setup the nested iframe proxy that points back to top domain:
261 - $j( 'body' ).append(
262 - $j('<iframe>').attr({
263 - 'id' : nestName,
264 - 'name' : nestName,
265 - 'src' : clientFrame + '#' + escape( JSON.stringify( resultObj ) )
266 - })
267 - );
268 - }
269 -
270 - /**
271 - * Api server proxy entry point:
272 - *
273 - * @param {Object} proxyConfig The server side proxy configuration
274 - * @param {Function} callbcak Function to call once server is setup
275 - *
276 - */
277 - $.proxy.server = function( proxyConfig, callback ) {
278 - /**
279 - * Clear the body of any html
280 - */
281 - $j( 'body' ).html( 'Proxy Setup: ' );
282 -
283 - var clientRequest = false;
284 -
285 - // Read the anchor action from the requesting url
286 - var hashMsg = unescape( mw.parseUri( document.URL ).anchor );
287 - try {
288 - var clientRequest = JSON.parse( hashMsg );
289 - } catch ( e ) {
290 - mw.log( "ProxyServer:: could not parse anchor" );
291 - }
292 -
293 - if ( !clientRequest || !clientRequest.clientFrame ) {
294 - mw.log( "Error: no client domain provided " );
295 - $j( 'body' ).append( "no client frame provided" );
296 - return false;
297 - }
298 -
299 - // Make sure we are logged in
300 - // (its a normal mediaWiki page so all site vars should be defined)
301 - if ( typeof wgUserName != 'undefined' && !wgUserName ) {
302 - mw.log( 'Error Not logged in' );
303 - return false;
304 - }
305 -
306 - mw.log( "Setup server on: " + mw.parseUri( document.URL ).host );
307 - mw.log('Client frame: ' + clientRequest.clientFrame );
308 -
309 - var clientDomain = mw.parseUri( clientRequest.clientFrame ).host ;
310 -
311 - /**
312 - * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig
313 - */
314 - // Check master blacklist
315 - for ( var i in proxyConfig.master_blacklist ) {
316 - if ( clientDomain == proxyConfig.master_blacklist ) {
317 - mw.log( 'domain: ' + clientDomain + ' is blacklisted ( no request )' );
318 - return false;
319 - }
320 - }
321 - // Check the master whitelist:
322 - for ( var i in proxyConfig.master_whitelist ) {
323 - if ( clientDomain == proxyConfig.master_whitelist[ i ] ) {
324 - // Do the request:
325 - return doApiRequest( clientRequest );
326 - }
327 - }
328 -
329 - // FIXME Add in user based approval ::
330 -
331 - // FIXME grab the users whitelist for our current domain
332 -
333 - // FIXME offer the user the ability to "approve" requested domain save to
334 - // their user preference setup )
335 -
336 - }
337 -
338 -} )( window.mw );
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/loader.js
@@ -1,13 +1,13 @@
22 /* apiProxy Loader */
33
44 mw.addClassFilePaths( {
5 - "mw.proxy" : "modules/ApiProxy/mw.proxy.js",
 5+ "mw.ApiProxy" : "modules/ApiProxy/mw.ApiProxy.js",
66 "JSON" : "modules/ApiProxy/json2.js"
77 } );
88
99 mw.addModuleLoader( 'ApiProxy', function( callback ){
1010 mw.load( [
11 - 'mw.proxy',
 11+ 'mw.ApiProxy',
1212 'JSON'
1313 ], function() {
1414 callback( 'ApiProxy' );
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/NestedCallbackIframe.html
@@ -6,7 +6,7 @@
77 <script type="text/javascript">
88 window.onload = function (){
99 //call the nested callback in top most frame:
10 - top.mw.proxy.nested( window.location.href.split("#")[1] || false );
 10+ top.mw.ApiProxy.nested( window.location.href.split("#")[1] || false );
1111 }
1212 </script>
1313 </head>
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js
@@ -0,0 +1,331 @@
 2+/**
 3+*
 4+* Api proxy system
 5+*
 6+* Supports cross domain uploading, and api actions for a approved set of domains.
 7+*
 8+* The framework ~will eventually~ support a request approval system for per-user domain approval
 9+* and a central blacklisting of domains controlled by the site
 10+*
 11+*
 12+* if the browser supports it we can pass msgs with the postMessage API
 13+* http://ejohn.org/blog/cross-window-messaging/
 14+*
 15+* NOTE: it would be nice if this supported multiple proxy targets (ie to a bright widgets future)
 16+*
 17+*/
 18+
 19+mw.addMessages( {
 20+ "mwe-setting-up-proxy" : "Setting up proxy...",
 21+ "mwe-re-try" : "Retry API request",
 22+ "mwe-re-trying" : "Retrying API request...",
 23+ "mwe-proxy-not-ready" : "Proxy is not configured",
 24+ "mwe-please-login" : "You are not <a target=\"_new\" href=\"$1\">logged in<\/a> on $2 or mwEmbed has not been enabled. Resolve the issue, and then retry the request.",
 25+ "mwe-remember-loging" : "General security reminder: Only login to web sites when your address bar displays that site's address."
 26+} );
 27+
 28+
 29+
 30+
 31+/**
 32+ * apiProxy jQuery binding
 33+ *
 34+ * Note: probably should split up "server" and "client" binding
 35+ *
 36+ * @param {String} mode Mode is either 'server' or 'client'
 37+ * @param {Object} proxyConfig Proxy configuration
 38+ * @param {Function} callback The function called once proxy request is done
 39+ */
 40+
 41+ /**
 42+ * Set the base API Proxy object
 43+ *
 44+ */
 45+mw.ApiProxy = { };
 46+
 47+// Proxy scoped functions:
 48+( function( $ ) {
 49+
 50+
 51+ // Local scope public vars
 52+ //( should probably tie these var defines to the scope of the doRequest call using something like "curry" function )
 53+
 54+ // Callback funcion for client requests
 55+ var proxyCallback = null;
 56+
 57+ // FrameProxy Flag:
 58+ var frameProxyOk = false;
 59+
 60+ // The last run api request data object
 61+ var currentApiReq = { };
 62+
 63+ // The url for the last api request target.
 64+ var currentApiUrl = null;
 65+
 66+ /**
 67+ * Takes a requestQuery, executes the query and then calls the callback
 68+ * sets the local callback to be called once requestQuery completes
 69+ *
 70+ * @param {String} apiUrl Url to the api we want to do the request on.
 71+ * @param {Object} requestQuery Api request object
 72+ * @param {Function} callback Function called once the request is complete
 73+ */
 74+ $.doRequest = function( apiUrl, requestQuery, callback ) {
 75+ // Reset local vars:
 76+ proxyCallback = false;
 77+ frameProxyOk = false;
 78+
 79+ // Sanity check:
 80+ if ( mw.isLocalDomain( apiUrl ) ) {
 81+ mw.log( "Error: trying to proxy local domain? " );
 82+ return false;
 83+ }
 84+
 85+ mw.log( "doRequest:: " + JSON.stringify( requestQuery ) );
 86+ currentApiReq = requestQuery;
 87+ currentApiUrl = apiUrl;
 88+ // Setup the callback:
 89+ proxyCallback = callback;
 90+ // Do the proxy req:
 91+ doFrameProxy( requestQuery );
 92+ }
 93+
 94+ /**
 95+ * The nested iframe action that passes its result back up to the top frame instance
 96+ *
 97+ * Entry point for hashResult from nested iframe
 98+ *
 99+ * @param {Object} hashResult Value to be sent to parent frame
 100+ */
 101+ $.nested = function( hashResult ) {
 102+ // Close the loader if present:
 103+ mw.closeLoaderDialog();
 104+ mw.log( '$.proxy.nested callback :: ' + unescape( hashResult ) );
 105+ frameProxyOk = true;
 106+
 107+ // Try to parse the hash result
 108+ try {
 109+ var resultObject = JSON.parse( unescape( hashResult ) );
 110+ } catch ( e ) {
 111+ mw.log( "Error could not parse hashResult" );
 112+ }
 113+
 114+ // Special callback to frameProxyOk flag
 115+ // (only used to test the proxy connection)
 116+ if ( resultObject.state == 'ok' )
 117+ return ;
 118+
 119+ // Pass the result object to the callback:
 120+ proxyCallback( resultObject );
 121+ }
 122+
 123+ /**
 124+ * Api server proxy entry point:
 125+ *
 126+ * @param {Object} proxyConfig The server side proxy configuration
 127+ * @param {Function} callbcak Function to call once server is setup
 128+ *
 129+ */
 130+ $.server = function( proxyConfig, callback ) {
 131+ /**
 132+ * Clear the body of any html
 133+ */
 134+ $j( 'body' ).html( 'Proxy Setup: ' );
 135+
 136+ var clientRequest = false;
 137+
 138+ // Read the anchor action from the requesting url
 139+ var hashMsg = unescape( mw.parseUri( document.URL ).anchor );
 140+ try {
 141+ var clientRequest = JSON.parse( hashMsg );
 142+ } catch ( e ) {
 143+ mw.log( "ProxyServer:: could not parse anchor" );
 144+ }
 145+
 146+ if ( !clientRequest || !clientRequest.clientFrame ) {
 147+ mw.log( "Error: no client domain provided " );
 148+ $j( 'body' ).append( "no client frame provided" );
 149+ return false;
 150+ }
 151+
 152+ // Make sure we are logged in
 153+ // (its a normal mediaWiki page so all site vars should be defined)
 154+ if ( typeof wgUserName != 'undefined' && !wgUserName ) {
 155+ mw.log( 'Error Not logged in' );
 156+ return false;
 157+ }
 158+
 159+ mw.log( "Setup server on: " + mw.parseUri( document.URL ).host );
 160+ mw.log('Client frame: ' + clientRequest.clientFrame );
 161+
 162+ var clientDomain = mw.parseUri( clientRequest.clientFrame ).host ;
 163+
 164+ /**
 165+ * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig
 166+ */
 167+ // Check master blacklist
 168+ for ( var i in proxyConfig.master_blacklist ) {
 169+ if ( clientDomain == proxyConfig.master_blacklist ) {
 170+ mw.log( 'domain: ' + clientDomain + ' is blacklisted ( no request )' );
 171+ return false;
 172+ }
 173+ }
 174+ // Check the master whitelist:
 175+ for ( var i in proxyConfig.master_whitelist ) {
 176+ if ( clientDomain == proxyConfig.master_whitelist[ i ] ) {
 177+ // Do the request:
 178+ return doApiRequest( clientRequest );
 179+ }
 180+ }
 181+
 182+ // FIXME Add in user based approval ::
 183+
 184+ // FIXME grab the users whitelist for our current domain
 185+
 186+ // FIXME offer the user the ability to "approve" requested domain save to
 187+ // their user preference setup )
 188+
 189+ }
 190+
 191+ /**
 192+ * local scoped helper functions:
 193+ */
 194+
 195+ /**
 196+ * Get the client frame path ( within mwEmbed )
 197+ */
 198+ function getClientFrame(){
 199+ return mw.getMwEmbedPath() + 'modules/ApiProxy/NestedCallbackIframe.html';
 200+ }
 201+
 202+ /**
 203+ * Get the server Frame path per requested Api url (prsently hard coded to MediaWiki:ApiProxy per /remotes/medaiWiki.js
 204+ */
 205+ function getServerFrame( ){
 206+ var parsedUrl = mw.parseUri( currentApiUrl );
 207+ return parsedUrl.protocol + '://' + parsedUrl.authority + '/w/index.php/MediaWiki:ApiProxy';
 208+ }
 209+
 210+ /**
 211+ * Does the frame proxy
 212+ * Writes an iframe with a hashed value of the requestQuery
 213+ *
 214+ * @param {Object} requestQuery The api request object
 215+ */
 216+ function doFrameProxy ( requestQuery ) {
 217+
 218+ var hashPack = {
 219+ // Client domain:
 220+ 'clientFrame' : getClientFrame(),
 221+ 'request' : requestQuery
 222+ }
 223+
 224+ mw.log( "Do frame proxy request on src: \n" + getServerFrame() + "\n" + JSON.stringify( requestQuery ) );
 225+
 226+ // We can't update src's so we have to remove and add all the time :(
 227+ // NOTE: we should support frame msg system
 228+ $j( '#frame_proxy' ).remove();
 229+ $j( 'body' ).append( '<iframe style="display:none" id="frame_proxy" name="frame_proxy" ' +
 230+ 'src="' + getServerFrame() +
 231+ '#' + escape( JSON.stringify( hashPack ) ) +
 232+ '"></iframe>' );
 233+
 234+ // add an onLoad hook:
 235+ $j( '#frame_proxy' ).get( 0 ).onload = function() {
 236+ // Add a 15 second timeout for setting up the nested child callback (after page load)
 237+
 238+ // NOTE: once we have a real entry point instead of ( mediaWiki:ApiProxy rewrite)
 239+ //this number can be reduced since it won't have to load all the style sheets and
 240+ // javascript for a normal page view
 241+
 242+ setTimeout( function() {
 243+ if ( !frameProxyOk ) {
 244+ // we timmed out no api proxy (should make sure the user is "logged in")
 245+ mw.log( "Error:: api proxy timeout are we logged in? mwEmbed is on?" );
 246+ proxyNotReadyDialog();
 247+ }
 248+ }, 15000 );
 249+ }
 250+ }
 251+
 252+
 253+ /**
 254+ * Dialog to send the user if a proxy to the remote server could not be created
 255+ */
 256+ function proxyNotReadyDialog() {
 257+ var buttons = { };
 258+ buttons[ gM( 'mwe-re-try' ) ] = function() {
 259+ mw.addLoaderDialog( gM( 'mwe-re-trying' ) );
 260+ doFrameProxy( currentApiReq );
 261+ }
 262+ buttons[ gM( 'mwe-cancel' ) ] = function() {
 263+ mw.closeLoaderDialog();
 264+ }
 265+ var pUri = mw.parseUri( currentApiUrl );
 266+
 267+ // FIXME we should have a Hosted page once we deploy mwEmbed on the servers.
 268+ // A hosted page would be much faster since than a normal page view rewrite
 269+
 270+ var login_url = pUri.protocol + '://' + pUri.host;
 271+ login_url += pUri.path.replace( 'MediaWiki:ApiProxy', 'Special:UserLogin' );
 272+
 273+ mw.addDialog(
 274+ gM( 'mwe-proxy-not-ready' ),
 275+ gM( 'mwe-please-login', [ login_url, pUri.host] ) +
 276+ '<p style="font-size:small">' +
 277+ gM( 'mwe-remember-loging' ) +
 278+ '</p>',
 279+ buttons
 280+ )
 281+ }
 282+
 283+
 284+
 285+
 286+ /**
 287+ * API iFrame Server::
 288+ *
 289+ * Handles the server side proxy of requests
 290+ * it adds child frames pointing to the parent "blank" frames
 291+ */
 292+
 293+ /**
 294+ * Api iFrame request:
 295+ * @param {Object} requestObj Api request object
 296+ */
 297+ function doApiRequest( clientRequest ) {
 298+
 299+ // Make sure its a json format
 300+ clientRequest.request[ 'format' ] = 'json';
 301+
 302+ // Process the API request. We don't use mw.apiReq since we need to "post"
 303+ $j.post( wgScriptPath + '/api' + wgScriptExtension,
 304+ clientRequest.request,
 305+ function( data ) {
 306+ // Put it result into nested frame hash string:
 307+ outputResultsFrame( clientRequest.clientFrame, 'nested_push', JSON.parse( data ) );
 308+ }
 309+ );
 310+ }
 311+
 312+ /**
 313+ * Outputs the result object to the client domain
 314+ *
 315+ * @param {clientFrame} clientFrame Client frame name
 316+ * @param {String} nestName Name of iframe
 317+ * @param {resultObj} the result to pass back to the client domain
 318+ */
 319+ function outputResultsFrame( clientFrame, nestName, resultObj ) {
 320+ $j( '#nested_push' ).remove();
 321+ // Setup the nested iframe proxy that points back to top domain:
 322+ $j( 'body' ).append(
 323+ $j('<iframe>').attr({
 324+ 'id' : nestName,
 325+ 'name' : nestName,
 326+ 'src' : clientFrame + '#' + escape( JSON.stringify( resultObj ) )
 327+ })
 328+ );
 329+ }
 330+
 331+
 332+} )( window.mw.ApiProxy );
Property changes on: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js
___________________________________________________________________
Name: svn:mergeinfo
1333 + /branches/REL1_15/phase3/js2/mwEmbed/libMwApi/mw.proxy.js:51646
/branches/sqlite/js2/mwEmbed/libMwApi/mw.proxy.js:58211-58321
Name: svn:eol-style
2334 + native
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -72,11 +72,11 @@
7373 'protect', 'block', 'unblock', 'move', 'edit', 'upload', 'emailuser',
7474 'import', 'userrights' ],
7575
76 - //If we are in debug mode ( results in fresh debugg javascript includes )
 76+ //If we are in debug mode ( results in fresh debug javascript includes )
7777 'debug' : false,
7878
7979 // Valid language codes ( has a file in /includes/languages/classes/Language{code}.js )
80 - // TODO: mirror the mw language "fallback" system
 80+ // TODO: mirror the mediaWiki language "fallback" system
8181 'languageCodeList': ['en', 'am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh',
8282 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi',
8383 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt',
@@ -1438,21 +1438,8 @@
14391439 // Check if we need to setup a proxy
14401440 if( ! mw.isLocalDomain( url ) ){
14411441 // Load the proxy and issue the request
1442 - mw.load( 'ApiProxy', function(){
1443 - var parsedUrl = mw.parseUri( url );
1444 - var server_frame = parsedUrl.protocol + '://' + parsedUrl.authority + '/w/index.php/MediaWiki:ApiProxy';
1445 - $j.apiProxy(
1446 - 'client',
1447 - {
1448 - // NOTE:: we need to setup a special page rather than the rewrite hack I use bellow:
1449 - // The rewrite hack is very slow cuz it loads the whole mediaWiki interface & skin
1450 - 'server_frame' : server_frame,
1451 - 'client_frame_path' : mw.getMwEmbedPath() + 'modules/ApiProxy/NestedCallbackIframe.html'
1452 - },
1453 - function(){
1454 - mw.proxy.doRequest( data, callback )
1455 - }
1456 - )
 1442+ mw.load( 'ApiProxy', function(){
 1443+ mw.ApiProxy.doRequest( url, data, callback );
14571444 });
14581445 }else{
14591446 // Do the request an ajax post
Index: branches/js2-work/phase3/js/apiProxyPage.js
@@ -10,8 +10,9 @@
1111
1212 mw.setConfig( 'pre-append-log', 'Proxy:');
1313
14 -if ( !mwApiProxyConfig )
 14+if ( !mwApiProxyConfig ){
1515 var mwApiProxyConfig = { };
 16+}
1617
1718 // The default mwApiProxyConfig config
1819 // (presently hard coded but should read from user and site config)
@@ -25,6 +26,6 @@
2627 mw.load( 'ApiProxy', function(){
2728 // Build our configuration from the default and mwApiProxyConfig vars
2829 mwApiProxyConfig = $j.extend( true, mwApiProxyDefaultConfig, mwApiProxyConfig );
29 - $j.apiProxy( 'server', mwApiProxyConfig );
 30+ mw.ApiProxy.server( mwApiProxyConfig );
3031 });
3132 } );

Status & tagging log