r38608 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38607‎ | r38608 | r38609 >
Date:02:37, 5 August 2008
Author:demon
Status:old
Tags:
Comment:
Refactor badaccess-groupX and friends to use User::getGroupsWithPermission().
* 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).
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -1069,29 +1069,23 @@
10701070 $this->mBodytext = '';
10711071
10721072 $groups = array();
1073 - foreach( $wgGroupPermissions as $key => $value ) {
1074 - if( isset( $value[$permission] ) && $value[$permission] == true ) {
1075 - $groupName = User::getGroupName( $key );
1076 - $groupPage = User::getGroupPage( $key );
1077 - if( $groupPage ) {
1078 - $skin = $wgUser->getSkin();
1079 - $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
1080 - } else {
1081 - $groups[] = $groupName;
1082 - }
 1073+ foreach( User::getGroupsWithPermission( $permission ) as $key ) {
 1074+ $groupName = User::getGroupName( $key );
 1075+ $groupPage = User::getGroupPage( $key );
 1076+ if( $groupPage ) {
 1077+ $skin = $wgUser->getSkin();
 1078+ $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
 1079+ } else {
 1080+ $groups[] = $groupName;
10831081 }
10841082 }
10851083 $n = count( $groups );
1086 - $groups = implode( ', ', $groups );
1087 - switch( $n ) {
1088 - case 0:
1089 - case 1:
1090 - case 2:
1091 - $message = wfMsgHtml( "badaccess-group$n", $groups );
1092 - break;
1093 - default:
1094 - $message = wfMsgHtml( 'badaccess-groups', $groups );
 1084+ if ( $count > 0 ) {
 1085+ $message = wfMsgHtml( 'badaccess-groups', array( $groups, $n ) );
10951086 }
 1087+ else {
 1088+ $message = wfMsgHtml( "badaccess-group0", $groups );
 1089+ }
10961090 $this->addHtml( $message );
10971091 $this->returnToMain();
10981092 }
Index: trunk/phase3/includes/Title.php
@@ -1308,29 +1308,23 @@
13091309 } elseif ( !$user->isAllowed( $action ) ) {
13101310 $return = null;
13111311 $groups = array();
1312 - global $wgGroupPermissions;
1313 - foreach( $wgGroupPermissions as $key => $value ) {
1314 - if( isset( $value[$action] ) && $value[$action] == true ) {
1315 - $groupName = User::getGroupName( $key );
1316 - $groupPage = User::getGroupPage( $key );
1317 - if( $groupPage ) {
1318 - $groups[] = '[['.$groupPage->getPrefixedText().'|'.$groupName.']]';
1319 - } else {
1320 - $groups[] = $groupName;
1321 - }
 1312+ foreach( User::getGroupsWithPermission( $action ) as $key ) {
 1313+ $groupName = User::getGroupName( $key );
 1314+ $groupPage = User::getGroupPage( $key );
 1315+ if( $groupPage ) {
 1316+ $groups[] = '[['.$groupPage->getPrefixedText().'|'.$groupName.']]';
 1317+ } else {
 1318+ $groups[] = $groupName;
13221319 }
13231320 }
13241321 $n = count( $groups );
1325 - $groups = implode( ', ', $groups );
1326 - switch( $n ) {
1327 - case 0:
1328 - case 1:
1329 - case 2:
1330 - $return = array( "badaccess-group$n", $groups );
1331 - break;
1332 - default:
1333 - $return = array( 'badaccess-groups', $groups );
 1322+ if ( $n > 0 ) {
 1323+ $groups = implode( ', ', $groups );
 1324+ $return = array( 'badaccess-groups', array( $groups, $n ) );
13341325 }
 1326+ else {
 1327+ $return = array( "badaccess-group0", $groups );
 1328+ }
13351329 $errors[] = $return;
13361330 }
13371331
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -719,9 +719,7 @@
720720
721721 'badaccess' => 'Permission error',
722722 'badaccess-group0' => 'You are not allowed to execute the action you have requested.',
723 -'badaccess-group1' => 'The action you have requested is limited to users in the group $1.',
724 -'badaccess-group2' => 'The action you have requested is limited to users in one of the groups $1.',
725 -'badaccess-groups' => 'The action you have requested is limited to users in one of the groups $1.',
 723+'badaccess-groups' => 'The action you have requested is limited to users in {{PLURAL:$2|the group|one of the groups}}: $1.',
726724
727725 'versionrequired' => 'Version $1 of MediaWiki required',
728726 'versionrequiredtext' => 'Version $1 of MediaWiki is required to use this page.

Follow-up revisions

RevisionCommit summaryAuthorDate
r38609Follow up per r38608: Update messages.incraymond03:26, 5 August 2008
r38613Cleanup to r38608 ("Refactor badaccess-groupX and friends to use User::getGro...brion05:32, 5 August 2008

Status & tagging log