]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialListgrouprights.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListgrouprights.php
1 <?php
2
3 /**
4  * This special page lists all defined user groups and the associated rights.
5  * See also @ref $wgGroupPermissions.
6  *
7  * @ingroup SpecialPage
8  * @author Petr Kadlec <mormegil@centrum.cz>
9  */
10 class SpecialListGroupRights extends SpecialPage {
11
12         var $skin;
13
14         /**
15          * Constructor
16          */
17         function __construct() {
18                 global $wgUser;
19                 parent::__construct( 'Listgrouprights' );
20                 $this->skin = $wgUser->getSkin();
21         }
22
23         /**
24          * Show the special page
25          */
26         public function execute( $par ) {
27                 global $wgOut, $wgImplicitGroups, $wgMessageCache;
28                 global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups;
29                 $wgMessageCache->loadAllMessages();
30
31                 $this->setHeaders();
32                 $this->outputHeader();
33
34                 $wgOut->addHTML(
35                         Xml::openElement( 'table', array( 'class' => 'mw-listgrouprights-table' ) ) .
36                                 '<tr>' .
37                                         Xml::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
38                                         Xml::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
39                                 '</tr>'
40                 );
41
42                 foreach( $wgGroupPermissions as $group => $permissions ) {
43                         $groupname = ( $group == '*' ) ? 'all' : htmlspecialchars( $group ); // Replace * with a more descriptive groupname
44
45                         $msg = wfMsg( 'group-' . $groupname );
46                         if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
47                                 $groupnameLocalized = $groupname;
48                         } else {
49                                 $groupnameLocalized = $msg;
50                         }
51
52                         $msg = wfMsgForContent( 'grouppage-' . $groupname );
53                         if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
54                                 $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
55                         } else {
56                                 $grouppageLocalized = $msg;
57                         }
58
59                         if( $group == '*' ) {
60                                 // Do not make a link for the generic * group
61                                 $grouppage = $groupnameLocalized;
62                         } else {
63                                 $grouppage = $this->skin->makeLink( $grouppageLocalized, $groupnameLocalized );
64                         }
65
66                         if ( !in_array( $group, $wgImplicitGroups ) ) {
67                                 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), 'group=' . $group );
68                         } else {
69                                 // No link to Special:listusers for implicit groups as they are unlistable
70                                 $grouplink = '';
71                         }
72
73                         $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
74                         $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
75
76                         $wgOut->addHTML(
77                                 '<tr>
78                                         <td>' .
79                                                 $grouppage . $grouplink .
80                                         '</td>
81                                         <td>' .
82                                                 self::formatPermissions( $permissions, $addgroups, $removegroups ) .
83                                         '</td>
84                                 </tr>'
85                         );
86                 }
87                 $wgOut->addHTML(
88                         Xml::closeElement( 'table' ) . "\n"
89                 );
90         }
91
92         /**
93          * Create a user-readable list of permissions from the given array.
94          *
95          * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
96          * @return string List of all granted permissions, separated by comma separator
97          */
98          private static function formatPermissions( $permissions, $add, $remove ) {
99                 global $wgLang;
100                 $r = array();
101                 foreach( $permissions as $permission => $granted ) {
102                         if ( $granted ) {
103                                 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
104                                         User::getRightDescription( $permission ),
105                                         $permission
106                                 );
107                                 $r[] = $description;
108                         }
109                 }
110                 sort( $r );
111                 if( $add === true ){
112                         $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
113                 } else if( is_array( $add ) && count( $add ) ) {
114                         $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
115                 }
116                 if( $remove === true ){
117                         $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
118                 } else if( is_array( $remove ) && count( $remove ) ) {
119                         $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
120                 }
121                 if( empty( $r ) ) {
122                         return '';
123                 } else {
124                         return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
125                 }
126         }
127 }