/** * Validates the parameters value and returns the result. * @see ParamDefinition::validateValue * * @since 0.5 * * @param $value mixed * @param $param IParam * @param $definitions array of IParamDefinition * @param $params array of IParam * @param ValidatorOptions $options * * @return boolean */ protected function validateValue($value, IParam $param, array $definitions, array $params, ValidatorOptions $options) { if (!parent::validateValue($value, $param, $definitions, $params, $options)) { return false; } return !$options->isStringlyTyped() && is_bool($value) || $options->isStringlyTyped() && (in_array($value, $this->true) || in_array($value, $this->false)); }
/** * Returns an array containing the parameter info. * * @since 1.0 * * @return array */ protected function getParameterInfo() { global $egMapsDefaultLabel, $egMapsDefaultTitle; global $smgQPForceShow, $smgQPShowTitle, $smgQPTemplate, $smgQPHideNamespace; $params = ParamDefinition::getCleanDefinitions(MapsMapper::getCommonParameters()); $this->service->addParameterInfo($params); $params['zoom']->setDefault(false); $params['zoom']->setDoManipulationOfDefault(false); $params['staticlocations'] = new ListParameter('staticlocations', ';'); $params['staticlocations']->addAliases('locations', 'points'); $params['staticlocations']->addCriteria(new CriterionIsLocation('~')); $params['staticlocations']->addManipulations(new MapsParamLocation('~')); $params['staticlocations']->setDefault(array()); $params['staticlocations']->setMessage('semanticmaps-par-staticlocations'); $params['icon'] = new Parameter('icon', Parameter::TYPE_STRING, '', array(), array(new CriterionNotEmpty())); $params['icon']->setMessage('maps-displaypoints-par-icon'); $params['visitedicon'] = new Parameter('visitedicon', Parameter::TYPE_STRING, '', array(), array(new CriterionNotEmpty())); $params['visitedicon']->setMessage('maps-displaymap-par-visitedicon'); $params['forceshow'] = new Parameter('forceshow', Parameter::TYPE_BOOLEAN, $smgQPForceShow, array('force show')); $params['forceshow']->setMessage('semanticmaps-par-forceshow'); $params['showtitle'] = new Parameter('showtitle', Parameter::TYPE_BOOLEAN, $smgQPShowTitle, array('show title')); $params['showtitle']->setMessage('semanticmaps-par-showtitle'); $params['hidenamespace'] = new Parameter('hidenamespace', Parameter::TYPE_BOOLEAN, $smgQPHideNamespace, array('hide namespace')); $params['hidenamespace']->setMessage('semanticmaps-par-hidenamespace'); $params['template'] = new Parameter('template', Parameter::TYPE_STRING, $smgQPTemplate, array(), array(new CriterionNotEmpty())); $params['template']->setDoManipulationOfDefault(false); $params['template']->setMessage('semanticmaps-par-template'); $params['title'] = new Parameter('title', Parameter::TYPE_STRING, $egMapsDefaultTitle); $params['title']->setMessage('maps-displaypoints-par-title'); $params['label'] = new Parameter('label', Parameter::TYPE_STRING, $egMapsDefaultLabel, array('text')); $params['label']->setMessage('maps-displaypoints-par-label'); return $params; }
/** * @see ParamDefinition::formatValue() * * @since 2.0 * * @param mixed $value * @param IParam $param * @param IParamDefinition[] $definitions * @param IParam[] $params * * @return mixed */ protected function formatValue($value, IParam $param, array &$definitions, array $params) { // Make sure the service is valid. $value = MapsMappingServices::getValidServiceName($value, $this->feature); // Get the service object so the service specific parameters can be retrieved. $serviceObject = MapsMappingServices::getServiceInstance($value); // Add the service specific service parameters. $serviceObject->addParameterInfo($definitions); $definitions = \ParamDefinition::getCleanDefinitions($definitions); return $value; }
/** * Constructor. * * @since 0.4.6 * * @param IParamDefinition|Parameter|array $param * @param mixed $currentValue */ public function __construct($param, $currentValue = false) { if ($param instanceof IParamDefinition) { $this->param = $param; } elseif (is_array($param)) { $this->param = ParamDefinition::newFromArray($param); } else { // Compat code, will go in 0.7 $this->param = ParamDefinition::newFromParameter($param); } $this->currentValue = $currentValue; $this->inputName = $param->getName(); $this->inputClass = ''; }
/** * Returns an array containing the parameter info. * * @since 1.0 * * @return array */ protected function getParameterInfo() { global $smgFIMulti, $smgFIFieldSize; $params = ParamDefinition::getCleanDefinitions(MapsMapper::getCommonParameters()); $this->service->addParameterInfo($params); $params['zoom']->setDefault(false, false); $params['multi'] = new Parameter('multi', Parameter::TYPE_BOOLEAN); $params['multi']->setDefault($smgFIMulti, false); $params['fieldsize'] = new Parameter('fieldsize', Parameter::TYPE_INTEGER); $params['fieldsize']->setDefault($smgFIFieldSize, false); $params['fieldsize']->addCriteria(new CriterionInRange(5, 100)); $params['icon'] = new Parameter('icon'); $params['icon']->setDefault(''); $params['icon']->addCriteria(new CriterionNotEmpty()); $manipulation = new MapsParamLocation(); $manipulation->toJSONObj = true; $params['locations'] = array('aliases' => array('points'), 'criteria' => new CriterionIsLocation(), 'manipulations' => $manipulation, 'default' => array(), 'islist' => true, 'delimiter' => self::SEPARATOR, 'message' => 'semanticmaps-par-locations'); $params['geocodecontrol'] = new Parameter('geocodecontrol', Parameter::TYPE_BOOLEAN); $params['geocodecontrol']->setDefault(true, false); $params['geocodecontrol']->setMessage('semanticmaps-par-geocodecontrol'); return $params; }
/** * Returns the definitions of all parameters supported by the specified format. * * @since 1.8 * * @param string $format * * @return array of IParamDefinition */ public static function getFormatParameters($format) { SMWParamFormat::resolveFormatAliases($format); if (array_key_exists($format, $GLOBALS['smwgResultFormats'])) { return ParamDefinition::getCleanDefinitions(SMWQueryProcessor::getResultPrinter($format)->getParamDefinitions(SMWQueryProcessor::getParameters())); } else { return array(); } }
/** * Applies the parameter manipulations. * @see IParam::format * * @since 0.5 * * @param $definitions array of IParamDefinition * @param $params array of IParam * @param ValidatorOptions $options */ public function format(array &$definitions, array $params, ValidatorOptions $options) { if ($this->definition->shouldManipulateDefault() || !$this->wasSetToDefault()) { $this->definition->format($this, $definitions, $params); $definitions = ParamDefinition::getCleanDefinitions($definitions); // Compat code. $manipulations = array(); foreach ($this->definition->getManipulations() as $manipulation) { if (!$manipulation instanceof ParamManipulationInteger && !$manipulation instanceof ParamManipulationFloat && !$manipulation instanceof ParamManipulationString) { $manipulations[] = $manipulation; } } // This whole block is compat code, to be removed in 0.7. if ($manipulations !== array()) { $parameter = $this->toParameter(); $parameters = array(); foreach ($params as $param) { $parameters[$param->getName()] = $param->toParameter(); } foreach ($definitions as $definition) { if (!array_key_exists($definition->getName(), $parameters)) { $parameters[$definition->getName()] = $definition->toParameter(); } } foreach ($manipulations as $manipulation) { $manipulation->manipulate($parameter, $parameters); } $this->setValue($parameter->getValue()); foreach ($parameters as $parameterObject) { if (!array_key_exists($parameterObject->getName(), $params)) { $definitions[$parameterObject->getName()] = ParamDefinition::newFromParameter($parameterObject); } } } } }
/** * Returns a cleaned version of the list of parameter definitions. * This includes having converted all supported definition types to * ParamDefinition classes and having all keys set to the names of the * corresponding parameters. * * * @since 0.5 * * @param $definitions array of IParamDefinition * * @return array * @throws MWException */ public static function getCleanDefinitions(array $definitions) { $cleanList = array(); foreach ($definitions as $key => $definition) { if (is_array($definition)) { if (!array_key_exists('name', $definition) && is_string($key)) { $definition['name'] = $key; } $definition = ParamDefinition::newFromArray($definition); } elseif ($definition instanceof Parameter) { // This if for backwards compat, will be removed in 0.7. $definition = ParamDefinition::newFromParameter($definition); } if (!$definition instanceof ParamDefinition) { throw new MWException('$definition not an instance of ParamDefinition'); } $cleanList[$definition->getName()] = $definition; } return $cleanList; }
/** * Sets the parameter definition values contained in the provided array. * @see ParamDefinition::setArrayValues * * @since 0.5 * * @param array $param * @throws MWException */ public function setArrayValues(array $param) { parent::setArrayValues($param); if (array_key_exists('range', $param)) { if (is_array($param['range']) && count($param['range']) == 2) { $this->setRange($param['range'][0], $param['range'][1]); } else { throw new MWException('The range argument must be an array with two elements'); } } if (array_key_exists('lowerbound', $param)) { $this->setLowerBound($param['lowerbound']); } if (array_key_exists('upperbound', $param)) { $this->setUpperBound($param['upperbound']); } }
/** * Handles Ajax call * @param integer $pageId * @param type $template * @param type $printrequests * @return type */ public static function handleGetResult($pageId, $template, $printrequests) { $title = Title::newFromID($pageId)->getPrefixedText(); $rp = new SMWListResultPrinter('template', true); $paramDefinitions = ParamDefinition::getCleanDefinitions($rp->getParamDefinitions(array())); $params = array(); /** * @param IParamDefinition $def */ foreach ($paramDefinitions as $def) { $params[$def->getName()] = $def->getDefault(); } $params = array_merge($params, array('format' => 'template', 'template' => $template, 'mainlabel' => '', 'sort' => '', 'order' => '', 'intro' => null, 'outro' => null, 'searchlabel' => null, 'link' => null, 'default' => null, 'headers' => null, 'introtemplate' => '', 'outrotemplate' => '')); $params = SMWQueryProcessor::getProcessedParams($params, array()); $p = json_decode($printrequests, true); $extraprintouts = array(); foreach ($p as $key => $prData) { // if printout mode is PRINT_PROP if ($prData[0] == SMWPrintRequest::PRINT_PROP) { // create property from property key $data = SMWPropertyValue::makeUserProperty($prData[2]); } else { $data = null; } // create printrequest from request mode, label, property name, output format, parameters $extraprintouts[] = new SMWPrintRequest($prData[0], $prData[1], $data, $prData[3], $prData[4]); } return SMWQueryProcessor::getResultFromQueryString('[[' . $title . ']]', $params, $extraprintouts, SMW_OUTPUT_HTML, SMWQueryProcessor::INLINE_QUERY); }
/** * Sets the parameter definition values contained in the provided array. * @see ParamDefinition::setArrayValues * * @since 0.5 * * @param array $param */ public function setArrayValues(array $param) { parent::setArrayValues($param); if (array_key_exists('hastoexist', $param)) { $this->setHasToExist($param['hastoexist']); } }
/** * Loops through a list of provided parameters, resolves aliasing and stores errors * for unknown parameters and optionally for parameter overriding. * * @param array $parameters Parameter name as key, parameter value as value * @param IParamDefinition[] $paramDefinitions List of parameter definitions. Either ParamDefinition objects or equivalent arrays. */ public function setParameters(array $parameters, array $paramDefinitions) { $this->paramDefinitions = ParamDefinition::getCleanDefinitions($paramDefinitions); // Loop through all the user provided parameters, and distinguish between those that are allowed and those that are not. foreach ($parameters as $paramName => $paramData) { if ($this->options->lowercaseNames()) { $paramName = strtolower($paramName); } if ($this->options->trimNames()) { $paramName = trim($paramName); } $paramValue = is_array($paramData) ? $paramData['original-value'] : $paramData; $this->rawParameters[$paramName] = $paramValue; } }
/** * Sets the parameter definition values contained in the provided array. * @see ParamDefinition::setArrayValues * * @since 0.5 * * @param array $param */ public function setArrayValues(array $param) { parent::setArrayValues($param); if (array_key_exists('tolower', $param)) { $this->toLower = $param['tolower']; } if (array_key_exists('length', $param)) { $this->setLength($param['length']); } if (array_key_exists('allowempty', $param)) { $this->canBeEmpty = $param['allowempty']; } }
/** * Does the actual parameter processing. * * @since 0.4 */ protected function doParamProcessing() { $this->getParamsToProcess(array(), $this->paramDefinitions); while ($this->paramsToHandle !== array()) { $paramName = array_shift($this->paramsToHandle); $definition = $this->paramDefinitions[$paramName]; // Compat code for 0.4.x style definitions, will be removed in 0.7. if ($definition instanceof Parameter) { $definition = ParamDefinition::newFromParameter($definition); } $param = new Param($definition); $setUserValue = $this->attemptToSetUserValue($param); // If the parameter is required but not provided, register a fatal error and stop processing. if (!$setUserValue && $param->isRequired()) { $this->registerNewError(wfMsgExt('validator_error_required_missing', 'parsemag', $paramName), array($paramName, 'missing'), ValidationError::SEVERITY_FATAL); break; } else { $this->params[$param->getName()] = $param; $param->validate($this->paramDefinitions, $this->params, $this->options); foreach ($param->getErrors() as $error) { $this->registerError($error); } if ($param->hasFatalError()) { // If there was a fatal error, and the parameter is required, stop processing. break; } $initialSet = $this->paramDefinitions; $param->format($this->paramDefinitions, $this->params, $this->options); $this->getParamsToProcess($initialSet, $this->paramDefinitions); } } }
/** * @dataProvider instanceProvider * * @param \SMWResultPrinter $printer */ public function testGetParamDefinitions(\SMWResultPrinter $printer) { $params = $printer->getParamDefinitions(\SMWQueryProcessor::getParameters()); $params = \ParamDefinition::getCleanDefinitions($params); $this->assertInternalType('array', $params); }
/** * @param string $format * * @return array of IParamDefinition */ protected function getFormatParameters($format) { if (array_key_exists($format, $GLOBALS['smwgResultFormats'])) { return ParamDefinition::getCleanDefinitions(SMWQueryProcessor::getResultPrinter($format)->getParamDefinitions(SMWQueryProcessor::getParameters())); } else { return array(); } }
/** * Returns the data needed to describe the parser hook. * This is mainly needed because some of the individual get methods * that return the needed data are protected, and cannot be made * public without breaking b/c in a rather bad way. * * @since 0.4.3 * * @param integer $type Item of the ParserHook::TYPE_ enum * * @return array */ public function getDescriptionData($type) { return array('names' => $this->getNames(), 'description' => $this->getDescription(), 'message' => $this->getMessage(), 'parameters' => ParamDefinition::getCleanDefinitions($this->getParameterInfo($type)), 'defaults' => $this->getDefaultParameters($type)); }