r51474 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51473‎ | r51474 | r51475 >
Date:18:51, 4 June 2009
Author:dale
Status:deferred
Tags:
Comment:
* updated script-server (stand alone mode fixes)
* fixed form integration with mediaWiki
* added support for "cancel" (only on mac linux for right now)
Modified paths:
  • /branches/new-upload/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/example_usage/Make_Ogg_Advanced.html (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/mv_embed.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/php/jsAutoloadLocalClasses.php (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/php/noMediaWikiConfig.php (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/php/script-cache (added) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/php/script-cache/README (added) (history)
  • /branches/new-upload/phase3/js2/uploadPage.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/includes/DefaultSettings.php
@@ -2579,8 +2579,11 @@
25802580 $wgJSAutoloadClasses = array();
25812581
25822582 /*
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.
25842584 * 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.
25852588 */
25862589 $wgEnableScriptLoader = false;
25872590
Index: branches/new-upload/phase3/js2/mwEmbed/example_usage/Make_Ogg_Advanced.html
@@ -3,7 +3,7 @@
44 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
55 <title>Firefogg - Make Ogg Video in your Browser</title>
66 <!-- <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>
88 <style type="text/css" media="all">@import "http://www.firefogg.org/css/style.css";</style>
99 <style type="text/css" media="all">
1010 .install{
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -98,11 +98,9 @@
9999 },
100100 doRewrite:function( callback ){
101101 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+ }
107105 //check if we are rewriting an input or a form:
108106 if( this.form_rewrite ){
109107 this.setupForm();
@@ -123,14 +121,14 @@
124122 //check for the target if missing add to the output:
125123 if( _this[target] === false){
126124 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+ }
130128 }
131 - });
132 - $j( this.selector ).append( out ).hide();
 129+ });
 130+ $j( this.selector ).append( out ).hide();
133131 },
134 - getTargetHtml:function(target){
 132+ getTargetHtml:function(target){
135133 if( target.substr(7,3)=='btn'){
136134 return '<input style="" class="' + target + '" type="button" value="' + gM( 'fogg-' + target.substring(11)) + '"/> ';
137135 }else if(target.substr(7,5)=='input'){
@@ -159,7 +157,7 @@
160158
161159 //if rewriting the form lets keep the text input around:
162160 if( _this.form_rewrite )
163 - $j('#target_input_file_name').show();
 161+ $j(this.target_input_file_name).show();
164162
165163 //hide all but check-for-fogg
166164 //check for firefogg
@@ -170,7 +168,11 @@
171169 ).css({'display':'inline'}
172170 ).click(function(){
173171 _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+ })
175177
176178 }else{
177179 //first check firefox version:
@@ -241,12 +243,14 @@
242244 });
243245 if(!$j(this.selector).attr('style'))
244246 inTag += 'style="display:inline" ';
245 - inTag+= '>';
 247+ inTag+= '/><span id="' + $j(this.selector).attr('name') + '_fogg-control"></span>';
246248
247249 js_log('set input: ' + inTag);
248250 $j(this.selector).replaceWith(inTag);
249251
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";
251255
252256 this.doControlHTML();
253257 //check for the other inline status indicator targets:
@@ -294,15 +298,21 @@
295299 }
296300 //~otherwise the encoding will be triggered by the form~
297301
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 );
299304 $j(_this.target_input_file_name).val(_this.fogg.sourceFilename).show();
300305
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);
303313 }
304314 }
305315 }else{
306 - js_error("Firefogg error selecting file");
 316+ //js_error("Firefogg error selecting file");
307317 }
308318 },
309319 saveLocalFogg:function(){
@@ -323,25 +333,32 @@
324334 var ext = '';
325335 if( sf.lastIndexOf('.') != -1){
326336 ext = sf.substring( sf.lastIndexOf('.')+1 ).toLowerCase();
327 - }
328 - //ogg video or audio
329 - var cat = _this.sourceFileInfo.contentType;
 337+ }
330338
331339 //set to passthrough by default (images, arbitrary files that we want to send with http chunks)
332340 this.encoder_settings['passthrough'] = false;
333341
334342 //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() ){
337344 _this.encoder_settings['passthrough'] = false;
338345 }
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() ){
342349 _this.encoder_settings['passthrough'] = true;
343 - }
 350+ }
 351+
