Extension:NoAnonymous

From MediaWiki.org
Jump to: navigation, search


MediaWiki extensions manual - list
Crystal Clear action run.png
NoAnonymous

Release status: beta

Implementation User rights
Description
Author(s) Charles de BeauchesneTalk
License GPL
Download No link
Hooks used
userCan

Check usage (experimental)

Contents

[edit] What can this extension do?

  1. Prevent access from non_logged user;
  2. Automatically redirect non-logged user to Special:Userlogin;
  3. After successful login, redirect user to main page

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/NoAnonymous/NoAnonymous.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/NoAnonymous/NoAnonymous.php");
Important!
You must include this extension before other extensions in localSettings.

[edit] Code

<?php
/* NoAnonymous - MediaWiki extension
 
* Add extension information to Special:Version
*/
$wgExtensionCredits['other'][] = array(
        'name' => 'NoAnonymous',
        'version' => '',
        'author' => 'Charles de Beauchesne',
        'description' => 'Restrict acces to logged user',
        'url' => 'http://www.mediawiki.org/wiki/Extension:NoAnonymous'
        ); 
 
$wgGroupPermissions['*'    ]['createaccount']   = false;
$wgGroupPermissions['*'    ]['read']            = false;
$wgGroupPermissions['*'    ]['edit']            = false;
$wgGroupPermissions['*'    ]['createpage']      = false;
$wgGroupPermissions['*'    ]['createtalk']      = false;
 
$wgExtensionFunctions[] = "wfNoAnonymous";
 
function wfNoAnonymous() 
{
        global $wgHooks;
 
        $wgHooks[ 'userCan' ][] = 'noAnonymousFoo';
}
 
function noAnonymousFoo( $title, $user, $action, $result )
{
 
        if(!$user->isAnon())
        {
                if($title->isSpecial( 'Userlogin' ) && !in_array("sysop", $user->getGroups()))
                        header("Location:http://".$_SERVER["SERVER_NAME"]."/wiki/");
        }
        else
        {
                global $wgWhitelistRead;
 
                if( $title->isSpecial( 'Userlogin' ) || $title->isSpecial( 'Resetpass' ) ) return true;
                if(is_array($wgWhitelistRead) )
                {
                        $name = $title->getPrefixedText();
                        $dbName = $title->getPrefixedDBKey();
                        if( in_array($name,$wgWhitelistRead,true) || in_array($dbName,$wgWhitelistRead,true) ) return true;
                }
 
                header("Location:http://".$_SERVER["SERVER_NAME"]."/wiki/special:Userlogin");
        }
 
        return true;
}
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox