registration: Prevent loading the same thing twice
authorKunal Mehta <legoktm@member.fsf.org>
Wed, 30 Dec 2015 01:52:11 +0000 (17:52 -0800)
committerKunal Mehta <legoktm@member.fsf.org>
Wed, 30 Dec 2015 01:52:11 +0000 (17:52 -0800)
Normally the registry load queue should filter out duplicates, but if
people do weird things with symlinks, throw a useful error message if
the double-loading makes it all the way to the processor.

Bug: T121493
Change-Id: I47f5cd754e5f3c91e6b83a6d0ab542404347a421

includes/registration/ExtensionProcessor.php
tests/phpunit/includes/registration/ExtensionProcessorTest.php

index cab889f..074a962 100644 (file)
@@ -294,6 +294,11 @@ class ExtensionProcessor implements Processor {
                }
        }
 
+       /**
+        * @param string $path
+        * @param array $info
+        * @throws Exception
+        */
        protected function extractCredits( $path, array $info ) {
                $credits = array(
                        'path' => $path,
@@ -305,7 +310,17 @@ class ExtensionProcessor implements Processor {
                        }
                }
 
-               $this->credits[$credits['name']] = $credits;
+               $name = $credits['name'];
+
+               // If someone is loading the same thing twice, throw
+               // a nice error (T121493)
+               if ( isset( $this->credits[$name] ) ) {
+                       $firstPath = $this->credits[$name]['path'];
+                       $secondPath = $credits['path'];
+                       throw new Exception( "It was attempted to load $name twice, from $firstPath and $secondPath." );
+               }
+
+               $this->credits[$name] = $credits;
        }
 
        /**
index 843f576..590644f 100644 (file)
@@ -118,7 +118,8 @@ class ExtensionProcessorTest extends MediaWikiTestCase {
                                '_prefix' => 'eg',
                                'Bar' => 'somevalue'
                        ),
-               ) + self::$default;
+                       'name' => 'FooBar2',
+               );
                $processor->extractInfo( $this->dir, $info, 1 );
                $processor->extractInfo( $this->dir, $info2, 1 );
                $extracted = $processor->getExtractedInfo();
@@ -193,6 +194,16 @@ class ExtensionProcessorTest extends MediaWikiTestCase {
                }
        }
 
+       /**
+        * @covers ExtensionProcessor::extractCredits
+        */
+       public function testExtractCredits() {
+               $processor = new ExtensionProcessor();
+               $processor->extractInfo( $this->dir, self::$default, 1 );
+               $this->setExpectedException( 'Exception' );
+               $processor->extractInfo( $this->dir, self::$default, 1 );
+       }
+
        /**
         * @covers ExtensionProcessor::extractResourceLoaderModules
         * @dataProvider provideExtractResourceLoaderModules