From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- includes/htmlform/HTMLTitleTextField.php | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 includes/htmlform/HTMLTitleTextField.php (limited to 'includes/htmlform/HTMLTitleTextField.php') diff --git a/includes/htmlform/HTMLTitleTextField.php b/includes/htmlform/HTMLTitleTextField.php new file mode 100644 index 00000000..a225c67c --- /dev/null +++ b/includes/htmlform/HTMLTitleTextField.php @@ -0,0 +1,81 @@ + false, + 'relative' => false, + 'creatable' => false, + 'exists' => false, + ); + + parent::__construct( $params ); + } + + public function validate( $value, $alldata ) { + if ( $this->mParent->getMethod() === 'get' && $value === '' ) { + // If the form is a GET form and has no value, assume it hasn't been + // submitted yet, and skip validation + return parent::validate( $value, $alldata ); + } + try { + if ( !$this->mParams['relative'] ) { + $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'] ); + $title = Title::newFromTextThrow( $namespaceName . ':' . $value ); + } + } catch ( MalformedTitleException $e ) { + $msg = $this->msg( $e->getErrorMessage() ); + $params = $e->getErrorMessageParameters(); + if ( $params ) { + $msg->params( $params ); + } + return $msg->parse(); + } + + $text = $title->getPrefixedText(); + if ( $this->mParams['namespace'] !== false && !$title->inNamespace( $this->mParams['namespace'] ) ) { + return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text )->parse(); + } + + if ( $this->mParams['creatable'] && !$title->canExist() ) { + return $this->msg( 'htmlform-title-not-creatable', $text )->escaped(); + } + + if ( $this->mParams['exists'] && !$title->exists() ) { + return $this->msg( 'htmlform-title-not-exists', $text )->parse(); + } + + return parent::validate( $value, $alldata ); + } + + protected function getInputWidget( $params ) { + $this->mParent->getOutput()->addModules( 'mediawiki.widgets' ); + if ( $this->mParams['namespace'] !== false ) { + $params['namespace'] = $this->mParams['namespace']; + } + $params['relative'] = $this->mParams['relative']; + return new TitleInputWidget( $params ); + } +} -- cgit v1.2.3-54-g00ecf