| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Rest\BasicAccess; |
| 4 |
|
| 5 |
use MediaWiki\Rest\Handler; |
| 6 |
use MediaWiki\Rest\RequestInterface; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
abstract class BasicRequestAuthorizer { |
| 16 |
protected RequestInterface $request; |
| 17 |
protected Handler $handler; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public function __construct( RequestInterface $request, Handler $handler ) { |
| 24 |
$this->request = $request; |
| 25 |
$this->handler = $handler; |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function authorize() { |
| 34 |
if ( $this->handler->needsReadAccess() && !$this->isReadAllowed() ) { |
| 35 |
return 'rest-read-denied'; |
| 36 |
} |
| 37 |
if ( $this->handler->needsWriteAccess() && !$this->isWriteAllowed() ) { |
| 38 |
return 'rest-write-denied'; |
| 39 |
} |
| 40 |
return null; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
abstract protected function isReadAllowed(); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
abstract protected function isWriteAllowed(); |
| 56 |
} |