Open main menu

Extension:ForceLogin

MediaWiki extensions manual
OOjs UI icon advanced.svg
ForceLogin
Release status: unmaintained
Implementation MyWiki
Description Forces login on Edit action of a page and redirects user back to the edit page on login.
Author(s) Kuldeep Ghogre, Manit Hirani (manithiranitalk)
Latest version 1.0 (2013-02-06)
MediaWiki 1.23+
PHP 5.3+
Database changes No
License GNU General Public License 2.0 or later
Download See the code section
Hooks used
AlternateEdit
Translate the ForceLogin extension if it is available at translatewiki.net
Check usage and version matrix.

The ForceLogin extension forces login on Edit action of a page and redirects user back to the edit page on login.

InstallationEdit

  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/ForceLogin/ForceLogin.php";
    
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

CodeEdit

ForceLogin.php
<?php
/**
 * ForceLogin extension
 * @file ForceLogin.php
 * @version 1.0
 * @author Manit Hirani (manithirani)
 * @author Kuldeep Ghogre
 * @link https://www.mediawiki.org/wiki/Extension:ForceLogin
 * @license GPL-2.0-or-later
 */

if ( !defined( 'MEDIAWIKI' ) ) {
	exit;
}
	
$wgExtensionCredits['other'][] = array(
       'path' => __FILE__,
       'name' => 'ForceLogin',
       'author' =>array('Manit Hirani','Kuldeep Ghogre'),
       'description' => 'Redirects to login page on edit action',
       'url' => 'https://www.mediawiki.org/wiki/Extension:ForceLogin',
       'version'  => 1.0,
       'license-name' => 'GPL-2.0-or-later'
       );

$wgHooks['AlternateEdit'][]='redirectOnEdit';

function redirectOnEdit($editPage){
	global $wgUser, $wgOut, $wgTitle, $wgScriptPath;
	if(!$wgUser->isLoggedIn()){
		$wgOut->redirect($wgScriptPath.'/index.php?title=Special:UserLogin&returnto='.$wgTitle.'&returntoquery=action%3Dedit');
	}
	return true;
}