Merge "HTMLTitleTextField: Support 'relative' config option"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 27 Jul 2015 02:12:47 +0000 (02:12 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 27 Jul 2015 02:12:47 +0000 (02:12 +0000)
1  2 
includes/htmlform/HTMLTitleTextField.php

@@@ -7,11 -7,11 +7,12 @@@ use MediaWiki\Widget\TitleInputWidget
   * Automatically does validation that the title is valid,
   * as well as autocompletion if using the OOUI display format.
   *
 - * FIXME: Does not work for forms that support GET requests.
 + * Note: Forms using GET requests will need to make sure the title value is not
 + * an empty string.
   *
   * Optional parameters:
   * 'namespace' - Namespace the page must be in
+  * 'relative' - If true and 'namespace' given, strip/add the namespace from/to the title as needed
   * 'creatable' - Whether to validate the title is creatable (not a special page)
   * 'exists' - Whether to validate that the title already exists
   *
@@@ -21,6 -21,7 +22,7 @@@ class HTMLTitleTextField extends HTMLTe
        public function __construct( $params ) {
                $params += array(
                        'namespace' => false,
+                       'relative' => false,
                        'creatable' => false,
                        'exists' => false,
                );
        }
  
        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 {
-                       $title = Title::newFromTextThrow( $value );
+                       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();
@@@ -66,7 -69,7 +75,7 @@@
                if ( $this->mParams['namespace'] !== false ) {
                        $params['namespace'] = $this->mParams['namespace'];
                }
-               $params['relative'] = false;
+               $params['relative'] = $this->mParams['relative'];
                return new TitleInputWidget( $params );
        }
  }