Extension:UserPageEditProtection

What can this extension do?
This extension will restrict edit access to user pages to the owner of the page (user) and users assigned to groups that have been given user page edit access through $wgGroupPermissions. This effectively provides users with a group of protected pages since this protection also extends to any subpages of the user page (i.e., User:Hoggwild/sandbox1). The User pages can be read by any user assigned to a group with view rights to user pages, but can only be edited by authorized users.

This extension has no effect on user talk pages.

Sysops should probably be provided the ability to edit all user pages to remove user page content that violates the provisions of the wiki. Other user groups can be provided the ability to edit user pages by assigning permission through $wgGroupPermissions as well.

Installation
Save the code below in your extensions folder of your MediaWiki installation as UserPageEditProtection.php. Add the following to LocalSettings.php:
 * $wgOnlyUserEditUserPage = true; /**< Set this to true to turn on user page protection */
 * $wgGroupPermissions['sysop']['editalluserpages'] = true; /**< Set this to allow sysops to edit all user pages */
 * require_once('extensions/UserPageEditProtection.php'); /**< Add this to activate the extension */

Changes to LocalSettings.php
Add the following to your LocalSettings.php file:

$wgOnlyUserEditUserPage = true; /**< Set this to true to turn on user page protection */ $wgGroupPermissions['sysop']['editalluserpages'] = true; /**< Set this to allow sysops to edit all user pages */

require_once("extensions/UserPageEditProtection.php" );

Code
'''Copy the following code and save as "extensions/UserPageEditProtection.php": <?php if(! defined( 'MEDIAWIKI' ) ) { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); } else { /** * Extension: UserPageEditProtection.php * Created: 26 May 2007 * Author: Lisa Ridley * Version: 0.9 beta * Copyright (C) 2007 Lisa Ridley * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You can find a copy of the GNU General Public License at http://www.gnu.org/copyleft/gpl.html * A paper copy can be obtained by writing to: Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * User Page Edit Protection * * Provides User Page Edit Protection to limit user page edits to User and to sysops. * * * Usage: * Save this file in your extensions folder of your MediaWiki installation. Add the following to LocalSettings.php: *   //turn on user page protection *   $wgOnlyUserEditUserPage = true; *   //allow sysops to edit user pages by adding the following setting *   $wgGroupPermissions['sysop']['editalluserpages'] = true; *   require_once('extensions/UserPageEditProtection.php'); **/

global $wgHooks;

/* use the userCan hook to check user page edit permissions */ $wgHooks[ 'userCan' ][] = 'fnUserPageEditProtection';

/* register extension */ $wgExtensionCredits['other'][] = array(  'name'=>'UserPageEditProtection',   'author' => 'Lisa Ridley',   'version' => '0.9 beta',   'url' => 'http://www.mediawiki.org/wiki/Extension:UserPageEditProtection',   'description' => 'This Extension restricts editing on user pages to User and allowed editors');

function fnUserPageEditProtection( &$title, &$user, $action, &$result ) {   global $wgUser, $wgNamespaceProtection, $wgOnlyUserEditUserPage;

if ($action == 'edit') { if (NS_USER == $title->mNamespace) { if ($wgOnlyUserEditUserPage) { $result = ($wgUser->isAllowed('editalluserpages')|| (substr_count($title->getText, $wgUser->getName) > 0)); } else { $result = false; }      }    }    if ($action == 'move') { if (NS_USER == $title->mNamespace) { if ($wgOnlyUserEditUserPage) { $result = ($wgUser->isAllowed('editalluserpages')|| (substr_count($title->getText, $wgUser->getName) > 0)); } else { $result = false; }      }    } } } ?>

MediaWiki Versions
This extension has been tested and appears to work fine on MediaWiki version 1.10. It has not been tested on prior versions of MediaWiki at this time. Once the extension is deemed stable and testing has been conducted on other stable MediaWiki versions (1.6.10, 1.8.4 and 1.9.3 at this time), this page will be updated to reflect the versions tested and the extension will be released as a stable version.