Index: trunk/phase3/includes/resourceloader/ResourceLoader.php |
— | — | @@ -23,7 +23,10 @@ |
24 | 24 | defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | 25 | |
26 | 26 | /** |
27 | | - * Dynamic JavaScript and CSS resource loading system |
| 27 | + * Dynamic JavaScript and CSS resource loading system. |
| 28 | + * |
| 29 | + * Most of the documention is on the MediaWiki documentation wiki starting at |
| 30 | + * http://www.mediawiki.org/wiki/ResourceLoader |
28 | 31 | */ |
29 | 32 | class ResourceLoader { |
30 | 33 | |
— | — | @@ -39,9 +42,12 @@ |
40 | 43 | * |
41 | 44 | * This is not inside the module code because it's so much more performant to request all of the information at once |
42 | 45 | * than it is to have each module requests it's own information. |
43 | | - * |
44 | | - * @param $modules array list of module names to preload information for |
45 | | - * @param $context ResourceLoaderContext context to load the information within |
| 46 | + * |
| 47 | + * This method grab modules dependencies from the database and initialize modules object. |
| 48 | + * A first pass compute dependencies, a second one the blob mtime. |
| 49 | + * |
| 50 | + * @param $modules Array List of module names to preload information for |
| 51 | + * @param $context ResourceLoaderContext Context to load the information within |
46 | 52 | */ |
47 | 53 | protected function preloadModuleInfo( array $modules, ResourceLoaderContext $context ) { |
48 | 54 | if ( !count( $modules ) ) { |
— | — | @@ -57,7 +63,8 @@ |
58 | 64 | 'md_skin' => $context->getSkin() |
59 | 65 | ), __METHOD__ |
60 | 66 | ); |
61 | | - |
| 67 | + |
| 68 | + // Set modules dependecies |
62 | 69 | $modulesWithDeps = array(); |
63 | 70 | foreach ( $res as $row ) { |
64 | 71 | $this->modules[$row->md_module]->setFileDependencies( $skin, |
— | — | @@ -65,7 +72,7 @@ |
66 | 73 | ); |
67 | 74 | $modulesWithDeps[] = $row->md_module; |
68 | 75 | } |
69 | | - // Register the absence of a dependencies row too |
| 76 | + // Register the absence of a dependency row too |
70 | 77 | foreach ( array_diff( $modules, $modulesWithDeps ) as $name ) { |
71 | 78 | $this->modules[$name]->setFileDependencies( $skin, array() ); |
72 | 79 | } |
— | — | @@ -96,7 +103,13 @@ |
97 | 104 | } |
98 | 105 | |
99 | 106 | /** |
100 | | - * Runs text through a filter, caching the filtered result for future calls |
| 107 | + * Runs text (js,CSS) through a filter, caching the filtered result for future calls. |
| 108 | + * |
| 109 | + * Availables filters are: |
| 110 | + * - minify-js \see JSMin::minify |
| 111 | + * - minify-css \see CSSMin::minify |
| 112 | + * - flip-css \see CSSJanus::transform |
| 113 | + * When the filter names does not exist, text is returned as is. |
101 | 114 | * |
102 | 115 | * @param $filter String: name of filter to run |
103 | 116 | * @param $data String: text to filter, such as JavaScript or CSS text |
— | — | @@ -108,6 +121,8 @@ |
109 | 122 | wfProfileIn( __METHOD__ ); |
110 | 123 | |
111 | 124 | // For empty or whitespace-only things, don't do any processing |
| 125 | + # FIXME: we should return the data unfiltered if $filter is not supported. |
| 126 | + # that would save up a md5 computation and one memcached get. |
112 | 127 | if ( trim( $data ) === '' ) { |
113 | 128 | wfProfileOut( __METHOD__ ); |
114 | 129 | return $data; |
— | — | @@ -125,6 +140,7 @@ |
126 | 141 | // Run the filter |
127 | 142 | try { |
128 | 143 | switch ( $filter ) { |
| 144 | + # note: if adding a new filter. Please update method documentation above. |
129 | 145 | case 'minify-js': |
130 | 146 | $result = JSMin::minify( $data ); |
131 | 147 | break; |
— | — | @@ -143,7 +159,7 @@ |
144 | 160 | throw new MWException( 'Filter threw an exception: ' . $exception->getMessage() ); |
145 | 161 | } |
146 | 162 | |
147 | | - // Save to memcached |
| 163 | + // Save filtered text to memcached |
148 | 164 | $wgMemc->set( $key, $result ); |
149 | 165 | |
150 | 166 | wfProfileOut( __METHOD__ ); |
— | — | @@ -259,13 +275,13 @@ |
260 | 276 | // If a version wasn't specified we need a shorter expiry time for updates to |
261 | 277 | // propagate to clients quickly |
262 | 278 | if ( is_null( $context->getVersion() ) ) { |
263 | | - $maxage = $wgResourceLoaderMaxage['unversioned']['client']; |
| 279 | + $maxage = $wgResourceLoaderMaxage['unversioned']['client']; |
264 | 280 | $smaxage = $wgResourceLoaderMaxage['unversioned']['server']; |
265 | 281 | } |
266 | 282 | // If a version was specified we can use a longer expiry time since changing |
267 | 283 | // version numbers causes cache misses |
268 | 284 | else { |
269 | | - $maxage = $wgResourceLoaderMaxage['versioned']['client']; |
| 285 | + $maxage = $wgResourceLoaderMaxage['versioned']['client']; |
270 | 286 | $smaxage = $wgResourceLoaderMaxage['versioned']['server']; |
271 | 287 | } |
272 | 288 | |
— | — | @@ -311,6 +327,12 @@ |
312 | 328 | wfProfileOut( __METHOD__ ); |
313 | 329 | } |
314 | 330 | |
| 331 | + /** |
| 332 | + * |
| 333 | + * @param $context ResourceLoaderContext |
| 334 | + * @param $modules Array array( modulename => ResourceLoaderModule ) |
| 335 | + * @param $missing Unavailables modules (Default null) |
| 336 | + */ |
315 | 337 | public function makeModuleResponse( ResourceLoaderContext $context, array $modules, $missing = null ) { |
316 | 338 | // Pre-fetch blobs |
317 | 339 | $blobs = $context->shouldIncludeMessages() ? |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderContext.php |
— | — | @@ -49,16 +49,19 @@ |
50 | 50 | |
51 | 51 | $this->resourceLoader = $resourceLoader; |
52 | 52 | $this->request = $request; |
| 53 | + |
53 | 54 | // Interpret request |
| 55 | + # list of modules |
54 | 56 | $modules = $request->getVal( 'modules' ); |
55 | | - $this->modules = $modules ? explode( '|', $modules ) : array(); |
56 | | - $this->language = $request->getVal( 'lang' ); |
| 57 | + $this->modules = $modules ? explode( '|', $modules ) : array(); |
| 58 | + # various parameters |
| 59 | + $this->language = $request->getVal( 'lang' ); |
57 | 60 | $this->direction = $request->getVal( 'dir' ); |
58 | | - $this->skin = $request->getVal( 'skin' ); |
59 | | - $this->user = $request->getVal( 'user' ); |
60 | | - $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug ); |
61 | | - $this->only = $request->getVal( 'only' ); |
62 | | - $this->version = $request->getVal( 'version' ); |
| 61 | + $this->skin = $request->getVal( 'skin' ); |
| 62 | + $this->user = $request->getVal( 'user' ); |
| 63 | + $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug ); |
| 64 | + $this->only = $request->getVal( 'only' ); |
| 65 | + $this->version = $request->getVal( 'version' ); |
63 | 66 | |
64 | 67 | // Fallback on system defaults |
65 | 68 | if ( !$this->language ) { |