/**
	 * Takes care of validation and rendering, and returns the output.
	 *
	 * @since 0.4
	 *
	 * @param array $arguments
	 * @param integer $type Item of the ParserHook::TYPE_ enum
	 *
	 * @return string
	 */
	public function validateAndRender( array $arguments, $type ) {
		$names = $this->getNames();
		$this->validator = new Validator( $names[0] );

		if ( $type === self::TYPE_FUNCTION ) {
			$this->validator->setFunctionParams( $arguments, $this->getParameterInfo( $type ), $this->getDefaultParameters( $type ) );
		}
		else {
			$this->validator->setParameters( $arguments, $this->getParameterInfo( $type ) );
		}

		$this->validator->validateParameters();

		$fatalError = $this->validator->hasFatalError();

		if ( $fatalError === false ) {
			$output = $this->render( $this->validator->getParameterValues() );
			$output = $this->renderErrors( $output );
		}
		else {
			$output = $this->renderFatalError( $fatalError );
		}

		return $output;
	}
Esempio n. 2
0
 /**
  * Takes an array of unprocessed parameters,
  * and sets them on a new Validator object,
  * which is returned and ready to process the parameters.
  *
  * @since 1.8
  *
  * @param array $params
  * @param array $printRequests
  * @param boolean $unknownInvalid
  *
  * @return Validator
  */
 public static function getValidatorForParams(array $params, array $printRequests = array(), $unknownInvalid = true)
 {
     $paramDefinitions = self::getParameters();
     $paramDefinitions['format']->setPrintRequests($printRequests);
     $validator = new Validator('SMW query', $unknownInvalid);
     $validator->setParameters($params, $paramDefinitions, false);
     return $validator;
 }
Esempio n. 3
0
 /**
  * Takes an array of unprocessed parameters,
  * processes them using Validator, and returns them.
  * 
  * Both input and output arrays are
  * param name (string) => param value (mixed)
  * 
  * @since 1.6.2
  * 
  * @param array $params
  * @param array $printRequests
  * @param boolean $unknownInvalid
  * 
  * @return array
  */
 public static function getProcessedParams(array $params, array $printRequests = null, $unknownInvalid = true)
 {
     $paramDefinitions = self::getParameters();
     $formatManipulation = new SMWParamFormat();
     if (!is_null($printRequests)) {
         $formatManipulation->setPrintRequests($printRequests);
     }
     $paramDefinitions['format']->addManipulations($formatManipulation);
     $validator = new Validator('SMW query', $unknownInvalid);
     $validator->setParameters($params, $paramDefinitions, false);
     $validator->validateParameters();
     return $validator->getParameterValues();
 }
Esempio n. 4
0
 /**
  * Sets the parameters for the query.
  *
  * The structure of $params is defined partly by #ask and also by the
  * Result Printer used. When validation is enabled, $params are checked
  * for conformance, and error messages, if any, are returned.
  *
  * Although it is not mandatory for any params to be set while calling
  * this method, this method must be called so that default parameters
  * are used.
  *
  * @global int $smwgQMaxInlineLimit
  * @global array $smwgResultFormats
  * @param array $params
  * @param boolean $enableValidation
  * @return array of strings
  */
 public function setParams(array $params = array(), $enableValidation = false)
 {
     global $smwgQMaxInlineLimit, $smwgResultFormats;
     $errors = array();
     // checking for missing parameters and adding them
     if (!array_key_exists('format', $params) || !array_key_exists($params['format'], $smwgResultFormats)) {
         $params['format'] = $this->defaultResultPrinter;
     }
     if (!array_key_exists('limit', $params)) {
         $params['limit'] = 20;
     }
     $params['limit'] = min($params['limit'], $smwgQMaxInlineLimit);
     if (!array_key_exists('offset', $params)) {
         $params['offset'] = 0;
     }
     if ($enableValidation) {
         // validating the format
         if (!array_key_exists($params['format'], $smwgResultFormats)) {
             $errors[] = wfMsg('smw_qui_invalidformat', $params['format']);
             $this->errorsOccured = true;
         } else {
             // validating parameters for result printer
             $printer = SMWQueryProcessor::getResultPrinter($params['format']);
             $para_meters = $printer->getParameters();
             if (is_array($para_meters)) {
                 $validator = new Validator();
                 $validator->setParameters($params, $para_meters);
                 $validator->validateParameters();
                 if ($validator->hasFatalError()) {
                     array_merge($errors, $validator->getErrorMessages());
                     $this->errorsOccured = true;
                 }
             }
         }
     }
     $this->parameters = $params;
     $this->errors = array_merge($errors, $this->errors);
     return $errors;
 }
