| Index: trunk/phase3/includes/ResourceLoaderContext.php |
| — | — | @@ -20,7 +20,8 @@ |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | | - * Object passed around to modules which contains information about the state of a specific loader request |
| | 24 | + * Object passed around to modules which contains information about the state |
| | 25 | + * of a specific loader request |
| 25 | 26 | */ |
| 26 | 27 | class ResourceLoaderContext { |
| 27 | 28 | /* Protected Members */ |
| — | — | @@ -115,9 +116,12 @@ |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | 119 | public function getHash() { |
| 119 | | - return isset( $this->hash ) ? |
| 120 | | - $this->hash : $this->hash = implode( '|', array( |
| 121 | | - $this->language, $this->direction, $this->skin, $this->user, $this->debug, $this->only, $this->version |
| | 120 | + if ( isset( $this->hash ) ) { |
| | 121 | + $this->hash = implode( '|', array( |
| | 122 | + $this->language, $this->direction, $this->skin, $this->user, |
| | 123 | + $this->debug, $this->only, $this->version |
| 122 | 124 | ) ); |
| | 125 | + } |
| | 126 | + return $this->hash; |
| 123 | 127 | } |
| 124 | | -} |
| \ No newline at end of file |
| | 128 | +} |
| Index: trunk/phase3/includes/OutputPage.php |
| — | — | @@ -2325,9 +2325,9 @@ |
| 2326 | 2326 | ksort( $query ); |
| 2327 | 2327 | // Automatically select style/script elements |
| 2328 | 2328 | if ( $only === 'styles' ) { |
| 2329 | | - $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ); |
| | 2329 | + $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ) . "\n"; |
| 2330 | 2330 | } else { |
| 2331 | | - $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ); |
| | 2331 | + $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ) . "\n"; |
| 2332 | 2332 | } |
| 2333 | 2333 | } |
| 2334 | 2334 | } |
| — | — | @@ -2378,8 +2378,8 @@ |
| 2379 | 2379 | if ( $this->getModules() ) { |
| 2380 | 2380 | $modules = FormatJson::encode( $this->getModules() ); |
| 2381 | 2381 | $scripts .= Html::inlineScript( |
| 2382 | | - "if ( mediaWiki !== undefined ) { mediaWiki.loader.load( {$modules} ); mediaWiki.loader.go(); }" |
| 2383 | | - ); |
| | 2382 | + "if ( mediaWiki !== undefined ) { mediaWiki.loader.load( {$modules} ); mediaWiki.loader.go(); }\n" |
| | 2383 | + ) . "\n"; |
| 2384 | 2384 | } |
| 2385 | 2385 | |
| 2386 | 2386 | // Add user JS if enabled - trying to load user.options as a bundle if possible |
| Index: trunk/phase3/includes/ResourceLoader.php |
| — | — | @@ -41,10 +41,13 @@ |
| 42 | 42 | |
| 43 | 43 | // Safety check - this should never be called more than once |
| 44 | 44 | if ( !self::$initialized ) { |
| 45 | | - // This needs to be first, because hooks might call ResourceLoader public interfaces which will call this |
| | 45 | + wfProfileIn( __METHOD__ ); |
| | 46 | + // This needs to be first, because hooks might call ResourceLoader |
| | 47 | + // public interfaces which will call this |
| 46 | 48 | self::$initialized = true; |
| 47 | 49 | self::register( include( "$IP/resources/Resources.php" ) ); |
| 48 | 50 | wfRunHooks( 'ResourceLoaderRegisterModules' ); |
| | 51 | + wfProfileOut( __METHOD__ ); |
| 49 | 52 | } |
| 50 | 53 | } |
| 51 | 54 | |
| — | — | @@ -53,14 +56,17 @@ |
| 54 | 57 | * |
| 55 | 58 | * @param $filter String: name of filter to run |
| 56 | 59 | * @param $data String: text to filter, such as JavaScript or CSS text |
| 57 | | - * @param $file String: path to file being filtered, (optional: only required for CSS to resolve paths) |
| | 60 | + * @param $file String: path to file being filtered, (optional: only required |
| | 61 | + * for CSS to resolve paths) |
| 58 | 62 | * @return String: filtered data |
| 59 | 63 | */ |
| 60 | 64 | protected static function filter( $filter, $data ) { |
| 61 | 65 | global $wgMemc; |
| | 66 | + wfProfileIn( __METHOD__ ); |
| 62 | 67 | |
| 63 | 68 | // For empty or whitespace-only things, don't do any processing |
| 64 | 69 | if ( trim( $data ) === '' ) { |
| | 70 | + wfProfileOut( __METHOD__ ); |
| 65 | 71 | return $data; |
| 66 | 72 | } |
| 67 | 73 | |
| — | — | @@ -69,6 +75,7 @@ |
| 70 | 76 | $cached = $wgMemc->get( $key ); |
| 71 | 77 | |
| 72 | 78 | if ( $cached !== false && $cached !== null ) { |
| | 79 | + wfProfileOut( __METHOD__ ); |
| 73 | 80 | return $cached; |
| 74 | 81 | } |
| 75 | 82 | |
| — | — | @@ -86,6 +93,7 @@ |
| 87 | 94 | break; |
| 88 | 95 | default: |
| 89 | 96 | // Don't cache anything, just pass right through |
| | 97 | + wfProfileOut( __METHOD__ ); |
| 90 | 98 | return $data; |
| 91 | 99 | } |
| 92 | 100 | } catch ( Exception $exception ) { |
| — | — | @@ -95,6 +103,7 @@ |
| 96 | 104 | // Save to memcached |
| 97 | 105 | $wgMemc->set( $key, $result ); |
| 98 | 106 | |
| | 107 | + wfProfileOut( __METHOD__ ); |
| 99 | 108 | return $result; |
| 100 | 109 | } |
| 101 | 110 | |
| — | — | @@ -103,18 +112,21 @@ |
| 104 | 113 | /** |
| 105 | 114 | * Registers a module with the ResourceLoader system. |
| 106 | 115 | * |
| 107 | | - * Note that registering the same object under multiple names is not supported and may silently fail in all |
| 108 | | - * kinds of interesting ways. |
| | 116 | + * Note that registering the same object under multiple names is not supported |
| | 117 | + * and may silently fail in all kinds of interesting ways. |
| 109 | 118 | * |
| 110 | 119 | * @param $name Mixed: string of name of module or array of name/object pairs |
| 111 | | - * @param $object ResourceLoaderModule: module object (optional when using multiple-registration calling style) |
| 112 | | - * @return Boolean: false if there were any errors, in which case one or more modules were not registered |
| | 120 | + * @param $object ResourceLoaderModule: module object (optional when using |
| | 121 | + * multiple-registration calling style) |
| | 122 | + * @return Boolean: false if there were any errors, in which case one or more |
| | 123 | + * modules were not registered |
| 113 | 124 | * |
| 114 | | - * @todo We need much more clever error reporting, not just in detailing what happened, but in bringing errors to |
| 115 | | - * the client in a way that they can easily see them if they want to, such as by using FireBug |
| | 125 | + * @todo We need much more clever error reporting, not just in detailing what |
| | 126 | + * happened, but in bringing errors to the client in a way that they can |
| | 127 | + * easily see them if they want to, such as by using FireBug |
| 116 | 128 | */ |
| 117 | 129 | public static function register( $name, ResourceLoaderModule $object = null ) { |
| 118 | | - |
| | 130 | + wfProfileIn( __METHOD__ ); |
| 119 | 131 | self::initialize(); |
| 120 | 132 | |
| 121 | 133 | // Allow multiple modules to be registered in one call |
| — | — | @@ -123,6 +135,7 @@ |
| 124 | 136 | self::register( $key, $value ); |
| 125 | 137 | } |
| 126 | 138 | |
| | 139 | + wfProfileOut( __METHOD__ ); |
| 127 | 140 | return; |
| 128 | 141 | } |
| 129 | 142 | |
| — | — | @@ -134,6 +147,7 @@ |
| 135 | 148 | // Attach module |
| 136 | 149 | self::$modules[$name] = $object; |
| 137 | 150 | $object->setName( $name ); |
| | 151 | + wfProfileOut( __METHOD__ ); |
| 138 | 152 | } |
| 139 | 153 | |
| 140 | 154 | /** |
| — | — | @@ -162,13 +176,14 @@ |
| 163 | 177 | } |
| 164 | 178 | |
| 165 | 179 | /** |
| 166 | | - * Gets registration code for all modules, except pre-registered ones listed in self::$preRegisteredModules |
| | 180 | + * Gets registration code for all modules, except pre-registered ones listed in |
| | 181 | + * self::$preRegisteredModules |
| 167 | 182 | * |
| 168 | 183 | * @param $context ResourceLoaderContext object |
| 169 | 184 | * @return String: JavaScript code for registering all modules with the client loader |
| 170 | 185 | */ |
| 171 | 186 | public static function getModuleRegistrations( ResourceLoaderContext $context ) { |
| 172 | | - |
| | 187 | + wfProfileIn( __METHOD__ ); |
| 173 | 188 | self::initialize(); |
| 174 | 189 | |
| 175 | 190 | $scripts = ''; |
| — | — | @@ -178,27 +193,34 @@ |
| 179 | 194 | // Support module loader scripts |
| 180 | 195 | if ( ( $loader = $module->getLoaderScript() ) !== false ) { |
| 181 | 196 | $deps = FormatJson::encode( $module->getDependencies() ); |
| 182 | | - $version = wfTimestamp( TS_ISO_8601, round( $module->getModifiedTime( $context ), -2 ) ); |
| 183 | | - $scripts .= "( function( name, version, dependencies ) { $loader } )( '$name', '$version', $deps );"; |
| | 197 | + $version = wfTimestamp( TS_ISO_8601, |
| | 198 | + round( $module->getModifiedTime( $context ), -2 ) ); |
| | 199 | + $scripts .= "( function( name, version, dependencies ) { $loader } )\n" . |
| | 200 | + "( '$name', '$version', $deps );\n"; |
| 184 | 201 | } |
| 185 | 202 | // Automatically register module |
| 186 | 203 | else { |
| 187 | | - // Modules without dependencies pass two arguments (name, timestamp) to mediaWiki.loader.register() |
| | 204 | + // Modules without dependencies pass two arguments (name, timestamp) to |
| | 205 | + // mediaWiki.loader.register() |
| 188 | 206 | if ( !count( $module->getDependencies() ) ) { |
| 189 | 207 | $registrations[] = array( $name, $module->getModifiedTime( $context ) ); |
| 190 | 208 | } |
| 191 | | - // Modules with dependencies pass three arguments (name, timestamp, dependencies) to mediaWiki.loader.register() |
| | 209 | + // Modules with dependencies pass three arguments (name, timestamp, dependencies) |
| | 210 | + // to mediaWiki.loader.register() |
| 192 | 211 | else { |
| 193 | | - $registrations[] = array( $name, $module->getModifiedTime( $context ), $module->getDependencies() ); |
| | 212 | + $registrations[] = array( $name, $module->getModifiedTime( $context ), |
| | 213 | + $module->getDependencies() ); |
| 194 | 214 | } |
| 195 | 215 | } |
| 196 | 216 | } |
| 197 | | - return $scripts . "mediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );"; |
| | 217 | + $out = $scripts . "mediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );\n"; |
| | 218 | + wfProfileOut( __METHOD__ ); |
| | 219 | + return $out; |
| 198 | 220 | } |
| 199 | 221 | |
| 200 | 222 | /** |
| 201 | | - * Get the highest modification time of all modules, based on a given combination of language code, |
| 202 | | - * skin name and debug mode flag. |
| | 223 | + * Get the highest modification time of all modules, based on a given |
| | 224 | + * combination of language code, skin name and debug mode flag. |
| 203 | 225 | * |
| 204 | 226 | * @param $context ResourceLoaderContext object |
| 205 | 227 | * @return Integer: UNIX timestamp |
| — | — | @@ -225,6 +247,7 @@ |
| 226 | 248 | global $wgResourceLoaderVersionedClientMaxage, $wgResourceLoaderVersionedServerMaxage; |
| 227 | 249 | global $wgResourceLoaderUnversionedServerMaxage, $wgResourceLoaderUnversionedClientMaxage; |
| 228 | 250 | |
| | 251 | + wfProfileIn( __METHOD__ ); |
| 229 | 252 | self::initialize(); |
| 230 | 253 | |
| 231 | 254 | // Split requested modules into two groups, modules and missing |
| — | — | @@ -239,22 +262,27 @@ |
| 240 | 263 | } |
| 241 | 264 | } |
| 242 | 265 | |
| 243 | | - // If a version wasn't specified we need a shorter expiry time for updates to propagate to clients quickly |
| | 266 | + // If a version wasn't specified we need a shorter expiry time for updates to |
| | 267 | + // propagate to clients quickly |
| 244 | 268 | if ( is_null( $context->getVersion() ) ) { |
| 245 | 269 | $maxage = $wgResourceLoaderUnversionedClientMaxage; |
| 246 | 270 | $smaxage = $wgResourceLoaderUnversionedServerMaxage; |
| 247 | 271 | } |
| 248 | | - // If a version was specified we can use a longer expiry time since changing version numbers causes cache misses |
| | 272 | + // If a version was specified we can use a longer expiry time since changing |
| | 273 | + // version numbers causes cache misses |
| 249 | 274 | else { |
| 250 | 275 | $maxage = $wgResourceLoaderVersionedClientMaxage; |
| 251 | 276 | $smaxage = $wgResourceLoaderVersionedServerMaxage; |
| 252 | 277 | } |
| 253 | 278 | |
| 254 | | - // To send Last-Modified and support If-Modified-Since, we need to detect the last modified time |
| | 279 | + // To send Last-Modified and support If-Modified-Since, we need to detect |
| | 280 | + // the last modified time |
| | 281 | + wfProfileIn( __METHOD__.'-getModifiedTime' ); |
| 255 | 282 | $mtime = 1; |
| 256 | 283 | foreach ( $modules as $name ) { |
| 257 | 284 | $mtime = max( $mtime, self::$modules[$name]->getModifiedTime( $context ) ); |
| 258 | 285 | } |
| | 286 | + wfProfileOut( __METHOD__.'-getModifiedTime' ); |
| 259 | 287 | |
| 260 | 288 | header( 'Content-Type: ' . ( $context->getOnly() === 'styles' ? 'text/css' : 'text/javascript' ) ); |
| 261 | 289 | header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) ); |
| — | — | @@ -266,6 +294,7 @@ |
| 267 | 295 | if ( $ims !== false && $mtime >= wfTimestamp( TS_UNIX, $ims ) ) { |
| 268 | 296 | header( 'HTTP/1.0 304 Not Modified' ); |
| 269 | 297 | header( 'Status: 304 Not Modified' ); |
| | 298 | + wfProfileOut( __METHOD__ ); |
| 270 | 299 | return; |
| 271 | 300 | } |
| 272 | 301 | |
| — | — | @@ -278,18 +307,20 @@ |
| 279 | 308 | |
| 280 | 309 | // Generate output |
| 281 | 310 | foreach ( $modules as $name ) { |
| | 311 | + wfProfileIn( __METHOD__ . '-' . $name ); |
| 282 | 312 | // Scripts |
| 283 | 313 | $scripts = ''; |
| 284 | 314 | |
| 285 | 315 | if ( $context->shouldIncludeScripts() ) { |
| 286 | | - $scripts .= self::$modules[$name]->getScript( $context ); |
| | 316 | + $scripts .= self::$modules[$name]->getScript( $context ) . "\n"; |
| 287 | 317 | } |
| 288 | 318 | |
| 289 | 319 | // Styles |
| 290 | 320 | $styles = array(); |
| 291 | 321 | |
| 292 | 322 | if ( |
| 293 | | - $context->shouldIncludeStyles() && ( count( $styles = self::$modules[$name]->getStyles( $context ) ) ) |
| | 323 | + $context->shouldIncludeStyles() |
| | 324 | + && ( count( $styles = self::$modules[$name]->getStyles( $context ) ) ) |
| 294 | 325 | ) { |
| 295 | 326 | foreach ( $styles as $media => $style ) { |
| 296 | 327 | if ( self::$modules[$name]->getFlip( $context ) ) { |
| — | — | @@ -330,6 +361,7 @@ |
| 331 | 362 | } |
| 332 | 363 | echo "mediaWiki.loader.implement( '$name', function() {{$scripts}},\n$styles,\n$messages );\n"; |
| 333 | 364 | } |
| | 365 | + wfProfileOut( __METHOD__ . '-' . $name ); |
| 334 | 366 | } |
| 335 | 367 | |
| 336 | 368 | // Update the status of script-only modules |
| — | — | @@ -359,5 +391,6 @@ |
| 360 | 392 | echo self::filter( 'minify-js', ob_get_clean() ); |
| 361 | 393 | } |
| 362 | 394 | } |
| | 395 | + wfProfileOut( __METHOD__ ); |
| 363 | 396 | } |
| 364 | | -} |
| \ No newline at end of file |
| | 397 | +} |
| Index: trunk/phase3/includes/MessageBlobStore.php |
| — | — | @@ -37,7 +37,9 @@ |
| 38 | 38 | */ |
| 39 | 39 | public static function get( $modules, $lang ) { |
| 40 | 40 | // TODO: Invalidate blob when module touched |
| | 41 | + wfProfileIn( __METHOD__ ); |
| 41 | 42 | if ( !count( $modules ) ) { |
| | 43 | + wfProfileOut( __METHOD__ ); |
| 42 | 44 | return array(); |
| 43 | 45 | } |
| 44 | 46 | // Try getting from the DB first |
| — | — | @@ -52,6 +54,7 @@ |
| 53 | 55 | } |
| 54 | 56 | } |
| 55 | 57 | |
| | 58 | + wfProfileOut( __METHOD__ ); |
| 56 | 59 | return $blobs; |
| 57 | 60 | } |
| 58 | 61 | |
| — | — | @@ -115,7 +118,8 @@ |
| 116 | 119 | * Update all message blobs for a given module. |
| 117 | 120 | * @param $module string Module name |
| 118 | 121 | * @param $lang string Language code (optional) |
| 119 | | - * @return mixed If $lang is set, the new message blob for that language is returned if present. Otherwise, null is returned. |
| | 122 | + * @return mixed If $lang is set, the new message blob for that language is |
| | 123 | + * returned if present. Otherwise, null is returned. |
| 120 | 124 | */ |
| 121 | 125 | public static function updateModule( $module, $lang = null ) { |
| 122 | 126 | $retval = null; |
| Index: trunk/phase3/includes/ResourceLoaderModule.php |
| — | — | @@ -380,7 +380,7 @@ |
| 381 | 381 | // Only store if modified |
| 382 | 382 | if ( $files !== $this->getFileDependencies( $context->getSkin() ) ) { |
| 383 | 383 | $encFiles = FormatJson::encode( $files ); |
| 384 | | - $dbw = wfGetDb( DB_MASTER ); |
| | 384 | + $dbw = wfGetDB( DB_MASTER ); |
| 385 | 385 | $dbw->replace( 'module_deps', |
| 386 | 386 | array( array( 'md_module', 'md_skin' ) ), array( |
| 387 | 387 | 'md_module' => $this->getName(), |
| — | — | @@ -430,6 +430,7 @@ |
| 431 | 431 | if ( isset( $this->modifiedTime[$context->getHash()] ) ) { |
| 432 | 432 | return $this->modifiedTime[$context->getHash()]; |
| 433 | 433 | } |
| | 434 | + wfProfileIn( __METHOD__ ); |
| 434 | 435 | |
| 435 | 436 | // Sort of nasty way we can get a flat list of files depended on by all styles |
| 436 | 437 | $styles = array(); |
| — | — | @@ -454,13 +455,16 @@ |
| 455 | 456 | $this->loaders, |
| 456 | 457 | $this->getFileDependencies( $context->getSkin() ) |
| 457 | 458 | ); |
| | 459 | + wfProfileIn( __METHOD__.'-filemtime' ); |
| 458 | 460 | $filesMtime = max( array_map( 'filemtime', array_map( array( __CLASS__, 'remapFilename' ), $files ) ) ); |
| | 461 | + wfProfileOut( __METHOD__.'-filemtime' ); |
| 459 | 462 | // Only get the message timestamp if there are messages in the module |
| 460 | 463 | $msgBlobMtime = 0; |
| 461 | 464 | if ( count( $this->messages ) ) { |
| 462 | 465 | // Get the mtime of the message blob |
| 463 | | - // TODO: This timestamp is queried a lot and queried separately for each module. Maybe it should be put in memcached? |
| 464 | | - $dbr = wfGetDb( DB_SLAVE ); |
| | 466 | + // TODO: This timestamp is queried a lot and queried separately for each module. |
| | 467 | + // Maybe it should be put in memcached? |
| | 468 | + $dbr = wfGetDB( DB_SLAVE ); |
| 465 | 469 | $msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array( |
| 466 | 470 | 'mr_resource' => $this->getName(), |
| 467 | 471 | 'mr_lang' => $context->getLanguage() |
| — | — | @@ -469,6 +473,7 @@ |
| 470 | 474 | $msgBlobMtime = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0; |
| 471 | 475 | } |
| 472 | 476 | $this->modifiedTime[$context->getHash()] = max( $filesMtime, $msgBlobMtime ); |
| | 477 | + wfProfileOut( __METHOD__ ); |
| 473 | 478 | return $this->modifiedTime[$context->getHash()]; |
| 474 | 479 | } |
| 475 | 480 | |
| — | — | @@ -576,7 +581,7 @@ |
| 577 | 582 | $deps = $wgMemc->get( $key ); |
| 578 | 583 | |
| 579 | 584 | if ( !$deps ) { |
| 580 | | - $dbr = wfGetDb( DB_SLAVE ); |
| | 585 | + $dbr = wfGetDB( DB_SLAVE ); |
| 581 | 586 | $deps = $dbr->selectField( 'module_deps', 'md_deps', array( |
| 582 | 587 | 'md_module' => $this->getName(), |
| 583 | 588 | 'md_skin' => $skin, |
| — | — | @@ -601,7 +606,12 @@ |
| 602 | 607 | * @return String: concatenated contents of $files |
| 603 | 608 | */ |
| 604 | 609 | protected static function concatScripts( $files ) { |
| 605 | | - return implode( "\n", array_map( 'file_get_contents', array_map( array( __CLASS__, 'remapFilename' ), array_unique( (array) $files ) ) ) ); |
| | 610 | + return implode( "\n", |
| | 611 | + array_map( |
| | 612 | + 'file_get_contents', |
| | 613 | + array_map( |
| | 614 | + array( __CLASS__, 'remapFilename' ), |
| | 615 | + array_unique( (array) $files ) ) ) ); |
| 606 | 616 | } |
| 607 | 617 | |
| 608 | 618 | protected static function organizeFilesByOption( $files, $option, $default ) { |
| — | — | @@ -636,7 +646,10 @@ |
| 637 | 647 | $styles = self::organizeFilesByOption( $styles, 'media', 'all' ); |
| 638 | 648 | foreach ( $styles as $media => $files ) { |
| 639 | 649 | $styles[$media] = |
| 640 | | - implode( "\n", array_map( array( __CLASS__, 'remapStyle' ), array_unique( (array) $files ) ) ); |
| | 650 | + implode( "\n", |
| | 651 | + array_map( |
| | 652 | + array( __CLASS__, 'remapStyle' ), |
| | 653 | + array_unique( (array) $files ) ) ); |
| 641 | 654 | } |
| 642 | 655 | return $styles; |
| 643 | 656 | } |
| — | — | @@ -841,7 +854,11 @@ |
| 842 | 855 | |
| 843 | 856 | public function getScript( ResourceLoaderContext $context ) { |
| 844 | 857 | $user = User::newFromName( $context->getUser() ); |
| 845 | | - $options = FormatJson::encode( $user instanceof User ? $user->getOptions() : User::getDefaultOptions() ); |
| | 858 | + if ( $user instanceof User ) { |
| | 859 | + $options = FormatJson::encode( $user->getOptions() ); |
| | 860 | + } else { |
| | 861 | + $options = FormatJson::encode( User::getDefaultOptions() ); |
| | 862 | + } |
| 846 | 863 | return "mediaWiki.user.options.set( $options );"; |
| 847 | 864 | } |
| 848 | 865 | |
| — | — | @@ -894,9 +911,11 @@ |
| 895 | 912 | /* Protected Methods */ |
| 896 | 913 | |
| 897 | 914 | protected function getConfig( $context ) { |
| 898 | | - global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, |
| 899 | | - $wgContLang, $wgBreakFrames, $wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgVersion, |
| 900 | | - $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest, $wgSitename, $wgFileExtensions; |
| | 915 | + global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, |
| | 916 | + $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgBreakFrames, |
| | 917 | + $wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgVersion, |
| | 918 | + $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest, |
| | 919 | + $wgSitename, $wgFileExtensions; |
| 901 | 920 | |
| 902 | 921 | // Pre-process information |
| 903 | 922 | $separatorTransTable = $wgContLang->separatorTransformTable(); |
| — | — | @@ -965,7 +984,12 @@ |
| 966 | 985 | // Build configuration |
| 967 | 986 | $config = FormatJson::encode( $this->getConfig( $context ) ); |
| 968 | 987 | // Add a well-known start-up function |
| 969 | | - $scripts .= "window.startUp = function() { $registration mediaWiki.config.set( $config ); };"; |
| | 988 | + $scripts .= <<<JAVASCRIPT |
| | 989 | +window.startUp = function() { |
| | 990 | + $registration |
| | 991 | + mediaWiki.config.set( $config ); |
| | 992 | +}; |
| | 993 | +JAVASCRIPT; |
| 970 | 994 | // Build load query for jquery and mediawiki modules |
| 971 | 995 | $query = array( |
| 972 | 996 | 'modules' => implode( '|', array( 'jquery', 'mediawiki' ) ), |
| — | — | @@ -983,9 +1007,9 @@ |
| 984 | 1008 | // Build HTML code for loading jquery and mediawiki modules |
| 985 | 1009 | $loadScript = Html::linkedScript( $wgLoadScript . '?' . wfArrayToCGI( $query ) ); |
| 986 | 1010 | // Add code to add jquery and mediawiki loading code; only if the current client is compatible |
| 987 | | - $scripts .= "if ( isCompatible() ) { document.write( '$loadScript' ); }"; |
| | 1011 | + $scripts .= "if ( isCompatible() ) { document.write( " . FormatJson::encode( $loadScript ) . "); }\n"; |
| 988 | 1012 | // Delete the compatible function - it's not needed anymore |
| 989 | | - $scripts .= "delete window['isCompatible'];"; |
| | 1013 | + $scripts .= "delete window['isCompatible'];\n"; |
| 990 | 1014 | } |
| 991 | 1015 | |
| 992 | 1016 | return $scripts; |