Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -439,18 +439,18 @@ |
440 | 440 | /** |
441 | 441 | * Using getAllowedParams(), this function makes an array of the values |
442 | 442 | * provided by the user, with key being the name of the variable, and |
443 | | - * value - validated value from user or default. limit=max will not be |
444 | | - * parsed if $parseMaxLimit is set to false; use this when the max |
| 443 | + * value - validated value from user or default. limits will not be |
| 444 | + * parsed if $parseLimit is set to false; use this when the max |
445 | 445 | * limit is not definitive yet, e.g. when getting revisions. |
446 | | - * @param $parseMaxLimit bool |
| 446 | + * @param $parseLimit bool |
447 | 447 | * @return array |
448 | 448 | */ |
449 | | - public function extractRequestParams($parseMaxLimit = true) { |
| 449 | + public function extractRequestParams($parseLimit = true) { |
450 | 450 | $params = $this->getFinalParams(); |
451 | 451 | $results = array (); |
452 | 452 | |
453 | 453 | foreach ($params as $paramName => $paramSettings) |
454 | | - $results[$paramName] = $this->getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit); |
| 454 | + $results[$paramName] = $this->getParameterFromSettings($paramName, $paramSettings, $parseLimit); |
455 | 455 | |
456 | 456 | return $results; |
457 | 457 | } |
— | — | @@ -458,13 +458,13 @@ |
459 | 459 | /** |
460 | 460 | * Get a value for the given parameter |
461 | 461 | * @param $paramName string Parameter name |
462 | | - * @param $parseMaxLimit bool see extractRequestParams() |
| 462 | + * @param $parseLimit bool see extractRequestParams() |
463 | 463 | * @return mixed Parameter value |
464 | 464 | */ |
465 | | - protected function getParameter($paramName, $parseMaxLimit = true) { |
| 465 | + protected function getParameter($paramName, $parseLimit = true) { |
466 | 466 | $params = $this->getFinalParams(); |
467 | 467 | $paramSettings = $params[$paramName]; |
468 | | - return $this->getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit); |
| 468 | + return $this->getParameterFromSettings($paramName, $paramSettings, $parseLimit); |
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
— | — | @@ -510,10 +510,10 @@ |
511 | 511 | * @param $paramName String: parameter name |
512 | 512 | * @param $paramSettings Mixed: default value or an array of settings |
513 | 513 | * using PARAM_* constants. |
514 | | - * @param $parseMaxLimit Boolean: parse limit when max is given? |
| 514 | + * @param $parseLimit Boolean: parse limit? |
515 | 515 | * @return mixed Parameter value |
516 | 516 | */ |
517 | | - protected function getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit) { |
| 517 | + protected function getParameterFromSettings($paramName, $paramSettings, $parseLimit) { |
518 | 518 | |
519 | 519 | // Some classes may decide to change parameter names |
520 | 520 | $encParamName = $this->encodeParamName($paramName); |
— | — | @@ -572,23 +572,23 @@ |
573 | 573 | |
574 | 574 | if (!is_null($min) || !is_null($max)) { |
575 | 575 | $values = is_array($value) ? $value : array($value); |
576 | | - foreach ($values as $v) { |
| 576 | + foreach ($values as &$v) { |
577 | 577 | $this->validateLimit($paramName, $v, $min, $max); |
578 | 578 | } |
579 | 579 | } |
580 | 580 | break; |
581 | 581 | case 'limit' : |
| 582 | + if ( !$parseLimit ) |
| 583 | + // Don't do any validation whatsoever |
| 584 | + break; |
582 | 585 | if (!isset ($paramSettings[self :: PARAM_MAX]) || !isset ($paramSettings[self :: PARAM_MAX2])) |
583 | 586 | ApiBase :: dieDebug(__METHOD__, "MAX1 or MAX2 are not defined for the limit $encParamName"); |
584 | 587 | if ($multi) |
585 | 588 | ApiBase :: dieDebug(__METHOD__, "Multi-values not supported for $encParamName"); |
586 | 589 | $min = isset ($paramSettings[self :: PARAM_MIN]) ? $paramSettings[self :: PARAM_MIN] : 0; |
587 | 590 | if( $value == 'max' ) { |
588 | | - if( $parseMaxLimit ) { |
589 | 591 | $value = $this->getMain()->canApiHighLimits() ? $paramSettings[self :: PARAM_MAX2] : $paramSettings[self :: PARAM_MAX]; |
590 | 592 | $this->getResult()->addValue( 'limits', $this->getModuleName(), $value ); |
591 | | - $this->validateLimit($paramName, $value, $min, $paramSettings[self :: PARAM_MAX], $paramSettings[self :: PARAM_MAX2]); |
592 | | - } |
593 | 593 | } |
594 | 594 | else { |
595 | 595 | $value = intval($value); |
— | — | @@ -681,9 +681,10 @@ |
682 | 682 | * @param $max int Maximum value for users |
683 | 683 | * @param $botMax int Maximum value for sysops/bots |
684 | 684 | */ |
685 | | - function validateLimit($paramName, $value, $min, $max, $botMax = null) { |
| 685 | + function validateLimit($paramName, &$value, $min, $max, $botMax = null) { |
686 | 686 | if (!is_null($min) && $value < $min) { |
687 | | - $this->dieUsage($this->encodeParamName($paramName) . " may not be less than $min (set to $value)", $paramName); |
| 687 | + $this->setWarning($this->encodeParamName($paramName) . " may not be less than $min (set to $value)"); |
| 688 | + $value = $min; |
688 | 689 | } |
689 | 690 | |
690 | 691 | // Minimum is always validated, whereas maximum is checked only if not running in internal call mode |
— | — | @@ -695,10 +696,12 @@ |
696 | 697 | if (!is_null($max) && $value > $max) { |
697 | 698 | if (!is_null($botMax) && $this->getMain()->canApiHighLimits()) { |
698 | 699 | if ($value > $botMax) { |
699 | | - $this->dieUsage($this->encodeParamName($paramName) . " may not be over $botMax (set to $value) for bots or sysops", $paramName); |
| 700 | + $this->setWarning($this->encodeParamName($paramName) . " may not be over $botMax (set to $value) for bots or sysops"); |
| 701 | + $value = $botMax; |
700 | 702 | } |
701 | 703 | } else { |
702 | | - $this->dieUsage($this->encodeParamName($paramName) . " may not be over $max (set to $value) for users", $paramName); |
| 704 | + $this->setWarning($this->encodeParamName($paramName) . " may not be over $max (set to $value) for users"); |
| 705 | + $value = $max; |
703 | 706 | } |
704 | 707 | } |
705 | 708 | } |