r62283 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62282‎ | r62283 | r62284 >
Date:02:00, 11 February 2010
Author:dale
Status:deferred
Tags:
Comment:
* stubs for api proxy upload
* fix for upload check in proccessApiResult
Modified paths:
  • /branches/js2-work/phase3/js/apiProxyPage.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html (modified) (history)
  • /branches/js2-work/phase3/js/uploadPage.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html
@@ -17,7 +17,9 @@
1818 $j('#setupDone').show('slow');
1919 $j('#doHello').click( doHello );
2020 $j('#doAppend').click( doAppend );
 21+ $j('#doFileBrowse').click( doFileUpload );
2122 });
 23+
2224 function doHello(){
2325 mw.log('to a hello user');
2426 $j('#helloTarget').html( mw.loading_spinner() );
@@ -44,7 +46,7 @@
4547 );
4648 }
4749
48 -//simple "hello from api proxy" append on talk page
 50+// Simple "hello from api proxy" append on talk page
4951 function doAppend(){
5052 $j('#appendTarget').html( mw.loading_spinner() );
5153 //get user name
@@ -74,6 +76,20 @@
7577 });
7678 });
7779 }
 80+
 81+
 82+function doFileUpload(){
 83+ $j('#browseTarget').html( mw.loading_spinner() );
 84+ mw.load( 'ApiProxy', function(){
 85+ mw.ApiProxy.browseFile( {
 86+ 'target' : '#browseTarget',
 87+ 'apiUrl' : remote_api_url
 88+ },function(){
 89+ mw.log( 'brwose file cb' );
 90+ });
 91+ });
 92+
 93+}
7894 </script>
7995
8096 </head>
@@ -83,8 +99,13 @@
84100 <div id="setupProxy">Proxy for: <span id="hostName"></span> <br><span style="font-size:small">( be sure to enable the mwEmbed gadget or add importScriptURI( 'path_to_local_mw_install' + /js/remoteMwEmbed.js ) to your User skin .js page </span></div>
85101 <div id="setupDone" style="display:none;">
86102 <br> <a href="#" id="doHello" >Hello User:</a> <span id="helloTarget"></span>
 103+
87104 <br><br><br> <a href="#" id="doAppend">Append Msg to Talk page:</a>
88105 <div id="appendTarget"></div>
 106+
 107+ <br><br><br> <a href="#" id="doFileBrowse">Upload a file to remote:</a>
 108+ <div id="browseTarget"></div>
 109+
89110 </div>
90111
91112 </body>
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js
@@ -1062,6 +1062,7 @@
10631063 mw.log( "could not parse uploadstatus / could not get responseText" );
10641064 }
10651065 }
 1066+
10661067
10671068 if ( _this.oldResponseText != response_text ) {
10681069 mw.log( 'new result text:' + response_text + ' state:' + _this.fogg.state );
@@ -1077,8 +1078,9 @@
10781079 } catch( e ) {
10791080 var apiResult = null;
10801081 }
1081 - }
1082 - //Check for scuccess:
 1082+ }
 1083+
 1084+ //Check for success:
10831085 if( apiResult && _this.isApiSuccess( apiResult ) ){
10841086 if( _this.processApiResult ( apiResult ) ){
10851087 return true;
@@ -1092,6 +1094,7 @@
10931095 _this.fogg.cancel();
10941096 return false;
10951097 }
 1098+
10961099 }
10971100 if ( _this.show_preview == true ) {
10981101 if ( _this.fogg.state == 'encoding' ) {
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js
@@ -843,6 +843,7 @@
844844 processApiResult: function( apiRes ) {
845845 var _this = this;
846846 mw.log( 'processApiResult::' );
 847+
847848 if ( !_this.isApiSuccess( apiRes ) ) {
848849 // Error detected, show it to the user
849850 _this.showApiError( apiRes );
@@ -856,7 +857,7 @@
857858 return;
858859 }
859860
860 - if ( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ) {
 861+ if ( apiRes.upload && apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ) {
861862 var url = apiRes.upload.imageinfo.descriptionurl;
862863
863864 // Upload complete.
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js
@@ -50,7 +50,7 @@
5151 // Local scope public vars
5252 //( should probably tie these var defines to the scope of the doRequest call using something like "curry" function )
5353
54 - // Callback funcion for client requests
 54+ // Callback function for client requests
5555 var proxyCallback = null;
5656
5757 // FrameProxy Flag:
@@ -119,6 +119,25 @@
120120 proxyCallback( resultObject );
121121 }
122122
 123+ /**
 124+ * Generates a remote browse file iframe window
 125+ * usefull for "uploading" cross domain
 126+ *
 127+ * @param {Function} callback Function to host the
 128+ */
 129+ $.browseFile = function( options ){
 130+ if( ! options.target ){
 131+ mw.log( "Error: no target for file browse" ) ;
 132+ return false;
 133+ }
 134+ if( ! options.apiUrl ){
 135+ mw.log( "Error: no api url to target" );
 136+ }
 137+ $j( options.target ).html(
 138+
 139+ );
 140+ }
 141+
123142 /**
124143 * Api server proxy entry point:
125144 *
@@ -127,64 +146,16 @@
128147 *
129148 */
130149 $.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 -
 150+ //Validate the server request:
 151+ if( validateIframeRequest( proxyConfig ) ){
 152+ // Process request type
 153+ if( proxyConfig['browserFile'] ){
 154+ doBrowseFile();
 155+ return ;
 156+ }
 157+ // Else do a normal api request :
 158+ return doApiRequest();
 159+ }
189160 }
190161
191162 /**
@@ -225,6 +196,7 @@
226197 // We can't update src's so we have to remove and add all the time :(
227198 // NOTE: we should support frame msg system
228199 $j( '#frame_proxy' ).remove();
 200+ // NOTE we can't use jQuery buildout for iframes because IE throws away the "name"
229201 $j( 'body' ).append( '<iframe style="display:none" id="frame_proxy" name="frame_proxy" ' +
230202 'src="' + getServerFrame() +
231203 '#' + escape( JSON.stringify( hashPack ) ) +
@@ -232,10 +204,11 @@
233205
234206 // add an onLoad hook:
235207 $j( '#frame_proxy' ).get( 0 ).onload = function() {
236 - // Add a 15 second timeout for setting up the nested child callback (after page load)
 208+
 209+ // Add a 10 second timeout for setting up the nested child callback (after page load)
237210
238211 // 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
 212+ // this number can be reduced since it won't have to load all the style sheets and
240213 // javascript for a normal page view
241214
242215 setTimeout( function() {
@@ -244,12 +217,84 @@
245218 mw.log( "Error:: api proxy timeout are we logged in? mwEmbed is on?" );
246219 proxyNotReadyDialog();
247220 }
248 - }, 15000 );
 221+ }, 10000 );
249222 }
250223 }
251 -
252224
253225 /**
 226+ * Validate an iframe request
 227+ * checks the url hash for required paramaters
 228+ * checks master_blacklist
 229+ * checks master_whitelist
 230+ */
 231+ function validateIframeRequest( proxyConfig ){
 232+ var clientRequest = false;
 233+
 234+
 235+ var clientRequest = getClientRequest();
 236+
 237+ if ( !clientRequest || !clientRequest.clientFrame ) {
 238+ mw.log( "Error: no client domain provided " );
 239+ $j( 'body' ).append( "no client frame provided" );
 240+ return false;
 241+ }
 242+
 243+ // Make sure we are logged in
 244+ // (its a normal mediaWiki page so all site vars should be defined)
 245+ if ( typeof wgUserName != 'undefined' && !wgUserName ) {
 246+ mw.log( 'Error Not logged in' );
 247+ return false;
 248+ }
 249+
 250+ mw.log( "Setup server on: " + mw.parseUri( document.URL ).host );
 251+ mw.log('Client frame: ' + clientRequest.clientFrame );
 252+
 253+ var clientDomain = mw.parseUri( clientRequest.clientFrame ).host ;
 254+
 255+ /**
 256+ * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig
 257+ */
 258+ // Check master blacklist
 259+ for ( var i in proxyConfig.master_blacklist ) {
 260+ if ( clientDomain == proxyConfig.master_blacklist ) {
 261+ mw.log( 'domain: ' + clientDomain + ' is blacklisted ( no request )' );
 262+ return false;
 263+ }
 264+ }
 265+ // Check the master whitelist:
 266+ for ( var i in proxyConfig.master_whitelist ) {
 267+ if ( clientDomain == proxyConfig.master_whitelist[ i ] ) {
 268+ return true;
 269+ }
 270+ }
 271+
 272+ // FIXME Add in user based approval ::
 273+
 274+ // FIXME offer the user the ability to "approve" requested domain save to
 275+ // their user preference setup )
 276+
 277+ // FIXME grab the users whitelist for our current domain
 278+
 279+ // Not a valid request return false
 280+ return false;
 281+ }
 282+
 283+ /**
 284+ * Get the client request from the document hash
 285+ * @return {Object} the object result of parsing the document anchor msg
 286+ */
 287+ function getClientRequest(){
 288+ // Read the anchor data package from the requesting url
 289+ var hashMsg = unescape( mw.parseUri( document.URL ).anchor );
 290+ try {
 291+ return JSON.parse( hashMsg );
 292+ } catch ( e ) {
 293+ mw.log( "ProxyServer:: could not parse anchor" );
 294+ return false;
 295+ }
 296+ }
 297+
 298+ /**
254299 * Dialog to send the user if a proxy to the remote server could not be created
255300 */
256301 function proxyNotReadyDialog() {
@@ -261,7 +306,7 @@
262307 buttons[ gM( 'mwe-cancel' ) ] = function() {
263308 mw.closeLoaderDialog();
264309 }
265 - var pUri = mw.parseUri( currentApiUrl );
 310+ var pUri = mw.parseUri( getServerFrame() );
266311
267312 // FIXME we should have a Hosted page once we deploy mwEmbed on the servers.
268313 // A hosted page would be much faster since than a normal page view rewrite
@@ -293,8 +338,9 @@
294339 * Api iFrame request:
295340 * @param {Object} requestObj Api request object
296341 */
297 - function doApiRequest( clientRequest ) {
298 -
 342+ function doApiRequest( ) {
 343+ // Get the client request
 344+ var clientRequest = getClientRequest();
299345 // Make sure its a json format
300346 clientRequest.request[ 'format' ] = 'json';
301347
@@ -309,6 +355,15 @@
310356 }
311357
312358 /**
 359+ * setup the browse file proxy.
 360+ *
 361+ * Sets the page content to browser file
 362+ */
 363+ function doBrowseFile(){
 364+
 365+ }
 366+
 367+ /**
313368 * Outputs the result object to the client domain
314369 *
315370 * @param {clientFrame} clientFrame Client frame name
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -1,4 +1,4 @@
2 -/*
 2+/**
33 * This file exposes some of the functionality of mwEmbed to wikis
44 * that do not yet have mwEmbed enabled
55 */
@@ -94,7 +94,7 @@
9595 }
9696
9797
98 - // Firefogg integration
 98+ // Upload page integration
9999 if ( wgPageName == "Special:Upload" ) {
100100 loadMwEmbed([
101101 'mw.BaseUploadInterface',
@@ -117,6 +117,15 @@
118118 } );
119119 }
120120
 121+ // Special api browse for file proxy page
 122+ if ( wgPageName == 'MediaWiki:ApiProxyBrowserFile' ) {
 123+ var wgEnableIframeApiProxy = true;
 124+ loadMwEmbed( [ 'mw.proxy' ], function() {
 125+ mwApiProxyConfig[ 'browserFile' ] = true;
 126+ mw.load( mwEmbedHostPath + '/apiProxyPage.js?' + mwGetReqArgs() );
 127+ } );
 128+ }
 129+
121130 // OggHandler rewrite for view pages:
122131 var vidIdList = [];
123132 var divs = document.getElementsByTagName( 'div' );
@@ -401,12 +410,12 @@
402411 return false;
403412 }
404413
405 - for( var i = 0 ; i < scripts.length ; i ++){
 414+ for( var i = 0 ; i < scripts.length ; i++ ){
406415 if (
407416 scripts[i].src
408417 && scripts[i].src.indexOf( 'MediaWiki:Gadget-mwEmbed.js' ) !== -1
409418 ){
410 - mw.log('gadget already installed: ' + scripts[i].src);
 419+ mw.log( 'gadget already installed: ' + scripts[i].src );
411420 // Gadget found / enabled
412421 return false;
413422 }
@@ -418,7 +427,7 @@
419428 'text' : gM( 'mwe-enable-gadget' ),
420429 'icon_id': 'check'
421430 })
422 - .css({
 431+ .css({
423432 'font-size': '90%'
424433 })
425434 .buttonHover()
@@ -442,7 +451,7 @@
443452 )
444453 .remove();
445454 // Load gadgets form:
446 - mwSubmitgadgetPref( 'mwEmbed' );
 455+ mwSubmitGadgetPref( 'mwEmbed' );
447456
448457 // return false to not follow link
449458 return false;
@@ -459,7 +468,7 @@
460469 )
461470 );
462471 }
463 -function mwSubmitgadgetPref( gadget_id ){
 472+function mwSubmitGadgetPref( gadget_id ){
464473 $j.get( wgArticlePath.replace('$1', 'Special:Preferences'), function( pageHTML ){
465474 // get the form
466475 var form = mwGetFormFromPage ( pageHTML );
Index: branches/js2-work/phase3/js/apiProxyPage.js
@@ -1,4 +1,4 @@
2 -/*
 2+/**
33 * mwProxy js2 page system.
44 *
55 * Invokes the apiProxy system
@@ -19,11 +19,16 @@
2020 var mwApiProxyDefaultConfig = {
2121 'master_whitelist' : [ 'en.wikipedia.org', 'localhost', '127.1.1.100' ],
2222 'master_blacklist' : []
23 -};
 23+};
2424
 25+
2526 // User white_list should also be checked and configured at runtime.
2627 mw.ready( function() {
2728 mw.load( 'ApiProxy', function(){
 29+
 30+ //Clear out the page content ( not needed for iframe proxy )
 31+ $j( 'body' ).html( '' );
 32+
2833 // Build our configuration from the default and mwApiProxyConfig vars
2934 mwApiProxyConfig = $j.extend( true, mwApiProxyDefaultConfig, mwApiProxyConfig );
3035 mw.ApiProxy.server( mwApiProxyConfig );
Index: branches/js2-work/phase3/js/uploadPage.js
@@ -19,7 +19,7 @@
2020 // An API URL (we won't submit directly to action of the form)
2121 'api_url': wgServer + wgScriptPath + '/api.php',
2222 // MediaWiki API supports chunk uploads:
23 - 'enable_chunks' : false,
 23+ 'enable_chunks' : true,
2424 'form_selector': mwUploadFormSelector,
2525 'new_source_cb': function( orgFilename, oggName ) {
2626 $j( '#wpDestFile' ).val( oggName );

Status & tagging log