Extension:Talkright

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Talkright

Release status: stable

Implementation User rights
Description This extension makes the editing of talk pages a distinct action from article editing.
Author(s) P Leveque, Marc Noirot
Last version 1.3
MediaWiki 1.12 - 1.18
License No license specified
Download see below
Added rights

Edit talk rights

Check usage (experimental)

Contents

[edit] What can this extension do?

Talkright extension makes the editing of talk pages a distinct action from the editing of articles to create finer permissions, by adding the talk right.

[edit] Usage

On a semi private wiki, a user can be allowed to read but not to edit the content of a page as well as its talk page. This is done by setting:

$wgGroupPermissions['user']['read'] = true;
$wgGroupPermissions['user']['edit'] = false;

Now, if you want to encourage comments to your wiki from a group of persons, by giving them rights to edit the talk pages only, you need to install this Talkright extension and to add, for example, the following two lines:

$wgGroupPermissions['commentators']['edit'] = false;
$wgGroupPermissions['commentators']['talk'] = true;

[edit] History

24 November 2011 Version 1.3 No need to modify 'includes/SkinTemplate.php' to edit "view source" button.
05 August 2008 Version 1.1 Added credits for MediaWiki version 1.12, 1.13.
20 June 2006 Version 1.0.1 Added credits and extension version information.
07 June 2006 Version 1.0 First release.

[edit] Version 1.3

New in this version: No need to modify 'includes/SkinTemplate.php' to edit "view source" button.

Tested with:

  • MW 1.16 - skins: monobook
  • MW 1.18

[edit] Installation

1. Make a folder 'TalkRight' in MediaWiki's extensions folder.
2. Copy the code below in a file named 'TalkRight.php' in this 'TalkRight' folder.
3. Add the following line in the LocalSettings.php file:
require_once("$IP/extensions/TalkRight/TalkRight.php");
4. Now you can use the 'talk' right within the group user rights.

[edit] Code

<?php
/**
 * Talkright MediaWiki extension
 * @author Marc Noirot - marc dot noirot at gmail
 * @author P.Levêque - User:Phillev
 *
 * This extension makes the editing of talk pages a distinct action from
 * the editing of articles, to create finer permissions by adding the 'talk' right.
 *
*/
 
if ( !defined( 'MEDIAWIKI' ) ) {
        echo <<<EOT
To install the TalkRight extension, put the following line in LocalSettings.php:
require_once( "\$IP/extensions/TalkRight/TalkRight.php" );
EOT;
        exit( 1 );
}
 
$wgExtensionCredits['other'][] = array(
        'name' => 'TalkRight',
        'version' => '1.3',
        'author' => array('P.Levêque', 'Marc Noirot'),
        'description' => 'Adds a <tt>talk</tt> permission independent from article edition',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Talkright',
);
 
 
# Register hooks
$wgHooks['userCan'      ][] = 'TalkRight::userCanTalk';
$wgHooks['AlternateEdit'][] = 'TalkRight::alternateEdit';
// 'SkinTemplateNavigation' replaced 'SkinTemplateTabs' in the Vector skin
$wgHooks['SkinTemplateTabs'      ][] = 'TalkRight::changeEditTab';
$wgHooks['SkinTemplateNavigation'][] = 'TalkRight::changeEditTab2';
 
# Global 'talk' right
$wgAvailableRights[] = 'talk';
 
class TalkRight {
 
        /**
         * Changes the label of the 'view source'-tab to 'edit' if the have the
         * 'talk' right.
         * @param $skin the skin it was called from
         * @param &$content_actions the array of content actions
         * return true to resume edition to normal operation
         */
        static function changeEditTab( $skin, &$content_actions ) {
                global $wgTitle, $wgUser;
                if ( $wgTitle->isTalkPage() && $wgUser->isAllowed( 'talk' ) ) {
                        if ( isset( $content_actions['viewsource'] ) ) {
                                $content_actions['viewsource']['text'] = wfMsg( 'edit' );;
                        }
                }
 
                return true;
        }
 
        /**
         * For wikis with vector-skin: Changes the label of the 'view source'-
         * tab to 'edit' if the user have the 'talk' right.
         * Function currently called only for the 'Vector' skin - will
         * possibly be called for additional skins later.
         * @param $obj SkinTemplate object
         * @param $links Structured navigation links
         * return true to resume edition to normal operation
         */
        static function changeEditTab2( $obj, &$links ) {
                // the old '$content_actions' array is thankfully just a
                // sub-array of this one
                $views_links = $links['views'];
                self::changeEditTab( $obj, $views_links );
                $links['views'] = $views_links;
                return true;
        }
 
        /**
         * Can user edit the given page if it's a talk page?
         * @param &$title the concerned page
         * @param &$wgUser the current MediaWiki user
         * @param $action the action performed
         * @param &$result (out) true or false, or null if we don't care about the parameters
         */
        static function userCanTalk( &$title, &$user, $action, &$result ) {
                if ( $action = 'edit' && $title->isTalkPage() ) {
                        $return = $user->isAllowed( 'talk' );
                }
                return true;
        }
 
