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