HTMLSelectLimitField.php 985 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * A limit dropdown, which accepts any valid number
  4. */
  5. class HTMLSelectLimitField extends HTMLSelectField {
  6. /**
  7. * Basically don't do any validation. If it's a number that's fine. Also,
  8. * add it to the list if it's not there already
  9. *
  10. * @param string $value
  11. * @param array $alldata
  12. * @return bool
  13. */
  14. public function validate( $value, $alldata ) {
  15. if ( $value == '' ) {
  16. return true;
  17. }
  18. // Let folks pick an explicit limit not from our list, as long as it's a real numbr.
  19. if ( !in_array( $value, $this->mParams['options'] )
  20. && $value == intval( $value )
  21. && $value > 0
  22. ) {
  23. // This adds the explicitly requested limit value to the drop-down,
  24. // then makes sure it's sorted correctly so when we output the list
  25. // later, the custom option doesn't just show up last.
  26. $this->mParams['options'][$this->mParent->getLanguage()->formatNum( $value )] =
  27. intval( $value );
  28. asort( $this->mParams['options'] );
  29. }
  30. return true;
  31. }
  32. }