]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialListgrouprights.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListgrouprights.php
index 910ffd0829b3cfa9ba8c1453b9e469526e8e94b0..2315887aa58342828e3c05957c43c646483a51cd 100644 (file)
  * @author Petr Kadlec <mormegil@centrum.cz>
  */
 class SpecialListGroupRights extends SpecialPage {
-
-       var $skin;
-
-       /**
-        * Constructor
-        */
        function __construct() {
-               global $wgUser;
                parent::__construct( 'Listgrouprights' );
-               $this->skin = $wgUser->getSkin();
        }
 
        /**
         * Show the special page
+        * @param string|null $par
         */
        public function execute( $par ) {
-               global $wgOut, $wgImplicitGroups;
-               global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
-               global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
-
                $this->setHeaders();
                $this->outputHeader();
 
-               $wgOut->addHTML(
-                       Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
+               $out = $this->getOutput();
+               $out->addModuleStyles( 'mediawiki.special' );
+
+               $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
+
+               $out->addHTML(
+                       Xml::openElement( 'table', [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
                                '<tr>' .
-                                       Xml::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
-                                       Xml::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
+                               Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
+                               Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
                                '</tr>'
                );
 
-               $allGroups = array_unique( array_merge( 
-                       array_keys( $wgGroupPermissions ),
-                       array_keys( $wgRevokePermissions ),
-                       array_keys( $wgAddGroups ),
-                       array_keys( $wgRemoveGroups ),
-                       array_keys( $wgGroupsAddToSelf ),
-                       array_keys( $wgGroupsRemoveFromSelf )
+               $config = $this->getConfig();
+               $groupPermissions = $config->get( 'GroupPermissions' );
+               $revokePermissions = $config->get( 'RevokePermissions' );
+               $addGroups = $config->get( 'AddGroups' );
+               $removeGroups = $config->get( 'RemoveGroups' );
+               $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
+               $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
+               $allGroups = array_unique( array_merge(
+                       array_keys( $groupPermissions ),
+                       array_keys( $revokePermissions ),
+                       array_keys( $addGroups ),
+                       array_keys( $removeGroups ),
+                       array_keys( $groupsAddToSelf ),
+                       array_keys( $groupsRemoveFromSelf )
                ) );
                asort( $allGroups );
-                               
+
+               $linkRenderer = $this->getLinkRenderer();
+
                foreach ( $allGroups as $group ) {
-                       $permissions = isset( $wgGroupPermissions[$group] ) 
-                               ? $wgGroupPermissions[$group] 
-                               : array();
+                       $permissions = isset( $groupPermissions[$group] )
+                               ? $groupPermissions[$group]
+                               : [];
                        $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
-                               ? 'all' 
-                               : $group; 
+                               ? 'all'
+                               : $group;
 
-                       $msg = wfMsg( 'group-' . $groupname );
-                       if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
-                               $groupnameLocalized = $groupname;
-                       } else {
-                               $groupnameLocalized = $msg;
-                       }
+                       $msg = $this->msg( 'group-' . $groupname );
+                       $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
 
-                       $msg = wfMsgForContent( 'grouppage-' . $groupname );
-                       if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
-                               $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
-                       } else {
-                               $grouppageLocalized = $msg;
-                       }
+                       $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
+                       $grouppageLocalized = !$msg->isBlank() ?
+                               $msg->text() :
+                               MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
+                       $grouppageLocalizedTitle = Title::newFromText( $grouppageLocalized );
 
-                       if( $group == '*' ) {
-                               // Do not make a link for the generic * group
+                       if ( $group == '*' || !$grouppageLocalizedTitle ) {
+                               // Do not make a link for the generic * group or group with invalid group page
                                $grouppage = htmlspecialchars( $groupnameLocalized );
                        } else {
-                               $grouppage = $this->skin->link(
-                                       Title::newFromText( $grouppageLocalized ),
-                                       htmlspecialchars( $groupnameLocalized )
+                               $grouppage = $linkRenderer->makeLink(
+                                       $grouppageLocalizedTitle,
+                                       $groupnameLocalized
                                );
                        }
 
                        if ( $group === 'user' ) {
                                // Link to Special:listusers for implicit group 'user'
-                               $grouplink = '<br />' . $this->skin->link(
+                               $grouplink = '<br />' . $linkRenderer->makeKnownLink(
                                        SpecialPage::getTitleFor( 'Listusers' ),
-                                       wfMsgHtml( 'listgrouprights-members' ),
-                                       array(),
-                                       array(),
-                                       array( 'known', 'noclasses' )
+                                       $this->msg( 'listgrouprights-members' )->text()
                                );
-                       } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
-                               $grouplink = '<br />' . $this->skin->link(
+                       } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
+                               $grouplink = '<br />' . $linkRenderer->makeKnownLink(
                                        SpecialPage::getTitleFor( 'Listusers' ),
-                                       wfMsgHtml( 'listgrouprights-members' ),
-                                       array(),
-                                       array( 'group' => $group ),
-                                       array( 'known', 'noclasses' )
+                                       $this->msg( 'listgrouprights-members' )->text(),
+                                       [],
+                                       [ 'group' => $group ]
                                );
                        } else {
                                // No link to Special:listusers for other implicit groups as they are unlistable
                                $grouplink = '';
                        }
 
-                       $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
-                       $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
-                       $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
-                       $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
-                       $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
+                       $revoke = isset( $revokePermissions[$group] ) ? $revokePermissions[$group] : [];
+                       $addgroups = isset( $addGroups[$group] ) ? $addGroups[$group] : [];
+                       $removegroups = isset( $removeGroups[$group] ) ? $removeGroups[$group] : [];
+                       $addgroupsSelf = isset( $groupsAddToSelf[$group] ) ? $groupsAddToSelf[$group] : [];
+                       $removegroupsSelf = isset( $groupsRemoveFromSelf[$group] )
+                               ? $groupsRemoveFromSelf[$group]
+                               : [];
 
-                       $id = $group == '*' ? false : Sanitizer::escapeId( $group );
-                       $wgOut->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
-                               "
+                       $id = $group == '*' ? false : Sanitizer::escapeIdForAttribute( $group );
+                       $out->addHTML( Html::rawElement( 'tr', [ 'id' => $id ], "
                                <td>$grouppage$grouplink</td>
                                        <td>" .
-                                               self::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
+                                       $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
+                                               $addgroupsSelf, $removegroupsSelf ) .
                                        '</td>
                                '
                        ) );
                }
-               $wgOut->addHTML(
-                       Xml::closeElement( 'table' ) . "\n<br /><hr />\n"
+               $out->addHTML( Xml::closeElement( 'table' ) );
+               $this->outputNamespaceProtectionInfo();
+       }
+
+       private function outputNamespaceProtectionInfo() {
+               global $wgParser, $wgContLang;
+               $out = $this->getOutput();
+               $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
+
+               if ( count( $namespaceProtection ) == 0 ) {
+                       return;
+               }
+
+               $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
+               $out->addHTML(
+                       Html::rawElement( 'h2', [], Html::element( 'span', [
+                               'class' => 'mw-headline',
+                               'id' => $wgParser->guessSectionNameFromWikiText( $header )
+                       ], $header ) ) .
+                       Xml::openElement( 'table', [ 'class' => 'wikitable' ] ) .
+                       Html::element(
+                               'th',
+                               [],
+                               $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
+                       ) .
+                       Html::element(
+                               'th',
+                               [],
+                               $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
+                       )
                );
-               $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
+               $linkRenderer = $this->getLinkRenderer();
+               ksort( $namespaceProtection );
+               foreach ( $namespaceProtection as $namespace => $rights ) {
+                       if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
+                               continue;
+                       }
+
+                       if ( $namespace == NS_MAIN ) {
+                               $namespaceText = $this->msg( 'blanknamespace' )->text();
+                       } else {
+                               $namespaceText = $wgContLang->convertNamespace( $namespace );
+                       }
+
+                       $out->addHTML(
+                               Xml::openElement( 'tr' ) .
+                               Html::rawElement(
+                                       'td',
+                                       [],
+                                       $linkRenderer->makeLink(
+                                               SpecialPage::getTitleFor( 'Allpages' ),
+                                               $namespaceText,
+                                               [],
+                                               [ 'namespace' => $namespace ]
+                                       )
+                               ) .
+                               Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
+                       );
+
+                       if ( !is_array( $rights ) ) {
+                               $rights = [ $rights ];
+                       }
+
+                       foreach ( $rights as $right ) {
+                               $out->addHTML(
+                                       Html::rawElement( 'li', [], $this->msg(
+                                               'listgrouprights-right-display',
+                                               User::getRightDescription( $right ),
+                                               Html::element(
+                                                       'span',
+                                                       [ 'class' => 'mw-listgrouprights-right-name' ],
+                                                       $right
+                                               )
+                                       )->parse() )
+                               );
+                       }
+
+                       $out->addHTML(
+                               Xml::closeElement( 'ul' ) .
+                               Xml::closeElement( 'td' ) .
+                               Xml::closeElement( 'tr' )
+                       );
+               }
+               $out->addHTML( Xml::closeElement( 'table' ) );
        }
 
        /**
         * Create a user-readable list of permissions from the given array.
         *
-        * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
-        * @param $revoke Array of permission => bool (from $wgRevokePermissions items)
-        * @param $add Array of groups this group is allowed to add or true
-        * @param $remove Array of groups this group is allowed to remove or true
-        * @param $addSelf Array of groups this group is allowed to add to self or true
-        * @param $removeSelf Array of group this group is allowed to remove from self or true
+        * @param array $permissions Array of permission => bool (from $wgGroupPermissions items)
+        * @param array $revoke Array of permission => bool (from $wgRevokePermissions items)
+        * @param array $add Array of groups this group is allowed to add or true
+        * @param array $remove Array of groups this group is allowed to remove or true
+        * @param array $addSelf Array of groups this group is allowed to add to self or true
+        * @param array $removeSelf Array of group this group is allowed to remove from self or true
         * @return string List of all granted permissions, separated by comma separator
         */
-        private static function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
-               global $wgLang;
-
-               $r = array();
-               foreach( $permissions as $permission => $granted ) {
-                       //show as granted only if it isn't revoked to prevent duplicate display of permissions
-                       if( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
-                               $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
+       private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
+               $r = [];
+               foreach ( $permissions as $permission => $granted ) {
+                       // show as granted only if it isn't revoked to prevent duplicate display of permissions
+                       if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
+                               $r[] = $this->msg( 'listgrouprights-right-display',
                                        User::getRightDescription( $permission ),
                                        '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
-                               );
-                               $r[] = $description;
+                               )->parse();
                        }
                }
-               foreach( $revoke as $permission => $revoked ) {
-                       if( $revoked ) {
-                               $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
+               foreach ( $revoke as $permission => $revoked ) {
+                       if ( $revoked ) {
+                               $r[] = $this->msg( 'listgrouprights-right-revoked',
                                        User::getRightDescription( $permission ),
                                        '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
-                               );
-                               $r[] = $description;
+                               )->parse();
                        }
                }
+
                sort( $r );
-               if( $add === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
-               } else if( is_array( $add ) && count( $add ) ) {
-                       $add = array_values( array_unique( $add ) );
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
-               }
-               if( $remove === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
-               } else if( is_array( $remove ) && count( $remove ) ) {
-                       $remove = array_values( array_unique( $remove ) );
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
-               }
-               if( $addSelf === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
-               } else if( is_array( $addSelf ) && count( $addSelf ) ) {
-                       $addSelf = array_values( array_unique( $addSelf ) );
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
-               }
-               if( $removeSelf === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
-               } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
-                       $removeSelf = array_values( array_unique( $removeSelf ) );
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
+
+               $lang = $this->getLanguage();
+               $allGroups = User::getAllGroups();
+
+               $changeGroups = [
+                       'addgroup' => $add,
+                       'removegroup' => $remove,
+                       'addgroup-self' => $addSelf,
+                       'removegroup-self' => $removeSelf
+               ];
+
+               foreach ( $changeGroups as $messageKey => $changeGroup ) {
+                       if ( $changeGroup === true ) {
+                               // For grep: listgrouprights-addgroup-all, listgrouprights-removegroup-all,
+                               // listgrouprights-addgroup-self-all, listgrouprights-removegroup-self-all
+                               $r[] = $this->msg( 'listgrouprights-' . $messageKey . '-all' )->escaped();
+                       } elseif ( is_array( $changeGroup ) ) {
+                               $changeGroup = array_intersect( array_values( array_unique( $changeGroup ) ), $allGroups );
+                               if ( count( $changeGroup ) ) {
+                                       $groupLinks = [];
+                                       foreach ( $changeGroup as $group ) {
+                                               $groupLinks[] = UserGroupMembership::getLink( $group, $this->getContext(), 'wiki' );
+                                       }
+                                       // For grep: listgrouprights-addgroup, listgrouprights-removegroup,
+                                       // listgrouprights-addgroup-self, listgrouprights-removegroup-self
+                                       $r[] = $this->msg( 'listgrouprights-' . $messageKey,
+                                               $lang->listToText( $groupLinks ), count( $changeGroup ) )->parse();
+                               }
+                       }
                }
-               if( empty( $r ) ) {
+
+               if ( empty( $r ) ) {
                        return '';
                } else {
                        return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
                }
        }
+
+       protected function getGroupName() {
+               return 'users';
+       }
 }