Merge "Handle $title === null in Title::newFromText"
[lhc/web/wiklou.git] / includes / Title.php
index 8586ad7..f6bc947 100644 (file)
@@ -37,7 +37,7 @@ use MediaWiki\MediaWikiServices;
  *       and does not rely on global state or the database.
  */
 class Title implements LinkTarget {
-       /** @var HashBagOStuff */
+       /** @var MapCacheLRU */
        static private $titleCache = null;
 
        /**
@@ -306,6 +306,10 @@ class Title implements LinkTarget {
        public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
                if ( is_object( $text ) ) {
                        throw new MWException( '$text must be a string, given an object' );
+               } elseif ( $text === null ) {
+                       // Legacy code relies on MalformedTitleException being thrown in this case
+                       // (happens when URL with no title in it is parsed). TODO fix
+                       throw new MalformedTitleException( 'title-invalid-empty' );
                }
 
                $titleCache = self::getTitleCache();
@@ -371,11 +375,11 @@ class Title implements LinkTarget {
        }
 
        /**
-        * @return HashBagOStuff
+        * @return MapCacheLRU
         */
        private static function getTitleCache() {
                if ( self::$titleCache == null ) {
-                       self::$titleCache = new HashBagOStuff( [ 'maxKeys' => self::CACHE_MAX ] );
+                       self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
                }
                return self::$titleCache;
        }