Esempio n. 1
0
 function validate($value, $alldata)
 {
     $p = parent::validate($value, $alldata);
     if ($p !== true) {
         return $p;
     }
     if ($value === '') {
         // required was already checked by parent::validate
         return true;
     }
     $date = $this->parseDate($value);
     if (!$date) {
         // Messages: htmlform-date-invalid htmlform-time-invalid htmlform-datetime-invalid
         return $this->msg("htmlform-{$this->mType}-invalid")->parseAsBlock();
     }
     if (isset($this->mParams['min'])) {
         $min = $this->parseDate($this->mParams['min']);
         if ($min && $date < $min) {
             // Messages: htmlform-date-toolow htmlform-time-toolow htmlform-datetime-toolow
             return $this->msg("htmlform-{$this->mType}-toolow", $this->formatDate($min))->parseAsBlock();
         }
     }
     if (isset($this->mParams['max'])) {
         $max = $this->parseDate($this->mParams['max']);
         if ($max && $date > $max) {
             // Messages: htmlform-date-toohigh htmlform-time-toohigh htmlform-datetime-toohigh
             return $this->msg("htmlform-{$this->mType}-toohigh", $this->formatDate($max))->parseAsBlock();
         }
     }
     return true;
 }
	/**
	 * @param $value
	 * @param $alldata
	 * @return bool|String
	 */
	function validate( $value, $alldata ) {
		$p = parent::validate( $value, $alldata );

		if ( $p !== true ) {
			return $p;
		}

		if ( !isset( $this->mParams['valid-values'] ) ) {
			return true;
		}

		if ( $value === 'default' ) {
			return true;
		}

		$codes = $this->tidy( $value );
		$valid = array_flip( $this->mParams['valid-values'] );

		foreach ( $codes as $code ) {
			if ( !isset( $valid[$code] ) ) {
				return wfMsgExt( 'translate-pref-editassistlang-bad', 'parse', $code );
			}
		}

		return true;
	}
Esempio n. 3
0
 function validate($value, $alldata)
 {
     $p = parent::validate($value, $alldata);
     if ($p !== true) {
         return $p;
     }
     $value = trim($value);
     # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers
     # with the addition that a leading '+' sign is ok.
     if (!preg_match('/^((\\+|\\-)?\\d+(\\.\\d+)?(E(\\+|\\-)?\\d+)?)?$/i', $value)) {
         return $this->msg('htmlform-float-invalid')->parseAsBlock();
     }
     # The "int" part of these message names is rather confusing.
     # They make equal sense for all numbers.
     if (isset($this->mParams['min'])) {
         $min = $this->mParams['min'];
         if ($min > $value) {
             return $this->msg('htmlform-int-toolow', $min)->parseAsBlock();
         }
     }
     if (isset($this->mParams['max'])) {
         $max = $this->mParams['max'];
         if ($max < $value) {
             return $this->msg('htmlform-int-toohigh', $max)->parseAsBlock();
         }
     }
     return true;
 }
Esempio n. 4
0
 function validate($value, $alldata)
 {
     $p = parent::validate($value, $alldata);
     if ($p !== true) {
         return $p;
     }
     $value = trim($value);
     // TODO: further validation
     return true;
 }
 public function validate($value, $alldata)
 {
     // check, if a user exists with the given username
     $user = User::newFromName($value, false);
     if (!$user) {
         return $this->msg('htmlform-user-not-valid', $value)->parse();
     } elseif ($this->mParams['exists'] && $user->getId() === 0 && !($this->mParams['ipallowed'] && User::isIP($value))) {
         return $this->msg('htmlform-user-not-exists', $user->getName())->parse();
     }
     return parent::validate($value, $alldata);
 }
 function validate($value, $alldata)
 {
     $p = parent::validate($value, $alldata);
     if ($p !== true) {
         return $p;
     }
     $validOptions = HTMLFormField::flattenOptions($this->getOptions());
     if (in_array(strval($value), $validOptions, true)) {
         return true;
     } elseif (in_array(strval($value), $this->autocomplete, true)) {
         return true;
     } elseif ($this->mParams['require-match']) {
         return $this->msg('htmlform-select-badoption')->parse();
     }
     return true;
 }
 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);
 }
Esempio n. 8
0
 public function validate($value, $alldata)
 {
     try {
         $title = Title::newFromTextThrow($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);
 }
Esempio n. 9
0
 function validate($value, $alldata)
 {
     $p = parent::validate($value, $alldata);
     if ($p !== true) {
         return $p;
     }
     if (floatval($value) != $value) {
         return wfMsgExt('htmlform-float-invalid', 'parse');
     }
     $in_range = true;
     # The "int" part of these message names is rather confusing.
     # They make equal sense for all numbers.
     if (isset($this->mParams['min'])) {
         $min = $this->mParams['min'];
         if ($min > $value) {
             return wfMsgExt('htmlform-int-toolow', 'parse', array($min));
         }
     }
     if (isset($this->mParams['max'])) {
         $max = $this->mParams['max'];
         if ($max < $value) {
             return wfMsgExt('htmlform-int-toohigh', 'parse', array($max));
         }
     }
     return true;
 }