3 use MediaWiki\Widget\TitleInputWidget
;
6 * Implements a text input field for page titles.
7 * Automatically does validation that the title is valid,
8 * as well as autocompletion if using the OOUI display format.
10 * FIXME: Does not work for forms that support GET requests.
12 * Optional parameters:
13 * 'namespace' - Namespace the page must be in
14 * 'creatable' - Whether to validate the title is creatable (not a special page)
15 * 'exists' - Whether to validate that the title already exists
19 class HTMLTitleTextField
extends HTMLTextField
{
20 public function __construct( $params ) {
27 parent
::__construct( $params );
30 public function validate( $value, $alldata ) {
32 $title = Title
::newFromTextThrow( $value );
33 } catch ( MalformedTitleException
$e ) {
34 $msg = $this->msg( $e->getErrorMessage() );
35 $params = $e->getErrorMessageParameters();
37 $msg->params( $params );
42 $text = $title->getPrefixedText();
43 if ( $this->mParams
['namespace'] !== false && !$title->inNamespace( $this->mParams
['namespace'] ) ) {
44 return $this->msg( 'htmlform-title-badnamespace', $this->mParams
['namespace'], $text )->parse();
47 if ( $this->mParams
['creatable'] && !$title->canExist() ) {
48 return $this->msg( 'htmlform-title-not-creatable', $text )->escaped();
51 if ( $this->mParams
['exists'] && !$title->exists() ) {
52 return $this->msg( 'htmlform-title-not-exists', $text )->parse();
55 return parent
::validate( $value, $alldata );
58 protected function getInputWidget( $params ) {
59 $this->mParent
->getOutput()->addModules( 'mediawiki.widgets' );
60 if ( $this->mParams
['namespace'] !== false ) {
61 $params['namespace'] = $this->mParams
['namespace'];
63 $params['relative'] = false;
64 return new TitleInputWidget( $params );