X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fexception%2FPermissionsError.php;h=cc69a762c1195ee1c1a56d845a8678a936cb633b;hb=97af92da48f0d434cf4b541e7a3f2d96619a95b2;hp=bfba7b2742e7781350bfad365fe55689887ed7fe;hpb=166191535f486569277e95b7e6a3850b5db6757d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/exception/PermissionsError.php b/includes/exception/PermissionsError.php index bfba7b2742..cc69a762c1 100644 --- a/includes/exception/PermissionsError.php +++ b/includes/exception/PermissionsError.php @@ -28,25 +28,39 @@ class PermissionsError extends ErrorPageError { public $permission, $errors; - public function __construct( $permission, $errors = array() ) { + /** + * @param string|null $permission A permission name or null if unknown + * @param array $errors Error message keys or [key, param...] arrays; must not be empty if + * $permission is null + * @throws \InvalidArgumentException + */ + public function __construct( $permission, $errors = [] ) { global $wgLang; + if ( $permission === null && !$errors ) { + throw new \InvalidArgumentException( __METHOD__ . + ': $permission and $errors cannot both be empty' ); + } + $this->permission = $permission; if ( !count( $errors ) ) { - $groups = array_map( - array( 'User', 'makeGroupLinkWiki' ), - User::getGroupsWithPermission( $this->permission ) - ); + $groups = []; + foreach ( User::getGroupsWithPermission( $this->permission ) as $group ) { + $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' ); + } if ( $groups ) { - $errors[] = array( 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ); + $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ]; } else { - $errors[] = array( 'badaccess-group0' ); + $errors[] = [ 'badaccess-group0' ]; } } $this->errors = $errors; + + // Give the parent class something to work with + parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) ); } public function report() {