Debian Codegraph @

extensions/Echo/includes/Api/ApiEchoPermissionsTrait.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Api;
4
5 use MediaWiki\Api\ApiBase;
6 use MediaWiki\Context\ContextSource;
7 use MediaWiki\Message\Message;
8 use MediaWiki\Permissions\Authority;
9 use Wikimedia\Message\MessageSpecifier;
10
11 trait ApiEchoPermissionsTrait {
12
13 /**
14 * @see ContextSource::getAuthority()
15 */
16 abstract public function getAuthority(): Authority;
17
18 /**
19 * @param string|array|MessageSpecifier $msg See ApiErrorFormatter::addError()
20 * @param string|null $code See ApiErrorFormatter::addError()
21 * @param array|null $data See ApiErrorFormatter::addError()
22 * @param int $httpCode HTTP error code to use
23 * @see ApiBase::dieWithError()
24 */
25 abstract public function dieWithError( $msg, $code = null, $data = null, $httpCode = 0 );
26
27 /**
28 * @param string $key
29 * @return Message
30 */
31 abstract public function msg( $key );
32
33 /**
34 * Ensure the user has read access to their own notifications
35 *
36 * Calls dieWithError() with appropriate messaging if omitted.
37 *
38 * @return void
39 */
40 private function checkReadNotificationsPermissions(): void {
41 if ( !$this->getAuthority()->isRegistered() ) {
42 $this->dieWithError( 'apierror-mustbeloggedin-generic', 'login-required' );
43 }
44 if ( !$this->getAuthority()->isAllowed( 'echo-read-notifications' ) ) {
45 $this->dieWithError( [
46 'apierror-permissiondenied',
47 $this->msg( 'action-echo-read-notifications' ),
48 ] );
49 }
50 }
51 }