User:Hoggwild5/Restricting Access to User Pages

The following is a code modification (hack) that restricts edit access on user pages to the user to whom the page belongs and system administrators (sysops). This hack allows for the creation of subpages (i.e., User/Subpage) that are also restricted, but allows all users to edit user talk pages per overall site permissions.

This code hack was originally authored by gauravpahuja, a user of the MediaWiki user's forums, and modified by Hoggwild5.

'''Please note: this is not an extension, it is a code hack. As such, there is the possibility that these changes will be overwritten if the MediaWiki source files are updated. I've been trying to figure out how to write this as an extension; if you can provide any insight into that process I would be very appreciative of your contribution. My programming skills are rudimentary at best.'''

This has been tested and verified to work on the following versions of MediaWiki:


 * Version 1.8.2
 * Version 1.8.3
 * Version 1.6.9
 * Version 1.9.2

I don't check my user page here that often, but as a moderator on the MediaWiki User's forum I do log in there almost every day. If you have questions or comments on this code hack, please leave me a message on the MediaWiki User's Forum (I am user "hoggwild") found at:

http://www.mwusers.com/

Go to includes/Title.php and change the two functions userCanEdit and userCanMove to read as follows:
function userCanEdit { global $wgOnlyUserEditUserPage; global $wgUser; if(NS_USER == $this->mNamespace && $wgOnlyUserEditUserPage) { return ($wgUser->isAllowed('editalluserpages')|| (substr_count($this->getText, $wgUser->getName) > 0)); } else { return $this->userCan('edit'); } }

function userCanMove { global $wgOnlyUserEditUserPage; global $wgUser; if(NS_USER == $this->mNamespace && $wgOnlyUserEditUserPage) { return ($wgUser->isAllowed('editalluserpages')|| (substr_count($this->getText, $wgUser->getName) > 0)); } else { return $this->userCan('move'); } } !

Add the following code to LocalSettings.php
$wgOnlyUserEditUserPage = true; $wgGroupPermissions['sysop']['editalluserpages'] = true;

The second line allows Adminstrators (sysops) to edit anyone's Personal pages.