344352 js_log('base autoEncoderSettings::' + _this.sourceFileInfo.contentType + ' passthrough:' + _this.encoder_settings['passthrough']);
345353 },
 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+ },
346363 getProgressTitle:function(){
347364 js_log("fogg:getProgressTitle f:" + this.fogg_enabled + ' rw:' + this.form_rewrite);
348365 //return the parent if we don't have fogg turned on:
@@ -505,7 +522,7 @@
506523 _this.updateProgressWin( gM('successfulupload'), gM( 'mv_upload_done', _this.fogg.resultUrl),
507524 {
508525 go_to_url_txt:function(){
509 - document.URL = _this.fogg.resultUrl;
 526+ window.location = _this.fogg.resultUrl;
510527 }
511528 });
512529 }else{
@@ -520,8 +537,21 @@
521538 }
522539 uploadStatus();
523540 },
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+ */
526556 procPageResponse:function( result_page ){
527557 js_log('f:procPageResponse');
528558 var sstring = 'var wgTitle = "' + this.formData['wpDestFile'].replace('_',' ');
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
@@ -515,7 +515,7 @@
516516 //confirm:
517517 if( confirm( gM('mv-canecl-confim') )){
518518 //@@todo (cancel the encode / upload)
519 - //$(this).dialog('close');
 519+ //$j(dlElm).dialog('close');
520520 alert('(sorry we do not yet support cancel)');
521521 }
522522 }
Index: branches/new-upload/phase3/js2/mwEmbed/php/jsAutoloadLocalClasses.php
@@ -15,13 +15,13 @@
1616
1717 $wgJSAutoloadLocalClasses['j.contextMenu'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.contextMenu.js';
1818 $wgJSAutoloadLocalClasses['j.fn.pngFix'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.pngFix.js';
19 -
 19+
2020 $wgJSAutoloadLocalClasses['j.fn.autocomplete'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.autocomplete.js';
2121 $wgJSAutoloadLocalClasses['j.fn.hoverIntent'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.hoverIntent.js';
2222 $wgJSAutoloadLocalClasses['j.Jcrop'] = $wgMwEmbedDirectory . 'jquery/plugins/Jcrop/js/jquery.Jcrop.js';
2323 $wgJSAutoloadLocalClasses['Date.fromString'] = $wgMwEmbedDirectory . 'jquery/plugins/date.js';
2424 $wgJSAutoloadLocalClasses['j.fn.datePicker'] = $wgMwEmbedDirectory . 'jquery/plugins/jquery.datePicker.js';
25 -
 25+
2626 //jquery.ui
2727 $wgJSAutoloadLocalClasses['j.ui'] = $wgMwEmbedDirectory . 'jquery/jquery.ui-1.7.1/ui/ui.core.js';
2828
@@ -50,11 +50,12 @@
5151 $wgJSAutoloadLocalClasses['j.ui.draggable'] = $wgMwEmbedDirectory . 'jquery/jquery.ui-1.7.1/ui/ui.draggable.js';
5252 $wgJSAutoloadLocalClasses['j.ui.selectable'] = $wgMwEmbedDirectory . 'jquery/jquery.ui-1.7.1/ui/ui.selectable.js';
5353
54 -
5554 //libAddMedia:
5655 $wgJSAutoloadLocalClasses['mvFirefogg'] = $wgMwEmbedDirectory . 'libAddMedia/mvFirefogg.js';
5756 $wgJSAutoloadLocalClasses['mvAdvFirefogg'] = $wgMwEmbedDirectory . 'libAddMedia/mvAdvFirefogg.js';
5857
 58+ $wgJSAutoloadLocalClasses['mvBaseUploadInterface'] = $wgMwEmbedDirectory . 'libAddMedia/mvBaseUploadInterface.js';
 59+
5960 $wgJSAutoloadLocalClasses['remoteSearchDriver'] = $wgMwEmbedDirectory . 'libAddMedia/remoteSearchDriver.js';
6061 $wgJSAutoloadLocalClasses['seqRemoteSearchDriver'] = $wgMwEmbedDirectory . 'libAddMedia/seqRemoteSearchDriver.js';
6162 $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
17 + *
Index: branches/new-upload/phase3/js2/mwEmbed/php/noMediaWikiConfig.php
@@ -13,20 +13,77 @@
1414 //$wgMwEmbedDirectory becomes the root $IP
1515 $wgMwEmbedDirectory = '';
1616
 17+$wgFileCacheDirectory = realpath(dirname(__FILE__)) . '/script-cache';
 18+
1719 $wgUseFileCache = true;
1820
1921 $wgEnableScriptLoaderJsFile = false;
2022
2123 $wgEnableScriptLocalization = false;
 24+$wgContLanguageCode ='';
2225
2326 $wgStyleVersion = '218';
2427
2528 $wgEnableScriptMinify = true;
2629
 30+$wgUseGzip = true;
 31+
 32+
 33+/**
 34+ * Default value for chmoding of new directories.
 35+ */
 36+$wgDirectoryMode = 0777;
 37+
 38+$wgJsMimeType = 'text/javascript';
 39+
2740 //get the autoLoadClasses
2841 require_once( realpath( dirname(__FILE__) ) . '/jsAutoloadLocalClasses.php' );
29 -
 42+
3043 //get the JSmin class:
3144 require_once( realpath( dirname(__FILE__) ) . '/minify/JSMin.php' );
3245
 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+}
3390 ?>
\ No newline at end of file
Index: branches/new-upload/phase3/js2/mwEmbed/mv_embed.js
@@ -658,8 +658,8 @@
659659 }
660660 var secondLoadSet = {};
661661 //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 ;)
664664 if($.browser.msie){
665665 secondLoadSet = {
666666 '$j.ui.progressbar' : 'jquery/' + jQueryUiVN + '/ui/ui.progressbar.js',
Index: branches/new-upload/phase3/js2/mwEmbed/jsScriptLoader.php
@@ -1,55 +1,55 @@
22 <?php
33 //This core jsScriptLoader class provides the script loader functionality
4 -
54 //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:
87 require_once( realpath( dirname(__FILE__) ) . '/php/noMediaWikiConfig.php' );
9 -
10 - //run the main action:
 8+
 9+ //run the main action:
1110 $myScriptLoader = new jsScriptLoader();
12 - //preset request values via normal $_GET opperation:
 11+ //preset request values via normal $_GET opperation:
1312 $myScriptLoader->doScriptLoader();
1413 }
1514
16 -//setup page output hook
 15+//setup page output hook
1716 class jsScriptLoader{
1817 var $jsFileList = array();
1918 var $jsout = '';
20 - var $rKey = ''; // the request key
 19+ var $rKey = ''; // the request key
2120 var $error_msg ='';
2221 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+
2625 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:
3533 if( $wgUseFileCache && !$this->debug ) {
36 - //setup file cache obj:
 34+ //setup file cache obj:
3735 $this->sFileCache = new simpleFileCache( $this->rKey );
3836 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();
4140 }
42 - }
 41+ }
 42+
4343 //setup script loader header info
4444 $this->jsout .= 'var mwSlScript = "'. $_SERVER['SCRIPT_NAME'] . '";' . "\n";
4545 $this->jsout .= 'var mwSlGenISODate = "'. date('c') . '";' ."\n";
4646 $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
4949 foreach($this->jsFileList as $classKey => $file_name){
5050 //special case: - title classes:
5151 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);
5454 if($title_block[0] == '-' && strpos($title_block, '|') !== false){
5555 //special case of "-" title with skin
5656 $parts = explode('|', $title_block);
@@ -61,185 +61,202 @@
6262 }
6363 }
6464 //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);
6868 if( in_array(strtolower($skin), $skinNames )){
6969 $this->jsout .= Skin::generateUserJs( $skin ) . "\n";
7070 //success continue:
7171 continue;
7272 }
73 - }else{
74 - //its a wikiTitle append the output of the wikitext:
 73+ }else{
 74+ //its a wikiTitle append the output of the wikitext:
7575 $t = Title::newFromText ( $title_block );
7676 $a = new Article( $t );
7777 //only get content if the page is not empty:
7878 if($a->getID() !== 0 ){
7979 $this->jsout .= $a->getContent() . "\n";
80 - }
 80+ }
