MediaWiki REL1_35
ParamValidatorCallbacks.php
Go to the documentation of this file.
1<?php
2
4
5use InvalidArgumentException;
9use Psr\Http\Message\UploadedFileInterface;
12
14
17
19 private $request;
20
22 private $user;
23
24 public function __construct(
28 ) {
29 $this->permissionManager = $permissionManager;
30 $this->request = $request;
31 $this->user = $user;
32 }
33
39 private function getParamsFromSource( $source ) {
40 switch ( $source ) {
41 case 'path':
42 return $this->request->getPathParams();
43
44 case 'query':
45 return $this->request->getQueryParams();
46
47 case 'post':
48 return $this->request->getPostParams();
49
50 default:
51 throw new InvalidArgumentException( __METHOD__ . ": Invalid source '$source'" );
52 }
53 }
54
55 public function hasParam( $name, array $options ) {
56 $params = $this->getParamsFromSource( $options['source'] );
57 return isset( $params[$name] );
58 }
59
60 public function getValue( $name, $default, array $options ) {
61 $params = $this->getParamsFromSource( $options['source'] );
62 return $params[$name] ?? $default;
63 // @todo Should normalization to NFC UTF-8 be done here (much like in the
64 // action API and the rest of MW), or should it be left to handlers to
65 // do whatever normalization they need?
66 }
67
68 public function hasUpload( $name, array $options ) {
69 if ( $options['source'] !== 'post' ) {
70 return false;
71 }
72 return $this->getUploadedFile( $name, $options ) !== null;
73 }
74
75 public function getUploadedFile( $name, array $options ) {
76 if ( $options['source'] !== 'post' ) {
77 return null;
78 }
79 $upload = $this->request->getUploadedFiles()[$name] ?? null;
80 return $upload instanceof UploadedFileInterface ? $upload : null;
81 }
82
83 public function recordCondition(
84 DataMessageValue $message, $name, $value, array $settings, array $options
85 ) {
86 // @todo Figure out how to handle warnings
87 }
88
89 public function useHighLimits( array $options ) {
90 return $this->permissionManager->userHasRight( $this->user, 'apihighlimits' );
91 }
92
93}
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
getValue( $name, $default, array $options)
Fetch a value from the request.
getParamsFromSource( $source)
Get the raw parameters from a source in the request.
__construct(PermissionManager $permissionManager, RequestInterface $request, UserIdentity $user)
hasParam( $name, array $options)
Test if a parameter exists in the request.
useHighLimits(array $options)
Indicate whether "high limits" should be used.
recordCondition(DataMessageValue $message, $name, $value, array $settings, array $options)
Record non-fatal conditions.
getUploadedFile( $name, array $options)
Fetch data for a file upload.
hasUpload( $name, array $options)
Test if a parameter exists as an upload in the request.
Value object representing a message for i18n with alternative machine-readable data.
A request interface similar to PSR-7's ServerRequestInterface.
Interface for objects representing user identity.
Interface defining callbacks needed by ParamValidator.
Definition Callbacks.php:21
$source