[Mediawiki-l] v1.10.1 - Namespace Protection

Jason Spirko jspirko at xorantech.com
Wed Jul 25 18:07:19 UTC 2007


I thought the new version of MediaWiki provides namespace protection which
is supposed to define who is able to edit a namespace. Am I just
misunderstanding the purpose of this?

http://www.mediawiki.org/wiki/Manual:$wgNamespaceProtection

In regards to the code below, should I be able to make a separate PHP file
and call it from LocalSettings.php?

Thanks again!

-----------------------------------
Jason Spirko
Systems Administrator
Xoran Technologies


-----Original Message-----
From: mediawiki-l-bounces at lists.wikimedia.org
[mailto:mediawiki-l-bounces at lists.wikimedia.org] On Behalf Of Platonides
Sent: Wednesday, July 25, 2007 12:30 PM
To: mediawiki-l at lists.wikimedia.org
Subject: Re: [Mediawiki-l] v1.10.1 - Namespace Protection

Jason Spirko wrote:
> Hi All:
> 
> Can somebody please explain how the namespace protection works in 
> v1.10 and how to implement it?
You need an extension to protect per namespace, thus the method used will
greatly vary with the extension chosen.


> I have several namespaces defined in my LocalSettings.php (see code
below).
> I want to be able to create user groups for each namespace and allow only
> that group associated with the namespace (and sysops of course) permission
> to edit pages (still allow others to read).
> 
> 	#
> 	# Custom Namespaces
> 	#
> 
> 	$wgExtraNamespaces =
> 	array(100 => "CSE",101 => "CSE_talk",
> 	102 => "IT",103 => "IT_talk",
> 	104 => "MarCom",105 => "MarCom_talk",
> 	106 => "OPS",107 => "OPS_talk",
> 	108 => "Sales",109 => "Sales_talk",
> 	);
> 
> 	#
> 	# End Custom Namespaces
> 	#
> 
 > Also, is there a way to allow a specific user group read permission 
to only
 > the main namespace and an additional namespace (ex. only Main & Sales)?
 >

Grant everybody else a permission to read the other namespaces.

> I just need to be pointed in the right direction. I've read the meta pages
> and I guess I just don't understand...



Your could use a code like this:

$wgPrivateNamespaces = array();
$wgHooks['userCan'][] = 'wfCheckNamespace';


function wfCheckNamespace( $title, $user, $action, &$result) {
     global $wgPrivateNamespaces;
     if ( $action == 'read' ) {
     if ( in_array( $title->getNamespace(), $wgPrivateNamespacesRead ) ) {
         if ( !$user->isAllowed( $wgPrivateNamespacesRead[
                 $title->getNamespace() ] ) ) {
             $result = false;
             return false;
         }
     }
     } else
     if ( in_array( $title->getNamespace(), $wgPrivateNamespaces ) ) {
         if ( !$user->isAllowed( $wgPrivateNamespaces[
                 $title->getNamespace() ] ) ) {
             $result = false;
             return false;
         }
     }
     }
     return true;
}


$wgPrivateNamespaces[100] = 'editCSE';
$wgPrivateNamespaces[101] = 'editCSE';
$wgPrivateNamespaces[102] = 'editIT';
$wgPrivateNamespaces[103] = 'editIT';
$wgPrivateNamespaces[104] = 'editMarCom';
...

$wgGroupPermissions['CSE']['editCSE'] = true;
$wgGroupPermissions['IT']['editIT'] = true;
$wgGroupPermissions['MarCom']['editMarCom'] = true;
...

$wgGroupPermissions['sysop']['editCSE'] = true;
$wgGroupPermissions['sysop']['editIT'] = true;
$wgGroupPermissions['sysop']['editMarCom'] = true;

...


//Restrict reading of CSE, IT, MarCom and OPS (and talk) namespaces
$wgPrivateNamespacesRead[100] = 'readMoreNamespaces';
$wgPrivateNamespacesRead[101] = 'readMoreNamespaces';
$wgPrivateNamespacesRead[102] = 'readMoreNamespaces';
$wgPrivateNamespacesRead[103] = 'readMoreNamespaces';
$wgPrivateNamespacesRead[104] = 'readMoreNamespaces';
$wgPrivateNamespacesRead[105] = 'readMoreNamespaces';
$wgPrivateNamespacesRead[106] = 'readMoreNamespaces';
$wgPrivateNamespacesRead[107] = 'readMoreNamespaces';


//to read them you need to be registered
$wgGroupPermissions['user' ]['readMoreNamespaces']            = true;



I practically copied PrivateNamespaces extension by amidaniel. Use at 
your own risk. If you know a bit of PHP, you should be able to customize 
it to do whatever you want.


_______________________________________________
MediaWiki-l mailing list
MediaWiki-l at lists.wikimedia.org
http://lists.wikimedia.org/mailman/listinfo/mediawiki-l


....................................................................................
This message (including any attachments) contains confidential and proprietary
information intended only for the addressee. If you are not the intended recipient, 
please notify the sender immediately by responding to this e-mail, and delete 
this message and attachments from your system. If you have any questions 
about this e-mail please notify the sender immediately. Any unauthorized 
disclosure, copying, distribution or reliance on the contents of this information 
is strictly prohibited and may constitute a violation of law. 





More information about the MediaWiki-l mailing list