exception: Let MediaWiki.php control final output for ErrorPageError
[lhc/web/wiklou.git] / includes / exception / PermissionsError.php
index e31374c..9fa1c7c 100644 (file)
@@ -18,6 +18,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Show an error when a user tries to do something they do not have the necessary
  * permissions for.
@@ -45,10 +47,12 @@ class PermissionsError extends ErrorPageError {
                $this->permission = $permission;
 
                if ( !count( $errors ) ) {
-                       $groups = array_map(
-                               [ 'User', 'makeGroupLinkWiki' ],
-                               User::getGroupsWithPermission( $this->permission )
-                       );
+                       $groups = [];
+                       foreach ( MediaWikiServices::getInstance()
+                                                 ->getPermissionManager()
+                                                 ->getGroupsWithPermission( $this->permission ) as $group ) {
+                               $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
+                       }
 
                        if ( $groups ) {
                                $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ];
@@ -58,12 +62,17 @@ class PermissionsError extends ErrorPageError {
                }
 
                $this->errors = $errors;
+
+               // Give the parent class something to work with
+               parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
        }
 
-       public function report() {
+       public function report( $action = self::SEND_OUTPUT ) {
                global $wgOut;
 
                $wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
-               $wgOut->output();
+               if ( $action === self::SEND_OUTPUT ) {
+                       $wgOut->output();
+               }
        }
 }