Merge "ForeignAPIRepo: Fetch thumb error from foreign repo"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 14c75e9..a3c3b10 100644 (file)
@@ -234,6 +234,7 @@ class ResourceLoader {
                foreach ( $registrations as $name => $info ) {
                        // Disallow duplicate registrations
                        if ( isset( $this->moduleInfos[$name] ) ) {
+                               wfProfileOut( __METHOD__ );
                                // A module has already been registered by this name
                                throw new MWException(
                                        'ResourceLoader duplicate registration error. ' .
@@ -243,6 +244,7 @@ class ResourceLoader {
 
                        // Check $name for validity
                        if ( !self::isValidModuleName( $name ) ) {
+                               wfProfileOut( __METHOD__ );
                                throw new MWException( "ResourceLoader module name '$name' is invalid, see ResourceLoader::isValidModuleName()" );
                        }
 
@@ -251,6 +253,7 @@ class ResourceLoader {
                                // Old calling convention
                                // Validate the input
                                if ( !( $info instanceof ResourceLoaderModule ) ) {
+                                       wfProfileOut( __METHOD__ );
                                        throw new MWException( 'ResourceLoader invalid module error. ' .
                                                'Instances of ResourceLoaderModule expected.' );
                                }
@@ -280,13 +283,13 @@ class ResourceLoader {
 
                // Get core test suites
                $testModules = array();
-               $testModules['qunit'] = include( "$IP/tests/qunit/QUnitTestResources.php" );
+               $testModules['qunit'] = include "$IP/tests/qunit/QUnitTestResources.php";
                // Get other test suites (e.g. from extensions)
                wfRunHooks( 'ResourceLoaderTestModules', array( &$testModules, &$this ) );
 
                // Add the testrunner (which configures QUnit) to the dependencies.
                // Since it must be ready before any of the test suites are executed.
-               foreach( $testModules['qunit'] as &$module ) {
+               foreach ( $testModules['qunit'] as &$module ) {
                        // Make sure all test modules are top-loading so that when QUnit starts
                        // on document-ready, it will run once and finish. If some tests arrive
                        // later (possibly after QUnit has already finished) they will be ignored.
@@ -294,7 +297,7 @@ class ResourceLoader {
                        $module['dependencies'][] = 'mediawiki.tests.qunit.testrunner';
                }
 
-               foreach( $testModules as $id => $names ) {
+               foreach ( $testModules as $id => $names ) {
                        // Register test modules
                        $this->register( $testModules[$id] );
 
@@ -315,7 +318,7 @@ class ResourceLoader {
         * @param array $properties source properties
         * @throws MWException
         */
-       public function addSource( $id, $properties = null) {
+       public function addSource( $id, $properties = null ) {
                // Allow multiple sources to be registered in one call
                if ( is_array( $id ) ) {
                        foreach ( $id as $key => $value ) {
@@ -361,7 +364,7 @@ class ResourceLoader {
         * @return Array
         */
        public function getTestModuleNames( $framework = 'all' ) {
-               /// @TODO: api siteinfo prop testmodulenames modulenames
+               /// @todo api siteinfo prop testmodulenames modulenames
                if ( $framework == 'all' ) {
                        return $this->testModuleNames;
                } elseif ( isset( $this->testModuleNames[$framework] ) && is_array( $this->testModuleNames[$framework] ) ) {
@@ -463,13 +466,13 @@ class ResourceLoader {
                // Preload information needed to the mtime calculation below
                try {
                        $this->preloadModuleInfo( array_keys( $modules ), $context );
-               } catch( Exception $e ) {
+               } catch ( Exception $e ) {
                        // Add exception to the output as a comment
                        $errors .= $this->makeComment( $e->__toString() );
                        $this->hasErrors = true;
                }
 
-               wfProfileIn( __METHOD__.'-getModifiedTime' );
+               wfProfileIn( __METHOD__ . '-getModifiedTime' );
 
                // To send Last-Modified and support If-Modified-Since, we need to detect
                // the last modified time
@@ -488,7 +491,7 @@ class ResourceLoader {
                        }
                }
 
-               wfProfileOut( __METHOD__.'-getModifiedTime' );
+               wfProfileOut( __METHOD__ . '-getModifiedTime' );
 
                // If there's an If-Modified-Since header, respond with a 304 appropriately
                if ( $this->tryRespondLastModified( $context, $mtime ) ) {
@@ -598,7 +601,9 @@ class ResourceLoader {
                                // no matter how often we call ob_get_clean(), so instead of doing
                                // the more intuitive while ( ob_get_level() > 0 ) ob_get_clean();
                                // we have to be safe here and avoid an infinite loop.
-                               for ( $i = 0, $len = ob_get_level(); $i < $len; $i++ ) {
+                               // Caching the level is not an option, need to allow it to
+                               // shorten the loop on-the-fly (bug 46836)
+                               for ( $i = 0; $i < ob_get_level(); $i++ ) {
                                        ob_end_clean();
                                }
 
@@ -632,7 +637,7 @@ class ResourceLoader {
                if ( !$good ) {
                        try { // RL always hits the DB on file cache miss...
                                wfGetDB( DB_SLAVE );
-                       } catch( DBConnectionError $e ) { // ...check if we need to fallback to cache
+                       } catch ( DBConnectionError $e ) { // ...check if we need to fallback to cache
                                $good = $fileCache->isCacheGood(); // cache existence check
                        }
                }
@@ -909,7 +914,7 @@ class ResourceLoader {
 
                                        if ( $media === '' || $media == 'all' ) {
                                                $out[] = $style;
-                                       } else if ( is_string( $media ) ) {
+                                       } elseif ( is_string( $media ) ) {
                                                $out[] = "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "}";
                                        }
                                        // else: skip