From 77cd56332b4f967da64373341b295e1adb6a5920 Mon Sep 17 00:00:00 2001 From: James Riordon Date: Wed, 24 Apr 2024 14:51:41 -0400 Subject: [PATCH] Upgrade to work in latest Mediawiki --- README.md | 51 +++++++++++++++++++++++++++++++++++++++ TalkRight.class.php | 59 +++++++++++++++++---------------------------- TalkRight.php | 23 +++++++++--------- composer.json | 1 - extension.json | 13 ++++------ i18n/en.json | 4 +-- 6 files changed, 92 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index f72bcf5..de521b4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/TalkRight.class.php b/TalkRight.class.php index b8f428e..68c115b 100644 --- a/TalkRight.class.php +++ b/TalkRight.class.php @@ -1,43 +1,28 @@ 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; - } - -} +} \ No newline at end of file diff --git a/TalkRight.php b/TalkRight.php index 5e39c59..b08573c 100644 --- a/TalkRight.php +++ b/TalkRight.php @@ -1,14 +1,15 @@ talk permission independent from article edition", - "talkright-extensionname": "Pipe Escape" + "talkright-desc": "Adds a talk permission independent from page permissions", + "talkright-extensionname": "Talk Right" }