8181 continue;
82 - }
 82+ }
8383 }
84 -
 84+
8585 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)
8888 $this->jsout .= "\n/**
89 -* File: $file_name
90 -*/\n";
 89+* File: $file_name
 90+*/\n";
9191 $this->jsout .= ( $this->doProccessJsFile( $file_name ) ). "\n";
9292 }
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
9797 $this->jsout = JSMin::minify( $this->jsout);
98 - }
99 - //save to the file cache:
 98+ }
 99+ //save to the file cache:
100100 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;
102104 }
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+ }
110113 }
111 - function outputJsHeaders(){
112 - global $wgJsMimeType;
113 - //output js mime type:
 114+ function outputJsHeaders(){
 115+ global $wgJsMimeType;
 116+ //output js mime type:
114117 header( 'Content-type: '.$wgJsMimeType);
115118 header( "Pragma: public" );
116 - //cache forever:
 119+ //cache forever:
117120 //(the point is we never have to re validate since we should always change the request url based on the svn or article version)
118121 $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");
121123 }
 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+ }
122138 /*
123 - * updates the proc Request
 139+ * updates the proc Request
124140 */
125141 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:
129145 if( (isset($_GET['debug']) && $_GET['debug']=='true') || (isset($wgEnableScriptDebug) && $wgEnableScriptDebug==true )){
130146 $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)
134150 if( isset( $_GET['urid'] ) && $_GET['urid'] !=''){
135151 $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;
143159 if( isset($_GET['class']) && $_GET['class']!=''){
144160 $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
149165 foreach( $reqClassList as $reqClass ){
150 - if(trim($reqClass) != ''){
 166+ if(trim($reqClass) != ''){
151167 //check for special case '-' class for user generated js
152168 if( substr( $reqClass, 0, 3) == 'WT:' ){
153169 $this->jsFileList[ $reqClass ] = true;
154170 $this->rKey .= $reqClass;
155 - $this->jsvarurl = true;
 171+ $this->jsvarurl = true;
156172 continue;
157 - }
158 -
 173+ }
 174+
159175 $reqClass = ereg_replace("[^A-Za-z0-9_\-\.]", "", $reqClass );
160 -
 176+
161177 if( isset( $wgJSAutoloadLocalClasses[$reqClass] ) ){
162178 $this->jsFileList[ $reqClass ] = $wgJSAutoloadLocalClasses[ $reqClass ];
163 - $this->rKey.=$reqClass;
 179+ $this->rKey.=$reqClass;
164180 }else if( isset($wgJSAutoloadClasses[$reqClass])) {
165181 $this->jsFileList[ $reqClass ] = $wgJSAutoloadClasses[ $reqClass ];
166 - $this->rKey.=$reqClass;
167 - }else{
 182+ $this->rKey.=$reqClass;
 183+ }else{
168184 $this->error_msg.= 'Requested class: ' . $reqClass . ' not found'."\n";
169 - }
 185+ }
170186 }
171187 }
172 - }
173 - //check for requested files if enabled:
 188+ }
 189+
 190+ //check for requested files if enabled:
