r65502 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65501‎ | r65502 | r65503 >
Date:02:21, 24 April 2010
Author:dale
Status:deferred
Tags:
Comment:
extension side of r65416
Modified paths:
  • /trunk/extensions/JS2Support/JS2AutoLoader.php (modified) (history)
  • /trunk/extensions/JS2Support/JS2Support.i18n.php (modified) (history)
  • /trunk/extensions/JS2Support/JS2Support.php (modified) (history)
  • /trunk/extensions/JS2Support/README (added) (history)
  • /trunk/extensions/JS2Support/ScriptLoaderOutputPage.php (modified) (history)
  • /trunk/extensions/JS2Support/mwScriptLoader.php (modified) (history)

Diff [purge]

Index: trunk/extensions/JS2Support/JS2Support.i18n.php
@@ -61,13 +61,6 @@
6262 'js2support-desc' => 'Apoio JS2 en forma de extensión',
6363 );
6464
65 -/** Swiss German (Alemannisch)
66 - * @author Als-Holder
67 - */
68 -$messages['gsw'] = array(
69 - 'js2support-desc' => 'JS2-Unterstitzig dur e Erwyterig',
70 -);
71 -
7265 /** Upper Sorbian (Hornjoserbsce)
7366 * @author Michawiki
7467 */
Index: trunk/extensions/JS2Support/ScriptLoaderOutputPage.php
@@ -6,7 +6,7 @@
77 */
88
99 /**
10 - * ScriptLoaderOutputPage extends OutputPage with script-loader calls
 10+ * ScriptLoaderOutputPage extends OutputPage with script-loader calls
1111 */
1212 class ScriptLoaderOutputPage extends OutputPage {
1313 // Flag javascript Classes loaded
@@ -22,11 +22,15 @@
2323 * Default Buckets include:
2424 * 'page' - Default, Script part of the "current page"
2525 * to improve cache hit rate only put scripts / css
26 - * into the page bucket if specific to a page
 26+ * into the page bucket if specific to a particular page ( and no other )
2727 * ( ie Special:Upload or action=edit )
2828 * 'user' - scripts /css specific to the current logged in user
29 - * 'core' - scripts /css loaded on every page view
30 - * ( mwEmbed.js, jQuery, and wikibits are in this bucket by deafult )
 29+ * 'allpage' - scripts /css loaded on every page view
 30+ * ( jQuery, mwEmbed.js and wikibits are in this bucket by default )
 31+ * 'abritraryString' - Arbitrary script grouping bucket string
 32+ * For example if you had a script that was included on
 33+ * all category pages then the bucket could be 'category'
 34+ * this way you would not break the cache for other per page scripts
3135 */
3236 var $mScriptLoaderClassList = array(
3337 'js'=> array(),
@@ -39,7 +43,7 @@
4044 // Local scriptLoader instance object
4145 var $mScriptLoader = null;
4246
43 -/**
 47+ /**
4448 * Add a JavaScript file out of skins/common, or a given relative path.
4549 *
4650 * @param $file String: filename in skins/common or complete on-server path
@@ -83,9 +87,9 @@
8488 if( isset( $reqSet['title'] ) && $reqSet != '' ) {
8589 // Make sure the title ends with .js or css
8690 if( substr( $reqSet['title'], -3 ) != '.js' &&
87 - substr( $reqSet['title'], -3 ) != 'css' &&
88 - $reqSet['title'] != '-' ){
89 - return false;
 91+ substr( $reqSet['title'], -3 ) != 'css' &&
 92+ $reqSet['title'] != '-' ){
 93+ return false;
9094 }
9195
9296 $className = 'WT:' . $reqSet['title'];
@@ -119,7 +123,7 @@
120124 // Add site JS if enabled:
121125 if( $wgUseSiteJs ) {
122126 $this->addScriptClass( 'WT:-|useskin=' .
123 - urlencode( $sk->getSkinName() ) .'|gen=js' );
 127+ urlencode( $sk->getSkinName() ) .'|gen=js' );
124128 }
125129
126130 // Add user js if enabled:
@@ -145,7 +149,7 @@
146150 }
147151
148152 // Add our core scripts to mScripts ( includes jQuery, mwEmbed & wikibits )
149 - $this->includeCoreJS();
 153+ $this->includeAllPageJS();
150154
151155
152156 // If the script-loader is enabled get script-loader classes per buckets
@@ -227,7 +231,7 @@
228232 return '';
229233 }
230234 }
231 -
 235+
232236 // If script-loader enabled check if we can add the script via script-loader
233237 if( $wgEnableScriptLoader ) {
234238 global $wgStylePath, $wgScript;
@@ -235,7 +239,7 @@
236240 if( strpos( $style, $wgScript ) === false ) {
237241 $style = $wgStylePath ."/". $style;
238242 }
239 - $cssClass = $this->getClassFromPath( $style );
 243+ $cssClass = $this->getClassFromPath( $style );
240244 if( $cssClass ) {
241245 $this->addScriptClass( $cssClass, $bucketKey, 'css');
242246 // Update the options for this script bucket. ( css has per-bucket options )
@@ -251,7 +255,7 @@
252256 * These will be applied to various media & IE conditionals.
253257 */
254258 public function buildCssLinks() {
255 - global $wgEnableScriptLoader;
 259+ global $wgEnableScriptLoader;
256260 $scriptLoaderCss = '';
257261 if( $wgEnableScriptLoader ){
258262 $scriptLoaderCss = $this->getScriptLoaderCss();
@@ -269,16 +273,18 @@
270274 *
271275 * @since 1.17
272276 */
273 - public function includeCoreJS ( ) {
 277+ public function includeAllPageJS ( ) {
274278 global $wgExtensionJavascriptLoader, $wgEnableScriptLoader,
275 - $wgJSAutoloadClasses, $wgScriptPath;
 279+ $wgScriptLoaderNamedPaths, $wgScriptPath;
276280
277 - // Set core Classes ( note wikibits will be phased out )
 281+ // Set core Classes
278282 $coreClasses = array( 'wikibits', 'window.jQuery', 'mwEmbed' );
279283
280 - // Merge in any scripts that have been set as "core"
281 - if( isset( $this->mScriptLoaderClassList[ 'js' ][ 'core' ] ) ) {
282 - $coreClasses = array_merge($coreClasses, $this->mScriptLoaderClassList[ 'js' ][ 'core' ] );
 284+ // Merge in any scripts that have been set as "allpage"
 285+ // Since the all page are on every page view they should just be part of the core
 286+ // script request.
 287+ if( isset( $this->mScriptLoaderClassList[ 'js' ][ 'allpage' ] ) ) {
 288+ $coreClasses = array_merge($coreClasses, $this->mScriptLoaderClassList[ 'js' ][ 'allpage' ] );
283289 }
284290
285291 // Make sure scripts are the first scripts include on the page.
@@ -288,6 +294,7 @@
289295 $this->mScripts = '';
290296
291297 if( $wgEnableScriptLoader ) {
 298+ $this->mScripts = "\n<!-- Script bucket: allpage --> \n";
292299 $this->mScripts = $this->getLinkedScriptLoaderJs( $coreClasses );
293300 } else {
294301 // No ScriptLoader manually add the classes:
@@ -309,12 +316,12 @@
310317 * Get style sheets grouped by "media", "condition" & "bucket" attributes
311318 * call getLinkedScriptLoaderCss for each group
312319 */
313 - private function getScriptLoaderCss( ){
314 -
 320+ private function getScriptLoaderCss( ){
 321+
315322 $s='';
316323 foreach( $this->mScriptLoaderClassList['css'] as $bucketKey => $classSet ){
317324 // Note we don't include the "core" bucket since its handled by
318 - // includeCoreJS
 325+ // includeAllPageJS
319326 if( count( $classSet) ) {
320327 $options = $this->getClassBucketOptions( $bucketKey );
321328 $s .= "\n<!-- Css bucket: " . htmlspecialchars( $bucketKey ) . "--> \n";
@@ -354,9 +361,11 @@
355362 private function getScriptLoaderJs(){
356363 $s='';
357364 foreach( $this->mScriptLoaderClassList['js'] as $bucket => $classSet ){
358 - // Note we don't include the "core" bucket since its handled by
359 - // includeCoreJS
360 - if( count( $classSet) && $bucket != 'core' ){
 365+ // Note we don't include the "allpage" bucket since its handled by
 366+ // includeAllPageJS
 367+ // allpage scripts are handled separately to ensure
 368+ // they are at the top of the page.
 369+ if( count( $classSet) && $bucket != 'allpage' ){
361370 $s .= "\n<!-- Script bucket: $bucket --> \n";
362371 $s .= $this->getLinkedScriptLoaderJs( $classSet );
363372 }
@@ -383,7 +392,7 @@
384393 * @return boolean False if the class wasn't found, True on success
385394 */
386395 function addScriptClass( $className, $scriptRequestBucket = 'page' , $type='js') {
387 - global $wgDebugJavaScript, $wgJSAutoloadClasses, $IP,
 396+ global $wgDebugJavaScript, $wgScriptLoaderNamedPaths, $IP,
388397 $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgStylePath,
389398 $wgUser;
390399
@@ -458,12 +467,12 @@
459468 * @return String script path or Boolean false if not found
460469 */
461470 function getClassFromPath( $path ) {
462 - global $wgJSAutoloadClasses, $wgScriptPath;
 471+ global $wgScriptLoaderNamedPaths, $wgScriptPath;
463472 // Make sure we have the scriptClass paths loaded:
464473 jsClassLoader::loadClassPaths();
465474
466475 // Check the autoload js class list
467 - foreach( $wgJSAutoloadClasses as $className => $classPath ) {
 476+ foreach( $wgScriptLoaderNamedPaths as $className => $classPath ) {
468477 $classPath = "{$wgScriptPath}/{$classPath}";
469478 if( $path == $classPath ){
470479 return $className;
@@ -560,7 +569,7 @@
561570 }
562571
563572 // Add the latest msg rev id if $wgScriptModifiedMsgCheck is enabled
564 - // NOTE this is too slow so its disabled ( we need to cache the msg key in the database )
 573+ // NOTE this is too slow so its disabled ( we need to cache the most recent msg key in the database )
565574 /*
566575 if( $wgScriptModifiedMsgCheck ){
567576 $dbr = wfGetDB( DB_SLAVE );
Index: trunk/extensions/JS2Support/JS2Support.php
@@ -17,28 +17,88 @@
1818 $wgExtensionMessagesFiles[ 'JS2Support' ] = $dir . 'JS2Support.i18n.php';
1919 $wgAutoloadClasses[ 'ScriptLoaderOutputPage' ] = $dir . 'ScriptLoaderOutputPage.php';
2020
 21+$wgAutoloadClasses = array_merge( $wgAutoloadClasses,
 22+ array(
 23+ 'JSMin' => $dir . 'js/mwEmbed/includes/library/JSMin.php',
 24+ 'Minify_CSS' => $dir . 'js/mwEmbed/includes/library/CSS.php',
 25+ 'Minify_CommentPreserver' => $dir . 'js/mwEmbed/includes/library/CommentPreserver.php',
 26+ 'Minify_CSS_Compressor' => $dir . 'js/mwEmbed/includes/library/CSS/Compressor.php',
 27+ 'Minify_CSS_UriRewriter' => $dir . 'js/mwEmbed/includes/library/CSS/UriRewriter.php',
 28+ 'JSMinException' => $dir . 'js/mwEmbed/includes/minify/JSMin.php',
 29+ 'jsScriptLoader' => $dir . 'js/mwEmbed/jsScriptLoader.php',
 30+ 'jsClassLoader' => $dir . 'js/mwEmbed/includes/jsClassLoader.php',
 31+ 'simpleFileCache' => $dir . 'js/mwEmbed/jsScriptLoader.php',
 32+ )
 33+);
 34+
 35+// Autoloader for core mediaWiki JavaScript files (path is from the MediaWiki root folder)
 36+// All other named paths should be merged with this global
 37+$wgScriptLoaderNamedPaths = array(
 38+ 'ajax' => 'skins/common/ajax.js',
 39+ 'ajaxwatch' => 'skins/common/ajaxwatch.js',
 40+ 'allmessages' => 'skins/common/allmessages.js',
 41+ 'block' => 'skins/common/block.js',
 42+ 'changepassword' => 'skins/common/changepassword.js',
 43+ 'diff' => 'skins/common/diff.js',
 44+ 'edit' => 'skins/common/edit.js',
 45+ 'enhancedchanges.js' => 'skins/common/enhancedchanges.js',
 46+ 'history' => 'skins/common/history.js',
 47+ 'htmlform' => 'skins/common/htmlform.js',
 48+ 'IEFixes' => 'skins/common/IEFixes.js',
 49+ 'metadata' => 'skins/common/metadata.js',
 50+ 'mwsuggest' => 'skins/common/mwsuggest.js',
 51+ 'prefs' => 'skins/common/prefs.js',
 52+ 'preview' => 'skins/common/preview.js',
 53+ 'protect' => 'skins/common/protect.js',
 54+ 'rightclickedit' => 'skins/common/rightclickedit.js',
 55+ 'sticky' => 'skins/common/sticky.js',
 56+ 'upload' => 'skins/common/upload.js',
 57+ 'wikibits' => 'skins/common/wikibits.js',
 58+
 59+ // Css bindings
 60+ 'mw.style.shared' => 'skins/common/shared.css',
 61+ 'mw.style.commonPrint' => 'skins/common/commonPrint.css',
 62+ 'mw.style.vectorMainLTR' => 'skins/vector/main-ltr.css',
 63+ 'mw.style.vectorMainRTR' => 'skins/vector/main-rtl.css',
 64+
 65+ // Monobook css
 66+ 'mw.sytle.mbMain' => 'skins/monobook/main.css',
 67+ 'mw.style.mbIE5' => 'skins/monobook/IE50Fixes.css',
 68+ 'mw.style.mbIE55' => 'skins/monobook/IE55Fixes.css',
 69+ 'mw.style.mbIE60' => 'skins/skins/monobook/IE60Fixes.css',
 70+ 'mw.style.mbIE7' => 'skins/monobook/IE70Fixes.css',
 71+);
 72+
 73+
 74+/**
 75+ * Remap output page
 76+ */
2177 $wgExtensionFunctions[] = 'wfReMapOutputPage';
22 -
2378 function wfReMapOutputPage(){
2479 global $wgOut;
2580 $wgOut = new StubObject( 'wgOut', 'ScriptLoaderOutputPage' );
2681 }
27 -require_once( $dir . 'JS2AutoLoader.php' );
2882
2983
 84+
 85+/***************************
 86+* LocalSettings.php enabled js extensions
 87+****************************/
 88+require_once( $dir . 'AddMediaWizard/AddMediaWizard.php' );
 89+
3090 /****************************
31 -* DefaultSettings.php
 91+* DefaultSettings.php
3292 *****************************/
3393
3494 /*
35 - * Array mapping JavaScript class to web path for use by the script loader.
36 - * This is populated in AutoLoader.php.
 95+ * Simple global to tell extensions JS2 support is available
3796 */
38 -$wgJSAutoloadClasses = array();
 97+$wgEnableJS2system = true;
3998
 99+
40100 /**
41101 * For defining the location of loader.js files of
42 - * Extension mwEmbed modules. ( ie modules hosted inside of extensions )
 102+ * for js-modules. ( ie modules hosted inside of extensions )
43103 */
44104 $wgExtensionJavascriptLoader = array();
45105
@@ -101,7 +161,7 @@
102162 /**
103163 * Path for mwEmbed normally js/mwEmbed/
104164 */
105 -$wgMwEmbedDirectory = "extensions/JS2Support/js/mwEmbed/";
 165+$wgMwEmbedDirectory = "extensions/JS2Support/js/mwEmbed";
106166
107167 /**
108168 * Enables javascript on debugging
@@ -111,4 +171,3 @@
112172 $wgDebugJavaScript = false;
113173
114174
115 -/* AddMedia Extension EntryPoints */
Index: trunk/extensions/JS2Support/JS2AutoLoader.php
@@ -3,19 +3,18 @@
44 /****************************
55 * JS2 AutoLoader.php
66 *****************************/
7 -$wgAutoloadClasses = array_merge( $wgAutoloadClasses,
8 - array(
9 - 'JSMin' => $dir . 'js/mwEmbed/includes/library/JSMin.php',
10 - 'Minify_CSS' => $dir . 'js/mwEmbed/includes/library/CSS.php',
11 - 'Minify_CommentPreserver' => $dir . 'js/mwEmbed/includes/library/CommentPreserver.php',
12 - 'Minify_CSS_Compressor' => $dir . 'js/mwEmbed/includes/library/CSS/Compressor.php',
13 - 'Minify_CSS_UriRewriter' => $dir . 'js/mwEmbed/includes/library/CSS/UriRewriter.php',
14 - 'JSMinException' => $dir . 'js/mwEmbed/includes/minify/JSMin.php',
15 - 'jsScriptLoader' => $dir . 'js/mwEmbed/jsScriptLoader.php',
16 - 'jsClassLoader' => $dir . 'js/mwEmbed/includes/jsClassLoader.php',
17 - 'simpleFileCache' => $dir . 'js/mwEmbed/jsScriptLoader.php',
18 - )
 7+$mwEmbedAutoLoadClasses = array(
 8+ 'JSMin' => $dir . 'mwEmbed/includes/library/JSMin.php',
 9+ 'Minify_CSS' => $dir . 'mwEmbed/includes/library/CSS.php',
 10+ 'Minify_CommentPreserver' => $dir . 'mwEmbed/includes/library/CommentPreserver.php',
 11+ 'Minify_CSS_Compressor' => $dir . 'mwEmbed/includes/library/CSS/Compressor.php',
 12+ 'Minify_CSS_UriRewriter' => $dir . 'mwEmbed/includes/library/CSS/UriRewriter.php',
 13+ 'JSMinException' => $dir . 'mwEmbed/includes/minify/JSMin.php',
 14+ 'jsScriptLoader' => $dir . 'mwEmbed/jsScriptLoader.php',
 15+ 'jsClassLoader' => $dir . 'mwEmbed/includes/jsClassLoader.php',
 16+ 'simpleFileCache' => $dir . 'mwEmbed/jsScriptLoader.php',
1917 );
 18+$wgAutoloadClasses = array_merge( $wgAutoloadClasses, $mwEmbedAutoLoadClasses);
2019
2120 // Autoloader for core mediaWiki JavaScript files (path is from the MediaWiki folder)
2221 $wgJSAutoloadLocalClasses = array(
@@ -40,23 +39,10 @@
4140 'upload' => 'skins/common/upload.js',
4241 'wikibits' => 'skins/common/wikibits.js',
4342
44 - // JS2 entry points
 43+ // js2 entry points
4544 'uploadPage' => $dir . 'uploadPage.js',
4645 'editPage' => $dir . 'editPage.js',
4746 'ajaxCategories' => $dir . 'ajaxcategories.js',
48 - 'apiProxyPage' => $dir . 'apiProxyPage.js',
49 -
50 - // Css bindings
51 - 'mw.style.shared' => 'skins/common/shared.css',
52 - 'mw.style.commonPrint' => 'skins/common/commonPrint.css',
53 - 'mw.style.vectorMainLTR' => 'skins/vector/main-ltr.css',
54 -
55 - //monobook css
56 - 'mw.sytle.mbMain' => 'skins/monobook/main.css',
57 - 'mw.style.mbIE5' => 'skins/monobook/IE50Fixes.css',
58 - 'mw.style.mbIE55' => 'skins/monobook/IE55Fixes.css',
59 - 'mw.style.mbIE60' => 'skins/skins/monobook/IE60Fixes.css',
60 - 'mw.style.mbIE7' => 'skins/monobook/IE70Fixes.css',
61 -
 47+ 'apiProxyPage' => $dir . 'apiProxyPage.js'
6248 );
6349 ?>
Index: trunk/extensions/JS2Support/mwScriptLoader.php
@@ -24,8 +24,8 @@
2525 * http://www.gnu.org/copyleft/gpl.html
2626 */
2727
28 -// First do a quick check for the cached file
29 -define('MW_CACHE_SCRIPT_CHECK', true);
 28+// Set a constant so the script-loader knows its not being used in "stand alone mode"
 29+define( 'SCRIPTLOADER_MEDIAWIKI', true);
3030
3131 require_once( dirname(__FILE__) . '/js/mwEmbed/jsScriptLoader.php');
3232 // Do quick cache check via jsScriptLoader
@@ -36,7 +36,7 @@
3737
3838 // Else no-cache hit load up mediaWiki stuff and continue scriptloader processing:
3939
40 -// Change to root mediaWiki directory
 40+// Change to root mediaWiki directory
4141 chdir( '../../' );
4242
4343 // include WebStart.php
@@ -64,3 +64,4 @@
6565 $myScriptLoader->doScriptLoader();
6666
6767 wfProfileOut( 'mwScriptLoader.php' );
 68+
Index: trunk/extensions/JS2Support/README
@@ -0,0 +1,70 @@
 2+= JS2 Support Extension =
 3+
 4+To add the base js2 library support simply add the following to your LocalSettings.php:
 5+require_once( "$IP/extensions/JS2Support/JS2Support.php" );
 6+
 7+== LocalSettings.php to enable all js2 components ==
 8+
 9+# Base JS2 Support
 10+require_once( "$IP/extensions/JS2Support/JS2Support.php" );
 11+
 12+# Add Media Wizard
 13+require_once( "$IP/extensions/JS2Support/AddMediaWizard/AddMediaWizard.php" );
 14+
 15+# Upload Wizard
 16+require_once( "$IP/extensions/JS2Support/UploadWizard/UploadWizard.php" );
 17+
 18+# Ogg Handler with new player, transcoding + subtitle support.
 19+require_once( "$IP/extensions/JS2Support/OggHandler/OggHandler.php" );
 20+
 21+== Developing and Debug mode ==
 22+
 23+By default js2 support groups script and css requests, disable script grouping set:
 24+$wgEnableScriptLoader = false;
 25+
 26+If you want a fresh copy of the scripts and to disable minification in grouped requests set:
 27+$wgDebugJavaScript = true;
 28+
 29+
 30+== Using JS2 with existing extensions ==
 31+
 32+Simply add the Named path to wgScriptLoaderNamedPaths variable
 33+$wgScriptLoaderNamedPaths[ 'myExtension' ] = 'extensions/myExtension/myExtension.js';
 34+
 35+If you would like to keep compatibility with non-js2 extension support you can then
 36+just use the base outputPage addScriptFile method
 37+$wgOut->addScriptFile( 'extensions/myExtension/myExtension.js' )
 38+
 39+If you want to have JS2Support be a dependency of your extension you can then use something like:
 40+$wgOut->addScriptClass( 'myExtension', 'page' );
 41+This lets you use the namedPath for includes and gives you control over script grouping.
 42+For more info see ScriptLoaderOutputPage.php $mScriptLoaderClassList
 43+
 44+
 45+== Using JS2 with js-modules ==
 46+
 47+JS Modules are reusable pieces of javascript that can be dynamically configured, loaded
 48+and executed in arbitrary javascript contexts.
 49+
 50+JS modules include "module loaders" that build request sets of the dependent javascript
 51+and css classes for a given interface component in the context of user or application
 52+configuration.
 53+
 54+When an application wants to use that interface component it calls the module loader.
 55+The module loader checks relevant configuration and javascript application state for existing
 56+satisfied dependencies or browser specific libraries, then issues a single script-loader
 57+request that retrieves all the needed javascript, css and localized message text for
 58+that interface in minfied, gziped
 59+
 60+For now see example modules, more documentation to follow.
 61+
 62+== Using JS2 localization system ==
 63+
 64+The JS2 Localization system works similar to its php counterpart.
 65+( it even support for {{PLURAL}} transforms )
 66+
 67+To enable JS2 localization of included scripts include the
 68+msg keys you want included with a given class in the head of the javascript file:
 69+
 70+mw.addMessegeKeys( ['list', 'of', 'msg-keys' ] );
 71+

Follow-up revisions

RevisionCommit summaryAuthorDate
r65505Partly revert r65502. Looks like committing without svn up first.raymond07:21, 24 April 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r65416* refactor to make javascript modules more self-contained ( not yet fully tes...dale00:40, 22 April 2010

Status & tagging log