SpecialListgrouprights.php 4.2 KB

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