Merge "Changed LoginForm::addNewaccountInternal() to return Status."
[lhc/web/wiklou.git] / includes / specials / SpecialListgrouprights.php
index 9a35336..1f95c22 100644 (file)
@@ -1,4 +1,25 @@
 <?php
+/**
+ * Implements Special:Listgrouprights
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
 
 /**
  * This special page lists all defined user groups and the associated rights.
  */
 class SpecialListGroupRights extends SpecialPage {
 
-       var $skin;
-
        /**
         * Constructor
         */
        function __construct() {
-               global $wgUser;
                parent::__construct( 'Listgrouprights' );
-               $this->skin = $wgUser->getSkin();
        }
 
        /**
         * Show the special page
         */
        public function execute( $par ) {
-               global $wgOut, $wgImplicitGroups, $wgMessageCache;
+               global $wgImplicitGroups;
                global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
                global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
-               $wgMessageCache->loadAllMessages();
 
                $this->setHeaders();
                $this->outputHeader();
 
-               $wgOut->addHTML(
+               $out = $this->getOutput();
+               $out->addModuleStyles( 'mediawiki.special' );
+
+               $out->addHTML(
                        Xml::openElement( 'table', array( '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>'
                );
 
-               foreach( $wgGroupPermissions as $group => $permissions ) {
-                       $groupname = ( $group == '*' ) ? 'all' : $group; // Replace * with a more descriptive groupname
+               $allGroups = array_unique( array_merge(
+                       array_keys( $wgGroupPermissions ),
+                       array_keys( $wgRevokePermissions ),
+                       array_keys( $wgAddGroups ),
+                       array_keys( $wgRemoveGroups ),
+                       array_keys( $wgGroupsAddToSelf ),
+                       array_keys( $wgGroupsRemoveFromSelf )
+               ) );
+               asort( $allGroups );
 
-                       $msg = wfMsg( 'group-' . $groupname );
-                       if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
-                               $groupnameLocalized = $groupname;
-                       } else {
-                               $groupnameLocalized = $msg;
-                       }
+               foreach ( $allGroups as $group ) {
+                       $permissions = isset( $wgGroupPermissions[$group] )
+                               ? $wgGroupPermissions[$group]
+                               : array();
+                       $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
+                               ? 'all'
+                               : $group;
 
-                       $msg = wfMsgForContent( 'grouppage-' . $groupname );
-                       if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
-                               $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
-                       } else {
-                               $grouppageLocalized = $msg;
-                       }
+                       $msg = $this->msg( 'group-' . $groupname );
+                       $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
+
+                       $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
+                       $grouppageLocalized = !$msg->isBlank() ?
+                               $msg->text() :
+                               MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
 
                        if( $group == '*' ) {
                                // Do not make a link for the generic * group
-                               $grouppage = htmlspecialchars($groupnameLocalized);
+                               $grouppage = htmlspecialchars( $groupnameLocalized );
                        } else {
-                               $grouppage = $this->skin->link(
+                               $grouppage = Linker::link(
                                        Title::newFromText( $grouppageLocalized ),
-                                       htmlspecialchars($groupnameLocalized)
+                                       htmlspecialchars( $groupnameLocalized )
                                );
                        }
 
                        if ( $group === 'user' ) {
                                // Link to Special:listusers for implicit group 'user'
-                               $grouplink = '<br />' . $this->skin->link(
+                               $grouplink = '<br />' . Linker::linkKnown(
                                        SpecialPage::getTitleFor( 'Listusers' ),
-                                       wfMsgHtml( 'listgrouprights-members' ),
-                                       array(),
-                                       array(),
-                                       array( 'known', 'noclasses' )
+                                       $this->msg( 'listgrouprights-members' )->escaped()
                                );
                        } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
-                               $grouplink = '<br />' . $this->skin->link(
+                               $grouplink = '<br />' . Linker::linkKnown(
                                        SpecialPage::getTitleFor( 'Listusers' ),
-                                       wfMsgHtml( 'listgrouprights-members' ),
+                                       $this->msg( 'listgrouprights-members' )->escaped(),
                                        array(),
-                                       array( 'group' => $group ),
-                                       array( 'known', 'noclasses' )
+                                       array( 'group' => $group )
                                );
                        } else {
                                // No link to Special:listusers for other implicit groups as they are unlistable
@@ -95,21 +119,21 @@ class SpecialListGroupRights extends SpecialPage {
                        $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
                        $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
 
-                       $wgOut->addHTML(
-                               '<tr>
-                                       <td>' .
-                                               $grouppage . $grouplink .
-                                       '</td>
-                                       <td>' .
-                                               self::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
+                       $id = $group == '*' ? false : Sanitizer::escapeId( $group );
+                       $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
+                               "
+                               <td>$grouppage$grouplink</td>
+                                       <td>" .
+                                               $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
+                                                       $addgroupsSelf, $removegroupsSelf ) .
                                        '</td>
-                               </tr>'
-                       );
+                               '
+                       ) );
                }
-               $wgOut->addHTML(
+               $out->addHTML(
                        Xml::closeElement( 'table' ) . "\n<br /><hr />\n"
                );
-               $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1</div>",'listgrouprights-key' );
+               $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
        }
 
        /**
@@ -123,48 +147,64 @@ class SpecialListGroupRights extends SpecialPage {
         * @param $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;
+        private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
                $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' ),
+                               $description = $this->msg( 'listgrouprights-right-display',
                                        User::getRightDescription( $permission ),
-                                       $permission
-                               );
+                                       '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
+                               )->parse();
                                $r[] = $description;
                        }
                }
                foreach( $revoke as $permission => $revoked ) {
                        if( $revoked ) {
-                               $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
+                               $description = $this->msg( 'listgrouprights-right-revoked',
                                        User::getRightDescription( $permission ),
-                                       $permission
-                               );
+                                       '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
+                               )->parse();
                                $r[] = $description;
                        }
                }
                sort( $r );
+               $lang = $this->getLanguage();
                if( $add === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
-               } else if( is_array( $add ) && count( $add ) ) {
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
+                       $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
+               } elseif( is_array( $add ) && count( $add ) ) {
+                       $add = array_values( array_unique( $add ) );
+                       $r[] = $this->msg( 'listgrouprights-addgroup',
+                               $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
+                               count( $add )
+                       )->parse();
                }
                if( $remove === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
-               } else if( is_array( $remove ) && count( $remove ) ) {
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
+                       $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
+               } elseif( is_array( $remove ) && count( $remove ) ) {
+                       $remove = array_values( array_unique( $remove ) );
+                       $r[] = $this->msg( 'listgrouprights-removegroup',
+                               $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
+                               count( $remove )
+                       )->parse();
                }
                if( $addSelf === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
-               } else if( is_array( $addSelf ) && count( $addSelf ) ) {
-                       $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
+                       $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
+               } elseif( is_array( $addSelf ) && count( $addSelf ) ) {
+                       $addSelf = array_values( array_unique( $addSelf ) );
+                       $r[] = $this->msg( 'listgrouprights-addgroup-self',
+                               $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
+                               count( $addSelf )
+                       )->parse();
                }
                if( $removeSelf === true ){
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
-               } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
-                       $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
+                       $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
+               } elseif( is_array( $removeSelf ) && count( $removeSelf ) ) {
+                       $removeSelf = array_values( array_unique( $removeSelf ) );
+                       $r[] = $this->msg( 'listgrouprights-removegroup-self',
+                               $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
+                               count( $removeSelf )
+                       )->parse();
                }
                if( empty( $r ) ) {
                        return '';