        /**
         * Bypass edit restriction when editing pages if user can talk and page is a comment.
         * @param $&editPage the page edition object
         * @return true to resume edition to normal operation
         */
        static function alternateEdit( $editPage ) {
                global $wgOut, $wgUser, $wgRequest, $wgTitle;
                if ( $wgTitle->isTalkPage() && $wgUser->isAllowed( 'talk' ) ) {
                        array_push( $wgUser->mRights, 'edit' );
                }
                return true;
        }
}

[edit] MediaWiki 1.12 and 1.13 Code

This code has been tested on MediaWiki 1.12 and 1.13.

<?php
/**
 * Talkright MediaWiki extension
 * @version 1.2
 * @author Marc Noirot - marc dot noirot at gmail
 * @author P.Levêque - User:Phillev
 * @link http://www.mediawiki.org/wiki/Extension:Talkright
 *
 * This extension makes the editing of talk pages a distinct action from
 * the editing of articles, to create finer permissions by adding the 'talk' right.
 *
 * Edit tab in talk page
       a "view source" button is still  existing on talk pages. To fix this problem, modify includes/SkinTemplate.php on line 672 changing :
     " if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {"
      to
     " if ( ($this->mTitle->quickUserCan( 'edit' ) || ($this->mTitle->isTalkPage() && $wgUser->isAllowed('talk'))) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {"
 
*/
 
if (!defined('MEDIAWIKI')) die();
 
$wgExtensionCredits['other'][] = array(
        'name' => 'Talkright',
        'version' => '1.2',
        'author' => array('P.Levêque', 'Marc Noirot'),
        'description' => 'Adds a <tt>talk</tt> permission independent from article edition',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Talkright',
);
 
 
/* Register hooks */
$wgHooks['userCan'][] = 'userCanTalk';
$wgHooks['AlternateEdit'][] = 'alternateEdit';
 
/* Global 'talk' right */
$wgAvailableRights[] = 'talk';
 
/**
 * Can user edit the given page if it's a talk page?
 * @param &$title the concerned page
 * @param &$wgUser the current MediaWiki user
 * @param $action the action performed
 * @param &$result (out) true or false, or null if we don't care about the parameters
 */
 
function userCanTalk(&$title, &$user, $action, &$result) {
        if ( $action = 'edit' && $title->isTalkPage() ) {
                $return = $user->isAllowed( 'talk' );
        }
        return true;
}
 
/*
 * Bypass edit restriction when editing pages if user can talk and page is a comment.
 * @param $&editPage the page edition object
 * @return true to resume edition to normal operation
*/
 
function alternateEdit(&$editPage) {
        global $wgOut, $wgUser, $wgRequest, $wgTitle;
        if ( $wgTitle->isTalkPage() && $wgUser->isAllowed( 'talk' )) {
                array_push($wgUser->mRights, 'edit');
        }
        return true;
}

[edit] MediaWiki 1.6.X Code

This code has been tested on MediaWiki 1.6.1 and 1.6.7. DOES NOT WORK FOR MediaWiki 1.12 and 1.13.

<?php
/*
    Talkright MediaWiki Extension
    By Marc Noirot - marc dot noirot at gmail
 
    This extension makes the editing of talk pages a distinct action from
    the editing of articles, to create finer permissions by adding the 'talk' right.
*/
 
if (!defined('MEDIAWIKI')) die();
 
$wgExtensionCredits['other'][] = array(
    'name' => 'talkright',
    'description' => 'adds a talk permission independant from article edition',
    'url' => 'http://www.mediawiki.org/wiki/Extension:Talkright',
    'author' => 'Marc Noirot',
    'version' => '1.0.1'
);
 
/*
    global 'talk' right
*/
array_push($wgAvailableRights, 'talk');
 
/**
 * Can user edit the given page if it's a talk page ?
 * @param &$title the concerned page
 * @param &$wgUser the current mediawiki user
 * @param $action the action performed
 * @param &$result (out) true or false, or null if we don't care about the parameters
 */
function userCanTalk(&$title, &$wgUser, $action, &$result) {
    if ($action == 'edit' && $title->isTalkPage()) {
        if (!$wgUser->isAllowed('talk')) {
            $result = false;
            return false;
        }
    }
    return true;
}
 
/**
 * Bypass edit restriction when editing pages if user can talk and page is a comment.
 * @param $&editPage the page edition object
 * @return true to resume edition to normal operation
 */
function alternateEdit(&$editPage) {
    global $wgOut, $wgUser, $wgRequest, $wgTitle;
 
    if ($wgTitle->isTalkPage() && $wgUser->isAllowed('talk')) {
        array_push($wgUser->mRights, 'edit');
    }
    return true;
}
 
/*
    register global hooks
*/
$wgHooks['userCan'][] = 'userCanTalk';
$wgHooks['AlternateEdit'][] = 'alternateEdit';

[edit] See also

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox