Index: trunk/phase3/includes/resourceloader/ResourceLoaderSiteModule.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Roan Kattouw |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | /** |
27 | 25 | * Module for site customizations |
28 | 26 | */ |
— | — | @@ -45,7 +43,10 @@ |
46 | 44 | 'Print.css' => array( 'ns' => NS_MEDIAWIKI, 'type' => 'style', 'media' => 'print' ), |
47 | 45 | ); |
48 | 46 | if ( $wgHandheldStyle ) { |
49 | | - $pages['Handheld.css'] = array( 'ns' => NS_MEDIAWIKI, 'type' => 'style', 'media' => 'handheld' ); |
| 47 | + $pages['Handheld.css'] = array( |
| 48 | + 'ns' => NS_MEDIAWIKI, |
| 49 | + 'type' => 'style', |
| 50 | + 'media' => 'handheld' ); |
50 | 51 | } |
51 | 52 | return $pages; |
52 | 53 | } |
Index: trunk/phase3/includes/resourceloader/ResourceLoader.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Trevor Parscal |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | /** |
27 | 25 | * Dynamic JavaScript and CSS resource loading system. |
28 | 26 | * |
— | — | @@ -40,10 +38,12 @@ |
41 | 39 | /** |
42 | 40 | * Loads information stored in the database about modules. |
43 | 41 | * |
44 | | - * This method grabs modules dependencies from the database and updates modules objects. |
| 42 | + * This method grabs modules dependencies from the database and updates modules |
| 43 | + * objects. |
45 | 44 | * |
46 | | - * This is not inside the module code because it's so much more performant to request all of the information at once |
47 | | - * than it is to have each module requests its own information. This sacrifice of modularity yields a profound |
| 45 | + * This is not inside the module code because it's so much more performant to |
| 46 | + * request all of the information at once than it is to have each module |
| 47 | + * requests its own information. This sacrifice of modularity yields a profound |
48 | 48 | * performance improvement. |
49 | 49 | * |
50 | 50 | * @param $modules Array: list of module names to preload information for |
— | — | @@ -111,7 +111,8 @@ |
112 | 112 | * - minify-css \see CSSMin::minify |
113 | 113 | * - flip-css \see CSSJanus::transform |
114 | 114 | * |
115 | | - * If $data is empty, only contains whitespace or the filter was unknown, $data is returned unmodified. |
| 115 | + * If $data is empty, only contains whitespace or the filter was unknown, |
| 116 | + * $data is returned unmodified. |
116 | 117 | * |
117 | 118 | * @param $filter String: name of filter to run |
118 | 119 | * @param $data String: text to filter, such as JavaScript or CSS text |
— | — | @@ -122,17 +123,21 @@ |
123 | 124 | |
124 | 125 | wfProfileIn( __METHOD__ ); |
125 | 126 | |
126 | | - // For empty/whitespace-only data or for unknown filters, don't perform any caching or processing |
127 | | - if ( trim( $data ) === '' || !in_array( $filter, array( 'minify-js', 'minify-css', 'flip-css' ) ) ) { |
| 127 | + // For empty/whitespace-only data or for unknown filters, don't perform |
| 128 | + // any caching or processing |
| 129 | + if ( trim( $data ) === '' |
| 130 | + || !in_array( $filter, array( 'minify-js', 'minify-css', 'flip-css' ) ) ) |
| 131 | + { |
128 | 132 | wfProfileOut( __METHOD__ ); |
129 | 133 | return $data; |
130 | 134 | } |
131 | 135 | |
132 | 136 | // Try for Memcached hit |
133 | 137 | $key = wfMemcKey( 'resourceloader', 'filter', $filter, md5( $data ) ); |
134 | | - if ( is_string( $cache = $wgMemc->get( $key ) ) ) { |
| 138 | + $cacheEntry = $wgMemc->get( $key ); |
| 139 | + if ( is_string( $cacheEntry ) ) { |
135 | 140 | wfProfileOut( __METHOD__ ); |
136 | | - return $cache; |
| 141 | + return $cacheEntry; |
137 | 142 | } |
138 | 143 | |
139 | 144 | // Run the filter - we've already verified one of these will work |
— | — | @@ -149,7 +154,8 @@ |
150 | 155 | break; |
151 | 156 | } |
152 | 157 | } catch ( Exception $exception ) { |
153 | | - throw new MWException( 'ResourceLoader filter error. Exception was thrown: ' . $exception->getMessage() ); |
| 158 | + throw new MWException( 'ResourceLoader filter error. ' . |
| 159 | + 'Exception was thrown: ' . $exception->getMessage() ); |
154 | 160 | } |
155 | 161 | |
156 | 162 | // Save filtered text to Memcached |
— | — | @@ -182,10 +188,13 @@ |
183 | 189 | * Registers a module with the ResourceLoader system. |
184 | 190 | * |
185 | 191 | * @param $name Mixed: string of name of module or array of name/object pairs |
186 | | - * @param $object ResourceLoaderModule: module object (optional when using multiple-registration calling style) |
| 192 | + * @param $object ResourceLoaderModule: module object (optional when using |
| 193 | + * multiple-registration calling style) |
187 | 194 | * @throws MWException If a duplicate module registration is attempted |
188 | | - * @throws MWException If something other than a ResourceLoaderModule is being registered |
189 | | - * @return Boolean: false if there were any errors, in which case one or more modules were not registered |
| 195 | + * @throws MWException If something other than a ResourceLoaderModule is being |
| 196 | + * registered |
| 197 | + * @return Boolean: false if there were any errors, in which case one or more |
| 198 | + * modules were not registered |
190 | 199 | */ |
191 | 200 | public function register( $name, ResourceLoaderModule $object = null ) { |
192 | 201 | |
— | — | @@ -206,13 +215,15 @@ |
207 | 216 | if ( isset( $this->modules[$name] ) ) { |
208 | 217 | // A module has already been registered by this name |
209 | 218 | throw new MWException( |
210 | | - 'ResourceLoader duplicate registration error. Another module has already been registered as ' . $name |
| 219 | + 'ResourceLoader duplicate registration error. ' . |
| 220 | + 'Another module has already been registered as ' . $name |
211 | 221 | ); |
212 | 222 | } |
213 | 223 | |
214 | 224 | // Validate the input (type hinting lets null through) |
215 | 225 | if ( !( $object instanceof ResourceLoaderModule ) ) { |
216 | | - throw new MWException( 'ResourceLoader invalid module error. Instances of ResourceLoaderModule expected.' ); |
| 226 | + throw new MWException( 'ResourceLoader invalid module error. ' . |
| 227 | + 'Instances of ResourceLoaderModule expected.' ); |
217 | 228 | } |
218 | 229 | |
219 | 230 | // Attach module |
— | — | @@ -262,12 +273,14 @@ |
263 | 274 | } |
264 | 275 | } |
265 | 276 | |
266 | | - // If a version wasn't specified we need a shorter expiry time for updates to propagate to clients quickly |
| 277 | + // If a version wasn't specified we need a shorter expiry time for updates |
| 278 | + // to propagate to clients quickly |
267 | 279 | if ( is_null( $context->getVersion() ) ) { |
268 | 280 | $maxage = $wgResourceLoaderMaxage['unversioned']['client']; |
269 | 281 | $smaxage = $wgResourceLoaderMaxage['unversioned']['server']; |
270 | 282 | } |
271 | | - // If a version was specified we can use a longer expiry time since changing version numbers causes cache misses |
| 283 | + // If a version was specified we can use a longer expiry time since changing |
| 284 | + // version numbers causes cache misses |
272 | 285 | else { |
273 | 286 | $maxage = $wgResourceLoaderMaxage['versioned']['client']; |
274 | 287 | $smaxage = $wgResourceLoaderMaxage['versioned']['server']; |
— | — | @@ -278,7 +291,8 @@ |
279 | 292 | |
280 | 293 | wfProfileIn( __METHOD__.'-getModifiedTime' ); |
281 | 294 | |
282 | | - // To send Last-Modified and support If-Modified-Since, we need to detect the last modified time |
| 295 | + // To send Last-Modified and support If-Modified-Since, we need to detect |
| 296 | + // the last modified time |
283 | 297 | $mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch ); |
284 | 298 | foreach ( $modules as $module ) { |
285 | 299 | // Bypass squid cache if the request includes any private modules |
— | — | @@ -291,7 +305,11 @@ |
292 | 306 | |
293 | 307 | wfProfileOut( __METHOD__.'-getModifiedTime' ); |
294 | 308 | |
295 | | - header( 'Content-Type: ' . ( $context->getOnly() === 'styles' ? 'text/css' : 'text/javascript' ) ); |
| 309 | + if ( $context->getOnly() === 'styles' ) { |
| 310 | + header( 'Content-Type: text/css' ); |
| 311 | + } else { |
| 312 | + header( 'Content-Type: text/javascript' ); |
| 313 | + } |
296 | 314 | header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) ); |
297 | 315 | if ( $context->getDebug() ) { |
298 | 316 | header( 'Cache-Control: must-revalidate' ); |
— | — | @@ -332,10 +350,15 @@ |
333 | 351 | * @param $missing Array: list of unavailable modules (optional) |
334 | 352 | * @return String: response data |
335 | 353 | */ |
336 | | - public function makeModuleResponse( ResourceLoaderContext $context, array $modules, $missing = array() ) { |
| 354 | + public function makeModuleResponse( ResourceLoaderContext $context, |
| 355 | + array $modules, $missing = array() ) |
| 356 | + { |
337 | 357 | // Pre-fetch blobs |
338 | | - $blobs = $context->shouldIncludeMessages() ? |
339 | | - MessageBlobStore::get( $this, $modules, $context->getLanguage() ) : array(); |
| 358 | + if ( $context->shouldIncludeMessages() ) { |
| 359 | + $blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() ); |
| 360 | + } else { |
| 361 | + $blobs = array(); |
| 362 | + } |
340 | 363 | |
341 | 364 | // Generate output |
342 | 365 | $out = ''; |
— | — | @@ -351,9 +374,10 @@ |
352 | 375 | |
353 | 376 | // Styles |
354 | 377 | $styles = array(); |
355 | | - if ( $context->shouldIncludeStyles() && ( count( $styles = $module->getStyles( $context ) ) ) ) { |
| 378 | + if ( $context->shouldIncludeStyles() ) { |
| 379 | + $styles = $module->getStyles( $context ); |
356 | 380 | // Flip CSS on a per-module basis |
357 | | - if ( $this->modules[$name]->getFlip( $context ) ) { |
| 381 | + if ( $styles && $this->modules[$name]->getFlip( $context ) ) { |
358 | 382 | foreach ( $styles as $media => $style ) { |
359 | 383 | $styles[$media] = $this->filter( 'flip-css', $style ); |
360 | 384 | } |
— | — | @@ -375,7 +399,8 @@ |
376 | 400 | $out .= self::makeMessageSetScript( $messages ); |
377 | 401 | break; |
378 | 402 | default: |
379 | | - // Minify CSS before embedding in mediaWiki.loader.implement call (unless in debug mode) |
| 403 | + // Minify CSS before embedding in mediaWiki.loader.implement call |
| 404 | + // (unless in debug mode) |
380 | 405 | if ( !$context->getDebug() ) { |
381 | 406 | foreach ( $styles as $media => $style ) { |
382 | 407 | $styles[$media] = $this->filter( 'minify-css', $style ); |
— | — | @@ -391,8 +416,11 @@ |
392 | 417 | // Update module states |
393 | 418 | if ( $context->shouldIncludeScripts() ) { |
394 | 419 | // Set the state of modules loaded as only scripts to ready |
395 | | - if ( count( $modules ) && $context->getOnly() === 'scripts' && !isset( $modules['startup'] ) ) { |
396 | | - $out .= self::makeLoaderStateScript( array_fill_keys( array_keys( $modules ), 'ready' ) ); |
| 420 | + if ( count( $modules ) && $context->getOnly() === 'scripts' |
| 421 | + && !isset( $modules['startup'] ) ) |
| 422 | + { |
| 423 | + $out .= self::makeLoaderStateScript( |
| 424 | + array_fill_keys( array_keys( $modules ), 'ready' ) ); |
397 | 425 | } |
398 | 426 | // Set the state of modules which were requested but unavailable as missing |
399 | 427 | if ( is_array( $missing ) && count( $missing ) ) { |
— | — | @@ -462,7 +490,9 @@ |
463 | 491 | "( '$name', $version, $dependencies, $group );\n"; |
464 | 492 | } |
465 | 493 | |
466 | | - public static function makeLoaderRegisterScript( $name, $version = null, $dependencies = null, $group = null ) { |
| 494 | + public static function makeLoaderRegisterScript( $name, $version = null, |
| 495 | + $dependencies = null, $group = null ) |
| 496 | + { |
467 | 497 | if ( is_array( $name ) ) { |
468 | 498 | $registrations = FormatJson::encode( $name ); |
469 | 499 | return "mediaWiki.loader.register( $registrations );\n"; |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserOptionsModule.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Roan Kattouw |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | /** |
27 | 25 | * Module for user preference customizations |
28 | 26 | */ |
— | — | @@ -80,7 +78,8 @@ |
81 | 79 | // Build CSS rules |
82 | 80 | $rules = array(); |
83 | 81 | if ( $options['underline'] < 2 ) { |
84 | | - $rules[] = "a { text-decoration: " . ( $options['underline'] ? 'underline' : 'none' ) . "; }"; |
| 82 | + $rules[] = "a { text-decoration: " . |
| 83 | + ( $options['underline'] ? 'underline' : 'none' ) . "; }"; |
85 | 84 | } |
86 | 85 | if ( $options['highlightbroken'] ) { |
87 | 86 | $rules[] = "a.new, #quickbar a.new { color: #ba0000; }\n"; |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderContext.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Roan Kattouw |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | /** |
27 | 25 | * Object passed around to modules which contains information about the state |
28 | 26 | * of a specific loader request |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserModule.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Roan Kattouw |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | /** |
27 | 25 | * Module for user customizations |
28 | 26 | */ |
— | — | @@ -36,9 +34,11 @@ |
37 | 35 | $username = $context->getUser(); |
38 | 36 | return array( |
39 | 37 | "$username/common.js" => array( 'ns' => NS_USER, 'type' => 'script' ), |
40 | | - "$username/" . $context->getSkin() . '.js' => array( 'ns' => NS_USER, 'type' => 'script' ), |
| 38 | + "$username/" . $context->getSkin() . '.js' => |
| 39 | + array( 'ns' => NS_USER, 'type' => 'script' ), |
41 | 40 | "$username/common.css" => array( 'ns' => NS_USER, 'type' => 'style' ), |
42 | | - "$username/" . $context->getSkin() . '.css' => array( 'ns' => NS_USER, 'type' => 'style' ), |
| 41 | + "$username/" . $context->getSkin() . '.css' => |
| 42 | + array( 'ns' => NS_USER, 'type' => 'style' ), |
43 | 43 | ); |
44 | 44 | } |
45 | 45 | return array(); |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Roan Kattouw |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | /** |
27 | 25 | * ResourceLoader module based on local JavaScript/CSS files. |
28 | 26 | */ |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderModule.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Roan Kattouw |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | /** |
27 | 25 | * Abstraction for resource loader modules, with name registration and maxage functionality. |
28 | 26 | */ |
— | — | @@ -160,9 +158,11 @@ |
161 | 159 | ), __METHOD__ |
162 | 160 | ); |
163 | 161 | if ( !is_null( $deps ) ) { |
164 | | - return $this->fileDeps[$skin] = (array) FormatJson::decode( $deps, true ); |
| 162 | + $this->fileDeps[$skin] = (array) FormatJson::decode( $deps, true ); |
| 163 | + } else { |
| 164 | + $this->fileDeps[$skin] = array(); |
165 | 165 | } |
166 | | - return $this->fileDeps[$skin] = array(); |
| 166 | + return $this->fileDeps[$skin]; |
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php |
— | — | @@ -20,8 +20,6 @@ |
21 | 21 | * @author Roan Kattouw |
22 | 22 | */ |
23 | 23 | |
24 | | -defined( 'MEDIAWIKI' ) || die( 1 ); |
25 | | - |
26 | 24 | class ResourceLoaderStartUpModule extends ResourceLoaderModule { |
27 | 25 | /* Protected Members */ |
28 | 26 | |
— | — | @@ -107,7 +105,8 @@ |
108 | 106 | if ( ( $loader = $module->getLoaderScript() ) !== false ) { |
109 | 107 | $deps = $module->getDependencies(); |
110 | 108 | $group = $module->getGroup(); |
111 | | - $version = wfTimestamp( TS_ISO_8601_BASIC, round( $module->getModifiedTime( $context ), -2 ) ); |
| 109 | + $version = wfTimestamp( TS_ISO_8601_BASIC, |
| 110 | + round( $module->getModifiedTime( $context ), -2 ) ); |
112 | 111 | $out .= ResourceLoader::makeCustomLoaderScript( $name, $version, $deps, $group, $loader ); |
113 | 112 | } |
114 | 113 | // Automatically register module |
— | — | @@ -118,8 +117,8 @@ |
119 | 118 | if ( !count( $module->getDependencies() && $module->getGroup() === null ) ) { |
120 | 119 | $registrations[] = array( $name, $mtime ); |
121 | 120 | } |
122 | | - // Modules with dependencies but no group pass three arguments (name, timestamp, dependencies) |
123 | | - // to mediaWiki.loader.register() |
| 121 | + // Modules with dependencies but no group pass three arguments |
| 122 | + // (name, timestamp, dependencies) to mediaWiki.loader.register() |
124 | 123 | else if ( $module->getGroup() === null ) { |
125 | 124 | $registrations[] = array( |
126 | 125 | $name, $mtime, $module->getDependencies() ); |
— | — | @@ -163,11 +162,18 @@ |
164 | 163 | // Startup function |
165 | 164 | $configuration = FormatJson::encode( $this->getConfig( $context ) ); |
166 | 165 | $registrations = self::getModuleRegistrations( $context ); |
167 | | - $out .= "var startUp = function() {\n\t$registrations\n\tmediaWiki.config.set( $configuration );\n};"; |
| 166 | + $out .= "var startUp = function() {\n" . |
| 167 | + "\t$registrations\n" . |
| 168 | + "\tmediaWiki.config.set( $configuration );" . |
| 169 | + "\n};"; |
168 | 170 | |
169 | 171 | // Conditional script injection |
170 | | - $scriptTag = Xml::escapeJsString( Html::linkedScript( $wgLoadScript . '?' . wfArrayToCGI( $query ) ) ); |
171 | | - $out .= "if ( isCompatible() ) {\n\tdocument.write( '$scriptTag' );\n}\ndelete isCompatible;"; |
| 172 | + $scriptTag = Xml::escapeJsString( |
| 173 | + Html::linkedScript( $wgLoadScript . '?' . wfArrayToCGI( $query ) ) ); |
| 174 | + $out .= "if ( isCompatible() ) {\n" . |
| 175 | + "\tdocument.write( '$scriptTag' );\n" . |
| 176 | + "}\n" . |
| 177 | + "delete isCompatible;"; |
172 | 178 | } |
173 | 179 | |
174 | 180 | return $out; |
— | — | @@ -182,8 +188,9 @@ |
183 | 189 | } |
184 | 190 | $this->modifiedTime[$hash] = filemtime( "$IP/resources/startup.js" ); |
185 | 191 | |
186 | | - // ATTENTION!: Because of the line above, this is not going to cause infinite recursion - think carefully |
187 | | - // before making changes to this code! |
| 192 | + // ATTENTION!: Because of the line above, this is not going to cause |
| 193 | + // infinite recursion - think carefully before making changes to this |
| 194 | + // code! |
188 | 195 | $time = wfTimestamp( TS_UNIX, $wgCacheEpoch ); |
189 | 196 | foreach ( $context->getResourceLoader()->getModules() as $module ) { |
190 | 197 | $time = max( $time, $module->getModifiedTime( $context ) ); |