MediaWiki
REL1_23
|
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 $this->outputNamespaceProtectionInfo(); 00136 } 00137 00138 private function outputNamespaceProtectionInfo() { 00139 global $wgNamespaceProtection, $wgParser, $wgContLang; 00140 $out = $this->getOutput(); 00141 00142 if ( count( $wgNamespaceProtection ) == 0 ) { 00143 return; 00144 } 00145 00146 $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse(); 00147 $out->addHTML( 00148 Html::rawElement( 'h2', array(), Html::element( 'span', array( 00149 'class' => 'mw-headline', 00150 'id' => $wgParser->guessSectionNameFromWikiText( $header ) 00151 ), $header ) ) . 00152 Xml::openElement( 'table', array( 'class' => 'wikitable' ) ) . 00153 Html::element( 00154 'th', 00155 array(), 00156 $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text() 00157 ) . 00158 Html::element( 00159 'th', 00160 array(), 00161 $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text() 00162 ) 00163 ); 00164 00165 ksort( $wgNamespaceProtection ); 00166 foreach ( $wgNamespaceProtection as $namespace => $rights ) { 00167 if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) { 00168 continue; 00169 } 00170 00171 if ( $namespace == NS_MAIN ) { 00172 $namespaceText = $this->msg( 'blanknamespace' )->text(); 00173 } else { 00174 $namespaceText = $wgContLang->convertNamespace( $namespace ); 00175 } 00176 00177 $out->addHTML( 00178 Xml::openElement( 'tr' ) . 00179 Html::rawElement( 00180 'td', 00181 array(), 00182 Linker::link( 00183 SpecialPage::getTitleFor( 'Allpages' ), 00184 $namespaceText, 00185 array(), 00186 array( 'namespace' => $namespace ) 00187 ) 00188 ) . 00189 Xml::openElement( 'td' ) . Xml::openElement( 'ul' ) 00190 ); 00191 00192 if ( !is_array( $rights ) ) { 00193 $rights = array( $rights ); 00194 } 00195 00196 foreach ( $rights as $right ) { 00197 $out->addHTML( 00198 Html::rawElement( 'li', array(), $this->msg( 00199 'listgrouprights-right-display', 00200 User::getRightDescription( $right ), 00201 Html::element( 00202 'span', 00203 array( 'class' => 'mw-listgrouprights-right-name' ), 00204 $right 00205 ) 00206 )->parse() ) 00207 ); 00208 } 00209 00210 $out->addHTML( 00211 Xml::closeElement( 'ul' ) . 00212 Xml::closeElement( 'td' ) . 00213 Xml::closeElement( 'tr' ) 00214 ); 00215 } 00216 $out->addHTML( Xml::closeElement( 'table' ) ); 00217 } 00218 00230 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) { 00231 $r = array(); 00232 foreach ( $permissions as $permission => $granted ) { 00233 //show as granted only if it isn't revoked to prevent duplicate display of permissions 00234 if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) { 00235 $description = $this->msg( 'listgrouprights-right-display', 00236 User::getRightDescription( $permission ), 00237 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>' 00238 )->parse(); 00239 $r[] = $description; 00240 } 00241 } 00242 foreach ( $revoke as $permission => $revoked ) { 00243 if ( $revoked ) { 00244 $description = $this->msg( 'listgrouprights-right-revoked', 00245 User::getRightDescription( $permission ), 00246 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>' 00247 )->parse(); 00248 $r[] = $description; 00249 } 00250 } 00251 00252 sort( $r ); 00253 00254 $lang = $this->getLanguage(); 00255 00256 if ( $add === true ) { 00257 $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped(); 00258 } elseif ( is_array( $add ) && count( $add ) ) { 00259 $add = array_values( array_unique( $add ) ); 00260 $r[] = $this->msg( 'listgrouprights-addgroup', 00261 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), 00262 count( $add ) 00263 )->parse(); 00264 } 00265 00266 if ( $remove === true ) { 00267 $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped(); 00268 } elseif ( is_array( $remove ) && count( $remove ) ) { 00269 $remove = array_values( array_unique( $remove ) ); 00270 $r[] = $this->msg( 'listgrouprights-removegroup', 00271 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), 00272 count( $remove ) 00273 )->parse(); 00274 } 00275 00276 if ( $addSelf === true ) { 00277 $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped(); 00278 } elseif ( is_array( $addSelf ) && count( $addSelf ) ) { 00279 $addSelf = array_values( array_unique( $addSelf ) ); 00280 $r[] = $this->msg( 'listgrouprights-addgroup-self', 00281 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), 00282 count( $addSelf ) 00283 )->parse(); 00284 } 00285 00286 if ( $removeSelf === true ) { 00287 $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse(); 00288 } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) { 00289 $removeSelf = array_values( array_unique( $removeSelf ) ); 00290 $r[] = $this->msg( 'listgrouprights-removegroup-self', 00291 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), 00292 count( $removeSelf ) 00293 )->parse(); 00294 } 00295 00296 if ( empty( $r ) ) { 00297 return ''; 00298 } else { 00299 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>'; 00300 } 00301 } 00302 00303 protected function getGroupName() { 00304 return 'users'; 00305 } 00306 }