Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to work in latest Mediawiki #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,57 @@ MediaWiki-TalkRight

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

## Installation
### Composer
From MediaWiki version 1.22 onwards TalkRight should be installed using Composer. The package name is mediawiki/talk-right. For instructions on how to install Composer see MediaWiki's Composer User manual.

Once you have Composer properly installed, all you need to do is go to your MediaWiki installation directory and run:

- composer require mediawiki/talk-right ~1.5 for the latest stable version or
- composer require mediawiki/talk-right 'dev-master' for the latest development version

Any future update is then just a call to composer update or composer update enterprisemediawiki/talk-right and you can always be sure that all dependencies are met (currently there are no dependencies).

Continue with the Common steps below.

Beware: If you have installed an earlier version of TalkRight you need to remove its code from the MediaWiki extension directory and delete the call to require_once from the LocalSettings.php file before starting the re-installation with Composer.

### Using packaged downloads

If this is not an option, you may also install it like this:

1. Download the latest stable release or latest development release from GitHub.
Alternatively you can clone TalkRight using git
2. Extract the files to the $IP/extensions directory
3. If necessary rename the newly created directory to TalkRight
4. Add to the end of LocalSettings.php:

```
wfLoadExtension( 'TalkRight' );
```

5. Continue with the Common steps below.

### Common steps

1. Edit LocalSettings to specify which users have the talk right (see below)
2. Go to the Special:Version page of your wiki and verify that an entry for TalkRight exists

## 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:

```php
$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:

```php
$wgGroupPermissions['commentators']['edit'] = false;
$wgGroupPermissions['commentators']['talk'] = true;
```
@author Marc Noirot - marc dot noirot at gmail
@author P.Levêque - User:Phillev
@author James Montalvo - User:Jamesmontalvo3
59 changes: 22 additions & 37 deletions TalkRight.class.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
<?php
/**
* Main class for the Talkright MediaWiki extension
* @author Marc Noirot - marc dot noirot at gmail
* @author P.Lev�que - User:Phillev
* @author James Montalvo - User:Jamesmontalvo3
*
*
*/
class TalkRight {

class TalkRight
{
/**
* Bypass edit restriction when EDITING pages if user has 'talk' right and page is a talk (discussion) page.
* @param $&editPage the page edition object
* @return true to resume edition to normal operation
* Dynamically adjust user rights
* Grant 'edit' right if the user has 'talk' permission and is trying to edit a talk page.
* @param User $user User object
* @param array &$rights Array of rights
*/
static function alternateEdit( $editPage ) {
global $wgOut, $wgUser, $wgRequest, $wgTitle;
if ( $wgTitle->isTalkPage() && $wgUser->isAllowed( 'talk' ) ) {
array_push( $wgUser->mRights, 'edit' );
public static function onUserGetRights(User $user, array &$rights)
{
$title = RequestContext::getMain()->getTitle();
if (($title && $title->getSubjectPage()->exists() && $title->isTalkPage()) ||
($title->getText() === $user->getName() &&
((in_array($title->getNamespace(), [NS_USER, NS_USER_TALK]))))
) {
if (in_array('talk', $rights)) {
if (!in_array('edit', $rights)) {
$rights[] = 'edit';
}
if (!in_array('createpage', $rights)) {
$rights[] = 'createpage';
}
}
}
return true;
}

/**
* Bypass edit restriction when VIEWING pages if user has 'talk' right and page is a talk (discussion) page.
* This is probably not the ideal hook to use. I just needed one earlier than creation of section links, edit tab and add topic tab
* @param &$parser parser object, used to gain access to User and Title objects
* @param &$text unused
* @param &$strip_state unused
* @return true and false both seemed to work. [[Manual:Hooks/ParserBeforeStrip]] doesn't indicate what return value affects
*/
static function giveEditRightsWhenViewingTalkPages ( &$parser, &$test1, &$test2 ) {

$user = $parser->getUser();
if ( $parser->getTitle()->isTalkPage() && $user->isAllowed( 'talk' ) ) {
array_push( $user->mRights, 'edit' );
}

return true;
}

}
}
23 changes: 12 additions & 11 deletions TalkRight.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php
if ( function_exists( 'wfLoadExtension' ) ) {
wfLoadExtension( 'TalkRight' );
// Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessagesDirs['TalkRight'] = __DIR__ . '/i18n';
wfWarn(
'Deprecated PHP entry point used for FooBar extension. ' .
'Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
);
return;

if (function_exists('wfLoadExtension')) {
wfLoadExtension('TalkRight');
// Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessagesDirs['TalkRight'] = __DIR__ . '/i18n';
wfWarn(
'Deprecated PHP entry point used for TalkRight extension. ' .
'Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
);
return;
} else {
die( 'This version of the TalkRight extension requires MediaWiki 1.25+' );
die('This version of the TalkRight extension requires MediaWiki 1.40+');
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}
],
"support": {
"issues": "https://bugzilla.wikimedia.org/",
"github": "https://github.com/enterprisemediawiki/TalkRight/issues"
},
"require": {
Expand Down
13 changes: 5 additions & 8 deletions extension.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "TalkRight",
"version": "2.0.0",
"version": "3.0.0",
"author": [
"P.Leveque",
"Marc Noirot",
"James Montalvo"
],
"url": "http://www.mediawiki.org/wiki/Extension:Talkright",
"descriptionmsg": "talkright-desc",
"descriptionmsg": "Grant 'edit' right if the user has 'talk' permission and is trying to edit a talk page. Works even if user has no page edit rights",
"type": "other",
"AvailableRights": [
"talk"
Expand All @@ -16,12 +16,9 @@
"TalkRight": "TalkRight.class.php"
},
"Hooks": {
"AlternateEdit": [
"TalkRight::alternateEdit"
],
"ParserBeforeStrip": [
"TalkRight::giveEditRightsWhenViewingTalkPages"
"UserGetRights": [
"TalkRight::onUserGetRights"
]
},
}
"manifest_version": 1
}
4 changes: 2 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"talkright-desc": "Adds a <tt>talk</tt> permission independent from article edition",
"talkright-extensionname": "Pipe Escape"
"talkright-desc": "Adds a <tt>talk</tt> permission independent from page permissions",
"talkright-extensionname": "Talk Right"
}