public $permission, $errors;
/**
- * @param string $permission A permission name.
- * @param string[] $errors Error message keys
+ * @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(
- [ 'User', 'makeGroupLinkWiki' ],
- User::getGroupsWithPermission( $this->permission )
- );
+ $groups = [];
+ foreach ( User::getGroupsWithPermission( $this->permission ) as $group ) {
+ $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
+ }
if ( $groups ) {
$errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ];
}
$this->errors = $errors;
+
+ // Give the parent class something to work with
+ parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
}
public function report() {