Extension:UserPageEditProtection
From MediaWiki.org
|
Release status: stable |
|||
|---|---|---|---|
| Implementation | User rights | ||
| Description | Restricts edit access to user pages | ||
| Author(s) | Lisa Ridley, Eric Gingell | ||
| Last Version | 1.00, 2.00 (6 December 2007) | ||
| MediaWiki | versions 1.6.x, 1.7.x, 1.8.x, 1.9.x, 1.10.x (use version 1.0); version 1.11, 1.12, 1.14 (use version 2.0) | ||
| License | GPL | ||
| Download | Code below | ||
|
|||
|
check usage (experimental) |
|||
Contents |
[edit] 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.
Note: MediaWiki version 1.11 underwent significant coding changes to the core code, which rendered version 1.0 of this extension obsolete. Version 2.0 has been rewritten to function with MediaWiki version 1.11+.
[edit] Installation
Save the code below in your extensions folder of your MediaWiki installation as UserPageEditProtection.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/UserPageEditProtection.php" ); /* Add this to activate the extension. */
[edit] Code
[edit] MediaWiki versions 1.6 through 1.10
For MediaWiki versions 1.6 through 1.10, 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: 5 December 2007 * Author: Lisa Ridley, Eric Gingell * Version: 1.0 * 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, Eric Gingell', 'version' => '1.0', '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 $wgNamespaceProtection, $wgOnlyUserEditUserPage; $lTitle = explode('/', $title->getText()); if ($action == 'edit'||$action == 'move') { if (NS_USER == $title->mNamespace) { if ($wgOnlyUserEditUserPage) { $result = ($user->isAllowed('editalluserpages') || ($lTitle[0] == $user->getName())); } else { $result = false; } } } return true; } }
[edit] MediaWiki version 1.11+ (works with version 1.12)
For MediaWiki version 1.11+, copy the following code and save as "extensions/UserPageEditProtection.php":
Note: If you have problems accessing your site after making this change, look in the HTTPD error log for an error message about this extension. > tail /etc/httpd/logs/error_log. If you see "Failed opening required 'extensions/UserPageEditProtection/UserPageEditProtection.php", create a extensions/UserPageEditProtection/ directory and move UserPageEditProtection.php to extensions/UserPageEditProtection/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: 6 December 2007 * Author: Lisa Ridley, Eric Gingell * Version: 2.0 * 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, Eric Gingell', 'version' => '2.0', '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 $wgOnlyUserEditUserPage; $lTitle = explode('/', $title->getText()); if (!($action == 'edit'||$action == 'move')) { $result = null; return true; } if (NS_USER !== $title->mNamespace) { $result = null; return true; } if ($wgOnlyUserEditUserPage) { if ($user->isAllowed('editalluserpages') || ($lTitle[0] == $user->getname())) { $result = null; return true; } else { $result = false; return false; } } $result = null; return true; } }
[edit] MediaWiki Versions
- Version 1.0 of this extension has been tested and works fine on MediaWiki versions 1.6.x, 1.7.x, 1.8.x, 1.9.x and 1.10.x.
- Version 2.0 of this extension has been tested and works fine on MediaWiki version 1.11.x, 1.12.x, 1.13.x and 1.14alpha.