Index: branches/new-upload/phase3/includes/DefaultSettings.php |
— | — | @@ -2579,8 +2579,11 @@ |
2580 | 2580 | $wgJSAutoloadClasses = array(); |
2581 | 2581 | |
2582 | 2582 | /* |
2583 | | - * boolean if the script loader should be used to group all javascript requests. |
| 2583 | + * boolean; if the script loader should be used to group all javascript requests. |
2584 | 2584 | * more about the script loader: http://www.mediawiki.org/wiki/ScriptLoader |
| 2585 | + * |
| 2586 | + * (its recommended you DO NOT enable the script loader without also enabling $wgUseFileCache |
| 2587 | + * (or have mediaWiki behind a proxy) otherwise all new js requests will result in script server js processing. |
2585 | 2588 | */ |
2586 | 2589 | $wgEnableScriptLoader = false; |
2587 | 2590 | |
Index: branches/new-upload/phase3/js2/mwEmbed/example_usage/Make_Ogg_Advanced.html |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | <meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
5 | 5 | <title>Firefogg - Make Ogg Video in your Browser</title> |
6 | 6 | <!-- <script type="text/javascript" src="../jsScriptLoader.php?class=mv_embed"></script> --> |
7 | | - <script type="text/javascript" src="../mv_embed.js?debug=true"></script> |
| 7 | + <script type="text/javascript" src="../jsScriptLoader.php?class=mv_embed"></script> |
8 | 8 | <style type="text/css" media="all">@import "http://www.firefogg.org/css/style.css";</style> |
9 | 9 | <style type="text/css" media="all"> |
10 | 10 | .install{ |
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js |
— | — | @@ -98,11 +98,9 @@ |
99 | 99 | }, |
100 | 100 | doRewrite:function( callback ){ |
101 | 101 | var _this = this; |
102 | | - $j(this.selector).each(function(){ |
103 | | - if( this.tagName.toLowerCase() == 'input' ){ |
104 | | - _this.form_rewrite = true; |
105 | | - } |
106 | | - }); |
| 102 | + if($j(this.selector).get(0).tagName == 'input' ){ |
| 103 | + _this.form_rewrite = true; |
| 104 | + } |
107 | 105 | //check if we are rewriting an input or a form: |
108 | 106 | if( this.form_rewrite ){ |
109 | 107 | this.setupForm(); |
— | — | @@ -123,14 +121,14 @@ |
124 | 122 | //check for the target if missing add to the output: |
125 | 123 | if( _this[target] === false){ |
126 | 124 | out+= _this.getTargetHtml(target) + ' '; |
127 | | - } |
128 | | - //update the target selector |
129 | | - _this[target] = _this.selector + ' .' + target; |
| 125 | + //update the target selector |
| 126 | + _this[target] = _this.selector + ' .' + target; |
| 127 | + } |
130 | 128 | } |
131 | | - }); |
132 | | - $j( this.selector ).append( out ).hide(); |
| 129 | + }); |
| 130 | + $j( this.selector ).append( out ).hide(); |
133 | 131 | }, |
134 | | - getTargetHtml:function(target){ |
| 132 | + getTargetHtml:function(target){ |
135 | 133 | if( target.substr(7,3)=='btn'){ |
136 | 134 | return '<input style="" class="' + target + '" type="button" value="' + gM( 'fogg-' + target.substring(11)) + '"/> '; |
137 | 135 | }else if(target.substr(7,5)=='input'){ |
— | — | @@ -159,7 +157,7 @@ |
160 | 158 | |
161 | 159 | //if rewriting the form lets keep the text input around: |
162 | 160 | if( _this.form_rewrite ) |
163 | | - $j('#target_input_file_name').show(); |
| 161 | + $j(this.target_input_file_name).show(); |
164 | 162 | |
165 | 163 | //hide all but check-for-fogg |
166 | 164 | //check for firefogg |
— | — | @@ -170,7 +168,11 @@ |
171 | 169 | ).css({'display':'inline'} |
172 | 170 | ).click(function(){ |
173 | 171 | _this.selectFogg(); |
174 | | - }); |
| 172 | + }); |
| 173 | + //also setup the text file display on Click to select file: |
| 174 | + $j(this.target_input_file_name).unbind().attr('readonly', 'readonly').click(function(){ |
| 175 | + _this.selectFogg(); |
| 176 | + }) |
175 | 177 | |
176 | 178 | }else{ |
177 | 179 | //first check firefox version: |
— | — | @@ -241,12 +243,14 @@ |
242 | 244 | }); |
243 | 245 | if(!$j(this.selector).attr('style')) |
244 | 246 | inTag += 'style="display:inline" '; |
245 | | - inTag+= '>'; |
| 247 | + inTag+= '/><span id="' + $j(this.selector).attr('name') + '_fogg-control"></span>'; |
246 | 248 | |
247 | 249 | js_log('set input: ' + inTag); |
248 | 250 | $j(this.selector).replaceWith(inTag); |
249 | 251 | |
250 | | - this.target_input_file_name = this.selector; |
| 252 | + this.target_input_file_name = 'input[name=' + $j(this.selector).attr('name') + ']'; |
| 253 | + //update the selector to the control target: |
| 254 | + this.selector = '#' + $j(this.selector).attr('name') + "_fogg-control"; |
251 | 255 | |
252 | 256 | this.doControlHTML(); |
253 | 257 | //check for the other inline status indicator targets: |
— | — | @@ -294,15 +298,21 @@ |
295 | 299 | } |
296 | 300 | //~otherwise the encoding will be triggered by the form~ |
297 | 301 | |
298 | | - //do source name update callback: |
| 302 | + //do source name update callback: |
| 303 | + js_log(" should update: " + _this.target_input_file_name + ' to: ' + _this.fogg.sourceFilename ); |
299 | 304 | $j(_this.target_input_file_name).val(_this.fogg.sourceFilename).show(); |
300 | 305 | |
301 | | - if(_this.new_source_cb){ |
302 | | - _this.new_source_cb( _this.fogg.sourceFilename ); |
| 306 | + if(_this.new_source_cb){ |
| 307 | + var oggExt = (_this.isSourceAudio())?'oga':'ogg'; |
| 308 | + oggExt = (_this.isSourceVideo())?'ogv':oggExt; |
| 309 | + oggName = _this.fogg.sourceFilename.substr(0, |
| 310 | + _this.fogg.sourceFilename.lastIndexOf('.')); |
| 311 | + |
| 312 | + _this.new_source_cb( _this.fogg.sourceFilename , oggName +'.'+ oggExt); |
303 | 313 | } |
304 | 314 | } |
305 | 315 | }else{ |
306 | | - js_error("Firefogg error selecting file"); |
| 316 | + //js_error("Firefogg error selecting file"); |
307 | 317 | } |
308 | 318 | }, |
309 | 319 | saveLocalFogg:function(){ |
— | — | @@ -323,25 +333,32 @@ |
324 | 334 | var ext = ''; |
325 | 335 | if( sf.lastIndexOf('.') != -1){ |
326 | 336 | ext = sf.substring( sf.lastIndexOf('.')+1 ).toLowerCase(); |
327 | | - } |
328 | | - //ogg video or audio |
329 | | - var cat = _this.sourceFileInfo.contentType; |
| 337 | + } |
330 | 338 | |
331 | 339 | //set to passthrough by default (images, arbitrary files that we want to send with http chunks) |
332 | 340 | this.encoder_settings['passthrough'] = false; |
333 | 341 | |
334 | 342 | //see if we have video or audio: |
335 | | - if( _this.sourceFileInfo.contentType.indexOf("video/") != -1 || |
336 | | - _this.sourceFileInfo.contentType.indexOf("audio/") != -1 ){ |
| 343 | + if( _this.isSourceAudio() || _this.isSourceVideo() ){ |
337 | 344 | _this.encoder_settings['passthrough'] = false; |
338 | 345 | } |
339 | | - |
340 | | - //see if we have ogg video: |
341 | | - if(_this.sourceFileInfo.contentType.indexOf("video/ogg") != -1 ){ |
| 346 | + |
| 347 | + //special case see if we already have ogg video: |
| 348 | + if( _this.isOggFormat() ){ |
342 | 349 | _this.encoder_settings['passthrough'] = true; |
343 | | - } |
| 350 | + } |
| 351 | + |
344 | 352 | js_log('base autoEncoderSettings::' + _this.sourceFileInfo.contentType + ' passthrough:' + _this.encoder_settings['passthrough']); |
345 | 353 | }, |
| 354 | + isSourceAudio:function(){ |
| 355 | + return (this.sourceFileInfo.contentType.indexOf("audio/") != -1); |
| 356 | + }, |
| 357 | + isSourceVideo:function(){ |
| 358 | + return (this.sourceFileInfo.contentType.indexOf("video/") != -1); |
| 359 | + }, |
| 360 | + isOggFormat:function(){ |
| 361 | + return ( this.sourceFileInfo.contentType.indexOf("video/ogg") != -1); |
| 362 | + }, |
346 | 363 | getProgressTitle:function(){ |
347 | 364 | js_log("fogg:getProgressTitle f:" + this.fogg_enabled + ' rw:' + this.form_rewrite); |
348 | 365 | //return the parent if we don't have fogg turned on: |
— | — | @@ -505,7 +522,7 @@ |
506 | 523 | _this.updateProgressWin( gM('successfulupload'), gM( 'mv_upload_done', _this.fogg.resultUrl), |
507 | 524 | { |
508 | 525 | go_to_url_txt:function(){ |
509 | | - document.URL = _this.fogg.resultUrl; |
| 526 | + window.location = _this.fogg.resultUrl; |
510 | 527 | } |
511 | 528 | }); |
512 | 529 | }else{ |
— | — | @@ -520,8 +537,21 @@ |
521 | 538 | } |
522 | 539 | uploadStatus(); |
523 | 540 | }, |
524 | | - /* |
525 | | - procPageResponse should be faded out soon.. its all very fragile to read the html output and guess at stuff*/ |
| 541 | + cancel_action:function( dlElm ){ |
| 542 | + js_log('firefogg:cancel') |
| 543 | + if( confirm( gM('mv-canecl-confim') )){ |
| 544 | + if(navigator.oscpu && navigator.oscpu.search('Win') >= 0){ |
| 545 | + alert( 'sorry we do not yet support cancel on windows' ); |
| 546 | + }else{ |
| 547 | + this.fogg.cancel(); |
| 548 | + $j(dlElm).dialog('close'); |
| 549 | + } |
| 550 | + } |
| 551 | + }, |
| 552 | + /** |
| 553 | + * procPageResponse should be faded out in favor of the upload api soon.. |
| 554 | + * its all very fragile to read the html output and guess at stuff |
| 555 | + */ |
526 | 556 | procPageResponse:function( result_page ){ |
527 | 557 | js_log('f:procPageResponse'); |
528 | 558 | var sstring = 'var wgTitle = "' + this.formData['wpDestFile'].replace('_',' '); |
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js |
— | — | @@ -515,7 +515,7 @@ |
516 | 516 | //confirm: |
517 | 517 | if( confirm( gM('mv-canecl-confim') )){ |
518 | 518 | //@@todo (cancel the encode / upload) |
519 | | - //$(this).dialog('close'); |
| 519 | + //$j(dlElm).dialog('close'); |
520 | 520 | alert('(sorry we do not yet support cancel)'); |
521 | 521 | } |
522 | 522 | } |
Index: branches/new-upload/phase3/js2/mwEmbed/php/jsAutoloadLocalClasses.php |
— | — | @@ -15,13 +15,13 @@ |
16 | 16 | |
17 | 17 | $wgJSAutoloadLocalClasses['j.contextMenu'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.contextMenu.js'; |
18 | 18 | $wgJSAutoloadLocalClasses['j.fn.pngFix'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.pngFix.js'; |
19 | | - |
| 19 | + |
20 | 20 | $wgJSAutoloadLocalClasses['j.fn.autocomplete'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.autocomplete.js'; |
21 | 21 | $wgJSAutoloadLocalClasses['j.fn.hoverIntent'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.hoverIntent.js'; |
22 | 22 | $wgJSAutoloadLocalClasses['j.Jcrop'] = $wgMwEmbedDirectory . 'jquery/plugins/Jcrop/js/jquery.Jcrop.js'; |
23 | 23 | $wgJSAutoloadLocalClasses['Date.fromString'] = $wgMwEmbedDirectory . 'jquery/plugins/date.js'; |
24 | 24 | $wgJSAutoloadLocalClasses['j.fn.datePicker'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.datePicker.js'; |
25 | | - |
| 25 | + |
26 | 26 | //jquery.ui |
27 | 27 | $wgJSAutoloadLocalClasses['j.ui'] = $wgMwEmbedDirectory . 'jquery/jquery.ui-1.7.1/ui/ui.core.js'; |
28 | 28 | |
— | — | @@ -50,11 +50,12 @@ |
51 | 51 | $wgJSAutoloadLocalClasses['j.ui.draggable'] = $wgMwEmbedDirectory . 'jquery/jquery.ui-1.7.1/ui/ui.draggable.js'; |
52 | 52 | $wgJSAutoloadLocalClasses['j.ui.selectable'] = $wgMwEmbedDirectory . 'jquery/jquery.ui-1.7.1/ui/ui.selectable.js'; |
53 | 53 | |
54 | | - |
55 | 54 | //libAddMedia: |
56 | 55 | $wgJSAutoloadLocalClasses['mvFirefogg'] = $wgMwEmbedDirectory . 'libAddMedia/mvFirefogg.js'; |
57 | 56 | $wgJSAutoloadLocalClasses['mvAdvFirefogg'] = $wgMwEmbedDirectory . 'libAddMedia/mvAdvFirefogg.js'; |
58 | 57 | |
| 58 | + $wgJSAutoloadLocalClasses['mvBaseUploadInterface'] = $wgMwEmbedDirectory . 'libAddMedia/mvBaseUploadInterface.js'; |
| 59 | + |
59 | 60 | $wgJSAutoloadLocalClasses['remoteSearchDriver'] = $wgMwEmbedDirectory . 'libAddMedia/remoteSearchDriver.js'; |
60 | 61 | $wgJSAutoloadLocalClasses['seqRemoteSearchDriver'] = $wgMwEmbedDirectory . 'libAddMedia/seqRemoteSearchDriver.js'; |
61 | 62 | $wgJSAutoloadLocalClasses['baseRemoteSearch'] = $wgMwEmbedDirectory . 'libAddMedia/searchLibs/baseRemoteSearch.js'; |
Index: branches/new-upload/phase3/js2/mwEmbed/php/script-cache/README |
— | — | @@ -0,0 +1,5 @@ |
| 2 | +This folder holds cached versions of grouped script requests. |
| 3 | +Be sure to enable write access by your web-server to this directory. |
| 4 | + |
| 5 | +You can specify a different directory by updating the $wgFileCacheDirectory variable in noMediaWikiConfig.php |
| 6 | + |
Property changes on: branches/new-upload/phase3/js2/mwEmbed/php/script-cache/README |
___________________________________________________________________ |
Name: svn:executable |
1 | 7 | + * |
Index: branches/new-upload/phase3/js2/mwEmbed/php/noMediaWikiConfig.php |
— | — | @@ -13,20 +13,77 @@ |
14 | 14 | //$wgMwEmbedDirectory becomes the root $IP |
15 | 15 | $wgMwEmbedDirectory = ''; |
16 | 16 | |
| 17 | +$wgFileCacheDirectory = realpath(dirname(__FILE__)) . '/script-cache'; |
| 18 | + |
17 | 19 | $wgUseFileCache = true; |
18 | 20 | |
19 | 21 | $wgEnableScriptLoaderJsFile = false; |
20 | 22 | |
21 | 23 | $wgEnableScriptLocalization = false; |
| 24 | +$wgContLanguageCode =''; |
22 | 25 | |
23 | 26 | $wgStyleVersion = '218'; |
24 | 27 | |
25 | 28 | $wgEnableScriptMinify = true; |
26 | 29 | |
| 30 | +$wgUseGzip = true; |
| 31 | + |
| 32 | + |
| 33 | +/** |
| 34 | + * Default value for chmoding of new directories. |
| 35 | + */ |
| 36 | +$wgDirectoryMode = 0777; |
| 37 | + |
| 38 | +$wgJsMimeType = 'text/javascript'; |
| 39 | + |
27 | 40 | //get the autoLoadClasses |
28 | 41 | require_once( realpath( dirname(__FILE__) ) . '/jsAutoloadLocalClasses.php' ); |
29 | | - |
| 42 | + |
30 | 43 | //get the JSmin class: |
31 | 44 | require_once( realpath( dirname(__FILE__) ) . '/minify/JSMin.php' ); |
32 | 45 | |
| 46 | +//some static utility mediaWiki functions that we use: |
| 47 | +function wfClientAcceptsGzip() { |
| 48 | + global $wgUseGzip; |
| 49 | + if( $wgUseGzip ) { |
| 50 | + # FIXME: we may want to blacklist some broken browsers |
| 51 | + $m = array(); |
| 52 | + if( preg_match( |
| 53 | + '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/', |
| 54 | + $_SERVER['HTTP_ACCEPT_ENCODING'], |
| 55 | + $m ) ) { |
| 56 | + if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) return false; |
| 57 | + wfDebug( " accepts gzip\n" ); |
| 58 | + return true; |
| 59 | + } |
| 60 | + } |
| 61 | + return false; |
| 62 | +} |
| 63 | +function wfDebug(){ |
| 64 | + return false; |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * Make directory, and make all parent directories if they don't exist |
| 69 | + * |
| 70 | + * @param string $dir Full path to directory to create |
| 71 | + * @param int $mode Chmod value to use, default is $wgDirectoryMode |
| 72 | + * @param string $caller Optional caller param for debugging. |
| 73 | + * @return bool |
| 74 | + */ |
| 75 | +function wfMkdirParents( $dir, $mode = null, $caller = null ) { |
| 76 | + global $wgDirectoryMode; |
| 77 | + |
| 78 | + if ( !is_null( $caller ) ) { |
| 79 | + wfDebug( "$caller: called wfMkdirParents($dir)" ); |
| 80 | + } |
| 81 | + |
| 82 | + if( strval( $dir ) === '' || file_exists( $dir ) ) |
| 83 | + return true; |
| 84 | + |
| 85 | + if ( is_null( $mode ) ) |
| 86 | + $mode = $wgDirectoryMode; |
| 87 | + |
| 88 | + return @mkdir( $dir, $mode, true ); // PHP5 <3 |
| 89 | +} |
33 | 90 | ?> |
\ No newline at end of file |
Index: branches/new-upload/phase3/js2/mwEmbed/mv_embed.js |
— | — | @@ -658,8 +658,8 @@ |
659 | 659 | } |
660 | 660 | var secondLoadSet = {}; |
661 | 661 | //IE* ~sometimes~ executes things out of order on DOM inserted scripts |
662 | | - //*(kind of pointless anyway since ie does not support firefogg |
663 | | - // but if you want firefog dirven "is not supported" msg here you go ;) |
| 662 | + //*(kind of pointless anyway since IE does not support firefogg |
| 663 | + // but if you want firefog to drive the "its not supported" msg here you go ;) |
664 | 664 | if($.browser.msie){ |
665 | 665 | secondLoadSet = { |
666 | 666 | '$j.ui.progressbar' : 'jquery/' + jQueryUiVN + '/ui/ui.progressbar.js', |
Index: branches/new-upload/phase3/js2/mwEmbed/jsScriptLoader.php |
— | — | @@ -1,55 +1,55 @@ |
2 | 2 | <?php |
3 | 3 | //This core jsScriptLoader class provides the script loader functionality |
4 | | - |
5 | 4 | //check if we are being invoked in mediaWiki context or stand alone usage: |
6 | | -if ( !defined( 'MEDIAWIKI' ) ){ |
7 | | - //load noMediaWiki helper: |
| 5 | +if ( !defined( 'MEDIAWIKI' ) ){ |
| 6 | + //load noMediaWiki helper: |
8 | 7 | require_once( realpath( dirname(__FILE__) ) . '/php/noMediaWikiConfig.php' ); |
9 | | - |
10 | | - //run the main action: |
| 8 | + |
| 9 | + //run the main action: |
11 | 10 | $myScriptLoader = new jsScriptLoader(); |
12 | | - //preset request values via normal $_GET opperation: |
| 11 | + //preset request values via normal $_GET opperation: |
13 | 12 | $myScriptLoader->doScriptLoader(); |
14 | 13 | } |
15 | 14 | |
16 | | -//setup page output hook |
| 15 | +//setup page output hook |
17 | 16 | class jsScriptLoader{ |
18 | 17 | var $jsFileList = array(); |
19 | 18 | var $jsout = ''; |
20 | | - var $rKey = ''; // the request key |
| 19 | + var $rKey = ''; // the request key |
21 | 20 | var $error_msg =''; |
22 | 21 | var $debug = false; |
23 | | - var $jsvarurl =false; // if we should include generated js (special class '-') |
24 | | - var $doProcReqFlag =true; |
25 | | - |
| 22 | + var $jsvarurl =false; // if we should include generated js (special class '-') |
| 23 | + var $doProcReqFlag =true; |
| 24 | + |
26 | 25 | function doScriptLoader(){ |
27 | | - global $wgJSAutoloadClasses,$wgJSAutoloadLocalClasses, $wgEnableScriptLoaderJsFile, $wgRequest, $IP, |
28 | | - $wgEnableScriptMinify, $wgUseFileCache; |
29 | | - |
30 | | - //process the request |
31 | | - $this->procRequestVars(); |
32 | | - |
33 | | - $wgUseFileCache=false; |
34 | | - //if cache is on and file is present grab it from there: |
| 26 | + global $wgJSAutoloadClasses,$wgJSAutoloadLocalClasses, $wgEnableScriptLoaderJsFile, $IP, |
| 27 | + $wgEnableScriptMinify, $wgUseFileCache; |
| 28 | + |
| 29 | + //process the request |
| 30 | + $this->procRequestVars(); |
| 31 | + |
| 32 | + //if cache is on and file is present grab it from there: |
35 | 33 | if( $wgUseFileCache && !$this->debug ) { |
36 | | - //setup file cache obj: |
| 34 | + //setup file cache obj: |
37 | 35 | $this->sFileCache = new simpleFileCache( $this->rKey ); |
38 | 36 | if( $this->sFileCache->isFileCached() ){ |
39 | | - $this->outputjsHeaders(); |
40 | | - $this->sFileCache->loadFromFileCache(); |
| 37 | + //just output headers so we can use php "efficient" readfile |
| 38 | + $this->outputJsHeaders(); |
| 39 | + $this->sFileCache->outputFromFileCache(); |
41 | 40 | } |
42 | | - } |
| 41 | + } |
| 42 | + |
43 | 43 | //setup script loader header info |
44 | 44 | $this->jsout .= 'var mwSlScript = "'. $_SERVER['SCRIPT_NAME'] . '";' . "\n"; |
45 | 45 | $this->jsout .= 'var mwSlGenISODate = "'. date('c') . '";' ."\n"; |
46 | 46 | $this->jsout .= 'var mwSlURID = "' . $this->urid . '";' ."\n"; |
47 | | - //Build the Output: |
48 | | - //swap in the appropriate language per js_file |
| 47 | + //Build the Output: |
| 48 | + //swap in the appropriate language per js_file |
49 | 49 | foreach($this->jsFileList as $classKey => $file_name){ |
50 | 50 | //special case: - title classes: |
51 | 51 | if( substr( $classKey, 0, 3) == 'WT:' ){ |
52 | | - //get just the tile part: |
53 | | - $title_block = substr( $classKey, 3); |
| 52 | + //get just the tile part: |
| 53 | + $title_block = substr( $classKey, 3); |
54 | 54 | if($title_block[0] == '-' && strpos($title_block, '|') !== false){ |
55 | 55 | //special case of "-" title with skin |
56 | 56 | $parts = explode('|', $title_block); |
— | — | @@ -61,185 +61,202 @@ |
62 | 62 | } |
63 | 63 | } |
64 | 64 | //make sure the skin name is valid |
65 | | - $skinNames = Skin::getSkinNames(); |
66 | | - //get the lower case skin name (array keys) |
67 | | - $skinNames = array_keys($skinNames); |
| 65 | + $skinNames = Skin::getSkinNames(); |
| 66 | + //get the lower case skin name (array keys) |
| 67 | + $skinNames = array_keys($skinNames); |
68 | 68 | if( in_array(strtolower($skin), $skinNames )){ |
69 | 69 | $this->jsout .= Skin::generateUserJs( $skin ) . "\n"; |
70 | 70 | //success continue: |
71 | 71 | continue; |
72 | 72 | } |
73 | | - }else{ |
74 | | - //its a wikiTitle append the output of the wikitext: |
| 73 | + }else{ |
| 74 | + //its a wikiTitle append the output of the wikitext: |
75 | 75 | $t = Title::newFromText ( $title_block ); |
76 | 76 | $a = new Article( $t ); |
77 | 77 | //only get content if the page is not empty: |
78 | 78 | if($a->getID() !== 0 ){ |
79 | 79 | $this->jsout .= $a->getContent() . "\n"; |
80 | | - } |
| 80 | + } |
81 | 81 | continue; |
82 | | - } |
| 82 | + } |
83 | 83 | } |
84 | | - |
| 84 | + |
85 | 85 | if( trim( $file_name ) != ''){ |
86 | | - //if in debug add a comment with the file name: |
87 | | - if($this->debug) |
| 86 | + //if in debug add a comment with the file name: |
| 87 | + if($this->debug) |
88 | 88 | $this->jsout .= "\n/** |
89 | | -* File: $file_name |
90 | | -*/\n"; |
| 89 | +* File: $file_name |
| 90 | +*/\n"; |
91 | 91 | $this->jsout .= ( $this->doProccessJsFile( $file_name ) ). "\n"; |
92 | 92 | } |
93 | | - } |
94 | | - //check if we should minify : |
95 | | - if( $wgEnableScriptMinify && !$this->debug){ |
96 | | - //do the minification and output |
| 93 | + } |
| 94 | + //check if we should minify : |
| 95 | + if( $wgEnableScriptMinify && !$this->debug){ |
| 96 | + //do the minification and output |
97 | 97 | $this->jsout = JSMin::minify( $this->jsout); |
98 | | - } |
99 | | - //save to the file cache: |
| 98 | + } |
| 99 | + //save to the file cache: |
100 | 100 | if( $wgUseFileCache && !$this->debug) { |
101 | | - $this->sFileCache->saveToFileCache($this->jsout); |
| 101 | + $status = $this->sFileCache->saveToFileCache($this->jsout); |
| 102 | + if($status!==true) |
| 103 | + $this->error_msg.= $status; |
102 | 104 | } |
103 | | - |
104 | | - $this->outputjsHeaders(); |
105 | | - if( $this->error_msg != '') |
106 | | - echo 'alert(\'ScriptLoader.php ::' . str_replace("\n", '\'+"\n"+'."\n'", $this->error_msg ). '\');'; |
107 | | - |
108 | | - echo trim($this->jsout); |
109 | | - |
| 105 | + //check for error msg: |
| 106 | + if( $this->error_msg != ''){ |
| 107 | + echo 'alert(\'Error With ScriptLoader.php ::' . str_replace("\n", '\'+"\n"+'."\n'", $this->error_msg ). '\');'; |
| 108 | + echo trim($this->jsout); |
| 109 | + }else{ |
| 110 | + //all good lets output cache forever headers: |
| 111 | + $this->outputJsWithHeaders(); |
| 112 | + } |
110 | 113 | } |
111 | | - function outputJsHeaders(){ |
112 | | - global $wgJsMimeType; |
113 | | - //output js mime type: |
| 114 | + function outputJsHeaders(){ |
| 115 | + global $wgJsMimeType; |
| 116 | + //output js mime type: |
114 | 117 | header( 'Content-type: '.$wgJsMimeType); |
115 | 118 | header( "Pragma: public" ); |
116 | | - //cache forever: |
| 119 | + //cache forever: |
117 | 120 | //(the point is we never have to re validate since we should always change the request url based on the svn or article version) |
118 | 121 | $one_year = 60*60*24*365; |
119 | | - header("Expires: " . gmdate( "D, d M Y H:i:s", time() + $one_year ) . " GM"); |
120 | | - |
| 122 | + header("Expires: " . gmdate( "D, d M Y H:i:s", time() + $one_year ) . " GM"); |
121 | 123 | } |
| 124 | + function outputJsWithHeaders(){ |
| 125 | + global $wgUseGzip; |
| 126 | + $this->outputJsHeaders(); |
| 127 | + if( $wgUseGzip ) { |
| 128 | + if( wfClientAcceptsGzip() ) { |
| 129 | + header( 'Content-Encoding: gzip' ); |
| 130 | + echo gzencode( $this->jsout ); |
| 131 | + }else{ |
| 132 | + echo $this->jsout; |
| 133 | + } |
| 134 | + }else{ |
| 135 | + echo $this->jsout; |
| 136 | + } |
| 137 | + } |
122 | 138 | /* |
123 | | - * updates the proc Request |
| 139 | + * updates the proc Request |
124 | 140 | */ |
125 | 141 | function procRequestVars(){ |
126 | | - global $wgRequest, $wgContLanguageCode, $wgEnableScriptMinify, $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgStyleVersion; |
127 | | - |
128 | | - //set debug flag: |
| 142 | + global $wgContLanguageCode, $wgEnableScriptMinify, $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgStyleVersion; |
| 143 | + |
| 144 | + //set debug flag: |
129 | 145 | if( (isset($_GET['debug']) && $_GET['debug']=='true') || (isset($wgEnableScriptDebug) && $wgEnableScriptDebug==true )){ |
130 | 146 | $this->debug = true; |
131 | | - } |
132 | | - |
133 | | - //set the urid: |
| 147 | + } |
| 148 | + |
| 149 | + //set the urid: (be sure to escape it as it goes into our js output) |
134 | 150 | if( isset( $_GET['urid'] ) && $_GET['urid'] !=''){ |
135 | 151 | $this->urid = htmlspecialchars( $_GET['urid'] ); |
136 | | - }else{ |
137 | | - //just give it the current style sheet id: |
138 | | - //@@todo read the svn version number |
139 | | - $this->urid = $wgStyleVersion; |
140 | | - } |
141 | | - |
142 | | - $reqClassList = false; |
| 152 | + }else{ |
| 153 | + //just give it the current style sheet id: |
| 154 | + //@@todo read the svn version number |
| 155 | + $this->urid = $wgStyleVersion; |
| 156 | + } |
| 157 | + |
| 158 | + $reqClassList = false; |
143 | 159 | if( isset($_GET['class']) && $_GET['class']!=''){ |
144 | 160 | $reqClassList = explode( ',', $_GET['class'] ); |
145 | | - } |
146 | | - //check for the requested classes |
147 | | - if( $reqClassList ){ |
148 | | - //clean the class list and populate jsFileList |
| 161 | + } |
| 162 | + //check for the requested classes |
| 163 | + if( $reqClassList ){ |
| 164 | + //clean the class list and populate jsFileList |
149 | 165 | foreach( $reqClassList as $reqClass ){ |
150 | | - if(trim($reqClass) != ''){ |
| 166 | + if(trim($reqClass) != ''){ |
151 | 167 | //check for special case '-' class for user generated js |
152 | 168 | if( substr( $reqClass, 0, 3) == 'WT:' ){ |
153 | 169 | $this->jsFileList[ $reqClass ] = true; |
154 | 170 | $this->rKey .= $reqClass; |
155 | | - $this->jsvarurl = true; |
| 171 | + $this->jsvarurl = true; |
156 | 172 | continue; |
157 | | - } |
158 | | - |
| 173 | + } |
| 174 | + |
159 | 175 | $reqClass = ereg_replace("[^A-Za-z0-9_\-\.]", "", $reqClass ); |
160 | | - |
| 176 | + |
161 | 177 | if( isset( $wgJSAutoloadLocalClasses[$reqClass] ) ){ |
162 | 178 | $this->jsFileList[ $reqClass ] = $wgJSAutoloadLocalClasses[ $reqClass ]; |
163 | | - $this->rKey.=$reqClass; |
| 179 | + $this->rKey.=$reqClass; |
164 | 180 | }else if( isset($wgJSAutoloadClasses[$reqClass])) { |
165 | 181 | $this->jsFileList[ $reqClass ] = $wgJSAutoloadClasses[ $reqClass ]; |
166 | | - $this->rKey.=$reqClass; |
167 | | - }else{ |
| 182 | + $this->rKey.=$reqClass; |
| 183 | + }else{ |
168 | 184 | $this->error_msg.= 'Requested class: ' . $reqClass . ' not found'."\n"; |
169 | | - } |
| 185 | + } |
170 | 186 | } |
171 | 187 | } |
172 | | - } |
173 | | - //check for requested files if enabled: |
| 188 | + } |
| 189 | + |
| 190 | + //check for requested files if enabled: |
174 | 191 | if( $wgEnableScriptLoaderJsFile ){ |
175 | | - if( $wgRequest->getVal('files')){ |
176 | | - $reqFileList = explode(',', $wgRequest->getVal('files')); |
| 192 | + if( isset($_GET['files'])){ |
| 193 | + $reqFileList = explode(',', isset($_GET['files'])); |
177 | 194 | //clean the file list and populate jsFileList |
178 | | - foreach($reqFileList as $reqFile){ |
179 | | - //no jumping dirs: |
| 195 | + foreach($reqFileList as $reqFile){ |
| 196 | + //no jumping dirs: |
180 | 197 | $reqFile = str_replace('../','',$reqFile); |
181 | 198 | //only allow alphanumeric underscores periods and ending with .js |
182 | | - $reqFile = ereg_replace("[^A-Za-z0-9_\-\/\.]", "", $reqFile ); |
| 199 | + $reqFile = ereg_replace("[^A-Za-z0-9_\-\/\.]", "", $reqFile ); |
183 | 200 | if( substr($reqFile, -3) == '.js' ){ |
184 | | - //don't add it twice: |
| 201 | + //don't add it twice: |
185 | 202 | if( !in_array($reqFile, $jsFileList )) { |
186 | 203 | $this->jsFileList[] = $IP . $reqFile; |
187 | 204 | $this->rKey.=$reqFile; |
188 | | - } |
| 205 | + } |
189 | 206 | }else{ |
190 | 207 | $this->error_msg.= 'Not valid requsted javascript file' . "\n"; |
191 | | - } |
| 208 | + } |
192 | 209 | } |
193 | 210 | } |
194 | 211 | } |
195 | | - |
| 212 | + |
196 | 213 | //add the language code to the rKey: |
197 | 214 | $this->rKey .= '_' . $wgContLanguageCode; |
198 | | - |
| 215 | + |
199 | 216 | //add the unique rid to the rKey |
200 | 217 | $this->rKey .= $this->urid; |
201 | | - |
202 | | - //add a min flag: |
| 218 | + |
| 219 | + //add a min flag: |
203 | 220 | if($wgEnableScriptMinify){ |
204 | 221 | $this->rKey.='_min'; |
205 | 222 | } |
206 | 223 | } |
207 | 224 | function doProccessJsFile( $file_name ){ |
208 | | - global $IP, $wgEnableScriptLocalization, $IP; |
209 | | - |
210 | | - //load the file: |
211 | | - $str = @file_get_contents("{$IP}/{$file_name}"); |
| 225 | + global $IP, $wgEnableScriptLocalization, $IP; |
212 | 226 | |
| 227 | + //load the file: |
| 228 | + $str = @file_get_contents("{$IP}/{$file_name}"); |
| 229 | + |
213 | 230 | if($str===false){ |
214 | | - //@@todo check php error level (don't want to expose paths if errors are hidden) |
| 231 | + //@@todo check php error level (don't want to expose paths if errors are hidden) |
215 | 232 | $this->error_msg.= 'Requested File: ' . htmlspecialchars( $file_name ) . ' could not be read' . "\n"; |
216 | 233 | return ''; |
217 | 234 | } |
218 | 235 | $this->cur_file = $file_name; |
219 | | - |
| 236 | + |
220 | 237 | //strip out js_log debug lines not much luck with this regExp yet: |
221 | 238 | //if( !$this->debug ) |
222 | 239 | // $str = preg_replace('/\n\s*js_log\s*\([^\)]([^;]|\n])*;/', "\n", $str); |
223 | | - |
224 | | - // do language swap |
| 240 | + |
| 241 | + // do language swap |
225 | 242 | if($wgEnableScriptLocalization) |
226 | | - $str = preg_replace_callback('/loadGM\s*\(\s*{(.*)}\s*\)\s*/siU', //@@todo fix: will break down if someone does }) in their msg text |
| 243 | + $str = preg_replace_callback('/loadGM\s*\(\s*{(.*)}\s*\)\s*/siU', //@@todo fix: will break down if someone does }) in their msg text |
227 | 244 | array($this, 'languageMsgReplace'), |
228 | | - $str); |
| 245 | + $str); |
229 | 246 | |
230 | | - return $str; |
| 247 | + return $str; |
231 | 248 | } |
232 | 249 | function languageMsgReplace($jvar){ |
233 | 250 | if(!isset($jvar[1])) |
234 | | - return ; |
235 | | - |
236 | | - $jmsg = json_decode( '{' . $jvar[1] . '}', true ); |
| 251 | + return ; |
| 252 | + |
| 253 | + $jmsg = json_decode( '{' . $jvar[1] . '}', true ); |
237 | 254 | //do the language lookup: |
238 | 255 | if($jmsg){ |
239 | 256 | foreach($jmsg as $msgKey => $default_en_value){ |
240 | 257 | $jmsg[$msgKey] = wfMsgNoTrans( $msgKey ); |
241 | 258 | } |
242 | | - //return the updated loadGM json with fixed new lines: |
243 | | - return 'loadGM( ' . json_encode( $jmsg ) . ')'; |
| 259 | + //return the updated loadGM json with fixed new lines: |
| 260 | + return 'loadGM( ' . json_encode( $jmsg ) . ')'; |
244 | 261 | }else{ |
245 | 262 | $this->error_msg.= "Could not parse JSON language msg in File:\n" . |
246 | 263 | $this->cur_file ."\n"; |
— | — | @@ -248,78 +265,93 @@ |
249 | 266 | return $jvar[0]; |
250 | 267 | } |
251 | 268 | } |
252 | | -//a simple version of HTMLFileCache (@@todo abstract shared pieces) |
| 269 | +//a simple version of HTMLFileCache (@@todo abstract shared pieces) |
253 | 270 | class simpleFileCache{ |
254 | 271 | var $mFileCache; |
| 272 | + var $filename= null; |
| 273 | + var $rKey= null; |
255 | 274 | public function __construct( &$rKey ) { |
256 | 275 | $this->rKey = $rKey; |
257 | | - $this->fileCacheName(); // init name |
| 276 | + $this->filename = $this->fileCacheName(); // init name |
258 | 277 | } |
259 | 278 | public function fileCacheName() { |
| 279 | + global $wgUseGzip; |
260 | 280 | if( !$this->mFileCache ) { |
261 | | - global $wgFileCacheDirectory, $wgRequest; |
262 | | - |
| 281 | + global $wgFileCacheDirectory; |
| 282 | + |
263 | 283 | $hash = md5( $this->rKey ); |
264 | 284 | # Avoid extension confusion |
265 | 285 | $key = str_replace( '.', '%2E', urlencode( $this->rKey ) ); |
266 | | - |
| 286 | + |
267 | 287 | $hash1 = substr( $hash, 0, 1 ); |
268 | | - $hash2 = substr( $hash, 0, 2 ); |
| 288 | + $hash2 = substr( $hash, 0, 2 ); |
269 | 289 | $this->mFileCache = "{$wgFileCacheDirectory}/{$subdir}{$hash1}/{$hash2}/{$this->rKey}.js"; |
270 | 290 | |
271 | | - if( $this->useGzip() ) |
| 291 | + if( $wgUseGzip ) |
272 | 292 | $this->mFileCache .= '.gz'; |
273 | 293 | |
274 | 294 | wfDebug( " fileCacheName() - {$this->mFileCache}\n" ); |
275 | 295 | } |
276 | 296 | return $this->mFileCache; |
277 | | - } |
278 | | - public function isFileCached() { |
279 | | - return file_exists( $this->fileCacheName() ); |
280 | | - } |
281 | | - public function loadFromFileCache(){ |
282 | | - global $wgJsMimeType; |
| 297 | + } |
| 298 | + public function isFileCached() { |
| 299 | + return file_exists( $this->filename ); |
| 300 | + } |
| 301 | + public function outputFromFileCache(){ |
| 302 | + global $wgUseGzip; |
283 | 303 | if( $wgUseGzip ) { |
284 | 304 | if( wfClientAcceptsGzip() ) { |
285 | 305 | header( 'Content-Encoding: gzip' ); |
286 | | - readfile( $filename ); |
| 306 | + readfile( $this->filename ); |
287 | 307 | } else { |
288 | | - /* Send uncompressed */ |
289 | | - readgzfile( $filename ); |
290 | | - return; |
| 308 | + /* Send uncompressed (check if fileCache is in compressed state (ends with .gz) |
| 309 | + * (unlikely to execute this since $wgUseGzip would have created a new file above.. but just in case: |
| 310 | + */ |
| 311 | + if(substr($this->filename, -3)=='.gz'){ |
| 312 | + readgzfile( $this->filename ); |
| 313 | + }else{ |
| 314 | + readfile( $this->filename ); |
| 315 | + } |
| 316 | + return true; |
291 | 317 | } |
292 | 318 | } |
293 | 319 | } |
294 | | - public function saveToFileCache( $text ) { |
295 | | - global $wgUseFileCache; |
| 320 | + public function saveToFileCache(& $text ) { |
| 321 | + global $wgUseFileCache, $wgUseGzip; |
296 | 322 | if( !$wgUseFileCache ) { |
297 | | - return $text; // return to output |
298 | | - } |
299 | | - if( strcmp($text,'') == 0 ) return ''; |
| 323 | + return 'Called saveToFileCache with $wgUseFileCache off'; // return to output |
| 324 | + } |
| 325 | + if( strcmp($text,'') == 0 ) return 'saveToFileCache: empty output file'; |
300 | 326 | |
301 | | - wfDebug(" simpleSaveToFileCache()\n", false); |
| 327 | + //check the directories if we could not create them error out: |
| 328 | + $status = $this->checkCacheDirs(); |
302 | 329 | |
303 | | - $this->checkCacheDirs(); |
| 330 | + if($wgUseGzip){ |
| 331 | + $outputText = gzencode( trim($text) ); |
| 332 | + }else{ |
| 333 | + $outputText = trim($text); |
| 334 | + } |
304 | 335 | |
305 | | - $f = fopen( $this->fileCacheName(), 'w' ); |
| 336 | + if($status !== true) |
| 337 | + return $status; |
| 338 | + $f = fopen( $this->filename, 'w' ); |
306 | 339 | if($f) { |
307 | | - $now = wfTimestampNow(); |
308 | | - $text = '//cached at: ' . $now . " :: " . $this->rKey . " \n" . $text ; |
309 | | - if( $this->useGzip() ) { |
310 | | - $text = gzencode( $text); |
311 | | - } |
312 | | - fwrite( $f, $text ); |
| 340 | + fwrite( $f, $outputText ); |
313 | 341 | fclose( $f ); |
| 342 | + }else{ |
| 343 | + return 'Could not open file for writing. Check your cache directory permissions?'; |
314 | 344 | } |
315 | | - return $text; |
| 345 | + return true; |
316 | 346 | } |
317 | 347 | protected function checkCacheDirs() { |
318 | | - $filename = $this->fileCacheName(); |
319 | | - $mydir2 = substr($filename,0,strrpos($filename,'/')); # subdirectory level 2 |
| 348 | + $mydir2 = substr($this->filename,0,strrpos($this->filename,'/')); # subdirectory level 2 |
320 | 349 | $mydir1 = substr($mydir2,0,strrpos($mydir2,'/')); # subdirectory level 1 |
321 | 350 | |
322 | | - wfMkdirParents( $mydir1 ); |
323 | | - wfMkdirParents( $mydir2 ); |
| 351 | + if( wfMkdirParents( $mydir1 ) === false || wfMkdirParents( $mydir2 ) === false){ |
| 352 | + return 'Could not create cache directory. Check your cache directory permissions?'; |
| 353 | + }else{ |
| 354 | + return true; |
| 355 | + } |
324 | 356 | } |
325 | 357 | } |
326 | 358 | |
Index: branches/new-upload/phase3/js2/uploadPage.js |
— | — | @@ -15,8 +15,8 @@ |
16 | 16 | //an api url (we won't submit directly to action of the form) |
17 | 17 | 'api_url' : wgServer + wgScriptPath + '/api.php', |
18 | 18 | 'form_rewrite': true, |
19 | | - 'new_source_cb' : function( filename ){ |
20 | | - $j('#wpDestFile').val( filename ); |
| 19 | + 'new_source_cb' : function( orgFilename, oggName ){ |
| 20 | + $j('#wpDestFile').val( oggName ); |
21 | 21 | mwUploadHelper.doDestCheck(); |
22 | 22 | } |
23 | 23 | }); |