Esempio n. 5
0
 /**
  * Validates the layer.
  * 
  * @since 0.7.1
  */
 protected function validate()
 {
     $validator = new Validator();
     $validator->setParameters($this->properties, $this->getParameterDefinitions(array()));
     $validator->validateParameters();
     if ($validator->hasFatalError() !== false) {
         $this->errors = $validator->getErrors();
     }
     $this->properties = $validator->getParameterValues();
 }
Esempio n. 6
0
 /**
  * Validates the layer.
  * 
  * @since 0.7.1
  */
 protected function validate()
 {
     if ($this->hasValidated) {
         return;
     }
     $this->hasValidated = true;
     $validator = new Validator();
     $validator->setParameters($this->properties, $this->getParameterDefinitions());
     $validator->validateParameters();
     if ($validator->hasErrors() !== false) {
         $this->errors = $validator->getErrors();
     }
     $params = $validator->getParameterValues();
     $this->properties = $params;
 }
 /**
  * 
  * 
  * @since 1.0
  * 
  * @param string $coordinates
  * @param string $input_name
  * @param boolean $is_mandatory
  * @param boolean $is_disabled
  * @param array $field_args
  * 
  * @return string
  */
 public function getInputOutput($coordinates, $input_name, $is_mandatory, $is_disabled, array $params)
 {
     $parameters = array();
     foreach ($params as $key => $value) {
         if (!is_array($value) && !is_object($value) && !is_null($value)) {
             $parameters[$key] = $value;
         }
     }
     if (!is_null($coordinates)) {
         $parameters['locations'] = $coordinates;
     }
     $validator = new Validator(wfMessage('maps_' . $this->service->getName())->text(), false);
     $validator->setParameters($parameters, $this->getParameterInfo());
     $validator->validateParameters();
     $fatalError = $validator->hasFatalError();
     if ($fatalError === false) {
         global $wgParser;
         $params = $validator->getParameterValues();
         // We can only take care of the zoom defaulting here,
         // as not all locations are available in whats passed to Validator.
         if ($params['zoom'] === false && count($params['locations']) <= 1) {
             $params['zoom'] = $this->service->getDefaultZoom();
         }
         $mapName = $this->service->getMapId();
         $params['inputname'] = $input_name;
         $output = $this->getInputHTML($params, $wgParser, $mapName);
         $this->service->addResourceModules($this->getResourceModules());
         $configVars = Skin::makeVariablesScript($this->service->getConfigVariables());
         // MediaWiki 1.17 does not play nice with addScript, so add the vars via the globals hook.
         if (version_compare($GLOBALS['wgVersion'], '1.18', '<')) {
             $GLOBALS['egMapsGlobalJSVars'] += $this->service->getConfigVariables();
         }
         if (true) {
             // TODO
             global $wgOut;
             $this->service->addDependencies($wgOut);
             $wgOut->addScript($configVars);
         } else {
             $this->service->addDependencies($wgParser);
         }
         return $output;
     } else {
         return '<span class="errorbox">' . htmlspecialchars(wfMessage('validator-fatal-error', $fatalError->getMessage())->text()) . '</span>';
     }
 }