174191 if( $wgEnableScriptLoaderJsFile ){
175 - if( $wgRequest->getVal('files')){
176 - $reqFileList = explode(',', $wgRequest->getVal('files'));
 192+ if( isset($_GET['files'])){
 193+ $reqFileList = explode(',', isset($_GET['files']));
177194 //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:
180197 $reqFile = str_replace('../','',$reqFile);
181198 //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 );
183200 if( substr($reqFile, -3) == '.js' ){
184 - //don't add it twice:
 201+ //don't add it twice:
185202 if( !in_array($reqFile, $jsFileList )) {
186203 $this->jsFileList[] = $IP . $reqFile;
187204 $this->rKey.=$reqFile;
188 - }
 205+ }
189206 }else{
190207 $this->error_msg.= 'Not valid requsted javascript file' . "\n";
191 - }
 208+ }
192209 }
193210 }
194211 }
195 -
 212+
196213 //add the language code to the rKey:
197214 $this->rKey .= '_' . $wgContLanguageCode;
198 -
 215+
199216 //add the unique rid to the rKey
200217 $this->rKey .= $this->urid;
201 -
202 - //add a min flag:
 218+
 219+ //add a min flag:
203220 if($wgEnableScriptMinify){
204221 $this->rKey.='_min';
205222 }
206223 }
207224 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;
212226
 227+ //load the file:
 228+ $str = @file_get_contents("{$IP}/{$file_name}");
 229+
213230 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)
215232 $this->error_msg.= 'Requested File: ' . htmlspecialchars( $file_name ) . ' could not be read' . "\n";
216233 return '';
217234 }
218235 $this->cur_file = $file_name;
219 -
 236+
220237 //strip out js_log debug lines not much luck with this regExp yet:
221238 //if( !$this->debug )
222239 // $str = preg_replace('/\n\s*js_log\s*\([^\)]([^;]|\n])*;/', "\n", $str);
223 -
224 - // do language swap
 240+
 241+ // do language swap
225242 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
227244 array($this, 'languageMsgReplace'),
228 - $str);
 245+ $str);
229246
230 - return $str;
 247+ return $str;
231248 }
232249 function languageMsgReplace($jvar){
233250 if(!isset($jvar[1]))
234 - return ;
235 -
236 - $jmsg = json_decode( '{' . $jvar[1] . '}', true );
 251+ return ;
 252+
 253+ $jmsg = json_decode( '{' . $jvar[1] . '}', true );
237254 //do the language lookup:
238255 if($jmsg){
239256 foreach($jmsg as $msgKey => $default_en_value){
240257 $jmsg[$msgKey] = wfMsgNoTrans( $msgKey );
241258 }
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 ) . ')';
244261 }else{
245262 $this->error_msg.= "Could not parse JSON language msg in File:\n" .
246263 $this->cur_file ."\n";
@@ -248,78 +265,93 @@
249266 return $jvar[0];
250267 }
251268 }
252 -//a simple version of HTMLFileCache (@@todo abstract shared pieces)
 269+//a simple version of HTMLFileCache (@@todo abstract shared pieces)
253270 class simpleFileCache{
254271 var $mFileCache;
 272+ var $filename= null;
 273+ var $rKey= null;
255274 public function __construct( &$rKey ) {
256275 $this->rKey = $rKey;
257 - $this->fileCacheName(); // init name
 276+ $this->filename = $this->fileCacheName(); // init name
258277 }
259278 public function fileCacheName() {
 279+ global $wgUseGzip;
260280 if( !$this->mFileCache ) {
261 - global $wgFileCacheDirectory, $wgRequest;
262 -
 281+ global $wgFileCacheDirectory;
 282+
263283 $hash = md5( $this->rKey );
264284 # Avoid extension confusion
265285 $key = str_replace( '.', '%2E', urlencode( $this->rKey ) );
266 -
 286+
267287 $hash1 = substr( $hash, 0, 1 );
268 - $hash2 = substr( $hash, 0, 2 );
 288+ $hash2 = substr( $hash, 0, 2 );
269289 $this->mFileCache = "{$wgFileCacheDirectory}/{$subdir}{$hash1}/{$hash2}/{$this->rKey}.js";
270290
271 - if( $this->useGzip() )
 291+ if( $wgUseGzip )
272292 $this->mFileCache .= '.gz';
273293
274294 wfDebug( " fileCacheName() - {$this->mFileCache}\n" );
275295 }
276296 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;
283303 if( $wgUseGzip ) {
284304 if( wfClientAcceptsGzip() ) {
285305 header( 'Content-Encoding: gzip' );
286 - readfile( $filename );
 306+ readfile( $this->filename );
287307 } 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;
291317 }
292318 }
293319 }
294 - public function saveToFileCache( $text ) {
295 - global $wgUseFileCache;
 320+ public function saveToFileCache(& $text ) {
 321+ global $wgUseFileCache, $wgUseGzip;
296322 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';
300326
301 - wfDebug(" simpleSaveToFileCache()\n", false);
 327+ //check the directories if we could not create them error out:
 328+ $status = $this->checkCacheDirs();
302329
303 - $this->checkCacheDirs();
 330+ if($wgUseGzip){
 331+ $outputText = gzencode( trim($text) );
 332+ }else{
 333+ $outputText = trim($text);
 334+ }
304335
305 - $f = fopen( $this->fileCacheName(), 'w' );
 336+ if($status !== true)
 337+ return $status;
 338+ $f = fopen( $this->filename, 'w' );
306339 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 );
313341 fclose( $f );
 342+ }else{
 343+ return 'Could not open file for writing. Check your cache directory permissions?';
314344 }
315 - return $text;
 345+ return true;
316346 }
317347 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
320349 $mydir1 = substr($mydir2,0,strrpos($mydir2,'/')); # subdirectory level 1
321350
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+ }
324356 }
325357 }
326358
Index: branches/new-upload/phase3/js2/uploadPage.js
@@ -15,8 +15,8 @@
1616 //an api url (we won't submit directly to action of the form)
1717 'api_url' : wgServer + wgScriptPath + '/api.php',
1818 '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 );
2121 mwUploadHelper.doDestCheck();
2222 }
2323 });

Status & tagging log