Difference between revisions of "How to Block User Rights"
Jump to navigation
Jump to search
Dsteinmark (talk | contribs) (Created page with "Need to edit: /home/wasteam8/public_html/mentor.wiki/LocalSettings.php Add this to the bottom: # Regulate user group permissions. $wgGroupPermissions['*']['userrights'] =...") |
Dsteinmark (talk | contribs) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | Need to edit: | + | '''Need to edit: |
| − | /home/wasteam8/public_html/mentor.wiki/LocalSettings.php | + | /home/wasteam8/public_html/mentor.wiki/LocalSettings.php''' |
Add this to the bottom: | Add this to the bottom: | ||
| Line 9: | Line 9: | ||
$wgGroupPermissions['administrators']['userrights'] = false; | $wgGroupPermissions['administrators']['userrights'] = false; | ||
| − | Need to edit: | + | # Disallow unregistered users from editing |
| + | $wgGroupPermissions['*']['edit'] = false; | ||
| + | |||
| + | '''Need to edit: | ||
/home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialUserrights.php | /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialUserrights.php | ||
/home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialListusers.php | /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialListusers.php | ||
| Line 15: | Line 18: | ||
/home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialBlockList.php | /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialBlockList.php | ||
/home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialListgrants.php | /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialListgrants.php | ||
| − | /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialActiveusers.php | + | /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialActiveusers.php''' |
Add this function: | Add this function: | ||
| Line 27: | Line 30: | ||
} | } | ||
| − | Note the following please: | + | ''Note the following please:'' |
In the function above, 'userrights', means the group rights set in LocalSettings.php. | In the function above, 'userrights', means the group rights set in LocalSettings.php. | ||
| Line 50: | Line 53: | ||
} | } | ||
| − | Note the following please: | + | '''Note the following please:''' |
The functions: | The functions: | ||
| Line 67: | Line 70: | ||
Will allow arbitrary non-standard messages if a user is denied access to one of these special pages. | Will allow arbitrary non-standard messages if a user is denied access to one of these special pages. | ||
| − | Also note the following please: | + | '''Also note the following please:''' |
Some pages are already protected by MediaWiki's authorization manager. | Some pages are already protected by MediaWiki's authorization manager. | ||
These pages don't require this function to be called: | These pages don't require this function to be called: | ||
$this->requireLogin(); | $this->requireLogin(); | ||
| + | |||
| + | Relevant Links: | ||
| + | https://www.mediawiki.org/wiki/Manual:Preventing_access | ||
Latest revision as of 16:17, 3 August 2018
Need to edit: /home/wasteam8/public_html/mentor.wiki/LocalSettings.php
Add this to the bottom:
# Regulate user group permissions. $wgGroupPermissions['*']['userrights'] = false; $wgGroupPermissions['user']['userrights'] = false; $wgGroupPermissions['administrators']['userrights'] = false;
# Disallow unregistered users from editing $wgGroupPermissions['*']['edit'] = false;
Need to edit:
/home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialUserrights.php /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialListusers.php /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialListgrouprights.php /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialBlockList.php /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialListgrants.php /home/wasteam8/public_html/mentor.wiki/includes/specials/SpecialActiveusers.php
Add this function:
public function userCanExecute( $user ) {
global $wgUser;
if ( $wgUser->isLoggedIn() ) {
return $user->isAllowed( 'userrights' );
} else {
return false;
}
}
Note the following please:
In the function above, 'userrights', means the group rights set in LocalSettings.php. So granular controls can be implemented by changing these values.
Edit this function:
public function execute( $par ) {
$user = $this->getUser();
$request = $this->getRequest();
$session = $request->getSession();
$out = $this->getOutput();
Add this section:
$this->getOutput()->disallowUserJs(); // Disable client side JavaScript to block XSS attacks.
$this->requireLogin(); // Force a login if the user is not logged in.
// This part alone would also block users not logged in, it will further deny users without the proper rights.
// See existing section noted above: $user = $this->getUser();
if ( !$this->userCanExecute( $user ) ) {
// $this->getOutput()->addWikiText( "Permission Denied!" );
throw new PermissionsError( $this->mRestriction );
return;
}
Note the following please:
The functions: $this->mRestriction $this->displayRestrictionError() (As seen in the link below for 'Special Pages : Restricting Page Access' Will both display HTML denial messages that look like the following: Permission error ---------------------------------------------------------------- You do not have permission to do that, for the following reason: You are not allowed to execute the action you have requested. However this function: $this->getOutput()->addWikiText( "Permission Denied!" ) Will allow arbitrary non-standard messages if a user is denied access to one of these special pages.
Also note the following please:
Some pages are already protected by MediaWiki's authorization manager. These pages don't require this function to be called: $this->requireLogin();
Relevant Links:
https://www.mediawiki.org/wiki/Manual:Preventing_access