Index: trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php |
— | — | @@ -241,6 +241,10 @@ |
242 | 242 | return $out; |
243 | 243 | } |
244 | 244 | |
| 245 | + public function supportsURLLoading() { |
| 246 | + return false; |
| 247 | + } |
| 248 | + |
245 | 249 | /** |
246 | 250 | * @param $context ResourceLoaderContext |
247 | 251 | * @return array|mixed |
Index: trunk/phase3/includes/resourceloader/ResourceLoader.php |
— | — | @@ -529,17 +529,31 @@ |
530 | 530 | try { |
531 | 531 | $scripts = ''; |
532 | 532 | if ( $context->shouldIncludeScripts() ) { |
533 | | - $scripts = $module->getScript( $context ); |
534 | | - if ( is_string( $scripts ) ) { |
535 | | - // bug 27054: Append semicolon to prevent weird bugs |
536 | | - // caused by files not terminating their statements right |
537 | | - $scripts .= ";\n"; |
| 533 | + // If we are in debug mode, we'll want to return an array of URLs if possible |
| 534 | + // However, we can't do this if the module doesn't support it |
| 535 | + // We also can't do this if there is an only= parameter, because we have to give |
| 536 | + // the module a way to return a load.php URL without causing an infinite loop |
| 537 | + if ( $context->getDebug() && !$context->getOnly() && $module->supportsURLLoading() ) { |
| 538 | + $scripts = $module->getScriptURLsForDebug( $context ); |
| 539 | + } else { |
| 540 | + $scripts = $module->getScript( $context ); |
| 541 | + if ( is_string( $scripts ) ) { |
| 542 | + // bug 27054: Append semicolon to prevent weird bugs |
| 543 | + // caused by files not terminating their statements right |
| 544 | + $scripts .= ";\n"; |
| 545 | + } |
538 | 546 | } |
539 | 547 | } |
540 | 548 | // Styles |
541 | 549 | $styles = array(); |
542 | 550 | if ( $context->shouldIncludeStyles() ) { |
543 | | - $styles = $module->getStyles( $context ); |
| 551 | + // If we are in debug mode, we'll want to return an array of URLs |
| 552 | + // See comment near shouldIncludeScripts() for more details |
| 553 | + if ( $context->getDebug() && !$context->getOnly() && $module->supportsURLLoading() ) { |
| 554 | + $styles = $module->getStyleURLsForDebug( $context ); |
| 555 | + } else { |
| 556 | + $styles = $module->getStyles( $context ); |
| 557 | + } |
544 | 558 | } |
545 | 559 | |
546 | 560 | // Messages |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php |
— | — | @@ -217,16 +217,21 @@ |
218 | 218 | */ |
219 | 219 | public function getScript( ResourceLoaderContext $context ) { |
220 | 220 | $files = $this->getScriptFiles( $context ); |
221 | | - if ( $context->getDebug() && $this->debugRaw ) { |
222 | | - $urls = array(); |
223 | | - foreach ( $this->getScriptFiles( $context ) as $file ) { |
224 | | - $urls[] = $this->getRemotePath( $file ); |
225 | | - } |
226 | | - return $urls; |
227 | | - } |
228 | 221 | return $this->readScriptFiles( $files ); |
229 | 222 | } |
| 223 | + |
| 224 | + public function getScriptURLsForDebug( ResourceLoaderContext $context ) { |
| 225 | + $urls = array(); |
| 226 | + foreach ( $this->getScriptFiles( $context ) as $file ) { |
| 227 | + $urls[] = $this->getRemotePath( $file ); |
| 228 | + } |
| 229 | + return $urls; |
| 230 | + } |
230 | 231 | |
| 232 | + public function supportsURLLoading() { |
| 233 | + return $this->debugRaw; |
| 234 | + } |
| 235 | + |
231 | 236 | /** |
232 | 237 | * Gets loader script. |
233 | 238 | * |
— | — | @@ -250,16 +255,6 @@ |
251 | 256 | $this->getStyleFiles( $context ), |
252 | 257 | $this->getFlip( $context ) |
253 | 258 | ); |
254 | | - if ( !$context->getOnly() && $context->getDebug() && $this->debugRaw ) { |
255 | | - $urls = array(); |
256 | | - foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) { |
257 | | - $urls[$mediaType] = array(); |
258 | | - foreach ( $list as $file ) { |
259 | | - $urls[$mediaType][] = $this->getRemotePath( $file ); |
260 | | - } |
261 | | - } |
262 | | - return $urls; |
263 | | - } |
264 | 259 | // Collect referenced files |
265 | 260 | $this->localFileRefs = array_unique( $this->localFileRefs ); |
266 | 261 | // If the list has been modified since last time we cached it, update the cache |
— | — | @@ -276,6 +271,17 @@ |
277 | 272 | return $styles; |
278 | 273 | } |
279 | 274 | |
| 275 | + public function getStyleURLsForDebug( ResourceLoaderContext $context ) { |
| 276 | + $urls = array(); |
| 277 | + foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) { |
| 278 | + $urls[$mediaType] = array(); |
| 279 | + foreach ( $list as $file ) { |
| 280 | + $urls[$mediaType][] = $this->getRemotePath( $file ); |
| 281 | + } |
| 282 | + } |
| 283 | + return $urls; |
| 284 | + } |
| 285 | + |
280 | 286 | /** |
281 | 287 | * Gets list of message keys used by this module. |
282 | 288 | * |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderModule.php |
— | — | @@ -126,6 +126,44 @@ |
127 | 127 | // Stub, override expected |
128 | 128 | return ''; |
129 | 129 | } |
| 130 | + |
| 131 | + /** |
| 132 | + * Get the URL or URLs to load for this module's JS in debug mode. |
| 133 | + * The default behavior is to return a load.php?only=scripts URL for |
| 134 | + * the module, but file-based modules will want to override this to |
| 135 | + * load the files directly. |
| 136 | + * |
| 137 | + * This function is called only when 1) we're in debug mode, 2) there |
| 138 | + * is no only= parameter and 3) supportsURLLoading() returns true. |
| 139 | + * #2 is important to prevent an infinite loop, therefore this function |
| 140 | + * MUST return either an only= URL or a non-load.php URL. |
| 141 | + * |
| 142 | + * @param $context ResourceLoaderContext: Context object |
| 143 | + * @return Array of URLs |
| 144 | + */ |
| 145 | + public function getScriptURLsForDebug( ResourceLoaderContext $context ) { |
| 146 | + global $wgLoadScript; // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink() |
| 147 | + $query = array( |
| 148 | + 'modules' => $this->getName(), |
| 149 | + 'only' => 'scripts', |
| 150 | + 'skin' => $context->getSkin(), |
| 151 | + 'user' => $context->getUser(), |
| 152 | + 'debug' => 'true', |
| 153 | + 'version' => $context->getVersion() |
| 154 | + ); |
| 155 | + ksort( $query ); |
| 156 | + return array( wfAppendQuery( $wgLoadScript, $query ) . '&*' ); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Whether this module supports URL loading. If this function returns false, |
| 161 | + * getScript() will be used even in cases (debug mode, no only param) where |
| 162 | + * getScriptURLsForDebug() would normally be used instead. |
| 163 | + * @return bool |
| 164 | + */ |
| 165 | + public function supportsURLLoading() { |
| 166 | + return true; |
| 167 | + } |
130 | 168 | |
131 | 169 | /** |
132 | 170 | * Get all CSS for this module for a given skin. |
— | — | @@ -137,6 +175,29 @@ |
138 | 176 | // Stub, override expected |
139 | 177 | return array(); |
140 | 178 | } |
| 179 | + |
| 180 | + /** |
| 181 | + * Get the URL or URLs to load for this module's CSS in debug mode. |
| 182 | + * The default behavior is to return a load.php?only=styles URL for |
| 183 | + * the module, but file-based modules will want to override this to |
| 184 | + * load the files directly. See also getScriptURLsForDebug() |
| 185 | + * |
| 186 | + * @param $context ResourceLoaderContext: Context object |
| 187 | + * @return Array: array( mediaType => array( URL1, URL2, ... ), ... ) |
| 188 | + */ |
| 189 | + public function getStyleURLsForDebug( ResourceLoaderContext $context ) { |
| 190 | + global $wgLoadScript; // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink() |
| 191 | + $query = array( |
| 192 | + 'modules' => $this->getName(), |
| 193 | + 'only' => 'styles', |
| 194 | + 'skin' => $context->getSkin(), |
| 195 | + 'user' => $context->getUser(), |
| 196 | + 'debug' => 'true', |
| 197 | + 'version' => $context->getVersion() |
| 198 | + ); |
| 199 | + ksort( $query ); |
| 200 | + return array( 'all' => array( wfAppendQuery( $wgLoadScript, $query ) . '&*' ) ); |
| 201 | + } |
141 | 202 | |
142 | 203 | /** |
143 | 204 | * Get the messages needed for this module. |