Utilisateur:Copernik : Différence entre versions

De Apocalypsis
Sauter à la navigation Sauter à la recherche
Ligne 126 : Ligne 126 :
 
<div style="color:#FFFFFF" valign="middle"></div>
 
<div style="color:#FFFFFF" valign="middle"></div>
 
|}
 
|}
 +
 +
 +
<?php
 +
/* NamespacePermissions - MediaWiki extension
 +
*
 +
* provides separate permissions for each action (read,edit,create,move)
 +
* on articles in custom namespaces for fine access management
 +
*
 +
* Author: Petr Andreev
 +
*
 +
* Sample usage:
 +
*
 +
* $wgExtraNamespaces = array(100 => "Foo", 101 => "Foo_Talk");
 +
* // optional (example): allow registered users to view and edit articles in Foo
 +
* $wgGroupPermissions[ 'user' ][ 'ns100_read' ] = true;
 +
* $wgGroupPermissions[ 'user' ][ 'ns100_edit' ] = true;
 +
* // end of optional
 +
* require('extensions/NamespacePermissions.php');
 +
*
 +
* Permissions provided:
 +
*  # ns{$num}_read
 +
*  # ns{$num}_edit
 +
*  # ns{$num}_create
 +
*  # ns{$num}_move
 +
* where {$num} - namespace number (e.g. ns100_read, ns101_create)
 +
*
 +
* Groups provided:
 +
*  # ns{$title}RW - full access to the namespace {$title}
 +
*  # ns{$title}RO - read-only access to the namespace {$title}
 +
*  e.g. nsFoo_talkRW, nsFooRO
 +
*/
 +
 +
// permissions for autocreated groups should be set now,
 +
// before the User object for current user is instantiated
 +
namespacePermissionsCreateGroups();
 +
// other stuff should better be done via standard mechanism of running extensions
 +
$wgExtensionFunctions[] = "wfNamespacePermissions";
 +
 +
// create groups for each custom namespace
 +
function namespacePermissionsCreateGroups() {
 +
    global $wgExtraNamespaces, $wgGroupPermissions;
 +
    foreach ( $wgExtraNamespaces as $num => $title ) {
 +
        $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_edit" ] = true;
 +
        $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_read" ] = true;
 +
        $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_create" ] = true;
 +
        $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_move" ] = true;
 +
        $wgGroupPermissions[ "ns{$title}RO" ][ "ns{$num}_read" ] = true;
 +
    }
 +
}
 +
 +
function wfNamespacePermissions() {
 +
    global $wgHooks;
 +
 +
    // use the userCan hook to check permissions
 +
    $wgHooks[ 'userCan' ][] = 'namespacePermissionsCheckNamespace';
 +
}
 +
 +
function namespacePermissionsCheckNamespace( $title, $user, $action, $result ) {
 +
    if ( ( $ns = $title->getNamespace() ) >= 100 ) {
 +
        if ( ! $user->isAllowed("ns{$ns}_{$action}") ) {
 +
            $result = false;
 +
            return false;
 +
        }
 +
    }
 +
    return null;
 +
}
 +
?>

Version du 3 septembre 2006 à 18:37

(Ne vous fiez pas à tout ce qui est marqué, je fais de nombreux tests...)


Warning003.jpg
Warning003.jpg
Cet Article est en travaux...
L'article n'est pas terminé, veuillez patienter.
Les dernières modifications apparaitront bientôt.

Modèle:Édit

Articles

Créés

Modifiés

Brouillon


Portails

Créés

Modifiés

Modèles

Créés

1 176

Modifiés


Psyko
Lethal Corporation



Cadres

Essais (2)

22 novembre 2024 1 176 2 361 195 Modèle:USER Modèle:PAGES

  • AVIS AUX JOUEURS ET VISITEURS EVENTUELS :
  • AVIS AUX JOUEURS ET VISITEURS EVENTUELS :


<?php /* NamespacePermissions - MediaWiki extension

* 
* provides separate permissions for each action (read,edit,create,move) 
* on articles in custom namespaces for fine access management
*
* Author: Petr Andreev
*
* Sample usage:
*
* $wgExtraNamespaces = array(100 => "Foo", 101 => "Foo_Talk");
* // optional (example): allow registered users to view and edit articles in Foo 
* $wgGroupPermissions[ 'user' ][ 'ns100_read' ] = true;
* $wgGroupPermissions[ 'user' ][ 'ns100_edit' ] = true;
* // end of optional
* require('extensions/NamespacePermissions.php');
* 
* Permissions provided:
*   # ns{$num}_read
*   # ns{$num}_edit
*   # ns{$num}_create
*   # ns{$num}_move
* where {$num} - namespace number (e.g. ns100_read, ns101_create)
*
* Groups provided:
*   # ns{$title}RW - full access to the namespace {$title}
*   # ns{$title}RO - read-only access to the namespace {$title}
*   e.g. nsFoo_talkRW, nsFooRO 
*/

// permissions for autocreated groups should be set now, // before the User object for current user is instantiated namespacePermissionsCreateGroups(); // other stuff should better be done via standard mechanism of running extensions $wgExtensionFunctions[] = "wfNamespacePermissions";

// create groups for each custom namespace function namespacePermissionsCreateGroups() {

   global $wgExtraNamespaces, $wgGroupPermissions;
   foreach ( $wgExtraNamespaces as $num => $title ) {
       $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_edit" ] = true;
       $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_read" ] = true;
       $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_create" ] = true;
       $wgGroupPermissions[ "ns{$title}RW" ][ "ns{$num}_move" ] = true;
       $wgGroupPermissions[ "ns{$title}RO" ][ "ns{$num}_read" ] = true;
   }

}

function wfNamespacePermissions() {

   global $wgHooks;
   // use the userCan hook to check permissions
   $wgHooks[ 'userCan' ][] = 'namespacePermissionsCheckNamespace';

}

function namespacePermissionsCheckNamespace( $title, $user, $action, $result ) {

   if ( ( $ns = $title->getNamespace() ) >= 100 ) {
       if ( ! $user->isAllowed("ns{$ns}_{$action}") ) {
           $result = false;
           return false;
       }
   } 
   return null;

} ?>