How to Block User Rights

From FRC11 - Mentor Wiki
Jump to navigation Jump to search

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