Merge "Make MapCacheLRU throw errors for bad $field arguments"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLTitleTextField.php
index 602ddee..93d09e7 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Widget\TitleInputWidget;
 
 /**
@@ -41,6 +42,11 @@ class HTMLTitleTextField extends HTMLTextField {
                        return parent::validate( $value, $alldata );
                }
 
+               // Default value (from getDefault()) is null, which breaks Title::newFromTextThrow() below
+               if ( $value === null ) {
+                       $value = '';
+               }
+
                if ( !$this->mParams['required'] && $value === '' ) {
                        // If this field is not required and the value is empty, that's okay, skip validation
                        return parent::validate( $value, $alldata );
@@ -51,8 +57,8 @@ class HTMLTitleTextField extends HTMLTextField {
                                $title = Title::newFromTextThrow( $value );
                        } else {
                                // Can't use Title::makeTitleSafe(), because it doesn't throw useful exceptions
-                               global $wgContLang;
-                               $namespaceName = $wgContLang->getNsText( $this->mParams['namespace'] );
+                               $namespaceName = MediaWikiServices::getInstance()->getContentLanguage()->
+                                       getNsText( $this->mParams['namespace'] );
                                $title = Title::newFromTextThrow( $namespaceName . ':' . $value );
                        }
                } catch ( MalformedTitleException $e ) {