MediaWiki  REL1_22
SpecialListgrouprights.php
Go to the documentation of this file.
00001 <?php
00031 class SpecialListGroupRights extends SpecialPage {
00035     function __construct() {
00036         parent::__construct( 'Listgrouprights' );
00037     }
00038 
00042     public function execute( $par ) {
00043         global $wgImplicitGroups;
00044         global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
00045         global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
00046 
00047         $this->setHeaders();
00048         $this->outputHeader();
00049 
00050         $out = $this->getOutput();
00051         $out->addModuleStyles( 'mediawiki.special' );
00052 
00053         $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
00054 
00055         $out->addHTML(
00056             Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
00057                 '<tr>' .
00058                 Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
00059                 Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
00060                 '</tr>'
00061         );
00062 
00063         $allGroups = array_unique( array_merge(
00064             array_keys( $wgGroupPermissions ),
00065             array_keys( $wgRevokePermissions ),
00066             array_keys( $wgAddGroups ),
00067             array_keys( $wgRemoveGroups ),
00068             array_keys( $wgGroupsAddToSelf ),
00069             array_keys( $wgGroupsRemoveFromSelf )
00070         ) );
00071         asort( $allGroups );
00072 
00073         foreach ( $allGroups as $group ) {
00074             $permissions = isset( $wgGroupPermissions[$group] )
00075                 ? $wgGroupPermissions[$group]
00076                 : array();
00077             $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
00078                 ? 'all'
00079                 : $group;
00080 
00081             $msg = $this->msg( 'group-' . $groupname );
00082             $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
00083 
00084             $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
00085             $grouppageLocalized = !$msg->isBlank() ?
00086                 $msg->text() :
00087                 MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
00088 
00089             if ( $group == '*' ) {
00090                 // Do not make a link for the generic * group
00091                 $grouppage = htmlspecialchars( $groupnameLocalized );
00092             } else {
00093                 $grouppage = Linker::link(
00094                     Title::newFromText( $grouppageLocalized ),
00095                     htmlspecialchars( $groupnameLocalized )
00096                 );
00097             }
00098 
00099             if ( $group === 'user' ) {
00100                 // Link to Special:listusers for implicit group 'user'
00101                 $grouplink = '<br />' . Linker::linkKnown(
00102                     SpecialPage::getTitleFor( 'Listusers' ),
00103                     $this->msg( 'listgrouprights-members' )->escaped()
00104                 );
00105             } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
00106                 $grouplink = '<br />' . Linker::linkKnown(
00107                     SpecialPage::getTitleFor( 'Listusers' ),
00108                     $this->msg( 'listgrouprights-members' )->escaped(),
00109                     array(),
00110                     array( 'group' => $group )
00111                 );
00112             } else {
00113                 // No link to Special:listusers for other implicit groups as they are unlistable
00114                 $grouplink = '';
00115             }
00116 
00117             $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
00118             $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
00119             $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
00120             $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
00121             $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
00122 
00123             $id = $group == '*' ? false : Sanitizer::escapeId( $group );
00124             $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
00125                 "
00126                 <td>$grouppage$grouplink</td>
00127                     <td>" .
00128                     $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
00129                         $addgroupsSelf, $removegroupsSelf ) .
00130                     '</td>
00131                 '
00132             ) );
00133         }
00134         $out->addHTML( Xml::closeElement( 'table' ) );
00135     }
00136 
00148     private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
00149         $r = array();
00150         foreach ( $permissions as $permission => $granted ) {
00151             //show as granted only if it isn't revoked to prevent duplicate display of permissions
00152             if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
00153                 $description = $this->msg( 'listgrouprights-right-display',
00154                     User::getRightDescription( $permission ),
00155                     '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
00156                 )->parse();
00157                 $r[] = $description;
00158             }
00159         }
00160         foreach ( $revoke as $permission => $revoked ) {
00161             if ( $revoked ) {
00162                 $description = $this->msg( 'listgrouprights-right-revoked',
00163                     User::getRightDescription( $permission ),
00164                     '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
00165                 )->parse();
00166                 $r[] = $description;
00167             }
00168         }
00169 
00170         sort( $r );
00171 
00172         $lang = $this->getLanguage();
00173 
00174         if ( $add === true ) {
00175             $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
00176         } elseif ( is_array( $add ) && count( $add ) ) {
00177             $add = array_values( array_unique( $add ) );
00178             $r[] = $this->msg( 'listgrouprights-addgroup',
00179                 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
00180                 count( $add )
00181             )->parse();
00182         }
00183 
00184         if ( $remove === true ) {
00185             $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
00186         } elseif ( is_array( $remove ) && count( $remove ) ) {
00187             $remove = array_values( array_unique( $remove ) );
00188             $r[] = $this->msg( 'listgrouprights-removegroup',
00189                 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
00190                 count( $remove )
00191             )->parse();
00192         }
00193 
00194         if ( $addSelf === true ) {
00195             $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
00196         } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
00197             $addSelf = array_values( array_unique( $addSelf ) );
00198             $r[] = $this->msg( 'listgrouprights-addgroup-self',
00199                 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
00200                 count( $addSelf )
00201             )->parse();
00202         }
00203 
00204         if ( $removeSelf === true ) {
00205             $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
00206         } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
00207             $removeSelf = array_values( array_unique( $removeSelf ) );
00208             $r[] = $this->msg( 'listgrouprights-removegroup-self',
00209                 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
00210                 count( $removeSelf )
00211             )->parse();
00212         }
00213 
00214         if ( empty( $r ) ) {
00215             return '';
00216         } else {
00217             return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
00218         }
00219     }
00220 
00221     protected function getGroupName() {
00222         return 'users';
00223     }
00224 }