r65008 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65007‎ | r65008 | r65009 >
Date:03:24, 14 April 2010
Author:dale
Status:deferred
Tags:
Comment:
* improved css support in script-loader and outputPage
* minor mwEmbed control tweeks.
Modified paths:
  • /branches/js2-work/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/js2-work/phase3/includes/OutputPage.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/skins/ctrlBuilder.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/includes/OutputPage.php
@@ -46,6 +46,7 @@
4747 * $Script Loader Class List
4848 *
4949 * An array of script-classes to be grouped and loaded by script loader
 50+ * for both css and js
5051 *
5152 * Default Buckets include:
5253 * 'page' - Default, Script part of the "current page"
@@ -56,8 +57,14 @@
5758 * 'core' - scripts /css loaded on every page view
5859 * ( mwEmbed.js, jQuery, and wikibits are in this bucket by deafult )
5960 */
60 - var $mScriptLoaderClassList = array();
 61+ var $mScriptLoaderClassList = array(
 62+ 'js'=> array(),
 63+ 'css'=>array()
 64+ );
6165
 66+ // Stores the options for a given bucket ( like css media type )
 67+ var $mScriptLoaderBucketOptions = array();
 68+
6269 // Local scriptLoader instance object
6370 var $mScriptLoader = null;
6471
@@ -217,14 +224,20 @@
218225
219226 // If script-loader enabled check if we can add the script via script-loader
220227 if( $wgEnableScriptLoader ) {
221 - $jsClass = $this->getJsClassFromPath( $path );
 228+ $jsClass = $this->getClassFromPath( $path );
222229 if( $jsClass ) {
223 - $this->addScriptClass( $jsClass );
 230+ $this->addScriptClass( $jsClass, $scriptRequestBucket );
224231 return true;
225232 }
226233 }
227 -
228 - // Do checks for wiki-titles
 234+ // Add script without grouping
 235+ $this->addScript( Html::linkedScript( wfAppendQuery( $path, $wgStyleVersion ) ) );
 236+ }
 237+ /*
 238+ * Gets the class name From an internal wiki title link
 239+ */
 240+ function getClassNameFromWikiTitle( $path ){
 241+ global $wgScript;
229242 if( strpos( $path, $wgScript ) !== false ) {
230243 $reqPath = str_replace( $wgScript . '?', '', $path );
231244 $reqArgs = explode( '&', $reqPath );
@@ -232,31 +245,31 @@
233246
234247 foreach( $reqArgs as $arg ) {
235248 list( $key, $var ) = explode( '=', $arg );
236 - $reqSet[$key] = $var;
 249+ $reqSet[ $key ] = $var;
237250 }
238251
239252 if( isset( $reqSet['title'] ) && $reqSet != '' ) {
240 - $jsTitleClass = 'WT:' . $reqSet['title'];
241 - if( $wgEnableScriptLoader ) {
242 - // Extract any extra parameters (for now just skin)
243 - $ext_param = ( isset( $reqSet['useskin'] ) && $reqSet['useskin'] != '' )
244 - ? '|useskin=' . ucfirst( $reqSet['useskin'] ) : '';
 253+ // Make sure the title ends with .js or css
 254+ if( substr( $reqSet['title'], -3 ) != '.js' &&
 255+ substr( $reqSet['title'], -3 ) != 'css' &&
 256+ $reqSet['title'] != '-' ){
 257+ return false;
 258+ }
245259
246 - $this->addClassToOutputBucket( $scriptRequestBucket, $jsTitleClass . $ext_param );
247 - return true;
248 - }else{
249 - $this->addScript( Html::linkedScript(
250 - wfAppendQuery( $path, $this->getURIDparam( $jsTitleClass ) )
251 - )
252 - );
253 - return true;
 260+ $className = 'WT:' . $reqSet['title'];
 261+ // Extract any extra parameters (for now just skin)
 262+ $extraParams = array();
 263+ if( isset( $reqSet['useskin'] ) && $reqSet['useskin'] != '' ) {
 264+ $className .= '|useskin=' . ucfirst( $reqSet['useskin'] );
254265 }
 266+ if( isset( $reqSet['gen'] ) && $reqSet['gen'] != '' ) {
 267+ $className .= '|gen=' . $reqSet['gen'];
 268+ }
 269+ return $className;
255270 }
256271 }
257 -
258 - $this->addScript( Html::linkedScript( wfAppendQuery( $path, $wgStyleVersion ) ) );
 272+ return false;
259273 }
260 -
261274 /**
262275 * Add a self-contained script tag with the given contents
263276 *
@@ -2253,7 +2266,8 @@
22542267
22552268 // Add site JS if enabled:
22562269 if( $wgUseSiteJs ) {
2257 - $this->addScriptClass( 'WT:-|useskin=' . urlencode( $sk->getSkinName() ) );
 2270+ $this->addScriptClass( 'WT:-|useskin=' .
 2271+ urlencode( $sk->getSkinName() ) .'|gen=js' );
22582272 }
22592273
22602274 // Add user js if enabled:
@@ -2278,35 +2292,46 @@
22792293 }
22802294 }
22812295
2282 - // Add our core scripts to mScripts (includes jQuery, mwEmbed & wikibits
 2296+ // Add our core scripts to mScripts ( includes jQuery, mwEmbed & wikibits )
22832297 $this->includeCoreJS();
22842298
2285 - /*
2286 - * If the script-loader is enabled get script-loader classes per buckets
2287 - * ( if script-loader is off $this->mScripts already has script links )
2288 - */
 2299+
 2300+ // If the script-loader is enabled get script-loader classes per buckets
22892301 if( $wgEnableScriptLoader ) {
2290 - foreach( $this->mScriptLoaderClassList as $bucket => $classSet ){
2291 - // Note we don't include the "core" bucket since its handled by
2292 - // includeCoreJS
2293 - if( count( $classSet) && $bucket != 'core' ){
2294 - if( $wgDebugJavaScript ){
2295 - $this->addScript( "\n<!-- Script bucket: $bucket --> \n" );
2296 - }
2297 - $this->mScripts.= $this->getLinkedScriptLoaderJs( $classSet );
2298 - }
2299 - }
 2302+ $this->mScripts .= $this->getScriptLoaderJS();
23002303 }
 2304+
23012305 $scripts .= "\n" . $this->mScripts;
23022306 return $scripts;
23032307 }
2304 - protected function addClassToOutputBucket( $bucket, $classPath){
2305 - if( ! isset( $this->mScriptLoaderClassList[ $bucket ] ) ){
2306 - $this->mScriptLoaderClassList[ $bucket ] = array();
 2308+
 2309+ /**
 2310+ * Add a className to an output Bucket
 2311+ */
 2312+ protected function addClassToOutputBucket( $className, $bucket, $type = 'js' ){
 2313+ if( ! isset( $this->mScriptLoaderClassList[ $type ][ $bucket ] ) ){
 2314+ $this->mScriptLoaderClassList[ $type ][ $bucket ] = array();
23072315 }
2308 - $this->mScriptLoaderClassList[ $bucket ][] = $classPath;
 2316+ $this->mScriptLoaderClassList[ $type ][ $bucket ][] = $className;
23092317 }
 2318+
23102319 /**
 2320+ * Set the embed options for a given bucketKey
 2321+ * @param $bucketKey String: the bucketkey to apply the options to.
 2322+ */
 2323+ protected function setClassBucketOptions( $bucketKey, $options ){
 2324+ $this->mScriptLoaderBucketOptions[ $bucketKey ] = $options;
 2325+ }
 2326+ /**
 2327+ * Get class bucket options
 2328+ */
 2329+ protected function getClassBucketOptions( $bucketKey ){
 2330+ if( isset( $this->mScriptLoaderBucketOptions[ $bucketKey ] ) ){
 2331+ return $this->mScriptLoaderBucketOptions[ $bucketKey ];
 2332+ }
 2333+ return array();
 2334+ }
 2335+ /**
23112336 * Add default \<meta\> tags
23122337 */
23132338 protected function addDefaultMeta() {
@@ -2436,18 +2461,62 @@
24372462 * @param $media String: to specify a media type, 'screen', 'printable', 'handheld' or any.
24382463 * @param $condition String: for IE conditional comments, specifying an IE version
24392464 * @param $dir String: set to 'rtl' or 'ltr' for direction-specific sheets
 2465+ * @param $bucket String: Script-loader grouping string
24402466 */
2441 - public function addStyle( $style, $media='', $condition='', $dir='' ) {
 2467+ public function addStyle( $style, $media='', $condition='', $dir='', $bucket='' ) {
 2468+ global $wgEnableScriptLoader;
24422469 $options = array();
2443 - // Even though we expect the media type to be lowercase, but here we
2444 - // force it to lowercase to be safe.
2445 - if( $media )
2446 - $options['media'] = $media;
2447 - if( $condition )
2448 - $options['condition'] = $condition;
2449 - if( $dir )
2450 - $options['dir'] = $dir;
2451 - $this->styles[$style] = $options;
 2470+
 2471+ if( $media ) {
 2472+ $options['media'] = $media;
 2473+ }
 2474+ if( $condition ) {
 2475+ $options['condition'] = $condition;
 2476+ }
 2477+ if( $bucket ){
 2478+ $options['bucket'] = $bucket;
 2479+ }
 2480+
 2481+ // Build the bucket key with supplied options
 2482+ //( no dir key since dir does not require a separate bucket )
 2483+ $bucketKey = implode( '.', $options );
 2484+
 2485+ if( $dir ) {
 2486+ $options['dir'] = $dir;
 2487+ }
 2488+
 2489+ // Check if the style will be included in output:
 2490+ if( isset( $options['dir'] ) ) {
 2491+ global $wgContLang;
 2492+ $siteDir = $wgContLang->getDir();
 2493+ if( $siteDir != $options['dir'] )
 2494+ return '';
 2495+ }
 2496+ // If style set media is for different than request don't include
 2497+ if( isset( $options['media'] ) ) {
 2498+ $media = $this->transformCssMedia( $options['media'] );
 2499+ if( is_null( $media ) ) {
 2500+ return '';
 2501+ }
 2502+ }
 2503+
 2504+ // If script-loader enabled check if we can add the script via script-loader
 2505+ if( $wgEnableScriptLoader ) {
 2506+ global $wgStylePath, $wgScript;
 2507+ // Append style path if we are not a wikititle self reference:
 2508+ if( strpos( $style, $wgScript ) === false ) {
 2509+ $style = $wgStylePath ."/". $style;
 2510+ }
 2511+ $cssClass = $this->getClassFromPath( $style );
 2512+ if( $cssClass ) {
 2513+ $this->addScriptClass( $cssClass, $bucketKey, 'css');
 2514+ // Update the options for this script bucket. ( css has per-bucket options )
 2515+ $this->setClassBucketOptions( $bucketKey, $options );
 2516+ return true;
 2517+ }
 2518+ }
 2519+ // Else use normal styles output:
 2520+ $this->styles[ $style ] = $options;
24522521 }
24532522
24542523 /**
@@ -2463,6 +2532,13 @@
24642533 * These will be applied to various media & IE conditionals.
24652534 */
24662535 public function getCssLinks() {
 2536+ global $wgEnableScriptLoader;
 2537+
 2538+ $scriptLoaderCss = '';
 2539+ if( $wgEnableScriptLoader ){
 2540+ $scriptLoaderCss = $this->getScriptLoaderCss();
 2541+ }
 2542+
24672543 $links = array();
24682544 foreach( $this->styles as $file => $options ) {
24692545 $link = $this->styleLink( $file, $options );
@@ -2470,7 +2546,7 @@
24712547 $links[] = $link;
24722548 }
24732549
2474 - return implode( "\n", $links );
 2550+ return $scriptLoaderCss . "\n" . implode( "\n", $links );
24752551 }
24762552
24772553 /**
@@ -2709,8 +2785,8 @@
27102786 $coreClasses = array( 'window.jQuery', 'mwEmbed', 'wikibits' );
27112787
27122788 // Merge in any scripts that have been set as "core"
2713 - if( isset( $this->mScriptLoaderClassList[ 'core' ] ) ) {
2714 - $coreClasses = array_merge($coreClasses, $this->mScriptLoaderClassList[ 'core' ] );
 2789+ if( isset( $this->mScriptLoaderClassList[ 'js' ][ 'core' ] ) ) {
 2790+ $coreClasses = array_merge($coreClasses, $this->mScriptLoaderClassList[ 'js' ][ 'core' ] );
27152791 }
27162792
27172793 // Make sure scripts are the first scripts include on the page.
@@ -2737,29 +2813,83 @@
27382814 //Now re-append any scripts that got added prior to the includeJQuery call
27392815 $this->mScripts = $this->mScripts . $postScripts;
27402816 }
 2817+ /**
 2818+ * Get style sheets grouped by "media", "condition" & "bucket" attributes
 2819+ * call getLinkedScriptLoaderCss for each group
 2820+ */
 2821+ private function getScriptLoaderCss( ){
 2822+ $s='';
 2823+ foreach( $this->mScriptLoaderClassList['css'] as $bucketKey => $classSet ){
 2824+ // Note we don't include the "core" bucket since its handled by
 2825+ // includeCoreJS
 2826+ if( count( $classSet) ) {
 2827+ $options = $this->getClassBucketOptions( $bucketKey );
 2828+ $s .= "\n<!-- Css bucket: " . htmlspecialchars( $bucketKey ) . "--> \n";
 2829+ $s .= $this->getLinkedScriptLoaderCss( $classSet, $options );
 2830+ }
 2831+ }
 2832+ return $s;
 2833+ }
 2834+ /**
 2835+ * Get the linked css script-loader calls
 2836+ * @param Array $stylesAry Array of style sheets to be added.
 2837+ */
 2838+ private function getLinkedScriptLoaderCss( $stylesAry, $options) {
 2839+ global $wgRequest, $wgDebugJavaScript;
 2840+ $stylesString = implode( ',', $stylesAry );
27412841
 2842+ $url = wfScript( 'mwScriptLoader' ) .
 2843+ "?class={$stylesString}&" . $this->getURIDparam( $stylesAry ). "&ctype=css";
 2844+
 2845+ // Check for the media option:
 2846+ if( isset( $options['media'] ) && $options['media']!='' ){
 2847+ $link = Html::linkedStyle( $url, $options['media']);
 2848+ } else {
 2849+ $link = Html::linkedStyle( $url );
 2850+ }
 2851+
 2852+ if( isset( $options['condition'] ) ) {
 2853+ $condition = htmlspecialchars( $options['condition'] );
 2854+ $link = "<!--[if $condition]>$link<![endif]-->";
 2855+ }
 2856+
 2857+ return $link;
 2858+ }
 2859+ /*
 2860+ * Adds the script loader to mScripts
 2861+ */
 2862+ private function getScriptLoaderJs(){
 2863+ $s='';
 2864+ foreach( $this->mScriptLoaderClassList['js'] as $bucket => $classSet ){
 2865+ // Note we don't include the "core" bucket since its handled by
 2866+ // includeCoreJS
 2867+ if( count( $classSet) && $bucket != 'core' ){
 2868+ $s .= "\n<!-- Script bucket: $bucket --> \n";
 2869+ $s .= $this->getLinkedScriptLoaderJs( $classSet );
 2870+ }
 2871+ }
 2872+ return $s;
 2873+ }
27422874 /**
27432875 * Get the <script> tag which will invoke the script loader
27442876 * @param $classAry A class array
 2877+ * @param $format String either 'js' or 'css'
27452878 */
27462879 private function getLinkedScriptLoaderJs( $classAry ) {
27472880 global $wgRequest, $wgDebugJavaScript;
2748 - $classList = implode( ',', $classAry );
 2881+ $classListString = implode( ',', $classAry );
27492882
2750 - $debugParam = ( $wgDebugJavaScript ||
2751 - $wgRequest->getVal( 'debug' ) == 'true' ||
2752 - $wgRequest->getVal( 'debug' ) == '1' )
2753 - ? '&debug=true' : '';
2754 -
27552883 return Html::linkedScript( wfScript( 'mwScriptLoader' ) .
2756 - "?class={$classList}{$debugParam}&" . $this->getURIDparam( $classAry) ) . "\n";
 2884+ "?class={$classListString}&" . $this->getURIDparam( $classAry) ) . "\n";
27572885 }
27582886
27592887 /**
2760 - * @param $className String Name of the JavaScript class
 2888+ * @param $className String Name of the class
 2889+ * @param $scriptRequestBucket Name of bucket for the class
 2890+ * @param $type 'js' or 'css' for type of head item being included
27612891 * @return boolean False if the class wasn't found, True on success
27622892 */
2763 - function addScriptClass( $className, $scriptRequestBucket = 'page' ) {
 2893+ function addScriptClass( $className, $scriptRequestBucket = 'page' , $type='js') {
27642894 global $wgDebugJavaScript, $wgJSAutoloadClasses, $IP,
27652895 $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgStylePath,
27662896 $wgUser;
@@ -2768,7 +2898,7 @@
27692899 if ( substr( $className, 0, 3 ) == 'WT:' ) {
27702900 if( $wgEnableScriptLoader ) {
27712901 // Add to the mScriptLoaderClassList list
2772 - $this->addClassToOutputBucket( $scriptRequestBucket, $className );
 2902+ $this->addClassToOutputBucket( $className, $scriptRequestBucket, $type);
27732903 } else {
27742904 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
27752905 $titlePage = substr( $className, 3 );
@@ -2781,7 +2911,7 @@
27822912 }
27832913 $this->addScriptFile(
27842914 Skin::makeUrl( $titlePage,
2785 - "action=raw$jsCache&gen=js$titleArg"
 2915+ "action=raw$jsCache&gen=js$titleArg"
27862916 )
27872917 );
27882918 }
@@ -2792,14 +2922,15 @@
27932923 // Get js or css path:
27942924 $path = jsScriptLoader::getPathFromClass( $className );
27952925 if( $path == false ){
 2926+ // NOTE:: could throw an error here
27962927 //print "could not find: $className\n";
2797 - wfDebug( __METHOD__ . ' could not find js_class: ' . $className );
 2928+ wfDebug( __METHOD__ . ' scriptLoader could not find class: ' . $className );
27982929 return false; // could not find the class
27992930 }
2800 - // Valid path add it to script-loder or "link" directly
 2931+ // Valid path add it to script-loader or "link" directly
28012932 if( $wgEnableScriptLoader ) {
28022933 // Register it with the script loader
2803 - $this->addClassToOutputBucket( $scriptRequestBucket, $className );
 2934+ $this->addClassToOutputBucket( $className, $scriptRequestBucket, $type );
28042935 } else {
28052936 // Source the script directly
28062937 $prefix = "skins/common/";
@@ -2827,39 +2958,34 @@
28282959 }
28292960
28302961 /**
2831 - * Get the JS class name from script path
 2962+ * Get the class name from script path
28322963 * return false if no such path is registered.
28332964 *
28342965 * @param $path string
28352966 * @return String script path or Boolean false if not found
28362967 */
2837 - function getJsClassFromPath( $path ) {
 2968+ function getClassFromPath( $path ) {
28382969 global $wgJSAutoloadClasses, $wgScriptPath;
2839 - //Make sure we have the scriptClasses loaded:
2840 - $this->loadJsClassPaths();
 2970+ // Make sure we have the scriptClass paths loaded:
 2971+ jsClassLoader::loadClassPaths();
28412972
2842 - foreach( $wgJSAutoloadClasses as $jsClass => $jsPath ) {
2843 - $jsPath = "{$wgScriptPath}/{$jsPath}";
2844 - if( $path == $jsPath )
2845 - return $jsClass;
 2973+ // Check the autoload js class list
 2974+ foreach( $wgJSAutoloadClasses as $className => $classPath ) {
 2975+ $classPath = "{$wgScriptPath}/{$classPath}";
 2976+ if( $path == $classPath ){
 2977+ return $className;
 2978+ }
28462979 }
 2980+ // Check for mediaWiki generated path:
 2981+ $className = $this->getClassNameFromWikiTitle( $path );
 2982+ if( $className ){
 2983+ return $className;
 2984+ }
 2985+
28472986 return false;
28482987 }
28492988
28502989 /**
2851 - * Loads the javascript class paths into the AutoLoad class var
2852 - */
2853 - function loadJsClassPaths(){
2854 - // Load the javascript script class paths
2855 - if( ! $this->mLoadedJavascriptClasses ){
2856 - // Issue the load request:
2857 - jsClassLoader::loadClassPaths();
2858 - // Set the flag to true
2859 - $this->mLoadedJavascriptClasses = true;
2860 - }
2861 - }
2862 -
2863 - /**
28642990 * Get the latest title revision from a title
28652991 * update the tRev if larger than the current
28662992 * @param {Number} $currentTitleRev Current latest revision
@@ -2883,13 +3009,15 @@
28843010 */
28853011 function getURIDparam( $classAry = array() ) {
28863012 global $wgDebugJavaScript, $wgStyleVersion, $IP, $wgScriptModifiedFileCheck;
2887 - global $wgLang, $wgUser, $wgScriptModifiedMsgCheck;
 3013+ global $wgLang, $wgUser, $wgRequest, $wgScriptModifiedMsgCheck;
28883014
2889 - //Always the language key param to keep urls distinct per language
 3015+ // Set language key param to keep urls distinct per language
28903016 $uriParam = 'uselang=' . $wgLang->getCode();
28913017
28923018 // If debug mode always send fresh url:
2893 - if( $wgDebugJavaScript ) {
 3019+ if( $wgDebugJavaScript ||
 3020+ $wgRequest->getVal( 'debug' ) == 'true' ||
 3021+ $wgRequest->getVal( 'debug' ) == '1' ) {
28943022 return $uriParam . '&urid=' . time() . '&debug=true';
28953023 } else {
28963024 // Support single $classAry string
@@ -2925,7 +3053,7 @@
29263054 }
29273055 }
29283056 }
2929 - // uild the actual unique request id:
 3057+ // use the actual unique request id:
29303058 $uriParam .= "&urid={$wgStyleVersion}";
29313059
29323060 // Add the file modification time if set
@@ -2939,7 +3067,7 @@
29403068 }
29413069
29423070 // Add the latest msg rev id if $wgScriptModifiedMsgCheck is enabled
2943 - // NOTE this is too slow so its disabled (we need to cache the msg key versions somehow
 3071+ // NOTE this is too slow so its disabled ( we need to cache the msg key in the database )
29443072 /*
29453073 if( $wgScriptModifiedMsgCheck ){
29463074 $dbr = wfGetDB( DB_SLAVE );
Index: branches/js2-work/phase3/includes/AutoLoader.php
@@ -653,7 +653,13 @@
654654 'uploadPage' => 'js/uploadPage.js',
655655 'editPage' => 'js/editPage.js',
656656 'ajaxCategories' => 'js/ajaxcategories.js',
657 - 'apiProxyPage' => 'js/apiProxyPage.js'
 657+ 'apiProxyPage' => 'js/apiProxyPage.js',
 658+
 659+ // Css bindings
 660+ 'mw.style.shared' => 'skins/common/shared.css',
 661+ 'mw.style.commonPrint' => 'skins/common/commonPrint.css',
 662+ 'mw.style.vectorMainLTR' => 'skins/vector/main-ltr.css',
 663+
658664 );
659665
660666
Index: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
@@ -33,8 +33,9 @@
3434 $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $IP;
3535
3636 // Only run once
37 - if( self::$classesLoaded )
 37+ if( self::$classesLoaded ) {
3838 return false;
 39+ }
3940 self::$classesLoaded = true;
4041
4142 // Load classes from mediaWiki $wgJSAutoloadLocalClasses var:
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js
@@ -3076,20 +3076,22 @@
30773077 // Test what codecs the native player supports:
30783078 try {
30793079 var dummyvid = document.createElement( "video" );
3080 - // Test for h264:
3081 - if ( dummyvid.canPlayType && dummyvid.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"' ) == "probably" ){
3082 - this.players.addPlayer( h264NativePlayer );
 3080+ if( dummyvid.canPlayType ) {
 3081+ var canPlayH264 = dummyvid.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"' );
 3082+ var canPlayOgg = dummyvid.canPlayType && dummyvid.canPlayType( "video/ogg;codecs=\"theora,vorbis\"" );
 3083+ // Test for h264:
 3084+ if ( canPlayH264 == "probably" || canPlayH264 == "maybe" ) {
 3085+ this.players.addPlayer( h264NativePlayer );
 3086+ }
 3087+ // Test for ogg
 3088+ if ( canPlayOgg == "probably" || canPlayOgg == "maybe" ) {
 3089+ this.players.addPlayer( oggNativePlayer );
 3090+ // older versions of safari do not support canPlayType,
 3091+ // but xiph qt registers mimetype via quicktime plugin
 3092+ } else if ( this.supportedMimeType( 'video/ogg' ) ) {
 3093+ this.players.addPlayer( oggNativePlayer );
 3094+ }
30833095 }
3084 - // Test for ogg
3085 - if ( dummyvid.canPlayType && dummyvid.canPlayType( "video/ogg;codecs=\"theora,vorbis\"" ) == "probably" )
3086 - {
3087 - this.players.addPlayer( oggNativePlayer );
3088 -
3089 - // older versions of safari do not support canPlayType,
3090 - // but xiph qt registers mimetype via quicktime plugin
3091 - } else if ( this.supportedMimeType( 'video/ogg' ) ) {
3092 - this.players.addPlayer( oggNativePlayer );
3093 - }
30943096 } catch ( e ) {
30953097 mw.log( 'could not run canPlayType ' + e );
30963098 }
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/skins/ctrlBuilder.js
@@ -78,8 +78,7 @@
7979 },
8080
8181 /**
82 - * Get the controls html
83 - * @return {String} html output of controls
 82+ * Add the controls html to palyer interface
8483 */
8584 addControls: function() {
8685 // Set up local pointer to the embedPlayer
@@ -129,8 +128,7 @@
130129 },
131130
132131 /**
133 - * Builds the interface controls
134 - * @return the interface html string
 132+ * Add control components as defined per this.components
135133 */
136134 addControlComponents: function( ) {
137135 var _this = this;
@@ -571,10 +569,8 @@
572570 * Hide the control bar.
573571 */
574572 hideControlBar : function(){
575 - var animateDuration = 'slow';
576 - // Else hide the control bar ( if checkOverlayControls is still true )
 573+ var animateDuration = 'slow';
577574 this.embedPlayer.$interface.find( '.control-bar')
578 - .stop()
579575 .fadeOut( animateDuration );
580576
581577 this.embedPlayer.$interface.find( '.itext' )
@@ -589,8 +585,7 @@
590586 * Show the control bar
591587 */
592588 showControlBar : function(){
593 - var animateDuration = 'slow';
594 -
 589+ var animateDuration = 'slow';
595590 // Move up itext if present
596591 this.embedPlayer.$interface.find( '.itext' )
597592 .animate(
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js
@@ -428,8 +428,8 @@
429429 * @param {URL} apiUrl The url of the api server
430430 */
431431 // Include gadget js ( in case the user has not enabled the gadget on that domain )
432 - //var gadgetWithJS = '?withJS=MediaWiki:MwEmbed.js';
433 - var gadgetWithJS = '';
 432+ var gadgetWithJS = '?withJS=MediaWiki:MwEmbed.js';
 433+ //var gadgetWithJS = '';
434434 function getServerFrame( context ) {
435435 if( ! context || ! context.apiUrl ){
436436 mw.log( "Error no context api url " );
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -32,15 +32,22 @@
3333 // The language code for the script-loader request
3434 var $langCode = '';
3535
36 - // The javascript output string
37 - var $jsout = '';
 36+ // The output string
 37+ var $output = '';
3838
 39+ // Special prepend js var to be added to the top of minification output.
 40+ // useful for special comment tags in minification output
 41+ var $notMinifiedTopOutput = '';
 42+
3943 // The request Key for the js
4044 var $requestKey = '';
4145
4246 // Error msg
4347 var $errorMsg = '';
4448
 49+ // Output format is either 'js' or 'css';
 50+ var $outputFormat = 'js';
 51+
4552 // Debug flag
4653 var $debug = false;
4754
@@ -59,7 +66,7 @@
6067 $this->sFileCache = new simpleFileCache( $this->requestKey );
6168 if ( $this->sFileCache->isFileCached() ) {
6269 // Output headers
63 - $this->outputJsHeaders();
 70+ $this->outputHeaders();
6471 // Output cached file
6572 $this->sFileCache->outputFile();
6673 return true;
@@ -91,66 +98,67 @@
9299
93100 // Reset the requestKey:
94101 $this->requestKey = '';
 102+
95103 // Do the post proc request with configuration vars:
96104 $this->postProcRequestVars();
97 - //update the filename (if gzip is on)
 105+
 106+ // Update the filename (if gzip is on)
98107 $this->sFileCache->getCacheFileName();
99108
100 - // Setup script loader header:
101 - $this->jsout .= 'var mwScriptLoaderDate = "' . date( 'c' ) . '";' . "\n";
102 - $this->jsout .= 'var mwScriptLoaderRequestKey = "' . htmlspecialchars( $this->requestKey ) . '";' . "\n";
103 - $this->jsout .= 'var mwLang = "' . htmlspecialchars( $this->langCode ) . '";' . "\n";
 109+ // Setup script loader header ( to easy identify file data )
 110+ if( $this->outputFormat == 'js' ) {
 111+ $this->output .= 'var mwScriptLoaderDate = "' .
 112+ xml::escapeJsString( date( 'c' ) ) . '";' . "\n";
 113+ $this->output .= 'var mwScriptLoaderRequestKey = "' .
 114+ xml::escapeJsString( $this->requestKey ) . '";' . "\n";
 115+ }
104116
105 - // Special prepend js var to be added to the top of minification output.
106 - // useful for special comment tags in minification output
107 - $NotMinifiedTopJs = '';
108 -
109117 // Build the output
110118 // Swap in the appropriate language per js_file
111119 foreach ( $this->jsFileList as $classKey => $filePath ) {
112120
113121 // Get the localized script content
114 - $this->jsout .= $this->getLocalizedScriptText( $classKey );
 122+ $this->output .= $this->getLocalizedScriptText( $classKey );
115123
116124 // If the core mwEmbed class entry point add some
117125 // other "core" files:
118126 if( $classKey == 'mwEmbed' ){
119127 // Output core components ( parts of mwEmbed that are in different files )
120 - $this->jsout .= jsClassLoader::getCombinedComponentJs( $this );
 128+ $this->output .= jsClassLoader::getCombinedComponentJs( $this );
121129
122130 // Output the loaders:
123 - $this->jsout .= jsClassLoader::getCombinedLoaderJs();
 131+ $this->output .= jsClassLoader::getCombinedLoaderJs();
124132
125133 // Output the current language class js
126 - $this->jsout .= jsClassLoader::getLanguageJs( $this->langCode );
 134+ $this->output .= jsClassLoader::getLanguageJs( $this->langCode );
127135
128136 // Output the "common" css file
129 - $this->jsout .= $this->getScriptText( 'mw.style.common' );
 137+ $this->output .= $this->getScriptText( 'mw.style.common' );
130138
131139 // Output the jQuery ui theme css
132 - $this->jsout .= $this->getScriptText( 'mw.style.redmond' );
 140+ $this->output .= $this->getScriptText( 'mw.style.redmond' );
133141
134142 // Output special IE comment tag to support special mwEmbed tags.
135 - $NotMinifiedTopJs.='/*@cc_on\'video source itext playlist\'.replace(/\w+/g,function(n){document.createElement(n)})@*/'."\n";
 143+ $this->notMinifiedTopOutput .='/*@cc_on\'video source itext playlist\'.replace(/\w+/g,function(n){document.createElement(n)})@*/'."\n";
136144 }
137145 }
138146
139147 /*
140148 * Add a mw.loadDone class callback if there was no "error" in getting any of the classes
141149 */
142 - if ( $this->errorMsg == '' ){
143 - $this->jsout .= self::getOnDoneCallback( );
 150+ if ( $this->errorMsg == '' && $this->outputFormat == 'js' ){
 151+ $this->output .= self::getOnDoneCallback( );
144152 }
145153
146154 // Check if we should minify the whole thing:
147155 if ( !$this->debug ) {
148 - $this->jsout = self::getMinifiedJs( $this->jsout , $this->requestKey );
149 - $this->jsout = $NotMinifiedTopJs . $this->jsout;
 156+ $this->output = self::getMinifiedJs( $this->output , $this->requestKey );
 157+ $this->output = $this->notMinifiedTopOutput . $this->output;
150158 }
151159
152160 // Save to the file cache
153161 if ( $wgUseFileCache && !$this->debug ) {
154 - $status = $this->sFileCache->saveToFileCache( $this->jsout );
 162+ $status = $this->sFileCache->saveToFileCache( $this->output );
155163 if ( $status !== true )
156164 $this->errorMsg .= $status;
157165 }
@@ -160,7 +168,7 @@
161169 //just set the content type (don't send cache header)
162170 header( 'Content-Type: text/javascript' );
163171 echo 'alert(\'Error With ScriptLoader ::' . str_replace( "\n", '\'+"\n"+' . "\n'", $this->errorMsg ) . '\');';
164 - echo trim( $this->jsout );
 172+ echo trim( $this->output );
165173 } else {
166174 // All good, let's output "cache" headers
167175 $this->outputJsWithHeaders();
@@ -259,9 +267,9 @@
260268 * @return String javascript to be included.
261269 */
262270 function getLocalizedScriptText( $classKey ){
263 - $jstxt = $this->getScriptText( $classKey );
264 - if( $jstxt ){
265 - return $this->doProcessJs( $jstxt );
 271+ $scriptText = $this->getScriptText( $classKey );
 272+ if( $scriptText ){
 273+ return $this->doProcessJs( $scriptText );
266274 }
267275 // Return an empty string ( error is put into $this->errorMsg )
268276 return '';
@@ -275,33 +283,44 @@
276284 * @return unknown
277285 */
278286 function getScriptText( $classKey ){
279 - $jsout = '';
280 -
 287+ $output = '';
281288 // Special case: title classes
282289 if ( substr( $classKey, 0, 3 ) == 'WT:' ) {
283290 global $wgUser;
284291 // Get just the title part
285292 $titleBlock = substr( $classKey, 3 );
286 - if ( $titleBlock[0] == '-' && strpos( $titleBlock, '|' ) !== false ) {
287 - // Special case of "-" title with skin
 293+ if ( $titleBlock[0] == '-' ) {
 294+ // Special case of "-" title
288295 $parts = explode( '|', $titleBlock );
289296 $title = array_shift( $parts );
290 - foreach ( $parts as $tparam ) {
291 - list( $key, $val ) = explode( '=', $tparam );
292 - if ( $key == 'useskin' ) {
293 - $skin = $val;
294 - }
 297+ $titleParams = array ();
 298+ foreach ( $parts as $titleParam ) {
 299+ list( $key, $val ) = explode( '=', $titleParam );
 300+ $titleParams[ $key ] = $val;
295301 }
 302+ /*
 303+ * The "-" is a special key to user / site js system sucks
 304+ * here is some code to handle it ... but it really
 305+ * should be depreciated for some more logical system
 306+ * like directly referencing the titles that we have a script-loader
 307+ */
296308 $sk = $wgUser->getSkin();
297 - // Make sure the skin name is valid
298 - $skinNames = Skin::getSkinNames();
299 - $skinNames = array_keys( $skinNames );
300 - if ( in_array( strtolower( $skin ), $skinNames ) ) {
301 - // If in debug mode, add a comment with wiki title and rev:
302 - if ( $this->debug ) {
303 - $jsout .= "\n/**\n* GenerateUserJs: \n*/\n";
 309+ if( isset( $titleParams[ 'useskin' ] ) ) {
 310+ // Make sure the skin name is valid
 311+ $skinNames = Skin::getSkinNames();
 312+ $skinNames = array_keys( $skinNames );
 313+ if ( in_array( strtolower( $titleParams[ 'useskin' ] ), $skinNames ) ) {
 314+ if( $titleParams['gen' ] == 'css' ){
 315+ return $sk->generateUserStylesheet();
 316+ }
 317+ // If in debug mode, add a comment with wiki title and rev:
 318+ if ( $this->debug ) {
 319+ $output .= "\n/**\n* GenerateUserJs: \n*/\n";
 320+ }
 321+ return $sk->generateUserJs( $titleParams[ 'useskin' ] ) . "\n";
304322 }
305 - return $sk->generateUserJs( $skin ) . "\n";
 323+ } else if( isset( $titleParams['gen' ] ) && $titleParams['gen' ] == 'css' ) {
 324+ return $sk->generateUserStylesheet();
306325 }
307326 } else {
308327 $ext = substr($titleBlock, strrpos($titleBlock, '.') + 1);
@@ -316,13 +335,14 @@
317336 // Only get the content if the page is not empty:
318337 if ( $a->getID() !== 0 ) {
319338 // If in debug mode, add a comment with wiki title and rev:
320 - if ( $this->debug )
321 - $jsout .= "\n/**\n* WikiJSPage: " . xml::escapeJsString( $titleBlock ) . " rev: " . $a->getID() . " \n*/\n";
 339+ if ( $this->debug ) {
 340+ $output .= "\n/**\n* ScriptLoader WikiPage: " . xml::escapeJsString( $titleBlock ) . " rev: " . $a->getID() . " \n*/\n";
 341+ }
322342 $fileStr = $a->getContent() . "\n";
323 - $jsout.= ( $ext == 'css' ) ?
 343+ $output.= ( $ext == 'css' ) ?
324344 $this->transformCssOutput( $classKey, $fileStr ) :
325345 $fileStr;
326 - return $jsout;
 346+ return $output;
327347 }
328348 }
329349 }
@@ -344,13 +364,13 @@
345365 if( $fileStr ){
346366 // Add the file name if debug is enabled
347367 if ( $this->debug ){
348 - $jsout .= "\n/**\n* File: " . xml::escapeJsString( $filePath ) . "\n*/\n";
 368+ $output .= "\n/**\n* File: " . xml::escapeJsString( $filePath ) . "\n*/\n";
349369 }
350 - $jsout.= ( $ext == 'css' ) ?
 370+ $output.= ( $ext == 'css' ) ?
351371 $this->transformCssOutput( $classKey, $fileStr, $filePath ) :
352372 $fileStr;
353373
354 - return $jsout;
 374+ return $output;
355375 }else{
356376 $this->errorMsg .= "\nError could not read file: ". xml::escapeJsString( $filePath ) ."\n";
357377 return false;
@@ -384,8 +404,16 @@
385405 str_replace('jsScriptLoader.php', '', $serverUri)
386406 . dirname( $path ) . '/';
387407 }
 408+ // We always run minify to update css urls
388409 $cssString = Minify_CSS::minify( $cssString, $cssOptions);
389 - // css classes should be of form mw.style.{className}
 410+
 411+ // Check output format ( if format is "css" ) return the css string directly
 412+ if( $this->outputFormat == 'css' ) {
 413+ return $cssString;
 414+ }
 415+
 416+ // Format is "javascript" return the string in an addStyleString call
 417+ // CSS classes should be of form mw.style.{className}
390418 $cssStyleName = str_replace('mw.style.', '', $classKey );
391419 return 'mw.addStyleString("' . Xml::escapeJsString( $cssStyleName )
392420 . '", "' . Xml::escapeJsString( $cssString ) . '");' . "\n";
@@ -416,9 +444,13 @@
417445 /**
418446 * Outputs the script headers
419447 */
420 - function outputJsHeaders() {
421 - // Output JS MIME type:
422 - header( 'Content-Type: text/javascript' );
 448+ function outputHeaders() {
 449+ // Output MIME type:
 450+ if( $this->outputFormat == 'css' ){
 451+ header( 'Content-Type: text/css' );
 452+ } else if ( $this->outputFormat == 'js' ) {
 453+ header( 'Content-Type: text/javascript' );
 454+ }
423455 header( 'Pragma: public' );
424456 if( $this->debug ){
425457 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
@@ -435,16 +467,16 @@
436468 */
437469 function outputJsWithHeaders() {
438470 global $wgUseGzip;
439 - $this->outputJsHeaders();
 471+ $this->outputHeaders();
440472 if ( $wgUseGzip ) {
441473 if ( $this->clientAcceptsGzip() ) {
442474 header( 'Content-Encoding: gzip' );
443 - echo gzencode( $this->jsout );
 475+ echo gzencode( $this->output );
444476 } else {
445 - echo $this->jsout;
 477+ echo $this->output;
446478 }
447479 } else {
448 - echo $this->jsout;
 480+ echo $this->output;
449481 }
450482 }
451483
@@ -502,9 +534,15 @@
503535 //set English as default
504536 $this->langCode = 'en';
505537 }
506 -
507538 $this->langCode = self::checkForCommonsLanguageFormHack( $this->langCode );
508539
 540+ // Check if the outupt format is "css" or "js"
 541+ if( isset( $_GET['ctype'] ) && $_GET['ctype'] == 'css' ){
 542+ $this->outputFormat = 'css';
 543+ } else {
 544+ $this->outputFormat = 'js';
 545+ }
 546+
509547 $reqClassList = false;
510548 if ( isset( $_GET['class'] ) && $_GET['class'] != '' ) {
511549 $reqClassList = explode( ',', $_GET['class'] );
@@ -572,7 +610,7 @@
573611 */
574612 function preProcRequestVars() {
575613 $requestKey = '';
576 - // Check for debug (won't use the cache)
 614+ // Check for debug ( won't use the cache)
577615 if ( ( isset( $_GET['debug'] ) && $_GET['debug'] == 'true' ) ) {
578616 // We are going to have to run postProcRequest
579617 return false;
@@ -595,7 +633,6 @@
596634 // Set English as default
597635 $langCode = 'en';
598636 }
599 -
600637 $langCode = self::checkForCommonsLanguageFormHack( $langCode );
601638
602639 $reqClassList = false;
@@ -622,11 +659,21 @@
623660 }
624661 }
625662 }
 663+ // Check if the outupt format is "css" or "js"
 664+ if( isset( $_GET['ctype'] ) && $_GET['ctype'] == 'css' ){
 665+ $outputFormat = 'css';
 666+ } else {
 667+ $outputFormat = 'js';
 668+ }
 669+
626670 // Add the language code to the requestKey:
627671 $requestKey .= '_' . $langCode;
628672
 673+ // Add the format to the requestKey:
 674+ $requestKey .= '_' . $outputFormat;
 675+
629676 // Add the unique rid
630 - $requestKey .= $urid;
 677+ $requestKey .= '_' . $urid;
631678
632679 return $requestKey;
633680 }
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -4,7 +4,7 @@
55 */
66 var urlparts = getRemoteEmbedPath();
77 var mwEmbedHostPath = urlparts[0];
8 -var mwRemoteVersion = 'r119';
 8+var mwRemoteVersion = 'r120';
99 var mwUseScriptLoader = true;
1010
1111 // Log the mwRemote version ( will determine what version of js we get )

Status & tagging log