* Should be a bit cleaner, and remove those ugly ugly switch() statements.
* Two messages are all that's needed here. Badaccess-group0, a generic "Permission denied" when no group is allowed access; and badaccess-groups which takes two parameters of $1 (groups required for access) and $2 (number of group matches, used for {{PLURAL:}}ing the message).
$this->mBodytext = '';
$groups = array();
- foreach( $wgGroupPermissions as $key => $value ) {
- if( isset( $value[$permission] ) && $value[$permission] == true ) {
- $groupName = User::getGroupName( $key );
- $groupPage = User::getGroupPage( $key );
- if( $groupPage ) {
- $skin = $wgUser->getSkin();
- $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
- } else {
- $groups[] = $groupName;
- }
+ foreach( User::getGroupsWithPermission( $permission ) as $key ) {
+ $groupName = User::getGroupName( $key );
+ $groupPage = User::getGroupPage( $key );
+ if( $groupPage ) {
+ $skin = $wgUser->getSkin();
+ $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
+ } else {
+ $groups[] = $groupName;
}
}
$n = count( $groups );
- $groups = implode( ', ', $groups );
- switch( $n ) {
- case 0:
- case 1:
- case 2:
- $message = wfMsgHtml( "badaccess-group$n", $groups );
- break;
- default:
- $message = wfMsgHtml( 'badaccess-groups', $groups );
+ if ( $count > 0 ) {
+ $message = wfMsgHtml( 'badaccess-groups', array( $groups, $n ) );
+ }
+ else {
+ $message = wfMsgHtml( "badaccess-group0", $groups );
}
$this->addHtml( $message );
$this->returnToMain();
} elseif ( !$user->isAllowed( $action ) ) {
$return = null;
$groups = array();
- global $wgGroupPermissions;
- foreach( $wgGroupPermissions as $key => $value ) {
- if( isset( $value[$action] ) && $value[$action] == true ) {
- $groupName = User::getGroupName( $key );
- $groupPage = User::getGroupPage( $key );
- if( $groupPage ) {
- $groups[] = '[['.$groupPage->getPrefixedText().'|'.$groupName.']]';
- } else {
- $groups[] = $groupName;
- }
+ foreach( User::getGroupsWithPermission( $action ) as $key ) {
+ $groupName = User::getGroupName( $key );
+ $groupPage = User::getGroupPage( $key );
+ if( $groupPage ) {
+ $groups[] = '[['.$groupPage->getPrefixedText().'|'.$groupName.']]';
+ } else {
+ $groups[] = $groupName;
}
}
$n = count( $groups );
- $groups = implode( ', ', $groups );
- switch( $n ) {
- case 0:
- case 1:
- case 2:
- $return = array( "badaccess-group$n", $groups );
- break;
- default:
- $return = array( 'badaccess-groups', $groups );
+ if ( $n > 0 ) {
+ $groups = implode( ', ', $groups );
+ $return = array( 'badaccess-groups', array( $groups, $n ) );
+ }
+ else {
+ $return = array( "badaccess-group0", $groups );
}
$errors[] = $return;
}
'badaccess' => 'Permission error',
'badaccess-group0' => 'You are not allowed to execute the action you have requested.',
-'badaccess-group1' => 'The action you have requested is limited to users in the group $1.',
-'badaccess-group2' => 'The action you have requested is limited to users in one of the groups $1.',
-'badaccess-groups' => 'The action you have requested is limited to users in one of the groups $1.',
+'badaccess-groups' => 'The action you have requested is limited to users in {{PLURAL:$2|the group|one of the groups}}: $1.',
'versionrequired' => 'Version $1 of MediaWiki required',
'versionrequiredtext' => 'Version $1 of MediaWiki is required to use this page.