KLNoSourceView

Jump to: navigation, search

This MediaWIki extension is used to restrict actions by users without edit privileges. Its main purpose is to prevent page source from being viewed.

Usage

Installing the extension restricts access for the entire site.

Installation

To install:

  • Copy the code from the code block at the end of this page to the file $IP/extensions/KLNoSourceView.php
  • Add this line to LocalSettings.php: require_once("$IP/extensions/KLNoSourceView.php");

Code

<?php
/**
 * KLNoSourceView.php
 * This extension denies edit actions to those without edit privileges
 * written by Kennylucius http://kennylucius.com/
 * LocalSettings.php file:
 * require_once("$IP/extensions/KLNoSourceView.php");
 */

if(! defined( 'MEDIAWIKI' ) ) {
    die("This is not a valid entry point.\n");
}

$wgExtensionCredits['other'][] = array(
	 'name' => 'KLNoSourceView',
	 'version' => '0.1',
	 'author' =>'Kenny Lucius', 
	 'url' => 'http://kennylucius.com/KLNoSourceView',
	 'description' => 'Restricts viewing of page source for all pages.'
	 );
 
$wgHooks['userCan'][] = 'KLNoSourceView_UserCan';

$KLNoSourceView_restrictedActions = array('edit', 'history', 'protect', 'move', 'delete');

function KLNoSourceView_UserCan($title, $user, $action, $result) {
	global $mediaWiki, $KLNoSourceView_restrictedActions, $wgMessageCache;
	if($user->isAllowed('edit')) {
		$result = null;
		return true;
	}
	if ( in_array($mediaWiki->GET['action'], $KLNoSourceView_restrictedActions) ) {
		if (! $user->isLoggedIn() ) {
			$wgMessageCache->addMessage('loginreqpagetext', 'You must be [[Special:Userlogin|logged in]] to access this function.' );
		}
		$result = false;
		return false;
	}
	$result = null;
	return true;
}
 
Personal tools