Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/load.php |
— | — | @@ -28,8 +28,24 @@ |
29 | 29 | |
30 | 30 | require ( dirname( __FILE__ ) . '/includes/MwEmbedWebStartSetup.php' ); |
31 | 31 | |
| 32 | +// A script we put in front of mwEmbedResourceLoader to quickly serve files from cache, |
| 33 | +// in the absence of a reverse proxy in front of the resource loader. |
| 34 | +// if you ~do~ reverse proxy resource loader you can set |
| 35 | +// $mwUsePoorManSquidProxy = false; |
| 36 | + |
| 37 | +MwEmbedPoorManSquidProxy::checkCacheRespond(); |
| 38 | + |
32 | 39 | // Respond to resource loading request |
33 | 40 | $resourceLoader = new MwEmbedResourceLoader(); |
34 | | -$resourceLoader->respond( new MwEmbedResourceLoaderContext( $resourceLoader, $wgRequest ) ); |
| 41 | +$output = $resourceLoader->respond( new MwEmbedResourceLoaderContext( $resourceLoader, $wgRequest ) ); |
35 | 42 | |
| 43 | +// Save the current response to the cache |
| 44 | +MwEmbedPoorManSquidProxy::saveCacheRespond($output); |
36 | 45 | |
| 46 | +/* |
| 47 | + * For profile info: |
| 48 | +*/ |
| 49 | +/* |
| 50 | +arsort( $wgSimpleProfile ); |
| 51 | +print_r( $wgSimpleProfile ); |
| 52 | +*/ |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedMediaWikiGlobalFunctions.php |
— | — | @@ -279,9 +279,11 @@ |
280 | 280 | global $IP; |
281 | 281 | $filePath = mwGetFilePathFromKey( $key ); |
282 | 282 | $path = dirname( $filePath ); |
283 | | - $ok = mkdir( $path, 0777, true ); // PHP5 <3 |
284 | | - if( !$ok ){ |
285 | | - return false; |
| 283 | + if( !is_dir($path ) ){ |
| 284 | + $ok = mkdir( $path, 0777, true ); // PHP5 <3 |
| 285 | + if( !$ok ){ |
| 286 | + return false; |
| 287 | + } |
286 | 288 | } |
287 | 289 | return @file_put_contents( $filePath, serialize( $data ) ); |
288 | 290 | } |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedAutoLoader.php |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | |
29 | 29 | # MwEmbed files ( that get autoloaded ): |
30 | 30 | 'MwEmbedResourceLoaderContext' => 'includes/MwEmbedResourceLoaderContext.php', |
| 31 | + 'MwEmbedPoorManSquidProxy' => 'includes/MwEmbedPoorManSquidProxy.php', |
31 | 32 | 'MwEmbedResourceLoader' => 'includes/MwEmbedResourceLoader.php', |
32 | 33 | 'MwEmbedResourceLoaderFileModule' => 'includes/MwEmbedResourceLoaderFileModule.php', |
33 | 34 | 'MwEmbedResourceLoaderStartUpModule' => 'includes/MwEmbedResourceLoaderStartUpModule.php', |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedPoorManSquidProxy.php |
— | — | @@ -0,0 +1,92 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class MwEmbedPoorManSquidProxy { |
| 5 | + public static $hash = null; |
| 6 | + public static $debug = null; |
| 7 | + |
| 8 | + public static function checkCacheRespond( ){ |
| 9 | + global $wgDefaultSkin, $wgResourceLoaderMaxage, $wgResourceLoaderDebug, $wgRequest; |
| 10 | + $request = $wgRequest; |
| 11 | + self::$debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug ) ; |
| 12 | + // Never respond in debug mode getDebug |
| 13 | + if( self::$debug ){ |
| 14 | + return ; |
| 15 | + } |
| 16 | + $modules = $request->getVal( 'modules' ); |
| 17 | + $modules = $modules ? explode( '|', $modules ) : array(); |
| 18 | + if( count( $modules ) == 0 ){ |
| 19 | + $modules[] = 'startup'; |
| 20 | + } |
| 21 | + $skin = $request->getVal( 'skin' ); |
| 22 | + if ( !$skin ) { |
| 23 | + $skin = $wgDefaultSkin; |
| 24 | + } |
| 25 | + $only = $request->getVal( 'only' ); |
| 26 | + $version = $request->getVal( 'version' ); |
| 27 | + |
| 28 | + // Set the version: |
| 29 | + if( !$version ){ |
| 30 | + $smaxage = $wgResourceLoaderMaxage['unversioned']['server']; |
| 31 | + } else { |
| 32 | + $smaxage = $wgResourceLoaderMaxage['versioned']['server']; |
| 33 | + } |
| 34 | + $modulesString = implode( '', $modules); |
| 35 | + self::$hash = md5( implode( '', array( $version, $skin, $only, $modulesString ) ) ); |
| 36 | + |
| 37 | + /** |
| 38 | + * Handle the response |
| 39 | + */ |
| 40 | + |
| 41 | + // Check if we have a cached file: |
| 42 | + if( !is_file( mwGetFilePathFromKey( self::$hash ) ) ){ |
| 43 | + return ; |
| 44 | + } |
| 45 | + |
| 46 | + // Check file modified time: |
| 47 | + $fileTime = wfTimestamp( TS_UNIX, filemtime( mwGetFilePathFromKey( self::$hash ) ) ); |
| 48 | + if( wfTimestamp( TS_UNIX, time() ) - $fileTime > $smaxage){ |
| 49 | + // Run the normal resource loader |
| 50 | + return ; |
| 51 | + } |
| 52 | + |
| 53 | + // Check if we can send a 304 to the client: |
| 54 | + // 'If-Modified-Since' and 'version' we can assume there is no modification: |
| 55 | + $ims = $request->getHeader( 'If-Modified-Since' ); |
| 56 | + if ( $ims !== false && $version ) { |
| 57 | + for ( $i = 0; $i < ob_get_level(); $i++ ) { |
| 58 | + ob_end_clean(); |
| 59 | + } |
| 60 | + header( 'HTTP/1.0 304 Not Modified' ); |
| 61 | + header( 'Status: 304 Not Modified' ); |
| 62 | + wfProfileOut( __METHOD__ ); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + // Send the same headers as ResourceLoader: |
| 67 | + if ( $only === 'styles' ) { |
| 68 | + header( 'Content-Type: text/css' ); |
| 69 | + } else { |
| 70 | + header( 'Content-Type: text/javascript' ); |
| 71 | + } |
| 72 | + header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $fileTime ) ); |
| 73 | + header( "Cache-Control: public, max-age=$smaxage, s-maxage=$smaxage" ); |
| 74 | + header( 'Expires: ' . wfTimestamp( TS_RFC2822, $smaxage + time() ) ); |
| 75 | + |
| 76 | + echo mweGetFromFileCache( self::$hash ); |
| 77 | + // exit ( don't continue resource loader handling ) |
| 78 | + exit(1); |
| 79 | + } |
| 80 | + public static function saveCacheRespond(& $output){ |
| 81 | + global $mwUsePoorManSquidProxy; |
| 82 | + // Don't cache debug output and only cache if squid proxy is enabled: |
| 83 | + if( !self::$debug && $mwUsePoorManSquidProxy ){ |
| 84 | + mweSaveFileToCache( self::$hash, $output); |
| 85 | + } |
| 86 | + // Headers already set in Resource loader ) |
| 87 | + echo $output; |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +?> |
\ No newline at end of file |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedResourceLoaderContext.php |
— | — | @@ -5,7 +5,6 @@ |
6 | 6 | * of a specific loader request |
7 | 7 | */ |
8 | 8 | class MwEmbedResourceLoaderContext extends ResourceLoaderContext{ |
9 | | - |
10 | 9 | public function getDirection() { |
11 | 10 | if ( $this->direction === null ) { |
12 | 11 | $this->direction = $this->request->getVal( 'dir' ); |
— | — | @@ -13,5 +12,5 @@ |
14 | 13 | return $this->direction; |
15 | 14 | } |
16 | 15 | } |
17 | | - |
| 16 | + |
18 | 17 | ?> |
\ No newline at end of file |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/DefaultSettings.php |
— | — | @@ -22,6 +22,9 @@ |
23 | 23 | // Default Load Script path |
24 | 24 | $wgLoadScript = $wgServer . $wgScriptPath . 'load.php'; |
25 | 25 | |
| 26 | +// If we should use simple php file cache infront of resource loader |
| 27 | +// helps performance in situations where you don't reverse proxy the resource loader. |
| 28 | +$mwUsePoorManSquidProxy = true; |
26 | 29 | |
27 | 30 | // The list of enabled modules |
28 | 31 | $wgMwEmbedEnabledModules = array(); |
— | — | @@ -60,8 +63,26 @@ |
61 | 64 | /* Default skin can be any jquery based skin */ |
62 | 65 | $wgDefaultSkin = 'kaltura-dark'; |
63 | 66 | |
| 67 | +// If the resource loader is in 'debug mode' |
| 68 | +$wgResourceLoaderDebug = false; |
64 | 69 | |
65 | 70 | |
| 71 | +/** |
| 72 | + * Maximum time in seconds to cache resources served by the resource loader |
| 73 | + */ |
| 74 | +$wgResourceLoaderMaxage = array( |
| 75 | + 'versioned' => array( |
| 76 | + // Squid/Varnish but also any other public proxy cache between the client and MediaWiki |
| 77 | + 'server' => 30 * 24 * 60 * 60, // 30 days |
| 78 | + // On the client side (e.g. in the browser cache). |
| 79 | + 'client' => 30 * 24 * 60 * 60, // 30 days |
| 80 | + ), |
| 81 | + 'unversioned' => array( |
| 82 | + 'server' => 5 * 60, // 5 minutes |
| 83 | + 'client' => 5 * 60, // 5 minutes |
| 84 | + ), |
| 85 | +); |
| 86 | + |
66 | 87 | /********************************************************* |
67 | 88 | * Default Kaltura Configuration: |
68 | 89 | * TODO move kaltura configuration to KalturaSupport module ( part of ResourceLoader update ) |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedMediaWikiStubs.php |
— | — | @@ -7,10 +7,15 @@ |
8 | 8 | /** |
9 | 9 | * global functions |
10 | 10 | */ |
| 11 | +$wgSimpleProfile = array(); |
11 | 12 | function wfProfileIn($na){ |
| 13 | + global $wgSimpleProfile; |
| 14 | + $wgSimpleProfile[$na] = microtime(); |
12 | 15 | return ; |
13 | 16 | } |
14 | 17 | function wfProfileOut($na){ |
| 18 | + global $wgSimpleProfile; |
| 19 | + $wgSimpleProfile[$na] = microtime() - $wgSimpleProfile[$na]; |
15 | 20 | return ; |
16 | 21 | } |
17 | 22 | function wfDebug( $text, $logonly = false ) { |
— | — | @@ -246,7 +251,14 @@ |
247 | 252 | * @return Boolean |
248 | 253 | */ |
249 | 254 | public function getFuzzyBool( $name, $default = false ) { |
250 | | - return ( isset( $this->data[ $name ] ) )? ( $this->data[ $name ] ) : $default; |
| 255 | + if( isset( $this->data[ $name ] ) ){ |
| 256 | + if( $this->data[ $name ] === 'false' ){ |
| 257 | + return false; |
| 258 | + } |
| 259 | + return true; |
| 260 | + } else { |
| 261 | + return $default; |
| 262 | + } |
251 | 263 | } |
252 | 264 | |
253 | 265 | /** |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/resourceloader/ResourceLoader.php |
— | — | @@ -411,7 +411,7 @@ |
412 | 412 | |
413 | 413 | // Remove the output buffer and output the response |
414 | 414 | ob_end_clean(); |
415 | | - echo $response; |
| 415 | + return $response; |
416 | 416 | |
417 | 417 | wfProfileOut( __METHOD__ ); |
418 | 418 | } |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/modules/EmbedPlayer/tests/Player_Sources.html |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | <head> |
5 | 5 | <title>Player sources</title> |
6 | 6 | |
7 | | -<script type="text/javascript" src="../../../load.php?modules=startup&only=scripts&debug=true"></script> |
| 7 | +<script type="text/javascript" src="../../../load.php?modules=startup&only=scripts"></script> |
8 | 8 | </head> |
9 | 9 | <body> |
10 | 10 | |