]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialListgrouprights.php
MediaWiki 1.15.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 ( $group === 'user' ) {
67                                 // Link to Special:listusers for implicit group 'user'
68                                 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), ''  );
69                         } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
70                                 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), 'group=' . $group );
71                         } else {
72                                 // No link to Special:listusers for other implicit groups as they are unlistable
73                                 $grouplink = '';
74                         }
75
76                         $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
77                         $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
78
79                         $wgOut->addHTML(
80                                 '<tr>
81                                         <td>' .
82                                                 $grouppage . $grouplink .
83                                         '</td>
84                                         <td>' .
85                                                 self::formatPermissions( $permissions, $addgroups, $removegroups ) .
86                                         '</td>
87                                 </tr>'
88                         );
89                 }
90                 $wgOut->addHTML(
91                         Xml::closeElement( 'table' ) . "\n"
92                 );
93         }
94
95         /**
96          * Create a user-readable list of permissions from the given array.
97          *
98          * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
99          * @return string List of all granted permissions, separated by comma separator
100          */
101          private static function formatPermissions( $permissions, $add, $remove ) {
102                 global $wgLang;
103                 $r = array();
104                 foreach( $permissions as $permission => $granted ) {
105                         if ( $granted ) {
106                                 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
107                                         User::getRightDescription( $permission ),
108                                         $permission
109                                 );
110                                 $r[] = $description;
111                         }
112                 }
113                 sort( $r );
114                 if( $add === true ){
115                         $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
116                 } else if( is_array( $add ) && count( $add ) ) {
117                         $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
118                 }
119                 if( $remove === true ){
120                         $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
121                 } else if( is_array( $remove ) && count( $remove ) ) {
122                         $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
123                 }
124                 if( empty( $r ) ) {
125                         return '';
126                 } else {
127                         return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
128                 }
129         }
130 }